95 Commits

Author SHA1 Message Date
Cao Shufeng
ba39fd3caa Fix omission of request_ids returned to user
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
2016-02-04 08:22:00 +00:00
Cao Shufeng
2131f777eb Remove unnecessary filter from Resource's __repr__() function
'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
2016-02-03 09:29:58 +08:00
Jenkins
8cf8edde26 Merge "Add wrapper classes for return-request-id-to-caller" 2016-01-28 10:49:05 +00:00
Takashi NATSUME
2220c56375 Add wrapper classes for return-request-id-to-caller
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
2016-01-26 23:46:10 +00:00
jichenjc
6791a8be69 Allow restore command with name param
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
2016-01-23 22:06:48 +08: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
Ghanshyam
aa73df2649 Fix H404/405 violations in client.py,base.py,api_version.py
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
2015-12-03 11:45:22 +09:00
melanie witt
abd0630bad Always send volume_id when booting with legacy bdm
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
2015-10-01 10:55:47 +00:00
Andrey Kurilin
3350a5713d Change default service_type for volumes managers
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
2015-09-30 14:20:04 +03:00
Andrey Kurilin
5153dcda80 [BugFix] Change parameters for legacy bdm
`_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
2015-09-10 20:44:49 +03: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
Davanum Srinivas
a5f30d173f cleanup openstack-common.conf and sync updated files
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
2015-06-16 20:32:08 -04:00
melanie witt
e0f5072907 Ensure the use of volume endpoint in volumes apis
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
2015-03-17 01:19:11 +00:00
Andrew Laski
ac6636a54d Revert "Overhaul bash-completion to support non-UUID based IDs"
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
2015-02-20 01:35:57 +00:00
Ritesh Paiboina
a0481e1c80 Add all tenants search opt to del instnce by name
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
2015-02-10 06:03:09 +01: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
Joe Gordon
07260236ab Make findall support server side filtering
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
2014-09-08 18:10:25 -07:00
Jenkins
8f53274ac6 Merge "Fix booting from volume when using api v3" 2014-07-25 12:57:02 +00:00
Russell Bryant
e14f9741a6 Revert "Set default http-based exception as HttpError"
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
2014-07-11 13:30:25 -04:00
liyingjun
58cdcabf1c Fix booting from volume when using api v3
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
2014-06-26 05:56:09 +08:00
Rick Harris
4c8cefb98a Overhaul bash-completion to support non-UUID based IDs
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
2014-06-20 16:37:28 -05:00
Andrey Kurilin
4e1ee66108 Set default http-based exception as HttpError
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
2014-05-22 16:48:24 +03:00
Chris Yeoh
c8ad315763 Adds ability to boot a server via the Nova V3 API
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
2014-01-28 23:29:16 +10:30
Andrey Kurilin
4045979418 Reuse Resource from oslo
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
2014-01-26 14:21:58 +02:00
Sahid Orentino Ferdjaoui
a5195c5033 Updates nova client to use the latest oslo files
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
2014-01-23 18:08:03 +00:00
Roman Rader
3c9a3d8d32 Don't slugify() None names
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
2014-01-13 20:23:22 +02:00
Chris Buccella
3dbab161be Code cleanup: use oslo's to_slug() instead of slugify()
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
2014-01-04 22:56:09 +00:00
wingwj
81c72dbc34 Fix typo in novaclient
hypen-separated --> hyphen-separated
overrwrite --> overwrite
typicaly --> typically
sematics --> semantics

Fixes bug: 1253881

Change-Id: I4aff614bb36b8f321837a9f54024b26ac0f11d40
2013-11-22 12:13:54 +08:00
Ryan Wilson
c320562877 Adds locking to completion caches
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
2013-10-28 01:53:13 -07:00
fujioka yuuichi
362cb18cb4 Apply six for metaclass
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
2013-10-18 14:14:50 +09:00
Kui Shi
f14273d1e0 py33: sort the files parameters of "--files"
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
2013-10-04 16:01:56 +08:00
Kui Shi
8b264fc61d py33: unknown encoding: base64 Edit
Python 3 doesn't support str.encode('base64'), we should use the
module "base64" instead.

Close-Bug #1229161

Change-Id: I1432952558f8c5c3cff39761306e91916d80207f
2013-09-25 06:24:14 +08:00
Jenkins
ecb9b8bf3c Merge "Allow name argument to flavor-access-add" 2013-09-17 18:43:00 +00:00
Jenkins
0af541c727 Merge "python3: Compatibility for iteritems differences" 2013-09-17 18:42:19 +00:00
Xavier Queralt
2e8900b6dc Add a block device for the image when using BDMv2
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
2013-09-13 18:27:45 +02:00
Chuck Short
450f02efe3 python3: Compatibility for iteritems differences
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>
2013-09-13 10:54:19 -04:00
Xavier Queralt
6a85c954c5 New syntax to boot from a block device mapping
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
2013-09-04 17:12:21 +02:00
fujioka yuuichi
97da33fcf5 Allow name argument to flavor-access-add
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
2013-09-03 02:07:35 +09:00
Jenkins
27700f9b36 Merge "Allow name argument to flavor-access-add" 2013-08-23 01:33:06 +00:00
Yuuichi Fujioka
476e50f4d7 Allow name argument to flavor-access-add
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
2013-08-15 03:06:51 +09:00
Chuck Short
8dbd684a5c python3: Fix traceback while running tests
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>
2013-08-13 18:57:51 +00:00
Brian Elliott
0d454089c9 Support programmatic use of disk config extension
Allow servers to be created, resized, and rebuilt with the disk_config
option:

http://api.openstack.org/api-ref.html#ext-os-disk-config

There is a separate extension that exists for disk config already, but
it only works via the novaclient CLI interface, not via programmatic use
of python-novaclient as a library.

assert changes in tests/v1_1/fakes allow for other data in rebuild
and resize requests.

Change-Id: I8051ffb8747cf5c67b0199d22fbbe80306b01499
2013-08-01 13:54:56 -05:00
Jenkins
95e7d70266 Merge "Merge v1_1's base module into main base module" 2013-07-30 17:55:26 +00:00
Christian Berendt
5fe9408d2e make findall in novaclient/base.py more efficient
Use /resources instead of /resources/detail to resolve
the resource ID by the name and load the details of the
resource in a separate step. This reduces the overhead
to resolve the resource ID and results in a better runtime
performance.

This patch does not solve the issue that the name resolving
takes place on the client side. For solving this issue new
Nova API methods are necessary.

fixes bug #1202179

Change-Id: Ib753b1d090cb74b2d137c68f6899dad4ae2ec1ca
2013-07-29 10:52:22 +02:00
Xavier Queralt
0d061f0aeb Merge v1_1's base module into main base module
This class was forked from novaclient.base when adding v1.1 support and
and because v1.0 is no longer supported it can be merged again.

blueprint: improve-block-device-handling

Change-Id: I3113eff522a9dc280f48053001afa9e1a0cad3e3
2013-07-26 16:39:46 +02:00
Chuck Short
3f0312eabc Remove python 2.4 and python 2.5 support.
As a project we do not support python 2.4 or python 2.5
and these versions of python are not tested, so remove
the compatibility code.

Change-Id: I267d9e7e83d85322c45d56d9c5256b514224ad8c
Signed-off-by: Chuck Short <chuck.short@canonical.com>
2013-07-24 13:48:42 -04:00
Chuck Short
a25d4fe59a python3: Compatibility for iteritems differences
In python3 dict.iteritems(), dict.iterkeys(), and
dict.itervalues() are no longer supported. So use
six.iteritems() where it is appropriate.

Change-Id: I8b07dc2a89d790ec275d45f859e1644e9b00c837
Signed-off-by: Chuck Short <chuck.short@canonical.com>
2013-06-24 11:51:04 -05:00
Alessio Ababilov
c9fc9b5b8f Make ManagerWithFind abstract and fix its descendants
ManagerWithFind requires list() method in its descendants.
Make it abstract and fix its improper descendants that do
not implement list() (SecurityGroupRuleManager and many others).

Fixes: bug #1180393
Change-Id: Ic8b466a57554018092c31c6d6b3ea62f181d7000
2013-05-15 21:47:05 +03:00
Mike Lundy
2a495c03d5 make sure .get() also updates _info
Having the _info get out of sync with the actual attributes is kind of a
trap for the unwary. _info is used in preference to the attributes in
many places, and letting it get out of sync means that the method of
retrieval (get() vs. list()) influences the result.

Change-Id: I9d9bf086fa790b811c520b2fa317f95cb1921805
2013-04-10 15:53:54 -07:00
Davanum Srinivas
c5b579926f Fix Copyright Headers from LLC to Foundation
follow the lead from nova and oslo projects

Change-Id: I270c5f1e4eefa4b72e292bfb4a4c60de0c3f6e4a
2013-03-13 20:12:23 -04:00