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 adfb6e3d..976a607c 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -1075,6 +1075,88 @@ class NsxPolicyTier0Api(NsxPolicyResourceBase): return cidrs +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'