2009-09-18 11:56:42 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class EC2
|
|
|
|
|
|
|
|
def security_groups
|
|
|
|
Fog::AWS::EC2::SecurityGroups.new(:connection => self)
|
|
|
|
end
|
|
|
|
|
|
|
|
class SecurityGroups < Fog::Collection
|
|
|
|
|
2009-09-25 12:01:51 -04:00
|
|
|
attribute :group_name
|
|
|
|
|
2009-10-30 03:11:50 -04:00
|
|
|
model Fog::AWS::EC2::SecurityGroup
|
2009-10-30 02:35:28 -04:00
|
|
|
|
2009-09-28 00:31:15 -04:00
|
|
|
def initialize(attributes)
|
|
|
|
@group_name ||= []
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2009-10-30 02:35:28 -04:00
|
|
|
def all(group_name = @group_name)
|
2010-01-05 01:03:24 -05:00
|
|
|
@group_name = group_name
|
|
|
|
if @loaded
|
|
|
|
clear
|
|
|
|
end
|
|
|
|
@loaded = true
|
2009-09-28 23:00:49 -04:00
|
|
|
data = connection.describe_security_groups(group_name).body
|
2009-09-18 11:56:42 -04:00
|
|
|
data['securityGroupInfo'].each do |security_group|
|
2010-01-05 01:03:24 -05:00
|
|
|
self << new(security_group)
|
2009-09-18 11:56:42 -04:00
|
|
|
end
|
2010-01-05 01:03:24 -05:00
|
|
|
self
|
2009-09-18 11:56:42 -04:00
|
|
|
end
|
|
|
|
|
2009-09-25 12:01:51 -04:00
|
|
|
def get(group_name)
|
2009-10-22 23:46:15 -04:00
|
|
|
if group_name
|
|
|
|
all(group_name).first
|
|
|
|
end
|
2009-11-08 15:16:52 -05:00
|
|
|
rescue Excon::Errors::BadRequest
|
2009-09-25 12:01:51 -04:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2009-09-18 11:56:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|