Any object of Resource class or its child class do not compare with
None as expected. For example if a server has been found and is
clearly not None, the test "server!=None" will be False.
This was occuring because the __eq__ implementation was returning the
'NotImplemented' keyword and the __ne__ implementation was returning
the not of __eq__, which in this case will return False as the
expected python behavior for a the not of NotImplemented is False.
Changed the __ne__ implementation to return the correct boolean value
and added the test case that fails with the older implementation and
passes in the current fix.
Change-Id: I6bf5a6e9c9eed4bbcf6678467df19dfea560b4de
Closes-Bug: #1648207
The attribute _info is an internal private field in Resource class,
to read this attribute in external class is a bad practice.
Change-Id: I8c705d6d08418d18973eb4a2d7858297a12a4d9d
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
This does a lookup directly to the image service for name => id
mapping of images. This is required to move on to supporting the
2.36 microversion since that microversion makes the compute
image API proxy return a 404, so before the client can support
that microversion it has to first drop it's usage of the proxy
API.
Because of the way the FakeHTTPClient was stubbing the image
API proxy and the tests are not passing uuids for image IDs,
there is a lot of cleaning up of the tests to make this work
with a fake glance v2 API backend. The tests were basically
false though since you can't do 'nova image-show 1', but because
the stubs mask that it's just been a mountain of lies that has to
be cleaned up here.
As a side effect of fixing a bunch of the tests, this also
makes debugging assert_called less terrible with a better error
message.
Co-Authored-By: Matt Riedemann <mriedem@us.ibm.com>
Related to blueprint deprecate-api-proxies
Change-Id: Iaff3999eafb7d746e5c6032f07ce0756f7b5e868
- Installation of the cryptography module fails on Ubuntu Xenial
because the libssl-dev package needs to be installed first, so we
add this to other-requirements.txt
- inspect.getargspec()` was deprecated in Python 3.0 and will be removed
in 3.6 (ETA late 2016). From Python 3.5 it started throwing a deprecation
warning which leds some tests failures.
Co-Authored-By: Andrey Kurilin <andr.kurilin@gmail.com>
Change-Id: Ic094ca5c636af9ac1e212914df910a020d92702d
Class base.Resource defines __eq__() built-in function, but does
not define __ne__() built-in function, so self.assertEqual works
but self.assertNotEqual does not work at all in this test case in
python2. This patch fixes it by defining __ne__() built-in function
of class base.Resource. Also fixes spelling errors:resoruces.
Change-Id: I39e6f6b94e9490afc14143208e6f20b0ef960991
Closes-Bug: #1586268
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
23f13437dd64496fcbc138bbaa9b0ac615a3cf23 deprecated the
purely volume or volume-snapshot related CLIs and python
API bindings during Kilo. python-cinderclient should be
used for the python API bindings now, and python-openstackclient
should be used for the CLI for those operations.
The alternate_service_type context manager is also removed
since it was only used for proxying through to the volume API
endpoint.
Since the proxy for creating volumes is removed, we have to
add python-cinderclient for testing the volume attachment
CLIs/APIs that are left intact.
Change-Id: I09a6501603667350f49b1b1fa130353a6d5272a2
The subclass of ManagerWithFind implements get() function, and all
the get() functions returns an object with request_ids. Let's expose
these request_ids to users directly.
Change-Id: Icb3c480c637c39412ed085f4523fb93e36fea0a7
Closes-Bug: 1541694
'request_ids' is a function of class RequestIdMixin.
Resource().__dict__.keys() doesn't contains a function. So it not
necessary to filter it.
Change-Id: I73af5d1be39769f70cbe4c1ec83144d56f94f91a
Added wrapper classes which are inherited from base data types str,
list, tuple and dict. Each of these wrapper classes and
the Resource class contain a 'request_ids' attribute
which is populated with a 'x-compute-request-id' or
a 'x-openstack-request-id' received in a header from a response body.
This change is required to return 'request_id' from
client to log request_id mappings of cross projects.
This patch is one of a series of patches for implementing
return-request-id-to-caller.
Co-authored-by: Ankit Agrawal <ankit11.agrawal@nttdata.com>
Change-Id: I422c4f4ee59991ca89a0a16f548b537c8b61bb97
Implements: blueprint return-request-id-to-caller
when we try to restore an instance, it's already deleted state,
so we need to add 'delete=True' as default to restore command,
otherwise, the search function can't find the instance
whose state is deleted with the given name
Change-Id: I81cdc46897d76333452069a691824264ad504518
Closes-Bug: 1534644
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
There is a lot of H404/405 violations in novaclient, and it is better
to fix those to have a better doc string for class/methods.
This patch fixes these violations for below files-
-api_versions.py
-base.py
-client.py
As there are lot of violations and cannot be fixed in single patches,
So separating those in multiple patches for easy review.
Change-Id: I30a714fc3b0b317f7ffa4a99fbb224b4d5f5477b
Partial-Bug: #1521899
Commit 5153dcda807c554769081626c10c43d16adea671 removed bdm v2-only
request parameters to pass nova api v2.1 schema validation, but also
removed the ability to boot with legacy bdm specifying volume_id only.
This adds volume_id back to the request for legacy bdm when
no other parameters are specified.
Closes-Bug: #1501435
Change-Id: Ie8c56c28492793990ef7ed6dc54768cef9e28a98
Currently, novaclient's gates are broken due to missed 'volume' service_type.
This patch changes default service type for all volume related managers to
"volumev2" and leave ability to set "volume" service_type.
Change-Id: Ia1e1d3def1e6127cc2b97797c577c15265f879bd
Closes-Bug: #1501258
`_parse_block_device_mapping` method was design to support both
bdm v1 and v2. The implementation is based on the fact that API side
ignores unknown/incorrect parameters, so `_parse_block_device_mapping` compose
equal parameter for bdm v1 and bdm v2. Since Nova V2.1 contains schema checks,
such implementation stoped working.
Despite the fact that novaclient.v2.servers contains separate logic for bdm v2,
we can make `_parse_block_device_mapping` works only with legacy bdm and
in future patches make it works for both bdm v1 and bdm v2.
Change-Id: I37c00ac77b1a3b500221d779533532e9f43e5277
Closes-Bug: #1491737
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
Changes include:
e782594 Add last_request_id only if it is not none
18bf5ca Fix usage of NotFound exception in apiclient.base
3bc8231 deprecate apiclient package
Depends-On: Ia83ef6136da1c551ea947679dc546a0d7ad2f876
Change-Id: I0b5917c657d6adc3d34229b14833a5224c168e07
Currently, several of the volumes apis depend on callers to pass
service_type='volume' as a parameter when creating a client object,
to route correctly. The problem is, it makes it impossible for
callers to work with both the compute and volume endpoints at the
same time. They can either work with compute and have volumes.* calls
return 404, or they can work with volume and have servers.* images.*
flavors.* calls return 404.
The CLI sets service_type='volume' for client objects for the
following commands via a decorator:
volume-list
volume-show
volume-create
volume-delete
volume-snapshot-list
volume-snapshot-show
volume-snapshot-create
volume-snapshot-delete
volume-type-list
volume-type-create
volume-type-delete
With this change, the service_type 'volume' is set in the api,
so the decorators on the shell commands are no longer needed.
Closes-Bug: #1431154
Change-Id: I11b48ac14fa4c64d8aae528552ec5b363be384c5
This reverts commit 4c8cefb98a425382204df2f38f24e6b5b71520dd.
The cache completion was causing a bug where 'nova volume-attach' would
then try to query Nova for volume information using a URL that was not
valid. This caused it to appear that the attach had failed.
Additionally the idea of making extra API queries for a bash completion
cache should be thought through more.
Conflicts:
novaclient/client.py
novaclient/shell.py
novaclient/v2/client.py
novaclient/v3/client.py
Closes-Bug: #1423695
Change-Id: I6676a11f9b5318a1cda2d03a5d4550bda549d5c2
Nova delete command deletes an instance by name
or ID. Nova delete command is able to delete an
instance within the same the tenant by name or
ID. When admin credentials are sourced and try
to delete a non admin tenant instances, nova
delete command is able to delete an instance by
ID only, it is not able to delete an instance by
name.
Nova delete command deletes an instances by id
using following api call
/v2/{tenant_id}/servers/{server_id}
But to delete an instance by name, nova delete
command first find the resources by name using
following api call
/servers?name={server_name}
This api call is not able to retrive the list
of other tenant instances.
Adding all tenants parameter to this api call
will retrive the list of other tenant
instances. The following will be new api
call
/servers?all_tenants=1&name={server_name}
Closes-Bug: #1247030
Change-Id: I03e578d58214c835d9a411752bd618d77ced37ff
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
Instead of listing all servers and doing clientside filtering, use the servers
filtering on name.the server's list already supports filtering
so just pass a search_opts dictionary into list().
This should speed up nova commands when a user has large numbers of servers.
Change-Id: I6deea8523754ff213f43bd059fb00f34fc0e1a12
Closes-Bug: #1202179
This reverts commit 4e1ee661083bd672a884fd13fdb1ffaadea5252a.
This change is a part of a series that is not backwards compatible,
and caused breakage in applications that use the client library.
Change-Id: If614826fb0832602110c1ac8be2c0e6324a5a248
Partial-Bug: #1340596
The current code in novaclient/base.py, class BootingManagerWithFind
do not take in account the differences required to boot an instance from
a volume in API v3. V3 expects UUID as volume id and also the source type
to be set.
Change-Id: Id8cfb2d7811aead27cb26cf7ff615c7a9ed05d54
Close-bug: 1325303
There are a few things currently wrong with bash-completion as it stands now:
1) IDs are currently required to be UUIDs. This is an arbitrary limitation
and doesn't make sense for certain kinds of objects, like `Flavors`
where a valid ID could be `performance-16gb`.
2) The code is spread out between Oslo's `Resource` and Novaclient's
`Manager` class. This makes it difficult to improve the code because it
requires changes to two separate projects. We should centralize the
code in Novaclient until the API is stable, then import the code into
Oslo in its entirety, not partially like it is now.
3) The completion code is handled by the `Manager` of which there is one
per Resource-type. In the interest of centralizing this functionality,
we should create a `CompletionCache` class and hang it off of `Client`
of which there is one-per-session.
4) The completion-code currently runs by default even in headless mode
(e.g. novaclient without the shell). It'd be much more efficient to
only write to the completion cache if we're accessing the `Client` from
the novaclient shell. We can make this an option to support third-party
CLI clients that want to use the completion-cache as well.
NOTE:
* The corresponding Oslo patch is here:
https://review.openstack.org/#/c/101376/
* This patch was tested in multithreaded mode to prevent any regression
from:
https://bugs.launchpad.net/python-novaclient/+bug/1213958.
Change-Id: Idada83de103358974b739f81d4f392574f9e1237
Closes-Bug: 1332270
Since exceptions from oslo is used, ClientException doesn't have any
attributes related to HTTP, so `HttpError` should be set as default
http-based exception.
Also, attribute `code` is used in several project, so it should be
returned and marked as deprecated.
Partial-Bug: #1322183
Change-Id: I3c71e2d25d6e36b5bac0f2b3add74d6747cf7c25
Creates an images client when attached to the the servers
client. This is necessary because the Nova V3 API no longer
proxies image queries to glance but when preparing a request to
boot a server it is necessary to retreive information about
images so we need to talk to both Nova and Glance in the same
command.
This is a bit ugly, but not much more than the already existing
ugliness of using the client class designed to talk to
Nova to talk to Glance and Cinder. The long term clean solution
is probably to a unified client that is designed to talk to
multiple openstack services.
Differences between the V2 and V3 API are described here:
https://wiki.openstack.org/wiki/NovaAPIv2tov3
Partially implements blueprint v3-api
Change-Id: Ib43682f38cd7a3e0f910b75e96685591246e7f67
All methods of Resource class novaclient is equal to common code.
In the process of unification of the clients code we should
reuse common functionality from Oslo.
Related to blueprint common-client-library-2
Change-Id: I2b72c6b34a44dec3572ca8ad70e41e42a32d48c0
This patchset updates modules based on the config file:
openstack-common.conf
Notes: Some corrections has been added to work with
new files.
+ utils.py: The method safe_decode from strutils.py
was updated and it is now not necessary to check for
decode string with py33.
+ base.py: base64 needs a 8-bit string for py33
+ test_shell.py: stdin.encoding is needed for strutils
Change-Id: Iebe474f1226f8b5faa7fb5722e65f41b80d1973c
Related to blueprint common-client-library-2
Closes-Bug: #1265473
If image has no name, human_id can't be built.
Also slugify raises ValueError if None argument passed.
It affects Docker images.
Closes-Bug: #1267429
Closes-Bug: #1267130
Change-Id: Ib975775b441917eef2a650049cee9991d10c50d7
The bash completion code is the sole user of the slugify() function
in utils, which is substantially similar to to_slug() provided in
strutils from oslo.
Change-Id: Ib4eb7e4c0fa0e9bc5c4a0856f6391911d8f8fd3b
Closes-bug: #1266118
Previously, completion caches were not thread-safe and multiple
threads could not make calls to python-novaclient simultaneously.
With locking, the completion caches are now thread-safe.
Closes-Bug: #1213958
Change-Id: I201c2ed0f1eb09b1c2a74de96119cbae9ed6f4b0
The way to using metaclass has changed in Python3.
Python 2.7 way:
class Foo(object):
__metaclass__ = FooMeta
Python 3 way:
class Foo(object, metaclass=FooMeta):
...
The six.add_metaclass() decorator allows us to use one syntax that
works for both Python 2.7 and Python 3.
Change-Id: Ibd31a9f91bac6ec220d802f16c77ee0306e211b3
Closes-Bug: #1236648
In Python 3.3, hash randomization is enabled by default. It causes the
iteration order of dicts and sets to be unpredictable and differ across
Python runs.
Sort the files parameters when multiple files are designated.
Close-Bug #1235096
Change-Id: I0db645b3fb92408bd8c6780bfabe7ce8265a65a8
Python 3 doesn't support str.encode('base64'), we should use the
module "base64" instead.
Close-Bug #1229161
Change-Id: I1432952558f8c5c3cff39761306e91916d80207f
Right now the cli was already adding a block device when it was passed
an image_id to boot from and more than one block device mapping v2. This
is done because nova expects the image to be another block device
mapping and would ignore it otherwise.
This patch moves this functionality from the cli to the base module so
users of the module can benefit from this and also to prevent some
misunderstandings that may arise when using BDMv2 and the image gets
ignored by nova. In the future we should handle this in the nova side
assuming a new BDM when an image is provided.
Fixes bug #1225061
Change-Id: I29f31c24f958cfa8b68b33edc63e0d7031aa241f
In python3 dict.iteritems(), dict.iterkeys(), and
dict.itervalues() are no longer supported. So use
six.iteritems() where it is appropriate.
blueprint python3-novaclient
Change-Id: I8c39bfe426d08d36215b55c3245dcfc69ec72517
Signed-off-by: Chuck Short <chuck.short@canonical.com>
Add new arguments and syntax for booting from a block device mapping
that use the new os-block-device-mapping-v2-boot extension. These
allow to:
* boot from an image, volume or snapshot (--image, --boot-volume, --snapshot)
* attach any type of block device (--block-device).
* attach an swap disk on boot (--swap).
* attach an ephemeral disk on boot (--ephemeral).
blueprint: improve-block-device-handling
DocImpact
Change-Id: I1aadeafed82b3bd1febcf0d1c3e64b258d6abeda
Administrator cannot use the flavor name in arguments of
"nova flavor-access-add" and "nova flavor-access-remove".
This patch fixes this problem.
Change-Id: I68b267dc071382f1978efc2088cd8e837455e8b4
Related-Bug: #1205298
Administrator cannot use the flavor name in arguments of
"nova flavor-access-add" and "nova flavor-access-remove"
in following conditions.
1. The flavor is non-public.
2. The falvor doesn't belong administrator's tenant.
This patch fixes this problem.
Change-Id: Ic5e3222d0ff62667e003a61e6a94e85833da5d11
Fixes: bug #1205298
Fix:
TypeError: Unicode-objects must be encoded before hashing
while running tests. This is due to the fact in python3 hashlib.md5
works with bytes and we are passing unicode strings.
Change-Id: I27a57d6afb2412e11bc2802e4559d56c5b5592a9
Signed-off-by: Chuck Short <chuck.short@canonical.com>