How to use the autonetkit.log.warning function in autonetkit

To help you get started, we’ve selected a few autonetkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datacenter / ignite-DEPRECATED / ank / autonetkit / autonetkit / console_script.py View on Github external
while True:
                time.sleep(1)
                rebuild = False
                if input_filemonitor.next():
                    rebuild = True

                if rebuild:
                    try:
                        log.info("Input graph updated, recompiling network")
                        with open(options.file, "r") as fh:
                            input_string = fh.read()  # read updates
                        dst_folder = workflow.manage_network(input_string,
                                       timestamp, build_options)
                        log.info("Monitoring for updates...")
                    except Exception, e:
                        log.warning("Unable to build network %s" % e)
                        traceback.print_exc()

        except KeyboardInterrupt:
            log.info("Exiting")

    return dst_folder
github sk2 / autonetkit / autonetkit / render.py View on Github external
# TODO: make sure is an abspath here so don't wipe user directory!!!
    if render_output_dir and not os.path.isdir(render_output_dir):
        try:
            os.makedirs(render_output_dir)
        except OSError, e:
            if e.strerror == "File exists":
                pass  # created by another process, safe to ignore
            else:
                raise e

    if render_template_file:
        try:
            render_template = TEMPLATE_LOOKUP.get_template(
                render_template_file)
        except SyntaxException, error:
            log.warning("Unable to render %s: "
                        "Syntax error in template: %s" % (node, error))
            return

        if node.render.dst_file:
            dst_file = os.path.join(render_output_dir, node.render.dst_file)
            with open(dst_file, 'wb') as dst_fh:
                try:
                    dst_fh.write(render_template.render(
                        node=node,
                        version_banner=version_banner,
                        date=date,
                    ))
                except KeyError, error:
                    log.warning("Unable to render %s:"
                                " %s not set" % (node, error))
                    from mako import exceptions
github sk2 / autonetkit / autonetkit / anm / node.py View on Github external
    @property
    def _nx_node_data(self):
        """Return NetworkX node data for the node
        """
        try:
            return self._graph.node[self.node_id]
        except Exception, e:
            log.warning("Error accessing node data %s for node %s: %s" %
                        (self.overlay_id, self.node_id, e))
github sk2 / autonetkit / autonetkit / nidb.py View on Github external
def __setitem__(self, key, value):
        if isinstance(value, dict):
            log.warning("Adding dictionary %s: did you mean to add a config_stanza?" % key)
        self._odict[key] = value
github sk2 / autonetkit / autonetkit / design / layer2.py View on Github external
g_l2 = anm['layer2']

        # check for igp and ebgp on same switch
        for switch in sorted(g_l2.switches()):
            neigh_asns = defaultdict(int)
            for neigh in switch.neighbors():
                if neigh.get('asn') is None:
                    continue  # don't add if not set
                neigh_asns[neigh.get('asn')] += 1

            # IGP if two or more neighbors share the same ASN
            is_igp = any(asns > 1 for asns in neigh_asns.values())
            # eBGP if more than one unique neigh ASN
            is_ebgp = len(neigh_asns.keys()) > 1
            if is_igp and is_ebgp:
                log.warning("Switch %s contains both IGP and eBGP neighbors",
                            switch)

        # check for multiple links from nodes to switch
        for switch in sorted(g_l2.switches()):
            for neighbor in sorted(switch.neighbors()):
                edges = g_l2.edges(switch, neighbor)
                if len(edges) > 1:
                    # more than one edge between the (src, dst) pair -> parallel
                    log.warning("There are multiple parallel edges (%s) between %s and device %s. "
                        "This may lead to unexpected protocol behavior.",
                                len(edges), switch, neighbor)
github sk2 / autonetkit / autonetkit / anm / ank_element.py View on Github external
def init_logging(self, my_type):
        return
        try:
            self_id = str(self)
        except Exception, e:
            #TODO: log warning here
            import autonetkit.log as log
            log.warning("Unable to set per-element logger %s", e)
            self_id = ""


        log_extra={"type": my_type, "id": self_id}
        object.__setattr__(self, 'log_extra', log_extra)
github sk2 / autonetkit / autonetkit / render.py View on Github external
with open(dst_file, 'wb') as dst_fh:
        try:
            dst_fh.write(render_template.render(
                topology=topology,
                version_banner=version_banner,
                date=date,
            ))
        except KeyError, error:
            log.warning("Unable to render %s: %s not set" % (topology, error))
        except AttributeError, error:
            log.warning("Unable to render %s: %s " % (topology, error))
        except NameError, error:
            log.warning("Unable to render %s: %s. Check all variables used are defined" % (
                topology, error))
        except TypeError, error:
            log.warning("Unable to render topology: %s." % (error))
            from mako import exceptions
            log.warning(exceptions.text_error_template().render())
github sk2 / autonetkit / autonetkit / compilers / device / ubuntu.py View on Github external
# initialise for case of no routes -> simplifies template logic
        node.host_routes_v6 = []
        if not self.anm['phy'].data.enable_routing:
            log.info('Routing disabled, not configuring static routes for Ubuntu server %s'
                     % node)
            return

        if self.anm['phy'].node(node).dont_configure_static_routing:
            log.info('Static routing disabled for server %s' % node)
            return

        l3_node = self.anm['layer3'].node(node)
        gateway_list = [n for n in l3_node.neighbors()
                        if n.is_router()]
        if not len(gateway_list):
            log.warning('Server %s is not directly connected to any routers'
                        % node)
            return
        elif len(gateway_list) > 1:
            log.info('Server %s is multi-homed: using gateways %s'
                     % (node, sorted(gateway_list)))

        # TODO: warn if server has no neighbors in same ASN (either in design or verification steps)
        # TODO: need to check that servers don't have any direct ebgp
        # connections

        cloud_init_static_routes = []
        g_l3 = self.anm['layer3']

        for gateway in sorted(gateway_list):
            for gateway_edge_l3 in g_l3.edges(node, gateway):
                server_interface = gateway_edge_l3.src_int
github sk2 / autonetkit / autonetkit / render.py View on Github external
dst_fh.write(render_template.render(
                topology=topology,
                version_banner=version_banner,
                date=date,
            ))
        except KeyError, error:
            log.warning("Unable to render %s: %s not set" % (topology, error))
        except AttributeError, error:
            log.warning("Unable to render %s: %s " % (topology, error))
        except NameError, error:
            log.warning("Unable to render %s: %s. Check all variables used are defined" % (
                topology, error))
        except TypeError, error:
            log.warning("Unable to render topology: %s." % (error))
            from mako import exceptions
            log.warning(exceptions.text_error_template().render())
github sk2 / autonetkit / autonetkit / anm / graph.py View on Github external
data = in_c

            elif len(in_edge) == 4:
                # (src, dst, ekey, data) format
                in_a, in_b = in_edge[0], in_edge[1]
                if in_a in self and in_b in self:
                    src = in_a
                    dst = in_b
                    ekey = in_edge[2]
                    data = in_edge[3]

            # TODO: if edge not set at this point, give error/warn

            # TODO: add check that edge.src and edge.dst exist
            if (src is None or dst is None) and warn:
                log.warning("Unsupported edge %s" % str(in_edge))
            if not(src in self and dst in self):
                if warn:
                    self.log.debug("Not adding edge %s, src/dst not in overlay"
                                   % str(in_edge))
                continue

            # TODO: warn if not multigraph and edge already exists - don't
            # add/clobber
            #TODO: double check this logic + add test case
            data.update(**kwargs)
            if self.is_multigraph() and ekey is None:
                # specifically allocate a key
                if src in used_keys and dst in used_keys[src]:
                    pass # already established
                else:
                    try: