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.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/osvm/machine_config.rb', line 168 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)
156 157 158 |
# File 'lib/osvm/machine_config.rb', line 156 def cpus @cpus end |
#disks ⇒ Array<Disk> (readonly)
150 151 152 |
# File 'lib/osvm/machine_config.rb', line 150 def disks @disks end |
#extra_qemu_options ⇒ Array<String> (readonly)
129 130 131 |
# File 'lib/osvm/machine_config.rb', line 129 def @extra_qemu_options end |
#initrd ⇒ String (readonly)
Returns path to initrd.
141 142 143 |
# File 'lib/osvm/machine_config.rb', line 141 def initrd @initrd end |
#kernel ⇒ String (readonly)
Returns path to kernel bzImage.
138 139 140 |
# File 'lib/osvm/machine_config.rb', line 138 def kernel @kernel end |
#kernel_params ⇒ Array<String> (readonly)
Returns kernel parameters.
144 145 146 |
# File 'lib/osvm/machine_config.rb', line 144 def kernel_params @kernel_params end |
#memory ⇒ Integer (readonly)
Returns system memory in MiB.
153 154 155 |
# File 'lib/osvm/machine_config.rb', line 153 def memory @memory end |
#network ⇒ Network (readonly)
165 166 167 |
# File 'lib/osvm/machine_config.rb', line 165 def network @network end |
#qemu ⇒ String (readonly)
Returns path to qemu package.
126 127 128 |
# File 'lib/osvm/machine_config.rb', line 126 def qemu @qemu end |
#shared_filesystems ⇒ Hash<String, String> (readonly)
Returns fs name => host directory.
162 163 164 |
# File 'lib/osvm/machine_config.rb', line 162 def shared_filesystems @shared_filesystems end |
#squashfs ⇒ String (readonly)
Returns path to squashfs rootfs image.
135 136 137 |
# File 'lib/osvm/machine_config.rb', line 135 def squashfs @squashfs end |
#toplevel ⇒ String (readonly)
Returns path to system top level.
147 148 149 |
# File 'lib/osvm/machine_config.rb', line 147 def toplevel @toplevel end |
#virtiofsd ⇒ String (readonly)
Returns path to virtiofsd package.
132 133 134 |
# File 'lib/osvm/machine_config.rb', line 132 def virtiofsd @virtiofsd end |
Class Method Details
.load_file(path) ⇒ MachineConfig
Load machine config from file
120 121 122 123 |
# File 'lib/osvm/machine_config.rb', line 120 def self.load_file(path) cfg = JSON.parse(File.read(path), symbolize_names: true) new(cfg) end |