Class: StackMate::CloudStackPortForwardingRule

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

def create
  logger.debug("Creating resource #{@name}")
  workitem[@name] = {}
  name_cs = workitem['StackName'] + '-' + @name
  args={}
  begin
    args['privateport'] = get_privateport
    args['protocol'] = get_protocol
    args['ipaddressid'] = get_ipaddressid
    args['virtualmachineid'] = get_virtualmachineid
    args['publicport'] = get_publicport
    args['privateendport'] = get_privateendport if @props.has_key?('privateendport')
    args['cidrlist'] = get_cidrlist if @props.has_key?('cidrlist')
    args['vmguestip'] = get_vmguestip if @props.has_key?('vmguestip')
    args['networkid'] = get_networkid if @props.has_key?('networkid')
    args['publicendport'] = get_publicendport if @props.has_key?('publicendport')
    args['openfirewall'] = get_openfirewall if @props.has_key?('openfirewall')

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



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

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('deletePortForwardingRule',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_cidrlistObject



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

def get_cidrlist
  resolved_cidrlist = get_resolved(@props['cidrlist'],workitem)
  if resolved_cidrlist.nil? || !validate_param(resolved_cidrlist,"list")
    raise "Malformed optional parameter cidrlist for resource #{@name}"
  end
  resolved_cidrlist
end

#get_ipaddressidObject



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

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

#get_networkidObject



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

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

#get_openfirewallObject



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

def get_openfirewall
  resolved_openfirewall = get_resolved(@props['openfirewall'],workitem)
  if resolved_openfirewall.nil? || !validate_param(resolved_openfirewall,"boolean")
    raise "Malformed optional parameter openfirewall for resource #{@name}"
  end
  resolved_openfirewall
end

#get_privateendportObject



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

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

#get_privateportObject



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

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

#get_protocolObject



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

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

#get_publicendportObject



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

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

#get_publicportObject



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

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

#get_virtualmachineidObject



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

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

#get_vmguestipObject



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

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

#on_workitemObject



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

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