Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 1154383 - [RFE] Ability to use user's default Org/Location in hammer CLI
[RFE] Ability to use user's default Org/Location in hammer CLI
Status: CLOSED ERRATA
Product: Red Hat Satellite 6
Classification: Red Hat
Component: Hammer (Show other bugs)
6.0.4
Unspecified Unspecified
medium Severity medium (vote)
: GA
: Unused
Assigned To: Martin Bacovsky
sthirugn@redhat.com
http://projects.theforeman.org/issues...
: FutureFeature, Triaged
: 1280015 (view as bug list)
Depends On:
Blocks: 1287901 1353215
  Show dependency treegraph
 
Reported: 2014-10-19 07:55 EDT by Rich Jerrido
Modified: 2018-08-31 11 EDT (History)
15 users (show)

See Also:
Fixed In Version: rubygem-hammer_cli-0.5.1.9-1
Doc Type: Enhancement
Doc Text:
The hammer command now supports defaults, which can be stored on the file system to make it easier to execute multiple hammer commands in a single session.
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-07-27 07:06:52 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Foreman Issue Tracker 8015 None None None 2016-04-26 13:04 EDT

  None (edit)
Description Rich Jerrido 2014-10-19 07:55:06 EDT
Description of problem:
This RFE requests the ability to set the default organization/location of a user that is leveraging Hammer CLI. This would save the user a great deal of typing when accessing the CLI. 

This value can potentially be:

* Set within the cli_config.yml file. 
* Inherited from the user's 'Default Organization | Default Locaiton' setting in the UI

Version-Release number of selected component (if applicable):
rubygem-hammer_cli-0.1.1-12.el6sat.noarch
Comment 1 RHEL Product and Program Management 2014-10-19 08:02:58 EDT
Since this issue was entered in Red Hat Bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.
Comment 3 Dominic Cleal 2014-10-21 11:37:41 EDT
Created redmine issue http://projects.theforeman.org/issues/8015 from this bug
Comment 5 Bryan Kearney 2015-11-13 11:47:57 EST
*** Bug 1280015 has been marked as a duplicate of this bug. ***
Comment 6 Bryan Kearney 2015-12-08 12:06:20 EST
Moving to POST since upstream bug http://projects.theforeman.org/issues/8015 has been closed
-------------
Alon Goldboim
Applied in changeset commit:417e7163c0964e8e64aabe25feed7f6a509545a6.
Comment 10 sthirugn@redhat.com 2016-03-21 13:12:57 EDT
Following the steps in Comment, this bug failed in Satellite 6.2.0-beta-snap4

# hammer defaults list
----------|------
PARAMETER | VALUE
----------|------

# hammer defaults providers
---------|------------------------------|-------------------------------------------------------------
PROVIDER | SUPPORTED DEFAULTS           | DESCRIPTION                                                 
---------|------------------------------|-------------------------------------------------------------
foreman  | organization_id, location_id | Use the default organization and/or location from the server
---------|------------------------------|-------------------------------------------------------------

# hammer defaults add --param-name=organization_id --provider=foreman
No such file or directory @ rb_sysopen - /root/.hammer/defaults.yml

# hammer defaults add --param-name=organization_id --param-value=1
No such file or directory @ rb_sysopen - /root/.hammer/defaults.yml

# hammer activation-key list
Error: Could not find organization, please set one of options --organization, --organization-label, --organization-id.
Comment 11 sthirugn@redhat.com 2016-03-21 13:43:36 EDT
I tried adding /root/.hammer/defaults.yml

# ll /root/.hammer/defaults.yml 
-rw-r--r--. 1 root root 0 Mar 21 13:32 /root/.hammer/defaults.yml

# hammer defaults add --param-name=organization_id --param-value=1
Error: undefined method `[]' for false:FalseClass

Note: I don't see error in any of these files: 
/var/log/{pulp,candlepin,foreman*,rhsm,puppet,tomcat*}/{*.log,*.out}
/var/log/messages
Comment 12 Shimon Shtein 2016-03-22 03:09:33 EDT
Disclaimer: I am guessing here.

I assume that /root/.hammer/defaults.yml is empty right now.
If it is, run:
echo "--- {}" > /root/.hammer/defaults.yml

This should make it work.
Comment 13 Shimon Shtein 2016-03-22 05:18:34 EDT
Created upstream bug (and a PR): http://projects.theforeman.org/issues/14311
Comment 17 Shimon Shtein 2016-03-23 04:44:00 EDT
Apparently bugzilla was already there: https://bugzilla.redhat.com/show_bug.cgi?id=1315645
Comment 18 Mike McCune 2016-04-01 00:26:22 EDT
this looks the same as 1315645, QE: feel free to close as a dupe
Comment 19 sthirugn@redhat.com 2016-04-01 15:02:55 EDT
Failed in Satellite 6.2-beta-snap-6.  The default foreman provider shows 'organization_id', 'location_id' instead of 'organization-id', 'location-id'.  Test steps below:


[root@sat6host ~] # hammer -u admin -p changeme defaults providers
---------|------------------------------|-------------------------------------------------------------
PROVIDER | SUPPORTED DEFAULTS           | DESCRIPTION                                                 
---------|------------------------------|-------------------------------------------------------------
foreman  | organization_id, location_id | Use the default organization and/or location from the server
---------|------------------------------|-------------------------------------------------------------

[root@sat6host ~] # hammer -u admin -p changeme defaults add --param-name=organization-id --param-value=1
Added organization-id default-option with value 1.

[root@sat6host ~]# hammer -u admin -p changeme defaults add --param-name=location-id --param-value=1
Added location-id default-option with value 1.

[root@sat6host ~]# hammer -u admin -p changeme defaults list
----------------|------
PARAMETER       | VALUE
----------------|------
organization-id | 1    
location-id     | 1    
----------------|------

[root@sat6host ~]# hammer -u admin -p changeme activation-key list
Error: Could not find organization, please set one of options --organization,
--organization-label, --organization-id.

[root@sat6host ~]# hammer -u admin -p changeme defaults add --param-name=organization_id --param-value=1
Added organization_id default-option with value 1.

[root@sat6host ~]# hammer -u admin -p changeme defaults add --param-name=location_id --param-value=1
Added location_id default-option with value 1.

[root@sat6host ~]# hammer -u admin -p changeme defaults list
----------------|------
PARAMETER       | VALUE
----------------|------
organization-id | 1    
location-id     | 1    
organization_id | 1    
location_id     | 1    
----------------|------

[root@sat6host ~]# hammer -u admin -p changeme activation-key list
---|---------|----------------|-----------------------|-------------
ID | NAME    | HOST LIMIT     | LIFECYCLE ENVIRONMENT | CONTENT VIEW
---|---------|----------------|-----------------------|-------------
2  | rhel7ak | 0 of Unlimited | prod                  |             
---|---------|----------------|-----------------------|-------------

[root@sat6host ~]# hammer -u admin -p changeme activation-key list --organization-id=3
---|--------------|----------------|-----------------------|--------------------------
ID | NAME         | HOST LIMIT     | LIFECYCLE ENVIRONMENT | CONTENT VIEW             
---|--------------|----------------|-----------------------|--------------------------
1  | testorg1_ack | 0 of Unlimited | Library               | Default Organization View
---|--------------|----------------|-----------------------|--------------------
Comment 21 Martin Bacovsky 2016-04-14 10:59:30 EDT
Defaults feature was designed to use names with underscores as it is the real name representing the option inside hammer. With respect to that the feature works as expected.

On the other side I understand it may be confusing for the users who use mostly the form with dashes.

I have prepared PR [1] that adds support for both forms.

Sureshkumar, would that be acceptable solution?

[1] https://github.com/theforeman/hammer-cli/pull/203
Comment 22 sthirugn@redhat.com 2016-05-16 08:21:01 EDT
@Martin: The proposed solution in Comment 21 looks good to me as long as the questions/comments in the PR are answered. Thanks!
Comment 24 Bryan Kearney 2016-06-02 16:40:48 EDT
Verified
Version Verified: Snap 14 satellite-cli-6.2.0-14.1.el7sat.noarch

Steps to verify:

[vagrant@sat-test-rhel7 ~]$ hammer -u admin -p changeme product list
Error: Could not find organization, please set one of options --organization, --organization-label, --organization-id.

[vagrant@sat-test-rhel7 ~]$ hammer defaults add --param-name organization-id  --param-value 1
Added organization-id default-option with value 1.

[vagrant@sat-test-rhel7 ~]$ hammer -u admin -p changeme product list
---|----------------------------------------------------------------------------------|-------------|----------------------|--------------|-----------
ID | NAME                                                                             | DESCRIPTION | ORGANIZATION         | REPOSITORIES | SYNC STATE
---|----------------------------------------------------------------------------------|-------------|----------------------|--------------|-----------
4  | Red Hat Software Collections for RHEL Server                                     |             | Default Organization | 0            |           
8  | Red Hat Software Collections Beta for RHEL Server                                |             | Default Organization | 0            |           
25 | Red Hat S-JIS Support for RHEL Server - Extended Update Support                  |             | Default Organization | 0            |           
27 | Red Hat Satellite with Embedded Oracle                                           |             | Default Organization | 0            |           
3  | Red Hat Satellite Proxy                                                          |             | Default Organization | 0            |           
2  | Red Hat Satellite Capsule Beta                                                   |             | Default Organization | 0            |           
5  | Red Hat Satellite Capsule                                                        |             | Default Organization | 0            |           
28 | Red Hat Satellite Beta                                                           |             | Default Organization | 0            |           
29 | Red Hat Satellite 6 Beta                                                         |             | Default Organization | 0            |           
30 | Red Hat Satellite                                                                |             | Default Organization | 1            |           
13 | Red Hat EUCJP Support for RHEL Server - Extended Update Support                  |             | Default Organization | 0            |           
15 | Red Hat Enterprise Linux Server - Extended Update Support                        |             | Default Organization | 0            |           
7  | Red Hat Enterprise Linux Server                                                  |             | Default Organization | 0            |           
19 | Red Hat Enterprise Linux Scalable File System for RHEL Server - Extended Upda... |             | Default Organization | 0            |           
10 | Red Hat Enterprise Linux Resilient Storage for RHEL Server - Extended Update ... |             | Default Organization | 0            |           
21 | Red Hat Enterprise Linux Load Balancer for RHEL Server - Extended Update Support |             | Default Organization | 0            |           
9  | Red Hat Enterprise Linux Load Balancer for RHEL Server                           |             | Default Organization | 0            |           
18 | Red Hat Enterprise Linux High Performance Networking for RHEL Server - Extend... |             | Default Organization | 0            |           
12 | Red Hat Enterprise Linux High Availability for RHEL Server - Extended Update ... |             | Default Organization | 0            |           
6  | Red Hat Enterprise Linux High Availability for RHEL Server                       |             | Default Organization | 0            |           
---|----------------------------------------------------------------------------------|-------------|----------------------|--------------|-----------
Comment 25 Bryan Kearney 2016-07-27 07:06:52 EDT
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2016:1501

Note You need to log in before you can comment on or make changes to this bug.