Sha256: 67832d1d99eb3c10b296079e1f968d1e4aa31dcd76ed134addd387b1505802b7

Contents?: true

Size: 1.97 KB

Versions: 12

Compression:

Stored size: 1.97 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 = connection.send("revoke_security_group_#{self.direction}", "id" => self.id)
          job = connection.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 = connection.send("authorize_security_group_#{self.direction}".to_sym, params)
          job = connection.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
          connection.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

12 entries across 12 versions & 7 rubygems

Version Path
fog-nirvanix-1.8.2 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-nirvanix-1.8.1 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-parser-fix-1.6.1 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-test-again-1.6.0 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-parser-fix-1.6.0 lib/fog/cloudstack/models/compute/security_group_rule.rb
ey-vendored-backup-3.0.27 vendor/gems/fog/lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-sgonyea-1.8.1 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-1.8.0 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-maestrodev-1.7.0.20121114190951 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-1.7.0 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-1.6.0 lib/fog/cloudstack/models/compute/security_group_rule.rb
fog-1.5.0 lib/fog/cloudstack/models/compute/security_group_rule.rb