summaryrefslogtreecommitdiff
path: root/openstackclient/shell.py
Commit message (Collapse)AuthorAgeFilesLines
* arguments are not locale decoded into UnicodeJohn Dennis2017-01-161-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the openstackclient in Python2 passes command line arguments to a subcommand it fails to pass the arguments as text (e.g. Unicode). Instead it passes the arguments as binary data encoded using the current locales encoding. An easy way to see this is trying to pass a username with a non-ASCII character. % openstack user delete ñew No user with a name or ID of 'ñew' exists. What occurs internally is when the user data is retrieved it's it properly represented in a Unicode object. However the username pased from the command line is still a str object encoded in the locales encoding (typically UTF-8). A string comparison is attempted between the encoded data from the command line and the Unicode text found in the user representation. This seldom ends well, either the comparison fails to match or a codec error is raised. There is a hard and fast rule, all text data must be stored in Unicode objects and the conversion from binary encoded text to Unicode must occur as close to the I/O boundary as possible. Python3 enforces this behavior automatically but in Python2 it is the programmers job to do so. In the past there have been attempts to fix problems deep inside internal code by attempting to decode from UTF-8. There are two problems with this approach. First, internal code has no way to accurately know what encoding was used to encode the binary data. This is way it needs to be decoded as close to the I/O source as possible because that is the best place to know the actual encoding. Guessing UTF-8 is at best a heuristic. Second, there must be a canonical representation for data "inside" the program, you don't want dozens of individual modules, classes, methods, etc. performing conversions, instead they should be able to make the assumption in what format text is represented in, the format for text data must be Unicode. This is another reason to decode as close to the I/O as possible. In Python3 the argv strings are decoded from the locales encoding by the interpreter. By the time any Python3 code sees the argv strings they will be Unicode. However in Python2 there must be explicit code added to decode the argv strings into Unicode. The conversion of sys.argv into Unicode only occurs when argv is not passed to OpenStackShell.run(). If a caller of OpenStackShell.run() supplies their own arg it is their responsiblity to assure they are passing actual text objects. Consider this a requirement of the API. Note: This patch does not contain a unittest to exercise the behavior because it is difficult to construct a test that depends on command invocation from a shell. The general structure of the unit tests is to pass fake argv into OpenStackShell.run() as if it came from a shell. Because the new code only operates when argv is not passed and defaults to sys.argv it conflicts with the unittest design. Change-Id: I779d260744728eae8455ff9dedb6e5c09c165559 Closes-Bug: 1603494 Signed-off-by: John Dennis <jdennis@redhat.com> (cherry picked from commit 756d2fac67b4128312e1d779648e62f1458b4ffc)
* Fix regression in interactive client modeDina Belova2016-03-011-1/+1
| | | | | | | | Fix typo introduced in OSprofiler intergation commit, that leaded to non-working interactive mode of the CLI client. Change-Id: If5dfc90dbbe64d4665c3e33e936f0cc674738351 Closes-Bug: 1551160
* Merge "Add shell --profile option to trigger osprofiler from CLI"Jenkins2016-02-261-0/+51
|\
| * Add shell --profile option to trigger osprofiler from CLIDina Belova2016-02-251-0/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This will allow to trigger profiling of various services that allow it currently and which APIs support is added to openstackclient. Cinder and Glance have osprofiler support already, Nova and Keystone are in progress. To use this functionality osprofiler (and its storage backend) needs to be installed in the environment. If so, you will be able to trigger profiling via the following command, for example: $ openstack --profile SECRET_KEY user list At the end of output there will be message with <trace_id>, and to plot nice HTML graphs the following command should be used: $ osprofiler trace show <trace_id> --html --out result.html Related Keystone change: https://review.openstack.org/#/c/103368/ Related Nova change: https://review.openstack.org/#/c/254703/ The similar change to the keystoneclient (https://review.openstack.org/#/c/255308/) was abandoned as new CLI extenstions are not more accepted to python-keystoneclient. Change-Id: I3d6ac613e5da70619d0a4781e5d066fde073b407
* | Support unscoped token requestguang-yee2016-02-191-0/+3
| | | | | | | | | | | | | | | | Make scope check optional for the "token issue" command as unscoped token is a valid Keystone V2/V3 API. Change-Id: Ie1cded4dbfdafd3a78c0ebdf89e3f66762509930 Closes-Bug: #1543214
* | Fix 'openstack --help' fails if clouds.yaml cannot be readHideki Saito2016-02-141-4/+9
|/ | | | | | | | 'openstack --help' can display the basic information, even if openstack command does not have permission to read clouds.yaml. Change-Id: I7d5255c5ce3bd60af77fc70f433ca78dc011a79f Closes-Bug: #1541047
* The format_exc method does not take an exceptionTerry Howe2015-12-081-1/+1
| | | | | | | | | | For py35, this call blows up. Seems to be ignored for py27, but even in py27, it doesn't take an exception. https://docs.python.org/2.7/library/traceback.html https://docs.python.org/3/library/traceback.html Change-Id: I2602426b966045b15b96e5e41d0df6524ed05119
* Allow int version numbers in the clouds.yamlTerryHowe2015-11-041-1/+1
| | | | | | | | OSC blows up if you try to use for example identity_api_version: 2 in the clouds.yaml. It will only work with a string '2'. This fixes that. Change-Id: I785d37a288126a1582464e907c7f9c9947bac27c
* Merge "Rename context.py to logs.py"Jenkins2015-10-301-4/+2
|\
| * Rename context.py to logs.pyTerry Howe2015-10-301-4/+2
| | | | | | | | | | | | | | | | | | At one point this file contained the context for logging, but the reason for its existence is now for logging. Implements: blueprint logging-migration Change-Id: I4ba42bbef97b09d31236ac8c01b6fb23827b8bee
* | Merge "Allow debug to be set in configuration file"Jenkins2015-10-301-0/+6
|\ \ | |/
| * Allow debug to be set in configuration fileTerryHowe2015-10-301-0/+6
| | | | | | | | | | | | | | | | | | | | | | The current default value for debug in cliff is False. Cloud config assumes that it was set that way on the command line and does not overlay it with the value from the configuration file. Cliff bug: https://bugs.launchpad.net/python-cliff/+bug/1483378 Change-Id: I66d82b489b2241dbcd1e1350e94259a54ce09de7
* | Mask the sensitive values in debug loglin-hua-cheng2015-10-121-3/+7
| | | | | | | | | | Change-Id: I0eb11a648c3be21749690f079229c8e63a678e6c Closes-Bug: #1501598
* | Merge "Override the debug default and help text"Jenkins2015-09-241-0/+4
|\ \
| * | Override the debug default and help textTerryHowe2015-08-181-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Cliff sets the default debug value to False and this makes it impossible to override debug with OCC. If we set the default to None, we can override debug in clouds.yaml. Also, OSC changes the meaning of --debug, so modify the help text. Change-Id: I5e6680b2286cd7f55afe4b083fae5f8a4a9567a2 Closes-Bug: #1483378
* | | Merge "Set default auth plugin back to 'password'"Jenkins2015-09-211-1/+1
|\ \ \
| * | | Set default auth plugin back to 'password'Dean Troyer2015-09-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | This was a hack that should be less needed now... Change-Id: Id8cba87ad05b106aa36e356c0d70a568316fd327
* | | | Move option logging back to start if initialize_app()Dean Troyer2015-09-181-2/+2
|/ / / | | | | | | | | | | | | | | | | | | The log for the options should be printed early enough to see what is being passed in to occ. Change-Id: I97b09bc28abcd485b6793d0223b9f8602237fd80
* | | Merge "Create log configuration class"Jenkins2015-09-091-56/+5
|\ \ \ | | |/ | |/|
| * | Create log configuration classTerryHowe2015-08-261-56/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Configuration of logging gets triggered twice. The first time it uses the CLI options when the application is started and second it uses the configuration file after that is read. The state of the logging needs to be saved from the first to the second time, so I created a class. Implements: blueprint logging-migration Change-Id: I7b8d1a3b6fd128e98cafd7c16009c7b694a52146
* | | Merge "Move options to log level out of shell.py"Jenkins2015-09-091-12/+1
|\ \ \ | |/ /
| * | Move options to log level out of shell.pyTerryHowe2015-08-131-12/+1
| | | | | | | | | | | | | | | | | | | | | | | | Move the conversion of command line options to log level out of shell.py. Change-Id: I86cb45a85cd63927aa1c87c1eed27542981df659 Implements: blueprint logging-migration
* | | Merge "Move set warnings filters to logging module"Jenkins2015-09-081-4/+1
|\ \ \ | |/ /
| * | Move set warnings filters to logging moduleTerryHowe2015-08-131-4/+1
| | | | | | | | | | | | | | | | | | | | | This is the first step in moving logging out of shell.py Change-Id: I3dcb4e17bb4687988ddf9b793ad1a308ef89b242 Implements: blueprint logging-migration
* | | Merge "Set up every time record log in file"Jenkins2015-09-081-11/+44
|\ \ \ | |/ /
| * | Set up every time record log in fileDaisuke Fujita2015-08-081-11/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | This will allow users to record logs of all their commands into a predefined log file, in clouds.yaml. The log should have a format similar to that of oslo.log. Change-Id: I1b334bf429d575fc25809c9706fc0b11116be3f1 Implements: blueprint every-time-record-log-in-file
* | | Fix compute API version snafuDean Troyer2015-09-041-5/+17
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | novaclient 2.27.0 introduced the API microversion discovery and client.Client now wants an api_version argument to properly work out the correct API version in use. OSC needs to provide this when required. Letting the compute client plugin do the version validity checking makes more sense than encoding it into shell.py, so I've added a new OSC plugin interface function check_api_version() that is called from shell.py if it exists. If it either does not exist or it returns False the previous version checking using API_VERSIONS is still performed. compute.client.check_api_version() conditionally imports the new novaclient.api_versions module and uses it if successful. Otherwise check_api_version() returns False and the previous code path is resumed. One side-effect of this is that it is now valid to use --os-compute-api-version with any valid microversion supported by the installed python-novaclient. Closes-Bug: #1492467 Change-Id: I4535b38a5639a03a9597bf83f6394f9bb45c2b9e
* | Merge "Do not set default versions in parsed args"Jenkins2015-07-241-1/+3
|\ \ | |/ |/|
| * Do not set default versions in parsed argsTerryHowe2015-07-181-1/+3
| | | | | | | | | | | | | | | | | | | | | | Setting default versions in parsed args makes it so OCC cannot tell if the argument was parsed, an environment variable was set or it is just defaulted. In order to set api versions from OCC, it will have to be defaulted after processing OCC. Closes-Bug: #1453229 Change-Id: I4d065919397b783f3bdd4022c986c0234a7a16e6
* | Fix the way auth_type default value is overridenJavier Pena2015-07-201-3/+4
|/ | | | | | | | | | | | | Commit 50f05448982b5fafd9d9a7783b639dd145090a0d to os-client-config removed the default values in the _defaults dict. This makes any call to cloud_config.set_default() before initializing the dict fail. The fix changes the way the auth_type default is overriden, by doing it when cloud_config.OpenStackConfig() is executed. Change-Id: If37d3ba303f01d4c77fd7c15a3cde9634534b64a Closes-bug: #1473921
* Rename endpoint type to interfaceTerryHowe2015-07-151-9/+9
| | | | | Change-Id: I4e21d09bc747e8210f4f79a1d6c4c7ccf2f25d1c Closes-Bug: #1454392
* Merge "Add --os-endpoint-type cli optional argument"Jenkins2015-07-031-1/+13
|\
| * Add --os-endpoint-type cli optional argumentRoxana Gherle2015-07-021-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | 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
* | Fix the typo in `openstackclient/shell.py`Dave Chen2015-06-141-2/+2
|/ | | | Change-Id: Ia101f6d50ecd4a195aa93b1f289def581b0c6f38
* Allow --insecure to override --os-cacertDean Troyer2015-06-041-6/+15
| | | | | | | | | | | | | Change --insecure to ignore the --os-cacert setting. This is a change from before where OSC followed the requests pattern of cacert taking priority. This logic is also introduced in os-client-config 1.3.0; we do not require that release yet so it is duplicated here for now. That change will come with the upcoming global options refactor. Closes-Bug: #1447784 Change-Id: Iaa6d499ed0929c00a56dcd92a2017487c702774a
* Rework shell testsDean Troyer2015-06-021-1/+3
| | | | | | | | | | | This is the first step in reworking the shell argument handling, clean up and add tests to ensure functionality doesn't change. * Rework shell tests to break down global options and auth options. * Make tests table-driven * Remove 'os_' from 'cacert' and 'default_domain' internal option names Change-Id: Icf69c7e84f3f44b366fe64b6bbf4e3fe958eb302
* Merge "Set tenant options on parsed namespace"Jenkins2015-06-021-0/+17
|\
| * Set tenant options on parsed namespaceJamie Lennox2015-05-311-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because of the way OSC registers all plugins together we end up with os-tenant-X parameters being saved to the project-X attribute after parsing. If you are using the v2 plugins directly then they and os-client-config expect the tenant_X values and will assuming no scoping information if they are not present. Validating options for scope will also fail in this situation, not just because the resultant auth dictionary is missing the tenant-X attributes, but because OSC validates that either project or domain scope information is present. Fix this by just always setting the v2 parameters if the v3 parameters are present. This will have no effect on the generic or v3 case but fix the v2 case. Expand validation to include the tenant options so it knows that v2 plugins are scoped. Change-Id: I8cab3e423663f801cbf2d83106c671bddc58d7e6 Closes-Bug: #1460369
* | Add cli tests for --verify and friendsDean Troyer2015-05-281-2/+2
|/ | | | | | | | | | The tests that will change after the verify-always-true bug is fixed are currently commented out. The commented asserts show where we want to go. Also fixes --verify parser value Change-Id: I891e3ead5fc3da3ed2ecba5d2befd9e910778655
* Fix insecure/verify optionsTerry Howe2015-05-171-11/+5
| | | | | | | | | | | The insecure and verify options are broken so that verify always gets set to True. One problem was that the parsed args not defaulted so os_cloud_config thinks there was always a command line specified. The other problem was getattr was called on cloud config instead of get. Closes-Bug: #1450855 Change-Id: Ib5f004f51a7453cc8f5a89759e2031ec42e04a30
* Minor logging/debug cleanupsDean Troyer2015-04-281-6/+2
| | | | | | This removed the rarely useful cliff command list from the debug output. Change-Id: I48f22086733acf90e79a6ddac8712734ee2d0b60
* Raise exception if no session is createdJuan Antonio Osorio Robles2015-04-271-6/+4
| | | | | | | | | | | | If the clientmanager is unable to create a keystone session (due to insufficient auth parameters or something else) then the exception caused by this shouldn't be ignored, as was the case. On the other hand, we don't want this behaviour in the case of the 'complete' command, so this is now properly detected. Change-Id: If4f453d23cc87900cda752e9ffbcf41ded59e26f Closes-Bug: #1444640
* Add --os-cloud supportDean Troyer2015-04-181-11/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a new option --os-cloud that allows the configuration values for multiple clouds to be stored in a local file and selected with a single option. Internal option names have had 'os_' removed to be comptible with the options returned from OpenStackConfig().get_one_cloud(). The config file is ~/.config/openstack/clouds.yaml: Sample ------ clouds: devstack: auth: auth_url: http://192.168.122.10:35357/ project_name: demo username: demo password: 0penstack region_name: RegionOne devstack: auth: auth_url: http://192.168.122.10:35357/ project_name: demo username: demo password: 0penstack region_name: RegionOne Co-Authored-By: Monty Taylor <mordred@inaugust.com> Change-Id: I4939acf8067e44ffe06a2e26fc28f1adf8985b7d Depends-On: I45e2550af58aee616ca168d20a557077beeab007
* Merge "Suppress warnings user can't fix"Jenkins2015-04-181-0/+5
|\
| * Suppress warnings user can't fixDean Troyer2015-04-021-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Requests/urllib3 started issuing warnings about certificates and SSL that our users are unable to do anything about. This is a very blunt way to suppress these warnings unless --verbose or --debug is supplied on the command line. Being more precise in the suppression requires importing the warning classes from urllib3 and dealing with the platforms where it has been unvendored from requests. Maybe in the future if there are concerns that this mutes too much otherwise. Change-Id: I50bb10a16222de12c5b95bfe042b92e43ea8ee7c
* | Merge "Print warning on authentication error"Jenkins2015-04-181-1/+2
|\ \
| * | Print warning on authentication errorTerryHowe2015-04-171-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At least print a warning on authentication error. I have no idea why an exception is being ignored here because if there is no session, nothing is going to happen. This at least will print some useful warning: (.venv)terry@f350:~/python-openstackclient$ os flavor list --os-cloud pro WARNING: openstackclient.shell Possible error authenticating: __init__() got an unexpected keyword argument 'asdf' ERROR: openstack Authentication requires 'auth_url', which should be specified in 'HTTPClient' This error was caused by having a bogus value 'asdf' in the cloud.yaml for the cloud pro. Change-Id: Ie08432e0464cfa86b3b3f67ca29d3b7d23d2f46f
* | | Merge "Fix session timing"Jenkins2015-04-171-5/+4
|\ \ \ | |/ / |/| |
| * | Fix session timingDean Troyer2015-04-071-5/+4
| |/ | | | | | | | | | | | | | | | | | | | | | | Subclass keystoneclient.session.Session to add the timing hooks to record the elapsed time returned by requests.Response objects, including the redirection history. Redirects are included individually and not rolled into the total time for the original request. This works for all clients that use OSC's session. Closes-Bug: #1402577 Change-Id: I9360c90c151579b89a37edb8c11c17feb15b3cb9
* | Merge "Use cliff deferred help instead of homemade one"Jenkins2015-04-141-32/+3
|\ \