Sha256: 20ae67449606f7efba4827429c341651408796540f05e37914a73f6cc296f5f5

Contents?: true

Size: 1.9 KB

Versions: 11

Compression:

Stored size: 1.9 KB

Contents

require 'fog/core/model'

module Fog
  module Terremark
    module Shared

      class InternetService < Fog::Model

        identity :Id

        attribute :Name
        attribute :Port
        attribute :Protocol
        attribute :Description
        attribute :PublicIpAddress
        attribute :public_ip_address_id

        def destroy(delete_public_ip=true)
          connection.delete_internet_service(self.Id)
          connection.delete_public_ip(self.PublicIpAddress["Id"]) if delete_public_ip
        true
        end

        def save
          requires :Name, :Protocol, :Port
          if not public_ip_address_id
            #Create the first internet service and allocate public IP
            data = connection.create_internet_service(
                vdc = connection.default_vdc_id,
                name = self.Name,
                protocol = self.Protocol,
                port = self.Port,
                options = {
                        'Enabled' => 'true',
                        "Description" => self.Name
                }
            )
          else
            #create additional services to existing Public IP
            data = connection.add_internet_service(
                      ip_id = public_ip_address_id,
                      name = self.Name,
                      protocol = self.Protocol,
                      port = self.Port,
                      options = {
                        'Enabled' => 'true',
                        "Description" => self.Name
                        }
                    )           
            end
            merge_attributes(data.body)
            true
        end
        private

        def href=(new_href)
          self.id = new_href.split('/').last.to_i
        end

        def type=(new_type); @type = new_type; end
        def size=(new_size); @size = new_size; end
        def Links=(new_links); @Links = new_links; end

      end
    end
  end
end

Version data entries

11 entries across 11 versions & 7 rubygems

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