Sha256: f4948f72df0e74c8f2ab86535acb8619522d8fa99adf5d96d5cdba225915e9c1

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

require 'fog/model'

module Fog
  module Vcloud
    module Terremark
      module Ecloud
        class InternetService < Fog::Vcloud::Model

          identity :href

          attribute :name
          attribute :id
          attribute :type
          attribute :protocol
          attribute :port
          attribute :enabled
          attribute :description
          attribute :public_ip
          attribute :timeout
          attribute :url_send_string
          attribute :http_header

          attr_accessor :new

          def delete
            requires :href

            connection.delete_internet_service( self.href )
            collection.reload
          end

          def save
            if new_record?
              result = connection.add_internet_service( collection.href, _compose_service_data )
              self.href = result.body.href
              self.reload
            else
              connection.configure_internet_service( self.href, _compose_service_data, _compose_ip_data )
            end
          end

          private

          def _compose_service_data
            service_data = {}
            self.class.attributes.select{ |attribute| !attribute.nil? }.each { |attribute| service_data[attribute] = send(attribute).to_s }
            service_data
          end

          def _compose_ip_data
            if public_ip.nil?
              {}
            else
              { :id => self.public_ip.id, :href => self.public_ip.href.to_s, :name => self.public_ip.name }
            end
          end

        end
      end
    end
  end
end


Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fog-0.2.0 lib/fog/vcloud/terremark/ecloud/models/internet_service.rb
fog-0.1.10 lib/fog/vcloud/terremark/ecloud/models/internet_service.rb
fog-0.1.9 lib/fog/vcloud/terremark/ecloud/models/internet_service.rb