Class: StackMate::CloudStackTemplate
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, #recursive_resolve, #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, #set_metadata
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
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 9
def create
logger.debug("Creating resource #{@name}")
workitem[@name] = {}
name_cs = workitem['StackName'] + '-' + @name
args={}
begin
args['displaytext'] = get_displaytext
args['ostypeid'] = get_ostypeid
args['name'] = workitem['StackName'] +'-' +get_name
args['snapshotid'] = get_snapshotid if @props.has_key?('snapshotid')
args['details'] = get_details if @props.has_key?('details')
args['virtualmachineid'] = get_virtualmachineid if @props.has_key?('virtualmachineid')
args['requireshvm'] = get_requireshvm if @props.has_key?('requireshvm')
args['ispublic'] = get_ispublic if @props.has_key?('ispublic')
args['volumeid'] = get_volumeid if @props.has_key?('volumeid')
args['bits'] = get_bits if @props.has_key?('bits')
args['url'] = get_url if @props.has_key?('url')
args['templatetag'] = get_templatetag if @props.has_key?('templatetag')
args['isdynamicallyscalable'] = get_isdynamicallyscalable if @props.has_key?('isdynamicallyscalable')
args['passwordenabled'] = get_passwordenabled if @props.has_key?('passwordenabled')
args['isfeatured'] = get_isfeatured if @props.has_key?('isfeatured')
logger.info("Creating resource #{@name} with following arguments")
p args
result_obj = make_async_request('createTemplate',args)
resource_obj = result_obj['Template'.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'],"Template") if @props.has_key?('tags')
set_metadata if workitem['Resources'][@name].has_key?('Metadata')
workitem['ResolvedNames'][@name] = name_cs
workitem['IdMap'][workitem[@name]['physical_id']] = @name
rescue NoMethodError => nme
logger.error("Create request failed for resource . Cleaning up the stack")
raise nme
rescue Exception => e
logger.error(e.message)
raise e
end
end
|
#delete ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 59
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('deleteTemplate',args)
if (!(result_obj['error'] == true))
logger.info("Successfully deleted resource #{@name}")
else
workitem[@name]['delete_error'] = true
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_bits ⇒ Object
166
167
168
169
170
171
172
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 166
def get_bits
resolved_bits = get_resolved(@props['bits'],workitem)
if resolved_bits.nil? || !validate_param(resolved_bits,"integer")
raise "Malformed optional parameter bits for resource #{@name}"
end
resolved_bits
end
|
#get_details ⇒ Object
126
127
128
129
130
131
132
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 126
def get_details
resolved_details = get_resolved(@props['details'],workitem)
if resolved_details.nil? || !validate_param(resolved_details,"map")
raise "Malformed optional parameter details for resource #{@name}"
end
resolved_details
end
|
#get_displaytext ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 94
def get_displaytext
resolved_displaytext = get_resolved(@props["displaytext"],workitem)
if resolved_displaytext.nil? || !validate_param(resolved_displaytext,"string")
raise "Missing mandatory parameter displaytext for resource #{@name}"
end
resolved_displaytext
end
|
#get_isdynamicallyscalable ⇒ Object
190
191
192
193
194
195
196
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 190
def get_isdynamicallyscalable
resolved_isdynamicallyscalable = get_resolved(@props['isdynamicallyscalable'],workitem)
if resolved_isdynamicallyscalable.nil? || !validate_param(resolved_isdynamicallyscalable,"boolean")
raise "Malformed optional parameter isdynamicallyscalable for resource #{@name}"
end
resolved_isdynamicallyscalable
end
|
#get_isfeatured ⇒ Object
206
207
208
209
210
211
212
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 206
def get_isfeatured
resolved_isfeatured = get_resolved(@props['isfeatured'],workitem)
if resolved_isfeatured.nil? || !validate_param(resolved_isfeatured,"boolean")
raise "Malformed optional parameter isfeatured for resource #{@name}"
end
resolved_isfeatured
end
|
#get_ispublic ⇒ Object
150
151
152
153
154
155
156
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 150
def get_ispublic
resolved_ispublic = get_resolved(@props['ispublic'],workitem)
if resolved_ispublic.nil? || !validate_param(resolved_ispublic,"boolean")
raise "Malformed optional parameter ispublic for resource #{@name}"
end
resolved_ispublic
end
|
#get_name ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 110
def get_name
resolved_name = get_resolved(@props["name"],workitem)
if resolved_name.nil? || !validate_param(resolved_name,"string")
raise "Missing mandatory parameter name for resource #{@name}"
end
resolved_name
end
|
#get_ostypeid ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 102
def get_ostypeid
resolved_ostypeid = get_resolved(@props["ostypeid"],workitem)
if resolved_ostypeid.nil? || !validate_param(resolved_ostypeid,"uuid")
raise "Missing mandatory parameter ostypeid for resource #{@name}"
end
resolved_ostypeid
end
|
#get_passwordenabled ⇒ Object
198
199
200
201
202
203
204
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 198
def get_passwordenabled
resolved_passwordenabled = get_resolved(@props['passwordenabled'],workitem)
if resolved_passwordenabled.nil? || !validate_param(resolved_passwordenabled,"boolean")
raise "Malformed optional parameter passwordenabled for resource #{@name}"
end
resolved_passwordenabled
end
|
#get_requireshvm ⇒ Object
142
143
144
145
146
147
148
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 142
def get_requireshvm
resolved_requireshvm = get_resolved(@props['requireshvm'],workitem)
if resolved_requireshvm.nil? || !validate_param(resolved_requireshvm,"boolean")
raise "Malformed optional parameter requireshvm for resource #{@name}"
end
resolved_requireshvm
end
|
#get_snapshotid ⇒ Object
118
119
120
121
122
123
124
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 118
def get_snapshotid
resolved_snapshotid = get_resolved(@props['snapshotid'],workitem)
if resolved_snapshotid.nil? || !validate_param(resolved_snapshotid,"uuid")
raise "Malformed optional parameter snapshotid for resource #{@name}"
end
resolved_snapshotid
end
|
#get_templatetag ⇒ Object
182
183
184
185
186
187
188
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 182
def get_templatetag
resolved_templatetag = get_resolved(@props['templatetag'],workitem)
if resolved_templatetag.nil? || !validate_param(resolved_templatetag,"string")
raise "Malformed optional parameter templatetag for resource #{@name}"
end
resolved_templatetag
end
|
#get_url ⇒ Object
174
175
176
177
178
179
180
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 174
def get_url
resolved_url = get_resolved(@props['url'],workitem)
if resolved_url.nil? || !validate_param(resolved_url,"string")
raise "Malformed optional parameter url for resource #{@name}"
end
resolved_url
end
|
#get_virtualmachineid ⇒ Object
134
135
136
137
138
139
140
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 134
def get_virtualmachineid
resolved_virtualmachineid = get_resolved(@props['virtualmachineid'],workitem)
if resolved_virtualmachineid.nil? || !validate_param(resolved_virtualmachineid,"uuid")
raise "Malformed optional parameter virtualmachineid for resource #{@name}"
end
resolved_virtualmachineid
end
|
#get_volumeid ⇒ Object
158
159
160
161
162
163
164
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 158
def get_volumeid
resolved_volumeid = get_resolved(@props['volumeid'],workitem)
if resolved_volumeid.nil? || !validate_param(resolved_volumeid,"uuid")
raise "Malformed optional parameter volumeid for resource #{@name}"
end
resolved_volumeid
end
|
#on_workitem ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/stackmate/participants/cloudstack_template.rb', line 81
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
|