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(:sts, 'aws/sts', 'STS')
service(:storage, 'aws/storage', 'Storage')
service(:vpc, 'aws/vpc', 'VPC')
def self.indexed_param(key, values)
params = {}

View file

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

View file

@ -25,6 +25,7 @@ module Fog
# description=nil,
# ip_permissions=nil,
# owner_id=nil
# vpc_id=nil
# >
#
@ -50,6 +51,7 @@ module Fog
# 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"}],
# owner_id="312571045469"
# vpc_id=nill
# >
# ]
# >
@ -79,6 +81,7 @@ module Fog
# 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"}],
# owner_id="312571045469"
# vpc_id=nil
# >
#

View file

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

View file

@ -18,12 +18,13 @@ module Fog
# * 'return'<~Boolean> - success?
#
# {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(
'Action' => 'CreateSecurityGroup',
'GroupName' => name,
'GroupDescription' => description,
:parser => Fog::Parsers::Compute::AWS::Basic.new
:parser => Fog::Parsers::Compute::AWS::Basic.new,
'VpcId' => vpc_id
)
end
@ -31,7 +32,7 @@ module Fog
class Mock
def create_security_group(name, description)
def create_security_group(name, description, vpc_id='')
response = Excon::Response.new
unless self.data[:security_groups][name]
data = {
@ -39,7 +40,8 @@ module Fog
'groupName' => name,
'ipPermissionsEgress' => [],
'ipPermissions' => [],
'ownerId' => self.data[:owner_id]
'ownerId' => self.data[:owner_id],
'vpcId' => vpc_id
}
self.data[:security_groups][name] = data
response.body = {