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



38
39
40
41
# File 'lib/fog/google/models/compute/disk.rb', line 38

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

#get_as_boot_disk(writable = true) ⇒ Object



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

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)


64
65
66
67
68
69
# File 'lib/fog/google/models/compute/disk.rb', line 64

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



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fog/google/models/compute/disk.rb', line 71

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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
    options['sizeGb']         = size_gb
  end

  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

#zoneObject



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

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