1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/requests/ec2/create_security_group.rb

63 lines
1.6 KiB
Ruby
Raw Normal View History

unless Fog.mocking?
module Fog
module AWS
class EC2
# Create a new security group
#
# ==== Parameters
# * group_name<~String> - Name of the security group.
# * group_description<~String> - Description of group.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'return'<~Boolean> - success?
def create_security_group(name, description)
request(
'Action' => 'CreateSecurityGroup',
'GroupName' => name,
'GroupDescription' => CGI.escape(description),
:parser => Fog::Parsers::AWS::EC2::Basic.new
)
end
end
end
end
else
module Fog
module AWS
class EC2
def create_security_group(name, description)
2009-11-20 14:08:08 -05:00
response = Excon::Response.new
unless Fog::AWS::EC2.data[:security_groups][name]
data = {
2009-09-12 14:35:14 -04:00
'groupDescription' => description,
'groupName' => name,
'ipPermissions' => [],
2009-09-12 14:35:14 -04:00
'ownerId' => Fog::AWS::Mock.owner_id
}
Fog::AWS::EC2.data[:security_groups][name] = data
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'return' => true
}
else
response.status = 400
2009-11-20 14:08:08 -05:00
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response
end
end
end
end
end