Sha256: 97d0d629a5818cc05513e651c2c6a50f89dcf91b81b9bd75aa8d906fcdf412f3

Contents?: true

Size: 1.96 KB

Versions: 65

Compression:

Stored size: 1.96 KB

Contents

module Fog
  module Compute
    class Cloudstack
      class SecurityGroupRule < Fog::Model

        identity  :id,                :aliases => 'ruleid'

        attribute :security_group_id, :type => :string
        attribute :protocol,          :type => :string
        attribute :start_port,        :type => :integer, :aliases => 'startport'
        attribute :end_port,          :type => :integer, :aliases => 'endport'
        attribute :cidr,              :type => :string
        attribute :direction,         :type => :string

        def destroy
          data = service.send("revoke_security_group_#{self.direction}", "id" => self.id)
          job = service.jobs.new(data["revokesecuritygroup#{self.direction}"])
          job.wait_for { ready? }
          job.successful?
        end

        def port_range
          (self.start_port..self.end_port)
        end

        def save
          requires :security_group_id, :cidr, :direction

          data = service.send("authorize_security_group_#{self.direction}".to_sym, params)
          job = service.jobs.new(data["authorizesecuritygroup#{self.direction}response"])
          job.wait_for { ready? }
          # durty
          merge_attributes(job.result.send("#{self.direction}_rules").last)
          self
        end

        def security_group
          service.security_groups.get(self.security_group_id)
        end

        def reload
          requires :id, :security_group_id, :cidr

          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

Version data entries

65 entries across 65 versions & 6 rubygems

Version Path
fog-1.22.0 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-1.21.0 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-1.20.0 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-1.19.0 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/cloudstack/models/compute/security_group_rule.rb