// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.B)) { StartCoroutine(projectHandle.ListNodes( (List <GNS3ProjectHandle.Node> nodes) => { foreach (var node in nodes) { Debug.Log(node.name + " " + node.console_type); foreach (var port in node.ports) { Debug.Log(port.adapter_number + " " + port.port_number); } } }, () => Debug.Log("ListNodes failed") )); } if (Input.GetKeyDown(KeyCode.X)) { var appliances = handle.GetAppliances(); foreach (var appliance in appliances) { Debug.Log(appliance.name + " " + appliance.appliance_id + " " + appliance.category); } } if (OVRInput.GetDown(OVRInput.Button.Two)) // 'B' button { if (!main_menu_active) { wakeMenu(); } else { sleepMenu(); } } operateMenu(); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Z)) { StartCoroutine(handle.ListProjects( (GNS3Handle.Projects projects) => { foreach (var project in projects.projects) { Debug.Log(project.name + " " + project.project_id); } }, () => Debug.Log("Failed") )); } if (Input.GetKeyDown(KeyCode.X)) { var appliances = handle.GetAppliances(); foreach (var appliance in appliances) { Debug.Log(appliance.name + " " + appliance.appliance_id + " " + appliance.category); } } if (Input.GetKeyDown(KeyCode.C)) { var nodes = projectHandle.GetNodes(); projectHandle.SendToConsole(nodes[0], "\rconf t\rint fa0/0\rip address 192.168.1.1 255.255.255.0\rno shutdown\rend\r"); projectHandle.StreamFromConsole(nodes[0], (s) => Debug.Log(s)); } if (Input.GetKeyDown(KeyCode.V)) { // StartCoroutine(projectHandle.CreateAppliance("7465a102-5c54-4cc6-ab76-7e917955223b")); } if (Input.GetKeyDown(KeyCode.B)) { StartCoroutine(projectHandle.ListNodes( (List <GNS3ProjectHandle.Node> nodes) => { foreach (var node in nodes) { Debug.Log(node.name + " " + node.console_type); foreach (var port in node.ports) { Debug.Log(port.adapter_number + " " + port.port_number); } } }, () => Debug.Log("ListNodes failed") )); } if (Input.GetKeyDown(KeyCode.N)) { // StartCoroutine(projectHandle.CreateLink("0453abfb-900b-44cb-811c-ea77e79fda6c", "5b2ca014-913b-4a72-b6bc-23588cd34c48", 0, 0)); } if (Input.GetKeyDown(KeyCode.U)) { var nodes = projectHandle.GetNodes(); StartCoroutine(projectHandle.StartNode(nodes[0].node_id)); } if (Input.GetKeyDown(KeyCode.I)) { var nodes = projectHandle.GetNodes(); StartCoroutine(projectHandle.StopNode(nodes[0].node_id)); } }
public IEnumerator CreateAppliance(string appliance_id, Action <Node> onSuccess, Action onFailure) { // Get type of appliance Debug.Log("Creating appliance"); var appliances = handle.GetAppliances(); GNS3Handle.Appliance appliance = appliances.Find(app => app.appliance_id == appliance_id); if (appliance == null) { Debug.Log("Appliance " + appliance_id + " seems to not exist"); yield break; } string postData = @"{""compute_id"": ""vm"",""x"": 10,""y"": 10}"; byte[] bodyRaw = Encoding.UTF8.GetBytes(postData); var request = new UnityWebRequest(url + "/appliances/" + appliance_id, "POST"); request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw); request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer(); request.SetRequestHeader("Content-Type", "application/json"); yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { Debug.Log("THERE WAS AN ERROR"); Debug.Log(request.downloadHandler.text); yield break; } else { Debug.Log("Yielding to ListNodes"); yield return(ListNodes( (List <Node> newNodes) => { Debug.Log("Calling ListNodes"); var oldNodes = GetNodes(); if (newNodes.Count != oldNodes.Count + 1) { Debug.Log("Tried to update project handle nodes but new node count (" + newNodes.Count.ToString() + ") does not match with old node count (" + oldNodes.Count.ToString() + ")"); return; } foreach (var node in newNodes) { if (oldNodes.Find(n => n.node_id == node.node_id) == null) { nodes.Add(node); /* * GameObject newAppliance = null; * if (appliance.category == "switch") * { * newAppliance = GameObject.Instantiate( * handle.manager.switchPrefab, * handle.manager.transform.position + handle.manager.transform.forward, * Quaternion.identity * ); * } * else * { * newAppliance = GameObject.Instantiate( * handle.manager.routerPrefab, * handle.manager.transform.position + handle.manager.transform.forward, * Quaternion.identity * ); * } * var deviceScript = newAppliance.GetComponent<NetworkDevice>(); * if (deviceScript == null) * { * Debug.Log("CreateAppliance error: device does not have a NetworkDevice script attached to it"); * onFailure(); * return; * } * deviceScript.node = node; */ onSuccess(node); Debug.Log("Successfully added new " + node.node_type + " node with id " + node.node_id); return; } } }, () => { Debug.Log("Failed to update project handle nodes"); onFailure(); } )); Debug.Log("Done yielding..."); // Debug.Log(request.downloadHandler.text); } }