Skip to content

Commit

Permalink
1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lmartinson committed Jun 10, 2021
1 parent 474d6a5 commit 48f82b4
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 199 deletions.
4 changes: 4 additions & 0 deletions smc-monitoring/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@ Release History
- Remove kwargs from websocket call to super to support older versions of websocket-client
- Fixed fetch_batch to only return a single payload, previous versions were unlimited

1.4.0
+++++

- Update requirements to fp_NGFW_SMC_python >= 1.0.0


2 changes: 1 addition & 1 deletion smc-monitoring/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This package has been tested with Python 2.7, 3.5 and 3.6.
Requirements
============

smc-python >= v0.6.1
fp_NGFW_SMC_python >= 1.0.0

websocket-client

Expand Down
2 changes: 1 addition & 1 deletion smc-monitoring/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#file:../#egg=smc-python
smc-python >= 0.6.0
fp_NGFW_SMC_python >= 1.0.0
websocket-client >= 0.48.0
2 changes: 1 addition & 1 deletion smc-monitoring/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@
"License :: OSI Approved :: Apache Software License",
],
zip_safe=False,
install_requires=["smc-python >=0.6.0", "websocket-client >=0.48.0"],
install_requires=["fp_NGFW_SMC_python >=1.0.0", "websocket-client >=0.48.0"],
)
2 changes: 1 addition & 1 deletion smc-monitoring/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "1.3.1"
VERSION = "1.4.0"
2 changes: 1 addition & 1 deletion smc/__version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.0.4'
__version__ = '1.0.5'
__author__ = 'Forcepoint'
__description__ = 'Python based API to Forcepoint NGFW Management Center'
__url__ = 'http://github.com/Forcepoint/fp-NGFW-SMC-python'
Expand Down
61 changes: 43 additions & 18 deletions smc/core/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@
VirtualPhysicalInterface,
SwitchPhysicalInterface,
VPNBrokerInterface,
SwitchInterface,
)
from smc.core.sub_interfaces import LoopbackClusterInterface, LoopbackInterface
from smc.base.structs import BaseIterable
from smc.api.exceptions import UnsupportedInterfaceType, InterfaceNotFound
from smc.compat import get_best_version
from smc.compat import get_best_version, is_api_version_less_than_or_equal


def get_all_loopbacks(engine):
Expand Down Expand Up @@ -332,7 +333,7 @@ class SwitchInterfaceCollection(InterfaceCollection):
Get specific switch interfaces assigned on the given engine::
for interface in engine.switch_physical_interface:
print(interface, interface.port_groups)
print(interface, interface.port_groups_interface)
You can also retrieve a switch directly by referencing it using the
switch interface id. Switch interfaces will always have a name starting
Expand All @@ -352,7 +353,10 @@ class SwitchInterfaceCollection(InterfaceCollection):
"""

def __init__(self, engine):
super(SwitchInterfaceCollection, self).__init__(engine, "switch_physical_interface")
if is_api_version_less_than_or_equal("6.7"):
super(SwitchInterfaceCollection, self).__init__(engine, "switch_physical_interface")
else:
super(SwitchInterfaceCollection, self).__init__(engine, "switch_interface")

def add_switch_interface(
self, interface_id, appliance_switch_module="110", comment=None, **kwargs
Expand All @@ -361,6 +365,7 @@ def add_switch_interface(
In case of Switch Physical/Port Group interfaces, the interface ID must
be prefixed by 'SWP\\_'. For example, for switch ID 1 and Port Group ID 1.2
you must enter 'SWP\\_1' for the switch and SWP_1.2 for the Port Group.
Since API 6.8 prefix is 'SWI\\_'
:param str interface_id: Name of the interface, must be prefixed with 'SWP\\_'
:param str appliance_switch_module: appliance switch module which specifies
Expand All @@ -372,13 +377,23 @@ def add_switch_interface(
:return: None
"""
interface = SwitchPhysicalInterface(
engine=self._engine,
interface_id=interface_id,
appliance_switch_module=appliance_switch_module,
comment=comment,
**kwargs
)
if is_api_version_less_than_or_equal("6.7"):
interface = SwitchPhysicalInterface(
engine=self._engine,
interface_id=interface_id,
appliance_switch_module=appliance_switch_module,
comment=comment,
**kwargs
)
else:
interface = SwitchInterface(
engine=self._engine,
interface_id=interface_id,
appliance_switch_module=appliance_switch_module,
comment=comment,
**kwargs
)

self._engine.add_interface(interface, **kwargs)

def add_port_group_interface(
Expand All @@ -402,7 +417,7 @@ def add_port_group_interface(
group with the specified settings
:param str interface_id: The top level switch, naming convention should be
SWP_0, SWP_1, etc.
SWP_0, SWP_1, etc. ( Since API 6.8: SWI_0, SWI_1..)
:param int port_group_id: Port group number encapsulating switch port/s
:param list interface_ports: list of interface ports to add to this port
group. If the port group.
Expand All @@ -414,13 +429,23 @@ def add_port_group_interface(
:return: None
"""
switch = self._engine.interface.get(interface_id)
switch_port = {
"interface_id": "{}.{}".format(switch.interface_id, port_group_id),
"switch_physical_interface_port": [
{"switch_physical_interface_port_number": port} for port in interface_ports
],
"zone_ref": zone_ref,
}
if is_api_version_less_than_or_equal("6.7"):
switch_port = {
"interface_id": "{}.{}".format(switch.interface_id, port_group_id),
"switch_physical_interface_port": [
{"switch_physical_interface_port_number": port} for port in interface_ports
],
"zone_ref": zone_ref,
}
else:
switch_port = {
"interface_id": "{}.{}".format(switch.interface_id, port_group_id),
"switch_interface_port": [
{"physical_switch_port_number": port} for port in interface_ports
],
"zone_ref": zone_ref,
}

switch_port.update(interfaces=interfaces if interfaces else [])
interface = {"interface_id": switch.interface_id, "port_group_interface": [switch_port]}
switch.update_interface(SwitchPhysicalInterface(**interface))
Expand Down
66 changes: 47 additions & 19 deletions smc/core/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
get_sub_interface,
SubInterfaceCollection,
)
from smc.compat import string_types
from smc.compat import string_types, is_api_version_less_than_or_equal
from smc.elements.helpers import zone_helper, logical_intf_helper
from smc.elements.network import Zone
from smc.base.structs import BaseIterable
Expand Down Expand Up @@ -1167,13 +1167,22 @@ def _add_interface(self, interface_id, **kw):
# Everything else is top level
base_interface = ElementCache()

base_interface.update(
switch_physical_interface_switch_module_ref=element_default(
ApplianceSwitchModule, kw.pop("appliance_switch_module", None)
),
interface_id=interface_id,
**kw
)
if is_api_version_less_than_or_equal("6.7"):
base_interface.update(
switch_physical_interface_switch_module_ref=element_default(
ApplianceSwitchModule, kw.pop("appliance_switch_module", None)
),
interface_id=interface_id,
**kw
)
else:
base_interface.update(
switch_interface_switch_module_ref=element_default(
ApplianceSwitchModule, kw.pop("appliance_switch_module", None)
),
interface_id=interface_id,
**kw
)

self.data = base_interface

Expand Down Expand Up @@ -1226,9 +1235,14 @@ def update_interface(self, other_interface, ignore_mgmt=True):
if len(this.switch_physical_interface_port) != len(
other.switch_physical_interface_port
):
this.data.update(
switch_physical_interface_port=other.switch_physical_interface_port
)
if is_api_version_less_than_or_equal("6.7"):
this.data.update(
switch_physical_interface_port=other.switch_physical_interface_port
)
else:
this.data.update(
switch_interface_port=other.switch_physical_interface_port
)
updated = True

if this.zone_ref != other.zone_ref: # Zone compare
Expand All @@ -1237,20 +1251,30 @@ def update_interface(self, other_interface, ignore_mgmt=True):

# Are port groups and comments alike. Switch port count matches, but value/s
# within the existing changed so take new setting
val = (
"switch_physical_interface_port_number",
"switch_physical_interface_port_comment",
)
if is_api_version_less_than_or_equal("6.7"):
val = (
"switch_physical_interface_port_number",
"switch_physical_interface_port_comment",
)
else:
val = (
"switch_interface_port_number",
"switch_interface_port_comment",
)

if set(
[(d.get(val[0]), d.get(val[1])) for d in this.switch_physical_interface_port]
) ^ set(
[(d.get(val[0]), d.get(val[1])) for d in other.switch_physical_interface_port]
):

this.data.update(
switch_physical_interface_port=other.switch_physical_interface_port
)
if is_api_version_less_than_or_equal("6.7"):
this.data.update(
switch_physical_interface_port=other.switch_physical_interface_port
)
else:
this.data.update(
switch_interface_port=other.switch_physical_interface_port
)
updated = True

# If there is more than 1 interfaces (IP's assigned) on any given
Expand Down Expand Up @@ -1308,6 +1332,10 @@ def appliance_switch_module(self):
)


class SwitchInterface(SwitchPhysicalInterface):
typeof = "switch_interface"


class PhysicalInterface(Interface):
"""
Physical Interfaces on NGFW. This represents the following base configuration for
Expand Down
12 changes: 9 additions & 3 deletions smc/elements/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"""
from smc.base.model import Element, SubElement, ElementCache
from smc.base.decorators import cached_property
from smc.compat import is_api_version_less_than_or_equal
from smc.elements.servers import ProxyServer
from smc.base.util import element_resolver
from smc.base.structs import BaseIterable
Expand Down Expand Up @@ -304,6 +305,9 @@ def proxy_server(self):
for proxy in ProxyServer.objects.all():
if self._inspected_service_ref.startswith(proxy.href + "/"):
return proxy
# Since API 6.11
else:
return Element.from_href(self.protocol_agent_values.get("proxy_server_ref"))

def _update(self, **kwargs):
"""
Expand All @@ -330,9 +334,11 @@ def _update(self, **kwargs):
)

if self._inspected_service_ref != enabled_services.get(self.protocol_agent.name):
self.protocol_agent_values["inspected_service_ref"] = enabled_services.get(
self.protocol_agent.name
)
if is_api_version_less_than_or_equal("6.10"):
self.protocol_agent_values["inspected_service_ref"] = enabled_services.get(
self.protocol_agent.name)
else:
self.protocol_agent_values["proxy_server_ref"] = proxy_server.href
updated = True
return updated

Expand Down
38 changes: 30 additions & 8 deletions smc/examples/engine-node-health.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,32 @@
"""

# Python Base Import
import sys
from smc import session
from smc.core.engines import Layer3VirtualEngine, Layer3Firewall
from smc.core.waiters import NodeStatusWaiter
from smc_info import *

if __name__ == "__main__":
URLSMC = "http://localhost:8082"
APIKEYSMC = "HuphG4Uwg4dN6TyvorTR0001"
try:
session.login(url=URLSMC, api_key=APIKEYSMC, verify=False, timeout=120, api_version="6.9")
except BaseException as exception_retournee:
sys.exit(-1)

if __name__ == "__main__":
session.login(url=SMC_URL, api_key=API_KEY, verify=False, timeout=120, api_version=API_VERSION)
print("session OK")

try:

virtual_engine = Layer3VirtualEngine("Dubai Virtual 1")
print("Check nodes status for {}...".format(virtual_engine))

for node in virtual_engine.nodes:

# Wait for node to be Online
waiter = NodeStatusWaiter(node, "Online", max_wait=3)
while not waiter.done():
status = waiter.result(5)
print("Status after 5 sec wait: {}".format(status))
print("Node:{} is {}".format(node, status))

assert status is not None, "Node {} can't be contacted".format(node)

for stats in node.hardware_status.filesystem:
print("hardware status.filesystem={}".format(stats))
for stats in node.hardware_status.logging_subsystem:
Expand All @@ -38,7 +47,19 @@
print("health=>{}".format(node.health))

single_fw = Layer3Firewall("Plano")
print("Check nodes status for {}...".format(single_fw))

for node in single_fw.nodes:

# Wait for node to be Online
waiter = NodeStatusWaiter(node, 'Online', max_wait=3)
while not waiter.done():
status = waiter.result(5)
print("Status after 5 sec wait: {}".format(status))
print("Node:{} is {}".format(node, status))

assert status is not None, "Node {} can't be contacted".format(node)

# should be None
print("health=>Master Node={}".format(node.health.master_node))
print("health=>Node status={}".format(node.health.engine_node_status))
Expand All @@ -48,5 +69,6 @@

except Exception as e:
print(e)
exit(-1)
finally:
session.logout()
Loading

0 comments on commit 48f82b4

Please sign in to comment.