Class: VagrantPlugins::ProviderLibvirt::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Config
- Defined in:
- lib/vagrant-libvirt/config.rb
Instance Attribute Summary collapse
-
#autostart ⇒ Object
Autostart.
-
#boot_order ⇒ Object
Returns the value of attribute boot_order.
-
#cdroms ⇒ Object
Returns the value of attribute cdroms.
-
#channel(options = {}) ⇒ Object
Returns the value of attribute channel.
-
#channels ⇒ Object
Channels.
-
#cmd_line ⇒ Object
Returns the value of attribute cmd_line.
-
#connect_via_ssh ⇒ Object
If use ssh tunnel to connect to Libvirt.
-
#cpu_fallback ⇒ Object
Returns the value of attribute cpu_fallback.
-
#cpu_features ⇒ Object
Returns the value of attribute cpu_features.
-
#cpu_mode ⇒ Object
Returns the value of attribute cpu_mode.
-
#cpu_model ⇒ Object
Returns the value of attribute cpu_model.
-
#cpus ⇒ Object
Returns the value of attribute cpus.
-
#default_prefix ⇒ Object
Default host prefix (alternative to use project folder name).
-
#disk_bus ⇒ Object
Returns the value of attribute disk_bus.
-
#disk_device ⇒ Object
Returns the value of attribute disk_device.
-
#disks ⇒ Object
Storage.
-
#driver ⇒ Object
A hypervisor name to access via Libvirt.
-
#dtb ⇒ Object
Returns the value of attribute dtb.
-
#emulator_path ⇒ Object
Returns the value of attribute emulator_path.
-
#features ⇒ Object
Returns the value of attribute features.
-
#graphics_autoport ⇒ Object
Returns the value of attribute graphics_autoport.
-
#graphics_ip ⇒ Object
Returns the value of attribute graphics_ip.
-
#graphics_passwd ⇒ Object
Returns the value of attribute graphics_passwd.
-
#graphics_port ⇒ Object
Returns the value of attribute graphics_port.
-
#graphics_type ⇒ Object
Returns the value of attribute graphics_type.
-
#host ⇒ Object
The name of the server, where libvirtd is running.
-
#id_ssh_key_file ⇒ Object
ID SSH key file.
-
#initrd ⇒ Object
Returns the value of attribute initrd.
-
#inputs ⇒ Object
Inputs.
-
#kernel ⇒ Object
Returns the value of attribute kernel.
-
#keymap ⇒ Object
Returns the value of attribute keymap.
-
#kvm_hidden ⇒ Object
Returns the value of attribute kvm_hidden.
-
#loader ⇒ Object
Returns the value of attribute loader.
-
#machine_arch ⇒ Object
Returns the value of attribute machine_arch.
-
#machine_type ⇒ Object
Returns the value of attribute machine_type.
-
#machine_virtual_size ⇒ Object
Returns the value of attribute machine_virtual_size.
-
#management_network_address ⇒ Object
Returns the value of attribute management_network_address.
-
#management_network_autostart ⇒ Object
Returns the value of attribute management_network_autostart.
-
#management_network_guest_ipv6 ⇒ Object
Returns the value of attribute management_network_guest_ipv6.
-
#management_network_mac ⇒ Object
Returns the value of attribute management_network_mac.
-
#management_network_mode ⇒ Object
Returns the value of attribute management_network_mode.
-
#management_network_name ⇒ Object
Libvirt default network.
-
#memory ⇒ Object
Returns the value of attribute memory.
-
#mgmt_attach ⇒ Object
Attach mgmt network.
-
#nested ⇒ Object
Returns the value of attribute nested.
-
#nic_adapter_count ⇒ Object
Sets the max number of NICs that can be created Default set to 8.
-
#nic_model_type ⇒ Object
Returns the value of attribute nic_model_type.
-
#numa_nodes ⇒ Object
Returns the value of attribute numa_nodes.
-
#password ⇒ Object
Password for Libvirt connection.
-
#pcis ⇒ Object
PCI device passthrough.
-
#qemu_args ⇒ Object
Additional qemuargs arguments.
-
#random_hostname ⇒ Object
Turn on to prevent hostname conflicts.
-
#redirdevs ⇒ Object
Redirected devices.
-
#redirfilters ⇒ Object
Returns the value of attribute redirfilters.
-
#rng ⇒ Object
Random number device passthrough.
-
#smartcard_dev ⇒ Object
smartcard device.
-
#socket ⇒ Object
Path towards the libvirt socket.
-
#sound_type ⇒ Object
Returns the value of attribute sound_type.
-
#storage_pool_name ⇒ Object
Libvirt storage pool name, where box image and instance snapshots will be stored.
-
#suspend_mode ⇒ Object
Suspend mode.
-
#tpm_model ⇒ Object
Sets the information for connecting to a host TPM device Only supports socket-based TPMs.
-
#tpm_path ⇒ Object
Returns the value of attribute tpm_path.
-
#tpm_type ⇒ Object
Returns the value of attribute tpm_type.
-
#uri ⇒ Object
manually specify URI will supercede most other options if provided.
-
#usbs ⇒ Object
USB device passthrough.
-
#username ⇒ Object
The username to access Libvirt.
-
#uuid ⇒ Object
Domain specific settings used while creating new domain.
-
#video_type ⇒ Object
Returns the value of attribute video_type.
-
#video_vram ⇒ Object
Returns the value of attribute video_vram.
-
#volume_cache ⇒ Object
Returns the value of attribute volume_cache.
-
#watchdog_dev ⇒ Object
Watchdog device.
Instance Method Summary collapse
- #_generate_numa ⇒ Object
-
#_generate_uri ⇒ Object
code to generate URI from a config moved out of the connect action.
- #_get_cdrom_dev(cdroms) ⇒ Object
- #_get_device(disks) ⇒ Object
- #_handle_cdrom_storage(options = {}) ⇒ Object
- #_handle_disk_storage(options = {}) ⇒ Object
- #boot(device) ⇒ Object
- #cpu_feature(options = {}) ⇒ Object
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #input(options = {}) ⇒ Object
- #merge(other) ⇒ Object
- #pci(options = {}) ⇒ Object
- #qemuargs(options = {}) ⇒ Object
- #random(options = {}) ⇒ Object
- #redirdev(options = {}) ⇒ Object
- #redirfilter(options = {}) ⇒ Object
- #smartcard(options = {}) ⇒ Object
-
#storage(storage_type, options = {}) ⇒ Object
NOTE: this will run twice for each time it’s needed- keep it idempotent.
- #usb(options = {}) ⇒ Object
- #validate(machine) ⇒ Object
- #watchdog(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/vagrant-libvirt/config.rb', line 147 def initialize @uri = UNSET_VALUE @driver = UNSET_VALUE @host = UNSET_VALUE @connect_via_ssh = UNSET_VALUE @username = UNSET_VALUE @password = UNSET_VALUE @id_ssh_key_file = UNSET_VALUE @storage_pool_name = UNSET_VALUE @random_hostname = UNSET_VALUE @management_network_name = UNSET_VALUE @management_network_address = UNSET_VALUE @management_network_mode = UNSET_VALUE @management_network_mac = UNSET_VALUE @management_network_guest_ipv6 = UNSET_VALUE @management_network_autostart = UNSET_VALUE # Domain specific settings. @uuid = UNSET_VALUE @memory = UNSET_VALUE @cpus = UNSET_VALUE @cpu_mode = UNSET_VALUE @cpu_model = UNSET_VALUE @cpu_fallback = UNSET_VALUE @cpu_features = UNSET_VALUE @features = UNSET_VALUE @numa_nodes = UNSET_VALUE @loader = UNSET_VALUE @machine_type = UNSET_VALUE @machine_arch = UNSET_VALUE @machine_virtual_size = UNSET_VALUE @disk_bus = UNSET_VALUE @disk_device = UNSET_VALUE @nic_model_type = UNSET_VALUE @nested = UNSET_VALUE @volume_cache = UNSET_VALUE @kernel = UNSET_VALUE @initrd = UNSET_VALUE @dtb = UNSET_VALUE @cmd_line = UNSET_VALUE @emulator_path = UNSET_VALUE @graphics_type = UNSET_VALUE @graphics_autoport = UNSET_VALUE @graphics_port = UNSET_VALUE @graphics_ip = UNSET_VALUE @graphics_passwd = UNSET_VALUE @video_type = UNSET_VALUE @video_vram = UNSET_VALUE @sound_type = UNSET_VALUE @keymap = UNSET_VALUE @kvm_hidden = UNSET_VALUE @tpm_model = UNSET_VALUE @tpm_type = UNSET_VALUE @tpm_path = UNSET_VALUE @nic_adapter_count = UNSET_VALUE # Boot order @boot_order = [] # Storage @disks = [] @cdroms = [] # Inputs @inputs = UNSET_VALUE # Channels @channels = UNSET_VALUE # PCI device passthrough @pcis = UNSET_VALUE # Random number device passthrough @rng = UNSET_VALUE # Watchdog device @watchdog_dev = UNSET_VALUE # USB device passthrough @usbs = UNSET_VALUE # Redirected devices @redirdevs = UNSET_VALUE @redirfilters = UNSET_VALUE # smartcard device @smartcard_dev = UNSET_VALUE # Suspend mode @suspend_mode = UNSET_VALUE # Autostart @autostart = UNSET_VALUE # Attach mgmt network @mgmt_attach = UNSET_VALUE @qemu_args = [] end |
Instance Attribute Details
#autostart ⇒ Object
Autostart
139 140 141 |
# File 'lib/vagrant-libvirt/config.rb', line 139 def autostart @autostart end |
#boot_order ⇒ Object
Returns the value of attribute boot_order.
70 71 72 |
# File 'lib/vagrant-libvirt/config.rb', line 70 def boot_order @boot_order end |
#cdroms ⇒ Object
Returns the value of attribute cdroms.
108 109 110 |
# File 'lib/vagrant-libvirt/config.rb', line 108 def cdroms @cdroms end |
#channel(options = {}) ⇒ Object
Returns the value of attribute channel.
61 62 63 |
# File 'lib/vagrant-libvirt/config.rb', line 61 def channel @channel end |
#channels ⇒ Object
Channels
114 115 116 |
# File 'lib/vagrant-libvirt/config.rb', line 114 def channels @channels end |
#cmd_line ⇒ Object
Returns the value of attribute cmd_line.
80 81 82 |
# File 'lib/vagrant-libvirt/config.rb', line 80 def cmd_line @cmd_line end |
#connect_via_ssh ⇒ Object
If use ssh tunnel to connect to Libvirt.
27 28 29 |
# File 'lib/vagrant-libvirt/config.rb', line 27 def connect_via_ssh @connect_via_ssh end |
#cpu_fallback ⇒ Object
Returns the value of attribute cpu_fallback.
65 66 67 |
# File 'lib/vagrant-libvirt/config.rb', line 65 def cpu_fallback @cpu_fallback end |
#cpu_features ⇒ Object
Returns the value of attribute cpu_features.
66 67 68 |
# File 'lib/vagrant-libvirt/config.rb', line 66 def cpu_features @cpu_features end |
#cpu_mode ⇒ Object
Returns the value of attribute cpu_mode.
63 64 65 |
# File 'lib/vagrant-libvirt/config.rb', line 63 def cpu_mode @cpu_mode end |
#cpu_model ⇒ Object
Returns the value of attribute cpu_model.
64 65 66 |
# File 'lib/vagrant-libvirt/config.rb', line 64 def cpu_model @cpu_model end |
#cpus ⇒ Object
Returns the value of attribute cpus.
62 63 64 |
# File 'lib/vagrant-libvirt/config.rb', line 62 def cpus @cpus end |
#default_prefix ⇒ Object
Default host prefix (alternative to use project folder name)
56 57 58 |
# File 'lib/vagrant-libvirt/config.rb', line 56 def default_prefix @default_prefix end |
#disk_bus ⇒ Object
Returns the value of attribute disk_bus.
74 75 76 |
# File 'lib/vagrant-libvirt/config.rb', line 74 def disk_bus @disk_bus end |
#disk_device ⇒ Object
Returns the value of attribute disk_device.
75 76 77 |
# File 'lib/vagrant-libvirt/config.rb', line 75 def disk_device @disk_device end |
#disks ⇒ Object
Storage
107 108 109 |
# File 'lib/vagrant-libvirt/config.rb', line 107 def disks @disks end |
#driver ⇒ Object
A hypervisor name to access via Libvirt.
21 22 23 |
# File 'lib/vagrant-libvirt/config.rb', line 21 def driver @driver end |
#dtb ⇒ Object
Returns the value of attribute dtb.
82 83 84 |
# File 'lib/vagrant-libvirt/config.rb', line 82 def dtb @dtb end |
#emulator_path ⇒ Object
Returns the value of attribute emulator_path.
83 84 85 |
# File 'lib/vagrant-libvirt/config.rb', line 83 def emulator_path @emulator_path end |
#features ⇒ Object
Returns the value of attribute features.
67 68 69 |
# File 'lib/vagrant-libvirt/config.rb', line 67 def features @features end |
#graphics_autoport ⇒ Object
Returns the value of attribute graphics_autoport.
85 86 87 |
# File 'lib/vagrant-libvirt/config.rb', line 85 def graphics_autoport @graphics_autoport end |
#graphics_ip ⇒ Object
Returns the value of attribute graphics_ip.
88 89 90 |
# File 'lib/vagrant-libvirt/config.rb', line 88 def graphics_ip @graphics_ip end |
#graphics_passwd ⇒ Object
Returns the value of attribute graphics_passwd.
87 88 89 |
# File 'lib/vagrant-libvirt/config.rb', line 87 def graphics_passwd @graphics_passwd end |
#graphics_port ⇒ Object
Returns the value of attribute graphics_port.
86 87 88 |
# File 'lib/vagrant-libvirt/config.rb', line 86 def graphics_port @graphics_port end |
#graphics_type ⇒ Object
Returns the value of attribute graphics_type.
84 85 86 |
# File 'lib/vagrant-libvirt/config.rb', line 84 def graphics_type @graphics_type end |
#host ⇒ Object
The name of the server, where libvirtd is running.
24 25 26 |
# File 'lib/vagrant-libvirt/config.rb', line 24 def host @host end |
#id_ssh_key_file ⇒ Object
ID SSH key file
38 39 40 |
# File 'lib/vagrant-libvirt/config.rb', line 38 def id_ssh_key_file @id_ssh_key_file end |
#initrd ⇒ Object
Returns the value of attribute initrd.
81 82 83 |
# File 'lib/vagrant-libvirt/config.rb', line 81 def initrd @initrd end |
#inputs ⇒ Object
Inputs
111 112 113 |
# File 'lib/vagrant-libvirt/config.rb', line 111 def inputs @inputs end |
#kernel ⇒ Object
Returns the value of attribute kernel.
79 80 81 |
# File 'lib/vagrant-libvirt/config.rb', line 79 def kernel @kernel end |
#keymap ⇒ Object
Returns the value of attribute keymap.
91 92 93 |
# File 'lib/vagrant-libvirt/config.rb', line 91 def keymap @keymap end |
#kvm_hidden ⇒ Object
Returns the value of attribute kvm_hidden.
92 93 94 |
# File 'lib/vagrant-libvirt/config.rb', line 92 def kvm_hidden @kvm_hidden end |
#loader ⇒ Object
Returns the value of attribute loader.
69 70 71 |
# File 'lib/vagrant-libvirt/config.rb', line 69 def loader @loader end |
#machine_arch ⇒ Object
Returns the value of attribute machine_arch.
72 73 74 |
# File 'lib/vagrant-libvirt/config.rb', line 72 def machine_arch @machine_arch end |
#machine_type ⇒ Object
Returns the value of attribute machine_type.
71 72 73 |
# File 'lib/vagrant-libvirt/config.rb', line 71 def machine_type @machine_type end |
#machine_virtual_size ⇒ Object
Returns the value of attribute machine_virtual_size.
73 74 75 |
# File 'lib/vagrant-libvirt/config.rb', line 73 def machine_virtual_size @machine_virtual_size end |
#management_network_address ⇒ Object
Returns the value of attribute management_network_address.
49 50 51 |
# File 'lib/vagrant-libvirt/config.rb', line 49 def management_network_address @management_network_address end |
#management_network_autostart ⇒ Object
Returns the value of attribute management_network_autostart.
53 54 55 |
# File 'lib/vagrant-libvirt/config.rb', line 53 def management_network_autostart @management_network_autostart end |
#management_network_guest_ipv6 ⇒ Object
Returns the value of attribute management_network_guest_ipv6.
52 53 54 |
# File 'lib/vagrant-libvirt/config.rb', line 52 def management_network_guest_ipv6 @management_network_guest_ipv6 end |
#management_network_mac ⇒ Object
Returns the value of attribute management_network_mac.
51 52 53 |
# File 'lib/vagrant-libvirt/config.rb', line 51 def management_network_mac @management_network_mac end |
#management_network_mode ⇒ Object
Returns the value of attribute management_network_mode.
50 51 52 |
# File 'lib/vagrant-libvirt/config.rb', line 50 def management_network_mode @management_network_mode end |
#management_network_name ⇒ Object
Libvirt default network
48 49 50 |
# File 'lib/vagrant-libvirt/config.rb', line 48 def management_network_name @management_network_name end |
#memory ⇒ Object
Returns the value of attribute memory.
60 61 62 |
# File 'lib/vagrant-libvirt/config.rb', line 60 def memory @memory end |
#mgmt_attach ⇒ Object
Attach mgmt network
142 143 144 |
# File 'lib/vagrant-libvirt/config.rb', line 142 def mgmt_attach @mgmt_attach end |
#nested ⇒ Object
Returns the value of attribute nested.
77 78 79 |
# File 'lib/vagrant-libvirt/config.rb', line 77 def nested @nested end |
#nic_adapter_count ⇒ Object
Sets the max number of NICs that can be created Default set to 8. Don’t change the default unless you know what are doing
104 105 106 |
# File 'lib/vagrant-libvirt/config.rb', line 104 def nic_adapter_count @nic_adapter_count end |
#nic_model_type ⇒ Object
Returns the value of attribute nic_model_type.
76 77 78 |
# File 'lib/vagrant-libvirt/config.rb', line 76 def nic_model_type @nic_model_type end |
#numa_nodes ⇒ Object
Returns the value of attribute numa_nodes.
68 69 70 |
# File 'lib/vagrant-libvirt/config.rb', line 68 def numa_nodes @numa_nodes end |
#password ⇒ Object
Password for Libvirt connection.
35 36 37 |
# File 'lib/vagrant-libvirt/config.rb', line 35 def password @password end |
#pcis ⇒ Object
PCI device passthrough
117 118 119 |
# File 'lib/vagrant-libvirt/config.rb', line 117 def pcis @pcis end |
#qemu_args ⇒ Object
Additional qemuargs arguments
145 146 147 |
# File 'lib/vagrant-libvirt/config.rb', line 145 def qemu_args @qemu_args end |
#random_hostname ⇒ Object
Turn on to prevent hostname conflicts
45 46 47 |
# File 'lib/vagrant-libvirt/config.rb', line 45 def random_hostname @random_hostname end |
#redirdevs ⇒ Object
Redirected devices
129 130 131 |
# File 'lib/vagrant-libvirt/config.rb', line 129 def redirdevs @redirdevs end |
#redirfilters ⇒ Object
Returns the value of attribute redirfilters.
130 131 132 |
# File 'lib/vagrant-libvirt/config.rb', line 130 def redirfilters @redirfilters end |
#rng ⇒ Object
Random number device passthrough
120 121 122 |
# File 'lib/vagrant-libvirt/config.rb', line 120 def rng @rng end |
#smartcard_dev ⇒ Object
smartcard device
133 134 135 |
# File 'lib/vagrant-libvirt/config.rb', line 133 def smartcard_dev @smartcard_dev end |
#socket ⇒ Object
Path towards the libvirt socket
29 30 31 |
# File 'lib/vagrant-libvirt/config.rb', line 29 def socket @socket end |
#sound_type ⇒ Object
Returns the value of attribute sound_type.
93 94 95 |
# File 'lib/vagrant-libvirt/config.rb', line 93 def sound_type @sound_type end |
#storage_pool_name ⇒ Object
Libvirt storage pool name, where box image and instance snapshots will be stored.
42 43 44 |
# File 'lib/vagrant-libvirt/config.rb', line 42 def storage_pool_name @storage_pool_name end |
#suspend_mode ⇒ Object
Suspend mode
136 137 138 |
# File 'lib/vagrant-libvirt/config.rb', line 136 def suspend_mode @suspend_mode end |
#tpm_model ⇒ Object
Sets the information for connecting to a host TPM device Only supports socket-based TPMs
97 98 99 |
# File 'lib/vagrant-libvirt/config.rb', line 97 def tpm_model @tpm_model end |
#tpm_path ⇒ Object
Returns the value of attribute tpm_path.
99 100 101 |
# File 'lib/vagrant-libvirt/config.rb', line 99 def tpm_path @tpm_path end |
#tpm_type ⇒ Object
Returns the value of attribute tpm_type.
98 99 100 |
# File 'lib/vagrant-libvirt/config.rb', line 98 def tpm_type @tpm_type end |
#uri ⇒ Object
manually specify URI will supercede most other options if provided
18 19 20 |
# File 'lib/vagrant-libvirt/config.rb', line 18 def uri @uri end |
#usbs ⇒ Object
USB device passthrough
126 127 128 |
# File 'lib/vagrant-libvirt/config.rb', line 126 def usbs @usbs end |
#username ⇒ Object
The username to access Libvirt.
32 33 34 |
# File 'lib/vagrant-libvirt/config.rb', line 32 def username @username end |
#uuid ⇒ Object
Domain specific settings used while creating new domain.
59 60 61 |
# File 'lib/vagrant-libvirt/config.rb', line 59 def uuid @uuid end |
#video_type ⇒ Object
Returns the value of attribute video_type.
89 90 91 |
# File 'lib/vagrant-libvirt/config.rb', line 89 def video_type @video_type end |
#video_vram ⇒ Object
Returns the value of attribute video_vram.
90 91 92 |
# File 'lib/vagrant-libvirt/config.rb', line 90 def video_vram @video_vram end |
#volume_cache ⇒ Object
Returns the value of attribute volume_cache.
78 79 80 |
# File 'lib/vagrant-libvirt/config.rb', line 78 def volume_cache @volume_cache end |
#watchdog_dev ⇒ Object
Watchdog device
123 124 125 |
# File 'lib/vagrant-libvirt/config.rb', line 123 def watchdog_dev @watchdog_dev end |
Instance Method Details
#_generate_numa ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/vagrant-libvirt/config.rb', line 281 def _generate_numa raise 'NUMA nodes must be a factor of CPUs' if @cpus % @numa_nodes != 0 if @memory % @numa_nodes != 0 raise 'NUMA nodes must be a factor of memory' end numa = [] (1..@numa_nodes).each do |node| numa_cpu_start = (@cpus / @numa_nodes) * (node - 1) numa_cpu_end = (@cpus / @numa_nodes) * node - 1 numa_cpu = Array(numa_cpu_start..numa_cpu_end).join(',') numa_mem = @memory / @numa_nodes numa.push(id: node, cpu: numa_cpu, mem: numa_mem) end @numa_nodes = numa end |
#_generate_uri ⇒ Object
code to generate URI from a config moved out of the connect action
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'lib/vagrant-libvirt/config.rb', line 502 def _generate_uri # builds the libvirt connection URI from the given driver config # Setup connection uri. uri = @driver.dup virt_path = case uri when 'qemu', 'openvz', 'uml', 'phyp', 'parallels', 'kvm' '/system' when '@en', 'esx' '/' when 'vbox', 'vmwarews', 'hyperv' '/session' else raise "Require specify driver #{uri}" end if uri == 'kvm' uri = 'qemu' # use qemu uri for kvm domain type end if @connect_via_ssh uri << '+ssh://' uri << @username + '@' if @username uri << if @host @host else 'localhost' end else uri << '://' uri << @host if @host end uri << virt_path uri << '?no_verify=1' if @id_ssh_key_file # set ssh key for access to libvirt host uri << "\&keyfile=" # if no slash, prepend $HOME/.ssh/ @id_ssh_key_file.prepend("#{`echo ${HOME}`.chomp}/.ssh/") if @id_ssh_key_file !~ /\A\// uri << @id_ssh_key_file end # set path to libvirt socket uri << "\&socket=" + @socket if @socket uri end |
#_get_cdrom_dev(cdroms) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/vagrant-libvirt/config.rb', line 263 def _get_cdrom_dev(cdroms) exist = Hash[cdroms.collect { |x| [x[:dev], true] }] # hda - hdc curr = 'a'.ord while curr <= 'd'.ord dev = 'hd' + curr.chr if exist[dev] curr += 1 next else return dev end end # is it better to raise our own error, or let libvirt cause the exception? raise 'Only four cdroms may be attached at a time' end |
#_get_device(disks) ⇒ Object
252 253 254 255 256 257 258 259 260 261 |
# File 'lib/vagrant-libvirt/config.rb', line 252 def _get_device(disks) # skip existing devices and also the first one (vda) exist = disks.collect { |x| x[:device] } + [1.vdev.to_s] skip = 1 # we're 1 based, not 0 based... loop do dev = skip.vdev # get lettered device return dev unless exist.include?(dev) skip += 1 end end |
#_handle_cdrom_storage(options = {}) ⇒ Object
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/vagrant-libvirt/config.rb', line 449 def _handle_cdrom_storage( = {}) # <disk type="file" device="cdrom"> # <source file="/home/user/virtio-win-0.1-100.iso"/> # <target dev="hdc"/> # <readonly/> # <address type='drive' controller='0' bus='1' target='0' unit='0'/> # </disk> # # note the target dev will need to be changed with each cdrom drive (hdc, hdd, etc), # as will the address unit number (unit=0, unit=1, etc) = { bus: 'ide', path: nil }.merge() cdrom = { dev: [:dev], bus: [:bus], path: [:path] } @cdroms << cdrom end |
#_handle_disk_storage(options = {}) ⇒ Object
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/vagrant-libvirt/config.rb', line 474 def _handle_disk_storage( = {}) = { type: 'qcow2', size: '10G', # matches the fog default path: nil, bus: 'virtio' }.merge() disk = { device: [:device], type: [:type], size: [:size], path: [:path], bus: [:bus], cache: [:cache] || 'default', allow_existing: [:allow_existing], shareable: [:shareable], serial: [:serial] } @disks << disk # append end |
#boot(device) ⇒ Object
248 249 250 |
# File 'lib/vagrant-libvirt/config.rb', line 248 def boot(device) @boot_order << device # append end |
#cpu_feature(options = {}) ⇒ Object
304 305 306 307 308 309 310 311 312 313 |
# File 'lib/vagrant-libvirt/config.rb', line 304 def cpu_feature( = {}) if [:name].nil? || [:policy].nil? raise 'CPU Feature name AND policy must be specified' end @cpu_features = [] if @cpu_features == UNSET_VALUE @cpu_features.push(name: [:name], policy: [:policy]) end |
#finalize! ⇒ Object
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
# File 'lib/vagrant-libvirt/config.rb', line 549 def finalize! @driver = 'kvm' if @driver == UNSET_VALUE @host = nil if @host == UNSET_VALUE @connect_via_ssh = false if @connect_via_ssh == UNSET_VALUE @username = nil if @username == UNSET_VALUE @password = nil if @password == UNSET_VALUE @id_ssh_key_file = 'id_rsa' if @id_ssh_key_file == UNSET_VALUE @storage_pool_name = 'default' if @storage_pool_name == UNSET_VALUE @random_hostname = false if @random_hostname == UNSET_VALUE @management_network_name = 'vagrant-libvirt' if @management_network_name == UNSET_VALUE @management_network_address = '192.168.121.0/24' if @management_network_address == UNSET_VALUE @management_network_mode = 'nat' if @management_network_mode == UNSET_VALUE @management_network_mac = nil if @management_network_mac == UNSET_VALUE @management_network_guest_ipv6 = 'yes' if @management_network_guest_ipv6 == UNSET_VALUE @management_network_autostart = false if @management_network_autostart == UNSET_VALUE # generate a URI if none is supplied @uri = _generate_uri if @uri == UNSET_VALUE # Domain specific settings. @uuid = '' if @uuid == UNSET_VALUE @memory = 512 if @memory == UNSET_VALUE @cpus = 1 if @cpus == UNSET_VALUE @cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE @cpu_model = if (@cpu_model == UNSET_VALUE) && (@cpu_mode == 'custom') 'qemu64' elsif @cpu_mode != 'custom' '' end @cpu_fallback = 'allow' if @cpu_fallback == UNSET_VALUE @cpu_features = [] if @cpu_features == UNSET_VALUE @features = ['acpi','apic','pae'] if @features == UNSET_VALUE @numa_nodes = @numa_nodes == UNSET_VALUE ? nil : _generate_numa @loader = nil if @loader == UNSET_VALUE @machine_type = nil if @machine_type == UNSET_VALUE @machine_arch = nil if @machine_arch == UNSET_VALUE @machine_virtual_size = nil if @machine_virtual_size == UNSET_VALUE @disk_bus = 'virtio' if @disk_bus == UNSET_VALUE @disk_device = 'vda' if @disk_device == UNSET_VALUE @nic_model_type = nil if @nic_model_type == UNSET_VALUE @nested = false if @nested == UNSET_VALUE @volume_cache = 'default' if @volume_cache == UNSET_VALUE @kernel = nil if @kernel == UNSET_VALUE @cmd_line = '' if @cmd_line == UNSET_VALUE @initrd = '' if @initrd == UNSET_VALUE @dtb = nil if @dtb == UNSET_VALUE @graphics_type = 'vnc' if @graphics_type == UNSET_VALUE @graphics_autoport = 'yes' if @graphics_port == UNSET_VALUE @graphics_autoport = 'no' if @graphics_port != UNSET_VALUE if (@graphics_type != 'vnc' && @graphics_type != 'spice') || @graphics_passwd == UNSET_VALUE @graphics_passwd = nil end @graphics_port = 5900 if @graphics_port == UNSET_VALUE @graphics_ip = '127.0.0.1' if @graphics_ip == UNSET_VALUE @video_type = 'cirrus' if @video_type == UNSET_VALUE @video_vram = 9216 if @video_vram == UNSET_VALUE @sound_type = nil if @sound_type == UNSET_VALUE @keymap = 'en-us' if @keymap == UNSET_VALUE @kvm_hidden = false if @kvm_hidden == UNSET_VALUE @tpm_model = 'tpm-tis' if @tpm_model == UNSET_VALUE @tpm_type = 'passthrough' if @tpm_type == UNSET_VALUE @tpm_path = nil if @tpm_path == UNSET_VALUE @nic_adapter_count = 8 if @nic_adapter_count == UNSET_VALUE @emulator_path = nil if @emulator_path == UNSET_VALUE # Boot order @boot_order = [] if @boot_order == UNSET_VALUE # Storage @disks = [] if @disks == UNSET_VALUE @disks.map! do |disk| disk[:device] = _get_device(@disks) if disk[:device].nil? disk end @cdroms = [] if @cdroms == UNSET_VALUE @cdroms.map! do |cdrom| cdrom[:dev] = _get_cdrom_dev(@cdroms) if cdrom[:dev].nil? cdrom end # Inputs @inputs = [{ type: 'mouse', bus: 'ps2' }] if @inputs == UNSET_VALUE # Channels @channels = [] if @channels == UNSET_VALUE # PCI device passthrough @pcis = [] if @pcis == UNSET_VALUE # Random number generator passthrough @rng = {} if @rng == UNSET_VALUE # Watchdog device @watchdog_dev = {} if @watchdog_dev == UNSET_VALUE # USB device passthrough @usbs = [] if @usbs == UNSET_VALUE # Redirected devices @redirdevs = [] if @redirdevs == UNSET_VALUE @redirfilters = [] if @redirfilters == UNSET_VALUE # smartcard device @smartcard_dev = {} if @smartcard_dev == UNSET_VALUE # Suspend mode @suspend_mode = 'pause' if @suspend_mode == UNSET_VALUE # Autostart @autostart = false if @autostart == UNSET_VALUE # Attach mgmt network @mgmt_attach = true if @mgmt_attach == UNSET_VALUE @qemu_args = [] if @qemu_args == UNSET_VALUE end |
#input(options = {}) ⇒ Object
315 316 317 318 319 320 321 322 323 324 |
# File 'lib/vagrant-libvirt/config.rb', line 315 def input( = {}) if [:type].nil? || [:bus].nil? raise 'Input type AND bus must be specified' end @inputs = [] if @inputs == UNSET_VALUE @inputs.push(type: [:type], bus: [:bus]) end |
#merge(other) ⇒ Object
685 686 687 688 689 690 691 692 693 694 695 |
# File 'lib/vagrant-libvirt/config.rb', line 685 def merge(other) super.tap do |result| c = disks.dup c += other.disks result.disks = c c = cdroms.dup c += other.cdroms result.cdroms = c end end |
#pci(options = {}) ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/vagrant-libvirt/config.rb', line 358 def pci( = {}) if [:bus].nil? || [:slot].nil? || [:function].nil? raise 'Bus AND slot AND function must be specified. Check `lspci` for that numbers.' end @pcis = [] if @pcis == UNSET_VALUE @pcis.push(bus: [:bus], slot: [:slot], function: [:function]) end |
#qemuargs(options = {}) ⇒ Object
497 498 499 |
# File 'lib/vagrant-libvirt/config.rb', line 497 def qemuargs( = {}) @qemu_args << if [:value] end |
#random(options = {}) ⇒ Object
348 349 350 351 352 353 354 355 356 |
# File 'lib/vagrant-libvirt/config.rb', line 348 def random( = {}) if ![:model].nil? && [:model] != 'random' raise 'The only supported rng backend is "random".' end @rng = {} if @rng == UNSET_VALUE @rng[:model] = [:model] end |
#redirdev(options = {}) ⇒ Object
398 399 400 401 402 403 404 |
# File 'lib/vagrant-libvirt/config.rb', line 398 def redirdev( = {}) raise 'Type must be specified.' if [:type].nil? @redirdevs = [] if @redirdevs == UNSET_VALUE @redirdevs.push(type: [:type]) end |
#redirfilter(options = {}) ⇒ Object
406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/vagrant-libvirt/config.rb', line 406 def redirfilter( = {}) raise 'Option allow must be specified.' if [:allow].nil? @redirfilters = [] if @redirfilters == UNSET_VALUE @redirfilters.push(class: [:class] || -1, vendor: [:class] || -1, product: [:class] || -1, version: [:class] || -1, allow: [:allow]) end |
#smartcard(options = {}) ⇒ Object
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/vagrant-libvirt/config.rb', line 418 def smartcard( = {}) if [:mode].nil? raise 'Option mode must be specified.' elsif [:mode] != 'passthrough' raise 'Currently only passthrough mode is supported!' elsif [:type] == 'tcp' && ([:source_mode].nil? || [:source_host].nil? || [:source_service].nil?) raise 'If using type "tcp", option "source_mode", "source_host" and "source_service" must be specified.' end if @smartcard_dev == UNSET_VALUE @smartcard_dev = {} end @smartcard_dev[:mode] = [:mode] @smartcard_dev[:type] = [:type] || 'spicevmc' @smartcard_dev[:source_mode] = [:source_mode] if @smartcard_dev[:type] == 'tcp' @smartcard_dev[:source_host] = [:source_host] if @smartcard_dev[:type] == 'tcp' @smartcard_dev[:source_service] = [:source_service] if @smartcard_dev[:type] == 'tcp' end |
#storage(storage_type, options = {}) ⇒ Object
NOTE: this will run twice for each time it’s needed- keep it idempotent
439 440 441 442 443 444 445 446 447 |
# File 'lib/vagrant-libvirt/config.rb', line 439 def storage(storage_type, = {}) if storage_type == :file if [:device] == :cdrom _handle_cdrom_storage() else _handle_disk_storage() end end end |
#usb(options = {}) ⇒ Object
384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/vagrant-libvirt/config.rb', line 384 def usb( = {}) if ([:bus].nil? || [:device].nil?) && [:vendor].nil? && [:product].nil? raise 'Bus and device and/or vendor and/or product must be specified. Check `lsusb` for these.' end @usbs = [] if @usbs == UNSET_VALUE @usbs.push(bus: [:bus], device: [:device], vendor: [:vendor], product: [:product], startupPolicy: [:startupPolicy]) end |
#validate(machine) ⇒ Object
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'lib/vagrant-libvirt/config.rb', line 667 def validate(machine) errors = _detected_errors machine.provider_config.disks.each do |disk| if disk[:path] && (disk[:path][0] == '/') errors << "absolute volume paths like '#{disk[:path]}' not yet supported" end end machine.config.vm.networks.each do |_type, opts| if opts[:mac] && opts[:mac].downcase! && !(opts[:mac] =~ /\A([0-9a-f]{2}:){5}([0-9a-f]{2})\z/) errors << "Configured NIC MAC '#{opts[:mac]}' is not in 'xx:xx:xx:xx:xx:xx' format" end end { 'Libvirt Provider' => errors } end |
#watchdog(options = {}) ⇒ Object
370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/vagrant-libvirt/config.rb', line 370 def watchdog( = {}) if [:model].nil? raise 'Model must be specified.' end if @watchdog_dev == UNSET_VALUE @watchdog_dev = {} end @watchdog_dev[:model] = [:model] @watchdog_dev[:action] = [:action] || 'reset' end |