private void ToggleWizardSteps() { // external network if (!PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPS2012_EXTERNAL_NETWORK_ENABLED)) { wizard.WizardSteps.Remove(stepExternalNetwork); chkExternalNetworkEnabled.Checked = false; } //KD FSJ // load package context PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); QuotaValueInfo cpuQuota2 = cntx.Quotas[Quotas.VPS2012_CPU_NUMBER]; if (cpuQuota2.QuotaAllocatedValue > cpuQuota2.QuotaUsedValue | cpuQuota2.QuotaAllocatedValue == -1) { wizard.Visible = true; } else { wizard.Visible = false; messageBox.ShowErrorMessage("NO_CPU_CORES"); } // private network if (!PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPS2012_PRIVATE_NETWORK_ENABLED)) { wizard.WizardSteps.Remove(stepPrivateNetwork); chkPrivateNetworkEnabled.Checked = false; } }
private void BindControls() { // load adapter details NetworkAdapterDetails nic = ES.Services.VPS2012.GetPrivateNetworkAdapterDetails(PanelRequest.ItemID); // load package context PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); if (cntx.Quotas.ContainsKey(Quotas.VPS2012_PRIVATE_IP_ADDRESSES_NUMBER)) { // set max number QuotaValueInfo privQuota = cntx.Quotas[Quotas.VPS2012_PRIVATE_IP_ADDRESSES_NUMBER]; int maxPrivate = privQuota.QuotaAllocatedValue; if (maxPrivate == -1) { maxPrivate = 10; } maxPrivate -= nic.IPAddresses.Length; txtPrivateAddressesNumber.Text = maxPrivate.ToString(); litMaxPrivateAddresses.Text = String.Format(GetLocalizedString("litMaxPrivateAddresses.Text"), maxPrivate); btnAdd.Enabled = btnAddByInject.Enabled = maxPrivate > 0; } }
public void BindQuota() { try { // load package context PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); // get quota if (cntx.Quotas.ContainsKey(QuotaName)) { QuotaValueInfo quota = cntx.Quotas[QuotaName]; quotaViewer.QuotaTypeId = quota.QuotaTypeId; quotaViewer.QuotaUsedValue = quota.QuotaUsedValue; quotaViewer.QuotaValue = quota.QuotaAllocatedValue; quotaViewer.QuotaAvailable = -1; //this.Visible = quota.QuotaAllocatedValue != 0; } else { this.Visible = false; quotaViewer.QuotaTypeId = 1; // bool quotaViewer.QuotaUsedValue = 0; quotaViewer.QuotaValue = 0; quotaViewer.QuotaAvailable = -1; } } catch { /* do nothing */ } }
private static bool CheckQuotas(int packageId, out int errorCode) { // check account errorCode = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (errorCode < 0) { return(false); } // check package errorCode = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive); if (errorCode < 0) { return(false); } // check organizations quota QuotaValueInfo quota = PackageController.GetPackageQuota(packageId, Quotas.ORGANIZATIONS); if (quota.QuotaExhausted) { errorCode = BusinessErrorCodes.ERROR_ORGS_RESOURCE_QUOTA_LIMIT; return(false); } // check sub-domains quota (for temporary domain) quota = PackageController.GetPackageQuota(packageId, Quotas.OS_SUBDOMAINS); if (quota.QuotaExhausted) { errorCode = BusinessErrorCodes.ERROR_SUBDOMAIN_QUOTA_LIMIT; return(false); } return(true); }
private static int RecalculateStorageMaxSize(int size, int packageId) { PackageContext cntx = PackageController.GetPackageContext(packageId); QuotaValueInfo quota = cntx.Quotas[Quotas.HOSTED_SHAREPOINT_STORAGE_SIZE]; if (quota.QuotaAllocatedValue == -1) { if (size == -1)//Unlimited { return(-1); } else { return(size); } } else { if (size == -1) { return(quota.QuotaAllocatedValue); } return(Math.Min(size, quota.QuotaAllocatedValue)); } }
private void CheckAdditionalHddQuota(int currCount) { PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); if (cntx.Quotas.ContainsKey(Quotas.VPS2012_ADDITIONAL_VHD_COUNT)) { QuotaValueInfo additionalHddQuota = cntx.Quotas[Quotas.VPS2012_ADDITIONAL_VHD_COUNT]; int quotaHddCount = additionalHddQuota.QuotaAllocatedValue; int maxHddCount; VirtualMachine vm = ES.Services.VPS2012.GetVirtualMachineItem(PanelRequest.ItemID); if (vm != null && vm.Generation > 1) { maxHddCount = 62; } else { maxHddCount = 2; } if (quotaHddCount == -1 || quotaHddCount > maxHddCount) { quotaHddCount = maxHddCount; } btnAddHdd.Enabled = (currCount < quotaHddCount); } else { btnAddHdd.Enabled = false; } }
public static void CheckQuotaValue(PackageContext cntx, List <string> errors, string quotaName, long currentVal, long val, string messageKey) { if (!cntx.Quotas.ContainsKey(quotaName)) { return; } QuotaValueInfo quota = cntx.Quotas[quotaName]; if (val == -1 && quota.QuotaExhausted) // check if quota already reached { errors.Add(messageKey + ":" + quota.QuotaAllocatedValue); } else if (quota.QuotaAllocatedValue == -1) { return; // unlimited } else if (quota.QuotaTypeId == 1 && val == 1 && quota.QuotaAllocatedValue == 0) // bool quota { errors.Add(messageKey); } else if (quota.QuotaTypeId == 2) { long maxValue = quota.QuotaAllocatedValue - quota.QuotaUsedValue + currentVal; if (val > maxValue) { errors.Add(messageKey + ":" + maxValue); } } else if (quota.QuotaTypeId == 3 && val > quota.QuotaAllocatedValue) { int maxValue = quota.QuotaAllocatedValue; errors.Add(messageKey + ":" + maxValue); } }
private bool CheckServiceLevelQuota(QuotaValueInfo quota) { if (quota.QuotaAllocatedValue != -1) { return(quota.QuotaAllocatedValue > quota.QuotaUsedValue); } return(true); }
private bool CheckServiceLevelQuota(QuotaValueInfo quota, int itemCount) { if (quota.QuotaAllocatedValue != -1) { return(quota.QuotaAllocatedValue >= quota.QuotaUsedValue + itemCount); } return(true); }
private void ToggleWizardSteps() { //CPU Core if (cntx == null) { cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); //Load package context } if (ddlCpu.Items.Count == 0 || String.IsNullOrWhiteSpace(ddlCpu.SelectedValue)) { int maxCores = 0; if (!String.IsNullOrWhiteSpace(listOperatingSystems.SelectedValue)) { maxCores = ES.Services.VPSPC.GetMaximumCpuCoresNumber(PanelSecurity.PackageId, listOperatingSystems.SelectedItem.Value); } if (cntx.Quotas.ContainsKey(Quotas.VPSForPC_CPU_NUMBER)) { QuotaValueInfo cpuQuota = cntx.Quotas[Quotas.VPSForPC_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 > 0 ? 0: -1); // select last (maximum) item } // external network if (!PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPSForPC_EXTERNAL_NETWORK_ENABLED)) { wizard.WizardSteps.Remove(stepExternalNetwork); chkExternalNetworkEnabled.Checked = false; } // private network if (!PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPSForPC_PRIVATE_NETWORK_ENABLED)) { wizard.WizardSteps.Remove(stepPrivateNetwork); chkPrivateNetworkEnabled.Checked = false; } }
protected void wizard_ActiveStepChanged(object sender, EventArgs e) { if (cntx == null) { cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); } if ((wizard.ActiveStepIndex == 1) && (cntx.Quotas.ContainsKey(Quotas.VPSForPC_HDD))) { QuotaValueInfo hddQuota = cntx.Quotas[Quotas.VPSForPC_HDD]; if (hddQuota.QuotaAllocatedValue == -1) { // unlimited HDD txtHdd.Text = ""; } else { int availSize = hddQuota.QuotaAllocatedValue - hddQuota.QuotaUsedValue; if (availSize <= 0) { txtHdd.Text = "0"; txtHdd.Enabled = false; Button btn = ((Button)wizard.FindControl("StepNavigationTemplateContainerID").FindControl("btnNext")); if (btn != null) { btn.Enabled = false; } messageBox.ShowErrorMessage("VPS_ERROR_CREATE", new Exception("The HDD quota has been exhausted.")); return; } else { txtHdd.Text = availSize.ToString(); } txtHdd.Text = ""; } } BindSummary(); }
private void SetVisibilityStatus4BriefQuotasBlock() { foreach (KeyValuePair <string, string> kvp in briefQuotaHash) { // Lookup for quota control... Quota quotaCtl = FindControl(kvp.Key) as Quota; Control containerCtl = FindControl(kvp.Value); // Skip processing if quota or its container ctrl not found if (quotaCtl == null || containerCtl == null) { continue; } // Find out a quota value info within the package context QuotaValueInfo qvi = Array.Find <QuotaValueInfo>( cntx.QuotasArray, x => x.QuotaName == quotaCtl.QuotaName); // Skip processing if quota not defined in the package context if (qvi == null) { continue; } // Show or hide corresponding quotas' containers switch (qvi.QuotaTypeId) { case QuotaInfo.BooleanQuota: // 1: Quota is enabled; // 0: Quota is disabled; containerCtl.Visible = (qvi.QuotaAllocatedValue > 0); break; case QuotaInfo.NumericQuota: case QuotaInfo.MaximumValueQuota: // -1: Quota is unlimited // 0: Quota is disabled // xx: Quota is enabled containerCtl.Visible = (qvi.QuotaAllocatedValue != 0); break; } } }
private void RebindAdditionalHdd(List <AdditionalHdd> hdd) { PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); if (cntx.Quotas.ContainsKey(Quotas.VPS2012_ADDITIONAL_VHD_COUNT)) { QuotaValueInfo additionalHddQuota = cntx.Quotas[Quotas.VPS2012_ADDITIONAL_VHD_COUNT]; int quotaHddCount = additionalHddQuota.QuotaAllocatedValue; int maxHddCount = 62; LibraryItem[] osTemplates = ES.Services.VPS2012.GetOperatingSystemTemplates(PanelSecurity.PackageId); foreach (LibraryItem item in osTemplates) { if (String.Compare(item.Path, listOperatingSystems.SelectedValue, true) == 0) { if (item.Generation > 1) { maxHddCount = 62; } else { maxHddCount = 2; } break; } } if (quotaHddCount == -1 || quotaHddCount > maxHddCount) { quotaHddCount = maxHddCount; } btnAddHdd.Enabled = (hdd.Count < quotaHddCount); } else { btnAddHdd.Enabled = false; } repHdd.DataSource = hdd; repHdd.DataBind(); }
private void BindConfiguration() { VirtualMachine vm = null; try { // load machine vm = ES.Services.VPS2012.GetVirtualMachineItem(PanelRequest.ItemID); if (vm == null) { messageBox.ShowErrorMessage("VPS_LOAD_VM_META_ITEM"); return; } // bind CPU cores int maxCores = ES.Services.VPS2012.GetMaximumCpuCoresNumber(vm.PackageId); PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); QuotaValueInfo cpuQuota2 = cntx.Quotas[Quotas.VPS2012_CPU_NUMBER]; int cpuQuotausable = (cpuQuota2.QuotaAllocatedValue - cpuQuota2.QuotaUsedValue) + vm.CpuCores; 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 (cpuQuotausable > 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 < cpuQuotausable + 1; i++) { ddlCpu.Items.Add(i.ToString()); } ddlCpu.SelectedIndex = ddlCpu.Items.Count - 1; // select last (maximum) item } } else { for (int i = 1; i < vm.CpuCores + 1; i++) { ddlCpu.Items.Add(i.ToString()); } ddlCpu.SelectedIndex = ddlCpu.Items.Count - 1; // select last (maximum) item } // bind item ddlCpu.SelectedValue = vm.CpuCores.ToString(); txtRam.Text = vm.RamSize.ToString(); txtHdd.Text = vm.HddSize[0].ToString(); hiddenTxtValHdd.Value = vm.HddSize[0].ToString(); BindAdditionalHdd(vm); txtHddMinIOPS.Text = vm.HddMinimumIOPS.ToString(); txtHddMaxIOPS.Text = vm.HddMaximumIOPS.ToString(); txtSnapshots.Text = vm.SnapshotsNumber.ToString(); chkDvdInstalled.Checked = vm.DvdDriveInstalled; chkBootFromCd.Checked = vm.BootFromCD; chkNumLock.Checked = vm.NumLockEnabled; chkSecureBoot.Checked = vm.EnableSecureBoot; if (vm.Generation == 1) { chkSecureBoot.Checked = false; chkSecureBoot.Enabled = false; } chkStartShutdown.Checked = vm.StartTurnOffAllowed; chkPauseResume.Checked = vm.PauseResumeAllowed; chkReset.Checked = vm.ResetAllowed; chkReboot.Checked = vm.RebootAllowed; chkReinstall.Checked = vm.ReinstallAllowed; chkExternalNetworkEnabled.Checked = vm.ExternalNetworkEnabled; chkPrivateNetworkEnabled.Checked = vm.PrivateNetworkEnabled; chkIgnoreHddWarning.Visible = (PanelSecurity.EffectiveUser.Role != UserRole.User); // other quotas 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); BindCheckboxOption(chkExternalNetworkEnabled, Quotas.VPS2012_EXTERNAL_NETWORK_ENABLED); if (chkExternalNetworkEnabled.Enabled && !chkExternalNetworkEnabled.Checked) { PackageIPAddress[] ips = ES.Services.Servers.GetPackageUnassignedIPAddresses(PanelSecurity.PackageId, 0, IPAddressPool.VpsExternalNetwork); if (ips.Length == 0) { chkExternalNetworkEnabled.Enabled = false; EmptyExternalAddressesMessage.Visible = true; } } BindCheckboxOption(chkPrivateNetworkEnabled, Quotas.VPS2012_PRIVATE_NETWORK_ENABLED); this.BindSettingsControls(vm); } catch (Exception ex) { messageBox.ShowErrorMessage("VPS_LOAD_VM_META_ITEM", ex); } }
private void BindFormControls() { try { // OS templates listOperatingSystems.DataSource = ES.Services.VPSPC.GetOperatingSystemTemplatesPC(PanelSecurity.PackageId); listOperatingSystems.DataBind(); } catch (Exception ex) { listOperatingSystems.Items.Add(new ListItem(GetLocalizedString("SelectOsTemplate.Text"), "")); listOperatingSystems.Enabled = false; txtVmName.Enabled = false; Button btn; btn = ((Button)wizard.FindControl("StepNavigationTemplateContainerID").FindControl("btnNext")); if (btn != null) { btn.Enabled = false; } btn = ((Button)wizard.FindControl("StartNavigationTemplateContainerID").FindControl("btnNext")); if (btn != null) { btn.Enabled = false; } messageBox.ShowErrorMessage("VPS_ERROR_CREATE", new Exception("no templates")); } // 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 if (cntx == null) { cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); } // bind CPU cores int maxCores = 0; if (!String.IsNullOrWhiteSpace(listOperatingSystems.SelectedValue)) { maxCores = ES.Services.VPSPC.GetMaximumCpuCoresNumber(PanelSecurity.PackageId, listOperatingSystems.SelectedValue); } if (cntx.Quotas.ContainsKey(Quotas.VPSForPC_CPU_NUMBER)) { QuotaValueInfo cpuQuota = cntx.Quotas[Quotas.VPSForPC_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 > 0 ? 0 : -1); // select last (maximum) item #region Network // external network details if (PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPSForPC_EXTERNAL_NETWORK_ENABLED)) { } // private network if (PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPSForPC_PRIVATE_NETWORK_ENABLED)) { //Fill VLanID list UserInfo user = UsersHelper.GetUser(PanelSecurity.SelectedUserId); chkPrivateNetworkEnabled.Checked = chkPrivateNetworkEnabled.Enabled = tablePrivateNetwork.Visible = user.Vlans.Count > 0; pVLanListIsEmptyMessage.Visible = user.Vlans.Count == 0; ddlPrivateVLanID.DataSource = user.Vlans; ddlPrivateVLanID.DataBind(); } #endregion // RAM size if (cntx.Quotas.ContainsKey(Quotas.VPSForPC_RAM)) { QuotaValueInfo ramQuota = cntx.Quotas[Quotas.VPSForPC_RAM]; if (ramQuota.QuotaAllocatedValue == -1) { // unlimited RAM txtRam.Text = ""; } else { int availSize = ramQuota.QuotaAllocatedValue - ramQuota.QuotaUsedValue; txtRam.Text = availSize < 0 ? "" : availSize.ToString(); } txtRam.Text = ""; } // HDD size if (cntx.Quotas.ContainsKey(Quotas.VPSForPC_HDD)) { QuotaValueInfo hddQuota = cntx.Quotas[Quotas.VPSForPC_HDD]; if (hddQuota.QuotaAllocatedValue == -1) { // unlimited HDD txtHdd.Text = ""; } else { int availSize = hddQuota.QuotaAllocatedValue - hddQuota.QuotaUsedValue; txtHdd.Text = availSize < 0 ? "" : availSize.ToString(); } txtHdd.Text = ""; } // snapshots number if (cntx.Quotas.ContainsKey(Quotas.VPSForPC_SNAPSHOTS_NUMBER)) { int snapsNumber = cntx.Quotas[Quotas.VPSForPC_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.VPSForPC_BOOT_CD_ALLOWED); BindCheckboxOption(chkStartShutdown, Quotas.VPSForPC_START_SHUTDOWN_ALLOWED); BindCheckboxOption(chkPauseResume, Quotas.VPSForPC_PAUSE_RESUME_ALLOWED); BindCheckboxOption(chkReset, Quotas.VPSForPC_RESET_ALOWED); BindCheckboxOption(chkReboot, Quotas.VPSForPC_REBOOT_ALLOWED); BindCheckboxOption(chkReinstall, Quotas.VPSForPC_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.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); }
private void BindConfiguration() { VMInfo vm = null; try { // load machine vm = ES.Services.VPSPC.GetVirtualMachineItem(PanelRequest.ItemID); if (vm == null) { messageBox.ShowErrorMessage("VPS_LOAD_VM_META_ITEM"); return; } // bind CPU cores int maxCores = ES.Services.VPSPC.GetMaximumCpuCoresNumber(vm.PackageId, vm.Name); PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); QuotaValueInfo cpuQuota2 = cntx.Quotas[Quotas.VPSForPC_CPU_NUMBER]; int cpuQuotausable = (cpuQuota2.QuotaAllocatedValue - cpuQuota2.QuotaUsedValue) + vm.CPUCount; 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 (cpuQuotausable > 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 < cpuQuotausable + 1; i++) { ddlCpu.Items.Add(i.ToString()); } ddlCpu.SelectedIndex = ddlCpu.Items.Count - 1; // select last (maximum) item } } else { for (int i = 1; i < vm.CPUCount + 1; i++) { ddlCpu.Items.Add(i.ToString()); } ddlCpu.SelectedIndex = ddlCpu.Items.Count - 1; // select last (maximum) item } // bind item ddlCpu.SelectedValue = vm.CPUCount.ToString(); txtRam.Text = vm.Memory.ToString(); txtHdd.Text = vm.HddSize.ToString(); txtSnapshots.Text = vm.SnapshotsNumber.ToString(); chkDvdInstalled.Checked = vm.DvdDriver; chkBootFromCd.Checked = vm.BootFromCD; chkNumLock.Checked = vm.NumLockEnabled; chkStartShutdown.Checked = vm.StartTurnOffAllowed; chkPauseResume.Checked = vm.PauseResumeAllowed; chkReset.Checked = vm.ResetAllowed; chkReboot.Checked = vm.RebootAllowed; chkReinstall.Checked = vm.ReinstallAllowed; chkExternalNetworkEnabled.Checked = vm.ExternalNetworkEnabled; chkPrivateNetworkEnabled.Checked = vm.PrivateNetworkEnabled; // toggle controls // other quotas BindCheckboxOption(chkDvdInstalled, Quotas.VPSForPC_DVD_ENABLED); chkBootFromCd.Enabled = PackagesHelper.IsQuotaEnabled(PanelSecurity.PackageId, Quotas.VPSForPC_BOOT_CD_ALLOWED); BindCheckboxOption(chkStartShutdown, Quotas.VPSForPC_START_SHUTDOWN_ALLOWED); BindCheckboxOption(chkPauseResume, Quotas.VPSForPC_PAUSE_RESUME_ALLOWED); BindCheckboxOption(chkReset, Quotas.VPSForPC_RESET_ALOWED); BindCheckboxOption(chkReboot, Quotas.VPSForPC_REBOOT_ALLOWED); BindCheckboxOption(chkReinstall, Quotas.VPSForPC_REINSTALL_ALLOWED); BindCheckboxOption(chkExternalNetworkEnabled, Quotas.VPSForPC_EXTERNAL_NETWORK_ENABLED); BindCheckboxOption(chkPrivateNetworkEnabled, Quotas.VPSForPC_PRIVATE_NETWORK_ENABLED); } catch (Exception ex) { messageBox.ShowErrorMessage("VPS_LOAD_VM_META_ITEM", ex); } }
private void BindConfiguration() { VirtualMachine vm = null; try { // load machine vm = ES.Services.Proxmox.GetVirtualMachineItem(PanelRequest.ItemID); if (vm == null) { messageBox.ShowErrorMessage("VPS_LOAD_VM_META_ITEM"); return; } // bind CPU cores int maxCores = ES.Services.Proxmox.GetMaximumCpuCoresNumber(vm.PackageId); PackageContext cntx = PackagesHelper.GetCachedPackageContext(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()); } // bind item ddlCpu.SelectedValue = vm.CpuCores.ToString(); txtRam.Text = vm.RamSize.ToString(); txtHdd.Text = vm.HddSize[0].ToString(); txtSnapshots.Text = vm.SnapshotsNumber.ToString(); chkDvdInstalled.Checked = vm.DvdDriveInstalled; chkBootFromCd.Checked = vm.BootFromCD; //chkNumLock.Checked = vm.NumLockEnabled; chkStartShutdown.Checked = vm.StartTurnOffAllowed; chkPauseResume.Checked = vm.PauseResumeAllowed; chkReset.Checked = vm.ResetAllowed; chkReboot.Checked = vm.RebootAllowed; chkReinstall.Checked = vm.ReinstallAllowed; chkExternalNetworkEnabled.Checked = vm.ExternalNetworkEnabled; chkPrivateNetworkEnabled.Checked = vm.PrivateNetworkEnabled; // other quotas 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); BindCheckboxOption(chkExternalNetworkEnabled, Quotas.PROXMOX_EXTERNAL_NETWORK_ENABLED); BindCheckboxOption(chkPrivateNetworkEnabled, Quotas.PROXMOX_PRIVATE_NETWORK_ENABLED); // Diksk Resize funktioniert nicht wenn snapshots existieren VirtualMachineSnapshot[] snapshots = ES.Services.Proxmox.GetVirtualMachineSnapshots(PanelRequest.ItemID); txtHdd.Enabled = (snapshots.Length <= 0); this.BindSettingsControls(vm); } catch (Exception ex) { messageBox.ShowErrorMessage("VPS_LOAD_VM_META_ITEM", ex); } }
/// <summary> /// Adds SharePoint site collection. /// </summary> /// <param name="item">Site collection description.</param> /// <returns>Created site collection id within metabase.</returns> public static int AddSiteCollection(SharePointEnterpriseSiteCollection item) { // Check account. int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // Check package. int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive); if (packageCheck < 0) { return(packageCheck); } // Check quota. OrganizationStatistics orgStats = OrganizationController.GetOrganizationStatistics(item.OrganizationId); //QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.HOSTED_SHAREPOINT_SITES); if (orgStats.AllocatedSharePointEnterpriseSiteCollections > -1 && orgStats.CreatedSharePointEnterpriseSiteCollections >= orgStats.AllocatedSharePointEnterpriseSiteCollections) { return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_QUOTA_LIMIT); } // Check if stats resource is available int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.SharepointEnterpriseServer); if (serviceId == 0) { return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE); } StringDictionary hostedSharePointSettings = ServerController.GetServiceSettings(serviceId); QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.HOSTED_SHAREPOINT_ENTERPRISE_USESHAREDSSL); Uri rootWebApplicationUri = new Uri(hostedSharePointSettings["RootWebApplicationUri"]); Organization org = OrganizationController.GetOrganization(item.OrganizationId); string siteName = item.Name; if (quota.QuotaAllocatedValue == 1) { string sslRoot = hostedSharePointSettings["SharedSSLRoot"]; string defaultDomain = org.DefaultDomain; string hostNameBase = string.Empty; string[] tmp = defaultDomain.Split('.'); if (tmp.Length == 2) { hostNameBase = tmp[0]; } else { if (tmp.Length > 2) { hostNameBase = tmp[0] + tmp[1]; } } int counter = 0; item.Name = String.Format("{0}://{1}", rootWebApplicationUri.Scheme, hostNameBase + "-" + counter.ToString() + "." + sslRoot); siteName = String.Format("{0}", hostNameBase + "-" + counter.ToString() + "." + sslRoot); while (DataProvider.CheckServiceItemExists(serviceId, item.Name, "WebsitePanel.Providers.SharePoint.SharePointEnterpriseSiteCollection, WebsitePanel.Providers.Base")) { counter++; item.Name = String.Format("{0}://{1}", rootWebApplicationUri.Scheme, hostNameBase + "-" + counter.ToString() + "." + sslRoot); siteName = String.Format("{0}", hostNameBase + "-" + counter.ToString() + "." + sslRoot); } } else { item.Name = String.Format("{0}://{1}", rootWebApplicationUri.Scheme, item.Name); } if (rootWebApplicationUri.Port > 0 && rootWebApplicationUri.Port != 80 && rootWebApplicationUri.Port != 443) { item.PhysicalAddress = String.Format("{0}:{1}", item.Name, rootWebApplicationUri.Port); } else { item.PhysicalAddress = item.Name; } if (Utils.ParseBool(hostedSharePointSettings["LocalHostFile"], false)) { item.RootWebApplicationInteralIpAddress = hostedSharePointSettings["RootWebApplicationInteralIpAddress"]; item.RootWebApplicationFQDN = item.Name.Replace(rootWebApplicationUri.Scheme + "://", ""); } item.MaxSiteStorage = RecalculateMaxSize(org.MaxSharePointEnterpriseStorage, (int)item.MaxSiteStorage); item.WarningStorage = item.MaxSiteStorage == -1 ? -1 : Math.Min((int)item.WarningStorage, item.MaxSiteStorage); // Check package item with given name already exists. if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SharePointEnterpriseSiteCollection)) != null) { return(BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_EXISTS); } // Log operation. TaskManager.StartTask("HOSTED_SHAREPOINT_ENTERPRISE", "ADD_SITE_COLLECTION", item.Name); try { // Create site collection on server. HostedSharePointServerEnt hostedSharePointServer = GetHostedSharePointServer(serviceId); hostedSharePointServer.Enterprise_CreateSiteCollection(item); // Make record in metabase. item.ServiceId = serviceId; int itemId = PackageController.AddPackageItem(item); hostedSharePointServer.Enterprise_SetPeoplePickerOu(item.Name, org.DistinguishedName); int dnsServiceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Dns); if (dnsServiceId > 0) { string[] tmpStr = siteName.Split('.'); string hostName = tmpStr[0]; string domainName = siteName.Substring(hostName.Length + 1, siteName.Length - (hostName.Length + 1)); List <GlobalDnsRecord> dnsRecords = ServerController.GetDnsRecordsByService(serviceId); List <DnsRecord> resourceRecords = DnsServerController.BuildDnsResourceRecords(dnsRecords, hostName, domainName, ""); DNSServer dns = new DNSServer(); ServiceProviderProxy.Init(dns, dnsServiceId); // add new resource records dns.AddZoneRecords(domainName, resourceRecords.ToArray()); } TaskManager.ItemId = itemId; return(itemId); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
protected void btnUpdate_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } try { // check rights bool manageAllowed = VirtualMachines2012Helper.IsVirtualMachineManagementAllowed(PanelSecurity.PackageId); if (!manageAllowed) { return; } // check snapshots VirtualMachineSnapshot[] snapshots = ES.Services.VPS2012.GetVirtualMachineSnapshots(PanelRequest.ItemID); if (snapshots.Length > 0) { return; } VirtualMachine virtualMachine = new VirtualMachine(); VirtualMachine vm = ES.Services.VPS2012.GetVirtualMachineItem(PanelRequest.ItemID); if (!chkIgnoreHddWarning.Checked || PanelSecurity.EffectiveUser.Role == UserRole.User) { if (Utils.ParseInt(hiddenTxtValHdd.Value) > Utils.ParseInt(txtHdd.Text.Trim())) { messageBox.ShowWarningMessage("VPS_CHANGE_HDD_SIZE"); return; } List <AdditionalHdd> hdds = GetAdditionalHdd(); foreach (AdditionalHdd hdd in hdds) { for (int i = 0; i < vm.VirtualHardDrivePath.Length; i++) { if (String.IsNullOrEmpty(vm.VirtualHardDrivePath[i])) { continue; } if (Path.GetFileName(vm.VirtualHardDrivePath[i]).ToLower().Equals(Path.GetFileName(hdd.DiskPath).ToLower()) && Utils.ParseInt(hdd.DiskSize.Trim()) < vm.HddSize[i]) { messageBox.ShowWarningMessage("VPS_CHANGE_HDD_SIZE"); return; } } } } // the custom provider control this.SaveSettingsControls(ref virtualMachine); virtualMachine.CpuCores = Utils.ParseInt(ddlCpu.SelectedValue); virtualMachine.RamSize = Utils.ParseInt(txtRam.Text.Trim()); List <int> hddSize = new List <int>(); List <String> hddPath = new List <String>(); hddSize.Add(Utils.ParseInt(txtHdd.Text.Trim())); hddPath.Add(vm.VirtualHardDrivePath[0]); List <AdditionalHdd> additionalHdd = GetAdditionalHdd(); foreach (AdditionalHdd hdd in additionalHdd) { int size = Utils.ParseInt(hdd.DiskSize.Trim()); if (size > 0) { hddSize.Add(size); hddPath.Add(hdd.DiskPath); } } virtualMachine.HddSize = hddSize.ToArray(); virtualMachine.VirtualHardDrivePath = hddPath.ToArray(); virtualMachine.SnapshotsNumber = Utils.ParseInt(txtSnapshots.Text.Trim()); virtualMachine.HddMinimumIOPS = Utils.ParseInt(txtHddMinIOPS.Text.Trim()); virtualMachine.HddMaximumIOPS = Utils.ParseInt(txtHddMaxIOPS.Text.Trim()); virtualMachine.DvdDriveInstalled = chkDvdInstalled.Checked; virtualMachine.BootFromCD = chkBootFromCd.Checked; virtualMachine.NumLockEnabled = chkNumLock.Checked; virtualMachine.EnableSecureBoot = chkSecureBoot.Checked; virtualMachine.StartTurnOffAllowed = chkStartShutdown.Checked; virtualMachine.PauseResumeAllowed = chkPauseResume.Checked; virtualMachine.RebootAllowed = chkReboot.Checked; virtualMachine.ResetAllowed = chkReset.Checked; virtualMachine.ReinstallAllowed = chkReinstall.Checked; virtualMachine.ExternalNetworkEnabled = chkExternalNetworkEnabled.Checked; virtualMachine.PrivateNetworkEnabled = chkPrivateNetworkEnabled.Checked; virtualMachine.NeedReboot = chkForceReboot.Checked; virtualMachine.defaultaccessvlan = vm.defaultaccessvlan; virtualMachine.PrivateNetworkVlan = vm.PrivateNetworkVlan; bool setupExternalNetwork = !vm.ExternalNetworkEnabled && chkExternalNetworkEnabled.Checked; bool setupPrivateNetwork = !vm.PrivateNetworkEnabled && chkPrivateNetworkEnabled.Checked; int[] ipId = new int[1]; int privAdrCount = 0; if (setupExternalNetwork) { PackageIPAddress[] ips = ES.Services.Servers.GetPackageUnassignedIPAddresses(PanelSecurity.PackageId, 0, IPAddressPool.VpsExternalNetwork); if (ips.Length > 0) { virtualMachine.defaultaccessvlan = ips[0].VLAN; ipId[0] = ips[0].PackageAddressID; } } if (setupPrivateNetwork) { PackageVLANsPaged vlans = ES.Services.Servers.GetPackagePrivateNetworkVLANs(PanelSecurity.PackageId, "", 0, Int32.MaxValue); if (vlans.Count > 0) { virtualMachine.PrivateNetworkVlan = vlans.Items[0].Vlan; } PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); if (cntx.Quotas.ContainsKey(Quotas.VPS2012_PRIVATE_IP_ADDRESSES_NUMBER)) { QuotaValueInfo privQuota = cntx.Quotas[Quotas.VPS2012_PRIVATE_IP_ADDRESSES_NUMBER]; if (privQuota.QuotaAllocatedValue > 0 || privQuota.QuotaAllocatedValue == -1) { privAdrCount = 1; } } } ResultObject res = ES.Services.VPS2012.UpdateVirtualMachineResource(PanelRequest.ItemID, virtualMachine); //ResultObject res = ES.Services.VPS2012.UpdateVirtualMachineConfiguration(PanelRequest.ItemID, // Utils.ParseInt(ddlCpu.SelectedValue), // Utils.ParseInt(txtRam.Text.Trim()), // Utils.ParseInt(txtHdd.Text.Trim()), // Utils.ParseInt(txtSnapshots.Text.Trim()), // chkDvdInstalled.Checked, // chkBootFromCd.Checked, // chkNumLock.Checked, // chkStartShutdown.Checked, // chkPauseResume.Checked, // chkReboot.Checked, // chkReset.Checked, // chkReinstall.Checked, // chkExternalNetworkEnabled.Checked, // chkPrivateNetworkEnabled.Checked, // virtualMachine); if (res.IsSuccess) { if (setupExternalNetwork && ipId[0] != 0) { ES.Services.VPS2012.AddVirtualMachineExternalIPAddresses(PanelRequest.ItemID, false, 1, ipId); } if (setupPrivateNetwork && privAdrCount > 0) { ES.Services.VPS2012.AddVirtualMachinePrivateIPAddresses(PanelRequest.ItemID, true, privAdrCount, new string[0], false, null, null, null, null); } // redirect back RedirectBack("changed"); } else { // show error messageBox.ShowMessage(res, "VPS_CHANGE_VM_CONFIGURATION", "VPS"); } } catch (Exception ex) { messageBox.ShowErrorMessage("VPS_CHANGE_VM_CONFIGURATION", ex); } }