Class: StackMate::CloudStackSecurityGroup

Inherits:
CloudStackResource show all
Defined in:
lib/stackmate/participants/cloudstack.rb

Instance Attribute Summary

Attributes inherited from CloudStackResource

#name

Instance Method Summary collapse

Methods inherited from CloudStackResource

#initialize

Methods included from Logging

configure_logger_for, #logger, logger_for

Constructor Details

This class inherits a constructor from StackMate::CloudStackResource

Instance Method Details

#on_workitemObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/stackmate/participants/cloudstack.rb', line 177

def on_workitem
  myname = workitem.participant_name
  workitem[participant_name] = {}
  logger.debug("Going to create resource #{myname}")
  @name = myname
  p myname
  resolved = workitem.fields['ResolvedNames']
  props = workitem.fields['Resources'][myname]['Properties']
  name = workitem.fields['StackName'] + '-' + workitem.participant_name;
  resolved[myname] = name
  args = { 'name' => name,
           'description' => props['GroupDescription']
  }
  sg_resp = make_request('createSecurityGroup', args)
  logger.debug("created resource #{myname}")
  props['SecurityGroupIngress'].each do |rule|
      cidrIp = rule['CidrIp']
      if cidrIp.kind_of?  Hash
          #TODO: some sort of validation
          cidrIpName = cidrIp['Ref']
          cidrIp = resolved[cidrIpName]
      end
      args = { 'securitygroupname' => name,
          'startport' => rule['FromPort'],
          'endport' => rule['ToPort'],
          'protocol' => rule['IpProtocol'],
          'cidrlist' => cidrIp
      }
      #TODO handle usersecuritygrouplist
      make_request('authorizeSecurityGroupIngress', args)
  end
  workitem[participant_name][:physical_id] =  sg_resp['securitygroup']['id']
  reply
end