private void BindExternalAddresses() { // load details NetworkAdapterDetails nic = ES.Services.VPS.GetExternalNetworkAdapterDetails(PanelRequest.ItemID); // bind details foreach (NetworkAdapterIPAddress ip in nic.IPAddresses) { if (ip.IsPrimary) { litExtAddress.Text = ip.IPAddress; litExtSubnet.Text = ip.SubnetMask; litExtGateway.Text = ip.DefaultGateway; break; } } lblTotalExternal.Text = nic.IPAddresses.Length.ToString(); // bind IP addresses gvExternalAddresses.DataSource = nic.IPAddresses; gvExternalAddresses.DataBind(); }
private void BindFormControls() { var virtualMachine = new VirtualMachine { DynamicMemory = new DynamicMemory { Buffer = 20, Priority = 50 } }; // bind password policy password.SetPackagePolicy(PanelSecurity.PackageId, UserSettings.VPS_POLICY, "AdministratorPasswordPolicy"); // OS templates listOperatingSystems.DataSource = ES.Services.VPS2012.GetOperatingSystemTemplates(PanelSecurity.PackageId); listOperatingSystems.DataBind(); listOperatingSystems.Items.Insert(0, new ListItem(GetLocalizedString("SelectOsTemplate.Text"), "")); // summary letter e-mail PackageInfo package = ES.Services.Packages.GetPackage(PanelSecurity.PackageId); if (package != null) { UserInfo user = ES.Services.Users.GetUserById(package.UserId); if (user != null) { chkSendSummary.Checked = IsMailConfigured(user); txtSummaryEmail.Text = user.Email; } } // load package context PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); // bind CPU cores int maxCores = ES.Services.VPS2012.GetMaximumCpuCoresNumber(PanelSecurity.PackageId); QuotaValueInfo cpuQuota2 = cntx.Quotas[Quotas.VPS2012_CPU_NUMBER]; if (cpuQuota2.QuotaAllocatedValue == -1) { for (int i = 1; i < maxCores + 1; i++) { ddlCpu.Items.Add(i.ToString()); } ddlCpu.SelectedIndex = ddlCpu.Items.Count - 1; // select last (maximum) item } else if (cpuQuota2.QuotaAllocatedValue >= cpuQuota2.QuotaUsedValue) { if ((cpuQuota2.QuotaAllocatedValue + 1 - cpuQuota2.QuotaUsedValue) > maxCores) { for (int i = 1; i < maxCores + 1; i++) { ddlCpu.Items.Add(i.ToString()); } ddlCpu.SelectedIndex = ddlCpu.Items.Count - 1; // select last (maximum) item } else { for (int i = 1; i < (cpuQuota2.QuotaAllocatedValue - cpuQuota2.QuotaUsedValue) + 1; i++) { ddlCpu.Items.Add(i.ToString()); } ddlCpu.SelectedIndex = ddlCpu.Items.Count - 1; // select last (maximum) item } } else { ddlCpu.Items.Add("0"); } // external network details if (PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPS2012_EXTERNAL_NETWORK_ENABLED)) { List <int> dupevlans = new List <int>(); List <int> vlans = new List <int>(); bool isUnassignedPackageIPs = false; // bind vlan list PackageIPAddress[] ips = ES.Services.Servers.GetPackageUnassignedIPAddresses(PanelSecurity.PackageId, 0, IPAddressPool.VpsExternalNetwork); if (ips.Length > 0) { foreach (PackageIPAddress ip in ips) { dupevlans.Add(ip.VLAN); } } else { if (PanelSecurity.EffectiveUser.Role != UserRole.User) { IPAddressInfo[] uips = ES.Services.Servers.GetUnallottedIPAddresses(PanelSecurity.PackageId, ResourceGroups.VPS2012, IPAddressPool.VpsExternalNetwork); isUnassignedPackageIPs = true; foreach (IPAddressInfo ip in uips) { dupevlans.Add(ip.VLAN); } } } // return vlan list without dupes vlans = dupevlans.Distinct().ToList(); //List<int> vlans = ES.Services.VPS2012.GetAvailableVLANs(PanelSecurity.PackageId).vlans; listVlanLists.Items.Clear(); //listVlanLists.Items.Add(new ListItem("External network disabled", "-1")); listVlanLists.Items.Add(new ListItem("Select a VLAN", "-1")); foreach (int vlan in vlans) { listVlanLists.Items.Add(new ListItem(String.Format("VLAN {0}", vlan.ToString()), vlan.ToString())); } // bind external network ips 4 selected vlan if (isUnassignedPackageIPs) { BindExternalUnallottedIps(); } else { BindExternalIps(); } //GenerateMac txtExternalMACAddress.Text = ES.Services.VPS2012.GenerateMacAddress(); } // private network if (PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPS2012_PRIVATE_NETWORK_ENABLED)) { NetworkAdapterDetails nic = ES.Services.VPS2012.GetPrivateNetworkDetails(PanelSecurity.PackageId); litPrivateNetworkFormat.Text = nic.NetworkFormat; litPrivateSubnetMask.Text = nic.SubnetMask; txtGateway.Text = nic.DefaultGateway; txtDNS1.Text = nic.PreferredNameServer; txtDNS2.Text = nic.AlternateNameServer; txtMask.Text = nic.SubnetMask; //firewall find VirtualMachines2012Helper vmh = new VirtualMachines2012Helper(); VirtualMachineMetaItem[] machines = vmh.GetVirtualMachines(PanelSecurity.PackageId, "", "", "SI.ItemID", 20, 0); foreach (var item in machines) { if (!String.IsNullOrEmpty(item.ExternalIP) && !String.IsNullOrEmpty(item.IPAddress)) { txtGateway.Text = item.IPAddress; txtDNS1.Text = item.IPAddress; VirtualMachine vm = ES.Services.VPS2012.GetVirtualMachineItem(item.ItemID); if (vm != null && !String.IsNullOrEmpty(vm.CustomPrivateMask)) { txtMask.Text = vm.CustomPrivateMask; } break; } } // set max number QuotaValueInfo privQuota = cntx.Quotas[Quotas.VPS2012_PRIVATE_IP_ADDRESSES_NUMBER]; int maxPrivate = privQuota.QuotaAllocatedValue; if (maxPrivate == -1) { maxPrivate = 10; } // handle DHCP mode if (nic.IsDHCP) { maxPrivate = 0; ViewState["DHCP"] = true; } txtPrivateAddressesNumber.Text = "1"; litMaxPrivateAddresses.Text = String.Format(GetLocalizedString("litMaxPrivateAddresses.Text"), maxPrivate); listPrivateNetworkVLAN.Items.Clear(); PackageVLANsPaged vlans = ES.Services.Servers.GetPackagePrivateNetworkVLANs(PanelSecurity.PackageId, "", 0, Int32.MaxValue); if (vlans != null && vlans.Count > 0) { foreach (PackageVLAN vlan in vlans.Items) { listPrivateNetworkVLAN.Items.Add(new ListItem(String.Format("VLAN {0}", vlan.Vlan.ToString()), vlan.Vlan.ToString())); } } } // RAM size if (cntx.Quotas.ContainsKey(Quotas.VPS2012_RAM)) { QuotaValueInfo ramQuota = cntx.Quotas[Quotas.VPS2012_RAM]; if (ramQuota.QuotaAllocatedValue == -1) { // unlimited RAM txtRam.Text = ""; } else { int availSize = ramQuota.QuotaAllocatedValue - ramQuota.QuotaUsedValue; txtRam.Text = availSize < 0 ? "" : availSize.ToString(); if (availSize > 0) { virtualMachine.DynamicMemory.Minimum = availSize / 2; virtualMachine.DynamicMemory.Maximum = availSize; } } } // HDD size if (cntx.Quotas.ContainsKey(Quotas.VPS2012_HDD)) { QuotaValueInfo hddQuota = cntx.Quotas[Quotas.VPS2012_HDD]; if (hddQuota.QuotaAllocatedValue == -1) { // unlimited HDD txtHdd.Text = ""; } else { int availSize = hddQuota.QuotaAllocatedValue - hddQuota.QuotaUsedValue; txtHdd.Text = availSize < 0 ? "" : availSize.ToString(); } } // IOPS number // TODO: checke txtHddMinIOPS.Text = "0"; txtHddMaxIOPS.Text = "0"; // snapshots number if (cntx.Quotas.ContainsKey(Quotas.VPS2012_SNAPSHOTS_NUMBER)) { int snapsNumber = cntx.Quotas[Quotas.VPS2012_SNAPSHOTS_NUMBER].QuotaAllocatedValue; txtSnapshots.Text = (snapsNumber != -1) ? snapsNumber.ToString() : ""; txtSnapshots.Enabled = (snapsNumber != 0); } // toggle controls BindCheckboxOption(chkDvdInstalled, Quotas.VPS2012_DVD_ENABLED); chkBootFromCd.Enabled = PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPS2012_BOOT_CD_ALLOWED); BindCheckboxOption(chkStartShutdown, Quotas.VPS2012_START_SHUTDOWN_ALLOWED); BindCheckboxOption(chkPauseResume, Quotas.VPS2012_PAUSE_RESUME_ALLOWED); BindCheckboxOption(chkReset, Quotas.VPS2012_RESET_ALOWED); BindCheckboxOption(chkReboot, Quotas.VPS2012_REBOOT_ALLOWED); BindCheckboxOption(chkReinstall, Quotas.VPS2012_REINSTALL_ALLOWED); // the settings user controls this.BindSettingsControls(virtualMachine); }
private void BindFormControls() { // bind password policy password.SetPackagePolicy(PanelSecurity.PackageId, UserSettings.VPS_POLICY, "AdministratorPasswordPolicy"); // OS templates listOperatingSystems.DataSource = ES.Services.VPS.GetOperatingSystemTemplates(PanelSecurity.PackageId); listOperatingSystems.DataBind(); listOperatingSystems.Items.Insert(0, new ListItem(GetLocalizedString("SelectOsTemplate.Text"), "")); // summary letter e-mail PackageInfo package = ES.Services.Packages.GetPackage(PanelSecurity.PackageId); if (package != null) { UserInfo user = ES.Services.Users.GetUserById(package.UserId); if (user != null) { chkSendSummary.Checked = true; txtSummaryEmail.Text = user.Email; } } // load package context PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); // bind CPU cores int maxCores = ES.Services.VPS.GetMaximumCpuCoresNumber(PanelSecurity.PackageId); QuotaValueInfo cpuQuota2 = cntx.Quotas[Quotas.VPS_CPU_NUMBER]; if (cpuQuota2.QuotaAllocatedValue == -1) { for (int i = 1; i < maxCores + 1; i++) { ddlCpu.Items.Add(i.ToString()); } ddlCpu.SelectedIndex = ddlCpu.Items.Count - 1; // select last (maximum) item } else if (cpuQuota2.QuotaAllocatedValue >= cpuQuota2.QuotaUsedValue) { if ((cpuQuota2.QuotaAllocatedValue + 1 - cpuQuota2.QuotaUsedValue) > maxCores) { for (int i = 1; i < maxCores + 1; i++) { ddlCpu.Items.Add(i.ToString()); } ddlCpu.SelectedIndex = ddlCpu.Items.Count - 1; // select last (maximum) item } else { for (int i = 1; i < (cpuQuota2.QuotaAllocatedValue - cpuQuota2.QuotaUsedValue) + 1; i++) { ddlCpu.Items.Add(i.ToString()); } ddlCpu.SelectedIndex = ddlCpu.Items.Count - 1; // select last (maximum) item } } else { ddlCpu.Items.Add("0"); } // external network details if (PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPS_EXTERNAL_NETWORK_ENABLED)) { // bind list PackageIPAddress[] ips = ES.Services.Servers.GetPackageUnassignedIPAddresses(PanelSecurity.PackageId, 0, IPAddressPool.VpsExternalNetwork); foreach (PackageIPAddress ip in ips) { string txt = ip.ExternalIP; if (!String.IsNullOrEmpty(ip.DefaultGateway)) { txt += "/" + ip.DefaultGateway; } listExternalAddresses.Items.Add(new ListItem(txt, ip.PackageAddressID.ToString())); } // toggle controls int maxAddresses = listExternalAddresses.Items.Count; litMaxExternalAddresses.Text = String.Format(GetLocalizedString("litMaxExternalAddresses.Text"), maxAddresses); if (maxAddresses > 0) { txtExternalAddressesNumber.Text = "1"; } } // private network if (PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPS_PRIVATE_NETWORK_ENABLED)) { NetworkAdapterDetails nic = ES.Services.VPS.GetPrivateNetworkDetails(PanelSecurity.PackageId); litPrivateNetworkFormat.Text = nic.NetworkFormat; litPrivateSubnetMask.Text = nic.SubnetMask; // set max number QuotaValueInfo privQuota = cntx.Quotas[Quotas.VPS_PRIVATE_IP_ADDRESSES_NUMBER]; int maxPrivate = privQuota.QuotaAllocatedValue; if (maxPrivate == -1) { maxPrivate = 10; } // handle DHCP mode if (nic.IsDHCP) { maxPrivate = 0; ViewState["DHCP"] = true; } txtPrivateAddressesNumber.Text = "1"; litMaxPrivateAddresses.Text = String.Format(GetLocalizedString("litMaxPrivateAddresses.Text"), maxPrivate); } // RAM size if (cntx.Quotas.ContainsKey(Quotas.VPS_RAM)) { QuotaValueInfo ramQuota = cntx.Quotas[Quotas.VPS_RAM]; if (ramQuota.QuotaAllocatedValue == -1) { // unlimited RAM txtRam.Text = ""; } else { int availSize = ramQuota.QuotaAllocatedValue - ramQuota.QuotaUsedValue; txtRam.Text = availSize < 0 ? "" : availSize.ToString(); } } // HDD size if (cntx.Quotas.ContainsKey(Quotas.VPS_HDD)) { QuotaValueInfo hddQuota = cntx.Quotas[Quotas.VPS_HDD]; if (hddQuota.QuotaAllocatedValue == -1) { // unlimited HDD txtHdd.Text = ""; } else { int availSize = hddQuota.QuotaAllocatedValue - hddQuota.QuotaUsedValue; txtHdd.Text = availSize < 0 ? "" : availSize.ToString(); } } // snapshots number if (cntx.Quotas.ContainsKey(Quotas.VPS_SNAPSHOTS_NUMBER)) { int snapsNumber = cntx.Quotas[Quotas.VPS_SNAPSHOTS_NUMBER].QuotaAllocatedValue; txtSnapshots.Text = (snapsNumber != -1) ? snapsNumber.ToString() : ""; txtSnapshots.Enabled = (snapsNumber != 0); } // toggle controls BindCheckboxOption(chkDvdInstalled, Quotas.VPS_DVD_ENABLED); chkBootFromCd.Enabled = PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPS_BOOT_CD_ALLOWED); BindCheckboxOption(chkStartShutdown, Quotas.VPS_START_SHUTDOWN_ALLOWED); BindCheckboxOption(chkPauseResume, Quotas.VPS_PAUSE_RESUME_ALLOWED); BindCheckboxOption(chkReset, Quotas.VPS_RESET_ALOWED); BindCheckboxOption(chkReboot, Quotas.VPS_REBOOT_ALLOWED); BindCheckboxOption(chkReinstall, Quotas.VPS_REINSTALL_ALLOWED); }
private void BindFormControls() { var virtualMachine = new VirtualMachine { DynamicMemory = new DynamicMemory { Buffer = 20, Priority = 50 } }; // bind password policy password.SetPackagePolicy(PanelSecurity.PackageId, UserSettings.VPS_POLICY, "AdministratorPasswordPolicy"); // OS templates listOperatingSystems.DataSource = ES.Services.Proxmox.GetOperatingSystemTemplates(PanelSecurity.PackageId); listOperatingSystems.DataBind(); listOperatingSystems.Items.Insert(0, new ListItem(GetLocalizedString("SelectOsTemplate.Text"), "")); // summary letter e-mail PackageInfo package = ES.Services.Packages.GetPackage(PanelSecurity.PackageId); if (package != null) { UserInfo user = ES.Services.Users.GetUserById(package.UserId); if (user != null) { chkSendSummary.Checked = true; txtSummaryEmail.Text = user.Email; } } // load package context PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); int maxCores = ES.Services.Proxmox.GetMaximumCpuCoresNumber(PanelSecurity.PackageId); if (cntx.Quotas.ContainsKey(Quotas.PROXMOX_CPU_NUMBER)) { QuotaValueInfo cpuQuota = cntx.Quotas[Quotas.PROXMOX_CPU_NUMBER]; if (cpuQuota.QuotaAllocatedValue != -1 && maxCores > cpuQuota.QuotaAllocatedValue) { maxCores = cpuQuota.QuotaAllocatedValue; } } for (int i = 1; i < maxCores + 1; i++) { ddlCpu.Items.Add(i.ToString()); } ddlCpu.SelectedIndex = ddlCpu.Items.Count - 1; // select last (maximum) item // external network details if (PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.PROXMOX_EXTERNAL_NETWORK_ENABLED)) { // bind vlan list PackageIPAddress[] ips = ES.Services.Servers.GetPackageUnassignedIPAddresses(PanelSecurity.PackageId, 0, IPAddressPool.VpsExternalNetwork); List <int> dupevlans = new List <int>(); List <int> vlans = new List <int>(); foreach (PackageIPAddress ip in ips) { dupevlans.Add(ip.VLAN); } // return vlan list without dupes vlans = dupevlans.Distinct().ToList(); //List<int> vlans = ES.Services.Proxmox.GetAvailableVLANs(PanelSecurity.PackageId).vlans; listVlanLists.Items.Clear(); listVlanLists.Items.Add(new ListItem("External network disabled", "-1")); foreach (int vlan in vlans) { listVlanLists.Items.Add(new ListItem(String.Format("VLAN {0}", vlan.ToString()), vlan.ToString())); } // bind external network ips 4 selected vlan BindExternalIps(); } // private network if (PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.PROXMOX_PRIVATE_NETWORK_ENABLED)) { NetworkAdapterDetails nic = ES.Services.Proxmox.GetPrivateNetworkDetails(PanelSecurity.PackageId); litPrivateNetworkFormat.Text = nic.NetworkFormat; litPrivateSubnetMask.Text = nic.SubnetMask; // set max number QuotaValueInfo privQuota = cntx.Quotas[Quotas.PROXMOX_PRIVATE_IP_ADDRESSES_NUMBER]; int maxPrivate = privQuota.QuotaAllocatedValue; if (maxPrivate == -1) { maxPrivate = 10; } // handle DHCP mode if (nic.IsDHCP) { maxPrivate = 0; ViewState["DHCP"] = true; } txtPrivateAddressesNumber.Text = "1"; litMaxPrivateAddresses.Text = String.Format(GetLocalizedString("litMaxPrivateAddresses.Text"), maxPrivate); } // RAM size if (cntx.Quotas.ContainsKey(Quotas.PROXMOX_RAM)) { QuotaValueInfo ramQuota = cntx.Quotas[Quotas.PROXMOX_RAM]; if (ramQuota.QuotaAllocatedValue == -1) { // unlimited RAM txtRam.Text = ""; } else { int availSize = ramQuota.QuotaAllocatedValue - ramQuota.QuotaUsedValue; txtRam.Text = availSize < 0 ? "" : availSize.ToString(); if (availSize > 0) { virtualMachine.DynamicMemory.Minimum = availSize / 2; virtualMachine.DynamicMemory.Maximum = availSize; } } } // HDD size if (cntx.Quotas.ContainsKey(Quotas.PROXMOX_HDD)) { QuotaValueInfo hddQuota = cntx.Quotas[Quotas.PROXMOX_HDD]; if (hddQuota.QuotaAllocatedValue == -1) { // unlimited HDD txtHdd.Text = ""; } else { int availSize = hddQuota.QuotaAllocatedValue - hddQuota.QuotaUsedValue; txtHdd.Text = availSize < 0 ? "" : availSize.ToString(); } } // snapshots number if (cntx.Quotas.ContainsKey(Quotas.PROXMOX_SNAPSHOTS_NUMBER)) { int snapsNumber = cntx.Quotas[Quotas.PROXMOX_SNAPSHOTS_NUMBER].QuotaAllocatedValue; txtSnapshots.Text = (snapsNumber != -1) ? snapsNumber.ToString() : ""; txtSnapshots.Enabled = (snapsNumber != 0); } // toggle controls BindCheckboxOption(chkDvdInstalled, Quotas.PROXMOX_DVD_ENABLED); chkBootFromCd.Enabled = PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.PROXMOX_BOOT_CD_ALLOWED); BindCheckboxOption(chkStartShutdown, Quotas.PROXMOX_START_SHUTDOWN_ALLOWED); BindCheckboxOption(chkPauseResume, Quotas.PROXMOX_PAUSE_RESUME_ALLOWED); BindCheckboxOption(chkReset, Quotas.PROXMOX_RESET_ALOWED); BindCheckboxOption(chkReboot, Quotas.PROXMOX_REBOOT_ALLOWED); BindCheckboxOption(chkReinstall, Quotas.PROXMOX_REINSTALL_ALLOWED); // the settings user controls this.BindSettingsControls(virtualMachine); }