Class: Fog::Compute::Google::Address

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/google/models/compute/address.rb

Overview

Represents an Address resource

Constant Summary collapse

IN_USE_STATE =
'IN_USE'
RESERVED_STATE =
'RESERVED'

Instance Method Summary collapse

Instance Method Details

#destroy(async = true) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/google/models/compute/address.rb', line 46

def destroy(async=true)
  requires :identity, :region

  data = service.delete_address(identity, self.region.split('/')[-1])
  operation = Fog::Compute::Google::Operations.new(:service => service).get(data.body['name'], nil, data.body['region'])
  unless async
    operation.wait_for { ready? }
  end
  operation
end

#in_use?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/fog/google/models/compute/address.rb', line 65

def in_use?
  self.status == IN_USE_STATE
end

#reloadObject



57
58
59
60
61
62
63
# File 'lib/fog/google/models/compute/address.rb', line 57

def reload
  requires :identity, :region

  data = collection.get(identity, self.region.split('/')[-1])
  merge_attributes(data.attributes)
  self
end

#saveObject



37
38
39
40
41
42
43
44
# File 'lib/fog/google/models/compute/address.rb', line 37

def save
  requires :identity, :region

  data = service.insert_address(identity, self.region, self.attributes)
  operation = Fog::Compute::Google::Operations.new(:service => service).get(data.body['name'], nil, data.body['region'])
  operation.wait_for { !pending? }
  reload
end

#serverObject



26
27
28
29
30
# File 'lib/fog/google/models/compute/address.rb', line 26

def server
  return nil if !in_use? || self.users.nil? || self.users.empty?

  service.servers.get(self.users.first.split('/')[-1])
end

#server=(server) ⇒ Object



32
33
34
35
# File 'lib/fog/google/models/compute/address.rb', line 32

def server=(server)
  requires :identity, :region
  server ? associate(server) : disassociate
end