コード例 #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            NewCustomFieldDialog dialog = new NewCustomFieldDialog(connection);
            if (dialog.ShowDialog() != DialogResult.OK)
                return;

            CustomFieldDefinition definition = dialog.Definition;

            DelegatedAsyncAction action = new DelegatedAsyncAction(connection,
                String.Format(Messages.ADD_CUSTOM_FIELD, definition.Name),
                String.Format(Messages.ADDING_CUSTOM_FIELD, definition.Name),
                String.Format(Messages.ADDED_CUSTOM_FIELD, definition.Name),
                delegate(Session session)
                {
                    CustomFieldsManager.AddCustomField(session, connection, definition);
                });
            action.RunAsync();
        }
コード例 #2
0
ファイル: VMOperationCommand.cs プロジェクト: huizh/xenadmin
        /// <summary>
        /// In the case there being nowhere to start/resume the VM (NO_HOSTS_AVAILABLE), shows the reason why the VM could not be started
        /// on each host. If the start failed due to HA_OPERATION_WOULD_BREAK_FAILOVER_PLAN, offers to decrement ntol and try the operation
        /// again.
        /// </summary>
        /// <param name="vm"></param>
        /// <param name="f"></param>
        /// <param name="kind">The kind of the operation that failed. Must be one of Start/StartOn/Resume/ResumeOn.</param>
        public static void StartDiagnosisForm(VMStartAbstractAction VMStartAction , Failure failure)
        {

            if (failure.ErrorDescription[0] == Failure.NO_HOSTS_AVAILABLE)
            {
                // Show a dialog displaying why the VM couldn't be started on each host
                StartDiagnosisForm(VMStartAction.VM);
            }
            else if (failure.ErrorDescription[0] == Failure.HA_OPERATION_WOULD_BREAK_FAILOVER_PLAN)
            {
                // The action was blocked by HA because it would reduce the number of tolerable server failures.
                // With the user's consent, we'll reduce the number of configured failures to tolerate and try again.
                Pool pool = Helpers.GetPool(VMStartAction.VM.Connection);
                if (pool == null)
                {
                    log.ErrorFormat("Could not get pool for VM {0} in StartDiagnosisForm()", Helpers.GetName(VMStartAction.VM));
                    return;
                }

                long ntol = pool.ha_host_failures_to_tolerate;
                long newNtol = Math.Min(pool.ha_plan_exists_for - 1, ntol - 1);
                if (newNtol <= 0)
                {
                    // We would need to basically turn HA off to start this VM
                    string msg = String.Format(VMStartAction.IsStart ? Messages.HA_VM_START_NTOL_ZERO : Messages.HA_VM_RESUME_NTOL_ZERO,
                        Helpers.GetName(pool).Ellipsise(100),
                        Helpers.GetName(VMStartAction.VM).Ellipsise(100));
                    Program.Invoke(Program.MainWindow, delegate()
                    {
                        new ThreeButtonDialog(new ThreeButtonDialog.Details(SystemIcons.Warning, msg, Messages.HIGH_AVAILABILITY)).ShowDialog(Program.MainWindow);
                    });
                }
                else
                {
                    // Show 'reduce ntol?' dialog
                    string msg = String.Format(VMStartAction.IsStart ? Messages.HA_VM_START_NTOL_DROP : Messages.HA_VM_RESUME_NTOL_DROP,
                        Helpers.GetName(pool).Ellipsise(100), ntol,
                        Helpers.GetName(VMStartAction.VM).Ellipsise(100), newNtol);

                    Program.Invoke(Program.MainWindow, delegate()
                    {
                        DialogResult r = new ThreeButtonDialog(
                            new ThreeButtonDialog.Details(SystemIcons.Warning, msg, Messages.HIGH_AVAILABILITY),
                            ThreeButtonDialog.ButtonYes,
                            new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true)).ShowDialog(Program.MainWindow);

                        if (r == DialogResult.Yes)
                        {
                            DelegatedAsyncAction action = new DelegatedAsyncAction(VMStartAction.VM.Connection, Messages.HA_LOWERING_NTOL, null, null,
                                delegate(Session session)
                                {
                                    // Set new ntol, then retry action
                                    XenAPI.Pool.set_ha_host_failures_to_tolerate(session, pool.opaque_ref, newNtol);
                                    // ntol set succeeded, start new action
                                    VMStartAction.Clone().RunAsync();
                                });
                            action.RunAsync();
                        }
                    });
                }
            }
        }
コード例 #3
0
        private void CheckXenServerCredentials()
        {
            if (string.IsNullOrEmpty(textboxXSUserName.Text.Trim()) || string.IsNullOrEmpty(textboxXSPassword.Text))
                return;

            bool passedRbacChecks = false;
            DelegatedAsyncAction action = new DelegatedAsyncAction(connection,
                Messages.CREDENTIALS_CHECKING, "", "", 
                delegate
                {
                    Session elevatedSession = null;
                    try
                    {
                        elevatedSession = connection.ElevatedSession(textboxXSUserName.Text.Trim(), textboxXSPassword.Text);
                        if (elevatedSession != null && (elevatedSession.IsLocalSuperuser || SessionAuthorized(elevatedSession, Role.ValidRoleList("pool.set_health_check_config", connection))))
                            passedRbacChecks = true;
                    }
                    catch (Failure f)
                    {
                        if (f.ErrorDescription.Count > 0 && f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED)
                        {
                            // we use a different error message here from the standard one in friendly names
                            throw new Exception(Messages.HEALTH_CHECK_USER_HAS_NO_PERMISSION_TO_CONNECT);
                        }
                        throw;
                    }
                    finally
                    {
                        if (elevatedSession != null)
                        {
                            elevatedSession.Connection.Logout(elevatedSession);
                            elevatedSession = null;
                        }
                    }
                },
                true);

            action.Completed += delegate
            {
                log.DebugFormat("Logging with the new credentials returned: {0} ", passedRbacChecks);
                Program.Invoke(Program.MainWindow, () =>
                {
                    if (passedRbacChecks)
                        ShowTestCredentialsStatus(Resources._000_Tick_h32bit_16, null);
                    else
                        ShowTestCredentialsStatus(Resources._000_error_h32bit_16, action.Exception != null ? action.Exception.Message : Messages.HEALTH_CHECK_USER_NOT_AUTHORIZED);
                    textboxXSUserName.Enabled = textboxXSPassword.Enabled = testCredentialsButton.Enabled = newXsCredentialsRadioButton.Checked;
                });
            };

            log.Debug("Testing logging in with the new credentials");
            ShowTestCredentialsStatus(Resources.ajax_loader, null);
            textboxXSUserName.Enabled = textboxXSPassword.Enabled = testCredentialsButton.Enabled = false;
            action.RunAsync();
        }
コード例 #4
0
ファイル: AdPage.cs プロジェクト: robhoes/xenadmin
        private void ButtonLogout_Click(object sender, EventArgs e)
        {
            Program.AssertOnEventThread();
            // Double check, this method is called from a context menu as well and the state could have changed under it
            if (!ButtonLogout.Enabled)
                return;

            Session session = pool.Connection.Session;
            if (session == null)
                return;

            // First we check through the list to check what warning message we show
            List<Subject> subjectsToLogout = new List<Subject>();
            foreach (AdSubjectRow r in GridViewSubjectList.SelectedRows)
            {
                if (r.IsLocalRootRow || !r.LoggedIn)
                    continue;

                subjectsToLogout.Add(r.subject);
            }

            bool suicide = false;
            // Warn if user is logging themselves out
            if (session.Subject != null)//have already checked session not null
            {
                var warnMsg = string.Format(subjectsToLogout.Count > 1 ? Messages.AD_LOGOUT_SUICIDE_MANY : Messages.AD_LOGOUT_SUICIDE_ONE,
                                            Helpers.GetName(pool).Ellipsise(50));

                foreach (Subject entry in subjectsToLogout)
                {
                    if (entry.opaque_ref == session.Subject)
                    {
                        DialogResult r = new ThreeButtonDialog(
                            new ThreeButtonDialog.Details(
                                SystemIcons.Warning,
                                warnMsg,
                                Messages.AD_FEATURE_NAME),
                            ThreeButtonDialog.ButtonYes,
                            new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true)).ShowDialog(this);

                        //CA-64818: DialogResult can be No if the No button has been hit
                        //or Cancel if the dialog has been closed from the control box
                        if (r != DialogResult.Yes)
                            return;

                        suicide = true;
                        break;
                    }
                }
            }

            var logoutMessage = subjectsToLogout.Count == 1
                ? string.Format(Messages.QUESTION_LOGOUT_AD_USER_ONE, subjectsToLogout[0].DisplayName ?? subjectsToLogout[0].SubjectName)
                : string.Format(Messages.QUESTION_LOGOUT_AD_USER_MANY, subjectsToLogout.Count);

            if (!suicide)//CA-68645
            {
                DialogResult questionDialog = new ThreeButtonDialog(
                new ThreeButtonDialog.Details(
                    SystemIcons.Warning,
                    logoutMessage,
                    Messages.AD_FEATURE_NAME),
                ThreeButtonDialog.ButtonYes,
                new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true)).ShowDialog(this);

                //CA-64818: DialogResult can be No if the No button has been hit
                //or Cancel if the dialog has been closed from the control box
                if (questionDialog != DialogResult.Yes)
                    return;
            }

            // Then we go through the list and disconnect each user session, doing our own last if necessary
            foreach (AdSubjectRow r in GridViewSubjectList.SelectedRows)
            {
                // check they are not the root row and are logged in
                if (r.IsLocalRootRow || !r.LoggedIn)
                    continue;

                // we suicide last
                if (session.UserSid == r.subject.subject_identifier)
                {
                    continue;
                }
                DelegatedAsyncAction logoutAction = new DelegatedAsyncAction(pool.Connection, Messages.TERMINATING_SESSIONS, Messages.IN_PROGRESS, Messages.COMPLETED, delegate(Session s)
                    {
                        Session.logout_subject_identifier(s, r.subject.subject_identifier);
                    }, "session.logout_subject_identifier");
                logoutAction.RunAsync();
            }
            if (suicide)
            {
                //bye bye
                DelegatedAsyncAction logoutAction = new DelegatedAsyncAction(pool.Connection, Messages.TERMINATING_SESSIONS, Messages.IN_PROGRESS, Messages.COMPLETED, delegate(Session s)
                    {
                        Session.logout_subject_identifier(s, session.UserSid);
                        pool.Connection.Logout();
                    }, "session.logout_subject_identifier");
                logoutAction.RunAsync();
            }
            else
            {
                // signal the background thread to update the logged in status
                lock (statusUpdaterLock)
                    Monitor.Pulse(statusUpdaterLock);
            }
        }
コード例 #5
0
        protected override void ExecuteCore(SelectedItemCollection selection)
        {
            var vdi = (VDI)selection[0].XenObject;
            string svid = vdi.sm_config["SVID"];
            var storageLinkVolume = vdi.StorageLinkVolume(Program.StorageLinkConnections.GetCopy());
            string volumeName = storageLinkVolume==null? "":storageLinkVolume.Name;

            var action = new DelegatedAsyncAction(
                vdi.Connection,
                string.Format(Messages.REMOVE_STORAGELINK_VOLUME_ACTION_TITLE, volumeName, _slr),
                string.Format(Messages.REMOVE_STORAGELINK_VOLUME_ACTION_START, volumeName, _slr),
                string.Format(Messages.REMOVE_STORAGELINK_VOLUME_ACTION_FINSH, volumeName, _slr), 
                s => _slr.StorageLinkConnection.RemoveStorageVolumesFromStorageRepository(_slr, new[] { svid }));
            
            action.AppliesTo.Add(vdi.opaque_ref);
            action.AppliesTo.Add(svid);
            action.AppliesTo.Add(_slr.opaque_ref);

            SR sr = _slr.SR(ConnectionsManager.XenConnectionsCopy);

            if(sr != null)
            {
                action.AppliesTo.Add(sr.opaque_ref);
            }

            action.RunAsync();
        }
コード例 #6
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            CustomFieldDefinition customFieldDefinition = lbCustomFields.SelectedItem as CustomFieldDefinition;
            if (customFieldDefinition == null)
                return;

            string name = customFieldDefinition.Name.Ellipsise(50);

            if (!MainWindow.Confirm(connection, Program.MainWindow, Messages.MESSAGEBOX_CONFIRM, Messages.MESSAGEBOX_DELETE_CUSTOM_FIELD, name))
                return;

            Program.MainWindow.AllowHistorySwitch = true;

            int selIdx = lbCustomFields.SelectedIndex;

            lbCustomFields.Items.RemoveAt(selIdx);
            DelegatedAsyncAction action = new DelegatedAsyncAction(connection,
                String.Format(Messages.DELETE_CUSTOM_FIELD, name),
                String.Format(Messages.DELETING_CUSTOM_FIELD, name),
                String.Format(Messages.DELETED_CUSTOM_FIELD, name),
                delegate(Session session)
                {
                    CustomFieldsManager.RemoveCustomField(session, connection, customFieldDefinition);
                });
            action.RunAsync();
        }
コード例 #7
0
ファイル: NewTagDialog.cs プロジェクト: huizh/xenadmin
        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (tagsListView.SelectedItems.Count == 1)
            {
                string tag = tagsListView.SelectedItems[0].Text;

                ThreeButtonDialog tbd = new ThreeButtonDialog(
                    new ThreeButtonDialog.Details(SystemIcons.Warning, String.Format(Messages.CONFIRM_DELETE_TAG, tag), Messages.CONFIRM_DELETE_TAG_TITLE),
                    new ThreeButtonDialog.TBDButton(Messages.OK, DialogResult.OK),
                    ThreeButtonDialog.ButtonCancel);
                    
                DialogResult result = tbd.ShowDialog(this);
                if (result != DialogResult.OK)
                    return;

                // Remove the tag from the tagsListView
                tagsListView.Items.Remove(tagsListView.SelectedItems[0]);
                setButtonEnablement();

                // Delete the tag from all resources on all servers
                DelegatedAsyncAction action = new DelegatedAsyncAction(null,
                    String.Format(Messages.DELETE_ALL_TAG, tag),
                    String.Format(Messages.DELETING_ALL_TAG, tag),
                    String.Format(Messages.DELETED_ALL_TAG, tag),
                    delegate(Session session)
                    {
                        Tags.RemoveTagGlobally(tag);
                    });
                action.RunAsync();
            }
        }
コード例 #8
0
ファイル: NewTagDialog.cs プロジェクト: huizh/xenadmin
        private void tagsListView_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            okButton.Enabled = true;

            TagsListViewItem itemRenaming = (TagsListViewItem)tagsListView.Items[e.Item];
            if (itemRenaming != null)
            {
                string oldName = itemRenaming.Text;
                string newName = (e.Label == null ? oldName : e.Label.Trim());   // null indicates no change

                if (newName == "")
                {
                    e.CancelEdit = true;
                    return;
                }

                foreach (TagsListViewItem currentItem in tagsListView.Items)
                {
                    if (currentItem != itemRenaming && currentItem.Text == newName)
                    {
                        e.CancelEdit = true;
                        return;
                    }
                }

                // Rename the tag in the list view ourselves (necessary if we've trimmed whitespace from the ends of the name)
                itemRenaming.Text = newName;
                e.CancelEdit = true;

                // Rename the tag on all the servers
                DelegatedAsyncAction action = new DelegatedAsyncAction(null,
                    String.Format(Messages.RENAME_TAG, oldName),
                    String.Format(Messages.RENAMING_TAG, oldName),
                    String.Format(Messages.RENAMED_TAG, oldName),
                    delegate(Session session)
                    {
                        Tags.RenameTagGlobally(oldName, newName);
                    });
                action.RunAsync();
            }
        }
コード例 #9
0
 protected override void ExecuteCore(SelectedItemCollection selection)
 {
     DelegatedAsyncAction action = new DelegatedAsyncAction(null,
         String.Format(Messages.RENAME_TAG, _oldName),
         String.Format(Messages.RENAMING_TAG, _oldName),
         String.Format(Messages.RENAMED_TAG, _oldName),
         delegate(Session session)
         {
             Tags.RenameTagGlobally(_oldName, _newName.Trim());
         });
     action.Completed += action_Completed;
     action.RunAsync();
 }
コード例 #10
0
        protected override void ExecuteCore(SelectedItemCollection selection)
        {
            var connections = new List<StorageLinkConnection>();

            foreach (IStorageLinkObject s in selection.AsXenObjects<IStorageLinkObject>())
            {
                if (!connections.Contains(s.StorageLinkConnection))
                {
                    connections.Add(s.StorageLinkConnection);
                }
            }

            foreach (StorageLinkConnection c in connections)
            {
                string title = string.Format(Messages.REFRESH_STORAGELINK_SYSTEMS_ACTION_TITLE, c.Host);
                string startDes = Messages.REFRESH_STORAGELINK_SYSTEMS_ACTION_START;
                string endDes = Messages.REFRESH_STORAGELINK_SYSTEMS_ACTION_END;

                var action = new DelegatedAsyncAction(null, title, startDes, endDes, s =>
                    {
                        c.Refresh();

                        // wait for refresh to finish so the user can see that
                        // the refresh is still in progress in the logs tab.
                        for (int i = 0; i < 60 && c.RefreshInProgress; i++)
                        {
                            Thread.Sleep(500);
                        }
                    });


                foreach (IStorageLinkObject s in selection.AsXenObjects<IStorageLinkObject>())
                {
                    if (s.StorageLinkConnection == c)
                    {
                        action.AppliesTo.Add(s.opaque_ref);
                    }
                }

                action.RunAsync();
            }
        }
コード例 #11
0
        protected override void ExecuteCore(SelectedItemCollection selection)
        {
            StorageLinkRepository slr = selection[0].XenObject as StorageLinkRepository;

            if (slr == null)
            {
                var sr = selection[0].XenObject as SR;
                slr = sr != null ? sr.StorageLinkRepository(Program.StorageLinkConnections) : null;
            }

            if (slr != null)
            {
                var dialog = new ImportStorageLinkVolumeDialog(slr);

                dialog.FormClosing += (s, e) =>
                    {
                        if (dialog.DialogResult == DialogResult.OK)
                        {
                            var volumes = dialog.Volumes;
                            if (volumes.Count > 0)
                            {
                                var action = new DelegatedAsyncAction(null,
                                    string.Format(Messages.IMPORT_STORAGELINK_VOLUME_ACTION_TITLE, slr), 
                                    string.Format(Messages.IMPORT_STORAGELINK_VOLUME_ACTION_START, slr),
                                    string.Format(Messages.IMPORT_STORAGELINK_VOLUME_ACTION_FINSH, slr), 
                                    session => slr.StorageLinkConnection.AddStorageVolumesToStorageRepository(slr, volumes));
                                
                                action.AppliesTo.Add(slr.opaque_ref);
                                action.AppliesTo.Add(slr.StorageLinkConnection.Cache.Server.opaque_ref);
                                action.RunAsync();
                            }
                        }
                    };

                dialog.Show(Parent);
            }
        }