Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def sz(self, name):
"""
Assign Security Zone to this subinterface.
:param name: (str) Name of Security Zone.
:return: None
"""
logging.debug("In sz() for SubInterfaces class.")
sz = SecurityZones(fmc=self.fmc)
sz.get(name=name)
if "id" in sz.__dict__:
new_zone = {"name": sz.name, "id": sz.id, "type": sz.type}
self.securityZone = new_zone
else:
logging.warning(
f'Security Zone, "{name}", not found. Cannot add to SubInterfaces.'
)
def get_zone_id(self, name):
"""
Pull the ID for a security zone
Args:
name (str): Name of interface zone object
Returns:
UUID of zone object (str)
"""
sec_zone = SecurityZones(fmc=self.fmc)
sec_zone.get(name=name)
if "id" in sec_zone.__dict__:
return sec_zone.id, sec_zone.type
else:
return None, None
def sz(self, name):
"""
Assign Security Zone to this group.
:param name: (str) Name of Security Zone.
:return: None
"""
logging.debug("In sz() for BridgeGroupInterfaces class.")
sz = SecurityZones(fmc=self.fmc)
sz.get(name=name)
if "id" in sz.__dict__:
new_zone = {"name": sz.name, "id": sz.id, "type": sz.type}
self.securityZone = new_zone
else:
logging.warning(
f'Security Zone, "{name}", not found. Cannot add to BridgeGroupInterfaces.'
)
def sz(self, name):
"""
Assign Security Zone to this redundant interface.
:param name: (str) Name of Security Zone.
:return: None
"""
logging.debug("In sz() for RedundantInterfaces class.")
sz = SecurityZones(fmc=self.fmc)
sz.get(name=name)
if "id" in sz.__dict__:
new_zone = {"name": sz.name, "id": sz.id, "type": sz.type}
self.securityZone = new_zone
else:
logging.warning(
f'Security Zone, "{name}", not found. Cannot add to RedundantInterfaces.'
)
def sz(self, name):
logging.debug("In sz() for PhysicalInterface class.")
sz = SecurityZones(fmc=self.fmc)
sz.get(name=name)
if 'id' in sz.__dict__:
new_zone = {'name': sz.name, 'id': sz.id, 'type': sz.type}
self.securityZone = new_zone
else:
logging.warning(f'Security Zone, "{name}", not found. Cannot add to PhysicalInterface.')
def parse_kwargs(self, **kwargs):
"""
Parse the kwargs and set self variables to match.
:return: None
"""
super().parse_kwargs(**kwargs)
logging.debug("In parse_kwargs() for SecurityZones class.")
if "interfaceMode" in kwargs:
self.interfaceMode = kwargs["interfaceMode"]
else:
self.interfaceMode = "ROUTED"
class SecurityZone(SecurityZones):
"""
Dispose of this Class after 20210101.
Use SecurityZones() instead.
"""
def __init__(self, fmc, **kwargs):
warnings.resetwarnings()
warnings.warn(
"Deprecated: SecurityZone() should be called via SecurityZones()."
)
super().__init__(fmc, **kwargs)
def source_zone(self, action, name=""):
"""
Add/modify name to sourceZones field of AccessRules object.
:param action: (str) 'add', 'remove', or 'clear'
:param name: (str) Name of Security Zone in FMC.
:return: None
"""
logging.debug("In source_zone() for AccessRules class.")
if action == "add":
sz = SecurityZones(fmc=self.fmc)
sz.get(name=name)
if "id" in sz.__dict__:
if "sourceZones" in self.__dict__:
new_zone = {"name": sz.name, "id": sz.id, "type": sz.type}
duplicate = False
for obj in self.sourceZones["objects"]:
if obj["name"] == new_zone["name"]:
duplicate = True
break
if not duplicate:
self.sourceZones["objects"].append(new_zone)
logging.info(
f'Adding "{name}" to sourceZones for this AccessRules.'
)
else:
self.sourceZones = {
def destination_zone(self, action, name=""):
"""
Add/modify name to destinationZones field of AccessRules object.
:param action: (str) 'add', 'remove', or 'clear'
:param name: (str) Name of Security Zone in FMC.
:return: None
"""
logging.debug("In destination_zone() for AccessRules class.")
if action == "add":
sz = SecurityZones(fmc=self.fmc)
sz.get(name=name)
if "id" in sz.__dict__:
if "destinationZones" in self.__dict__:
new_zone = {"name": sz.name, "id": sz.id, "type": sz.type}
duplicate = False
for obj in self.destinationZones["objects"]:
if obj["name"] == new_zone["name"]:
duplicate = True
break
if not duplicate:
self.destinationZones["objects"].append(new_zone)
logging.info(
f'Adding "{name}" to destinationZones for this AccessRules.'
)
else:
self.destinationZones = {