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/document.rb
DELETED
@@ -1,259 +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/pool_element'
|
18
|
-
|
19
|
-
module OpenNebula
|
20
|
-
|
21
|
-
# All subclasses must define the DOCUMENT_TYPE constant.
|
22
|
-
#
|
23
|
-
# @example
|
24
|
-
# require 'opennebula/document'
|
25
|
-
#
|
26
|
-
# module OpenNebula
|
27
|
-
# class CustomObject < Document
|
28
|
-
#
|
29
|
-
# DOCUMENT_TYPE = 400
|
30
|
-
#
|
31
|
-
# end
|
32
|
-
# end
|
33
|
-
class Document < PoolElement
|
34
|
-
|
35
|
-
#######################################################################
|
36
|
-
# Constants and Class Methods
|
37
|
-
#######################################################################
|
38
|
-
|
39
|
-
DOCUMENT_METHODS = {
|
40
|
-
:allocate => "document.allocate",
|
41
|
-
:delete => "document.delete",
|
42
|
-
:info => "document.info",
|
43
|
-
:update => "document.update",
|
44
|
-
:chown => "document.chown",
|
45
|
-
:chmod => "document.chmod",
|
46
|
-
:clone => "document.clone",
|
47
|
-
:rename => "document.rename"
|
48
|
-
}
|
49
|
-
|
50
|
-
# Creates a Document Object description with just its identifier
|
51
|
-
# this method should be used to create plain Document objects.
|
52
|
-
# @param [Integer] pe_id the id of the object
|
53
|
-
#
|
54
|
-
# @return [Nokogiri::XML::Node, REXML::Element] the empty xml
|
55
|
-
def Document.build_xml(pe_id=nil)
|
56
|
-
if pe_id
|
57
|
-
obj_xml = "<DOCUMENT><ID>#{pe_id}</ID></DOCUMENT>"
|
58
|
-
else
|
59
|
-
obj_xml = "<DOCUMENT></DOCUMENT>"
|
60
|
-
end
|
61
|
-
|
62
|
-
XMLElement.build_xml(obj_xml,'DOCUMENT')
|
63
|
-
end
|
64
|
-
|
65
|
-
# Class constructor
|
66
|
-
#
|
67
|
-
# @param [Nokogiri::XML::Node, REXML::Element] xml string
|
68
|
-
# created by the build_xml() method
|
69
|
-
# @param [OpenNebula::Client] client the xml-rpc client
|
70
|
-
#
|
71
|
-
# @return [Document] the new object
|
72
|
-
#
|
73
|
-
# @example
|
74
|
-
# doc = Document.new(Document.build_xml(3),rpc_client)
|
75
|
-
def initialize(xml, client)
|
76
|
-
super(xml,client)
|
77
|
-
end
|
78
|
-
|
79
|
-
#######################################################################
|
80
|
-
# XML-RPC Methods for the Document Object
|
81
|
-
#######################################################################
|
82
|
-
|
83
|
-
# Retrieves the information of the given Document.
|
84
|
-
#
|
85
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
86
|
-
# otherwise
|
87
|
-
def info()
|
88
|
-
rc = super(DOCUMENT_METHODS[:info], 'DOCUMENT')
|
89
|
-
|
90
|
-
if !OpenNebula.is_error?(rc) && self['TYPE'].to_i != document_type
|
91
|
-
return OpenNebula::Error.new("[DocumentInfo] Error getting document [#{@pe_id}].")
|
92
|
-
end
|
93
|
-
|
94
|
-
return rc
|
95
|
-
end
|
96
|
-
|
97
|
-
# Allocates a new Document in OpenNebula
|
98
|
-
#
|
99
|
-
# @param description [String] The contents of the Document.
|
100
|
-
#
|
101
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
102
|
-
# otherwise
|
103
|
-
def allocate(description)
|
104
|
-
super(DOCUMENT_METHODS[:allocate], description, document_type)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Deletes the Document
|
108
|
-
#
|
109
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
110
|
-
# otherwise
|
111
|
-
def delete()
|
112
|
-
rc = check_type()
|
113
|
-
return rc if OpenNebula.is_error?(rc)
|
114
|
-
|
115
|
-
return call(DOCUMENT_METHODS[:delete], @pe_id)
|
116
|
-
end
|
117
|
-
|
118
|
-
# Replaces the template contents
|
119
|
-
#
|
120
|
-
# @param [String] new_template new template contents
|
121
|
-
#
|
122
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
123
|
-
# otherwise
|
124
|
-
def update(new_template)
|
125
|
-
rc = check_type()
|
126
|
-
return rc if OpenNebula.is_error?(rc)
|
127
|
-
|
128
|
-
super(DOCUMENT_METHODS[:update], new_template)
|
129
|
-
end
|
130
|
-
|
131
|
-
# Changes the owner/group
|
132
|
-
#
|
133
|
-
# @param [Integer] uid the new owner id. Set to -1 to leave the current one
|
134
|
-
# @param [Integer] gid the new group id. Set to -1 to leave the current one
|
135
|
-
#
|
136
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
137
|
-
# otherwise
|
138
|
-
def chown(uid, gid)
|
139
|
-
rc = check_type()
|
140
|
-
return rc if OpenNebula.is_error?(rc)
|
141
|
-
|
142
|
-
super(DOCUMENT_METHODS[:chown], uid, gid)
|
143
|
-
end
|
144
|
-
|
145
|
-
# Changes the Document permissions.
|
146
|
-
#
|
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(octet)
|
152
|
-
rc = check_type()
|
153
|
-
return rc if OpenNebula.is_error?(rc)
|
154
|
-
|
155
|
-
super(DOCUMENT_METHODS[:chmod], octet)
|
156
|
-
end
|
157
|
-
|
158
|
-
# Changes the Document permissions.
|
159
|
-
# Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
|
160
|
-
#
|
161
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
162
|
-
# otherwise
|
163
|
-
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
164
|
-
other_m, other_a)
|
165
|
-
rc = check_type()
|
166
|
-
return rc if OpenNebula.is_error?(rc)
|
167
|
-
|
168
|
-
super(DOCUMENT_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
169
|
-
group_m, group_a, other_u, other_m, other_a)
|
170
|
-
end
|
171
|
-
|
172
|
-
# Clones this Document into a new one
|
173
|
-
#
|
174
|
-
# @param name [String] Name for the new Document.
|
175
|
-
#
|
176
|
-
# @return [Integer, OpenNebula::Error] The new Document ID in case
|
177
|
-
# of success, Error otherwise
|
178
|
-
def clone(name)
|
179
|
-
rc = check_type()
|
180
|
-
return rc if OpenNebula.is_error?(rc)
|
181
|
-
|
182
|
-
return Error.new('ID not defined') if !@pe_id
|
183
|
-
|
184
|
-
rc = @client.call(DOCUMENT_METHODS[:clone], @pe_id, name)
|
185
|
-
|
186
|
-
return rc
|
187
|
-
end
|
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
|
-
|
199
|
-
#######################################################################
|
200
|
-
# Helpers to get Document information
|
201
|
-
#######################################################################
|
202
|
-
|
203
|
-
# Returns the group identifier
|
204
|
-
# @return [Integer] the element's group ID
|
205
|
-
def gid
|
206
|
-
self['GID'].to_i
|
207
|
-
end
|
208
|
-
|
209
|
-
# Returns the owner user ID
|
210
|
-
# @return [Integer] the element's owner user ID
|
211
|
-
def owner_id
|
212
|
-
self['UID'].to_i
|
213
|
-
end
|
214
|
-
|
215
|
-
# Returns true if the GROUP_U permission bit is set
|
216
|
-
# @return [true, false] true if the GROUP_U permission bit is set
|
217
|
-
def public?
|
218
|
-
if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
|
219
|
-
true
|
220
|
-
else
|
221
|
-
false
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def document_type
|
226
|
-
self.class::DOCUMENT_TYPE
|
227
|
-
end
|
228
|
-
|
229
|
-
private
|
230
|
-
|
231
|
-
def set_publish(published)
|
232
|
-
group_u = published ? 1 : 0
|
233
|
-
|
234
|
-
chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
|
235
|
-
end
|
236
|
-
|
237
|
-
def check_type()
|
238
|
-
type = self['TYPE']
|
239
|
-
|
240
|
-
if type.nil? && @pe_id
|
241
|
-
rc = @client.call(DOCUMENT_METHODS[:info], @pe_id)
|
242
|
-
|
243
|
-
return rc if OpenNebula.is_error?(rc)
|
244
|
-
|
245
|
-
xmldoc = XMLElement.new
|
246
|
-
xmldoc.initialize_xml(rc, 'DOCUMENT')
|
247
|
-
|
248
|
-
type = xmldoc['TYPE']
|
249
|
-
end
|
250
|
-
|
251
|
-
if !type.nil? && type.to_i != document_type
|
252
|
-
return OpenNebula::Error.new(
|
253
|
-
"[DocumentInfo] Error getting document [#{@pe_id}].")
|
254
|
-
end
|
255
|
-
|
256
|
-
return nil
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
@@ -1,129 +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 'json'
|
18
|
-
|
19
|
-
module OpenNebula
|
20
|
-
class DocumentJSON < Document
|
21
|
-
|
22
|
-
TEMPLATE_TAG = "BODY"
|
23
|
-
|
24
|
-
# Allocate a new Document containing the json inside the TEMPLATE
|
25
|
-
#
|
26
|
-
# @param [String] template_json json to be inserted in the TEMPLATE
|
27
|
-
# of the new resource
|
28
|
-
# @param [String, nil] name name of the object, this value will be
|
29
|
-
# processed by the OpenNebula core
|
30
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
31
|
-
# otherwise
|
32
|
-
#
|
33
|
-
def allocate(template_json, name=nil)
|
34
|
-
text = build_template_xml(template_json, name)
|
35
|
-
|
36
|
-
super(text)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Retrieves the information of the Service and all its Nodes.
|
40
|
-
#
|
41
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
42
|
-
# otherwise
|
43
|
-
#
|
44
|
-
def info
|
45
|
-
rc = super
|
46
|
-
if OpenNebula.is_error?(rc)
|
47
|
-
return rc
|
48
|
-
end
|
49
|
-
|
50
|
-
load_body
|
51
|
-
end
|
52
|
-
|
53
|
-
# Updates the current state of this Service in the OpenNebula DB
|
54
|
-
#
|
55
|
-
# @params [String, nil] template_json string to be inserted in the
|
56
|
-
# template. If nil @body will be used instead
|
57
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
58
|
-
# otherwise
|
59
|
-
#
|
60
|
-
def update(template_json=nil)
|
61
|
-
template_json ||= @body.to_json
|
62
|
-
|
63
|
-
text = build_template_xml(template_json)
|
64
|
-
|
65
|
-
super(text)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Generates a json representing the object
|
69
|
-
#
|
70
|
-
# @param [true, false] pretty_generate
|
71
|
-
# @return [String] json representing the object
|
72
|
-
#
|
73
|
-
def to_json(pretty_generate=true)
|
74
|
-
hash = self.to_hash
|
75
|
-
|
76
|
-
body = hash['DOCUMENT']['TEMPLATE']["#{TEMPLATE_TAG}"]
|
77
|
-
if body
|
78
|
-
body_hash = JSON.parse(body)
|
79
|
-
hash['DOCUMENT']['TEMPLATE']["#{TEMPLATE_TAG}"] = body_hash
|
80
|
-
end
|
81
|
-
|
82
|
-
if pretty_generate
|
83
|
-
JSON.pretty_generate hash
|
84
|
-
else
|
85
|
-
hash.to_json
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
# Fill the @body hash with the values of the template
|
91
|
-
def load_body
|
92
|
-
body_str = self["TEMPLATE/#{TEMPLATE_TAG}"]
|
93
|
-
|
94
|
-
if body_str
|
95
|
-
begin
|
96
|
-
@body = JSON.parse(body_str)
|
97
|
-
rescue JSON::JSONError
|
98
|
-
return OpenNebula::Error.new($!)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
return nil
|
103
|
-
end
|
104
|
-
|
105
|
-
private
|
106
|
-
|
107
|
-
# Build an xml string incluiding the provided json
|
108
|
-
#
|
109
|
-
# @param [String] template_json The template to be inserted
|
110
|
-
# @param [String, nil] name The string to be inserted as name
|
111
|
-
# @return [String] The xml containing the json
|
112
|
-
#
|
113
|
-
def build_template_xml(template_json, name=nil)
|
114
|
-
template_json ||= ""
|
115
|
-
|
116
|
-
text = "<TEMPLATE>"
|
117
|
-
|
118
|
-
text << "<NAME>#{name}</NAME>" if name
|
119
|
-
|
120
|
-
text << "<#{TEMPLATE_TAG}>"
|
121
|
-
text << "<![CDATA[#{template_json}]]>"
|
122
|
-
text << "</#{TEMPLATE_TAG}>"
|
123
|
-
|
124
|
-
text << "</TEMPLATE>"
|
125
|
-
|
126
|
-
text
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,97 +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/pool'
|
18
|
-
|
19
|
-
module OpenNebula
|
20
|
-
|
21
|
-
# All subclasses must define the DOCUMENT_TYPE constant
|
22
|
-
# and the factory method.
|
23
|
-
#
|
24
|
-
# @example
|
25
|
-
# require 'opennebuña/document_pool'
|
26
|
-
#
|
27
|
-
# module OpenNebula
|
28
|
-
# class CustomObjectPool < DocumentPool
|
29
|
-
#
|
30
|
-
# DOCUMENT_TYPE = 400
|
31
|
-
#
|
32
|
-
# def factory(element_xml)
|
33
|
-
# OpenNebula::CustomObject.new(element_xml, @client)
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
class DocumentPool < Pool
|
38
|
-
|
39
|
-
#######################################################################
|
40
|
-
# Constants and Class attribute accessors
|
41
|
-
#######################################################################
|
42
|
-
|
43
|
-
DOCUMENT_POOL_METHODS = {
|
44
|
-
:info => "documentpool.info"
|
45
|
-
}
|
46
|
-
|
47
|
-
#######################################################################
|
48
|
-
# Class constructor & Pool Methods
|
49
|
-
#######################################################################
|
50
|
-
|
51
|
-
# Class constructor
|
52
|
-
#
|
53
|
-
# @param [OpenNebula::Client] client the xml-rpc client
|
54
|
-
# @param [Integer] user_id the filter flag, see
|
55
|
-
# http://opennebula.org/documentation:rel3.6:api
|
56
|
-
#
|
57
|
-
# @return [DocumentPool] the new object
|
58
|
-
def initialize(client, user_id=-1)
|
59
|
-
super('DOCUMENT_POOL','DOCUMENT',client)
|
60
|
-
|
61
|
-
@user_id = user_id
|
62
|
-
end
|
63
|
-
|
64
|
-
#######################################################################
|
65
|
-
# XML-RPC Methods for the Document Object
|
66
|
-
#######################################################################
|
67
|
-
|
68
|
-
# Retrieves all or part of the Documents in the pool.
|
69
|
-
#
|
70
|
-
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
71
|
-
# otherwise
|
72
|
-
def info(*args)
|
73
|
-
case args.size
|
74
|
-
when 0
|
75
|
-
info_filter(DOCUMENT_POOL_METHODS[:info],@user_id,-1,-1, document_type)
|
76
|
-
when 3
|
77
|
-
info_filter(DOCUMENT_POOL_METHODS[:info],args[0],args[1],args[2], document_type)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def info_all()
|
82
|
-
return super(DOCUMENT_POOL_METHODS[:info], document_type)
|
83
|
-
end
|
84
|
-
|
85
|
-
def info_mine()
|
86
|
-
return super(DOCUMENT_POOL_METHODS[:info], document_type)
|
87
|
-
end
|
88
|
-
|
89
|
-
def info_group()
|
90
|
-
return super(DOCUMENT_POOL_METHODS[:info], document_type)
|
91
|
-
end
|
92
|
-
|
93
|
-
def document_type
|
94
|
-
self.class::DOCUMENT_TYPE
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,58 +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
|
-
module OpenNebula
|
18
|
-
class DocumentPoolJSON < DocumentPool
|
19
|
-
|
20
|
-
TEMPLATE_TAG = "BODY"
|
21
|
-
|
22
|
-
def factory(element_xml)
|
23
|
-
doc = OpenNebula::DocumentJSON.new(element_xml, @client)
|
24
|
-
doc.load_body
|
25
|
-
doc
|
26
|
-
end
|
27
|
-
|
28
|
-
# Generates a json representing the object
|
29
|
-
#
|
30
|
-
# @param [true, false] pretty_generate
|
31
|
-
# @return [String] json representing the object
|
32
|
-
#
|
33
|
-
def to_json(pretty_generate=true)
|
34
|
-
hash = self.to_hash
|
35
|
-
|
36
|
-
if hash['DOCUMENT_POOL'] && hash['DOCUMENT_POOL']['DOCUMENT']
|
37
|
-
if !hash['DOCUMENT_POOL']['DOCUMENT'].instance_of?(Array)
|
38
|
-
array = [hash['DOCUMENT_POOL']['DOCUMENT']]
|
39
|
-
hash['DOCUMENT_POOL']['DOCUMENT'] = array.compact
|
40
|
-
end
|
41
|
-
|
42
|
-
hash['DOCUMENT_POOL']['DOCUMENT'].each { |doc|
|
43
|
-
body = doc['TEMPLATE']["#{TEMPLATE_TAG}"]
|
44
|
-
if body
|
45
|
-
b_hash = JSON.parse(body)
|
46
|
-
doc['TEMPLATE']["#{TEMPLATE_TAG}"] = b_hash
|
47
|
-
end
|
48
|
-
}
|
49
|
-
end
|
50
|
-
|
51
|
-
if pretty_generate
|
52
|
-
JSON.pretty_generate hash
|
53
|
-
else
|
54
|
-
hash.to_json
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/lib/opennebula/error.rb
DELETED
@@ -1,52 +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
|
-
# 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
|