示例#1
0
        public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
        {
            if (direction == PageLoadedDirection.Back)
                return;

            Host master = Helpers.GetMaster(Connection);
            if (master == null)
            {
                cancel = true;
                return;
            }

            SrDescriptors = new List<LvmOhbaSrDescriptor>();

            var existingSrDescriptors = new List<LvmOhbaSrDescriptor>();
            var formatDiskDescriptors = new List<LvmOhbaSrDescriptor>();

            foreach (var device in _selectedDevices)
            {
                LvmOhbaSrDescriptor descr = CreateSrDescriptor(device);

                var action = new SrProbeAction(Connection, master, SrType, descr.DeviceConfig);
                using (var dlg = new ActionProgressDialog(action, ProgressBarStyle.Marquee))
                    dlg.ShowDialog(this);

                if (!action.Succeeded)
                {
                    cancel = true;
                    return;
                }

                descr.UUID = SrWizardHelpers.ExtractUUID(action.Result);

                if (!string.IsNullOrEmpty(SrWizardType.UUID))
                {
                    // Check LUN contains correct SR
                    if (descr.UUID == SrWizardType.UUID)
                    {
                        SrDescriptors.Add(descr);
                        continue;
                    }

                    using (var dlog = new ThreeButtonDialog(
                        new ThreeButtonDialog.Details(SystemIcons.Error,
                            String.Format(Messages.INCORRECT_LUN_FOR_SR, SrWizardType.SrName), Messages.XENCENTER)))
                    {
                        dlog.ShowDialog(this);
                    }

                    cancel = true;
                    return;
                }

                if (string.IsNullOrEmpty(descr.UUID))
                {
                    // No existing SRs were found on this LUN. If allowed to create
                    // a new SR, ask the user if they want to proceed and format.
                    if (!SrWizardType.AllowToCreateNewSr)
                    {
                        using (var dlog = new ThreeButtonDialog(
                            new ThreeButtonDialog.Details(SystemIcons.Error,
                                Messages.NEWSR_LUN_HAS_NO_SRS, Messages.XENCENTER)))
                        {
                            dlog.ShowDialog(this);
                        }

                        cancel = true;
                        return;
                    }

                    if (!Program.RunInAutomatedTestMode)
                        formatDiskDescriptors.Add(descr);
                }
                else
                {
                    // CA-17230: Check this isn't a detached SR. If it is then just continue
                    SR sr = SrWizardHelpers.SrInUse(descr.UUID);
                    if (sr != null)
                    {
                        SrDescriptors.Add(descr);
                        continue;
                    }

                    // We found a SR on this LUN. Will ask user for choice later.
                    existingSrDescriptors.Add(descr);
                }
            }

            if (!cancel && existingSrDescriptors.Count > 0)
            {
                var launcher = new LVMoHBAWarningDialogLauncher(this, existingSrDescriptors, true);
                launcher.ShowWarnings();
                cancel = launcher.Cancelled;
                if (!cancel && launcher.SrDescriptors.Count > 0)
                    SrDescriptors.AddRange(launcher.SrDescriptors);
            }

            if (!cancel && formatDiskDescriptors.Count > 0)
            {
                var launcher = new LVMoHBAWarningDialogLauncher(this, formatDiskDescriptors, false);
                launcher.ShowWarnings();
                cancel = launcher.Cancelled;
                if (!cancel && launcher.SrDescriptors.Count > 0)
                    SrDescriptors.AddRange(launcher.SrDescriptors);
            }

            base.PageLeave(direction, ref cancel);
        }
示例#2
0
文件: VHDoNFS.cs 项目: huizh/xenadmin
        private void buttonNfsScan_Click(object sender, EventArgs e)
        {
            NfsScanButton.Enabled = false;

            // Perform an SR.probe to see if there is already an SR present
            Dictionary<String, String> dconf = new Dictionary<String, String>();
            string[] fullpath = NfsServerPathTextBox.Text.Trim().Split(new char[] { ':' });
            dconf[SERVER] = fullpath[0];
            if (fullpath.Length > 1)
            {
                dconf[SERVERPATH] = fullpath[1];
            }
            dconf[OPTIONS] = serverOptionsTextBox.Text;

            Host master = Helpers.GetMaster(Connection);
            if (master == null)
                return;

            if (Helpers.DundeeOrGreater(Connection))
                dconf[PROBEVERSION] = string.Empty; //this needs to be passed to the API in order to get back the NFS versions supported

            // Start probe
            SrProbeAction action = new SrProbeAction(Connection, master, SR.SRTypes.nfs, dconf);
            ActionProgressDialog dialog = new ActionProgressDialog(action, ProgressBarStyle.Marquee);
            dialog.ShowCancel = true;
            dialog.ShowDialog(this);

            try
            {
                NfsScanButton.Enabled = true;
                if (radioButtonNfsNew.Enabled)
                    radioButtonNfsNew.Checked = true;

                listBoxNfsSRs.Items.Clear();

                if (!action.Succeeded)
                    return;

                List<SR.SRInfo> SRs = SR.ParseSRListXML(action.Result);
                if (SRs.Count == 0)
                {
                    // Disable box
                    ToggleReattachControlsEnabledState(false);
                    listBoxNfsSRs.Items.Add(Messages.NEWSR_NO_SRS_FOUND);
                    return;
                }

                // Fill box
                foreach(SR.SRInfo info in SRs)
                    listBoxNfsSRs.Items.Add(info);

                listBoxNfsSRs.TryAndSelectUUID();

                GetSupportedNfsVersionsAndSetUI(action.Result);
                
                ToggleReattachControlsEnabledState(true);
            }
            finally
            {
                UpdateButtons();
            }
        }
        private bool ScanDeviceForSRs(SR.SRTypes type, string deviceId, Dictionary<string, string> dconf)
        {
            Host master = Helpers.GetMaster(Connection);
            if (master == null || dconf == null)
            {
                return false;
            }

            Dictionary<string, string> smconf = new Dictionary<string, string>();
            smconf[METADATA] = "true";

            // Start probe
            SrProbeAction srProbeAction = new SrProbeAction(Connection, master, type, dconf, smconf);
            new ActionProgressDialog(srProbeAction, ProgressBarStyle.Marquee).ShowDialog(this);

            if (!srProbeAction.Succeeded)
                return false;

            try
            {
                List<SR.SRInfo> srList = SR.ParseSRListXML(srProbeAction.Result);

                List<SR.SRInfo> metadataSrs = srList; //srList.Where(srInfo => srInfo.PoolMetadataDetected).ToList();

                if (ScannedDevices.ContainsKey(deviceId))
                {
                    //update SR list
                    ScannedDevices[deviceId].SRList.Clear();
                    ScannedDevices[deviceId].SRList.AddRange(metadataSrs);
                }
                else
                {
                    ScannedDevices.Add(deviceId, new ScannedDeviceInfo(type, dconf, metadataSrs));
                }

                foreach (SR.SRInfo srInfo in metadataSrs)
                {
                    SrRow row;
                    if (!FindRowByUuid(srInfo.UUID, out row))
                    {
                        row = new SrRow(srInfo, type, srInfo.PoolMetadataDetected,
                                               srInfo.PoolMetadataDetected);
                        dataGridViewSRs.Rows.Add(row);
                        ToggleRowChecked(row);
                    }
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
        private List<SR.SRInfo> ScanDeviceForSRs(SR.SRTypes type, string deviceId, Dictionary<string, string> dconf)
        {
            Host master = Helpers.GetMaster(Connection);
            if (master == null || dconf == null)
                return null;

            Dictionary<string, string> smconf = new Dictionary<string, string>();
            smconf[METADATA] = "true";

            // Start probe
            SrProbeAction srProbeAction = new SrProbeAction(Connection, master, type, dconf, smconf);
            using (var dlg = new ActionProgressDialog(srProbeAction, ProgressBarStyle.Marquee))
                dlg.ShowDialog(this);

            if (!srProbeAction.Succeeded)
                return null;

            try
            {
                var metadataSrs = SR.ParseSRListXML(srProbeAction.Result);

                if (ScannedDevices.ContainsKey(deviceId))
                {
                    //update SR list
                    ScannedDevices[deviceId].SRList.Clear();
                    ScannedDevices[deviceId].SRList.AddRange(metadataSrs);
                }
                else
                {
                    ScannedDevices.Add(deviceId, new ScannedDeviceInfo(type, dconf, metadataSrs));
                }

                return metadataSrs;
            }
            catch
            {
                return null;
            }
        }
示例#5
0
        /// <summary>
        /// Called with the results of an iSCSI SR.probe(), either immediately after the scan, or after the
        /// user has performed a scan, clicked 'cancel' on a dialog, and then clicked 'next' again (this
        /// avoids duplicate probing if none of the settings have changed).
        /// </summary>
        /// <returns>
        /// Whether to continue or not - wheter to format or not is stored in 
        /// iScsiFormatLUN.
        /// </returns>
        private bool ExamineIscsiProbeResults(SrProbeAction action)
        {
            _srToIntroduce = null;

            if (!action.Succeeded)
            {
                Exception exn = action.Exception;
                log.Warn(exn, exn);
                Failure failure = exn as Failure;
                if (failure != null && failure.ErrorDescription[0] == "SR_BACKEND_FAILURE_140")
                {
                    errorIconAtHostOrIP.Visible = true;
                    errorLabelAtHostname.Visible = true;
                    errorLabelAtHostname.Text = Messages.INVALID_HOST;
                    textBoxIscsiHost.Focus();
                }
                else if (failure != null)
                {
                    errorIconAtHostOrIP.Visible = true;
                    errorLabelAtHostname.Visible = true;
                    errorLabelAtHostname.Text = failure.ErrorDescription.Count > 2 ? failure.ErrorDescription[2] : failure.ErrorDescription[0];
                    textBoxIscsiHost.Focus();
                }
                return false;
            }

            try
            {
                List<SR.SRInfo> SRs = SR.ParseSRListXML(action.Result);

                if (!String.IsNullOrEmpty(SrWizardType.UUID))
                {
                    // Check LUN contains correct SR
                    if (SRs.Count == 1 && SRs[0].UUID == SrWizardType.UUID)
                    {
                        _srToIntroduce = SRs[0];
                        return true;
                    }

                    errorIconAtTargetLUN.Visible = true;
                    errorLabelAtTargetLUN.Visible = true;
                    errorLabelAtTargetLUN.Text = String.Format(Messages.INCORRECT_LUN_FOR_SR, SrWizardType.SrName);

                    return false;
                }
                else if (SRs.Count == 0)
                {
                    // No existing SRs were found on this LUN. If allowed to create new SR, ask the user if they want to proceed and format.
                    if (!SrWizardType.AllowToCreateNewSr)
                    {
                        using (var dlg = new ThreeButtonDialog(
                           new ThreeButtonDialog.Details(SystemIcons.Error, Messages.NEWSR_LUN_HAS_NO_SRS, Messages.XENCENTER)))
                        {
                            dlg.ShowDialog(this);
                        }

                        return false;
                    }
                    DialogResult result = DialogResult.Yes;
                    if (!Program.RunInAutomatedTestMode)
                    {
                        using (var dlg = new ThreeButtonDialog(
                            new ThreeButtonDialog.Details(SystemIcons.Warning, Messages.NEWSR_ISCSI_FORMAT_WARNING, this.Text),
                            ThreeButtonDialog.ButtonYes,
                            new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true)))
                        {
                            result = dlg.ShowDialog(this);
                        }
                    }

                    return result == DialogResult.Yes;
                }
                else
                {
                    // There should be 0 or 1 SRs on the LUN
                    System.Diagnostics.Trace.Assert(SRs.Count == 1);

                    // CA-17230
                    // Check this isn't a detached SR
                    SR.SRInfo info = SRs[0];
                    SR sr = SrWizardHelpers.SrInUse(info.UUID);
                    if (sr != null)
                    {
                        DialogResult res;
                        using (var d = new ThreeButtonDialog(
                            new ThreeButtonDialog.Details(null, string.Format(Messages.DETACHED_ISCI_DETECTED, Helpers.GetName(sr.Connection))),
                            new ThreeButtonDialog.TBDButton(Messages.ATTACH_SR, DialogResult.OK),
                            ThreeButtonDialog.ButtonCancel))
                        {
                            res = d.ShowDialog(Program.MainWindow);
                        }

                        if (res == DialogResult.Cancel)
                            return false;

                        _srToIntroduce = info;
                        return true;
                    }

                    // An SR exists on this LUN. Ask the user if they want to attach it, format it and
                    // create a new SR, or cancel.
                    DialogResult result = Program.RunInAutomatedTestMode ? DialogResult.Yes :
                        new IscsiChoicesDialog(Connection, info).ShowDialog(this);

                    switch (result)
                    {
                        case DialogResult.Yes:
                            // Reattach
                            _srToIntroduce = SRs[0];
                            return true;

                        case DialogResult.No:
                            // Format - SrToIntroduce is already null
                            return true;

                        default:
                            return false;
                    }
                }
            }
            catch
            {
                // We really want to prevent the user getting to the next step if there is any kind of
                // exception here, since clicking 'finish' might destroy data: require another probe.
                return false;
            }
        }
示例#6
0
        public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
        {
            if (direction == PageLoadedDirection.Back)
                return;

            // For Miami hosts we need to ensure an SR.probe()
            // has been performed, and that the user has made a decision. Show the iSCSI choices dialog until
            // they click something other than 'Cancel'. For earlier host versions, warn that data loss may
            // occur.

            Host master = Helpers.GetMaster(Connection);
            if (master == null)
            {
                cancel = true;
                return;
            }

            Dictionary<String, String> dconf = DeviceConfig;
            if (dconf == null)
            {
                cancel = true;
                return;
            }

            // Start probe
            SrProbeAction IscsiProbeAction = new SrProbeAction(Connection, master, SR.SRTypes.lvmoiscsi, dconf);
            using (var  dialog = new ActionProgressDialog(IscsiProbeAction, ProgressBarStyle.Marquee))
            {
                dialog.ShowCancel = true;
                dialog.ShowDialog(this);
            }

            // Probe has been performed. Now ask the user if they want to Reattach/Format/Cancel.
            // Will return false on cancel
            cancel = !ExamineIscsiProbeResults(IscsiProbeAction);
            iscsiProbeError = cancel;

            base.PageLeave(direction, ref cancel);
        }
示例#7
0
        private void buttonCifsScan_Click(object sender, EventArgs e)
        {
            try
            {
                CifsScanButton.Enabled = false;

                // Perform an SR.probe to see if there is already an SR present
                Dictionary<String, String> dconf = new Dictionary<String, String>();
                string[] fullpath = CifsServerPathTextBox.Text.Split(new char[] { ':' });
                dconf[SERVER] = fullpath[0];
                if (fullpath.Length > 1)
                {
                    dconf[SERVERPATH] = fullpath[1];
                }

                if (userNameTextBox.Text.Trim().Length > 0 || passwordTextBox.Text.Trim().Length > 0)
                {
                    dconf["username"] = userNameTextBox.Text;
                    dconf["password"] = passwordTextBox.Text;
                }

                Host master = Helpers.GetMaster(Connection);
                if (master == null)
                    return;

                // Start probe
                SrProbeAction action = new SrProbeAction(Connection, master, SR.SRTypes.smb, dconf);
                using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Marquee))
                {
                    dialog.ShowCancel = true;
                    dialog.ShowDialog(this);
                }

                if (radioButtonCifsNew.Enabled)
                    radioButtonCifsNew.Checked = true;

                listBoxCifsSRs.Items.Clear();

                if (!action.Succeeded)
                    return;

                List<SR.SRInfo> SRs = SR.ParseSRListXML(action.Result);
                if (SRs.Count == 0)
                {
                    // Disable box
                    ToggleReattachControlsEnabledState(false);
                    listBoxCifsSRs.Items.Add(Messages.NEWSR_NO_SRS_FOUND);
                    return;
                }

                // Fill box
                foreach(SR.SRInfo info in SRs)
                    listBoxCifsSRs.Items.Add(info);

                listBoxCifsSRs.TryAndSelectUUID();

                ToggleReattachControlsEnabledState(true);
            }
            finally
            {
                UpdateButtons();
            }
        }