def l3route(name, gateway, ip_network): """ Add route to l3fw This could be added to any engine type. Non-routable engine roles (L2/IPS) may still require route/s defined on the L3 management interface :param l3fw: name of firewall to add route :param gw: next hop router object :param ip_network: next hop network behind gw :return: :py:class:`smc.qpi.web.SMCResult` """ engine = Engine(name).load() return engine.add_route(gateway, ip_network)
netmask = network_and_netmask.split('/') cidr = sum([bin(int(x)).count('1') for x in netmask.pop().split('.')]) netmask.append(str(cidr)) return '/'.join(netmask) if __name__ == '__main__': session.login(url='http://172.18.1.150:8082', api_key='EiGpKD4QxlLJ25dbBEp20001') #Load the engine configuration; raises LoadEngineFailed for not found engine engine = Engine(firewall).load() with open(filename) as f: for line in f: for match in re.finditer('route=(.*) gateway=(.*) distance.*?', line, re.S): network = mask_convertor(match.group(1)) gateway = match.group(2) print "Adding route to network: {}, via gateway: {}".format(\ network, gateway) result = engine.add_route(gateway, str(network)) if not result.href: print "Failed adding network: {} with gateway: {}, reason: {}".format(\ network, gateway, result.msg) else: print "Success adding route to network: {} via gateway: {}".format(\ network, gateway) session.logout()