Class: Fog::Compute::Google::ResourceView

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

Overview

the resource view model creates either a region view or zone view depending on which is parameter is passed

Constant Summary collapse

RUNNING_STATE =
"READY"

Instance Method Summary collapse

Instance Method Details

#add_resources(resources) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/fog/compute/google/models/resource_view.rb', line 75

def add_resources(resources)
  resources = [resources] unless resources.class == Array
  resources.map { |resource| resource.class == String ? resource : resource.self_link }
  service.add_zone_view_resources(self, resources, @zone) if @zone
  service.add_region_view_resources(self, resources, @region) if @region
  reload
end

#destroy(async = false) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fog/compute/google/models/resource_view.rb', line 53

def destroy(async = false)
  requires :name
  # parse the self link to get the zone or region
  selflink = self_link.split("/")
  if selflink[7] == "regions"
    operation = service.delete_region_view(name, selflink[8])
  end

  if selflink[7] == "zones"
    operation = service.delete_zone_view(name, selflink[8])
  end

  unless async
    # wait until "DONE" to ensure the operation doesn't fail, raises
    # exception on error
    Fog.wait_for do
      operation.body.nil?
    end
  end
  operation
end

#ready?Boolean

Returns:

  • (Boolean)


83
84
85
86
87
88
89
# File 'lib/fog/compute/google/models/resource_view.rb', line 83

def ready?
  service.get_zone_view(name, @zone) if @zone
  service.get_region_view(name, @region) if @region
  true
rescue Fog::Errors::NotFound
  false
end

#reloadObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/fog/compute/google/models/resource_view.rb', line 91

def reload
  requires :name

  return unless data = begin
    collection.get(name, region, zone)
  rescue Excon::Errors::SocketError
    nil
  end

  new_attributes = data.attributes
  merge_attributes(new_attributes)
  self
end

#saveObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/compute/google/models/resource_view.rb', line 20

def save
  requires :name
  labels ||= []
  members ||= []

  if region
    options = {
      "description" => description,
      "labels" => labels,
      "lastModified" => last_modified,
      "members" => members,
      "numMembers" => num_members
    }
    @region = region
    data = service.insert_region_view(name, region, options).body
    operation = service.get_region_view(data["resource"]["name"], nil, @region).body
  end

  if zone
    options = {
      "description" => description,
      "labels" => labels,
      "lastModified" => last_modified,
      "members" => members,
      "numMembers" => num_members
    }
    @zone = zone
    data = service.insert_zone_view(name, zone, options).body
    operation = service.get_zone_view(data["resource"]["name"], @zone).body
  end
  reload
end