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-09-28 00:31:15 -04:00
|
|
|
def initialize(attributes)
|
|
|
|
@group_name ||= []
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2009-09-18 11:56:42 -04:00
|
|
|
def all(group_name = [])
|
2009-09-28 23:00:49 -04:00
|
|
|
data = connection.describe_security_groups(group_name).body
|
2009-09-26 22:42:08 -04:00
|
|
|
security_groups = Fog::AWS::EC2::SecurityGroups.new({
|
2009-09-28 00:31:15 -04:00
|
|
|
:connection => connection,
|
|
|
|
:group_name => group_name
|
2009-09-26 22:42:08 -04:00
|
|
|
}.merge!(attributes))
|
2009-09-18 11:56:42 -04:00
|
|
|
data['securityGroupInfo'].each do |security_group|
|
|
|
|
security_groups << Fog::AWS::EC2::SecurityGroup.new({
|
2009-10-24 01:23:55 -04:00
|
|
|
:collection => security_groups,
|
|
|
|
:connection => connection
|
2009-09-18 11:56:42 -04:00
|
|
|
}.merge!(security_group))
|
|
|
|
end
|
|
|
|
security_groups
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(attributes = {})
|
|
|
|
security_group = new(attributes)
|
|
|
|
security_group.save
|
|
|
|
security_group
|
|
|
|
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-09-25 12:01:51 -04:00
|
|
|
rescue Fog::Errors::BadRequest
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2009-09-18 11:56:42 -04:00
|
|
|
def new(attributes = {})
|
2009-09-20 12:21:03 -04:00
|
|
|
Fog::AWS::EC2::SecurityGroup.new(
|
|
|
|
attributes.merge!(
|
2009-10-24 01:23:55 -04:00
|
|
|
:collection => self,
|
|
|
|
:connection => connection
|
2009-09-20 12:21:03 -04:00
|
|
|
)
|
|
|
|
)
|
2009-09-18 11:56:42 -04:00
|
|
|
end
|
|
|
|
|
2009-09-25 12:01:51 -04:00
|
|
|
def reload
|
|
|
|
all(group_name)
|
|
|
|
end
|
|
|
|
|
2009-09-18 11:56:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|