Example #1
0
        table = next(iter(node.labels))
        unique_tn = ns.get_unique_tn(node)
        props = dict(table=table, unique_tn=unique_tn)
        tables.append(props)
        get_attributes(node)
    linked_tables[parent_table] = tables
    return


# Initialize Environment
projectname = "ansible"
config = my_env.init_env(projectname, __file__)
logging.info("Start application")
cmdb_json = os.getenv('JSONFILE')
ans = ansiblestore.SqliteUtils()
ns = neostore.NeoStore(refresh='No')

# Collect structure first: attributes related to tables, and how tables are linked to each other.
# Key is the unique table name, value is a list of dictionary attributes
attribs_table = {}
# Key is unique table name, value is dictionary with table (dictionary table name) and unique_tn (unique table name)
linked_tables = {}
start_node = ns.get_nodes('server')[0]
get_attributes(start_node)

with open(cmdb_json) as cmdb_file:
    data = json.loads(cmdb_file.read())
    li = my_env.LoopInfo('Servers', 20)
    # Create Server Node
    t_name = 'server'
    for item in data:
Example #2
0
"""
This script will read the person and convert it to a Neo4J database.
"""

import logging
from lib import localstore
from lib import my_env
from lib.murcs import *
from lib.neostructure import *
from lib import neostore

cfg = my_env.init_env("bellavista", __file__)
logging.info("Start Application")
lcl = localstore.sqliteUtils(cfg)
ns = neostore.NeoStore(cfg)

sites = lcl.get_table("site")
region_d = {}
country_d = {}
site_node_d = {}
my_loop = my_env.LoopInfo("Sites", 20)
for site in sites:
    row = dict(site)
    # Get site links
    region = row.pop("region")
    if region:
        region_d[row["siteId"]] = region
    country = row.pop("country")
    if country:
        country_d[row["siteId"]] = country
    # Site link information is handled and removed from row, now handle remaining columns
Example #3
0
                handle_dict(diction[k], parent_node)
            elif isinstance(diction[k], list):
                for elem in diction[k]:
                    if isinstance(elem, dict):
                        parent_node = attribs[attrib_name]
                        handle_dict(elem, parent_node)
            # To do: Handle case where diction[k] is list of strings (not a list of dictionaries.
    return


# Initialize Environment
projectname = "ansible"
config = my_env.init_env(projectname, __file__)
logging.info("Start application")
cmdb_json = os.getenv('JSONFILE')
ns = neostore.NeoStore(refresh='Yes')

with open(cmdb_json) as cmdb_file:
    data = json.loads(cmdb_file.read())
    li = my_env.LoopInfo('Servers', 10000)
    # Create Server Node
    t_lbl = 'server'
    t_props = dict(name=t_lbl, attrib=t_lbl)
    top_node = ns.create_node(t_lbl, **t_props)
    attribs[t_lbl] = top_node
    for item in data:
        handle_dict(data[item], top_node)
print(f"Found {li.end_loop()} servers.")
for attrib in attribs:
    print(f"Server attribute: {attrib}")
logging.info("End Application")