Class: Fog::Compute::Google::Disks
- Inherits:
-
Fog::Collection
- Object
- Fog::Collection
- Fog::Compute::Google::Disks
- Defined in:
- lib/fog/compute/google/models/disks.rb
Instance Method Summary collapse
- #all(zone: nil, filter: nil, max_results: nil, order_by: nil, page_token: nil) ⇒ Object
-
#attached_disk_obj(source, writable: true, boot: false, device_name: nil, encryption_key: nil, auto_delete: false) ⇒ Hash
Returns an attached disk configuration hash.
- #get(identity, zone = nil) ⇒ Object
Instance Method Details
#all(zone: nil, filter: nil, max_results: nil, order_by: nil, page_token: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fog/compute/google/models/disks.rb', line 7 def all(zone: nil, filter: nil, max_results: nil, order_by: nil, page_token: nil) opts = { :filter => filter, :max_results => max_results, :order_by => order_by, :page_token => page_token } items = [] next_page_token = nil loop do if zone data = service.list_disks(zone, **opts) next_items = data.items || [] items.concat(next_items) next_page_token = data.next_page_token else data = service.list_aggregated_disks(**opts) data.items.each_value do |scoped_list| items.concat(scoped_list.disks) if scoped_list && scoped_list.disks end next_page_token = data.next_page_token end break if next_page_token.nil? || next_page_token.empty? opts[:page_token] = next_page_token end load(items.map(&:to_h)) end |
#attached_disk_obj(source, writable: true, boot: false, device_name: nil, encryption_key: nil, auto_delete: false) ⇒ Hash
Returns an attached disk configuration hash.
Compute API needs attached disks to be specified in a custom format. This provides a handy shortcut for generating a preformatted config.
Example output:
:boot=>true,
:mode=>"READ_WRITE",
:source=>"https://www.googleapis.com/compute/v1/projects/myproj/zones/us-central1-f/disks/mydisk",
:type=>"PERSISTENT"
See Instances.insert API docs for more info: cloud.google.com/compute/docs/reference/rest/v1/instances/insert
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/fog/compute/google/models/disks.rb', line 84 def attached_disk_obj(source, writable: true, boot: false, device_name: nil, encryption_key: nil, auto_delete: false) { :auto_delete => auto_delete, :boot => boot, :device_name => device_name, :disk_encryption_key => encryption_key, :mode => writable ? "READ_WRITE" : "READ_ONLY", :source => source, :type => "PERSISTENT" }.reject { |_k, v| v.nil? } end |
#get(identity, zone = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/compute/google/models/disks.rb', line 36 def get(identity, zone = nil) if zone disk = service.get_disk(identity, zone).to_h # Force the hash to contain a :users key so that it will override any :users key in the existing object disk[:users] = nil unless disk.include?(:users) return new(disk) elsif identity response = all(:filter => "name eq #{identity}", :max_results => 1) disk = response.first unless response.empty? return disk end rescue ::Google::Apis::ClientError => e raise e unless e.status_code == 404 # Return an empty object so that wait_for processes the block return new({:status => nil}) end |