occi 1.2.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/.gitignore +9 -0
  2. data/.project +32 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +8 -0
  5. data/.yardopts +1 -0
  6. data/AUTHORS +8 -0
  7. data/Gemfile +35 -14
  8. data/Gemfile.lock +89 -32
  9. data/LICENSE +13 -4
  10. data/README.md +70 -21
  11. data/Rakefile +25 -21
  12. data/lib/OpenNebula/Acl.rb +256 -0
  13. data/lib/OpenNebula/AclPool.rb +53 -0
  14. data/lib/OpenNebula/Group.rb +147 -0
  15. data/lib/OpenNebula/GroupPool.rb +54 -0
  16. data/lib/OpenNebula/Host.rb +143 -0
  17. data/lib/OpenNebula/HostPool.rb +55 -0
  18. data/lib/OpenNebula/Image.rb +256 -0
  19. data/lib/OpenNebula/ImagePool.rb +74 -0
  20. data/lib/OpenNebula/OpenNebula.rb +137 -0
  21. data/lib/OpenNebula/Pool.rb +285 -0
  22. data/lib/OpenNebula/Template.rb +173 -0
  23. data/lib/OpenNebula/TemplatePool.rb +74 -0
  24. data/lib/OpenNebula/User.rb +157 -0
  25. data/lib/OpenNebula/UserPool.rb +53 -0
  26. data/lib/OpenNebula/VirtualMachine.rb +319 -0
  27. data/lib/OpenNebula/VirtualMachinePool.rb +120 -0
  28. data/lib/OpenNebula/VirtualNetwork.rb +229 -0
  29. data/lib/OpenNebula/VirtualNetworkPool.rb +74 -0
  30. data/lib/OpenNebula/XMLUtils.rb +337 -0
  31. data/lib/occi/antlr/.gitignore +18 -0
  32. data/lib/occi/antlr/OCCI.g +164 -0
  33. data/lib/occi/antlr/OCCI.tokens +75 -0
  34. data/lib/occi/antlr/OCCILexer.rb +1532 -0
  35. data/lib/occi/antlr/OCCIParser.rb +2472 -0
  36. data/lib/occi/antlr/README.md +2 -0
  37. data/lib/occi/backend/dummy.rb +232 -0
  38. data/lib/occi/backend/ec2/Compute.rb +310 -0
  39. data/lib/occi/backend/ec2/compute.rb +310 -0
  40. data/lib/occi/backend/ec2/ec2.rb +215 -0
  41. data/lib/occi/backend/manager.rb +131 -0
  42. data/lib/occi/backend/opennebula/compute.rb +360 -0
  43. data/lib/occi/backend/opennebula/network.rb +143 -0
  44. data/lib/occi/backend/opennebula/opennebula.rb +188 -0
  45. data/lib/occi/backend/opennebula/storage.rb +175 -0
  46. data/lib/occi/configuration.rb +118 -0
  47. data/lib/occi/core/action.rb +29 -0
  48. data/lib/occi/core/attribute_properties.rb +54 -0
  49. data/lib/occi/core/attributes.rb +40 -0
  50. data/lib/occi/core/category.rb +62 -0
  51. data/lib/occi/core/collection.rb +27 -0
  52. data/lib/occi/core/entity.rb +135 -0
  53. data/lib/occi/core/kind.rb +55 -0
  54. data/lib/occi/core/link.rb +88 -0
  55. data/lib/occi/core/mixin.rb +43 -0
  56. data/lib/occi/core/resource.rb +73 -0
  57. data/lib/occi/exceptions.rb +59 -0
  58. data/lib/occi/extensions/monitoring/cpu.rb +51 -0
  59. data/lib/occi/extensions/monitoring/memory.rb +49 -0
  60. data/lib/occi/extensions/monitoring/metric.rb +54 -0
  61. data/lib/occi/extensions/monitoring/netrx.rb +49 -0
  62. data/lib/occi/extensions/monitoring/nettx.rb +55 -0
  63. data/lib/occi/extensions/one/VNC.rb +58 -0
  64. data/lib/occi/extensions/one/vnc.rb +58 -0
  65. data/lib/occi/log.rb +47 -0
  66. data/lib/occi/parse.rb +164 -0
  67. data/lib/occi/registry.rb +87 -0
  68. data/lib/occi/server.rb +594 -0
  69. data/lib/occi/version.rb +3 -0
  70. data/occi.gemspec +18 -96
  71. data/spec/occi/antlr/parser_spec.rb +82 -0
  72. data/spec/spec_helper.rb +6 -0
  73. metadata +100 -208
  74. data/.autotest +0 -21
  75. data/.rvmrc +0 -1
  76. data/VERSION +0 -1
  77. data/lib/occi.rb +0 -1
  78. data/lib/occi/client.rb +0 -36
  79. data/lib/occi/compute.rb +0 -4
  80. data/lib/occi/network.rb +0 -4
  81. data/lib/occi/resource.rb +0 -59
  82. data/lib/occi/storage.rb +0 -7
  83. data/test/fixtures/cassettes/compute_all.yml +0 -28
  84. data/test/fixtures/cassettes/compute_create.yml +0 -45
  85. data/test/fixtures/cassettes/compute_destroy.yml +0 -22
  86. data/test/fixtures/cassettes/compute_find.yml +0 -28
  87. data/test/fixtures/cassettes/compute_update.yml +0 -35
  88. data/test/fixtures/cassettes/network_all.yml +0 -28
  89. data/test/fixtures/cassettes/network_create.yml +0 -37
  90. data/test/fixtures/cassettes/network_destroy.yml +0 -22
  91. data/test/fixtures/cassettes/network_find.yml +0 -28
  92. data/test/fixtures/cassettes/storage_all.yml +0 -28
  93. data/test/fixtures/cassettes/storage_create.yml +0 -50
  94. data/test/fixtures/cassettes/storage_destroy.yml +0 -22
  95. data/test/fixtures/cassettes/storage_find.yml +0 -28
  96. data/test/lib/occi/compute_test.rb +0 -91
  97. data/test/lib/occi/network_test.rb +0 -57
  98. data/test/lib/occi/storage_test.rb +0 -67
  99. data/test/test_helper.rb +0 -48
@@ -0,0 +1,74 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ #--------------------------------------------------------------------------- #
16
+
17
+
18
+ require 'OpenNebula/Pool'
19
+
20
+ module OpenNebula
21
+ class TemplatePool < Pool
22
+ #######################################################################
23
+ # Constants and Class attribute accessors
24
+ #######################################################################
25
+
26
+
27
+ TEMPLATE_POOL_METHODS = {
28
+ :info => "templatepool.info"
29
+ }
30
+
31
+ #######################################################################
32
+ # Class constructor & Pool Methods
33
+ #######################################################################
34
+
35
+ # +client+ a Client object that represents an XML-RPC connection
36
+ # +user_id+ used to refer to a Pool with Templates from that user
37
+ def initialize(client, user_id=-1)
38
+ super('VMTEMPLATE_POOL','VMTEMPLATE',client)
39
+
40
+ @user_id = user_id
41
+ end
42
+
43
+ # Factory method to create Template objects
44
+ def factory(element_xml)
45
+ OpenNebula::Template.new(element_xml,@client)
46
+ end
47
+
48
+ #######################################################################
49
+ # XML-RPC Methods for the Template Object
50
+ #######################################################################
51
+
52
+ # Retrieves all or part of the VirtualMachines in the pool.
53
+ def info(*args)
54
+ case args.size
55
+ when 0
56
+ info_filter(TEMPLATE_POOL_METHODS[:info],@user_id,-1,-1)
57
+ when 3
58
+ info_filter(TEMPLATE_POOL_METHODS[:info],args[0],args[1],args[2])
59
+ end
60
+ end
61
+
62
+ def info_all()
63
+ return super(TEMPLATE_POOL_METHODS[:info])
64
+ end
65
+
66
+ def info_mine()
67
+ return super(TEMPLATE_POOL_METHODS[:info])
68
+ end
69
+
70
+ def info_group()
71
+ return super(TEMPLATE_POOL_METHODS[:info])
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,157 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ #--------------------------------------------------------------------------- #
16
+
17
+
18
+ require 'OpenNebula/Pool'
19
+
20
+ module OpenNebula
21
+ class User < PoolElement
22
+ #######################################################################
23
+ # Constants and Class Methods
24
+ #######################################################################
25
+
26
+ USER_METHODS = {
27
+ :info => "user.info",
28
+ :allocate => "user.allocate",
29
+ :delete => "user.delete",
30
+ :passwd => "user.passwd",
31
+ :chgrp => "user.chgrp",
32
+ :update => "user.update",
33
+ :chauth => "user.chauth"
34
+ }
35
+
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"
52
+
53
+ # Creates a User description with just its identifier
54
+ # this method should be used to create plain User objects.
55
+ # +id+ the id of the user
56
+ #
57
+ # Example:
58
+ # user = User.new(User.build_xml(3),rpc_client)
59
+ #
60
+ def User.build_xml(pe_id=nil)
61
+ if pe_id
62
+ user_xml = "<USER><ID>#{pe_id}</ID></USER>"
63
+ else
64
+ user_xml = "<USER></USER>"
65
+ end
66
+
67
+ XMLElement.build_xml(user_xml, 'USER')
68
+ end
69
+
70
+ # Class constructor
71
+ def initialize(xml, client)
72
+ super(xml,client)
73
+
74
+ @client = client
75
+ end
76
+
77
+ #######################################################################
78
+ # XML-RPC Methods for the User Object
79
+ #######################################################################
80
+
81
+ # Retrieves the information of the given User.
82
+ def info()
83
+ super(USER_METHODS[:info], 'USER')
84
+ end
85
+
86
+ # Allocates a new User in OpenNebula
87
+ #
88
+ # +username+ Name of the new user.
89
+ #
90
+ # +password+ Password for the new user
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)
100
+ end
101
+
102
+ # Deletes the User
103
+ def delete()
104
+ super(USER_METHODS[:delete])
105
+ end
106
+
107
+ # Changes the password of the given User
108
+ #
109
+ # +password+ String containing the new password
110
+ def passwd(password)
111
+ return Error.new('ID not defined') if !@pe_id
112
+
113
+ rc = @client.call(USER_METHODS[:passwd], @pe_id, password)
114
+ rc = nil if !OpenNebula.is_error?(rc)
115
+
116
+ return rc
117
+ end
118
+
119
+ # Changes the main group
120
+ # gid:: _Integer_ the new group id. Set to -1 to leave the current one
121
+ # [return] nil in case of success or an Error object
122
+ def chgrp(gid)
123
+ return Error.new('ID not defined') if !@pe_id
124
+
125
+ rc = @client.call(USER_METHODS[:chgrp],@pe_id, gid)
126
+ rc = nil if !OpenNebula.is_error?(rc)
127
+
128
+ return rc
129
+ end
130
+
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
+ #######################################################################
148
+ # Helpers to get User information
149
+ #######################################################################
150
+
151
+ # Returns the group identifier
152
+ # [return] _Integer_ the element's group ID
153
+ def gid
154
+ self['GID'].to_i
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,53 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ #--------------------------------------------------------------------------- #
16
+
17
+
18
+ require 'OpenNebula/Pool'
19
+
20
+ module OpenNebula
21
+ class UserPool < Pool
22
+ #######################################################################
23
+ # Constants and Class attribute accessors
24
+ #######################################################################
25
+
26
+ USER_POOL_METHODS = {
27
+ :info => "userpool.info"
28
+ }
29
+
30
+ #######################################################################
31
+ # Class constructor & Pool Methods
32
+ #######################################################################
33
+
34
+ # +client+ a Client object that represents a XML-RPC connection
35
+ def initialize(client)
36
+ super('USER_POOL','USER',client)
37
+ end
38
+
39
+ # Factory method to create User objects
40
+ def factory(element_xml)
41
+ OpenNebula::User.new(element_xml,@client)
42
+ end
43
+
44
+ #######################################################################
45
+ # XML-RPC Methods for the User Object
46
+ #######################################################################
47
+
48
+ # Retrieves all the Users in the pool.
49
+ def info()
50
+ super(USER_POOL_METHODS[:info])
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,319 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ #--------------------------------------------------------------------------- #
16
+
17
+
18
+ require 'OpenNebula/Pool'
19
+
20
+ module OpenNebula
21
+ class VirtualMachine < PoolElement
22
+ #######################################################################
23
+ # Constants and Class Methods
24
+ #######################################################################
25
+
26
+
27
+ VM_METHODS = {
28
+ :info => "vm.info",
29
+ :allocate => "vm.allocate",
30
+ :action => "vm.action",
31
+ :migrate => "vm.migrate",
32
+ :deploy => "vm.deploy",
33
+ :savedisk => "vm.savedisk",
34
+ :chown => "vm.chown",
35
+ :chmod => "vm.chmod",
36
+ }
37
+
38
+ VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED}
39
+
40
+ LCM_STATE=%w{LCM_INIT PROLOG BOOT RUNNING MIGRATE SAVE_STOP SAVE_SUSPEND
41
+ SAVE_MIGRATE PROLOG_MIGRATE PROLOG_RESUME EPILOG_STOP EPILOG
42
+ SHUTDOWN CANCEL FAILURE CLEANUP UNKNOWN}
43
+
44
+ SHORT_VM_STATES={
45
+ "INIT" => "init",
46
+ "PENDING" => "pend",
47
+ "HOLD" => "hold",
48
+ "ACTIVE" => "actv",
49
+ "STOPPED" => "stop",
50
+ "SUSPENDED" => "susp",
51
+ "DONE" => "done",
52
+ "FAILED" => "fail"
53
+ }
54
+
55
+ SHORT_LCM_STATES={
56
+ "PROLOG" => "prol",
57
+ "BOOT" => "boot",
58
+ "RUNNING" => "runn",
59
+ "MIGRATE" => "migr",
60
+ "SAVE_STOP" => "save",
61
+ "SAVE_SUSPEND" => "save",
62
+ "SAVE_MIGRATE" => "save",
63
+ "PROLOG_MIGRATE"=> "migr",
64
+ "PROLOG_RESUME" => "prol",
65
+ "EPILOG_STOP" => "epil",
66
+ "EPILOG" => "epil",
67
+ "SHUTDOWN" => "shut",
68
+ "CANCEL" => "shut",
69
+ "FAILURE" => "fail",
70
+ "CLEANUP" => "clea",
71
+ "UNKNOWN" => "unkn"
72
+ }
73
+
74
+ MIGRATE_REASON=%w{NONE ERROR STOP_RESUME USER CANCEL}
75
+
76
+ SHORT_MIGRATE_REASON={
77
+ "NONE" => "none",
78
+ "ERROR" => "erro",
79
+ "STOP_RESUME" => "stop",
80
+ "USER" => "user",
81
+ "CANCEL" => "canc"
82
+ }
83
+
84
+ # Creates a VirtualMachine description with just its identifier
85
+ # this method should be used to create plain VirtualMachine objects.
86
+ # +id+ the id of the vm
87
+ #
88
+ # Example:
89
+ # vnet = VirtualMachine.new(VirtualMachine.build_xml(3),rpc_client)
90
+ #
91
+ def VirtualMachine.build_xml(pe_id=nil)
92
+ if pe_id
93
+ vm_xml = "<VM><ID>#{pe_id}</ID></VM>"
94
+ else
95
+ vm_xml = "<VM></VM>"
96
+ end
97
+
98
+ XMLElement.build_xml(vm_xml, 'VM')
99
+ end
100
+
101
+ def VirtualMachine.get_reason(reason)
102
+ reason=MIGRATE_REASON[reason.to_i]
103
+ reason_str=SHORT_MIGRATE_REASON[reason]
104
+
105
+ reason_str
106
+ end
107
+
108
+ # Class constructor
109
+ def initialize(xml, client)
110
+ super(xml,client)
111
+ end
112
+
113
+ #######################################################################
114
+ # XML-RPC Methods for the Virtual Machine Object
115
+ #######################################################################
116
+
117
+ # Retrieves the information of the given VirtualMachine.
118
+ def info()
119
+ super(VM_METHODS[:info], 'VM')
120
+ end
121
+
122
+ # Allocates a new VirtualMachine in OpenNebula
123
+ #
124
+ # +description+ A string containing the template of the VirtualMachine.
125
+ def allocate(description)
126
+ super(VM_METHODS[:allocate],description)
127
+ end
128
+
129
+ # Initiates the instance of the VM on the target host.
130
+ #
131
+ # +host_id+ The host id (hid) of the target host where
132
+ # the VM will be instantiated.
133
+ def deploy(host_id)
134
+ return Error.new('ID not defined') if !@pe_id
135
+
136
+ rc = @client.call(VM_METHODS[:deploy], @pe_id, host_id.to_i)
137
+ rc = nil if !OpenNebula.is_error?(rc)
138
+
139
+ return rc
140
+ end
141
+
142
+ # Shutdowns an already deployed VM
143
+ def shutdown
144
+ action('shutdown')
145
+ end
146
+
147
+ # Shutdowns an already deployed VM
148
+ def reboot
149
+ action('reboot')
150
+ end
151
+
152
+ # Cancels a running VM
153
+ def cancel
154
+ action('cancel')
155
+ end
156
+
157
+ # Sets a VM to hold state, scheduler will not deploy it
158
+ def hold
159
+ action('hold')
160
+ end
161
+
162
+ # Releases a VM from hold state
163
+ def release
164
+ action('release')
165
+ end
166
+
167
+ # Stops a running VM
168
+ def stop
169
+ action('stop')
170
+ end
171
+
172
+ # Saves a running VM
173
+ def suspend
174
+ action('suspend')
175
+ end
176
+
177
+ # Resumes the execution of a saved VM
178
+ def resume
179
+ action('resume')
180
+ end
181
+
182
+ # Deletes a VM from the pool
183
+ def finalize
184
+ action('finalize')
185
+ end
186
+
187
+ # Forces a re-deployment of a VM in UNKNOWN or BOOT state
188
+ def restart
189
+ action('restart')
190
+ end
191
+
192
+ # Resubmits a VM to PENDING state
193
+ def resubmit
194
+ action('resubmit')
195
+ end
196
+
197
+ # Saves a running VM and starts it again in the specified host
198
+ def migrate(host_id)
199
+ return Error.new('ID not defined') if !@pe_id
200
+
201
+ rc = @client.call(VM_METHODS[:migrate], @pe_id, host_id.to_i, false)
202
+ rc = nil if !OpenNebula.is_error?(rc)
203
+
204
+ return rc
205
+ end
206
+
207
+ # Migrates a running VM to another host without downtime
208
+ def live_migrate(host_id)
209
+ return Error.new('ID not defined') if !@pe_id
210
+
211
+ rc = @client.call(VM_METHODS[:migrate], @pe_id, host_id.to_i, true)
212
+ rc = nil if !OpenNebula.is_error?(rc)
213
+
214
+ return rc
215
+ end
216
+
217
+ # Set the specified vm's disk to be saved in a new image
218
+ # when the VirtualMachine shutdowns
219
+ #
220
+ # @param disk_id [Integer] ID of the disk to be saved
221
+ # @param image_name [String] Name for the new image where the
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
225
+ #
226
+ # @return [Integer, OpenNebula::Error] the new Image ID in case of
227
+ # success, error otherwise
228
+ def save_as(disk_id, image_name, image_type="")
229
+ return Error.new('ID not defined') if !@pe_id
230
+
231
+ rc = @client.call(VM_METHODS[:savedisk],
232
+ @pe_id,
233
+ disk_id,
234
+ image_name,
235
+ image_type)
236
+
237
+ return rc
238
+ end
239
+
240
+ # Changes the owner/group
241
+ # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
242
+ # gid:: _Integer_ the new group id. Set to -1 to leave the current one
243
+ # [return] nil in case of success or an Error object
244
+ def chown(uid, gid)
245
+ super(VM_METHODS[:chown], uid, gid)
246
+ end
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
+
268
+ #######################################################################
269
+ # Helpers to get VirtualMachine information
270
+ #######################################################################
271
+
272
+ # Returns the VM state of the VirtualMachine (numeric value)
273
+ def state
274
+ self['STATE'].to_i
275
+ end
276
+
277
+ # Returns the VM state of the VirtualMachine (string value)
278
+ def state_str
279
+ VM_STATE[state]
280
+ end
281
+
282
+ # Returns the LCM state of the VirtualMachine (numeric value)
283
+ def lcm_state
284
+ self['LCM_STATE'].to_i
285
+ end
286
+
287
+ # Returns the LCM state of the VirtualMachine (string value)
288
+ def lcm_state_str
289
+ LCM_STATE[lcm_state]
290
+ end
291
+
292
+ # Returns the short status string for the VirtualMachine
293
+ def status
294
+ short_state_str=SHORT_VM_STATES[state_str]
295
+
296
+ if short_state_str=="actv"
297
+ short_state_str=SHORT_LCM_STATES[lcm_state_str]
298
+ end
299
+
300
+ short_state_str
301
+ end
302
+
303
+ # Returns the group identifier
304
+ # [return] _Integer_ the element's group ID
305
+ def gid
306
+ self['GID'].to_i
307
+ end
308
+
309
+ private
310
+ def action(name)
311
+ return Error.new('ID not defined') if !@pe_id
312
+
313
+ rc = @client.call(VM_METHODS[:action], name, @pe_id)
314
+ rc = nil if !OpenNebula.is_error?(rc)
315
+
316
+ return rc
317
+ end
318
+ end
319
+ end