ndejong / pfsense_fauxapi

REST based API interface for pfSense 2.3.x and 2.4.x to facilitate devops
Apache License 2.0
354 stars 61 forks source link

config_set does update but new Virtual IP is not added #80

Open maltere opened 3 years ago

maltere commented 3 years ago

I try to update the Virtual IPs using the FauxAPI, but added IPs are not actually assigned to the interface.

I can add or remove the configuration of new Virtual IPs. The IPs are shown in the WebGUI and are also shown in the API call using config_get. However, these IPs are not added nor removed after an successful API call. If I update the Virtual IP in the Web GUI the IP is added to the Interface. (click the edit button and save without changes)

api = PfsenseFauxapi(config.PFSENSE_IP,
                     config.FAUXAPI_KEY,
                     config.FAUXAPI_SECRET)

vips_raw = ['192.168.50.5'] # example ip

new_vips = [
    {
        'mode': 'ipalias',
        'interface': 'wan',
        'uniqid': '60be5980e1c0d',
        'descr': '',
        'type': 'single',
        'subnet_bits': '32',
        'subnet': ip
    }
    for ip in vips_raw
]

api.config_set({ 'vip': new_vips }, 'virtualip')

I tried additionally:

api.config_reload()
api.send_event('interface reconfigure all')

What else can I try to add the Virtual IP via the FauxAPI?

maltere commented 3 years ago

In case someone wonders:

Not setting the param uniqid or setting it uniquely computed based on the IP is also not helping.

def uniqueid(ip):
    length = 13
    _hashable = f'salt-vip {ip}'
    _hash = sha256(_hashable.encode('utf-8')).hexdigest()
    return _hash[:length].lower()

new_vips = [
    {
        'mode': 'ipalias',
        'interface': 'wan',
        'uniqid': uniqueid(ip),
        'descr': 'Added by DB Listen',
        'type': 'single',
        'subnet_bits': '32',
        'subnet': ip
    }
    for ip in vips_raw
]