def __init__(self, name, gp, config=None): with open(f'{GNS_ROUTER_PATH}/juniper-vmx-vcp.json') as f: router_conf = json.load(f) router_conf['name'] = f'{name}-vcp' param = json.dumps(router_conf) jdata_vcp = send_request('POST', f'/v2/projects/{gp.pid}/nodes', param, True) with open(f'{GNS_ROUTER_PATH}/juniper-vmx-vfp.json') as f: router_conf = json.load(f) router_conf['name'] = f'{name}-vfp' param = json.dumps(router_conf) jdata_vfp = send_request('POST', f'/v2/projects/{gp.pid}/nodes', param, True) gp.link_nodes((jdata_vfp['node_id'], 1, 0), (jdata_vcp['node_id'], 1, 0)) gp.sleep_time = 220 super().__init__(jdata_vcp['node_id'], jdata_vcp['console'], name, config) self.vcp_id = jdata_vcp['node_id'] self.vfp_id = jdata_vfp['node_id'] self.delay = 4 self.netmiko_node['global_delay_factor'] = self.delay self.netmiko_node['timeout'] = 300
def link_nodes(self, link1, link2): """ Links two GNS3 nodes :param link1: Triplet of node id, adapter, and port specifying the first node for the link :param link2: Triplet of node id, adapter, and port specifying the second node for the link :return: HTTP request status """ nid1, adapter1, port1 = link1 nid2, adapter2, port2 = link2 param = json.dumps({ 'nodes': [{ 'adapter_number': adapter1, 'node_id': nid1, 'port_number': port1 }, { 'adapter_number': adapter2, 'node_id': nid2, 'port_number': port2 }] }) return send_request('POST', f'/v2/projects/{self.pid}/links', param)
def delete(self): """ Deletes the GNS3 project from the server, including any local files :return: HTTP status of the request """ return send_request('DELETE', f'/v2/projects/{self.pid}')
def start(self, pid): send_request('POST', f'/v2/projects/{pid}/nodes/{self.vcp_id}/start') send_request('POST', f'/v2/projects/{pid}/nodes/{self.vfp_id}/start')