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.
- data/.travis.yml +1 -0
- data/README.md +3 -37
- data/lib/occi/version.rb +1 -1
- metadata +1 -22
- data/lib/OpenNebula/Acl.rb +0 -256
- data/lib/OpenNebula/AclPool.rb +0 -53
- data/lib/OpenNebula/Group.rb +0 -147
- data/lib/OpenNebula/GroupPool.rb +0 -54
- data/lib/OpenNebula/Host.rb +0 -143
- data/lib/OpenNebula/HostPool.rb +0 -55
- data/lib/OpenNebula/Image.rb +0 -256
- data/lib/OpenNebula/ImagePool.rb +0 -74
- data/lib/OpenNebula/OpenNebula.rb +0 -137
- data/lib/OpenNebula/Pool.rb +0 -285
- data/lib/OpenNebula/Template.rb +0 -173
- data/lib/OpenNebula/TemplatePool.rb +0 -74
- data/lib/OpenNebula/User.rb +0 -157
- data/lib/OpenNebula/UserPool.rb +0 -53
- data/lib/OpenNebula/VirtualMachine.rb +0 -319
- data/lib/OpenNebula/VirtualMachinePool.rb +0 -120
- data/lib/OpenNebula/VirtualNetwork.rb +0 -229
- data/lib/OpenNebula/VirtualNetworkPool.rb +0 -74
- data/lib/OpenNebula/XMLUtils.rb +0 -337
- data/lib/occi/configuration.rb +0 -118
- data/lib/occi/server.rb +0 -594
@@ -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 VirtualNetworkPool < Pool
|
22
|
-
#######################################################################
|
23
|
-
# Constants and Class attribute accessors
|
24
|
-
#######################################################################
|
25
|
-
|
26
|
-
|
27
|
-
VN_POOL_METHODS = {
|
28
|
-
:info => "vnpool.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 VirtualNetworks from that user
|
37
|
-
def initialize(client, user_id=0)
|
38
|
-
super('VNET_POOL','VNET',client)
|
39
|
-
|
40
|
-
@user_id = user_id
|
41
|
-
end
|
42
|
-
|
43
|
-
# Default Factory Method for the Pools
|
44
|
-
def factory(element_xml)
|
45
|
-
OpenNebula::VirtualNetwork.new(element_xml,@client)
|
46
|
-
end
|
47
|
-
|
48
|
-
#######################################################################
|
49
|
-
# XML-RPC Methods for the Virtual Network 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(VN_POOL_METHODS[:info],@user_id,-1,-1)
|
57
|
-
when 3
|
58
|
-
info_filter(VN_POOL_METHODS[:info],args[0],args[1],args[2])
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def info_all()
|
63
|
-
return super(VN_POOL_METHODS[:info])
|
64
|
-
end
|
65
|
-
|
66
|
-
def info_mine()
|
67
|
-
return super(VN_POOL_METHODS[:info])
|
68
|
-
end
|
69
|
-
|
70
|
-
def info_group()
|
71
|
-
return super(VN_POOL_METHODS[:info])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/lib/OpenNebula/XMLUtils.rb
DELETED
@@ -1,337 +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
|
-
begin
|
21
|
-
require 'nokogiri'
|
22
|
-
NOKOGIRI=true
|
23
|
-
rescue LoadError
|
24
|
-
NOKOGIRI=false
|
25
|
-
end
|
26
|
-
|
27
|
-
begin
|
28
|
-
require 'rexml/formatters/pretty'
|
29
|
-
REXML_FORMATTERS=true
|
30
|
-
rescue LoadError
|
31
|
-
REXML_FORMATTERS=false
|
32
|
-
end
|
33
|
-
|
34
|
-
# The XMLElement class provides an abstraction of the underlying
|
35
|
-
# XML parser engine. It provides XML-related methods for the Pool and
|
36
|
-
# PoolElement classes
|
37
|
-
class XMLElement
|
38
|
-
|
39
|
-
# xml:: _opaque xml object_ an xml object as returned by build_xml
|
40
|
-
def initialize(xml=nil)
|
41
|
-
@xml = xml
|
42
|
-
end
|
43
|
-
|
44
|
-
# Initialize a XML document for the element
|
45
|
-
# xml:: _String_ the XML document of the object
|
46
|
-
# root_element:: _String_ Base xml element
|
47
|
-
def initialize_xml(xml, root_element)
|
48
|
-
@xml = XMLElement.build_xml(xml, root_element)
|
49
|
-
|
50
|
-
if OpenNebula.is_error?(@xml)
|
51
|
-
@xml = nil
|
52
|
-
else
|
53
|
-
if NOKOGIRI
|
54
|
-
if @xml.size == 0
|
55
|
-
@xml = nil
|
56
|
-
end
|
57
|
-
else
|
58
|
-
if @xml.name != root_element
|
59
|
-
@xml = nil
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Builds a XML document
|
66
|
-
# xml:: _String_ the XML document of the object
|
67
|
-
# root_element:: _String_ Base xml element
|
68
|
-
# [return] _XML_ object for the underlying XML engine
|
69
|
-
def self.build_xml(xml, root_element)
|
70
|
-
begin
|
71
|
-
if NOKOGIRI
|
72
|
-
doc = Nokogiri::XML(xml).xpath("/#{root_element}")
|
73
|
-
else
|
74
|
-
doc = REXML::Document.new(xml).root
|
75
|
-
end
|
76
|
-
rescue Exception => e
|
77
|
-
return OpenNebula::Error.new(e.message)
|
78
|
-
end
|
79
|
-
|
80
|
-
return doc
|
81
|
-
end
|
82
|
-
# Extract an element from the XML description of the PoolElement.
|
83
|
-
# key::_String_ The name of the element
|
84
|
-
# [return] _String_ the value of the element
|
85
|
-
# Examples:
|
86
|
-
# ['VID'] # gets VM id
|
87
|
-
# ['HISTORY/HOSTNAME'] # get the hostname from the history
|
88
|
-
def [](key)
|
89
|
-
if NOKOGIRI
|
90
|
-
element=@xml.xpath(key.to_s)
|
91
|
-
|
92
|
-
if element.size == 0
|
93
|
-
return nil
|
94
|
-
end
|
95
|
-
else
|
96
|
-
element=@xml.elements[key.to_s]
|
97
|
-
end
|
98
|
-
|
99
|
-
if element
|
100
|
-
element.text
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# Gets an array of text from elemenets extracted
|
105
|
-
# using the XPATH expression passed as filter
|
106
|
-
def retrieve_elements(filter)
|
107
|
-
elements_array = Array.new
|
108
|
-
|
109
|
-
if NOKOGIRI
|
110
|
-
@xml.xpath(filter.to_s).each { |pelem|
|
111
|
-
elements_array << pelem.text if pelem.text
|
112
|
-
}
|
113
|
-
else
|
114
|
-
@xml.elements.each(filter.to_s) { |pelem|
|
115
|
-
elements_array << pelem.text if pelem.text
|
116
|
-
}
|
117
|
-
end
|
118
|
-
|
119
|
-
if elements_array.size == 0
|
120
|
-
return nil
|
121
|
-
else
|
122
|
-
return elements_array
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
# Gets an attribute from an elemenT
|
128
|
-
# key:: _String_ xpath for the element
|
129
|
-
# name:: _String_ name of the attribute
|
130
|
-
def attr(key,name)
|
131
|
-
value = nil
|
132
|
-
|
133
|
-
if NOKOGIRI
|
134
|
-
element=@xml.xpath(key.to_s.upcase)
|
135
|
-
if element.size == 0
|
136
|
-
return nil
|
137
|
-
end
|
138
|
-
|
139
|
-
attribute = element.attr(name)
|
140
|
-
|
141
|
-
value = attribute.text if attribute != nil
|
142
|
-
else
|
143
|
-
element=@xml.elements[key.to_s.upcase]
|
144
|
-
|
145
|
-
value = element.attributes[name] if element != nil
|
146
|
-
end
|
147
|
-
|
148
|
-
return value
|
149
|
-
end
|
150
|
-
|
151
|
-
# Iterates over every Element in the XPath and calls the block with a
|
152
|
-
# a XMLElement
|
153
|
-
# block:: _Block_
|
154
|
-
def each(xpath_str,&block)
|
155
|
-
if NOKOGIRI
|
156
|
-
@xml.xpath(xpath_str).each { |pelem|
|
157
|
-
block.call XMLElement.new(pelem)
|
158
|
-
}
|
159
|
-
else
|
160
|
-
@xml.elements.each(xpath_str) { |pelem|
|
161
|
-
block.call XMLElement.new(pelem)
|
162
|
-
}
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def each_xpath(xpath_str,&block)
|
167
|
-
if NOKOGIRI
|
168
|
-
@xml.xpath(xpath_str).each { |pelem|
|
169
|
-
block.call pelem.text
|
170
|
-
}
|
171
|
-
else
|
172
|
-
@xml.elements.each(xpath_str) { |pelem|
|
173
|
-
block.call pelem.text
|
174
|
-
}
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def name
|
179
|
-
@xml.name
|
180
|
-
end
|
181
|
-
|
182
|
-
def text
|
183
|
-
if NOKOGIRI
|
184
|
-
@xml.content
|
185
|
-
else
|
186
|
-
@xml.text
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
def has_elements?(xpath_str)
|
191
|
-
if NOKOGIRI
|
192
|
-
element = @xml.xpath(xpath_str.to_s.upcase)
|
193
|
-
return element != nil && element.children.size > 0
|
194
|
-
else
|
195
|
-
element = @xml.elements[xpath_str.to_s]
|
196
|
-
return element != nil && element.has_elements?
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
def template_str(indent=true)
|
201
|
-
template_like_str('TEMPLATE', indent)
|
202
|
-
end
|
203
|
-
|
204
|
-
def template_like_str(root_element, indent=true, xpath_exp=nil)
|
205
|
-
if NOKOGIRI
|
206
|
-
xml_template=@xml.xpath(root_element).to_s
|
207
|
-
rexml=REXML::Document.new(xml_template).root
|
208
|
-
else
|
209
|
-
rexml=@xml.elements[root_element]
|
210
|
-
end
|
211
|
-
|
212
|
-
if indent
|
213
|
-
ind_enter="\n"
|
214
|
-
ind_tab=' '
|
215
|
-
else
|
216
|
-
ind_enter=''
|
217
|
-
ind_tab=' '
|
218
|
-
end
|
219
|
-
|
220
|
-
str=rexml.elements.collect(xpath_exp) {|n|
|
221
|
-
if n.class==REXML::Element
|
222
|
-
str_line=""
|
223
|
-
if n.has_elements?
|
224
|
-
str_line << n.name << "=[" << ind_enter
|
225
|
-
|
226
|
-
str_line << n.collect {|n2|
|
227
|
-
if n2 && n2.class==REXML::Element
|
228
|
-
str = ""
|
229
|
-
str << ind_tab << n2.name << '='
|
230
|
-
str << attr_to_str(n2.text) if n2.text
|
231
|
-
str
|
232
|
-
end
|
233
|
-
}.compact.join(','+ind_enter)
|
234
|
-
str_line<<" ]"
|
235
|
-
else
|
236
|
-
str_line << n.name << '=' << attr_to_str(n.text.to_s)
|
237
|
-
end
|
238
|
-
str_line
|
239
|
-
end
|
240
|
-
}.compact.join("\n")
|
241
|
-
|
242
|
-
str
|
243
|
-
end
|
244
|
-
|
245
|
-
def to_xml(pretty=false)
|
246
|
-
if NOKOGIRI && pretty
|
247
|
-
str = @xml.to_xml
|
248
|
-
elsif REXML_FORMATTERS && pretty
|
249
|
-
str = String.new
|
250
|
-
|
251
|
-
formatter = REXML::Formatters::Pretty.new
|
252
|
-
formatter.compact = true
|
253
|
-
|
254
|
-
formatter.write(@xml,str)
|
255
|
-
else
|
256
|
-
str = @xml.to_s
|
257
|
-
end
|
258
|
-
|
259
|
-
return str
|
260
|
-
end
|
261
|
-
|
262
|
-
def to_hash(hash={}, element=nil)
|
263
|
-
element ||= @xml.document.root
|
264
|
-
|
265
|
-
if NOKOGIRI
|
266
|
-
array = element.children
|
267
|
-
if array.length==1 and (array.first.text? or array.first.cdata?)
|
268
|
-
r = array.first.text
|
269
|
-
else
|
270
|
-
r = {}
|
271
|
-
array.each { |c|
|
272
|
-
if c.element?
|
273
|
-
to_hash(r, c)
|
274
|
-
end
|
275
|
-
}
|
276
|
-
end
|
277
|
-
else
|
278
|
-
r = {}
|
279
|
-
if element.has_elements?
|
280
|
-
element.each_element { |c| to_hash(r, c) }
|
281
|
-
elsif element.has_text?
|
282
|
-
r = element.text
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
key = element.name
|
287
|
-
if hash.has_key?(key)
|
288
|
-
if hash[key].instance_of?(Array)
|
289
|
-
hash[key] << r
|
290
|
-
else
|
291
|
-
hash[key] = [hash[key], r]
|
292
|
-
end
|
293
|
-
else
|
294
|
-
hash[key] = r
|
295
|
-
end
|
296
|
-
|
297
|
-
hash
|
298
|
-
end
|
299
|
-
|
300
|
-
private
|
301
|
-
def attr_to_str(attr)
|
302
|
-
attr.gsub!('"',"\\\"")
|
303
|
-
|
304
|
-
if attr.match(/[=,' ']/)
|
305
|
-
return '"' + attr + '"'
|
306
|
-
end
|
307
|
-
|
308
|
-
return attr
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
# The XMLUtilsPool module provides an abstraction of the underlying
|
313
|
-
# XML parser engine. It provides XML-related methods for the Pools
|
314
|
-
class XMLPool < XMLElement
|
315
|
-
|
316
|
-
def initialize(xml=nil)
|
317
|
-
super(xml)
|
318
|
-
end
|
319
|
-
|
320
|
-
#Executes the given block for each element of the Pool
|
321
|
-
#block:: _Block_
|
322
|
-
def each_element(block)
|
323
|
-
if NOKOGIRI
|
324
|
-
@xml.xpath(
|
325
|
-
"#{@element_name}").each {|pelem|
|
326
|
-
block.call self.factory(pelem)
|
327
|
-
}
|
328
|
-
else
|
329
|
-
@xml.elements.each(
|
330
|
-
"#{@element_name}") {|pelem|
|
331
|
-
block.call self.factory(pelem)
|
332
|
-
}
|
333
|
-
end
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
end
|
data/lib/occi/configuration.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
##############################################################################
|
2
|
-
# Copyright 2011 Service Computing group, TU Dortmund
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain 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
|
-
# Description: Configuration of OCCI Webservice
|
19
|
-
# Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
|
20
|
-
##############################################################################
|
21
|
-
|
22
|
-
require 'occi/log'
|
23
|
-
|
24
|
-
module OCCI
|
25
|
-
class Configuration
|
26
|
-
|
27
|
-
###########################################################################
|
28
|
-
# Mandatory config parameters
|
29
|
-
|
30
|
-
@@mandatory_params = []
|
31
|
-
# the backend needs to be specified, currently supported: dummy and opennebula
|
32
|
-
@@mandatory_params << "backend"
|
33
|
-
# the url of the server needs to be specified
|
34
|
-
@@mandatory_params << "server"
|
35
|
-
# the port of the server needs to be specified
|
36
|
-
@@mandatory_params << "port"
|
37
|
-
|
38
|
-
###########################################################################
|
39
|
-
# Patterns to parse the Configuration File
|
40
|
-
|
41
|
-
NAME_REG =/[\w\d_-]+/
|
42
|
-
VARIABLE_REG =/\s*(#{NAME_REG})\s*=\s*/
|
43
|
-
|
44
|
-
SIMPLE_VARIABLE_REG =/#{VARIABLE_REG}([^\[]+?)(#.*)?/
|
45
|
-
SINGLE_VARIABLE_REG =/^#{SIMPLE_VARIABLE_REG}$/
|
46
|
-
ARRAY_VARIABLE_REG =/^#{VARIABLE_REG}\[(.*?)\]/m
|
47
|
-
|
48
|
-
###########################################################################
|
49
|
-
def initialize(file)
|
50
|
-
@conf=parse_conf(file)
|
51
|
-
end
|
52
|
-
|
53
|
-
def add_configuration_value(key,value)
|
54
|
-
add_value(@conf,key,value)
|
55
|
-
end
|
56
|
-
|
57
|
-
def [](key)
|
58
|
-
@conf[key.to_s.upcase]
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
def add_value(conf, key, value)
|
67
|
-
if conf[key]
|
68
|
-
if !conf[key].kind_of?(Array)
|
69
|
-
conf[key]=[conf[key]]
|
70
|
-
end
|
71
|
-
conf[key]<<value
|
72
|
-
else
|
73
|
-
conf[key]=value
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def check_params(conf)
|
78
|
-
@@mandatory_params.each do
|
79
|
-
|param|
|
80
|
-
if conf[param.upcase] == nil
|
81
|
-
raise "Mandatory parameter " + param + " not provided in config file. exiting"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def parse_conf(file)
|
87
|
-
conf_file=File.read(file)
|
88
|
-
|
89
|
-
conf=Hash.new
|
90
|
-
|
91
|
-
conf_file.scan(SINGLE_VARIABLE_REG) {|m|
|
92
|
-
key=m[0].strip.upcase
|
93
|
-
value=m[1].strip
|
94
|
-
|
95
|
-
# hack to skip multiline VM_TYPE values
|
96
|
-
next if %w{NAME TEMPLATE}.include? key.upcase
|
97
|
-
|
98
|
-
add_value(conf, key, value)
|
99
|
-
}
|
100
|
-
|
101
|
-
conf_file.scan(ARRAY_VARIABLE_REG) {|m|
|
102
|
-
master_key=m[0].strip.upcase
|
103
|
-
|
104
|
-
pieces=m[1].split(',')
|
105
|
-
|
106
|
-
vars=Hash.new
|
107
|
-
pieces.each {|p|
|
108
|
-
key, value=p.split('=')
|
109
|
-
vars[key.strip.upcase]=value.strip
|
110
|
-
}
|
111
|
-
|
112
|
-
add_value(conf, master_key, vars)
|
113
|
-
}
|
114
|
-
|
115
|
-
conf
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|