From df0904bf8b8adf10602ef9e8894613042ad7ceab Mon Sep 17 00:00:00 2001 From: Abhishek Raut Date: Fri, 18 Jan 2019 17:40:15 -0800 Subject: [PATCH] Add Tier0Natrule APIs to core_resources Change-Id: I6a8da24c023817a10bdc54c54a337ed7d80cb8db --- vmware_nsxlib/v3/policy/__init__.py | 2 + vmware_nsxlib/v3/policy/core_resources.py | 82 +++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/vmware_nsxlib/v3/policy/__init__.py b/vmware_nsxlib/v3/policy/__init__.py index 6cee25ec..ba802a28 100644 --- a/vmware_nsxlib/v3/policy/__init__.py +++ b/vmware_nsxlib/v3/policy/__init__.py @@ -59,6 +59,8 @@ class NsxPolicyLib(lib.NsxLibBase): self.ip_protocol_service = ( core_resources.NsxPolicyIPProtocolServiceApi(*args)) self.tier0 = core_resources.NsxPolicyTier0Api(*args) + self.tier0_nat_rule = core_resources.NsxPolicyTier0NatRuleApi( + *args) self.tier1 = core_resources.NsxPolicyTier1Api(*args) self.tier1_segment = core_resources.NsxPolicyTier1SegmentApi(*args) self.tier1_nat_rule = core_resources.NsxPolicyTier1NatRuleApi( diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 248318cc..fd1bec3c 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -1058,6 +1058,88 @@ class NsxPolicyTier0Api(NsxPolicyResourceBase): return uplink_ips +class NsxPolicyTier0NatRuleApi(NsxPolicyResourceBase): + DEFAULT_NAT_ID = 'USER' + + @property + def entry_def(self): + return core_defs.Tier0NatRule + + def create_or_overwrite(self, name, tier0_id, + nat_id=DEFAULT_NAT_ID, + nat_rule_id=None, + description=IGNORE, + source_network=IGNORE, + destination_network=IGNORE, + translated_network=IGNORE, + firewall_match=IGNORE, + action=IGNORE, + sequence_number=IGNORE, + log=IGNORE, + tags=IGNORE, + tenant=constants.POLICY_INFRA_TENANT): + + nat_rule_id = self._init_obj_uuid(nat_rule_id) + nat_rule_def = self._init_def(tier0_id=tier0_id, + nat_id=nat_id, + nat_rule_id=nat_rule_id, + name=name, + description=description, + source_network=source_network, + destination_network=destination_network, + translated_network=translated_network, + firewall_match=firewall_match, + action=action, + sequence_number=sequence_number, + log=log, + tags=tags, + tenant=tenant) + self._create_or_store(nat_rule_def) + return nat_rule_id + + def delete(self, tier0_id, nat_rule_id, nat_id=DEFAULT_NAT_ID, + tenant=constants.POLICY_INFRA_TENANT): + nat_rule_def = self.entry_def(tier0_id=tier0_id, nat_id=nat_id, + nat_rule_id=nat_rule_id, tenant=tenant) + self.policy_api.delete(nat_rule_def) + + def get(self, tier0_id, nat_rule_id, nat_id=DEFAULT_NAT_ID, + tenant=constants.POLICY_INFRA_TENANT): + nat_rule_def = self.entry_def(tier0_id=tier0_id, nat_id=nat_id, + nat_rule_id=nat_rule_id, tenant=tenant) + self.policy_api.get(nat_rule_def) + + def list(self, tier0_id, nat_id=DEFAULT_NAT_ID, + tenant=constants.POLICY_INFRA_TENANT): + nat_rule_def = self.entry_def(tier0_id=tier0_id, nat_id=nat_id, + tenant=tenant) + return self._list(nat_rule_def) + + def update(self, tier0_id, nat_rule_id, + nat_id=DEFAULT_NAT_ID, + name=IGNORE, + description=IGNORE, + source_network=IGNORE, + destination_network=IGNORE, + translated_network=IGNORE, + action=IGNORE, + log=IGNORE, + tags=IGNORE, + tenant=constants.POLICY_INFRA_TENANT): + self._update(tier0_id=tier0_id, + nat_id=nat_id, + nat_rule_id=nat_rule_id, + name=name, + description=description, + source_network=source_network, + destination_network=destination_network, + translated_network=translated_network, + action=action, + log=log, + tags=tags, + tenant=tenant) + + class NsxPolicyTier1NatRuleApi(NsxPolicyResourceBase): DEFAULT_NAT_ID = 'USER'