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

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

Overview

Represents an Address resource

Constant Summary collapse

IN_USE_STATE =
"IN_USE".freeze
RESERVED_STATE =
"RESERVED".freeze
RESERVING_STATE =
"RESERVING".freeze

Instance Method Summary collapse

Instance Method Details

#destroy(async = true) ⇒ Object



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

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

  data = service.delete_address(identity, region.split("/")[-1])
  operation = Fog::Compute::Google::Operations
              .new(:service => service)
              .get(data.name, nil, data.region)

  operation.wait_for { ready? } unless async
  operation
end

#in_use?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/fog/compute/google/models/address.rb', line 67

def in_use?
  status == IN_USE_STATE
end

#ready?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/fog/compute/google/models/address.rb', line 71

def ready?
  status != RESERVING_STATE
end

#reloadObject



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

def reload
  requires :identity, :region

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

#saveObject



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

def save
  requires :identity, :region

  data = service.insert_address(identity, region, attributes)
  operation = Fog::Compute::Google::Operations
              .new(service: service)
              .get(data.name, nil, data.region)
  operation.wait_for { ready? }
  reload
end

#serverObject



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

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

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

#server=(server) ⇒ Object



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

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