-
Notifications
You must be signed in to change notification settings - Fork 82
/
content_view_version.rb
251 lines (203 loc) · 8.24 KB
/
content_view_version.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
module HammerCLIKatello
class ContentViewVersion < HammerCLIKatello::Command
resource :content_view_versions
command_name 'version'
desc 'View and manage content view versions'
class ListCommand < HammerCLIKatello::ListCommand
output do
field :id, _("ID")
field :name, _("Name")
field :version, _("Version")
field :environments, _("Lifecycle Environments"), Fields::List
end
def extend_data(version)
version['environments'] = version['environments'].map { |e| e["name"] }
version
end
build_options do |o|
o.expand(:all).including(:organizations)
end
end
class InfoCommand < HammerCLIKatello::InfoCommand
resource :content_view_versions, :show
output do
field :id, _("ID")
field :name, _("Name")
field :version, _("Version")
field :description, _("Description")
from :content_view do
field :id, _("Content View ID")
field :name, _("Content View Name")
field :label, _("Content View Label")
end
collection :environments, _("Lifecycle Environments") do
field :id, _("ID")
field :name, _("Name")
field :label, _("Label")
end
collection :repositories, _("Repositories") do
field :id, _("ID")
field :name, _("Name")
field :label, _("Label")
end
collection :puppet_modules, _("Puppet Modules") do
field :id, _("ID")
field :name, _("Name")
field :author, _("Author")
field :version, _("Version")
end
end
build_options do |o|
o.expand(:all).including(:environments, :content_views, :organizations)
end
end
class PromoteCommand < HammerCLIKatello::SingleResourceCommand
include HammerCLIForemanTasks::Async
action :promote
command_name "promote"
success_message _("Content view is being promoted with task %{id}")
failure_message _("Could not promote the content view")
option "--force",
:flag,
_("force content view promotion and bypass lifecycle environment restriction")
option "--to-lifecycle-environment", "TO_ENVIRONMENT",
_("Name of the target environment"), :attribute_name => :option_to_environment_name
option "--to-lifecycle-environment-id", "TO_ENVIRONMENT_ID",
_("Id of the target environment"), :attribute_name => :option_to_environment_id
option "--from-lifecycle-environment", "FROM_ENVIRONMENT_ID",
_("Environment name from where to promote its version from (if version is unknown)"),
:attribute_name => :option_from_environment_name
option "--from-lifecycle-environment-id", "FROM_ENVIRONMENT_ID",
_(["Id of the environment from where to promote its version ",
"from (if version is unknown)"].join),
:attribute_name => :option_from_environment_id
def environment_search_options
{
"option_id" => options["option_to_environment_id"],
"option_name" => options["option_to_environment_name"],
"option_organization_id" => options["option_organization_id"],
"option_organization_name" => options["option_organization_name"],
"option_organization_label" => options["option_organization_label"]
}
end
def request_params
params = super
params['environment_id'] = resolver.lifecycle_environment_id(environment_search_options)
params['force'] = option_force?
params
end
build_options do |o|
o.expand(:all).except(:environments).including(:content_views, :organizations)
o.without(:environment_id)
end
end
class DeleteCommand < HammerCLIKatello::DeleteCommand
include HammerCLIForemanTasks::Async
action :destroy
command_name "delete"
success_message _("Content view is being deleted with task %{id}")
failure_message _("Could not delete the content view")
build_options do |o|
o.expand(:all).including(:environments, :content_views, :organizations)
end
end
class IncrementalUpdate < HammerCLIKatello::Command
include HammerCLIForemanTasks::Async
action :incremental_update
command_name "incremental-update"
success_message _("Incremental update is being performed with task %{id}")
failure_message _("An error occurred incrementally updating the content view")
option('--lifecycle-environment-ids',
'ENVIRONMENT_IDS',
_("list of lifecycle environment IDs to update the content view version in"),
:format => HammerCLI::Options::Normalizers::List.new
)
option('--lifecycle-environments',
'ENVIRONMENTS',
_("list of lifecycle environment names to update the content view version in"),
:format => HammerCLI::Options::Normalizers::List.new,
:attribute_name => :option_lifecycle_environment_names
)
option('--organization',
'ORGANIZATION_NAME',
_("Organization name for resolving lifecycle environment names"),
:attribute_name => :option_organization_name
)
option('--organization-id',
'ORGANIZATION_ID',
_("Organization id for resolving lifecycle environment names")
)
option('--update-all-hosts',
'UPDATE',
_('Update all editable and applicable hosts within the specified Content View and \
Lifecycle Environments'),
:format => HammerCLI::Options::Normalizers::Bool.new
)
option('--host-ids',
'HOST_IDS',
_("IDs of hosts to update"),
:format => HammerCLI::Options::Normalizers::List.new
)
validate_options do
organization_options = [:option_organization_id, :option_organization_name]
if option(:option_lifecycle_environment_ids).exist?
any(*organization_options).rejected
option(:option_lifecycle_environment_names).rejected
end
if option(:option_lifecycle_environment_names).exist?
any(*organization_options).required
end
end
def request_params
params = super
params[:content_view_version_environments] = [
{
:content_view_version_id => option_content_view_version_id
}
]
if options.key?(HammerCLI.option_accessor_name(:lifecycle_environment_names)) ||
options.key?(HammerCLI.option_accessor_name(:lifecycle_environment_ids))
params[:content_view_version_environments][0][:environment_ids] =
resolver.environment_ids(options)
end
add_content = {}
params['add_content'].each do |key, value|
add_content[key] = value if options.key?(HammerCLI.option_accessor_name(key))
end
params = request_params_hosts(params)
params['add_content'] = add_content
params.delete('id')
params
end
def request_params_hosts(params)
if params['update_hosts'] && params['update_hosts']['included'] &&
params['update_hosts']['included'].key?('ids')
params['update_hosts'].delete('excluded')
else
params.delete('update_hosts')
end
if option_host_ids
params['update_hosts'] = {'included' => {'ids' => option_host_ids}}
elsif option_update_all_hosts
params['update_hosts'] = { 'included' => {:search => ''}}
end
params
end
build_options do |o|
o.expand(:all).except(:environments)
o.without(:content_view_version_environments, :ids, :update_hosts, :update_hosts_included)
end
end
class ExportCommand < HammerCLIKatello::SingleResourceCommand
include HammerCLIForemanTasks::Async
action :export
command_name "export"
success_message _("Content view is being exported in task %{id}")
failure_message _("Could not export the content view")
build_options do |o|
o.expand(:all).including(:environments, :content_views, :organizations)
end
end
autoload_subcommands
end
end