diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 7900f1dc..3f7a3bcb 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -6086,6 +6086,22 @@ class TestPolicyCertificate(NsxPolicyLibTestCase): sleep=0.1, tenant=TEST_TENANT) self.assertEqual(info, actual_info) + def test_find_cert_with_pem(self): + id1 = '1' + id2 = '2' + pem1 = '111' + pem2 = '222' + with mock.patch.object(self.policy_api, "list", + return_value={'results': [ + {'id': id1, 'pem_encoded': pem1}, + {'id': id2, 'pem_encoded': pem2}]}) as api: + cert_ids = self.resourceApi.find_cert_with_pem( + pem1, tenant=TEST_TENANT) + self.assertEqual(1, len(cert_ids)) + self.assertEqual(id1, cert_ids[0]) + expected_def = core_defs.CertificateDef(tenant=TEST_TENANT) + self.assert_called_with_def(api, expected_def) + class TestPolicyExcludeList(NsxPolicyLibTestCase): diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 91ba53a9..b7b2ca8d 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -2384,7 +2384,7 @@ class CertificateDef(ResourceDef): @staticmethod def resource_type(): - return "TlsTrustData" + return "TlsCertificate" def get_obj_dict(self): body = super(CertificateDef, self).get_obj_dict() diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index b09ba7ce..c1d2cb97 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -4491,6 +4491,14 @@ class NsxPolicyCertApi(NsxPolicyResourceBase): certificate_def = self.entry_def(tenant=tenant) return self._list(certificate_def) + def find_cert_with_pem(self, cert_pem, + tenant=constants.POLICY_INFRA_TENANT): + # Find certificate with cert_pem + certs = self.list(tenant=tenant) + cert_ids = [cert['id'] for cert in certs + if cert['pem_encoded'] == cert_pem] + return cert_ids + def update(self, certificate_id, name=IGNORE, pem_encoded=IGNORE, private_key=IGNORE, passphrase=IGNORE, key_algo=IGNORE, description=IGNORE,