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
- #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.
- #spin ⇒ 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.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/osvm/machine_config.rb', line 230 def initialize(cfg) @spin = cfg.fetch('spin', 'vpsadminos') @qemu = cfg.fetch('qemu') @extra_qemu_options = cfg.fetch('extraQemuOptions', []) @virtiofsd = cfg.fetch('virtiofsd') @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)
218 219 220 |
# File 'lib/osvm/machine_config.rb', line 218 def cpus @cpus end |
#disks ⇒ Array<Disk> (readonly)
212 213 214 |
# File 'lib/osvm/machine_config.rb', line 212 def disks @disks end |
#extra_qemu_options ⇒ Array<String> (readonly)
194 195 196 |
# File 'lib/osvm/machine_config.rb', line 194 def @extra_qemu_options end |
#initrd ⇒ String (readonly)
Returns path to initrd.
203 204 205 |
# File 'lib/osvm/machine_config.rb', line 203 def initrd @initrd end |
#kernel ⇒ String (readonly)
Returns path to kernel bzImage.
200 201 202 |
# File 'lib/osvm/machine_config.rb', line 200 def kernel @kernel end |
#kernel_params ⇒ Array<String> (readonly)
Returns kernel parameters.
206 207 208 |
# File 'lib/osvm/machine_config.rb', line 206 def kernel_params @kernel_params end |
#memory ⇒ Integer (readonly)
Returns system memory in MiB.
215 216 217 |
# File 'lib/osvm/machine_config.rb', line 215 def memory @memory end |
#networks ⇒ Array<Network> (readonly)
227 228 229 |
# File 'lib/osvm/machine_config.rb', line 227 def networks @networks end |
#qemu ⇒ String (readonly)
Returns path to qemu package.
191 192 193 |
# File 'lib/osvm/machine_config.rb', line 191 def qemu @qemu end |
#shared_filesystems ⇒ Hash<String, String> (readonly)
Returns fs name => host directory.
224 225 226 |
# File 'lib/osvm/machine_config.rb', line 224 def shared_filesystems @shared_filesystems end |
#spin ⇒ String (readonly)
188 189 190 |
# File 'lib/osvm/machine_config.rb', line 188 def spin @spin end |
#toplevel ⇒ String (readonly)
Returns path to system top level.
209 210 211 |
# File 'lib/osvm/machine_config.rb', line 209 def toplevel @toplevel end |
#virtiofsd ⇒ String (readonly)
Returns path to virtiofsd package.
197 198 199 |
# File 'lib/osvm/machine_config.rb', line 197 def virtiofsd @virtiofsd end |
Class Method Details
.from_config(cfg) ⇒ MachineConfig
Build machine config from hash
174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/osvm/machine_config.rb', line 174 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
166 167 168 169 |
# File 'lib/osvm/machine_config.rb', line 166 def self.load_file(path) cfg = JSON.parse(File.read(path)) from_config(cfg) end |