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,155 @@
1
+ <domain type='<%= domain_type %>'>
2
+ <name><%= name %></name>
3
+ <memory><%= memory_size %></memory>
4
+ <% if hugepages -%>
5
+ <memoryBacking>
6
+ <hugepages/>
7
+ </memoryBacking>
8
+ <% end -%>
9
+ <vcpu><%= cpus %></vcpu>
10
+ <os>
11
+ <type arch='<%= arch %>'><%= os_type %></type>
12
+ <% boot_order.each do |dev| -%>
13
+ <boot dev='<%= dev %>'/>
14
+ <% end -%>
15
+ </os>
16
+ <features>
17
+ <acpi/>
18
+ <apic/>
19
+ <pae/>
20
+ </features>
21
+ <% if !cpu.empty? -%>
22
+ <% if cpu[:mode] -%>
23
+ <cpu mode='<%= cpu[:mode] %>'>
24
+ <% else -%>
25
+ <cpu>
26
+ <% end -%>
27
+ <%
28
+ fallback = 'allow'
29
+ model = ''
30
+ if cpu[:model]
31
+ fallback = cpu[:model][:fallback] if cpu[:model][:fallback]
32
+ model = cpu[:model][:name] if cpu[:model][:name]
33
+ end
34
+ -%>
35
+ <model fallback='<%= fallback %>'><%= model %></model>
36
+ </cpu>
37
+ <% end -%>
38
+ <clock offset='utc'/>
39
+ <devices>
40
+ <% args = {}
41
+ if File.file?('/etc/foreman/ceph.conf')
42
+ File.readlines('/etc/foreman/ceph.conf').each do |line|
43
+ pair = line.strip.split("=")
44
+ key = pair[0]
45
+ value = pair[1]
46
+ args[key] = value
47
+ end
48
+ end
49
+ %>
50
+ <% volumes.each do |vol| -%>
51
+ <% if File.file?('/etc/foreman/ceph.conf') && vol.pool_name.include?(args["libvirt_ceph_pool"]) %>
52
+ <disk type='network' device='disk'>
53
+ <driver name='qemu' type='<%= vol.format_type %>' cache='writeback' discard='unmap'/>
54
+ <source protocol='rbd' name='<%= vol.path %>'>
55
+ <% if args.key?("monitor") -%>
56
+ <% args["monitor"].split(",").each do |mon| %>
57
+ <host name='<%= mon %>' port='<%= args["port"] %>'/>
58
+ <% end %>
59
+ <% end %>
60
+ </source>
61
+ <auth username='<%= args["auth_username"] %>'>
62
+ <% if args.key?("auth_uuid") -%>
63
+ <secret type='ceph' uuid='<%= args["auth_uuid"] %>'/>
64
+ <% else -%>
65
+ <secret type='ceph' usage='<%= args["auth_usage"] %>'/>
66
+ <% end -%>
67
+ </auth>
68
+ <% if args['bus_type'] == 'virtio' %>
69
+ <target dev='vd<%= ('a'..'z').to_a[volumes.index(vol)] %>' bus='virtio'/>
70
+ <% else %>
71
+ <target dev='sd<%= ('a'..'z').to_a[volumes.index(vol)] %>' bus='scsi'/>
72
+ <% end %>
73
+ </disk>
74
+ <% else %>
75
+ <disk type='file' device='disk'>
76
+ <driver name='qemu' type='<%= vol.format_type %>'/>
77
+ <source file='<%= vol.path %>'/>
78
+ <%# we need to ensure a unique target dev -%>
79
+ <target dev='vd<%= ('a'..'z').to_a[volumes.index(vol)] %>' bus='virtio'/>
80
+ </disk>
81
+ <% end %>
82
+ <% end -%>
83
+ <% if iso_file -%>
84
+ <disk type='file' device='cdrom'>
85
+ <driver name='qemu' type='raw'/>
86
+ <source file='<%= "#{iso_dir}/#{iso_file}" %>'/>
87
+ <target dev='hdc' bus='ide'/>
88
+ <readonly/>
89
+ <address type='drive' controller='0' bus='1' unit='0'/>
90
+ </disk>
91
+ <% end -%>
92
+ <% nics.each do |nic| -%>
93
+ <interface type='<%= nic.type %>'>
94
+ <source <%= nic.type == 'bridge' ? "bridge='#{nic.bridge}'" : "network='#{nic.network}'" %> />
95
+ <model type='<%= nic.model %>'/>
96
+ </interface>
97
+ <% end -%>
98
+ <% if guest_agent -%>
99
+ <channel type='unix'>
100
+ <target type='virtio' name='org.qemu.guest_agent.0'/>
101
+ </channel>
102
+ <% end -%>
103
+ <rng model='virtio'>
104
+ <%
105
+ rng_backend_model = virtio_rng[:backend_model] ? virtio_rng[:backend_model] : 'random'
106
+ -%>
107
+ <% if virtio_rng[:backend_path] -%>
108
+ <backend model='<%= rng_backend_model %>'><%= virtio_rng[:backend_path] %></backend>
109
+ <% else -%>
110
+ <backend model='<%= rng_backend_model %>'/>
111
+ <% end -%>
112
+ </rng>
113
+ <% if arch == "s390x" -%>
114
+ <controller type="scsi" index="0" model="virtio-scsi"/>
115
+ <console type="pty">
116
+ <target type="sclp"/>
117
+ </console>
118
+ <memballoon model="virtio"/>
119
+ <% else -%>
120
+ <serial type='pty'>
121
+ <target port='0'/>
122
+ </serial>
123
+ <console type='pty'>
124
+ <target port='0'/>
125
+ </console>
126
+ <input type='tablet' bus='usb'/>
127
+ <input type='mouse' bus='ps2'/>
128
+ <% end -%>
129
+ <%
130
+ display_type = display[:type]
131
+
132
+ if display[:port].empty?
133
+ display_port = display[:port]
134
+ autoport = 'no'
135
+ else
136
+ display_port = '-1'
137
+ autoport = 'yes'
138
+ end
139
+
140
+ unless display[:listen].empty?
141
+ display_listen = "listen='#{display[:listen]}'"
142
+ end
143
+
144
+ unless display[:password].empty?
145
+ display_password = "passwd='#{display[:password]}'"
146
+ end
147
+ -%>
148
+ <% if arch != "s390x" -%>
149
+ <graphics type='<%= display_type %>' port='<%= display_port %>' autoport='<%= autoport %>' <%= display_listen %> <%= display_password %> />
150
+ <video>
151
+ <model type='cirrus' vram='9216' heads='1'/>
152
+ </video>
153
+ <% end -%>
154
+ </devices>
155
+ </domain>
@@ -0,0 +1,30 @@
1
+ <volume>
2
+ <name><%= name %></name>
3
+ <allocation unit="<%= split_size_unit(allocation)[1] %>"><%= split_size_unit(allocation)[0] %></allocation>
4
+ <capacity unit="<%= split_size_unit(capacity)[1] %>"><%= split_size_unit(capacity)[0] %></capacity>
5
+ <target>
6
+ <format type="<%= format_type %>"/>
7
+ <permissions>
8
+ <% if owner -%>
9
+ <owner><%= owner %></owner>
10
+ <% end -%>
11
+ <% if group -%>
12
+ <group><%= group %></group>
13
+ <% end -%>
14
+ <mode>0744</mode>
15
+ <label>virt_image_t</label>
16
+ </permissions>
17
+ </target>
18
+ <% if backing_volume -%>
19
+ <backingStore>
20
+ <path><%= backing_volume.path %></path>
21
+ <format type="<%= backing_volume.format_type %>"/>
22
+ <permissions>
23
+ <owner><%= owner %></owner>
24
+ <group><%= group %></group>
25
+ <mode>0744</mode>
26
+ <label>virt_image_t</label>
27
+ </permissions>
28
+ </backingStore>
29
+ <% end -%>
30
+ </volume>
@@ -0,0 +1,138 @@
1
+ require 'uri'
2
+ require 'cgi'
3
+
4
+ module Fog
5
+ module Libvirt
6
+ module Util
7
+ class URI
8
+ attr_reader :uri
9
+
10
+ def initialize(uri)
11
+ @parsed_uri=::URI.parse(uri)
12
+ @uri=uri
13
+ return self
14
+ end
15
+
16
+ # Transport will be part of the scheme
17
+ # The part after the plus sign
18
+ # f.i. qemu+ssh
19
+ def transport
20
+ scheme=@parsed_uri.scheme
21
+ return nil if scheme.nil?
22
+
23
+ return scheme.split(/\+/)[1]
24
+ end
25
+
26
+ def scheme
27
+ return @parsed_uri.scheme
28
+ end
29
+
30
+ def driver
31
+ scheme=@parsed_uri.scheme
32
+ return nil if scheme.nil?
33
+
34
+ return scheme.split(/\+/).first
35
+ end
36
+
37
+ def ssh_enabled?
38
+ if remote?
39
+ return transport.include?("ssh")
40
+ else
41
+ return false
42
+ end
43
+ end
44
+
45
+ def remote?
46
+ return !transport.nil?
47
+ end
48
+
49
+ def user
50
+ @parsed_uri.user
51
+ end
52
+
53
+ def host
54
+ @parsed_uri.host
55
+ end
56
+
57
+ def port
58
+ @parsed_uri.port
59
+ end
60
+
61
+ def password
62
+ @parsed_uri.password
63
+ end
64
+
65
+ def name
66
+ value("name")
67
+ end
68
+
69
+ def command
70
+ value("command")
71
+ end
72
+
73
+ def socket
74
+ value("socket")
75
+ end
76
+
77
+ def keyfile
78
+ value("keyfile")
79
+ end
80
+
81
+ def netcat
82
+ value("netcat")
83
+ end
84
+
85
+ def no_verify?
86
+ no_verify=value("no_verify")
87
+ return false if no_verify.nil?
88
+
89
+ if no_verify.to_s=="0"
90
+ return false
91
+ else
92
+ return true
93
+ end
94
+ end
95
+
96
+ def verify?
97
+ return !no_verify?
98
+ end
99
+
100
+ def no_tty?
101
+ no_tty=value("no_tty")
102
+
103
+ return false if no_tty.nil?
104
+
105
+ if no_tty=="0"
106
+ return false
107
+ else
108
+ return true
109
+ end
110
+ end
111
+
112
+ def tty?
113
+ return !no_tty?
114
+ end
115
+
116
+ def pkipath
117
+ value("pkipath")
118
+ end
119
+
120
+ # A libvirt URI allows you to specify extra params
121
+ # http://libvirt.org/remote.html
122
+ private
123
+ def value(name)
124
+ unless @parsed_uri.query.nil?
125
+ params=CGI.parse(@parsed_uri.query)
126
+ if params.key?(name)
127
+ return params[name].first
128
+ else
129
+ return nil
130
+ end
131
+ else
132
+ return nil
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,32 @@
1
+ require 'nokogiri'
2
+ require 'erb'
3
+ require 'ostruct'
4
+ require 'securerandom'
5
+
6
+ module Fog
7
+ module Libvirt
8
+ module Util
9
+ def xml_element(xml, path, attribute=nil)
10
+ xml = Nokogiri::XML(xml)
11
+ attribute.nil? ? (xml/path).first.text : (xml/path).first[attribute.to_sym]
12
+ end
13
+
14
+ def xml_elements(xml, path, attribute=nil)
15
+ xml = Nokogiri::XML(xml)
16
+ attribute.nil? ? (xml/path).map : (xml/path).map{|element| element[attribute.to_sym]}
17
+ end
18
+
19
+ def to_xml template_name = nil
20
+ # figure out our ERB template filename
21
+ erb = template_name || self.class.to_s.split("::").last.downcase
22
+ path = File.join(File.dirname(__FILE__), "..", "templates", "#{erb}.xml.erb")
23
+ template = File.read(path)
24
+ ERB.new(template, nil, '-').result(binding)
25
+ end
26
+
27
+ def randomized_name
28
+ "fog-#{(SecureRandom.random_number*10E14).to_i.round}"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,129 @@
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 Volume < Fog::Model
8
+ attr_reader :xml
9
+ include Fog::Libvirt::Util
10
+
11
+ identity :id, :aliases => 'key'
12
+
13
+ attribute :pool_name
14
+ attribute :key
15
+ attribute :name
16
+ attribute :path
17
+ attribute :capacity
18
+ attribute :allocation
19
+ attribute :owner
20
+ attribute :group
21
+ attribute :format_type
22
+ attribute :backing_volume
23
+
24
+ # Can be created by passing in :xml => "<xml to create volume>"
25
+ # A volume always belongs to a pool, :pool_name => "<name of pool>"
26
+ #
27
+ def initialize(attributes={ })
28
+ @xml = attributes.delete(:xml)
29
+ super(defaults.merge(attributes))
30
+
31
+ # We need a connection to calculate the pool_name
32
+ # This is why we do this after super
33
+ self.pool_name ||= default_pool_name
34
+ end
35
+
36
+ # Takes a pool and either :xml or other settings
37
+ def save
38
+ requires :pool_name
39
+
40
+ raise Fog::Errors::Error.new('Reserving an existing volume may create a duplicate') if key
41
+ @xml ||= to_xml
42
+ self.path = service.create_volume(pool_name, xml).path
43
+ end
44
+
45
+ # Destroy a volume
46
+ def destroy
47
+ service.volume_action key, :delete
48
+ end
49
+
50
+ # Wipes a volume , zeroes disk
51
+ def wipe
52
+ service.volume_action key, :wipe
53
+ end
54
+
55
+ # Clones this volume to the name provided
56
+ def clone(name)
57
+ new_volume = self.dup
58
+ new_volume.key = nil
59
+ new_volume.name = name
60
+ new_volume.save
61
+
62
+ new_volume.reload
63
+ end
64
+
65
+ def clone_volume(new_name)
66
+ requires :pool_name
67
+
68
+ new_volume = self.dup
69
+ new_volume.key = nil
70
+ new_volume.name = new_name
71
+ new_volume.path = service.clone_volume(pool_name, new_volume.to_xml, self.name).path
72
+
73
+ new_volume.reload
74
+ end
75
+
76
+ def upload_image(file_path)
77
+ requires :pool_name
78
+ service.upload_volume(pool_name, name, file_path)
79
+ end
80
+
81
+ private
82
+
83
+ def image_suffix
84
+ return "img" if format_type == "raw"
85
+ format_type
86
+ end
87
+
88
+ def randominzed_name
89
+ "#{super}.#{image_suffix}"
90
+ end
91
+
92
+ # Try to guess the default/first pool of no pool_name was specified
93
+ def default_pool_name
94
+ name = "default"
95
+ return name unless (service.pools.all(:name => name)).empty?
96
+
97
+ # we default to the first pool we find.
98
+ first_pool = service.pools.first
99
+
100
+ raise Fog::Errors::Error.new('No storage pools are defined') unless first_pool
101
+ first_pool.name
102
+ end
103
+
104
+ def defaults
105
+ {
106
+ :persistent => true,
107
+ :format_type => "raw",
108
+ :name => randomized_name,
109
+ :capacity => "10G",
110
+ :allocation => "1G",
111
+ :owner => nil,
112
+ :group => nil,
113
+ }
114
+ end
115
+
116
+ def split_size_unit(text)
117
+ if (text.kind_of? String) && (matcher = text.match(/(\d+)(.+)/))
118
+ size = matcher[1]
119
+ unit = matcher[2]
120
+ else
121
+ size = text.to_i
122
+ unit = "G"
123
+ end
124
+ [size, unit]
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,20 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/libvirt/models/compute/volume'
3
+
4
+ module Fog
5
+ module Libvirt
6
+ class Compute
7
+ class Volumes < Fog::Collection
8
+ model Fog::Libvirt::Compute::Volume
9
+
10
+ def all(filter = {})
11
+ load(service.list_volumes(filter))
12
+ end
13
+
14
+ def get(key)
15
+ self.all(:key => key).first
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Libvirt
3
+ class Compute
4
+ class Real
5
+ def clone_volume (pool_name, xml, name)
6
+ vol = client.lookup_storage_pool_by_name(pool_name).lookup_volume_by_name(name)
7
+ client.lookup_storage_pool_by_name(pool_name).create_vol_xml_from(xml, vol)
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def clone_volume(pool_name, xml, name)
13
+ Fog::Libvirt::Compute::Volume.new({:pool_name => pool_name, :xml => xml})
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Libvirt
3
+ class Compute
4
+ class Real
5
+ def create_domain(xml)
6
+ client.create_domain_xml(xml)
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def create_domain(xml)
12
+ ::Libvirt::Domain.new()
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module Fog
2
+ module Libvirt
3
+ class Compute
4
+ class Real
5
+ def create_volume(pool_name, xml)
6
+ client.lookup_storage_pool_by_name(pool_name).create_vol_xml(xml)
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def create_volume(pool_name, xml)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Libvirt
3
+ class Compute
4
+ class Real
5
+ def define_domain(xml)
6
+ client.define_domain_xml(xml)
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def define_domain(xml)
12
+ ::Libvirt::Domain.new()
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module Fog
2
+ module Libvirt
3
+ class Compute
4
+ class Real
5
+ def define_pool(xml)
6
+ client.define_storage_pool_xml(xml)
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def define_pool(xml)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Libvirt
3
+ class Compute
4
+ class Real
5
+ #shutdown the interface
6
+ def destroy_interface(uuid)
7
+ client.lookup_interface_by_uuid(uuid).destroy
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def destroy_interface(uuid)
13
+ true
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Libvirt
3
+ class Compute
4
+ class Real
5
+ def destroy_network(uuid)
6
+ client.lookup_network_by_uuid(uuid).destroy
7
+ end
8
+ end
9
+
10
+ class Mock
11
+ def destroy_network(uuid)
12
+ true
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ require 'socket'
2
+
3
+ module Fog
4
+ module Libvirt
5
+ class Compute
6
+ class Real
7
+ def dhcp_leases(uuid, mac, flags = 0)
8
+ client.lookup_network_by_uuid(uuid).dhcp_leases(mac, flags)
9
+ end
10
+ end
11
+
12
+ class Mock
13
+ def dhcp_leases(uuid, mac, flags = 0)
14
+ leases1 = {
15
+ 'aa:bb:cc:dd:ee:ff' => [
16
+ { 'type' => Socket::AF_INET, 'ipaddr' => '1.2.3.4', 'prefix' => 24, 'expirytime' => 5000 },
17
+ { 'type' => Socket::AF_INET, 'ipaddr' => '1.2.5.6', 'prefix' => 24, 'expirytime' => 5005 }
18
+ ]
19
+ }
20
+ leases2 = {
21
+ '99:88:77:66:55:44' => [
22
+ { 'type' => Socket::AF_INET, 'ipaddr' => '10.1.1.5', 'prefix' => 24, 'expirytime' => 50 }
23
+ ]
24
+ }
25
+ networks = {
26
+ # should match mock net uuid from list_networks.rb
27
+ 'a29146ea-39b2-412d-8f53-239eef117a32' => leases1,
28
+ 'fbd4ac68-cbea-4f95-86ed-22953fd92384' => leases2
29
+ }
30
+ if !networks[uuid].nil?
31
+ return networks[uuid][mac]
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end