gabstopper / smc-python

Forcepoint Security Management Center python library:(Moved to official Forcepoint repo)
https://github.com/Forcepoint/fp-NGFW-SMC-python
Apache License 2.0
29 stars 13 forks source link

link DHCP server with an interface as DHCP relay #64

Closed Exethir closed 5 years ago

Exethir commented 5 years ago

Hi david, i'm currently working with smc-python and i can't find how to make the DHCP relay of a virtual interface linked with a DHCP server. I'm searching a function that seems like that : interface.add_dhcp_relay(vlan_id, dhcp_serveur) but i could not find anything like that in the doc.

ad1rie1 commented 5 years ago

Hi, the Element DHCPServer do not exist in the code ;) You can easily créte him with the code : from smc.base.model import Element,ElementCreator class DHCPServer(Element): typeof = 'dhcp_server'

@classmethod
def create(cls, name, address, comment=None):       
    json = {
        'name': name,
        'address': address,
        'comment': comment}
    return ElementCreator(cls, json)
Exethir commented 5 years ago

thanks for your response, but i already have the DHCP server created from the management client. I need to use it as a DHCP relay on an interface

ad1rie1 commented 5 years ago

Ok , Use the object bellow like this :

from smc.base.model import Element,ElementCreator
class DHCPServer(Element):
       typeof = 'dhcp_server'

        @classmethod
         def create(cls, name, address, comment=None):       
          json = {
                  'name': name,
                  'address': address,
                  'comment': comment}
          return ElementCreator(cls, json)
if name == 'main':
            DHCP = DHCPServer(name='YOURDHCP')

            DHCPDATA = {'element': [DHCP.href], 'enabled': True, 'max_packet_size': 576, 'trusted_circuit': False}
            interface0VLAN3 = engine.interface.get('0.3') # <- retrieve the interface

            for node in interface0VLAN3.interfaces: # <- iterate the nodes of that interface and set value/s
                if node.typeof == 'cluster_virtual_interface': 
                    node.update(relayed_by_dhcp=True)

            interface0VLAN3.update(dhcp_relay=DHCPDATA)
            interface0VLAN3.update()
Exethir commented 5 years ago

thanks a lot, that's exactly what i wanted to do :)