Class: VagrantPlugins::ProviderLibvirt::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Config
- Defined in:
- lib/vagrant-libvirt/config.rb
Instance Attribute Summary collapse
-
#cmd_line ⇒ Object
Returns the value of attribute cmd_line.
-
#connect_via_ssh ⇒ Object
If use ssh tunnel to connect to Libvirt.
-
#cpu_mode ⇒ Object
Returns the value of attribute cpu_mode.
-
#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.
-
#disks ⇒ Object
Storage.
-
#driver ⇒ Object
A hypervisor name to access via Libvirt.
-
#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.
-
#kernel ⇒ Object
Returns the value of attribute kernel.
-
#management_network_address ⇒ Object
Returns the value of attribute management_network_address.
-
#management_network_name ⇒ Object
Libvirt default network.
-
#memory ⇒ Object
Domain specific settings used while creating new domain.
-
#nested ⇒ Object
Returns the value of attribute nested.
-
#password ⇒ Object
Password for Libvirt connection.
-
#socket ⇒ Object
Path towards the libvirt socket.
-
#storage_pool_name ⇒ Object
Libvirt storage pool name, where box image and instance snapshots will be stored.
-
#uri ⇒ Object
manually specify URI will supercede most other options if provided.
-
#username ⇒ Object
The username to access Libvirt.
-
#volume_cache ⇒ Object
Returns the value of attribute volume_cache.
Instance Method Summary collapse
-
#_generate_uri ⇒ Object
code to generate URI from a config moved out of the connect action.
- #_get_device(disks) ⇒ Object
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#storage(storage_type, options = {}) ⇒ Object
NOTE: this will run twice for each time it’s needed- keep it idempotent.
- #validate(machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/vagrant-libvirt/config.rb', line 64 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 @management_network_name = UNSET_VALUE @management_network_address = UNSET_VALUE # Domain specific settings. @memory = UNSET_VALUE @cpus = UNSET_VALUE @cpu_mode = UNSET_VALUE @disk_bus = UNSET_VALUE @nested = UNSET_VALUE @volume_cache = UNSET_VALUE @kernel = UNSET_VALUE @initrd = UNSET_VALUE @cmd_line = UNSET_VALUE # Storage @disks = UNSET_VALUE end |
Instance Attribute Details
#cmd_line ⇒ Object
Returns the value of attribute cmd_line.
58 59 60 |
# File 'lib/vagrant-libvirt/config.rb', line 58 def cmd_line @cmd_line end |
#connect_via_ssh ⇒ Object
If use ssh tunnel to connect to Libvirt.
26 27 28 |
# File 'lib/vagrant-libvirt/config.rb', line 26 def connect_via_ssh @connect_via_ssh end |
#cpu_mode ⇒ Object
Returns the value of attribute cpu_mode.
53 54 55 |
# File 'lib/vagrant-libvirt/config.rb', line 53 def cpu_mode @cpu_mode end |
#cpus ⇒ Object
Returns the value of attribute cpus.
52 53 54 |
# File 'lib/vagrant-libvirt/config.rb', line 52 def cpus @cpus end |
#default_prefix ⇒ Object
Default host prefix (alternative to use project folder name)
48 49 50 |
# File 'lib/vagrant-libvirt/config.rb', line 48 def default_prefix @default_prefix end |
#disk_bus ⇒ Object
Returns the value of attribute disk_bus.
54 55 56 |
# File 'lib/vagrant-libvirt/config.rb', line 54 def disk_bus @disk_bus end |
#disks ⇒ Object
Storage
62 63 64 |
# File 'lib/vagrant-libvirt/config.rb', line 62 def disks @disks end |
#driver ⇒ Object
A hypervisor name to access via Libvirt.
20 21 22 |
# File 'lib/vagrant-libvirt/config.rb', line 20 def driver @driver end |
#host ⇒ Object
The name of the server, where libvirtd is running.
23 24 25 |
# File 'lib/vagrant-libvirt/config.rb', line 23 def host @host end |
#id_ssh_key_file ⇒ Object
ID SSH key file
37 38 39 |
# File 'lib/vagrant-libvirt/config.rb', line 37 def id_ssh_key_file @id_ssh_key_file end |
#initrd ⇒ Object
Returns the value of attribute initrd.
59 60 61 |
# File 'lib/vagrant-libvirt/config.rb', line 59 def initrd @initrd end |
#kernel ⇒ Object
Returns the value of attribute kernel.
57 58 59 |
# File 'lib/vagrant-libvirt/config.rb', line 57 def kernel @kernel end |
#management_network_address ⇒ Object
Returns the value of attribute management_network_address.
45 46 47 |
# File 'lib/vagrant-libvirt/config.rb', line 45 def management_network_address @management_network_address end |
#management_network_name ⇒ Object
Libvirt default network
44 45 46 |
# File 'lib/vagrant-libvirt/config.rb', line 44 def management_network_name @management_network_name end |
#memory ⇒ Object
Domain specific settings used while creating new domain.
51 52 53 |
# File 'lib/vagrant-libvirt/config.rb', line 51 def memory @memory end |
#nested ⇒ Object
Returns the value of attribute nested.
55 56 57 |
# File 'lib/vagrant-libvirt/config.rb', line 55 def nested @nested end |
#password ⇒ Object
Password for Libvirt connection.
34 35 36 |
# File 'lib/vagrant-libvirt/config.rb', line 34 def password @password end |
#socket ⇒ Object
Path towards the libvirt socket
28 29 30 |
# File 'lib/vagrant-libvirt/config.rb', line 28 def socket @socket end |
#storage_pool_name ⇒ Object
Libvirt storage pool name, where box image and instance snapshots will be stored.
41 42 43 |
# File 'lib/vagrant-libvirt/config.rb', line 41 def storage_pool_name @storage_pool_name end |
#uri ⇒ Object
manually specify URI will supercede most other options if provided
17 18 19 |
# File 'lib/vagrant-libvirt/config.rb', line 17 def uri @uri end |
#username ⇒ Object
The username to access Libvirt.
31 32 33 |
# File 'lib/vagrant-libvirt/config.rb', line 31 def username @username end |
#volume_cache ⇒ Object
Returns the value of attribute volume_cache.
56 57 58 |
# File 'lib/vagrant-libvirt/config.rb', line 56 def volume_cache @volume_cache end |
Instance Method Details
#_generate_uri ⇒ Object
code to generate URI from a config moved out of the connect action
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 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 |
# File 'lib/vagrant-libvirt/config.rb', line 130 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://' if @username uri << @username + '@' end if @host uri << @host else uri << '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 home_dir = `echo ${HOME}`.chomp uri << "\&keyfile=#{home_dir}/.ssh/"+@id_ssh_key_file end # set path to libvirt socket uri << "\&socket="+@socket if @socket return uri end |
#_get_device(disks) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/vagrant-libvirt/config.rb', line 91 def _get_device(disks) disks = [] if disks == UNSET_VALUE # 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... while true do dev = skip.vdev # get lettered device if !exist.include?(dev) return dev end skip+=1 end end |
#finalize! ⇒ Object
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 |
# File 'lib/vagrant-libvirt/config.rb', line 177 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 @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 # generate a URI if none is supplied @uri = _generate_uri() if @uri == UNSET_VALUE # Domain specific settings. @memory = 512 if @memory == UNSET_VALUE @cpus = 1 if @cpus == UNSET_VALUE @cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE @disk_bus = 'virtio' if @disk_bus == 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 # Storage @disks = [] if @disks == UNSET_VALUE end |
#storage(storage_type, options = {}) ⇒ Object
NOTE: this will run twice for each time it’s needed- keep it idempotent
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/vagrant-libvirt/config.rb', line 106 def storage(storage_type, ={}) = { :device => _get_device(@disks), :type => 'qcow2', :size => '10G', # matches the fog default :path => nil, }.merge() #puts "storage(#{storage_type} --- #{options.to_s})" @disks = [] if @disks == UNSET_VALUE disk = { :device => [:device], :type => [:type], :size => [:size], :path => [:path], } if storage_type == :file @disks << disk # append end end |
#validate(machine) ⇒ Object
206 207 |
# File 'lib/vagrant-libvirt/config.rb', line 206 def validate(machine) end |