143 Commits

Author SHA1 Message Date
Cyril Roelandt
91ae9347db glance help <subcommand>: Clearly specify which options are mandatory
Earlier glance help <subcommand> was listing required arguments as
optional arguments in help text. Added new argument group to list
required argument properly.

$ glance help stores-delete

Example before this change:
usage: glance stores-delete --store <STORE_ID> <IMAGE_ID>

Delete image from specific store.

Positional arguments:
  <IMAGE_ID>          ID of image to update.

Optional arguments:
  --store <STORE_ID>  Store to delete image from.

After this change:
usage: glance stores-delete --store <STORE_ID> <IMAGE_ID>

Delete image from specific store.

Positional arguments:
  <IMAGE_ID>          ID of image to update.

Required arguments:
  --store <STORE_ID>  Store to delete image from.

Change-Id: I51ea4c43fa62164ed43e78d1ae0fb0cb2521fc83
Closes-Bug: #1933390
2021-12-14 15:14:10 +00:00
Mridula Joshi
1eb0bbbed7 Fix undesirable raw Python error
Using the glanceclient without a subcommand while
passing an optional argument triggers the raw Python
error `ERROR: 'Namespace' object has no attribute
'func'`. This bug can be reproduced by issuing the
command `glance --os-image-api-version 2`.
Added a default value to `func` as placeholder
so that a help message is shown instead of the Python error.

Closes-Bug: #1903727
Change-Id: Ie4288262e408192310cbbc240bd1779b265a64fd
2021-08-03 10:35:40 +00:00
Zuul
a29c6be97d Merge "Do not use the six library." 2020-07-17 19:32:29 +00:00
Cyril Roelandt
b513c8db4b Do not use the six library.
Change-Id: I3dbfcfa0f5f590a41ed549afd44537d8ed41433a
2020-06-23 21:51:07 +02:00
Hervé Beraud
e8455f5c18 Stop to use the __future__ module.
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.

We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.

Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]

[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328

Change-Id: I732a57361319687ca0a64693f0e60bc0d8f5b3d2
2020-06-02 20:47:47 +02:00
Rui Yuan Dou
8e862b6018 Remove deprecated ssl options
Old deprecated ssl options block the new keystoneauth parser get the
correct value, should be removed.

Change-Id: Ie080f9a8fa7f4407b1fcbb7fb7c763152c5ec295
Closes-Bug: 1697163
2018-01-17 08:50:57 +08:00
Jenkins
ca9ae01841 Merge "Make --profile load from environment variables" 2017-07-26 04:33:49 +00:00
PranaliD
28c003dc11 Removed the --no-ssl-compression parameter which is deprecated
--no-ssl-compression is deprecated and no longer used. So, it is
removed from the help message.

Change-Id: I2b886671a568ed191ee380cf16335ccd9ae85062
Closes-Bug: #1583919
2017-07-25 18:51:38 +05:30
Tovin Seven
c0f88d5fc0 Make --profile load from environment variables
--profile argument can be loaded from OS_PROFILE environment variables
to avoid repeating --profile in client commands.

Correct/update help text.

Co-Authored-By: Hieu LE <hieulq@vn.fujitsu.com>
Change-Id: I67c1e4b859b972e380eb658c98ceae4fbef5c254
2017-07-24 13:30:29 +07:00
Jenkins
8f8df1cced Merge "Handle formatting of subcommand name in error output" 2017-01-13 19:35:35 +00:00
Ian Cordasco
81039a1e36 Handle formatting of subcommand name in error output
On Python 2, decoding all arguments leads to the possibility that users
that use the wrong command or mistype the name will see error output
with a unicode string's representation instead of one without it. To
avoid this we try and find the first non-option string in the argument
list and replace it with an string that is not text only on Python 2. If
we encoded the string at all times, then users installing glanceclient
on Python 3 would see b'invalid-subcommand' instead. That's as bad as
seeing u'invalid-subcommand' on Python 2.

Closes-bug: 1533090
Change-Id: I018769e159a607ebb233902cbeb13b95ca417190
2017-01-11 07:33:34 -06:00
Li Wei
4773c96672 Use import_versioned_module from oslo.utils
oslo.utils 3.17 provides this funtion, so just use it directly.

Change-Id: I85cb78a6fd33a5b1f7e09648efed1b0737678eee
Closes-Bug: #1627313
2016-12-06 09:35:55 +00:00
Itisha Dewan
a9115b4cd8 switch from keystoneclient to keystoneauth
move glanceclient to keystoneauth as keystoneclient's auth session,
plugins and adapter code has been deprecated.

refer to [1] for more information.

1: 1a84e24fa4

implements bp: use-keystoneauth

Co-Authored-By: Itisha <ishadewan07@gmail.com>
Change-Id: I88fb327628e1bec48dc391f50d66b3deab4a8ab9
2016-09-03 03:22:04 +00:00
Jenkins
985df912e1 Merge "Remove unused skip_authentication decorator" 2016-06-21 16:13:59 +00:00
kairat_kushaev
2ab2678140 Remove deprecated construct method from session init
construct method is marked as deprecated and might be deleted
in one of future releases. So glanceclient need to be aware of
that and initialize sesssion from command line arguments directly.

Change-Id: Ie81b62b7e70bb177f178caadc41554ae88e51b05
2016-06-09 19:31:02 +00:00
kairat_kushaev
f58a73495f Remove unused skip_authentication decorator
skip_authentication is not used as decorator for glanceclient methods.
So this method can be safely removed from glance codebase because
it is artifact from old implementation.

Change-Id: I235b4c6b835c75266d8fae1bb603685aa17ad497
2016-06-02 13:25:30 +00:00
ZhiQiang Fan
3066256ba7 [Trivial] Remove unnecessary executable privilege
glanceclient/shell.py defines a main entry, however this file cannot
be executed directly because we do not call the main function in
this file. It is actually a module which will be used by
/usr/bin/glance, hence doesn't need to be executable.

Change-Id: I8b45ac7b8b88265cfc27e5ba7201e4766d9dc276
2016-05-21 13:17:41 +00:00
Niall Bunting
a862196cfb Get endpoint if os_image_url is not set
If env['OS_IMAGE_URL'] is not set then None is returned. This is then
used ignoring the endpoint_type, service_type and region_name. This
patch will use those values if the endpoint is None.

Change-Id: I76cc527b05d2be75d3dbc33123a0d71be97fe25c
Closes-bug: #1579768
2016-05-12 12:47:35 +00:00
Jenkins
12e92558e5 Merge "Re-enable stacktracing when --debug is used" 2016-04-18 17:04:57 +00:00
Dao Cong Tien
9faa9d47aa Fix typos in docstrings and comments
Update a comment to be more meaningful

Change-Id: Ie1aa46917c1a253db92a0dc819803a1d3e795b07
2016-04-11 09:08:02 +07:00
Stuart McLaren
d0ec3a7ebb Re-enable stacktracing when --debug is used
Commit 1f89beb6098f4f6a8d8c2912392b273bc068b2e3 introduced the behaviour
that a stacktrace is printed if an exception is encountered.

This helped make the client more supportable:

 $ glance --debug image-list
  .
  .
  .
  File "glanceclient/common/http.py", line 337, in get_http_client
    xxx
 NameError: global name 'xxx' is not defined
 global name 'xxx' is not defined

The behaviour was lost at some point. This patch re-enables it.

Change-Id: I25fc8624797909d606590747f54b9cf649ade079
Closes-bug: 1563830
2016-04-07 15:42:51 +00:00
Jenkins
8eaefe90a9 Merge "Fix v2 so that you can see the default help info" 2016-04-04 22:25:43 +00:00
zwei
444ffbeaa9 Fix v2 so that you can see the default help info
you can see the default help informatiion is v2
subcommand information if input glance command

Co-Authored-By: Stuart McLaren <stuart.mclaren@hp.com>

Closes-bug: #1563649
Change-Id: I7d227f3e68aa555b2e25848618f76df4872af35d
2016-03-30 12:37:28 +00:00
Cao ShuFeng
87c8c933bd Fix missing of debug info after we use session
After the introduce of this patch set[1], cli user can't get debug
info even --debug is passed. With the patch set[1], the request
action will be performed in keystoneclient.session.Session.
However the default log level of keystoneclient module is WARNING,
so user can't get debug info from keystoneclient.session.Session.

This change set the root log level to DEBUG when --debug is
passed.

[1]: https://review.openstack.org/#/c/262220/

Change-Id: I0db0fd7ab07a0d61082b86829a671d8dbc0f2963
Closes-bug: 1551076
2016-03-28 04:34:57 +00:00
Jenkins
95df686d35 Merge "Use session when not specified token or endpoint" 2016-02-01 01:48:26 +00:00
Darja Shakhray
bda34034eb Use session when not specified token or endpoint
When no token or endpoint, it creates a session and from there
taken the necessary values.
This commit proposes to transfer a session in such cases.
This will avoid unnecessary actions and some of the problems.

Change-Id: Idc874b6c01e915e52904604d59e8e0b460e71621
Partial-bug: #1519546
2016-01-14 17:32:30 +00:00
Steve Martinelli
bda4dd4dac use keystoneclient exceptions instead of oslo-incubator code
depending on any oslo-incubator code from another project is
dangerous. keystoneclient makes its exceptions public and it's
not recommended to use any code from
keystoneclient.openstack.common.apiclient since it's maintained
by oslo-incubator.

Change-Id: Ibfd9d364d3199fb485987edef06e1de916e57ee5
2015-12-27 01:37:44 -05:00
NiallBunting
bf67b80dbf Disable suggestion of v1 help for v2 commands
Currently the client suggests 'Run `glance --os-image-api-version 1
help` for v1 help' at the end of every help message. This is could
be confusing for a v2 only command.

Therefore this patch disables it if the command does not exist in v1,
while keeping the message on the 'glance help' results.

Change-Id: I967e9ba35afb8dc40524bd1d13284e684b435f81
Closes-Bug: 1520602
2015-12-09 13:21:17 +00:00
Jenkins
c4cb6a42ef Merge "Fix typo in 'help' in python-glanceclient" 2015-11-27 17:09:28 +00:00
Darja Shakhray
8b4f07767b Fix typo in 'help' in python-glanceclient
Fix typo `glance --os-image-api-version 1 helpNone` in help
in python-glanceclient.

Change-Id: I21bd7a7a5809e7c5fca4c8df1275321a9014bc6f
Closes-bug: #1506049
2015-11-27 16:20:14 +03:00
Jenkins
fcd9ab5769 Merge "Use common identity parameters fro keystone client" 2015-11-05 14:50:55 +00:00
kairat_kushaev
6b9133c9b6 Import i18n functions directly
As stated in i18n guide it is normal to import i18n functions
(_, _LW..)  directly and we can include i18n functions in
hacking exceptions.
Also there is no need to make exceptions for six moves
because pep8 passes correctly without it.

Change-Id: I9c9aa490f1447bb7ae221809df7bc110c27d1336
2015-10-16 11:26:11 +03:00
Jenkins
b88b510d3b Merge "print usage when no argument is specified for python3" 2015-10-14 11:04:16 +00:00
Flavio Percoco
36937bbf63 Use the subcomand parsed args instead of the base
Pass the subcomand's arguments instead of the base ones to the endpoint
creation call when quering the `/versions` endpoint. Passing the wrong
arguments will end in the auth_requirement not being identified and an
error 'Expected Endpoint' will be raised as no endpoint will be gotten
from keystone.

This patch also removes an unnecessary mock in the test code related to
this fix.

Depends-On Iefeb9bc123f8c65fecd0cba585ecd3eb349b23a6
Change-Id: I46088130b9175798e3719e43f48dc474fbc8a251
Closes-bug: #1504058
2015-10-12 17:05:55 +09:00
Zhiqiang Fan
a8a7c68990 print usage when no argument is specified for python3
When running just 'glance' under python3, we will get the error:
ERROR: 'Namespace' object has no attribute 'func'

This is because map() is used to decode sys.argv, but under Python3
it returns a map object which is an iterable. Some code later tries
to use this in a boolean context and it will always return True,
even if it's empty.

Change-Id: I2f03e462cb813833b75b9f2de7badd10b10cddff
Closes-Bug: #1295356
2015-10-09 11:03:15 -06:00
Jenkins
8c0c3c9ed4 Merge "Replace exception_to_str with oslo.utils function" 2015-09-30 18:10:40 +00:00
Jenkins
a98ed22091 Merge "Add check Identity validate when get schemas" 2015-09-29 08:22:41 +00:00
kairat_kushaev
1f2fefbc19 Use common identity parameters fro keystone client
The common identity params need to be requested from keystone
client instead of storing them in glance client.

Change-Id: If1260fb1e01b1fff798e9ce170e58ac62521d97d
2015-09-28 11:29:29 +03:00
Jenkins
5eaa52eae4 Merge "No auth when token and endpoint are passed" 2015-09-25 17:12:18 +00:00
Flavio Percoco
c31c136557 No auth when token and endpoint are passed
The latest change to the auth_required logic introduced a bug were even
when the token and endpoint were passed, authentication was being
required.

This patch fixes that issue and makes sure that authentication is not
required when these 2 arguements are present.

Closes-bug: #1499540

Change-Id: I4c9c15ba526378970da5461511ed922d42c5a9f9
2015-09-25 10:59:54 +02:00
kairat_kushaev
c6addc722c Replace exception_to_str with oslo.utils function
The oslo.utils function has exception_to_unicode that can
replace glance util function exception_to_str.
So we don't to have this exception_to_str function in glance
anymore.

Change-Id: I332bc55558087920fdd6ae2d822bece5166f5ba6
2015-09-22 15:40:02 +03:00
Atsushi SAKAI
05cd0c7508 Add period in help message
Command help message uses help and CLI-Reference generation.
  and in convention, help message stops with period ".".

Change-Id: I652afdb5e4d69a0476a0a2dc313ae60ece3b7bbc
2015-09-19 17:27:14 +00:00
Erno Kuvaja
160825f909 Fixes CLI client called without subcommands
If CLI client is called without any subcommands or arguments it will
fail with """'Namespace' object has no attribute 'command'""". This
is coming from the getattr which does not have alternate value
specified.

Closes-Bug: #1494259

Change-Id: I461f0d4a91f3af2224bafc14a88572a8e4a3c051
2015-09-11 12:56:08 +00:00
Erno Kuvaja
f6712f5d33 Print the reverting back to v1 to stderr
Printing to stderr to fix the download issue.

Change-Id: I2916bb100ac451378db82291855078f2b37466bd
Closes-Bug: #1488914
2015-09-09 13:34:05 +00:00
Flavio Percoco
5026774bd1 Don't make help require auth parameters
The `help` command was behaving a bit funky. This patch re-orders the
code a bit so that the `help` command will be parsed at the very
beginning before running other commands and checks.

It also allows to get help without downloading/checking schemas and
without requiring auth credentials (previously required by the schema
operations).

Change-Id: Ib7b10d4d80f15e6b75bb8644d7d916bef09413d6
Closes-bug: #1490457
2015-09-09 10:47:13 +00:00
Flavio Percoco
1322fbc5d8 Consider --os-token when using v2
The `_cache_schemas` call currently forces authentication even when the
`auth_token` and `os_image_url` are passed. Instead of handling forced
authentications, let the client use the passed arguments and
authenticate only once if needed.

This was not caught by the existing tests because the call to
`_cache_schemas` was mocked.

Change-Id: I93cec9a68cafc0992d14dab38114d03e25f1e5da
Closes-bug: #1490462
2015-09-04 13:31:55 +02:00
Flavio Percoco
47423ebbb2 Check if v2 is available and fallback
We have a basic implementation for a fallback mechanism that will use v1
rather than v2 when downloading schema files from glance-api fails.
However, this is not sound. If the schemas are cached already, we won't
check if v2 is available and fail to fallback.

This patch fixes the aforementioned issue by getting the list of
available versions from the server only when the API versions was not
explicitly specified through the CLI. That is, for all commands that
don't pass `--os-image-api-version 2`, we'll check v2's availability and
we'll fallback to v1 if it isn't available.

This patch also changes how we handle `/versions` calls in the client.
The server has been, incorrectly, replying to requests to `/version`
with a 300 error, which ended up in the client re-raising such
exception. While I think 300 shouldn't raise an exception, I think we
should handle that in a spearate patch. Therefore, this patch just
avoids raising such exception when `/version` is explicitly called.

This fallback behaviour and the check on `/versions` will be removed in
future versions of the client. The later depends on this bug[0] being
fixed.

[0] https://bugs.launchpad.net/glance/+bug/1491350

Closes-bug: #1489381
Change-Id: Ibeba6bc86db2a97b8a2b4bd042248464cd792e5e
2015-09-04 13:31:55 +02:00
Flavio Percoco
1e2274aef0 Password should be prompted once
There's a corner case where password may be requested twice. In a fresh
environment, when schemas have not be downloaded for v2, the client will
ask for a password to download the schemas and then it'll ask for the
password again to run the actual command. This happens because we parse
the CLI arguments twice to make sure we're parsing them for the right
client version.

This patch checks if the password is unset in the newly parsed arguments
and if it's been set in the previously parsed ones. In this case it
keeps the set password. I believe this approach is safer than re-using
the already parsed arguements which may have been parsed for a different
API version (might happen because we fallback to v1 if v2 is not
available).

Change-Id: I080253170e3e84a90363e5bb494cf137895fe2e7
Closes-bug: #1488892
2015-09-01 18:03:41 +02:00
Stuart McLaren
618637a5bd Remove custom SSL compression handling
Custom SSL handling was introduced because disabling SSL layer compression
provided an approximately five fold performance increase in some
cases. Without SSL layer compression disabled the image transfer would be
CPU bound -- with the CPU performing the DEFLATE algorithm.  This would
typically limit image transfers to < 20 MB/s. When --no-ssl-compression
was specified the client would not negotiate any compression algorithm
during the SSL handshake with the server which would remove the CPU
bottleneck and transfers could approach wire speed.

In order to support '--no-ssl-compression' two totally separate code
paths exist depending on whether this is True or False.  When SSL
compression is disabled, rather than using the standard 'requests'
library, we enter some custom code based on pyopenssl and httplib in
order to disable compression.

This patch/spec proposes removing the custom code because:

* It is a burden to maintain

 Eg adding new code such as keystone session support is more complicated

* It can introduce additional failure modes

 We have seen some bugs related to the 'custom' certificate checking

* Newer Operating Systems disable SSL for us.

 Eg. While Debian 7 defaulted to compression 'on', Debian 8 has compression
 'off'. This makes both servers and client less likely to have compression
 enabled.

* Newer combinations of 'requests' and 'python' do this for us

 Requests disables compression when backed by a version of python which
 supports it (>= 2.7.9). This makes clients more likely to disable
 compression out-of-the-box.

* It is (in principle) possible to do this on older versions too

 If pyopenssl, ndg-httpsclient and pyasn1 are installed on older
 operating system/python combinations, the requests library should
 disable SSL compression on the client side.

* Systems that have SSL compression enabled may be vulnerable to the CRIME
(https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2012-4929) attack.
Installations which are security conscious should be running the Glance
server with SSL disabled.

Full Spec: https://review.openstack.org/#/c/187674
Blueprint: remove-custom-client-ssl-handling

Change-Id: I7e7761fc91b0d6da03939374eeedd809534f6edf
2015-08-26 12:26:21 +00:00
Fei Long Wang
181131ef2e Use API v2 as default
Now we have claimed v2 is the current API version of Glance,
we should change the Glance client as well to be consistent
with Glance server.

DocImpact

Change-Id: I09c9e409d149e2d797785591183e06c13229b7f7
2015-08-11 14:01:28 +12:00