2012-07-17 18:24:04 -04:00
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Cloudstack
|
|
|
|
class SecurityGroupRule < Fog::Model
|
|
|
|
|
|
|
|
identity :id, :aliases => 'ruleid'
|
|
|
|
|
|
|
|
attribute :security_group_id, :type => :string
|
|
|
|
attribute :protocol, :type => :string
|
2012-07-20 12:50:28 -04:00
|
|
|
attribute :start_port, :type => :integer, :aliases => 'startport'
|
|
|
|
attribute :end_port, :type => :integer, :aliases => 'endport'
|
2012-07-17 18:24:04 -04:00
|
|
|
attribute :cidr, :type => :string
|
|
|
|
attribute :direction, :type => :string
|
|
|
|
|
|
|
|
def destroy
|
2012-12-22 18:28:53 -05:00
|
|
|
data = service.send("revoke_security_group_#{self.direction}", "id" => self.id)
|
|
|
|
job = service.jobs.new(data["revokesecuritygroup#{self.direction}"])
|
2012-07-17 18:24:04 -04:00
|
|
|
job.wait_for { ready? }
|
|
|
|
job.successful?
|
|
|
|
end
|
|
|
|
|
2012-07-20 12:50:28 -04:00
|
|
|
def port_range
|
|
|
|
(self.start_port..self.end_port)
|
|
|
|
end
|
|
|
|
|
2012-07-17 18:24:04 -04:00
|
|
|
def save
|
|
|
|
requires :security_group_id, :cidr, :direction
|
|
|
|
|
2012-12-22 18:28:53 -05:00
|
|
|
data = service.send("authorize_security_group_#{self.direction}".to_sym, params)
|
|
|
|
job = service.jobs.new(data["authorizesecuritygroup#{self.direction}response"])
|
2012-07-17 18:24:04 -04:00
|
|
|
job.wait_for { ready? }
|
|
|
|
# durty
|
|
|
|
merge_attributes(job.result.send("#{self.direction}_rules").last)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def security_group
|
2012-12-22 18:28:53 -05:00
|
|
|
service.security_groups.get(self.security_group_id)
|
2012-07-17 18:24:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
requires :id, :security_group_id, :cidr
|
2012-07-20 12:50:28 -04:00
|
|
|
|
2012-07-17 18:24:04 -04:00
|
|
|
merge_attributes(security_group.rules.get(self.id))
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def params
|
|
|
|
options = {
|
|
|
|
"securitygroupid" => self.security_group_id,
|
|
|
|
"protocol" => self.protocol,
|
|
|
|
"cidrlist" => self.cidr
|
|
|
|
}
|
|
|
|
options.merge!("startport" => self.start_port) unless self.start_port.nil?
|
|
|
|
options.merge("endport" => self.end_port) unless self.end_port.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
end # SecurityGroupRule
|
|
|
|
end # Cloudstack
|
|
|
|
end # Compute
|
|
|
|
end # Fog
|