Sha256: 1bfefef97c6814c6f9d77209f70c074874b8ee042be308317384995672e0d693

Contents?: true

Size: 1.73 KB

Versions: 45

Compression:

Stored size: 1.73 KB

Contents

require 'fog/core/model'

module Fog
  module Compute
    class Ninefold

      class IpForwardingRule < Fog::Model

        identity  :id

        attribute :protocol
        attribute :virtualmachineid
        attribute :virtualmachinename
        attribute :ipaddressid
        attribute :ipaddress
        attribute :startport
        attribute :endport
        attribute :state

        attribute :jobid

        def initialize(attributes={})
          super
        end

        def destroy
          requires :identity
          self.jobid = extract_job_id(connection.delete_ip_forwarding_rule(:id => identity))
          true
        end

        def ready?
          if jobid && connection.query_async_job_result(:jobid => jobid)['jobstatus'] == 0
            false
          else # No running job, we are ready. Refresh data.
            reload
            true
          end
        end

        def address
          Ninefold.address.get(ipaddressid)
        end

        def address=(addr)
          self.ipaddressid = addr.identity
        end

        def save
          raise "Operation not supported" if self.identity
          requires :ipaddressid
          requires :protocol
          requires :startport

          options = {
            :ipaddressid => ipaddressid,
            :protocol => protocol,
            :startport => startport,
            :endport => endport
          }.delete_if {|k,v| v.nil? || v == "" }
          data = connection.create_ip_forwarding_rule(options)
          merge_attributes(data)
          true
        end

        private

        def extract_job_id(job)
          if job.kind_of? Integer
            job
          else
            job['jobid'] || job['id']
          end
        end

      end
    end
  end
end

Version data entries

45 entries across 45 versions & 14 rubygems

Version Path
fog-nirvanix-1.8.2 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-nirvanix-1.8.1 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-parser-fix-1.6.1 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-test-again-1.6.0 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-parser-fix-1.6.0 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
ey-vendored-backup-3.0.27 vendor/gems/fog/lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-sgonyea-1.8.1 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-1.8.0 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-maestrodev-1.7.0.20121114190951 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-1.7.0 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-1.6.0 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-1.5.0 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-1.4.0 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
brightbox-cli-0.18.1 lib/brightbox-cli/vendor/fog/lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
michiels-fog-1.3.1 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
ftl-0.2.0 vendor/bundle/gems/fog-1.3.1/lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
brightbox-cli-0.18.0 lib/brightbox-cli/vendor/fog/lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-1.3.1 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
fog-1.3.0 lib/fog/ninefold/models/compute/ip_forwarding_rule.rb
brightbox-cli-0.17.5 lib/brightbox-cli/vendor/fog/lib/fog/ninefold/models/compute/ip_forwarding_rule.rb