2011-06-15 02:10:54 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class HP
|
|
|
|
|
|
|
|
class SecurityGroup < Fog::Model
|
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :name
|
|
|
|
attribute :description
|
|
|
|
attribute :rules
|
|
|
|
attribute :tenant_id
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :id
|
|
|
|
|
2012-12-22 18:26:21 -05:00
|
|
|
service.delete_security_group(id)
|
2011-06-15 02:10:54 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
requires :name, :description
|
|
|
|
|
2012-12-22 18:26:21 -05:00
|
|
|
data = service.create_security_group(name, description)
|
2011-06-15 02:10:54 -04:00
|
|
|
merge_attributes(data.body['security_group'])
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_rule(range, ip_protocol = "tcp", cidr = "0.0.0.0/0", group_id=nil)
|
|
|
|
requires :id
|
2012-12-22 18:26:21 -05:00
|
|
|
service.create_security_group_rule(id, ip_protocol, range.min, range.max, cidr, group_id)
|
2011-06-15 02:10:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def delete_rule(rule_id)
|
2012-12-22 18:26:21 -05:00
|
|
|
service.delete_security_group_rule(rule_id)
|
2011-06-15 02:10:54 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_all_rules()
|
|
|
|
self.rules.each do |rule|
|
|
|
|
delete_rule(rule['id'])
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|