oca 3.0.1 → 3.2.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.
@@ -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
  IMAGE_POOL_METHODS = {
26
28
  :info => "imagepool.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 Images from that user
35
37
  def initialize(client, user_id=-1)
@@ -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,10 +14,11 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
+
17
18
  module OpenNebula
19
+
18
20
  # The Pool class represents a generic OpenNebula Pool in XML format
19
21
  # and provides the basic functionality to handle the Pool elements
20
-
21
22
  class Pool < XMLPool
22
23
  include Enumerable
23
24
 
@@ -32,7 +33,6 @@ module OpenNebula
32
33
  @element_name = element.upcase
33
34
 
34
35
  @client = client
35
- @hash = nil
36
36
  end
37
37
 
38
38
  # Default Factory Method for the Pools. The factory method returns an
@@ -47,7 +47,7 @@ module OpenNebula
47
47
  #######################################################################
48
48
  # Common XML-RPC Methods for all the Pool Types
49
49
  #######################################################################
50
-
50
+
51
51
  #Gets the pool without any filter. Host, Group and User Pools
52
52
  # xml_method:: _String_ the name of the XML-RPC method
53
53
  def info(xml_method)
@@ -65,7 +65,7 @@ module OpenNebula
65
65
  def info_group(xml_method)
66
66
  return xmlrpc_info(xml_method,INFO_GROUP,-1,-1)
67
67
  end
68
-
68
+
69
69
  def info_filter(xml_method, who, start_id, end_id)
70
70
  return xmlrpc_info(xml_method,who, start_id, end_id)
71
71
  end
@@ -119,7 +119,6 @@ module OpenNebula
119
119
  def initialize(node, client)
120
120
  @xml = node
121
121
  @client = client
122
- @hash = nil
123
122
 
124
123
  if self['ID']
125
124
  @pe_id = self['ID'].to_i
@@ -213,6 +212,47 @@ module OpenNebula
213
212
  return rc
214
213
  end
215
214
 
215
+ # Calls to the corresponding chmod method to modify
216
+ # the object's permission bits
217
+ #
218
+ # @param xml_method [String] the name of the XML-RPC method
219
+ # @param octet [String] Permissions octed , e.g. 640
220
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
221
+ # otherwise
222
+ def chmod_octet(xml_method, octet)
223
+ owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0
224
+ owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0
225
+ owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0
226
+ group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0
227
+ group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0
228
+ group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0
229
+ other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0
230
+ other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0
231
+ other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0
232
+
233
+ chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
234
+ other_m, other_a)
235
+ end
236
+
237
+ # Calls to the corresponding chmod method to modify
238
+ # the object's permission bits
239
+ # Each [Integer] parameter must be 1 to allow, 0 deny, -1 do not change
240
+ #
241
+ # @param xml_method [String] the name of the XML-RPC method
242
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
243
+ # otherwise
244
+ def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
245
+ other_m, other_a)
246
+ return Error.new('ID not defined') if !@pe_id
247
+
248
+ rc = @client.call(xml_method, @pe_id, owner_u, owner_m,
249
+ owner_a, group_u, group_m, group_a, other_u,
250
+ other_m, other_a)
251
+ rc = nil if !OpenNebula.is_error?(rc)
252
+
253
+ return rc
254
+ end
255
+
216
256
  public
217
257
 
218
258
  # Creates new element specifying its id
@@ -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 Template < PoolElement
21
- # ---------------------------------------------------------------------
22
+ #######################################################################
22
23
  # Constants and Class Methods
23
- # ---------------------------------------------------------------------
24
+ #######################################################################
25
+
26
+
24
27
  TEMPLATE_METHODS = {
25
28
  :allocate => "template.allocate",
26
29
  :instantiate => "template.instantiate",
@@ -28,7 +31,8 @@ module OpenNebula
28
31
  :update => "template.update",
29
32
  :publish => "template.publish",
30
33
  :delete => "template.delete",
31
- :chown => "template.chown"
34
+ :chown => "template.chown",
35
+ :chmod => "template.chmod"
32
36
  }
33
37
 
34
38
  # Creates a Template description with just its identifier
@@ -48,18 +52,16 @@ module OpenNebula
48
52
  XMLElement.build_xml(obj_xml,'VMTEMPLATE')
49
53
  end
50
54
 
51
- # ---------------------------------------------------------------------
52
55
  # Class constructor
53
- # ---------------------------------------------------------------------
54
56
  def initialize(xml, client)
55
57
  super(xml,client)
56
58
 
57
59
  @client = client
58
60
  end
59
61
 
60
- # ---------------------------------------------------------------------
62
+ #######################################################################
61
63
  # XML-RPC Methods for the Template Object
62
- # ---------------------------------------------------------------------
64
+ #######################################################################
63
65
 
64
66
  # Retrieves the information of the given Template.
65
67
  def info()
@@ -118,9 +120,29 @@ module OpenNebula
118
120
  super(TEMPLATE_METHODS[:chown], uid, gid)
119
121
  end
120
122
 
121
- # ---------------------------------------------------------------------
123
+ # Changes the Template permissions.
124
+ #
125
+ # @param octet [String] Permissions octed , e.g. 640
126
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
127
+ # otherwise
128
+ def chmod_octet(octet)
129
+ super(TEMPLATE_METHODS[:chmod], octet)
130
+ end
131
+
132
+ # Changes the Template permissions.
133
+ # Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
134
+ #
135
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
136
+ # otherwise
137
+ def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
138
+ other_m, other_a)
139
+ super(TEMPLATE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
140
+ group_m, group_a, other_u, other_m, other_a)
141
+ end
142
+
143
+ #######################################################################
122
144
  # Helpers to get Template information
123
- # ---------------------------------------------------------------------
145
+ #######################################################################
124
146
 
125
147
  # Returns the group identifier
126
148
  # [return] _Integer_ the element's group ID
@@ -132,15 +154,20 @@ module OpenNebula
132
154
  self['UID'].to_i
133
155
  end
134
156
 
157
+ def public?
158
+ if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
159
+ true
160
+ else
161
+ false
162
+ end
163
+ end
164
+
135
165
  private
136
166
 
137
167
  def set_publish(published)
138
- return Error.new('ID not defined') if !@pe_id
168
+ group_u = published ? 1 : 0
139
169
 
140
- rc = @client.call(TEMPLATE_METHODS[:publish], @pe_id, published)
141
- rc = nil if !OpenNebula.is_error?(rc)
142
-
143
- return rc
170
+ chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
144
171
  end
145
172
  end
146
173
  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,21 +14,23 @@
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 TemplatePool < Pool
21
- # ---------------------------------------------------------------------
22
+ #######################################################################
22
23
  # Constants and Class attribute accessors
23
- # ---------------------------------------------------------------------
24
+ #######################################################################
25
+
24
26
 
25
27
  TEMPLATE_POOL_METHODS = {
26
28
  :info => "templatepool.info"
27
29
  }
28
30
 
29
- # ---------------------------------------------------------------------
31
+ #######################################################################
30
32
  # Class constructor & Pool Methods
31
- # ---------------------------------------------------------------------
33
+ #######################################################################
32
34
 
33
35
  # +client+ a Client object that represents an XML-RPC connection
34
36
  # +user_id+ used to refer to a Pool with Templates from that user
@@ -43,9 +45,10 @@ module OpenNebula
43
45
  OpenNebula::Template.new(element_xml,@client)
44
46
  end
45
47
 
46
- # ---------------------------------------------------------------------
48
+ #######################################################################
47
49
  # XML-RPC Methods for the Template Object
48
- # ---------------------------------------------------------------------
50
+ #######################################################################
51
+
49
52
  # Retrieves all or part of the VirtualMachines in the pool.
50
53
  def info(*args)
51
54
  case args.size
@@ -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,22 +14,41 @@
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 User < PoolElement
21
- # ---------------------------------------------------------------------
22
+ #######################################################################
22
23
  # Constants and Class Methods
23
- # ---------------------------------------------------------------------
24
+ #######################################################################
25
+
24
26
  USER_METHODS = {
25
27
  :info => "user.info",
26
28
  :allocate => "user.allocate",
27
29
  :delete => "user.delete",
28
30
  :passwd => "user.passwd",
29
- :chgrp => "user.chgrp"
31
+ :chgrp => "user.chgrp",
32
+ :update => "user.update",
33
+ :chauth => "user.chauth"
30
34
  }
31
35
 
32
- SELF = -1
36
+ SELF = -1
37
+
38
+ # Driver name for default core authentication
39
+ CORE_AUTH = "core"
40
+
41
+ # Driver name for default core authentication
42
+ CIPHER_AUTH = "server_cipher"
43
+
44
+ # Driver name for ssh authentication
45
+ SSH_AUTH = "ssh"
46
+
47
+ # Driver name for x509 authentication
48
+ X509_AUTH = "x509"
49
+
50
+ # Driver name for x509 proxy authentication
51
+ X509_PROXY_AUTH = "x509_proxy"
33
52
 
34
53
  # Creates a User description with just its identifier
35
54
  # this method should be used to create plain User objects.
@@ -48,18 +67,16 @@ module OpenNebula
48
67
  XMLElement.build_xml(user_xml, 'USER')
49
68
  end
50
69
 
51
- # ---------------------------------------------------------------------
52
70
  # Class constructor
53
- # ---------------------------------------------------------------------
54
71
  def initialize(xml, client)
55
72
  super(xml,client)
56
73
 
57
74
  @client = client
58
75
  end
59
76
 
60
- # ---------------------------------------------------------------------
77
+ #######################################################################
61
78
  # XML-RPC Methods for the User Object
62
- # ---------------------------------------------------------------------
79
+ #######################################################################
63
80
 
64
81
  # Retrieves the information of the given User.
65
82
  def info()
@@ -71,8 +88,15 @@ module OpenNebula
71
88
  # +username+ Name of the new user.
72
89
  #
73
90
  # +password+ Password for the new user
74
- def allocate(username, password)
75
- super(USER_METHODS[:allocate], username, password)
91
+ def allocate(username, password, driver=CORE_AUTH)
92
+ super(USER_METHODS[:allocate], username, password, driver)
93
+ end
94
+
95
+ # Replaces the template contents
96
+ #
97
+ # +new_template+ New template contents
98
+ def update(new_template)
99
+ super(USER_METHODS[:update], new_template)
76
100
  end
77
101
 
78
102
  # Deletes the User
@@ -104,9 +128,25 @@ module OpenNebula
104
128
  return rc
105
129
  end
106
130
 
107
- # ---------------------------------------------------------------------
131
+ # Changes the auth driver and the password of the given User
132
+ #
133
+ # @param auth [String] the new auth driver
134
+ # @param password [String] the new password. If it is an empty string,
135
+ # the user password is not changed
136
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
137
+ # otherwise
138
+ def chauth(auth, password="")
139
+ return Error.new('ID not defined') if !@pe_id
140
+
141
+ rc = @client.call(USER_METHODS[:chauth],@pe_id, auth, password)
142
+ rc = nil if !OpenNebula.is_error?(rc)
143
+
144
+ return rc
145
+ end
146
+
147
+ #######################################################################
108
148
  # Helpers to get User information
109
- # ---------------------------------------------------------------------
149
+ #######################################################################
110
150
 
111
151
  # Returns the group identifier
112
152
  # [return] _Integer_ the element's group ID
@@ -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,22 +14,23 @@
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 UserPool < Pool
21
- # ---------------------------------------------------------------------
22
+ #######################################################################
22
23
  # Constants and Class attribute accessors
23
- # ---------------------------------------------------------------------
24
+ #######################################################################
24
25
 
25
26
  USER_POOL_METHODS = {
26
27
  :info => "userpool.info"
27
28
  }
28
29
 
29
- # ---------------------------------------------------------------------
30
+ #######################################################################
30
31
  # Class constructor & Pool Methods
31
- # ---------------------------------------------------------------------
32
-
32
+ #######################################################################
33
+
33
34
  # +client+ a Client object that represents a XML-RPC connection
34
35
  def initialize(client)
35
36
  super('USER_POOL','USER',client)
@@ -40,9 +41,9 @@ module OpenNebula
40
41
  OpenNebula::User.new(element_xml,@client)
41
42
  end
42
43
 
43
- # ---------------------------------------------------------------------
44
+ #######################################################################
44
45
  # XML-RPC Methods for the User Object
45
- # ---------------------------------------------------------------------
46
+ #######################################################################
46
47
 
47
48
  # Retrieves all the Users in the pool.
48
49
  def info()