Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            VirtualMachine vm = VirtualMachinesProxmoxHelper.GetCachedVirtualMachine(PanelRequest.ItemID);

            if (vm != null)
            {
                litServerName.Text = vm.Name;
            }
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            resolution.Text = Request["Resolution"];

            // load server info
            VirtualMachine vm = VirtualMachinesProxmoxHelper.GetCachedVirtualMachine(PanelRequest.ItemID);

            litServerName.Text = vm.Name + " - ";
            username.Text      = "Administrator";
            password.Text      = vm.AdministratorPassword;

            // load external network parameters
            NetworkAdapterDetails nic = ES.Services.Proxmox.GetExternalNetworkAdapterDetails(PanelRequest.ItemID);

            if (nic.IPAddresses.Length > 0)
            {
                NetworkAdapterIPAddress ip = nic.IPAddresses[0];
                serverName.Text = !String.IsNullOrEmpty(ip.NATAddress) ? ip.NATAddress : ip.IPAddress;
            }
        }
Пример #3
0
        private void BindFormDetails()
        {
            // load VM item
            VirtualMachine vm = VirtualMachinesProxmoxHelper.GetCachedVirtualMachine(PanelRequest.ItemID);

            if (!String.IsNullOrEmpty(vm.CurrentTaskId))
            {
                messageBox.ShowWarningMessage("VPS_PROVISIONING_PROCESS");
                btnDelete.Enabled = false;
                return;
            }

            // load export settings
            if (PanelSecurity.EffectiveUser.Role == SolidCP.EnterpriseServer.UserRole.Administrator)
            {
                txtExportPath.Text = ES.Services.Proxmox.GetDefaultExportPath(PanelRequest.ItemID);
            }
            else
            {
                AdminOptionsPanel.Visible = false;
            }
        }
Пример #4
0
        private void BindGeneralDetails()
        {
            VirtualMachine item = VirtualMachinesProxmoxHelper.GetCachedVirtualMachine(PanelRequest.ItemID);

            if (!String.IsNullOrEmpty(item.CurrentTaskId) ||
                item.ProvisioningStatus == VirtualMachineProvisioningStatus.Error)
            {
                DetailsTable.Visible = false;
                return;
            }

            VirtualMachine vm = null;

            try
            {
                vm = ES.Services.Proxmox.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 != VirtualMachineState.Off &&
                                   vm.State != VirtualMachineState.Paused &&
                                   vm.State != VirtualMachineState.Saved &&
                                   item.RemoteDesktopEnabled);
                lnkHostname.Text    = item.Hostname.ToUpper();
                lnkHostname.Visible = displayRDP;

                litHostname.Text    = item.Hostname.ToUpper();
                litHostname.Visible = !displayRDP;

                litDomain.Text = item.Domain;

                if (!IsPostBack)
                {
                    // set host name change form
                    txtHostname.Text = item.Hostname;
                    txtDomain.Text   = item.Domain;
                }

                lnkHostname.Visible = false;
                //litRdpPageUrl.Text = Page.ResolveUrl(ES.Services.Proxmox.GetVirtualMachineVNCURL(PanelRequest.ItemID));


                TimeSpan uptime = TimeSpan.FromMilliseconds(vm.Uptime * 1000);
                uptime          = uptime.Subtract(TimeSpan.FromMilliseconds(uptime.Milliseconds));
                litUptime.Text  = uptime.ToString();
                litStatus.Text  = GetLocalizedString("State." + vm.State);
                litCreated.Text = vm.CreatedDate.ToString();
                //litHeartbeat.Text = GetLocalizedString("Heartbeat." + vm.Heartbeat);

                // CPU
                cpuGauge.Progress     = vm.CpuUsage;
                litCpuPercentage.Text = String.Format(GetLocalizedString("CpuPercentage.Text"), vm.CpuUsage);

                // RAM
                if (vm.RamSize > 0)
                {
                    var totalRam = vm.RamSize;

                    if (vm.DynamicMemory != null && vm.DynamicMemory.Enabled)
                    {
                        totalRam = vm.DynamicMemory.Maximum;
                    }

                    int ramPercent = Convert.ToInt32((float)vm.RamUsage / (float)totalRam * 100);
                    ramGauge.Total        = totalRam;
                    ramGauge.Progress     = vm.RamUsage;
                    litRamPercentage.Text = String.Format(GetLocalizedString("MemoryPercentage.Text"), ramPercent);
                    litRamUsage.Text      = String.Format(GetLocalizedString("MemoryUsage.Text"), vm.RamUsage, totalRam);
                }

                // 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/SolidCP/Proxmox/VirtualMachineImage.ashx?ItemID={0}&rnd={1}",
                                  PanelRequest.ItemID, DateTime.Now.Ticks);

                // load virtual machine meta item
                VirtualMachine vmi = VirtualMachinesProxmoxHelper.GetCachedVirtualMachine(PanelRequest.ItemID);

                // draw buttons
                List <ActionButton> buttons = new List <ActionButton>();

                if (vmi.StartTurnOffAllowed &&
                    (vm.State == VirtualMachineState.Off ||
                     vm.State == VirtualMachineState.Saved))
                {
                    buttons.Add(CreateActionButton("Start", "start.png"));
                }

                if (vm.State == VirtualMachineState.Running)
                {
                    if (vmi.RebootAllowed)
                    {
                        buttons.Add(CreateActionButton("Reboot", "reboot.png"));
                    }

                    if (vmi.StartTurnOffAllowed)
                    {
                        buttons.Add(CreateActionButton("ShutDown", "shutdown.png"));
                    }
                }

                if (vmi.StartTurnOffAllowed &&
                    (vm.State == VirtualMachineState.Running ||
                     vm.State == VirtualMachineState.Paused))
                {
                    buttons.Add(CreateActionButton("TurnOff", "turnoff.png"));
                }

                if (vmi.PauseResumeAllowed &&
                    vm.State == VirtualMachineState.Running)
                {
                    buttons.Add(CreateActionButton("Pause", "pause.png"));
                }

                if (vmi.PauseResumeAllowed &&
                    vm.State == VirtualMachineState.Paused)
                {
                    buttons.Add(CreateActionButton("Resume", "start2.png"));
                }

                if (vmi.ResetAllowed &&
                    (vm.State == VirtualMachineState.Running ||
                     vm.State == VirtualMachineState.Paused))
                {
                    buttons.Add(CreateActionButton("Reset", "reset2.png"));
                }

                repButtons.DataSource = buttons;
                repButtons.DataBind();

                // other actions
                bool manageAllowed = VirtualMachinesProxmoxHelper.IsVirtualMachineManagementAllowed(PanelSecurity.PackageId);
                btnChangeHostnamePopup.Visible = manageAllowed;
            }
            else
            {
                DetailsTable.Visible = false;
                messageBox.ShowErrorMessage("VPS_LOAD_VM_ITEM");
            }
        }
Пример #5
0
        private void BindTabs()
        {
            // load item
            VirtualMachine vm = VirtualMachinesProxmoxHelper.GetCachedVirtualMachine(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 Proxmox created with error
            bool createError = (vm.ProvisioningStatus == VirtualMachineProvisioningStatus.Error);

            // 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.DvdDriveInstalled && !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"));
            }


            /*
             * if (PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.PROXMOX_REPLICATION_ENABLED))
             * {
             *  tabsList.Add(CreateTab("vps_replication", "Tab.Replication"));
             * }
             */

            //tabsList.Add(CreateTab("vps_permissions", "Tab.Permissions"));
            //tabsList.Add(CreateTab("vps_tools", "Tab.Tools"));
            tabsList.Add(CreateTab("vps_audit_log", "Tab.AuditLog"));

            //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");
            }
        }