Class: OsVm::MachineConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/osvm/machine_config.rb

Defined Under Namespace

Classes: BridgeNetwork, Cpu, Disk, Network, UserNetwork

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg) ⇒ MachineConfig

Returns a new instance of MachineConfig.

Parameters:

  • cfg (Hash)


169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/osvm/machine_config.rb', line 169

def initialize(cfg)
  @qemu = cfg.fetch(:qemu)
  @extra_qemu_options = cfg.fetch(:extraQemuOptions, [])
  @virtiofsd = cfg.fetch(:virtiofsd)
  @squashfs = cfg.fetch(:squashfs)
  @kernel = cfg.fetch(:kernel)
  @initrd = cfg.fetch(:initrd)
  @kernel_params = cfg.fetch(:kernelParams)
  @toplevel = cfg.fetch(:toplevel)
  @disks = cfg.fetch(:disks).map { |disk_cfg| Disk.new(disk_cfg) }
  @memory = cfg.fetch(:memory)
  @cpus = cfg.fetch(:cpus)
  @cpu = Cpu.new(cfg.fetch(:cpu))
  @shared_filesystems = cfg.fetch(:sharedFileSystems, {})
  @network = Network.from_config(cfg.fetch(:network, {
    mode: 'user',
    opts: {
      network: '10.0.2.0/24',
      host: '10.0.2.2',
      dns: '10.0.2.3'
    }
  }))
end

Instance Attribute Details

#cpuCpu (readonly)

Returns:



160
161
162
# File 'lib/osvm/machine_config.rb', line 160

def cpu
  @cpu
end

#cpusInteger (readonly)

Returns:

  • (Integer)


157
158
159
# File 'lib/osvm/machine_config.rb', line 157

def cpus
  @cpus
end

#disksArray<Disk> (readonly)

Returns:



151
152
153
# File 'lib/osvm/machine_config.rb', line 151

def disks
  @disks
end

#extra_qemu_optionsArray<String> (readonly)

Returns:

  • (Array<String>)


130
131
132
# File 'lib/osvm/machine_config.rb', line 130

def extra_qemu_options
  @extra_qemu_options
end

#initrdString (readonly)

Returns path to initrd.

Returns:

  • (String)

    path to initrd



142
143
144
# File 'lib/osvm/machine_config.rb', line 142

def initrd
  @initrd
end

#kernelString (readonly)

Returns path to kernel bzImage.

Returns:

  • (String)

    path to kernel bzImage



139
140
141
# File 'lib/osvm/machine_config.rb', line 139

def kernel
  @kernel
end

#kernel_paramsArray<String> (readonly)

Returns kernel parameters.

Returns:

  • (Array<String>)

    kernel parameters



145
146
147
# File 'lib/osvm/machine_config.rb', line 145

def kernel_params
  @kernel_params
end

#memoryInteger (readonly)

Returns system memory in MiB.

Returns:

  • (Integer)

    system memory in MiB



154
155
156
# File 'lib/osvm/machine_config.rb', line 154

def memory
  @memory
end

#networkNetwork (readonly)

Returns:



166
167
168
# File 'lib/osvm/machine_config.rb', line 166

def network
  @network
end

#qemuString (readonly)

Returns path to qemu package.

Returns:

  • (String)

    path to qemu package



127
128
129
# File 'lib/osvm/machine_config.rb', line 127

def qemu
  @qemu
end

#shared_filesystemsHash<String, String> (readonly)

Returns fs name => host directory.

Returns:

  • (Hash<String, String>)

    fs name => host directory



163
164
165
# File 'lib/osvm/machine_config.rb', line 163

def shared_filesystems
  @shared_filesystems
end

#squashfsString (readonly)

Returns path to squashfs rootfs image.

Returns:

  • (String)

    path to squashfs rootfs image



136
137
138
# File 'lib/osvm/machine_config.rb', line 136

def squashfs
  @squashfs
end

#toplevelString (readonly)

Returns path to system top level.

Returns:

  • (String)

    path to system top level



148
149
150
# File 'lib/osvm/machine_config.rb', line 148

def toplevel
  @toplevel
end

#virtiofsdString (readonly)

Returns path to virtiofsd package.

Returns:

  • (String)

    path to virtiofsd package



133
134
135
# File 'lib/osvm/machine_config.rb', line 133

def virtiofsd
  @virtiofsd
end

Class Method Details

.load_file(path) ⇒ MachineConfig

Load machine config from file

Parameters:

  • path (String)

Returns:



121
122
123
124
# File 'lib/osvm/machine_config.rb', line 121

def self.load_file(path)
  cfg = JSON.parse(File.read(path), symbolize_names: true)
  new(cfg)
end