Class: OsVm::MachineConfig
- Inherits:
-
Object
- Object
- OsVm::MachineConfig
- Defined in:
- lib/osvm/machine_config.rb
Direct Known Subclasses
Defined Under Namespace
Classes: BridgeNetwork, Cpu, Disk, Network, SocketNetwork, UserNetwork
Instance Attribute Summary collapse
- #boot_mode ⇒ 'direct', 'firmware' readonly
- #boot_order ⇒ String? readonly
- #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.
- #labels ⇒ Hash<String, String> readonly
-
#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.
- #spin ⇒ String readonly
- #tags ⇒ Array<String> readonly
-
#toplevel ⇒ String
readonly
Path to system top level.
-
#virtiofsd ⇒ String
readonly
Path to virtiofsd package.
Class Method Summary collapse
-
.from_config(cfg) ⇒ MachineConfig
Build machine config from hash.
-
.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.
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/osvm/machine_config.rb', line 260 def initialize(cfg) @spin = cfg.fetch('spin', 'vpsadminos') @qemu = cfg.fetch('qemu') @boot_mode = cfg.fetch('bootMode', 'direct') @boot_order = cfg['bootOrder'] @extra_qemu_options = cfg.fetch('extraQemuOptions', []) @virtiofsd = cfg.fetch('virtiofsd') @kernel = cfg['kernel'] @initrd = cfg['initrd'] @kernel_params = cfg.fetch('kernelParams', []) @toplevel = cfg['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 @tags = cfg.fetch('tags', []) @labels = cfg.fetch('labels', {}) unless %w[direct firmware].include?(@boot_mode) raise ArgumentError, "unsupported boot mode #{@boot_mode.inspect}" end return unless @boot_mode == 'direct' %w[kernel initrd toplevel].each do |v| next if cfg[v] raise ArgumentError, "missing #{v.inspect} for direct boot machine" end end |
Instance Attribute Details
#boot_mode ⇒ 'direct', 'firmware' (readonly)
212 213 214 |
# File 'lib/osvm/machine_config.rb', line 212 def boot_mode @boot_mode end |
#boot_order ⇒ String? (readonly)
215 216 217 |
# File 'lib/osvm/machine_config.rb', line 215 def boot_order @boot_order end |
#cpus ⇒ Integer (readonly)
242 243 244 |
# File 'lib/osvm/machine_config.rb', line 242 def cpus @cpus end |
#disks ⇒ Array<Disk> (readonly)
236 237 238 |
# File 'lib/osvm/machine_config.rb', line 236 def disks @disks end |
#extra_qemu_options ⇒ Array<String> (readonly)
218 219 220 |
# File 'lib/osvm/machine_config.rb', line 218 def @extra_qemu_options end |
#initrd ⇒ String (readonly)
Returns path to initrd.
227 228 229 |
# File 'lib/osvm/machine_config.rb', line 227 def initrd @initrd end |
#kernel ⇒ String (readonly)
Returns path to kernel bzImage.
224 225 226 |
# File 'lib/osvm/machine_config.rb', line 224 def kernel @kernel end |
#kernel_params ⇒ Array<String> (readonly)
Returns kernel parameters.
230 231 232 |
# File 'lib/osvm/machine_config.rb', line 230 def kernel_params @kernel_params end |
#labels ⇒ Hash<String, String> (readonly)
257 258 259 |
# File 'lib/osvm/machine_config.rb', line 257 def labels @labels end |
#memory ⇒ Integer (readonly)
Returns system memory in MiB.
239 240 241 |
# File 'lib/osvm/machine_config.rb', line 239 def memory @memory end |
#networks ⇒ Array<Network> (readonly)
251 252 253 |
# File 'lib/osvm/machine_config.rb', line 251 def networks @networks end |
#qemu ⇒ String (readonly)
Returns path to qemu package.
209 210 211 |
# File 'lib/osvm/machine_config.rb', line 209 def qemu @qemu end |
#shared_filesystems ⇒ Hash<String, String> (readonly)
Returns fs name => host directory.
248 249 250 |
# File 'lib/osvm/machine_config.rb', line 248 def shared_filesystems @shared_filesystems end |
#spin ⇒ String (readonly)
206 207 208 |
# File 'lib/osvm/machine_config.rb', line 206 def spin @spin end |
#tags ⇒ Array<String> (readonly)
254 255 256 |
# File 'lib/osvm/machine_config.rb', line 254 def @tags end |
#toplevel ⇒ String (readonly)
Returns path to system top level.
233 234 235 |
# File 'lib/osvm/machine_config.rb', line 233 def toplevel @toplevel end |
#virtiofsd ⇒ String (readonly)
Returns path to virtiofsd package.
221 222 223 |
# File 'lib/osvm/machine_config.rb', line 221 def virtiofsd @virtiofsd end |
Class Method Details
.from_config(cfg) ⇒ MachineConfig
Build machine config from hash
192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/osvm/machine_config.rb', line 192 def self.from_config(cfg) spin = cfg.fetch('spin', 'vpsadminos') case spin when 'vpsadminos' VpsadminosMachineConfig.new(cfg) when 'nixos' NixosMachineConfig.new(cfg) else raise ArgumentError, "Unknown machine spin #{spin.inspect}" end end |
.load_file(path) ⇒ MachineConfig
Load machine config from file
184 185 186 187 |
# File 'lib/osvm/machine_config.rb', line 184 def self.load_file(path) cfg = JSON.parse(File.read(path)) from_config(cfg) end |