Class: Fog::Compute::Google::Disk

Inherits:
Model
  • Object
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

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_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

#destroyObject



27
28
29
30
# File 'lib/fog/google/models/compute/disk.rb', line 27

def destroy
  requires :name, :zone
  service.delete_disk(name, zone)
end

#get_as_boot_disk(writable = true) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/google/models/compute/disk.rb', line 42

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

Returns:

  • (Boolean)


53
54
55
56
57
58
# File 'lib/fog/google/models/compute/disk.rb', line 53

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

#reloadObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fog/google/models/compute/disk.rb', line 60

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

#saveObject



21
22
23
24
25
# File 'lib/fog/google/models/compute/disk.rb', line 21

def save
  data = service.insert_disk(name, size_gb, zone_name, image_name).body
  data = service.backoff_if_unfound {service.get_disk(name, zone_name).body}
  service.disks.merge_attributes(data)
end

#zoneObject



32
33
34
35
36
37
38
39
40
# File 'lib/fog/google/models/compute/disk.rb', line 32

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