occi 2.0.0 → 2.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.
@@ -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
@@ -1,137 +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
- begin # require 'rubygems'
19
- require 'rubygems'
20
- rescue Exception
21
- end
22
-
23
- 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
-
46
- module OpenNebula
47
-
48
- # The Error Class represents a generic error in the OpenNebula
49
- # library. It contains a readable representation of the error.
50
- # Any function in the OpenNebula module will return an Error
51
- # object in case of error.
52
- class Error
53
- ESUCCESS = 0x0000
54
- EAUTHENTICATION = 0x0100
55
- EAUTHORIZATION = 0x0200
56
- ENO_EXISTS = 0x0400
57
- EACTION = 0x0800
58
- EXML_RPC_API = 0x1000
59
- EINTERNAL = 0x2000
60
- ENOTDEFINED = 0x1111
61
-
62
- attr_reader :message, :errno
63
-
64
- # +message+ Description of the error
65
- # +errno+ OpenNebula code error
66
- def initialize(message=nil, errno=0x1111)
67
- @message = message
68
- @errno = errno
69
- end
70
-
71
- def to_str()
72
- @message
73
- end
74
- end
75
-
76
- # Returns true if the object returned by a method of the OpenNebula
77
- # library is an Error
78
- def self.is_error?(value)
79
- value.class==OpenNebula::Error
80
- end
81
-
82
- # The client class, represents the connection with the core and handles the
83
- # xml-rpc calls.
84
- class Client
85
- attr_accessor :one_auth
86
-
87
- begin
88
- require 'xmlparser'
89
- XMLPARSER=true
90
- rescue LoadError
91
- XMLPARSER=false
92
- end
93
-
94
- def initialize(secret=nil, endpoint=nil)
95
- if secret
96
- @one_auth = secret
97
- elsif ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"])
98
- @one_auth = File.read(ENV["ONE_AUTH"])
99
- elsif File.file?(ENV["HOME"]+"/.one/one_auth")
100
- @one_auth = File.read(ENV["HOME"]+"/.one/one_auth")
101
- else
102
- raise "ONE_AUTH file not present"
103
- end
104
-
105
- @one_auth.rstrip!
106
-
107
- if endpoint
108
- @one_endpoint = endpoint
109
- elsif ENV["ONE_XMLRPC"]
110
- @one_endpoint = ENV["ONE_XMLRPC"]
111
- else
112
- @one_endpoint = "http://localhost:2633/RPC2"
113
- end
114
-
115
- @server = XMLRPC::Client.new2(@one_endpoint)
116
- end
117
-
118
- def call(action, *args)
119
-
120
- if XMLPARSER
121
- @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new)
122
- end
123
-
124
- begin
125
- response = @server.call_async("one."+action, @one_auth, *args)
126
-
127
- if response[0] == false
128
- Error.new(response[1], response[2])
129
- else
130
- response[1] #response[1..-1]
131
- end
132
- rescue Exception => e
133
- Error.new(e.message)
134
- end
135
- end
136
- end
137
- end
@@ -1,285 +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
- module OpenNebula
19
-
20
- # The Pool class represents a generic OpenNebula Pool in XML format
21
- # and provides the basic functionality to handle the Pool elements
22
- class Pool < XMLPool
23
- include Enumerable
24
-
25
- protected
26
- #pool:: _String_ XML name of the root element
27
- #element:: _String_ XML name of the Pool elements
28
- #client:: _Client_ represents a XML-RPC connection
29
- def initialize(pool,element,client)
30
- super(nil)
31
-
32
- @pool_name = pool.upcase
33
- @element_name = element.upcase
34
-
35
- @client = client
36
- end
37
-
38
- # Default Factory Method for the Pools. The factory method returns an
39
- # suitable PoolElement object. Each Pool MUST implement the
40
- # corresponding factory method
41
- # element_xml:: _XML_ XML element describing the pool element
42
- # [return] a PoolElement object
43
- def factory(element_xml)
44
- OpenNebula::PoolElement.new(element_xml,client)
45
- end
46
-
47
- #######################################################################
48
- # Common XML-RPC Methods for all the Pool Types
49
- #######################################################################
50
-
51
- #Gets the pool without any filter. Host, Group and User Pools
52
- # xml_method:: _String_ the name of the XML-RPC method
53
- def info(xml_method)
54
- return xmlrpc_info(xml_method)
55
- end
56
-
57
- def info_all(xml_method)
58
- return xmlrpc_info(xml_method,INFO_ALL,-1,-1)
59
- end
60
-
61
- def info_mine(xml_method)
62
- return xmlrpc_info(xml_method,INFO_MINE,-1,-1)
63
- end
64
-
65
- def info_group(xml_method)
66
- return xmlrpc_info(xml_method,INFO_GROUP,-1,-1)
67
- end
68
-
69
- def info_filter(xml_method, who, start_id, end_id)
70
- return xmlrpc_info(xml_method,who, start_id, end_id)
71
- end
72
-
73
- private
74
- # Calls to the corresponding info method to retreive the pool
75
- # representation in XML format
76
- # xml_method:: _String_ the name of the XML-RPC method
77
- # args:: _Array_ with additional arguments for the info call
78
- # [return] nil in case of success or an Error object
79
- def xmlrpc_info(xml_method,*args)
80
- rc = @client.call(xml_method,*args)
81
-
82
- if !OpenNebula.is_error?(rc)
83
- initialize_xml(rc,@pool_name)
84
- rc = nil
85
- end
86
-
87
- return rc
88
- end
89
-
90
- public
91
- # Constants for info queries (include/RequestManagerPoolInfoFilter.h)
92
- INFO_GROUP = -1
93
- INFO_ALL = -2
94
- INFO_MINE = -3
95
-
96
- # Iterates over every PoolElement in the Pool and calls the block with a
97
- # a PoolElement obtained calling the factory method
98
- # block:: _Block_
99
- def each(&block)
100
- each_element(block) if @xml
101
- end
102
-
103
- # DO NOT USE - ONLY REXML BACKEND
104
- def to_str
105
- str = ""
106
- REXML::Formatters::Pretty.new(1).write(@xml,str)
107
-
108
- return str
109
- end
110
- end
111
-
112
- # The PoolElement Class represents a generic element of a Pool in
113
- # XML format
114
- class PoolElement < XMLElement
115
-
116
- protected
117
- # node:: _XML_is a XML element that represents the Pool element
118
- # client:: _Client_ represents a XML-RPC connection
119
- def initialize(node, client)
120
- @xml = node
121
- @client = client
122
-
123
- if self['ID']
124
- @pe_id = self['ID'].to_i
125
- else
126
- @pe_id = nil
127
- end
128
- @name = self['NAME'] if self['NAME']
129
- end
130
-
131
- #######################################################################
132
- # Common XML-RPC Methods for all the Pool Element Types
133
- #######################################################################
134
-
135
- # Calls to the corresponding info method to retreive the element
136
- # detailed information in XML format
137
- # xml_method:: _String_ the name of the XML-RPC method
138
- # root_element:: _String_ Base XML element
139
- # [return] nil in case of success or an Error object
140
- def info(xml_method, root_element)
141
- return Error.new('ID not defined') if !@pe_id
142
-
143
- rc = @client.call(xml_method,@pe_id)
144
-
145
- if !OpenNebula.is_error?(rc)
146
- initialize_xml(rc, root_element)
147
- rc = nil
148
-
149
- @pe_id = self['ID'].to_i if self['ID']
150
- @name = self['NAME'] if self['NAME']
151
- end
152
-
153
- return rc
154
- end
155
-
156
- # Calls to the corresponding allocate method to create a new element
157
- # in the OpenNebula core
158
- # xml_method:: _String_ the name of the XML-RPC method
159
- # args:: _Array_ additional arguments including the template for the
160
- # new element
161
- # [return] nil in case of success or an Error object
162
- def allocate(xml_method, *args)
163
- rc = @client.call(xml_method, *args)
164
-
165
- if !OpenNebula.is_error?(rc)
166
- @pe_id = rc
167
- rc = nil
168
- end
169
-
170
- return rc
171
- end
172
-
173
- # Calls to the corresponding update method to modify
174
- # the object's template
175
- # xml_method:: _String_ the name of the XML-RPC method
176
- # new_template:: _String_ the new template contents
177
- # [return] nil in case of success or an Error object
178
- def update(xml_method, new_template)
179
- return Error.new('ID not defined') if !@pe_id
180
-
181
- rc = @client.call(xml_method,@pe_id, new_template)
182
- rc = nil if !OpenNebula.is_error?(rc)
183
-
184
- return rc
185
- end
186
-
187
- # Calls to the corresponding delete method to remove this element
188
- # from the OpenNebula core
189
- # xml_method:: _String_ the name of the XML-RPC method
190
- # [return] nil in case of success or an Error object
191
- def delete(xml_method)
192
- return Error.new('ID not defined') if !@pe_id
193
-
194
- rc = @client.call(xml_method,@pe_id)
195
- rc = nil if !OpenNebula.is_error?(rc)
196
-
197
- return rc
198
- end
199
-
200
- # Calls to the corresponding chown method to modify
201
- # the object's owner and group
202
- # xml_method:: _String_ the name of the XML-RPC method
203
- # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
204
- # gid:: _Integer_ the new group id. Set to -1 to leave the current one
205
- # [return] nil in case of success or an Error object
206
- def chown(xml_method, uid, gid)
207
- return Error.new('ID not defined') if !@pe_id
208
-
209
- rc = @client.call(xml_method,@pe_id, uid, gid)
210
- rc = nil if !OpenNebula.is_error?(rc)
211
-
212
- return rc
213
- end
214
-
215
- # Calls to the corresponding chmod method to modify
216
- # the object's permission bits
217
- #
218
- # @param xml_method [String] the name of the XML-RPC method
219
- # @param octet [String] Permissions octed , e.g. 640
220
- # @return [nil, OpenNebula::Error] nil in case of success, Error
221
- # otherwise
222
- def chmod_octet(xml_method, octet)
223
- owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0
224
- owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0
225
- owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0
226
- group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0
227
- group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0
228
- group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0
229
- other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0
230
- other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0
231
- other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0
232
-
233
- chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
234
- other_m, other_a)
235
- end
236
-
237
- # Calls to the corresponding chmod method to modify
238
- # the object's permission bits
239
- # Each [Integer] parameter must be 1 to allow, 0 deny, -1 do not change
240
- #
241
- # @param xml_method [String] the name of the XML-RPC method
242
- # @return [nil, OpenNebula::Error] nil in case of success, Error
243
- # otherwise
244
- def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
245
- other_m, other_a)
246
- return Error.new('ID not defined') if !@pe_id
247
-
248
- rc = @client.call(xml_method, @pe_id, owner_u, owner_m,
249
- owner_a, group_u, group_m, group_a, other_u,
250
- other_m, other_a)
251
- rc = nil if !OpenNebula.is_error?(rc)
252
-
253
- return rc
254
- end
255
-
256
- public
257
-
258
- # Creates new element specifying its id
259
- # id:: identifyier of the element
260
- # client:: initialized OpenNebula::Client object
261
- def self.new_with_id(id, client=nil)
262
- self.new(self.build_xml(id), client)
263
- end
264
-
265
- # Returns element identifier
266
- # [return] _Integer_ the PoolElement ID
267
- def id
268
- @pe_id
269
- end
270
-
271
- # Gets element name
272
- # [return] _String_ the PoolElement name
273
- def name
274
- @name
275
- end
276
-
277
- # DO NOT USE - ONLY REXML BACKEND
278
- def to_str
279
- str = ""
280
- REXML::Formatters::Pretty.new(1).write(@xml,str)
281
-
282
- return str
283
- end
284
- end
285
- end