Sha256: 0b2f9bdb780eecac45b010ec6bd9e13220603e1bbf51789303ed810b1b87c37e

Contents?: true

Size: 1.88 KB

Versions: 28

Compression:

Stored size: 1.88 KB

Contents

module Fog
  module Compute
    class Google
      class TargetInstance < Fog::Model
        identity :name

        attribute :creation_timestamp, :aliases => "creationTimestamp"
        attribute :description
        attribute :id
        attribute :instance
        attribute :kind
        attribute :nat_policy, :aliases => "natPolicy"
        attribute :self_link, :aliases => "selfLink"
        attribute :zone

        def save
          requires :identity, :zone

          options = {
            :description => description,
            :zone => zone,
            :nat_policy => nat_policy,
            :instance => instance
          }

          data = service.insert_target_instance(identity, zone, options)
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name, data.zone)
          operation.wait_for { ready? }
          reload
        end

        def destroy(async = true)
          requires :name, :zone
          data = service.delete_target_instance(name, zone)
          operation = Fog::Compute::Google::Operations.new(:service => service)
                                                      .get(data.name, data.zone)
          operation.wait_for { ready? } unless async
          operation
        end

        def ready?
          service.get_target_instance(name, zone)
          true
        rescue ::Google::Apis::ClientError => e
          raise e unless e.status_code == 404
          false
        end

        def reload
          requires :name, :zone

          begin
            data = collection.get(name, zone)
            new_attributes = data.attributes
            merge_attributes(new_attributes)
            return self
          rescue Excon::Errors::SocketError
            return nil
          end
        end

        RUNNING_STATE = "READY".freeze
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
fog-google-1.24.1 lib/fog/compute/google/models/target_instance.rb
fog-google-1.24.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.23.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.22.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.21.1 lib/fog/compute/google/models/target_instance.rb
fog-google-1.21.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.20.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.19.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.18.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.17.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.16.1 lib/fog/compute/google/models/target_instance.rb
fog-google-1.16.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.15.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.14.0 lib/fog/compute/google/models/target_instance.rb
gitlab-fog-google-1.14.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.13.0 lib/fog/compute/google/models/target_instance.rb
gitlab-fog-google-1.13.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.12.1 lib/fog/compute/google/models/target_instance.rb
fog-google-1.12.0 lib/fog/compute/google/models/target_instance.rb
fog-google-1.11.0 lib/fog/compute/google/models/target_instance.rb