stackmate 0.0.4 → 0.1.0
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.
- data/CHANGELOG.txt +7 -0
- data/README.md +25 -8
- data/bin/stackmate.rb +57 -53
- data/lib/stackmate/aws_attribs.rb +31 -31
- data/lib/stackmate/classmap.rb +33 -25
- data/lib/stackmate/client.rb +80 -0
- data/lib/stackmate/intrinsic_functions.rb +94 -38
- data/lib/stackmate/logging.rb +19 -19
- data/lib/stackmate/participants/cloudstack.rb +250 -165
- data/lib/stackmate/participants/cloudstack_affinitygroup.rb +122 -0
- data/lib/stackmate/participants/cloudstack_autoscalepolicy.rb +113 -0
- data/lib/stackmate/participants/cloudstack_autoscalevmgroup.rb +86 -0
- data/lib/stackmate/participants/cloudstack_autoscalevmprofile.rb +140 -0
- data/lib/stackmate/participants/cloudstack_condition.rb +122 -0
- data/lib/stackmate/participants/cloudstack_egressfirewallrule.rb +149 -0
- data/lib/stackmate/participants/cloudstack_firewallrule.rb +149 -0
- data/lib/stackmate/participants/cloudstack_globalloadbalancerrule.rb +158 -0
- data/lib/stackmate/participants/cloudstack_instancegroup.rb +113 -0
- data/lib/stackmate/participants/cloudstack_ipaddress.rb +149 -0
- data/lib/stackmate/participants/cloudstack_ipforwardingrule.rb +131 -0
- data/lib/stackmate/participants/cloudstack_iptonic.rb +95 -0
- data/lib/stackmate/participants/cloudstack_iso.rb +95 -0
- data/lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb +140 -0
- data/lib/stackmate/participants/cloudstack_lbstickinesspolicy.rb +122 -0
- data/lib/stackmate/participants/cloudstack_loadbalancer.rb +158 -0
- data/lib/stackmate/participants/cloudstack_loadbalancerrule.rb +185 -0
- data/lib/stackmate/participants/cloudstack_network.rb +293 -0
- data/lib/stackmate/participants/cloudstack_networkacl.rb +176 -0
- data/lib/stackmate/participants/cloudstack_networkacllist.rb +104 -0
- data/lib/stackmate/participants/cloudstack_nictovirtualmachine.rb +104 -0
- data/lib/stackmate/participants/cloudstack_portforwardingrule.rb +176 -0
- data/lib/stackmate/participants/cloudstack_project.rb +113 -0
- data/lib/stackmate/participants/cloudstack_remoteaccessvpn.rb +122 -0
- data/lib/stackmate/participants/cloudstack_securitygroup.rb +122 -0
- data/lib/stackmate/participants/cloudstack_securitygroupegress.rb +185 -0
- data/lib/stackmate/participants/cloudstack_securitygroupingress.rb +185 -0
- data/lib/stackmate/participants/cloudstack_snapshot.rb +113 -0
- data/lib/stackmate/participants/cloudstack_snapshotpolicy.rb +122 -0
- data/lib/stackmate/participants/cloudstack_sshkeypair.rb +113 -0
- data/lib/stackmate/participants/cloudstack_staticnat.rb +113 -0
- data/lib/stackmate/participants/cloudstack_staticroute.rb +95 -0
- data/lib/stackmate/participants/cloudstack_tags.rb +113 -0
- data/lib/stackmate/participants/cloudstack_template.rb +212 -0
- data/lib/stackmate/participants/cloudstack_togloballoadbalancerrule.rb +104 -0
- data/lib/stackmate/participants/cloudstack_toloadbalancerrule.rb +95 -0
- data/lib/stackmate/participants/cloudstack_virtualmachine.rb +348 -0
- data/lib/stackmate/participants/cloudstack_virtualmachineops.rb +95 -0
- data/lib/stackmate/participants/cloudstack_vmsnapshot.rb +113 -0
- data/lib/stackmate/participants/cloudstack_volume.rb +176 -0
- data/lib/stackmate/participants/cloudstack_volumeops.rb +111 -0
- data/lib/stackmate/participants/cloudstack_vpc.rb +158 -0
- data/lib/stackmate/participants/cloudstack_vpnconnection.rb +95 -0
- data/lib/stackmate/participants/cloudstack_vpncustomergateway.rb +176 -0
- data/lib/stackmate/participants/cloudstack_vpngateway.rb +86 -0
- data/lib/stackmate/participants/cloudstack_vpnuser.rb +122 -0
- data/lib/stackmate/participants/common.rb +219 -70
- data/lib/stackmate/participants/stacknest.rb +6 -0
- data/lib/stackmate/resolver.rb +122 -0
- data/lib/stackmate/stack.rb +116 -60
- data/lib/stackmate/stack_executor.rb +99 -37
- data/lib/stackmate/stackpi.rb +46 -0
- data/lib/stackmate/version.rb +1 -1
- data/lib/stackmate/waitcondition_server.rb +15 -15
- data/lib/stackmate.rb +1 -1
- data/stackmate.gemspec +2 -4
- metadata +70 -19
@@ -0,0 +1,348 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackVirtualMachine < CloudStackResource
|
5
|
+
|
6
|
+
include Logging
|
7
|
+
include Intrinsic
|
8
|
+
include Resolver
|
9
|
+
def create
|
10
|
+
logger.debug("Creating resource #{@name}")
|
11
|
+
workitem[@name] = {}
|
12
|
+
name_cs = workitem['StackName'] + '-' + @name
|
13
|
+
args={}
|
14
|
+
begin
|
15
|
+
|
16
|
+
args['templateid'] = get_templateid
|
17
|
+
args['serviceofferingid'] = get_serviceofferingid
|
18
|
+
args['zoneid'] = get_zoneid
|
19
|
+
args['securitygroupnames'] = get_securitygroupnames if @props.has_key?('securitygroupnames')
|
20
|
+
args['affinitygroupids'] = get_affinitygroupids if @props.has_key?('affinitygroupids')
|
21
|
+
args['startvm'] = get_startvm if @props.has_key?('startvm')
|
22
|
+
args['displayvm'] = get_displayvm if @props.has_key?('displayvm')
|
23
|
+
args['diskofferingid'] = get_diskofferingid if @props.has_key?('diskofferingid')
|
24
|
+
args['hypervisor'] = get_hypervisor if @props.has_key?('hypervisor')
|
25
|
+
args['keyboard'] = get_keyboard if @props.has_key?('keyboard')
|
26
|
+
args['name'] = workitem['StackName'] +'-' + get_name if @props.has_key?('name')
|
27
|
+
#args['iptonetworklist'] = get_iptonetworklist if @props.has_key?('iptonetworklist')
|
28
|
+
if @props.has_key?('iptonetworklist')
|
29
|
+
ipnetworklist = get_iptonetworklist
|
30
|
+
#split
|
31
|
+
list_params = ipnetworklist.split("&")
|
32
|
+
list_params.each do |p|
|
33
|
+
fields = p.split("=")
|
34
|
+
args[fields[0]] = fields[1]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
args['networkids'] = get_networkids if @props.has_key?('networkids')
|
38
|
+
args['account'] = get_account if @props.has_key?('account')
|
39
|
+
args['userdata'] = get_userdata if @props.has_key?('userdata')
|
40
|
+
args['keypair'] = get_keypair if @props.has_key?('keypair')
|
41
|
+
args['projectid'] = get_projectid if @props.has_key?('projectid')
|
42
|
+
args['ipaddress'] = get_ipaddress if @props.has_key?('ipaddress')
|
43
|
+
args['displayname'] = get_displayname if @props.has_key?('displayname')
|
44
|
+
args['ip6address'] = get_ip6address if @props.has_key?('ip6address')
|
45
|
+
args['affinitygroupnames'] = get_affinitygroupnames if @props.has_key?('affinitygroupnames')
|
46
|
+
args['domainid'] = get_domainid if @props.has_key?('domainid')
|
47
|
+
args['size'] = get_size if @props.has_key?('size')
|
48
|
+
args['hostid'] = get_hostid if @props.has_key?('hostid')
|
49
|
+
args['securitygroupids'] = get_securitygroupids if @props.has_key?('securitygroupids')
|
50
|
+
args['group'] = get_group if @props.has_key?('group')
|
51
|
+
|
52
|
+
logger.info("Creating resource #{@name} with following arguments")
|
53
|
+
p args
|
54
|
+
result_obj = make_async_request('deployVirtualMachine',args)
|
55
|
+
resource_obj = result_obj['VirtualMachine'.downcase]
|
56
|
+
#doing it this way since it is easier to change later, rather than cloning whole object
|
57
|
+
resource_obj.each_key do |k|
|
58
|
+
val = resource_obj[k]
|
59
|
+
if('id'.eql?(k))
|
60
|
+
k = 'physical_id'
|
61
|
+
end
|
62
|
+
workitem[@name][k] = val
|
63
|
+
end
|
64
|
+
workitem[@name][:PrivateIp] = resource_obj['nic'][0]['ipaddress']
|
65
|
+
set_tags(@props['tags'],workitem[@name]['physical_id'],"UserVm") if @props.has_key?('tags')
|
66
|
+
workitem['ResolvedNames'][@name] = name_cs
|
67
|
+
workitem['IdMap'][workitem[@name]['physical_id']] = @name
|
68
|
+
|
69
|
+
rescue NoMethodError => nme
|
70
|
+
logger.error("Create request failed for resource #{@name}. Cleaning up the stack")
|
71
|
+
raise nme
|
72
|
+
rescue Exception => e
|
73
|
+
logger.error(e.message)
|
74
|
+
raise e
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def delete
|
80
|
+
logger.debug("Deleting resource #{@name}")
|
81
|
+
begin
|
82
|
+
physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
|
83
|
+
if(!physical_id.nil?)
|
84
|
+
args = {'id' => physical_id
|
85
|
+
}
|
86
|
+
result_obj = make_async_request('destroyVirtualMachine',args)
|
87
|
+
if (!(result_obj['error'] == true))
|
88
|
+
logger.info("Successfully deleted resource #{@name}")
|
89
|
+
else
|
90
|
+
logger.info("CloudStack error while deleting resource #{@name}")
|
91
|
+
end
|
92
|
+
else
|
93
|
+
logger.info("Resource not created in CloudStack. Skipping delete...")
|
94
|
+
end
|
95
|
+
rescue Exception => e
|
96
|
+
logger.error("Unable to delete resorce #{@name}")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def on_workitem
|
101
|
+
@name = workitem.participant_name
|
102
|
+
@props = workitem['Resources'][@name]['Properties']
|
103
|
+
@props.downcase_key
|
104
|
+
@resolved_names = workitem['ResolvedNames']
|
105
|
+
if workitem['params']['operation'] == 'create'
|
106
|
+
create
|
107
|
+
else
|
108
|
+
delete
|
109
|
+
end
|
110
|
+
reply
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def get_templateid
|
115
|
+
resolved_templateid = get_resolved(@props["templateid"],workitem)
|
116
|
+
if resolved_templateid.nil? || !validate_param(resolved_templateid,"uuid")
|
117
|
+
raise "Missing mandatory parameter templateid for resource #{@name}"
|
118
|
+
end
|
119
|
+
resolved_templateid
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def get_serviceofferingid
|
124
|
+
resolved_serviceofferingid = get_resolved(@props["serviceofferingid"],workitem)
|
125
|
+
if resolved_serviceofferingid.nil? || !validate_param(resolved_serviceofferingid,"uuid")
|
126
|
+
raise "Missing mandatory parameter serviceofferingid for resource #{@name}"
|
127
|
+
end
|
128
|
+
resolved_serviceofferingid
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
def get_zoneid
|
133
|
+
resolved_zoneid = get_resolved(@props["zoneid"],workitem)
|
134
|
+
if resolved_zoneid.nil? || !validate_param(resolved_zoneid,"uuid")
|
135
|
+
raise "Missing mandatory parameter zoneid for resource #{@name}"
|
136
|
+
end
|
137
|
+
resolved_zoneid
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
def get_securitygroupnames
|
142
|
+
resolved_securitygroupnames = get_resolved(@props['securitygroupnames'],workitem)
|
143
|
+
if resolved_securitygroupnames.nil? || !validate_param(resolved_securitygroupnames,"list")
|
144
|
+
raise "Malformed optional parameter securitygroupnames for resource #{@name}"
|
145
|
+
end
|
146
|
+
resolved_securitygroupnames
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
def get_affinitygroupids
|
151
|
+
resolved_affinitygroupids = get_resolved(@props['affinitygroupids'],workitem)
|
152
|
+
if resolved_affinitygroupids.nil? || !validate_param(resolved_affinitygroupids,"list")
|
153
|
+
raise "Malformed optional parameter affinitygroupids for resource #{@name}"
|
154
|
+
end
|
155
|
+
resolved_affinitygroupids
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
def get_startvm
|
160
|
+
resolved_startvm = get_resolved(@props['startvm'],workitem)
|
161
|
+
if resolved_startvm.nil? || !validate_param(resolved_startvm,"boolean")
|
162
|
+
raise "Malformed optional parameter startvm for resource #{@name}"
|
163
|
+
end
|
164
|
+
resolved_startvm
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
def get_displayvm
|
169
|
+
resolved_displayvm = get_resolved(@props['displayvm'],workitem)
|
170
|
+
if resolved_displayvm.nil? || !validate_param(resolved_displayvm,"boolean")
|
171
|
+
raise "Malformed optional parameter displayvm for resource #{@name}"
|
172
|
+
end
|
173
|
+
resolved_displayvm
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
def get_diskofferingid
|
178
|
+
resolved_diskofferingid = get_resolved(@props['diskofferingid'],workitem)
|
179
|
+
if resolved_diskofferingid.nil? || !validate_param(resolved_diskofferingid,"uuid")
|
180
|
+
raise "Malformed optional parameter diskofferingid for resource #{@name}"
|
181
|
+
end
|
182
|
+
resolved_diskofferingid
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
def get_hypervisor
|
187
|
+
resolved_hypervisor = get_resolved(@props['hypervisor'],workitem)
|
188
|
+
if resolved_hypervisor.nil? || !validate_param(resolved_hypervisor,"string")
|
189
|
+
raise "Malformed optional parameter hypervisor for resource #{@name}"
|
190
|
+
end
|
191
|
+
resolved_hypervisor
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
def get_keyboard
|
196
|
+
resolved_keyboard = get_resolved(@props['keyboard'],workitem)
|
197
|
+
if resolved_keyboard.nil? || !validate_param(resolved_keyboard,"string")
|
198
|
+
raise "Malformed optional parameter keyboard for resource #{@name}"
|
199
|
+
end
|
200
|
+
resolved_keyboard
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
def get_name
|
205
|
+
resolved_name = get_resolved(@props['name'],workitem)
|
206
|
+
if resolved_name.nil? || !validate_param(resolved_name,"string")
|
207
|
+
raise "Malformed optional parameter name for resource #{@name}"
|
208
|
+
end
|
209
|
+
resolved_name
|
210
|
+
end
|
211
|
+
|
212
|
+
|
213
|
+
def get_iptonetworklist
|
214
|
+
resolved_iptonetworklist = get_resolved(@props['iptonetworklist'],workitem)
|
215
|
+
if resolved_iptonetworklist.nil? || !validate_param(resolved_iptonetworklist,"map")
|
216
|
+
raise "Malformed optional parameter iptonetworklist for resource #{@name}"
|
217
|
+
end
|
218
|
+
resolved_iptonetworklist
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
def get_networkids
|
223
|
+
resolved_networkids = get_resolved(@props['networkids'],workitem)
|
224
|
+
if resolved_networkids.nil? || !validate_param(resolved_networkids,"list")
|
225
|
+
raise "Malformed optional parameter networkids for resource #{@name}"
|
226
|
+
end
|
227
|
+
resolved_networkids
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
def get_account
|
232
|
+
resolved_account = get_resolved(@props['account'],workitem)
|
233
|
+
if resolved_account.nil? || !validate_param(resolved_account,"string")
|
234
|
+
raise "Malformed optional parameter account for resource #{@name}"
|
235
|
+
end
|
236
|
+
resolved_account
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
def get_userdata
|
241
|
+
resolved_userdata = get_resolved(@props['userdata'],workitem)
|
242
|
+
if resolved_userdata.nil? || !validate_param(resolved_userdata,"string")
|
243
|
+
raise "Malformed optional parameter userdata for resource #{@name}"
|
244
|
+
end
|
245
|
+
resolved_userdata
|
246
|
+
end
|
247
|
+
|
248
|
+
|
249
|
+
def get_keypair
|
250
|
+
resolved_keypair = get_resolved(@props['keypair'],workitem)
|
251
|
+
if resolved_keypair.nil? || !validate_param(resolved_keypair,"string")
|
252
|
+
raise "Malformed optional parameter keypair for resource #{@name}"
|
253
|
+
end
|
254
|
+
resolved_keypair
|
255
|
+
end
|
256
|
+
|
257
|
+
|
258
|
+
def get_projectid
|
259
|
+
resolved_projectid = get_resolved(@props['projectid'],workitem)
|
260
|
+
if resolved_projectid.nil? || !validate_param(resolved_projectid,"uuid")
|
261
|
+
raise "Malformed optional parameter projectid for resource #{@name}"
|
262
|
+
end
|
263
|
+
resolved_projectid
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
def get_ipaddress
|
268
|
+
resolved_ipaddress = get_resolved(@props['ipaddress'],workitem)
|
269
|
+
if resolved_ipaddress.nil? || !validate_param(resolved_ipaddress,"string")
|
270
|
+
raise "Malformed optional parameter ipaddress for resource #{@name}"
|
271
|
+
end
|
272
|
+
resolved_ipaddress
|
273
|
+
end
|
274
|
+
|
275
|
+
|
276
|
+
def get_displayname
|
277
|
+
resolved_displayname = get_resolved(@props['displayname'],workitem)
|
278
|
+
if resolved_displayname.nil? || !validate_param(resolved_displayname,"string")
|
279
|
+
raise "Malformed optional parameter displayname for resource #{@name}"
|
280
|
+
end
|
281
|
+
resolved_displayname
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
def get_ip6address
|
286
|
+
resolved_ip6address = get_resolved(@props['ip6address'],workitem)
|
287
|
+
if resolved_ip6address.nil? || !validate_param(resolved_ip6address,"string")
|
288
|
+
raise "Malformed optional parameter ip6address for resource #{@name}"
|
289
|
+
end
|
290
|
+
resolved_ip6address
|
291
|
+
end
|
292
|
+
|
293
|
+
|
294
|
+
def get_affinitygroupnames
|
295
|
+
resolved_affinitygroupnames = get_resolved(@props['affinitygroupnames'],workitem)
|
296
|
+
if resolved_affinitygroupnames.nil? || !validate_param(resolved_affinitygroupnames,"list")
|
297
|
+
raise "Malformed optional parameter affinitygroupnames for resource #{@name}"
|
298
|
+
end
|
299
|
+
resolved_affinitygroupnames
|
300
|
+
end
|
301
|
+
|
302
|
+
|
303
|
+
def get_domainid
|
304
|
+
resolved_domainid = get_resolved(@props['domainid'],workitem)
|
305
|
+
if resolved_domainid.nil? || !validate_param(resolved_domainid,"uuid")
|
306
|
+
raise "Malformed optional parameter domainid for resource #{@name}"
|
307
|
+
end
|
308
|
+
resolved_domainid
|
309
|
+
end
|
310
|
+
|
311
|
+
|
312
|
+
def get_size
|
313
|
+
resolved_size = get_resolved(@props['size'],workitem)
|
314
|
+
if resolved_size.nil? || !validate_param(resolved_size,"long")
|
315
|
+
raise "Malformed optional parameter size for resource #{@name}"
|
316
|
+
end
|
317
|
+
resolved_size
|
318
|
+
end
|
319
|
+
|
320
|
+
|
321
|
+
def get_hostid
|
322
|
+
resolved_hostid = get_resolved(@props['hostid'],workitem)
|
323
|
+
if resolved_hostid.nil? || !validate_param(resolved_hostid,"uuid")
|
324
|
+
raise "Malformed optional parameter hostid for resource #{@name}"
|
325
|
+
end
|
326
|
+
resolved_hostid
|
327
|
+
end
|
328
|
+
|
329
|
+
|
330
|
+
def get_securitygroupids
|
331
|
+
resolved_securitygroupids = get_resolved(@props['securitygroupids'],workitem)
|
332
|
+
if resolved_securitygroupids.nil? || !validate_param(resolved_securitygroupids,"list")
|
333
|
+
raise "Malformed optional parameter securitygroupids for resource #{@name}"
|
334
|
+
end
|
335
|
+
resolved_securitygroupids
|
336
|
+
end
|
337
|
+
|
338
|
+
|
339
|
+
def get_group
|
340
|
+
resolved_group = get_resolved(@props['group'],workitem)
|
341
|
+
if resolved_group.nil? || !validate_param(resolved_group,"string")
|
342
|
+
raise "Malformed optional parameter group for resource #{@name}"
|
343
|
+
end
|
344
|
+
resolved_group
|
345
|
+
end
|
346
|
+
|
347
|
+
end
|
348
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackVirtualMachineOps < CloudStackResource
|
5
|
+
|
6
|
+
include Logging
|
7
|
+
include Intrinsic
|
8
|
+
include Resolver
|
9
|
+
def create
|
10
|
+
logger.debug("Creating resource #{@name}")
|
11
|
+
workitem[@name] = {}
|
12
|
+
name_cs = workitem['StackName'] + '-' + @name
|
13
|
+
args={}
|
14
|
+
begin
|
15
|
+
args['id'] = get_id
|
16
|
+
args['hostid'] = get_hostid if @props.has_key?('hostid')
|
17
|
+
|
18
|
+
logger.info("Creating resource #{@name} with following arguments")
|
19
|
+
p args
|
20
|
+
result_obj = make_async_request('startVirtualMachine',args)
|
21
|
+
resource_obj = result_obj['VirtualMachine'.downcase]
|
22
|
+
#doing it this way since it is easier to change later, rather than cloning whole object
|
23
|
+
resource_obj.each_key do |k|
|
24
|
+
val = resource_obj[k]
|
25
|
+
if('id'.eql?(k))
|
26
|
+
k = 'physical_id'
|
27
|
+
end
|
28
|
+
workitem[@name][k] = val
|
29
|
+
end
|
30
|
+
set_tags(@props['tags'],workitem[@name]['physical_id'],"UserVM") if @props.has_key?('tags')
|
31
|
+
workitem['ResolvedNames'][@name] = name_cs
|
32
|
+
workitem['IdMap'][workitem[@name]['physical_id']] = @name
|
33
|
+
|
34
|
+
rescue NoMethodError => nme
|
35
|
+
logger.error("Create request failed for resource . Cleaning up the stack")
|
36
|
+
raise nme
|
37
|
+
rescue Exception => e
|
38
|
+
logger.error(e.message)
|
39
|
+
raise e
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete
|
45
|
+
logger.debug("Deleting resource #{@name}")
|
46
|
+
begin
|
47
|
+
physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
|
48
|
+
if(!physical_id.nil?)
|
49
|
+
args = {'id' => physical_id
|
50
|
+
}
|
51
|
+
result_obj = make_async_request('stopVirtualMachine',args)
|
52
|
+
if (!(result_obj['error'] == true))
|
53
|
+
logger.info("Successfully deleted resource #{@name}")
|
54
|
+
else
|
55
|
+
logger.info("CloudStack error while deleting resource #{@name}")
|
56
|
+
end
|
57
|
+
else
|
58
|
+
logger.info("Resource not created in CloudStack. Skipping delete...")
|
59
|
+
end
|
60
|
+
rescue Exception => e
|
61
|
+
logger.error("Unable to delete resorce #{@name}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def on_workitem
|
66
|
+
@name = workitem.participant_name
|
67
|
+
@props = workitem['Resources'][@name]['Properties']
|
68
|
+
@props.downcase_key
|
69
|
+
@resolved_names = workitem['ResolvedNames']
|
70
|
+
if workitem['params']['operation'] == 'create'
|
71
|
+
create
|
72
|
+
else
|
73
|
+
delete
|
74
|
+
end
|
75
|
+
reply
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_id
|
79
|
+
resolved_id = get_resolved(@props["id"],workitem)
|
80
|
+
if resolved_id.nil? || !validate_param(resolved_id,"uuid")
|
81
|
+
raise "Missing mandatory parameter id for resource #{@name}"
|
82
|
+
end
|
83
|
+
resolved_id
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_hostid
|
87
|
+
resolved_hostid = get_resolved(@props['hostid'],workitem)
|
88
|
+
if resolved_hostid.nil? || !validate_param(resolved_hostid,"uuid")
|
89
|
+
raise "Malformed optional parameter hostid for resource #{@name}"
|
90
|
+
end
|
91
|
+
resolved_hostid
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'stackmate/participants/cloudstack'
|
2
|
+
|
3
|
+
module StackMate
|
4
|
+
class CloudStackVMSnapshot < CloudStackResource
|
5
|
+
|
6
|
+
include Logging
|
7
|
+
include Intrinsic
|
8
|
+
include Resolver
|
9
|
+
def create
|
10
|
+
logger.debug("Creating resource #{@name}")
|
11
|
+
workitem[@name] = {}
|
12
|
+
name_cs = workitem['StackName'] + '-' + @name
|
13
|
+
args={}
|
14
|
+
begin
|
15
|
+
args['virtualmachineid'] = get_virtualmachineid
|
16
|
+
args['description'] = get_description if @props.has_key?('description')
|
17
|
+
args['snapshotmemory'] = get_snapshotmemory if @props.has_key?('snapshotmemory')
|
18
|
+
args['name'] = workitem['StackName'] +'-' +get_name if @props.has_key?('name')
|
19
|
+
|
20
|
+
logger.info("Creating resource #{@name} with following arguments")
|
21
|
+
p args
|
22
|
+
result_obj = make_async_request('createVMSnapshot',args)
|
23
|
+
resource_obj = result_obj['VMSnapshot'.downcase]
|
24
|
+
#doing it this way since it is easier to change later, rather than cloning whole object
|
25
|
+
resource_obj.each_key do |k|
|
26
|
+
val = resource_obj[k]
|
27
|
+
if('id'.eql?(k))
|
28
|
+
k = 'physical_id'
|
29
|
+
end
|
30
|
+
workitem[@name][k] = val
|
31
|
+
end
|
32
|
+
set_tags(@props['tags'],workitem[@name]['physical_id'],"VMSnapshot") if @props.has_key?('tags')
|
33
|
+
workitem['ResolvedNames'][@name] = name_cs
|
34
|
+
workitem['IdMap'][workitem[@name]['physical_id']] = @name
|
35
|
+
|
36
|
+
rescue NoMethodError => nme
|
37
|
+
logger.error("Create request failed for resource . Cleaning up the stack")
|
38
|
+
raise nme
|
39
|
+
rescue Exception => e
|
40
|
+
logger.error(e.message)
|
41
|
+
raise e
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete
|
47
|
+
logger.debug("Deleting resource #{@name}")
|
48
|
+
begin
|
49
|
+
physical_id = workitem[@name]['physical_id'] if !workitem[@name].nil?
|
50
|
+
if(!physical_id.nil?)
|
51
|
+
args = {'vmsnapshotid' => physical_id
|
52
|
+
}
|
53
|
+
result_obj = make_async_request('deleteVMSnapshot',args)
|
54
|
+
if (!(result_obj['error'] == true))
|
55
|
+
logger.info("Successfully deleted resource #{@name}")
|
56
|
+
else
|
57
|
+
logger.info("CloudStack error while deleting resource #{@name}")
|
58
|
+
end
|
59
|
+
else
|
60
|
+
logger.info("Resource not created in CloudStack. Skipping delete...")
|
61
|
+
end
|
62
|
+
rescue Exception => e
|
63
|
+
logger.error("Unable to delete resorce #{@name}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def on_workitem
|
68
|
+
@name = workitem.participant_name
|
69
|
+
@props = workitem['Resources'][@name]['Properties']
|
70
|
+
@props.downcase_key
|
71
|
+
@resolved_names = workitem['ResolvedNames']
|
72
|
+
if workitem['params']['operation'] == 'create'
|
73
|
+
create
|
74
|
+
else
|
75
|
+
delete
|
76
|
+
end
|
77
|
+
reply
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_virtualmachineid
|
81
|
+
resolved_virtualmachineid = get_resolved(@props["virtualmachineid"],workitem)
|
82
|
+
if resolved_virtualmachineid.nil? || !validate_param(resolved_virtualmachineid,"uuid")
|
83
|
+
raise "Missing mandatory parameter virtualmachineid for resource #{@name}"
|
84
|
+
end
|
85
|
+
resolved_virtualmachineid
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_description
|
89
|
+
resolved_description = get_resolved(@props['description'],workitem)
|
90
|
+
if resolved_description.nil? || !validate_param(resolved_description,"string")
|
91
|
+
raise "Malformed optional parameter description for resource #{@name}"
|
92
|
+
end
|
93
|
+
resolved_description
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_snapshotmemory
|
97
|
+
resolved_snapshotmemory = get_resolved(@props['snapshotmemory'],workitem)
|
98
|
+
if resolved_snapshotmemory.nil? || !validate_param(resolved_snapshotmemory,"boolean")
|
99
|
+
raise "Malformed optional parameter snapshotmemory for resource #{@name}"
|
100
|
+
end
|
101
|
+
resolved_snapshotmemory
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_name
|
105
|
+
resolved_name = get_resolved(@props['name'],workitem)
|
106
|
+
if resolved_name.nil? || !validate_param(resolved_name,"string")
|
107
|
+
raise "Malformed optional parameter name for resource #{@name}"
|
108
|
+
end
|
109
|
+
resolved_name
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|