-
Notifications
You must be signed in to change notification settings - Fork 4
/
image.rb
140 lines (124 loc) · 3.06 KB
/
image.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# frozen_string_literal: true
module HCloud
##
# 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, ...>
#
class Image < Resource
actionable
queryable
updatable
deletable
labelable
attribute :id, :integer
attribute :name
attribute :description
attribute :architecture
attribute :type
attribute :status
attribute :build_id
attribute :disk_size, :integer
attribute :image_size, :integer
attribute :os_flavor
attribute :os_version
attribute :protection, :protection
attribute :bound_to, :server
attribute :created_from, :server
# Explicitly specify created attribute, because resource is not Creatable
attribute :created, :datetime
attribute :deleted, :datetime
attribute :deprecated, :datetime
attribute :rapid_deploy
action :change_protection
def created?
created.present?
end
def deleted?
deleted.present?
end
def deprecated?
deprecated.present?
end
def rapid_deploy?
rapid_deploy.present?
end
def updatable_attributes
[:description, :type, :labels]
end
end
end