Browse Source

Merge "Added Tier 0 static routes" into stable/victoria

changes/22/794622/1
Zuul 2 months ago
committed by Gerrit Code Review
parent
commit
aa5b7deac3
  1. 49
      vmware_nsxlib/tests/unit/v3/policy/test_resources.py
  2. 2
      vmware_nsxlib/v3/policy/__init__.py
  3. 62
      vmware_nsxlib/v3/policy/core_resources.py

49
vmware_nsxlib/tests/unit/v3/policy/test_resources.py

@ -7013,5 +7013,54 @@ class TestNsxPolicyObjectRolePermissionGroup(NsxPolicyLibTestCase):
path_prefix=path_prefix,
role_name=role_name,
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
class TestPolicyTier0StaticRoute(NsxPolicyLibTestCase):
def setUp(self, *args, **kwargs):
super(TestPolicyTier0StaticRoute, self).setUp()
self.resourceApi = self.policy_lib.tier0_static_route
def test_create(self):
name = 'test'
description = 'desc'
tier0_id = '111'
static_route_id = '222'
network = '1.1.1.1/24'
nexthop = '2.2.2.2'
with mock.patch.object(self.policy_api,
"create_or_update") as api_call:
result = self.resourceApi.create_or_overwrite(
name, tier0_id,
static_route_id=static_route_id,
description=description,
network=network,
next_hop=nexthop,
tenant=TEST_TENANT)
expected_def = core_defs.Tier0StaticRoute(
tier0_id=tier0_id,
static_route_id=static_route_id,
name=name,
description=description,
network=network,
next_hop=nexthop,
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)
self.assertIsNotNone(result)
def test_delete(self):
tier0_id = '111'
static_route_id = '222'
with mock.patch.object(self.policy_api, "delete") as api_call:
self.resourceApi.delete(
tier0_id,
static_route_id,
tenant=TEST_TENANT)
expected_def = core_defs.Tier0StaticRoute(
tier0_id=tier0_id,
static_route_id=static_route_id,
tenant=TEST_TENANT)
self.assert_called_with_def(api_call, expected_def)

2
vmware_nsxlib/v3/policy/__init__.py

@ -80,6 +80,8 @@ class NsxPolicyLib(lib.NsxLibBase):
self.tier0_prefix_list = core_resources.NsxPolicyTier0PrefixListApi(
*args)
self.tier0_bgp = core_resources.NsxPolicyTier0BgpApi(*args)
self.tier0_static_route = (
core_resources.NSXPolicyTier0StaticRouteApi(*args))
self.tier1 = core_resources.NsxPolicyTier1Api(*args)
self.tier1_segment = core_resources.NsxPolicyTier1SegmentApi(*args)
self.tier1_nat_rule = core_resources.NsxPolicyTier1NatRuleApi(

62
vmware_nsxlib/v3/policy/core_resources.py

@ -2000,6 +2000,68 @@ class NsxPolicyTier1NatRuleApi(NsxPolicyResourceBase):
enabled=enabled)
class NSXPolicyTier0StaticRouteApi(NsxPolicyResourceBase):
@property
def entry_def(self):
return core_defs.Tier0StaticRoute
def create_or_overwrite(self, name, tier0_id,
static_route_id=None,
description=IGNORE,
network=IGNORE,
next_hop=IGNORE,
tags=IGNORE,
tenant=constants.POLICY_INFRA_TENANT):
static_route_id = self._init_obj_uuid(static_route_id)
static_route_def = self._init_def(tier0_id=tier0_id,
static_route_id=static_route_id,
name=name,
description=description,
network=network,
next_hop=next_hop,
tags=tags,
tenant=tenant)
self._create_or_store(static_route_def)
return static_route_id
def delete(self, tier0_id, static_route_id,
tenant=constants.POLICY_INFRA_TENANT):
static_route_def = self.entry_def(tier0_id=tier0_id,
static_route_id=static_route_id,
tenant=tenant)
self._delete_with_retry(static_route_def)
def get(self, tier0_id, static_route_id,
tenant=constants.POLICY_INFRA_TENANT, silent=False):
static_route_def = self.entry_def(tier0_id=tier0_id,
static_route_id=static_route_id,
tenant=tenant)
return self.policy_api.get(static_route_def, silent=silent)
def list(self, tier0_id,
tenant=constants.POLICY_INFRA_TENANT):
static_route_def = self.entry_def(tier0_id=tier0_id,
tenant=tenant)
return self._list(static_route_def)
def update(self, tier0_id, static_route_id,
name=IGNORE,
description=IGNORE,
network=IGNORE,
next_hop=IGNORE,
tags=IGNORE,
tenant=constants.POLICY_INFRA_TENANT):
self._update(tier0_id=tier0_id,
static_route_id=static_route_id,
name=name,
description=description,
network=network,
next_hop=next_hop,
tags=tags,
tenant=tenant)
class NsxPolicyTier1StaticRouteApi(NsxPolicyResourceBase):
@property

Loading…
Cancel
Save