hammer_cli_foreman 0.1.1 → 0.1.2

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.
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
@@ -1,99 +0,0 @@
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,172 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
2
- require File.join(File.dirname(__FILE__), 'helpers/fake_searchables')
3
-
4
-
5
-
6
- describe HammerCLIForeman::SearchablesOptionBuilder do
7
-
8
- let(:resource) { HammerCLIForeman.foreman_resource(:architectures) }
9
- let(:searchables) { FakeSearchables.new(["name", "label"]) }
10
- let(:builder) { HammerCLIForeman::SearchablesOptionBuilder.new(resource, searchables) }
11
- let(:options) { builder.build }
12
-
13
- describe "empty searchables" do
14
- let(:searchables) { FakeSearchables.new([]) }
15
-
16
- it "builds no options for empty searchables" do
17
- options.must_equal []
18
- end
19
- end
20
-
21
- describe "multiple searchables" do
22
-
23
- it "builds correct switches" do
24
- options.map(&:switches).must_equal [["--name"], ["--label"]]
25
- end
26
-
27
- it "builds correct descriptions" do
28
- options.map(&:description).must_equal ["Search by name", "Search by label"]
29
- end
30
-
31
- it "builds correct types" do
32
- options.map(&:type).must_equal ["NAME", "LABEL"]
33
- end
34
-
35
- it "builds correct attribute readers" do
36
- options.map(&:read_method).must_equal [
37
- "option_name",
38
- "option_label"
39
- ]
40
- end
41
-
42
- it "none of the options is required" do
43
- options.any?{|opt| opt.required? }.must_equal false
44
- end
45
- end
46
-
47
- end
48
-
49
-
50
- describe HammerCLIForeman::DependentSearchablesOptionBuilder do
51
-
52
- let(:resource) { HammerCLIForeman.foreman_resource(:architectures) }
53
- let(:searchables) { FakeSearchables.new(["name", "label", "uuid"]) }
54
- let(:builder) { HammerCLIForeman::DependentSearchablesOptionBuilder.new(resource, searchables) }
55
- let(:options) { builder.build }
56
-
57
- describe "empty searchables" do
58
-
59
- let(:searchables) { FakeSearchables.new([]) }
60
-
61
- it "builds only id options" do
62
- options.map(&:switches).must_equal [["--architecture-id"]]
63
- end
64
-
65
- end
66
-
67
-
68
- describe "multiple searchables" do
69
-
70
- it "creates correct switches" do
71
- options.map(&:switches).must_equal [
72
- ["--architecture"], # first option does not have the suffix
73
- ["--architecture-label"], # other options with suffixes
74
- ["--architecture-uuid"],
75
- ["--architecture-id"] # additional id
76
- ]
77
- end
78
-
79
- it "creates correct option types" do
80
- options.map(&:type).must_equal [
81
- "ARCHITECTURE_NAME",
82
- "ARCHITECTURE_LABEL",
83
- "ARCHITECTURE_UUID",
84
- "ARCHITECTURE_ID",
85
- ]
86
- end
87
-
88
- it "creates correct attribute readers" do
89
- options.map(&:read_method).must_equal [
90
- "option_architecture_name",
91
- "option_architecture_label",
92
- "option_architecture_uuid",
93
- "option_architecture_id",
94
- ]
95
- end
96
-
97
- it "none of the options is required" do
98
- options.any?{|opt| opt.required? }.must_equal false
99
- end
100
- end
101
-
102
-
103
- describe "multiple resources" do
104
-
105
- let(:resource) { [
106
- HammerCLIForeman.foreman_resource(:architectures),
107
- HammerCLIForeman.foreman_resource(:domains)
108
- ] }
109
- let(:searchables) { FakeSearchables.new(["name", "label"]) }
110
-
111
- it "builds options for all resources" do
112
- options.map(&:switches).must_equal [
113
- ["--architecture"], # first option does not have the suffix
114
- ["--architecture-label"], # other options with suffixes
115
- ["--architecture-id"], # additional id
116
- ["--domain"], # first option does not have the suffix
117
- ["--domain-label"], # other options with suffixes
118
- ["--domain-id"] # additional id
119
- ]
120
- end
121
-
122
- it "none of the options is required" do
123
- options.any?{|opt| opt.required? }.must_equal false
124
- end
125
-
126
- end
127
-
128
- end
129
-
130
-
131
- describe HammerCLIForeman::SearchablesUpdateOptionBuilder do
132
-
133
- let(:resource) { HammerCLIForeman.foreman_resource(:architectures) }
134
- let(:searchables) { FakeSearchables.new(["name"], ["label"]) }
135
- let(:builder) { HammerCLIForeman::SearchablesUpdateOptionBuilder.new(resource, searchables) }
136
- let(:options) { builder.build }
137
-
138
- describe "empty searchables" do
139
- let(:searchables) { FakeSearchables.new([]) }
140
-
141
- it "builds no options for empty searchables" do
142
- options.must_equal []
143
- end
144
- end
145
-
146
- describe "multiple searchables" do
147
-
148
- it "builds correct switches" do
149
- options.map(&:switches).must_equal [["--new-label"]]
150
- end
151
-
152
- it "builds correct descriptions" do
153
- options.map(&:description).must_equal [" "]
154
- end
155
-
156
- it "builds correct types" do
157
- options.map(&:type).must_equal ["NEW_LABEL"]
158
- end
159
-
160
- it "builds correct attribute readers" do
161
- options.map(&:read_method).must_equal [
162
- "option_new_label"
163
- ]
164
- end
165
-
166
- it "none of the options is required" do
167
- options.any?{|opt| opt.required? }.must_equal false
168
- end
169
- end
170
-
171
-
172
- end