From 6c224f5acfeb2288f2f4be41aee112fd01cbf4d0 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Mon, 16 Feb 2015 23:21:00 -0800 Subject: Add project and domain params to network create Without this patch, openstackclient has no way to specify to which project a network belongs upon creation. Instead, it uses the project ID that the user is authenticating with to fill the tenant_id column. This is a problem because an admin user is unable to specify a project for a non-admin network. To fix this and to improve feature parity with the neutron client, this patch adds project and domain parameters to the network create command and uses the given project name to look up the project ID. Neutron does not allow the project to be changed after creation, so no such parameter has been added to the neutron set command. Neutron calls the field 'tenant_id', but this change exposes the parameter as '--project' to support the newer terminology. If no project is specified, the client defaults to the previous behavior of using the auth project. Change-Id: Ia33ff7d599542c5b88baf2a69b063a23089a3cc4 --- openstackclient/network/v2/network.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'openstackclient/network') diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index 1a79c80a..9b246642 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -22,6 +22,7 @@ from cliff import show from openstackclient.common import exceptions from openstackclient.common import utils +from openstackclient.identity import common as identity_common from openstackclient.network import common @@ -82,6 +83,14 @@ class CreateNetwork(show.ShowOne): action='store_false', help='Do not share the network between projects', ) + parser.add_argument( + '--project', + metavar='', + help="Owner's project (name or ID)") + parser.add_argument( + '--domain', + metavar='', + help="Owner's domain (name or ID)") return parser def take_action(self, parsed_args): @@ -101,6 +110,18 @@ class CreateNetwork(show.ShowOne): 'admin_state_up': parsed_args.admin_state} if parsed_args.shared is not None: body['shared'] = parsed_args.shared + if parsed_args.project is not None: + identity_client = self.app.client_manager.identity + if parsed_args.domain is not None: + domain = identity_common.find_domain(identity_client, + parsed_args.domain) + project_id = utils.find_resource(identity_client.projects, + parsed_args.project, + domain_id=domain.id).id + else: + project_id = utils.find_resource(identity_client.projects, + parsed_args.project).id + body['tenant_id'] = project_id return {'network': body} -- cgit v1.2.1