public IActionResult DeleteInstancesAsync(string id) { bool result = false; string type = ""; //check file type to delete - jupyter var codeResponse = CodePayload.Get(); foreach (var item in codeResponse) { if (item.Id == id) { type = item.Type; } } //check got pmml file if (string.IsNullOrEmpty(type)) { var modalResponse = ModelPayload.Get(); foreach (var item in modalResponse) { if (item.Id == id) { type = item.Type; } } } //check for zmk if (string.IsNullOrEmpty(type)) { type = "ZMK"; } switch (type) { case "JUPYTER_NOTEBOOK": result = StopJupyter(id); InstancePayload.Delete(id); break; case "PMML": result = StopTensorboard(id); InstancePayload.Delete(id); break; case "ZMK": result = ZMKDockerCmdHelper.StopZMKInstance(id); break; } var zmkResponse1 = InstancePayload.Get(); return(Ok(new { user = string.Empty, id = id, type = type, message = "Instance deleted successfully.", Json = JsonConvert.SerializeObject(zmkResponse1) })); }
public async Task <IActionResult> StartInstancesAsync() { string reqBody = ""; string instanceType = ""; // string cmd =""; try { //read request body using (var reader = new StreamReader(Request.Body)) { var body = await reader.ReadToEndAsync(); reqBody = body.ToString(); } // IList <InstanceResponse> getAllInstances = InstancePayload.Get(); // JObject jObj = JObject.Parse(reqBody); instanceType = jObj["type"].ToString(); switch (instanceType) { case "ZMK": #region start ZMK instances try { string unassigned = ZMKDockerCmdHelper.GetUnassignedZMKInstance(); if (!string.IsNullOrEmpty(unassigned)) { ZMKDockerCmdHelper.StartZMKInstance(unassigned); } } catch (Exception ex) { return(BadRequest(new { message = "starting instance failed.", exception = ex.StackTrace })); } #endregion break; } } catch (Exception ex) { return(BadRequest(new { message = "starting instance failed.", exception = ex.StackTrace })); } return(Ok()); }
public IActionResult GetRunningInstances() { string cmd = ""; string output = ""; List <InstanceResponse> getAllInstances = InstancePayload.Get(); #region GPU listing cmd = "gpustat --json"; try { output = cmd.Bash(); if (!string.IsNullOrEmpty(output)) { JObject jsonObj = JObject.Parse(output); JArray arr = (JArray)jsonObj["gpus"]; int gpuctr = 1; foreach (var a in arr) { JArray tmpArr = (JArray)a["processes"]; List <InstanceProperty> _props = new List <InstanceProperty>(); _props.Add(new InstanceProperty { key = "temperature.gpu [celsius]", value = a["temperature.gpu"] }); _props.Add(new InstanceProperty { key = "utilization.gpu [%]", value = a["utilization.gpu"] }); _props.Add(new InstanceProperty { key = "power.draw [W]", value = a["power.draw"] }); _props.Add(new InstanceProperty { key = "enforced.power.limit [W]", value = a["enforced.power.limit"] }); _props.Add(new InstanceProperty { key = "memory.used [MB]", value = a["memory.used"] }); _props.Add(new InstanceProperty { key = "memory.total [MB]", value = a["memory.total"] }); InstanceResponse _instance = new InstanceResponse() { Id = a["uuid"].ToString(), Name = $"GPU {gpuctr}", Type = "GPU", Properties = _props, Processes = tmpArr }; getAllInstances.Add(_instance); gpuctr++; } } } catch (Exception ex) { return(BadRequest(new { message = "running instance loading failed.", exception = ex.StackTrace })); } #endregion #region ZMK listing IList <InstanceResponse> zmkList = ZMKDockerCmdHelper.GetAllRunningZMK(); if (zmkList.Count > 0) { getAllInstances.AddRange(zmkList); } #endregion return(Json(getAllInstances)); }