fog-libvirt 0.9.0 → 0.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c5d75c89309efc19a2a8e70db7f95dc754fe127358089bd8ebe0cd0f2ecf896
4
- data.tar.gz: 2270fa713728f8824dffc45dca9344c1b244feeb3add91130d26fff493c00f18
3
+ metadata.gz: c7115a1bb2c554de544d464049d48c6a15f2b39499a729180ab0e37bab55d3f3
4
+ data.tar.gz: c38e323849b149376f72edacd821788aa9df923d7bd4ca334dd0792a1ade5fab
5
5
  SHA512:
6
- metadata.gz: 1834c04363667e8bb7632055010f7544ec72aec0f49254e8c708bc1b73c0d731aa6474acd01644de9fa35d43491bfd5d7e60d3a6636d6301ba2446f6470b80cd
7
- data.tar.gz: f6834023432a36058571b78e8c1b8f5ec5a5043990d8f738cbf7c986a9038a8a723415214fa702bc7ad09c83fbd119b961ea4ee5c0bc6ebd328b0ab744f12158
6
+ metadata.gz: dc0dd759cec37c6e89557dec04bc05a679150183474cf589509cf0a36d51a129bcfd521b0ecbb2682b8eb76ef1d2bd25f81bff8e3117ba35961fd8d8f2d1a285
7
+ data.tar.gz: f7f1661e4e48a4fdaa68475ca34eb6f35bd346981891ea7cdb49a4b05d236b2886bf125ffb51ec2538277d3b7fe7584f3338eea30e0c4011a4712290d7370533
data/README.md CHANGED
@@ -18,6 +18,60 @@ $ sudo gem install fog-libvirt
18
18
 
19
19
  ## Usage
20
20
 
21
+ Example REPL session:
22
+
23
+ ```
24
+ >> require "fog/libvirt"
25
+ => true
26
+ >> compute = Fog::Compute.new(provider: :libvirt, libvirt_uri: "qemu:///session")
27
+ => #<Fog::Libvirt::Compute::Real:46980 @uri=#<Fog::Libvirt::Util::URI:0x0000000002def920 @parsed_uri=#<URI::Generic qemu:/session>, @uri="qemu:///session"...
28
+ >> server = compute.servers.create(name: "test")
29
+ =>
30
+ <Fog::Libvirt::Compute::Server
31
+ id="bbb663e4-723b-4165-bc29-c77b54b12bca",
32
+ cpus=1,
33
+ cputime=0,
34
+ os_type="hvm",
35
+ memory_size=262144,
36
+ max_memory_size=262144,
37
+ name="test",
38
+ arch="x86_64",
39
+ persistent=true,
40
+ domain_type="kvm",
41
+ uuid="bbb663e4-723b-4165-bc29-c77b54b12bca",
42
+ autostart=false,
43
+ nics=[ <Fog::Libvirt::Compute::Nic
44
+ mac="52:54:00:d1:18:23",
45
+ id=nil,
46
+ type="network",
47
+ network="default",
48
+ bridge=nil,
49
+ model="virtio"
50
+ >],
51
+ volumes=[ <Fog::Libvirt::Compute::Volume
52
+ id=nil,
53
+ pool_name="1Download",
54
+ key=nil,
55
+ name="test.img",
56
+ path="/home/lzap/1Download/test.img",
57
+ capacity="10G",
58
+ allocation="1G",
59
+ owner=nil,
60
+ group=nil,
61
+ format_type="raw",
62
+ backing_volume=nil
63
+ >],
64
+ active=false,
65
+ boot_order=["hd", "cdrom", "network"],
66
+ display={:type=>"vnc", :port=>"-1", :listen=>"127.0.0.1"},
67
+ cpu={},
68
+ hugepages=false,
69
+ guest_agent=true,
70
+ virtio_rng={},
71
+ state="shutoff"
72
+ >
73
+ ```
74
+
21
75
  See [README.md](https://github.com/fog/fog-libvirt/blob/master/lib/fog/libvirt/models/compute/README.md).
22
76
 
23
77
  ## Contributing
data/fog-libvirt.gemspec CHANGED
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.add_development_dependency("shindo", "~> 0.3.4")
41
41
  s.add_development_dependency("simplecov")
42
42
  s.add_development_dependency("yard")
43
- s.add_development_dependency("mocha", "~> 1.13.0")
43
+ s.add_development_dependency("mocha", "~> 1.15.0")
44
44
 
45
45
  # Let's not ship dot files and gemfiles
46
46
  git_files = `git ls-files`.split("\n")
@@ -90,9 +90,13 @@ module Fog
90
90
  volumes.first.path if volumes and volumes.first
91
91
  end
92
92
 
93
- def destroy(options={ :destroy_volumes => false})
93
+ def destroy(options={ :destroy_volumes => false, :flags => 0 })
94
94
  poweroff unless stopped?
95
- service.vm_action(uuid, :undefine)
95
+ if options[:flags].zero?
96
+ service.vm_action(uuid, :undefine)
97
+ else
98
+ service.vm_action(uuid, :undefine, options[:flags])
99
+ end
96
100
  volumes.each { |vol| vol.destroy } if options[:destroy_volumes]
97
101
  true
98
102
  end
@@ -407,13 +411,11 @@ module Fog
407
411
  ip_address = nil
408
412
  nic = self.nics.find {|nic| nic.mac==mac}
409
413
  if !nic.nil?
410
- service.networks.all.each do |net|
411
- if net.name == nic.network
412
- leases = net.dhcp_leases(mac, 0)
413
- # Assume the lease expiring last is the current IP address
414
- ip_address = leases.sort_by { |lse| lse["expirytime"] }.last["ipaddr"] if !leases.empty?
415
- break
416
- end
414
+ net = service.networks.all(:name => nic.network).first
415
+ if !net.nil?
416
+ leases = net.dhcp_leases(mac, 0)
417
+ # Assume the lease expiring last is the current IP address
418
+ ip_address = leases.sort_by { |lse| lse["expirytime"] }.last["ipaddr"] if !leases.empty?
417
419
  end
418
420
  end
419
421
 
@@ -20,8 +20,12 @@
20
20
  <path><%= backing_volume.path %></path>
21
21
  <format type="<%= backing_volume.format_type %>"/>
22
22
  <permissions>
23
+ <% if owner -%>
23
24
  <owner><%= owner %></owner>
25
+ <% end -%>
26
+ <% if group -%>
24
27
  <group><%= group %></group>
28
+ <% end -%>
25
29
  <mode>0744</mode>
26
30
  <label>virt_image_t</label>
27
31
  </permissions>
@@ -66,7 +66,7 @@ module Fog
66
66
  end
67
67
 
68
68
  def domain_to_attributes(dom)
69
- states= %w(nostate running blocked paused shutting-down shutoff crashed)
69
+ states= %w(nostate running blocked paused shutting-down shutoff crashed pmsuspended)
70
70
 
71
71
  begin
72
72
  {
@@ -44,8 +44,8 @@ module Fog
44
44
  end
45
45
 
46
46
  class Mock
47
- def list_networks(filters={ })
48
- [ {
47
+ def list_networks(filter={ })
48
+ networks = [ {
49
49
  :uuid => 'a29146ea-39b2-412d-8f53-239eef117a32',
50
50
  :name => 'net1',
51
51
  :bridge_name => 'virbr0'
@@ -56,6 +56,16 @@ module Fog
56
56
  :bridge_name => 'virbr1'
57
57
  }
58
58
  ]
59
+ return networks if filter.empty?
60
+
61
+ case filter.keys.first
62
+ when :uuid
63
+ [networks.find(:uuid => filter[:uuid]).first]
64
+ when :name
65
+ [networks.find(:name => filter[:name]).first]
66
+ else
67
+ networks
68
+ end
59
69
  end
60
70
  end
61
71
  end
@@ -5,19 +5,22 @@ module Fog
5
5
  def list_pools(filter = { })
6
6
  data=[]
7
7
  if filter.key?(:name)
8
- data << find_pool_by_name(filter[:name])
8
+ data << find_pool_by_name(filter[:name], filter[:include_inactive])
9
9
  elsif filter.key?(:uuid)
10
- data << find_pool_by_uuid(filter[:uuid])
10
+ data << find_pool_by_uuid(filter[:uuid], filter[:include_inactive])
11
11
  else
12
12
  (client.list_storage_pools + client.list_defined_storage_pools).each do |name|
13
- data << find_pool_by_name(name)
13
+ data << find_pool_by_name(name, filter[:include_inactive])
14
14
  end
15
15
  end
16
16
  data.compact
17
17
  end
18
18
 
19
19
  private
20
- def pool_to_attributes(pool)
20
+
21
+ private_class_method def self.pool_to_attributes(pool, include_inactive = nil)
22
+ return nil unless pool.active? || include_inactive
23
+
21
24
  states=[:inactive, :building, :running, :degrated, :inaccessible]
22
25
  {
23
26
  :uuid => pool.uuid,
@@ -27,19 +30,19 @@ module Fog
27
30
  :name => pool.name,
28
31
  :allocation => pool.info.allocation,
29
32
  :capacity => pool.info.capacity,
30
- :num_of_volumes => pool.num_of_volumes,
33
+ :num_of_volumes => pool.active? ? pool.num_of_volumes : nil,
31
34
  :state => states[pool.info.state]
32
35
  }
33
36
  end
34
37
 
35
- def find_pool_by_name name
36
- pool_to_attributes(client.lookup_storage_pool_by_name(name))
38
+ def find_pool_by_name name, include_inactive
39
+ pool_to_attributes(client.lookup_storage_pool_by_name(name), include_inactive)
37
40
  rescue ::Libvirt::RetrieveError
38
41
  nil
39
42
  end
40
43
 
41
- def find_pool_by_uuid uuid
42
- pool_to_attributes(client.lookup_storage_pool_by_uuid(uuid))
44
+ def find_pool_by_uuid uuid, include_inactive
45
+ pool_to_attributes(client.lookup_storage_pool_by_uuid(uuid), include_inactive)
43
46
  rescue ::Libvirt::RetrieveError
44
47
  nil
45
48
  end
@@ -2,15 +2,15 @@ module Fog
2
2
  module Libvirt
3
3
  class Compute
4
4
  class Real
5
- def vm_action(uuid, action)
5
+ def vm_action(uuid, action, *params)
6
6
  domain = client.lookup_domain_by_uuid(uuid)
7
- domain.send(action)
7
+ domain.send(action, *params)
8
8
  true
9
9
  end
10
10
  end
11
11
 
12
12
  class Mock
13
- def vm_action(uuid, action)
13
+ def vm_action(uuid, action, *params)
14
14
  true
15
15
  end
16
16
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Libvirt
3
- VERSION = '0.9.0'
3
+ VERSION = '0.10.0'
4
4
  end
5
5
  end
@@ -0,0 +1,71 @@
1
+ class FakePool < Fog::Model
2
+ # Fake pool object to allow exercising the internal parsing of pools
3
+ # returned by the client queries
4
+ identity :uuid
5
+
6
+ attribute :persistent
7
+ attribute :autostart
8
+ attribute :active
9
+ attribute :name
10
+ attribute :num_of_volumes
11
+ attr_reader :info
12
+
13
+ class FakeInfo < Fog::Model
14
+ attribute :allocation
15
+ attribute :capacity
16
+ attribute :state
17
+ end
18
+
19
+ def initialize(attributes = {})
20
+ @info = FakeInfo.new(attributes.dup.delete(:info))
21
+ super(attributes)
22
+ end
23
+
24
+ def active?
25
+ active
26
+ end
27
+
28
+ def autostart?
29
+ autostart
30
+ end
31
+
32
+ def persistent?
33
+ persistent
34
+ end
35
+ end
36
+
37
+ Shindo.tests("Fog::Compute[:libvirt] | list_pools request", 'libvirt') do
38
+
39
+ compute = Fog::Compute[:libvirt]
40
+
41
+ tests("Lists Pools") do
42
+ response = compute.list_pools
43
+ test("should be an array") { response.kind_of? Array }
44
+ test("should have two pools") { response.length == 2 }
45
+ end
46
+
47
+ tests("Handle Inactive Pools") do
48
+ inactive_pool = {
49
+ :uuid => 'pool.uuid',
50
+ :persistent => true,
51
+ :autostart => true,
52
+ :active => false,
53
+ :name => 'inactive_pool1',
54
+ :info => {
55
+ :allocation => 123456789,
56
+ :capacity => 123456789,
57
+ :state => 2 # running
58
+ },
59
+ :num_of_volumes => 3
60
+ }
61
+
62
+ response = ::Fog::Libvirt::Compute::Real.send(:pool_to_attributes, FakePool.new(inactive_pool), true)
63
+
64
+ test("should be hash of attributes") { response.kind_of? Hash }
65
+
66
+ response = ::Fog::Libvirt::Compute::Real.send(:pool_to_attributes, FakePool.new(inactive_pool))
67
+
68
+ test("should be nil") { response.nil? }
69
+
70
+ end
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-libvirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus (Wesley Beary)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-16 00:00:00.000000000 Z
11
+ date: 2022-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core
@@ -212,14 +212,14 @@ dependencies:
212
212
  requirements:
213
213
  - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: 1.13.0
215
+ version: 1.15.0
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
- version: 1.13.0
222
+ version: 1.15.0
223
223
  description: This library can be used as a module for 'fog' or as standalone libvirt
224
224
  provider.
225
225
  email: geemus@gmail.com
@@ -306,6 +306,7 @@ files:
306
306
  - tests/libvirt/requests/compute/create_domain_tests.rb
307
307
  - tests/libvirt/requests/compute/define_domain_tests.rb
308
308
  - tests/libvirt/requests/compute/dhcp_leases_tests.rb
309
+ - tests/libvirt/requests/compute/list_pools_tests.rb
309
310
  - tests/libvirt/requests/compute/update_autostart_tests.rb
310
311
  - tests/libvirt/requests/compute/update_display.rb
311
312
  homepage: http://github.com/fog/fog-libvirt
@@ -328,7 +329,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
328
329
  - !ruby/object:Gem::Version
329
330
  version: '0'
330
331
  requirements: []
331
- rubygems_version: 3.2.15
332
+ rubygems_version: 3.3.7
332
333
  signing_key:
333
334
  specification_version: 2
334
335
  summary: Module for the 'fog' gem to support libvirt
@@ -354,5 +355,6 @@ test_files:
354
355
  - tests/libvirt/requests/compute/create_domain_tests.rb
355
356
  - tests/libvirt/requests/compute/define_domain_tests.rb
356
357
  - tests/libvirt/requests/compute/dhcp_leases_tests.rb
358
+ - tests/libvirt/requests/compute/list_pools_tests.rb
357
359
  - tests/libvirt/requests/compute/update_autostart_tests.rb
358
360
  - tests/libvirt/requests/compute/update_display.rb