diff options
Diffstat (limited to 'openstackclient/compute')
| -rw-r--r-- | openstackclient/compute/v2/keypair.py | 31 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server_event.py | 117 |
2 files changed, 145 insertions, 3 deletions
diff --git a/openstackclient/compute/v2/keypair.py b/openstackclient/compute/v2/keypair.py index 2a8524d6..851cced0 100644 --- a/openstackclient/compute/v2/keypair.py +++ b/openstackclient/compute/v2/keypair.py @@ -41,12 +41,19 @@ class CreateKeypair(command.ShowOne): metavar='<name>', help=_("New public or private key name") ) - parser.add_argument( + key_group = parser.add_mutually_exclusive_group() + key_group.add_argument( '--public-key', metavar='<file>', help=_("Filename for public key to add. If not used, " "creates a private key.") ) + key_group.add_argument( + '--private-key', + metavar='<file>', + help=_("Filename for private key to save. If not used, " + "print private key in console.") + ) return parser def take_action(self, parsed_args): @@ -69,13 +76,31 @@ class CreateKeypair(command.ShowOne): public_key=public_key, ) + private_key = parsed_args.private_key + # Save private key into specified file + if private_key: + try: + with io.open( + os.path.expanduser(parsed_args.private_key), 'w+' + ) as p: + p.write(keypair.private_key) + except IOError as e: + msg = _("Key file %(private_key)s can not be saved: " + "%(exception)s") + raise exceptions.CommandError( + msg % {"private_key": parsed_args.private_key, + "exception": e} + ) # NOTE(dtroyer): how do we want to handle the display of the private # key when it needs to be communicated back to the user # For now, duplicate nova keypair-add command output info = {} - if public_key: + if public_key or private_key: info.update(keypair._info) - del info['public_key'] + if 'public_key' in info: + del info['public_key'] + if 'private_key' in info: + del info['private_key'] return zip(*sorted(six.iteritems(info))) else: sys.stdout.write(keypair.private_key) diff --git a/openstackclient/compute/v2/server_event.py b/openstackclient/compute/v2/server_event.py new file mode 100644 index 00000000..ccb19ef7 --- /dev/null +++ b/openstackclient/compute/v2/server_event.py @@ -0,0 +1,117 @@ +# Copyright 2017 Huawei, Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +"""Compute v2 Server operation event implementations""" + +import logging +import six + +from osc_lib.command import command +from osc_lib import utils + +from openstackclient.i18n import _ + + +LOG = logging.getLogger(__name__) + + +class ListServerEvent(command.Lister): + _description = _("List recent events of a server") + + def get_parser(self, prog_name): + parser = super(ListServerEvent, self).get_parser(prog_name) + parser.add_argument( + 'server', + metavar='<server>', + help=_('Server to list events (name or ID)'), + ) + parser.add_argument( + '--long', + action='store_true', + default=False, + help=_("List additional fields in output") + ) + return parser + + def take_action(self, parsed_args): + compute_client = self.app.client_manager.compute + server_id = utils.find_resource(compute_client.servers, + parsed_args.server).id + data = compute_client.instance_action.list(server_id) + + if parsed_args.long: + columns = ( + 'request_id', + 'instance_uuid', + 'action', + 'start_time', + 'message', + 'project_id', + 'user_id', + ) + column_headers = ( + 'Request ID', + 'Server ID', + 'Action', + 'Start Time', + 'Message', + 'Project ID', + 'User ID', + ) + else: + columns = ( + 'request_id', + 'instance_uuid', + 'action', + 'start_time', + ) + column_headers = ( + 'Request ID', + 'Server ID', + 'Action', + 'Start Time', + ) + + return (column_headers, + (utils.get_item_properties( + s, columns, + ) for s in data)) + + +class ShowServerEvent(command.ShowOne): + _description = _("Show server event details") + + def get_parser(self, prog_name): + parser = super(ShowServerEvent, self).get_parser(prog_name) + parser.add_argument( + 'server', + metavar='<server>', + help=_('Server to show event details (name or ID)'), + ) + parser.add_argument( + 'request_id', + metavar='<request-id>', + help=_('Request ID of the event to show (ID only)'), + ) + return parser + + def take_action(self, parsed_args): + compute_client = self.app.client_manager.compute + server_id = utils.find_resource(compute_client.servers, + parsed_args.server).id + action_detail = compute_client.instance_action.get( + server_id, parsed_args.request_id) + + return zip(*sorted(six.iteritems(action_detail._info))) |
