summaryrefslogtreecommitdiff
path: root/glanceclient/common/utils.py
Commit message (Collapse)AuthorAgeFilesLines
...
* Merge "Close iterables at the end of iteration"Jenkins2015-06-161-1/+5
|\
| * Close iterables at the end of iterationRobert Collins2015-06-111-1/+5
| | | | | | | | | | | | | | | | | | | | | | This fixes a bug where if iteration is interrupted, we're stuck until the iterable is garbage collected, which can be a very long time (e.g. if the iterable is held in an exception stack frame). Co-authored-by: Stuart McLaren <stuart.mclaren@hp.com> Change-Id: Ibe9990e8c337c117a978b1cd8ec388c4bc6d3b4b Closes-bug: 1461678
* | Make glanceclient accept a session objectJamie Lennox2015-06-111-0/+8
|/ | | | | | | | | | | To make this work we create a different HTTPClient that extends the basic keystoneclient Adapter. The Adapter is a standard set of parameters that all clients should know how to use like region_name and user_agent. We extend this with the glance specific response manipulation like loading and sending iterables. Implements: bp session-objects Change-Id: Ie8eb4bbf7d1a037099a6d4b272cab70525fbfc85
* glance image-show now have --human-readable optionyatin karel2015-03-221-1/+3
| | | | | | | | Added option '--human-readable' to image-show cli which allows users to display image size in human-readable format. Change-Id: Ic3452ce4560d3cf90fa7f59f98e5ff42e804f8c9 Closes-Bug: #1434381
* Merge "Return 130 for keyboard interrupt"Jenkins2015-02-061-2/+2
|\
| * Return 130 for keyboard interruptRakesh H S2015-02-051-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Change oslo.utils to oslo_utilsLouis Taylor2015-02-051-3/+3
|/ | | | | | | | | | The oslo.utils libraries are moving away from namespace packages. This requires oslo.utils>=1.2.0 bp drop-namespace-packages Change-Id: I803df61e91eabb96329d859aef6bea03530fb84f
* Remove openstack.common.importutilsLouis Taylor2015-01-281-1/+1
| | | | | | This module now lives in oslo.utils, so import it from there. Change-Id: I41fa4897fc820596fb010336044ff4c493017d5a
* Remove openstack.common.strutilsLouis Taylor2015-01-271-6/+9
| | | | | | | 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
* Fix Requests breaking download progress barLouis Taylor2015-01-041-0/+15
| | | | | | | | | | | 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
* Support schema types with non-str valueFlavio Percoco2014-12-101-2/+18
| | | | | | | | | | | | | | | | | 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
* Don't require version to create Client instanceFlavio Percoco2014-12-091-3/+11
| | | | | | | | | | | | | | | | | | 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
* Update how tokens are redactedTravis Tripp2014-09-151-0/+12
| | | | | | | | | | | | | Using SHA-1 to match how Nova and Swift redact their tokens. Was discussed in the below thread: http://lists.openstack.org/pipermail/openstack-dev/2014-September/045802.html Here's what nova went with: https://review.openstack.org/#/c/99511/ swift seem to be following suit: https://review.openstack.org/#/c/99632/ Change-Id: I3045d6d9d2a13770f4022dbbd474b34eb1032f6e Closes-bug: 1329301
* Fix v2 requests to non-bleeding edge serversLakshmi N Sampath2014-09-121-0/+18
| | | | | | | | | | | | In the case where v2 requests are sent to a server which is not running head of tree which includes the v2 metadef code some 404 cases need to be handled to enable standard requests to complete. This patch aslo improves fetching schemas -- they are now only fetched as needed. Change-Id: I8c871f11b909337bd7df19b77e606772dbc634b2 Closes-bug: #1367326
* Support for Metadata Definitions Catalog API0.14.0Pawel Koniszewski2014-09-031-2/+12
| | | | | | | | | | | | | | | 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>
* Merge "Use immutable arg rather mutable arg"Jenkins2014-08-031-2/+4
|\
| * Use immutable arg rather mutable argliuqing2014-07-031-2/+4
| | | | | | | | | | | | | | | | Passing mutable objects as default args is a known Python pitfall. We'd better avoid this. This commit changes mutable default args with None. Change-Id: I78323383c8b6a9a516a2a217303124870822418b
* | Replace old httpclient with requestsAmalaBasha2014-07-101-0/+20
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | This review implements blueprint python-request and replaces the old http client implementation in favor of a new one based on python-requests. Major changes: * raw_request and json_request removed since everything is now being handled by the same method "_request" * New methods that match HTTP's methods were added: - get - put - post - head - patch - delete * Content-Type is now being "inferred" based on the data being sent: - if it is file-like object it chunks the request - if it is a python type not instance of basestring then it'll try to serialize it to json - Every other case will keep the incoming content-type and will send the data as is. * Glanceclient's HTTPSConnection implementation will be used if no-compression flag is set to True. Co-Author: Flavio Percoco<flaper87@gmail.com> Change-Id: I09f70eee3e2777f52ce040296015d41649c2586a
* Add support for location parameters in v2 commandsDavid Koo2014-06-161-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently glanceclient's v2 commands don't support modification operations on an image's location attribute - the argparse specification for the location attribute of the image-update command causes the image id argument to be included in list of locations and so the command parsing fails (because it causes the image id to appear to be missing). Furthermore even if the 'locations' argument were to be accepted by argparse (e.g. by changing the argument specs and using --id to specify the image id) the command would still fail because the arguments are passed directly to the schema which expects the value of the 'locations' argument to be a valid dictionary (there is nobody to convert the argument string to a python dictionary that the schema expects). This commit adds the following location related commands to glanceclient: --location-add: Add a new location to the list of image locations. --location-delete: Remove an existing location from the list of image locations. --location-update: Update the metadata of existing location. The glanceclient.v2.images.Controller class has been agumented with three new methods to support the commands listed above: - add_location - delete_locations - update_location The server has not been modified, i.e. all location related API requests are passed to the server via HTTP PATCH requests and handled by the server's image update function. The v2 'image' and 'shell' related tests have also been supplemented. Note that in order to use these options the server must be first configured to expose location related info to the clients (i.e. 'show_multiple_locations' must be set to 'True"). I also added a mailmap entry for myself. DocImpact Closes-bug: #1271452 Co-Author: David Koo (koofoss) <david.koo@huawei.com> Change-Id: Id1f320af05d9344645836359758e4aa227aafc69
* Merge "Finalize Python3 support"Jenkins2014-05-281-1/+2
|\
| * Finalize Python3 supportFrederic Lepied2014-05-201-1/+2
| | | | | | | | | | | | | | Set the environment variable PYTHONHASHSEED to 0 to have predictive tests under Python 3. Change-Id: Ia15a9383e0f20bd0e4572e9f9b9772f1704dff86
* | fixed typos found by RETF rulesChristian Berendt2014-05-051-1/+1
|/ | | | | | rules are avaialble at https://en.wikipedia.org/wiki/Wikipedia:AutoWikiBrowser/Typos Change-Id: I70245e5ddf342762eb76d8e2e74b6363767726ef
* Python 3: do not use the unicode() functionCyril Roelandt2014-03-031-1/+1
| | | | | | | It is Python2-specific, and should not be used in code intended to be portable. Change-Id: Ibebef1a7e51a7444538275d22d444c926b8b4dec Closes-Bug: 1284677
* Merge "Using common method 'bool_from_string' from oslo strutils"Jenkins2014-01-311-5/+1
|\
| * Using common method 'bool_from_string' from oslo strutilsllg82122014-01-241-5/+1
| | | | | | | | | | | | | | | | | | Using common method 'bool_from_string' from oslo strutils to replace utils.string_to_bool. partially implements blueprint common-client-library-2 Change-Id: I23924db3000feadcfe823c6cc979ea9752a13fa9
* | Handle endpoints with versions consistentlyStuart McLaren2014-01-221-0/+13
|/ | | | | | | | | | | | | | | | | When using the cli the Glance client wraps the endpoint in a 'strip version' function. This means that endpoints of the following forms can both be used: https://region-x.images.example.com:443/v1 https://region-x.images.example.com:443 When calling the client library directly (as Ceilometer does) however only endpoints of the second form work. The cli and library should handle the two cases consistently. Addresses bug 1243276. Change-Id: Ice7b581fee32540a7057ba47433a10166a3caed2
* Python 3: use six.iteritems and six.string_typesYassine Lamgarchal2014-01-131-2/+4
| | | | | | | | | | six.iteritems() replaces dictionary.iteritems() on Python 2 and dictionary.items() on Python 3. six.string_types replaces basestring() in Python 2 and str in Python 3. Change-Id: Ia18510d167df35caec83626718010228e2140bc0
* Get better format for long lines with PrettyTableFei Long Wang2014-01-061-1/+2
| | | | | | | | | | | | | Based on current implement, the cli output format will be bad if the lines are too long. This issue can be fixed by setting 'max_width'. However, there is a bug against it, see https://code.google.com/p/prettytable/source/browse/trunk/CHANGELOG?r=85 line 3. So the requirements.txt is updated as well. docImpact Fixes bug 1251283 Change-Id: I0d4192ad9d10a3d6d47a8319463a5edb57719a68
* Merge "Replace OpenStack LLC with OpenStack Foundation"Jenkins2013-11-151-1/+1
|\
| * Replace OpenStack LLC with OpenStack FoundationZhiQiang Fan2013-09-201-1/+1
| | | | | | | | | | Change-Id: I38dcbcf1a6c8efe540fcf5f29e782cb3826e583d Fixes-Bug: #1214176
* | Merge "Fix python 3.x related Hacking warnings"Jenkins2013-11-121-3/+5
|\ \
| * | Fix python 3.x related Hacking warningsDirk Mueller2013-08-261-3/+5
| |/ | | | | | | | | | | | | | | Convert print operator usages to print functions. Fix one instance of outdated "except x,y:" syntactical construct. Remove usages of local() in string formatting alongway. Change-Id: Id0673a9183a6ea6bd9bf3f5c6d8e7c5f114ebf01
* | Add CLI for V2 image create, update, and uploadeddie-sheffield2013-10-021-0/+86
|/ | | | | | | | | | | | | | | Provides command line support for image-create, image-update, and image-upload using the Glance V2 API. This includes building help text for create and update based on the image jsonschema as fetched from the server. Also fixes bug caused by default warlock patch generation not matching what Glance expects when updating a core property which had not originally been set when the image was created. Related to bp glance-client-v2 Change-Id: I841f9e3d05802f4b794cb6f4849abe03ff0324d9
* Updated from global requirementsMonty Taylor2013-08-101-1/+1
| | | | Change-Id: I2e2bd3a38458e1307bcc0410da74dc76c0a5987a
* Show a pretty progressbar when uploading and downloading an image.mouad benchchaoui2013-08-081-18/+28
| | | | | | | | | | | | Add a new module that contain generic wrapper for file and iterator, which are used to wrap image to upload and the request body iterator in upload and download cases repectively, to show and advance a pretty progress bar when this laters are consumed, The progress bar is triggered by adding a --progress command line argument to commands: image-create, image-download or image-update. Change-Id: I2ba42fd0c58f4fa087adb568ec3f08246cae3759 bug fix: LP#1112309 blueprint: progressbar-when-uploading
* Encode error messages before sending them to stdoutFlaper Fesp2013-07-291-0/+12
| | | | | | | | | | When an error with non-ascii characters is caught by glanceclient, it fails at printing it and exists with a UnicodeEncodedError. This patch encodes errors' messages using strutils before sending them to stdout. Fixes bug: #1200206 Change-Id: I4dabcd76ffb258840bd6a66ad23c030f34960e86
* Replace utils.ensure_(str|unicode) with strutils.safe(decode|encode)Flaper Fesp2013-06-041-77/+5
| | | | | | | | | | | | | | | | Glanceclient implemented both functions before they landed into oslo. Since both functions are already in oslo, it is now possible to pull them in. There's a small difference between glance's implementation and oslo's, that is the later does not convert non-str objects - int, bool - to str before trying to decode / encode them. This patch takes care of that where necessary, more precisely, while encoding headers before doing a new request. Fixes bug: #1172253 Change-Id: I9a0dca31140bae28d8ec6aede515c5bb852b701b
* Prevent WantReadError when using httpsStuart McLaren2013-04-231-0/+11
| | | | | | | | | | | | | | | | If the glance client is instantiated when the socket module has been monkey patched requests to the server can yield a WantReadError because the socket has been set to non-blocking but this is not being handled correctly. When this is the case use eventlet's GreenConnection which handles non-blocking sockets correctly. Also, for now, add a required getsockopt method to GreenConnection. This can be removed once the eventlet fix (https://bitbucket.org/eventlet/eventlet/commits/609f230) lands. Fixes bug 1157864. Change-Id: I187b69f75b8bcfe16facd41e69b1cd0490dae605
* Decode input and encode outputFlaper Fesp2013-02-131-4/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | Currently glanceclient doesn't support non-ASCII characters for images names and properties (names and values as well). This patch introduces 2 functions (utils.py) that will help encoding and decoding strings in a more "secure" way. About the ensure_(str|unicode) functions: They both try to use first the encoding used in stdin (or python's default encoding if that's None) and fallback to utf-8 if those encodings fail to decode a given text. About the changes in glanceclient: The major change is that all inputs will be decoded and will kept as such inside the client's functions and will then be encoded before being printed / sent out the client. There are other small changes, all related to encoding to str, around in order to avoid fails during some conversions. i.e: quoting url encoded parameters. Fixes bug: 1061150 Change-Id: I5c3ea93a716edfe284d19f6291d4e36028f91eb2
* Add image names to glance command arguments.Ken'ichi Ohmichi2013-01-051-3/+10
| | | | | | | | | | | | | | | | | | | | Now a user should specify ID as an image by glance command, and I feel it is easy-use that a user can specify name also as an image like nova command(ex. "nova boot"). By applying this patch, a user can specify name as image like the following examples: $ glance image-show cirros-0.3.0-x86_64-uec $ glance image-update --name root-fs cirros-0.3.0-x86_64-uec $ glance image-delete cirros-0.3.0-x86_64-uec $ glance image-download cirros-0.3.0-x86_64-uec $ glance member-create cirros-0.3.0-x86_64-uec 94b0e63a27ca43348fe056622fe3fe94 $ glance member-delete cirros-0.3.0-x86_64-uec 94b0e63a27ca43348fe056622fe3fe94 Fixes bug 1093380 Change-Id: Ia0a070eed6ae3853ef02032f479087edb1d75a67
* Add --sort-key and --sort-dir to image-listBrian Waldon2012-11-281-1/+1
| | | | | | | | | | | The --sort-key and --sort-dir CLI options allow users to control the field and direction by which their images are sorted in an image-list operation. The previous default sort behavior of sorting by ID asc has been preserved. Fixes bug 1082957. Change-Id: I1d3664219c275b0379fe176f8288d6ffae0dffbe
* Simplify human-readable size outputBrian Waldon2012-11-191-2/+5
| | | | | | | | * Limit human-readable sizes to a single decimal * Drop trailing zero * Step one suffix further in the case of a size being 1024 Change-Id: I2eb8ac0571d3d08b52f62155912863870573a37c
* Make image sizes more readable for humansChristian Berendt2012-11-191-0/+12
| | | | | | | | | By introducing the parameter --human-readable for several functions (image-list, image-show, image-update, image-create) it's possible to convert the size in bytes to something more readable like 9.309MB or 1.375GB. Change-Id: I4e2654994361dcf330ed6d681dbed73388f159cb
* Enable client V2 to download imagesLars Gellrich2012-08-091-0/+38
| | | | | | | | | | Added the CLI option image-download to download an image via API V2. Added utility function to save an image. Added common iterator to validate the checksum. Related to bp glance-client-v2 Change-Id: I0247f5a3462142dc5e9f3dc16cbe00c8e3d42f42
* Align print_dict to the leftBrian Waldon2012-07-131-1/+1
| | | | Change-Id: Ib98e912a7af0bb570b4fd738733edd9b837d1a10
* Rewrite link parsing for finding v2 schemasBrian Waldon2012-07-131-1/+8
| | | | | | | | | | | | | | | | What we called 'links' are no longer returned in a container of objects, they are top-level entity attribtues. This fixes the parsing of the entities to look in the correct place when trying to locate a specific schema. Add a helper for printing to stderr and exiting with a non-zero exit code. Map 'name' to 'Attribute' when explaining a schema. Related to bp glance-client-v2 Change-Id: Ib98e912a7af0bb570b4fd738733edd9b837d1a05
* Establish the supported importable interfaceBrian Waldon2012-07-131-5/+5
| | | | | | | | | | | | | * Consumers of this client should not depend on being able to import any module other than glanceclient and glanceclient * The only attributs of the glanceclient module are Client and __version__ * The attributes of the glanceclient.exc modules have yet to be locked down * glanceclient.common.exceptions was replaced with a placeholder module until consumers of it are updated Change-Id: Iea9648cd06906d65764987c1f2ee5a88ebeee748
* Stick prettytable at v0.6Brian Waldon2012-06-071-1/+1
| | | | | | Doing this so we can align columns reliably Change-Id: Ibdbc6f3df08d6f9c45b6e0a0f5a2440ba2637dbd
* Add minimal support for the v2 APIBrian Waldon2012-06-041-0/+8
| | | | | | | | | This only allows you to run image-list, but sets up a framework that we can use to fill in the rest of the v2 functionality. * Related to bp glance-client-v2 Change-Id: I8827e36fdcf79fe402990a6d05898ec00cbd54c6
* Remove printtDean Troyer2012-05-071-2/+2
| | | | | | | | prettyprint 0.6 removed printt at the last minute, replace with get_string Fixes bug 995826 Change-Id: I9a25efc3d723ab0208ea88fc6431a95cc9176acb