Class: StackMate::CloudStackVolumeOps
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
|
# File 'lib/stackmate/participants/cloudstack_volumeops.rb', line 9
def create
logger.debug("Creating resource #{@name}")
workitem[@name] = {}
name_cs = workitem['StackName'] + '-' + @name
args={}
begin
args['id'] = get_id
args['virtualmachineid'] = get_virtualmachineid
args['deviceid'] = get_deviceid if @props.has_key?('deviceid')
logger.info("Creating resource #{@name} with following arguments")
p args
result_obj = make_async_request('attachVolume',args)
resource_obj = result_obj['Volume'.downcase]
resource_obj.each_key do |k|
val = resource_obj[k]
if('id'.eql?(k))
k = 'physical_id'
end
workitem[@name][k] = val
end
set_tags(@props['tags'],workitem[@name]['physical_id'],"Volume") 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/stackmate/participants/cloudstack_volumeops.rb', line 49
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('detachVolume',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_deviceid ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/stackmate/participants/cloudstack_volumeops.rb', line 102
def get_deviceid
resolved_deviceid = get_resolved(@props['deviceid'],workitem)
if resolved_deviceid.nil? || !validate_param(resolved_deviceid,"long")
raise "Malformed optional parameter deviceid for resource #{@name}"
end
resolved_deviceid
end
|
#get_id ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/stackmate/participants/cloudstack_volumeops.rb', line 84
def get_id
resolved_id = get_resolved(@props["id"],workitem)
if resolved_id.nil? || !validate_param(resolved_id,"uuid")
raise "Missing mandatory parameter id for resource #{@name}"
end
resolved_id
end
|
#get_virtualmachineid ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/stackmate/participants/cloudstack_volumeops.rb', line 93
def get_virtualmachineid
resolved_virtualmachineid = get_resolved(@props["virtualmachineid"],workitem)
if resolved_virtualmachineid.nil? || !validate_param(resolved_virtualmachineid,"uuid")
raise "Missing mandatory parameter virtualmachineid for resource #{@name}"
end
resolved_virtualmachineid
end
|
#on_workitem ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/stackmate/participants/cloudstack_volumeops.rb', line 70
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
|