Sha256: 19c1d7e7296cc483874a0b24c247883bd758fb73d286f70b055f241fb2dfbc64

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

require 'fog/openstack/models/model'

module Fog
  module Network
    class OpenStack
      class FloatingIp < Fog::OpenStack::Model
        identity :id

        attribute :floating_network_id
        attribute :port_id
        attribute :tenant_id
        attribute :fixed_ip_address
        attribute :floating_ip_address

        def initialize(attributes)
          @connection = attributes[:connection]
          super
        end

        def create
          requires :floating_network_id
          merge_attributes(service.create_floating_ip(self.floating_network_id,

                                                      self.attributes).body['floatingip'])
          self
        end

        def update
          self
        end

        def destroy
          requires :id
          service.delete_floating_ip(self.id)
          true
        end

        def associate(port_id, fixed_ip_address = nil)
          requires :id
          options = if !fixed_ip_address.nil?
                      { 'fixed_ip_address': fixed_ip_address }
                    else
                      {}
                    end
          merge_attributes(service.associate_floating_ip(self.id,
                                                         port_id,
                                                         options).body['floatingip'])
        end

        def disassociate(fixed_ip_address = nil)
          requires :id
          options = if !fixed_ip_address.nil?
                      { 'fixed_ip_address': fixed_ip_address }
                    else
                      {}
                    end
          merge_attributes(service.disassociate_floating_ip(self.id,
                                                            options).body['floatingip'])
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fog-openstack-0.1.1 lib/fog/openstack/models/network/floating_ip.rb