Skip to content

Instantly share code, notes, and snippets.

@adrianlzt
Created February 23, 2022 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianlzt/4f65cca1e4a044aaf4f68b1f315d9174 to your computer and use it in GitHub Desktop.
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)
#! /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