Class: Fog::Compute::Google::Disk
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::Google::Disk
show all
- Defined in:
- lib/fog/google/models/compute/disk.rb
Constant Summary
collapse
- RUNNING_STATE =
"READY"
Instance Attribute Summary
Attributes inherited from Model
#collection, #service
Instance Method Summary
collapse
Methods inherited from Model
#initialize, #inspect, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#connection, #connection=, #prepare_service_value
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Model
Instance Method Details
#create_snapshot(snapshot_name, snapshot_description = "") ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/fog/google/models/compute/disk.rb', line 87
def create_snapshot(snapshot_name, snapshot_description="")
requires :name
requires :zone_name
if snap_name.nil? or snap_name.empty?
raise ArgumentError, 'Invalid snapshot name'
end
options = {
'name' => snapshot_name,
'description' => snapshot_description,
}
service.insert_snapshot(name, self.zone, service.project, options)
data = service.backoff_if_unfound {
service.get_snapshot(snapshot_name, service.project).body
}
service.snapshots.merge_attributes(data)
service.snapshots.get(snapshot_name)
end
|
#destroy ⇒ Object
39
40
41
42
|
# File 'lib/fog/google/models/compute/disk.rb', line 39
def destroy
requires :name, :zone_name
service.delete_disk(name, zone_name)
end
|
#get_as_boot_disk(writable = true) ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/fog/google/models/compute/disk.rb', line 54
def get_as_boot_disk(writable=true)
mode = writable ? 'READ_WRITE' : 'READ_ONLY'
return {
'name' => name,
'type' => 'PERSISTENT',
'boot' => true,
'source' => self_link,
'mode' => mode
}
end
|
#ready? ⇒ Boolean
65
66
67
68
69
70
|
# File 'lib/fog/google/models/compute/disk.rb', line 65
def ready?
data = service.get_disk(self.name, self.zone_name).body
data['zone_name'] = self.zone_name
self.merge_attributes(data)
self.status == RUNNING_STATE
end
|
#reload ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/fog/google/models/compute/disk.rb', line 72
def reload
requires :identity
requires :zone_name
return unless data = begin
collection.get(identity, zone_name)
rescue Excon::Errors::SocketError
nil
end
new_attributes = data.attributes
merge_attributes(new_attributes)
self
end
|
#save ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/fog/google/models/compute/disk.rb', line 23
def save
requires :name
requires :zone_name
options = {}
if source_image.nil?
options['sourceSnapshot'] = source_snapshot
end
options['sizeGb'] = size_gb
data = service.insert_disk(name, zone_name, source_image, options).body
data = service.backoff_if_unfound {service.get_disk(name, zone_name).body}
service.disks.merge_attributes(data)
end
|
#zone ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/fog/google/models/compute/disk.rb', line 44
def zone
if self.zone_name.is_a? String
service.get_zone(self.zone_name.split('/')[-1]).body["name"]
elsif zone_name.is_a? Excon::Response
service.get_zone(zone_name.body["name"]).body["name"]
else
self.zone_name
end
end
|