Commit Graph

133 Commits

Author SHA1 Message Date
Stephen Finucane c408db2dd9 Update pre-commit hook, hacking versions
This was done with 'pre-commit autoupdate'. An invalid message is
removed from the requirements.txt files as it no longer applies with
pip's new dependency resolver.

Change-Id: I01c3ece51f81d67c740e6faca6b77df7c9932435
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2022-04-08 17:49:08 +09:00
Stephen Finucane c4c44bcb2d Remove six
Mostly a find-replace job. Let's do this now so we don't have to carry
it for the next decade.

Change-Id: I7bef9fb7c6895f746cee1aca6522786f38b9857c
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2020-02-21 09:48:38 +00:00
Zuul 9b184080fc Merge "Use uuidutils of oslo.utils" 2018-08-08 18:00:11 +00:00
Takashi NATSUME 46ad782fb0 Use uuidutils of oslo.utils
Replace standard uuid library with uuidutils of oslo.utils.

TrivialFix
Change-Id: Ibb6ec8b56a404685d9727f1b771dbff178fdecdf
2018-08-08 15:12:28 +09:00
Takashi NATSUME 33e89f99a4 Fix server strings in reboot operation
The following message is shown currently in the reboot operation.

  Request to reboot server <Server: server1> has been accepted.

The server name string is a bit odd. So fix it as follows.

  Request to reboot server server1
  (ff79e91e-e2a7-4e0f-b4c3-7157676d43c9) has been accepted.

Change-Id: I62df4589dc950f69fdc23eafcbb5792e897cb635
Closes-Bug: #1785495
2018-08-07 15:30:48 +09:00
Takashi NATSUME 1f75c7662d Use jsonutils of oslo.serialization
Both standard json library and jsonutils of oslo.serialization are used.
Replace standard json library with jsonutils for consistency.

Change-Id: Id6cbb4d78817ff4993b73538935cc4cc61b64a72
2018-07-31 13:19:01 +09:00
Andrey Kurilin ca27736810 Remove 2 redundant methods
I suppose that methods get_resource_manager_extra_kwargs and
add_resource_manager_extra_kwargs_hook were designed in those days when
Nova API had extensions.
Nowdays, Nova API has strict schema validation of requests, so no
additional arguments are allowed and these methods look redundant.

The fact that get_resource_manager_extra_kwargs lists of the objects
added by add_resource_manager_extra_kwargs_hook whereas
add_resource_manager_extra_kwargs_hook is not called anywhere
doesn't add chances for leaving these methods in our code.

Compatibility: both methods are designed for CLI and the CLI behaviour
  will not change after removing them, so we can do a cleanup without
  following standard deprecation cycle.

Change-Id: Id61457c3db8a17e2294dc579b2519873927fec48
2018-02-09 15:26:08 +00:00
Yikun Jiang 50460bddfc Use utils.prepare_query_string instead of duplicated code
There are some duplicated code in nova client for generating
query string.

The 'prepare_query_string' method can convert dict params to
query string(it transforms the dict to a sequence of two-element
tuples in fixed order, then the encoded string will be consistent
in Python 2&3.)

This patch use utils.prepare_query_string instead of these and
plus some notes in the 'prepare_query_string' method.

Change-Id: Idb3c5e97f8bbcd5ec5446f776c10fa8c84b54d5d
Closes-Bug: 1727968
2017-11-22 13:35:27 +00:00
Stephen Finucane 437b08cf38 Remove custom autodoc implementation
pbr provides this functionality for us. Make use of it.

Change-Id: Ide7b2992ac931395b776d39ed4a1a50bded0a881
2017-07-12 15:13:04 +01:00
Kevin_Zheng 0797115241 Tags and Metadata fields with unicode cannot be correctly displayed
Currently, Tags(list) and Metadata(dict) fields of instance will
firstly transformed to str using jsondump first when display. And
cannot be correctly transfomed and displayed afterwards.

This patch adds ensure_ascii=False to the transform function thus
those fields can be correctly tranformed and displayed afterwards.

Change-Id: Ib4e7a34f3b19db89280cc73053acbac8c8816f85
Closes-Bug: #1669683
2017-03-05 17:37:29 +08:00
gengchc2 56bb3dae5f Replace six.iteritems() with .items()
1.As mentioned in [1], we should avoid using
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: I6289f46344876d19d9a6793875f896cedc85a01c
2016-12-09 11:04:16 +08:00
Takashi NATSUME 89a1f7c077 Remove unused code
The 'load_entry_point' method has not been used
since Ia649db257c416ca054977812ecb3f1a8044fa584.

TrivialFix
Change-Id: If477b0bb753c1a8bed2ebb440ac43f55805a0744
2016-11-22 17:51:58 +09:00
bhagyashris d8c07006dd Fix 'UnicodeEncodeError' for unicode values
Used '%' instead of format() because "%" formatting operation
returns a unicode string for both unicode and non-unicode
format strings.

Encoded the exception error message in novaclient.shell.main and
novaclient.utils.do_action_on_many method to avoid
"UnicodeEncodeError" and print valid message.

NOTE:
Not used u'{0}.format(<str>) because in python 3 everything
is unicode so no need to add explicit 'u' to format string.

Closes-Bug: #1403379
Change-Id: I13f1ef2e1b41299b417cad3759a5cda241890df7
2016-08-30 15:30:16 +05:30
Hironori Shiina fae24eee4a Modify flatten method to display an empty dict
When a dict is flattened, if a value of an item is empty,
e.g. {"cpu_info": {}}, the item is not displayed.

This patch fixes _flatten method to display such an item including an
empty dict.

Change-Id: I2e4ada0de217c5c4ddea10f3f283c6d8e78083b6
Related-Bug: #1594230
2016-08-05 02:15:14 +09:00
Andrey Volkov 6bbcedb000 Add support for microversion 2.33
This change allows novaclient to get several hypervisors
with the help of new optional parameters 'limit' and 'marker'
which were added to hipervisor-list command.

Change-Id: Ib723fb1dc1cd57b6f796bb93e0dd8ddf2da4b2a0
2016-08-03 18:37:55 +03:00
Andrey Kurilin f9bdba2dd7 Extend microversion stuff to support resource classes
Current implementation of novaclient.api_versions.wraps allow to use
versioned methods for shell functions and resource managers. As resource
managers can have versioned methods, resource objects can have it too, but
it was not implemented yet. This patch fixes this omission.

Changes:
 - Add api_version property to base resource class. It is mapped to
   api_version property of manager class;
 - Move `novaclient.utils.generate_function_name` to
   `novaclient.api_versions._generate_function_name`, since this method is
   specific to microversion stuff and should not used outside api_versions
   module;
 - Rewrite _generate_function_name to handle class(owner) name. Previously,
   it was improssible to have two classes in one module with versioned
   methods with equal names.
 - Remove call of generate_function_name from novaclient.shell. Shell module
   should not take care about function identifiers. get_substitutions accepts
   object with __id__ property now.
 - Mark _add_substitution as private method, since it should not be used
   outside api_versions module
 - Split all versioned methods of Server resource from novaclient.v2.servers
   module.

Change-Id: Icfce16bfa6f919d7f8451d592f4a8e276b1f1709
2016-06-16 05:57:59 +00:00
ZhiQiang Fan c22cbb6fac [Trivial] change some functions in novaclient/utils.py to public
There are some functions in novaclient/utils.py which have name with
prefix `_`, in Python, this means it is a private function which
should be only used in its own module. However, these functions are
used in other modules such as novaclient/v2/shell.py.

This patch removes the prefix _ for these functions.

Change-Id: I7bc8a76fd390a7dd30eecbb5c7e641b6ccfb40c0
2016-04-27 20:13:45 +08:00
Andrey Kurilin cd88097ff5 [microversions] Enable 2.21
2.21 - The os-instance-actions API now returns information from deleted
       instances.

Change-Id: Iff514e4fa9135207c6f8e32e444d45b1b61d8c7c
2016-02-24 20:57:34 +02:00
Andrey Kurilin 01961d68a2 Cleanup needless code from oslo-incubator
oslo-incubator was deprecated and all modules used by novaclient were
removed from oslo-incubator master branch. This patch removes all unused
code from novaclient's repo.

Change-Id: Ie3c542d19da6ed4d25ec490faf6a86a82f48cd34
2015-12-18 08:46:12 +00:00
Jenkins ebdcf077eb Merge "Change the logic for the client to retrive resources" 2015-12-16 15:34:17 +00:00
Zhihai 11e0782f62 Change the logic for the client to retrive resources
The ID (primary key) of a resource can not be retrived by the client.
There is no sense to provide the functionality to get an resource by
its ID. Especially when an instance is named by an interger, client
will try to get the instance with the ID of that interger value.
This patch will change the order in which the novaclient retrive
resources. First by UUID, then by name, finally by the ID. This will
also reduce api call overhead, since UUID is used mostly.

Change-Id: I0bfa5cb03a04625c3def5608dd4529e52d50f944
Closes-Bug: #1516924
2015-12-09 12:47:05 +00:00
jichenjc 8b8edc72e0 Not transform to str on potential unicode fields
some fields such as instance.display_name can be unicode,
nova client should not translate it to 'str'. otherwise
it will report UnicodeEncodeError.

Change-Id: I4f6011105b3b11dbbcb23f3a7c1bbcf7f20bcc8c
Closes-Bug: 1518141
2015-11-22 04:34:07 +08:00
Matt Riedemann 63c7a576e1 Revert "Do not expose exceptions from requests library"
This reverts commit 2961e82bfa

This broke cinder unit tests that have a timeout test for novaclient
where they mock the requests library raising a Timeout exception. That
test expects to get a requests Timeout passed through but with the
change being reverted it was getting a RequestTimeout exception from
novaclient, which breaks the test and fails the gate runs.

We could change the cinder unit test to handle both the requests.Timeout
and the new novaclient RequestTimeout, but that's just papering over
the cinder failure, we wouldn't know what other clients are failing
in the same way because they have code working around the requests
exceptions getting passed through, so we should treat this like an API
change.

I'd be in favor of making the same change again iff the novaclient
exceptions extended the requests exception types so it would be transparent
to consumers, since novaclient.exceptions.RequestTimeout would be a
requests.Timeout via inheritance. But given the gate breakage and it being
summit week I'm inclined to revert first and think about a better long term
fix later when people are back to discuss.

Change-Id: I368728588e5997eef860a168539eb66c58f2e72a
Closes-Bug: #1510790
2015-10-28 07:27:40 -07:00
Jason Dunsmore 2961e82bfa Do not expose exceptions from requests library
Novaclient expects the requests library to always be able to get a
response back and doesn't handle other cases where it might raise
an exception even before the request is completed (e.g.
ConnectionError).

These exceptions should be captured and properly converted to some
native novaclient exception.

Change-Id: Iec7247b715c38c29910b30e76413cead4e951a37
Co-Authored-By: Kuo-tung Kao <jelly.k@inwinstack.com>
Closes-Bug: #1406586
2015-10-22 14:34:23 -05:00
Jenkins 40a4070f28 Merge "Implements 'microversions' api type - Part 2" 2015-07-27 23:13:36 +00:00
Jenkins 9d8633d9f1 Merge "Fixes table when there are multiline in result data" 2015-07-27 16:37:00 +00:00
Andrey Kurilin 936cf572df Implements 'microversions' api type - Part 2
New decorator "novaclient.api_versions.wraps" replaces original method with
substitution. This substitution searches for methods which desire specified
api version.

Also, this patch updates novaclient shell to discover versioned methods and
arguments.

Related to bp api-microversion-support
Co-Authored-By: Alex Xu <hejie.xu@intel.com>
Change-Id: I1939c19664e58e2def684380d64c465dc1cfc132
2015-07-25 15:57:17 +08:00
liyingjun 1d39033c8e Fixes table when there are multiline in result data
The table doesn't display right when there are multiple line in
result data. Fixes this by replace "\r" with "".

Change-Id: Ia3ca4146f17c3ae097a2aad0092c25f6807fcbab
Closes-bug: #1476462
2015-07-24 14:56:29 +08:00
Chung Chih, Hung c3a0c035dc hypervisor command can't use cell format id to show hypervisor
This bug was occurred in cell mode.

In cell mode, compute node's id was not identified by integer type. It
was formatted with "path!to!cell@ID".
Therefore we can't using the id of hypervisor-list output.

For example,
> nova hypervisor-list
+----------------+--------------------------+-------+---------+
| ID | Hypervisor hostname | State | Status |
+----------------+--------------------------+-------+---------+
| region!child@1 | vagrant-ubuntu-trusty-64 | up | enabled |
+----------------+--------------------------+-------+---------+

Change-Id: Iba0cc1993f67351b11d034f372d7a5b98dc017f0
Closes-Bug: 1475973
2015-07-20 04:55:32 +00:00
Doug Hellmann e649cea843 Do not check requirements when loading entry points
Update the calls to pkg_resources to avoid forcing a requirements check
when the plugins are being loaded.

There are 2 versions of the entry point API in different releases of
setuptools. In one version, the require keyword argument can be passed
to load(). In the other, separate methods resolve() and require() need
to be used. This change updates the mock and fake objects to support
either, since the fakes are subclasses of the EntryPoint class in
pkg_resources.

It would be better to replace the calls to pkg_resources with stevedore,
which provides a more stable API, abstracts away this difference, and
provides an API for creating test managers directly. That change would
have required more extensive updates to the test suite, though, and
since I'm not as familiar with this code base as others will be, I will
leave those changes for someone else.

Change-Id: I2a9aeb53ccad04c7fa687f25340306b84218f9ff
Partial-bug: #1457100
2015-05-27 18:08:02 +00:00
Andrey Kurilin ccff3d3c94 Remove all imports from oslo namespace
oslo namespace is deprecated

Change-Id: I345eb210222d8e973b99f27821099f52883ab27d
2015-04-20 13:52:38 +03:00
ZhiQiang Fan 1c39f8fabf Don't record time when self.timing is False
The expected behavior is when timing is True, then we record each
request's time, then we should call reset_timings() to release memory.

However, the shell, client.{HTTPClient,SessionClient} will record each
request's time no matter what timing is set, then after long running
time in service like ceilometer-agent-compute, the memory keeps increasing.

We'd better not record request's time when timing is set to False.
Users are not responiable to call reset_timings() when they don't want
timing functionality.

Change-Id: I3e7d2fadf9a21be018781d528a1b6562228da6dd
Closes-Bug: #1433491
2015-03-21 19:27:36 +08:00
Tomofumi Hayashi 0fd8816aa5 Change logic in find_resource() to identify upper-case/lower-case name.
Currently find_resource() searches resource with human_id before does
with name_attr.  With this logic, find_resource() cannot identify
upper/lower case. In find_resource(), human_id always matches and
name_attr never used in find_resource() because human_id made from
small letters of name_attr string (see bug/1318503).

To identify upper/lower case, name_attr should be used before human_id.
This fix moves name_attr to ahead of human_id with unit-test cases.

Change-Id: I9b821d7111c11a97be38f19de06172daf410022d
Closes-Bug: #1318503
2015-02-05 02:48:24 +00:00
Andrey Kurilin 96a124fae6 Remove aliases for `args` and `env` in utils
To remove aliases for `arg` and `env` functions in novaclient.utils,
we should use `arg` and `env` directly from cliutils in novaclients modules.

This patch removes aliases in `novaclient.utils` and starts using
`args` and `env` from novaclient.openstack.common.cliutils directly.

Change-Id: I4585adae62bc66ad6bc9d19be10d4679bb3dc5a1
2014-12-04 17:22:12 +02:00
Jenkins 525a510b5a Merge "Define helper to run an action on many resources" 2014-11-13 01:10:51 +00:00
Andrey Kurilin 8de2237cc4 Enable check for E126
E126 continuation line over-indented for hanging indent

Change-Id: Id64edce8278d96c1b2d4a6ca536e9fc8fbef478c
2014-10-23 17:28:25 +03:00
Cedric Brandily 333d2e7bd9 Define helper to run an action on many resources
This change defines do_action_on_many function as a helper to run an
action on many resources (like nova delete).

Change-Id: I1c45d11a520703c57e3ac1923d94ec5f864f266b
2014-10-22 16:20:30 +02:00
Andrey Kurilin dc09cf27e3 Port to use oslo.i18n
Module gettextutils from oslo-incubator was graduated to separate
library (oslo.i18n) and removed from repository, so we should use
new library.

Change-Id: I15d36ac5a2bb88b332ffa38d29488b75c55a20a9
2014-10-16 01:19:48 +03:00
Jenkins 963484513d Merge "Use oslo.serialization" 2014-09-23 03:53:12 +00:00
Andrey Kurilin 8c0fd9a674 Use oslo.serialization
Since module `jsonutils` from common code is graduated in
`oslo.serialization`, we should remove code from oslo-incubator and use this
library.

Change-Id: Ia8b5ef598ff415cdde19f523a36a552918f9f94b
2014-09-20 20:42:52 +03:00
Andrey Kurilin d03014cdb0 Use common code instead of novaclient.utils
Module `novaclient.utils` contains a lot of functions which are
presented in modules from common code.

* service_type -> novaclient.openstack.common.cliutils.service_type
* get_service_type -> novaclient.openstack.common.cliutils.get_service_type
* pretty_choice_list ->
      novaclient.openstack.common.cliutils.pretty_choice_list
* import_class -> oslo.utils.importutils.importclass
* HookableMixin -> novaclient.openstack.common.apiclient.base.HookableMixin

Change-Id: Ia6cac058da12c852d92f26875a66ae31cc4c63d4
2014-09-19 16:56:13 +03:00
Andrey Kurilin 392148c7ef Use oslo.utils
Modules `strutils`, `timeutils` and `network_utils` from common code are
graduated in `oslo.utils`, so we can:
 1. remove `novaclient.openstack.common.network_utils` and use
    `oslo.utils.netutils` instead.
 2. use `oslo.utils.encodeutils` and `oslo.utils.strutils` instead of
    `novaclient.openstack.common.strutils`.
 3. use `oslo.utils.timeutils` instead of
    `novaclient.openstack.common.timeutils`.

Additional information:
 - modules `importutils`, `strutils` and `timeutils` from
   `novaclient.openstack.common` cannot be removed, because:
   - importutils is used by apiclient and jsonutils;
   - strutils is used by apiclient, cliutils and jsonutils;
   - timeutils is used by jsonutils
 - additional check for `safe_encode` in Py3 is required, since
   If91a866d864a22d28a352152beff4c7406a27b7b was merged.

Change-Id: Ib8d79d9c85af4916e87a76a1a67a13488ddaa111
2014-08-28 12:17:22 +03:00
Christian Berendt d51b546774 Enabled hacking checks H305 and H307
* H305  imports not grouped correctly
* H307  like imports should be grouped together

Change-Id: I23fdad285508707a2c1d7c832ff8b1a6a10e8f88
2014-07-17 15:31:08 +02:00
Russell Bryant d678dd2955 Revert "Reuse exceptions from Oslo"
This reverts commit 3bde9c3f42.

This change is a part of a series that is not backwards compatible.
It broke applications using the client library.

Change-Id: Id01a0a0feb601539d3855f445ebaf6a3cc000610
Partial-Bug: #1340596
2014-07-14 09:43:44 -04:00
huangtianhua 65b0d36f3c Fix using a variable which is not defined
There is a variable which is not defined but used, we should define it
before using. Add a test for get_resource_manager_extra_kwargs_hook
function, and change the exception to a more detail instead broad
'Exception'.

Change-Id: I7a798dad55a65f06ebbe175925a00028940bb168
2014-06-26 11:32:55 +08:00
Jenkins 1a7f84cb46 Merge ""nova boot" should not log an error if subsidiary commands fail" 2014-06-24 06:33:10 +00:00
ChangBo Guo(gcb) 88d0b6f2d9 Enable F841
F841 detects local variable is assigned to but never used.
This commit fix the violations and enable F841 in gate.

Change-Id: I52419f5e17db70e511ff2d4d61c85458c958e9c3
2014-06-19 09:49:05 +08:00
Jyotsna b78c0d4f46 "nova boot" should not log an error if subsidiary commands fail
Fix:
Intially the cli was raising "CommadError" in case the requested
flavor or image were not present.
This error category was not approrpiate as it signifies an error
in the command syntax. When the requested resource (flavour/image)
does not exist, a ResourceNotFound error should be raised. So,
added a new error category "ResourceNotFound" to cater for this
scenario and updated the code to raise this new error.
"nova show <instance_name>" command has also been updated to raise
"ResourceNotFound" error when the requested vm for which details
have to be displayed does not exist.

Closes-Bug: #1258488
Change-Id: If64a087944586ef5792efe3baa62e455b9bbaa07
2014-06-17 14:48:11 +05:30
Zhengguang fdd59e142a Fix the incorrect return messages in keypair show and delete
When we delete or show a keypair, if the keypair doesn't exist,
we'll get "The resource could not be found.(HTTP 404)", this
patch will change it to "ERROR: No keypair with a name or ID of
'keypair_name' exists."

Change-Id: Ifebd8d2213c327f3d3fdd672207170aebbe1bb40
Closes-Bug: #1307338
2014-04-20 10:59:22 -04:00
Jenkins d703381c45 Merge "Fix i18n messages in novaclient, part I" 2014-02-10 02:25:23 +00:00