hammer_cli_foreman 0.1.1 → 0.1.2

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.

Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -3
  3. data/doc/developer_docs.md +13 -0
  4. data/doc/name_id_resolution.md +50 -0
  5. data/doc/option_builder.md +48 -0
  6. data/doc/release_notes.md +64 -0
  7. data/lib/hammer_cli_foreman.rb +100 -23
  8. data/lib/hammer_cli_foreman/architecture.rb +0 -1
  9. data/lib/hammer_cli_foreman/associating_commands.rb +71 -0
  10. data/lib/hammer_cli_foreman/auth.rb +0 -1
  11. data/lib/hammer_cli_foreman/commands.rb +112 -80
  12. data/lib/hammer_cli_foreman/common_parameter.rb +5 -3
  13. data/lib/hammer_cli_foreman/compute_resource.rb +0 -2
  14. data/lib/hammer_cli_foreman/dependency_resolver.rb +32 -0
  15. data/lib/hammer_cli_foreman/domain.rb +0 -1
  16. data/lib/hammer_cli_foreman/environment.rb +0 -2
  17. data/lib/hammer_cli_foreman/exception_handler.rb +3 -3
  18. data/lib/hammer_cli_foreman/fact.rb +1 -1
  19. data/lib/hammer_cli_foreman/filter.rb +102 -0
  20. data/lib/hammer_cli_foreman/host.rb +5 -7
  21. data/lib/hammer_cli_foreman/hostgroup.rb +4 -3
  22. data/lib/hammer_cli_foreman/id_resolver.rb +60 -51
  23. data/lib/hammer_cli_foreman/image.rb +0 -1
  24. data/lib/hammer_cli_foreman/location.rb +7 -3
  25. data/lib/hammer_cli_foreman/media.rb +1 -1
  26. data/lib/hammer_cli_foreman/model.rb +1 -1
  27. data/lib/hammer_cli_foreman/operating_system.rb +4 -6
  28. data/lib/hammer_cli_foreman/option_builders.rb +285 -0
  29. data/lib/hammer_cli_foreman/organization.rb +7 -3
  30. data/lib/hammer_cli_foreman/param_filters.rb +61 -0
  31. data/lib/hammer_cli_foreman/parameter.rb +5 -3
  32. data/lib/hammer_cli_foreman/partition_table.rb +1 -1
  33. data/lib/hammer_cli_foreman/puppet_class.rb +1 -1
  34. data/lib/hammer_cli_foreman/references.rb +16 -0
  35. data/lib/hammer_cli_foreman/report.rb +1 -1
  36. data/lib/hammer_cli_foreman/role.rb +78 -0
  37. data/lib/hammer_cli_foreman/smart_class_parameter.rb +1 -1
  38. data/lib/hammer_cli_foreman/smart_proxy.rb +17 -2
  39. data/lib/hammer_cli_foreman/smart_variables.rb +111 -0
  40. data/lib/hammer_cli_foreman/subnet.rb +1 -1
  41. data/lib/hammer_cli_foreman/template.rb +10 -4
  42. data/lib/hammer_cli_foreman/user.rb +5 -1
  43. data/lib/hammer_cli_foreman/usergroup.rb +58 -0
  44. data/lib/hammer_cli_foreman/version.rb +1 -1
  45. data/locale/Makefile +12 -11
  46. data/locale/README.md +18 -0
  47. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  48. data/locale/en/hammer-cli-foreman.po +1584 -0
  49. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  50. data/locale/en_GB/hammer-cli-foreman.po +1975 -0
  51. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  52. data/locale/es/hammer-cli-foreman.po +1976 -0
  53. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  54. data/locale/fr/hammer-cli-foreman.po +1976 -0
  55. data/locale/hammer-cli-foreman.pot +1197 -787
  56. data/test/unit/api_test.rb +25 -0
  57. data/test/unit/architecture_test.rb +1 -0
  58. data/test/unit/commands_test.rb +18 -0
  59. data/test/unit/common_parameter_test.rb +1 -0
  60. data/test/unit/compute_resource_test.rb +1 -0
  61. data/test/unit/data/1.6/foreman_api.json +1 -0
  62. data/test/unit/dependency_resolver_test.rb +42 -0
  63. data/test/unit/domain_test.rb +1 -0
  64. data/test/unit/environment_test.rb +1 -0
  65. data/test/unit/fact_test.rb +1 -0
  66. data/test/unit/filter_test.rb +133 -0
  67. data/test/unit/helpers/command.rb +0 -13
  68. data/test/unit/host_test.rb +3 -0
  69. data/test/unit/hostgroup_test.rb +1 -0
  70. data/test/unit/id_resolver_test.rb +21 -68
  71. data/test/unit/image_test.rb +1 -1
  72. data/test/unit/location_test.rb +2 -0
  73. data/test/unit/media_test.rb +2 -0
  74. data/test/unit/model_test.rb +1 -0
  75. data/test/unit/operating_system_test.rb +1 -0
  76. data/test/unit/option_builders_test.rb +543 -0
  77. data/test/unit/organization_test.rb +1 -0
  78. data/test/unit/param_filters_test.rb +143 -0
  79. data/test/unit/partition_table_test.rb +1 -0
  80. data/test/unit/puppet_class_test.rb +1 -0
  81. data/test/unit/report_test.rb +1 -0
  82. data/test/unit/role_test.rb +94 -0
  83. data/test/unit/smart_class_parameter_test.rb +1 -0
  84. data/test/unit/smart_proxy_test.rb +14 -1
  85. data/test/unit/subnet_test.rb +1 -0
  86. data/test/unit/template_test.rb +1 -0
  87. data/test/unit/test_helper.rb +1 -1
  88. data/test/unit/user_test.rb +1 -0
  89. data/test/unit/usergroup_test.rb +80 -0
  90. metadata +50 -7
  91. data/lib/hammer_cli_foreman/searchables_option_builder.rb +0 -99
  92. data/test/unit/searchables_option_builder_test.rb +0 -172
@@ -41,7 +41,9 @@ module HammerCLIForeman
41
41
  end
42
42
 
43
43
 
44
- build_options
44
+ build_options do |o|
45
+ o.expand.primary(:organizations)
46
+ end
45
47
  end
46
48
 
47
49
 
@@ -75,7 +77,9 @@ module HammerCLIForeman
75
77
  success_message _("Organization deleted")
76
78
  failure_message _("Could not delete the organization")
77
79
 
78
- build_options
80
+ build_options do |o|
81
+ o.expand.primary(:organizations)
82
+ end
79
83
  end
80
84
 
81
85
 
@@ -94,5 +98,5 @@ module HammerCLIForeman
94
98
 
95
99
  end
96
100
 
97
- HammerCLI::MainCommand.subcommand 'organization', _("Manipulate organizations."), HammerCLIForeman::Organization
101
+
98
102
 
@@ -0,0 +1,61 @@
1
+ module HammerCLIForeman
2
+
3
+ class AbstractParamsFilter
4
+
5
+ def for_action(action)
6
+ filter(action.params)
7
+ end
8
+
9
+ def filter(params)
10
+ []
11
+ end
12
+
13
+ end
14
+
15
+ class ParamsFlattener < AbstractParamsFilter
16
+
17
+ def filter(params)
18
+ flatten_params(params)
19
+ end
20
+
21
+ private
22
+
23
+ def flatten_params(params)
24
+ result = params
25
+ params.each do |p|
26
+ result += flatten_params(p.params)
27
+ end
28
+ result
29
+ end
30
+
31
+ end
32
+
33
+ class IdParamsFilter < AbstractParamsFilter
34
+
35
+ def initialize(options={})
36
+ @required = !(options[:only_required] == false)
37
+ end
38
+
39
+ def filter(params)
40
+ params = ParamsFlattener.new.filter(params)
41
+ params = params.reject{ |p| !(p.name.end_with?("_id")) }
42
+ params = params.reject{ |p| !(p.required?) } if @required
43
+ params
44
+ end
45
+
46
+ end
47
+
48
+
49
+ class ParamsNameFilter < AbstractParamsFilter
50
+
51
+ def initialize(name)
52
+ @name = name
53
+ end
54
+
55
+ def filter(params)
56
+ ParamsFlattener.new.filter(params).select{ |p| p.name == @name }
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -7,7 +7,7 @@ module HammerCLIForeman
7
7
  class AbstractParameterCommand < HammerCLIForeman::Command
8
8
 
9
9
  def self.parameter_resource
10
- HammerCLIForeman.foreman_resource(:parameters)
10
+ HammerCLIForeman.foreman_resource!(:parameters)
11
11
  end
12
12
 
13
13
  def parameter_resource
@@ -34,10 +34,12 @@ module HammerCLIForeman
34
34
  }
35
35
  end
36
36
 
37
- def self.custom_option_builders
38
- [
37
+ def self.create_option_builder
38
+ builder = super
39
+ builder.builders = [
39
40
  DependentSearchablesOptionBuilder.new(resource, searchables)
40
41
  ]
42
+ builder
41
43
  end
42
44
 
43
45
  end
@@ -77,4 +77,4 @@ module HammerCLIForeman
77
77
 
78
78
  end
79
79
 
80
- HammerCLI::MainCommand.subcommand 'partition-table', _("Manipulate partition tables."), HammerCLIForeman::PartitionTable
80
+
@@ -57,5 +57,5 @@ module HammerCLIForeman
57
57
 
58
58
  end
59
59
 
60
- HammerCLI::MainCommand.subcommand 'puppet-class', _("Search puppet modules."), HammerCLIForeman::PuppetClass
60
+
61
61
 
@@ -29,6 +29,14 @@ module HammerCLIForeman
29
29
  end
30
30
  end
31
31
 
32
+ def self.usergroups(dsl)
33
+ dsl.build do
34
+ collection :usergroups, _("User groups"), :numbered => false do
35
+ custom_field Fields::Reference
36
+ end
37
+ end
38
+ end
39
+
32
40
  def self.smart_proxies(dsl)
33
41
  dsl.build do
34
42
  collection :smart_proxies, _("Smart proxies"), :numbered => false do
@@ -118,5 +126,13 @@ module HammerCLIForeman
118
126
  end
119
127
  end
120
128
 
129
+ def self.roles(dsl)
130
+ dsl.build do
131
+ collection :roles, _("Roles"), :numbered => false do
132
+ custom_field Fields::Reference
133
+ end
134
+ end
135
+ end
136
+
121
137
  end
122
138
  end
@@ -85,5 +85,5 @@ module HammerCLIForeman
85
85
 
86
86
  end
87
87
 
88
- HammerCLI::MainCommand.subcommand 'report', _("Browse and read reports."), HammerCLIForeman::Report
88
+
89
89
 
@@ -0,0 +1,78 @@
1
+ require 'hammer_cli_foreman/filter'
2
+
3
+ module HammerCLIForeman
4
+
5
+ class Role < HammerCLIForeman::Command
6
+
7
+ resource :roles
8
+
9
+ class ListCommand < HammerCLIForeman::ListCommand
10
+ output do
11
+ field :id, _("Id")
12
+ field :name, _("Name")
13
+ end
14
+
15
+ build_options
16
+ end
17
+
18
+
19
+ class FiltersCommand < HammerCLIForeman::ListCommand
20
+ command_name "filters"
21
+ resource :filters, :index
22
+
23
+ option "--id", "ID", _("User role id")
24
+
25
+ output HammerCLIForeman::Filter::ListCommand.output_definition
26
+
27
+ def request_params
28
+ role_id = get_resource_id(HammerCLIForeman.foreman_resource(:roles))
29
+
30
+ params = super
31
+ params[:search] = "role_id = \"#{role_id}\""
32
+ params
33
+ end
34
+
35
+ def extend_data(filter)
36
+ filter['resource_type'] ||= _("(Miscellaneous)")
37
+ filter['search'] ||= _("none")
38
+ filter['permissions'] = filter.fetch('permissions', []).collect{|p| p["name"]}
39
+ filter
40
+ end
41
+
42
+ build_options do |o|
43
+ o.expand.primary(:roles)
44
+ o.without(:search)
45
+ end
46
+ end
47
+
48
+
49
+ class CreateCommand < HammerCLIForeman::CreateCommand
50
+ success_message _("User role [%<name>s] created")
51
+ failure_message _("Could not create the user role")
52
+
53
+ build_options
54
+ end
55
+
56
+
57
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
58
+ success_message _("User role [%<name>s] updated")
59
+ failure_message _("Could not update the user role")
60
+
61
+ build_options
62
+ end
63
+
64
+
65
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
66
+ success_message _("User role [%<name>s] deleted")
67
+ failure_message _("Could not delete the user roles")
68
+
69
+ build_options
70
+ end
71
+
72
+ autoload_subcommands
73
+ end
74
+
75
+ end
76
+
77
+
78
+
@@ -104,6 +104,6 @@ module HammerCLIForeman
104
104
 
105
105
  end
106
106
 
107
- HammerCLI::MainCommand.subcommand 'sc-param', _("Manipulate smart class parameters."), HammerCLIForeman::SmartClassParameter
107
+
108
108
 
109
109
  end
@@ -71,7 +71,10 @@ module HammerCLIForeman
71
71
 
72
72
  option "--dryrun", :flag, _("Do not run the import")
73
73
 
74
- build_options :without => [:smart_proxy_id, :dryrun]
74
+ build_options do |o|
75
+ o.without(:smart_proxy_id, :dryrun)
76
+ o.expand.except(:smart_proxies)
77
+ end
75
78
 
76
79
  def request_params
77
80
  opts = super
@@ -80,9 +83,21 @@ module HammerCLIForeman
80
83
  end
81
84
  end
82
85
 
86
+
87
+ class RefreshFeaturesCommand < HammerCLIForeman::Command
88
+
89
+ action :refresh
90
+
91
+ command_name "refresh-features"
92
+ success_message _("Smart proxy features were refreshed")
93
+ failure_message _("Refresh of smart proxy features failed")
94
+
95
+ build_options
96
+ end
97
+
83
98
  autoload_subcommands
84
99
  end
85
100
 
86
101
  end
87
102
 
88
- HammerCLI::MainCommand.subcommand 'proxy', _("Manipulate smart proxies."), HammerCLIForeman::SmartProxy
103
+
@@ -0,0 +1,111 @@
1
+ module HammerCLIForeman
2
+
3
+ class SmartVariableBriefList < HammerCLIForeman::AssociatedResourceListCommand
4
+ resource :smart_variables, :index
5
+
6
+ output do
7
+ field :id, _("Id")
8
+
9
+ field :parameter, _("Parameter")
10
+ field :default_value, _("Default Value")
11
+ field :override, _("Override")
12
+ end
13
+
14
+ def send_request
15
+ res = super
16
+ # FIXME: API returns doubled records, probably just if filtered by puppetclasses
17
+ # it seems group by environment is missing
18
+ # having the uniq to fix that
19
+ HammerCLI::Output::RecordCollection.new(res.uniq, :meta => res.meta)
20
+ end
21
+
22
+ def self.build_options(options={})
23
+ options[:without] ||= [:host_id, :hostgroup_id, :puppetclass_id, :environment_id]
24
+ super(options)
25
+ end
26
+ end
27
+
28
+ class SmartVariableList < SmartVariableBriefList
29
+
30
+ output do
31
+ from :puppetclass do
32
+ field :name, _("Puppet class")
33
+ field :id, _("Class Id"), Fields::Id
34
+ end
35
+ end
36
+ end
37
+
38
+ class SmartVariable < HammerCLIForeman::Command
39
+
40
+ resource :smart_variables
41
+
42
+ class ListCommand < HammerCLIForeman::ListCommand
43
+
44
+ output SmartVariablesList.output_definition
45
+
46
+ build_options
47
+ end
48
+
49
+ class InfoCommand < HammerCLIForeman::InfoCommand
50
+
51
+ output ListCommand.output_definition do
52
+ field :description, _("Description")
53
+ field :parameter_type, _("Type")
54
+ field :required, _("Required")
55
+
56
+ label _("Validator") do
57
+ field :validator_type, _("Type")
58
+ field :validator_rule, _("Rule")
59
+ end
60
+ label _("Override values") do
61
+ field :override_value_order, _("Order"), Fields::List
62
+ field :override_values_count, _("Count")
63
+ collection :override_values, "Values" do
64
+ label _("Value") do
65
+ field :id, _('Id')
66
+ field :match, _('Match')
67
+ field :value, _('Value')
68
+ end
69
+ end
70
+ end
71
+ HammerCLIForeman::References.environments(self)
72
+ HammerCLIForeman::References.timestamps(self)
73
+ end
74
+
75
+ def extend_data(res)
76
+ res['override_value_order'] = res['override_value_order'].split("\n")
77
+ res
78
+ end
79
+
80
+ build_options
81
+ end
82
+
83
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
84
+
85
+ success_message _("Parameter updated")
86
+ failure_message _("Could not update the parameter")
87
+
88
+ build_options :without => [:parameter_type, :validator_type, :override, :required]
89
+
90
+ option "--override", "OVERRIDE", _("Override this parameter."),
91
+ :format => HammerCLI::Options::Normalizers::Bool.new
92
+ option "--required", "REQUIRED", _("This parameter is required."),
93
+ :format => HammerCLI::Options::Normalizers::Bool.new
94
+ option "--parameter-type", "PARAMETER_TYPE", _("Type of the parameter."),
95
+ :format => HammerCLI::Options::Normalizers::Enum.new(
96
+ ['string', 'boolean', 'integer', 'real', 'array', 'hash', 'yaml', 'json'])
97
+ option "--validator-type", "VALIDATOR_TYPE", _("Type of the validator."),
98
+ :format => HammerCLI::Options::Normalizers::Enum.new(['regexp', 'list', ''])
99
+ end
100
+
101
+ class AddOverrideValueCommand < HammerCLIForeman::UpdateCommand
102
+
103
+ end
104
+
105
+ autoload_subcommands
106
+
107
+ end
108
+
109
+ HammerCLI::MainCommand.subcommand 'smart-variable', _("Manipulate smart variables."), HammerCLIForeman::SmartVariable
110
+
111
+ end
@@ -70,5 +70,5 @@ module HammerCLIForeman
70
70
 
71
71
  end
72
72
 
73
- HammerCLI::MainCommand.subcommand 'subnet', _("Manipulate subnets."), HammerCLIForeman::Subnet
73
+
74
74
 
@@ -12,7 +12,7 @@ module HammerCLIForeman
12
12
 
13
13
  def option_template_kind_id
14
14
  kinds = HammerCLIForeman.collection_to_common_format(
15
- HammerCLIForeman.foreman_resource(:template_kinds).call(:index))
15
+ HammerCLIForeman.foreman_resource!(:template_kinds).call(:index))
16
16
  table = kinds.inject({}){ |result, k| result.update(k["name"] => k["id"]) }
17
17
  table[option_type]
18
18
  end
@@ -108,7 +108,10 @@ module HammerCLIForeman
108
108
 
109
109
  include TemplateCreateUpdateCommons
110
110
 
111
- build_options :without => [:template_combinations_attributes, :template, :snippet, :template_kind_id]
111
+ build_options do |o|
112
+ o.without(:template_combinations_attributes, :template, :snippet, :template_kind_id)
113
+ o.expand.except(:template_kinds)
114
+ end
112
115
  end
113
116
 
114
117
 
@@ -123,7 +126,10 @@ module HammerCLIForeman
123
126
 
124
127
  include TemplateCreateUpdateCommons
125
128
 
126
- build_options :without => [:template_combinations_attributes, :template, :snippet, :template_kind_id]
129
+ build_options do |o|
130
+ o.without(:template_combinations_attributes, :template, :snippet, :template_kind_id)
131
+ o.expand.except(:template_kinds)
132
+ end
127
133
  end
128
134
 
129
135
 
@@ -145,5 +151,5 @@ module HammerCLIForeman
145
151
 
146
152
  end
147
153
 
148
- HammerCLI::MainCommand.subcommand 'template', _("Manipulate config templates."), HammerCLIForeman::Template
154
+
149
155