hammer_cli_foreman 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of hammer_cli_foreman might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +12 -1
- data/doc/configuration.md +13 -0
- data/lib/hammer_cli_foreman.rb +3 -0
- data/lib/hammer_cli_foreman/architecture.rb +9 -9
- data/lib/hammer_cli_foreman/associating_commands.rb +57 -34
- data/lib/hammer_cli_foreman/commands.rb +188 -101
- data/lib/hammer_cli_foreman/common_parameter.rb +7 -10
- data/lib/hammer_cli_foreman/compute_resource.rb +8 -11
- data/lib/hammer_cli_foreman/domain.rb +14 -40
- data/lib/hammer_cli_foreman/environment.rb +10 -15
- data/lib/hammer_cli_foreman/exceptions.rb +4 -0
- data/lib/hammer_cli_foreman/fact.rb +5 -5
- data/lib/hammer_cli_foreman/host.rb +76 -132
- data/lib/hammer_cli_foreman/hostgroup.rb +26 -61
- data/lib/hammer_cli_foreman/id_resolver.rb +163 -0
- data/lib/hammer_cli_foreman/image.rb +14 -50
- data/lib/hammer_cli_foreman/location.rb +35 -17
- data/lib/hammer_cli_foreman/media.rb +9 -16
- data/lib/hammer_cli_foreman/model.rb +6 -8
- data/lib/hammer_cli_foreman/operating_system.rb +129 -63
- data/lib/hammer_cli_foreman/organization.rb +36 -16
- data/lib/hammer_cli_foreman/output/fields.rb +10 -2
- data/lib/hammer_cli_foreman/output/formatters.rb +44 -18
- data/lib/hammer_cli_foreman/parameter.rb +45 -41
- data/lib/hammer_cli_foreman/partition_table.rb +9 -12
- data/lib/hammer_cli_foreman/puppet_class.rb +14 -14
- data/lib/hammer_cli_foreman/references.rb +122 -0
- data/lib/hammer_cli_foreman/report.rb +3 -6
- data/lib/hammer_cli_foreman/searchables_option_builder.rb +99 -0
- data/lib/hammer_cli_foreman/smart_class_parameter.rb +17 -13
- data/lib/hammer_cli_foreman/smart_proxy.rb +18 -28
- data/lib/hammer_cli_foreman/subnet.rb +12 -13
- data/lib/hammer_cli_foreman/template.rb +10 -19
- data/lib/hammer_cli_foreman/user.rb +9 -28
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/locale/hammer-cli-foreman.pot +828 -817
- data/test/unit/apipie_resource_mock.rb +33 -11
- data/test/unit/architecture_test.rb +7 -10
- data/test/unit/commands_test.rb +8 -9
- data/test/unit/common_parameter_test.rb +6 -8
- data/test/unit/compute_resource_test.rb +9 -12
- data/test/unit/data/1.5/foreman_api.json +14130 -0
- data/test/unit/domain_test.rb +19 -22
- data/test/unit/environment_test.rb +9 -11
- data/test/unit/fact_test.rb +5 -6
- data/test/unit/helpers/command.rb +115 -59
- data/test/unit/helpers/fake_searchables.rb +19 -0
- data/test/unit/host_test.rb +44 -33
- data/test/unit/hostgroup_test.rb +19 -26
- data/test/unit/id_resolver_test.rb +225 -0
- data/test/unit/image_test.rb +16 -18
- data/test/unit/location_test.rb +8 -10
- data/test/unit/media_test.rb +11 -13
- data/test/unit/model_test.rb +8 -10
- data/test/unit/operating_system_test.rb +23 -23
- data/test/unit/organization_test.rb +9 -10
- data/test/unit/output/formatters_test.rb +133 -20
- data/test/unit/partition_table_test.rb +12 -9
- data/test/unit/puppet_class_test.rb +3 -7
- data/test/unit/report_test.rb +3 -7
- data/test/unit/searchables_option_builder_test.rb +172 -0
- data/test/unit/smart_class_parameter_test.rb +5 -7
- data/test/unit/smart_proxy_test.rb +11 -12
- data/test/unit/subnet_test.rb +15 -16
- data/test/unit/template_test.rb +15 -12
- data/test/unit/test_helper.rb +1 -1
- data/test/unit/user_test.rb +9 -12
- metadata +536 -509
@@ -0,0 +1,122 @@
|
|
1
|
+
module HammerCLIForeman
|
2
|
+
|
3
|
+
module References
|
4
|
+
|
5
|
+
|
6
|
+
def self.timestamps(dsl)
|
7
|
+
dsl.build do
|
8
|
+
field :created_at, _("Created at"), Fields::Date
|
9
|
+
field :updated_at, _("Updated at"), Fields::Date
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.taxonomies(dsl)
|
14
|
+
dsl.build do
|
15
|
+
collection :locations, _("Locations"), :numbered => false, :hide_blank => true do
|
16
|
+
custom_field Fields::Reference
|
17
|
+
end
|
18
|
+
collection :organizations, _("Organizations"), :numbered => false, :hide_blank => true do
|
19
|
+
custom_field Fields::Reference
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.users(dsl)
|
25
|
+
dsl.build do
|
26
|
+
collection :users, _("Users"), :numbered => false do
|
27
|
+
custom_field Fields::Reference, :name_key => :login
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.smart_proxies(dsl)
|
33
|
+
dsl.build do
|
34
|
+
collection :smart_proxies, _("Smart proxies"), :numbered => false do
|
35
|
+
custom_field Fields::Reference
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.compute_resources(dsl)
|
41
|
+
dsl.build do
|
42
|
+
collection :compute_resources, _("Compute resources"), :numbered => false do
|
43
|
+
custom_field Fields::Reference
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.media(dsl)
|
49
|
+
dsl.build do
|
50
|
+
collection :media, _("Installation media"), :numbered => false do
|
51
|
+
custom_field Fields::Reference
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.config_templates(dsl)
|
57
|
+
dsl.build do
|
58
|
+
collection :config_templates, _("Templates"), :numbered => false do
|
59
|
+
custom_field Fields::Template
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.domains(dsl)
|
65
|
+
dsl.build do
|
66
|
+
collection :domains, _("Domains"), :numbered => false do
|
67
|
+
custom_field Fields::Reference
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.environments(dsl)
|
73
|
+
dsl.build do
|
74
|
+
collection :environments, _("Environments"), :numbered => false do
|
75
|
+
custom_field Fields::Reference
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.hostgroups(dsl)
|
81
|
+
dsl.build do
|
82
|
+
collection :hostgroups, _("Hostgroups"), :numbered => false do
|
83
|
+
custom_field Fields::Reference
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.subnets(dsl)
|
89
|
+
dsl.build do
|
90
|
+
collection :subnets, _("Subnets"), :numbered => false do
|
91
|
+
custom_field Fields::Reference, :details => :network_address
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def self.parameters(dsl)
|
98
|
+
dsl.build do
|
99
|
+
collection :parameters, _("Parameters"), :numbered => false do
|
100
|
+
custom_field Fields::KeyValue
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.puppetclasses(dsl)
|
106
|
+
dsl.build do
|
107
|
+
collection :puppetclasses, _("Puppetclasses"), :numbered => false do
|
108
|
+
custom_field Fields::Reference
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.operating_systems(dsl)
|
114
|
+
dsl.build do
|
115
|
+
collection :operatingsystems, _("Operating systems"), :numbered => false do
|
116
|
+
custom_field Fields::Reference, :name_key => :fullname
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
@@ -20,14 +20,12 @@ module HammerCLIForeman
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
build_options
|
24
24
|
end
|
25
25
|
|
26
26
|
|
27
27
|
class InfoCommand < HammerCLIForeman::InfoCommand
|
28
28
|
|
29
|
-
identifiers :id
|
30
|
-
|
31
29
|
output do
|
32
30
|
field :id, _("Id")
|
33
31
|
field :host_name, _("Host")
|
@@ -70,16 +68,15 @@ module HammerCLIForeman
|
|
70
68
|
end
|
71
69
|
end
|
72
70
|
|
73
|
-
|
71
|
+
build_options
|
74
72
|
end
|
75
73
|
|
76
74
|
|
77
75
|
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
78
|
-
identifiers :id
|
79
76
|
success_message _("Report has been deleted")
|
80
77
|
failure_message _("Could not delete the report")
|
81
78
|
|
82
|
-
|
79
|
+
build_options
|
83
80
|
end
|
84
81
|
|
85
82
|
|
@@ -0,0 +1,99 @@
|
|
1
|
+
|
2
|
+
module HammerCLIForeman
|
3
|
+
|
4
|
+
class SearchablesOptionBuilder < HammerCLI::AbstractOptionBuilder
|
5
|
+
|
6
|
+
def initialize(resource, searchables)
|
7
|
+
@resource = resource
|
8
|
+
@searchables = searchables
|
9
|
+
end
|
10
|
+
|
11
|
+
def build(builder_params={})
|
12
|
+
@searchables.for(@resource).collect do |s|
|
13
|
+
option(
|
14
|
+
optionamize("--#{s.name}"),
|
15
|
+
s.name.upcase,
|
16
|
+
s.description
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
class DependentSearchablesOptionBuilder < HammerCLI::AbstractOptionBuilder
|
24
|
+
|
25
|
+
def initialize(dependent_resources, searchables)
|
26
|
+
@dependent_resources = dependent_resources.is_a?(Array) ? dependent_resources : [dependent_resources]
|
27
|
+
@searchables = searchables
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def build(builder_params={})
|
32
|
+
@dependent_resources.collect do |res|
|
33
|
+
dependent_options(res)
|
34
|
+
end.flatten(1)
|
35
|
+
end
|
36
|
+
|
37
|
+
def dependent_options(resource)
|
38
|
+
options = []
|
39
|
+
searchables = @searchables.for(resource)
|
40
|
+
resource_name = resource.singular_name
|
41
|
+
|
42
|
+
unless searchables.empty?
|
43
|
+
first = searchables[0]
|
44
|
+
remaining = searchables[1..-1] || []
|
45
|
+
|
46
|
+
# First option is named by the resource
|
47
|
+
# Eg. --organization with accessor option_organization_name
|
48
|
+
options << option(
|
49
|
+
optionamize("--#{resource_name}"),
|
50
|
+
"#{resource_name}_#{first.name}".upcase,
|
51
|
+
" ",
|
52
|
+
:attribute_name => HammerCLI.option_accessor_name("#{resource_name}_#{first.name}")
|
53
|
+
)
|
54
|
+
|
55
|
+
# Other options are named by the resource plus the searchable name
|
56
|
+
# Eg. --organization-label with accessor option_organization_label
|
57
|
+
remaining.each do |s|
|
58
|
+
options << option(
|
59
|
+
optionamize("--#{resource_name}-#{s.name}"),
|
60
|
+
"#{resource_name}_#{s.name}".upcase,
|
61
|
+
" "
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
options << option(
|
67
|
+
optionamize("--#{resource_name}-id"),
|
68
|
+
"#{resource_name}_id".upcase,
|
69
|
+
" "
|
70
|
+
)
|
71
|
+
options
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
class SearchablesUpdateOptionBuilder < HammerCLI::AbstractOptionBuilder
|
77
|
+
|
78
|
+
def initialize(resource, searchables)
|
79
|
+
@resource = resource
|
80
|
+
@searchables = searchables
|
81
|
+
end
|
82
|
+
|
83
|
+
def build(builder_params={})
|
84
|
+
|
85
|
+
@searchables.for(@resource).collect do |s|
|
86
|
+
if s.editable?
|
87
|
+
option(
|
88
|
+
optionamize("--new-#{s.name}"),
|
89
|
+
"NEW_#{s.name.upcase}",
|
90
|
+
" "
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end.compact
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module HammerCLIForeman
|
2
2
|
|
3
|
-
class SmartClassParametersBriefList < HammerCLIForeman::
|
3
|
+
class SmartClassParametersBriefList < HammerCLIForeman::AssociatedResourceListCommand
|
4
4
|
resource :smart_class_parameters, :index
|
5
5
|
command_name 'sc-params'
|
6
6
|
|
@@ -12,13 +12,18 @@ module HammerCLIForeman
|
|
12
12
|
field :override, _("Override")
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def send_request
|
16
16
|
res = super
|
17
17
|
# FIXME: API returns doubled records, probably just if filtered by puppetclasses
|
18
18
|
# it seems group by environment is missing
|
19
19
|
# having the uniq to fix that
|
20
20
|
HammerCLI::Output::RecordCollection.new(res.uniq, :meta => res.meta)
|
21
21
|
end
|
22
|
+
|
23
|
+
def self.build_options(options={})
|
24
|
+
options[:without] ||= [:host_id, :hostgroup_id, :puppetclass_id, :environment_id]
|
25
|
+
super(options)
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
29
|
class SmartClassParametersList < SmartClassParametersBriefList
|
@@ -35,9 +40,11 @@ module HammerCLIForeman
|
|
35
40
|
|
36
41
|
resource :smart_class_parameters
|
37
42
|
|
38
|
-
class ListCommand < HammerCLIForeman::
|
39
|
-
|
40
|
-
|
43
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
44
|
+
|
45
|
+
output SmartClassParametersList.output_definition
|
46
|
+
|
47
|
+
build_options
|
41
48
|
end
|
42
49
|
|
43
50
|
class InfoCommand < HammerCLIForeman::InfoCommand
|
@@ -46,8 +53,7 @@ module HammerCLIForeman
|
|
46
53
|
field :description, _("Description")
|
47
54
|
field :parameter_type, _("Type")
|
48
55
|
field :required, _("Required")
|
49
|
-
|
50
|
-
field :_environment_ids, _("Environment Ids"), Fields::List
|
56
|
+
|
51
57
|
label _("Validator") do
|
52
58
|
field :validator_type, _("Type")
|
53
59
|
field :validator_rule, _("Rule")
|
@@ -63,18 +69,16 @@ module HammerCLIForeman
|
|
63
69
|
end
|
64
70
|
end
|
65
71
|
end
|
66
|
-
|
67
|
-
|
72
|
+
HammerCLIForeman::References.environments(self)
|
73
|
+
HammerCLIForeman::References.timestamps(self)
|
68
74
|
end
|
69
75
|
|
70
76
|
def extend_data(res)
|
71
77
|
res['override_value_order'] = res['override_value_order'].split("\n")
|
72
|
-
res['_environments'] = res['environments'].map { |e| e['name']}
|
73
|
-
res['_environment_ids'] = res['environments'].map { |e| e['id']}
|
74
78
|
res
|
75
79
|
end
|
76
80
|
|
77
|
-
|
81
|
+
build_options
|
78
82
|
end
|
79
83
|
|
80
84
|
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
@@ -82,7 +86,7 @@ module HammerCLIForeman
|
|
82
86
|
success_message _("Parameter updated")
|
83
87
|
failure_message _("Could not update the parameter")
|
84
88
|
|
85
|
-
|
89
|
+
build_options :without => [:parameter_type, :validator_type, :override, :required]
|
86
90
|
|
87
91
|
option "--override", "OVERRIDE", _("Override this parameter."),
|
88
92
|
:format => HammerCLI::Options::Normalizers::Bool.new
|
@@ -6,72 +6,62 @@ module HammerCLIForeman
|
|
6
6
|
|
7
7
|
class ListCommand < HammerCLIForeman::ListCommand
|
8
8
|
|
9
|
-
action :index
|
10
|
-
|
11
9
|
#FIXME: search by unknown type returns 500 from the server, propper error handling should resove this
|
12
10
|
output do
|
13
11
|
field :id, _("Id")
|
14
12
|
field :name, _("Name")
|
15
13
|
field :url, _("URL")
|
14
|
+
field :_features, _( "Features"), Fields::List, :width => 25, :hide_blank => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def extend_data(proxy)
|
18
|
+
proxy['_features'] = proxy['features'].map { |f| f['name'] } if proxy['features']
|
19
|
+
proxy
|
16
20
|
end
|
17
21
|
|
18
|
-
|
22
|
+
build_options
|
19
23
|
end
|
20
24
|
|
21
25
|
|
22
26
|
class InfoCommand < HammerCLIForeman::InfoCommand
|
23
27
|
|
24
|
-
action :show
|
25
|
-
|
26
28
|
output ListCommand.output_definition do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def extend_data(proxy)
|
33
|
-
proxy['_features'] = proxy['features'].map { |f| f['name'] }
|
34
|
-
proxy
|
29
|
+
collection :features, _("Features"), :numbered => false do
|
30
|
+
custom_field Fields::Reference
|
31
|
+
end
|
32
|
+
HammerCLIForeman::References.taxonomies(self)
|
33
|
+
HammerCLIForeman::References.timestamps(self)
|
35
34
|
end
|
36
35
|
|
37
|
-
|
36
|
+
build_options
|
38
37
|
end
|
39
38
|
|
40
39
|
|
41
40
|
class CreateCommand < HammerCLIForeman::CreateCommand
|
42
|
-
|
43
|
-
action :create
|
44
|
-
|
45
41
|
success_message _("Smart proxy created")
|
46
42
|
failure_message _("Could not create the proxy")
|
47
43
|
|
48
|
-
|
44
|
+
build_options
|
49
45
|
end
|
50
46
|
|
51
47
|
|
52
48
|
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
53
|
-
|
54
|
-
action :update
|
55
|
-
|
56
49
|
success_message _("Smart proxy updated")
|
57
50
|
failure_message _("Could not update the proxy")
|
58
51
|
|
59
|
-
|
52
|
+
build_options
|
60
53
|
end
|
61
54
|
|
62
55
|
|
63
56
|
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
64
|
-
|
65
|
-
action :destroy
|
66
|
-
|
67
57
|
success_message _("Smart proxy deleted")
|
68
58
|
failure_message _("Could not delete the proxy")
|
69
59
|
|
70
|
-
|
60
|
+
build_options
|
71
61
|
end
|
72
62
|
|
73
63
|
|
74
|
-
class ImportPuppetClassesCommand < HammerCLIForeman::
|
64
|
+
class ImportPuppetClassesCommand < HammerCLIForeman::Command
|
75
65
|
|
76
66
|
action :import_puppetclasses
|
77
67
|
|
@@ -81,7 +71,7 @@ module HammerCLIForeman
|
|
81
71
|
|
82
72
|
option "--dryrun", :flag, _("Do not run the import")
|
83
73
|
|
84
|
-
|
74
|
+
build_options :without => [:smart_proxy_id, :dryrun]
|
85
75
|
|
86
76
|
def request_params
|
87
77
|
opts = super
|
@@ -13,7 +13,7 @@ module HammerCLIForeman
|
|
13
13
|
field :mask, _("Mask")
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
build_options
|
17
17
|
end
|
18
18
|
|
19
19
|
|
@@ -21,22 +21,21 @@ module HammerCLIForeman
|
|
21
21
|
|
22
22
|
output ListCommand.output_definition do
|
23
23
|
field :priority, _("Priority")
|
24
|
-
field :
|
25
|
-
field :dns, _("DNS"), Fields::Server
|
24
|
+
field :dns, _("DNS"), Fields::Reference, :details => :url
|
26
25
|
field :dns_primary, _("Primary DNS")
|
27
26
|
field :dns_secondary, _("Secondary DNS")
|
28
|
-
field :
|
29
|
-
field :
|
30
|
-
|
31
|
-
field :
|
32
|
-
field :dhcp_id, _("DHCP id")
|
33
|
-
field :vlanid, _("vlan id")
|
27
|
+
field :tftp, _("TFTP"), Fields::Reference, :details => :url
|
28
|
+
field :dhcp, _("DHCP"), Fields::Reference, :details => :url
|
29
|
+
|
30
|
+
field :vlanid, _("VLAN ID")
|
34
31
|
field :gateway, _("Gateway")
|
35
32
|
field :from, _("From")
|
36
33
|
field :to, _("To")
|
34
|
+
HammerCLIForeman::References.domains(self)
|
35
|
+
HammerCLIForeman::References.taxonomies(self)
|
37
36
|
end
|
38
37
|
|
39
|
-
|
38
|
+
build_options
|
40
39
|
end
|
41
40
|
|
42
41
|
|
@@ -45,7 +44,7 @@ module HammerCLIForeman
|
|
45
44
|
success_message _("Subnet created")
|
46
45
|
failure_message _("Could not create the subnet")
|
47
46
|
|
48
|
-
|
47
|
+
build_options
|
49
48
|
end
|
50
49
|
|
51
50
|
|
@@ -54,7 +53,7 @@ module HammerCLIForeman
|
|
54
53
|
success_message _("Subnet updated")
|
55
54
|
failure_message _("Could not update the subnet")
|
56
55
|
|
57
|
-
|
56
|
+
build_options
|
58
57
|
end
|
59
58
|
|
60
59
|
|
@@ -63,7 +62,7 @@ module HammerCLIForeman
|
|
63
62
|
success_message _("Subnet deleted")
|
64
63
|
failure_message _("Could not delete the subnet")
|
65
64
|
|
66
|
-
|
65
|
+
build_options
|
67
66
|
end
|
68
67
|
|
69
68
|
autoload_subcommands
|