mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
first pass at security group models
This commit is contained in:
parent
eea51b719f
commit
528fdb4ed3
2 changed files with 79 additions and 0 deletions
40
lib/fog/aws/models/ec2/security_group.rb
Normal file
40
lib/fog/aws/models/ec2/security_group.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
class SecurityGroup < Fog::Model
|
||||
|
||||
attribute :group_description, 'groupDescription'
|
||||
attribute :group_name, 'groupName'
|
||||
attribute :ip_permissions, 'ipPermissions'
|
||||
attribute :owner_id, 'ownerId'
|
||||
|
||||
def delete
|
||||
connection.delete_security_group(@group_name)
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
data = connection.create_create_security_group(@group_name, @group_description).body
|
||||
true
|
||||
end
|
||||
|
||||
def security_groups
|
||||
@security_groups ||= begin
|
||||
Fog::AWS::S3::SecurityGroups.new(
|
||||
:connection => connection
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def security_groups=(new_security_groups)
|
||||
@security_groups = new_security_groups
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
39
lib/fog/aws/models/ec2/security_groups.rb
Normal file
39
lib/fog/aws/models/ec2/security_groups.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class EC2
|
||||
|
||||
def security_groups
|
||||
Fog::AWS::EC2::SecurityGroups.new(:connection => self)
|
||||
end
|
||||
|
||||
class SecurityGroups < Fog::Collection
|
||||
|
||||
def all(group_name = [])
|
||||
data = connection.describe_security_groups(group_name)
|
||||
security_groups = Fog::AWS::EC2::SecurityGroups.new(:connection => connection)
|
||||
data['securityGroupInfo'].each do |security_group|
|
||||
security_groups << Fog::AWS::EC2::SecurityGroup.new({
|
||||
:connection => connection
|
||||
}.merge!(security_group))
|
||||
end
|
||||
security_groups
|
||||
end
|
||||
|
||||
def create(attributes = {})
|
||||
security_group = new(attributes)
|
||||
security_group.save
|
||||
security_group
|
||||
end
|
||||
|
||||
def new(attributes = {})
|
||||
Fog::AWS::S3::SecurityGroup.new({
|
||||
:connection => connection,
|
||||
:security_groups => self
|
||||
}.merge!(attributes))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue