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 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 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)