hammer_cli_foreman 0.0.11 → 0.0.12
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/lib/hammer_cli_foreman/architecture.rb +5 -9
- data/lib/hammer_cli_foreman/commands.rb +55 -0
- data/lib/hammer_cli_foreman/common_parameter.rb +2 -4
- data/lib/hammer_cli_foreman/compute_resource.rb +10 -14
- data/lib/hammer_cli_foreman/domain.rb +16 -17
- data/lib/hammer_cli_foreman/environment.rb +6 -10
- data/lib/hammer_cli_foreman/fact.rb +6 -8
- data/lib/hammer_cli_foreman/host.rb +59 -60
- data/lib/hammer_cli_foreman/hostgroup.rb +17 -16
- data/lib/hammer_cli_foreman/image.rb +11 -17
- data/lib/hammer_cli_foreman/location.rb +4 -8
- data/lib/hammer_cli_foreman/media.rb +7 -29
- data/lib/hammer_cli_foreman/model.rb +7 -11
- data/lib/hammer_cli_foreman/operating_system.rb +25 -22
- data/lib/hammer_cli_foreman/organization.rb +4 -8
- data/lib/hammer_cli_foreman/output/formatters.rb +3 -2
- data/lib/hammer_cli_foreman/parameter.rb +8 -9
- data/lib/hammer_cli_foreman/partition_table.rb +6 -10
- data/lib/hammer_cli_foreman/puppet_class.rb +12 -13
- data/lib/hammer_cli_foreman/report.rb +43 -47
- data/lib/hammer_cli_foreman/smart_class_parameter.rb +6 -7
- data/lib/hammer_cli_foreman/smart_proxy.rb +11 -17
- data/lib/hammer_cli_foreman/subnet.rb +17 -21
- data/lib/hammer_cli_foreman/template.rb +27 -32
- data/lib/hammer_cli_foreman/user.rb +19 -27
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/test/unit/commands_test.rb +79 -0
- data/test/unit/output/formatters_test.rb +10 -0
- data/test/unit/test_output_adapter.rb +6 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c9636fa0ca48a82b536662e35f1cd988ee25db9
|
4
|
+
data.tar.gz: 04975e3d8bf5e7926dfe2b32fc7fa60b990d49a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 953e5470e53f5b93517549dd5033f5d5133993a2e6f4b7869442ca61c0be678b9f8681549ff7d4961f87ccb35d958a43e28529b33fd5f794288ce066213f788a
|
7
|
+
data.tar.gz: 423b4e98464a0c927d1438ba4004b77a194c64d46008b0f5f530db42f24a13c8a31aad7860daf5892ce73cc539512e6ac8348df96b70c7aa509e0e437fe1397f
|
@@ -12,10 +12,8 @@ module HammerCLIForeman
|
|
12
12
|
class ListCommand < HammerCLIForeman::ListCommand
|
13
13
|
|
14
14
|
output do
|
15
|
-
|
16
|
-
|
17
|
-
field :name, "Name"
|
18
|
-
end
|
15
|
+
field :id, "Id"
|
16
|
+
field :name, "Name"
|
19
17
|
end
|
20
18
|
|
21
19
|
apipie_options
|
@@ -25,11 +23,9 @@ module HammerCLIForeman
|
|
25
23
|
class InfoCommand < HammerCLIForeman::InfoCommand
|
26
24
|
|
27
25
|
output ListCommand.output_definition do
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
field :updated_at, "Updated at", Fields::Date
|
32
|
-
end
|
26
|
+
field :operatingsystem_ids, "OS ids", Fields::List
|
27
|
+
field :created_at, "Created at", Fields::Date
|
28
|
+
field :updated_at, "Updated at", Fields::Date
|
33
29
|
end
|
34
30
|
|
35
31
|
end
|
@@ -2,6 +2,32 @@ require 'hammer_cli'
|
|
2
2
|
|
3
3
|
module HammerCLIForeman
|
4
4
|
|
5
|
+
def self.collection_to_common_format(data)
|
6
|
+
if data.class <= Hash && data.has_key?('total') && data.has_key?('results')
|
7
|
+
col = HammerCLI::Output::RecordCollection.new(data['results'],
|
8
|
+
:total => data['total'],
|
9
|
+
:subtotal => data['subtotal'],
|
10
|
+
:page => data['page'],
|
11
|
+
:per_page => data['per_page'],
|
12
|
+
:search => data['search'],
|
13
|
+
:sort_by => data['sort']['by'],
|
14
|
+
:sort_order => data['sort']['order'])
|
15
|
+
elsif data.class <= Hash
|
16
|
+
col = HammerCLI::Output::RecordCollection.new(data)
|
17
|
+
elsif data.class <= Array
|
18
|
+
# remove object types. From [ { 'type' => { 'attr' => val } }, ... ]
|
19
|
+
# produce [ { 'attr' => 'val' }, ... ]
|
20
|
+
col = HammerCLI::Output::RecordCollection.new(data.map { |r| r.keys.length == 1 ? r[r.keys[0]] : r })
|
21
|
+
else
|
22
|
+
raise RuntimeError.new("Received data of unknown format")
|
23
|
+
end
|
24
|
+
col
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.record_to_common_format(data)
|
28
|
+
data.class <= Hash && data.keys.length == 1 ? data[data.keys[0]] : data
|
29
|
+
end
|
30
|
+
|
5
31
|
class WriteCommand < HammerCLI::Apipie::WriteCommand
|
6
32
|
|
7
33
|
def success_message_params(response)
|
@@ -14,6 +40,10 @@ module HammerCLIForeman
|
|
14
40
|
end
|
15
41
|
end
|
16
42
|
|
43
|
+
def send_request
|
44
|
+
HammerCLIForeman.record_to_common_format(resource.call(action, request_params)[0])
|
45
|
+
end
|
46
|
+
|
17
47
|
end
|
18
48
|
|
19
49
|
class ListCommand < HammerCLI::Apipie::ReadCommand
|
@@ -24,6 +54,17 @@ module HammerCLIForeman
|
|
24
54
|
:table
|
25
55
|
end
|
26
56
|
|
57
|
+
def retrieve_data
|
58
|
+
data = super
|
59
|
+
set = HammerCLIForeman.collection_to_common_format(data)
|
60
|
+
set.map! { |r| extend_data(r) }
|
61
|
+
set
|
62
|
+
end
|
63
|
+
|
64
|
+
def extend_data(record)
|
65
|
+
record
|
66
|
+
end
|
67
|
+
|
27
68
|
def self.command_name(name=nil)
|
28
69
|
super(name) || "list"
|
29
70
|
end
|
@@ -49,6 +90,20 @@ module HammerCLIForeman
|
|
49
90
|
super({:without => declared_identifiers.keys}.merge(options))
|
50
91
|
end
|
51
92
|
|
93
|
+
def retrieve_data
|
94
|
+
data = super
|
95
|
+
record = HammerCLIForeman.record_to_common_format(data)
|
96
|
+
extend_data(record)
|
97
|
+
end
|
98
|
+
|
99
|
+
def extend_data(record)
|
100
|
+
record
|
101
|
+
end
|
102
|
+
|
103
|
+
def print_data(record)
|
104
|
+
print_record(output_definition, record)
|
105
|
+
end
|
106
|
+
|
52
107
|
end
|
53
108
|
|
54
109
|
|
@@ -10,10 +10,8 @@ module HammerCLIForeman
|
|
10
10
|
resource ForemanApi::Resources::CommonParameter, "index"
|
11
11
|
|
12
12
|
output do
|
13
|
-
|
14
|
-
|
15
|
-
field :value, "Value"
|
16
|
-
end
|
13
|
+
field :name, "Name"
|
14
|
+
field :value, "Value"
|
17
15
|
end
|
18
16
|
|
19
17
|
apipie_options
|
@@ -11,11 +11,9 @@ module HammerCLIForeman
|
|
11
11
|
class ListCommand < HammerCLIForeman::ListCommand
|
12
12
|
|
13
13
|
output do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
field :provider, "Provider"
|
18
|
-
end
|
14
|
+
field :id, "Id"
|
15
|
+
field :name, "Name"
|
16
|
+
field :provider, "Provider"
|
19
17
|
end
|
20
18
|
|
21
19
|
apipie_options
|
@@ -46,19 +44,17 @@ module HammerCLIForeman
|
|
46
44
|
}
|
47
45
|
|
48
46
|
output ListCommand.output_definition do
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
field :updated_at, "Updated at", Fields::Date
|
55
|
-
end
|
47
|
+
field :url, "Url"
|
48
|
+
field :description, "Description"
|
49
|
+
field :user, "User"
|
50
|
+
field :created_at, "Created at", Fields::Date
|
51
|
+
field :updated_at, "Updated at", Fields::Date
|
56
52
|
end
|
57
53
|
|
58
54
|
def print_data(data)
|
59
|
-
provider = data["
|
55
|
+
provider = data["provider"].downcase
|
60
56
|
output_definition.fields.concat PROVIDER_SPECIFIC_FIELDS[provider]
|
61
|
-
|
57
|
+
print_collection(output_definition, data)
|
62
58
|
end
|
63
59
|
|
64
60
|
end
|
@@ -10,10 +10,8 @@ module HammerCLIForeman
|
|
10
10
|
resource ForemanApi::Resources::Domain, "index"
|
11
11
|
|
12
12
|
output do
|
13
|
-
|
14
|
-
|
15
|
-
field :name, "Name"
|
16
|
-
end
|
13
|
+
field :id, "Id"
|
14
|
+
field :name, "Name"
|
17
15
|
end
|
18
16
|
|
19
17
|
apipie_options
|
@@ -24,24 +22,21 @@ module HammerCLIForeman
|
|
24
22
|
|
25
23
|
resource ForemanApi::Resources::Domain, "show"
|
26
24
|
|
27
|
-
def retrieve_data
|
28
|
-
domain = super
|
29
|
-
domain["parameters"] = HammerCLIForeman::Parameter.get_parameters resource_config, domain
|
30
|
-
domain
|
31
|
-
end
|
32
|
-
|
33
25
|
output ListCommand.output_definition do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
field :updated_at, "Updated at", Fields::Date
|
39
|
-
end
|
26
|
+
field :fullname, "Description"
|
27
|
+
field :dns_id, "DNS Id"
|
28
|
+
field :created_at, "Created at", Fields::Date
|
29
|
+
field :updated_at, "Updated at", Fields::Date
|
40
30
|
collection :parameters, "Parameters" do
|
41
|
-
field
|
31
|
+
field nil, nil, Fields::KeyValue
|
42
32
|
end
|
43
33
|
end
|
44
34
|
|
35
|
+
def extend_data(record)
|
36
|
+
record["parameters"] = HammerCLIForeman::Parameter.get_parameters(resource_config, :domain, record)
|
37
|
+
record
|
38
|
+
end
|
39
|
+
|
45
40
|
end
|
46
41
|
|
47
42
|
|
@@ -79,6 +74,8 @@ module HammerCLIForeman
|
|
79
74
|
|
80
75
|
class SetParameterCommand < HammerCLIForeman::Parameter::SetCommand
|
81
76
|
|
77
|
+
resource ForemanApi::Resources::Parameter
|
78
|
+
|
82
79
|
desc "Create or update parameter for a domain."
|
83
80
|
|
84
81
|
option "--domain-name", "DOMAIN_NAME", "name of the domain the parameter is being set for"
|
@@ -103,6 +100,8 @@ module HammerCLIForeman
|
|
103
100
|
|
104
101
|
class DeleteParameterCommand < HammerCLIForeman::Parameter::DeleteCommand
|
105
102
|
|
103
|
+
resource ForemanApi::Resources::Parameter
|
104
|
+
|
106
105
|
desc "Delete parameter for a domain."
|
107
106
|
|
108
107
|
option "--domain-name", "DOMAIN_NAME", "name of the domain the parameter is being deleted for"
|
@@ -11,10 +11,8 @@ module HammerCLIForeman
|
|
11
11
|
resource ForemanApi::Resources::Environment, "index"
|
12
12
|
|
13
13
|
output do
|
14
|
-
|
15
|
-
|
16
|
-
field :name, "Name"
|
17
|
-
end
|
14
|
+
field :id, "Id"
|
15
|
+
field :name, "Name"
|
18
16
|
end
|
19
17
|
|
20
18
|
apipie_options
|
@@ -25,10 +23,8 @@ module HammerCLIForeman
|
|
25
23
|
resource ForemanApi::Resources::Environment, "show"
|
26
24
|
|
27
25
|
output ListCommand.output_definition do
|
28
|
-
|
29
|
-
|
30
|
-
field :updated_at, "Updated at", Fields::Date
|
31
|
-
end
|
26
|
+
field :created_at, "Created at", Fields::Date
|
27
|
+
field :updated_at, "Updated at", Fields::Date
|
32
28
|
end
|
33
29
|
|
34
30
|
end
|
@@ -66,8 +62,8 @@ module HammerCLIForeman
|
|
66
62
|
class SCParamsCommand < HammerCLIForeman::SmartClassParametersList
|
67
63
|
|
68
64
|
apipie_options :without => [:host_id, :hostgroup_id, :puppetclass_id, :environment_id]
|
69
|
-
option ['--id', '--name'], 'ENVIRONMENT_ID', 'environment id/name',
|
70
|
-
:required => true, :attribute_name => :environment_id
|
65
|
+
option ['--id', '--name'], 'ENVIRONMENT_ID', 'environment id/name',
|
66
|
+
:required => true, :attribute_name => :environment_id
|
71
67
|
end
|
72
68
|
|
73
69
|
|
@@ -13,11 +13,9 @@ module HammerCLIForeman
|
|
13
13
|
apipie_options
|
14
14
|
|
15
15
|
output do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
field :value, "Value"
|
20
|
-
end
|
16
|
+
field :host, "Host"
|
17
|
+
field :fact, "Fact"
|
18
|
+
field :value, "Value"
|
21
19
|
end
|
22
20
|
|
23
21
|
def retrieve_data
|
@@ -25,13 +23,13 @@ module HammerCLIForeman
|
|
25
23
|
end
|
26
24
|
|
27
25
|
def self.unhash_facts(facts_hash)
|
28
|
-
facts_hash.inject([]) do |list, (host, facts)|
|
26
|
+
facts = facts_hash.first.inject([]) do |list, (host, facts)|
|
29
27
|
list + facts.collect do |(fact, value)|
|
30
|
-
{ :
|
28
|
+
{ :host => host, :fact => fact, :value => value }
|
31
29
|
end
|
32
30
|
end
|
31
|
+
HammerCLI::Output::RecordCollection.new(facts, :meta => facts_hash.meta)
|
33
32
|
end
|
34
|
-
|
35
33
|
end
|
36
34
|
|
37
35
|
autoload_subcommands
|
@@ -99,14 +99,12 @@ module HammerCLIForeman
|
|
99
99
|
class ListCommand < HammerCLIForeman::ListCommand
|
100
100
|
# FIXME: list compute resource (model)
|
101
101
|
output do
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
field :mac, "MAC"
|
109
|
-
end
|
102
|
+
field :id, "Id"
|
103
|
+
field :name, "Name"
|
104
|
+
field :operatingsystem_id, "Operating System Id"
|
105
|
+
field :hostgroup_id, "Host Group Id"
|
106
|
+
field :ip, "IP"
|
107
|
+
field :mac, "MAC"
|
110
108
|
end
|
111
109
|
|
112
110
|
apipie_options
|
@@ -115,57 +113,55 @@ module HammerCLIForeman
|
|
115
113
|
|
116
114
|
class InfoCommand < HammerCLIForeman::InfoCommand
|
117
115
|
|
118
|
-
def
|
119
|
-
host =
|
120
|
-
host["
|
121
|
-
host["parameters"] = HammerCLIForeman::Parameter.get_parameters(resource_config, host)
|
116
|
+
def extend_data(host)
|
117
|
+
host["environment_name"] = host["environment"]["environment"]["name"] rescue nil
|
118
|
+
host["parameters"] = HammerCLIForeman::Parameter.get_parameters(resource_config, :host, host)
|
122
119
|
host
|
123
120
|
end
|
124
121
|
|
125
122
|
output ListCommand.output_definition do
|
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
|
-
end
|
123
|
+
field :uuid, "UUID"
|
124
|
+
field :certname, "Cert name"
|
125
|
+
|
126
|
+
field :environment_name, "Environment"
|
127
|
+
field :environment_id, "Environment Id"
|
128
|
+
|
129
|
+
field :managed, "Managed"
|
130
|
+
field :enabled, "Enabled"
|
131
|
+
field :build, "Build"
|
132
|
+
|
133
|
+
field :use_image, "Use image"
|
134
|
+
field :disk, "Disk"
|
135
|
+
field :image_file, "Image file"
|
136
|
+
|
137
|
+
field :sp_name, "SP Name"
|
138
|
+
field :sp_ip, "SP IP"
|
139
|
+
field :sp_mac, "SP MAC"
|
140
|
+
field :sp_subnet, "SP Subnet"
|
141
|
+
field :sp_subnet_id, "SP Subnet Id"
|
142
|
+
|
143
|
+
field :created_at, "Created at", Fields::Date
|
144
|
+
field :updated_at, "Updated at", Fields::Date
|
145
|
+
field :installed_at, "Installed at", Fields::Date
|
146
|
+
field :last_report, "Last report", Fields::Date
|
147
|
+
|
148
|
+
field :puppet_ca_proxy_id, "Puppet CA Proxy Id"
|
149
|
+
field :medium_id, "Medium Id"
|
150
|
+
field :model_id, "Model Id"
|
151
|
+
field :owner_id, "Owner Id"
|
152
|
+
field :subnet_id, "Subnet Id"
|
153
|
+
field :domain_id, "Domain Id"
|
154
|
+
field :puppet_proxy_id, "Puppet Proxy Id"
|
155
|
+
field :owner_type, "Owner Type"
|
156
|
+
field :ptable_id, "Partition Table Id"
|
157
|
+
field :architecture_id, "Architecture Id"
|
158
|
+
field :image_id, "Image Id"
|
159
|
+
field :compute_resource_id, "Compute Resource Id"
|
160
|
+
|
161
|
+
field :comment, "Comment"
|
162
|
+
|
167
163
|
collection :parameters, "Parameters" do
|
168
|
-
field
|
164
|
+
field nil, nil, Fields::KeyValue
|
169
165
|
end
|
170
166
|
end
|
171
167
|
end
|
@@ -228,10 +224,8 @@ module HammerCLIForeman
|
|
228
224
|
apipie_options :without => declared_identifiers.keys
|
229
225
|
|
230
226
|
output do
|
231
|
-
|
232
|
-
|
233
|
-
field :value, "Value"
|
234
|
-
end
|
227
|
+
field :fact, "Fact"
|
228
|
+
field :value, "Value"
|
235
229
|
end
|
236
230
|
|
237
231
|
def request_params
|
@@ -241,7 +235,8 @@ module HammerCLIForeman
|
|
241
235
|
end
|
242
236
|
|
243
237
|
def retrieve_data
|
244
|
-
|
238
|
+
data = super
|
239
|
+
HammerCLIForeman::Fact::ListCommand.unhash_facts(data)
|
245
240
|
end
|
246
241
|
|
247
242
|
end
|
@@ -324,6 +319,8 @@ module HammerCLIForeman
|
|
324
319
|
|
325
320
|
class SetParameterCommand < HammerCLIForeman::Parameter::SetCommand
|
326
321
|
|
322
|
+
resource ForemanApi::Resources::Parameter
|
323
|
+
|
327
324
|
desc "Create or update parameter for a host."
|
328
325
|
|
329
326
|
option "--host-name", "HOST_NAME", "name of the host the parameter is being set for"
|
@@ -348,6 +345,8 @@ module HammerCLIForeman
|
|
348
345
|
|
349
346
|
class DeleteParameterCommand < HammerCLIForeman::Parameter::DeleteCommand
|
350
347
|
|
348
|
+
resource ForemanApi::Resources::Parameter
|
349
|
+
|
351
350
|
desc "Delete parameter for a host."
|
352
351
|
|
353
352
|
option "--host-name", "HOST_NAME", "name of the host the parameter is being deleted for"
|
@@ -427,7 +426,7 @@ module HammerCLIForeman
|
|
427
426
|
class SCParamsCommand < HammerCLIForeman::SmartClassParametersList
|
428
427
|
|
429
428
|
apipie_options :without => [:host_id, :hostgroup_id, :puppetclass_id, :environment_id]
|
430
|
-
option ['--id', '--name'], 'HOST_ID', 'host id/name',
|
429
|
+
option ['--id', '--name'], 'HOST_ID', 'host id/name',
|
431
430
|
:attribute_name => :host_id, :required => true
|
432
431
|
end
|
433
432
|
|