fog-libvirt 0.4.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/fog-libvirt.gemspec +7 -16
  3. data/lib/fog/bin/libvirt.rb +2 -2
  4. data/lib/fog/libvirt.rb +1 -3
  5. data/lib/fog/libvirt/compute.rb +6 -4
  6. data/lib/fog/libvirt/models/compute/README.md +16 -0
  7. data/lib/fog/libvirt/models/compute/interface.rb +2 -2
  8. data/lib/fog/libvirt/models/compute/interfaces.rb +3 -3
  9. data/lib/fog/libvirt/models/compute/network.rb +3 -3
  10. data/lib/fog/libvirt/models/compute/networks.rb +3 -3
  11. data/lib/fog/libvirt/models/compute/nic.rb +2 -2
  12. data/lib/fog/libvirt/models/compute/nics.rb +3 -3
  13. data/lib/fog/libvirt/models/compute/node.rb +2 -2
  14. data/lib/fog/libvirt/models/compute/nodes.rb +3 -3
  15. data/lib/fog/libvirt/models/compute/pool.rb +2 -2
  16. data/lib/fog/libvirt/models/compute/pools.rb +3 -3
  17. data/lib/fog/libvirt/models/compute/server.rb +149 -9
  18. data/lib/fog/libvirt/models/compute/servers.rb +3 -3
  19. data/lib/fog/libvirt/models/compute/templates/server.xml.erb +55 -0
  20. data/lib/fog/libvirt/models/compute/templates/volume.xml.erb +4 -4
  21. data/lib/fog/libvirt/models/compute/util/uri.rb +2 -2
  22. data/lib/fog/libvirt/models/compute/util/util.rb +2 -2
  23. data/lib/fog/libvirt/models/compute/volume.rb +11 -9
  24. data/lib/fog/libvirt/models/compute/volumes.rb +3 -3
  25. data/lib/fog/libvirt/requests/compute/clone_volume.rb +3 -3
  26. data/lib/fog/libvirt/requests/compute/create_domain.rb +2 -2
  27. data/lib/fog/libvirt/requests/compute/create_volume.rb +2 -2
  28. data/lib/fog/libvirt/requests/compute/define_domain.rb +2 -2
  29. data/lib/fog/libvirt/requests/compute/define_pool.rb +2 -2
  30. data/lib/fog/libvirt/requests/compute/destroy_interface.rb +2 -2
  31. data/lib/fog/libvirt/requests/compute/destroy_network.rb +2 -2
  32. data/lib/fog/libvirt/requests/compute/dhcp_leases.rb +2 -2
  33. data/lib/fog/libvirt/requests/compute/get_node_info.rb +2 -2
  34. data/lib/fog/libvirt/requests/compute/libversion.rb +18 -0
  35. data/lib/fog/libvirt/requests/compute/list_domains.rb +9 -3
  36. data/lib/fog/libvirt/requests/compute/list_interfaces.rb +2 -2
  37. data/lib/fog/libvirt/requests/compute/list_networks.rb +11 -3
  38. data/lib/fog/libvirt/requests/compute/list_pool_volumes.rb +2 -2
  39. data/lib/fog/libvirt/requests/compute/list_pools.rb +2 -2
  40. data/lib/fog/libvirt/requests/compute/list_volumes.rb +16 -8
  41. data/lib/fog/libvirt/requests/compute/pool_action.rb +2 -2
  42. data/lib/fog/libvirt/requests/compute/update_autostart.rb +18 -0
  43. data/lib/fog/libvirt/requests/compute/update_display.rb +2 -2
  44. data/lib/fog/libvirt/requests/compute/upload_volume.rb +2 -2
  45. data/lib/fog/libvirt/requests/compute/vm_action.rb +2 -2
  46. data/lib/fog/libvirt/requests/compute/volume_action.rb +2 -2
  47. data/lib/fog/libvirt/version.rb +1 -1
  48. data/minitests/server/server_test.rb +64 -0
  49. data/minitests/server/user_data_iso_test.rb +8 -8
  50. data/tests/libvirt/compute_tests.rb +2 -1
  51. data/tests/libvirt/models/compute/interface_tests.rb +1 -1
  52. data/tests/libvirt/models/compute/interfaces_tests.rb +1 -1
  53. data/tests/libvirt/models/compute/network_tests.rb +1 -1
  54. data/tests/libvirt/models/compute/networks_tests.rb +1 -1
  55. data/tests/libvirt/models/compute/nic_tests.rb +1 -1
  56. data/tests/libvirt/models/compute/pool_tests.rb +1 -1
  57. data/tests/libvirt/models/compute/pools_tests.rb +1 -1
  58. data/tests/libvirt/models/compute/server_tests.rb +4 -1
  59. data/tests/libvirt/models/compute/servers_tests.rb +1 -1
  60. data/tests/libvirt/models/compute/volume_tests.rb +1 -1
  61. data/tests/libvirt/models/compute/volumes_tests.rb +2 -1
  62. data/tests/libvirt/requests/compute/update_autostart_tests.rb +12 -0
  63. metadata +27 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1be3f7614833884bc18f6c8cc31784d9d831e8f2
4
- data.tar.gz: 7e6fc8812af255b7e640ce5fc02f1a3f6a1fc4d3
2
+ SHA256:
3
+ metadata.gz: f3f3d3db14311de4008b43186334103d78f393b03f30282fc6276c1c5f3a7bd3
4
+ data.tar.gz: acdeffc9be9ca8fa2d2fe5065616b9c7a14c4415b03359437500cfd7c47f63f0
5
5
  SHA512:
6
- metadata.gz: 73a49e73d10ba49159cb92bf950e6bb76deac2b60d9bf537beefe21314a1ce4e53015347f5f421060f791cbeae121da5dbffa602979ae9f2d077b69aa321de1d
7
- data.tar.gz: 17decadd48d88dc4b61845ec6fdb5b946e9b78a23fbe68cc1998d44f210218af9416002daf3628c7d39fdc7c141965d5e73a5e7231088a8c776c04b55fd7cdd6
6
+ metadata.gz: e0cb8dbd4c13fd8aa4540e8da830d5853b4507c87795edb3aeb03f644d68d895405e7ed804795b70cf0921fb3a54586f6c912ee67eb52abb4e8e7ee07212bfa6
7
+ data.tar.gz: 8e0f16895181fc4becbf81a3a08d215b39be6d77414425fd2238b696b313c9fd9931f23ce38af538f109d403e50aa4430fa674266050c3698f703331762cdec5
@@ -23,25 +23,16 @@ Gem::Specification.new do |s|
23
23
  s.rdoc_options = ["--charset=UTF-8"]
24
24
  s.extra_rdoc_files = %w[README.md]
25
25
 
26
- s.add_dependency("fog-core", "~> 1.27", ">= 1.27.4")
26
+ s.required_ruby_version = '>= 2.0.0'
27
+
28
+ s.add_dependency("fog-core", ">= 1.27.4")
27
29
  s.add_dependency("fog-json")
28
30
  s.add_dependency("fog-xml", "~> 0.1.1")
29
31
  s.add_dependency('ruby-libvirt','>= 0.7.0')
30
- s.add_dependency('mime-types','< 2.0') if RUBY_VERSION < '1.9'
31
- s.add_dependency('nokogiri', '< 1.6') if RUBY_VERSION < '1.9'
32
- s.add_dependency('octokit', '< 3.0') if RUBY_VERSION < '1.9'
33
- s.add_dependency('rest-client', '<= 1.7.0') if RUBY_VERSION < '1.9'
34
- s.add_dependency("tins", "<= 1.6.0") if RUBY_VERSION < "1.9"
35
-
36
- # Fedora and derivates need explicit require.
37
- # Also we cannot use newer JSON on Ruby 1.8 & 1.9.
38
- if RUBY_VERSION < '2.0'
39
- s.add_dependency("json", '< 2.0')
40
- else
41
- s.add_dependency("json")
42
- end
43
-
44
- s.add_development_dependency("minitest")
32
+ s.add_dependency("json")
33
+
34
+ s.add_development_dependency("net-ssh")
35
+ s.add_development_dependency("minitest", "~> 5.0")
45
36
  s.add_development_dependency("minitest-stub-const")
46
37
  s.add_development_dependency("pry")
47
38
  s.add_development_dependency("rake")
@@ -1,9 +1,9 @@
1
- module Libvirt # deviates from other bin stuff to accomodate gem
1
+ module Libvirt # deviates from other bin stuff to accommodate gem
2
2
  class << self
3
3
  def class_for(key)
4
4
  case key
5
5
  when :compute
6
- Fog::Compute::Libvirt
6
+ Fog::Libvirt::Compute
7
7
  else
8
8
  raise ArgumentError, "Unrecognized service: #{key}"
9
9
  end
@@ -9,9 +9,7 @@ module Fog
9
9
  module Libvirt
10
10
  extend Fog::Provider
11
11
 
12
- module Compute
13
- autoload :Libvirt, File.expand_path('../libvirt/compute', __FILE__)
14
- end
12
+ autoload :Compute, File.expand_path('../libvirt/compute', __FILE__)
15
13
 
16
14
  service(:compute, 'Compute')
17
15
  end
@@ -2,8 +2,8 @@ require 'fog/libvirt/models/compute/util/util'
2
2
  require 'fog/libvirt/models/compute/util/uri'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Libvirt < Fog::Service
5
+ module Libvirt
6
+ class Compute < Fog::Service
7
7
  requires :libvirt_uri
8
8
  recognizes :libvirt_username, :libvirt_password
9
9
  recognizes :libvirt_ip_command
@@ -44,10 +44,12 @@ module Fog
44
44
  request :list_interfaces
45
45
  request :destroy_interface
46
46
  request :get_node_info
47
+ request :update_autostart
47
48
  request :update_display
49
+ request :libversion
48
50
 
49
51
  module Shared
50
- include Fog::Compute::LibvirtUtil
52
+ include Fog::Libvirt::Util
51
53
  end
52
54
 
53
55
  class Mock
@@ -77,7 +79,7 @@ module Fog
77
79
  attr_reader :ip_command
78
80
 
79
81
  def initialize(options={})
80
- @uri = ::Fog::Compute::LibvirtUtil::URI.new(enhance_uri(options[:libvirt_uri]))
82
+ @uri = ::Fog::Libvirt::Util::URI.new(enhance_uri(options[:libvirt_uri]))
81
83
  @ip_command = options[:libvirt_ip_command]
82
84
 
83
85
  # libvirt is part of the gem => ruby-libvirt
@@ -26,6 +26,22 @@ Only ssh is supported as the transport for remote URI's. TLS is NOT supported, a
26
26
  - To check the connection you need to override your libvirt socket location in the URI
27
27
  - "qemu+ssh://patrick@myserver/system?socket=/var/run/libvirt/libvirt-sock"
28
28
 
29
+ ## Ceph RBD volumes
30
+ To configure Ceph RBD volumes, the file ``/etc/foreman/ceph.conf`` is used.
31
+ After adding the authentication key to a libvirt secret, it can be configured as follows:
32
+ ```
33
+ monitor=mon001.example.com,mon002.example.com,mon003.example.com
34
+ port=6789
35
+ libvirt_ceph_pool=rbd_pool_name
36
+ auth_username=libvirt
37
+ auth_uuid=uuid_of_libvirt_secret
38
+ bus_type=virtio
39
+ ```
40
+ For more recent versions of libvirt which support using the secret by name (`usage` attribute in the `secret` tag),
41
+ you can also drop `auth_uuid` and specify `auth_usage` instead. If both are specified, `auth_uuid` will be preferred for maximum compatibility.
42
+
43
+ The `bus_type` can be set to `virtio` or `scsi`. If it is ommited, the default is `scsi`.
44
+
29
45
  ## Configuration
30
46
 
31
47
  The URI can be configured in two ways:
@@ -1,8 +1,8 @@
1
1
  require 'fog/core/model'
2
2
 
3
3
  module Fog
4
- module Compute
5
- class Libvirt
4
+ module Libvirt
5
+ class Compute
6
6
  class Interface < Fog::Model
7
7
  identity :name
8
8
  attribute :mac
@@ -2,10 +2,10 @@ require 'fog/core/collection'
2
2
  require 'fog/libvirt/models/compute/interface'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Libvirt
5
+ module Libvirt
6
+ class Compute
7
7
  class Interfaces < Fog::Collection
8
- model Fog::Compute::Libvirt::Interface
8
+ model Fog::Libvirt::Compute::Interface
9
9
 
10
10
  def all(filter={})
11
11
  load(service.list_interfaces(filter))
@@ -2,10 +2,10 @@ require 'fog/core/model'
2
2
  require 'fog/libvirt/models/compute/util/util'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Libvirt
5
+ module Libvirt
6
+ class Compute
7
7
  class Network < Fog::Model
8
- include Fog::Compute::LibvirtUtil
8
+ include Fog::Libvirt::Util
9
9
 
10
10
  identity :uuid
11
11
  attribute :name
@@ -2,10 +2,10 @@ require 'fog/core/collection'
2
2
  require 'fog/libvirt/models/compute/network'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Libvirt
5
+ module Libvirt
6
+ class Compute
7
7
  class Networks < Fog::Collection
8
- model Fog::Compute::Libvirt::Network
8
+ model Fog::Libvirt::Compute::Network
9
9
 
10
10
  def all(filter={})
11
11
  load(service.list_networks(filter))
@@ -1,8 +1,8 @@
1
1
  require 'fog/core/model'
2
2
 
3
3
  module Fog
4
- module Compute
5
- class Libvirt
4
+ module Libvirt
5
+ class Compute
6
6
  class Nic < Fog::Model
7
7
  identity :mac
8
8
  attribute :id
@@ -2,10 +2,10 @@ require 'fog/core/collection'
2
2
  require 'fog/libvirt/models/compute/nic'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Libvirt
5
+ module Libvirt
6
+ class Compute
7
7
  class Nics < Fog::Collection
8
- model Fog::Compute::Libvirt::Nic
8
+ model Fog::Libvirt::Compute::Nic
9
9
  end
10
10
  end
11
11
  end
@@ -1,8 +1,8 @@
1
1
  require 'fog/core/model'
2
2
 
3
3
  module Fog
4
- module Compute
5
- class Libvirt
4
+ module Libvirt
5
+ class Compute
6
6
  class Node < Fog::Model
7
7
  identity :uuid
8
8
 
@@ -2,10 +2,10 @@ require 'fog/core/collection'
2
2
  require 'fog/libvirt/models/compute/node'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Libvirt
5
+ module Libvirt
6
+ class Compute
7
7
  class Nodes < Fog::Collection
8
- model Fog::Compute::Libvirt::Node
8
+ model Fog::Libvirt::Compute::Node
9
9
 
10
10
  def all(filter={ })
11
11
  load(service.get_node_info)
@@ -1,8 +1,8 @@
1
1
  require 'fog/core/model'
2
2
 
3
3
  module Fog
4
- module Compute
5
- class Libvirt
4
+ module Libvirt
5
+ class Compute
6
6
  class Pool < Fog::Model
7
7
  attr_reader :xml
8
8
 
@@ -2,10 +2,10 @@ require 'fog/core/collection'
2
2
  require 'fog/libvirt/models/compute/pool'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Libvirt
5
+ module Libvirt
6
+ class Compute
7
7
  class Pools < Fog::Collection
8
- model Fog::Compute::Libvirt::Pool
8
+ model Fog::Libvirt::Compute::Pool
9
9
 
10
10
  def all(filter = {})
11
11
  load(service.list_pools(filter))
@@ -3,10 +3,10 @@ require 'fog/libvirt/models/compute/util/util'
3
3
  require 'fileutils'
4
4
 
5
5
  module Fog
6
- module Compute
7
- class Libvirt
6
+ module Libvirt
7
+ class Compute
8
8
  class Server < Fog::Compute::Server
9
- include Fog::Compute::LibvirtUtil
9
+ include Fog::Libvirt::Util
10
10
  attr_reader :xml
11
11
 
12
12
  identity :id, :aliases => 'uuid'
@@ -28,6 +28,9 @@ module Fog
28
28
  attribute :boot_order
29
29
  attribute :display
30
30
  attribute :cpu
31
+ attribute :hugepages
32
+ attribute :guest_agent
33
+ attribute :virtio_rng
31
34
 
32
35
  attribute :state
33
36
 
@@ -75,6 +78,10 @@ module Fog
75
78
  action_status
76
79
  end
77
80
 
81
+ def update_autostart(value)
82
+ service.update_autostart(uuid, value)
83
+ end
84
+
78
85
  def mac
79
86
  nics.first.mac if nics && nics.first
80
87
  end
@@ -129,9 +136,10 @@ module Fog
129
136
  end
130
137
 
131
138
  #alias methods
132
- alias_method :halt, :poweroff
133
- alias_method :stop, :shutdown
134
- alias_method :active?, :active
139
+ alias_method :halt, :poweroff
140
+ alias_method :stop, :shutdown
141
+ alias_method :active?, :active
142
+ alias_method :autostart?, :autostart
135
143
 
136
144
  def volumes
137
145
  # lazy loading of volumes
@@ -258,11 +266,139 @@ module Fog
258
266
  private
259
267
  attr_accessor :volumes_path
260
268
 
261
- # This retrieves the ip address of the mac address
269
+ # This tests the library version before redefining the address
270
+ # method for this instance to use a method compatible with
271
+ # earlier libvirt libraries, or uses the dhcp method from more
272
+ # recent releases.
273
+ def addresses(service_arg=service, options={})
274
+ addresses_method = self.method(:addresses_dhcp)
275
+ # check if ruby-libvirt was compiled against a new enough version
276
+ # that can use dhcp_leases, as otherwise it will not provide the
277
+ # method dhcp_leases on any of the network objects.
278
+ has_dhcp_leases = true
279
+ begin
280
+ service.networks.first.dhcp_leases(self.mac)
281
+ rescue NoMethodError
282
+ has_dhcp_leases = false
283
+ rescue
284
+ # assume some other odd exception.
285
+ end
286
+
287
+ # if ruby-libvirt not compiled with support, or remote library is
288
+ # too old (must be newer than 1.2.8), then use old fallback
289
+ if not has_dhcp_leases or service.libversion() < 1002008
290
+ addresses_method = self.method(:addresses_ip_command)
291
+ end
292
+
293
+ # replace current definition for this instance with correct one for
294
+ # detected libvirt to perform check once for connection
295
+ (class << self; self; end).class_eval do
296
+ define_method(:addresses, addresses_method)
297
+ end
298
+ addresses(service_arg, options)
299
+ end
300
+
301
+ def ssh_ip_command(ip_command, uri)
302
+ # Retrieve the parts we need from the service to setup our ssh options
303
+ user=uri.user #could be nil
304
+ host=uri.host
305
+ keyfile=uri.keyfile
306
+ port=uri.port
307
+
308
+ # Setup the options
309
+ ssh_options={}
310
+ ssh_options[:keys]=[ keyfile ] unless keyfile.nil?
311
+ ssh_options[:port]=port unless keyfile.nil?
312
+ ssh_options[:paranoid]=true if uri.no_verify?
313
+
314
+ begin
315
+ result=Fog::SSH.new(host, user, ssh_options).run(ip_command)
316
+ rescue Errno::ECONNREFUSED
317
+ raise Fog::Errors::Error.new("Connection was refused to host #{host} to retrieve the ip_address for #{mac}")
318
+ rescue Net::SSH::AuthenticationFailed
319
+ raise Fog::Errors::Error.new("Error authenticating over ssh to host #{host} and user #{user}")
320
+ end
321
+
322
+ # Check for a clean exit code
323
+ if result.first.status == 0
324
+ return result.first.stdout.strip
325
+ else
326
+ # We got a failure executing the command
327
+ raise Fog::Errors::Error.new("The command #{ip_command} failed to execute with a clean exit code")
328
+ end
329
+ end
330
+
331
+ def local_ip_command(ip_command)
332
+ # Execute the ip_command locally
333
+ # Initialize empty ip_address string
334
+ ip_address=""
335
+
336
+ IO.popen("#{ip_command}") do |p|
337
+ p.each_line do |l|
338
+ ip_address+=l
339
+ end
340
+ status=Process.waitpid2(p.pid)[1].exitstatus
341
+ if status!=0
342
+ raise Fog::Errors::Error.new("The command #{ip_command} failed to execute with a clean exit code")
343
+ end
344
+ end
345
+
346
+ #Strip any new lines from the string
347
+ ip_address.chomp
348
+ end
349
+
350
+ # This retrieves the ip address of the mac address using ip_command
262
351
  # It returns an array of public and private ip addresses
263
352
  # Currently only one ip address is returned, but in the future this could be multiple
264
353
  # if the server has multiple network interface
265
- def addresses(service_arg=service, options={})
354
+ def addresses_ip_command(service_arg=service, options={})
355
+ mac=self.mac
356
+
357
+ # Aug 24 17:34:41 juno arpwatch: new station 10.247.4.137 52:54:00:88:5a:0a eth0.4
358
+ # Aug 24 17:37:19 juno arpwatch: changed ethernet address 10.247.4.137 52:54:00:27:33:00 (52:54:00:88:5a:0a) eth0.4
359
+ # Check if another ip_command string was provided
360
+ ip_command_global=service_arg.ip_command.nil? ? 'grep $mac /var/log/arpwatch.log|sed -e "s/new station//"|sed -e "s/changed ethernet address//g" |sed -e "s/reused old ethernet //" |tail -1 |cut -d ":" -f 4-| cut -d " " -f 3' : service_arg.ip_command
361
+ ip_command_local=options[:ip_command].nil? ? ip_command_global : options[:ip_command]
362
+
363
+ ip_command="mac=#{mac}; server_name=#{name}; "+ip_command_local
364
+
365
+ ip_address=nil
366
+
367
+ if service_arg.uri.ssh_enabled?
368
+ ip_address=ssh_ip_command(ip_command, service_arg.uri)
369
+ else
370
+ # It's not ssh enabled, so we assume it is
371
+ if service_arg.uri.transport=="tls"
372
+ raise Fog::Errors::Error.new("TlS remote transport is not currently supported, only ssh")
373
+ end
374
+ ip_address=local_ip_command(ip_command)
375
+ end
376
+
377
+ # The Ip-address command has been run either local or remote now
378
+
379
+ if ip_address==""
380
+ #The grep didn't find an ip address result"
381
+ ip_address=nil
382
+ else
383
+ # To be sure that the command didn't return another random string
384
+ # We check if the result is an actual ip-address
385
+ # otherwise we return nil
386
+ unless ip_address=~/^(\d{1,3}\.){3}\d{1,3}$/
387
+ raise Fog::Errors::Error.new(
388
+ "The result of #{ip_command} does not have valid ip-address format\n"+
389
+ "Result was: #{ip_address}\n"
390
+ )
391
+ end
392
+ end
393
+
394
+ return { :public => [ip_address], :private => [ip_address]}
395
+ end
396
+
397
+ # This retrieves the ip address of the mac address using dhcp_leases
398
+ # It returns an array of public and private ip addresses
399
+ # Currently only one ip address is returned, but in the future this could be multiple
400
+ # if the server has multiple network interface
401
+ def addresses_dhcp(service_arg=service, options={})
266
402
  mac=self.mac
267
403
 
268
404
  ip_address = nil
@@ -343,13 +479,17 @@ module Fog
343
479
  :os_type => "hvm",
344
480
  :arch => "x86_64",
345
481
  :domain_type => "kvm",
482
+ :autostart => false,
346
483
  :iso_dir => default_iso_dir,
347
484
  :network_interface_type => "network",
348
485
  :network_nat_network => "default",
349
486
  :network_bridge_name => "br0",
350
487
  :boot_order => %w[hd cdrom network],
351
488
  :display => default_display,
352
- :cpu => {}
489
+ :cpu => {},
490
+ :hugepages => false,
491
+ :guest_agent => true,
492
+ :virtio_rng => {},
353
493
  }
354
494
  end
355
495