diff options
Diffstat (limited to 'openstackclient')
| -rw-r--r-- | openstackclient/common/restapi.py | 18 | ||||
| -rw-r--r-- | openstackclient/identity/v2_0/user.py | 7 | ||||
| -rw-r--r-- | openstackclient/identity/v3/endpoint.py | 8 | ||||
| -rw-r--r-- | openstackclient/object/v1/container.py | 51 | ||||
| -rw-r--r-- | openstackclient/object/v1/lib/container.py | 39 | ||||
| -rw-r--r-- | openstackclient/tests/volume/test_find_resource.py | 1 |
6 files changed, 116 insertions, 8 deletions
diff --git a/openstackclient/common/restapi.py b/openstackclient/common/restapi.py index a4822a10..a646acb3 100644 --- a/openstackclient/common/restapi.py +++ b/openstackclient/common/restapi.py @@ -189,7 +189,11 @@ class RESTApi(object): :param \*\*kwargs: Optional arguments passed to ``request`` """ - return self.request('PATCH', url, data=data, json=json, **kwargs) + if json: + kwargs['json'] = json + if data: + kwargs['data'] = data + return self.request('PATCH', url, **kwargs) def post(self, url, data=None, json=None, **kwargs): """Send a POST request. Returns :class:`requests.Response` object. @@ -201,7 +205,11 @@ class RESTApi(object): :param \*\*kwargs: Optional arguments passed to ``request`` """ - return self.request('POST', url, data=data, json=json, **kwargs) + if json: + kwargs['json'] = json + if data: + kwargs['data'] = data + return self.request('POST', url, **kwargs) def put(self, url, data=None, json=None, **kwargs): """Send a PUT request. Returns :class:`requests.Response` object. @@ -213,7 +221,11 @@ class RESTApi(object): :param \*\*kwargs: Optional arguments passed to ``request`` """ - return self.request('PUT', url, data=data, json=json, **kwargs) + if json: + kwargs['json'] = json + if data: + kwargs['data'] = data + return self.request('PUT', url, **kwargs) # Command verb methods diff --git a/openstackclient/identity/v2_0/user.py b/openstackclient/identity/v2_0/user.py index 60af6ddb..b291c882 100644 --- a/openstackclient/identity/v2_0/user.py +++ b/openstackclient/identity/v2_0/user.py @@ -99,9 +99,10 @@ class CreateUser(show.ShowOne): # NOTE(dtroyer): The users.create() method wants 'tenant_id' but # the returned resource has 'tenantId'. Sigh. # We're using project_id now inside OSC so there. - user._info.update( - {'project_id': user._info.pop('tenantId')} - ) + if 'tenantId' in user._info: + user._info.update( + {'project_id': user._info.pop('tenantId')} + ) info = {} info.update(user._info) diff --git a/openstackclient/identity/v3/endpoint.py b/openstackclient/identity/v3/endpoint.py index fa1b8628..4ea44e7a 100644 --- a/openstackclient/identity/v3/endpoint.py +++ b/openstackclient/identity/v3/endpoint.py @@ -181,16 +181,20 @@ class SetEndpoint(command.Command): identity_client = self.app.client_manager.identity endpoint = utils.find_resource(identity_client.endpoints, parsed_args.endpoint) - service = common.find_service(identity_client, parsed_args.service) if (not parsed_args.interface and not parsed_args.url and not parsed_args.service and not parsed_args.region): sys.stdout.write("Endpoint not updated, no arguments present") return + service_id = None + if parsed_args.service: + service = common.find_service(identity_client, parsed_args.service) + service_id = service.id + identity_client.endpoints.update( endpoint.id, - service=service.id, + service=service_id, url=parsed_args.url, interface=parsed_args.interface, region=parsed_args.region, diff --git a/openstackclient/object/v1/container.py b/openstackclient/object/v1/container.py index 1e252aaf..ae4013fc 100644 --- a/openstackclient/object/v1/container.py +++ b/openstackclient/object/v1/container.py @@ -19,6 +19,7 @@ import logging import six +from cliff import command from cliff import lister from cliff import show @@ -26,6 +27,56 @@ from openstackclient.common import utils from openstackclient.object.v1.lib import container as lib_container +class CreateContainer(show.ShowOne): + """Create a container""" + + log = logging.getLogger(__name__ + '.CreateContainer') + + def get_parser(self, prog_name): + parser = super(CreateContainer, self).get_parser(prog_name) + parser.add_argument( + 'container', + metavar='<container>', + help='New container name', + ) + return parser + + def take_action(self, parsed_args): + self.log.debug('take_action(%s)', parsed_args) + + data = lib_container.create_container( + self.app.restapi, + self.app.client_manager.object_store.endpoint, + parsed_args.container, + ) + + return zip(*sorted(six.iteritems(data))) + + +class DeleteContainer(command.Command): + """Delete a container""" + + log = logging.getLogger(__name__ + '.DeleteContainer') + + def get_parser(self, prog_name): + parser = super(DeleteContainer, self).get_parser(prog_name) + parser.add_argument( + 'container', + metavar='<container>', + help='Container name to delete', + ) + return parser + + def take_action(self, parsed_args): + self.log.debug('take_action(%s)', parsed_args) + + lib_container.delete_container( + self.app.restapi, + self.app.client_manager.object_store.endpoint, + parsed_args.container, + ) + + class ListContainer(lister.Lister): """List containers""" diff --git a/openstackclient/object/v1/lib/container.py b/openstackclient/object/v1/lib/container.py index 72e97d4e..bd509555 100644 --- a/openstackclient/object/v1/lib/container.py +++ b/openstackclient/object/v1/lib/container.py @@ -22,6 +22,45 @@ except ImportError: from urlparse import urlparse # noqa +def create_container( + api, + url, + container, +): + """Create a container + + :param api: a restapi object + :param url: endpoint + :param container: name of container to create + :returns: dict of returned headers + """ + + response = api.put("%s/%s" % (url, container)) + url_parts = urlparse(url) + data = { + 'account': url_parts.path.split('/')[-1], + 'container': container, + } + data['x-trans-id'] = response.headers.get('x-trans-id', None) + + return data + + +def delete_container( + api, + url, + container, +): + """Delete a container + + :param api: a restapi object + :param url: endpoint + :param container: name of container to delete + """ + + api.delete("%s/%s" % (url, container)) + + def list_containers( api, url, diff --git a/openstackclient/tests/volume/test_find_resource.py b/openstackclient/tests/volume/test_find_resource.py index 8539070f..56081966 100644 --- a/openstackclient/tests/volume/test_find_resource.py +++ b/openstackclient/tests/volume/test_find_resource.py @@ -21,6 +21,7 @@ from cinderclient.v1 import volumes from openstackclient.common import exceptions from openstackclient.common import utils from openstackclient.tests import utils as test_utils +from openstackclient.volume import client # noqa ID = '1after909' |
