opennebula-oca 3.9.0.beta → 3.9.90.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- metadata +35 -108
- data/LICENSE +0 -202
- data/NOTICE +0 -48
- data/lib/opennebula/acl.rb +0 -259
- data/lib/opennebula/acl_pool.rb +0 -53
- data/lib/opennebula/client.rb +0 -102
- data/lib/opennebula/cluster.rb +0 -247
- data/lib/opennebula/cluster_pool.rb +0 -56
- data/lib/opennebula/datastore.rb +0 -169
- data/lib/opennebula/datastore_pool.rb +0 -53
- data/lib/opennebula/document.rb +0 -259
- data/lib/opennebula/document_json.rb +0 -129
- data/lib/opennebula/document_pool.rb +0 -97
- data/lib/opennebula/document_pool_json.rb +0 -58
- data/lib/opennebula/error.rb +0 -52
- data/lib/opennebula/group.rb +0 -161
- data/lib/opennebula/group_pool.rb +0 -54
- data/lib/opennebula/host.rb +0 -199
- data/lib/opennebula/host_pool.rb +0 -91
- data/lib/opennebula/image.rb +0 -293
- data/lib/opennebula/image_pool.rb +0 -74
- data/lib/opennebula/ldap_auth.rb +0 -99
- data/lib/opennebula/ldap_auth_spec.rb +0 -70
- data/lib/opennebula/pool.rb +0 -157
- data/lib/opennebula/pool_element.rb +0 -269
- data/lib/opennebula/server_cipher_auth.rb +0 -148
- data/lib/opennebula/server_x509_auth.rb +0 -104
- data/lib/opennebula/ssh_auth.rb +0 -139
- data/lib/opennebula/system.rb +0 -141
- data/lib/opennebula/template.rb +0 -201
- data/lib/opennebula/template_pool.rb +0 -74
- data/lib/opennebula/user.rb +0 -172
- data/lib/opennebula/user_pool.rb +0 -53
- data/lib/opennebula/virtual_machine.rb +0 -426
- data/lib/opennebula/virtual_machine_pool.rb +0 -318
- data/lib/opennebula/virtual_network.rb +0 -247
- data/lib/opennebula/virtual_network_pool.rb +0 -74
- data/lib/opennebula/x509_auth.rb +0 -241
- data/lib/opennebula/xml_element.rb +0 -427
- data/lib/opennebula/xml_pool.rb +0 -45
- data/lib/opennebula/xml_utils.rb +0 -34
- data/lib/opennebula.rb +0 -58
data/lib/opennebula/image.rb
DELETED
@@ -1,293 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
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_element'
|
19
|
-
require 'fileutils'
|
20
|
-
|
21
|
-
module OpenNebula
|
22
|
-
class Image < PoolElement
|
23
|
-
#######################################################################
|
24
|
-
# Constants and Class Methods
|
25
|
-
#######################################################################
|
26
|
-
|
27
|
-
|
28
|
-
IMAGE_METHODS = {
|
29
|
-
:info => "image.info",
|
30
|
-
:allocate => "image.allocate",
|
31
|
-
:update => "image.update",
|
32
|
-
:enable => "image.enable",
|
33
|
-
:persistent => "image.persistent",
|
34
|
-
:delete => "image.delete",
|
35
|
-
:chown => "image.chown",
|
36
|
-
:chmod => "image.chmod",
|
37
|
-
:chtype => "image.chtype",
|
38
|
-
:clone => "image.clone",
|
39
|
-
:rename => "image.rename"
|
40
|
-
}
|
41
|
-
|
42
|
-
IMAGE_STATES=%w{INIT READY USED DISABLED LOCKED ERROR CLONE DELETE USED_PERS}
|
43
|
-
|
44
|
-
SHORT_IMAGE_STATES={
|
45
|
-
"INIT" => "init",
|
46
|
-
"READY" => "rdy",
|
47
|
-
"USED" => "used",
|
48
|
-
"DISABLED" => "disa",
|
49
|
-
"LOCKED" => "lock",
|
50
|
-
"ERROR" => "err",
|
51
|
-
"CLONE" => "clon",
|
52
|
-
"DELETE" => "dele",
|
53
|
-
"USED_PERS" => "used"
|
54
|
-
}
|
55
|
-
|
56
|
-
IMAGE_TYPES=%w{OS CDROM DATABLOCK KERNEL RAMDISK CONTEXT}
|
57
|
-
|
58
|
-
SHORT_IMAGE_TYPES={
|
59
|
-
"OS" => "OS",
|
60
|
-
"CDROM" => "CD",
|
61
|
-
"DATABLOCK" => "DB",
|
62
|
-
"KERNEL" => "KL",
|
63
|
-
"RAMDISK" => "RD",
|
64
|
-
"CONTEXT" => "CX"
|
65
|
-
}
|
66
|
-
|
67
|
-
# Creates an Image description with just its identifier
|
68
|
-
# this method should be used to create plain Image objects.
|
69
|
-
# +id+ the id of the image
|
70
|
-
#
|
71
|
-
# Example:
|
72
|
-
# image = Image.new(Image.build_xml(3),rpc_client)
|
73
|
-
#
|
74
|
-
def Image.build_xml(pe_id=nil)
|
75
|
-
if pe_id
|
76
|
-
image_xml = "<IMAGE><ID>#{pe_id}</ID></IMAGE>"
|
77
|
-
else
|
78
|
-
image_xml = "<IMAGE></IMAGE>"
|
79
|
-
end
|
80
|
-
|
81
|
-
XMLElement.build_xml(image_xml,'IMAGE')
|
82
|
-
end
|
83
|
-
|
84
|
-
# Class constructor
|
85
|
-
def initialize(xml, client)
|
86
|
-
super(xml,client)
|
87
|
-
|
88
|
-
@client = client
|
89
|
-
end
|
90
|
-
|
91
|
-
#######################################################################
|
92
|
-
# XML-RPC Methods for the Image Object
|
93
|
-
#######################################################################
|
94
|
-
|
95
|
-
# Retrieves the information of the given Image.
|
96
|
-
def info()
|
97
|
-
super(IMAGE_METHODS[:info], 'IMAGE')
|
98
|
-
end
|
99
|
-
|
100
|
-
# Allocates a new Image in OpenNebula
|
101
|
-
#
|
102
|
-
# @param description [String] A string containing the template of the Image.
|
103
|
-
# @param ds_id [Integer] the target datastore ID
|
104
|
-
#
|
105
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
106
|
-
# otherwise
|
107
|
-
def allocate(description, ds_id)
|
108
|
-
super(IMAGE_METHODS[:allocate],description, ds_id)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Replaces the template contents
|
112
|
-
#
|
113
|
-
# +new_template+ New template contents. If no argument is provided
|
114
|
-
# the object will be updated using the @xml variable
|
115
|
-
def update(new_template=nil)
|
116
|
-
super(IMAGE_METHODS[:update], new_template)
|
117
|
-
end
|
118
|
-
|
119
|
-
# Enables an Image
|
120
|
-
def enable
|
121
|
-
set_enabled(true)
|
122
|
-
end
|
123
|
-
|
124
|
-
# Disables an Image
|
125
|
-
def disable
|
126
|
-
set_enabled(false)
|
127
|
-
end
|
128
|
-
|
129
|
-
# Publishes the Image, to be used by other users
|
130
|
-
def publish
|
131
|
-
set_publish(true)
|
132
|
-
end
|
133
|
-
|
134
|
-
# Unplubishes the Image
|
135
|
-
def unpublish
|
136
|
-
set_publish(false)
|
137
|
-
end
|
138
|
-
|
139
|
-
# Makes the Image persistent
|
140
|
-
def persistent
|
141
|
-
set_persistent(true)
|
142
|
-
end
|
143
|
-
|
144
|
-
# Makes the Image non persistent
|
145
|
-
def nonpersistent
|
146
|
-
set_persistent(false)
|
147
|
-
end
|
148
|
-
|
149
|
-
# Deletes the Image
|
150
|
-
def delete()
|
151
|
-
super(IMAGE_METHODS[:delete])
|
152
|
-
end
|
153
|
-
|
154
|
-
# Changes the owner/group
|
155
|
-
# uid:: _Integer_ the new owner id. Set to -1 to leave the current one
|
156
|
-
# gid:: _Integer_ the new group id. Set to -1 to leave the current one
|
157
|
-
# [return] nil in case of success or an Error object
|
158
|
-
def chown(uid, gid)
|
159
|
-
super(IMAGE_METHODS[:chown], uid, gid)
|
160
|
-
end
|
161
|
-
|
162
|
-
# Changes the Image permissions.
|
163
|
-
#
|
164
|
-
# @param octet [String] Permissions octed , e.g. 640
|
165
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
166
|
-
# otherwise
|
167
|
-
def chmod_octet(octet)
|
168
|
-
super(IMAGE_METHODS[:chmod], octet)
|
169
|
-
end
|
170
|
-
|
171
|
-
# Changes the Image permissions.
|
172
|
-
# Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
|
173
|
-
#
|
174
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
175
|
-
# otherwise
|
176
|
-
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
177
|
-
other_m, other_a)
|
178
|
-
super(IMAGE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
179
|
-
group_m, group_a, other_u, other_m, other_a)
|
180
|
-
end
|
181
|
-
|
182
|
-
# Changes the Image type
|
183
|
-
# @param type [String] new Image type
|
184
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
185
|
-
# otherwise
|
186
|
-
def chtype(type)
|
187
|
-
return Error.new('ID not defined') if !@pe_id
|
188
|
-
|
189
|
-
rc = @client.call(IMAGE_METHODS[:chtype], @pe_id, type)
|
190
|
-
rc = nil if !OpenNebula.is_error?(rc)
|
191
|
-
|
192
|
-
return rc
|
193
|
-
end
|
194
|
-
|
195
|
-
# Clones this Image into a new one
|
196
|
-
#
|
197
|
-
# @param [String] name for the new Image.
|
198
|
-
#
|
199
|
-
# @return [Integer, OpenNebula::Error] The new Image ID in case
|
200
|
-
# of success, Error otherwise
|
201
|
-
def clone(name)
|
202
|
-
return Error.new('ID not defined') if !@pe_id
|
203
|
-
|
204
|
-
rc = @client.call(IMAGE_METHODS[:clone], @pe_id, name)
|
205
|
-
|
206
|
-
return rc
|
207
|
-
end
|
208
|
-
|
209
|
-
# Renames this Image
|
210
|
-
#
|
211
|
-
# @param name [String] New name for the Image.
|
212
|
-
#
|
213
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
214
|
-
# otherwise
|
215
|
-
def rename(name)
|
216
|
-
return call(IMAGE_METHODS[:rename], @pe_id, name)
|
217
|
-
end
|
218
|
-
|
219
|
-
#######################################################################
|
220
|
-
# Helpers to get Image information
|
221
|
-
#######################################################################
|
222
|
-
|
223
|
-
# Returns the state of the Image (numeric value)
|
224
|
-
def state
|
225
|
-
self['STATE'].to_i
|
226
|
-
end
|
227
|
-
|
228
|
-
# Returns the state of the Image (string value)
|
229
|
-
def state_str
|
230
|
-
IMAGE_STATES[state]
|
231
|
-
end
|
232
|
-
|
233
|
-
# Returns the state of the Image (string value)
|
234
|
-
def short_state_str
|
235
|
-
SHORT_IMAGE_STATES[state_str]
|
236
|
-
end
|
237
|
-
|
238
|
-
# Returns the type of the Image (numeric value)
|
239
|
-
def type
|
240
|
-
self['TYPE'].to_i
|
241
|
-
end
|
242
|
-
|
243
|
-
# Returns the type of the Image (string value)
|
244
|
-
def type_str
|
245
|
-
IMAGE_TYPES[type]
|
246
|
-
end
|
247
|
-
|
248
|
-
# Returns the state of the Image (string value)
|
249
|
-
def short_type_str
|
250
|
-
SHORT_IMAGE_TYPES[type_str]
|
251
|
-
end
|
252
|
-
|
253
|
-
# Returns the group identifier
|
254
|
-
# [return] _Integer_ the element's group ID
|
255
|
-
def gid
|
256
|
-
self['GID'].to_i
|
257
|
-
end
|
258
|
-
|
259
|
-
def public?
|
260
|
-
if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
|
261
|
-
true
|
262
|
-
else
|
263
|
-
false
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
private
|
268
|
-
|
269
|
-
def set_enabled(enabled)
|
270
|
-
return Error.new('ID not defined') if !@pe_id
|
271
|
-
|
272
|
-
rc = @client.call(IMAGE_METHODS[:enable], @pe_id, enabled)
|
273
|
-
rc = nil if !OpenNebula.is_error?(rc)
|
274
|
-
|
275
|
-
return rc
|
276
|
-
end
|
277
|
-
|
278
|
-
def set_publish(published)
|
279
|
-
group_u = published ? 1 : 0
|
280
|
-
|
281
|
-
chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
|
282
|
-
end
|
283
|
-
|
284
|
-
def set_persistent(persistence)
|
285
|
-
return Error.new('ID not defined') if !@pe_id
|
286
|
-
|
287
|
-
rc = @client.call(IMAGE_METHODS[:persistent], @pe_id, persistence)
|
288
|
-
rc = nil if !OpenNebula.is_error?(rc)
|
289
|
-
|
290
|
-
return rc
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
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
|
-
end
|
74
|
-
end
|
data/lib/opennebula/ldap_auth.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
# ---------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2010-2012, 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
|
-
|
@@ -1,70 +0,0 @@
|
|
1
|
-
# ---------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2010-2012, 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
|
-
|
data/lib/opennebula/pool.rb
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
|
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
|
-
|
26
|
-
protected
|
27
|
-
#pool:: _String_ XML name of the root element
|
28
|
-
#element:: _String_ XML name of the Pool elements
|
29
|
-
#client:: _Client_ represents a XML-RPC connection
|
30
|
-
def initialize(pool,element,client)
|
31
|
-
super(nil)
|
32
|
-
|
33
|
-
@pool_name = pool.upcase
|
34
|
-
@element_name = element.upcase
|
35
|
-
|
36
|
-
@client = client
|
37
|
-
end
|
38
|
-
|
39
|
-
# Default Factory Method for the Pools. The factory method returns an
|
40
|
-
# suitable PoolElement object. Each Pool MUST implement the
|
41
|
-
# corresponding factory method
|
42
|
-
# element_xml:: _XML_ XML element describing the pool element
|
43
|
-
# [return] a PoolElement object
|
44
|
-
def factory(element_xml)
|
45
|
-
OpenNebula::PoolElement.new(element_xml,client)
|
46
|
-
end
|
47
|
-
|
48
|
-
#######################################################################
|
49
|
-
# Common XML-RPC Methods for all the Pool Types
|
50
|
-
#######################################################################
|
51
|
-
|
52
|
-
#Gets the pool without any filter. Host, Group and User Pools
|
53
|
-
# xml_method:: _String_ the name of the XML-RPC method
|
54
|
-
def info(xml_method)
|
55
|
-
return xmlrpc_info(xml_method)
|
56
|
-
end
|
57
|
-
|
58
|
-
def info_all(xml_method, *args)
|
59
|
-
return xmlrpc_info(xml_method,INFO_ALL,-1,-1, *args)
|
60
|
-
end
|
61
|
-
|
62
|
-
def info_mine(xml_method, *args)
|
63
|
-
return xmlrpc_info(xml_method,INFO_MINE,-1,-1, *args)
|
64
|
-
end
|
65
|
-
|
66
|
-
def info_group(xml_method, *args)
|
67
|
-
return xmlrpc_info(xml_method,INFO_GROUP,-1,-1, *args)
|
68
|
-
end
|
69
|
-
|
70
|
-
def info_filter(xml_method, who, start_id, end_id, *args)
|
71
|
-
return xmlrpc_info(xml_method,who, start_id, end_id, *args)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Retrieves the monitoring data for all the Objects in the pool
|
75
|
-
#
|
76
|
-
# @param [String] xml_method xml-rcp method
|
77
|
-
# @param [String] root_elem Root for each individual PoolElement
|
78
|
-
# @param [String] timestamp_elem Name of the XML element with the last
|
79
|
-
# monitorization timestamp
|
80
|
-
# @param [Array<String>] xpath_expressions Elements to retrieve.
|
81
|
-
# @param args arguemnts for the xml_method call
|
82
|
-
#
|
83
|
-
# @return [Hash<String, <Hash<String, Array<Array<int>>>>>,
|
84
|
-
# OpenNebula::Error] The first level hash uses the Object ID as keys,
|
85
|
-
# and as value a Hash with the requested xpath expressions,
|
86
|
-
# and an Array of 'timestamp, value'.
|
87
|
-
def monitoring(xml_method, root_elem, timestamp_elem, xpath_expressions,
|
88
|
-
*args)
|
89
|
-
|
90
|
-
rc = @client.call(xml_method, *args)
|
91
|
-
|
92
|
-
if ( OpenNebula.is_error?(rc) )
|
93
|
-
return rc
|
94
|
-
end
|
95
|
-
|
96
|
-
xmldoc = XMLElement.new
|
97
|
-
xmldoc.initialize_xml(rc, 'MONITORING_DATA')
|
98
|
-
|
99
|
-
hash = {}
|
100
|
-
|
101
|
-
# Get all existing Object IDs
|
102
|
-
ids = xmldoc.retrieve_elements("#{root_elem}/ID")
|
103
|
-
|
104
|
-
if ids.nil?
|
105
|
-
return hash
|
106
|
-
else
|
107
|
-
ids.uniq!
|
108
|
-
end
|
109
|
-
|
110
|
-
ids.each { |id|
|
111
|
-
hash[id] = OpenNebula.process_monitoring(
|
112
|
-
xmldoc, root_elem, timestamp_elem, id, xpath_expressions)
|
113
|
-
|
114
|
-
}
|
115
|
-
|
116
|
-
return hash
|
117
|
-
end
|
118
|
-
|
119
|
-
private
|
120
|
-
# Calls to the corresponding info method to retreive the pool
|
121
|
-
# representation in XML format
|
122
|
-
# xml_method:: _String_ the name of the XML-RPC method
|
123
|
-
# args:: _Array_ with additional arguments for the info call
|
124
|
-
# [return] nil in case of success or an Error object
|
125
|
-
def xmlrpc_info(xml_method,*args)
|
126
|
-
rc = @client.call(xml_method,*args)
|
127
|
-
|
128
|
-
if !OpenNebula.is_error?(rc)
|
129
|
-
initialize_xml(rc,@pool_name)
|
130
|
-
rc = nil
|
131
|
-
end
|
132
|
-
|
133
|
-
return rc
|
134
|
-
end
|
135
|
-
|
136
|
-
public
|
137
|
-
# Constants for info queries (include/RequestManagerPoolInfoFilter.h)
|
138
|
-
INFO_GROUP = -1
|
139
|
-
INFO_ALL = -2
|
140
|
-
INFO_MINE = -3
|
141
|
-
|
142
|
-
# Iterates over every PoolElement in the Pool and calls the block with a
|
143
|
-
# a PoolElement obtained calling the factory method
|
144
|
-
# block:: _Block_
|
145
|
-
def each(&block)
|
146
|
-
each_element(block) if @xml
|
147
|
-
end
|
148
|
-
|
149
|
-
# DO NOT USE - ONLY REXML BACKEND
|
150
|
-
def to_str
|
151
|
-
str = ""
|
152
|
-
REXML::Formatters::Pretty.new(1).write(@xml,str)
|
153
|
-
|
154
|
-
return str
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|