Bug 1154383 - [RFE] Ability to use user's default Org/Location in hammer CLI
Summary: [RFE] Ability to use user's default Org/Location in hammer CLI
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Hammer
Version: 6.0.4
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: Unspecified
Assignee: Martin Bacovsky
QA Contact: sthirugn@redhat.com
URL: http://projects.theforeman.org/issues...
Whiteboard:
: 1280015 (view as bug list)
Depends On:
Blocks: 1353215 1287901
TreeView+ depends on / blocked
 
Reported: 2014-10-19 11:55 UTC by Rich Jerrido
Modified: 2019-11-14 06:32 UTC (History)
15 users (show)

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.
Clone Of:
Environment:
Last Closed: 2016-07-27 11:06:52 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 8015 0 None None None 2016-04-26 17:04:49 UTC
Red Hat Bugzilla 1247781 0 unspecified CLOSED hammer queries defaults to 1000 items per page 2021-02-22 00:41:40 UTC
Red Hat Bugzilla 1315645 1 None None None 2021-01-20 06:05:38 UTC

Internal Links: 1247781 1315645

Description Rich Jerrido 2014-10-19 11:55:06 UTC
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 Program Management 2014-10-19 12:02:58 UTC
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 15:37:41 UTC
Created redmine issue http://projects.theforeman.org/issues/8015 from this bug

Comment 5 Bryan Kearney 2015-11-13 16:47:57 UTC
*** Bug 1280015 has been marked as a duplicate of this bug. ***

Comment 6 Bryan Kearney 2015-12-08 17:06:20 UTC
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 17:12:57 UTC
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 17:43:36 UTC
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 07:09:33 UTC
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 09:18:34 UTC
Created upstream bug (and a PR): http://projects.theforeman.org/issues/14311

Comment 17 Shimon Shtein 2016-03-23 08:44:00 UTC
Apparently bugzilla was already there: https://bugzilla.redhat.com/show_bug.cgi?id=1315645

Comment 18 Mike McCune 2016-04-01 04:26:22 UTC
this looks the same as 1315645, QE: feel free to close as a dupe

Comment 19 sthirugn@redhat.com 2016-04-01 19:02:55 UTC
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 14:59:30 UTC
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 12:21:01 UTC
@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 20:40:48 UTC
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 11:06:52 UTC
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.