Class: Fog::Compute::Google::Disks

Inherits:
Fog::Collection
  • Object
show all
Defined in:
lib/fog/compute/google/models/disks.rb

Instance Method Summary collapse

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
# 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
  }
  if zone
    data = service.list_disks(zone, opts).items || []
  else
    data = []
    service.list_aggregated_disks(opts).items.each_value do |scoped_list|
      data.concat(scoped_list.disks) if scoped_list.disks
    end
  end
  load(data.map(&:to_h))
end

#attached_disk_obj(source, writable: true, boot: false, device_name: nil, encryption_key: nil, auto_delete: false) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fog/compute/google/models/disks.rb', line 35

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) ⇒ Object


26
27
28
29
30
31
32
33
# File 'lib/fog/compute/google/models/disks.rb', line 26

def get(identity, zone)
  response = service.get_disk(identity, zone)
  return nil if response.nil?
  new(response.to_h)
rescue ::Google::Apis::ClientError => e
  raise e unless e.status_code == 404
  nil
end