fog-libvirt 0.0.1
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 +7 -0
- data/CONTRIBUTORS.md +23 -0
- data/Gemfile +9 -0
- data/LICENSE.md +20 -0
- data/README.md +29 -0
- data/Rakefile +122 -0
- data/fog-libvirt.gemspec +49 -0
- data/lib/fog/bin/libvirt.rb +58 -0
- data/lib/fog/libvirt/compute.rb +136 -0
- data/lib/fog/libvirt/models/compute/README.md +76 -0
- data/lib/fog/libvirt/models/compute/interface.rb +25 -0
- data/lib/fog/libvirt/models/compute/interfaces.rb +20 -0
- data/lib/fog/libvirt/models/compute/network.rb +29 -0
- data/lib/fog/libvirt/models/compute/networks.rb +20 -0
- data/lib/fog/libvirt/models/compute/nic.rb +50 -0
- data/lib/fog/libvirt/models/compute/nics.rb +12 -0
- data/lib/fog/libvirt/models/compute/node.rb +29 -0
- data/lib/fog/libvirt/models/compute/nodes.rb +20 -0
- data/lib/fog/libvirt/models/compute/pool.rb +84 -0
- data/lib/fog/libvirt/models/compute/pools.rb +20 -0
- data/lib/fog/libvirt/models/compute/server.rb +401 -0
- data/lib/fog/libvirt/models/compute/servers.rb +21 -0
- data/lib/fog/libvirt/models/compute/templates/network.xml.erb +6 -0
- data/lib/fog/libvirt/models/compute/templates/pool.xml.erb +6 -0
- data/lib/fog/libvirt/models/compute/templates/server.xml.erb +54 -0
- data/lib/fog/libvirt/models/compute/templates/volume.xml.erb +26 -0
- data/lib/fog/libvirt/models/compute/util/uri.rb +138 -0
- data/lib/fog/libvirt/models/compute/util/util.rb +32 -0
- data/lib/fog/libvirt/models/compute/volume.rb +122 -0
- data/lib/fog/libvirt/models/compute/volumes.rb +20 -0
- data/lib/fog/libvirt/requests/compute/clone_volume.rb +18 -0
- data/lib/fog/libvirt/requests/compute/create_domain.rb +17 -0
- data/lib/fog/libvirt/requests/compute/create_volume.rb +16 -0
- data/lib/fog/libvirt/requests/compute/define_domain.rb +17 -0
- data/lib/fog/libvirt/requests/compute/define_pool.rb +16 -0
- data/lib/fog/libvirt/requests/compute/destroy_interface.rb +18 -0
- data/lib/fog/libvirt/requests/compute/destroy_network.rb +17 -0
- data/lib/fog/libvirt/requests/compute/get_node_info.rb +37 -0
- data/lib/fog/libvirt/requests/compute/list_domains.rb +105 -0
- data/lib/fog/libvirt/requests/compute/list_interfaces.rb +57 -0
- data/lib/fog/libvirt/requests/compute/list_networks.rb +55 -0
- data/lib/fog/libvirt/requests/compute/list_pool_volumes.rb +19 -0
- data/lib/fog/libvirt/requests/compute/list_pools.rb +71 -0
- data/lib/fog/libvirt/requests/compute/list_volumes.rb +88 -0
- data/lib/fog/libvirt/requests/compute/mock_files/domain.xml +40 -0
- data/lib/fog/libvirt/requests/compute/pool_action.rb +19 -0
- data/lib/fog/libvirt/requests/compute/update_display.rb +31 -0
- data/lib/fog/libvirt/requests/compute/vm_action.rb +19 -0
- data/lib/fog/libvirt/requests/compute/volume_action.rb +18 -0
- data/lib/fog/libvirt/version.rb +5 -0
- data/lib/fog/libvirt.rb +18 -0
- data/tests/helper.rb +17 -0
- data/tests/helpers/formats_helper.rb +98 -0
- data/tests/helpers/formats_helper_tests.rb +110 -0
- data/tests/helpers/mock_helper.rb +14 -0
- data/tests/helpers/succeeds_helper.rb +9 -0
- data/tests/libvirt/compute_tests.rb +17 -0
- data/tests/libvirt/models/compute/interface_tests.rb +27 -0
- data/tests/libvirt/models/compute/interfaces_tests.rb +14 -0
- data/tests/libvirt/models/compute/network_tests.rb +27 -0
- data/tests/libvirt/models/compute/networks_tests.rb +13 -0
- data/tests/libvirt/models/compute/nic_tests.rb +31 -0
- data/tests/libvirt/models/compute/nics_tests.rb +10 -0
- data/tests/libvirt/models/compute/pool_tests.rb +27 -0
- data/tests/libvirt/models/compute/pools_tests.rb +13 -0
- data/tests/libvirt/models/compute/server_tests.rb +58 -0
- data/tests/libvirt/models/compute/servers_tests.rb +14 -0
- data/tests/libvirt/models/compute/volume_tests.rb +38 -0
- data/tests/libvirt/models/compute/volumes_tests.rb +14 -0
- data/tests/libvirt/requests/compute/create_domain_tests.rb +21 -0
- data/tests/libvirt/requests/compute/define_domain_tests.rb +11 -0
- data/tests/libvirt/requests/compute/update_display.rb +13 -0
- metadata +355 -0
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Compute
|
6
|
+
module LibvirtUtil
|
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 Compute
|
8
|
+
module LibvirtUtil
|
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,122 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
require 'fog/libvirt/models/compute/util/util'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Compute
|
6
|
+
class Libvirt
|
7
|
+
class Volume < Fog::Model
|
8
|
+
attr_reader :xml
|
9
|
+
include Fog::Compute::LibvirtUtil
|
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 :format_type
|
20
|
+
attribute :backing_volume
|
21
|
+
|
22
|
+
# Can be created by passing in :xml => "<xml to create volume>"
|
23
|
+
# A volume always belongs to a pool, :pool_name => "<name of pool>"
|
24
|
+
#
|
25
|
+
def initialize(attributes={ })
|
26
|
+
@xml = attributes.delete(:xml)
|
27
|
+
super(defaults.merge(attributes))
|
28
|
+
|
29
|
+
# We need a connection to calculate the pool_name
|
30
|
+
# This is why we do this after super
|
31
|
+
self.pool_name ||= default_pool_name
|
32
|
+
end
|
33
|
+
|
34
|
+
# Takes a pool and either :xml or other settings
|
35
|
+
def save
|
36
|
+
requires :pool_name
|
37
|
+
|
38
|
+
raise Fog::Errors::Error.new('Reserving an existing volume may create a duplicate') if key
|
39
|
+
@xml ||= to_xml
|
40
|
+
self.path = service.create_volume(pool_name, xml).path
|
41
|
+
end
|
42
|
+
|
43
|
+
# Destroy a volume
|
44
|
+
def destroy
|
45
|
+
service.volume_action key, :delete
|
46
|
+
end
|
47
|
+
|
48
|
+
# Wipes a volume , zeroes disk
|
49
|
+
def wipe
|
50
|
+
service.volume_action key, :wipe
|
51
|
+
end
|
52
|
+
|
53
|
+
# Clones this volume to the name provided
|
54
|
+
def clone(name)
|
55
|
+
new_volume = self.dup
|
56
|
+
new_volume.key = nil
|
57
|
+
new_volume.name = name
|
58
|
+
new_volume.save
|
59
|
+
|
60
|
+
new_volume.reload
|
61
|
+
end
|
62
|
+
|
63
|
+
def clone_volume(new_name)
|
64
|
+
requires :pool_name
|
65
|
+
|
66
|
+
new_volume = self.dup
|
67
|
+
new_volume.key = nil
|
68
|
+
new_volume.name = new_name
|
69
|
+
new_volume.path = service.clone_volume(pool_name, new_volume.to_xml, self.name).path
|
70
|
+
|
71
|
+
new_volume.reload
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def image_suffix
|
77
|
+
return "img" if format_type == "raw"
|
78
|
+
format_type
|
79
|
+
end
|
80
|
+
|
81
|
+
def randominzed_name
|
82
|
+
"#{super}.#{image_suffix}"
|
83
|
+
end
|
84
|
+
|
85
|
+
# Try to guess the default/first pool of no pool_name was specified
|
86
|
+
def default_pool_name
|
87
|
+
name = "default"
|
88
|
+
return name unless (service.pools.all(:name => name)).empty?
|
89
|
+
|
90
|
+
# we default to the first pool we find.
|
91
|
+
first_pool = service.pools.first
|
92
|
+
|
93
|
+
raise Fog::Errors::Error.new('No storage pools are defined') unless first_pool
|
94
|
+
first_pool.name
|
95
|
+
end
|
96
|
+
|
97
|
+
def defaults
|
98
|
+
{
|
99
|
+
:persistent => true,
|
100
|
+
:format_type => "raw",
|
101
|
+
:name => randomized_name,
|
102
|
+
:capacity => "10G",
|
103
|
+
:allocation => "1G",
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
def split_size_unit(text)
|
108
|
+
if text.kind_of? Integer
|
109
|
+
# if text is an integer, match will fail
|
110
|
+
size = text
|
111
|
+
unit = 'G'
|
112
|
+
else
|
113
|
+
matcher = text.match(/(\d+)(.+)/)
|
114
|
+
size = matcher[1]
|
115
|
+
unit = matcher[2]
|
116
|
+
end
|
117
|
+
[size, unit]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/libvirt/models/compute/volume'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Compute
|
6
|
+
class Libvirt
|
7
|
+
class Volumes < Fog::Collection
|
8
|
+
model Fog::Compute::Libvirt::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 Compute
|
3
|
+
class Libvirt
|
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::Compute::Libvirt::Volume.new({:pool_name => pool_name, :xml => xml})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Libvirt
|
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,18 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Libvirt
|
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,37 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Libvirt
|
4
|
+
class Real
|
5
|
+
def get_node_info
|
6
|
+
node_hash = Hash.new
|
7
|
+
node_info = client.node_get_info
|
8
|
+
[:model, :memory, :cpus, :mhz, :nodes, :sockets, :cores, :threads].each do |param|
|
9
|
+
node_hash[param] = node_info.send(param) rescue nil
|
10
|
+
end
|
11
|
+
[:type, :version, :node_free_memory, :max_vcpus].each do |param|
|
12
|
+
node_hash[param] = client.send(param) rescue nil
|
13
|
+
end
|
14
|
+
node_hash[:uri] = client.uri
|
15
|
+
xml = client.sys_info rescue nil
|
16
|
+
[:uuid, :manufacturer, :product, :serial].each do |attr|
|
17
|
+
node_hash[attr] = node_attr(attr, xml) rescue nil
|
18
|
+
end if xml
|
19
|
+
|
20
|
+
node_hash[:hostname] = client.hostname
|
21
|
+
[node_hash]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def node_attr attr, xml
|
27
|
+
xml_element(xml, "sysinfo/system/entry[@name='#{attr}']").strip
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Mock
|
32
|
+
def get_node_info
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Libvirt
|
4
|
+
class Real
|
5
|
+
def list_domains(filter = { })
|
6
|
+
data=[]
|
7
|
+
|
8
|
+
if filter.key?(:uuid)
|
9
|
+
data << client.lookup_domain_by_uuid(filter[:uuid])
|
10
|
+
elsif filter.key?(:name)
|
11
|
+
data << client.lookup_domain_by_name(filter[:name])
|
12
|
+
else
|
13
|
+
client.list_defined_domains.each { |name| data << client.lookup_domain_by_name(name) } unless filter[:defined] == false
|
14
|
+
client.list_domains.each { |id| data << client.lookup_domain_by_id(id) } unless filter[:active] == false
|
15
|
+
end
|
16
|
+
data.compact.map { |d| domain_to_attributes d }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Shared
|
21
|
+
private
|
22
|
+
|
23
|
+
def domain_display xml
|
24
|
+
attrs = {}
|
25
|
+
[:type, :port, :password, :listen].each do |element|
|
26
|
+
attrs[element] = xml_element(xml, "domain/devices/graphics",element.to_s) rescue nil
|
27
|
+
end
|
28
|
+
attrs.reject{|k,v| v.nil? or v == ""}
|
29
|
+
end
|
30
|
+
|
31
|
+
def domain_volumes xml
|
32
|
+
xml_elements(xml, "domain/devices/disk/source", "file")
|
33
|
+
end
|
34
|
+
|
35
|
+
def boot_order xml
|
36
|
+
xml_elements(xml, "domain/os/boot", "dev")
|
37
|
+
end
|
38
|
+
|
39
|
+
def domain_interfaces xml
|
40
|
+
ifs = xml_elements(xml, "domain/devices/interface")
|
41
|
+
ifs.map { |i|
|
42
|
+
nics.new({
|
43
|
+
:type => i['type'],
|
44
|
+
:mac => (i/'mac').first[:address],
|
45
|
+
:network => ((i/'source').first[:network] rescue nil),
|
46
|
+
:bridge => ((i/'source').first[:bridge] rescue nil),
|
47
|
+
:model => ((i/'model').first[:type] rescue nil),
|
48
|
+
}.reject{|k,v| v.nil?})
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def domain_to_attributes(dom)
|
53
|
+
states= %w(nostate running blocked paused shutting-down shutoff crashed)
|
54
|
+
{
|
55
|
+
:id => dom.uuid,
|
56
|
+
:uuid => dom.uuid,
|
57
|
+
:name => dom.name,
|
58
|
+
:max_memory_size => dom.info.max_mem,
|
59
|
+
:cputime => dom.info.cpu_time,
|
60
|
+
:memory_size => dom.info.memory,
|
61
|
+
:cpus => dom.info.nr_virt_cpu,
|
62
|
+
:autostart => dom.autostart?,
|
63
|
+
:os_type => dom.os_type,
|
64
|
+
:active => dom.active?,
|
65
|
+
:display => domain_display(dom.xml_desc),
|
66
|
+
:boot_order => boot_order(dom.xml_desc),
|
67
|
+
:nics => domain_interfaces(dom.xml_desc),
|
68
|
+
:volumes_path => domain_volumes(dom.xml_desc),
|
69
|
+
:state => states[dom.info.state]
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Mock
|
75
|
+
def list_domains(filter = { })
|
76
|
+
dom1 = mock_domain 'fog-dom1'
|
77
|
+
dom2 = mock_domain 'fog-dom2'
|
78
|
+
dom3 = mock_domain 'a-fog-dom3'
|
79
|
+
[dom1, dom2, dom3]
|
80
|
+
end
|
81
|
+
|
82
|
+
def mock_domain name
|
83
|
+
xml = read_xml 'domain.xml'
|
84
|
+
{
|
85
|
+
:id => "dom.uuid",
|
86
|
+
:uuid => "dom.uuid",
|
87
|
+
:name => name,
|
88
|
+
:max_memory_size => 8,
|
89
|
+
:cputime => 7,
|
90
|
+
:memory_size => 6,
|
91
|
+
:cpus => 5,
|
92
|
+
:autostart => false,
|
93
|
+
:os_type => "RHEL6",
|
94
|
+
:active => false,
|
95
|
+
:vnc_port => 5910,
|
96
|
+
:boot_order => boot_order(xml),
|
97
|
+
:nics => domain_interfaces(xml),
|
98
|
+
:volumes_path => domain_volumes(xml),
|
99
|
+
:state => 'shutoff'
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Libvirt
|
4
|
+
class Real
|
5
|
+
def list_interfaces(filter = { })
|
6
|
+
data=[]
|
7
|
+
if filter.keys.empty?
|
8
|
+
active_networks = client.list_interfaces rescue []
|
9
|
+
defined_networks = client.list_defined_interfaces rescue []
|
10
|
+
(active_networks + defined_networks).each do |ifname|
|
11
|
+
data << interface_to_attributes(client.lookup_interface_by_name(ifname))
|
12
|
+
end
|
13
|
+
else
|
14
|
+
data = [interface_to_attributes(get_interface_by_filter(filter))]
|
15
|
+
end
|
16
|
+
data.compact
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
# Retrieve the interface by mac or by name
|
21
|
+
def get_interface_by_filter(filter)
|
22
|
+
case filter.keys.first
|
23
|
+
when :mac
|
24
|
+
client.lookup_interface_by_mac(filter[:mac])
|
25
|
+
when :name
|
26
|
+
client.lookup_interface_by_name(filter[:name])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def interface_to_attributes(net)
|
31
|
+
return if net.nil? || net.name == 'lo'
|
32
|
+
{
|
33
|
+
:mac => net.mac,
|
34
|
+
:name => net.name,
|
35
|
+
:active => net.active?
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Mock
|
41
|
+
def list_interfaces(filters={ })
|
42
|
+
if1 = mock_interface 'if1'
|
43
|
+
if2 = mock_interface 'if2'
|
44
|
+
[if1, if2]
|
45
|
+
end
|
46
|
+
|
47
|
+
def mock_interface name
|
48
|
+
{
|
49
|
+
:mac => 'aa:bb:cc:dd:ee:ff',
|
50
|
+
:name => name,
|
51
|
+
:active => true
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class Libvirt
|
4
|
+
class Real
|
5
|
+
def list_networks(filter = { })
|
6
|
+
data=[]
|
7
|
+
if filter.keys.empty?
|
8
|
+
(client.list_networks + client.list_defined_networks).each do |network_name|
|
9
|
+
data << network_to_attributes(client.lookup_network_by_name(network_name))
|
10
|
+
end
|
11
|
+
else
|
12
|
+
data = [network_to_attributes(get_network_by_filter(filter))]
|
13
|
+
end
|
14
|
+
data
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
# Retrieve the network by uuid or name
|
19
|
+
def get_network_by_filter(filter)
|
20
|
+
case filter.keys.first
|
21
|
+
when :uuid
|
22
|
+
client.lookup_network_by_uuid(filter[:uuid])
|
23
|
+
when :name
|
24
|
+
client.lookup_network_by_name(filter[:name])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def network_to_attributes(net)
|
29
|
+
return if net.nil?
|
30
|
+
{
|
31
|
+
:uuid => net.uuid,
|
32
|
+
:name => net.name,
|
33
|
+
:bridge_name => net.bridge_name
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Mock
|
39
|
+
def list_networks(filters={ })
|
40
|
+
net1 = mock_network 'net1'
|
41
|
+
net2 = mock_network 'net2'
|
42
|
+
[net1, net2]
|
43
|
+
end
|
44
|
+
|
45
|
+
def mock_network name
|
46
|
+
{
|
47
|
+
:uuid => 'net.uuid',
|
48
|
+
:name => name,
|
49
|
+
:bridge_name => 'net.bridge_name'
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|