164 Commits

Author SHA1 Message Date
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
Jenkins
a45c49bafc Merge "python3: Fix unicode compatibility python2/python3" 2013-07-10 04:09:58 +00:00
Phil Day
02f906bcd6 Allow tenant ID for authentication
Tenant names are not necessarily unique for a User, so the client
should also allow authentication by tenant_id

If both ID and Name are specificed then use the ID

Fixes bug 1195454

Change-Id: Ib62aabc3702db88f02259cd721f9efb31404bcb7
2013-07-03 16:05:13 +01:00
Ben Nemec
b526c9beff Remove Diablo compatibility options
According to the fixme in the code, these should have been removed
in Folsom.

Change-Id: If11c576e45931b72c227f51a0b8f63bc5f7dd4cb
2013-06-26 14:34:01 -05:00
Chuck Short
8c4e145b92 python3: Fix unicode compatibility python2/python3
Python3 enforces the distinction between byte strings and text strings
more rigorously than python2. So use six.text_type/six.u()
where appropriate

Change-Id: I890e19cb857e10f0292aabdaebaa8e7a7bd8db23
Signed-off-by: Chuck Short <chuck.short@canonical.com>
2013-06-24 11:47:15 -05:00
Jenkins
0aa6200544 Merge "catch NoKeyringDaemonError from gnomekeyring" 2013-04-02 16:10:35 +00:00
Jenkins
d195c6a6f7 Merge "Improve authentication plugins management." 2013-04-02 16:10:34 +00:00
Alan Pevec
49ab03e6a6 do not ignore --os-cache
Change-Id: Ib8808da00967163faa9ce05e580605f4e499891d
2013-04-02 12:22:05 +02:00
Alvaro Lopez Garcia
abd75f24b1 Improve authentication plugins management.
The current auth plugin system lacks some functionality to be used with
other methods that might require additional configuration options or
that do not require a user to pass some options that are now compulsory
(for example, X.509 authentication needs to get a certificate file, and
does not need either a username or a password). This commit extends
the current system to handle these extra features, while remaining
compatible with older plugins.

DocImpact: We should documment how to implement additional
authentication plugins, such as BasicAuth, X509, etc.
Implements: blueprint authentication-plugins

Change-Id: I7b0ef4981efba8160dea94bf852dba7e2e4068f5
2013-04-01 14:19:01 +00:00
Davanum Srinivas
adb5941df9 catch NoKeyringDaemonError from gnomekeyring
Looks like we need to add more exceptions, start to maintain
a tuple of exceptions

Change-Id: I3a027f5d2d8f82fe397e3096ff82358040f3729e
2013-03-31 18:45:49 +00:00
Alvaro Lopez Garcia
e9e05d7dfe Set up debug level on root logger.
If we set up the debug level on the root logger, this can be used by the
submodules that might need to print some debug output.

Change-Id: I2a00b40d4748cc62e6081df7d6a44622f5ad4467
2013-03-15 10:28:12 +01: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
Jenkins
b01ce12995 Merge "Decodes input and encodes output" 2013-03-11 16:37:11 +00:00
Alvaro Lopez Garcia
f1e5a88d2b Fix typo in error message
Change-Id: Ia37ec318329dc527b30a1835e4a52ace14b2bda3
2013-03-07 09:40:42 +01:00
Flaper Fesp
47e6bc25ae Decodes input and encodes output
Currently novaclient doesn't handle properly incoming and outgoing
encode / decode process. As a solution for this, this patch implements a
decoding process for all data incoming from the user side and decodes
everything going out of the client, i.e: http requests, prints, etc.

This patch introduces a new module (strutils.py) taken from
oslo-incubator in order to use 2 of the functions present in it:

About safe_(decode|encode):

    Both functions try to encode / decode the incoming text using the
    stdin encoding, fallback to python's default encoding if that
    returns None or to UTF-8 as the last option.

    In both functions only basestring objects are accepted and they both
    raise TypeError if an object of another type is passed.

About the general novaclient changes:

    In order to better support non-ASCII characters, it is a good
    practice to use unicode interanlly and encode everything that has to
    go out. This patch aims to do that and introduces this behaviour in
    the client.

Testing:

    A good test (besides using tox) is to use nova client with and
    without setting any locale (export LANG=).

Fixes bug: 1061156

Change-Id: I20b75e42b0c3dac89f1048faa1127253a64f86c7
2013-03-04 19:01:27 +01:00
Vasyl Khomenko
8ac304f7f5 Fixed bug with password prompt, added tests
Fixes: bug #1131237

Change-Id: Ifcd9543ed5ac9526e32025ff3acd51d36b27a224
2013-03-04 11:00:44 +00:00
Jenkins
4e2c829135 Merge "A minimum of Python3 fixes so that installation works without errors/warnings." 2013-03-01 23:50:39 +00:00
Davanum Srinivas
34c8a6bb7a Missing import for gnomekeyring
follow on to previous attempt to fix to bug 1116302,
looks like we missed an import

Fixes LP#1116302

Change-Id: If56e3cedaa63a594907bb851a2701bd64806ed85
2013-02-21 11:41:02 -05:00
Thomas Schreiber
68e6af73ba A minimum of Python3 fixes so that installation works without errors/warnings.
Fixes bug: 1130937
Change-Id: I740652fcd5804fc1c120fc409afdf4693c8e5781
2013-02-20 23:17:49 +01:00
Jenkins
76bacaa645 Merge "Allow extensions to provide a name when discovered on the python path." 2013-02-15 23:41:42 +00:00
Davanum Srinivas
132465231a Issue when gnomekeyring is present but not the current backend
Issue was identified in the review for the previous
patch for bug 1116302. Took this chance to rename _IOError
to a better name (KeyringIOError)

Change-Id: I321353d519eaebea27617702f92ecafe2052eb8e
2013-02-15 10:11:51 -05:00
David Scannell
c0e85a84b0 Allow extensions to provide a name when discovered on the python path.
Using novaclient with some extensions via python code, you might have an
invocation like this:

    extensions = shell.OpenStackComputeShell()._discover_extensions("1.1")
    novaclient = Client("1.1", user, apikey, project, authurl, extensions=extensions,
                        endpoint_type=shell.DEFAULT_NOVA_ENDPOINT_TYPE,
                        service_type=shell.DEFAULT_NOVA_SERVICE_TYPE)

If you have an extension like 'myextension.py' in the v1_1/contrib directory, you'll
end up with a very sensible attribute on the resulting novaclient object, i.e.

    novaclient.myextension

If you have a package distributed in the package myextension_python_novaclient_ext,
then it'll automatically be picked up as an extension (awesome!) but the name is not
as intuitive.

    novaclient.myextension_python_novaclient_ext

This patch simply changes this to allow the Extension to provide a name for itself.
The possibility of collisions exists, but is not really any more significant than
before (where you might have different versions of the same package installed in the
system or heck, even a bizarrely named 'myextension_python_novaclient_ext.py' in the
contrib/ directory).

Fixes bug 1058366

Change-Id: Ie68463ffd7a939744e035b20fd50a7dc8da605de
2013-02-14 13:22:25 -05:00
Davanum Srinivas
d1d4f33aca Fix IOError with gnomekeyring.find_network_password_sync
find_network_password_sync throws a gnomekeyring.IOError
when a non-root user tries to run nova client
from a ssh console. If we don't catch this exception nova client
throws the traceback (shown in the bug report) and stops.
If we catch this exception (just like we catch ValueError),
and return None, Nova client executes just fine.

Fixes LP# 1116302

Change-Id: If6937b3f8eafb1dc55224b2ca2bd0f93ae07f8c6
2013-02-14 11:58:08 -05:00
Joe Gordon
96630b8248 Upgrade to pep8 1.3.3
Also expand scope of what is covered by pep8 test

Change-Id: Ifc8924914b5a0d625bc8df6442ee85eb21459cde
2013-02-01 12:24:19 -08:00
Vishvananda Ishaya
1e4a778bf8 Store tenant_id from keystone and use for quotas
Some calls in nova require a tenant_id when it could be interpreted
from the current authentication data, so save the tenant id and
use it in the quotas command if tenant_id is not specified.

Change-Id: I89647cfe9da73bc474ef80a61a5678db42a5571c
2013-01-31 14:38:21 -08:00
Joshua Harlow
7c6f538cf6 Fix the usage of password, keyrings, and tokens.
Fix how you keep on getting prompted for the password
all over the place and at the wrong time (the keyring code
should be used before a auth request, and not during).

Fix this by trying to use the token first (which comes from
the keyring module), then falling back to using the password
(which will get a token, and then store said token so that it
 isn't fetched again).

Change-Id: I58e69f3b3fbcc7a467797f25695b7ca59178a1d7
2013-01-30 12:53:47 -08:00