2010-03-16 18:46:21 -04:00
|
|
|
require 'fog/model'
|
|
|
|
|
2009-09-18 11:56:42 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2010-03-16 18:46:21 -04:00
|
|
|
module EC2
|
2009-09-18 11:56:42 -04:00
|
|
|
|
|
|
|
class SecurityGroup < Fog::Model
|
|
|
|
|
2009-12-05 17:53:42 -05:00
|
|
|
identity :name, 'groupName'
|
2009-10-24 01:23:55 -04:00
|
|
|
|
2009-12-05 17:53:42 -05:00
|
|
|
attribute :description, 'groupDescription'
|
|
|
|
attribute :ip_permissions, 'ipPermissions'
|
|
|
|
attribute :owner_id, 'ownerId'
|
2009-09-18 11:56:42 -04:00
|
|
|
|
2009-10-24 14:20:05 -04:00
|
|
|
def authorize_group_and_owner(group, owner)
|
2009-12-05 17:53:42 -05:00
|
|
|
requires :name
|
2009-11-21 16:56:39 -05:00
|
|
|
|
2009-10-24 14:20:05 -04:00
|
|
|
connection.authorize_security_group_ingress(
|
2009-12-05 17:53:42 -05:00
|
|
|
'GroupName' => @name,
|
2009-10-24 14:20:05 -04:00
|
|
|
'SourceSecurityGroupName' => group,
|
|
|
|
'SourceSecurityGroupOwnerId' => owner
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_port_range(range, options = {})
|
2009-12-05 17:53:42 -05:00
|
|
|
requires :name
|
2009-11-21 16:56:39 -05:00
|
|
|
|
2009-10-24 14:20:05 -04:00
|
|
|
connection.authorize_security_group_ingress(
|
|
|
|
'CidrIp' => options[:cidr_ip] || '0.0.0.0/0',
|
|
|
|
'FromPort' => range.min,
|
2009-12-05 17:53:42 -05:00
|
|
|
'GroupName' => @name,
|
2009-10-24 14:20:05 -04:00
|
|
|
'ToPort' => range.max,
|
|
|
|
'IpProtocol' => options[:ip_protocol] || 'tcp'
|
|
|
|
)
|
2009-10-23 17:37:04 -04:00
|
|
|
end
|
|
|
|
|
2009-09-20 12:21:03 -04:00
|
|
|
def destroy
|
2009-12-05 17:53:42 -05:00
|
|
|
requires :name
|
2009-11-21 16:56:39 -05:00
|
|
|
|
2009-12-05 17:53:42 -05:00
|
|
|
connection.delete_security_group(@name)
|
2009-09-18 11:56:42 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2010-01-21 22:23:46 -05:00
|
|
|
requires :description, :name
|
2009-11-21 16:56:39 -05:00
|
|
|
|
2009-12-05 17:53:42 -05:00
|
|
|
data = connection.create_security_group(@name, @description).body
|
2009-09-18 11:56:42 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|