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

[openstack|compute] added security group models

This commit is contained in:
Hunter Nield 2012-02-16 17:53:29 +08:00 committed by Nelvin Driz
parent 2a552c4801
commit 19591ffd06
3 changed files with 74 additions and 0 deletions

View file

@ -22,6 +22,8 @@ module Fog
collection :metadata
model :key_pair
collection :key_pairs
model :security_group
collection :security_groups
request_path 'fog/openstack/requests/compute'

View file

@ -0,0 +1,45 @@
require 'fog/core/model'
module Fog
module Compute
class Openstack
class SecurityGroup < Fog::Model
identity :id
attribute :name
attribute :description
attribute :rules
attribute :tenant_id
def save
requires :name, :description
data = connection.create_security_group(name, description)
merge_attributes(data.body['security_group'])
true
end
def destroy
requires :id
connection.delete_security_group(id)
true
end
def create_security_group_rule(min, max, ip_protocol = "tcp", cidr = "0.0.0.0/0", group_id = nil)
requires :id
connection.create_security_group_rule(id, ip_protocol, min, max, cidr, group_id)
end
def delete_security_group_rule(rule_id)
connection.delete_security_group_rule(rule_id)
true
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/core/collection'
require 'fog/openstack/models/compute/security_group'
module Fog
module Compute
class Openstack
class SecurityGroups < Fog::Collection
model Fog::Compute::Openstack::SecurityGroup
def all
load(connection.list_security_groups.body['security_groups'])
end
def get(security_group_id)
if security_group_id
new(connection.get_security_group(security_group_id).body['security_group'])
end
rescue Fog::Compute::Openstack::NotFound
nil
end
end
end
end
end