/
compute_resource.rb
288 lines (224 loc) · 8.14 KB
/
compute_resource.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
require 'hammer_cli_foreman/image'
require 'hammer_cli_foreman/virtual_machine'
require 'hammer_cli_foreman/compute_resource/register_compute_resources'
module HammerCLIForeman
class ComputeResource < HammerCLIForeman::Command
resource :compute_resources
module ProviderNameLegacy
def extend_data(data)
# api used to return provider_friendly_name as a provider
data['provider_friendly_name'] ||= data['provider']
data
end
end
class ListCommand < HammerCLIForeman::ListCommand
include ProviderNameLegacy
output do
field :id, _("Id")
field :name, _("Name")
field :provider_friendly_name, _("Provider")
end
build_options
end
class InfoCommand < HammerCLIForeman::InfoCommand
include ProviderNameLegacy
output ListCommand.output_definition do
field :description, _("Description")
field :user, _("User")
HammerCLIForeman::References.taxonomies(self)
HammerCLIForeman::References.timestamps(self)
end
def print_data(data)
provider = ::HammerCLIForeman.compute_resources[data['provider'].downcase]
if provider
output_definition.fields.concat(provider.provider_specific_fields || [])
super(data)
end
end
build_options
end
class CreateCommand < HammerCLIForeman::CreateCommand
option "--public-key-path", "PUBLIC_KEY_PATH", _("Path to a file that contains oVirt public key (For oVirt only)"),
:format => HammerCLI::Options::Normalizers::File.new
success_message _("Compute resource created.")
failure_message _("Could not create the compute resource")
build_options
def request_params
params = super
params['compute_resource']['public_key'] = option_public_key_path if option_public_key_path
params
end
validate_options do
if option(:option_provider).value.nil? || option(:option_name).value.nil?
all(:option_name, :option_provider).required
else
provider = ::HammerCLIForeman.compute_resources[option(:option_provider).value.to_s.downcase]
if provider
required_options = provider.mandatory_resource_options.map { |attr| "option_#{attr}".to_sym }
all(*required_options).required
else
raise ArgumentError, "incorrect/invalid --provider option"
end
end
end
end
class UpdateCommand < HammerCLIForeman::UpdateCommand
option "--public-key-path", "PUBLIC_KEY_PATH", _("Path to a file that contains oVirt public key (For oVirt only)"),
:format => HammerCLI::Options::Normalizers::File.new
success_message _("Compute resource updated.")
failure_message _("Could not update the compute resource")
def request_params
params = super
params['compute_resource']['public_key'] = option_public_key_path if option_public_key_path
params
end
build_options :without => :name
end
class DeleteCommand < HammerCLIForeman::DeleteCommand
success_message _("Compute resource deleted.")
failure_message _("Could not delete the compute resource")
build_options
end
class AssociateVmsCommand < HammerCLIForeman::Command
action :associate
command_name 'associate-vms'
option "--vm-id","VM ID", _("Associate a specific VM")
success_message _("Virtual machines have been associated.")
failure_message _("Could not associate the virtual machines")
build_options
end
class AvailableClustersCommand < HammerCLIForeman::ListCommand
action :available_clusters
command_name 'clusters'
output do
field :id, _('Id')
field :name, _('Name')
field :datacenter, _('Datacenter')
field :num_host, _('Hosts')
field :full_path, _('Cluster path')
end
build_options
end
class AvailableNetworksCommand < HammerCLIForeman::ListCommand
action :available_networks
command_name 'networks'
output do
field :id, _('Id'), Fields::Field, :max_width => 200, :hide_blank => true
field :name, _('Name')
field :datacenter, _('Datacenter')
field :virtualswitch, _('Virtual switch')
field :vlanid, _('VLAN ID')
end
build_options without: :cluster_id
extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params]))
end
class AvailableVnicProfilesCommand < HammerCLIForeman::ListCommand
action :available_vnic_profiles
command_name 'vnic-profiles'
output do
field :id, _('VNIC profile ID'), Fields::Field, :max_width => 200, :hide_blank => true
field :name, _('Name')
field :network, _('Network ID')
end
build_options
end
class AvailableImagesCommand < HammerCLIForeman::ListCommand
action :available_images
command_name 'images'
output do
field :uuid, _('Uuid')
field :name, _('Name')
field :path, _('Path'), Fields::Field, :hide_blank => true
end
build_options
end
class AvailableFlavorsCommand < HammerCLIForeman::ListCommand
action :available_flavors
command_name 'flavors'
output do
field :id, _('Id')
field :name, _('Name')
end
build_options
end
class AvailableFoldersCommand < HammerCLIForeman::ListCommand
action :available_folders
command_name 'folders'
output do
field :id, _('Id')
field :name, _('Name')
field :parent, _('Parent')
field :datacenter, _('Datacenter')
field :path, _('Path'), Fields::Field, :max_width => 50
field :type, _('Type')
end
build_options
end
class AvailableZonesCommand < HammerCLIForeman::ListCommand
action :available_zones
command_name 'zones'
output do
field :id, _('Id')
field :name, _('Name')
end
build_options
end
class AvailableResourcePoolsCommand < HammerCLIForeman::ListCommand
action :available_resource_pools
command_name 'resource-pools'
output do
field :id, _('Id')
field :name, _('Name')
field :cluster, _('Cluster')
field :datacenter, _('Datacenter')
end
build_options without: :cluster_id
extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params]))
end
class AvailableStorageDomainsCommand < HammerCLIForeman::ListCommand
action :available_storage_domains
command_name 'storage-domains'
output do
field :id, _('Id')
field :name, _('Name')
end
build_options without: :cluster_id
extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params]))
end
class AvailableStoragePodsCommand < HammerCLIForeman::ListCommand
action :available_storage_pods
command_name 'storage-pods'
output do
field :id, _('Id')
field :name, _('Name')
field :datacenter, _('Datacenter')
end
build_options without: :cluster_id
extend_with(HammerCLIForeman::CommandExtensions::ComputeResourceSubcommand.new(only: %i[option request_params]))
end
class AvailableSecurityGroupsCommand < HammerCLIForeman::ListCommand
action :available_security_groups
command_name 'security-groups'
output do
field :id, _('Id')
field :name, _('Name')
end
build_options
end
class AvailableVirtualMachinesCommand < HammerCLIForeman::ListCommand
action :available_virtual_machines
command_name 'virtual-machines'
output do
field :id, _('Id')
field :name, _('Name')
field :path, _('Path'), Fields::Field, :max_width => 50
field :state, _('State')
end
build_options
end
autoload_subcommands
subcommand 'virtual-machine', HammerCLIForeman::VirtualMachine.desc,
HammerCLIForeman::VirtualMachine
subcommand 'image', HammerCLIForeman::Image.desc, HammerCLIForeman::Image
end
end