def read(logger, name, config): ''' Create a static tunnel from the given configuration object. ''' mode = util.enum_get(config["mode"], ["gre", "gretap"]) local = util.ip_address_get(config["local"]) remote = util.ip_address_get(config["remote"]) address = util.ip_address_get(config["address"]) netmask = util.netmask_get(config["netmask"], util.ip_address_is_v6(address)) key = util.integer_get(config["key"], minval=0) if "key" in config else None ikey = util.integer_get(config["ikey"], minval=0) if "ikey" in config else None okey = util.integer_get(config["okey"], minval=0) if "okey" in config else None if key is None and ikey is not None and okey is None: raise ReadError("ikey defined but okey undefined in overlay '%s'" % name) if key is None and ikey is None and okey is not None: raise ReadError("okey defined but ikey undefined in overlay '%s'" % name) return Tunnel( logger, name, mode, local, remote, address, netmask, key, ikey, okey, )
def read(log, log_level, conf=None, config=None): ''' Parse a configuration, file or dictionary, and return an overlay object. ''' # If specified, read the overlay configuration file. if conf: config = util.config(conf) elif config: config = copy.deepcopy(config) else: raise NoOverlayConfigError() # Get the overlay configuration. section = config["overlay"] # Fetch just enough configuration to start an overlay logger. name = util.name_get(section["name"]) lg = logger.create(log, log_level, "l3overlay", name) lg.start() # Global overlay configuration. enabled = util.boolean_get(section["enabled"]) if "enabled" in section else True asn = util.integer_get(section["asn"], minval=0, maxval=65535) linknet_pool = util.ip_network_get(section["linknet-pool"]) fwbuilder_script_file = section["fwbuilder-script"] if "fwbuilder-script" in section else None # Generate the list of nodes, sorted numerically. nodes = [] for key, value in section.items(): if key.startswith("node-"): node = util.list_get(value, length=2, pattern="\\s") nodes.append((util.name_get(node[0]), util.ip_address_get(node[1]))) if not nodes: raise NoNodeListError(name) # Get the node object for this node from the list of nodes. this_node = next((n for n in nodes if n[0] == util.name_get(section["this-node"])), None) if not this_node: raise MissingThisNodeError(name, util.name_get(section["this-node"])) # Static interfaces. interfaces = [] for s, c in config.items(): if s.startswith("static"): interfaces.append(interface.read(lg, s, c)) elif s == "DEFAULT" or s == "overlay": continue else: raise UnsupportedSectionTypeError(name, s) # Return overlay object. return Overlay(lg, name, enabled, asn, linknet_pool, fwbuilder_script_file, nodes, this_node, interfaces)
def read(logger, name, config): ''' Create a static overlay link from the given configuration object. ''' outer_address = util.ip_address_get(config["outer-address"]) inner_address = util.ip_address_get(config["inner-address"]) inner_overlay_name = util.name_get(config["inner-overlay-name"]) netmask = util.netmask_get(config["netmask"], util.ip_address_is_v6(inner_address)) if (type(inner_address) != type(outer_address)): raise ReadError("inner address '%s' (%s) and outer address '%s' (%s) must be the same type of IP address" % (inner_address, str(type(nner_address)), outer_address, str(type(outer_address)))) return OverlayLink(logger, name, outer_address, inner_address, inner_overlay_name, netmask)
def read(logger, name, config): ''' Create a static dummy from the given configuration object. ''' address = util.ip_address_get(config["address"]) netmask = util.netmask_get(config["netmask"], util.ip_address_is_v6(address)) return Dummy(logger, name, address, netmask)
def read(logger, name, config): ''' Create a static bgp from the given configuration object. ''' neighbor = util.ip_address_get(config["neighbor"]) local = util.ip_address_get(config["local"]) if "local" in config else None local_asn = util.integer_get(config["local-asn"], minval=0, maxval=65535) if "local-asn" in config else None neighbor_asn = util.integer_get(config["neighbor-asn"], minval=0, maxval=65535) if "neighbor-asn" in config else None bfd = util.boolean_get(config["bfd"]) if "bfd" in config else False ttl_security = util.boolean_get(config["ttl-security"]) if "ttl-security" in config else False description = config["description"] if "description" in config else None import_prefixes = [util.bird_prefix_get(v) for k, v in config.items() if k.startswith("import-prefix")] return BGP(logger, name, neighbor, local, local_asn, neighbor_asn, bfd, ttl_security, import_prefixes)
def read(logger, name, config): ''' Create a static vlan from the given configuration object. ''' id = util.integer_get(config["id"], minval=0, maxval=4096) physical_interface = util.name_get(config["physical-interface"]) address = util.ip_address_get(config["address"]) netmask = util.netmask_get(config["netmask"], util.ip_address_is_v6(address)) return VLAN(logger, name, id, physical_interface, address, netmask)
def read(logger, name, config): ''' Create a static tuntap from the given configuration object. ''' mode = util.enum_get(config["mode"], ["tun", "tap"]) address = util.ip_address_get(config["address"]) netmask = util.netmask_get(config["netmask"], util.ip_address_is_v6(address)) uid = util.integer_get(config["uid"], minval=0) if "uid" in config else None gid = util.integer_get(config["gid"], minval=0) if "gid" in config else None return Tuntap(logger, name, mode, address, netmask, uid, gid)