Class: OsVm::MachineConfig

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

Defined Under Namespace

Classes: BridgeNetwork, Cpu, Disk, Network, SocketNetwork, 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)


214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/osvm/machine_config.rb', line 214

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', {})
  @networks = cfg.fetch('networks', [{ 'type' => 'user' }]).each_with_index.map do |net_cfg, i|
    Network.from_config(i, net_cfg)
  end
end

Instance Attribute Details

#cpuCpu (readonly)

Returns:



205
206
207
# File 'lib/osvm/machine_config.rb', line 205

def cpu
  @cpu
end

#cpusInteger (readonly)

Returns:

  • (Integer)


202
203
204
# File 'lib/osvm/machine_config.rb', line 202

def cpus
  @cpus
end

#disksArray<Disk> (readonly)

Returns:



196
197
198
# File 'lib/osvm/machine_config.rb', line 196

def disks
  @disks
end

#extra_qemu_optionsArray<String> (readonly)

Returns:

  • (Array<String>)


175
176
177
# File 'lib/osvm/machine_config.rb', line 175

def extra_qemu_options
  @extra_qemu_options
end

#initrdString (readonly)

Returns path to initrd.

Returns:

  • (String)

    path to initrd



187
188
189
# File 'lib/osvm/machine_config.rb', line 187

def initrd
  @initrd
end

#kernelString (readonly)

Returns path to kernel bzImage.

Returns:

  • (String)

    path to kernel bzImage



184
185
186
# File 'lib/osvm/machine_config.rb', line 184

def kernel
  @kernel
end

#kernel_paramsArray<String> (readonly)

Returns kernel parameters.

Returns:

  • (Array<String>)

    kernel parameters



190
191
192
# File 'lib/osvm/machine_config.rb', line 190

def kernel_params
  @kernel_params
end

#memoryInteger (readonly)

Returns system memory in MiB.

Returns:

  • (Integer)

    system memory in MiB



199
200
201
# File 'lib/osvm/machine_config.rb', line 199

def memory
  @memory
end

#networksArray<Network> (readonly)

Returns:



211
212
213
# File 'lib/osvm/machine_config.rb', line 211

def networks
  @networks
end

#qemuString (readonly)

Returns path to qemu package.

Returns:

  • (String)

    path to qemu package



172
173
174
# File 'lib/osvm/machine_config.rb', line 172

def qemu
  @qemu
end

#shared_filesystemsHash<String, String> (readonly)

Returns fs name => host directory.

Returns:

  • (Hash<String, String>)

    fs name => host directory



208
209
210
# File 'lib/osvm/machine_config.rb', line 208

def shared_filesystems
  @shared_filesystems
end

#squashfsString (readonly)

Returns path to squashfs rootfs image.

Returns:

  • (String)

    path to squashfs rootfs image



181
182
183
# File 'lib/osvm/machine_config.rb', line 181

def squashfs
  @squashfs
end

#toplevelString (readonly)

Returns path to system top level.

Returns:

  • (String)

    path to system top level



193
194
195
# File 'lib/osvm/machine_config.rb', line 193

def toplevel
  @toplevel
end

#virtiofsdString (readonly)

Returns path to virtiofsd package.

Returns:

  • (String)

    path to virtiofsd package



178
179
180
# File 'lib/osvm/machine_config.rb', line 178

def virtiofsd
  @virtiofsd
end

Class Method Details

.load_file(path) ⇒ MachineConfig

Load machine config from file

Parameters:

  • path (String)

Returns:



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

def self.load_file(path)
  cfg = JSON.parse(File.read(path))
  new(cfg)
end