195 Commits

Author SHA1 Message Date
Andrey Kurilin
147a1a6ee4 Deprecate 'novaclient.client.get_client_class'
This method is redundant and blocks versioned client classes to change
interface. `novaclient.client.Client` should be used instead.

Releated-Bug: #1493576
Change-Id: I73cea2c6062419d75646e9239c6194f4d1ffd2b1
2015-09-10 15:55:26 +03:00
Andrey Kurilin
a96e9d57c5 Restrict direct usage of novaclient.v2.client
A lot of project uses incorrect import of versioned novaclient client obj
(i.e. novaclient.v2.client.Client). It leads to unability to change
interface of such inner classes.

This patch updates docs to include warning note and add warning message to
`novaclient.v2.client.Client` object.

Change-Id: Ifeba391716d3d51d6a75a53cad405e1ec595e27b
Related-Bug: #1493576
2015-09-10 15:54:38 +03:00
Jenkins
72190ba9a2 Merge "Fix versions.list for v2.1 Nova API" 2015-08-24 23:19:10 +00:00
Feodor Tersin
b6130e2e18 Fix a fault of request logging with no credentials
If a user doesn't specify for novaclient's Client neither credentials
nor auth token, but specifies http_log_debug=True, and requests Nova
version list, novaclient fails with AttributeError exception.

The reason is that obfuscation of auth token doesn't expect None value
of the token. This patch bypass obfuscation of None token.

Closes-Bug: #1488169
Change-Id: I3712d633719bc77310ce863da33b2eec59a7ce91
2015-08-24 19:46:17 +03:00
Feodor Tersin
bf91805f35 Fix versions.list for v2.1 Nova API
novaclient transforms its management_url to get an url for a request for
server versions list. Currently this transformation does not consider
that version part of an url can be complex and contain major and minor
parts. As a result versions.list does request on a wrong url and fails
with NotFound error.

This patch adds support of version formats like 'vN.N', 'vN.NN', etc.

Partial-Bug: #1483030
Change-Id: Ie105bec37ee41c6a77ffc5f1cf680bbf88846159
2015-08-21 22:04:15 +03:00
Ian Cordasco
c69c38c58f Use keystoneclient's TCPKeepAliveAdapter
When novaclient isn't using a session from keystoneclient, it needs to
set reasonable TCP Keep-Alive values otherwise the operating system
defaults may cause the client to hang for hours before a connection will
time out. Using keystoneclient's adpater (which sets good defaults) will
allow us to not have to maintain this adapter here and to benefit from
their defaults.

Closes-bug: 1477275
Related-bug: 1323862
Depends-On: Ibd53ae2d4d2455db0ebc9951e5c764befc57850f
Change-Id: I1924bd96eb1a4bac5d57a5cc5d5461acb3f7f5ac
2015-07-28 20:20:29 -05:00
Andrey Kurilin
ea0b3bd608 Implements 'microversions' api type - Part 1
Compute API version will be transmitted to API side via
X-OpenStack-Nova-API-Version header, if minor part of version is presented.

New module "novaclient.api_versions" was added as storage for all api versions
related functions, classes, variables and etc.

`novaclient.api_versions.APIVersion` class is similar to
`nova.api.openstack.api_version_request.APIVersionRequest`. The main
difference relates to compare methods(method `cmp` is missed from Py3) and
processing "latest" version.

Related to bp api-microversion-support

Change-Id: I0e6574ddaec11fdd053a49adb6b9de9056d0fbac
2015-07-16 16:06:28 +03: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
Matt Thompson
84aec86319 Pass full path to pkgutil.iter_modules()
On my production system, when using client version 3, an exception is
raised with an incomplete message as the installed novaclient is
failing to find the bundled client versions.  This commit creates a new
_get_available_client_versions() method and moves the client version
searching from get_client_class() into it.

We also update __get_available_client_versions() to pass
pkgutil.iter_modules the full path to novaclient rather than
'novaclient', which is what actually resolves the issue here.

Lastly, we add a single test to ensure that
__get_available_client_versions() does not return an empty list.

Change-Id: I07ce414863e833c72e50ad8cf1824054cfb41457
Closes-Bug: #1463809
2015-06-11 09:42:02 +01:00
Andrey Kurilin
aa4c947519 Remove redundant check for version of requests
Novaclient requirements list contains next entry:
  requests>=2.5.2

so we don't need to check that installed version of requests is greater
than '2.4.1'

Change-Id: I7d270e6d75c76bc56e21f42c683fde9284a8dfd7
2015-05-15 18:05:14 +03:00
kylin7-sg
02c04c5658 Make _discover_extensions public
Heat uses `novaclient.shell.OpenStackComputeShell._discover_extensions`
function, which is private currently. It's better to change this method
to public for public use.

Change-Id: I15879d56db2ec88a9bef99b6af8924ebd4ad169b
Closes-bug: #1440779
2015-05-06 14:10:59 +08:00
Jenkins
2a7c2f14c2 Merge "Don't lookup service url when bypass_url is given" 2015-04-27 17:12:51 +00:00
Andrey Kurilin
61ef35fe79 Deprecate v1.1 and remove v3
Module novaclient.v1_1 is already deprecated, so it's time to stop using it
inside novaclient.

Since support of v3 nova is undocumented feature, which uses v2
implementation, we can remove code related to it.

Also, this patch removes redundant check for compute api version != 1.0.

Change-Id: I06b349f704d5ae2c592d8d286da268870f2a69e9
2015-04-22 15:03:07 +03:00
melanie witt
4f9e65c438 Don't lookup service url when bypass_url is given
Change https://review.openstack.org/#/c/164321 broke the bypass_url
option. It made the assumption that self.service_catalog won't be set
in novaclient/client.py when bypass_url is specified, which isn't
necessarily true. This change adds a check for self.bypass_url and
looks up service url only if bypass_url hasn't been specified.

Closes-Bug: #1445086

Change-Id: I72d2b3e3199aeae7fb2f2c68be259774e07a4501
2015-04-21 23:54:14 +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
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
David Moreau Simard
689a884e18 Fix typo in socket attribute name
The proper attribute name is 'IPPROTO_TCP', not 'IPROTO_TCP'.
This would lead to an AttributeError since socket does
not have an attribute named 'IPROTO_TCP'.

Change-Id: Ibd3c1e8d48ae57994d023bf18dd53a298466f6cb
Closes-Bug: 1430935
2015-03-11 13:53:24 -04: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
Andrey Kurilin
f84c6531fd Check 'auth_url' is presented while authentication
If 'auth_url' is missed in HTTPClient, authenticate method failed with
non-friendly error while trying to parse it.

Change-Id: Iaec95527293f3e1a34eb7f9ffa81097ba48107b3
2015-02-09 21:47:48 +02:00
Ikuo Kumagai
9a6a7664c2 Change the unsuitable item caching for completion
This fix changes the item that cached for completion from
"human_id" to "name".
A string for completion shoud not be changed in any way,
because changed keyword can not use as command line parameter.
But the "human_id" means "human readable id" that is
changed from "name" by method "to_slug". "to_slug" is meant to
create a valid path name from a string.

The tools/nova.bash_completion take the completion string from
the file ".novaclient/*/*-cache". The file is created when client
call "list" command. For example , "nova list","nova image-list",
and the others.
Currently, items that are written to the cache file is the "id"
and "human_id".

Closes-Bug: #1193049

Change-Id: I241ec8b7c8729274ee43db6e360141fd381b265e
2015-02-06 05:14:05 +00:00
Andrey Kurilin
0a60aae852 Rename v1_1 to v2
Module novaclient.v1_1 is used as implementation of V1.1, V2 and V3.
Since future development(microversioning) will be done across V2,
implementation should be done in appropriate module(to prevent misleading).

Despite the fact that implementation for all versions are equal, discover
method for contrib path worked only for v1.1. This patch fixes this bug and
modifies shell tests to check all versions.

Change-Id: Ib6798f4dfe177586302141f522dc593560ce6a5b
2015-02-04 17:40:46 +02:00
Jenkins
0ae527665a Merge "Use TCP Keep-Alive on the socket level" 2015-01-23 23:05:53 +00:00
Ian Cordasco
7713fa0b18 Use TCP Keep-Alive on the socket level
There is not a way to pass the socket options to the HTTPAdapter upon
creation so we have to sub-class it and override the init_poolmanager
method.  This also requires at least python-requests 2.4.0 but that
has 2 severe bugs that were fixed in 2.4.1. If we try to fix this
without a hard lower limit, we will not be able to properly set these
options on the socket at creation time.

Change-Id: I06e0d2c67d3197607e5f23f623c8fca69e1b23d7
Closes-bug: 1323862
2015-01-23 15:38:39 -06:00
Jamie Lennox
003f1ed048 Pass kwargs through to the adapter
A major point of the adapter is that we should be able to add new
arguments to the adapter that are supported automatically by the clients
that support it. This means we have to pass all additional arguments
through to adapter.

Regardless of whether the arguments are passed to the adapter or to the
traditional client the kwargs are explicitly provided so we won't end up
with missing arguments.

Closes-Bug: #1403329
Change-Id: I7303b184875dc296ca855ad89496173c42070879
2014-12-19 11:15:32 +10: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
Andrey Kurilin
cc62efef41 Remove code related to V3
Since V3 API is not supported, code related to it should be removed.

Discussion in mailing:
http://lists.openstack.org/pipermail/openstack-dev/2014-December/052095.html

Change-Id: Iac5c5e6d81479cbeb8bf10cfcda1cc5617680de8
2014-12-03 14:11:39 +02:00
Eugeniya Kudryashova
1aa020989e Enable check for E128 rule
Fix E128 failures in novaclient/client and
novaclient/shell and enable check for E128

E128 continuation line under-indented for visual indent

Change-Id: Id3ac46ccdbb8a9f97e54b4643240d93b06fac6ea
2014-11-27 14:19:55 +02:00
Jenkins
7120fe4dee Merge "Curl statements to include globoff for IPv6 URLs" 2014-11-18 06:05:08 +00:00
sridhargaddam
e91d469704 Curl statements to include globoff for IPv6 URLs
Novaclient displays curl statements for debugging/troubleshooting
purposes. For IPv6 URLs, curl requires --globoff to be passed in
the arguments. Since novaclient does not use curl directly, this
patch displays the curl commands with globoff option which works
for both IPv4 and IPv6 URLs.

Closes-Bug: #1228744
Change-Id: Ib7099e8e3bbc15f29bbaa1db37ef21e78a74e7bc
2014-11-14 14:27:03 +00:00
David Hu
8597a0c234 Support using the Keystone V3 API from the Nova CLI
This changeset enables support for Keystone V3 authentication
on the Nova CLI. This provides consistency between using
novaclient as the Nova CLI and using it as a library
as the Keystone V3 support already exists for the libary usecase.

The bulk of the change surrounds the use of the keystoneclient
session object for authentication, retriving the service catalog,
and HTTP connection/session management.

Co-Authored-By: Morgan Fainberg <morgan.fainberg@gmail.com>
Change-Id: Iece9f41320a8770176c7eeb5acd86be4d80cc58f
2014-11-11 21:04:20 -08:00
Andrey Kurilin
3065afd6c0 Enable check for E129
E129 visually indented line with same indent as next logical line

Change-Id: I438bf0d9de7f61ab65e753169c9a8007e84b215a
2014-10-23 14:28:57 +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
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
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
Jamie Lennox
db6d6780d5 Use adapter from keystoneclient
SessionClient is mostly common code that wasn't yet released in
keystoneclient. Now that 0.10 is released we should use the adapter from
there as much as possible.

Change-Id: Ief6cd7e752fd8c9e9157364f99e270da7faff074
2014-08-08 07:34:32 +10:00
Jenkins
50b1068ba6 Merge "Don't log sensitive auth data" 2014-07-28 05:43:11 +00:00
Qin Zhao
60d1283968 Don't log sensitive auth data
This code change redacts the password in keystone request, and
also redact the token text in keystone response. The code still
makes REST call by itelf, instead of calling keystone client.

Closes-Bug: 1327019

Change-Id: Ib9c0610c1ef351a127364478721cf961c2a30125
2014-07-21 01:45:36 +08:00
Ken'ichi Ohmichi
67585ab36e Add "version-list" for listing REST API versions
Nova provides REST API versions.
This patch adds a subcommand "version-list" for outputting the versions.

Change-Id: I1b40ad57912aa740c0b1d9221018aba9b13a5436
2014-07-15 06:50:50 +00:00
Jamie Lennox
cc7364067f Allow us to use keystoneclient's session
The session object is a cross-client means of standardizing the
transport layer.

Novaclient's HTTPClient object has diverged significantly from other
clients. It is easier to simply replace it if a session is provided. If
a session is provided then users of the library need to be aware that
functions such as authenticate() will no longer have any effect/are in
error because this is no longer managed by nova.

Change-Id: I8f146b878908239d9b6c1c7d6cdc01c7e124f4e5
2014-07-01 16:53:47 +01: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
Sean Dague
ef91a5732a adjust to {SHA1} convention for token
based on openstack-dev mailing list thread, support the {SHA1}
convention for headers that is generally agreed on.

Also fix a minor issue that Johannes found after the review landed,
which was doing substring matching instead of tuple matching.

Change-Id: I80a456c765026ac6179fd424ead01715798c1dac
2014-06-12 10:51:24 +00:00
Sean Dague
40d814b02e mask keystone token in debug output
replaying the keystone token in debug output is both completely
burdensome to read (given it's unbounded size), but it's also
potentially a security issue given that it could be used in replay
attacks.

Instead, filter the headers to sha1 sensitive things, with X-Auth-Token
being the only one listed so far. The sha1 will at least give us the
understanding of tokens being the same or different (and an administrator
could use that to figure out if they were valid later).

This also removes some extra '\n' that were being injected into the
debug logs, because they were not helping with readability.

Lastly, actually test logging. This introduces the first tests of the
logging path using the logging fixture. It's pretty basic, but does
verify that requests are logged at debug, that the SHA1 format works,
and that headers which are not listed get shown straight through.

DocImpact because this changes the curl dumped strings which people
may have been using. They can still do that as long as they generate
their own keystone token.

Change-Id: I1edb94785705c3b6a05f118b77d3aeb07461cd44
2014-06-10 06:47:02 -04:00
Christian Berendt
22277e6d0b debug level logs should not be translated
According to the OpenStack translation policy available at
https://wiki.openstack.org/wiki/LoggingStandards debug messages
should not be translated. Like mentioned in several changes in
Nova by garyk this is to help prioritize log translation.

Change-Id: I43c5d4ecd2286f1a622b6822603ba62881a317a2
2014-05-13 11:39:13 +02:00
Boris Pavlovic
98934d7bf1 Fix session handling in novaclient
Prior to this patch, novaclient was handling sessions in an inconsistent
manner.

Every time we created a client instance, it would use a global
connection pool, which made it difficult to use in a process that is
meant to be forked.

Obviously sessions like the ones provided by the requests library that
will automatically cause connections to be kept alive should not be
implicit. This patch moves the novaclient back to the age of a single
session-less request call by default, but also adds two more
resource-reuse friendly options that a user needs to be explicit about.

The first one is that both v1_1 and v3 clients can now be used as
context managers,. where the session will be kept open (and thus the
connection kept-alive) for the duration of the with block. This is far
more ideal for a web worker use-case as the session can be made
request-long.

The second one is the per-instance session. This is very similar to what
we had up until now, except it is not a global object so forking is
possible as long as each child instantiates it's own client. The session
once created will be kept open for the duration of the client object
lifetime.

Please note: client instances are not thread safe. As can be seen from
above forking example - if you wish to use threading/multiprocessing,
you *must not* share client instances.

DocImpact

Related-bug: #1247056
Closes-Bug: #1297796
Co-authored-by: Nikola Dipanov <ndipanov@redhat.com>
Change-Id: Id59e48f61bb3f3c6223302355c849e1e99673410
2014-04-07 19:38:51 +02:00
Davanum Srinivas
9344f02649 Fix for invalid literal ValueError parsing ipv6 url(s)
Switch to using network_utils for splitting the URL. The code
in oslo-incubator supports ipv6 urls

HEAD of oslo-incubator is bb52a3fc49f033b9f36238231ca56e754a78cf4b

Updated openstack-common.conf to pick up the new dependency from
oslo-incubator

Change-Id: Ifa3dec384e85942a191260d17e8141030d31ff84
Closes-Bug: #1298137
2014-03-29 14:16:02 -04:00
Jenkins
8ecc6b3eff Merge "Allow user ID for authentication" 2014-03-21 19:51:23 +00:00
Arata Notsu
4cfaa4a61c Do auth_url.rstrip('/') only if auth_url is set
auth_url can be None, for example, when we use bypass_url.

Also, add rstrip('/') for bypass_url (and management_url), which
is done when management_url is gotten from service catalog.

Change-Id: I4f59cc405386a15f8a266d279b27f279eacdb7f1
2014-03-18 11:25:05 +09:00
Phil Day
dd8bde71ff Allow user ID for authentication
In Keystone V3 user names are no longer necessarily unique
accross domains.

A user can still authenticate a user in the non default
domain via the V2 API providng they use IDs instead of names.

Tenant_ID is already supported, this change adds support
for user ID

Change-Id: I36ba75f3e67c8cdb959e31923d5e557414ab6f9b
2014-03-07 19:24:22 +00:00