opennebula 4.10.2 → 4.11.80.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1405cdbd2929cbba2006e8fc8b3f5babf8063d17
4
- data.tar.gz: 5fd0a3980a8c556b5f2b436a444432d20ac9cad2
3
+ metadata.gz: b55fbcd210776bb0c2c343d9d42f1debef46541f
4
+ data.tar.gz: 09fbe6a0dd0e784de398efef0a00ac42294d1283
5
5
  SHA512:
6
- metadata.gz: b3ab73f9baba7c9359297e6093f8b7e30ca5b8e1943a139c20cd3e0e6cdfa28d0077dd1d7486de4afceccb37ea1759bc72dbb91a479b64583b36aae10b71ea0f
7
- data.tar.gz: cb437ef6456d5426c2d84fa2852516bd8213fde9e7f5f049e531955cd793a141393a1883e3d44ddf8e8c8a54fd0e9172651f4a5ece65e4816e859ecb1c1799e7
6
+ metadata.gz: f7755255b96a584aacc078dd9c79a9a9bb8395956547ddd01eb9cc73b29ad1987eed11046a96b399eee1e89a259dd0febfb4f96b2006f0d5a910231beeb2e00a
7
+ data.tar.gz: 356821d145ebc6ee6d068b85806f5f22b1b2359a2cf0515d380f8b2df2309a9f796ea12bde198f7588fd36576f3840f682ef61d35cdddf7817d51aed36f0b2d9
data/lib/opennebula.rb CHANGED
@@ -51,10 +51,14 @@ require 'opennebula/document'
51
51
  require 'opennebula/document_pool'
52
52
  require 'opennebula/zone'
53
53
  require 'opennebula/zone_pool'
54
+ require 'opennebula/security_group'
55
+ require 'opennebula/security_group_pool'
56
+ require 'opennebula/vdc'
57
+ require 'opennebula/vdc_pool'
54
58
  require 'opennebula/system'
55
59
 
56
60
  module OpenNebula
57
61
 
58
62
  # OpenNebula version
59
- VERSION = '4.10.2'
63
+ VERSION = '4.11.80'
60
64
  end
@@ -31,6 +31,8 @@ module OpenNebula
31
31
  # TEMPLATE
32
32
  # GROUP
33
33
  # ACL
34
+ # SECGROUP
35
+ # VDC
34
36
  # RIGHTS -> + separated list
35
37
  # USE
36
38
  # MANAGE
@@ -47,17 +49,19 @@ module OpenNebula
47
49
 
48
50
  RESOURCES =
49
51
  {
50
- "VM" => 0x1000000000,
51
- "HOST" => 0x2000000000,
52
- "NET" => 0x4000000000,
53
- "IMAGE" => 0x8000000000,
54
- "USER" => 0x10000000000,
55
- "TEMPLATE" => 0x20000000000,
56
- "GROUP" => 0x40000000000,
57
- "DATASTORE" => 0x100000000000,
58
- "CLUSTER" => 0x200000000000,
59
- "DOCUMENT" => 0x400000000000,
60
- "ZONE" => 0x800000000000
52
+ "VM" => 0x1000000000,
53
+ "HOST" => 0x2000000000,
54
+ "NET" => 0x4000000000,
55
+ "IMAGE" => 0x8000000000,
56
+ "USER" => 0x10000000000,
57
+ "TEMPLATE" => 0x20000000000,
58
+ "GROUP" => 0x40000000000,
59
+ "DATASTORE" => 0x100000000000,
60
+ "CLUSTER" => 0x200000000000,
61
+ "DOCUMENT" => 0x400000000000,
62
+ "ZONE" => 0x800000000000,
63
+ "SECGROUP" => 0x1000000000000,
64
+ "VDC" => 0x2000000000000
61
65
  }
62
66
 
63
67
  RIGHTS =
@@ -30,7 +30,8 @@ module OpenNebula
30
30
  :update => "datastore.update",
31
31
  :chown => "datastore.chown",
32
32
  :chmod => "datastore.chmod",
33
- :rename => "datastore.rename"
33
+ :rename => "datastore.rename",
34
+ :enable => "datastore.enable"
34
35
  }
35
36
 
36
37
  DATASTORE_TYPES=%w{IMAGE SYSTEM FILE}
@@ -41,6 +42,13 @@ module OpenNebula
41
42
  "FILE" => "fil"
42
43
  }
43
44
 
45
+ DATASTORE_STATES=%w{READY DISABLED}
46
+
47
+ SHORT_DATASTORE_STATES={
48
+ "READY" => "on",
49
+ "DISABLED" => "off"
50
+ }
51
+
44
52
  # Creates a Datastore description with just its identifier
45
53
  # this method should be used to create plain Datastore objects.
46
54
  # +id+ the id of the user
@@ -66,20 +74,6 @@ module OpenNebula
66
74
  #######################################################################
67
75
  # XML-RPC Methods for the Datastore Object
68
76
  #######################################################################
69
- # Returns the datastore type
70
- def type
71
- self['TYPE'].to_i
72
- end
73
-
74
- # Returns the datastore type (string value)
75
- def type_str
76
- DATASTORE_TYPES[type]
77
- end
78
-
79
- # Returns the datastore type (string value)
80
- def short_type_str
81
- SHORT_DATASTORE_TYPES[type_str]
82
- end
83
77
 
84
78
  # Retrieves the information of the given Datastore.
85
79
  def info()
@@ -157,10 +151,50 @@ module OpenNebula
157
151
  return call(DATASTORE_METHODS[:rename], @pe_id, name)
158
152
  end
159
153
 
154
+ # Enables a Datastore
155
+ def enable
156
+ return call(DATASTORE_METHODS[:enable], @pe_id, true)
157
+ end
158
+
159
+ # Disables a Datastore
160
+ def disable
161
+ return call(DATASTORE_METHODS[:enable], @pe_id, false)
162
+ end
163
+
160
164
  # ---------------------------------------------------------------------
161
165
  # Helpers to get information
162
166
  # ---------------------------------------------------------------------
163
167
 
168
+ # Returns the datastore type
169
+ def type
170
+ self['TYPE'].to_i
171
+ end
172
+
173
+ # Returns the datastore type (string value)
174
+ def type_str
175
+ DATASTORE_TYPES[type]
176
+ end
177
+
178
+ # Returns the datastore type (string value)
179
+ def short_type_str
180
+ SHORT_DATASTORE_TYPES[type_str]
181
+ end
182
+
183
+ # Returns the state of the datastore (numeric value)
184
+ def state
185
+ self['STATE'].to_i
186
+ end
187
+
188
+ # Returns the state of the datastore (string value)
189
+ def state_str
190
+ DATASTORE_STATES[state]
191
+ end
192
+
193
+ # Returns the state of the datastore (string value)
194
+ def short_state_str
195
+ SHORT_DATASTORE_STATES[state_str]
196
+ end
197
+
164
198
  # Returns whether or not the image with id 'id' is part of this datastore
165
199
  def contains(id)
166
200
  #This doesn't work in ruby 1.8.5
@@ -29,20 +29,19 @@ module OpenNebula
29
29
  :update => "group.update",
30
30
  :delete => "group.delete",
31
31
  :quota => "group.quota",
32
- :add_provider => "group.addprovider",
33
- :del_provider => "group.delprovider"
32
+ :add_admin => "group.addadmin",
33
+ :del_admin => "group.deladmin",
34
34
  }
35
35
 
36
36
  # Flag for requesting connected user's group info
37
37
  SELF = -1
38
38
 
39
39
  # Default resource ACL's for group users (create)
40
- GROUP_DEFAULT_ACLS = "VM+IMAGE+TEMPLATE+DOCUMENT"
41
- ALL_CLUSTERS_IN_ZONE = 10
40
+ GROUP_DEFAULT_ACLS = "VM+IMAGE+TEMPLATE+DOCUMENT+SECGROUP"
42
41
 
43
42
  # The default view for group and group admins, must be defined in
44
43
  # sunstone_views.yaml
45
- GROUP_ADMIN_SUNSTONE_VIEWS = "vdcadmin"
44
+ GROUP_ADMIN_SUNSTONE_VIEWS = "groupadmin"
46
45
 
47
46
  # Creates a Group description with just its identifier
48
47
  # this method should be used to create plain Group objects.
@@ -82,13 +81,14 @@ module OpenNebula
82
81
  # group_hash[:name] the group name
83
82
  # group_hash[:group_admin] the admin user definition hash, see def
84
83
  # create_admin_user function description for details.
85
- # group_hash[:resource_providers]
86
- # group_hash[:resource_providers][:zone_id]
87
- # group_hash[:resource_providers][:cluster_id]
88
84
  # group_hash[:views] Array of sunstone view names, to be stored
89
85
  # in SUNSTONE_VIEWS
90
86
  # group_hash[:default_view] Default sunstone view name, to be stored
91
87
  # in DEFAULT_VIEW
88
+ # group_hash[:admin_views] Array of sunstone view names, to be stored
89
+ # in GROUP_ADMIN_VIEWS
90
+ # group_hash[:default_admin_view] Default sunstone view name, to be stored
91
+ # in DEFAULT_ADMIN_DEFAULT_VIEW
92
92
  #
93
93
  def create(group_hash)
94
94
  # Check arguments
@@ -107,17 +107,6 @@ module OpenNebula
107
107
  rc = self.allocate(group_hash[:name])
108
108
  return rc if OpenNebula.is_error?(rc)
109
109
 
110
- # Handle resource providers
111
- group_hash[:resource_providers].each { |rp|
112
- next if rp[:zone_id].nil? && rp[:cluster_id].nil?
113
-
114
- if rp[:cluster_id].class == String && rp[:cluster_id] == "ALL"
115
- add_provider(rp[:zone_id],ALL_CLUSTERS_IN_ZONE)
116
- else
117
- add_provider(rp[:zone_id],rp[:cluster_id])
118
- end
119
- } if !group_hash[:resource_providers].nil?
120
-
121
110
  # Set group ACLs to create resources
122
111
  rc, msg = create_default_acls(group_hash[:resources])
123
112
 
@@ -151,24 +140,31 @@ module OpenNebula
151
140
  end
152
141
 
153
142
  str = ""
154
- update = false
155
143
 
156
144
  # Add Sunstone views for the group
157
145
  if group_hash[:views]
158
146
  str += "SUNSTONE_VIEWS=\"#{group_hash[:views].join(",")}\"\n"
159
- update = true
160
147
  end
161
148
 
162
- # Add Sunstone views for the group
163
149
  if group_hash[:default_view]
164
150
  str += "DEFAULT_VIEW=\"#{group_hash[:default_view]}\"\n"
165
- update = true
166
151
  end
167
152
 
168
- if update
169
- self.update(str, true)
153
+ # And the admin views
154
+ if group_hash[:admin_views]
155
+ str += "GROUP_ADMIN_VIEWS=\"#{group_hash[:admin_views].join(",")}\"\n"
156
+ else
157
+ str += "GROUP_ADMIN_VIEWS=#{GROUP_ADMIN_SUNSTONE_VIEWS}\n"
170
158
  end
171
159
 
160
+ if group_hash[:default_admin_view]
161
+ str += "GROUP_ADMIN_DEFAULT_VIEW=\"#{group_hash[:default_admin_view]}\"\n"
162
+ else
163
+ str += "GROUP_ADMIN_DEFAULT_VIEW=#{GROUP_ADMIN_SUNSTONE_VIEWS}"
164
+ end
165
+
166
+ self.update(str, true)
167
+
172
168
  return 0
173
169
  end
174
170
 
@@ -210,24 +206,22 @@ module OpenNebula
210
206
  return rc
211
207
  end
212
208
 
213
- # Adds a resource provider to this group
214
- # @param zone_id [Integer] Zone ID
215
- # @param cluster_id [Integer] Cluster ID
209
+ # Adds a User to the Group administrators set
210
+ # @param user_id [Integer] User ID
216
211
  #
217
212
  # @return [nil, OpenNebula::Error] nil in case of success, Error
218
213
  # otherwise
219
- def add_provider(zone_id, cluster_id)
220
- return call(GROUP_METHODS[:add_provider], @pe_id, zone_id.to_i, cluster_id.to_i)
214
+ def add_admin(user_id)
215
+ return call(GROUP_METHODS[:add_admin], @pe_id, user_id.to_i)
221
216
  end
222
217
 
223
- # Deletes a resource provider from this group
224
- # @param zone_id [Integer] Zone ID
225
- # @param cluster_id [Integer] Cluster ID
218
+ # Removes a User from the Group administrators set
219
+ # @param user_id [Integer] User ID
226
220
  #
227
221
  # @return [nil, OpenNebula::Error] nil in case of success, Error
228
222
  # otherwise
229
- def del_provider(zone_id, cluster_id)
230
- return call(GROUP_METHODS[:del_provider], @pe_id, zone_id.to_i, cluster_id.to_i)
223
+ def del_admin(user_id)
224
+ return call(GROUP_METHODS[:del_admin], @pe_id, user_id.to_i)
231
225
  end
232
226
 
233
227
  # ---------------------------------------------------------------------
@@ -243,15 +237,31 @@ module OpenNebula
243
237
  return id_array != nil && id_array.include?(uid.to_s)
244
238
  end
245
239
 
240
+ # Returns whether or not the user with id 'uid' is an admin of this group
241
+ def contains_admin(uid)
242
+ #This doesn't work in ruby 1.8.5
243
+ #return self["ADMINS/ID[.=#{uid}]"] != nil
244
+
245
+ id_array = retrieve_elements('ADMINS/ID')
246
+ return id_array != nil && id_array.include?(uid.to_s)
247
+ end
248
+
246
249
  # Returns an array with the numeric user ids
247
250
  def user_ids
248
- array = Array.new
251
+ ids = self.retrieve_elements("USERS/ID")
252
+
253
+ return [] if ids.nil?
249
254
 
250
- self.each("USERS/ID") do |id|
251
- array << id.text.to_i
252
- end
255
+ return ids.collect! {|x| x.to_i}
256
+ end
257
+
258
+ # Returns an array with the numeric admin user ids
259
+ def admin_ids
260
+ ids = self.retrieve_elements("ADMINS/ID")
261
+
262
+ return [] if ids.nil?
253
263
 
254
- return array
264
+ return ids.collect! {|x| x.to_i}
255
265
  end
256
266
 
257
267
  private
@@ -297,10 +307,6 @@ module OpenNebula
297
307
  # gdef[:group_admin][:name] username for group admin
298
308
  # gdef[:group_admin][:password] password for group admin
299
309
  # gdef[:group_admin][:auth_driver] auth driver for group admin
300
- # gdef[:group_admin][:resources] resources that group admin manage
301
- # gdef[:group_admin][:manage_resources] whether group admin manages
302
- # group users
303
- # gdef[:resources] resources that group users manage
304
310
  #
305
311
  # @return [nil, OpenNebula::Error] nil in case of success, Error
306
312
  def create_admin_user(gdef)
@@ -336,37 +342,13 @@ module OpenNebula
336
342
  return rc
337
343
  end
338
344
 
339
- # Set the default admin view to vdcadmin
340
- group_admin.update("DEFAULT_VIEW=#{GROUP_ADMIN_SUNSTONE_VIEWS}", true)
341
-
342
- #Create admin group acls
343
- acls = Array.new
344
-
345
- acls_str = (gdef[:group_admin][:resources] || \
346
- gdef[:resources] || GROUP_DEFAULT_ACLS)
347
-
348
- manage_users = gdef[:group_admin][:manage_users] || "YES"
349
-
350
- if manage_users.upcase == "YES"
351
- acls << "##{group_admin.id} USER/@#{self.id} CREATE+USE+MANAGE+ADMIN"
352
- end
353
-
354
- acls << "##{group_admin.id} #{acls_str}/@#{self.id} " +
355
- "CREATE+USE+MANAGE"
356
-
357
- rc, tmp = create_group_acls(acls)
345
+ rc = self.add_admin(group_admin.id)
358
346
 
359
347
  if OpenNebula.is_error?(rc)
360
348
  group_admin.delete
361
349
  return rc
362
350
  end
363
351
 
364
- #Set Sunstone Views for the group
365
- gtmpl = "GROUP_ADMINS=#{gdef[:group_admin][:name]}\n"
366
- gtmpl << "GROUP_ADMIN_VIEWS=#{GROUP_ADMIN_SUNSTONE_VIEWS}\n"
367
-
368
- self.update(gtmpl, true)
369
-
370
352
  return nil
371
353
  end
372
354
  end
@@ -25,7 +25,7 @@ module OpenNebula
25
25
  alias_method :each_with_xpath, :each
26
26
 
27
27
  PAGINATED_POOLS=%w{VM_POOL IMAGE_POOL TEMPLATE_POOL VN_POOL
28
- DOCUMENT_POOL}
28
+ DOCUMENT_POOL SECGROUP_POOL}
29
29
 
30
30
  protected
31
31
  #pool:: _String_ XML name of the root element
@@ -0,0 +1,164 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2015, 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 SecurityGroup < PoolElement
22
+ #######################################################################
23
+ # Constants and Class Methods
24
+ #######################################################################
25
+
26
+
27
+ SECGROUP_METHODS = {
28
+ :allocate => "secgroup.allocate",
29
+ :info => "secgroup.info",
30
+ :update => "secgroup.update",
31
+ :delete => "secgroup.delete",
32
+ :chown => "secgroup.chown",
33
+ :chmod => "secgroup.chmod",
34
+ :clone => "secgroup.clone",
35
+ :rename => "secgroup.rename"
36
+ }
37
+
38
+ # Creates a SecurityGroup description with just its identifier
39
+ # this method should be used to create plain SecurityGroup objects.
40
+ # @param pe_id [Integer] the id of the object
41
+ def SecurityGroup.build_xml(pe_id=nil)
42
+ if pe_id
43
+ obj_xml = "<SECURITY_GROUP><ID>#{pe_id}</ID></SECURITY_GROUP>"
44
+ else
45
+ obj_xml = "<SECURITY_GROUP></SECURITY_GROUP>"
46
+ end
47
+
48
+ XMLElement.build_xml(obj_xml,'SECURITY_GROUP')
49
+ end
50
+
51
+ # Class constructor
52
+ def initialize(xml, client)
53
+ super(xml,client)
54
+
55
+ @client = client
56
+ end
57
+
58
+ #######################################################################
59
+ # XML-RPC Methods for the SecurityGroup Object
60
+ #######################################################################
61
+
62
+ # Retrieves the information of the given SecurityGroup.
63
+ def info()
64
+ super(SECGROUP_METHODS[:info], 'SECURITY_GROUP')
65
+ end
66
+
67
+ alias_method :info!, :info
68
+
69
+ # Allocates a new SecurityGroup in OpenNebula
70
+ #
71
+ # @param description [String] The contents of the SecurityGroup.
72
+ #
73
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
74
+ # otherwise
75
+ def allocate(description)
76
+ super(SECGROUP_METHODS[:allocate], description)
77
+ end
78
+
79
+ # Deletes the SecurityGroup
80
+ def delete()
81
+ super(SECGROUP_METHODS[:delete])
82
+ end
83
+
84
+ # Replaces the securitygroup contents
85
+ #
86
+ # @param new_securitygroup [String] New securitygroup contents
87
+ # @param append [true, false] True to append new attributes instead of
88
+ # replace the whole securitygroup
89
+ #
90
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
91
+ # otherwise
92
+ def update(new_securitygroup, append=false)
93
+ super(SECGROUP_METHODS[:update], new_securitygroup, append ? 1 : 0)
94
+ end
95
+
96
+ # Changes the owner/group
97
+ #
98
+ # @param uid [Integer] the new owner id. Set to -1 to leave the current one
99
+ # @param gid [Integer] the new group id. Set to -1 to leave the current one
100
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
101
+ # otherwise
102
+ def chown(uid, gid)
103
+ super(SECGROUP_METHODS[:chown], uid, gid)
104
+ end
105
+
106
+ # Changes the SecurityGroup permissions.
107
+ #
108
+ # @param octet [String] Permissions octed , e.g. 640
109
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
110
+ # otherwise
111
+ def chmod_octet(octet)
112
+ super(SECGROUP_METHODS[:chmod], octet)
113
+ end
114
+
115
+ # Changes the SecurityGroup permissions.
116
+ # Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
117
+ #
118
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
119
+ # otherwise
120
+ def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
121
+ other_m, other_a)
122
+ super(SECGROUP_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
123
+ group_m, group_a, other_u, other_m, other_a)
124
+ end
125
+
126
+ # Clones this SecurityGroup into a new one
127
+ #
128
+ # @param [String] name for the new SecurityGroup.
129
+ #
130
+ # @return [Integer, OpenNebula::Error] The new SecurityGroup ID in case
131
+ # of success, Error otherwise
132
+ def clone(name)
133
+ return Error.new('ID not defined') if !@pe_id
134
+
135
+ rc = @client.call(SECGROUP_METHODS[:clone], @pe_id, name)
136
+
137
+ return rc
138
+ end
139
+
140
+ # Renames this SecurityGroup
141
+ #
142
+ # @param name [String] New name for the SecurityGroup.
143
+ #
144
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
145
+ # otherwise
146
+ def rename(name)
147
+ return call(SECGROUP_METHODS[:rename], @pe_id, name)
148
+ end
149
+
150
+ #######################################################################
151
+ # Helpers to get SecurityGroup information
152
+ #######################################################################
153
+
154
+ # Returns the group identifier
155
+ # [return] _Integer_ the element's group ID
156
+ def gid
157
+ self['GID'].to_i
158
+ end
159
+
160
+ def owner_id
161
+ self['UID'].to_i
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,78 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2015, 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 SecurityGroupPool < Pool
22
+ #######################################################################
23
+ # Constants and Class attribute accessors
24
+ #######################################################################
25
+
26
+ SECGROUP_POOL_METHODS = {
27
+ :info => "secgrouppool.info"
28
+ }
29
+
30
+ #######################################################################
31
+ # Class constructor & Pool Methods
32
+ #######################################################################
33
+
34
+ # +client+ a Client object that represents an XML-RPC connection
35
+ # +user_id+ used to refer to a Pool with Templates from that user
36
+ def initialize(client, user_id=-1)
37
+ super('SECURITY_GROUP_POOL','SECURITY_GROUP',client)
38
+
39
+ @user_id = user_id
40
+ end
41
+
42
+ # Factory method to create Template objects
43
+ def factory(element_xml)
44
+ OpenNebula::SecurityGroup.new(element_xml,@client)
45
+ end
46
+
47
+ #######################################################################
48
+ # XML-RPC Methods for the Template Object
49
+ #######################################################################
50
+
51
+ # Retrieves all or part of the objects in the pool.
52
+ def info(*args)
53
+ case args.size
54
+ when 0
55
+ info_filter(SECGROUP_POOL_METHODS[:info],@user_id,-1,-1)
56
+ when 3
57
+ info_filter(SECGROUP_POOL_METHODS[:info],args[0],args[1],args[2])
58
+ end
59
+ end
60
+
61
+ def info_all()
62
+ return super(SECGROUP_POOL_METHODS[:info])
63
+ end
64
+
65
+ def info_mine()
66
+ return super(SECGROUP_POOL_METHODS[:info])
67
+ end
68
+
69
+ def info_group()
70
+ return super(SECGROUP_POOL_METHODS[:info])
71
+ end
72
+
73
+ alias_method :info!, :info
74
+ alias_method :info_all!, :info_all
75
+ alias_method :info_mine!, :info_mine
76
+ alias_method :info_group!, :info_group
77
+ end
78
+ end
@@ -0,0 +1,236 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2015, 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 Vdc < PoolElement
22
+ #######################################################################
23
+ # Constants and Class Methods
24
+ #######################################################################
25
+
26
+ ALL_RESOURCES = "-10"
27
+
28
+ VDC_METHODS = {
29
+ :info => "vdc.info",
30
+ :allocate => "vdc.allocate",
31
+ :update => "vdc.update",
32
+ :rename => "vdc.rename",
33
+ :delete => "vdc.delete",
34
+
35
+ :add_group => "vdc.addgroup",
36
+ :del_group => "vdc.delgroup",
37
+ :add_cluster => "vdc.addcluster",
38
+ :del_cluster => "vdc.delcluster",
39
+ :add_host => "vdc.addhost",
40
+ :del_host => "vdc.delhost",
41
+ :add_datastore => "vdc.adddatastore",
42
+ :del_datastore => "vdc.deldatastore",
43
+ :add_vnet => "vdc.addvnet",
44
+ :del_vnet => "vdc.delvnet",
45
+ }
46
+
47
+ # Creates a Vdc description with just its identifier
48
+ # this method should be used to create plain Vdc objects.
49
+ # @param id [Integer] the id of the Vdc
50
+ #
51
+ # Example:
52
+ # vdc = Vdc.new(Vdc.build_xml(3),rpc_client)
53
+ #
54
+ def Vdc.build_xml(pe_id=nil)
55
+ if pe_id
56
+ vdc_xml = "<VDC><ID>#{pe_id}</ID></VDC>"
57
+ else
58
+ vdc_xml = "<VDC></VDC>"
59
+ end
60
+
61
+ XMLElement.build_xml(vdc_xml,'VDC')
62
+ end
63
+
64
+ # Class constructor
65
+ def initialize(xml, client)
66
+ super(xml,client)
67
+ end
68
+
69
+ #######################################################################
70
+ # XML-RPC Methods for the Vdc Object
71
+ #######################################################################
72
+
73
+ # Retrieves the information of the given Vdc.
74
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
75
+ # otherwise
76
+ def info()
77
+ super(VDC_METHODS[:info], 'VDC')
78
+ end
79
+
80
+ alias_method :info!, :info
81
+
82
+ # Allocates a new Vdc in OpenNebula
83
+ #
84
+ # @param description [String] The template of the Vdc.
85
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
86
+ # otherwise
87
+ def allocate(description)
88
+ super(VDC_METHODS[:allocate], description)
89
+ end
90
+
91
+ # Replaces the template contents
92
+ #
93
+ # @param new_template [String] New template contents
94
+ # @param append [true, false] True to append new attributes instead of
95
+ # replace the whole template
96
+ #
97
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
98
+ # otherwise
99
+ def update(new_template=nil, append=false)
100
+ super(VDC_METHODS[:update], new_template, append ? 1 : 0)
101
+ end
102
+
103
+ # Deletes the Vdc
104
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
105
+ # otherwise
106
+ def delete()
107
+ super(VDC_METHODS[:delete])
108
+ end
109
+
110
+ # Renames this Vdc
111
+ #
112
+ # @param name [String] New name for the Vdc.
113
+ #
114
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
115
+ # otherwise
116
+ def rename(name)
117
+ return call(VDC_METHODS[:rename], @pe_id, name)
118
+ end
119
+
120
+ # Adds a group to this VDC
121
+ # @param group_id [Integer] Group ID
122
+ #
123
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
124
+ # otherwise
125
+ def add_group(group_id)
126
+ return call(VDC_METHODS[:add_group], @pe_id, group_id.to_i)
127
+ end
128
+
129
+ # Deletes a group from this VDC
130
+ # @param group_id [Integer] Group ID
131
+ #
132
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
133
+ # otherwise
134
+ def del_group(group_id)
135
+ return call(VDC_METHODS[:del_group], @pe_id, group_id.to_i)
136
+ end
137
+
138
+ # Adds a cluster to this VDC
139
+ # @param zone_id [Integer] Zone ID
140
+ # @param cluster_id [Integer] Cluster ID
141
+ #
142
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
143
+ # otherwise
144
+ def add_cluster(zone_id, cluster_id)
145
+ return call(VDC_METHODS[:add_cluster], @pe_id, zone_id.to_i, cluster_id.to_i)
146
+ end
147
+
148
+ # Deletes a cluster from this VDC
149
+ # @param zone_id [Integer] Zone ID
150
+ # @param cluster_id [Integer] Cluster ID
151
+ #
152
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
153
+ # otherwise
154
+ def del_cluster(zone_id, cluster_id)
155
+ return call(VDC_METHODS[:del_cluster], @pe_id, zone_id.to_i, cluster_id.to_i)
156
+ end
157
+
158
+ # Adds a host to this VDC
159
+ # @param zone_id [Integer] Zone ID
160
+ # @param host_id [Integer] Host ID
161
+ #
162
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
163
+ # otherwise
164
+ def add_host(zone_id, host_id)
165
+ return call(VDC_METHODS[:add_host], @pe_id, zone_id.to_i, host_id.to_i)
166
+ end
167
+
168
+ # Deletes a host from this VDC
169
+ # @param zone_id [Integer] Zone ID
170
+ # @param host_id [Integer] Host ID # Adds a host to this VDC
171
+ # @param zone_id [Integer] Zone ID
172
+ # @param host_id [Integer] Host ID
173
+ #
174
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
175
+ # otherwise
176
+ def add_host(zone_id, host_id)
177
+ return call(VDC_METHODS[:add_host], @pe_id, zone_id.to_i, host_id.to_i)
178
+ end
179
+
180
+ # Deletes a host from this VDC
181
+ # @param zone_id [Integer] Zone ID
182
+ # @param host_id [Integer] Host ID
183
+ #
184
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
185
+ # otherwise
186
+ def del_host(zone_id, host_id)
187
+ return call(VDC_METHODS[:del_host], @pe_id, zone_id.to_i, host_id.to_i)
188
+ end
189
+ #
190
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
191
+ # otherwise
192
+ def del_host(zone_id, host_id)
193
+ return call(VDC_METHODS[:del_host], @pe_id, zone_id.to_i, host_id.to_i)
194
+ end
195
+
196
+ # Adds a datastore to this VDC
197
+ # @param zone_id [Integer] Zone ID
198
+ # @param datastore_id [Integer] Datastore ID
199
+ #
200
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
201
+ # otherwise
202
+ def add_datastore(zone_id, datastore_id)
203
+ return call(VDC_METHODS[:add_datastore], @pe_id, zone_id.to_i, datastore_id.to_i)
204
+ end
205
+
206
+ # Deletes a datastore from this VDC
207
+ # @param zone_id [Integer] Zone ID
208
+ # @param datastore_id [Integer] Datastore ID
209
+ #
210
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
211
+ # otherwise
212
+ def del_datastore(zone_id, datastore_id)
213
+ return call(VDC_METHODS[:del_datastore], @pe_id, zone_id.to_i, datastore_id.to_i)
214
+ end
215
+
216
+ # Adds a vnet to this VDC
217
+ # @param zone_id [Integer] Zone ID
218
+ # @param vnet_id [Integer] Vnet ID
219
+ #
220
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
221
+ # otherwise
222
+ def add_vnet(zone_id, vnet_id)
223
+ return call(VDC_METHODS[:add_vnet], @pe_id, zone_id.to_i, vnet_id.to_i)
224
+ end
225
+
226
+ # Deletes a vnet from this VDC
227
+ # @param zone_id [Integer] Zone ID
228
+ # @param vnet_id [Integer] Vnet ID
229
+ #
230
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
231
+ # otherwise
232
+ def del_vnet(zone_id, vnet_id)
233
+ return call(VDC_METHODS[:del_vnet], @pe_id, zone_id.to_i, vnet_id.to_i)
234
+ end
235
+ end
236
+ end
@@ -0,0 +1,58 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2015, 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 VdcPool < Pool
22
+ #######################################################################
23
+ # Constants and Class attribute accessors
24
+ #######################################################################
25
+
26
+ VDC_POOL_METHODS = {
27
+ :info => "vdcpool.info"
28
+ }
29
+
30
+ #######################################################################
31
+ # Class constructor & Pool Methods
32
+ #######################################################################
33
+
34
+ # @param client [OpenNebula::Client] XML-RPC connection
35
+ def initialize(client)
36
+ super('VDC_POOL','VDC',client)
37
+ end
38
+
39
+ # Factory method to create Vdc objects
40
+ # @return [Vdc] new Vdc object
41
+ def factory(element_xml)
42
+ OpenNebula::Vdc.new(element_xml,@client)
43
+ end
44
+
45
+ #######################################################################
46
+ # XML-RPC Methods for the Vdc Object
47
+ #######################################################################
48
+
49
+ # Retrieves all the VDCs in the pool.
50
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
51
+ # otherwise
52
+ def info()
53
+ super(VDC_POOL_METHODS[:info])
54
+ end
55
+
56
+ alias_method :info!, :info
57
+ end
58
+ end
@@ -25,9 +25,11 @@ module OpenNebula
25
25
 
26
26
 
27
27
  VM_POOL_METHODS = {
28
- :info => "vmpool.info",
29
- :monitoring => "vmpool.monitoring",
30
- :accounting => "vmpool.accounting"
28
+ :info => "vmpool.info",
29
+ :monitoring => "vmpool.monitoring",
30
+ :accounting => "vmpool.accounting",
31
+ :showback => "vmpool.showback",
32
+ :calculate_showback => "vmpool.calculateshowback"
31
33
  }
32
34
 
33
35
  # Constants for info queries (include/RequestManagerPoolInfoFilter.h)
@@ -162,6 +164,27 @@ module OpenNebula
162
164
  return @client.call(VM_POOL_METHODS[:monitoring], filter_flag)
163
165
  end
164
166
 
167
+ # Processes all the history records, and stores the monthly cost for
168
+ # each VM
169
+ #
170
+ # @param [Integer] start_month First month (+year) to process. January is 1.
171
+ # Use -1 to unset
172
+ # @param [Integer] start_year First year (+month) to process. e.g. 2014.
173
+ # Use -1 to unset
174
+ # @param [Integer] end_month Last month (+year) to process. January is 1.
175
+ # Use -1 to unset
176
+ # @param [Integer] end_year Last year (+month) to process. e.g. 2014.
177
+ # Use -1 to unset
178
+ def calculate_showback(start_month, start_year, end_month, end_year)
179
+ start_month ||= -1
180
+ start_year ||= -1
181
+ end_month ||= -1
182
+ end_year ||= -1
183
+
184
+ return @client.call(VM_POOL_METHODS[:calculate_showback],
185
+ start_month, start_year, end_month, end_year)
186
+ end
187
+
165
188
  # Retrieves the accounting data for all the VMs in the pool
166
189
  #
167
190
  # @param [Integer] filter_flag Optional filter flag to retrieve all or
@@ -283,6 +306,92 @@ module OpenNebula
283
306
  xml_str
284
307
  end
285
308
 
309
+ # Retrieves the showback data for all the VMs in the pool
310
+ #
311
+ # @param [Integer] filter_flag Optional filter flag to retrieve all or
312
+ # part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE
313
+ # or user_id
314
+ # @param [Hash] options
315
+ # @option params [Integer] :start_year First month (+year) to take
316
+ # into account, if no start time is required use -1
317
+ # @option params [Integer] :start_month First year (+month) to take
318
+ # into account, if no start time is required use -1
319
+ # @option params [Integer] :end_year Last month (+year) to take
320
+ # into account, if no end time is required use -1
321
+ # @option params [Integer] :end_month Last year (+month) to take
322
+ # into account, if no end time is required use -1
323
+ # @option params [Integer] :group Group id to filter the results
324
+ # @option params [String] :xpath Xpath expression to filter the results.
325
+ # For example: SHOWBACK[TOTAL_COST>0]
326
+ # @option params [String] :order_by_1 Xpath expression to group the
327
+ # @option params [String] :order_by_2 Xpath expression to group the
328
+ # returned hash. This will be the second level of the hash
329
+ #
330
+ # @return [Hash, OpenNebula::Error]
331
+ # The first level hash uses the :order_by_1 values as keys, and
332
+ # as value a Hash with the :order_by_2 values and the SHOWBACK_RECORDS
333
+ def showback(filter_flag=INFO_ALL, options={})
334
+ data_hash = Hash.new
335
+
336
+ rc = build_showback(filter_flag, options) do |record|
337
+ hash = data_hash
338
+
339
+ if options[:order_by_1]
340
+ id_1 = record[options[:order_by_1]]
341
+ data_hash[id_1] ||= Hash.new
342
+
343
+ if options[:order_by_2]
344
+ id_2 = record[options[:order_by_2]]
345
+ data_hash[id_1][id_2] ||= Hash.new
346
+
347
+ hash = data_hash[id_1][id_2]
348
+ else
349
+ hash = data_hash[id_1]
350
+ end
351
+ end
352
+
353
+ hash["SHOWBACK_RECORDS"] ||= Hash.new
354
+ hash["SHOWBACK_RECORDS"]["SHOWBACK"] ||= Array.new
355
+ hash["SHOWBACK_RECORDS"]["SHOWBACK"] << record.to_hash['SHOWBACK']
356
+ end
357
+
358
+ return rc if OpenNebula.is_error?(rc)
359
+
360
+ data_hash
361
+ end
362
+
363
+ # Retrieves the showback data for all the VMs in the pool, in xml
364
+ #
365
+ # @param [Integer] filter_flag Optional filter flag to retrieve all or
366
+ # part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE
367
+ # or user_id
368
+ # @param [Hash] options
369
+ # @option params [Integer] :start_year First month (+year) to take
370
+ # into account, if no start time is required use -1
371
+ # @option params [Integer] :start_month First year (+month) to take
372
+ # into account, if no start time is required use -1
373
+ # @option params [Integer] :end_year Last month (+year) to take
374
+ # into account, if no end time is required use -1
375
+ # @option params [Integer] :end_month Last year (+month) to take
376
+ # into account, if no end time is required use -1
377
+ # @option params [Integer] :group Group id to filter the results
378
+ # @option params [String] :xpath Xpath expression to filter the results.
379
+ # For example: SHOWBACK[TOTAL_COST>10]
380
+ #
381
+ # @return [String] the xml representing the showback data
382
+ def showback_xml(filter_flag=INFO_ALL, options={})
383
+ xml_str = "<SHOWBACK_RECORDS>\n"
384
+
385
+ rc = build_showback(filter_flag, options) do |showback|
386
+ xml_str << showback.to_xml
387
+ end
388
+
389
+ return rc if OpenNebula.is_error?(rc)
390
+
391
+ xml_str << "\n</SHOWBACK_RECORDS>"
392
+ xml_str
393
+ end
394
+
286
395
  private
287
396
 
288
397
  def build_accounting(filter_flag, options, &block)
@@ -316,6 +425,38 @@ module OpenNebula
316
425
  acct_hash
317
426
  end
318
427
 
428
+ def build_showback(filter_flag, options, &block)
429
+ xml_str = @client.call(VM_POOL_METHODS[:showback],
430
+ filter_flag,
431
+ options[:start_month],
432
+ options[:start_year],
433
+ options[:end_month],
434
+ options[:end_year])
435
+
436
+ return xml_str if OpenNebula.is_error?(xml_str)
437
+
438
+ xmldoc = XMLElement.new
439
+ xmldoc.initialize_xml(xml_str, 'SHOWBACK_RECORDS')
440
+
441
+ xpath_array = Array.new
442
+ xpath_array << "SHOWBACK[GID=#{options[:group]}]" if options[:group]
443
+ xpath_array << options[:xpath] if options[:xpath]
444
+
445
+ if xpath_array.empty?
446
+ xpath_str = "SHOWBACK"
447
+ else
448
+ xpath_str = xpath_array.join(' | ')
449
+ end
450
+
451
+ data_hash = Hash.new
452
+
453
+ xmldoc.each(xpath_str) do |showback|
454
+ block.call(showback)
455
+ end
456
+
457
+ data_hash
458
+ end
459
+
319
460
  def info_filter(xml_method, who, start_id, end_id, state)
320
461
  return xmlrpc_info(xml_method, who, start_id, end_id, state)
321
462
  end
@@ -224,7 +224,7 @@ module OpenNebula
224
224
  end
225
225
 
226
226
  # Reserve a set of addresses from this virtual network
227
- # @param name [String] of the reservation
227
+ # @param rname [String] of the reservation
228
228
  # @param rsize[String] number of addresses to reserve
229
229
  # @param ar_id[String] the ar_id to make the reservation. If set to nil
230
230
  # any address range will be used
@@ -232,6 +232,8 @@ module OpenNebula
232
232
  # nil the first free address will be used
233
233
  # @param vnet [String] ID of the VNET to add the reservation to. If not
234
234
  # set a new VNET will be created.
235
+ # @return [Integer, OpenNebula::Error] The reservation vnet id on
236
+ # success, Error otherwise
235
237
  def reserve(rname, rsize, ar_id, addr, vnet)
236
238
  return Error.new('ID not defined') if !@pe_id
237
239
 
@@ -250,10 +252,7 @@ module OpenNebula
250
252
  rtmpl << "#{addr_name} = #{addr}\n"
251
253
  end
252
254
 
253
- rc = @client.call(VN_METHODS[:reserve], @pe_id, rtmpl)
254
- rc = nil if !OpenNebula.is_error?(rc)
255
-
256
- return rc
255
+ return @client.call(VN_METHODS[:reserve], @pe_id, rtmpl)
257
256
  end
258
257
 
259
258
  # Removes an Address Range from the VirtualNetwork
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opennebula
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.10.2
4
+ version: 4.11.80.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenNebula
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-16 00:00:00.000000000 Z
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -84,6 +84,8 @@ files:
84
84
  - lib/opennebula/oneflow_client.rb
85
85
  - lib/opennebula/pool.rb
86
86
  - lib/opennebula/pool_element.rb
87
+ - lib/opennebula/security_group.rb
88
+ - lib/opennebula/security_group_pool.rb
87
89
  - lib/opennebula/server_cipher_auth.rb
88
90
  - lib/opennebula/server_x509_auth.rb
89
91
  - lib/opennebula/ssh_auth.rb
@@ -92,6 +94,8 @@ files:
92
94
  - lib/opennebula/template_pool.rb
93
95
  - lib/opennebula/user.rb
94
96
  - lib/opennebula/user_pool.rb
97
+ - lib/opennebula/vdc.rb
98
+ - lib/opennebula/vdc_pool.rb
95
99
  - lib/opennebula/virtual_machine.rb
96
100
  - lib/opennebula/virtual_machine_pool.rb
97
101
  - lib/opennebula/virtual_network.rb
@@ -117,9 +121,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
121
  version: '0'
118
122
  required_rubygems_version: !ruby/object:Gem::Requirement
119
123
  requirements:
120
- - - ">="
124
+ - - ">"
121
125
  - !ruby/object:Gem::Version
122
- version: '0'
126
+ version: 1.3.1
123
127
  requirements: []
124
128
  rubyforge_project:
125
129
  rubygems_version: 2.4.5
@@ -127,3 +131,4 @@ signing_key:
127
131
  specification_version: 4
128
132
  summary: OpenNebula Client API
129
133
  test_files: []
134
+ has_rdoc: