Ejemplo n.º 1
0
        /// <summary>
        /// User has clicked the detach button. Unplug the VBD, then destroy it.
        /// </summary>
        private void DetachButton_Click(object sender, EventArgs e)
        {
            List<VBDRow> rows = SelectedVBDRows;
            if (rows == null)
                return;
            List<SelectedItem> l = new List<SelectedItem>();
            foreach (VBDRow r in rows)
                l.Add(new SelectedItem(r.VDI));

            DetachVirtualDiskCommand cmd = new DetachVirtualDiskCommand(Program.MainWindow, l, vm);
            if (cmd.CanExecute())
                cmd.Execute();
        }
Ejemplo n.º 2
0
        private void UpdateButtons()
        {
            AttachVirtualDiskCommand attachCmd = new AttachVirtualDiskCommand(Program.MainWindow, vm);
            AttachButton.Enabled = attachCmd.CanExecute();
            AddButton.Enabled = attachCmd.CanExecute();

            List<VBDRow> vbdRows = SelectedVBDRows;

            if (dataGridViewStorage.Rows.Count == 0 || vbdRows == null || vm == null)
            {
                DeactivateButton.Enabled = false;
                DetachDriveButton.Enabled = false;
                DeleteDriveButton.Enabled = false;
                EditButton.Enabled = false;
                MoveButton.Enabled = false;
                return;
            }
            EditButton.Enabled = vbdRows.Count == 1 && !vbdRows[0].VBD.Locked && !vbdRows[0].VDI.Locked;

            List<SelectedItem> selectedVDIs = new List<SelectedItem>();
            List<SelectedItem> selectedVBDs = new List<SelectedItem>();

            foreach (VBDRow r in vbdRows)
            {
                selectedVDIs.Add(new SelectedItem(r.VDI));
                selectedVBDs.Add(new SelectedItem(r.VBD));
            }
            DeleteVirtualDiskCommand deleteCmd = new DeleteVirtualDiskCommand(Program.MainWindow, selectedVDIs);
            // User has visibility that this disk in use by this VM. Allow unplug + delete in single step (non default behaviour),
            // but only if we are the only VBD (default behaviour)
            deleteCmd.AllowRunningVMDelete = true;
            if (deleteCmd.CanExecute())
            {
                DeleteButtonContainer.RemoveAll();
                DeleteDriveButton.Enabled = true;
            }
            else
            {
                DeleteButtonContainer.SetToolTip(deleteCmd.ToolTipText);
                DeleteDriveButton.Enabled = false;
            }

            Command activationCmd = null;

            SelectedItemCollection vbdCol = new SelectedItemCollection(selectedVBDs);
            if (vbdCol.AsXenObjects<VBD>().Find(delegate(VBD vbd) { return !vbd.currently_attached; }) == null)
            {
                // no VBDs are attached so we are deactivating
                DeactivateButton.Text = Messages.DEACTIVATE;
                activationCmd = new DeactivateVBDCommand(Program.MainWindow, selectedVBDs);
            }
            else
            {
                // this is the default cause in the mixed attached/detatched scenario. We try to activate all the selection
                // The command error reports afterwards about the ones which are already attached
                DeactivateButton.Text = Messages.ACTIVATE;
                activationCmd = new ActivateVBDCommand(Program.MainWindow, selectedVBDs);
            }

            if (activationCmd.CanExecute())
            {
                DeactivateButtonContainer.RemoveAll();
                DeactivateButton.Enabled = true;
            }
            else
            {
                DeactivateButtonContainer.SetToolTip(activationCmd.ToolTipText);
                DeactivateButton.Enabled = false;
            }

            DetachVirtualDiskCommand detachCmd = new DetachVirtualDiskCommand(Program.MainWindow, selectedVDIs, vm);
            if (detachCmd.CanExecute())
            {
                DetachButtonContainer.RemoveAll();
                DetachDriveButton.Enabled = true;
            }
            else
            {
                DetachButtonContainer.SetToolTip(detachCmd.ToolTipText);
                DetachDriveButton.Enabled = false;
            }

            // Move button
            Command moveCmd = MoveMigrateCommand(selectedVDIs);
            if (moveCmd.CanExecute())
            {
                MoveButton.Enabled = true;
                MoveButtonContainer.RemoveAll();
            }
            else
            {
                MoveButton.Enabled = false;
                MoveButtonContainer.SetToolTip(moveCmd.ToolTipText);
            }
        }