Class: Hcloud::Image

Inherits:
Object
  • Object
show all
Includes:
EntryLoader
Defined in:
lib/hcloud/image.rb

Constant Summary collapse

Attributes =
{
  id: nil,
  type: nil,
  status: nil,
  name: nil,
  description: nil,
  image_size: nil,
  disk_size: nil,
  created: :time,
  created_from: nil,
  bound_to: nil,
  os_flavor: nil,
  os_version: nil,
  rapid_deploy: nil,
}

Instance Method Summary collapse

Methods included from EntryLoader

#initialize, #request

Instance Method Details

#destroyObject



37
38
39
40
# File 'lib/hcloud/image.rb', line 37

def destroy
  request("images/#{id.to_i}", method: :delete).run
  true
end

#to_snapshotObject



21
22
23
# File 'lib/hcloud/image.rb', line 21

def to_snapshot
  update(type: "snapshot")
end

#update(description: nil, type: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hcloud/image.rb', line 25

def update(description: nil, type: nil)
  query = {}
  method(:update).parameters.inject(query) do |r,x| 
    (var = eval(x.last.to_s)).nil? ? r : r.merge!(x.last => var)
  end
  Image.new(
    Oj.load(request("images/#{id.to_i}", j: query, method: :put).run.body)["image"],
    parent,
    client
  )
end