189 Commits

Author SHA1 Message Date
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
e25bd57555 Merge "Avoid "ambiguous option" when only current/deprecated forms match" 2014-12-11 17:51:55 +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
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
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
Jenkins
d485d755ec Merge "support OS_ENDPOINT_TYPE in nova client" 2014-10-30 00:03:34 +00:00
Miguel Grinberg
607ac48e6c support OS_ENDPOINT_TYPE in nova client
This change makes the handling of the endpoint_type setting in the nova
client more consistent while keeping backwards compatibility. The
NOVA_ENDPOINT_TYPE environment variable is checked first, and if it is
not set then the more generic OS_ENDPOINT_TYPE variable is checked. A
--os-endpoint-type command line option was added as well.

Change-Id: I0d96f9f87106fc41a9853920f557ffad724859e7
Closes-Bug: 1382249
2014-10-28 19:21:26 +00:00
Jenkins
bf439b370a Merge "Update novaclient shell to use shared arguments from Session" 2014-10-24 23:27:42 +00: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
ae6c39397e Enable check for E127
E127 continuation line over-indented for visual indent

Change-Id: I9dfd489565ee2d1469b2048a930c3a8384dd245d
2014-10-23 14:28:50 +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
Morgan Fainberg
c8a7e6a02d Update novaclient shell to use shared arguments from Session
The novaclient implemented it's own version of the CLI arguments that
are now provided by keystoneclient's session object. This changeset
converts nova over to utilizing the shared argument registration.

Change-Id: Ifc9ddc08614e28358229db84cb9b54552ca36d51
Co-Authored-By: David Hu <david.hu@hp.com>
2014-10-22 17:39:44 -07: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
Cedric Brandily
f4709f02c2 Avoid "ambiguous option" when only current/deprecated forms match
argparse.ArgumentParser allows to specify partially options:

  nova boot ... --key-nam mykey
  # is equivalent to
  nova boot ... --key-name mykey

an error is raised if the provided prefix matchs 0 or 2+ options:

  nova boot ... --os value
  # raises an "ambiguous option" error because --os could match
  # --os-username, --os_username ...

even if the provided prefix matchs only the current/deprecated
forms of the same attribute:

  nova boot ... --key mykey
  # raises an "ambiguous option" error because --key could match
  # --my-key, --my_key ...

This change extends argparse.ArgumentParser to avoid raising an
"ambiguous option" when the provided prefix matchs only the current and
deprecated forms of the same attribute.

Change-Id: I1089901de769df3312d4a15b6d6e5e60b1ed51e0
2014-10-13 11:19:21 +02:00
Rakesh H S
09f97e9ee4 return 130 for keyboard interrupt
when keyboard interrupt is received by novaclient, the return code as
of now is 1.

But since the client was terminated by an keyboard interrupt, the return
code should be 130. (http://tldp.org/LDP/abs/html/exitcodes.html)
It is useful when people are writing automation test cases and want to
validate based on the return code.
I have also changed the message that is printed on shell to match other
clients.

Change-Id: If544ade154c53b1f18518773f4d49cd335a394d0
Closes-Bug: #1373231
2014-09-26 20:45:49 +05:30
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
Jenkins
b6246ea844 Merge "Fix variable error for nova --service-type" 2014-08-23 01:50:50 +00:00
liyingjun
c55383f734 Fix variable error for nova --service-type
When running 'nova' with '--service-type' option, it raises an variable
error.

$ nova --service-type compute list
ERROR: local variable 'os_compute_api_version' referenced before
assignment

When '--service-type' option is given, the default value of
'os_compute_api_version' does not apply.

Change-Id: I19554756e8eb56e3a5984ed3078137af9687f986
Closes-bug: 1315368
2014-08-07 08:11:29 +08:00
Christian Berendt
33058cbe8e Enable several checks and do not check docs/source/conf.py
* E265 block comment should start with '# '
* H302 import only modules

Do not check docs/source/conf.py. The file is imported from the
cookiecutter template.

Documented why checks are ignored and if they should be enabled
in the future.

Change-Id: I367064ecaa6d1fd9d918f7ce003303e2db660647
2014-08-05 22:18:14 +02: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
Jenkins
b8e900fe86 Merge "Overwrite HelpFormatter constructur to extend argument column" 2014-06-10 06:43:49 +00:00
Christian Berendt
8bef1e1110 Overwrite HelpFormatter constructur to extend argument column
Overwrite the HelpFormatter constructor in the class
OpenStackHelpFormatter to modify the default value of the
max_help_position to extend the width of the argument column
in the help output.

example output before this patch:

    volume-snapshot-create
                        Add a new snapshot.
    volume-snapshot-delete
                        Remove a snapshot.
    volume-snapshot-list
                        List all the snapshots.
    volume-snapshot-show
                        Show details about a snapshot.

example output after this patch:

    volume-snapshot-create      Add a new snapshot.
    volume-snapshot-delete      Remove a snapshot.
    volume-snapshot-list        List all the snapshots.
    volume-snapshot-show        Show details about a snapshot.

Change-Id: I517098748947e7bded03160a15e778bf79475d0d
Closes-Bug: #1326471
2014-06-04 20:16:46 +02:00
Rick Harris
85faf9cbf0 Add NOVACLIENT_BYPASS_URL env variable
Currently, in order to use a bypass URL, you need to specify it using the
`--bypass-url` command-line option each time, which is inconvenient if you
plan on always using a bypass URL.

This patch adds a `NOVACLIENT_BYPASS_URL` environment variable which can be
placed in the `novarc` to persistently set this option.

Change-Id: I49e67ee1fc3570a43e49dc1d78d8ca0b26945bc8
Closes-Bug: 1326134
2014-06-03 15:33:15 -05:00
Johannes Erdfelt
656cf91f89 Fix error when run with no arguments on Python 3
Python 3 changed the map built-in to return an iterable instead of a list.
When tested in a boolean context, this always returns True, even if it
would not return anything when iterated.

Instead of the usage being printed, this error was printed:
ERROR: 'Namespace' object has no attribute 'func'

Use list comprehension instead to ensure that an iterable isn't returned

Change-Id: Ie15f2fa8ee93ab26490e371133fa0f944430737b
Closes-bug: 1295356
2014-03-25 08:49:05 -07:00
Jenkins
733f1e58d8 Merge "Fix authentication bug when booting an server in V3" 2014-03-25 05:33:57 +00:00
Jenkins
6e3b2878a1 Merge "Show Exception Name in Shell Output" 2014-03-22 09:09:08 +00:00
Solly Ross
0b1a29e7b0 Show Exception Name in Shell Output
Currently, when the CLI encounters an exception, only the exception
message is shown.  However, the name of the exception can be quite
informative as well.

For instance, an error message might read "Cannot do xyz", which
simply indicates the operation was unsucessful.  However, the attached
exception name (HTTPNotImplemented, for instance) indicates the
*reason* that the call was unsuccessful.

Change-Id: I0298477bd9d40d98c95bb797c68c47dbc952b345
2014-03-18 17:23:18 -04:00
Haiwei Xu
02a091cc6c Fix authentication bug when booting an server in V3
Currently when booting a server with V3, novaclient sends an empty
os_password to image_cs. This will cause 401(Unauthorized: Invalid
user/password) when trying to find image. This is is a result of
changes nova's V3 API: nova is no longer used as a proxy for the
image service. So novaclient uses two Client instances: one for
nova, the other for image service. This patch checks os_password
before creating the image Client and assigns it if it's empty.

Change-Id: Ic54cef93e9b823fb98b1edd78776c9a1fc06ba46
Closes-Bug: #1277425
2014-03-08 05:54:39 +00: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
Jenkins
265a6ead1b Merge "Fix spelling miss of password_func variable" 2014-02-15 02:36:12 +00:00
Haiwei Xu
8edc9b6a6a Fix spelling miss of password_func variable
In novaclient/shell.py there is a variable called 'password_fun'
which isn't used anywhere.
In fact it's a spelling miss, and should be modified to 'password_func'
which is used in novaclient/client.py
This patch fixes this bug.

Change-Id: Ibb8e95a2efc77575dcc8544584c708c5c62b7dea
2014-02-13 17:34:19 +09:00
Jenkins
d703381c45 Merge "Fix i18n messages in novaclient, part I" 2014-02-10 02:25:23 +00:00
Sergio Cazzolato
6b070c82d4 Fix i18n messages in novaclient, part I
This change make all the text visible by the user i18n. The
messages changes are in prints, logs, exceptions, helps, etc
Pep8 errors about "Multiple positional placeholders" also fixed

Change-Id: I731afea790baddbc34d059b93a35e3d275fc1df8
2014-01-28 14:56:00 -05: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
Sahid Orentino Ferdjaoui
da11e62216 Using common methods from oslo cliutils
There are some common methods in cliutils we can use in novaclient:
 arg, env, unauthenticated, isunauthenticated.

 + Replaces utils.env to add alias env from cliutils.
 + Replaces utils.arg to add alias arg from cliutils.
 + Removes unused methods: add_arg, unauthenticated, isunauthenticated
   To use methods from clituils.

Related to blueprint common-client-library-2
Change-Id: Ic7c132c37d6a91cf3eae55530300efd153c31903
2014-01-23 09:53:42 +00:00
Alexis Lee
bd9ebc5d27 Don't call CS if a token + URL are provided
Adds --os-auth-token (matching Glance client at least) to accept a
pre-obtained authentication token.

CS will be called iff:
      One or both of token and URL are not provided;
  AND the cache is empty/disabled or we don't have a tenant-id.

Removed some code altering the auth request to a GET if a token is
supplied - did not work for me and I think the path was dead previously.
Fixed test to account for this change.

Completes blueprint token-endpoint-instantiation

Change-Id: I67410b80e506bb80c152223cd113b7139a62a536
2014-01-15 17:11:35 +00:00
Matthew Farrellee
669cdc4ffd Replace some utils.bool_from_str with strutils
Instead of using novaclient.utils' bool_from_str, use bool_from_string
from the oslo incubating strutils

Notes:
 0. utils.bool_from_str was strict, only accepted a small set of
    values, while strutils.bool_from_string is not strict by default,
    anything not true is false
 1. bool_from_string accepts on/off, which bool_from_str did not

Change-Id: I04744844b55697819289def081d3c9117ed0713f
2013-12-25 07:22:24 -05:00
Jenkins
915442404f Merge "Stop using deprecated keyring backends" 2013-12-17 15:31:58 +00:00
Joe Gordon
572f9a985e Stop using deprecated keyring backends
keyring.backend.* was deprecated in python-keyring 1.1 and we already
require keyring 1.6.1. This also makes novaclient compatible with python-keyring 3.0
which removes the deprecated paths.

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728470#10.

Change-Id: I4919ac515e589fddc6044c0cd2f4cbc06c2ec91f
Co-Authored-By: Sebastian Ramacher <sramacher@debian.org>
2013-12-16 15:25:37 -08:00
Jenkins
65f9b9b61e Merge "Allow graceful shutdown on Ctrl+C" 2013-12-14 02:26:59 +00:00
Abhishek Chanda
589f665e29 Allow graceful shutdown on Ctrl+C
Currently it prints a stacktrace and exits. This patch makes it print
a message and exit gracefully.

Closes-Bug: #1256732

Change-Id: I59ae8d09be43cd3e56dbe9bed4f6f328377dcc13
2013-12-13 14:30:04 +05:30
Chris Yeoh
fe7ac8800d Sets default service type for Nova V3 API
Set the default service type when talking to the Nova V3 API to
computev3 rather than compute. Although it is rather ugly to have
a different service type for a different version of a service,
this is necessary for the medium term because traditionally the
compute service endpoint has pointed to the V2 API rather than
the root and then version discovery done.

This change allows progression of the V3 API support in
novaclient and although devstack too currently points computev3
directly to the V3 API, the intent is to change this to point to
the root and implement version discovery during the Icehouse
development cycle.

Longer term when the V2 API support is eventually removed we can
reclaim the 'compute' service type and point it to the root.

Partially implements blueprint v3-api

Change-Id: If5d6a0d8af037cde7bf253d71aac2823b89f8066
2013-12-03 16:32:12 +10:30
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
Joe Gordon
6f9d9df7df Make os-cache retry on an invalid token
client.authenticate doesn't actually do any rest calls if a token is present,
it just assumes the token is valid.  Instead re-authentication is done if the
request raises an Unauthorized exception, at which point we want to
unauthenticate (delete the token from in-memory) and overwrite the old token
in the keyring. Also if a password is present allways pass it into the client
so re-authentication is possible during _cs_request.

Change-Id: I86d0356d5685ffa802f1bdc97e33727ff2dd075e
2013-10-10 10:14:32 -07:00
Joe Gordon
18ad5270f4 Document and make OS_CACHE work
Before the --os-no-cache option logic would overwrite any value set in env['OS_CACHE'].
Since os-no-cache  is deprecated, and also the default value, just remove it.
Also update the help message for --os-cache to mention the environment variable.

Change-Id: Ie2569d5cdf0f12f3a29e9a6f20faef75956d2209
2013-10-10 08:27:32 +00:00
Ben Nemec
211dfe6ea7 Enable v3 api code
Add mappings to enable v3 code

bp v3-api

Change-Id: I035e5b9d65c06ce5691573832bb9b6c4c705b121
2013-08-09 10:47:51 -05:00
Masayuki Igawa
83118620d2 Fix the help text process and the generated wrong help
The wrong help text of bash-completion is generated by the process of
choosing first line from the source code comment. We should get the all
help text from the source code comment, and use it.

So this commit removes this unnecessary process, and also fix the
README.rst for proper help text.

Fixes bug 1206005

Change-Id: Id4f5b6a7722197f09eb366ba8f3e643e1af91805
2013-07-29 15:38:05 +09:00
Jenkins
32f38fe19e Merge "Allow tenant ID for authentication" 2013-07-18 21:51:19 +00:00