summaryrefslogtreecommitdiff
path: root/glanceclient/common/utils.py
Commit message (Collapse)AuthorAgeFilesLines
* Merge "Remove unicode-related Python2-only code"Zuul2023-01-121-23/+0
|\
| * Remove unicode-related Python2-only codeCyril Roelandt2022-11-141-23/+0
| | | | | | | | | | | | | | | | This commit: - removes the old "u" prefix from all strings - removes the unicode_key_value_to_string function Change-Id: I1da347e31e828fd2359f0935a4da47257116d4cb
* | Merge "Boolean options: use strict checking"Zuul2023-01-121-1/+1
|\ \
| * | Boolean options: use strict checkingCyril Roelandt2022-11-141-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Boolean options (such as "--protected" for glance md-namespace-update) should accept a limited amount of valid values, rather than assuming an "invalid" value means "False". The following values (no matter the case) will now be interpreted as True: ‘t’,’true’, ‘on’, ‘y’, ‘yes’, or ‘1’. The following values (no matter the case) will now be interpreted as False: ‘f’, ‘false’, ‘off’, ‘n’, ‘no’, or ‘0’. Change-Id: I0e7942045d883ac398bab4a7a85f2b4ac9b1ed8c Closes-Bug: #1607317
* | schema_args: Do not generate option for read-only propertiesCyril Roelandt2022-09-261-0/+2
|/ | | | | | | | | | The schema_args decorator generates command line options based on the properties defined in a schema. This commit makes sure read-only properties are skipped during this process, since trying to modify their value would result in a Glance error. Closes-Bug: #1561828 Change-Id: I7ccc628a23c9ebdaeedcb9e6d43559f497ce9555
* Check if stdin has isatty attributeBenedikt Loeffler2022-07-071-1/+1
| | | | | | | When the stdin is closed, it has no isatty atrribute which leads to a KeyError. Closes-Bug: #1980890 Change-Id: If9a3bf68b8dfd953b346697241166578d18bb563
* Add support for Cache APIErno Kuvaja2022-02-221-1/+43
| | | | | | | This change provides support for the Cache API changes and deprecation path for glance-cache-manage command. Change-Id: I6fca9bbe6bc0bd9b14d8dba685405838131160af
* Get tasks associated with imageAbhishek Kekane2021-03-021-0/+28
| | | | | | | Add support to get tasks associated with specific image. bp: messages-api Change-Id: Ia505cf6f47ca6c628e195be3ca5231d22d53040d
* Merge "Do not use the six library."Zuul2020-07-171-12/+9
|\
| * Do not use the six library.Cyril Roelandt2020-06-231-12/+9
| | | | | | | | Change-Id: I3dbfcfa0f5f590a41ed549afd44537d8ed41433a
* | Stop to use the __future__ module.Hervé Beraud2020-06-021-2/+0
|/ | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Fail gracefully when MD5 is unavailableBrian Rosmaita2020-05-041-1/+8
| | | | | | | | | The glanceclient currently assumes that MD5 will always be available. This is not the case, however, in a FIPS-compliant environment. This patch enables the glanceclient to fail gracefully in such a case. Closes-bug: #1871675 Change-Id: Ibd89989e06cc5be7da71f5f21561d73b5abc4104
* Update hacking versionjacky062019-03-271-4/+4
| | | | | | Use latest release 1.1.0 and compatible changes w.r.t pep8 Change-Id: Ifc3b96d98c1a7feff187f953d487e12135887fb9
* Use "multihash" for data download validationBrian Rosmaita2018-09-071-0/+20
| | | | | | | | | | | | When the Glance "multihash" is available on an image, the glanceclient should use it instead of MD5 to validate data downloads. For cases in which the multihash specifies an algorithm not available to the client, an option is added to the image-download command that will allow fallback to the legacy MD5 checksum verification. Change-Id: I4ee6e5071eca08d3bbedceda2acc170e7ed21a6b Closes-bug: #1788323
* Image show: print human readable string when the virtual size is unknownCyril Roelandt2018-05-311-0/+2
| | | | | | | | | Currently, when the virtual size of an image is not known, "None" is displayed. To a regular user, it feels like a programming error. We try and make things clearer by using a "human readable" string instead. Change-Id: Id7b8799356857d9bc58cc8a3677024fe1a7f4f56 Partial-Bug: #1665037
* Merge "Removes unicode 'u' response from "glance image-tag-update""Zuul2018-05-181-0/+31
|\
| * Removes unicode 'u' response from "glance image-tag-update"Abijitha Nadagouda2018-02-021-0/+31
| | | | | | | | | | | | | | | | | | | | | | "glance image-tag-update" command returns unicoded response for lists. Therefore it requires print_list method from util class to handle such case. Added unicode_key_value_to_string() method to remove extra 'u' from lists and dictionaries. This fix is inspired from cinderclient's implementation. Change-Id: I16a04e8d34f7629f72fe389456001ca1db9335ea Closes-bug: #1534046
* | Fix python 3.6 escape char warningEric Harney2017-07-311-1/+1
|/ | | | | | | | | In python 3.6, escape sequences that are not recognized in string literals issue DeprecationWarnings. Convert these to raw strings. Change-Id: I508a9147b932e219069eeee756bcbc43c7e961c5
* turn on warning-is-error in sphinx buildDoug Hellmann2017-06-281-1/+1
| | | | | | | | Fix a formatting error in one docstring and turn on the flag to ensure that future warnings in the doc build trigger a build failure. Change-Id: I7159b985d1690a8ae61ff885408da4623c105952 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
* Merge "Replace six.iteritems() with .items()"Jenkins2017-06-281-4/+4
|\
| * Replace six.iteritems() with .items()ji-xuepeng2017-02-081-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | 1.As mentioned in [1], we should avoid usingg six.iteritems to achieve iterators. We can use dict.items instead, as it will return iterators in PY3 as well. And dict.items/keys will more readable. 2.In py2, the performance about list should be negligible, see the link [2]. [1] https://wiki.openstack.org/wiki/Python3 [2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html Change-Id: I71c13040318eca6e5ed993e8aa03f8003986a71c
* | Downloading image with --progress failsAbhishek Kekane2017-05-291-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Downloading image with --progress fails with "RequestIdProxy object is not an iterator". This is because to display download progress VerboseFileWrapper in progressbar requires object of IterableWithLength, but after support of returning request-id [1] to caller it returns RequestIdProxy object which is wrapped around IterableWithLength and response. To resolve this issue overridden next and __next__ methods in RequestIdProxy so that it can act as iterator for python 2.x and 3.x as well. [1] 610177a779b95f931356c1e90b05a5bffd2616b3 Closes-Bug: #1670464 Change-Id: I188e67c2487b7e4178ea246f02154bbcbc35a2b1
* | Downloading image with --progress fails for python3Abhishek Kekane2017-05-181-0/+3
|/ | | | | | | | | | | | Downloading image with --progress fails for python3 with, TypeError: 'IterableWithLength' object is not an iterator. This is because IterableWithLength class does not implemented python3 compatible __next__ method. Added __next__ method for python3 compatibility. Change-Id: Ic2114180fac26e9a60678f06612be733e8671bdb Closes-Bug: #1671365
* Add request id to returned objectsRavi Jethani2017-01-201-0/+74
| | | | | | | | | | | | | | | | | | | | | | | Adding two classes RequestIdProxy and GeneratorProxy derived from wrapt.ObjectProxy to wrap objects returned from the API. GeneratorProxy class is used to wrap generator objects returned by cases like images.list() etc. whereas RequestIdProxy class is used to wrap non-generator object cases like images.create() etc. In all cases the returned object will have the same behavior as the wrapped(original) object. However now the returned objects will have an extra property 'request_ids' which is a list of exactly one request id. For generator cases the request_ids property will be an empty list until the underlying generator is invoked at-least once. Co-Authored-By: Abhishek Kekane <abhishek.kekane@nttdata.com> Closes-Bug: #1525259 Blueprint: return-request-id-to-caller Change-Id: If8c0e0843270ff718a37ca2697afeb8da22aa3b1
* Use import_versioned_module from oslo.utilsLi Wei2016-12-061-8/+0
| | | | | | | oslo.utils 3.17 provides this funtion, so just use it directly. Change-Id: I85cb78a6fd33a5b1f7e09648efed1b0737678eee Closes-Bug: #1627313
* py3: Fix encoding and use sys.stdin.bufferSirushti Murugesan2016-07-251-2/+5
| | | | | | | | | * exc.py: Encode body in response before calling replace over it. * http.py: prepend the bytes literal to the empty string or else we hit bug 1342080 again in python 3. * utils.py: Use sys.stdin.buffer in python 3. Change-Id: Ieefb8c633658e507486438e5518c5d53e819027d
* Add comment about workaround for py3Louis Taylor2016-07-131-0/+2
| | | | Change-Id: Ibe8720c14e8ec401bc0d595915cbb962f4021bcb
* image-download: tests to catch stray outputStuart McLaren2016-06-291-4/+2
| | | | | | | | | | Add unit tests to ensure that any stray output (eg print statements) during image-download cause a test failure. Regression test for bug 1488914. Change-Id: Ic19ba5693d059bf7c283702e7c333672a878a1a1 Partial-bug: 1488914
* Remove unused skip_authentication decoratorkairat_kushaev2016-06-021-15/+0
| | | | | | | | 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
* Merge "Re-enable stacktracing when --debug is used"Jenkins2016-04-181-0/+8
|\
| * Re-enable stacktracing when --debug is usedStuart McLaren2016-04-071-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Fix typos in docstrings and commentsDao Cong Tien2016-04-111-3/+3
|/ | | | | | Update a comment to be more meaningful Change-Id: Ie1aa46917c1a253db92a0dc819803a1d3e795b07
* Merge "Handle 403 forbidden on download"Jenkins2016-02-291-1/+1
|\
| * Handle 403 forbidden on downloadStuart McLaren2016-02-241-1/+1
| | | | | | | | | | | | | | | | | | | | A download of a deactivated image may result in a 403. The cli should catch this error rather than stack trace. We also catch other unexpected http responses. Change-Id: If33fbc3a56cdb02b3ab32a6479a67fff20b4b1a9 Closes-bug: 1523612
* | Fix image-download to stdout on Python 3.xAndy Botting2015-12-221-1/+4
|/ | | | | | | | | | | Glance image-download to stdout fails on Python3 due to sys.stdout.write not allowing bytes to be written directly. A good description of the issue is listed at http://bugs.python.org/issue18512 Closes-Bug: #1528083 Change-Id: I2963914e2e0744410267b5735ff77939413916d4
* Ensure that identity token in header is not an unicode stringVincent Untz2015-11-171-2/+1
| | | | | | | | | | | | | We need all the headers to be safe strings so they can be joined together and not become an unicode string in doing so. This fixes a bug when creating an image with non-ascii characters in the name. This is required for python 2.6 compatibility. Change-Id: I66ebc27edf4ccd8f903399da58705711c372536d Closes-Bug: 1448080
* Fix the missing help descripiton of "image-create"wangxiyuan2015-10-271-0/+2
| | | | | | | | Now, when use "glance help" to show the help message, the description of 'image-create' is missing. Change-Id: I748209222c540e0024580dccac850ea465d176b4 Closes-bug: #1510340
* Import i18n functions directlykairat_kushaev2015-10-161-2/+1
| | | | | | | | | | 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
* Support image deletion in batches in v2wangxiyuan2015-10-101-0/+4
| | | | | | | | Client doesn't support image deletion in batches in v2 now. It's useful. So it's need to add it. Change-Id: Idf5a6890b3fd01a65fecab2033b21367c30bc6b1 Closes-bug:#1485407
* Merge "Replace exception_to_str with oslo.utils function"Jenkins2015-09-301-12/+0
|\
| * Replace exception_to_str with oslo.utils functionkairat_kushaev2015-09-221-12/+0
| | | | | | | | | | | | | | | | | | 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
* | Merge "Fix human readable when size is None"Jenkins2015-09-281-1/+3
|\ \ | |/ |/|
| * Fix human readable when size is NoneStuart McLaren2015-09-141-1/+3
| | | | | | | | | | | | | | If an image size is null don't stack trace when listing. Change-Id: Iba18470edbe032d1d01380372d57fa17adef5f7e Closes-bug: 1495632
* | Merge "Add parsing the endpoint URL"Jenkins2015-09-161-4/+7
|\ \ | |/ |/|
| * Add parsing the endpoint URLTakashi NATSUME2015-09-081-4/+7
| | | | | | | | | | | | | | | | Add parsing the endpoint URL and check the path string only in order to decide the API version. Change-Id: Ib0a035f3bed31e2162a1231a5f5dcc3907d37243 Closes-Bug: #1489727
* | check for None value in utils.safe_headerDavid Edery2015-09-081-1/+1
|/ | | | | | | | | In case that a sensetive header (that should be obscured by its SHA1 hash) is None, the safe_header throws an exception which fails the calling process and by that may harm the functionality. Change-Id: I56944a382fd546eba0a6dd6d6b1cecf83b1dc106 Closes-Bug: #1491311
* Remove custom SSL compression handlingStuart McLaren2015-08-261-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Require disk and container format on image-createGorka Eguileor2015-08-141-0/+45
| | | | | | | | | | | | | | | Currently glanceclient doesn't enforce disk-format or container-format presence in the command line on image-create when providing image data (with --file, --location, --copy-from), which means that the POST request is made with the whole image and error is reported by Glance API. This post enforces presence of those arguments when image data is provided so we can get the error quicker and avoid sending unnecessary data over the network. Change-Id: I5914fa9cfef190a028b374005adbf3a804b1b677 Closes-Bug: #1309272
* Add unicode support for properties values in v2 shellDarja Shakhray2015-08-031-1/+1
| | | | | | This code allows to set unicode values to v2 properties. Change-Id: I5f9c29a3e458808dd95375c7557dfce0c4f09038 Closes-bug: #1475769
* Enable flake8 checksDarja Shakhray2015-07-211-7/+5
| | | | | | | | | | | | 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