Class: OsVm::MachineConfig
- Inherits:
-
Object
- Object
- OsVm::MachineConfig
- Defined in:
- lib/osvm/machine_config.rb
Defined Under Namespace
Classes: BridgeNetwork, Cpu, Disk, Network, SocketNetwork, UserNetwork
Instance Attribute Summary collapse
- #cpu ⇒ Cpu readonly
- #cpus ⇒ Integer readonly
- #disks ⇒ Array<Disk> readonly
- #extra_qemu_options ⇒ Array<String> readonly
-
#initrd ⇒ String
readonly
Path to initrd.
-
#kernel ⇒ String
readonly
Path to kernel bzImage.
-
#kernel_params ⇒ Array<String>
readonly
Kernel parameters.
-
#memory ⇒ Integer
readonly
System memory in MiB.
- #networks ⇒ Array<Network> readonly
-
#qemu ⇒ String
readonly
Path to qemu package.
-
#shared_filesystems ⇒ Hash<String, String>
readonly
Fs name => host directory.
-
#squashfs ⇒ String
readonly
Path to squashfs rootfs image.
-
#toplevel ⇒ String
readonly
Path to system top level.
-
#virtiofsd ⇒ String
readonly
Path to virtiofsd package.
Class Method Summary collapse
-
.load_file(path) ⇒ MachineConfig
Load machine config from file.
Instance Method Summary collapse
-
#initialize(cfg) ⇒ MachineConfig
constructor
A new instance of MachineConfig.
Constructor Details
#initialize(cfg) ⇒ MachineConfig
Returns a new instance of MachineConfig.
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
#cpus ⇒ Integer (readonly)
202 203 204 |
# File 'lib/osvm/machine_config.rb', line 202 def cpus @cpus end |
#disks ⇒ Array<Disk> (readonly)
196 197 198 |
# File 'lib/osvm/machine_config.rb', line 196 def disks @disks end |
#extra_qemu_options ⇒ Array<String> (readonly)
175 176 177 |
# File 'lib/osvm/machine_config.rb', line 175 def @extra_qemu_options end |
#initrd ⇒ String (readonly)
Returns path to initrd.
187 188 189 |
# File 'lib/osvm/machine_config.rb', line 187 def initrd @initrd end |
#kernel ⇒ String (readonly)
Returns path to kernel bzImage.
184 185 186 |
# File 'lib/osvm/machine_config.rb', line 184 def kernel @kernel end |
#kernel_params ⇒ Array<String> (readonly)
Returns kernel parameters.
190 191 192 |
# File 'lib/osvm/machine_config.rb', line 190 def kernel_params @kernel_params end |
#memory ⇒ Integer (readonly)
Returns system memory in MiB.
199 200 201 |
# File 'lib/osvm/machine_config.rb', line 199 def memory @memory end |
#networks ⇒ Array<Network> (readonly)
211 212 213 |
# File 'lib/osvm/machine_config.rb', line 211 def networks @networks end |
#qemu ⇒ String (readonly)
Returns path to qemu package.
172 173 174 |
# File 'lib/osvm/machine_config.rb', line 172 def qemu @qemu end |
#shared_filesystems ⇒ Hash<String, String> (readonly)
Returns fs name => host directory.
208 209 210 |
# File 'lib/osvm/machine_config.rb', line 208 def shared_filesystems @shared_filesystems end |
#squashfs ⇒ String (readonly)
Returns path to squashfs rootfs image.
181 182 183 |
# File 'lib/osvm/machine_config.rb', line 181 def squashfs @squashfs end |
#toplevel ⇒ String (readonly)
Returns path to system top level.
193 194 195 |
# File 'lib/osvm/machine_config.rb', line 193 def toplevel @toplevel end |
#virtiofsd ⇒ String (readonly)
Returns 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
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 |