opennebula-oca 3.8.0 → 3.9.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/{OpenNebula/Acl.rb → opennebula/acl.rb} +0 -0
- data/lib/{OpenNebula/AclPool.rb → opennebula/acl_pool.rb} +1 -1
- data/lib/{OpenNebula.rb → opennebula/client.rb} +0 -73
- data/lib/{OpenNebula/Cluster.rb → opennebula/cluster.rb} +1 -1
- data/lib/{OpenNebula/ClusterPool.rb → opennebula/cluster_pool.rb} +1 -1
- data/lib/{OpenNebula/Datastore.rb → opennebula/datastore.rb} +23 -1
- data/lib/{OpenNebula/DatastorePool.rb → opennebula/datastore_pool.rb} +1 -1
- data/lib/{OpenNebula/Document.rb → opennebula/document.rb} +13 -2
- data/lib/{OpenNebula/DocumentJSON.rb → opennebula/document_json.rb} +0 -0
- data/lib/{OpenNebula/DocumentPool.rb → opennebula/document_pool.rb} +2 -2
- data/lib/{OpenNebula/DocumentPoolJSON.rb → opennebula/document_pool_json.rb} +0 -0
- data/lib/opennebula/error.rb +52 -0
- data/lib/{OpenNebula/Group.rb → opennebula/group.rb} +1 -1
- data/lib/{OpenNebula/GroupPool.rb → opennebula/group_pool.rb} +1 -1
- data/lib/{OpenNebula/Host.rb → opennebula/host.rb} +1 -1
- data/lib/{OpenNebula/HostPool.rb → opennebula/host_pool.rb} +1 -1
- data/lib/{OpenNebula/Image.rb → opennebula/image.rb} +20 -6
- data/lib/{OpenNebula/ImagePool.rb → opennebula/image_pool.rb} +1 -1
- data/lib/opennebula/ldap_auth.rb +99 -0
- data/lib/opennebula/ldap_auth_spec.rb +70 -0
- data/lib/opennebula/pool.rb +157 -0
- data/lib/{OpenNebula/Pool.rb → opennebula/pool_element.rb} +1 -138
- 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 → opennebula/template.rb} +13 -2
- data/lib/{OpenNebula/TemplatePool.rb → opennebula/template_pool.rb} +1 -1
- data/lib/{OpenNebula/User.rb → opennebula/user.rb} +1 -1
- data/lib/{OpenNebula/UserPool.rb → opennebula/user_pool.rb} +1 -1
- data/lib/{OpenNebula/VirtualMachine.rb → opennebula/virtual_machine.rb} +45 -25
- data/lib/{OpenNebula/VirtualMachinePool.rb → opennebula/virtual_machine_pool.rb} +1 -1
- data/lib/{OpenNebula/VirtualNetwork.rb → opennebula/virtual_network.rb} +13 -2
- data/lib/{OpenNebula/VirtualNetworkPool.rb → opennebula/virtual_network_pool.rb} +1 -1
- data/lib/opennebula/x509_auth.rb +241 -0
- data/lib/{OpenNebula/XMLUtils.rb → opennebula/xml_element.rb} +12 -21
- data/lib/opennebula/xml_pool.rb +45 -0
- data/lib/opennebula/xml_utils.rb +34 -0
- data/lib/opennebula.rb +58 -0
- metadata +102 -63
File without changes
|
@@ -14,81 +14,9 @@
|
|
14
14
|
# limitations under the License. #
|
15
15
|
#--------------------------------------------------------------------------- #
|
16
16
|
|
17
|
-
|
18
|
-
begin # require 'rubygems'
|
19
|
-
require 'rubygems'
|
20
|
-
rescue Exception
|
21
|
-
end
|
22
|
-
|
23
17
|
require 'xmlrpc/client'
|
24
|
-
require 'digest/sha1'
|
25
|
-
require 'rexml/document'
|
26
|
-
require 'pp'
|
27
|
-
|
28
|
-
require 'OpenNebula/XMLUtils'
|
29
|
-
require 'OpenNebula/VirtualMachine'
|
30
|
-
require 'OpenNebula/VirtualMachinePool'
|
31
|
-
require 'OpenNebula/VirtualNetwork'
|
32
|
-
require 'OpenNebula/VirtualNetworkPool'
|
33
|
-
require 'OpenNebula/Image'
|
34
|
-
require 'OpenNebula/ImagePool'
|
35
|
-
require 'OpenNebula/User'
|
36
|
-
require 'OpenNebula/UserPool'
|
37
|
-
require 'OpenNebula/Host'
|
38
|
-
require 'OpenNebula/HostPool'
|
39
|
-
require 'OpenNebula/Template'
|
40
|
-
require 'OpenNebula/TemplatePool'
|
41
|
-
require 'OpenNebula/Group'
|
42
|
-
require 'OpenNebula/GroupPool'
|
43
|
-
require 'OpenNebula/Acl'
|
44
|
-
require 'OpenNebula/AclPool'
|
45
|
-
require 'OpenNebula/Datastore'
|
46
|
-
require 'OpenNebula/DatastorePool'
|
47
|
-
require 'OpenNebula/Cluster'
|
48
|
-
require 'OpenNebula/ClusterPool'
|
49
|
-
require 'OpenNebula/Document'
|
50
|
-
require 'OpenNebula/DocumentPool'
|
51
18
|
|
52
19
|
module OpenNebula
|
53
|
-
|
54
|
-
# OpenNebula version
|
55
|
-
VERSION = '3.8.0'
|
56
|
-
|
57
|
-
# The Error Class represents a generic error in the OpenNebula
|
58
|
-
# library. It contains a readable representation of the error.
|
59
|
-
# Any function in the OpenNebula module will return an Error
|
60
|
-
# object in case of error.
|
61
|
-
class Error
|
62
|
-
ESUCCESS = 0x0000
|
63
|
-
EAUTHENTICATION = 0x0100
|
64
|
-
EAUTHORIZATION = 0x0200
|
65
|
-
ENO_EXISTS = 0x0400
|
66
|
-
EACTION = 0x0800
|
67
|
-
EXML_RPC_API = 0x1000
|
68
|
-
EINTERNAL = 0x2000
|
69
|
-
ENOTDEFINED = 0x1111
|
70
|
-
|
71
|
-
attr_reader :message, :errno
|
72
|
-
|
73
|
-
# +message+ Description of the error
|
74
|
-
# +errno+ OpenNebula code error
|
75
|
-
def initialize(message=nil, errno=0x1111)
|
76
|
-
@message = message
|
77
|
-
@errno = errno
|
78
|
-
end
|
79
|
-
|
80
|
-
def to_str()
|
81
|
-
@message
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Returns true if the object returned by a method of the OpenNebula
|
86
|
-
# library is an Error
|
87
|
-
def self.is_error?(value)
|
88
|
-
value.class==OpenNebula::Error
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
20
|
if OpenNebula::NOKOGIRI
|
93
21
|
class NokogiriStreamParser < XMLRPC::XMLParser::AbstractStreamParser
|
94
22
|
def initialize
|
@@ -111,7 +39,6 @@ module OpenNebula
|
|
111
39
|
end
|
112
40
|
end
|
113
41
|
|
114
|
-
|
115
42
|
# The client class, represents the connection with the core and handles the
|
116
43
|
# xml-rpc calls.
|
117
44
|
class Client
|
@@ -15,7 +15,7 @@
|
|
15
15
|
#--------------------------------------------------------------------------- #
|
16
16
|
|
17
17
|
|
18
|
-
require '
|
18
|
+
require 'opennebula/pool_element'
|
19
19
|
|
20
20
|
module OpenNebula
|
21
21
|
class Datastore < PoolElement
|
@@ -32,6 +32,14 @@ module OpenNebula
|
|
32
32
|
:chmod => "datastore.chmod"
|
33
33
|
}
|
34
34
|
|
35
|
+
DATASTORE_TYPES=%w{IMAGE SYSTEM FILE}
|
36
|
+
|
37
|
+
SHORT_DATASTORE_TYPES = {
|
38
|
+
"IMAGE" => "img",
|
39
|
+
"SYSTEM"=> "sys",
|
40
|
+
"FILE" => "fil"
|
41
|
+
}
|
42
|
+
|
35
43
|
# Creates a Datastore description with just its identifier
|
36
44
|
# this method should be used to create plain Datastore objects.
|
37
45
|
# +id+ the id of the user
|
@@ -57,6 +65,20 @@ module OpenNebula
|
|
57
65
|
#######################################################################
|
58
66
|
# XML-RPC Methods for the Datastore Object
|
59
67
|
#######################################################################
|
68
|
+
# Returns the datastore type
|
69
|
+
def type
|
70
|
+
self['TYPE'].to_i
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns the datastore type (string value)
|
74
|
+
def type_str
|
75
|
+
DATASTORE_TYPES[type]
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns the datastore type (string value)
|
79
|
+
def short_type_str
|
80
|
+
SHORT_DATASTORE_TYPES[type_str]
|
81
|
+
end
|
60
82
|
|
61
83
|
# Retrieves the information of the given Datastore.
|
62
84
|
def info()
|
@@ -14,14 +14,14 @@
|
|
14
14
|
# limitations under the License. #
|
15
15
|
#--------------------------------------------------------------------------- #
|
16
16
|
|
17
|
-
require '
|
17
|
+
require 'opennebula/pool_element'
|
18
18
|
|
19
19
|
module OpenNebula
|
20
20
|
|
21
21
|
# All subclasses must define the DOCUMENT_TYPE constant.
|
22
22
|
#
|
23
23
|
# @example
|
24
|
-
# require '
|
24
|
+
# require 'opennebula/document'
|
25
25
|
#
|
26
26
|
# module OpenNebula
|
27
27
|
# class CustomObject < Document
|
@@ -44,6 +44,7 @@ module OpenNebula
|
|
44
44
|
:chown => "document.chown",
|
45
45
|
:chmod => "document.chmod",
|
46
46
|
:clone => "document.clone",
|
47
|
+
:rename => "document.rename"
|
47
48
|
}
|
48
49
|
|
49
50
|
# Creates a Document Object description with just its identifier
|
@@ -185,6 +186,16 @@ module OpenNebula
|
|
185
186
|
return rc
|
186
187
|
end
|
187
188
|
|
189
|
+
# Renames this Document
|
190
|
+
#
|
191
|
+
# @param name [String] New name for the Document.
|
192
|
+
#
|
193
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
194
|
+
# otherwise
|
195
|
+
def rename(name)
|
196
|
+
return call(DOCUMENT_METHODS[:rename], @pe_id, name)
|
197
|
+
end
|
198
|
+
|
188
199
|
#######################################################################
|
189
200
|
# Helpers to get Document information
|
190
201
|
#######################################################################
|
File without changes
|
@@ -14,7 +14,7 @@
|
|
14
14
|
# limitations under the License. #
|
15
15
|
#--------------------------------------------------------------------------- #
|
16
16
|
|
17
|
-
require '
|
17
|
+
require 'opennebula/pool'
|
18
18
|
|
19
19
|
module OpenNebula
|
20
20
|
|
@@ -22,7 +22,7 @@ module OpenNebula
|
|
22
22
|
# and the factory method.
|
23
23
|
#
|
24
24
|
# @example
|
25
|
-
# require '
|
25
|
+
# require 'opennebuña/document_pool'
|
26
26
|
#
|
27
27
|
# module OpenNebula
|
28
28
|
# class CustomObjectPool < DocumentPool
|
File without changes
|
@@ -0,0 +1,52 @@
|
|
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
|
+
module OpenNebula
|
19
|
+
# The Error Class represents a generic error in the OpenNebula
|
20
|
+
# library. It contains a readable representation of the error.
|
21
|
+
# Any function in the OpenNebula module will return an Error
|
22
|
+
# object in case of error.
|
23
|
+
class Error
|
24
|
+
ESUCCESS = 0x0000
|
25
|
+
EAUTHENTICATION = 0x0100
|
26
|
+
EAUTHORIZATION = 0x0200
|
27
|
+
ENO_EXISTS = 0x0400
|
28
|
+
EACTION = 0x0800
|
29
|
+
EXML_RPC_API = 0x1000
|
30
|
+
EINTERNAL = 0x2000
|
31
|
+
ENOTDEFINED = 0x1111
|
32
|
+
|
33
|
+
attr_reader :message, :errno
|
34
|
+
|
35
|
+
# +message+ Description of the error
|
36
|
+
# +errno+ OpenNebula code error
|
37
|
+
def initialize(message=nil, errno=0x1111)
|
38
|
+
@message = message
|
39
|
+
@errno = errno
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_str()
|
43
|
+
@message
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns true if the object returned by a method of the OpenNebula
|
48
|
+
# library is an Error
|
49
|
+
def self.is_error?(value)
|
50
|
+
value.class==OpenNebula::Error
|
51
|
+
end
|
52
|
+
end
|
@@ -15,7 +15,7 @@
|
|
15
15
|
#--------------------------------------------------------------------------- #
|
16
16
|
|
17
17
|
|
18
|
-
require '
|
18
|
+
require 'opennebula/pool_element'
|
19
19
|
require 'fileutils'
|
20
20
|
|
21
21
|
module OpenNebula
|
@@ -35,7 +35,8 @@ module OpenNebula
|
|
35
35
|
:chown => "image.chown",
|
36
36
|
:chmod => "image.chmod",
|
37
37
|
:chtype => "image.chtype",
|
38
|
-
:clone => "image.clone"
|
38
|
+
:clone => "image.clone",
|
39
|
+
:rename => "image.rename"
|
39
40
|
}
|
40
41
|
|
41
42
|
IMAGE_STATES=%w{INIT READY USED DISABLED LOCKED ERROR CLONE DELETE USED_PERS}
|
@@ -52,12 +53,15 @@ module OpenNebula
|
|
52
53
|
"USED_PERS" => "used"
|
53
54
|
}
|
54
55
|
|
55
|
-
IMAGE_TYPES=%w{OS CDROM DATABLOCK}
|
56
|
+
IMAGE_TYPES=%w{OS CDROM DATABLOCK KERNEL RAMDISK CONTEXT}
|
56
57
|
|
57
58
|
SHORT_IMAGE_TYPES={
|
58
|
-
"OS"
|
59
|
-
"CDROM"
|
60
|
-
"DATABLOCK"
|
59
|
+
"OS" => "OS",
|
60
|
+
"CDROM" => "CD",
|
61
|
+
"DATABLOCK" => "DB",
|
62
|
+
"KERNEL" => "KL",
|
63
|
+
"RAMDISK" => "RD",
|
64
|
+
"CONTEXT" => "CX"
|
61
65
|
}
|
62
66
|
|
63
67
|
# Creates an Image description with just its identifier
|
@@ -202,6 +206,16 @@ module OpenNebula
|
|
202
206
|
return rc
|
203
207
|
end
|
204
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
|
+
|
205
219
|
#######################################################################
|
206
220
|
# Helpers to get Image information
|
207
221
|
#######################################################################
|
@@ -0,0 +1,99 @@
|
|
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
|
+
|
@@ -0,0 +1,70 @@
|
|
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
|
+
|