Пример #1
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            DiskListVdiItem item = DiskListTreeView.SelectedItem as DiskListVdiItem;

            if (item == null)
            {
                return;
            }

            VDI TheVDI = item.TheVDI;

            // Run this stuff off the event thread, since it involves a server call
            System.Threading.ThreadPool.QueueUserWorkItem(delegate
            {
                // Get a spare userdevice
                string[] uds = VM.get_allowed_VBD_devices(connection.DuplicateSession(), TheVM.opaque_ref);
                if (uds.Length == 0)
                {
                    Program.Invoke(Program.MainWindow, delegate()
                    {
                        using (var dlg = new ErrorDialog(FriendlyErrorNames.VBDS_MAX_ALLOWED)
                        {
                            WindowTitle = Messages.DISK_ATTACH
                        })
                        {
                            dlg.ShowDialog(Program.MainWindow);
                        }
                    });

                    return;
                }
                string ud = uds[0];

                VBD vbd      = new VBD();
                vbd.VDI      = new XenRef <VDI>(TheVDI);
                vbd.VM       = new XenRef <VM>(TheVM);
                vbd.bootable = ud == "0";
                vbd.device   = "";
                vbd.SetIsOwner(TheVDI.VBDs.Count == 0);
                vbd.empty       = false;
                vbd.userdevice  = ud;
                vbd.type        = vbd_type.Disk;
                vbd.mode        = ReadOnlyCheckBox.Checked ? vbd_mode.RO : vbd_mode.RW;
                vbd.unpluggable = true;

                // Try to hot plug the VBD.
                var action = new VbdSaveAndPlugAction(TheVM, vbd, TheVDI.Name(), null, false);
                action.ShowUserInstruction += Action_ShowUserInstruction;
                action.RunAsync();
            });

            Close();
        }
Пример #2
0
        private void OkButton_Click(object sender, EventArgs e)
        {
            if (SrListBox.SR == null || NameTextBox.Text == "" || !connection.IsConnected)
            {
                return;
            }

            if (DontCreateVDI)
            {
                DialogResult = DialogResult.OK;
                Close();
                return;
            }
            XenAPI.SR sr = SrListBox.SR;
            if (!sr.shared && TheVM != null && TheVM.HaPriorityIsRestart())
            {
                DialogResult dialogResult;
                using (var dlg = new WarningDialog(Messages.NEW_SR_DIALOG_ATTACH_NON_SHARED_DISK_HA,
                                                   ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo))
                {
                    dialogResult = dlg.ShowDialog(Program.MainWindow);
                }
                if (dialogResult != DialogResult.Yes)
                {
                    return;
                }
                new HAUnprotectVMAction(TheVM).RunExternal(TheVM.Connection.Session);
            }

            VDI vdi = NewDisk();


            if (TheVM != null)
            {
                var alreadyHasBootableDisk = HasBootableDisk(TheVM);

                Actions.DelegatedAsyncAction action = new Actions.DelegatedAsyncAction(connection,
                                                                                       string.Format(Messages.ACTION_DISK_ADDING_TITLE, NameTextBox.Text, sr.NameWithoutHost()),
                                                                                       Messages.ACTION_DISK_ADDING, Messages.ACTION_DISK_ADDED,
                                                                                       delegate(XenAPI.Session session)
                {
                    // Get legitimate unused userdevice numbers
                    string[] uds = XenAPI.VM.get_allowed_VBD_devices(session, TheVM.opaque_ref);
                    if (uds.Length == 0)
                    {
                        throw new Exception(FriendlyErrorNames.VBDS_MAX_ALLOWED);
                    }
                    string ud      = uds[0];
                    string vdiref  = VDI.create(session, vdi);
                    XenAPI.VBD vbd = NewDevice();
                    vbd.VDI        = new XenAPI.XenRef <XenAPI.VDI>(vdiref);
                    vbd.VM         = new XenAPI.XenRef <XenAPI.VM>(TheVM);

                    // CA-44959: only make bootable if there aren't other bootable VBDs.
                    vbd.bootable   = ud == "0" && !alreadyHasBootableDisk;
                    vbd.userdevice = ud;

                    // Now try to plug the VBD.
                    var plugAction = new VbdSaveAndPlugAction(TheVM, vbd, vdi.Name(), session, false);
                    plugAction.ShowUserInstruction += PlugAction_ShowUserInstruction;
                    plugAction.RunAsync();
                });

                action.VM = TheVM;
                using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Blocks))
                    dialog.ShowDialog();
                if (!action.Succeeded)
                {
                    return;
                }
            }
            else
            {
                CreateDiskAction action = new CreateDiskAction(vdi);
                using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Marquee))
                    dialog.ShowDialog();
                if (!action.Succeeded)
                {
                    return;
                }
            }
            DialogResult = DialogResult.OK;
            Close();
        }