Ejemplo n.º 1
0
#pylint: skip-file
from __future__ import print_function
from ruruki.graphs import Graph

# create a empty graph
graph = Graph()


# create some constraints to ensure uniqueness
graph.add_vertex_constraint("person", "name")
graph.add_vertex_constraint("book", "title")
graph.add_vertex_constraint("author", "fullname")
graph.add_vertex_constraint("category", "name")


# add in a couple books and their authors
# Note that I am duplicating the books title property as a name too. This is for ruruki-eye display
programming = graph.get_or_create_vertex("category", name="Programming")
operating_systems = graph.get_or_create_vertex("category", name="Operating Systems")


python_crash_course = graph.get_or_create_vertex("book", title="Python Crash Course")
graph.set_property(python_crash_course, name="Python Crash Course")
eric_matthes = graph.get_or_create_vertex("author", fullname="Eric Matthes", name="Eric", surname="Matthes")
graph.get_or_create_edge(python_crash_course, "CATEGORY", programming)
graph.get_or_create_edge(python_crash_course, "BY", eric_matthes)


python_pocket_ref = graph.get_or_create_vertex("book", title="Python Pocket Reference")
graph.set_property(python_pocket_ref, name="Python Pocket Reference")
mark_lutz = graph.get_or_create_vertex("author", fullname="Mark Lutz", name="Mark", surname="Lutz")
Ejemplo n.º 2
0
"""
Scrape an ansable inventory and build a dependency graph.
"""
from ruruki.graphs import Graph

__all__ = ["GRAPH", "scrape_inventroy", "scrape_hosts", "scrape_playbook"]

GRAPH = Graph()
GRAPH.add_vertex_constraint("HOST", "name")
GRAPH.add_vertex_constraint("GROUP", "name")
GRAPH.add_vertex_constraint("PLAY", "name")
GRAPH.add_vertex_constraint("TASK", "name")


def _link_node_to_groups(node, groups, edge_label="HAS-GROUP"):
    """
    Create group node for all the groups provided and link the
    node to the group node.

    :param node: Node that is using the group.
    :type node: :class:`ruruki.interfaces.IVertex`
    :param groups: Iterable of groups that you are creating,
        inspecting and linking to the node.
    :type groups: :class:`ansible.inventroy.group.Group`
    :param edge_label: Edge label to use.
    :type edge_label: :class:`str`
    """
    for group in groups:
        if group.get_name() == "all":
            continue
Ejemplo n.º 3
0
#pylint: skip-file

import logging
import inspect
import ruruki

from ruruki.graphs import Graph

GRAPH = Graph()
GRAPH.add_vertex_constraint("class", "name")
GRAPH.add_vertex_constraint("method", "name")
GRAPH.add_vertex_constraint("file", "name")
GRAPH.add_vertex_constraint("function", "name")
GRAPH.add_vertex_constraint("module", "name")

SEEN = set()


def build_dep(lib, parent):
    previous = parent

    for name, module in inspect.getmembers(lib, inspect.ismodule):
        if module in SEEN:
            continue
        SEEN.add(module)
        parent = GRAPH.get_or_create_vertex("module", name=name)

        # link to the previous parent
        GRAPH.get_or_create_edge(parent, "comes-form", previous)

        try:
Ejemplo n.º 4
0
"""
Scrape an ansable inventory and build a dependency graph.
"""
from ruruki.graphs import Graph

__all__ = ["GRAPH", "scrape_inventroy", "scrape_hosts", "scrape_playbook"]

GRAPH = Graph()
GRAPH.add_vertex_constraint("HOST", "name")
GRAPH.add_vertex_constraint("GROUP", "name")
GRAPH.add_vertex_constraint("PLAY", "name")
GRAPH.add_vertex_constraint("TASK", "name")


def _link_node_to_groups(node, groups, edge_label="HAS-GROUP"):
    """
    Create group node for all the groups provided and link the
    node to the group node.

    :param node: Node that is using the group.
    :type node: :class:`ruruki.interfaces.IVertex`
    :param groups: Iterable of groups that you are creating,
        inspecting and linking to the node.
    :type groups: :class:`ansible.inventroy.group.Group`
    :param edge_label: Edge label to use.
    :type edge_label: :class:`str`
    """
    for group in groups:
        if group.get_name() == "all":
            continue
Ejemplo n.º 5
0
#pylint: skip-file
from ruruki.graphs import Graph

# create a empty graph
graph = Graph()

# create some constraints to ensure uniqueness
graph.add_vertex_constraint("person", "name")
graph.add_vertex_constraint("book", "title")
graph.add_vertex_constraint("author", "fullname")
graph.add_vertex_constraint("category", "name")

# add in a couple books and their authors
# Note that I am duplicating the books title property as a name too. This is for ruruki-eye display
programming = graph.get_or_create_vertex("category", name="Programming")
operating_systems = graph.get_or_create_vertex("category",
                                               name="Operating Systems")

python_crash_course = graph.get_or_create_vertex("book",
                                                 title="Python Crash Course")
graph.set_property(python_crash_course, name="Python Crash Course")
eric_matthes = graph.get_or_create_vertex("author",
                                          fullname="Eric Matthes",
                                          name="Eric",
                                          surname="Matthes")
graph.get_or_create_edge(python_crash_course, "CATEGORY", programming)
graph.get_or_create_edge(python_crash_course, "BY", eric_matthes)

python_pocket_ref = graph.get_or_create_vertex("book",
                                               title="Python Pocket Reference")
graph.set_property(python_pocket_ref, name="Python Pocket Reference")
Ejemplo n.º 6
0
#pylint: skip-file

import logging
import inspect
import ruruki

from ruruki.graphs import Graph


GRAPH = Graph()
GRAPH.add_vertex_constraint("class", "name")
GRAPH.add_vertex_constraint("method", "name")
GRAPH.add_vertex_constraint("file", "name")
GRAPH.add_vertex_constraint("function", "name")
GRAPH.add_vertex_constraint("module", "name")


SEEN = set()

def build_dep(lib, parent):
    previous = parent

    for name, module in inspect.getmembers(lib, inspect.ismodule):
        if module in SEEN:
            continue
        SEEN.add(module)
        parent = GRAPH.get_or_create_vertex("module", name=name)

        # link to the previous parent
        GRAPH.get_or_create_edge(parent, "comes-form", previous)