Beispiel #1
0
 /// <summary>
 /// Attempts to set the LastPowerOnSucceeded flag in the WLB Host configuration
 /// </summary>
 private void UpdateHostLastPowerOnSucceeded(bool succeeded, XenAPI.Host host)
 {
     try
     {
         //Helpers.SetOtherConfig(this.Host.Connection.Session, this.Host, "LastPowerOnsucceeded", successful.ToString());
         WlbHostConfiguration hostConfig = new WlbHostConfiguration(host.uuid);
         hostConfig.LastPowerOnSucceeded = succeeded;
         if (!succeeded)
         {
             hostConfig.ParticipatesInPowerManagement = false;
         }
         XenAPI.Pool pool = Helpers.GetPoolOfOne(host.Connection);
         if (null != pool)
         {
             SendWlbConfigurationAction action = new SendWlbConfigurationAction(pool, hostConfig.ToDictionary(), SendWlbConfigurationKind.SetHostConfiguration);
             action.RunExternal(Session);
         }
         else
         {
             throw new Failure(Failure.INTERNAL_ERROR, Messages.POOL_GONE);
         }
     }
     catch (Exception ex)
     {
         log.Error("Unable to set the host's LastPowerOnSucceeded status.", ex);
     }
 }
Beispiel #2
0
        private void SaveWLBConfig(WlbPoolConfiguration PoolConfiguration)
        {
            Dictionary <string, string> completeConfiguration = PoolConfiguration.ToDictionary();
            SendWlbConfigurationKind    kind = SendWlbConfigurationKind.SetPoolConfiguration;

            // check for host configurations in the pool configuration
            if (PoolConfiguration.HostConfigurations.Count > 0)
            {
                // add the flag denoting that there are host configs to be saved
                kind |= SendWlbConfigurationKind.SetHostConfiguration;
                // get the key for each host config (host.uuid)
                foreach (string key in PoolConfiguration.HostConfigurations.ToDictionary().Keys)
                {
                    //Drop any exising copy from the pool configuration
                    if (completeConfiguration.ContainsKey(key))
                    {
                        completeConfiguration.Remove(key);
                    }
                    // and add the task to the collection
                    completeConfiguration.Add(key, PoolConfiguration.HostConfigurations.ToDictionary()[key]);
                }
            }

            // check for scheduled tasks in the pool configuration
            if (PoolConfiguration.ScheduledTasks.TaskList.Count > 0)
            {
                // add the flag denoting that there are scheduled tasks to be saved
                kind |= SendWlbConfigurationKind.SetScheduledTask;
                // get the key for each scheduled task
                foreach (string key in PoolConfiguration.ScheduledTasks.ToDictionary().Keys)
                {
                    //Drop any exising copy from the pool configuration
                    if (completeConfiguration.ContainsKey(key))
                    {
                        completeConfiguration.Remove(key);
                    }
                    // and add the task to the collection
                    completeConfiguration.Add(key, PoolConfiguration.ScheduledTasks.ToDictionary()[key]);
                }
            }

            SendWlbConfigurationAction action = new SendWlbConfigurationAction(_pool, PoolConfiguration.ToDictionary(), kind);

            using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Blocks))
            {
                dialog.ShowCancel = true;
                dialog.ShowDialog(this);
            }
            Program.MainWindow.UpdateToolbars();
        }
Beispiel #3
0
        private void DeleteReportSubscription(object sender, EventArgs e)
        {
            SendWlbConfigurationAction action = new SendWlbConfigurationAction(_pool, this._subscription.ToDictionary(), SendWlbConfigurationKind.DeleteReportSubscription);
            ActionProgressDialog       dialog = new ActionProgressDialog(action, ProgressBarStyle.Blocks);

            dialog.ShowCancel = true;
            dialog.ShowDialog(this);

            if (action.Succeeded)
            {
                // Update treeView
                OnChangeOK(this, e);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Finds the WLBAction in progress that pertains to the given connection, or null
        /// if there is no such action.
        /// Must be called on the event thread.
        /// </summary>
        /// <param name="connection">May not be null.</param>
        /// <returns></returns>
        internal static AsyncAction FindActiveWLBAction(IXenConnection connection)
        {
            Program.AssertOnEventThread();
            foreach (ActionBase action in ConnectionsManager.History)
            {
                if (action.IsCompleted)
                {
                    continue;
                }

                InitializeWLBAction configureAction = action as InitializeWLBAction;
                if (configureAction != null && !configureAction.Cancelled && configureAction.Connection == connection)
                {
                    return(configureAction);
                }

                EnableWLBAction enableAction = action as EnableWLBAction;
                if (enableAction != null && !enableAction.Cancelled && enableAction.Connection == connection)
                {
                    return(enableAction);
                }

                DisableWLBAction disableAction = action as DisableWLBAction;
                if (disableAction != null && !disableAction.Cancelled && disableAction.Connection == connection)
                {
                    return(disableAction);
                }

                RetrieveWlbConfigurationAction retrieveAction = action as RetrieveWlbConfigurationAction;
                if (retrieveAction != null && !retrieveAction.Cancelled && retrieveAction.Connection == connection)
                {
                    return(retrieveAction);
                }

                SendWlbConfigurationAction sendAction = action as SendWlbConfigurationAction;
                if (sendAction != null && !sendAction.Cancelled && sendAction.Connection == connection)
                {
                    return(sendAction);
                }
            }
            return(null);
        }
        private void SaveConfig(Host host, Host.PowerOnMode mode)
        {
            var    newMode    = mode.ToString();
            var    config     = mode.Config;
            string secretuuid = "";


            if (newMode == "iLO" && Helpers.StockholmOrGreater(Connection))
            {
                //the UI should have already prevented us from getting here, but be defensive
                newMode = "";
                config  = new Dictionary <string, string>();
            }

            try
            {
                if (newMode == "DRAC" || newMode == "iLO" || newMode != "wake-on-lan" && newMode != "")
                {
                    if (config.ContainsKey("power_on_password_secret"))
                    {
                        secretuuid = Secret.CreateSecret(Session, config["power_on_password_secret"]);
                        config["power_on_password_secret"] = secretuuid;
                    }
                }
                else if (string.IsNullOrEmpty(newMode))
                {
                    //if WLB is on, we need to exclude the host from WLB power management,
                    //since we cannot turn it back on if it is powered down automatically

                    try
                    {
                        Pool pool = Helpers.GetPool(Connection);
                        if (pool != null && WlbServerState.GetState(pool) == WlbServerState.ServerState.Enabled)
                        {
                            var hostConfig = new WlbHostConfiguration(host.uuid)
                            {
                                ParticipatesInPowerManagement = false
                            };

                            var wlbAction = new SendWlbConfigurationAction(pool, hostConfig.ToDictionary(),
                                                                           SendWlbConfigurationKind.SetHostConfiguration);
                            wlbAction.RunExternal(Session);
                        }
                    }
                    catch
                    {
                        //Do nothing on failure.
                    }
                }

                Host.set_power_on_mode(Session, host.opaque_ref, newMode, config);
            }
            catch
            {
                if (!string.IsNullOrEmpty(secretuuid))
                {
                    string secretRef = Secret.get_by_uuid(Session, secretuuid);
                    Secret.destroy(Session, secretRef);
                }

                throw;
            }
        }
        private void SaveSubscription()
        {
            if (this._subscription == null)
            {
                _subscription = new WlbReportSubscription(String.Empty);
                _subscription.SubscriberName = GetLoggedInAsText();
                _subscription.Created        = DateTime.UtcNow;
            }
            _subscription.Name        = this.subNameTextBox.Text;
            _subscription.Description = this.subNameTextBox.Text;

            DateTime utcExecuteTime;

            WlbScheduledTask.WlbTaskDaysOfWeek utcDaysOfWeek;
            WlbScheduledTask.GetUTCTaskTimes((WlbScheduledTask.WlbTaskDaysOfWeek) this.schedDeliverComboBox.SelectedValue, this.dateTimePickerSubscriptionRunTime.Value, out utcDaysOfWeek, out utcExecuteTime);
            _subscription.ExecuteTimeOfDay = utcExecuteTime;
            _subscription.DaysOfWeek       = utcDaysOfWeek;
            if (_subscription.DaysOfWeek != WlbScheduledTask.WlbTaskDaysOfWeek.All)
            {
                _subscription.TriggerType = (int)WlbScheduledTask.WlbTaskTriggerType.Weekly;
            }
            else
            {
                _subscription.TriggerType = (int)WlbScheduledTask.WlbTaskTriggerType.Daily;
            }
            _subscription.Enabled       = true;
            _subscription.EnableDate    = this.dateTimePickerSchedStart.Value == DateTime.MinValue ? DateTime.UtcNow : this.dateTimePickerSchedStart.Value.ToUniversalTime();
            _subscription.DisableDate   = this.dateTimePickerSchedEnd.Value == DateTime.MinValue ? DateTime.UtcNow.AddMonths(1) : this.dateTimePickerSchedEnd.Value.ToUniversalTime();
            _subscription.LastTouched   = DateTime.UtcNow;
            _subscription.LastTouchedBy = GetLoggedInAsText();

            // store email info
            _subscription.EmailTo      = this.emailToTextBox.Text.Trim();
            _subscription.EmailCc      = this.emailCcTextBox.Text.Trim();
            _subscription.EmailBcc     = this.emailBccTextBox.Text.Trim();
            _subscription.EmailReplyTo = this.emailReplyTextBox.Text.Trim();
            _subscription.EmailSubject = this.emailSubjectTextBox.Text.Trim();
            _subscription.EmailComment = this.emailCommentRichTextBox.Text;

            // store reoprt Info
            //sub.ReportId = ;
            _subscription.ReportRenderFormat = this.rpRenderComboBox.SelectedIndex;
            Dictionary <string, string> rps = new Dictionary <string, string>();

            foreach (string key in this._rpParams.Keys)
            {
                if (String.Compare(key, WlbReportSubscription.REPORT_NAME, true) == 0)
                {
                    _subscription.ReportName = this._rpParams[WlbReportSubscription.REPORT_NAME];
                }
                else
                {
                    //Get start date range
                    if (String.Compare(key, "start", true) == 0)
                    {
                        rps.Add(key, ((this.rpParamComboBox.SelectedIndex + 1) * (-7) + 1).ToString());
                    }
                    else
                    {
                        rps.Add(key, _rpParams[key]);
                    }
                }
            }
            _subscription.ReportParameters = rps;

            SendWlbConfigurationAction action = new SendWlbConfigurationAction(this._pool, _subscription.ToDictionary(), SendWlbConfigurationKind.SetReportSubscription);

            using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Blocks))
            {
                dialog.ShowCancel = true;
                dialog.ShowDialog(this);
            }

            if (action.Succeeded)
            {
                DialogResult = DialogResult.OK;
                this.Close();
            }
            else if (!action.Cancelled)
            {
                using (var dlg = new ThreeButtonDialog(
                           new ThreeButtonDialog.Details(
                               SystemIcons.Error,
                               String.Format(Messages.WLB_SUBSCRIPTION_ERROR, _subscription.Description),
                               Messages.XENCENTER)))
                {
                    dlg.ShowDialog(this);
                }
                //log.ErrorFormat("There was an error calling SendWlbConfigurationAction to SetReportSubscription {0}, Action Result: {1}.", _subscription.Description, action.Result);
                DialogResult = DialogResult.None;
            }
        }
Beispiel #7
0
        protected void SaveConfig(Host host)
        {
            string secretuuid = "";

            try
            {
                Dictionary <string, string> powerONConfig = new Dictionary <string, string>();
                if (newMode == "DRAC" || newMode == "iLO")
                {
                    powerONConfig.Add("power_on_ip", ip);
                    powerONConfig.Add("power_on_user", user);
                    secretuuid = Secret.CreateSecret(Session, password);
                    powerONConfig.Add("power_on_password_secret", secretuuid);
                }
                else if (newMode != "wake-on-lan" && newMode != "")
                {
                    foreach (KeyValuePair <string, string> pair in customConfig)
                    {
                        if (pair.Key == "power_on_password_secret")
                        {
                            secretuuid = Secret.CreateSecret(Session, pair.Value);
                            powerONConfig.Add(pair.Key, secretuuid);
                        }
                        else
                        {
                            powerONConfig.Add(pair.Key, pair.Value);
                        }
                    }
                }
                else if (string.IsNullOrEmpty(newMode))
                {
                    // We don't want this bit to alter the function of the main action so...
                    try
                    {
                        Pool pool = Core.Helpers.GetPool(this.Connection);
                        if (null != pool)
                        {
                            if (WlbServerState.GetState(pool) == XenAdmin.Wlb.WlbServerState.ServerState.Enabled)
                            {
                                //Tell WLB to not allow this host to be powered down automatically, since we cannot turn it back on
                                WlbHostConfiguration hostConfig = new WlbHostConfiguration(host.uuid);
                                hostConfig.ParticipatesInPowerManagement = false;
                                //Use the existing SendWlbConfig action, as it wraps the config functionality
                                //  as well as the RBAC checks.
                                SendWlbConfigurationAction wlbAction = new SendWlbConfigurationAction(pool,
                                                                                                      hostConfig.ToDictionary(),
                                                                                                      SendWlbConfigurationKind.SetHostConfiguration);
                                wlbAction.RunExternal(Session);
                            }
                        }
                    }

                    catch (Exception)
                    {
                        //Do nothing on failure.
                    }
                }

                Host.set_power_on_mode(Session, host.opaque_ref, newMode, powerONConfig);
            }
            catch (Exception e)
            {
                if (!string.IsNullOrEmpty(secretuuid))
                {
                    string secretRef = Secret.get_by_uuid(Session, secretuuid);
                    Secret.destroy(Session, secretRef);
                }
                throw e;
            }
        }