opennebula 3.9.80.beta
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.
- 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,213 @@
|
|
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_element'
|
19
|
+
|
20
|
+
module OpenNebula
|
21
|
+
class Template < PoolElement
|
22
|
+
#######################################################################
|
23
|
+
# Constants and Class Methods
|
24
|
+
#######################################################################
|
25
|
+
|
26
|
+
|
27
|
+
TEMPLATE_METHODS = {
|
28
|
+
:allocate => "template.allocate",
|
29
|
+
:instantiate => "template.instantiate",
|
30
|
+
:info => "template.info",
|
31
|
+
:update => "template.update",
|
32
|
+
:delete => "template.delete",
|
33
|
+
:chown => "template.chown",
|
34
|
+
:chmod => "template.chmod",
|
35
|
+
:clone => "template.clone",
|
36
|
+
:rename => "template.rename"
|
37
|
+
}
|
38
|
+
|
39
|
+
# Creates a Template description with just its identifier
|
40
|
+
# this method should be used to create plain Template objects.
|
41
|
+
# +id+ the id of the user
|
42
|
+
#
|
43
|
+
# Example:
|
44
|
+
# template = Template.new(Template.build_xml(3),rpc_client)
|
45
|
+
#
|
46
|
+
def Template.build_xml(pe_id=nil)
|
47
|
+
if pe_id
|
48
|
+
obj_xml = "<VMTEMPLATE><ID>#{pe_id}</ID></VMTEMPLATE>"
|
49
|
+
else
|
50
|
+
obj_xml = "<VMTEMPLATE></VMTEMPLATE>"
|
51
|
+
end
|
52
|
+
|
53
|
+
XMLElement.build_xml(obj_xml,'VMTEMPLATE')
|
54
|
+
end
|
55
|
+
|
56
|
+
# Class constructor
|
57
|
+
def initialize(xml, client)
|
58
|
+
super(xml,client)
|
59
|
+
|
60
|
+
@client = client
|
61
|
+
end
|
62
|
+
|
63
|
+
#######################################################################
|
64
|
+
# XML-RPC Methods for the Template Object
|
65
|
+
#######################################################################
|
66
|
+
|
67
|
+
# Retrieves the information of the given Template.
|
68
|
+
def info()
|
69
|
+
super(TEMPLATE_METHODS[:info], 'VMTEMPLATE')
|
70
|
+
end
|
71
|
+
|
72
|
+
alias_method :info!, :info
|
73
|
+
|
74
|
+
# Allocates a new Template in OpenNebula
|
75
|
+
#
|
76
|
+
# @param description [String] The contents of the Template.
|
77
|
+
#
|
78
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
79
|
+
# otherwise
|
80
|
+
def allocate(description)
|
81
|
+
super(TEMPLATE_METHODS[:allocate], description)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Deletes the Template
|
85
|
+
def delete()
|
86
|
+
super(TEMPLATE_METHODS[:delete])
|
87
|
+
end
|
88
|
+
|
89
|
+
# Creates a VM instance from a Template
|
90
|
+
#
|
91
|
+
# @param name [String] Name for the VM instance. If it is an empty
|
92
|
+
# string OpenNebula will set a default name
|
93
|
+
# @param hold [true,false] false to create the VM in pending state,
|
94
|
+
# true to create it on hold
|
95
|
+
# @param template [String] User provided Template to merge with the
|
96
|
+
# one being instantiated
|
97
|
+
#
|
98
|
+
# @return [Integer, OpenNebula::Error] The new VM id, Error
|
99
|
+
# otherwise
|
100
|
+
def instantiate(name="", hold=false, template="")
|
101
|
+
return Error.new('ID not defined') if !@pe_id
|
102
|
+
|
103
|
+
name ||= ""
|
104
|
+
template ||= ""
|
105
|
+
|
106
|
+
rc = @client.call(
|
107
|
+
TEMPLATE_METHODS[:instantiate], @pe_id, name, hold, template)
|
108
|
+
|
109
|
+
return rc
|
110
|
+
end
|
111
|
+
|
112
|
+
# Replaces the template contents
|
113
|
+
#
|
114
|
+
# +new_template+ New template contents
|
115
|
+
def update(new_template)
|
116
|
+
return Error.new('ID not defined') if !@pe_id
|
117
|
+
|
118
|
+
super(TEMPLATE_METHODS[:update], new_template)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Publishes the Template, to be used by other users
|
122
|
+
def publish
|
123
|
+
set_publish(true)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Unplubishes the Image
|
127
|
+
def unpublish
|
128
|
+
set_publish(false)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Changes the owner/group
|
132
|
+
# uid:: _Integer_ the new owner id. Set to -1 to leave the current one
|
133
|
+
# gid:: _Integer_ the new group id. Set to -1 to leave the current one
|
134
|
+
# [return] nil in case of success or an Error object
|
135
|
+
def chown(uid, gid)
|
136
|
+
super(TEMPLATE_METHODS[:chown], uid, gid)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Changes the Template permissions.
|
140
|
+
#
|
141
|
+
# @param octet [String] Permissions octed , e.g. 640
|
142
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
143
|
+
# otherwise
|
144
|
+
def chmod_octet(octet)
|
145
|
+
super(TEMPLATE_METHODS[:chmod], octet)
|
146
|
+
end
|
147
|
+
|
148
|
+
# Changes the Template permissions.
|
149
|
+
# Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
|
150
|
+
#
|
151
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
152
|
+
# otherwise
|
153
|
+
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
154
|
+
other_m, other_a)
|
155
|
+
super(TEMPLATE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
156
|
+
group_m, group_a, other_u, other_m, other_a)
|
157
|
+
end
|
158
|
+
|
159
|
+
# Clones this Template into a new one
|
160
|
+
#
|
161
|
+
# @param [String] name for the new Template.
|
162
|
+
#
|
163
|
+
# @return [Integer, OpenNebula::Error] The new Template ID in case
|
164
|
+
# of success, Error otherwise
|
165
|
+
def clone(name)
|
166
|
+
return Error.new('ID not defined') if !@pe_id
|
167
|
+
|
168
|
+
rc = @client.call(TEMPLATE_METHODS[:clone], @pe_id, name)
|
169
|
+
|
170
|
+
return rc
|
171
|
+
end
|
172
|
+
|
173
|
+
# Renames this Template
|
174
|
+
#
|
175
|
+
# @param name [String] New name for the Template.
|
176
|
+
#
|
177
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
178
|
+
# otherwise
|
179
|
+
def rename(name)
|
180
|
+
return call(TEMPLATE_METHODS[:rename], @pe_id, name)
|
181
|
+
end
|
182
|
+
|
183
|
+
#######################################################################
|
184
|
+
# Helpers to get Template information
|
185
|
+
#######################################################################
|
186
|
+
|
187
|
+
# Returns the group identifier
|
188
|
+
# [return] _Integer_ the element's group ID
|
189
|
+
def gid
|
190
|
+
self['GID'].to_i
|
191
|
+
end
|
192
|
+
|
193
|
+
def owner_id
|
194
|
+
self['UID'].to_i
|
195
|
+
end
|
196
|
+
|
197
|
+
def public?
|
198
|
+
if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
|
199
|
+
true
|
200
|
+
else
|
201
|
+
false
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
private
|
206
|
+
|
207
|
+
def set_publish(published)
|
208
|
+
group_u = published ? 1 : 0
|
209
|
+
|
210
|
+
chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -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 TemplatePool < Pool
|
22
|
+
#######################################################################
|
23
|
+
# Constants and Class attribute accessors
|
24
|
+
#######################################################################
|
25
|
+
|
26
|
+
|
27
|
+
TEMPLATE_POOL_METHODS = {
|
28
|
+
:info => "templatepool.info"
|
29
|
+
}
|
30
|
+
|
31
|
+
#######################################################################
|
32
|
+
# Class constructor & Pool Methods
|
33
|
+
#######################################################################
|
34
|
+
|
35
|
+
# +client+ a Client object that represents an XML-RPC connection
|
36
|
+
# +user_id+ used to refer to a Pool with Templates from that user
|
37
|
+
def initialize(client, user_id=-1)
|
38
|
+
super('VMTEMPLATE_POOL','VMTEMPLATE',client)
|
39
|
+
|
40
|
+
@user_id = user_id
|
41
|
+
end
|
42
|
+
|
43
|
+
# Factory method to create Template objects
|
44
|
+
def factory(element_xml)
|
45
|
+
OpenNebula::Template.new(element_xml,@client)
|
46
|
+
end
|
47
|
+
|
48
|
+
#######################################################################
|
49
|
+
# XML-RPC Methods for the Template 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(TEMPLATE_POOL_METHODS[:info],@user_id,-1,-1)
|
57
|
+
when 3
|
58
|
+
info_filter(TEMPLATE_POOL_METHODS[:info],args[0],args[1],args[2])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def info_all()
|
63
|
+
return super(TEMPLATE_POOL_METHODS[:info])
|
64
|
+
end
|
65
|
+
|
66
|
+
def info_mine()
|
67
|
+
return super(TEMPLATE_POOL_METHODS[:info])
|
68
|
+
end
|
69
|
+
|
70
|
+
def info_group()
|
71
|
+
return super(TEMPLATE_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,174 @@
|
|
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_element'
|
19
|
+
|
20
|
+
module OpenNebula
|
21
|
+
class User < PoolElement
|
22
|
+
#######################################################################
|
23
|
+
# Constants and Class Methods
|
24
|
+
#######################################################################
|
25
|
+
|
26
|
+
USER_METHODS = {
|
27
|
+
:info => "user.info",
|
28
|
+
:allocate => "user.allocate",
|
29
|
+
:delete => "user.delete",
|
30
|
+
:passwd => "user.passwd",
|
31
|
+
:chgrp => "user.chgrp",
|
32
|
+
:update => "user.update",
|
33
|
+
:chauth => "user.chauth",
|
34
|
+
:quota => "user.quota"
|
35
|
+
}
|
36
|
+
|
37
|
+
SELF = -1
|
38
|
+
|
39
|
+
# Driver name for default core authentication
|
40
|
+
CORE_AUTH = "core"
|
41
|
+
|
42
|
+
# Driver name for default core authentication
|
43
|
+
CIPHER_AUTH = "server_cipher"
|
44
|
+
|
45
|
+
# Driver name for ssh authentication
|
46
|
+
SSH_AUTH = "ssh"
|
47
|
+
|
48
|
+
# Driver name for x509 authentication
|
49
|
+
X509_AUTH = "x509"
|
50
|
+
|
51
|
+
# Driver name for x509 proxy authentication
|
52
|
+
X509_PROXY_AUTH = "x509_proxy"
|
53
|
+
|
54
|
+
# Creates a User description with just its identifier
|
55
|
+
# this method should be used to create plain User objects.
|
56
|
+
# +id+ the id of the user
|
57
|
+
#
|
58
|
+
# Example:
|
59
|
+
# user = User.new(User.build_xml(3),rpc_client)
|
60
|
+
#
|
61
|
+
def User.build_xml(pe_id=nil)
|
62
|
+
if pe_id
|
63
|
+
user_xml = "<USER><ID>#{pe_id}</ID></USER>"
|
64
|
+
else
|
65
|
+
user_xml = "<USER></USER>"
|
66
|
+
end
|
67
|
+
|
68
|
+
XMLElement.build_xml(user_xml, 'USER')
|
69
|
+
end
|
70
|
+
|
71
|
+
# Class constructor
|
72
|
+
def initialize(xml, client)
|
73
|
+
super(xml,client)
|
74
|
+
|
75
|
+
@client = client
|
76
|
+
end
|
77
|
+
|
78
|
+
#######################################################################
|
79
|
+
# XML-RPC Methods for the User Object
|
80
|
+
#######################################################################
|
81
|
+
|
82
|
+
# Retrieves the information of the given User.
|
83
|
+
def info()
|
84
|
+
super(USER_METHODS[:info], 'USER')
|
85
|
+
end
|
86
|
+
|
87
|
+
alias_method :info!, :info
|
88
|
+
|
89
|
+
# Allocates a new User in OpenNebula
|
90
|
+
#
|
91
|
+
# +username+ Name of the new user.
|
92
|
+
#
|
93
|
+
# +password+ Password for the new user
|
94
|
+
def allocate(username, password, driver=CORE_AUTH)
|
95
|
+
super(USER_METHODS[:allocate], username, password, driver)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Replaces the template contents
|
99
|
+
#
|
100
|
+
# +new_template+ New template contents
|
101
|
+
def update(new_template)
|
102
|
+
super(USER_METHODS[:update], new_template)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Deletes the User
|
106
|
+
def delete()
|
107
|
+
super(USER_METHODS[:delete])
|
108
|
+
end
|
109
|
+
|
110
|
+
# Changes the password of the given User
|
111
|
+
#
|
112
|
+
# +password+ String containing the new password
|
113
|
+
def passwd(password)
|
114
|
+
return Error.new('ID not defined') if !@pe_id
|
115
|
+
|
116
|
+
rc = @client.call(USER_METHODS[:passwd], @pe_id, password)
|
117
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
118
|
+
|
119
|
+
return rc
|
120
|
+
end
|
121
|
+
|
122
|
+
# Changes the main group
|
123
|
+
# gid:: _Integer_ the new group id. Set to -1 to leave the current one
|
124
|
+
# [return] nil in case of success or an Error object
|
125
|
+
def chgrp(gid)
|
126
|
+
return Error.new('ID not defined') if !@pe_id
|
127
|
+
|
128
|
+
rc = @client.call(USER_METHODS[:chgrp],@pe_id, gid)
|
129
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
130
|
+
|
131
|
+
return rc
|
132
|
+
end
|
133
|
+
|
134
|
+
# Changes the auth driver and the password of the given User
|
135
|
+
#
|
136
|
+
# @param auth [String] the new auth driver
|
137
|
+
# @param password [String] the new password. If it is an empty string,
|
138
|
+
# the user password is not changed
|
139
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
140
|
+
# otherwise
|
141
|
+
def chauth(auth, password="")
|
142
|
+
return Error.new('ID not defined') if !@pe_id
|
143
|
+
|
144
|
+
rc = @client.call(USER_METHODS[:chauth],@pe_id, auth, password)
|
145
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
146
|
+
|
147
|
+
return rc
|
148
|
+
end
|
149
|
+
|
150
|
+
# Sets the user quota limits
|
151
|
+
# @param quota [String] a template (XML or txt) with the new quota limits
|
152
|
+
#
|
153
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
154
|
+
# otherwise
|
155
|
+
def set_quota(quota)
|
156
|
+
return Error.new('ID not defined') if !@pe_id
|
157
|
+
|
158
|
+
rc = @client.call(USER_METHODS[:quota],@pe_id, quota)
|
159
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
160
|
+
|
161
|
+
return rc
|
162
|
+
end
|
163
|
+
|
164
|
+
#######################################################################
|
165
|
+
# Helpers to get User information
|
166
|
+
#######################################################################
|
167
|
+
|
168
|
+
# Returns the group identifier
|
169
|
+
# [return] _Integer_ the element's group ID
|
170
|
+
def gid
|
171
|
+
self['GID'].to_i
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|