Class: StackMate::CloudStackTemplate

Inherits:
CloudStackResource show all
Includes:
Intrinsic, Logging, Resolver
Defined in:
lib/stackmate/participants/cloudstack_template.rb

Constant Summary

Constants included from Resolver

Resolver::INTEXP, Resolver::STRINGEXP, Resolver::UUIDEXP

Instance Attribute Summary

Attributes inherited from CloudStackResource

#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

Methods inherited from CloudStackResource

#initialize

Constructor Details

This class inherits a constructor from StackMate::CloudStackResource

Instance Method Details

#createObject



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
# 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]
    #doing it this way since it is easier to change later, rather than cloning whole object
    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')
    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

#deleteObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/stackmate/participants/cloudstack_template.rb', line 57

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
        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_bitsObject



163
164
165
166
167
168
169
# File 'lib/stackmate/participants/cloudstack_template.rb', line 163

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_detailsObject



123
124
125
126
127
128
129
# File 'lib/stackmate/participants/cloudstack_template.rb', line 123

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_displaytextObject



91
92
93
94
95
96
97
# File 'lib/stackmate/participants/cloudstack_template.rb', line 91

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_isdynamicallyscalableObject



187
188
189
190
191
192
193
# File 'lib/stackmate/participants/cloudstack_template.rb', line 187

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_isfeaturedObject



203
204
205
206
207
208
209
# File 'lib/stackmate/participants/cloudstack_template.rb', line 203

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_ispublicObject



147
148
149
150
151
152
153
# File 'lib/stackmate/participants/cloudstack_template.rb', line 147

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_nameObject



107
108
109
110
111
112
113
# File 'lib/stackmate/participants/cloudstack_template.rb', line 107

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_ostypeidObject



99
100
101
102
103
104
105
# File 'lib/stackmate/participants/cloudstack_template.rb', line 99

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_passwordenabledObject



195
196
197
198
199
200
201
# File 'lib/stackmate/participants/cloudstack_template.rb', line 195

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_requireshvmObject



139
140
141
142
143
144
145
# File 'lib/stackmate/participants/cloudstack_template.rb', line 139

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_snapshotidObject



115
116
117
118
119
120
121
# File 'lib/stackmate/participants/cloudstack_template.rb', line 115

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_templatetagObject



179
180
181
182
183
184
185
# File 'lib/stackmate/participants/cloudstack_template.rb', line 179

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_urlObject



171
172
173
174
175
176
177
# File 'lib/stackmate/participants/cloudstack_template.rb', line 171

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_virtualmachineidObject



131
132
133
134
135
136
137
# File 'lib/stackmate/participants/cloudstack_template.rb', line 131

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_volumeidObject



155
156
157
158
159
160
161
# File 'lib/stackmate/participants/cloudstack_template.rb', line 155

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_workitemObject



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/stackmate/participants/cloudstack_template.rb', line 78

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