opennebula 4.4.0 → 4.5.80.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NOTICE +1 -1
- data/lib/opennebula.rb +4 -2
- data/lib/opennebula/acl.rb +36 -8
- data/lib/opennebula/acl_pool.rb +1 -1
- data/lib/opennebula/client.rb +52 -4
- data/lib/opennebula/cluster.rb +1 -1
- data/lib/opennebula/cluster_pool.rb +1 -1
- data/lib/opennebula/datastore.rb +1 -1
- data/lib/opennebula/datastore_pool.rb +1 -1
- data/lib/opennebula/document.rb +1 -1
- data/lib/opennebula/document_json.rb +1 -1
- data/lib/opennebula/document_pool.rb +1 -1
- data/lib/opennebula/document_pool_json.rb +1 -1
- data/lib/opennebula/error.rb +1 -1
- data/lib/opennebula/group.rb +227 -43
- data/lib/opennebula/group_pool.rb +1 -1
- data/lib/opennebula/host.rb +1 -1
- data/lib/opennebula/host_pool.rb +1 -1
- data/lib/opennebula/image.rb +1 -1
- data/lib/opennebula/image_pool.rb +1 -1
- data/lib/opennebula/ldap_auth.rb +1 -1
- data/lib/opennebula/ldap_auth_spec.rb +1 -1
- data/lib/opennebula/oneflow_client.rb +1 -1
- data/lib/opennebula/pool.rb +57 -1
- data/lib/opennebula/pool_element.rb +1 -1
- data/lib/opennebula/server_cipher_auth.rb +1 -1
- data/lib/opennebula/server_x509_auth.rb +1 -1
- data/lib/opennebula/ssh_auth.rb +1 -1
- data/lib/opennebula/system.rb +1 -1
- data/lib/opennebula/template.rb +1 -1
- data/lib/opennebula/template_pool.rb +1 -1
- data/lib/opennebula/user.rb +10 -3
- data/lib/opennebula/user_pool.rb +1 -1
- data/lib/opennebula/virtual_machine.rb +1 -1
- data/lib/opennebula/virtual_machine_pool.rb +1 -1
- data/lib/opennebula/virtual_network.rb +1 -1
- data/lib/opennebula/virtual_network_pool.rb +1 -1
- data/lib/opennebula/x509_auth.rb +1 -1
- data/lib/opennebula/xml_element.rb +1 -1
- data/lib/opennebula/xml_pool.rb +2 -1
- data/lib/opennebula/xml_utils.rb +104 -1
- data/lib/opennebula/zone.rb +107 -0
- data/lib/opennebula/zone_pool.rb +58 -0
- metadata +21 -18
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/host.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/host_pool.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/image.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/ldap_auth.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# ---------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2010-
|
2
|
+
# Copyright 2010-2014, C12G Labs S.L #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# ---------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2010-
|
2
|
+
# Copyright 2010-2014, C12G Labs S.L #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2010-
|
2
|
+
# Copyright 2010-2014, C12G Labs S.L. #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/pool.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -24,6 +24,9 @@ module OpenNebula
|
|
24
24
|
include Enumerable
|
25
25
|
alias_method :each_with_xpath, :each
|
26
26
|
|
27
|
+
PAGINATED_POOLS=%w{VM_POOL IMAGE_POOL TEMPLATE_POOL VN_POOL
|
28
|
+
DOCUMENT_POOL}
|
29
|
+
|
27
30
|
protected
|
28
31
|
#pool:: _String_ XML name of the root element
|
29
32
|
#element:: _String_ XML name of the Pool elements
|
@@ -156,5 +159,58 @@ module OpenNebula
|
|
156
159
|
|
157
160
|
return str
|
158
161
|
end
|
162
|
+
|
163
|
+
# Gets a hash from a pool
|
164
|
+
#
|
165
|
+
# size:: nil => default page size
|
166
|
+
# < 2 => not paginated
|
167
|
+
# >=2 => page size
|
168
|
+
#
|
169
|
+
# The default page size can be changed with the environment variable
|
170
|
+
# ONE_POOL_PAGE_SIZE. Any value > 2 will set a page size, a non
|
171
|
+
# numeric value disables pagination.
|
172
|
+
def get_hash(size=nil)
|
173
|
+
allow_paginated = PAGINATED_POOLS.include?(@pool_name)
|
174
|
+
|
175
|
+
if OpenNebula.pool_page_size && allow_paginated &&
|
176
|
+
( ( size && size >= 2 ) || !size )
|
177
|
+
size = OpenNebula.pool_page_size if !size
|
178
|
+
hash=info_paginated(size)
|
179
|
+
|
180
|
+
return hash if OpenNebula.is_error?(hash)
|
181
|
+
{ @pool_name => { @element_name => hash } }
|
182
|
+
else
|
183
|
+
rc=info
|
184
|
+
return rc if OpenNebula.is_error?(rc)
|
185
|
+
to_hash
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
# Gets a pool in hash form using pagination
|
190
|
+
#
|
191
|
+
# size:: _Integer_ size of each page
|
192
|
+
def info_paginated(size)
|
193
|
+
array=Array.new
|
194
|
+
current=0
|
195
|
+
|
196
|
+
parser=ParsePoolSax.new(@pool_name, @element_name)
|
197
|
+
|
198
|
+
while true
|
199
|
+
a=@client.call("#{@pool_name.delete('_').downcase}.info",
|
200
|
+
-2, current, -size, -1)
|
201
|
+
return a if OpenNebula.is_error?(a)
|
202
|
+
|
203
|
+
a_array=parser.parse(a)
|
204
|
+
|
205
|
+
array += a_array
|
206
|
+
current += size
|
207
|
+
break if !a || a_array.length<size
|
208
|
+
end
|
209
|
+
|
210
|
+
array.compact!
|
211
|
+
array=nil if array.length == 0
|
212
|
+
|
213
|
+
array
|
214
|
+
end
|
159
215
|
end
|
160
216
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/ssh_auth.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/system.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/template.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/user.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -172,8 +172,8 @@ module OpenNebula
|
|
172
172
|
end
|
173
173
|
|
174
174
|
# Sets the user quota limits
|
175
|
-
# @param quota [String] a template (XML or txt) with the new quota limits
|
176
|
-
#
|
175
|
+
# @param quota [String] a template (XML or txt) with the new quota limits
|
176
|
+
#
|
177
177
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
178
178
|
# otherwise
|
179
179
|
def set_quota(quota)
|
@@ -194,5 +194,12 @@ module OpenNebula
|
|
194
194
|
def gid
|
195
195
|
self['GID'].to_i
|
196
196
|
end
|
197
|
+
|
198
|
+
# Returns a list with all the group IDs for the user including primary
|
199
|
+
# [return] _Array_ with the group ID's (as integers)
|
200
|
+
def groups
|
201
|
+
all_groups = self.retrieve_elements("GROUPS/ID")
|
202
|
+
all_groups.collect! {|x| x.to_i}
|
203
|
+
end
|
197
204
|
end
|
198
205
|
end
|
data/lib/opennebula/user_pool.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/x509_auth.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
data/lib/opennebula/xml_pool.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -17,6 +17,7 @@
|
|
17
17
|
require 'opennebula/xml_element'
|
18
18
|
|
19
19
|
module OpenNebula
|
20
|
+
|
20
21
|
# The XMLUtilsPool module provides an abstraction of the underlying
|
21
22
|
# XML parser engine. It provides XML-related methods for the Pools
|
22
23
|
class XMLPool < XMLElement
|
data/lib/opennebula/xml_utils.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-
|
2
|
+
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
|
3
3
|
# #
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
@@ -25,10 +25,113 @@ module OpenNebula
|
|
25
25
|
NOKOGIRI=false
|
26
26
|
end
|
27
27
|
|
28
|
+
begin
|
29
|
+
require 'ox'
|
30
|
+
OX=true
|
31
|
+
rescue LoadError
|
32
|
+
OX=false
|
33
|
+
end
|
34
|
+
|
28
35
|
begin
|
29
36
|
require 'rexml/formatters/pretty'
|
30
37
|
REXML_FORMATTERS=true
|
31
38
|
rescue LoadError
|
32
39
|
REXML_FORMATTERS=false
|
33
40
|
end
|
41
|
+
|
42
|
+
# Utilities to parse pools with sax (Nokogiri and Ox)
|
43
|
+
|
44
|
+
# vmpool, imagepool, templatepool, vnpool, documentpool
|
45
|
+
|
46
|
+
module ParsePoolBase
|
47
|
+
attr_accessor :pool
|
48
|
+
|
49
|
+
def initialize (pool_name, elem_name)
|
50
|
+
@current = 0
|
51
|
+
@levels = [{}]
|
52
|
+
@pool = Array.new
|
53
|
+
|
54
|
+
@pool_name = pool_name
|
55
|
+
@elem_name = elem_name
|
56
|
+
end
|
57
|
+
|
58
|
+
def start_element(name, attrs = [])
|
59
|
+
return if name == @pool_name
|
60
|
+
@value = nil
|
61
|
+
|
62
|
+
@current = @current + 1
|
63
|
+
|
64
|
+
@levels[@current] = Hash.new if @levels[@current].nil?
|
65
|
+
end
|
66
|
+
|
67
|
+
def characters(s)
|
68
|
+
@value = s
|
69
|
+
end
|
70
|
+
|
71
|
+
def end_element(name)
|
72
|
+
if @levels[@current].empty?
|
73
|
+
@levels[@current-1][name] = @value || {}
|
74
|
+
else
|
75
|
+
@levels[@current-1][name] = @levels[@current]
|
76
|
+
@levels[@current] = Hash.new
|
77
|
+
end
|
78
|
+
|
79
|
+
if name == @elem_name
|
80
|
+
@pool << @levels[0][@elem_name]
|
81
|
+
|
82
|
+
@current = 0
|
83
|
+
@levels[0] = Hash.new
|
84
|
+
else
|
85
|
+
@current = @current -1
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class ParsePoolSaxBase
|
91
|
+
def initialize(pool_name, elem_name)
|
92
|
+
@pool_sax=ParsePoolSax::PoolSax.new(pool_name, elem_name)
|
93
|
+
end
|
94
|
+
|
95
|
+
def parse(str)
|
96
|
+
@pool_sax.pool.clear
|
97
|
+
sax_parse(str)
|
98
|
+
@pool_sax.pool
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
if OX
|
103
|
+
class ParsePoolSax < ParsePoolSaxBase
|
104
|
+
def sax_parse(str)
|
105
|
+
Ox.sax_parse(@pool_sax, StringIO.new(str),
|
106
|
+
:symbolize => false,
|
107
|
+
:convert_special => true)
|
108
|
+
end
|
109
|
+
|
110
|
+
class PoolSax < Ox::Sax
|
111
|
+
include ParsePoolBase
|
112
|
+
|
113
|
+
alias :text :characters
|
114
|
+
alias :cdata :characters
|
115
|
+
end
|
116
|
+
end
|
117
|
+
elsif NOKOGIRI
|
118
|
+
class ParsePoolSax < ParsePoolSaxBase
|
119
|
+
def initialize(pool_name, elem_name)
|
120
|
+
super(pool_name, elem_name)
|
121
|
+
@parser = Nokogiri::XML::SAX::Parser.new(@pool_sax)
|
122
|
+
end
|
123
|
+
|
124
|
+
def sax_parse(str)
|
125
|
+
@parser.parse(str)
|
126
|
+
end
|
127
|
+
|
128
|
+
class PoolSax < Nokogiri::XML::SAX::Document
|
129
|
+
include ParsePoolBase
|
130
|
+
|
131
|
+
alias :cdata_block :characters
|
132
|
+
end
|
133
|
+
end
|
134
|
+
else
|
135
|
+
raise "nokogiri gem not installed."
|
136
|
+
end
|
34
137
|
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# -------------------------------------------------------------------------- #
|
2
|
+
# Copyright 2002-2014, 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 Zone < PoolElement
|
22
|
+
#######################################################################
|
23
|
+
# Constants and Class Methods
|
24
|
+
#######################################################################
|
25
|
+
|
26
|
+
ZONE_METHODS = {
|
27
|
+
:info => "zone.info",
|
28
|
+
:allocate => "zone.allocate",
|
29
|
+
:update => "zone.update",
|
30
|
+
:rename => "zone.rename",
|
31
|
+
:delete => "zone.delete"
|
32
|
+
}
|
33
|
+
|
34
|
+
# Creates a Zone description with just its identifier
|
35
|
+
# this method should be used to create plain Zone objects.
|
36
|
+
# @param id [Integer] the id of the Zone
|
37
|
+
#
|
38
|
+
# Example:
|
39
|
+
# zone = Zone.new(Zone.build_xml(3),rpc_client)
|
40
|
+
#
|
41
|
+
def Zone.build_xml(pe_id=nil)
|
42
|
+
if pe_id
|
43
|
+
zone_xml = "<ZONE><ID>#{pe_id}</ID></ZONE>"
|
44
|
+
else
|
45
|
+
zone_xml = "<ZONE></ZONE>"
|
46
|
+
end
|
47
|
+
|
48
|
+
XMLElement.build_xml(zone_xml,'ZONE')
|
49
|
+
end
|
50
|
+
|
51
|
+
# Class constructor
|
52
|
+
def initialize(xml, client)
|
53
|
+
super(xml,client)
|
54
|
+
end
|
55
|
+
|
56
|
+
#######################################################################
|
57
|
+
# XML-RPC Methods for the Zone Object
|
58
|
+
#######################################################################
|
59
|
+
|
60
|
+
# Retrieves the information of the given Zone.
|
61
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
62
|
+
# otherwise
|
63
|
+
def info()
|
64
|
+
super(ZONE_METHODS[:info], 'ZONE')
|
65
|
+
end
|
66
|
+
|
67
|
+
alias_method :info!, :info
|
68
|
+
|
69
|
+
# Allocates a new Zone in OpenNebula
|
70
|
+
#
|
71
|
+
# @param description [String] The template of the Zone.
|
72
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
73
|
+
# otherwise
|
74
|
+
def allocate(description)
|
75
|
+
super(ZONE_METHODS[:allocate], description)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Replaces the template contents
|
79
|
+
#
|
80
|
+
# @param new_template [String] New template contents
|
81
|
+
# @param append [true, false] True to append new attributes instead of
|
82
|
+
# replace the whole template
|
83
|
+
#
|
84
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
85
|
+
# otherwise
|
86
|
+
def update(new_template=nil, append=false)
|
87
|
+
super(ZONE_METHODS[:update], new_template, append ? 1 : 0)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Deletes the Zone
|
91
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
92
|
+
# otherwise
|
93
|
+
def delete()
|
94
|
+
super(ZONE_METHODS[:delete])
|
95
|
+
end
|
96
|
+
|
97
|
+
# Renames this Zone
|
98
|
+
#
|
99
|
+
# @param name [String] New name for the Zone.
|
100
|
+
#
|
101
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
102
|
+
# otherwise
|
103
|
+
def rename(name)
|
104
|
+
return call(ZONE_METHODS[:rename], @pe_id, name)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|