1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Add code to support the creation and modification of security groups existing in a VPC

This commit is contained in:
Eric Stonfer 2011-12-23 08:40:47 -05:00
parent 351a7dea17
commit 9a94955597
5 changed files with 17 additions and 7 deletions

View file

@ -22,6 +22,7 @@ module Fog
service(:sqs, 'aws/sqs', 'SQS') service(:sqs, 'aws/sqs', 'SQS')
service(:sts, 'aws/sts', 'STS') service(:sts, 'aws/sts', 'STS')
service(:storage, 'aws/storage', 'Storage') service(:storage, 'aws/storage', 'Storage')
service(:vpc, 'aws/vpc', 'VPC')
def self.indexed_param(key, values) def self.indexed_param(key, values)
params = {} params = {}

View file

@ -11,6 +11,7 @@ module Fog
attribute :group_id, :aliases => 'groupId' attribute :group_id, :aliases => 'groupId'
attribute :ip_permissions, :aliases => 'ipPermissions' attribute :ip_permissions, :aliases => 'ipPermissions'
attribute :owner_id, :aliases => 'ownerId' attribute :owner_id, :aliases => 'ownerId'
attribute :vpc_id, :aliases => 'vpcId'
# Authorize access by another security group # Authorize access by another security group
# #
@ -193,8 +194,11 @@ module Fog
def save def save
requires :description, :name requires :description, :name
if (vpc_id.length)
data = connection.create_security_group(name, description).body data = connection.create_security_group(name, description, vpc_id).body
else
data = connection.create_security_group(name, description).body
end
true true
end end

View file

@ -25,6 +25,7 @@ module Fog
# description=nil, # description=nil,
# ip_permissions=nil, # ip_permissions=nil,
# owner_id=nil # owner_id=nil
# vpc_id=nil
# > # >
# #
@ -50,6 +51,7 @@ module Fog
# description="default group", # description="default group",
# ip_permissions=[{"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>-1, "toPort"=>-1, "ipRanges"=>[], "ipProtocol"=>"icmp"}, {"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>0, "toPort"=>65535, "ipRanges"=>[], "ipProtocol"=>"tcp"}, {"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>0, "toPort"=>65535, "ipRanges"=>[], "ipProtocol"=>"udp"}], # ip_permissions=[{"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>-1, "toPort"=>-1, "ipRanges"=>[], "ipProtocol"=>"icmp"}, {"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>0, "toPort"=>65535, "ipRanges"=>[], "ipProtocol"=>"tcp"}, {"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>0, "toPort"=>65535, "ipRanges"=>[], "ipProtocol"=>"udp"}],
# owner_id="312571045469" # owner_id="312571045469"
# vpc_id=nill
# > # >
# ] # ]
# > # >
@ -79,6 +81,7 @@ module Fog
# description="default group", # description="default group",
# ip_permissions=[{"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>-1, "toPort"=>-1, "ipRanges"=>[], "ipProtocol"=>"icmp"}, {"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>0, "toPort"=>65535, "ipRanges"=>[], "ipProtocol"=>"tcp"}, {"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>0, "toPort"=>65535, "ipRanges"=>[], "ipProtocol"=>"udp"}], # ip_permissions=[{"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>-1, "toPort"=>-1, "ipRanges"=>[], "ipProtocol"=>"icmp"}, {"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>0, "toPort"=>65535, "ipRanges"=>[], "ipProtocol"=>"tcp"}, {"groups"=>[{"groupName"=>"default", "userId"=>"312571045469"}], "fromPort"=>0, "toPort"=>65535, "ipRanges"=>[], "ipProtocol"=>"udp"}],
# owner_id="312571045469" # owner_id="312571045469"
# vpc_id=nil
# > # >
# #

View file

@ -40,7 +40,7 @@ module Fog
end end
when 'groups' when 'groups'
@in_groups = false @in_groups = false
when 'groupDescription', 'ownerId', 'groupId' when 'groupDescription', 'ownerId', 'groupId', 'vpcId'
@security_group[name] = value @security_group[name] = value
when 'groupName' when 'groupName'
if @in_groups if @in_groups

View file

@ -18,12 +18,13 @@ module Fog
# * 'return'<~Boolean> - success? # * 'return'<~Boolean> - success?
# #
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSecurityGroup.html] # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSecurityGroup.html]
def create_security_group(name, description) def create_security_group(name, description, vpc_id='')
request( request(
'Action' => 'CreateSecurityGroup', 'Action' => 'CreateSecurityGroup',
'GroupName' => name, 'GroupName' => name,
'GroupDescription' => description, 'GroupDescription' => description,
:parser => Fog::Parsers::Compute::AWS::Basic.new :parser => Fog::Parsers::Compute::AWS::Basic.new,
'VpcId' => vpc_id
) )
end end
@ -31,7 +32,7 @@ module Fog
class Mock class Mock
def create_security_group(name, description) def create_security_group(name, description, vpc_id='')
response = Excon::Response.new response = Excon::Response.new
unless self.data[:security_groups][name] unless self.data[:security_groups][name]
data = { data = {
@ -39,7 +40,8 @@ module Fog
'groupName' => name, 'groupName' => name,
'ipPermissionsEgress' => [], 'ipPermissionsEgress' => [],
'ipPermissions' => [], 'ipPermissions' => [],
'ownerId' => self.data[:owner_id] 'ownerId' => self.data[:owner_id],
'vpcId' => vpc_id
} }
self.data[:security_groups][name] = data self.data[:security_groups][name] = data
response.body = { response.body = {