/// <summary> /// Get instance of vm. Used to get the state of vm /// </summary> /// <param name="instanceId"></param> /// <returns></returns> private VmInstanceModel GetVm(string instanceId) { string result = helper.GetVmInstance(instanceId).GetAwaiter().GetResult(); VmInstanceModel model = JsonConvert.DeserializeObject <VmInstanceModel>(result); return(model); }
/// <summary> /// Gets the datatable for the grid /// </summary> /// <param name="inputString">Json input containing all the info about vms</param> /// <returns></returns> private DataTable GetVmData(string inputString) { try { //parse json input into vm model var values = VmssModel.FromJson(inputString); DataTable table = new DataTable(); table.Columns.Add("Id", typeof(string)); table.Columns.Add("Instance Id", typeof(string)); table.Columns.Add("Name", typeof(string)); table.Columns.Add("Status", typeof(string)); table.Columns.Add("Ip", typeof(string)); //table.Columns.Add("Status", typeof(string)); foreach (Value vm in values.Value) { VmInstanceModel v = GetVm(vm.InstanceId.ToString()); PublicIpAddressConfiguration publicIpConfig = vm.Properties.NetworkProfileConfiguration.NetworkInterfaceConfigurations[0].Properties.IpConfigurations[0].Properties.PublicIpAddressConfiguration; string ipName = ""; if (publicIpConfig != null) { IpModel ip = GetIp(publicIpConfig.Name); ipName = ip.Properties.IpAddress; } string powerState = v.Statuses[1].Code.Replace("PowerState/", string.Empty); table.Rows.Add(vm.Id, vm.InstanceId, vm.Name, powerState, ipName); } ; return(table); } catch (Exception ex) { throw ex; } }