opennebula 3.9.80.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +202 -0
- data/NOTICE +47 -0
- data/lib/opennebula.rb +58 -0
- data/lib/opennebula/acl.rb +266 -0
- data/lib/opennebula/acl_pool.rb +55 -0
- data/lib/opennebula/client.rb +119 -0
- data/lib/opennebula/cluster.rb +249 -0
- data/lib/opennebula/cluster_pool.rb +58 -0
- data/lib/opennebula/datastore.rb +171 -0
- data/lib/opennebula/datastore_pool.rb +55 -0
- data/lib/opennebula/document.rb +261 -0
- data/lib/opennebula/document_json.rb +131 -0
- data/lib/opennebula/document_pool.rb +102 -0
- data/lib/opennebula/document_pool_json.rb +58 -0
- data/lib/opennebula/error.rb +52 -0
- data/lib/opennebula/group.rb +163 -0
- data/lib/opennebula/group_pool.rb +56 -0
- data/lib/opennebula/host.rb +201 -0
- data/lib/opennebula/host_pool.rb +93 -0
- data/lib/opennebula/image.rb +297 -0
- data/lib/opennebula/image_pool.rb +79 -0
- data/lib/opennebula/ldap_auth.rb +99 -0
- data/lib/opennebula/ldap_auth_spec.rb +70 -0
- data/lib/opennebula/pool.rb +160 -0
- data/lib/opennebula/pool_element.rb +269 -0
- data/lib/opennebula/server_cipher_auth.rb +148 -0
- data/lib/opennebula/server_x509_auth.rb +104 -0
- data/lib/opennebula/ssh_auth.rb +139 -0
- data/lib/opennebula/system.rb +141 -0
- data/lib/opennebula/template.rb +213 -0
- data/lib/opennebula/template_pool.rb +79 -0
- data/lib/opennebula/user.rb +174 -0
- data/lib/opennebula/user_pool.rb +55 -0
- data/lib/opennebula/virtual_machine.rb +560 -0
- data/lib/opennebula/virtual_machine_pool.rb +323 -0
- data/lib/opennebula/virtual_network.rb +249 -0
- data/lib/opennebula/virtual_network_pool.rb +79 -0
- data/lib/opennebula/x509_auth.rb +288 -0
- data/lib/opennebula/xml_element.rb +427 -0
- data/lib/opennebula/xml_pool.rb +45 -0
- data/lib/opennebula/xml_utils.rb +34 -0
- metadata +118 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
# -------------------------------------------------------------------------- #
|
2
|
+
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
|
+
# #
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
+
# not use this file except in compliance with the License. You may obtain #
|
6
|
+
# a copy of the License at #
|
7
|
+
# #
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
+
# #
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
+
# See the License for the specific language governing permissions and #
|
14
|
+
# limitations under the License. #
|
15
|
+
#--------------------------------------------------------------------------- #
|
16
|
+
|
17
|
+
|
18
|
+
require 'opennebula/pool'
|
19
|
+
|
20
|
+
module OpenNebula
|
21
|
+
class ImagePool < Pool
|
22
|
+
#######################################################################
|
23
|
+
# Constants and Class attribute accessors
|
24
|
+
#######################################################################
|
25
|
+
|
26
|
+
|
27
|
+
IMAGE_POOL_METHODS = {
|
28
|
+
:info => "imagepool.info"
|
29
|
+
}
|
30
|
+
|
31
|
+
#######################################################################
|
32
|
+
# Class constructor & Pool Methods
|
33
|
+
#######################################################################
|
34
|
+
|
35
|
+
# +client+ a Client object that represents a XML-RPC connection
|
36
|
+
# +user_id+ is to refer to a Pool with Images from that user
|
37
|
+
def initialize(client, user_id=-1)
|
38
|
+
super('IMAGE_POOL','IMAGE',client)
|
39
|
+
|
40
|
+
@user_id = user_id
|
41
|
+
end
|
42
|
+
|
43
|
+
# Default Factory Method for the Pools
|
44
|
+
def factory(element_xml)
|
45
|
+
OpenNebula::Image.new(element_xml,@client)
|
46
|
+
end
|
47
|
+
|
48
|
+
#######################################################################
|
49
|
+
# XML-RPC Methods for the Image Object
|
50
|
+
#######################################################################
|
51
|
+
|
52
|
+
# Retrieves all or part of the VirtualMachines in the pool.
|
53
|
+
def info(*args)
|
54
|
+
case args.size
|
55
|
+
when 0
|
56
|
+
info_filter(IMAGE_POOL_METHODS[:info],@user_id,-1,-1)
|
57
|
+
when 3
|
58
|
+
info_filter(IMAGE_POOL_METHODS[:info],args[0],args[1],args[2])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def info_all()
|
63
|
+
return super(IMAGE_POOL_METHODS[:info])
|
64
|
+
end
|
65
|
+
|
66
|
+
def info_mine()
|
67
|
+
return super(IMAGE_POOL_METHODS[:info])
|
68
|
+
end
|
69
|
+
|
70
|
+
def info_group()
|
71
|
+
return super(IMAGE_POOL_METHODS[:info])
|
72
|
+
end
|
73
|
+
|
74
|
+
alias_method :info!, :info
|
75
|
+
alias_method :info_all!, :info_all
|
76
|
+
alias_method :info_mine!, :info_mine
|
77
|
+
alias_method :info_group!, :info_group
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# ---------------------------------------------------------------------------- #
|
2
|
+
# Copyright 2010-2013, C12G Labs S.L #
|
3
|
+
# #
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
+
# not use this file except in compliance with the License. You may obtain #
|
6
|
+
# a copy of the License at #
|
7
|
+
# #
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
+
# #
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
+
# See the License for the specific language governing permissions and #
|
14
|
+
# limitations under the License. #
|
15
|
+
# ---------------------------------------------------------------------------- #
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
require 'net/ldap'
|
19
|
+
|
20
|
+
module OpenNebula; end
|
21
|
+
|
22
|
+
class OpenNebula::LdapAuth
|
23
|
+
def initialize(options)
|
24
|
+
@options={
|
25
|
+
:host => 'localhost',
|
26
|
+
:port => 389,
|
27
|
+
:user => nil,
|
28
|
+
:password => nil,
|
29
|
+
:base => nil,
|
30
|
+
:auth_method => :simple,
|
31
|
+
:user_field => 'cn'
|
32
|
+
}.merge(options)
|
33
|
+
|
34
|
+
ops={}
|
35
|
+
|
36
|
+
if @options[:user]
|
37
|
+
ops[:auth] = {
|
38
|
+
:method => @options[:auth_method],
|
39
|
+
:username => @options[:user],
|
40
|
+
:password => @options[:password]
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
ops[:host]=@options[:host] if @options[:host]
|
45
|
+
ops[:port]=@options[:port].to_i if @options[:port]
|
46
|
+
ops[:encryption]=@options[:encryption] if @options[:encryption]
|
47
|
+
|
48
|
+
@ldap=Net::LDAP.new(ops)
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_user(name)
|
52
|
+
begin
|
53
|
+
result=@ldap.search(
|
54
|
+
:base => @options[:base],
|
55
|
+
:filter => "#{@options[:user_field]}=#{name}")
|
56
|
+
|
57
|
+
if result && result.first
|
58
|
+
result.first.dn
|
59
|
+
else
|
60
|
+
result=@ldap.search(:base => name)
|
61
|
+
|
62
|
+
if result && result.first
|
63
|
+
name
|
64
|
+
else
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
rescue
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def is_in_group?(user, group)
|
74
|
+
result=@ldap.search(:base => group, :filter => "(member=#{user})")
|
75
|
+
|
76
|
+
if result && result.first
|
77
|
+
true
|
78
|
+
else
|
79
|
+
false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def authenticate(user, password)
|
84
|
+
ldap=@ldap.clone
|
85
|
+
|
86
|
+
auth={
|
87
|
+
:method => @options[:auth_method],
|
88
|
+
:username => user,
|
89
|
+
:password => password
|
90
|
+
}
|
91
|
+
|
92
|
+
if ldap.bind(auth)
|
93
|
+
true
|
94
|
+
else
|
95
|
+
false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# ---------------------------------------------------------------------------- #
|
2
|
+
# Copyright 2010-2013, C12G Labs S.L #
|
3
|
+
# #
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
+
# not use this file except in compliance with the License. You may obtain #
|
6
|
+
# a copy of the License at #
|
7
|
+
# #
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
+
# #
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
+
# See the License for the specific language governing permissions and #
|
14
|
+
# limitations under the License. #
|
15
|
+
# ---------------------------------------------------------------------------- #
|
16
|
+
|
17
|
+
$: << ".."
|
18
|
+
|
19
|
+
require 'ldap_auth'
|
20
|
+
|
21
|
+
options={
|
22
|
+
:host => 'ubuntu-test',
|
23
|
+
:base => 'dc=localdomain'
|
24
|
+
}
|
25
|
+
|
26
|
+
describe LdapAuth do
|
27
|
+
before(:all) do
|
28
|
+
@ldap=LdapAuth.new(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should find user dn' do
|
32
|
+
name=@ldap.find_user('user01')
|
33
|
+
name.should=='cn=user01,dc=localdomain'
|
34
|
+
|
35
|
+
name=@ldap.find_user('user02')
|
36
|
+
name.should=='cn=user02,dc=localdomain'
|
37
|
+
|
38
|
+
name=@ldap.find_user('user03')
|
39
|
+
name.should==nil
|
40
|
+
|
41
|
+
name=@ldap.find_user('cn=user01,dc=localdomain')
|
42
|
+
name.should=='cn=user01,dc=localdomain'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should tell if a user is in a group' do
|
46
|
+
group='cn=cloud,ou=groups,dc=localdomain'
|
47
|
+
|
48
|
+
result=@ldap.is_in_group?('cn=user01,dc=localdomain', group)
|
49
|
+
result.should==true
|
50
|
+
|
51
|
+
result=@ldap.is_in_group?('cn=user02,dc=localdomain', group)
|
52
|
+
result.should==false
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should authenticate user' do
|
56
|
+
result=@ldap.authenticate('cn=user01,dc=localdomain', 'password01')
|
57
|
+
result.should==true
|
58
|
+
|
59
|
+
result=@ldap.authenticate('cn=user02,dc=localdomain', 'password02')
|
60
|
+
result.should==true
|
61
|
+
|
62
|
+
result=@ldap.authenticate('cn=user01,dc=localdomain', 'password02')
|
63
|
+
result.should==false
|
64
|
+
|
65
|
+
result=@ldap.authenticate('user01,dc=localdomain', 'password01')
|
66
|
+
result.should==false
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,160 @@
|
|
1
|
+
# -------------------------------------------------------------------------- #
|
2
|
+
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
|
+
# #
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
+
# not use this file except in compliance with the License. You may obtain #
|
6
|
+
# a copy of the License at #
|
7
|
+
# #
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
+
# #
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
+
# See the License for the specific language governing permissions and #
|
14
|
+
# limitations under the License. #
|
15
|
+
#--------------------------------------------------------------------------- #
|
16
|
+
|
17
|
+
require 'opennebula/xml_utils'
|
18
|
+
|
19
|
+
module OpenNebula
|
20
|
+
|
21
|
+
# The Pool class represents a generic OpenNebula Pool in XML format
|
22
|
+
# and provides the basic functionality to handle the Pool elements
|
23
|
+
class Pool < XMLPool
|
24
|
+
include Enumerable
|
25
|
+
alias_method :each_with_xpath, :each
|
26
|
+
|
27
|
+
protected
|
28
|
+
#pool:: _String_ XML name of the root element
|
29
|
+
#element:: _String_ XML name of the Pool elements
|
30
|
+
#client:: _Client_ represents a XML-RPC connection
|
31
|
+
def initialize(pool,element,client)
|
32
|
+
super(nil)
|
33
|
+
|
34
|
+
@pool_name = pool.upcase
|
35
|
+
@element_name = element.upcase
|
36
|
+
|
37
|
+
@client = client
|
38
|
+
end
|
39
|
+
|
40
|
+
# Default Factory Method for the Pools. The factory method returns an
|
41
|
+
# suitable PoolElement object. Each Pool MUST implement the
|
42
|
+
# corresponding factory method
|
43
|
+
# element_xml:: _XML_ XML element describing the pool element
|
44
|
+
# [return] a PoolElement object
|
45
|
+
def factory(element_xml)
|
46
|
+
OpenNebula::PoolElement.new(element_xml,client)
|
47
|
+
end
|
48
|
+
|
49
|
+
#######################################################################
|
50
|
+
# Common XML-RPC Methods for all the Pool Types
|
51
|
+
#######################################################################
|
52
|
+
|
53
|
+
#Gets the pool without any filter. Host, Group and User Pools
|
54
|
+
# xml_method:: _String_ the name of the XML-RPC method
|
55
|
+
def info(xml_method)
|
56
|
+
return xmlrpc_info(xml_method)
|
57
|
+
end
|
58
|
+
|
59
|
+
alias_method :info!, :info
|
60
|
+
|
61
|
+
def info_all(xml_method, *args)
|
62
|
+
return xmlrpc_info(xml_method,INFO_ALL,-1,-1, *args)
|
63
|
+
end
|
64
|
+
|
65
|
+
def info_mine(xml_method, *args)
|
66
|
+
return xmlrpc_info(xml_method,INFO_MINE,-1,-1, *args)
|
67
|
+
end
|
68
|
+
|
69
|
+
def info_group(xml_method, *args)
|
70
|
+
return xmlrpc_info(xml_method,INFO_GROUP,-1,-1, *args)
|
71
|
+
end
|
72
|
+
|
73
|
+
def info_filter(xml_method, who, start_id, end_id, *args)
|
74
|
+
return xmlrpc_info(xml_method,who, start_id, end_id, *args)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Retrieves the monitoring data for all the Objects in the pool
|
78
|
+
#
|
79
|
+
# @param [String] xml_method xml-rcp method
|
80
|
+
# @param [String] root_elem Root for each individual PoolElement
|
81
|
+
# @param [String] timestamp_elem Name of the XML element with the last
|
82
|
+
# monitorization timestamp
|
83
|
+
# @param [Array<String>] xpath_expressions Elements to retrieve.
|
84
|
+
# @param args arguemnts for the xml_method call
|
85
|
+
#
|
86
|
+
# @return [Hash<String, <Hash<String, Array<Array<int>>>>>,
|
87
|
+
# OpenNebula::Error] The first level hash uses the Object ID as keys,
|
88
|
+
# and as value a Hash with the requested xpath expressions,
|
89
|
+
# and an Array of 'timestamp, value'.
|
90
|
+
def monitoring(xml_method, root_elem, timestamp_elem, xpath_expressions,
|
91
|
+
*args)
|
92
|
+
|
93
|
+
rc = @client.call(xml_method, *args)
|
94
|
+
|
95
|
+
if ( OpenNebula.is_error?(rc) )
|
96
|
+
return rc
|
97
|
+
end
|
98
|
+
|
99
|
+
xmldoc = XMLElement.new
|
100
|
+
xmldoc.initialize_xml(rc, 'MONITORING_DATA')
|
101
|
+
|
102
|
+
hash = {}
|
103
|
+
|
104
|
+
# Get all existing Object IDs
|
105
|
+
ids = xmldoc.retrieve_elements("#{root_elem}/ID")
|
106
|
+
|
107
|
+
if ids.nil?
|
108
|
+
return hash
|
109
|
+
else
|
110
|
+
ids.uniq!
|
111
|
+
end
|
112
|
+
|
113
|
+
ids.each { |id|
|
114
|
+
hash[id] = OpenNebula.process_monitoring(
|
115
|
+
xmldoc, root_elem, timestamp_elem, id, xpath_expressions)
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
return hash
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
# Calls to the corresponding info method to retreive the pool
|
124
|
+
# representation in XML format
|
125
|
+
# xml_method:: _String_ the name of the XML-RPC method
|
126
|
+
# args:: _Array_ with additional arguments for the info call
|
127
|
+
# [return] nil in case of success or an Error object
|
128
|
+
def xmlrpc_info(xml_method,*args)
|
129
|
+
rc = @client.call(xml_method,*args)
|
130
|
+
|
131
|
+
if !OpenNebula.is_error?(rc)
|
132
|
+
initialize_xml(rc,@pool_name)
|
133
|
+
rc = nil
|
134
|
+
end
|
135
|
+
|
136
|
+
return rc
|
137
|
+
end
|
138
|
+
|
139
|
+
public
|
140
|
+
# Constants for info queries (include/RequestManagerPoolInfoFilter.h)
|
141
|
+
INFO_GROUP = -1
|
142
|
+
INFO_ALL = -2
|
143
|
+
INFO_MINE = -3
|
144
|
+
|
145
|
+
# Iterates over every PoolElement in the Pool and calls the block with a
|
146
|
+
# a PoolElement obtained calling the factory method
|
147
|
+
# block:: _Block_
|
148
|
+
def each(&block)
|
149
|
+
each_element(block) if @xml
|
150
|
+
end
|
151
|
+
|
152
|
+
# DO NOT USE - ONLY REXML BACKEND
|
153
|
+
def to_str
|
154
|
+
str = ""
|
155
|
+
REXML::Formatters::Pretty.new(1).write(@xml,str)
|
156
|
+
|
157
|
+
return str
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,269 @@
|
|
1
|
+
# -------------------------------------------------------------------------- #
|
2
|
+
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
|
+
# #
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
|
+
# not use this file except in compliance with the License. You may obtain #
|
6
|
+
# a copy of the License at #
|
7
|
+
# #
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
9
|
+
# #
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
13
|
+
# See the License for the specific language governing permissions and #
|
14
|
+
# limitations under the License. #
|
15
|
+
#--------------------------------------------------------------------------- #
|
16
|
+
|
17
|
+
require 'opennebula/pool'
|
18
|
+
|
19
|
+
module OpenNebula
|
20
|
+
# The PoolElement Class represents a generic element of a Pool in
|
21
|
+
# XML format
|
22
|
+
class PoolElement < XMLElement
|
23
|
+
|
24
|
+
protected
|
25
|
+
# node:: _XML_is a XML element that represents the Pool element
|
26
|
+
# client:: _Client_ represents a XML-RPC connection
|
27
|
+
def initialize(node, client)
|
28
|
+
@xml = node
|
29
|
+
@client = client
|
30
|
+
|
31
|
+
if self['ID']
|
32
|
+
@pe_id = self['ID'].to_i
|
33
|
+
else
|
34
|
+
@pe_id = nil
|
35
|
+
end
|
36
|
+
@name = self['NAME'] if self['NAME']
|
37
|
+
end
|
38
|
+
|
39
|
+
#######################################################################
|
40
|
+
# Common XML-RPC Methods for all the Pool Element Types
|
41
|
+
#######################################################################
|
42
|
+
|
43
|
+
# Common client call wrapper. Checks that @pe_id is defined, and
|
44
|
+
# returns nil instead of the response if it is successful
|
45
|
+
#
|
46
|
+
# @param [String] xml_method xml-rpc method
|
47
|
+
# @param [Array] args any arguments for the xml-rpc method
|
48
|
+
#
|
49
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
50
|
+
# otherwise
|
51
|
+
def call(xml_method, *args)
|
52
|
+
return Error.new('ID not defined') if !@pe_id
|
53
|
+
|
54
|
+
rc = @client.call(xml_method, *args)
|
55
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
56
|
+
|
57
|
+
return rc
|
58
|
+
end
|
59
|
+
|
60
|
+
# Calls to the corresponding info method to retreive the element
|
61
|
+
# detailed information in XML format
|
62
|
+
#
|
63
|
+
# @param [String] xml_method the name of the XML-RPC method
|
64
|
+
# @param [String] root_element Base XML element name
|
65
|
+
# @param [Array] args additional arguments
|
66
|
+
#
|
67
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
68
|
+
# otherwise
|
69
|
+
def info(xml_method, root_element)
|
70
|
+
return Error.new('ID not defined') if !@pe_id
|
71
|
+
|
72
|
+
rc = @client.call(xml_method, @pe_id)
|
73
|
+
|
74
|
+
if !OpenNebula.is_error?(rc)
|
75
|
+
initialize_xml(rc, root_element)
|
76
|
+
rc = nil
|
77
|
+
|
78
|
+
@pe_id = self['ID'].to_i if self['ID']
|
79
|
+
@name = self['NAME'] if self['NAME']
|
80
|
+
end
|
81
|
+
|
82
|
+
return rc
|
83
|
+
end
|
84
|
+
|
85
|
+
# Calls to the corresponding allocate method to create a new element
|
86
|
+
# in the OpenNebula core
|
87
|
+
#
|
88
|
+
# @param [String] xml_method the name of the XML-RPC method
|
89
|
+
# @param [Array] args any extra arguments for the xml-rpc method
|
90
|
+
#
|
91
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
92
|
+
# otherwise
|
93
|
+
def allocate(xml_method, *args)
|
94
|
+
rc = @client.call(xml_method, *args)
|
95
|
+
|
96
|
+
if !OpenNebula.is_error?(rc)
|
97
|
+
@pe_id = rc
|
98
|
+
rc = nil
|
99
|
+
end
|
100
|
+
|
101
|
+
return rc
|
102
|
+
end
|
103
|
+
|
104
|
+
# Calls to the corresponding update method to modify
|
105
|
+
# the object's template
|
106
|
+
#
|
107
|
+
# @param [String] xml_method the name of the XML-RPC method
|
108
|
+
# @param [String] new_template the new template contents
|
109
|
+
# @param [Array] args any extra arguments for the xml-rpc method
|
110
|
+
#
|
111
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
112
|
+
# otherwise
|
113
|
+
def update(xml_method, new_template, *args)
|
114
|
+
new_template ||= template_xml
|
115
|
+
|
116
|
+
return call(xml_method, @pe_id, new_template, *args)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Calls to the corresponding delete method to remove this element
|
120
|
+
# from the OpenNebula core
|
121
|
+
#
|
122
|
+
# @param [String] xml_method the name of the XML-RPC method
|
123
|
+
#
|
124
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
125
|
+
# otherwise
|
126
|
+
def delete(xml_method)
|
127
|
+
return call(xml_method,@pe_id)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Calls to the corresponding chown method to modify
|
131
|
+
# the object's owner and group
|
132
|
+
#
|
133
|
+
# @param [String] xml_method the name of the XML-RPC method
|
134
|
+
# @param [Integer] uid the new owner id. Set to -1 to leave the current one
|
135
|
+
# @param [Integer] gid the new goup id. Set to -1 to leave the current one
|
136
|
+
#
|
137
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
138
|
+
# otherwise
|
139
|
+
def chown(xml_method, uid, gid)
|
140
|
+
return call(xml_method, @pe_id, uid, gid)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Calls to the corresponding chmod method to modify
|
144
|
+
# the object's permission bits
|
145
|
+
#
|
146
|
+
# @param xml_method [String] the name of the XML-RPC method
|
147
|
+
# @param octet [String] Permissions octed , e.g. 640
|
148
|
+
#
|
149
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
150
|
+
# otherwise
|
151
|
+
def chmod_octet(xml_method, octet)
|
152
|
+
owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0
|
153
|
+
owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0
|
154
|
+
owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0
|
155
|
+
group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0
|
156
|
+
group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0
|
157
|
+
group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0
|
158
|
+
other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0
|
159
|
+
other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0
|
160
|
+
other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0
|
161
|
+
|
162
|
+
chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
163
|
+
other_m, other_a)
|
164
|
+
end
|
165
|
+
|
166
|
+
# Calls to the corresponding chmod method to modify
|
167
|
+
# the object's permission bits
|
168
|
+
# Each [Integer] parameter must be 1 to allow, 0 deny, -1 do not change
|
169
|
+
#
|
170
|
+
# @param xml_method [String] the name of the XML-RPC method
|
171
|
+
#
|
172
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
173
|
+
# otherwise
|
174
|
+
def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
175
|
+
other_m, other_a)
|
176
|
+
return call(xml_method, @pe_id, owner_u, owner_m,
|
177
|
+
owner_a, group_u, group_m, group_a, other_u,
|
178
|
+
other_m, other_a)
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
# Retrieves this Element's monitoring data from OpenNebula
|
183
|
+
#
|
184
|
+
# @param [String] xml_method the name of the XML-RPC method
|
185
|
+
# @param [String] root_elem Root for each individual PoolElement
|
186
|
+
# @param [String] timestamp_elem Name of the XML element with the last
|
187
|
+
# monitorization timestamp
|
188
|
+
# @param xpath_expressions [Array<String>] Xpath expressions for the
|
189
|
+
# elements to retrieve.
|
190
|
+
#
|
191
|
+
# @return [Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with
|
192
|
+
# the requested xpath expressions, and an Array of [timestamp, value].
|
193
|
+
def monitoring(xml_method, root_elem, timestamp_elem, xpath_expressions)
|
194
|
+
return Error.new('ID not defined') if !@pe_id
|
195
|
+
|
196
|
+
rc = @client.call(xml_method, @pe_id)
|
197
|
+
|
198
|
+
if ( OpenNebula.is_error?(rc) )
|
199
|
+
return rc
|
200
|
+
end
|
201
|
+
|
202
|
+
xmldoc = XMLElement.new
|
203
|
+
xmldoc.initialize_xml(rc, 'MONITORING_DATA')
|
204
|
+
|
205
|
+
|
206
|
+
return OpenNebula.process_monitoring(
|
207
|
+
xmldoc, root_elem, timestamp_elem, @pe_id, xpath_expressions)
|
208
|
+
end
|
209
|
+
|
210
|
+
public
|
211
|
+
|
212
|
+
# Creates new element specifying its id
|
213
|
+
# id:: identifyier of the element
|
214
|
+
# client:: initialized OpenNebula::Client object
|
215
|
+
def self.new_with_id(id, client=nil)
|
216
|
+
self.new(self.build_xml(id), client)
|
217
|
+
end
|
218
|
+
|
219
|
+
# Returns element identifier
|
220
|
+
# [return] _Integer_ the PoolElement ID
|
221
|
+
def id
|
222
|
+
@pe_id
|
223
|
+
end
|
224
|
+
|
225
|
+
# Gets element name
|
226
|
+
# [return] _String_ the PoolElement name
|
227
|
+
def name
|
228
|
+
@name
|
229
|
+
end
|
230
|
+
|
231
|
+
# DO NOT USE - ONLY REXML BACKEND
|
232
|
+
def to_str
|
233
|
+
str = ""
|
234
|
+
REXML::Formatters::Pretty.new(1).write(@xml,str)
|
235
|
+
|
236
|
+
return str
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
# Processes the monitoring data in XML returned by OpenNebula
|
241
|
+
#
|
242
|
+
# @param [XMLElement] xmldoc monitoring data returned by OpenNebula
|
243
|
+
# @param [String] root_elem Root for each individual PoolElement
|
244
|
+
# @param [String] timestamp_elem Name of the XML element with the last
|
245
|
+
# monitorization timestamp
|
246
|
+
# @param [Integer] Id of the object to process
|
247
|
+
# @param [Array<String>] xpath_expressions Elements to retrieve.
|
248
|
+
# @param args arguemnts for the xml_method call
|
249
|
+
#
|
250
|
+
# @return [Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with
|
251
|
+
# the requested xpath expressions, and an Array of [timestamp, value].
|
252
|
+
def self.process_monitoring(xmldoc, root_elem, timestamp_elem, oid, xpath_expressions)
|
253
|
+
hash = {}
|
254
|
+
timestamps = xmldoc.retrieve_elements(
|
255
|
+
"#{root_elem}[ID=#{oid}]/#{timestamp_elem}")
|
256
|
+
|
257
|
+
xpath_expressions.each { |xpath|
|
258
|
+
xpath_values = xmldoc.retrieve_elements("#{root_elem}[ID=#{oid}]/#{xpath}")
|
259
|
+
|
260
|
+
if ( xpath_values.nil? )
|
261
|
+
hash[xpath] = []
|
262
|
+
else
|
263
|
+
hash[xpath] = timestamps.zip(xpath_values)
|
264
|
+
end
|
265
|
+
}
|
266
|
+
|
267
|
+
return hash
|
268
|
+
end
|
269
|
+
end
|