Class: Fog::Compute::Google::Disk
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::Google::Disk
- Defined in:
- lib/fog/compute/google/models/disk.rb
Constant Summary collapse
- RUNNING_STATE =
"READY".freeze
Instance Method Summary collapse
- #attached_disk_obj(opts = {}) ⇒ Object
- #create_snapshot(snapshot_name, snapshot = {}) ⇒ Object
- #default_description ⇒ Object
- #destroy(async = true) ⇒ Object
- #get_as_boot_disk(writable = true, auto_delete = false) ⇒ Object
- #ready? ⇒ Boolean
- #reload ⇒ Object
- #save ⇒ Object
- #zone_name ⇒ Object
Instance Method Details
#attached_disk_obj(opts = {}) ⇒ Object
71 72 73 74 |
# File 'lib/fog/compute/google/models/disk.rb', line 71 def attached_disk_obj(opts = {}) requires :self_link collection.attached_disk_obj(self_link, opts) end |
#create_snapshot(snapshot_name, snapshot = {}) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/fog/compute/google/models/disk.rb', line 104 def create_snapshot(snapshot_name, snapshot = {}) requires :name, :zone raise ArgumentError, "Invalid snapshot name" unless snapshot_name data = service.create_disk_snapshot(snapshot_name, name, zone_name, snapshot) operation = Fog::Compute::Google::Operations.new(:service => service) .get(data.name, data.zone) operation.wait_for { ready? } service.snapshots.get(snapshot_name) end |
#default_description ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/fog/compute/google/models/disk.rb', line 21 def default_description if !source_image.nil? "created from image: #{source_image}" elsif !source_snapshot.nil? "created from snapshot: #{source_snapshot}" else "created with fog" end end |
#destroy(async = true) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/fog/compute/google/models/disk.rb', line 57 def destroy(async = true) requires :name, :zone data = service.delete_disk(name, zone_name) operation = Fog::Compute::Google::Operations.new(:service => service) .get(data.name, data.zone) operation.wait_for { ready? } unless async operation end |
#get_as_boot_disk(writable = true, auto_delete = false) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/fog/compute/google/models/disk.rb', line 76 def get_as_boot_disk(writable = true, auto_delete = false) { :auto_delete => auto_delete, :boot => true, :source => self_link, :mode => writable ? "READ_WRITE" : "READ_ONLY", :type => "PERSISTENT" } end |
#ready? ⇒ Boolean
86 87 88 |
# File 'lib/fog/compute/google/models/disk.rb', line 86 def ready? status == RUNNING_STATE end |
#reload ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/fog/compute/google/models/disk.rb', line 90 def reload requires :identity, :zone return unless data = begin collection.get(identity, zone_name) rescue Google::Apis::TransmissionError nil end new_attributes = data.attributes merge_attributes(new_attributes) self end |
#save ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fog/compute/google/models/disk.rb', line 31 def save requires :name, :zone, :size_gb = { :description => description || default_description, :type => type, :size_gb => size_gb, :source_image => source_image, :source_snapshot => source_snapshot } if [:source_image] unless source_image.include?("projects/") [:source_image] = service.images.get(source_image).self_link end end # Request needs backward compatibility so source image is specified in # method arguments data = service.insert_disk(name, zone, [:source_image], ) operation = Fog::Compute::Google::Operations.new(:service => service) .get(data.name, data.zone) operation.wait_for { ready? } reload end |
#zone_name ⇒ Object
67 68 69 |
# File 'lib/fog/compute/google/models/disk.rb', line 67 def zone_name zone.nil? ? nil : zone.split("/")[-1] end |