Class: HCloud::Image

Inherits:
Resource show all
Defined in:
lib/hcloud/resources/image.rb

Overview

Represents a image

List all images

HCloud::Image.all
# => [#<HCloud::Image id: 1, ...>, ...]

Sort images

HCloud::Image.sort(name: :desc)
# => [#<HCloud::Image id: 1, ...>, ...]

HCloud::Image.sort(:id, name: :asc)
# => [#<HCloud::Image id: 1, ...>, ...]

Search images

HCloud::Image.where(name: "my_image")
# => #<HCloud::Image id: 1, ...>

HCloud::Image.where(status: "available", include_deprecated: false)
# => #<HCloud::Image id: 1, ...>

HCloud::Image.where(type: "backup", bound_to: 1)
# => #<HCloud::Image id: 1, ...>

Find image by ID

HCloud::Image.find(1)
# => #<HCloud::Image id: 1, ...>

Update image

image = HCloud::Image.find(1)
image.type = "snapshot"
image.description = "#{image.description} (snapshot)"
image.update

Delete image

image = HCloud::Image.find(1)
image.delete
image.deleted?
# => true

Actions

List actions

actions = HCloud::Image.find(1).actions
# => [#<HCloud::Action id: 1, ...>, ...]

Sort actions

HCloud::Image.find(1).actions.sort(finished: :desc)
# => [#<HCloud::Action id: 1, ...>, ...]

HCloud::Image.find(1).actions.sort(:command, finished: :asc)
# => [#<HCloud::Actions id: 1, ...>, ...]

Search actions

HCloud::Image.find(1).actions.where(command: "change_protection")
# => #<HCloud::Action id: 1, ...>

HCloud::Image.find(1).actions.where(status: "success")
# => #<HCloud::Action id: 1, ...>

Find action by ID

HCloud::Image.find(1).actions.find(1)
# => #<HCloud::Action id: 1, ...>

Resource-specific actions

Change protection

HCloud::Image.find(1).change_protection(delete: true)
# => #<HCloud::Action id: 1, ...>

Instance Method Summary collapse

Methods inherited from Resource

#==, attribute, client, #initialize, #inspect, resource_name, #to_h

Constructor Details

This class inherits a constructor from HCloud::Resource

Instance Method Details

#created?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/hcloud/resources/image.rb', line 120

def created?
  created.present?
end

#deleted?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/hcloud/resources/image.rb', line 124

def deleted?
  deleted.present?
end

#deprecated?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/hcloud/resources/image.rb', line 128

def deprecated?
  deprecated.present?
end

#rapid_deploy?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/hcloud/resources/image.rb', line 132

def rapid_deploy?
  rapid_deploy.present?
end

#updatable_attributesObject



136
137
138
# File 'lib/hcloud/resources/image.rb', line 136

def updatable_attributes
  [:description, :type, :labels]
end