Class: OsVm::MachineConfig
- Inherits:
-
Object
- Object
- OsVm::MachineConfig
- Defined in:
- lib/osvm/machine_config.rb
Defined Under Namespace
Classes: BridgeNetwork, Cpu, Disk, Network, 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.
- #network ⇒ 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.
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
#cpus ⇒ Integer (readonly)
157 158 159 |
# File 'lib/osvm/machine_config.rb', line 157 def cpus @cpus end |
#disks ⇒ Array<Disk> (readonly)
151 152 153 |
# File 'lib/osvm/machine_config.rb', line 151 def disks @disks end |
#extra_qemu_options ⇒ Array<String> (readonly)
130 131 132 |
# File 'lib/osvm/machine_config.rb', line 130 def @extra_qemu_options end |
#initrd ⇒ String (readonly)
Returns path to initrd.
142 143 144 |
# File 'lib/osvm/machine_config.rb', line 142 def initrd @initrd end |
#kernel ⇒ String (readonly)
Returns path to kernel bzImage.
139 140 141 |
# File 'lib/osvm/machine_config.rb', line 139 def kernel @kernel end |
#kernel_params ⇒ Array<String> (readonly)
Returns kernel parameters.
145 146 147 |
# File 'lib/osvm/machine_config.rb', line 145 def kernel_params @kernel_params end |
#memory ⇒ Integer (readonly)
Returns system memory in MiB.
154 155 156 |
# File 'lib/osvm/machine_config.rb', line 154 def memory @memory end |
#network ⇒ Network (readonly)
166 167 168 |
# File 'lib/osvm/machine_config.rb', line 166 def network @network end |
#qemu ⇒ String (readonly)
Returns path to qemu package.
127 128 129 |
# File 'lib/osvm/machine_config.rb', line 127 def qemu @qemu end |
#shared_filesystems ⇒ Hash<String, String> (readonly)
Returns fs name => host directory.
163 164 165 |
# File 'lib/osvm/machine_config.rb', line 163 def shared_filesystems @shared_filesystems end |
#squashfs ⇒ String (readonly)
Returns path to squashfs rootfs image.
136 137 138 |
# File 'lib/osvm/machine_config.rb', line 136 def squashfs @squashfs end |
#toplevel ⇒ String (readonly)
Returns path to system top level.
148 149 150 |
# File 'lib/osvm/machine_config.rb', line 148 def toplevel @toplevel end |
#virtiofsd ⇒ String (readonly)
Returns 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
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 |