Created
February 23, 2022 10:36
-
-
Save adrianlzt/4f65cca1e4a044aaf4f68b1f315d9174 to your computer and use it in GitHub Desktop.
Read a Skydive topology from a json file and import into skydive (extract json file with HTTP GET to /api/topology)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# vim:fenc=utf-8 | |
""" | |
Leer la topologia de un fichero JSON y cargarlo en skydive | |
""" | |
import json | |
from tqdm import tqdm | |
from skydive.rest.client import RESTClient | |
skydive = RESTClient("localhost:8082") | |
# Read skydive_topology.json file | |
with open("skydive_topology.json", "r") as fd: | |
data = json.load(fd) | |
nodes = data["Nodes"] | |
edges = data["Edges"] | |
# Load nodes | |
for n in tqdm(nodes): | |
skydive.node_create(node_id=n["ID"], host=n["Host"], metadata=n["Metadata"]) | |
# Load edges | |
for e in tqdm(edges): | |
skydive.edge_create(parent_id=e["Parent"], child_id=e["Child"], edge_id=e["ID"], host=e["Host"], metadata=e["Metadata"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment