hammer_cli_foreman 0.0.11 → 0.0.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42450c6d2fad76c1f31ea6a860406c4a6511ccd8
4
- data.tar.gz: d6b26b6896df8cd1db9b2f4e8d3f5a037d145167
3
+ metadata.gz: 1c9636fa0ca48a82b536662e35f1cd988ee25db9
4
+ data.tar.gz: 04975e3d8bf5e7926dfe2b32fc7fa60b990d49a1
5
5
  SHA512:
6
- metadata.gz: fa6ed7e0730233e68b0ee1c4894905a34b6352a9225f73536830ab993dfc9606454339e70173cbb20f122c0b258e2dde6b0e39a173df7f5b92e1c1435433378c
7
- data.tar.gz: 34c6dc5106bf9d507927600b20c778e6272cf4a24d15eda085b25ac5aedfd6eb0b0d7891aaf5fea92fd482525a2da145e5c9c690417be3797c96111db85a8211
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
- from "architecture" do
16
- field :id, "Id"
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
- from "architecture" do
29
- field :operatingsystem_ids, "OS ids", Fields::List
30
- field :created_at, "Created at", Fields::Date
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
- from "common_parameter" do
14
- field :name, "Name"
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
- from "compute_resource" do
15
- field :id, "Id"
16
- field :name, "Name"
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
- from "compute_resource" do
50
- field :url, "Url"
51
- field :description, "Description"
52
- field :user, "User"
53
- field :created_at, "Created at", Fields::Date
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["compute_resource"]["provider"].downcase
55
+ provider = data["provider"].downcase
60
56
  output_definition.fields.concat PROVIDER_SPECIFIC_FIELDS[provider]
61
- print_records(output_definition, data)
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
- from "domain" do
14
- field :id, "Id"
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
- from "domain" do
35
- field :fullname, "Description"
36
- field :dns_id, "DNS Id"
37
- field :created_at, "Created at", Fields::Date
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 :parameter, nil, Fields::KeyValue
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
- from "environment" do
15
- field :id, "Id"
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
- from "environment" do
29
- field :created_at, "Created at", Fields::Date
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
- from "fact" do
17
- field :host, "Host"
18
- field :fact, "Fact"
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
- { :fact => { :host => host, :fact => fact, :value => value } }
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
- from "host" do
103
- field :id, "Id"
104
- field :name, "Name"
105
- field :operatingsystem_id, "Operating System Id"
106
- field :hostgroup_id, "Host Group Id"
107
- field :ip, "IP"
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 retrieve_data
119
- host = super
120
- host["host"]["environment_name"] = host["host"]["environment"]["environment"]["name"] rescue nil
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
- from "host" do
127
- field :uuid, "UUID"
128
- field :certname, "Cert name"
129
-
130
- field :environment_name, "Environment"
131
- field :environment_id, "Environment Id"
132
-
133
- field :managed, "Managed"
134
- field :enabled, "Enabled"
135
- field :build, "Build"
136
-
137
- field :use_image, "Use image"
138
- field :disk, "Disk"
139
- field :image_file, "Image file"
140
-
141
- field :sp_name, "SP Name"
142
- field :sp_ip, "SP IP"
143
- field :sp_mac, "SP MAC"
144
- field :sp_subnet, "SP Subnet"
145
- field :sp_subnet_id, "SP Subnet Id"
146
-
147
- field :created_at, "Created at", Fields::Date
148
- field :updated_at, "Updated at", Fields::Date
149
- field :installed_at, "Installed at", Fields::Date
150
- field :last_report, "Last report", Fields::Date
151
-
152
- field :puppet_ca_proxy_id, "Puppet CA Proxy Id"
153
- field :medium_id, "Medium Id"
154
- field :model_id, "Model Id"
155
- field :owner_id, "Owner Id"
156
- field :subnet_id, "Subnet Id"
157
- field :domain_id, "Domain Id"
158
- field :puppet_proxy_id, "Puppet Proxy Id"
159
- field :owner_type, "Owner Type"
160
- field :ptable_id, "Partition Table Id"
161
- field :architecture_id, "Architecture Id"
162
- field :image_id, "Image Id"
163
- field :compute_resource_id, "Compute Resource Id"
164
-
165
- field :comment, "Comment"
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 :parameter, nil, Fields::KeyValue
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
- from "fact" do
232
- field :fact, "Fact"
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
- HammerCLIForeman::Fact::ListCommand.unhash_facts(super)
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