fog-libvirt-csem 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTORS.md +24 -0
  3. data/Gemfile +9 -0
  4. data/LICENSE.md +20 -0
  5. data/README.md +83 -0
  6. data/Rakefile +127 -0
  7. data/fog-libvirt-csem.gemspec +49 -0
  8. data/lib/fog/bin/libvirt.rb +58 -0
  9. data/lib/fog/libvirt/compute.rb +140 -0
  10. data/lib/fog/libvirt/models/compute/README.md +92 -0
  11. data/lib/fog/libvirt/models/compute/interface.rb +25 -0
  12. data/lib/fog/libvirt/models/compute/interfaces.rb +20 -0
  13. data/lib/fog/libvirt/models/compute/network.rb +33 -0
  14. data/lib/fog/libvirt/models/compute/networks.rb +20 -0
  15. data/lib/fog/libvirt/models/compute/nic.rb +50 -0
  16. data/lib/fog/libvirt/models/compute/nics.rb +12 -0
  17. data/lib/fog/libvirt/models/compute/node.rb +29 -0
  18. data/lib/fog/libvirt/models/compute/nodes.rb +20 -0
  19. data/lib/fog/libvirt/models/compute/pool.rb +84 -0
  20. data/lib/fog/libvirt/models/compute/pools.rb +20 -0
  21. data/lib/fog/libvirt/models/compute/server.rb +514 -0
  22. data/lib/fog/libvirt/models/compute/servers.rb +21 -0
  23. data/lib/fog/libvirt/models/compute/templates/network.xml.erb +6 -0
  24. data/lib/fog/libvirt/models/compute/templates/pool.xml.erb +6 -0
  25. data/lib/fog/libvirt/models/compute/templates/server.xml.erb +155 -0
  26. data/lib/fog/libvirt/models/compute/templates/volume.xml.erb +30 -0
  27. data/lib/fog/libvirt/models/compute/util/uri.rb +138 -0
  28. data/lib/fog/libvirt/models/compute/util/util.rb +32 -0
  29. data/lib/fog/libvirt/models/compute/volume.rb +129 -0
  30. data/lib/fog/libvirt/models/compute/volumes.rb +20 -0
  31. data/lib/fog/libvirt/requests/compute/clone_volume.rb +18 -0
  32. data/lib/fog/libvirt/requests/compute/create_domain.rb +17 -0
  33. data/lib/fog/libvirt/requests/compute/create_volume.rb +16 -0
  34. data/lib/fog/libvirt/requests/compute/define_domain.rb +17 -0
  35. data/lib/fog/libvirt/requests/compute/define_pool.rb +16 -0
  36. data/lib/fog/libvirt/requests/compute/destroy_interface.rb +18 -0
  37. data/lib/fog/libvirt/requests/compute/destroy_network.rb +17 -0
  38. data/lib/fog/libvirt/requests/compute/dhcp_leases.rb +37 -0
  39. data/lib/fog/libvirt/requests/compute/get_node_info.rb +37 -0
  40. data/lib/fog/libvirt/requests/compute/libversion.rb +18 -0
  41. data/lib/fog/libvirt/requests/compute/list_domains.rb +128 -0
  42. data/lib/fog/libvirt/requests/compute/list_interfaces.rb +57 -0
  43. data/lib/fog/libvirt/requests/compute/list_networks.rb +63 -0
  44. data/lib/fog/libvirt/requests/compute/list_pool_volumes.rb +19 -0
  45. data/lib/fog/libvirt/requests/compute/list_pools.rb +71 -0
  46. data/lib/fog/libvirt/requests/compute/list_volumes.rb +106 -0
  47. data/lib/fog/libvirt/requests/compute/mock_files/domain.xml +40 -0
  48. data/lib/fog/libvirt/requests/compute/pool_action.rb +19 -0
  49. data/lib/fog/libvirt/requests/compute/update_autostart.rb +18 -0
  50. data/lib/fog/libvirt/requests/compute/update_display.rb +36 -0
  51. data/lib/fog/libvirt/requests/compute/upload_volume.rb +31 -0
  52. data/lib/fog/libvirt/requests/compute/vm_action.rb +19 -0
  53. data/lib/fog/libvirt/requests/compute/volume_action.rb +18 -0
  54. data/lib/fog/libvirt/version.rb +5 -0
  55. data/lib/fog/libvirt.rb +16 -0
  56. data/minitests/server/server_test.rb +64 -0
  57. data/minitests/server/user_data_iso_test.rb +77 -0
  58. data/minitests/test_helper.rb +18 -0
  59. data/tests/helper.rb +17 -0
  60. data/tests/helpers/formats_helper.rb +100 -0
  61. data/tests/helpers/formats_helper_tests.rb +107 -0
  62. data/tests/helpers/mock_helper.rb +14 -0
  63. data/tests/helpers/succeeds_helper.rb +9 -0
  64. data/tests/libvirt/compute_tests.rb +19 -0
  65. data/tests/libvirt/models/compute/interface_tests.rb +27 -0
  66. data/tests/libvirt/models/compute/interfaces_tests.rb +14 -0
  67. data/tests/libvirt/models/compute/network_tests.rb +31 -0
  68. data/tests/libvirt/models/compute/networks_tests.rb +13 -0
  69. data/tests/libvirt/models/compute/nic_tests.rb +31 -0
  70. data/tests/libvirt/models/compute/nics_tests.rb +10 -0
  71. data/tests/libvirt/models/compute/pool_tests.rb +27 -0
  72. data/tests/libvirt/models/compute/pools_tests.rb +13 -0
  73. data/tests/libvirt/models/compute/server_tests.rb +63 -0
  74. data/tests/libvirt/models/compute/servers_tests.rb +14 -0
  75. data/tests/libvirt/models/compute/volume_tests.rb +38 -0
  76. data/tests/libvirt/models/compute/volumes_tests.rb +15 -0
  77. data/tests/libvirt/requests/compute/create_domain_tests.rb +21 -0
  78. data/tests/libvirt/requests/compute/define_domain_tests.rb +11 -0
  79. data/tests/libvirt/requests/compute/dhcp_leases_tests.rb +15 -0
  80. data/tests/libvirt/requests/compute/update_autostart_tests.rb +12 -0
  81. data/tests/libvirt/requests/compute/update_display.rb +13 -0
  82. metadata +335 -0
@@ -0,0 +1,33 @@
1
+ require 'fog/core/model'
2
+ require 'fog/libvirt/models/compute/util/util'
3
+
4
+ module Fog
5
+ module Libvirt
6
+ class Compute
7
+ class Network < Fog::Model
8
+ include Fog::Libvirt::Util
9
+
10
+ identity :uuid
11
+ attribute :name
12
+ attribute :bridge_name
13
+ attribute :xml
14
+
15
+ def initialize(attributes = {})
16
+ super
17
+ end
18
+
19
+ def dhcp_leases(mac, flags = 0)
20
+ service.dhcp_leases(uuid, mac, flags)
21
+ end
22
+
23
+ def save
24
+ raise Fog::Errors::Error.new('Creating a new network is not yet implemented. Contributions welcome!')
25
+ end
26
+
27
+ def shutdown
28
+ service.destroy_network(uuid)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,20 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/libvirt/models/compute/network'
3
+
4
+ module Fog
5
+ module Libvirt
6
+ class Compute
7
+ class Networks < Fog::Collection
8
+ model Fog::Libvirt::Compute::Network
9
+
10
+ def all(filter={})
11
+ load(service.list_networks(filter))
12
+ end
13
+
14
+ def get(uuid)
15
+ self.all(:uuid => uuid).first
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,50 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Libvirt
5
+ class Compute
6
+ class Nic < Fog::Model
7
+ identity :mac
8
+ attribute :id
9
+ attribute :type
10
+ attribute :network
11
+ attribute :bridge
12
+ attribute :model
13
+
14
+ attr_accessor :server
15
+
16
+ TYPES = ["network", "bridge", "user"]
17
+
18
+ def new?
19
+ mac.nil?
20
+ end
21
+
22
+ def initialize attributes
23
+ super defaults.merge(attributes)
24
+ raise Fog::Errors::Error.new("#{type} is not a supported nic type") if new? && !TYPES.include?(type)
25
+ end
26
+
27
+ def save
28
+ raise Fog::Errors::Error.new('Creating a new nic is not yet implemented. Contributions welcome!')
29
+ #requires :server
30
+ #service.attach_nic(domain , self)
31
+ end
32
+
33
+ def destroy
34
+ raise Fog::Errors::Error.new('Destroying an interface is not yet implemented. Contributions welcome!')
35
+ #requires :server
36
+ ##detach the nic
37
+ #service.detach_nic(domain, mac)
38
+ end
39
+
40
+ private
41
+ def defaults
42
+ {
43
+ :type => "bridge",
44
+ :model => "virtio"
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,12 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/libvirt/models/compute/nic'
3
+
4
+ module Fog
5
+ module Libvirt
6
+ class Compute
7
+ class Nics < Fog::Collection
8
+ model Fog::Libvirt::Compute::Nic
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Libvirt
5
+ class Compute
6
+ class Node < Fog::Model
7
+ identity :uuid
8
+
9
+ attribute :model
10
+ attribute :memory
11
+ attribute :cpus
12
+ attribute :mhz
13
+ attribute :nodes
14
+ attribute :sockets
15
+ attribute :cores
16
+ attribute :threads
17
+ attribute :type
18
+ attribute :version
19
+ attribute :uri
20
+ attribute :node_free_memory
21
+ attribute :max_vcpus
22
+ attribute :manufacturer
23
+ attribute :product
24
+ attribute :serial
25
+ attribute :hostname
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/libvirt/models/compute/node'
3
+
4
+ module Fog
5
+ module Libvirt
6
+ class Compute
7
+ class Nodes < Fog::Collection
8
+ model Fog::Libvirt::Compute::Node
9
+
10
+ def all(filter={ })
11
+ load(service.get_node_info)
12
+ end
13
+
14
+ def get
15
+ all.first
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,84 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Libvirt
5
+ class Compute
6
+ class Pool < Fog::Model
7
+ attr_reader :xml
8
+
9
+ identity :uuid
10
+
11
+ attribute :persistent
12
+ attribute :autostart
13
+ attribute :active
14
+ attribute :name
15
+ attribute :allocation
16
+ attribute :capacity
17
+ attribute :num_of_volumes
18
+ attribute :state
19
+
20
+ def initialize(attributes={} )
21
+ # Can be created by passing in XML
22
+ @xml = attributes.delete(:xml)
23
+ super(attributes)
24
+ end
25
+
26
+ def save
27
+ raise Fog::Errors::Error.new('Creating a new pool requires proper xml') unless xml
28
+ self.uuid = (persistent ? service.define_pool(xml) : service.create_pool(xml)).uuid
29
+ reload
30
+ end
31
+
32
+ # Start the pool = make it active
33
+ # Performs a libvirt create (= start)
34
+ def start
35
+ service.pool_action uuid, :create
36
+ end
37
+
38
+ # Stop the pool = make it non-active
39
+ # Performs a libvirt destroy (= stop)
40
+ def stop
41
+ service.pool_action uuid, :destroy
42
+ end
43
+
44
+ # Shuts down the pool
45
+ def shutdown
46
+ stop
47
+ end
48
+
49
+ # Build this storage pool
50
+ def build
51
+ service.pool_action uuid, :build
52
+ end
53
+
54
+ # Destroys the storage pool
55
+ def destroy
56
+ # Shutdown pool if active
57
+ service.pool_action uuid, :destroy if active?
58
+ # If this is a persistent domain we need to undefine it
59
+ service.pool_action uuid, :undefine if persistent?
60
+ end
61
+
62
+ # Is the pool active or not?
63
+ def active?
64
+ active
65
+ end
66
+
67
+ # Will the pool autostart or not?
68
+ def auto_start?
69
+ autostart
70
+ end
71
+
72
+ # Is the pool persistent or not?
73
+ def persistent?
74
+ persistent
75
+ end
76
+
77
+ # Retrieves the volumes of this pool
78
+ def volumes
79
+ service.list_pool_volumes uuid
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,20 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/libvirt/models/compute/pool'
3
+
4
+ module Fog
5
+ module Libvirt
6
+ class Compute
7
+ class Pools < Fog::Collection
8
+ model Fog::Libvirt::Compute::Pool
9
+
10
+ def all(filter = {})
11
+ load(service.list_pools(filter))
12
+ end
13
+
14
+ def get(uuid)
15
+ self.all(:uuid => uuid).first
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end