Project

General

Profile

Revision b2e88b7c

Added by Thomas McKay over 6 years ago

fixes #14162 - hide unsupported sub-commands and options

+ updated for ruby 2.0.0
+ updated README
+ fixed rubocop
+ updated tests
+ based on feedback switched to default being unsupported for new commands

View differences:

Gemfile
3 3
gemspec
4 4

  
5 5
group :test do
6
  gem 'rake'
6
  gem 'rake', '~> 10.1.0'
7 7
  gem 'thor'
8 8
  gem 'minitest', '4.7.4'
9 9
  gem 'minitest-spec-context'
10 10
  gem 'simplecov'
11 11
  gem 'mocha'
12
  gem 'ci_reporter'
12
  gem 'ci_reporter', '>= 1.6.3', "< 2.0.0", :require => false
13 13
  gem 'rubocop-checkstyle_formatter'
14 14
end
15 15

  
README.md
4 4

  
5 5
[Hammer](https://github.com/theforeman/hammer-cli/blob/master/README.md) is a command line interface (CLI) framework which provides a core to which modules may be added. This module, hammer-cli-csv, adds commands to interact with the following products: [Foreman](https://theforeman.org) standalone, [Katello](http://www.katello.org/), Red Hat's Satellite-6, and Red Hat's Subscription Asset Manager (SAM).
6 6

  
7
The purpose of this module's commands are to allow a convenient mechanism to both export to and import from CSV files (comma separated values). Each of the server's supported resource types, such as organizations and users, are handled.
7
The purpose of this module's commands are to allow a convenient mechanism to both export to and import from CSV files (comma separated values). Each of the server's supported resource types, such as organizations and users, is handled.
8 8

  
9 9
Some possible uses include
10 10

  
11 11
* Import demo or development data easily and consistently
12 12
* Export another server's data and then import into elsewhere for testing and debug
13 13
* Export for backup and auditing
14
* Export from SAM-1.4 to import into Satellite-6
15 14

  
16 15
The following sections will cover installation, usage, and examples. All of the resource types are follow in the order which generally is required for dependency resolution (eg. roles must exist to assign to users so the role section comes first).
17 16

  
......
33 32

  
34 33
```
35 34

  
36
## Usage
35
## General Usage
36

  
37
Supported commands and options are available by using the --help option. Additional subcommands and options may be listed here but are considered "tech preview" to indicate the lack of testing and official support.
37 38

  
38 39
| Option | Description |
39 40
| ---------------:| :--------------|
40
| --csv-export | If not specified will run import. |
41
| --csv-file FILE_NAME | File to import from or export to. If not specified reads or writes to/from stdin and stdout. Note: On ruby-1.8.7 this option is required. |
41
| --export | If not specified will run import. |
42
| --file FILE_NAME | File to import from or export to. If not specified reads or writes to/from stdin and stdout. Note: On ruby-1.8.7 this option is required. |
42 43
| --prefix PREFIX | Convenience method to add a prefix to all Count substituted values. See examples below. |
43 44
| --server SERVER | The server to run against. Overrides any config file value. |
44 45
| --username USERNAME | Username for server. Overrides any config file value. |
......
77 78

  
78 79
*Note: % column indicates Count substituion*
79 80

  
80
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
81
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
82
| Name         | Name of the organization to update or create | x | x | x | x | x |
83
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x | x |
84
| Label | Unique organization label | x |   | x | x | x |
85
| Description | Organization description |   | x | x | x | x |
81
| Column Title | Column Description | % |
82
| :----------- | :----------------- | :-: |
83
| Name         | Name of the organization to update or create | x |
84
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
85
| Label | Unique organization label | x |   |
86
| Description | Organization description |   |
86 87

  
87 88
**Examples**
88 89

  
......
125 126

  
126 127
*Note: % column indicates Count substituion*
127 128

  
128
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
129
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
130
| Name         | Name of the location to update or create | x | x | x | x |   |
131
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
132
| Parent Location | Parent location |   | x | x | x |   |
129
| Column Title | Column Description | % |
130
| :----------- | :----------------- | :-: |
131
| Name         | Name of the location to update or create | x |
132
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
133
| Parent Location | Parent location |   |
133 134

  
134 135
## Puppet Environments
135 136

  
......
144 145

  
145 146
*Note: % column indicates Count substituion*
146 147

  
147
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
148
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
149
| Name         | Name of the puppet environments to update or create | x | x | x | x |   |
150
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
151
| Organizations | Comma separated list of organizations |   | x | x | x |   |
148
| Column Title | Column Description | % |
149
| :----------- | :----------------- | :-: |
150
| Name         | Name of the puppet environments to update or create | x |
151
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
152
| Organizations | Comma separated list of organizations |   |
152 153

  
153 154
## Operating Systems
154 155

  
......
162 163

  
163 164
*Note: % column indicates Count substituion*
164 165

  
165
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
166
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
167
| Name         | Name of the operating systems to update or create | x | x | x | x |   |
168
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
169
| Family | Operating system family |   | x | x | x |   |
170
| Description | Operating system description |   | x | x | x |   |
171
| Password Hash | MD5, SHA256, SHA512, or Base64 |   | x | x | x |   |
172
| Partition Tables | List of partition table names |   | x | x | x |   |
173
| Architectures | List of architectures names |   | x | x | x |   |
174
| Media | List of media names |   | x | x | x |   |
175
| Provisioning Templates | List of provisioning template names |   | x | x | x |   |
176
| Parameters | List of parameters |   | x | x | x |   |
166
| Column Title | Column Description | % |
167
| :----------- | :----------------- | :-: |
168
| Name         | Name of the operating systems to update or create | x |
169
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
170
| Family | Operating system family |   |
171
| Description | Operating system description |   |
172
| Password Hash | MD5, SHA256, SHA512, or Base64 |   |
173
| Partition Tables | List of partition table names |   |
174
| Architectures | List of architectures names |   |
175
| Media | List of media names |   |
176
| Provisioning Templates | List of provisioning template names |   |
177
| Parameters | List of parameters |   |
177 178

  
178 179
## Domains
179 180

  
......
187 188

  
188 189
*Note: % column indicates Count substituion*
189 190

  
190
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
191
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
192
| Name         | Name of the domains to update or create | x | x | x | x |   |
193
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
194
| Full Name | Full name of the domain |   | x | x | x |   |
195
| Organizations | Comma separated list of organizations |   | x | x | x |   |
191
| Column Title | Column Description | % |
192
| :----------- | :----------------- | :-: |
193
| Name         | Name of the domains to update or create | x |
194
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
195
| Full Name | Full name of the domain |   |
196
| Organizations | Comma separated list of organizations |   |
196 197

  
197 198
## Architectures
198 199

  
......
206 207

  
207 208
*Note: % column indicates Count substituion*
208 209

  
209
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
210
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
211
| Name         | Name of the architectures to update or create | x | x | x | x |   |
212
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
213
| Operating Systems | Comma separated list of operating system names |   | x | x | x |   |
210
| Column Title | Column Description | % |
211
| :----------- | :----------------- | :-: |
212
| Name         | Name of the architectures to update or create | x |
213
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
214
| Operating Systems | Comma separated list of operating system names |   |
214 215

  
215 216
## Partition Tables
216 217

  
......
226 227

  
227 228
*Note: % column indicates Count substituion*
228 229

  
229
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
230
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
231
| Name         | Name of the partition tables to update or create | x | x | x | x |   |
232
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
233
| OS Family | Operating system family |   | x | x | x |   |
234
| Operating Systems | Comma separated list of operating system names |   | x | x | x |   |
235
| Layout | Disk layout |   | x | x | x |   |
230
| Column Title | Column Description | % |
231
| :----------- | :----------------- | :-: |
232
| Name         | Name of the partition tables to update or create | x |
233
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
234
| OS Family | Operating system family |   |
235
| Operating Systems | Comma separated list of operating system names |   |
236
| Layout | Disk layout |   |
236 237

  
237 238
## Lifecycle Environments
238 239

  
......
246 247

  
247 248
*Note: % column indicates Count substituion*
248 249

  
249
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
250
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
251
| Name         | Name of the lifecycle environments to update or create | x | x | x | x |   |
252
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
253
| Organization | Organization name |   | x | x | x |   |
254
| Prior Environment | Previous organization name in path |   | x | x | x |   |
255
| Description | Lifecycle environment description |   | x | x | x |   |
250
| Column Title | Column Description | % |
251
| :----------- | :----------------- | :-: |
252
| Name         | Name of the lifecycle environments to update or create | x |
253
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
254
| Organization | Organization name |   |
255
| Prior Environment | Previous organization name in path |   |
256
| Description | Lifecycle environment description |   |
256 257

  
257 258
## Host Collections
258 259

  
......
270 271

  
271 272
*Note: % column indicates Count substituion*
272 273

  
273
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
274
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
275
| Name         | Name of the host collections to update or create | x | x | x | x |   |
276
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
277
| Organization | Organization name |   | x | x | x |   |
278
| Limit | Usage limit |   | x | x | x |   |
279
| Description | Host collection description |   | x | x | x |   |
274
| Column Title | Column Description | % |
275
| :----------- | :----------------- | :-: |
276
| Name         | Name of the host collections to update or create | x |
277
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
278
| Organization | Organization name |   |
279
| Limit | Usage limit |   |
280
| Description | Host collection description |   |
280 281

  
281 282
## Products
282 283

  
......
296 297

  
297 298
*Note: % column indicates Count substituion*
298 299

  
299
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
300
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
301
| Name         | Name of the host collections to update or create | x | x | x | x |   |
302
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
303
| Label | Unique label  |   | x | x | x |   |
304
| Organization | Organization name |   | x | x | x |   |
305
| Repository | Repository name |   | x | x | x |   |
306
| Repository Url | Repository Url |   | x | x | x |   |
307
| Description | Repository description |   | x | x | x |   |
300
| Column Title | Column Description | % |
301
| :----------- | :----------------- | :-: |
302
| Name         | Name of the host collections to update or create | x |
303
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
304
| Label | Unique label  |   |
305
| Organization | Organization name |   |
306
| Repository | Repository name |   |
307
| Repository Url | Repository Url |   |
308
| Description | Repository description |   |
308 309

  
309 310
## Provisioning Templates
310 311

  
......
322 323

  
323 324
*Note: % column indicates Count substituion*
324 325

  
325
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
326
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
327
| Name         | Name of the provisioning templates to update or create | x | x | x | x |   |
328
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
329
| Organizations  | Comma separated list of organizations |   | x | x | x |   |
330
| Locations  | Comma separated list of locations |   | x | x | x |   |
331
| Operating Systems  | Comma separated list of associated operating systems |   | x | x | x |   |
332
| Host Group / Puppet Environment Combinations  | Comma separated list of host group and puppet environment associations |   | x | x | x |   |
333
| Kind  | Kind of template (eg. snippet) |   | x | x | x |   |
334
| Template  | Full text of template |   | x | x | x |   |
326
| Column Title | Column Description | % |
327
| :----------- | :----------------- | :-: |
328
| Name         | Name of the provisioning templates to update or create | x |
329
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
330
| Organizations  | Comma separated list of organizations |   |
331
| Locations  | Comma separated list of locations |   |
332
| Operating Systems  | Comma separated list of associated operating systems |   |
333
| Host Group / Puppet Environment Combinations  | Comma separated list of host group and puppet environment associations |   |
334
| Kind  | Kind of template (eg. snippet) |   |
335
| Template  | Full text of template |   |
335 336

  
336 337
## Subscriptions
337 338

  
......
345 346

  
346 347
*Note: % column indicates Count substituion*
347 348

  
348
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
349
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
350
| Name         | Name of the subscriptions to update or create | x | x | x | x |   |
351
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
352
| Organization | Organization name |   | x | x | x |   |
353
| Manifest File | Path to manifest file |   | x | x | x |   |
354
| Content Set | Repository content set to enable |   | x | x | x |   |
355
| Arch | Architecture |   | x | x | x |   |
356
| Release | Release version |   | x | x | x |   |
349
| Column Title | Column Description | % |
350
| :----------- | :----------------- | :-: |
351
| Name         | Name of the subscriptions to update or create | x |
352
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
353
| Organization | Organization name |   |
354
| Manifest File | Path to manifest file |   |
355
| Content Set | Repository content set to enable |   |
356
| Arch | Architecture |   |
357
| Release | Release version |   |
357 358

  
358 359
## Activation Keys
359 360

  
......
367 368

  
368 369
*Note: % column indicates Count substituion*
369 370

  
370
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
371
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
372
| Name         | Name of the activation keys to update or create | x | x | x | x |   |
373
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
374
| Organization | Parent organization name |   | x | x | x |   |
375
| Description | Activation key description |   | x | x | x |   |
376
| Limit | Usage limit |   | x | x | x |   |
377
| Environment | Lifecycle environment name |   | x | x | x |   |
378
| Content View | Content view name |   | x | x | x |   |
379
| Host Collections | Comma separated list of host collections |   | x | x | x |   |
380
| Subscriptions | Comma separated list of subscriptions |   | x | x | x |   |
371
| Column Title | Column Description | % |
372
| :----------- | :----------------- | :-: |
373
| Name         | Name of the activation keys to update or create | x |
374
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
375
| Organization | Parent organization name |   |
376
| Description | Activation key description |   |
377
| Limit | Usage limit |   |
378
| Environment | Lifecycle environment name |   |
379
| Content View | Content view name |   |
380
| Host Collections | Comma separated list of host collections |   |
381
| Subscriptions | Comma separated list of subscriptions |   |
381 382

  
382 383
## Hosts
383 384

  
......
391 392

  
392 393
*Note: % column indicates Count substituion*
393 394

  
394
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
395
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
396
| Name         | Name of the hosts to update or create | x | x | x | x |   |
397
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
398
| Organization | Organization name |   | x | x | x |   |
399
| Environment | Puppet environment name |   | x | x | x |   |
400
| Operating System | Operating system name |   | x | x | x |   |
401
| Architecture | Architecture name |   | x | x | x |   |
402
| MAC Address | Unique MAC address | x | x | x | x |   |
403
| Domain | Domain name |   | x | x | x |   |
404
| Partition Table | Partition table name |   | x | x | x |   |
395
| Column Title | Column Description | % |
396
| :----------- | :----------------- | :-: |
397
| Name         | Name of the hosts to update or create | x |
398
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
399
| Organization | Organization name |   |
400
| Environment | Puppet environment name |   |
401
| Operating System | Operating system name |   |
402
| Architecture | Architecture name |   |
403
| MAC Address | Unique MAC address | x |
404
| Domain | Domain name |   |
405
| Partition Table | Partition table name |   |
405 406

  
406 407
## Content Hosts
407 408

  
......
419 420

  
420 421
*Note: % column indicates Count substituion*
421 422

  
422
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
423
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
424
| Name         | Name of the content hosts to update or create | x | x | x | x |   |
425
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
426
| Organization | Organization name |   | x | x | x |   |
427
| Environment | Puppet environment name |   | x | x | x |   |
428
| Content View | Content view name |   | x | x | x |   |
429
| Host Collections | Comma separate list of host collectoins |   | x | x | x |   |
430
| Virtual | Virtual (Yes or No) |   | x | x | x |   |
431
| Host | Virtual content host name |   | x | x | x |   |
432
| OS | Operating system name |   | x | x | x |   |
433
| Arch | Architecture name |   | x | x | x |   |
434
| Sockets | Number of sockets |   | x | x | x |   |
435
| RAM | Amount of RAM with units |   | x | x | x |   |
436
| Cores | Number of cores |   | x | x | x |   |
437
| SLA | Service Level Agreement |   | x | x | x |   |
438
| Products | Comma separated list of subscriptions |   | x | x | x |   |
439
| Subscriptions | Comma separated list of subscriptions |   | x | x | x |   |
423
| Column Title | Column Description | % |
424
| :----------- | :----------------- | :-: |
425
| Name         | Name of the content hosts to update or create | x |
426
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
427
| Organization | Organization name |   |
428
| Environment | Puppet environment name |   |
429
| Content View | Content view name |   |
430
| Host Collections | Comma separate list of host collectoins |   |
431
| Virtual | Virtual (Yes or No) |   |
432
| Host | Virtual content host name |   |
433
| OS | Operating system name |   |
434
| Arch | Architecture name |   |
435
| Sockets | Number of sockets |   |
436
| RAM | Amount of RAM with units |   |
437
| Cores | Number of cores |   |
438
| SLA | Service Level Agreement |   |
439
| Products | Comma separated list of subscriptions |   |
440
| Subscriptions | Comma separated list of subscriptions |   |
440 441

  
441 442
## Reports
442 443

  
......
450 451

  
451 452
*Note: % column indicates Count substituion*
452 453

  
453
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
454
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
455
| Name         | Name of the reports to update or create | x | x | x | x |   |
456
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
457
| Time | Time of report |   | x | x | x |   |
458
| Applied |  |   | x | x | x |   |
459
| Restarted |  |   | x | x | x |   |
460
| Failed |  |   | x | x | x |   |
461
| Failed Restarts |  |   | x | x | x |   |
462
| Skipped |  |   | x | x | x |   |
463
| Pending |  |   | x | x | x |   |
464
| Metrics |  |   | x | x | x |   |
454
| Column Title | Column Description | % |
455
| :----------- | :----------------- | :-: |
456
| Name         | Name of the reports to update or create | x |
457
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
458
| Time | Time of report |   |
459
| Applied |  |   |
460
| Restarted |  |   |
461
| Failed |  |   |
462
| Failed Restarts |  |   |
463
| Skipped |  |   |
464
| Pending |  |   |
465
| Metrics |  |   |
465 466

  
466 467
## Roles
467 468

  
......
475 476

  
476 477
*Note: % column indicates Count substituion*
477 478

  
478
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
479
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
480
| Name         | Name of the roles to update or create | x | x | x | x |   |
481
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
482
| Resource | Resource to apply role to |   | x | x | x |   |
483
| Search | Search string |   | x | x | x |   |
484
| Permissions | Role permission |   | x | x | x |   |
485
| Organizations | Comma separated list of organizations |   | x | x | x |   |
486
| Locations | Comma separated list of locations |   | x | x | x |   |
479
| Column Title | Column Description | % |
480
| :----------- | :----------------- | :-: |
481
| Name         | Name of the roles to update or create | x |
482
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
483
| Resource | Resource to apply role to |   |
484
| Search | Search string |   |
485
| Permissions | Role permission |   |
486
| Organizations | Comma separated list of organizations |   |
487
| Locations | Comma separated list of locations |   |
487 488

  
488 489
## Users
489 490

  
......
497 498

  
498 499
*Note: % column indicates Count substituion*
499 500

  
500
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
501
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
502
| Name         | Name of the users to update or create | x | x | x | x |   |
503
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
504
| First Name | First name of user |   | x | x | x |   |
505
| Last Name | Last name of user |   | x | x | x |   |
506
| email | Email address |   | x | x | x |   |
507
| Organizations | Comma separated list of organizations |   | x | x | x |   |
508
| Locations | Comma separated list of locations |   | x | x | x |   |
509
| Roles | Comma separated list of role names for user |   | x | x | x |   |
501
| Column Title | Column Description | % |
502
| :----------- | :----------------- | :-: |
503
| Name         | Name of the users to update or create | x |
504
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
505
| First Name | First name of user |   |
506
| Last Name | Last name of user |   |
507
| email | Email address |   |
508
| Organizations | Comma separated list of organizations |   |
509
| Locations | Comma separated list of locations |   |
510
| Roles | Comma separated list of role names for user |   |
510 511

  
511 512
## Settings
512 513

  
......
520 521

  
521 522
*Note: % column indicates Count substituion*
522 523

  
523
| Column Title | Column Description | % | Foreman | Katello | Satellite | SAM |
524
| :----------- | :----------------- | :-: | :-: | :-: | :-: | :-: |
525
| Name         | Setting name to update or create | x | x | x | x |   |
526
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   | x | x | x |   |
527
| Value | Setting value |   | x | x | x |   |
524
| Column Title | Column Description | % |
525
| :----------- | :----------------- | :-: |
526
| Name         | Setting name to update or create | x |
527
| Count | Number of times to iterate this CSV row, incrementing value for substitution |   |
528
| Value | Setting value |   |
528 529

  
529 530
**Examples**
530 531
```
......
542 543
**Examples**
543 544

  
544 545
```
545
% hammer csv import -v --organizations test/data/organizations.csv --locations test/data/locations.csv
546
Creating organization 'Mega Corporation'... done
547
Creating organization 'Mega Subsidiary'... done
548
Creating location 'Asia Pacific'... done
549
Creating location 'Asia Pacific (Tokyo) Region'... done
550
Creating location 'Asia Pacific (Singapore) Region'... done
551
Creating location 'Asia Pacific (Sydney) Region'... done
552
Creating location 'EU (Ireland) Region'... done
553
Creating location 'South America (Sao Paulo) Region'... done
554
Creating location 'US East (Northern Virginia) Region'... done
555
Creating location 'US West (Northern California) Region'... done
556
Creating location 'US West (Oregon) Region'... done
546
% hammer csv import -v --dir test/data --settings
547
Importing settings from 'test/data/settings.csv'
548
Updating setting 'idle_timeout'...done
557 549
```
558 550

  
559 551
# Development
......
566 558

  
567 559
The tests are meant to run against a live server.
568 560

  
561
```rake test TEST=test/settings_test.rb```
562

  
563
Test server configuration is taken from test/config.yml
564

  
565
```
566
% cat test/config.yml
567

  
568
:csv:
569
  :enable_module: true
570

  
571
:foreman:
572
  :enable_module: true
573
  :host:          'http://katello:3000'
574
  :username:      'admin'
575
  :password:      'changeme'
576

  
577
:katello:
578
  :enable_module: true
579
```
lib/hammer_cli_csv.rb
6 6
  require 'hammer_cli_foreman_tasks'
7 7

  
8 8
  require 'hammer_cli_csv/base'
9
  require 'hammer_cli_csv/exception_handler'
10 9

  
11 10
  require 'hammer_cli_csv/csv'
12 11
  require 'hammer_cli_csv/activation_keys'
lib/hammer_cli_csv/base.rb
13 13
           :default => 1, :hidden => true
14 14
    option %w(--export), :flag, 'Export current data instead of importing'
15 15
    option %w(--file), 'FILE_NAME', 'CSV file (default to /dev/stdout with --csv-export, otherwise required)'
16
    option %w(--prefix), 'PREFIX', 'Prefix for all name columns'
16
    option %w(--prefix), 'PREFIX', 'Prefix for all name columns',
17
           :hidden => true
17 18
    option %w(--organization), 'ORGANIZATION', _('Only process organization matching this name')
18 19

  
19 20
    option %w(--csv-file), 'FILE_NAME', 'Option --csv-file is deprecated. Use --file',
......
23 24
           :deprecated => "Use --export", :hidden => true,
24 25
           :attribute_name => :option_export
25 26

  
26

  
27 27
    NAME = 'Name'
28 28
    COUNT = 'Count'
29 29

  
30
    def self.supported?
31
      false
32
    end
33

  
34
    def supported?
35
      self.class.supported?
36
    end
37

  
38
    def help
39
      print_message _('**** This command is unsupported and is provided as tech preview. ****') unless supported?
40
      super
41
    end
42

  
30 43
    def execute
31 44
      @server = (HammerCLI::Settings.settings[:_params] &&
32 45
                 HammerCLI::Settings.settings[:_params][:host]) ||
lib/hammer_cli_csv/csv.rb
3 3

  
4 4
module HammerCLICsv
5 5
  class CsvCommand < HammerCLI::AbstractCommand
6
    def help
7
      self.class.help(invocation_path, CsvSortedBuilder.new)
8
    end
9

  
10
    class CsvSortedBuilder < SortedBuilder
11
      def add_list(heading, items)
12
        items.delete_if do |item|
13
          if item.class == Clamp::Subcommand::Definition
14
            !item.subcommand_class.supported?
15
          else
16
            false
17
          end
18
        end
19
        super(heading, items)
20
      end
21
    end
6 22
  end
7 23

  
8 24
  HammerCLI::MainCommand.subcommand('csv',
9
                                    _('import to, or export from a running foretello server'),
25
                                    _('import to or export from a running foreman server'),
10 26
                                    HammerCLICsv::CsvCommand)
11 27
end
lib/hammer_cli_csv/exception_handler.rb
1
require 'hammer_cli/exception_handler'
2

  
3
module HammerCLICsv
4
  class ExceptionHandler < HammerCLI::ExceptionHandler
5
    def mappings
6
      super + [
7
        [Exception, :handle_csv_exception],
8
        [RestClient::Forbidden, :handle_forbidden],
9
        [RestClient::UnprocessableEntity, :handle_unprocessable_entity],
10
        [ArgumentError, :handle_argument_error]
11
      ]
12
    end
13

  
14
    protected
15

  
16
    def handle_csv_exception(e)
17
      $stderr.puts e.message
18
      log_full_error e
19
      HammerCLI::EX_DATAERR
20
    end
21

  
22
    def handle_unprocessable_entity(e)
23
      response = JSON.parse(e.response)
24
      response = response[response.keys[0]]
25

  
26
      print_error response['full_messages']
27
      HammerCLI::EX_DATAERR
28
    end
29

  
30
    def handle_argument_error(e)
31
      print_error e.message
32
      log_full_error e
33
      HammerCLI::EX_USAGE
34
    end
35

  
36
    def handle_forbidden(e)
37
      print_error 'Forbidden - server refused to process the request'
38
      log_full_error e
39
      HammerCLI::EX_NOPERM
40
    end
41
  end
42
end
lib/hammer_cli_csv/export.rb
4 4
      command_name 'export'
5 5
      desc         'export into directory'
6 6

  
7
      def self.supported?
8
        true
9
      end
10

  
7 11
      option %w(-v --verbose), :flag, _('be verbose')
8 12
      option %w(--threads), 'THREAD_COUNT', _('Number of threads to hammer with'),
9 13
             :default => 1, :hidden => true
10
      option '--dir', 'DIRECTORY', _('directory to import from')
14
      option '--dir', 'DIRECTORY', _('directory to export to')
11 15
      option %w(--organization), 'ORGANIZATION', _('Only process organization matching this name')
12 16

  
13 17
      RESOURCES = %w(
14
        organizations locations puppet_environments operating_systems
18
        settings organizations locations puppet_environments operating_systems
15 19
        domains architectures partition_tables lifecycle_environments host_collections
16 20
        provisioning_templates
17 21
        subscriptions activation_keys hosts content_hosts reports roles users
18 22
      )
23
      SUPPORTED_RESOURCES = %w(
24
        settings
25
      )
19 26
      RESOURCES.each do |resource|
20 27
        dashed = resource.sub('_', '-')
21
        option "--#{dashed}", 'FILE', "csv file for #{dashed}"
28
        option "--#{dashed}", 'FILE', "csv file for #{dashed}",
29
               :hidden => !SUPPORTED_RESOURCES.include?(resource)
22 30
      end
23 31

  
24 32
      def execute
......
46 54
                                      :username => @username,
47 55
                                      :password => @password
48 56
                                    })
49
          skipped_resources = %w( locations puppet_environments operating_systems
57
          skipped_resources = %w( settings locations puppet_environments operating_systems
50 58
                                  domains architectures partition_tables lifecycle_environments
51 59
                                  provisioning_templates
52 60
                                  hosts reports )
......
58 66
                                           :password => @password,
59 67
                                           :api_version => 2
60 68
                                         })
61
          skipped_resources = []
69
          skipped_resources = (RESOURCES - SUPPORTED_RESOURCES)
62 70
        end
63 71

  
64 72
        # Swing the hammers
lib/hammer_cli_csv/import.rb
6 6
      command_name 'import'
7 7
      desc         'import by directory'
8 8

  
9
      def self.supported?
10
        true
11
      end
12

  
9 13
      option %w(-v --verbose), :flag, _('be verbose')
10 14
      option %w(--threads), 'THREAD_COUNT', _('Number of threads to hammer with'),
11 15
             :default => 1, :hidden => true
12 16
      option '--dir', 'DIRECTORY', _('directory to import from')
13 17
      option %w(--organization), 'ORGANIZATION', _('Only process organization matching this name')
14
      option %w(--prefix), 'PREFIX', _('Prefix for all name columns')
18
      option %w(--prefix), 'PREFIX', _('Prefix for all name columns'),
19
             :hidden => true
15 20

  
16
      RESOURCES = %w( settings organizations locations puppet_environments operating_systems
17
                      domains architectures partition_tables lifecycle_environments host_collections
18
                      provisioning_templates
19
                      subscriptions products content_views content_view_filters activation_keys
20
                      hosts content_hosts smart_proxies compute_resources reports roles users )
21
      RESOURCES = %w(
22
        settings organizations locations puppet_environments operating_systems
23
        domains architectures partition_tables lifecycle_environments host_collections
24
        provisioning_templates
25
        subscriptions products content_views content_view_filters activation_keys
26
        hosts content_hosts smart_proxies compute_resources reports roles users
27
      )
28
      SUPPORTED_RESOURCES = %w(
29
        settings
30
      )
21 31
      RESOURCES.each do |resource|
22 32
        dashed = resource.gsub('_', '-')
23
        option "--#{dashed}", 'FILE', "csv file for #{dashed}"
33
        option "--#{dashed}", 'FILE', "csv file for #{dashed}",
34
               :hidden => !SUPPORTED_RESOURCES.include?(resource)
24 35
      end
25 36

  
26 37
      def execute
......
67 78

  
68 79
      def hammer_resource(resource)
69 80
        return if !self.send("option_#{resource}") && !option_dir
70
        options_file = "#{option_dir}/#{resource.gsub('_', '-')}.csv" || self.send("option_#{resource}")
81
        options_file = option_dir ? "#{option_dir}/#{resource.gsub('_', '-')}.csv" :  self.send("option_#{resource}")
71 82
        unless options_file_exists? options_file
72 83
          if option_dir
84
            return unless SUPPORTED_RESOURCES.include?(resource)
73 85
            puts _("Skipping #{resource} because '#{options_file}' does not exist") if option_verbose?
74 86
            return
75 87
          end
lib/hammer_cli_csv/settings.rb
6 6

  
7 7
      VALUE = 'Value'
8 8

  
9
      def self.supported?
10
        true
11
      end
12

  
9 13
      def export
10 14
        CSV.open(option_file || '/dev/stdout', 'wb') do |csv|
11 15
          csv << [NAME, VALUE]
test/csv_test.rb
1
require File.join(File.dirname(__FILE__), 'csv_test_helper')
2

  
3
describe 'csv' do
4
  extend CommandTestHelper
5

  
6
  context "help" do
7
    it "displays supported options" do
8
      set_user 'admin'
9

  
10
      stdout,stderr = capture {
11
        hammer.run(%W{csv --help})
12
      }
13
      stderr.must_equal ''
14
      stdout.must_equal <<-HELP
15
Usage:
16
     csv [OPTIONS] SUBCOMMAND [ARG] ...
17

  
18
Parameters:
19
 SUBCOMMAND                    subcommand
20
 [ARG] ...                     subcommand arguments
21

  
22
Subcommands:
23
 export                        export into directory
24
 import                        import by directory
25
 settings                      import or export settings
26

  
27
Options:
28
 -h, --help                    print help
29
HELP
30
    end
31
  end
32
end
test/export_test.rb
1
require File.join(File.dirname(__FILE__), 'csv_test_helper')
2

  
3
describe 'export' do
4
  extend CommandTestHelper
5

  
6
  context "help" do
7
    it "displays supported options" do
8
      set_user 'admin'
9

  
10
      stdout,stderr = capture {
11
        hammer.run(%W{csv export --help})
12
      }
13
      stderr.must_equal ''
14
      stdout.must_equal <<-HELP
15
Usage:
16
     csv export [OPTIONS]
17

  
18
Options:
19
 --dir DIRECTORY               directory to export to
20
 --organization ORGANIZATION   Only process organization matching this name
21
 --settings FILE               csv file for settings
22
 -h, --help                    print help
23
 -v, --verbose                 be verbose
24
HELP
25
    end
26
  end
27
end
test/import_test.rb
1 1
require File.join(File.dirname(__FILE__), 'csv_test_helper')
2 2

  
3
require 'stringio'
4
require 'tempfile'
5

  
6 3
describe 'import' do
7 4
  extend CommandTestHelper
8 5

  
9
  before :each do
10
    HammerCLI::Settings.load_from_file 'test/config.yml'
6
  context "help" do
7
    it "displays supported options" do
8
      set_user 'admin'
9

  
10
      stdout,stderr = capture {
11
        hammer.run(%W{csv import --help})
12
      }
13
      stderr.must_equal ''
14
      stdout.must_equal <<-HELP
15
Usage:
16
     csv import [OPTIONS]
17

  
18
Options:
19
 --dir DIRECTORY               directory to import from
20
 --organization ORGANIZATION   Only process organization matching this name
21
 --settings FILE               csv file for settings
22
 -h, --help                    print help
23
 -v, --verbose                 be verbose
24
HELP
25
    end
11 26
  end
12 27

  
13 28
  context "--dir" do
......
19 34
      stdout.must_equal(
20 35
<<-eos
21 36
Skipping settings because 'does-not-exist/settings.csv' does not exist
22
Skipping organizations because 'does-not-exist/organizations.csv' does not exist
23
Skipping locations because 'does-not-exist/locations.csv' does not exist
24
Skipping puppet_environments because 'does-not-exist/puppet-environments.csv' does not exist
25
Skipping operating_systems because 'does-not-exist/operating-systems.csv' does not exist
26
Skipping domains because 'does-not-exist/domains.csv' does not exist
27
Skipping architectures because 'does-not-exist/architectures.csv' does not exist
28
Skipping partition_tables because 'does-not-exist/partition-tables.csv' does not exist
29
Skipping lifecycle_environments because 'does-not-exist/lifecycle-environments.csv' does not exist
30
Skipping host_collections because 'does-not-exist/host-collections.csv' does not exist
31
Skipping provisioning_templates because 'does-not-exist/provisioning-templates.csv' does not exist
32
Skipping subscriptions because 'does-not-exist/subscriptions.csv' does not exist
33
Skipping products because 'does-not-exist/products.csv' does not exist
34
Skipping content_views because 'does-not-exist/content-views.csv' does not exist
35
Skipping content_view_filters because 'does-not-exist/content-view_filters.csv' does not exist
36
Skipping activation_keys because 'does-not-exist/activation-keys.csv' does not exist
37
Skipping hosts because 'does-not-exist/hosts.csv' does not exist
38
Skipping content_hosts because 'does-not-exist/content-hosts.csv' does not exist
39
Skipping reports because 'does-not-exist/reports.csv' does not exist
40
Skipping roles because 'does-not-exist/roles.csv' does not exist
41
Skipping users because 'does-not-exist/users.csv' does not exist
42 37
eos
43 38
)
44 39
    end
test/settings_test.rb
1 1
require File.join(File.dirname(__FILE__), 'csv_test_helper')
2 2

  
3
describe 'job-templates' do
4

  
3
describe 'settings' do
5 4
  extend CommandTestHelper
6 5

  
6
  context "help" do
7
    it "displays supported options" do
8
      set_user 'admin'
9

  
10
      stdout,stderr = capture {
11
        hammer.run(%W{csv settings --help})
12
      }
13
      stderr.must_equal ''
14
      stdout.must_equal <<-HELP
15
Usage:
16
     csv settings [OPTIONS]
17

  
18
Options:
19
 --export                      Export current data instead of importing
20
 --file FILE_NAME              CSV file (default to /dev/stdout with --csv-export, otherwise required)
21
 --organization ORGANIZATION   Only process organization matching this name
22
 -h, --help                    print help
23
 -v, --verbose                 be verbose
24
HELP
25
    end
26
  end
27

  
7 28
  context "import" do
8 29
    it "update settings w/ Count column" do
9 30
      set_user 'admin'

Also available in: Unified diff