diff --git a/doc/source/command-objects/network.rst b/doc/source/command-objects/network.rst index e6a028b778..6b63c35da8 100644 --- a/doc/source/command-objects/network.rst +++ b/doc/source/command-objects/network.rst @@ -13,20 +13,20 @@ Create new network .. code:: bash os network create - [--domain ] + [--project [--project-domain ]] [--enable | --disable] - [--project ] [--share | --no-share] -.. option:: --domain - - Owner's domain (name or ID) - .. option:: --project Owner's project (name or ID) +.. option:: --project-domain + + Domain the project belongs to (name or ID). + This can be used in case collisions between project names exist. + .. option:: --enable Enable network (default) diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index 9b2466422a..1fa05462f0 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -87,10 +87,7 @@ class CreateNetwork(show.ShowOne): '--project', metavar='', help="Owner's project (name or ID)") - parser.add_argument( - '--domain', - metavar='', - help="Owner's domain (name or ID)") + identity_common.add_project_domain_option_to_parser(parser) return parser def take_action(self, parsed_args): @@ -112,15 +109,11 @@ class CreateNetwork(show.ShowOne): 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 + project_id = identity_common.find_project( + identity_client, + parsed_args.project, + parsed_args.project_domain, + ).id body['tenant_id'] = project_id return {'network': body} diff --git a/openstackclient/tests/network/v2/test_network.py b/openstackclient/tests/network/v2/test_network.py index 90085f287a..36133a3bb8 100644 --- a/openstackclient/tests/network/v2/test_network.py +++ b/openstackclient/tests/network/v2/test_network.py @@ -90,14 +90,14 @@ class TestCreateNetwork(common.TestNetworkBase): "--disable", "--share", "--project", identity_fakes_v3.project_name, - "--domain", identity_fakes_v3.domain_name, + "--project-domain", identity_fakes_v3.domain_name, FAKE_NAME, ] + self.given_show_options verifylist = [ ('admin_state', False), ('shared', True), ('project', identity_fakes_v3.project_name), - ('domain', identity_fakes_v3.domain_name), + ('project_domain', identity_fakes_v3.domain_name), ('name', FAKE_NAME), ] + self.then_show_options mocker = mock.Mock(return_value=copy.deepcopy(RESPONSE)) @@ -165,7 +165,6 @@ class TestCreateNetwork(common.TestNetworkBase): arglist = [ "--project", identity_fakes_v2.project_name, FAKE_NAME, - ] verifylist = [ ('admin_state', True), @@ -203,14 +202,14 @@ class TestCreateNetwork(common.TestNetworkBase): def test_create_with_domain_identityv2(self): arglist = [ "--project", identity_fakes_v3.project_name, - "--domain", identity_fakes_v3.domain_name, + "--project-domain", identity_fakes_v3.domain_name, FAKE_NAME, ] verifylist = [ ('admin_state', True), ('shared', None), ('project', identity_fakes_v3.project_name), - ('domain', identity_fakes_v3.domain_name), + ('project_domain', identity_fakes_v3.domain_name), ('name', FAKE_NAME), ] mocker = mock.Mock(return_value=copy.deepcopy(RESPONSE))