70 Commits

Author SHA1 Message Date
Dean Troyer
6c269efda8 Use osc-lib and set up deprecation warnings
The initial use of osc-lib is behind the compatibility/deprecation
modules that we will leave in place for a time for plugins to catch
up.

* openstackclient.common.exceptions
* openstackclient.common.utils

Module-level warnings are emitted directly on stderr since logging
has not been configured yet.

Change-Id: I79e57ce9523a20366bccaf9b949ab5906792ea0d
2016-06-10 08:35:54 -05:00
Huanxuan Ao
b36d521ff6 Fix i18n supports in commom
I checked all the files in openstackclient/common
and fixed the missing i18n supprots.

Change-Id: Id7f76a24aae663f5832ef9bcf1bd5a6b7081af24
Partial-bug: #1574965
2016-06-07 19:56:00 +08:00
Hidekazu Nakamura
55b37d5e33 Don't mask authorization errors
Project show with name argument returns 'Could not find resource'
error when the user is not authorized. It should report the
authorization error instead. This patch makes that change.

Change-Id: Iac3521f8a411060b0ec9ef46c8f0e1f3551e56ae
Closes-Bug: #1511625
2016-04-01 16:44:33 -04:00
Tang Chen
dc7e4fc15d Fix dict.keys() compatibility for python 3
In Python 2, dict.keys() will return a list.
But in Python 3, it will return an iterator.
So we need to fix all the places that assuming
dict.keys() is a list.

Change-Id: I8d1cc536377b3e5c644cfaa0892e40d0bd7c11b1
Closes-Bug: #1556350
2016-03-12 10:58:28 +08:00
ting.wang
dc5a8faddd Fix Mutable default argument
Python’s default arguments are evaluated once when the function is defined,
not each time the function is called. This means that if you use a mutable
default argument (like list and dict) and mutate it, you will and have mutated
that object for all future calls to the function as well.

more details about this wrong usage here:
http://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments

Change-Id: If187f16bfb305ac4fe6e4177e498a06c49c3f946
2016-02-20 16:35:11 +08:00
Jenkins
e4c0d8583d Merge "Allow wait_for_delete to work for all clients" 2016-02-04 00:39:47 +00:00
Jenkins
65f8845ea8 Merge "Add "os port show" command" 2016-02-03 21:01:17 +00:00
Richard Theis
981621e984 Add "os port show" command
Add "os port show" command.

Change-Id: Id87c81640e74c60ae8f247c722c64fdadff022a2
Partial-Bug: #1519909
Partially-Implements: blueprint neutron-client
2016-02-02 08:40:05 -06:00
Akihiro Motoki
a05d9fd9f1 Drop log_method decorator
As a result of the recent logging refactoring, log_method decorator
is no longer required. oslo.log provides a similar decorator
oslo_log.helpers.log_method_call. If a similar feature is needed,
we can use the decorator from oslo_log.

searchlightclient is the only OSC external plugin which uses this
decorator. The depending patch removes it, so we can safely drop
the decorator.

Change-Id: If3df09cf6aa0a401d9f89e8924adce851d0c6dec
Depends-On: Ib94e7ba77262a9a8cbfce71f3083c47cb1973364
2016-02-02 12:51:24 +09:00
Mark Vanderwiel
5903ffff8a Allow wait_for_delete to work for all clients
Allow the exception and error status
strings to be passed in such that other plugins can
make use of this function.

There is a comment in find_resource:
  The exception to catch here is dependent on which
  client library the manager passed in belongs to.
  Eventually this should be pulled from a common set
  of client exceptions.

Since I think that is a long ways off, this change will
work now and also work when a common exception is defined
and used.

Change-Id: Iab56cd1166028caed4f1e657e0b1ee81af3f48d8
2016-01-28 10:52:45 -06:00
Akihiro Motoki
50d54bb007 log_method: get logger from decorated method if unspecified
This commit makes 'log' optional.
'log' attribute of each command class does not exist
when the class is defined because 'log' is now setup
dynamically when a class is instantiated. Instead log_method
looks for a logger from a decorating method.

compute.v2.server is changed in this commit as an example.

Change-Id: Ic4d128f8e027d3b8e6f884f31369e9085c0f0871
Partial-Bug: #1532294
2016-01-20 22:02:19 +09:00
Jenkins
9317df07a2 Merge "Trivial: Remove useless string_to_bool()" 2016-01-08 06:23:32 +00:00
Tang Chen
5f0147ad12 Trivial: Remove useless string_to_bool()
string_to_bool() is not used by anyone.
Furthermore, it is not well designed. It tries to convirt 't', '1'
to True, which could be confused.

So remove it. If we need something similar, let's make a better one.

Change-Id: Ic1f63480c806bf7bcc9f541fc806eed297ddf718
2015-12-29 10:50:44 +08:00
Richard Theis
0e38ef8484 Improve output for "os security group show"
Improve the security group rules output when running the
"os security group show" command. Each security group rule
is now displayed on a separate line.

Current output example:
$ openstack security group show default
+-------------+------------------------- ... ---+
| Field       | Value                    ...    |
+-------------+------------------------- ... ---+
| description | Default security group   ...    |
| id          | 048a5fc3-3be1-407d-ae47-9...    |
| name        | default                  ...    |
| project_id  | 3b96bb2020c1459da76963f9e...    |
| rules       | [u"id='5d812367-9829-4340...t"] |
+-------------+------------------------- ... ---+

New output example:
+-------------+------------------------- ... ---+
| Field       | Value                    ...    |
+-------------+------------------------- ... ---+
| description | Default security group   ...    |
| id          | 048a5fc3-3be1-407d-ae47-9...    |
| name        | default                  ...    |
| project_id  | 3b96bb2020c1459da76963f9e...    |
| rules       | id='5d812367-9829-4340-95...lt' |
|             | id='ee451d1c-ade3-4975-8e...lt' |
+-------------+------------------------- ... ---+

Change-Id: I1386075310896c58a2b776e2bbec3603bd00eff1
Partial-Bug: #1519511
Related-To: blueprint neutron-client
2015-12-23 13:44:22 -06:00
Tang Chen
c48afe6032 Trivial: Fix a typo.
Change-Id: I236b4f53ee23cc97900e6244ab709404cc44a4ca
2015-11-27 13:20:44 +08:00
Tang Chen
f3c69ceeb5 Trivial: Add missing doc for parameter in wait_for_delete().
The doc of parameter manager is missing.

Change-Id: I4e99c06ab713532d73615670ada0a61462285d76
2015-11-26 10:19:01 +08:00
Jenkins
42a5909f6a Merge "Trivial: Fix wrong doc for wait_for_status()." 2015-11-23 06:07:37 +00:00
Tang Chen
6957fb3ee7 Trivial: Fix wrong doc for wait_for_status().
Two trivial fixes:
1. docs for parameters are not sorted correctly
2. missing doc for a parameter

Change-Id: I0cfb65e0f897c391b9b6e7225251e88855b07a56
2015-11-24 09:22:22 +08:00
Tang Chen
319fc09430 Trivial: Remove doc for non-existing param in format_dict().
There is no parameter named format.

Change-Id: I286006430efb2850b978b6f2abaed87216156d12
2015-11-21 19:02:32 +08:00
Mark Vanderwiel
71e1adeaf0 Allow error status to be specified
For some apis, heat, the error status is "failed". This patch
changes the wait_for_status method to allow for the error
status to be passed in the same way as the success status.

Change-Id: I20db4051d3f5611a4b13fe23ea8798b82a40da81
2015-11-18 17:48:43 -06:00
Steve Martinelli
cfd2bf5882 validate non-ascii values for swift properties
skip properties that are non-ascii values, but proceed
with properties that work. log these failed values back
to the user.

Change-Id: Iaca8909f4465a01c8aebfd290b1a322823702359
Closes-Bug: 1503898
2015-11-12 11:07:57 -06:00
Steve Martinelli
83282bc5e1 attempt to find resource by listing
add a last-ditch effort to find the resource in question by
listing all the resources and doing a simply match for name and
id. if no match is found then raise an error, if the list call
is unsuccessful, raise the same error. we have failed this city.

Closes-Bug: #1501362

Change-Id: I0d3d7002e9ac47b17b1ef1a5534406c85b1fc753
2015-09-30 09:58:44 -05:00
Steve Martinelli
05f5e043d8 Additional exception handling for find_resource
A few things here: 1) we need to check if the client class even
has a 'resource_class', in the case of glanceclient, it does not.

2) If everything fails we should print a better error message,
rather than a "find" failed, since some clients don't support find.

Change-Id: I6277322639e75b1635f9f3d159753efadbce1031
2015-09-30 09:54:28 -05:00
Joshua Harlow
e3c46ece4a Use a common decorator to log 'take_action' activation
Instead of duplicating the same log statement throughout
the code, the same logic can be provided by a shared decorator
that abstracts away the logging capability and unifies it behind
a common function instead.

Change-Id: Icc63bced7347c8bbf0299a4c5821425a10892a79
2015-09-01 16:49:54 -07:00
TerryHowe
643d1d90fe More minor docs fixes
Change-Id: Ia74b8e14bacb562d9bac29221f511acbab5296df
2015-07-19 07:03:57 -06:00
Jenkins
ee64c2fa6b Merge "Add --os-endpoint-type cli optional argument" 2015-07-03 02:48:47 +00:00
Roxana Gherle
5521e4c504 Add --os-endpoint-type cli optional argument
User should be able to specify the endpoint type through
a CLI optional argument/ENV variable setting. We will name this new
optional argument: --os-endpoint-type (Env: OS_ENDPOINT_TYPE) and
based on the value given, the service API will use that specific
endpoint type. Possible values: public, admin, internal.

DocImpact
Closes-Bug: #1454392
Change-Id: Ife3d4e46b44c0ddcd712b1130e27e362545a9a29
2015-07-02 10:10:46 -07:00
Rodrigo Duarte Sousa
4fab606349 Enables retrieval of project's parents and subtree
Adds the possibility to retrieve a project and list its
parents and subtree in the hierarchy.

Co-Authored-By: Rodrigo Duarte <rodrigods@lsd.ufcg.edu.br>
Co-Authored-By: Samuel de Medeiros Queiroz <samuel@lsd.ufcg.edu.br>

Implements: bp hierarchical-multitenancy

Change-Id: I874f6faffc8a2db9d99f12cbe0a69c0a30c0d9df
2015-06-09 13:10:22 -03:00
Matt Riedemann
224d375ef4 Add --wait to server delete
This allows the server delete command to wait for the server to be
deleted (obviously).

The wait method is the same model that Tempest uses, i.e. wait for a 404
on server GET (successful deletion), fail if the server went to ERROR
status, or fail if a timeout is reached.  The default timeout of 300
seconds is also what Tempest uses.

Closes-Bug: #1460112

Change-Id: I0e66c400903e82832944d1cad61e7eb30177c3e8
2015-05-29 14:32:51 -07:00
Jenkins
9ce112f1a1 Merge "Fix error msg in sort_items" 2015-03-02 17:16:04 +00:00
Terry Howe
1186cb4c9f change oslo namespace to avoid warning
Change-Id: Ieff86f841623e1ce34b79c66bc5e8b1b239fa3e9
2015-02-25 17:38:34 +00:00
zhiyuan_cai
d13023b32a Fix error msg in sort_items
Include direction users pass in the error msg to help users know
which part of the argument is troublesome.

Change-Id: I796a85fbf40f6ddf544fb52a61f967e1914abdcc
Closes-Bug: #1420732
2015-02-11 20:35:08 +08:00
zhiyuan_cai
42cff38834 Add sort support to image list
Add sort support to image list by sorting items in the client side.
The parameter syntax follows this spec[1].

[1] https://review.openstack.org/#/c/145544/

Change-Id: I42b487d18f00f937db1938daa46487cea2a896ab
Closes-Bug: #1410251
2015-02-06 10:57:10 +08:00
Steve Martinelli
364071a90b Add domain parameters to user show for Identity V3
Update `user show` for Identity V3 to account for a domain argument,
in doing so, also update `find resource` to be more flexible by
allowing **kwargs.
Also update `group show` and `project show` since they follow the
same logic as a user within a group.

Change-Id: Ib828e4dbeb0bd31164396069ce8a64c873179779
Closes-Bug: #1378165
2014-10-09 14:34:48 -04:00
wanghong
7029cf37e2 utils.find_resource does not catch right exception
Currently, utils.find_resource catch NotFound exception defined in
openstackclient. However, different client libraries raise different
exceptions defined in thire own library.

Change-Id: Idc40428e30e59f71dbdbfa0555c0066fddc441c2
Closes-Bug: #1371924
2014-09-24 11:04:41 +08:00
Oleksii Chuprykov
ffe976ce3e Use oslo.utils
Module `importutils` from common code was graduated to oslo.utils,
so it would be great if we reuse this library.
Remove unused strutils.py and gettextutils.py

Change-Id: Iaae19fc5018d83103e5f15ff76d6da686bfdf5f8
2014-09-22 13:07:31 +03:00
Jenkins
3317e0abf6 Merge "Add action 'user password set' for identiy v3" 2014-09-07 15:12:18 +00:00
Jenkins
dcf658cc4e Merge "Unordered dicts and lists causes variable results" 2014-09-07 12:59:35 +00:00
Mouad Benchchaoui
0069adef5c Add action 'user password set' for identiy v3
This new action will allow a user to change their own password by
either providing the new password as an argument (--password) or by
being prompted to enter the new password.
In both cases user will be prompted to enter their current password
as required by the v3 API.

Closes-Bug: #1337245
Change-Id: I5e1e0fd2b46a4502318da57f7cce2b236fb2d93d
2014-09-07 02:37:54 -04:00
Terry Howe
514ecc6e96 Unordered dicts and lists causes variable results
The unordered dict and lists causes variable results.  The user
may see different results and tests can fail.  Might as well make
this more consistent.

Change-Id: I7045b40b44cbf3ee0f2ca79c6ea0d279b6d8cfe3
2014-09-06 23:55:31 -04:00
Aaron Rosen
c43854048c Leverage openstack.common.importutils for import_class
This patch drops the import_utils method from common.utils and leverages
it from openstack.common.importutils instead.

Change-Id: If7e7383aa742afe44f750f916c0d90d747793150
Closes-bug: 1365273
2014-09-06 23:36:59 -04:00
Cyril Roelandt
1fedd38de6 Python 3: remove a useless code to safe_encode()
The safe_encode method returns bytes, so we cannot concatenate its output with
text strings. This call does not seem needed after all, so let's just remove
it.

Change-Id: I6c18427559147d4c732ff7daa6d6006e7e5f6365
2014-07-04 10:25:53 +02:00
Terry Howe
8f59524c3e Network CRUD
bp/neutron
https://wiki.openstack.org/wiki/OpenStackClient/Commands#Network_2

Change-Id: I89ee083154afa544b03587e84becace36d9d522a
2014-06-24 15:00:25 -06:00
Terry Howe
0b2987fef3 Fix find_resource for keystone and cinder
The find_resource method had two hacks in in to support cinder
and keystone and I have removed those in favor of a monkey patch
for cinder.

The find_resource method used to attempt to UUID parse the id, but
it would do a manager.get anyway.  I changed it to skip the UUID
parsing.  This will make things run minorly faster and it supports
LDAP for keystone.

The find_resource used to attempt to use display_name=name_or_id
when finding.  This was a hack for cinder support, but it breaks
keystone because keystone totally messes up with the bogus filter
and keystone refuses to fix it.

Change-Id: I66e45a6341f704900f1d5321a0e70eac3d051665
Closes-Bug: #1306699
2014-06-17 10:24:26 -06:00
Steve Martinelli
01db6d977f move read_blob_file_contents to utils
Thinking ahead, a few other upcoming keystone features could
benefit from reading contents from a file. Thus, moving the
function from policy to utils.

Change-Id: I713ab0e5a00c949ad996daf83b775a7c19044888
2014-04-14 22:16:59 -05:00
Terry Howe
4900c64d09 Produce a useful error message for NoUniqueMatch
Most of the CLIs use a NoUniqueMatch, so produce a useful
error message if that happens.  Added some tests for
find_resource as well.

Change-Id: I85ba61d5f6d1be5bd336a1cc4b02501492905f33
Closes-Bug: #1293846
2014-03-17 17:32:41 -06:00
Terry Howe
033f27fe4d Add ability to prompt for passwords for user create and set
* Add get_password method to the utilities
* Add --password-prompt option
* Call the get_password method if a prompt is requested
* Various tests

Change-Id: I1786ad531e2a2fbcc21b8bc86aac0ccd7985995a
Closes-Bug: 1100116
2014-02-21 14:42:22 -07:00
Florent Flament
a5e087e7a9 Displaying curl commands for nova and cinder calls
When using the -v option, displays curl equivalent commands and http
messages exchanged with the nova and cinder API servers. Displays the
same messages as those displayed with the --debug option of
python-novaclient and python-cinderclient.

Implements: blueprint curl-commands-in-debugging-messages for nova and
cinder related calls

Change-Id: Ibc8ef79d874334585b81d652b9c7df9e874fffa9
2014-01-02 11:08:53 +01:00
Dean Troyer
17f13f7bf4 Create a new base REST API interface
* restapi module provides basic REST API support
  * uses dicts rather than Resource classes
  * JSON serialization/deserialization
  * log requests in 'curl' format
  * basic API boilerplate for create/delete/list/set/show verbs
* ignore H302 due to urllib import

Change-Id: I3cb91e44e631ee19e9f5dea19b6bac5d599d19ce
2013-08-23 12:08:32 -05:00
Jenkins
f293027815 Merge "Remove tenant round 3 - other commands" 2013-07-31 22:30:12 +00:00