Class: StackMate::CloudStackSecurityGroupEgress

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

def create
  logger.debug("Creating resource #{@name}")
  workitem[@name] = {}
  name_cs = workitem['StackName'] + '-' + @name
  args={}
  begin
    args['cidrlist'] = get_cidrlist if @props.has_key?('cidrlist')
    args['securitygroupname'] = get_securitygroupname if @props.has_key?('securitygroupname')
    args['account'] =  if @props.has_key?('account')
    args['endport'] = get_endport if @props.has_key?('endport')
    args['usersecuritygrouplist'] = get_usersecuritygrouplist if @props.has_key?('usersecuritygrouplist')
    args['protocol'] = get_protocol if @props.has_key?('protocol')
    args['domainid'] = get_domainid if @props.has_key?('domainid')
    args['icmptype'] = get_icmptype if @props.has_key?('icmptype')
    args['startport'] = get_startport if @props.has_key?('startport')
    args['icmpcode'] = get_icmpcode if @props.has_key?('icmpcode')
    args['projectid'] = get_projectid if @props.has_key?('projectid')
    args['securitygroupid'] = get_securitygroupid if @props.has_key?('securitygroupid')

    logger.info("Creating resource #{@name} with following arguments")
    p args
    result_obj = make_async_request('authorizeSecurityGroupEgress',args)
    resource_obj = result_obj['securitygroup']['egressrule'.downcase][0]
    #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('ruleid'.eql?(k))
        k = 'physical_id'
      end
      workitem[@name][k] = val
    end
    set_tags(@props['tags'],workitem[@name]['physical_id'],"SecurityGroupEgress") 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



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

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('revokeSecurityGroupEgress',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_accountObject



104
105
106
107
108
109
110
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 104

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

#get_cidrlistObject



88
89
90
91
92
93
94
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 88

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_domainidObject



136
137
138
139
140
141
142
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 136

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

#get_endportObject



112
113
114
115
116
117
118
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 112

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

#get_icmpcodeObject



160
161
162
163
164
165
166
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 160

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

#get_icmptypeObject



144
145
146
147
148
149
150
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 144

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

#get_projectidObject



168
169
170
171
172
173
174
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 168

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

#get_protocolObject



128
129
130
131
132
133
134
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 128

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

#get_securitygroupidObject



176
177
178
179
180
181
182
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 176

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

#get_securitygroupnameObject



96
97
98
99
100
101
102
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 96

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

#get_startportObject



152
153
154
155
156
157
158
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 152

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

#get_usersecuritygrouplistObject



120
121
122
123
124
125
126
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 120

def get_usersecuritygrouplist
  resolved_usersecuritygrouplist = get_resolved(@props['usersecuritygrouplist'],workitem)
  if resolved_usersecuritygrouplist.nil? || !validate_param(resolved_usersecuritygrouplist,"map")
    raise "Malformed optional parameter usersecuritygrouplist for resource #{@name}"
  end
  resolved_usersecuritygrouplist
end

#on_workitemObject



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/stackmate/participants/cloudstack_securitygroupegress.rb', line 75

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