Class: StackMate::CloudStackLoadBalancer

Inherits:
CloudStackResource show all
Includes:
Intrinsic, Logging, Resolver
Defined in:
lib/stackmate/participants/cloudstack_loadbalancer.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
# File 'lib/stackmate/participants/cloudstack_loadbalancer.rb', line 9

def create
  logger.debug("Creating resource #{@name}")
  workitem[@name] = {}
  name_cs = workitem['StackName'] + '-' + @name
  args={}
  begin
    args['sourceport'] = get_sourceport
    args['scheme'] = get_scheme
    args['algorithm'] = get_algorithm
    args['networkid'] = get_networkid
    args['sourceipaddressnetworkid'] = get_sourceipaddressnetworkid
    args['name'] = workitem['StackName'] +'-' +get_name
    args['instanceport'] = get_instanceport
    args['description'] = get_description if @props.has_key?('description')
    args['sourceipaddress'] = get_sourceipaddress if @props.has_key?('sourceipaddress')

    logger.info("Creating resource #{@name} with following arguments")
    p args
    result_obj = make_async_request('createLoadBalancer',args)
    resource_obj = result_obj['LoadBalancer'.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'],"LoadBalancer") 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



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/stackmate/participants/cloudstack_loadbalancer.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('deleteLoadBalancer',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_algorithmObject



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

def get_algorithm
  resolved_algorithm = get_resolved(@props["algorithm"],workitem)
  if resolved_algorithm.nil? || !validate_param(resolved_algorithm,"string")
    raise "Missing mandatory parameter algorithm for resource #{@name}"
  end
  resolved_algorithm
end

#get_descriptionObject



141
142
143
144
145
146
147
# File 'lib/stackmate/participants/cloudstack_loadbalancer.rb', line 141

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_instanceportObject



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

def get_instanceport
  resolved_instanceport = get_resolved(@props["instanceport"],workitem)
  if resolved_instanceport.nil? || !validate_param(resolved_instanceport,"integer")
    raise "Missing mandatory parameter instanceport for resource #{@name}"
  end
  resolved_instanceport
end

#get_nameObject



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

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_networkidObject



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

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

#get_schemeObject



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

def get_scheme
  resolved_scheme = get_resolved(@props["scheme"],workitem)
  if resolved_scheme.nil? || !validate_param(resolved_scheme,"string")
    raise "Missing mandatory parameter scheme for resource #{@name}"
  end
  resolved_scheme
end

#get_sourceipaddressObject



149
150
151
152
153
154
155
# File 'lib/stackmate/participants/cloudstack_loadbalancer.rb', line 149

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

#get_sourceipaddressnetworkidObject



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

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

#get_sourceportObject



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

def get_sourceport
  resolved_sourceport = get_resolved(@props["sourceport"],workitem)
  if resolved_sourceport.nil? || !validate_param(resolved_sourceport,"integer")
    raise "Missing mandatory parameter sourceport for resource #{@name}"
  end
  resolved_sourceport
end

#on_workitemObject



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

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