From c943979f972aec9527ec49014b85eeb3e4959326 Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Mon, 28 Jan 2019 13:13:18 +0200 Subject: [PATCH] NSXP: expose path_to_id method Change-Id: Ib42d3f0765adea04dbc6ab9fc5fe4bee6d3e7dee --- vmware_nsxlib/v3/policy/core_resources.py | 6 ++---- vmware_nsxlib/v3/policy/utils.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 vmware_nsxlib/v3/policy/utils.py diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 4d0c206b..16be8084 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -31,6 +31,7 @@ from vmware_nsxlib.v3 import utils from vmware_nsxlib.v3.policy import constants from vmware_nsxlib.v3.policy import core_defs from vmware_nsxlib.v3.policy import transaction as trans +from vmware_nsxlib.v3.policy import utils as p_utils LOG = logging.getLogger(__name__) @@ -259,9 +260,6 @@ class NsxPolicyResourceBase(object): else: self.policy_api.create_or_update(policy_def) - def _path_to_id(self, path): - return path.split('/')[-1] - class NsxPolicyDomainApi(NsxPolicyResourceBase): """NSX Policy Domain.""" @@ -1520,7 +1518,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase): segment = self.get(segment_id, tenant=tenant) tz_path = segment.get('transport_zone_path') if tz_path: - return self._path_to_id(tz_path) + return p_utils.path_to_id(tz_path) class NsxPolicySegmentPortApi(NsxPolicyResourceBase): diff --git a/vmware_nsxlib/v3/policy/utils.py b/vmware_nsxlib/v3/policy/utils.py new file mode 100644 index 00000000..759945b7 --- /dev/null +++ b/vmware_nsxlib/v3/policy/utils.py @@ -0,0 +1,18 @@ +# Copyright 2019 VMware, 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. + + +def path_to_id(path): + return path.split('/')[-1]