Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def find_network_object(self, name):
"""
Search for network object by name
Args:
name (str): Name of network object
Returns:
id (str), type (str) or None None
"""
network_object = NetworkAddresses(fmc=self.fmc, name=name)
resp = network_object.get()
return self._return_id_type(resp)
}
)
else:
self.selectedNetworks = [
{
"type": net1[0]["type"],
"id": net1[0]["id"],
"name": net1[0]["name"],
}
]
else:
logging.warning(
f'Network "{network}" not found. Cannot set up device for IPv6StaticRoute.'
)
elif action == "remove":
ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
networkgroup_json = NetworkGroups(fmc=self.fmc).get()
items = ipaddresses_json.get("items", []) + networkgroup_json.get(
"items", []
)
for network in networks:
net1 = list(filter(lambda i: i["name"] == network, items))
if len(net1) > 0:
if "selectedNetworks" in self.__dict__:
self.selectedNetworks = list(
filter(
lambda i: i["id"] != net1[0]["id"],
self.selectedNetworks,
)
)
else:
logging.warning(
def original_source(self, name):
"""
Associate Network to be used as Original Source.
:param name: (str) Name of Network.
:return: None
"""
logging.debug("In original_source() for ManualNatRules class.")
ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
networkgroup_json = NetworkGroups(
fmc=self.fmc
).get() # FIXME, shouldn't this be a part of items?
items = ipaddresses_json.get("items", [])
new_net = None
for item in items:
if item["name"] == name:
new_net = {"id": item["id"], "type": item["type"]}
break
if new_net is None:
logging.warning(
f'Network "{name}" is not found in FMC. Cannot add to original_source.'
)
else:
self.originalSource = new_net
logging.info(f'Adding "{name}" to original_source for this ManualNatRule.')
def original_destination(self, name):
"""
Associate Network to be used as Original Destination.
:param name: (str) Name of Network.
:return: None
"""
logging.debug("In original_destination() for ManualNatRules class.")
ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
networkgroup_json = NetworkGroups(
fmc=self.fmc
).get() # FIXME, shouldn't this be a part of items?
items = ipaddresses_json.get("items", [])
new_net = None
for item in items:
if item["name"] == name:
new_net = {"id": item["id"], "type": item["type"]}
break
if new_net is None:
logging.warning(
f'Network "{name}" is not found in FMC. Cannot add to original_destination.'
)
else:
self.originalDestination = new_net
logging.info(
def patPool(self, name, options={}):
"""
Associate a PAT Pool with this rule.
:param name: (str) Name of PAT Pool.
:param options: (dict) Dictionary of options.
:return: None
"""
# Network Group Object permitted for patPool
ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
networkgroup_json = NetworkGroups(fmc=self.fmc).get()
items = ipaddresses_json.get("items", []) + networkgroup_json.get("items", [])
new_net = None
for item in items:
if item["name"] == name:
new_net = {"name": item["name"], "id": item["id"], "type": item["type"]}
break
if new_net is None:
logging.warning(
f'Network "{name}" is not found in FMC. Cannot add to patPool.'
)
else:
self.natType = "DYNAMIC"
self.patOptions = {"patPoolAddress": new_net}
self.patOptions["interfacePat"] = (
options.interfacePat if "interfacePat" in options.keys() else False
def translated_network(self, name):
"""
Associate Network to this rule.
:param name: (str) Name of Network.
:return: None
"""
# Auto Nat rules can't use network group objects
logging.debug("In translated_network() for AutoNatRules class.")
ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
items = ipaddresses_json.get("items", [])
new_net = None
for item in items:
if item["name"] == name:
new_net = {"id": item["id"], "type": item["type"]}
break
if new_net is None:
logging.warning(
f'Network "{name}" is not found in FMC. Cannot add to translatedNetwork.'
)
else:
self.translatedNetwork = new_net
logging.info(
f'Adding "{name}" to destinationNetworks for this AutoNatRule.'
)
}
)
else:
self.selectedNetworks = [
{
"type": net1[0]["type"],
"id": net1[0]["id"],
"name": net1[0]["name"],
}
]
else:
logging.warning(
f'Network "{network}" not found. Cannot set up device for IPv4StaticRoute.'
)
elif action == "remove":
ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
networkgroup_json = NetworkGroups(fmc=self.fmc).get()
items = ipaddresses_json.get("items", []) + networkgroup_json.get(
"items", []
)
for network in networks:
net1 = list(filter(lambda i: i["name"] == network, items))
if len(net1) > 0:
if "selectedNetworks" in self.__dict__:
self.selectedNetworks = list(
filter(
lambda i: i["id"] != net1[0]["id"],
self.selectedNetworks,
)
)
else:
logging.warning(
def translated_destination(self, name):
"""
Associate Network to be used as Translated Destination.
:param name: (str) Name of Network.
:return: None
"""
logging.debug("In translated_destination() for ManualNatRules class.")
ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
networkgroup_json = NetworkGroups(
fmc=self.fmc
).get() # FIXME, shouldn't this be a part of items?
items = ipaddresses_json.get("items", [])
new_net = None
for item in items:
if item["name"] == name:
new_net = {"id": item["id"], "type": item["type"]}
break
if new_net is None:
logging.warning(
f'Network "{name}" is not found in FMC. Cannot add to translated_destination.'
)
else:
self.translatedDestination = new_net
logging.info(
def translated_source(self, name):
"""
Associate Network to be used as Translated Source.
:param name: (str) Name of Network.
:return: None
"""
logging.debug("In translated_source() for ManualNatRules class.")
ipaddresses_json = NetworkAddresses(fmc=self.fmc).get()
networkgroup_json = NetworkGroups(
fmc=self.fmc
).get() # FIXME, shouldn't this be a part of items?
items = ipaddresses_json.get("items", [])
new_net = None
for item in items:
if item["name"] == name:
new_net = {"id": item["id"], "type": item["type"]}
break
if new_net is None:
logging.warning(
f'Network "{name}" is not found in FMC. Cannot add to translated_source.'
)
else:
self.translatedSource = new_net
logging.info(
"""POST method for API for NetworkAddresses not supported."""
logging.info("POST method for API for NetworkAddresses not supported.")
pass
def put(self):
"""PUT method for API for NetworkAddresses not supported."""
logging.info("PUT method for API for NetworkAddresses not supported.")
pass
def delete(self):
"""DELETE method for API for NetworkAddresses not supported."""
logging.info("DELETE method for API for NetworkAddresses not supported.")
pass
class IPAddresses(NetworkAddresses):
"""
Dispose of this Class after 20210101.
Use NetworkAddresses() instead.
"""
def __init__(self, fmc, **kwargs):
warnings.resetwarnings()
warnings.warn(
"Deprecated: IPAddresses() should be called via NetworkAddresses()."
)
super().__init__(fmc, **kwargs)