2012-07-17 18:24:04 -04:00
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Cloudstack
|
|
|
|
class SecurityGroup < Fog::Model
|
|
|
|
identity :id, :aliases => 'id'
|
|
|
|
attribute :name, :type => :string
|
|
|
|
attribute :description, :type => :string
|
|
|
|
attribute :account, :type => :string
|
|
|
|
attribute :domain_id, :aliases => "domainid", :type => :string
|
|
|
|
attribute :domain_name, :aliases => "domain", :type => :string
|
|
|
|
attribute :project_id, :aliases => "projectid", :type => :string
|
|
|
|
attribute :project_name, :aliases => "project", :type => :string
|
|
|
|
attribute :ingress_rules, :aliases => "ingressrule", :type => :array
|
|
|
|
attribute :egress_rules, :aliases => "egressrule", :type => :array
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :id
|
2012-12-22 18:28:53 -05:00
|
|
|
service.delete_security_group('id' => self.id)
|
2012-07-17 18:24:04 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def egress_rules
|
|
|
|
attributes[:egress_rules] || []
|
|
|
|
end
|
|
|
|
|
|
|
|
def ingress_rules
|
|
|
|
attributes[:ingress_rules] || []
|
|
|
|
end
|
|
|
|
|
2012-07-18 19:00:32 -04:00
|
|
|
def save
|
|
|
|
requires :name
|
|
|
|
|
|
|
|
options = {
|
|
|
|
'name' => self.name,
|
|
|
|
'account' => self.account,
|
|
|
|
'description' => self.description,
|
|
|
|
'projectid' => self.project_id,
|
|
|
|
'domainid' => self.domain_id,
|
|
|
|
}
|
2012-12-22 18:28:53 -05:00
|
|
|
data = service.create_security_group(options)
|
2012-07-18 19:00:32 -04:00
|
|
|
merge_attributes(data['createsecuritygroupresponse']['securitygroup'])
|
|
|
|
end
|
|
|
|
|
2012-07-17 18:24:04 -04:00
|
|
|
def rules
|
2012-12-22 18:28:53 -05:00
|
|
|
service.security_group_rules.all("security_group_id" => self.id)
|
2012-07-17 18:24:04 -04:00
|
|
|
end
|
|
|
|
end # SecurityGroup
|
|
|
|
end # Cloudstack
|
|
|
|
end # Compute
|
|
|
|
end # Fog
|