hammer_cli_foreman 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of hammer_cli_foreman might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/config/foreman.yml +16 -0
- data/doc/host_create.md +102 -54
- data/doc/release_notes.md +20 -0
- data/lib/hammer_cli_foreman.rb +8 -0
- data/lib/hammer_cli_foreman/commands.rb +33 -9
- data/lib/hammer_cli_foreman/compute_resource.rb +13 -2
- data/lib/hammer_cli_foreman/domain.rb +24 -1
- data/lib/hammer_cli_foreman/environment.rb +1 -2
- data/lib/hammer_cli_foreman/host.rb +131 -73
- data/lib/hammer_cli_foreman/hostgroup.rb +18 -8
- data/lib/hammer_cli_foreman/i18n.rb +2 -6
- data/lib/hammer_cli_foreman/id_resolver.rb +41 -6
- data/lib/hammer_cli_foreman/interface.rb +165 -0
- data/lib/hammer_cli_foreman/output/fields.rb +7 -0
- data/lib/hammer_cli_foreman/output/formatters.rb +3 -5
- data/lib/hammer_cli_foreman/puppet_class.rb +16 -2
- data/lib/hammer_cli_foreman/settings.rb +37 -0
- data/lib/hammer_cli_foreman/smart_class_parameter.rb +75 -11
- data/lib/hammer_cli_foreman/smart_variable.rb +146 -0
- data/lib/hammer_cli_foreman/user.rb +9 -3
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/locale/Makefile +9 -17
- data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/de/hammer-cli-foreman.edit.po +2403 -0
- data/locale/de/hammer-cli-foreman.po +302 -355
- data/locale/de/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en/hammer-cli-foreman.edit.po +2260 -0
- data/locale/en/hammer-cli-foreman.po +946 -823
- data/locale/en/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en_GB/hammer-cli-foreman.edit.po +2267 -0
- data/locale/en_GB/hammer-cli-foreman.po +297 -351
- data/locale/en_GB/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/es/hammer-cli-foreman.edit.po +2427 -0
- data/locale/es/hammer-cli-foreman.po +301 -354
- data/locale/es/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/fr/hammer-cli-foreman.edit.po +2427 -0
- data/locale/fr/hammer-cli-foreman.po +299 -353
- data/locale/fr/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/hammer-cli-foreman.pot +1413 -1112
- data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/it/hammer-cli-foreman.edit.po +2402 -0
- data/locale/it/hammer-cli-foreman.po +299 -353
- data/locale/it/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ja/hammer-cli-foreman.edit.po +2401 -0
- data/locale/ja/hammer-cli-foreman.po +338 -391
- data/locale/ja/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ko/hammer-cli-foreman.edit.po +2401 -0
- data/locale/ko/hammer-cli-foreman.po +299 -353
- data/locale/ko/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/pt_BR/hammer-cli-foreman.edit.po +2417 -0
- data/locale/pt_BR/hammer-cli-foreman.po +312 -365
- data/locale/pt_BR/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ru/hammer-cli-foreman.edit.po +2401 -0
- data/locale/ru/hammer-cli-foreman.po +300 -354
- data/locale/ru/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_CN/hammer-cli-foreman.edit.po +2400 -0
- data/locale/zh_CN/hammer-cli-foreman.po +299 -353
- data/locale/zh_CN/hammer-cli-foreman.po.time_stamp +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_TW/hammer-cli-foreman.edit.po +2400 -0
- data/locale/zh_TW/hammer-cli-foreman.po +299 -353
- data/locale/zh_TW/hammer-cli-foreman.po.time_stamp +0 -0
- data/test/unit/apipie_resource_mock.rb +7 -0
- data/test/unit/commands_test.rb +42 -0
- data/test/unit/data/1.7/foreman_api.json +1 -0
- data/test/unit/dependency_resolver_test.rb +4 -2
- data/test/unit/environment_test.rb +2 -2
- data/test/unit/host_test.rb +50 -27
- data/test/unit/hostgroup_test.rb +19 -3
- data/test/unit/media_test.rb +2 -2
- data/test/unit/puppet_class_test.rb +17 -2
- data/test/unit/smart_class_parameter_test.rb +26 -2
- data/test/unit/smart_variable_test.rb +134 -0
- data/test/unit/test_helper.rb +1 -1
- metadata +36 -4
@@ -0,0 +1,165 @@
|
|
1
|
+
module HammerCLIForeman
|
2
|
+
|
3
|
+
class Interface < HammerCLIForeman::Command
|
4
|
+
|
5
|
+
resource :interfaces
|
6
|
+
desc _("View and manage host's network interfaces")
|
7
|
+
|
8
|
+
def self.format_type(nic)
|
9
|
+
flags = []
|
10
|
+
flags << _('primary') if nic['primary']
|
11
|
+
flags << _('provision') if nic['provision']
|
12
|
+
|
13
|
+
type = nic['type']
|
14
|
+
if !flags.empty?
|
15
|
+
type += " (#{flags.join(', ')})"
|
16
|
+
end
|
17
|
+
type
|
18
|
+
end
|
19
|
+
|
20
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
21
|
+
|
22
|
+
output do
|
23
|
+
field :id, _("Id")
|
24
|
+
field :identifier, _("Identifier")
|
25
|
+
field :_type , _("Type")
|
26
|
+
field :mac , _("MAC address")
|
27
|
+
field :ip , _("IP address")
|
28
|
+
field :name , _("DNS name")
|
29
|
+
end
|
30
|
+
|
31
|
+
def extend_data(nic)
|
32
|
+
nic['_type'] = HammerCLIForeman::Interface.format_type(nic)
|
33
|
+
nic
|
34
|
+
end
|
35
|
+
|
36
|
+
build_options
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
41
|
+
|
42
|
+
output do
|
43
|
+
field :id, _("Id")
|
44
|
+
field :identifier, _("Identifier")
|
45
|
+
field :type , _("Type")
|
46
|
+
field :mac , _("MAC address")
|
47
|
+
field :ip , _("IP address")
|
48
|
+
field :name , _("DNS name")
|
49
|
+
field nil, _("Subnet"), Fields::SingleReference, :key => :subnet
|
50
|
+
field nil, _("Domain"), Fields::SingleReference, :key => :domain
|
51
|
+
field :managed, _("Managed"), Fields::Boolean
|
52
|
+
field :primary, _("Primary"), Fields::Boolean
|
53
|
+
field :provision, _("Provision"), Fields::Boolean
|
54
|
+
field :virtual, _("Virtual"), Fields::Boolean
|
55
|
+
field :tag, _("Tag"), nil, :hide_blank => true
|
56
|
+
field :attached_to, _("Attached to"), nil, :hide_blank => true
|
57
|
+
|
58
|
+
label _("BMC"), :hide_blank => true do
|
59
|
+
field :username, _("Username"), nil, :hide_blank => true
|
60
|
+
field :provider, _("Provider"), nil, :hide_blank => true
|
61
|
+
end
|
62
|
+
|
63
|
+
label _("Bond"), :hide_blank => true do
|
64
|
+
field :mode, _("Mode"), nil, :hide_blank => true
|
65
|
+
field :attached_devices, _("Attached devices"), nil, :hide_blank => true
|
66
|
+
field :bond_options, _("Bond options"), nil, :hide_blank => true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
build_options
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
module InterfaceUpdate
|
75
|
+
|
76
|
+
def self.included(base)
|
77
|
+
base.option "--primary", :flag, _("Should this interface be used for constructing the FQDN of the host? Each managed hosts needs to have one primary interface.")
|
78
|
+
base.option "--provision", :flag, _("Should this interface be used for TFTP of PXELinux (or SSH for image-based hosts)? Each managed hosts needs to have one provision interface.")
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_interfaces(host_id)
|
82
|
+
HammerCLIForeman.foreman_resource!(:interfaces).call(:index, {'host_id' => host_id}, request_headers, request_options)
|
83
|
+
end
|
84
|
+
|
85
|
+
def mandatory_interfaces(host_id, nic_id)
|
86
|
+
mandatory_options = []
|
87
|
+
get_interfaces(host_id)['results'].each do |nic|
|
88
|
+
if (nic['primary'] || nic['provision']) && nic['id'] != nic_id
|
89
|
+
mandatory_options << {
|
90
|
+
'id' => nic['id'],
|
91
|
+
'primary' => nic['primary'],
|
92
|
+
'provision' => nic['provision']
|
93
|
+
}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
mandatory_options
|
97
|
+
end
|
98
|
+
|
99
|
+
def reset_flag(interfaces_params, flag)
|
100
|
+
interfaces_params.each do |nic|
|
101
|
+
nic[flag] = false if nic[flag]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def send_request
|
106
|
+
nic_params = request_params
|
107
|
+
interface = nic_params['interface']
|
108
|
+
|
109
|
+
interface['id'] = nic_params['id'].to_i if nic_params['id']
|
110
|
+
interface['compute_attributes'] = option_compute_attributes
|
111
|
+
|
112
|
+
host_params = {}
|
113
|
+
host_params['id'] = nic_params['host_id']
|
114
|
+
host_params['host'] = {}
|
115
|
+
host_params['host']['interfaces_attributes'] = mandatory_interfaces(nic_params['host_id'], interface['id'])
|
116
|
+
|
117
|
+
reset_flag(host_params['host']['interfaces_attributes'], 'primary') if option_primary?
|
118
|
+
reset_flag(host_params['host']['interfaces_attributes'], 'provision') if option_provision?
|
119
|
+
|
120
|
+
host_params['host']['interfaces_attributes'] += [interface]
|
121
|
+
|
122
|
+
HammerCLIForeman.foreman_resource!(:hosts).call(:update, host_params, request_headers, request_options)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
class CreateCommand < HammerCLIForeman::CreateCommand
|
128
|
+
success_message _("Interface created")
|
129
|
+
failure_message _("Could not create the interface")
|
130
|
+
|
131
|
+
option "--compute-attributes", "COMPUTE_ATTRS", _("Compute resource specific attributes."),
|
132
|
+
:format => HammerCLI::Options::Normalizers::KeyValueList.new
|
133
|
+
|
134
|
+
include InterfaceUpdate
|
135
|
+
|
136
|
+
build_options :without => [:primary, :provision]
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
141
|
+
success_message _("Interface updated")
|
142
|
+
failure_message _("Could not update the interface")
|
143
|
+
|
144
|
+
option "--compute-attributes", "COMPUTE_ATTRS", _("Compute resource specific attributes."),
|
145
|
+
:format => HammerCLI::Options::Normalizers::KeyValueList.new
|
146
|
+
|
147
|
+
include InterfaceUpdate
|
148
|
+
|
149
|
+
build_options :without => [:primary, :provision]
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
154
|
+
success_message _("Interface deleted")
|
155
|
+
failure_message _("Could not delete the interface")
|
156
|
+
|
157
|
+
build_options
|
158
|
+
end
|
159
|
+
|
160
|
+
autoload_subcommands
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
|
@@ -3,6 +3,13 @@ require 'hammer_cli'
|
|
3
3
|
module Fields
|
4
4
|
|
5
5
|
class SingleReference < Field
|
6
|
+
|
7
|
+
def display?(value)
|
8
|
+
id_key = "#{parameters[:key]}_id"
|
9
|
+
name_key = "#{parameters[:key]}_name"
|
10
|
+
|
11
|
+
(value[name_key.to_sym] || value[name_key]) && (value[id_key.to_sym] || value[id_key])
|
12
|
+
end
|
6
13
|
end
|
7
14
|
|
8
15
|
class Reference < Field
|
@@ -20,11 +20,9 @@ module HammerCLIForeman::Output
|
|
20
20
|
|
21
21
|
context = field_params[:context] || {}
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
"#{name}" if name
|
27
|
-
end
|
23
|
+
out = "#{name}"
|
24
|
+
out += " (id: #{id})" if context[:show_ids] && id
|
25
|
+
out
|
28
26
|
end
|
29
27
|
|
30
28
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'hammer_cli_foreman/smart_class_parameter'
|
2
|
+
require 'hammer_cli_foreman/smart_variable'
|
2
3
|
|
3
4
|
module HammerCLIForeman
|
4
5
|
|
@@ -47,8 +48,21 @@ module HammerCLIForeman
|
|
47
48
|
|
48
49
|
|
49
50
|
class SCParamsCommand < HammerCLIForeman::SmartClassParametersBriefList
|
50
|
-
|
51
|
-
|
51
|
+
build_options_for :puppetclasses
|
52
|
+
|
53
|
+
def validate_options
|
54
|
+
super
|
55
|
+
validator.any(:option_puppetclass_name, :option_puppetclass_id).required
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class SmartVariablesCommand < HammerCLIForeman::SmartVariablesBriefList
|
60
|
+
build_options_for :puppetclasses
|
61
|
+
|
62
|
+
def validate_options
|
63
|
+
super
|
64
|
+
validator.any(:option_puppetclass_name, :option_puppetclass_id).required
|
65
|
+
end
|
52
66
|
end
|
53
67
|
|
54
68
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
module HammerCLIForeman
|
3
|
+
|
4
|
+
class Settings < HammerCLIForeman::Command
|
5
|
+
|
6
|
+
resource :settings
|
7
|
+
|
8
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
9
|
+
|
10
|
+
output do
|
11
|
+
field :id, _('Id'), Fields::Id
|
12
|
+
field :name, _('Name')
|
13
|
+
field :value, _('Value')
|
14
|
+
field :description, _('Description')
|
15
|
+
end
|
16
|
+
|
17
|
+
def extend_data(data)
|
18
|
+
data['value'] = data['value'].to_s
|
19
|
+
data
|
20
|
+
end
|
21
|
+
|
22
|
+
build_options
|
23
|
+
end
|
24
|
+
|
25
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
26
|
+
command_name 'set'
|
27
|
+
|
28
|
+
success_message _("Setting [%{name}] updated to [%{value}]")
|
29
|
+
failure_message _("Could not update the setting")
|
30
|
+
|
31
|
+
build_options
|
32
|
+
end
|
33
|
+
|
34
|
+
autoload_subcommands
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module HammerCLIForeman
|
2
2
|
|
3
|
-
class SmartClassParametersBriefList < HammerCLIForeman::
|
3
|
+
class SmartClassParametersBriefList < HammerCLIForeman::ListCommand
|
4
4
|
resource :smart_class_parameters, :index
|
5
5
|
command_name 'sc-params'
|
6
6
|
|
@@ -20,9 +20,12 @@ module HammerCLIForeman
|
|
20
20
|
HammerCLI::Output::RecordCollection.new(res.uniq, :meta => res.meta)
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.
|
24
|
-
options
|
25
|
-
|
23
|
+
def self.build_options_for(resource)
|
24
|
+
options = {}
|
25
|
+
options[:without] = [:host_id, :puppetclass_id, :environment_id, :hostgroup_id]
|
26
|
+
options[:expand] = {}
|
27
|
+
options[:expand][:except] = ([:hosts, :puppetclasses, :environments, :hostgroups] - [resource])
|
28
|
+
build_options(options)
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
@@ -44,6 +47,11 @@ module HammerCLIForeman
|
|
44
47
|
|
45
48
|
output SmartClassParametersList.output_definition
|
46
49
|
|
50
|
+
def extend_data(res)
|
51
|
+
res['parameter_type'] ||= 'string'
|
52
|
+
res
|
53
|
+
end
|
54
|
+
|
47
55
|
build_options
|
48
56
|
end
|
49
57
|
|
@@ -59,14 +67,13 @@ module HammerCLIForeman
|
|
59
67
|
field :validator_rule, _("Rule")
|
60
68
|
end
|
61
69
|
label _("Override values") do
|
70
|
+
field :merge_overrides, _("Merge overrides"), Fields::Boolean
|
71
|
+
field :avoid_duplicates, _("Avoid duplicates"), Fields::Boolean
|
62
72
|
field :override_value_order, _("Order"), Fields::List
|
63
|
-
|
64
|
-
collection :override_values, "Values" do
|
65
|
-
label _("Value") do
|
73
|
+
collection :override_values, _("Values") do
|
66
74
|
field :id, _('Id')
|
67
75
|
field :match, _('Match')
|
68
76
|
field :value, _('Value')
|
69
|
-
end
|
70
77
|
end
|
71
78
|
end
|
72
79
|
HammerCLIForeman::References.environments(self)
|
@@ -74,11 +81,20 @@ module HammerCLIForeman
|
|
74
81
|
end
|
75
82
|
|
76
83
|
def extend_data(res)
|
77
|
-
res['override_value_order'] = res['override_value_order'].split(
|
84
|
+
res['override_value_order'] = res['override_value_order'].split(/\r?\n/)
|
85
|
+
res['parameter_type'] ||= 'string'
|
78
86
|
res
|
79
87
|
end
|
80
88
|
|
81
|
-
build_options
|
89
|
+
build_options do |options|
|
90
|
+
options.expand.including(:puppetclasses)
|
91
|
+
end
|
92
|
+
|
93
|
+
validate_options do
|
94
|
+
if option(:option_name).exist?
|
95
|
+
any(:option_puppetclass_name, :option_puppetclass_id).required
|
96
|
+
end
|
97
|
+
end
|
82
98
|
end
|
83
99
|
|
84
100
|
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
@@ -86,7 +102,10 @@ module HammerCLIForeman
|
|
86
102
|
success_message _("Parameter updated")
|
87
103
|
failure_message _("Could not update the parameter")
|
88
104
|
|
89
|
-
build_options
|
105
|
+
build_options do |options|
|
106
|
+
options.expand.including(:puppetclasses)
|
107
|
+
options.without(:parameter_type, :validator_type, :override, :required)
|
108
|
+
end
|
90
109
|
|
91
110
|
option "--override", "OVERRIDE", _("Override this parameter."),
|
92
111
|
:format => HammerCLI::Options::Normalizers::Bool.new
|
@@ -97,8 +116,53 @@ module HammerCLIForeman
|
|
97
116
|
['string', 'boolean', 'integer', 'real', 'array', 'hash', 'yaml', 'json'])
|
98
117
|
option "--validator-type", "VALIDATOR_TYPE", _("Type of the validator."),
|
99
118
|
:format => HammerCLI::Options::Normalizers::Enum.new(['regexp', 'list', ''])
|
119
|
+
|
120
|
+
validate_options do
|
121
|
+
if option(:option_name).exist?
|
122
|
+
any(:option_puppetclass_name, :option_puppetclass_id).required
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class AddOverrideValueCommand < HammerCLIForeman::CreateCommand
|
128
|
+
resource :override_values
|
129
|
+
command_name 'add-override-value'
|
130
|
+
|
131
|
+
success_message _("Override value created")
|
132
|
+
failure_message _("Could not create the override_value")
|
133
|
+
|
134
|
+
build_options do |options|
|
135
|
+
options.without(:smart_variable_id)
|
136
|
+
options.expand.except(:smart_variables)
|
137
|
+
options.expand.including(:puppetclasses)
|
138
|
+
end
|
139
|
+
|
140
|
+
validate_options do
|
141
|
+
if option(:option_smart_class_parameter_name).exist?
|
142
|
+
any(:option_puppetclass_name, :option_puppetclass_id).required
|
143
|
+
end
|
144
|
+
end
|
100
145
|
end
|
101
146
|
|
147
|
+
class RemoveOverrideValueCommand < HammerCLIForeman::DeleteCommand
|
148
|
+
resource :override_values
|
149
|
+
command_name 'remove-override-value'
|
150
|
+
|
151
|
+
success_message _("Override value deleted")
|
152
|
+
failure_message _("Could not delete the override value")
|
153
|
+
|
154
|
+
build_options do |options|
|
155
|
+
options.without(:smart_variable_id)
|
156
|
+
options.expand.except(:smart_variables)
|
157
|
+
options.expand.including(:puppetclasses)
|
158
|
+
end
|
159
|
+
|
160
|
+
validate_options do
|
161
|
+
if option(:option_smart_class_parameter_name).exist?
|
162
|
+
any(:option_puppetclass_name, :option_puppetclass_id).required
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
102
166
|
|
103
167
|
autoload_subcommands
|
104
168
|
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module HammerCLIForeman
|
2
|
+
|
3
|
+
class SmartVariablesBriefList < HammerCLIForeman::ListCommand
|
4
|
+
resource :smart_variables, :index
|
5
|
+
command_name 'smart-variables'
|
6
|
+
|
7
|
+
output do
|
8
|
+
field :id, _("Id")
|
9
|
+
|
10
|
+
field :variable, _("Name")
|
11
|
+
field :default_value, _("Default Value")
|
12
|
+
field :parameter_type, _("Type")
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.build_options_for(resource)
|
16
|
+
options = {}
|
17
|
+
options[:without] = [:host_id, :puppetclass_id, :hostgroup_id]
|
18
|
+
options[:expand] = {}
|
19
|
+
options[:expand][:except] = ([:hosts, :puppetclasses, :hostgroups] - [resource])
|
20
|
+
build_options(options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class SmartVariablesList < SmartVariablesBriefList
|
25
|
+
|
26
|
+
output do
|
27
|
+
field :puppetclass_name, _("Puppet class")
|
28
|
+
field :puppetclass_id, _("Class Id"), Fields::Id
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class SmartVariable < HammerCLIForeman::Command
|
33
|
+
|
34
|
+
resource :smart_variables
|
35
|
+
|
36
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
37
|
+
|
38
|
+
output SmartVariablesList.output_definition
|
39
|
+
|
40
|
+
def extend_data(res)
|
41
|
+
res['parameter_type'] ||= 'string'
|
42
|
+
res
|
43
|
+
end
|
44
|
+
|
45
|
+
build_options
|
46
|
+
end
|
47
|
+
|
48
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
49
|
+
|
50
|
+
output ListCommand.output_definition do
|
51
|
+
field :description, _("Description")
|
52
|
+
|
53
|
+
label _("Validator") do
|
54
|
+
field :validator_type, _("Type")
|
55
|
+
field :validator_rule, _("Rule")
|
56
|
+
end
|
57
|
+
label _("Override values") do
|
58
|
+
field :merge_overrides, _("Merge overrides"), Fields::Boolean
|
59
|
+
field :avoid_duplicates, _("Avoid duplicates"), Fields::Boolean
|
60
|
+
field :override_value_order, _("Order"), Fields::List
|
61
|
+
collection :override_values, _("Values") do
|
62
|
+
field :id, _('Id')
|
63
|
+
field :match, _('Match')
|
64
|
+
field :value, _('Value')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
HammerCLIForeman::References.timestamps(self)
|
68
|
+
end
|
69
|
+
|
70
|
+
def extend_data(res)
|
71
|
+
res['override_value_order'] = res['override_value_order'].split(/\r?\n/)
|
72
|
+
res['parameter_type'] ||= 'string'
|
73
|
+
res
|
74
|
+
end
|
75
|
+
|
76
|
+
build_options
|
77
|
+
end
|
78
|
+
|
79
|
+
class CreateCommand < HammerCLIForeman::CreateCommand
|
80
|
+
|
81
|
+
success_message _("Smart variable [%{variable}] created")
|
82
|
+
failure_message _("Could not create the smart variable")
|
83
|
+
|
84
|
+
build_options :without => [:variable_type, :validator_type]
|
85
|
+
|
86
|
+
option "--variable-type", "VARIABLE_TYPE", _("Type of the variable."),
|
87
|
+
:format => HammerCLI::Options::Normalizers::Enum.new(
|
88
|
+
['string', 'boolean', 'integer', 'real', 'array', 'hash', 'yaml', 'json'])
|
89
|
+
option "--validator-type", "VALIDATOR_TYPE", _("Type of the validator."),
|
90
|
+
:format => HammerCLI::Options::Normalizers::Enum.new(['regexp', 'list', ''])
|
91
|
+
end
|
92
|
+
|
93
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
94
|
+
|
95
|
+
success_message _("Smart variable [%{variable}] updated")
|
96
|
+
failure_message _("Could not update the smart variable")
|
97
|
+
|
98
|
+
build_options :without => [:variable_type, :validator_type]
|
99
|
+
|
100
|
+
option "--variable-type", "VARIABLE_TYPE", _("Type of the variable."),
|
101
|
+
:format => HammerCLI::Options::Normalizers::Enum.new(
|
102
|
+
['string', 'boolean', 'integer', 'real', 'array', 'hash', 'yaml', 'json'])
|
103
|
+
option "--validator-type", "VALIDATOR_TYPE", _("Type of the validator."),
|
104
|
+
:format => HammerCLI::Options::Normalizers::Enum.new(['regexp', 'list', ''])
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
109
|
+
|
110
|
+
success_message _("Smart variable [%{variable}] deleted")
|
111
|
+
failure_message _("Could not delete the smart variable")
|
112
|
+
|
113
|
+
build_options
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
class AddOverrideValueCommand < HammerCLIForeman::CreateCommand
|
118
|
+
resource :override_values
|
119
|
+
command_name 'add-override-value'
|
120
|
+
|
121
|
+
success_message _("Override value created")
|
122
|
+
failure_message _("Could not create the override_value")
|
123
|
+
|
124
|
+
build_options do |options|
|
125
|
+
options.without(:smart_class_parameter_id)
|
126
|
+
options.expand.except(:smart_class_parameters)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class RemoveOverrideValueCommand < HammerCLIForeman::DeleteCommand
|
131
|
+
resource :override_values
|
132
|
+
command_name 'remove-override-value'
|
133
|
+
|
134
|
+
success_message _("Override value deleted")
|
135
|
+
failure_message _("Could not delete the override value")
|
136
|
+
|
137
|
+
build_options do |options|
|
138
|
+
options.without(:smart_class_parameter_id)
|
139
|
+
options.expand.except(:smart_class_parameters)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
autoload_subcommands
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|