From 33ea9a239e2802d5366925888de4360018279fb7 Mon Sep 17 00:00:00 2001 From: Zachery Lantz Date: Wed, 17 Apr 2024 11:11:11 -0400 Subject: [PATCH] added support for objects.timeranges --- TestingUserScript.py | 1 + fmcapi/api_objects/__init__.py | 2 ++ .../api_objects/object_services/__init__.py | 2 ++ .../api_objects/object_services/timeranges.py | 36 +++++++++++++++++++ unit_tests/__init__.py | 2 ++ unit_tests/timeranges.py | 22 ++++++++++++ 6 files changed, 65 insertions(+) create mode 100644 fmcapi/api_objects/object_services/timeranges.py create mode 100644 unit_tests/timeranges.py diff --git a/TestingUserScript.py b/TestingUserScript.py index 2ce3d40..15c6921 100644 --- a/TestingUserScript.py +++ b/TestingUserScript.py @@ -86,6 +86,7 @@ def main(): # unit_tests.test__ravpn(fmc=fmc1) # unit_tests.test__connectionprofiles(fmc=fmc1) # Requires existing RAVPN Policy ID # unit_tests.test__dynamicaccesspolicies(fmc=fmc1) + # unit_tests.test__timeranges(fmc=fmc1) """ diff --git a/fmcapi/api_objects/__init__.py b/fmcapi/api_objects/__init__.py index c2b7166..c78db7b 100644 --- a/fmcapi/api_objects/__init__.py +++ b/fmcapi/api_objects/__init__.py @@ -109,6 +109,7 @@ from .policy_services.ravpns import RAVpn from .policy_services import ConnectionProfiles from .policy_services import DynamicAccessPolicies +from .object_services import TimeRanges logging.debug("In the api_objects __init__.py file.") @@ -216,4 +217,5 @@ "RAVpn", "ConnectionProfiles", "DynamicAccessPolicies", + "TimeRanges", ] diff --git a/fmcapi/api_objects/object_services/__init__.py b/fmcapi/api_objects/object_services/__init__.py index 2304919..6e38a7c 100644 --- a/fmcapi/api_objects/object_services/__init__.py +++ b/fmcapi/api_objects/object_services/__init__.py @@ -53,6 +53,7 @@ from .dynamicobjects import DynamicObject from .dynamicobjectmappings import DynamicObjectMappings from .grouppolicies import GroupPolicies +from .timeranges import TimeRanges logging.debug("In the object_services __init__.py file.") @@ -110,4 +111,5 @@ "VlanTags", "DynamicObjectMappings", "DynamicObject", + "TimeRanges", ] diff --git a/fmcapi/api_objects/object_services/timeranges.py b/fmcapi/api_objects/object_services/timeranges.py new file mode 100644 index 0000000..f8a8318 --- /dev/null +++ b/fmcapi/api_objects/object_services/timeranges.py @@ -0,0 +1,36 @@ +"""Time Ranges Class.""" + +from fmcapi.api_objects.apiclasstemplate import APIClassTemplate +import logging + + +class TimeRanges(APIClassTemplate): + """The TimeRanges Object in the FMC.""" + + VALID_JSON_DATA = [ + "id", + "name", + "description", + "effectiveStartDateTime", + "effectiveEndDateTime", + "recurrenceList" + ] + VALID_FOR_KWARGS = VALID_JSON_DATA + [] + REQUIRED_FOR_POST = [ + "name", + "effectiveStartDateTime", + "effectiveEndDateTime" + ] + URL_SUFFIX = "/object/timeranges" + + def __init__(self, fmc, **kwargs): + """ + Initialize TimeRanges object. + + :param fmc: (object) FMC object + :param kwargs: Any other values passed during instantiation. + :return: None + """ + super().__init__(fmc, **kwargs) + logging.debug("In __init__() for TimeRanges class.") + self.parse_kwargs(**kwargs) diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py index 0dcba12..9d7f47c 100644 --- a/unit_tests/__init__.py +++ b/unit_tests/__init__.py @@ -77,6 +77,7 @@ from .ravpn import test__ravpn from .connectionprofiles import test__connectionprofiles from .dynamicaccesspolicies import test__dynamicaccesspolicies +from .timeranges import test__timeranges logging.debug("In the unit-tests __init__.py file.") @@ -158,4 +159,5 @@ "test__ravpn", "test__connectionprofiles", "test__dynamicaccesspolicies", + "test__timeranges", ] diff --git a/unit_tests/timeranges.py b/unit_tests/timeranges.py new file mode 100644 index 0000000..a868a87 --- /dev/null +++ b/unit_tests/timeranges.py @@ -0,0 +1,22 @@ +import logging +import fmcapi +import time + +def test__timeranges(fmc): + logging.info("Testing TimeRanges class.") + + starttime = str(int(time.time())) + namer = f"_fmcapi_test_{starttime}" + + time_range = fmcapi.TimeRanges(fmc=fmc) + time_range.name = namer + time_range.effectiveStartDateTime = "1979-01-01T00:00" + time_range.effectiveEndDateTime = "1979-01-01T00:01" + time_range.post() + time_range.get() + time_range.effectiveStartDateTime = "1979-01-02T00:00" + time_range.effectiveEndDateTime = "1979-01-02T00:01" + time_range.put() + time_range.delete() + + logging.info("Testing TimeRanges class done.\n") \ No newline at end of file