oca 3.0.1 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
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 #
@@ -14,6 +14,7 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
+
17
18
  require 'OpenNebula/Pool'
18
19
 
19
20
  module OpenNebula
@@ -21,6 +22,8 @@ module OpenNebula
21
22
  #######################################################################
22
23
  # Constants and Class Methods
23
24
  #######################################################################
25
+
26
+
24
27
  VM_METHODS = {
25
28
  :info => "vm.info",
26
29
  :allocate => "vm.allocate",
@@ -28,7 +31,8 @@ module OpenNebula
28
31
  :migrate => "vm.migrate",
29
32
  :deploy => "vm.deploy",
30
33
  :savedisk => "vm.savedisk",
31
- :chown => "vm.chown"
34
+ :chown => "vm.chown",
35
+ :chmod => "vm.chmod",
32
36
  }
33
37
 
34
38
  VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED}
@@ -101,14 +105,9 @@ module OpenNebula
101
105
  reason_str
102
106
  end
103
107
 
104
- #######################################################################
105
108
  # Class constructor
106
- #######################################################################
107
109
  def initialize(xml, client)
108
110
  super(xml,client)
109
-
110
- @element_name = "VM"
111
- @client = client
112
111
  end
113
112
 
114
113
  #######################################################################
@@ -145,6 +144,11 @@ module OpenNebula
145
144
  action('shutdown')
146
145
  end
147
146
 
147
+ # Shutdowns an already deployed VM
148
+ def reboot
149
+ action('reboot')
150
+ end
151
+
148
152
  # Cancels a running VM
149
153
  def cancel
150
154
  action('cancel')
@@ -216,13 +220,19 @@ module OpenNebula
216
220
  # @param disk_id [Integer] ID of the disk to be saved
217
221
  # @param image_name [String] Name for the new image where the
218
222
  # disk will be saved
223
+ # @param image_type [String] Type of the new image. Set to empty string
224
+ # to use the default type
219
225
  #
220
226
  # @return [Integer, OpenNebula::Error] the new Image ID in case of
221
227
  # success, error otherwise
222
- def save_as(disk_id, image_name)
228
+ def save_as(disk_id, image_name, image_type="")
223
229
  return Error.new('ID not defined') if !@pe_id
224
230
 
225
- rc = @client.call(VM_METHODS[:savedisk], @pe_id, disk_id, image_name)
231
+ rc = @client.call(VM_METHODS[:savedisk],
232
+ @pe_id,
233
+ disk_id,
234
+ image_name,
235
+ image_type)
226
236
 
227
237
  return rc
228
238
  end
@@ -235,6 +245,26 @@ module OpenNebula
235
245
  super(VM_METHODS[:chown], uid, gid)
236
246
  end
237
247
 
248
+ # Changes the permissions.
249
+ #
250
+ # @param octet [String] Permissions octed , e.g. 640
251
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
252
+ # otherwise
253
+ def chmod_octet(octet)
254
+ super(VM_METHODS[:chmod], octet)
255
+ end
256
+
257
+ # Changes the permissions.
258
+ # Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
259
+ #
260
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
261
+ # otherwise
262
+ def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
263
+ other_m, other_a)
264
+ super(VM_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
265
+ group_m, group_a, other_u, other_m, other_a)
266
+ end
267
+
238
268
  #######################################################################
239
269
  # Helpers to get VirtualMachine information
240
270
  #######################################################################
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
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 #
@@ -14,6 +14,7 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
+
17
18
  require 'OpenNebula/Pool'
18
19
 
19
20
  module OpenNebula
@@ -22,6 +23,7 @@ module OpenNebula
22
23
  # Constants and Class attribute accessors
23
24
  #######################################################################
24
25
 
26
+
25
27
  VM_POOL_METHODS = {
26
28
  :info => "vmpool.info"
27
29
  }
@@ -33,7 +35,8 @@ module OpenNebula
33
35
  #######################################################################
34
36
  # Class constructor & Pool Methods
35
37
  #######################################################################
36
-
38
+
39
+
37
40
  # +client+ a Client object that represents a XML-RPC connection
38
41
  # +user_id+ is to refer to a Pool with VirtualMachines from that user
39
42
  def initialize(client, user_id=0)
@@ -50,7 +53,7 @@ module OpenNebula
50
53
  #######################################################################
51
54
  # XML-RPC Methods for the Virtual Network Object
52
55
  #######################################################################
53
-
56
+
54
57
  # Retrieves all or part of the VirtualMachines in the pool.
55
58
  # No arguments, returns the not-in-done VMs for the user
56
59
  # [user_id, start_id, end_id]
@@ -107,9 +110,9 @@ module OpenNebula
107
110
  -1,
108
111
  INFO_NOT_DONE)
109
112
  end
110
-
113
+
111
114
  private
112
-
115
+
113
116
  def info_filter(xml_method, who, start_id, end_id, state)
114
117
  return xmlrpc_info(xml_method, who, start_id, end_id, state)
115
118
  end
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
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 #
@@ -14,13 +14,16 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
+
17
18
  require 'OpenNebula/Pool'
18
19
 
19
20
  module OpenNebula
20
21
  class VirtualNetwork < PoolElement
21
- # ---------------------------------------------------------------------
22
+ #######################################################################
22
23
  # Constants and Class Methods
23
- # ---------------------------------------------------------------------
24
+ #######################################################################
25
+
26
+
24
27
  VN_METHODS = {
25
28
  :info => "vn.info",
26
29
  :allocate => "vn.allocate",
@@ -28,7 +31,11 @@ module OpenNebula
28
31
  :delete => "vn.delete",
29
32
  :addleases => "vn.addleases",
30
33
  :rmleases => "vn.rmleases",
31
- :chown => "vn.chown"
34
+ :chown => "vn.chown",
35
+ :chmod => "vn.chmod",
36
+ :update => "vn.update",
37
+ :hold => "vn.hold",
38
+ :release => "vn.release"
32
39
  }
33
40
 
34
41
  VN_TYPES=%w{RANGED FIXED}
@@ -58,8 +65,6 @@ module OpenNebula
58
65
  # Class constructor
59
66
  def initialize(xml, client)
60
67
  super(xml,client)
61
-
62
- @client = client
63
68
  end
64
69
 
65
70
  #######################################################################
@@ -77,7 +82,14 @@ module OpenNebula
77
82
  def allocate(description)
78
83
  super(VN_METHODS[:allocate],description)
79
84
  end
80
-
85
+
86
+ # Replaces the template contents
87
+ #
88
+ # +new_template+ New template contents
89
+ def update(new_template)
90
+ super(VN_METHODS[:update], new_template)
91
+ end
92
+
81
93
  # Publishes the VirtualNetwork, to be used by other users
82
94
  def publish
83
95
  set_publish(true)
@@ -119,6 +131,32 @@ module OpenNebula
119
131
  return rc
120
132
  end
121
133
 
134
+ # Holds a virtual network Lease as used
135
+ # @param ip [String] IP to hold
136
+ def hold(ip)
137
+ return Error.new('ID not defined') if !@pe_id
138
+
139
+ lease_template = "LEASES = [ IP = #{ip} ]"
140
+
141
+ rc = @client.call(VN_METHODS[:hold], @pe_id, lease_template)
142
+ rc = nil if !OpenNebula.is_error?(rc)
143
+
144
+ return rc
145
+ end
146
+
147
+ # Releases a virtual network Lease on hold
148
+ # @param ip [String] IP to release
149
+ def release(ip)
150
+ return Error.new('ID not defined') if !@pe_id
151
+
152
+ lease_template = "LEASES = [ IP = #{ip} ]"
153
+
154
+ rc = @client.call(VN_METHODS[:release], @pe_id, lease_template)
155
+ rc = nil if !OpenNebula.is_error?(rc)
156
+
157
+ return rc
158
+ end
159
+
122
160
  # Changes the owner/group
123
161
  # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
124
162
  # gid:: _Integer_ the new group id. Set to -1 to leave the current one
@@ -127,9 +165,29 @@ module OpenNebula
127
165
  super(VN_METHODS[:chown], uid, gid)
128
166
  end
129
167
 
130
- # ---------------------------------------------------------------------
168
+ # Changes the virtual network permissions.
169
+ #
170
+ # @param octet [String] Permissions octed , e.g. 640
171
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
172
+ # otherwise
173
+ def chmod_octet(octet)
174
+ super(VN_METHODS[:chmod], octet)
175
+ end
176
+
177
+ # Changes the virtual network permissions.
178
+ # Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
179
+ #
180
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
181
+ # otherwise
182
+ def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
183
+ other_m, other_a)
184
+ super(VN_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
185
+ group_m, group_a, other_u, other_m, other_a)
186
+ end
187
+
188
+ #######################################################################
131
189
  # Helpers to get VirtualNetwork information
132
- # ---------------------------------------------------------------------
190
+ #######################################################################
133
191
 
134
192
  # Returns the group identifier
135
193
  # [return] _Integer_ the element's group ID
@@ -152,14 +210,19 @@ module OpenNebula
152
210
  SHORT_VN_TYPES[type_str]
153
211
  end
154
212
 
213
+ def public?
214
+ if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
215
+ true
216
+ else
217
+ false
218
+ end
219
+ end
220
+
155
221
  private
156
222
  def set_publish(published)
157
- return Error.new('ID not defined') if !@pe_id
223
+ group_u = published ? 1 : 0
158
224
 
159
- rc = @client.call(VN_METHODS[:publish], @pe_id, published)
160
- rc = nil if !OpenNebula.is_error?(rc)
161
-
162
- return rc
225
+ chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
163
226
  end
164
227
 
165
228
  end
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
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 #
@@ -14,6 +14,7 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
+
17
18
  require 'OpenNebula/Pool'
18
19
 
19
20
  module OpenNebula
@@ -21,7 +22,8 @@ module OpenNebula
21
22
  #######################################################################
22
23
  # Constants and Class attribute accessors
23
24
  #######################################################################
24
-
25
+
26
+
25
27
  VN_POOL_METHODS = {
26
28
  :info => "vnpool.info"
27
29
  }
@@ -29,7 +31,7 @@ module OpenNebula
29
31
  #######################################################################
30
32
  # Class constructor & Pool Methods
31
33
  #######################################################################
32
-
34
+
33
35
  # +client+ a Client object that represents a XML-RPC connection
34
36
  # +user_id+ is to refer to a Pool with VirtualNetworks from that user
35
37
  def initialize(client, user_id=0)
@@ -1,5 +1,5 @@
1
1
  # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
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 #
@@ -14,6 +14,7 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
+
17
18
  module OpenNebula
18
19
 
19
20
  begin
@@ -30,11 +31,9 @@ module OpenNebula
30
31
  REXML_FORMATTERS=false
31
32
  end
32
33
 
33
- ###########################################################################
34
34
  # The XMLElement class provides an abstraction of the underlying
35
35
  # XML parser engine. It provides XML-related methods for the Pool and
36
36
  # PoolElement classes
37
- ###########################################################################
38
37
  class XMLElement
39
38
 
40
39
  # xml:: _opaque xml object_ an xml object as returned by build_xml
@@ -202,7 +201,7 @@ module OpenNebula
202
201
  template_like_str('TEMPLATE', indent)
203
202
  end
204
203
 
205
- def template_like_str(root_element, indent=true)
204
+ def template_like_str(root_element, indent=true, xpath_exp=nil)
206
205
  if NOKOGIRI
207
206
  xml_template=@xml.xpath(root_element).to_s
208
207
  rexml=REXML::Document.new(xml_template).root
@@ -218,7 +217,7 @@ module OpenNebula
218
217
  ind_tab=' '
219
218
  end
220
219
 
221
- str=rexml.collect {|n|
220
+ str=rexml.elements.collect(xpath_exp) {|n|
222
221
  if n.class==REXML::Element
223
222
  str_line=""
224
223
  if n.has_elements?
@@ -310,10 +309,8 @@ module OpenNebula
310
309
  end
311
310
  end
312
311
 
313
- ###########################################################################
314
312
  # The XMLUtilsPool module provides an abstraction of the underlying
315
313
  # XML parser engine. It provides XML-related methods for the Pools
316
- ###########################################################################
317
314
  class XMLPool < XMLElement
318
315
 
319
316
  def initialize(xml=nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oca
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: