vagrant-libvirt 0.0.36 → 0.0.37

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/Gemfile +1 -0
  4. data/README.md +171 -13
  5. data/lib/vagrant-libvirt/action/create_domain.rb +44 -19
  6. data/lib/vagrant-libvirt/action/create_domain_volume.rb +12 -12
  7. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +37 -39
  8. data/lib/vagrant-libvirt/action/create_networks.rb +34 -34
  9. data/lib/vagrant-libvirt/action/destroy_domain.rb +7 -8
  10. data/lib/vagrant-libvirt/action/destroy_networks.rb +12 -13
  11. data/lib/vagrant-libvirt/action/forward_ports.rb +21 -23
  12. data/lib/vagrant-libvirt/action/halt_domain.rb +8 -9
  13. data/lib/vagrant-libvirt/action/handle_box_image.rb +28 -27
  14. data/lib/vagrant-libvirt/action/handle_storage_pool.rb +8 -8
  15. data/lib/vagrant-libvirt/action/is_created.rb +1 -1
  16. data/lib/vagrant-libvirt/action/is_running.rb +2 -2
  17. data/lib/vagrant-libvirt/action/is_suspended.rb +4 -4
  18. data/lib/vagrant-libvirt/action/message_already_created.rb +2 -2
  19. data/lib/vagrant-libvirt/action/message_not_created.rb +2 -2
  20. data/lib/vagrant-libvirt/action/message_not_running.rb +2 -2
  21. data/lib/vagrant-libvirt/action/message_not_suspended.rb +2 -2
  22. data/lib/vagrant-libvirt/action/package_domain.rb +6 -5
  23. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +7 -6
  24. data/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb +2 -2
  25. data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +3 -3
  26. data/lib/vagrant-libvirt/action/read_mac_addresses.rb +8 -10
  27. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +4 -4
  28. data/lib/vagrant-libvirt/action/remove_stale_volume.rb +8 -7
  29. data/lib/vagrant-libvirt/action/resume_domain.rb +5 -5
  30. data/lib/vagrant-libvirt/action/set_boot_order.rb +70 -27
  31. data/lib/vagrant-libvirt/action/set_name_of_domain.rb +10 -12
  32. data/lib/vagrant-libvirt/action/share_folders.rb +16 -18
  33. data/lib/vagrant-libvirt/action/start_domain.rb +59 -64
  34. data/lib/vagrant-libvirt/action/suspend_domain.rb +5 -5
  35. data/lib/vagrant-libvirt/action/wait_till_up.rb +24 -26
  36. data/lib/vagrant-libvirt/action.rb +18 -23
  37. data/lib/vagrant-libvirt/cap/mount_p9.rb +11 -10
  38. data/lib/vagrant-libvirt/cap/nic_mac_addresses.rb +1 -1
  39. data/lib/vagrant-libvirt/cap/synced_folder.rb +20 -19
  40. data/lib/vagrant-libvirt/config.rb +164 -136
  41. data/lib/vagrant-libvirt/driver.rb +10 -13
  42. data/lib/vagrant-libvirt/errors.rb +4 -3
  43. data/lib/vagrant-libvirt/plugin.rb +4 -6
  44. data/lib/vagrant-libvirt/provider.rb +23 -24
  45. data/lib/vagrant-libvirt/templates/domain.xml.erb +14 -1
  46. data/lib/vagrant-libvirt/templates/private_network.xml.erb +4 -0
  47. data/lib/vagrant-libvirt/util/collection.rb +0 -3
  48. data/lib/vagrant-libvirt/util/erb_template.rb +6 -10
  49. data/lib/vagrant-libvirt/util/error_codes.rb +32 -33
  50. data/lib/vagrant-libvirt/util/network_util.rb +29 -21
  51. data/lib/vagrant-libvirt/util.rb +3 -4
  52. data/lib/vagrant-libvirt/version.rb +1 -1
  53. data/locales/en.yml +3 -0
  54. data/spec/spec_helper.rb +3 -0
  55. data/spec/support/environment_helper.rb +5 -7
  56. data/spec/support/libvirt_context.rb +13 -11
  57. data/spec/support/sharedcontext.rb +9 -10
  58. data/spec/unit/action/destroy_domain_spec.rb +38 -37
  59. data/spec/unit/action/set_name_of_domain_spec.rb +4 -4
  60. data/spec/unit/action/wait_till_up_spec.rb +45 -46
  61. data/spec/unit/config_spec.rb +106 -0
  62. data/spec/unit/templates/domain_all_settings.xml +125 -0
  63. data/spec/unit/templates/domain_defaults.xml +44 -0
  64. data/spec/unit/templates/domain_spec.rb +69 -0
  65. data/tools/create_box.sh +8 -2
  66. metadata +12 -3
@@ -33,8 +33,7 @@ module VagrantPlugins
33
33
  # can use this method to load in new data for the actual backing
34
34
  # machine or to realize that the machine is now gone (the ID can
35
35
  # become `nil`).
36
- def machine_id_changed
37
- end
36
+ def machine_id_changed; end
38
37
 
39
38
  # This should return a hash of information that explains how to
40
39
  # SSH into the machine. If the machine is not at a point where
@@ -45,12 +44,12 @@ module VagrantPlugins
45
44
  #
46
45
  # Ssh info has following format..
47
46
  #
48
- #{
47
+ # {
49
48
  # :host => "1.2.3.4",
50
49
  # :port => "22",
51
50
  # :username => "mitchellh",
52
51
  # :private_key_path => "/path/to/my/key"
53
- #}
52
+ # }
54
53
  # note that modifing @machine.id or accessing @machine.state is not
55
54
  # thread safe, so be careful to avoid these here as this method may
56
55
  # be called from other threads of execution.
@@ -60,21 +59,23 @@ module VagrantPlugins
60
59
 
61
60
  # if can't determine the IP, just return nil and let the core
62
61
  # deal with it, similar to the docker provider
63
- return nil if !ip
62
+ return nil unless ip
64
63
 
65
64
  ssh_info = {
66
- :host => ip,
67
- :port => @machine.config.ssh.guest_port,
68
- :forward_agent => @machine.config.ssh.forward_agent,
69
- :forward_x11 => @machine.config.ssh.forward_x11,
65
+ host: ip,
66
+ port: @machine.config.ssh.guest_port,
67
+ forward_agent: @machine.config.ssh.forward_agent,
68
+ forward_x11: @machine.config.ssh.forward_x11
70
69
  }
71
70
 
72
- ssh_info[:proxy_command] = (
73
- "ssh '#{@machine.provider_config.host}' " +
74
- "-l '#{@machine.provider_config.username}' " +
75
- "-i '#{@machine.provider_config.id_ssh_key_file}' " +
76
- "nc %h %p"
77
- ) if @machine.provider_config.connect_via_ssh
71
+ if @machine.provider_config.connect_via_ssh
72
+ ssh_info[:proxy_command] =
73
+ "ssh '#{@machine.provider_config.host}' " \
74
+ "-l '#{@machine.provider_config.username}' " \
75
+ "-i '#{@machine.provider_config.id_ssh_key_file}' " \
76
+ 'nc %h %p'
77
+
78
+ end
78
79
 
79
80
  ssh_info
80
81
  end
@@ -94,22 +95,21 @@ module VagrantPlugins
94
95
  # This should return the state of the machine within this provider.
95
96
  # The state must be an instance of {MachineState}.
96
97
  def state
97
-
98
98
  state_id = nil
99
- state_id = :not_created if !@machine.id
100
- state_id = :not_created if (
101
- !state_id && (!@machine.id || !driver.created?(@machine.id)))
99
+ state_id = :not_created unless @machine.id
100
+ state_id = :not_created if
101
+ !state_id && (!@machine.id || !driver.created?(@machine.id))
102
102
  # Query the driver for the current state of the machine
103
103
  state_id = driver.state(@machine) if @machine.id && !state_id
104
- state_id = :unknown if !state_id
104
+ state_id = :unknown unless state_id
105
105
 
106
106
  # This is a special pseudo-state so that we don't set the
107
107
  # NOT_CREATED_ID while we're setting up the machine. This avoids
108
108
  # clearing the data dir.
109
- state_id = :preparing if @machine.id == "preparing"
109
+ state_id = :preparing if @machine.id == 'preparing'
110
110
 
111
111
  # Get the short and long description
112
- short = state_id.to_s.gsub("_", " ")
112
+ short = state_id.to_s.tr('_', ' ')
113
113
  long = I18n.t("vagrant_libvirt.states.#{state_id}")
114
114
 
115
115
  # If we're not created, then specify the special ID flag
@@ -122,10 +122,9 @@ module VagrantPlugins
122
122
  end
123
123
 
124
124
  def to_s
125
- id = @machine.id.nil? ? "new" : @machine.id
125
+ id = @machine.id.nil? ? 'new' : @machine.id
126
126
  "Libvirt (#{id})"
127
127
  end
128
128
  end
129
129
  end
130
130
  end
131
-
@@ -7,7 +7,7 @@
7
7
 
8
8
  <cpu mode='<%= @cpu_mode %>'>
9
9
  <% if @cpu_mode != 'host-passthrough' %>
10
- <model fallback='<%= @cpu_fallback %>'><%= @cpu_model %></model>
10
+ <model fallback='<%= @cpu_fallback %>'><% if @cpu_mode == 'custom' %><%= @cpu_model %><% end %></model>
11
11
  <% if @nested %>
12
12
  <feature policy='optional' name='vmx'/>
13
13
  <feature policy='optional' name='svm'/>
@@ -170,6 +170,19 @@
170
170
  </source>
171
171
  </hostdev>
172
172
  <% end %>
173
+ <% unless @redirdevs.empty? %>
174
+ <% @redirdevs.each do |redirdev| %>
175
+ <redirdev bus='usb' type='<%= redirdev[:type] %>'>
176
+ </redirdev>
177
+ <% end %>
178
+ <% unless @redirfilters.empty? %>
179
+ <redirfilter>
180
+ <% @redirfilters.each do |usbdev| %>
181
+ <usbdev class='<%= usbdev[:class] %>' vendor='<%= usbdev[:vendor] %>' product='<%= usbdev[:product] %>' version='<%= usbdev[:version] %>' allow='<%= usbdev[:allow] %>'/>
182
+ <% end %>
183
+ </redirfilter>
184
+ <% end %>
185
+ <% end %>
173
186
 
174
187
  <% if @tpm_path -%>
175
188
  <%# TPM Device -%>
@@ -27,4 +27,8 @@
27
27
  </ip>
28
28
  <% end %>
29
29
 
30
+ <% if !@network_ipv6_address.nil? && !@network_ipv6_prefix.nil? %>
31
+ <ip family='ipv6' address="<%= @network_ipv6_address %>" prefix="<%= @network_ipv6_prefix %>"></ip>
32
+ <% end %>
33
+
30
34
  </network>
@@ -2,7 +2,6 @@ module VagrantPlugins
2
2
  module ProviderLibvirt
3
3
  module Util
4
4
  module Collection
5
-
6
5
  # This method finds a matching _thing_ in a collection of
7
6
  # _things_. This works matching if the ID or NAME equals to
8
7
  # `name`. Or, if `name` is a regexp, a partial match is chosen
@@ -14,9 +13,7 @@ module VagrantPlugins
14
13
 
15
14
  nil
16
15
  end
17
-
18
16
  end
19
17
  end
20
18
  end
21
19
  end
22
-
@@ -4,22 +4,18 @@ module VagrantPlugins
4
4
  module ProviderLibvirt
5
5
  module Util
6
6
  module ErbTemplate
7
-
8
-
9
- # TODO might be a chance to use vagrant template system according to https://github.com/mitchellh/vagrant/issues/3231
10
- def to_xml template_name = nil, data = binding
11
- erb = template_name || self.class.to_s.split("::").last.downcase
12
- path = File.join(File.dirname(__FILE__), "..", "templates",
7
+ # TODO: might be a chance to use vagrant template system according to https://github.com/mitchellh/vagrant/issues/3231
8
+ def to_xml(template_name = nil, data = binding)
9
+ erb = template_name || self.class.to_s.split('::').last.downcase
10
+ path = File.join(File.dirname(__FILE__), '..', 'templates',
13
11
  "#{erb}.xml.erb")
14
12
  template = File.read(path)
15
13
 
16
- # TODO according to erubis documentation, we should rather use evaluate and forget about
14
+ # TODO: according to erubis documentation, we should rather use evaluate and forget about
17
15
  # binding since the template may then change variables values
18
- Erubis::Eruby.new(template, :trim => true).result(data)
16
+ Erubis::Eruby.new(template, trim: true).result(data)
19
17
  end
20
-
21
18
  end
22
19
  end
23
20
  end
24
21
  end
25
-
@@ -6,19 +6,19 @@ module VagrantPlugins
6
6
  VIR_ERR_OK = 0
7
7
  VIR_ERR_INTERNAL_ERROR = 1 # internal error
8
8
  VIR_ERR_NO_MEMORY = 2 # memory allocation failure
9
- VIR_ERR_NO_SUPPORT = 3 # no support for this function
10
- VIR_ERR_UNKNOWN_HOST = 4 # could not resolve hostname
11
- VIR_ERR_NO_CONNECT = 5 # can't connect to hypervisor
12
- VIR_ERR_INVALID_CONN = 6 # invalid connection object
13
- VIR_ERR_INVALID_DOMAIN = 7 # invalid domain object
9
+ VIR_ERR_NO_SUPPORT = 3 # no support for this function
10
+ VIR_ERR_UNKNOWN_HOST = 4 # could not resolve hostname
11
+ VIR_ERR_NO_CONNECT = 5 # can't connect to hypervisor
12
+ VIR_ERR_INVALID_CONN = 6 # invalid connection object
13
+ VIR_ERR_INVALID_DOMAIN = 7 # invalid domain object
14
14
  VIR_ERR_INVALID_ARG = 8 # invalid function argument
15
- VIR_ERR_OPERATION_FAILED = 9 # a command to hypervisor failed
15
+ VIR_ERR_OPERATION_FAILED = 9 # a command to hypervisor failed
16
16
  VIR_ERR_GET_FAILED = 10 # a HTTP GET command to failed
17
17
  VIR_ERR_POST_FAILED = 11 # a HTTP POST command to failed
18
18
  VIR_ERR_HTTP_ERROR = 12 # unexpected HTTP error code
19
- VIR_ERR_SEXPR_SERIAL = 13 # failure to serialize an S-Expr
20
- VIR_ERR_NO_XEN = 14 # could not open Xen hypervisor control
21
- VIR_ERR_XEN_CALL = 15 # failure doing an hypervisor call
19
+ VIR_ERR_SEXPR_SERIAL = 13 # failure to serialize an S-Expr
20
+ VIR_ERR_NO_XEN = 14 # could not open Xen hypervisor control
21
+ VIR_ERR_XEN_CALL = 15 # failure doing an hypervisor call
22
22
  VIR_ERR_OS_TYPE = 16 # unknown OS type
23
23
  VIR_ERR_NO_KERNEL = 17 # missing kernel information
24
24
  VIR_ERR_NO_ROOT = 18 # missing root device information
@@ -32,31 +32,31 @@ module VagrantPlugins
32
32
  VIR_ERR_CALL_FAILED = 26 # not supported by the drivers (DEPRECATED)
33
33
  VIR_ERR_XML_ERROR = 27 # an XML description is not well formed or broken
34
34
  VIR_ERR_DOM_EXIST = 28 # the domain already exist
35
- VIR_ERR_OPERATION_DENIED = 29 # operation forbidden on read-only connections
35
+ VIR_ERR_OPERATION_DENIED = 29 # operation forbidden on read-only connections
36
36
  VIR_ERR_OPEN_FAILED = 30 # failed to open a conf file
37
37
  VIR_ERR_READ_FAILED = 31 # failed to read a conf file
38
- VIR_ERR_PARSE_FAILED = 32 # failed to parse a conf file
38
+ VIR_ERR_PARSE_FAILED = 32 # failed to parse a conf file
39
39
  VIR_ERR_CONF_SYNTAX = 33 # failed to parse the syntax of a conf file
40
- VIR_ERR_WRITE_FAILED = 34 # failed to write a conf file
41
- VIR_ERR_XML_DETAIL = 35 # detail of an XML error
40
+ VIR_ERR_WRITE_FAILED = 34 # failed to write a conf file
41
+ VIR_ERR_XML_DETAIL = 35 # detail of an XML error
42
42
  VIR_ERR_INVALID_NETWORK = 36 # invalid network object
43
43
  VIR_ERR_NETWORK_EXIST = 37 # the network already exist
44
44
  VIR_ERR_SYSTEM_ERROR = 38 # general system call failure
45
45
  VIR_ERR_RPC = 39 # some sort of RPC error
46
- VIR_ERR_GNUTLS_ERROR = 40 # error from a GNUTLS call
47
- VIR_WAR_NO_NETWORK = 41 # failed to start network
46
+ VIR_ERR_GNUTLS_ERROR = 40 # error from a GNUTLS call
47
+ VIR_WAR_NO_NETWORK = 41 # failed to start network
48
48
  VIR_ERR_NO_DOMAIN = 42 # domain not found or unexpectedly disappeared
49
49
  VIR_ERR_NO_NETWORK = 43 # network not found
50
50
  VIR_ERR_INVALID_MAC = 44 # invalid MAC address
51
51
  VIR_ERR_AUTH_FAILED = 45 # authentication failed
52
- VIR_ERR_INVALID_STORAGE_POOL = 46 # invalid storage pool object
52
+ VIR_ERR_INVALID_STORAGE_POOL = 46 # invalid storage pool object
53
53
  VIR_ERR_INVALID_STORAGE_VOL = 47 # invalid storage vol object
54
- VIR_WAR_NO_STORAGE = 48 # failed to start storage
54
+ VIR_WAR_NO_STORAGE = 48 # failed to start storage
55
55
  VIR_ERR_NO_STORAGE_POOL = 49 # storage pool not found
56
56
  VIR_ERR_NO_STORAGE_VOL = 50 # storage volume not found
57
57
  VIR_WAR_NO_NODE = 51 # failed to start node driver
58
58
  VIR_ERR_INVALID_NODE_DEVICE = 52 # invalid node device object
59
- VIR_ERR_NO_NODE_DEVICE = 53 # node device not found
59
+ VIR_ERR_NO_NODE_DEVICE = 53 # node device not found
60
60
  VIR_ERR_NO_SECURITY_MODEL = 54 # security model not found
61
61
  VIR_ERR_OPERATION_INVALID = 55 # operation is not applicable at this time
62
62
  VIR_WAR_NO_INTERFACE = 56 # failed to start interface driver
@@ -64,32 +64,32 @@ module VagrantPlugins
64
64
  VIR_ERR_INVALID_INTERFACE = 58 # invalid interface object
65
65
  VIR_ERR_MULTIPLE_INTERFACES = 59 # more than one matching interface found
66
66
  VIR_WAR_NO_NWFILTER = 60 # failed to start nwfilter driver
67
- VIR_ERR_INVALID_NWFILTER = 61 # invalid nwfilter object
67
+ VIR_ERR_INVALID_NWFILTER = 61 # invalid nwfilter object
68
68
  VIR_ERR_NO_NWFILTER = 62 # nw filter pool not found
69
- VIR_ERR_BUILD_FIREWALL = 63 # nw filter pool not found
69
+ VIR_ERR_BUILD_FIREWALL = 63 # nw filter pool not found
70
70
  VIR_WAR_NO_SECRET = 64 # failed to start secret storage
71
- VIR_ERR_INVALID_SECRET = 65 # invalid secret
71
+ VIR_ERR_INVALID_SECRET = 65 # invalid secret
72
72
  VIR_ERR_NO_SECRET = 66 # secret not found
73
- VIR_ERR_CONFIG_UNSUPPORTED = 67 # unsupported configuration construct
73
+ VIR_ERR_CONFIG_UNSUPPORTED = 67 # unsupported configuration construct
74
74
  VIR_ERR_OPERATION_TIMEOUT = 68 # timeout occurred during operation
75
- VIR_ERR_MIGRATE_PERSIST_FAILED = 69 # a migration worked, but making the VM persist on the dest host failed
76
- VIR_ERR_HOOK_SCRIPT_FAILED = 70 # a synchronous hook script failed
75
+ VIR_ERR_MIGRATE_PERSIST_FAILED = 69 # a migration worked, but making the VM persist on the dest host failed
76
+ VIR_ERR_HOOK_SCRIPT_FAILED = 70 # a synchronous hook script failed
77
77
  VIR_ERR_INVALID_DOMAIN_SNAPSHOT = 71 # invalid domain snapshot
78
- VIR_ERR_NO_DOMAIN_SNAPSHOT = 72 # domain snapshot not found
79
- VIR_ERR_INVALID_STREAM = 73 # stream pointer not valid
78
+ VIR_ERR_NO_DOMAIN_SNAPSHOT = 72 # domain snapshot not found
79
+ VIR_ERR_INVALID_STREAM = 73 # stream pointer not valid
80
80
  VIR_ERR_ARGUMENT_UNSUPPORTED = 74 # valid API use but unsupported by the given driver
81
81
  VIR_ERR_STORAGE_PROBE_FAILED = 75 # storage pool probe failed
82
- VIR_ERR_STORAGE_POOL_BUILT = 76 # storage pool already built
82
+ VIR_ERR_STORAGE_POOL_BUILT = 76 # storage pool already built
83
83
  VIR_ERR_SNAPSHOT_REVERT_RISKY = 77 # force was not requested for a risky domain snapshot revert
84
84
  VIR_ERR_OPERATION_ABORTED = 78 # operation on a domain was canceled/aborted by user
85
- VIR_ERR_AUTH_CANCELLED = 79 # authentication cancelled
86
- VIR_ERR_NO_DOMAIN_METADATA = 80 # The metadata is not present
87
- VIR_ERR_MIGRATE_UNSAFE = 81 # Migration is not safe
88
- VIR_ERR_OVERFLOW = 82 # integer overflow
85
+ VIR_ERR_AUTH_CANCELLED = 79 # authentication cancelled
86
+ VIR_ERR_NO_DOMAIN_METADATA = 80 # The metadata is not present
87
+ VIR_ERR_MIGRATE_UNSAFE = 81 # Migration is not safe
88
+ VIR_ERR_OVERFLOW = 82 # integer overflow
89
89
  VIR_ERR_BLOCK_COPY_ACTIVE = 83 # action prevented by block copy job
90
90
  VIR_ERR_OPERATION_UNSUPPORTED = 84 # The requested operation is not supported
91
91
  VIR_ERR_SSH = 85 # error in ssh transport driver
92
- VIR_ERR_AGENT_UNRESPONSIVE = 86 # guest agent is unresponsive, not running or not usable
92
+ VIR_ERR_AGENT_UNRESPONSIVE = 86 # guest agent is unresponsive, not running or not usable
93
93
  VIR_ERR_RESOURCE_BUSY = 87 # resource is already in use
94
94
  VIR_ERR_ACCESS_DENIED = 88 # operation on the object/resource was denied
95
95
  VIR_ERR_DBUS_SERVICE = 89 # error from a dbus service
@@ -98,4 +98,3 @@ module VagrantPlugins
98
98
  end
99
99
  end
100
100
  end
101
-
@@ -13,39 +13,51 @@ module VagrantPlugins
13
13
  management_network_mode = env[:machine].provider_config.management_network_mode
14
14
  management_network_mac = env[:machine].provider_config.management_network_mac
15
15
  management_network_guest_ipv6 = env[:machine].provider_config.management_network_guest_ipv6
16
+ management_network_autostart = env[:machine].provider_config.management_network_autostart
16
17
  logger.info "Using #{management_network_name} at #{management_network_address} as the management network #{management_network_mode} is the mode"
17
18
 
18
19
  begin
19
20
  management_network_ip = IPAddr.new(management_network_address)
20
21
  rescue ArgumentError
21
22
  raise Errors::ManagementNetworkError,
22
- error_message: "#{management_network_address} is not a valid IP address"
23
+ error_message: "#{management_network_address} is not a valid IP address"
23
24
  end
24
25
 
25
26
  # capture address into $1 and mask into $2
26
27
  management_network_ip.inspect =~ /IPv4:(.*)\/(.*)>/
27
28
 
28
- if $2 == '255.255.255.255'
29
+ if Regexp.last_match(2) == '255.255.255.255'
29
30
  raise Errors::ManagementNetworkError,
30
- error_message: "#{management_network_address} does not include both an address and subnet mask"
31
+ error_message: "#{management_network_address} does not include both an address and subnet mask"
31
32
  end
32
33
 
33
34
  management_network_options = {
34
35
  iface_type: :private_network,
35
36
  network_name: management_network_name,
36
- ip: $1,
37
- netmask: $2,
37
+ ip: Regexp.last_match(1),
38
+ netmask: Regexp.last_match(2),
38
39
  dhcp_enabled: true,
39
40
  forward_mode: management_network_mode,
40
41
  guest_ipv6: management_network_guest_ipv6,
42
+ autostart: management_network_autostart
41
43
  }
42
44
 
43
45
  unless management_network_mac.nil?
44
46
  management_network_options[:mac] = management_network_mac
45
47
  end
46
48
 
49
+ if (env[:machine].config.vm.box &&
50
+ !env[:machine].provider_config.mgmt_attach)
51
+ raise Errors::ManagementNetworkRequired
52
+ end
53
+
47
54
  # add management network to list of networks to check
48
- networks = [ management_network_options ]
55
+ # unless mgmt_attach set to false
56
+ networks = if env[:machine].provider_config.mgmt_attach
57
+ [management_network_options]
58
+ else
59
+ []
60
+ end
49
61
 
50
62
  env[:machine].config.vm.networks.each do |type, original_options|
51
63
  logger.debug "In config found network type #{type} options #{original_options}"
@@ -59,18 +71,18 @@ module VagrantPlugins
59
71
  iface_type: type,
60
72
  netmask: '255.255.255.0',
61
73
  dhcp_enabled: true,
62
- forward_mode: 'nat',
74
+ forward_mode: 'nat'
63
75
  }.merge(options)
64
76
 
65
77
  if options[:type].to_s == 'dhcp' && options[:ip].nil?
66
- options[:network_name] = "vagrant-private-dhcp"
78
+ options[:network_name] = 'vagrant-private-dhcp'
67
79
  end
68
80
 
69
81
  # add to list of networks to check
70
82
  networks.push(options)
71
83
  end
72
84
 
73
- return networks
85
+ networks
74
86
  end
75
87
 
76
88
  # Return a list of all (active and inactive) libvirt networks as a list
@@ -84,7 +96,8 @@ module VagrantPlugins
84
96
  # Iterate over all (active and inactive) networks.
85
97
  active.concat(inactive).each do |network_name|
86
98
  libvirt_network = libvirt_client.lookup_network_by_name(
87
- network_name)
99
+ network_name
100
+ )
88
101
 
89
102
  # Parse ip address and netmask from the network xml description.
90
103
  xml = Nokogiri::XML(libvirt_network.xml_desc)
@@ -93,19 +106,15 @@ module VagrantPlugins
93
106
  netmask = xml.xpath('/network/ip/@netmask').first
94
107
  netmask = netmask.value if netmask
95
108
 
96
- if xml.at_xpath('//network/ip/dhcp')
97
- dhcp_enabled = true
98
- else
99
- dhcp_enabled = false
100
- end
109
+ dhcp_enabled = if xml.at_xpath('//network/ip/dhcp')
110
+ true
111
+ else
112
+ false
113
+ end
101
114
 
102
115
  # Calculate network address of network from ip address and
103
116
  # netmask.
104
- if ip && netmask
105
- network_address = network_address(ip, netmask)
106
- else
107
- network_address = nil
108
- end
117
+ network_address = (network_address(ip, netmask) if ip && netmask)
109
118
 
110
119
  libvirt_networks << {
111
120
  name: network_name,
@@ -123,7 +132,6 @@ module VagrantPlugins
123
132
 
124
133
  libvirt_networks
125
134
  end
126
-
127
135
  end
128
136
  end
129
137
  end
@@ -3,10 +3,9 @@ module VagrantPlugins
3
3
  module Util
4
4
  autoload :ErbTemplate, 'vagrant-libvirt/util/erb_template'
5
5
  autoload :Collection, 'vagrant-libvirt/util/collection'
6
- autoload :Timer, 'vagrant-libvirt/util/timer'
7
- autoload :NetworkUtil, 'vagrant-libvirt/util/network_util'
8
- autoload :ErrorCodes, 'vagrant-libvirt/util/error_codes'
6
+ autoload :Timer, 'vagrant-libvirt/util/timer'
7
+ autoload :NetworkUtil, 'vagrant-libvirt/util/network_util'
8
+ autoload :ErrorCodes, 'vagrant-libvirt/util/error_codes'
9
9
  end
10
10
  end
11
11
  end
12
-
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ProviderLibvirt
3
- VERSION = '0.0.36'
3
+ VERSION = '0.0.37'.freeze
4
4
  end
5
5
  end
data/locales/en.yml CHANGED
@@ -137,6 +137,9 @@ en:
137
137
  Error while deleting snapshot: %{error_message}.
138
138
  tunnel_port_not_defined: |-
139
139
  tunnel UDP or TCP port not defined.
140
+ management_network_required: |-
141
+ Management network can't be disabled when VM use box.
142
+ Please fix your configuration and run vagrant again.
140
143
 
141
144
  states:
142
145
  paused: |-
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'vagrant-libvirt'
2
5
  require 'support/environment_helper'
3
6
  require 'vagrant-spec/unit'
@@ -1,14 +1,13 @@
1
- require "ostruct"
2
- require "pathname"
1
+ require 'ostruct'
2
+ require 'pathname'
3
3
 
4
4
  class EnvironmentHelper
5
-
6
5
  attr_writer :domain_name
7
6
 
8
7
  attr_accessor :random_hostname, :name, :default_prefix
9
8
 
10
9
  def [](value)
11
- self.send(value.to_sym)
10
+ send(value.to_sym)
12
11
  end
13
12
 
14
13
  def cpus
@@ -34,15 +33,14 @@ class EnvironmentHelper
34
33
  end
35
34
 
36
35
  def root_path
37
- Pathname.new("./spec/support/foo")
36
+ Pathname.new('./spec/support/foo')
38
37
  end
39
38
 
40
39
  def domain_name
41
- #noop
40
+ # noop
42
41
  end
43
42
 
44
43
  def libvirt_compute
45
44
  OpenStruct.new(servers: [])
46
45
  end
47
-
48
46
  end
@@ -1,28 +1,30 @@
1
1
  require 'fog/libvirt'
2
2
 
3
- shared_context "libvirt" do
4
- include_context "unit"
3
+ shared_context 'libvirt' do
4
+ include_context 'unit'
5
5
 
6
6
  let(:libvirt_context) { true }
7
- let(:id) { "dummy-vagrant_dummy" }
8
- let(:connection) { double("connection") }
9
- let(:domain) { double("domain") }
7
+ let(:id) { 'dummy-vagrant_dummy' }
8
+ let(:connection) { double('connection') }
9
+ let(:domain) { double('domain') }
10
10
 
11
- def connection_result(options={})
11
+ def connection_result(options = {})
12
12
  result = options.fetch(:result, nil)
13
- double("connection_result" => result)
13
+ double('connection_result' => result)
14
14
  end
15
15
 
16
16
  before (:each) do
17
17
  # we don't want unit tests to ever run commands on the system; so we wire
18
18
  # in a double to ensure any unexpected messages raise exceptions
19
- stub_const("::Fog::Compute", connection)
19
+ stub_const('::Fog::Compute', connection)
20
20
 
21
21
  # drivers also call vm_exists? during init;
22
- allow(connection).to receive(:servers).with(kind_of(String)).
23
- and_return(connection_result(result: nil))
22
+ allow(connection).to receive(:servers).with(kind_of(String))
23
+ .and_return(connection_result(result: nil))
24
24
 
25
25
  # return some information for domain when needed
26
- allow(domain).to receive(:mac).and_return("9C:D5:53:F1:5A:E7")
26
+ allow(domain).to receive(:mac).and_return('9C:D5:53:F1:5A:E7')
27
+
28
+ machine.stub(id: id)
27
29
  end
28
30
  end
@@ -1,9 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- shared_context "unit" do
3
+ shared_context 'unit' do
4
4
  include_context 'vagrant-unit'
5
5
 
6
- let(:vagrantfile) do <<-EOF
6
+ let(:vagrantfile) do
7
+ <<-EOF
7
8
  Vagrant.configure('2') do |config|
8
9
  config.vm.define :test
9
10
  end
@@ -15,21 +16,19 @@ shared_context "unit" do
15
16
  test_env
16
17
  end
17
18
  let(:env) { { env: iso_env, machine: machine, ui: ui, root_path: '/rootpath' } }
18
- let(:conf) { Vagrant::Config::V2::DummyConfig.new() }
19
- let(:ui) { Vagrant::UI::Basic.new() }
19
+ let(:conf) { Vagrant::Config::V2::DummyConfig.new }
20
+ let(:ui) { Vagrant::UI::Basic.new }
20
21
  let(:iso_env) { test_env.create_vagrant_env ui_class: Vagrant::UI::Basic }
21
22
  let(:machine) { iso_env.machine(:test, :libvirt) }
22
23
  # Mock the communicator to prevent SSH commands for being executed.
23
24
  let(:communicator) { double('communicator') }
24
25
  # Mock the guest operating system.
25
26
  let(:guest) { double('guest') }
26
- let(:app) { lambda { |env| } }
27
- let(:plugin) { register_plugin() }
27
+ let(:app) { ->(env) {} }
28
+ let(:plugin) { register_plugin }
28
29
 
29
30
  before (:each) do
30
- machine.stub(:guest => guest)
31
- machine.stub(:communicator => communicator)
32
- machine.stub(:id => id)
31
+ machine.stub(guest: guest)
32
+ machine.stub(communicator: communicator)
33
33
  end
34
-
35
34
  end