def delete_disconnected()

in source/tools/delete_disconnected.py [0:0]


def delete_disconnected():
    """
    This function will clean nodes without connections from the content database table.
    """
    node_type = "S3"
    nodes = []
    connections = []
    for node_type in NODE_TYPES:
        nodes = nodes + cached_by_service(node_type)
    for conn_type in CONNECTION_TYPES:
        connections = connections + cached_by_service(conn_type)
    remove_nodes = []
    # scan for connections with 'to' or 'from' set with
    for node in nodes:
        found = False
        for conn in connections:
            if node["arn"] == conn["from"] or node["arn"] == conn["to"]:
                found = True
        if not found:
            remove_nodes.append(node)

    resource = boto3.resource("dynamodb")
    table = resource.Table(os.environ["CONTENT_TABLE_NAME"])
    for node in remove_nodes:
        print(node)
        table.delete_item(Key={"arn": node["arn"]})