108 Commits

Author SHA1 Message Date
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
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
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
Takeaki Matsumoto
b9eee5ee32 Add check Identity validate when get schemas
Glance client don't check Identity validate when get schemas.
So when you exec "glance image-create" with invalid credentials in
glance-api.conf, it returns "unrecognized arguments: --foo".
It is difficult to debug such message.

This change makes invalid credentials error clear.

Change-Id: Ib641333cd8d51f459df70306a1eeda250ada5ca1
Closes-Bug: 1467719
2015-07-24 09:20:56 +09:00
Darja Shakhray
ec0f2dfd85 Enable flake8 checks
This commit enables new flake8 checks:
* E265  block comment should start with '# '
* H405  multi line docstring summary not separated with an empty line
* E123  closing bracket does not match indentation of opening bracket's line
* H238  old style class declaration, use new style (inherit from `object`)
* E128  continuation line under-indented for visual indent
and makes related changes in the code.

Change-Id: Ie993afc930f6b74d7a990bcaa9fc0e9f5ba1585c
2015-07-21 17:08:27 +03:00
Cindy Pallares
997c12d3ab Import only modules and update tox.ini
As stated in the OpenStack Hacking Guidelines, it is prefered
that only modules should be imported.

Also updated tox.ini to ignore opestack/common among others.

Change-Id: I2f0a603c31052eadee581c11880c0ec6bd392829
2015-06-17 10:56:37 -05:00
Jenkins
d80c70e58a Merge "Improve import related error handling" 2015-05-26 18:20:16 +00:00
Thomas Goirand
1686d6aa53 Do not crash on homedir mkdir
Glanceclient is trying to create ~/.glanceclient, and crashes if it can't
do that. In some environment (for example, when building the package
under Jenkins), writing on $HOME is simply not allowed, and Glanceclient
can simply ignore it. This patch allows the mkdir() to fail, which fixes
the issue.

Closes-Bug: #1446096
Change-Id: Ib3591fb4e54ccd2fe63a1a4815551ac10ef5b961
2015-05-14 15:41:24 +00:00
Stuart McLaren
1f89beb609 Improve import related error handling
If there was a problem importing a library we would incorrectly raise
an unsupported version error:

  $ glance --os-image-api-version 1 image-list
  "1" is not a supported API version. Example values are "1" or "2".

We should change this to provide information on the failed import, eg:

  $ glance --os-image-api-version 1 image-list
  No module named badimport

We also now raise the full stacktrace in this case if '--debug' is passed
on the command line.

Change-Id: I1c687ae6c5da239090b0b7a4a855b3271a9076da
Related-bug: 1402632
2015-05-08 12:51:02 +00:00
Jenkins
9e09211914 Merge "Remove duplicate 'a' in the help string of --os-image-url" 2015-03-10 11:50:53 +00:00
Jenkins
7f9b643371 Merge "Remove graduated gettextutils from openstack/common" 2015-03-03 23:38:17 +00:00
Jenkins
99c46d64a0 Merge "Strip json and html from error messages" 2015-03-01 16:19:15 +00:00
Jenkins
437c44f40b Merge "Fixed CLI help for bash-completion" 2015-02-23 19:02:44 +00:00
d34dh0r53
01caf4e734 Strip json and html from error messages
Error messages were being passed with either JSON or HTML formatting
leading to an unpleasant user experience. This strips the JSON or HTML
tags and presents the clean error message to the user.

Rewrote the lispy function to be more pythonic, added test cases
and cleaned up some pep8 violations.

Removed commented out cruft from a previous version of this
patch.

Changed the HTML details from a set to a list in order to ensure
the ordering of the exception details.

Added code to eliminate the duplicate detail messages from the list
and reordered the assertion string to match actual output.

Refactored duplicate elimination code to be more readable and
reliable.

Some reworking of the duplication elimination loop to make it
more readable.

Removed unneeded conditional to filter out empty elements.

Change-Id: I79985b3e305cb30328a3c16b025315a8e969243d
Closes-Bug: 1398838
2015-02-16 10:01:53 -06:00
Jenkins
1c37721287 Merge "Return 130 for keyboard interrupt" 2015-02-06 16:23:21 +00:00
Louis Taylor
e99e0c8690 Change oslo.utils to oslo_utils
The oslo.utils libraries are moving away from namespace packages.

This requires oslo.utils>=1.2.0

bp drop-namespace-packages

Change-Id: I803df61e91eabb96329d859aef6bea03530fb84f
2015-02-05 22:27:16 +00:00
Rakesh H S
96ff6e46c4 Return 130 for keyboard interrupt
When keyboard interrupt is received by glanceclient, the return code as
of now is 1.

But since the client was terminated by an keyboard interrupt, the return
code should be 130. (http://tldp.org/LDP/abs/html/exitcodes.html)
It is useful when people are writing automation test cases and want to
validate based on the return code.

Change-Id: Ia70116ab6f0708a0ce6eeaed07c1e7a56e68c9f4
Closes-Bug: #1373231
2015-02-05 05:08:59 +00:00
Ian Cordasco
1d823962e1 Remove graduated gettextutils from openstack/common
Use oslo.i18n package and handle different versions properly in
glanceclient._i18n. The oslo namespace is being deprecated so imports
will be oslo_i18n going forward. For older versions of oslo.i18n though,
we will still be able to import i18n from oslo.

Change-Id: Id56d34ccf447dc6f7becafb74d6a30e8a1642030
2015-02-03 13:20:39 -06:00
Louis Taylor
869e6ace0e Use utils.exit rather than print+sys.exit
This replaces the use of a pattern along the lines of

    print(error message)
    sys.exit(1)

in a couple of place in the shell. utils.exit does much the same job,
but outputs to stderr.

Change-Id: I1d3b52e0685772c10aa806a8f208eb6dd7a0e7ef
2015-02-03 18:21:04 +05:30
Yvonne Stachowski
9daada9b9a Fixed CLI help for bash-completion
When running 'glance help' the following lines were displayed:

bash-completion     Prints all of the commands and options to stdout so
                    that the

The help now prints:

bash-completion     Prints arguments for bash_completion.

similar to other Openstack CLIs (such as Cinder and Trove).

Change-Id: I1b1d60e23a3662675c5e81a332e9fd8360f6c7b1
2015-01-28 13:25:31 -05:00
Louis Taylor
878bdcbdbc Remove openstack.common.importutils
This module now lives in oslo.utils, so import it from there.

Change-Id: I41fa4897fc820596fb010336044ff4c493017d5a
2015-01-28 02:12:18 +00:00
Louis Taylor
b818826420 Remove openstack.common.strutils
This module now lives in oslo.utils, so import it from there instead.

Co-Authored-By: Ian Cordasco <ian.cordasco@rackspace.com>
Change-Id: Ib35dc840992433542490670781badd9529ec8947
2015-01-27 19:22:42 +00:00
Christian Berendt
b64dba8fa2 Remove duplicate 'a' in the help string of --os-image-url
Instead of 'url contains a a version number' it should be
'url contains a version number'.

Change-Id: I7caa350954a37e2af90c656ceb698d9ab772e463
2015-01-20 10:06:13 +01:00
Jenkins
7ce1ff9325 Merge "Add os_ prefix to project_domain_name/id" 2015-01-04 10:40:07 +00:00
Mike Fedosin
8e8dde2052 Output clear error message on invalid api version
Now if --os-image-api-version mistakenly contains a string then
you will get a ValueError

Example:
$ glance --os-image-api-version hui
ValueError: invalid literal for int() with base 10: 'hui'

This code correctly handles this situation, prints a warning
message and interrupts the execution of the client

Change-Id: I4733578adfc70bd57afd5f0d4d361c8ef689a381
Closes-bug: 1401197
2014-12-10 21:39:18 +03:00
Flavio Percoco
9829d7b6b9 Don't require version to create Client instance
We currently require a version to always be passed to discover the
client version that should be loaded. However, this information is
commonly present in the URL instead. The current behavior forces
consumers of the library to keep the required version around and/or to
strip it themselves from the URL.

This patch relaxes that requirement by making the version a keyword and
requesting instead an endpoint to be passed. The patch gives priority to
the version in the endpoint and falls back to the keyword if the later is
not present.

Follow-up patches will improve this code making it interact a bit more
with the endpoint's catalog.

Closes-bug: #1395714
Change-Id: I4ada9e724ac4709429e502b5a006604ca0453f61
2014-12-09 14:45:06 +00:00
Oleksii Chuprykov
bd73a5482c Add os_ prefix to project_domain_name/id
Running glance without defining --os-tenant-id and
--os-tenant-name leads to AttributeError. Add os_ prefix
to project_domain_name and project_domain_id because args
object doesn't have them

Closes-Bug: #1384759

Change-Id: Id85569aad538efcf327312d9936bb6463279ce34
2014-12-09 11:34:57 +00:00
Jenkins
acb1659357 Merge "Add useful error on invalid --os-image-api-version" 2014-12-02 01:43:35 +00:00
Louis Taylor
d5a0e657ed Add useful error on invalid --os-image-api-version
This adds a useful error message when a user enters an invalid value
for --os-image-api-version. Previously, the shell directly attempted to
import the module the user specified, and printed the error from the
exception raised when that failed:

    $ glance --os-image-api-version stupid-glance-version
    No module named vstupid-glance-version.shell

Glanceclient now catches this exception and prints something
understandable for a user:

    $ glance --os-image-api-version stupid-glance-version
    "stupid-glance-version" is not a supported API version. Example values are "1" or "2".

Closes-Bug: #1395841

Change-Id: I48a95b7562c10bd68d777be408dcfa22cb05ec6a
2014-11-25 16:22:47 +00:00
Jenkins
3b6754a8cc Merge "Adds tty password entry for glanceclient" 2014-11-25 09:38:15 +00:00
Jenkins
265bb4aa17 Merge "Add bash completion to glance client" 2014-11-20 10:06:53 +00:00
Jenkins
b126351d9d Merge "Fix to ensure endpoint_type is used by _get_endpoint()" 2014-11-11 03:31:55 +00:00
John Trowbridge
751e064761 Adds tty password entry for glanceclient
Added functionality from keystoneclient to fallback to the tty for password
entry if no password is given via the environment or the --os-password option.

Change-Id: I096e81b61d7f499cbda300abdc14430928d18491
Closes-Bug: 1357549
2014-10-23 18:31:36 +00:00
Louis Taylor
4d6b94a679 Print traceback to stderr if --debug is set
This change allows easier debugging of client related issues, with a
full traceback printed out when an uncaught error occurs in the client.
Previously, it could be hard to find the portion of code raising an
exception, with just the message from the exception being displayed.

Previous behaviour (with a rather artificial client error being raised):

    $ glance --debug image-list
    Contrived exception

Behaviour after this patch:

    $ glance --debug image-list
    Traceback (most recent call last):
      File "/opt/stack/python-glanceclient/glanceclient/shell.py", line 590, in main
        args.func(client, args)
      File "/opt/stack/python-glanceclient/glanceclient/v1/shell.py", line 77, in do_image_list
        raise(Exception('Contrived exception'))
    Exception: Contrived exception
    Contrived exception

Change-Id: Id7b76b707e5fc16a0402dcb104ec40787e0ffbe2
2014-09-15 20:04:38 +00:00
Jenkins
e4417169a6 Merge "Import missing gettextutils._ in shell.py" 2014-09-13 00:54:26 +00:00
Andy McCrae
cbbfbc91c9 Fix to ensure endpoint_type is used by _get_endpoint()
* ks_session get_endpoint uses "interface" instead of "endpoint_type"

Change-Id: I59e45423703774f6dc26c96644f83083832b0627
Closes-Bug: #1367782
2014-09-10 15:43:46 +01:00
Pawel Koniszewski
33dcea81b2 Support for Metadata Definitions Catalog API
API calls and shell commands added in this patch:
- CRUD for metadefs namespaces;
- CRUD for metadefs objects;
- CRUD for metadefs properites;
- CRD for metadefs resource types and resource type associations.

Change-Id: I6d15f749038e8fd24fc651f0b314df5be7c673ef
Implements: blueprint metadata-schema-catalog-support
Co-Authored-By: Facundo Maldonado <facundo.n.maldonado@intel.com>
Co-Authored-By: Michal Dulko <michal.dulko@intel.com>
Co-Authored-By: Lakshmi N Sampath <lakshmi.sampath@hp.com>
Co-Authored-By: Pawel Koniszewski <pawel.koniszewski@intel.com>
2014-09-03 11:45:57 -06:00
Matthew Booth
d97f03e099 Import missing gettextutils._ in shell.py
Closes-Bug: #1355252

Change-Id: I3aef19235735b3b374b92985f142712cb0f37a35
2014-09-02 15:32:07 +01:00