Class: Fog::Compute::Google::ResourceView
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::Google::ResourceView
- Defined in:
- lib/fog/google/models/compute/resource_view.rb
Constant Summary collapse
- RUNNING_STATE =
"READY"
Instance Method Summary collapse
- #add_resources(resources) ⇒ Object
- #destroy(async = false) ⇒ Object
- #ready? ⇒ Boolean
- #reload ⇒ Object
- #save ⇒ Object
Instance Method Details
#add_resources(resources) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/fog/google/models/compute/resource_view.rb', line 77 def add_resources resources resources = [resources] unless resources.class == Array resources.map { |resource| resource.class == String ? resource : resource.self_link } if @zone then service.add_zone_view_resources(self, resources, @zone) end if @region then service.add_region_view_resources(self, reources, @region) end reload end |
#destroy(async = false) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fog/google/models/compute/resource_view.rb', line 55 def destroy(async=false) requires :name # parse the self link to get the zone or region selflink = self.self_link.split('/') if selflink[7]=='regions' then operation = service.delete_region_view(name, selflink[8]) end if selflink[7]== 'zones' then operation= service.delete_zone_view(name, selflink[8]) end if not 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
89 90 91 92 93 94 95 96 97 |
# File 'lib/fog/google/models/compute/resource_view.rb', line 89 def ready? begin if @zone then service.get_zone_view(self.name, @zone) end if @region then service.get_region_view(self.name, @region) end true rescue Fog::Errors::NotFound false end end |
#reload ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fog/google/models/compute/resource_view.rb', line 99 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 |
#save ⇒ Object
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 52 53 |
# File 'lib/fog/google/models/compute/resource_view.rb', line 22 def save requires :name labels ||= [] members ||= [] if region then = { 'description' => description, 'labels' => labels, 'lastModified' => last_modified, 'members' => members, 'numMembers' => num_members } @region = region data = service.insert_region_view(name, region, ).body operation = service.get_region_view(data['resource']['name'],nil, @region).body end if zone then = { 'description' => description, 'labels' => labels, 'lastModified' => last_modified, 'members' => members, 'numMembers' => num_members } @zone = zone data = service.insert_zone_view(name, zone, ).body operation = service.get_zone_view(data['resource']['name'], @zone).body end reload end |