Skip to content

Instantly share code, notes, and snippets.

@cerealskill
Last active April 2, 2018 21:03
Show Gist options
  • Select an option

  • Save cerealskill/66b94a74e702a3f91f5abd1e61795328 to your computer and use it in GitHub Desktop.

Select an option

Save cerealskill/66b94a74e702a3f91f5abd1e61795328 to your computer and use it in GitHub Desktop.
leer_switches_ports_ravello.py
import json
import sys
from pprint import pprint
with open('api.json') as json_file:
json_data = json.load(json_file);
#json_data.close();
parse_json_switches_ports = json_data["design"]["network"]["switches"][5]["ports"];
json_data["design"]["network"]["switches"][5]["ports"][5]["index"] = 89
json_data["design"]["network"]["switches"][5]["ports"][5]["deviceType"] = 'VM'
json_data["design"]["network"]["switches"][5]["ports"][5]["deviceId"] = sys.argv[1]
json_data["design"]["network"]["switches"][5]["ports"][5]["networkSegmentReferences"]["networkSegmentId"] = 6140501108125908
json_data["design"]["network"]["switches"][5]["ports"][6]["networkSegmentReferences"]["anyNetworkSegmnet"] = false
json_data["design"]["network"]["switches"][5]["ports"][6]["networkSegmentReferences"]["egressPolicy"] = 'UNTAGGED'
#json_data["design"]["network"]["switches"][5]["ports"][7]= "['index'] = 89,
#['deviceType'] = 'vm',
#['deviceId']: ID_VM,
#['networkSegmentReferences': [{
# 'networkSegmentId': NetworkSegmentID,
# 'anyNetworkSegmnet': false,
# 'egressPolicy': 'UNTAGGED'
# }]";
#parse_json_name = json_data["design"]["vms"][0]["name"];
#parse_json_network = json_data["design"]["vms"][0]["networkConnections"][0]["id"];
#json_data["network"]["switches"]
pprint(parse_json_switches_ports);
# pprint(json.dumps(json_data));
#pprint(parse_json_name);
#pprint(parse_json_network);
#
#output_file = "output.json"
#with open(output_file, 'w') as write_file_object:
#Serialize dictionary to a JSON formatted string and write to file
#write_file_object.write(json.dumps(json_data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment