Commit Graph

442 Commits

Author SHA1 Message Date
Jenkins ab52bf3ce2 Merge "Unify using six.moves.range rename everywhere" 2015-03-04 16:29:50 +00:00
Jenkins 5ce1de9da4 Merge "https: Prevent leaking sockets for some operations" 2015-03-04 08:38:19 +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 db0179f5c4 Merge "Register our own ConnectionPool without globals" 2015-02-26 21:29:06 +00:00
Erno Kuvaja 2d67dfa97a Unify using six.moves.range rename everywhere
Mainly to improve consistency, use range() from six.moves
renames across glance.

Behaves consistently like py2 xrange() and py3 range().

Change-Id: I7c573a3a9775f454b98d25f2a14f8e9f5f4ac432
2015-02-25 12:17:24 +00:00
Jenkins 437c44f40b Merge "Fixed CLI help for bash-completion" 2015-02-23 19:02:44 +00:00
Jenkins 93ca39ba18 Merge "Reduce the set of supported client SSL ciphers" 2015-02-23 16:06:48 +00:00
Jenkins 654ba87a89 Merge "Glance image delete output" 2015-02-20 14:48:49 +00:00
Jenkins 72f0bc3579 Merge "Update HTTPS certificate handling for pep-0476" 2015-02-19 17:58:58 +00:00
Stuart McLaren ef9fd9fca0 https: Prevent leaking sockets for some operations
Other OpenStack services which instantiate a 'https' glanceclient using
ssl_compression=False and insecure=False (eg Nova, Cinder) are leaking
sockets due to glanceclient not closing the connection to the Glance
server.

This could happen for a sub-set of calls, eg 'show', 'delete', 'update'.

netstat -nopd would show the sockets would hang around forever:

... 127.0.0.1:9292          ESTABLISHED 9552/python      off (0.00/0/0)

urllib's ConnectionPool relies on the garbage collector to tear down
sockets which are no longer in use. The 'verify_callback' function used to
validate SSL certs was holding a reference to the VerifiedHTTPSConnection
instance which prevented the sockets being torn down.

Change-Id: Idb3e68151c48ed623ab89d05d88ea48465429838
Closes-bug: 1423165
2015-02-18 12:31:24 +00:00
Abhishek Talwar f7cdc3eefe Glance image delete output
Deleting an already deleted image using admin user is throwing an
error "404 Not Found" which is confusing. Deleting an image that does
not exist throws "No image with a name or ID of 'image-id' exists."

Updated the code so that trying to delete an already deleted image
throws "No image with an ID of 'image-id' exists." error.

Closes-Bug: #1333119
Change-Id: I8f9a6174663337a0f48aafa029a4339c32eb2134
Co-Authored-By: Abhishek Talwar <abhishek.talwar@tcs.com>
Co-Authored-By: Kamil Rykowski <kamil.rykowski@intel.com>
2015-02-17 11:27:24 +01: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
Ian Cordasco 7ee96cbe39 Register our own ConnectionPool without globals
Currently, on systems like Fedora and Debian, it is possible to import
urllib3 as well as requests.packages.urllib3. They functionally point to
the same code but sys.modules considers them to be separate items. When
downstream packagers unvendor urllib3 from requests, they also change
all the imports inside of the package. So if the code imports urllib3
from requests.packages.urllib3 and modifies globals in a submodule, that
will not be visible to requests since it has been rewritten to use
urllib3 (not requests.packages.urllib3). By handling this logic
ourselves, we can issue a release until upstream packages and requests
can fix this and cut a new release.

Change-Id: Ic77ce8a06d9d148a899b4b8695990fca8fdaefc5
Closes-bug: 1396550
2015-02-06 13:49:13 -06:00
Jenkins 1c37721287 Merge "Return 130 for keyboard interrupt" 2015-02-06 16:23:21 +00:00
Jenkins 60e7beb28b Merge "Change oslo.utils to oslo_utils" 2015-02-06 12:44:17 +00:00
Jenkins 0272106717 Merge "Close streamed requests explicitly" 2015-02-06 12:16:46 +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
Jenkins ce5e1f0d48 Merge "Ignore NoneType when encoding headers" 2015-02-05 18:48:29 +00:00
Jenkins 945a697bba Merge "Use utils.exit rather than print+sys.exit" 2015-02-05 12:09:10 +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
Jenkins 5b2603d74e Merge "Disable progress bar if image is piped into client" 2015-02-04 23:41:11 +00:00
Jenkins 9a78cb2471 Merge "Add validation to --property-filter in v1 shell" 2015-02-04 23:40:50 +00:00
Ian Cordasco db743e3635 Ignore NoneType when encoding headers
Some generated header values may in fact be None. Trying to encode None
causes the client to fail with an exception and cannot be worked around
by the user.

Change-Id: I638b1fba0ef9a07d726445d8c2cdd774140f5b83
Closes-bug: 1415935
2015-02-03 13:22:44 -06: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
Jenkins b595ab73ed Merge "Remove openstack.common.importutils" 2015-02-02 09:44:21 +00:00
Jenkins 4bfd8d5097 Merge "Remove openstack.common.strutils" 2015-02-02 04:49:32 +00:00
Flavio Percoco 93c9bc1fe0 Add a --limit parameter to list operations
In v2, we use the link header during paginations to know when there are
more images available in the server that could be returned in the same
request. This way, it's possible to iterate over the generator returned
by list and consume the images in the server.

However, it's currently not possible to tell glanceclient the exact
number of images we want, which basically means that it'll *always* go
through the whole list of images in the server unless the limit is
implemented by the consumer.

DocImpact
Change-Id: I9f65a40d4eafda6320e5c7d94d03fcd1bbc93e33
Closes-bug: #1415035
2015-01-29 10:37:55 +00:00
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
Zhi Yan Liu 363b170851 Sync latest apiclient from oslo-inc
a908d66 Remove uuidutils
5985b35 Prefer delayed %r formatting over explicit repr use
002999b Curl statements to include globoff for IPv6 URLs
03e6272 Add ConnectionError exception
3bc8231 deprecate apiclient package
fd8dc0c Handle different format of api exception
a7af1e2 Mask keystone token in debug output
55ca7c3 Split cliutils
5d40e14 Remove code that moved to oslo.i18n
6ff6b4b Switch oslo-incubator to use oslo.utils and remove old modules
f76f44c Delete the token and endpoint on expiry of token of client
ed0ffb8 Do not incur the cost of a second method call
cf449e2 Fix response_key parameter usage in BaseManager
94245b1 Make it possible to get the request_id from python clients
d73f3b1 Remove unused/mutable default args
5e00685 Centralize bash-completion in Novaclient
4ef0193 Handle non-openstack errors gracefully
ac995be Fix E126 pep8 errors
de4adbc pep8: fixed multiple violations
e42e77f Restore UUID and human-ID bash completion
9e88af1 fixed typos found by RETF rules
822e09b Don't slugify names that don't exist
4a777e5 Fix warnings in doc build for apiclient
3fb053c apiclient.exceptions.from_response() may miss request_id

Btw, the patch removed the uesless 'network_utils' line from
openstack-common.conf, currently we use oslo_utils.netutils directly.

Change-Id: Ic3d48a13d5366b050b07ef26ab34fad411a0db05
Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
2015-01-23 23:05:05 +08:00
Jenkins cb34b9b6eb Merge "Handle HTTP byte returns in python 3" 2015-01-23 14:47:36 +00:00
Jenkins 88f6319b7b Merge "Make non-boolean check strict" 2015-01-23 14:40:27 +00:00
Ian Cordasco f2107512ee Close streamed requests explicitly
If we don't explicitly close a response after streaming its download,
then we can run into HTTPConnectionPool full warnings. It also will hurt
performance if we have to continuously create new sockets for new
responses. Calling close will return the connection to the pool so it
can be reused. Note this is only necessary when streaming a response. If
we don't stream it, then requests will return the connection to the pool
for us.

Change-Id: I803bd4dd0e769c233501d5e5ff07a19705fbe233
Closes-bug: 1341777
2015-01-15 17:20:57 -06:00
Jamie Lennox 62df6c669f Handle HTTP byte returns in python 3
The returns from requests' response.content is a bytes type. Under
python 3 this fails in error handling and string conversion. The
response.text variable should be used to treat a response body as a
string.

Closes-Bug: #1407531
Change-Id: Ifd588b5f6820ef21beb186d88d0b3f1a267695aa
2015-01-14 12:32:07 +10:00
Louis Taylor cb046bc4fc Add validation to --property-filter in v1 shell
Previously, using --property-filter with invalid arguments resulted in
a rather cryptic error message:

    $ glance image-list --property-filter name
    dictionary update sequence element #0 has length 1; 2 is required

Now, something which is human decipherable is printed:

    $ glance image-list --property-filter name
    Argument --property-filter requires properties in the format KEY=VALUE

Change-Id: I61d19894fd8864bdca2fa3f627da3c7eb1341c51
2015-01-08 17:01:17 +00:00
Jenkins dac71b4be9 Merge "Curl statements to include globoff for IPv6 URLs" 2015-01-08 14:58:41 +00:00
Cindy Pallares 6eaaad532a Make non-boolean check strict
Currently when we enter any non-boolean strings in the client, it
accepts it and defaults the value to false. It should check if the
strings are boolean values and respond with an error if they're not.

Closes-Bug: #1394236
Change-Id: Ie498ee1b93524d91a43343f73140446c2cc9ab92
2015-01-06 11:36:01 -05:00
Louis Taylor 9054324442 Disable progress bar if image is piped into client
Previously, running:

    cat something.img | glance image-create --progress --container-format=bare --disk-format=raw

or

    cat something.img | glance --os-image-api-version 2 image-upload --progress <image id>

would result in an error. This error was caused by the length of the
input being unknown, so the overall progress cannot be found.

This patch disables the progress bar whenever the size of the input file
cannot be determined.

Change-Id: I6bfef7441864b638194126880241cc2c96d5b18b
Closes-Bug: #1402746
2015-01-06 10:36:01 +00:00
Louis Taylor df02ee8e2a Fix Requests breaking download progress bar
The move to the requests library (dbb242b) broke the progress bar during
downloading an image with --progress enabled, due to requests returning
a generator, which has no __len__ function. This patch adds an iterable
wrapper which provides the length, sourced from Content-Length headers.

Closes-Bug: #1384664

Change-Id: I48598a824396bc6e7cba69eb3ce32e7c8f30a18a
2015-01-04 20:52:00 +00:00
Jenkins 7ce1ff9325 Merge "Add os_ prefix to project_domain_name/id" 2015-01-04 10:40:07 +00:00
Sabari Kumar Murugesan e3600ad7be Fix broken-pipe seen in glance-api
When file size is an exact multiple of chunk_size, glance client
is processing EOF in image-data as a chunk and sends to
glance-api. The server treats this as the end of chunked 
transmission and sends a http response.

When the actual last chunk is sent by the 'requests' library, the
server sends a 400 response and tracebacks with broken pipe
as the client has already closed the socket.

Closes-Bug: #1342080
Change-Id: Icdbff838450db1c252ddc919a230a7d3ca16765f
2014-12-22 19:57:46 +00:00
James Page b96f613026 Update HTTPS certificate handling for pep-0476
This pep (included in python 2.7.9) changes the behaviour of SSL
certificate chain handling to be more py3 like.

Include required new exception behaviour in the list of
exceptions to translate under py2.

https://github.com/python/peps/blob/master/pep-0476.txt

Closes-Bug: 1404227

Change-Id: I7da1a13d1ec861a07fd96684d0431508a214a2c8
2014-12-19 13:01:32 +00:00
Jenkins 0cdc947bf9 Merge "Output clear error message on invalid api version" 2014-12-15 15:55:58 +00:00
Travis Tripp 9a4d8580e8 Support Pagination for namespace list
The rest api metadefs/namespaces supports pagination using the parameters
of limit, marker, sort_dir, & sort_key. However, the glance client isn't
passing those parameters through (they come in as kwargs). This is
preventing pagination from working properly in horizon.

This is affecting Horizon support: https://review.openstack.org/#/c/104063/

Change-Id: Ib349cf3a3a437eb1711f350b37d0bd0e7d01330a
Closes-Bug: 1381816
2014-12-10 23:21:41 -07: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 3989cd202d Support schema types with non-str value
Change I75da1e9309e0f7ef8839dea3ec9c99c58edc5d63 introduced some
properties' types which are not string. This broke the `schema_args`
utility since lists are not hashable and there was no support for such
type values.

This patch fixes this issue with a very glance specific strategy in
which this values are assumed to have a `null` type and another type -
string, integer, etc. The fix ignores `null` options and it takes the
first non-null type as the valid one.

The patch adds support for enum types that accept `None`

Closes-bug: #1401032
Change-Id: I250e8912aca262a56c54ac59bb24f917e5d8cfce
2014-12-10 13:23:36 +01: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