Example #1
0
        private void createPool()
        {
            try
            {
                Host master = getMaster();
                if (master == null)
                {
                    log.Error("Disconnected during create pool");
                    return;
                }
                List <Host> slaves = getSlaves();
                // Check supp packs and warn
                List <string> badSuppPacks = PoolJoinRules.HomogeneousSuppPacksDiffering(slaves, master);
                if (!HelpersGUI.GetPermissionFor(badSuppPacks, sp => true,
                                                 Messages.NEW_POOL_SUPP_PACK, Messages.NEW_POOL_SUPP_PACKS, false, "PoolJoinSuppPacks"))
                {
                    return;
                }

                // Are there any hosts which are forbidden from masking their CPUs for licensing reasons?
                // If so, we need to show upsell.
                if (null != slaves.Find(host =>
                                        !PoolJoinRules.CompatibleCPUs(host, master, false) &&
                                        Helpers.FeatureForbidden(host, Host.RestrictCpuMasking) &&
                                        !PoolJoinRules.FreeHostPaidMaster(host, master, false))) // in this case we can upgrade the license and then mask the CPU
                {
                    using (var dlg = new UpsellDialog(HiddenFeatures.LinkLabelHidden ? Messages.UPSELL_BLURB_CPUMASKING : Messages.UPSELL_BLURB_CPUMASKING + Messages.UPSELL_BLURB_CPUMASKING_MORE,
                                                      InvisibleMessages.UPSELL_LEARNMOREURL_CPUMASKING))
                        dlg.ShowDialog(this);
                    return;
                }

                if (!HelpersGUI.GetPermissionFor(slaves, host => PoolJoinRules.FreeHostPaidMaster(host, master, false),
                                                 Messages.NEW_POOL_LICENSE_MESSAGE, Messages.NEW_POOL_LICENSE_MESSAGE_MULTIPLE, true, "PoolJoinRelicensing")
                    ||
                    !HelpersGUI.GetPermissionFor(slaves, host => !PoolJoinRules.CompatibleCPUs(host, master, false),
                                                 Messages.NEW_POOL_CPU_MASKING_MESSAGE, Messages.NEW_POOL_CPU_MASKING_MESSAGE_MULTIPLE, true, "PoolJoinCpuMasking")
                    ||
                    !HelpersGUI.GetPermissionFor(slaves, host => !PoolJoinRules.CompatibleAdConfig(host, master, false),
                                                 Messages.NEW_POOL_AD_MESSAGE, Messages.NEW_POOL_AD_MESSAGE_MULTIPLE, true, "PoolJoinAdConfiguring")
                    ||
                    !HelpersGUI.GetPermissionForCpuFeatureLevelling(slaves, Helpers.GetPoolOfOne(master.Connection)))
                {
                    return;
                }

                log.DebugFormat("Creating new pool {0} ({1}) with master {2}", poolName, poolDescription, Helpers.GetName(master));
                foreach (Host slave in slaves)
                {
                    log.DebugFormat("  Slave {0}", Helpers.GetName(slave));
                }

                new CreatePoolAction(master, slaves, poolName, poolDescription, AddHostToPoolCommand.GetAdPrompt,
                                     AddHostToPoolCommand.NtolDialog, ApplyLicenseEditionCommand.ShowLicensingFailureDialog).RunAsync();
            }
            catch (System.Net.WebException exn)
            {
                log.Debug(exn, exn);
            }
        }
        /// <summary>
        /// For Create only.
        /// </summary>
        /// <param name="master"></param>
        /// <param name="slaves"></param>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="acceptNTolChanges"></param>
        /// <param name="doOnLicensingFailure"></param>
        /// <param name="getAdCredentials"></param>
        public CreatePoolAction(Host master, List <Host> slaves, string name, string description, Func <Host, AdUserAndPassword> getAdCredentials,
                                Func <HostAbstractAction, Pool, long, long, bool> acceptNTolChanges, Action <List <LicenseFailure>, string> doOnLicensingFailure)
            : base(master.Connection, string.Format(Messages.CREATING_NAMED_POOL_WITH_MASTER, name, master.Name),
                   getAdCredentials, acceptNTolChanges, doOnLicensingFailure)
        {
            System.Diagnostics.Trace.Assert(master != null);

            this.Host           = master;
            this._slaves        = slaves;
            _hostsToRelicense   = slaves.FindAll(h => PoolJoinRules.FreeHostPaidMaster(h, master, false));
            _hostsToCpuMask     = slaves.FindAll(h => !PoolJoinRules.CompatibleCPUs(h, master, false));
            _hostsToAdConfigure = slaves.FindAll(h => !PoolJoinRules.CompatibleAdConfig(h, master, false));
            this._name          = name;
            this._description   = description;
            this.Description    = Messages.WAITING;
            SetRBACPermissions();
        }
Example #3
0
        public AddHostToPoolAction(Pool poolToJoin, Host joiningHost, Func <Host, AdUserAndPassword> getAdCredentials,
                                   Func <HostAbstractAction, Pool, long, long, bool> acceptNTolChanges, Action <List <LicenseFailure>, string> doOnLicensingFailure)
            : base(joiningHost.Connection, string.Format(Messages.ADDING_SERVER_TO_POOL, joiningHost.Name, poolToJoin.Name),
                   getAdCredentials, acceptNTolChanges, doOnLicensingFailure)
        {
            this.Pool = poolToJoin;
            this.Host = joiningHost;
            Host master = Helpers.GetMaster(poolToJoin);

            _hostsToRelicense   = new List <Host>();
            _hostsToCpuMask     = new List <Host>();
            _hostsToAdConfigure = new List <Host>();
            if (PoolJoinRules.FreeHostPaidMaster(joiningHost, master, false))
            {
                _hostsToRelicense.Add(joiningHost);
            }
            if (!PoolJoinRules.CompatibleCPUs(joiningHost, master, false))
            {
                _hostsToCpuMask.Add(joiningHost);
            }
            if (!PoolJoinRules.CompatibleAdConfig(joiningHost, master, false))
            {
                _hostsToAdConfigure.Add(joiningHost);
            }
            this.Description = Messages.WAITING;
            AddCommonAPIMethodsToRoleCheck();
            // SaveChanges in the ClearNonSharedSrs
            ApiMethodsToRoleCheck.Add("pool.set_name_label");
            ApiMethodsToRoleCheck.Add("pool.set_name_description");
            ApiMethodsToRoleCheck.Add("pool.set_other_config");
            ApiMethodsToRoleCheck.Add("pool.add_to_other_config");
            ApiMethodsToRoleCheck.Add("pool.set_gui_config");
            ApiMethodsToRoleCheck.Add("pool.add_to_gui_config");
            ApiMethodsToRoleCheck.Add("pool.set_default_SR");
            ApiMethodsToRoleCheck.Add("pool.set_suspend_image_SR");
            ApiMethodsToRoleCheck.Add("pool.set_crash_dump_SR");
            ApiMethodsToRoleCheck.Add("pool.remove_from_other_config");
            ApiMethodsToRoleCheck.Add("pool.remove_tags");
            ApiMethodsToRoleCheck.Add("pool.set_wlb_enabled");
            ApiMethodsToRoleCheck.Add("pool.set_wlb_verify_cert");

            ApiMethodsToRoleCheck.Add("pool.join");
        }
        protected override void ExecuteCore(SelectedItemCollection selection)
        {
            Dictionary <SelectedItem, string> reasons = new Dictionary <SelectedItem, string>();

            foreach (Host host in _hosts)
            {
                PoolJoinRules.Reason reason = PoolJoinRules.CanJoinPool(host.Connection, _pool.Connection, true, true, true);
                if (reason != PoolJoinRules.Reason.Allowed)
                {
                    reasons[new SelectedItem(host)] = PoolJoinRules.ReasonMessage(reason);
                }
            }

            if (reasons.Count > 0)
            {
                string title = Messages.ERROR_DIALOG_ADD_TO_POOL_TITLE;
                string text  = string.Format(Messages.ERROR_DIALOG_ADD_TO_POOL_TEXT, Helpers.GetName(_pool).Ellipsise(500));

                new CommandErrorDialog(title, text, reasons).ShowDialog(Parent);
                return;
            }

            if (_confirm && !ShowConfirmationDialog())
            {
                // Bail out if the user doesn't want to continue.
                return;
            }

            if (!Helpers.IsConnected(_pool))
            {
                string message = _hosts.Count == 1
                                     ? string.Format(Messages.ADD_HOST_TO_POOL_DISCONNECTED_POOL,
                                                     Helpers.GetName(_hosts[0]).Ellipsise(500), Helpers.GetName(_pool).Ellipsise(500))
                                     : string.Format(Messages.ADD_HOST_TO_POOL_DISCONNECTED_POOL_MULTIPLE,
                                                     Helpers.GetName(_pool).Ellipsise(500));

                new ThreeButtonDialog(
                    new ThreeButtonDialog.Details(SystemIcons.Error, message, Messages.XENCENTER)).ShowDialog(Parent);
                return;
            }

            // Check supp packs and warn
            List <string> badSuppPacks = PoolJoinRules.HomogeneousSuppPacksDiffering(_hosts, _pool);

            if (!HelpersGUI.GetPermissionFor(badSuppPacks, sp => true,
                                             Messages.ADD_HOST_TO_POOL_SUPP_PACK, Messages.ADD_HOST_TO_POOL_SUPP_PACKS, false, "PoolJoinSuppPacks"))
            {
                return;
            }

            // Are there any hosts which are forbidden from masking their CPUs for licensing reasons?
            // If so, we need to show upsell.
            Host master = Helpers.GetMaster(_pool);

            if (null != _hosts.Find(host =>
                                    !PoolJoinRules.CompatibleCPUs(host, master, false) &&
                                    Helpers.FeatureForbidden(host, Host.RestrictCpuMasking) &&
                                    !PoolJoinRules.FreeHostPaidMaster(host, master, false))) // in this case we can upgrade the license and then mask the CPU
            {
                UpsellDialog dlg = new UpsellDialog(HiddenFeatures.LinkLabelHidden ? Messages.UPSELL_BLURB_CPUMASKING : Messages.UPSELL_BLURB_CPUMASKING + Messages.UPSELL_BLURB_CPUMASKING_MORE,
                                                    InvisibleMessages.UPSELL_LEARNMOREURL_CPUMASKING);
                dlg.ShowDialog(Parent);
                return;
            }

            // Get permission for any fix-ups: 1) Licensing free hosts; 2) CPU masking 3) Ad configuration 4) CPU feature levelling (Dundee or higher only)
            // (We already know that these things are fixable because we have been through CanJoinPool() above).
            if (!HelpersGUI.GetPermissionFor(_hosts, host => PoolJoinRules.FreeHostPaidMaster(host, master, false),
                                             Messages.ADD_HOST_TO_POOL_LICENSE_MESSAGE, Messages.ADD_HOST_TO_POOL_LICENSE_MESSAGE_MULTIPLE, true, "PoolJoinRelicensing")
                ||
                !HelpersGUI.GetPermissionFor(_hosts, host => !PoolJoinRules.CompatibleCPUs(host, master, false),
                                             Messages.ADD_HOST_TO_POOL_CPU_MASKING_MESSAGE, Messages.ADD_HOST_TO_POOL_CPU_MASKING_MESSAGE_MULTIPLE, true, "PoolJoinCpuMasking")
                ||
                !HelpersGUI.GetPermissionFor(_hosts, host => !PoolJoinRules.CompatibleAdConfig(host, master, false),
                                             Messages.ADD_HOST_TO_POOL_AD_MESSAGE, Messages.ADD_HOST_TO_POOL_AD_MESSAGE_MULTIPLE, true, "PoolJoinAdConfiguring")
                ||
                !HelpersGUI.GetPermissionForCpuFeatureLevelling(_hosts, _pool))
            {
                return;
            }

            MainWindowCommandInterface.SelectObjectInTree(_pool);

            List <AsyncAction> actions = new List <AsyncAction>();

            foreach (Host host in _hosts)
            {
                string opaque_ref          = host.opaque_ref;
                AddHostToPoolAction action = new AddHostToPoolAction(_pool, host, GetAdPrompt, NtolDialog, ApplyLicenseEditionCommand.ShowLicensingFailureDialog);
                action.Completed += s => Program.ShowObject(opaque_ref);
                actions.Add(action);

                // hide connection. If the action fails, re-show it.
                Program.HideObject(opaque_ref);
            }

            RunMultipleActions(actions, string.Format(Messages.ADDING_SERVERS_TO_POOL, _pool.Name), Messages.POOLCREATE_ADDING, Messages.POOLCREATE_ADDED, true);
        }