occi 2.0.0 → 2.0.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,319 +0,0 @@
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
@@ -1,120 +0,0 @@
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 VirtualMachinePool < Pool
22
- #######################################################################
23
- # Constants and Class attribute accessors
24
- #######################################################################
25
-
26
-
27
- VM_POOL_METHODS = {
28
- :info => "vmpool.info"
29
- }
30
-
31
- # Constants for info queries (include/RequestManagerPoolInfoFilter.h)
32
- INFO_NOT_DONE = -1
33
- INFO_ALL_VM = -2
34
-
35
- #######################################################################
36
- # Class constructor & Pool Methods
37
- #######################################################################
38
-
39
-
40
- # +client+ a Client object that represents a XML-RPC connection
41
- # +user_id+ is to refer to a Pool with VirtualMachines from that user
42
- def initialize(client, user_id=0)
43
- super('VM_POOL','VM',client)
44
-
45
- @user_id = user_id
46
- end
47
-
48
- # Default Factory Method for the Pools
49
- def factory(element_xml)
50
- OpenNebula::VirtualMachine.new(element_xml,@client)
51
- end
52
-
53
- #######################################################################
54
- # XML-RPC Methods for the Virtual Network Object
55
- #######################################################################
56
-
57
- # Retrieves all or part of the VirtualMachines in the pool.
58
- # No arguments, returns the not-in-done VMs for the user
59
- # [user_id, start_id, end_id]
60
- # [user_id, start_id, end_id, state]
61
- def info(*args)
62
- case args.size
63
- when 0
64
- info_filter(VM_POOL_METHODS[:info],
65
- @user_id,
66
- -1,
67
- -1,
68
- INFO_NOT_DONE)
69
- when 1
70
- info_filter(VM_POOL_METHODS[:info],
71
- args[0],
72
- -1,
73
- -1,
74
- INFO_NOT_DONE)
75
- when 3
76
- info_filter(VM_POOL_METHODS[:info],
77
- args[0],
78
- args[1],
79
- args[2],
80
- INFO_NOT_DONE)
81
- when 4
82
- info_filter(VM_POOL_METHODS[:info],
83
- args[0],
84
- args[1],
85
- args[2],
86
- args[3])
87
- end
88
- end
89
-
90
- def info_all()
91
- return info_filter(VM_POOL_METHODS[:info],
92
- INFO_ALL,
93
- -1,
94
- -1,
95
- INFO_NOT_DONE)
96
- end
97
-
98
- def info_mine()
99
- return info_filter(VM_POOL_METHODS[:info],
100
- INFO_MINE,
101
- -1,
102
- -1,
103
- INFO_NOT_DONE)
104
- end
105
-
106
- def info_group()
107
- return info_filter(VM_POOL_METHODS[:info],
108
- INFO_GROUP,
109
- -1,
110
- -1,
111
- INFO_NOT_DONE)
112
- end
113
-
114
- private
115
-
116
- def info_filter(xml_method, who, start_id, end_id, state)
117
- return xmlrpc_info(xml_method, who, start_id, end_id, state)
118
- end
119
- end
120
- end
@@ -1,229 +0,0 @@
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 VirtualNetwork < PoolElement
22
- #######################################################################
23
- # Constants and Class Methods
24
- #######################################################################
25
-
26
-
27
- VN_METHODS = {
28
- :info => "vn.info",
29
- :allocate => "vn.allocate",
30
- :publish => "vn.publish",
31
- :delete => "vn.delete",
32
- :addleases => "vn.addleases",
33
- :rmleases => "vn.rmleases",
34
- :chown => "vn.chown",
35
- :chmod => "vn.chmod",
36
- :update => "vn.update",
37
- :hold => "vn.hold",
38
- :release => "vn.release"
39
- }
40
-
41
- VN_TYPES=%w{RANGED FIXED}
42
-
43
- SHORT_VN_TYPES={
44
- "RANGED" => "R",
45
- "FIXED" => "F"
46
- }
47
-
48
- # Creates a VirtualNetwork description with just its identifier
49
- # this method should be used to create plain VirtualNetwork objects.
50
- # +id+ the id of the network
51
- #
52
- # Example:
53
- # vnet = VirtualNetwork.new(VirtualNetwork.build_xml(3),rpc_client)
54
- #
55
- def VirtualNetwork.build_xml(pe_id=nil)
56
- if pe_id
57
- vn_xml = "<VNET><ID>#{pe_id}</ID></VNET>"
58
- else
59
- vn_xml = "<VNET></VNET>"
60
- end
61
-
62
- XMLElement.build_xml(vn_xml, 'VNET')
63
- end
64
-
65
- # Class constructor
66
- def initialize(xml, client)
67
- super(xml,client)
68
- end
69
-
70
- #######################################################################
71
- # XML-RPC Methods for the Virtual Network Object
72
- #######################################################################
73
-
74
- # Retrieves the information of the given VirtualNetwork.
75
- def info()
76
- super(VN_METHODS[:info], 'VNET')
77
- end
78
-
79
- # Allocates a new VirtualNetwork in OpenNebula
80
- #
81
- # +description+ A string containing the template of the VirtualNetwork.
82
- def allocate(description)
83
- super(VN_METHODS[:allocate],description)
84
- end
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
-
93
- # Publishes the VirtualNetwork, to be used by other users
94
- def publish
95
- set_publish(true)
96
- end
97
-
98
- # Unplubishes the VirtualNetwork
99
- def unpublish
100
- set_publish(false)
101
- end
102
-
103
- # Deletes the VirtualNetwork
104
- def delete()
105
- super(VN_METHODS[:delete])
106
- end
107
-
108
- # Adds a lease to the VirtualNetwork
109
- def addleases(ip, mac = nil)
110
- return Error.new('ID not defined') if !@pe_id
111
-
112
- lease_template = "LEASES = [ IP = #{ip}"
113
- lease_template << ", MAC = #{mac}" if mac
114
- lease_template << " ]"
115
-
116
- rc = @client.call(VN_METHODS[:addleases], @pe_id, lease_template)
117
- rc = nil if !OpenNebula.is_error?(rc)
118
-
119
- return rc
120
- end
121
-
122
- # Removes a lease from the VirtualNetwork
123
- def rmleases(ip)
124
- return Error.new('ID not defined') if !@pe_id
125
-
126
- lease_template = "LEASES = [ IP = #{ip} ]"
127
-
128
- rc = @client.call(VN_METHODS[:rmleases], @pe_id, lease_template)
129
- rc = nil if !OpenNebula.is_error?(rc)
130
-
131
- return rc
132
- end
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
-
160
- # Changes the owner/group
161
- # uid:: _Integer_ the new owner id. Set to -1 to leave the current one
162
- # gid:: _Integer_ the new group id. Set to -1 to leave the current one
163
- # [return] nil in case of success or an Error object
164
- def chown(uid, gid)
165
- super(VN_METHODS[:chown], uid, gid)
166
- end
167
-
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
- #######################################################################
189
- # Helpers to get VirtualNetwork information
190
- #######################################################################
191
-
192
- # Returns the group identifier
193
- # [return] _Integer_ the element's group ID
194
- def gid
195
- self['GID'].to_i
196
- end
197
-
198
- # Returns the type of the Virtual Network (numeric value)
199
- def type
200
- self['TYPE'].to_i
201
- end
202
-
203
- # Returns the type of the Virtual Network (string value)
204
- def type_str
205
- VN_TYPES[type]
206
- end
207
-
208
- # Returns the state of the Virtual Network (string value)
209
- def short_type_str
210
- SHORT_VN_TYPES[type_str]
211
- end
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
-
221
- private
222
- def set_publish(published)
223
- group_u = published ? 1 : 0
224
-
225
- chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
226
- end
227
-
228
- end
229
- end