public IHttpActionResult AccountOVMs(List <VmModel> model) { model = new List <VmModel>(); List <OracleVirtualMachine> ovms = new List <OracleVirtualMachine>(); Klant k = klantmgr.GetKlant(User.Identity.GetUserName()); List <OVMLijst> lijsten = mgr.GetLijstAccount(k.KlantId).ToList(); for (int i = 0; i < lijsten.Count(); i++) { OracleVirtualMachine ovm = mgr.GetOVMById(lijsten[i].OVMId); ovms.Add(ovm); } foreach (OracleVirtualMachine vm in ovms) { VmModel vmModel = new VmModel(); vmModel.Name = vm.Naam; vmModel.id = vm.OvmId; model.Add(vmModel); } if (!model.Any()) { return(Ok(false)); } else { return(Ok(model)); } }
public async Task <VmModel> GetModel(Guid uuid, string accessToken) { VmModel model = new VmModel(); vmApiClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); string url = $"{_options.ApiUrl}/{uuid}"; HttpResponseMessage response = await vmApiClient.GetAsync(url); if (response.IsSuccessStatusCode) { // model = await response.Content.ReadAsAsync<IEnumerable<VmModel>>(); _logger.LogDebug($"name obtained from s3.vm.api at {url}"); model = await response.Content.ReadAsAsync <VmModel>(); } else { _logger.LogError($"{response.ReasonPhrase} for s3.vm.api at {url}"); } return(model); }
public IHttpActionResult GetVmsDB(List <VmModel> model, int id) { model = new List <VmModel>(); List <OracleVirtualMachine> ovms = new List <OracleVirtualMachine>(); ovms = mgr.GetOVMsByServer(id).ToList(); foreach (OracleVirtualMachine vm in ovms) { VmModel vmModel = new VmModel(); vmModel.Name = vm.Naam; vmModel.id = vm.OvmId.Trim(); vmModel.KlantId = vm.KlantId; vmModel.Serverid = vm.ServerId; model.Add(vmModel); } var orderModel = model.OrderBy(c => c.Name); return(Ok(orderModel)); }
public void AddVmModel(int vmIndex, VmModel vmModel) { CheckInitialization(); if (vmIndex < 0 || vmIndex >= _maxVmNumber) { throw new ArgumentException("无效的模拟器索引!", nameof(vmIndex)); } if (_vmModels == null) { _vmModels = new Dictionary <int, VmModel>(_maxVmNumber); } if (_vmModels.ContainsKey(vmIndex)) { _vmModels[vmIndex] = vmModel; } else { _vmModels.Add(vmIndex, vmModel); } }
public async Task <VmModel> GetAsync(Guid id, VmModel model) { VirtualMachine machine = await GetMachineById(id); if (machine != null) { model.State = machine.State; // we cannot get a ticket when the vm is powered off, could check powerstate first if (model.State == "off") { _logger.LogDebug($"{id} is poweredoff, cannot get ticket"); model.Ticket = null; } else { model.Ticket = await GetConsoleUrl(id, machine.Reference); } model.VmToolsAvailable = machine.VmToolsAvailable; if (model.CanAccessNicConfiguration || model.AllowedNetworks.Any()) { model.NetworkCards = (await GetNicOptions(id, model.CanAccessNicConfiguration, model.AllowedNetworks, machine)); } else { model.NetworkCards = new VmNicOptions { AvailableNetworks = new List <string>(), CurrentNetworks = new Dictionary <string, string>() }; } } return(model); }
public IHttpActionResult KlantOVMs(List <VmModel> model) { model = new List <VmModel>(); List <OracleVirtualMachine> ovms = new List <OracleVirtualMachine>(); Klant k = klantmgr.GetKlant(User.Identity.GetUserName()); ovms = mgr.GetKlantOVMs(k.KlantId).ToList(); foreach (OracleVirtualMachine vm in ovms) { VmModel vmModel = new VmModel(); vmModel.Name = vm.Naam; vmModel.id = vm.OvmId; model.Add(vmModel); } if (!model.Any()) { return(Ok(false)); } else { var orderModel = model.OrderBy(c => c.Name); return(Ok(orderModel)); } }
public IHttpActionResult GetVms(List <VmModel> model) { model = new List <VmModel>(); //VmModel vmModel = new VmModel(); List <string> vmState = new List <string>(); string[] vmInfo = new string[7]; string[] getVmInfo = new string[7]; List <string> LijstServerVMs = new List <string>(); string[] serverVMs; string[] VmNames; using (ssh) { ssh.Connect(); var ServerResult = ssh.RunCommand("show Server name=hes-ora-vmtst01"); serverVMs = ServerResult.Result.Split('\n'); ssh.Disconnect(); //2 ssh.Connect(); var VmResult = ssh.RunCommand("list vm "); VmNames = VmResult.Result.Split('\n'); ssh.Disconnect(); string patternVM = @"Vm [0-9]+"; string idPattern = @"id: [0-9]+"; //foreach (string line in serverVMs) for (int i = 0; i < serverVMs.Length; i++) { var res = Regex.Match(serverVMs[i], patternVM); var resId = Regex.Match(serverVMs[i], idPattern); if (res.Length != 0) { VmModel vmModel = new VmModel(); string name = serverVMs[i].Substring(serverVMs[i].IndexOf("[") + 1, serverVMs[i].IndexOf("]") - serverVMs[i].IndexOf("[") - 1); string id = serverVMs[i].Substring(serverVMs[i].IndexOf("=") + 1, (serverVMs[i].IndexOf("[")) - serverVMs[i].IndexOf("=") - 1); vmModel.Name = name; vmModel.id = id; //if (name.Contains(" ") || name.Contains(".")) //{ // vmModel.id = name.Replace(" ", "-").Replace(".", "-"); //} //else //{ // vmModel.id=name; //} vmInfo = GetInfo(name, ssh, getVmInfo); var regex = @"Status = [A-Z]+"; //foreach (var line2 in vmInfo) for (int j = 0; j < vmInfo.Length; j++) { var match = Regex.Match(vmInfo[j], regex); if (match.Length != 0) { vmModel.Status = vmInfo[j].Substring(vmInfo[j].IndexOf("=") + 2, vmInfo[j].Length - vmInfo[j].IndexOf("=") - 2); // vmModel.Name = name; } //vmModel.info.Add(line2); } model.Add(vmModel); } } } //List<string> LijstVms = new List<string>(); //string pattern = @"name:*\w"; //foreach (string line in VmNames) //{ // var res = Regex.Match(line, pattern); // if (res.Length != 0) // { // string cut = line.Substring(line.LastIndexOf(":") +2, line.Length - line.LastIndexOf(":") - 2); // LijstVms.Add(cut); // } //} //// Id's maken voor Vms zonder " " of . //List<string> ids = new List<string>(); //foreach (var id in LijstServerVMs) //{ // if (id.Contains(" ") || id.Contains(".")) // { // string test = id.Replace(" ", "-").Replace(".", "-"); // ids.Add(test); // } // else // { // ids.Add(id); // } //} //ViewBag.Ids = ids; //ViewBag.VmInfo = vmInfo; //ViewBag.State = vmState; //ViewBag.VMs = LijstServerVMs; return(Ok(model)); }