Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def edit(self, name, ha_name):
"""
Edit existing device HA and change physical interface params.
:param name: (str)
:param ha_name: (str)
:return: None
"""
logging.debug("In edit() for FailoverInterfaceMACAddressConfigs class.")
deviceha1 = FTDDeviceHAPairs(fmc=self.fmc, name=ha_name)
deviceha1.get()
obj1 = FailoverInterfaceMACAddressConfigs(fmc=self.fmc)
obj1.device_ha(ha_name=ha_name)
failovermac_json = obj1.get()
items = failovermac_json.get("items", [])
found = False
for item in items:
if item["physicalInterface"]["name"] == name:
found = True
self.id = item["id"]
self.name = item["physicalInterface"]["name"]
self.failoverActiveMac = item["failoverActiveMac"]
self.failoverStandbyMac = item["failoverStandbyMac"]
self.deviceha_id = deviceha1.id
self.URL = (
f"{self.fmc.configuration_url}{self.PREFIX_URL}/"
def device_ha(self, ha_name):
"""
Add deviceha_id to URL.
:param ha_name: (str) Name of Device HA.
:return: None
"""
logging.debug("In device_ha() for MonitoredInterfaces class.")
deviceha1 = FTDDeviceHAPairs(fmc=self.fmc, name=ha_name)
deviceha1.get()
if "id" in deviceha1.__dict__:
self.deviceha_id = deviceha1.id
self.URL = f"{self.fmc.configuration_url}{self.PREFIX_URL}/{self.deviceha_id}/monitoredinterfaces"
self.deviceha_added_to_url = True
else:
logging.warning(
f"Device HA {ha_name} not found. Cannot set up device for MonitoredInterfaces."
)
elif action == "remove":
if "members" in self.__dict__:
for member in members:
if member["type"] == "device":
dev1 = DeviceRecords(fmc=self.fmc)
dev1.get(name=member["name"])
elif member["type"] == "deviceHAPair":
dev1 = FTDDeviceHAPairs(fmc=self.fmc)
dev1.get(name=member["name"])
if "id" in dev1.__dict__:
if member["type"] == "device":
self.members = list(
filter(lambda i: i["id"] != dev1.id, self.members)
)
elif member["type"] == "deviceHAPair":
devHA1 = FTDDeviceHAPairs(fmc=self.fmc)
devHA1.get(name=member["name"])
self.members = list(
filter(
lambda i: i["id"] != devHA1.primary["id"],
self.members,
)
)
self.members = list(
filter(
lambda i: i["id"] != devHA1.secondary["id"],
self.members,
)
)
else:
logging.warning(
f"DeviceRecord {member} not registered. Cannot remove DeviceRecord"
def devices(self, action, members=[]):
"""
Add/modify name to members field of DeviceGroupRecords object.
:param action: (str) 'add', 'remove', or 'clear'
:param membres: (list) List of members in group.
:return: None
"""
logging.debug("In devices() for DeviceGroupRecords class.")
if action == "add":
for member in members:
if member["type"] == "device":
dev1 = DeviceRecords(fmc=self.fmc)
dev1.get(name=member["name"])
elif member["type"] == "deviceHAPair":
dev1 = FTDDeviceHAPairs(fmc=self.fmc)
dev1.get(name=member["name"])
if "id" in dev1.__dict__:
if "members" in self.__dict__:
self.members.append(
{"id": dev1.id, "type": dev1.type, "name": dev1.name}
)
else:
self.members = [
{"id": dev1.id, "type": dev1.type, "name": dev1.name}
]
logging.info(
f'DeviceRecord "{dev1.name}" added to this DeviceGroupRecords object.'
)
else:
logging.warning(
f"{member} not found. Cannot add DeviceRecord to DeviceGroupRecords."
self.fmc.autodeploy = False
return super().post(**kwargs)
def put(self, **kwargs):
"""
Disable autodeploy and then PUT.
:return: requests response
"""
logging.debug("In put() for FTDDeviceHAPairs class.")
# Attempting to "Deploy" during Device registration causes issues.
self.fmc.autodeploy = False
return super().put(**kwargs)
class DeviceHAPairs(FTDDeviceHAPairs):
"""
Dispose of this Class after 20210101.
Use FTDDeviceHAPairs() instead.
"""
def __init__(self, fmc, **kwargs):
warnings.resetwarnings()
warnings.warn(
"Deprecated: DeviceHAPairs() should be called via FTDDeviceHAPairs()."
)
super().__init__(fmc, **kwargs)
from .ftddevicehapairs import FTDDeviceHAPairs
class DeviceHAPairs(FTDDeviceHAPairs):
"""
The DeviceHAPairs Object in the FMC.
def device_ha(self, ha_name):
"""
Add deviceha_id to URL.
:param ha_name: (str) Name of Device HA.
:return: None
"""
logging.debug("In device_ha() for FailoverInterfaceMACAddressConfigs class.")
deviceha1 = FTDDeviceHAPairs(fmc=self.fmc, name=ha_name)
deviceha1.get()
if "id" in deviceha1.__dict__:
self.deviceha_id = deviceha1.id
self.URL = (
f"{self.fmc.configuration_url}{self.PREFIX_URL}/"
f"{self.deviceha_id}/failoverinterfacemacaddressconfigs"
)
self.deviceha_added_to_url = True
else:
logging.warning(
f"Device HA {ha_name} not found. "
f"Cannot set up device for FailoverInterfaceMACAddressConfigs."