protected void btnCreate_Click(object sender, EventArgs e) { try { VMInfo selectedVM = VirtualMachinesForPCHelper.GetCachedVirtualMachineForPC(Convert.ToInt32(listOperatingSystems.SelectedValue.Trim())); ResultObject res = ES.Services.VPSPC.CreateVMFromVM(PanelSecurity.PackageId , selectedVM, txtVmName.Text.Trim()); if (res.IsSuccess) { // return to the list Response.Redirect(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), "")); return; } else { // show error messageBox.ShowMessage(res, "VPS_ERROR_CREATE", "VPS"); } } catch (Exception ex) { messageBox.ShowErrorMessage("VPS_ERROR_CREATE", ex); } }
protected void Page_Load(object sender, EventArgs e) { VMInfo vm = VirtualMachinesForPCHelper.GetCachedVirtualMachineForPC(PanelRequest.ItemID); if (vm != null && !String.IsNullOrWhiteSpace(vm.Name)) { litServerName.Text = vm.Name; } }
private void BindFormDetails() { // load VM item VMInfo vm = VirtualMachinesForPCHelper.GetCachedVirtualMachineForPC(PanelRequest.ItemID); if (!String.IsNullOrEmpty(vm.CurrentTaskId)) { messageBox.ShowWarningMessage("VPS_PROVISIONING_PROCESS"); btnDelete.Enabled = false; return; } AdminOptionsPanel.Visible = (PanelSecurity.EffectiveUser.Role == WebsitePanel.EnterpriseServer.UserRole.Administrator); //// load export settings //if (PanelSecurity.EffectiveUser.Role == WebsitePanel.EnterpriseServer.UserRole.Administrator) //{ // txtExportPath.Text = ES.Services.VPSPC.GetDefaultExportPath(PanelRequest.ItemID); //} //else //{ // AdminOptionsPanel.Visible = false; //} }
private void BindGeneralDetails() { VMInfo item = VirtualMachinesForPCHelper.GetCachedVirtualMachineForPC(PanelRequest.ItemID); if (!String.IsNullOrEmpty(item.CurrentTaskId)) { DetailsTable.Visible = false; return; } VMInfo vm = null; try { vm = ES.Services.VPSPC.GetVirtualMachineGeneralDetails(PanelRequest.ItemID); } catch (Exception ex) { messageBox.ShowErrorMessage("VPS_ERROR_GET_VM_DETAILS", ex); } if (vm != null) { bool displayRDP = (Request.Browser.Browser == "IE" && Request.Browser.ActiveXControls && Request.Browser.VBScript && vm.State != VMComputerSystemStateInfo.PowerOff && vm.State != VMComputerSystemStateInfo.Paused && vm.State != VMComputerSystemStateInfo.Saved); lnkHostname.Text = item.HostName.ToUpper(); lnkHostname.Visible = displayRDP; litHostname.Text = item.HostName.ToUpper(); litHostname.Visible = !displayRDP; litDomain.Text = item.JoinDomain; if (!IsPostBack) { // set host name change form txtHostname.Text = item.HostName; txtDomain.Text = item.JoinDomain; UpdatePanel1.Attributes.Add("style", "Width:160px; Height:120px;"); } litRdpPageUrl.Text = Page.ResolveUrl("~/DesktopModules/WebsitePanel/VPSForPC/RemoteDesktop/Connect.aspx?ItemID=" + PanelRequest.ItemID + "&Resolution="); litUptime.Text = vm.ModifiedTime; litStatus.Text = GetLocalizedString("State." + vm.State.ToString()); litCreated.Text = vm.CreatedDate.ToString(); // CPU vmInfoPerfomence.Visible = (vm.State != VMComputerSystemStateInfo.CreationFailed); imgThumbnail.Visible = (vm.State != VMComputerSystemStateInfo.CreationFailed); if (vm.State != VMComputerSystemStateInfo.CreationFailed) { cpuGauge.Progress = vm.PerfCPUUtilization; litCpuPercentage.Text = String.Format(GetLocalizedString("CpuPercentage.Text"), vm.PerfCPUUtilization); // RAM if (vm.Memory > 0) { int ramPercent = Convert.ToInt32((float)vm.ProcessMemory / (float)vm.Memory * 100); ramGauge.Total = vm.Memory; ramGauge.Progress = vm.ProcessMemory; litRamPercentage.Text = String.Format(GetLocalizedString("MemoryPercentage.Text"), ramPercent); litRamUsage.Text = String.Format(GetLocalizedString("MemoryUsage.Text"), vm.ProcessMemory, vm.Memory); } else { ramGauge.Visible = false; litRamPercentage.Visible = false; litRamUsage.Visible = false; locRam.Visible = false; } // HDD if (vm.HddLogicalDisks != null && vm.HddLogicalDisks.Length > 0) { HddRow.Visible = true; int freeHdd = 0; int sizeHdd = 0; foreach (LogicalDisk disk in vm.HddLogicalDisks) { freeHdd += disk.FreeSpace; sizeHdd += disk.Size; } int usedHdd = sizeHdd - freeHdd; int hddPercent = Convert.ToInt32((float)usedHdd / (float)sizeHdd * 100); hddGauge.Total = sizeHdd; hddGauge.Progress = usedHdd; litHddPercentage.Text = String.Format(GetLocalizedString("HddPercentage.Text"), hddPercent); litHddUsage.Text = String.Format(GetLocalizedString("HddUsage.Text"), freeHdd, sizeHdd, vm.HddLogicalDisks.Length); } // update image imgThumbnail.ImageUrl = String.Format("~/DesktopModules/WebsitePanel/VPSForPC/VirtualMachineImage.ashx?ItemID={0}&rnd={1}", PanelRequest.ItemID, DateTime.Now.Ticks); } // load virtual machine meta item VMInfo vmi = VirtualMachinesForPCHelper.GetCachedVirtualMachineForPC(PanelRequest.ItemID); // draw buttons List <ActionButton> buttons = new List <ActionButton>(); vmi.StartTurnOffAllowed = true; vmi.RebootAllowed = true; vmi.StartTurnOffAllowed = true; vmi.PauseResumeAllowed = true; vmi.ResetAllowed = true; if (vmi.StartTurnOffAllowed && (vm.State == VMComputerSystemStateInfo.PowerOff || vm.State == VMComputerSystemStateInfo.Saved || vm.State == VMComputerSystemStateInfo.Stored)) { buttons.Add(CreateActionButton("Start", "start.png")); } if (vm.State == VMComputerSystemStateInfo.Running) { if (vmi.RebootAllowed) { buttons.Add(CreateActionButton("Reboot", "reboot.png")); } if (vmi.StartTurnOffAllowed) { buttons.Add(CreateActionButton("ShutDown", "shutdown.png")); } } if (vmi.StartTurnOffAllowed && (vm.State == VMComputerSystemStateInfo.Running || vm.State == VMComputerSystemStateInfo.Paused)) { buttons.Add(CreateActionButton("TurnOff", "turnoff.png")); } if (vmi.PauseResumeAllowed && vm.State == VMComputerSystemStateInfo.Running) { buttons.Add(CreateActionButton("Pause", "pause.png")); } if (vmi.PauseResumeAllowed && vm.State == VMComputerSystemStateInfo.Paused) { buttons.Add(CreateActionButton("Resume", "start2.png")); } if (vmi.ResetAllowed && (vm.State == VMComputerSystemStateInfo.Running || vm.State == VMComputerSystemStateInfo.Paused)) { buttons.Add(CreateActionButton("Reset", "reset2.png")); } repButtons.DataSource = buttons; repButtons.DataBind(); // other actions bool manageAllowed = VirtualMachinesForPCHelper.IsVirtualMachineManagementAllowed(PanelSecurity.PackageId); btnChangeHostnamePopup.Visible = manageAllowed; } else { DetailsTable.Visible = false; messageBox.ShowErrorMessage("VPS_LOAD_VM_ITEM"); } }
private void BindTabs() { // load item VMInfo vm = VirtualMachinesForPCHelper.GetCachedVirtualMachineForPC(PanelRequest.ItemID); if (!String.IsNullOrEmpty(vm.CurrentTaskId)) { // show panel TaskTable.Visible = true; // bind task details BindTask(vm); return; } if (TaskTable.Visible) { Response.Redirect(Request.Url.ToString()); // refresh screen } // show tabs TabsTable.Visible = true; // disable timer refreshTimer.Enabled = false; // check if VPS created with error bool createError = ((vm.ProvisioningStatus == VirtualMachineProvisioningStatus.Error) || (vm.State == VMComputerSystemStateInfo.CreationFailed)); // load package context PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); // build tabs list List <Tab> tabsList = new List <Tab>(); tabsList.Add(CreateTab("vps_general", "Tab.General")); if (!createError) { tabsList.Add(CreateTab("vps_config", "Tab.Configuration")); } if (vm.DvdDriver && !createError) { tabsList.Add(CreateTab("vps_dvd", "Tab.DVD")); } //if (vm.SnapshotsNumber > 0 && !createError) // tabsList.Add(CreateTab("vps_snapshots", "Tab.Snapshots")); //if ((vm.ExternalNetworkEnabled || vm.PrivateNetworkEnabled) && !createError) // tabsList.Add(CreateTab("vps_network", "Tab.Network")); //tabsList.Add(CreateTab("vps_permissions", "Tab.Permissions")); //tabsList.Add(CreateTab("vps_tools", "Tab.Tools")); tabsList.Add(CreateTab("vps_audit_log", "Tab.AuditLog")); tabsList.Add(CreateTab("vps_events_log", "Tab.EventsLog")); tabsList.Add(CreateTab("vps_alerts_log", "Tab.AlertsLog")); tabsList.Add(CreateTab("vps_monitoring", "Tab.VpsMonitoring")); if (vm.SnapshotsNumber > 0 && !createError) { tabsList.Add(CreateTab("vps_checkpoints", "Tab.VpsCheckPoints")); } //if (!createError) // tabsList.Add(CreateTab("vps_help", "Tab.Help")); // find selected menu item int idx = 0; foreach (Tab tab in tabsList) { if (String.Compare(tab.Id, SelectedTab, true) == 0) { break; } idx++; } dlTabs.SelectedIndex = idx; dlTabs.DataSource = tabsList; dlTabs.DataBind(); // show provision error message if (createError && idx == 0) { messageBox.ShowErrorMessage("VPS_PROVISION_ERROR"); } }