Class: StackMate::CloudStackSecurityGroupAWS

Inherits:
CloudStackResource show all
Defined in:
lib/stackmate/participants/cloudstack.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 inherited from CloudStackResource

#initialize, #set_metadata

Methods included from Resolver

#get_named_tag, #get_resolved, #recursive_resolve, #resolve_tags, #resolve_to_deviceid, #validate_param

Methods included from Logging

configure_logger_for, #logger, logger_for

Constructor Details

This class inherits a constructor from StackMate::CloudStackResource

Instance Method Details

#createObject



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/stackmate/participants/cloudstack.rb', line 281

def create
  myname = workitem.participant_name
  workitem[participant_name] = {}
  logger.debug("Going to create resource #{myname}")
  @name = myname
  p myname
  resolved = workitem['ResolvedNames']
  props = workitem['Resources'][myname]['Properties']
  name = workitem['StackName'] + '-' + workitem.participant_name;
  resolved[myname] = name
  args = { 'name' => name,
           'description' => props['GroupDescription']
           }
  sg_resp = make_sync_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_async_request('authorizeSecurityGroupIngress', args)
  end
  workitem[participant_name][:physical_id] = sg_resp['securitygroup']['id']
end

#deleteObject



315
316
317
318
319
320
321
322
323
324
# File 'lib/stackmate/participants/cloudstack.rb', line 315

def delete
  logger.info "In delete #{participant_name}"
  return nil if !workitem[participant_name]
  logger.info "In delete #{participant_name} #{workitem[participant_name].inspect}"
  physical_id = workitem[participant_name]['physical_id']
  if physical_id
    args = {'id' => physical_id}
    del_resp = make_sync_request('deleteSecurityGroup', args)
  end
end

#on_workitemObject



326
327
328
329
330
331
332
333
# File 'lib/stackmate/participants/cloudstack.rb', line 326

def on_workitem
  if workitem['params']['operation'] == 'create'
    create
  else
    delete
  end
  reply
end