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); ActionProgressDialog dialog = new ActionProgressDialog(action, ProgressBarStyle.Blocks); dialog.ShowCancel = true; dialog.ShowDialog(this); Program.MainWindow.UpdateToolbars(); }
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; } }
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); } }
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; } }
/// <summary> /// Attempts to set the LastPowerOnSucceeded flag in the WLB Host configuration /// </summary> /// <param name="successful">bool </param> 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 Exception("Could not find host's pool."); } } catch (Exception ex) { log.Error("Unable to set the host's LastPowerOnSucceeded status.", ex); } }