Class: StackMate::CloudStackLBHealthCheckPolicy

Inherits:
CloudStackResource show all
Includes:
Intrinsic, Logging, Resolver
Defined in:
lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.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, #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

Methods inherited from CloudStackResource

#initialize, #set_metadata

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
# File 'lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb', line 9

def create
  logger.debug("Creating resource #{@name}")
  workitem[@name] = {}
  name_cs = workitem['StackName'] + '-' + @name
  args={}
  begin
    args['lbruleid'] = get_lbruleid
    args['responsetimeout'] = get_responsetimeout if @props.has_key?('responsetimeout')
    args['unhealthythreshold'] = get_unhealthythreshold if @props.has_key?('unhealthythreshold')
    args['pingpath'] = get_pingpath if @props.has_key?('pingpath')
    args['description'] = get_description if @props.has_key?('description')
    args['intervaltime'] = get_intervaltime if @props.has_key?('intervaltime')
    args['healthythreshold'] = get_healthythreshold if @props.has_key?('healthythreshold')

    logger.info("Creating resource #{@name} with following arguments")
    p args
    result_obj = make_async_request('createLBHealthCheckPolicy',args)
    resource_obj = result_obj['LBHealthCheckPolicy'.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'],"LBHealthCheckPolicy") if @props.has_key?('tags')
     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

#deleteObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb', line 51

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('deleteLBHealthCheckPolicy',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_descriptionObject



118
119
120
121
122
123
124
# File 'lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb', line 118

def get_description
  resolved_description = get_resolved(@props['description'],workitem)
  if resolved_description.nil? || !validate_param(resolved_description,"string")
    raise "Malformed optional parameter description for resource #{@name}"
  end
  resolved_description
end

#get_healthythresholdObject



134
135
136
137
138
139
140
# File 'lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb', line 134

def get_healthythreshold
  resolved_healthythreshold = get_resolved(@props['healthythreshold'],workitem)
  if resolved_healthythreshold.nil? || !validate_param(resolved_healthythreshold,"integer")
    raise "Malformed optional parameter healthythreshold for resource #{@name}"
  end
  resolved_healthythreshold
end

#get_intervaltimeObject



126
127
128
129
130
131
132
# File 'lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb', line 126

def get_intervaltime
  resolved_intervaltime = get_resolved(@props['intervaltime'],workitem)
  if resolved_intervaltime.nil? || !validate_param(resolved_intervaltime,"integer")
    raise "Malformed optional parameter intervaltime for resource #{@name}"
  end
  resolved_intervaltime
end

#get_lbruleidObject



86
87
88
89
90
91
92
# File 'lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb', line 86

def get_lbruleid
  resolved_lbruleid = get_resolved(@props["lbruleid"],workitem)
  if resolved_lbruleid.nil? || !validate_param(resolved_lbruleid,"uuid")
    raise "Missing mandatory parameter lbruleid for resource #{@name}"
  end
  resolved_lbruleid
end

#get_pingpathObject



110
111
112
113
114
115
116
# File 'lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb', line 110

def get_pingpath
  resolved_pingpath = get_resolved(@props['pingpath'],workitem)
  if resolved_pingpath.nil? || !validate_param(resolved_pingpath,"string")
    raise "Malformed optional parameter pingpath for resource #{@name}"
  end
  resolved_pingpath
end

#get_responsetimeoutObject



94
95
96
97
98
99
100
# File 'lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb', line 94

def get_responsetimeout
  resolved_responsetimeout = get_resolved(@props['responsetimeout'],workitem)
  if resolved_responsetimeout.nil? || !validate_param(resolved_responsetimeout,"integer")
    raise "Malformed optional parameter responsetimeout for resource #{@name}"
  end
  resolved_responsetimeout
end

#get_unhealthythresholdObject



102
103
104
105
106
107
108
# File 'lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb', line 102

def get_unhealthythreshold
  resolved_unhealthythreshold = get_resolved(@props['unhealthythreshold'],workitem)
  if resolved_unhealthythreshold.nil? || !validate_param(resolved_unhealthythreshold,"integer")
    raise "Malformed optional parameter unhealthythreshold for resource #{@name}"
  end
  resolved_unhealthythreshold
end

#on_workitemObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/stackmate/participants/cloudstack_lbhealthcheckpolicy.rb', line 73

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