Class: StackMate::CloudStackVirtualMachine
Constant Summary
Constants included
from Resolver
Resolver::INTEXP, Resolver::STRINGEXP, Resolver::UUIDEXP
Instance Attribute Summary
#name
Instance Method Summary
collapse
Methods included from Resolver
#get_named_tag, #get_resolved, #resolve_tags, #resolve_to_deviceid, #validate_param
Methods included from Intrinsic
#fn_base64, #fn_getatt, #fn_join, #fn_lookup, #fn_map, #fn_ref, #fn_select, #intrinsic
Methods included from Logging
configure_logger_for, #logger, logger_for
#initialize
Instance Method Details
#create ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 9
def create
logger.debug("Creating resource #{@name}")
workitem[@name] = {}
name_cs = workitem['StackName'] + '-' + @name
args={}
begin
args['templateid'] = get_templateid
args['serviceofferingid'] = get_serviceofferingid
args['zoneid'] = get_zoneid
args['securitygroupnames'] = get_securitygroupnames if @props.has_key?('securitygroupnames')
args['affinitygroupids'] = get_affinitygroupids if @props.has_key?('affinitygroupids')
args['startvm'] = get_startvm if @props.has_key?('startvm')
args['displayvm'] = get_displayvm if @props.has_key?('displayvm')
args['diskofferingid'] = get_diskofferingid if @props.has_key?('diskofferingid')
args['hypervisor'] = get_hypervisor if @props.has_key?('hypervisor')
args['keyboard'] = get_keyboard if @props.has_key?('keyboard')
args['name'] = workitem['StackName'] +'-' + get_name if @props.has_key?('name')
if @props.has_key?('iptonetworklist')
ipnetworklist = get_iptonetworklist
list_params = ipnetworklist.split("&")
list_params.each do |p|
fields = p.split("=")
args[fields[0]] = fields[1]
end
end
args['networkids'] = get_networkids if @props.has_key?('networkids')
args['account'] = get_account if @props.has_key?('account')
args['userdata'] = get_userdata if @props.has_key?('userdata')
args['keypair'] = get_keypair if @props.has_key?('keypair')
args['projectid'] = get_projectid if @props.has_key?('projectid')
args['ipaddress'] = get_ipaddress if @props.has_key?('ipaddress')
args['displayname'] = get_displayname if @props.has_key?('displayname')
args['ip6address'] = get_ip6address if @props.has_key?('ip6address')
args['affinitygroupnames'] = get_affinitygroupnames if @props.has_key?('affinitygroupnames')
args['domainid'] = get_domainid if @props.has_key?('domainid')
args['size'] = get_size if @props.has_key?('size')
args['hostid'] = get_hostid if @props.has_key?('hostid')
args['securitygroupids'] = get_securitygroupids if @props.has_key?('securitygroupids')
args['group'] = get_group if @props.has_key?('group')
logger.info("Creating resource #{@name} with following arguments")
p args
result_obj = make_async_request('deployVirtualMachine',args)
resource_obj = result_obj['VirtualMachine'.downcase]
resource_obj.each_key do |k|
val = resource_obj[k]
if('id'.eql?(k))
k = 'physical_id'
end
workitem[@name][k] = val
end
workitem[@name][:PrivateIp] = resource_obj['nic'][0]['ipaddress']
set_tags(@props['tags'],workitem[@name]['physical_id'],"UserVm") if @props.has_key?('tags')
workitem['ResolvedNames'][@name] = name_cs
workitem['IdMap'][workitem[@name]['physical_id']] = @name
rescue NoMethodError => nme
logger.error("Create request failed for resource #{@name}. Cleaning up the stack")
raise nme
rescue Exception => e
logger.error(e.message)
raise e
end
end
|
#delete ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 79
def delete
logger.debug("Deleting resource #{@name}")
begin
physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
if(!physical_id.nil?)
args = {'id' => physical_id
}
result_obj = make_async_request('destroyVirtualMachine',args)
if (!(result_obj['error'] == true))
logger.info("Successfully deleted resource #{@name}")
else
logger.info("CloudStack error while deleting resource #{@name}")
end
else
logger.info("Resource not created in CloudStack. Skipping delete...")
end
rescue Exception => e
logger.error("Unable to delete resorce #{@name}")
end
end
|
#get_account ⇒ Object
231
232
233
234
235
236
237
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 231
def get_account
resolved_account = get_resolved(@props['account'],workitem)
if resolved_account.nil? || !validate_param(resolved_account,"string")
raise "Malformed optional parameter account for resource #{@name}"
end
resolved_account
end
|
#get_affinitygroupids ⇒ Object
150
151
152
153
154
155
156
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 150
def get_affinitygroupids
resolved_affinitygroupids = get_resolved(@props['affinitygroupids'],workitem)
if resolved_affinitygroupids.nil? || !validate_param(resolved_affinitygroupids,"list")
raise "Malformed optional parameter affinitygroupids for resource #{@name}"
end
resolved_affinitygroupids
end
|
#get_affinitygroupnames ⇒ Object
294
295
296
297
298
299
300
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 294
def get_affinitygroupnames
resolved_affinitygroupnames = get_resolved(@props['affinitygroupnames'],workitem)
if resolved_affinitygroupnames.nil? || !validate_param(resolved_affinitygroupnames,"list")
raise "Malformed optional parameter affinitygroupnames for resource #{@name}"
end
resolved_affinitygroupnames
end
|
#get_diskofferingid ⇒ Object
177
178
179
180
181
182
183
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 177
def get_diskofferingid
resolved_diskofferingid = get_resolved(@props['diskofferingid'],workitem)
if resolved_diskofferingid.nil? || !validate_param(resolved_diskofferingid,"uuid")
raise "Malformed optional parameter diskofferingid for resource #{@name}"
end
resolved_diskofferingid
end
|
#get_displayname ⇒ Object
276
277
278
279
280
281
282
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 276
def get_displayname
resolved_displayname = get_resolved(@props['displayname'],workitem)
if resolved_displayname.nil? || !validate_param(resolved_displayname,"string")
raise "Malformed optional parameter displayname for resource #{@name}"
end
resolved_displayname
end
|
#get_displayvm ⇒ Object
168
169
170
171
172
173
174
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 168
def get_displayvm
resolved_displayvm = get_resolved(@props['displayvm'],workitem)
if resolved_displayvm.nil? || !validate_param(resolved_displayvm,"boolean")
raise "Malformed optional parameter displayvm for resource #{@name}"
end
resolved_displayvm
end
|
#get_domainid ⇒ Object
303
304
305
306
307
308
309
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 303
def get_domainid
resolved_domainid = get_resolved(@props['domainid'],workitem)
if resolved_domainid.nil? || !validate_param(resolved_domainid,"uuid")
raise "Malformed optional parameter domainid for resource #{@name}"
end
resolved_domainid
end
|
#get_group ⇒ Object
339
340
341
342
343
344
345
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 339
def get_group
resolved_group = get_resolved(@props['group'],workitem)
if resolved_group.nil? || !validate_param(resolved_group,"string")
raise "Malformed optional parameter group for resource #{@name}"
end
resolved_group
end
|
#get_hostid ⇒ Object
321
322
323
324
325
326
327
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 321
def get_hostid
resolved_hostid = get_resolved(@props['hostid'],workitem)
if resolved_hostid.nil? || !validate_param(resolved_hostid,"uuid")
raise "Malformed optional parameter hostid for resource #{@name}"
end
resolved_hostid
end
|
#get_hypervisor ⇒ Object
186
187
188
189
190
191
192
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 186
def get_hypervisor
resolved_hypervisor = get_resolved(@props['hypervisor'],workitem)
if resolved_hypervisor.nil? || !validate_param(resolved_hypervisor,"string")
raise "Malformed optional parameter hypervisor for resource #{@name}"
end
resolved_hypervisor
end
|
#get_ip6address ⇒ Object
285
286
287
288
289
290
291
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 285
def get_ip6address
resolved_ip6address = get_resolved(@props['ip6address'],workitem)
if resolved_ip6address.nil? || !validate_param(resolved_ip6address,"string")
raise "Malformed optional parameter ip6address for resource #{@name}"
end
resolved_ip6address
end
|
#get_ipaddress ⇒ Object
267
268
269
270
271
272
273
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 267
def get_ipaddress
resolved_ipaddress = get_resolved(@props['ipaddress'],workitem)
if resolved_ipaddress.nil? || !validate_param(resolved_ipaddress,"string")
raise "Malformed optional parameter ipaddress for resource #{@name}"
end
resolved_ipaddress
end
|
#get_iptonetworklist ⇒ Object
213
214
215
216
217
218
219
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 213
def get_iptonetworklist
resolved_iptonetworklist = get_resolved(@props['iptonetworklist'],workitem)
if resolved_iptonetworklist.nil? || !validate_param(resolved_iptonetworklist,"map")
raise "Malformed optional parameter iptonetworklist for resource #{@name}"
end
resolved_iptonetworklist
end
|
#get_keyboard ⇒ Object
195
196
197
198
199
200
201
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 195
def get_keyboard
resolved_keyboard = get_resolved(@props['keyboard'],workitem)
if resolved_keyboard.nil? || !validate_param(resolved_keyboard,"string")
raise "Malformed optional parameter keyboard for resource #{@name}"
end
resolved_keyboard
end
|
#get_keypair ⇒ Object
249
250
251
252
253
254
255
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 249
def get_keypair
resolved_keypair = get_resolved(@props['keypair'],workitem)
if resolved_keypair.nil? || !validate_param(resolved_keypair,"string")
raise "Malformed optional parameter keypair for resource #{@name}"
end
resolved_keypair
end
|
#get_name ⇒ Object
204
205
206
207
208
209
210
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 204
def get_name
resolved_name = get_resolved(@props['name'],workitem)
if resolved_name.nil? || !validate_param(resolved_name,"string")
raise "Malformed optional parameter name for resource #{@name}"
end
resolved_name
end
|
#get_networkids ⇒ Object
222
223
224
225
226
227
228
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 222
def get_networkids
resolved_networkids = get_resolved(@props['networkids'],workitem)
if resolved_networkids.nil? || !validate_param(resolved_networkids,"list")
raise "Malformed optional parameter networkids for resource #{@name}"
end
resolved_networkids
end
|
#get_projectid ⇒ Object
258
259
260
261
262
263
264
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 258
def get_projectid
resolved_projectid = get_resolved(@props['projectid'],workitem)
if resolved_projectid.nil? || !validate_param(resolved_projectid,"uuid")
raise "Malformed optional parameter projectid for resource #{@name}"
end
resolved_projectid
end
|
#get_securitygroupids ⇒ Object
330
331
332
333
334
335
336
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 330
def get_securitygroupids
resolved_securitygroupids = get_resolved(@props['securitygroupids'],workitem)
if resolved_securitygroupids.nil? || !validate_param(resolved_securitygroupids,"list")
raise "Malformed optional parameter securitygroupids for resource #{@name}"
end
resolved_securitygroupids
end
|
#get_securitygroupnames ⇒ Object
141
142
143
144
145
146
147
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 141
def get_securitygroupnames
resolved_securitygroupnames = get_resolved(@props['securitygroupnames'],workitem)
if resolved_securitygroupnames.nil? || !validate_param(resolved_securitygroupnames,"list")
raise "Malformed optional parameter securitygroupnames for resource #{@name}"
end
resolved_securitygroupnames
end
|
#get_serviceofferingid ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 123
def get_serviceofferingid
resolved_serviceofferingid = get_resolved(@props["serviceofferingid"],workitem)
if resolved_serviceofferingid.nil? || !validate_param(resolved_serviceofferingid,"uuid")
raise "Missing mandatory parameter serviceofferingid for resource #{@name}"
end
resolved_serviceofferingid
end
|
#get_size ⇒ Object
312
313
314
315
316
317
318
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 312
def get_size
resolved_size = get_resolved(@props['size'],workitem)
if resolved_size.nil? || !validate_param(resolved_size,"long")
raise "Malformed optional parameter size for resource #{@name}"
end
resolved_size
end
|
#get_startvm ⇒ Object
159
160
161
162
163
164
165
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 159
def get_startvm
resolved_startvm = get_resolved(@props['startvm'],workitem)
if resolved_startvm.nil? || !validate_param(resolved_startvm,"boolean")
raise "Malformed optional parameter startvm for resource #{@name}"
end
resolved_startvm
end
|
#get_templateid ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 114
def get_templateid
resolved_templateid = get_resolved(@props["templateid"],workitem)
if resolved_templateid.nil? || !validate_param(resolved_templateid,"uuid")
raise "Missing mandatory parameter templateid for resource #{@name}"
end
resolved_templateid
end
|
#get_userdata ⇒ Object
240
241
242
243
244
245
246
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 240
def get_userdata
resolved_userdata = get_resolved(@props['userdata'],workitem)
if resolved_userdata.nil? || !validate_param(resolved_userdata,"string")
raise "Malformed optional parameter userdata for resource #{@name}"
end
resolved_userdata
end
|
#get_zoneid ⇒ Object
132
133
134
135
136
137
138
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 132
def get_zoneid
resolved_zoneid = get_resolved(@props["zoneid"],workitem)
if resolved_zoneid.nil? || !validate_param(resolved_zoneid,"uuid")
raise "Missing mandatory parameter zoneid for resource #{@name}"
end
resolved_zoneid
end
|
#on_workitem ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/stackmate/participants/cloudstack_virtualmachine.rb', line 100
def on_workitem
@name = workitem.participant_name
@props = workitem['Resources'][@name]['Properties']
@props.downcase_key
@resolved_names = workitem['ResolvedNames']
if workitem['params']['operation'] == 'create'
create
else
delete
end
reply
end
|