Exemple #1
0
 protected override void Run()
 {
     if (SrType != SR.SRTypes.gfs2)
     {
         RelatedTask = SR.async_probe(this.Session, host.opaque_ref,
                                      dconf, SrType.ToString().ToLowerInvariant(), smconf);
         PollToCompletion();
     }
     else
     {
         ProbeExtResult = SR.probe_ext(this.Session, host.opaque_ref,
                                       dconf, SrType.ToString().ToLowerInvariant(), smconf);
     }
     Description = Messages.ACTION_SR_SCAN_SUCCESSFUL;
 }
Exemple #2
0
 protected override void Run()
 {
     RelatedTask = XenAPI.SR.async_probe(this.Session, host.opaque_ref,
                                         dconf, srType.ToString().ToLowerInvariant(), smconf);
     PollToCompletion();
     Description = Messages.ACTION_SR_SCAN_SUCCESSFUL;
 }
Exemple #3
0
        protected override void Run()
        {
            Description = Messages.PROBING_HBA;
            if (srType != SR.SRTypes.gfs2)
            {
                try
                {
                    Result = SR.probe(Session, Host.opaque_ref, new Dictionary <string, string>(), srType.ToString(), new Dictionary <string, string>());
                }
                catch (Failure f)
                {
                    if (f.ErrorDescription[0] == "SR_BACKEND_FAILURE_90" ||
                        f.ErrorDescription[0] == "SR_BACKEND_FAILURE_107")
                    {
                        Result = f.ErrorDescription[3];
                    }
                    else
                    {
                        throw;
                    }
                }

                FibreChannelDevices = ProcessXml(Result);
            }
            else
            {
                var deviceConfig = new Dictionary <string, string>();
                deviceConfig["provider"] = "hba";
                var result = SR.probe_ext(Session, Host.opaque_ref, deviceConfig, srType.ToString(), new Dictionary <string, string>());

                var list = new List <FibreChannelDevice>();
                foreach (var r in result)
                {
                    var dict = new Dictionary <string, string>(r.configuration);
                    r.extra_info.ToList().ForEach(kvp => dict.Add(kvp.Key, kvp.Value));
                    list.Add(new FibreChannelDevice(dict));
                }
                FibreChannelDevices = list;
            }
            Description = Messages.PROBED_HBA;
        }
        protected override void Run()
        {
            log.Debug("Running SR.Introduce");
            log.DebugFormat("SR uuid='{0}'", _srUuid);
            log.DebugFormat("name='{0}'", _srName);
            log.DebugFormat("description='{0}'", _srDescription);
            log.DebugFormat("type='{0}'", _srType);
            log.DebugFormat("content type='{0}'", _srContentType);
            log.DebugFormat("is shared='{0}'", _srIsShared);

            Description = Messages.ACTION_SR_ATTACHING;
            // If SR is already attached, forget it (it may be in a broken invisible state with no PBDs)
            try
            {
                log.Debug("Performing preemptive SR.forget()");
                RelatedTask = XenAPI.SR.async_forget(this.Session, XenAPI.SR.get_by_uuid(this.Session,
                                                                                         _srUuid).opaque_ref);
                PollToCompletion(0, 5);
            }
            catch (Failure)
            {
                // Allow failure
            }

            // Introduce the existing SR
            RelatedTask = XenAPI.SR.async_introduce(this.Session, _srUuid, _srName,
                                                    _srDescription, _srType.ToString(), _srContentType,
                                                    _srIsShared, new Dictionary <string, string>());
            PollToCompletion(5, 10);

            // cache result, in order to reassign it later
            string introducedSr = Result;

            // Now repair the SR with new PBDs for each host in the pool
            XenAPI.PBD pbdTemplate = new PBD();
            pbdTemplate.currently_attached = false;
            pbdTemplate.device_config      = _dconf;
            pbdTemplate.SR = new XenRef <SR>(Result);
            int delta = 90 / Connection.Cache.HostCount / 2;

            foreach (Host host in Connection.Cache.Hosts)
            {
                // Create the PBD
                log.DebugFormat("Creating PBD for host {0}", host.Name());
                this.Description = string.Format(Messages.ACTION_SR_REPAIR_CREATE_PBD, Helpers.GetName(host));
                pbdTemplate.host = new XenRef <Host>(host.opaque_ref);
                RelatedTask      = PBD.async_create(this.Session, pbdTemplate);
                PollToCompletion(PercentComplete, PercentComplete + delta);
                XenRef <PBD> pbdRef = new XenRef <PBD>(this.Result);

                // Now plug the PBD
                log.DebugFormat("Plugging PBD for host {0}", host.Name());
                this.Description = string.Format(Messages.ACTION_SR_REPAIR_PLUGGING_PBD, Helpers.GetName(host));
                RelatedTask      = XenAPI.PBD.async_plug(this.Session, pbdRef);
                PollToCompletion(PercentComplete, PercentComplete + delta);
            }

            // reassign result
            Result = introducedSr;

            if (isFirstSharedNonISOSR())
            {
                SR new_sr = Connection.WaitForCache(new XenRef <SR>(Result), GetCancelling);
                if (Cancelling)
                {
                    throw new CancelledException();
                }
                if (new_sr == null)
                {
                    throw new Failure(Failure.HANDLE_INVALID, "SR", Result);
                }

                // Set this SR to be the default
                new SrAction(SrActionKind.SetAsDefault, new_sr).RunExternal(Session);
            }

            Description = Messages.ACTION_SR_ATTACH_SUCCESSFUL;
        }
Exemple #5
0
 protected override void Run()
 {
     this.Description = Messages.PROBING_HBA;
     try
     {
         Result = XenAPI.SR.probe(Session, Host.opaque_ref, new Dictionary <string, string>(), srType.ToString(), new Dictionary <string, string>());
     }
     catch (XenAPI.Failure f)
     {
         if (f.ErrorDescription[0] == "SR_BACKEND_FAILURE_90" ||
             f.ErrorDescription[0] == "SR_BACKEND_FAILURE_107")
         {
             Result = f.ErrorDescription[3];
         }
         else
         {
             throw;
         }
     }
     this.Description = Messages.PROBED_HBA;
 }
        protected override void Run()
        {
            log.Debug("Running SR.Create()");
            log.DebugFormat("host='{0}'", Host.Name());
            log.DebugFormat("name='{0}'", _srName);
            log.DebugFormat("description='{0}'", _srDescription);
            log.DebugFormat("type='{0}'", _srType);
            log.DebugFormat("content type='{0}'", _srContentType);
            log.DebugFormat("is shared='{0}'", _srIsShared);

            string secretuuid = null;
            string value;

            if (_dconf.TryGetValue("cifspassword", out value))
            {
                secretuuid = CreateSecret("cifspassword", value);
            }
            else if (_dconf.TryGetValue("password", out value))
            {
                secretuuid = CreateSecret("password", value);
            }
            else if (_dconf.TryGetValue("chappassword", out value))
            {
                secretuuid = CreateSecret("chappassword", value);
            }

            Description = Messages.ACTION_SR_CREATING;
            XenRef <SR> sr;

            try
            {
                sr = XenAPI.SR.create(Session, Host.opaque_ref, _dconf, 0,
                                      _srName, _srDescription, _srType.ToString().ToLowerInvariant(),
                                      _srContentType,
                                      _srIsShared,
                                      _smconf ?? new Dictionary <string, string>());

                Result = sr;
            }
            catch
            {
                if (!string.IsNullOrEmpty(secretuuid))
                {
                    string opaqref = Secret.get_by_uuid(Session, secretuuid);
                    Secret.destroy(Session, opaqref);
                }
                throw;
            }
            finally
            {
                // Destroy secret after the SR creation is complete. This is safe
                // since all PBDs will have duplicated the secret (CA-113396).
                //
                // We do this on a best-effort basis because some types of errors
                // mean the secret was never actually created, so the operation will
                // fail, masking any earlier error (CA-145254), or causing a successful
                // SR.create to be reported as an error. The worst that can happen is
                // that an unused secret will be left lying around without warning.
                try
                {
                    if (!string.IsNullOrEmpty(secretuuid))
                    {
                        string opaqref = Secret.get_by_uuid(Session, secretuuid);
                        Secret.destroy(Session, opaqref);
                    }
                }
                catch { }
            }

            log.Debug("Checking that SR.create() actually succeeded");
            foreach (XenRef <PBD> pbdRef in XenAPI.SR.get_PBDs(Session, sr.opaque_ref))
            {
                if (!XenAPI.PBD.get_currently_attached(Session, pbdRef))
                {
                    // The automatic plug done by the SR.create has failed to plug this PDB:
                    // try the plug manually, and report the failure. Roll back the operation
                    // by forgetting the SR.
                    try
                    {
                        XenAPI.PBD.plug(this.Session, pbdRef);
                    }
                    catch (Exception exn)
                    {
                        if (exn is Failure)
                        {
                            Failure f = (Failure)exn;
                            if (f.ErrorDescription[0] == Failure.HOST_OFFLINE ||
                                f.ErrorDescription[0] == Failure.HOST_STILL_BOOTING)
                            {
                                log.Warn("Unable to check storage settings, due to host being down", f);
                            }
                        }
                        else
                        {
                            log.Debug("Plug failed on a PBD: performing SR.forget");
                            ForgetFailedSR(sr);
                            throw;
                        }
                    }
                }
            }

            Dictionary <string, string> other_config = new Dictionary <string, string>();

            other_config.Add("auto-scan", _srContentType == XenAPI.SR.Content_Type_ISO ? "true" : "false");
            XenAPI.SR.set_other_config(Session, Result, other_config);

            if (isFirstSharedNonISOSR())
            {
                SR new_sr = Connection.WaitForCache(new XenRef <SR>(Result), GetCancelling);
                if (Cancelling)
                {
                    throw new CancelledException();
                }
                if (new_sr == null)
                {
                    throw new Failure(Failure.HANDLE_INVALID, "SR", Result);
                }

                // Set this SR to be the default
                new SrAction(SrActionKind.SetAsDefault, new_sr).RunExternal(Session);
            }

            Description = Messages.ACTION_SR_CREATE_SUCCESSFUL;
        }
Exemple #7
0
        protected override void Run()
        {
            // Fill in dictionary params
            Dictionary <String, String> dconf = new Dictionary <String, String>();

            dconf.Add("target", hostname);
            dconf.Add("username", username);
            dconf.Add("password", password);

            log.DebugFormat("Attempting to find SRs on {0} filer {1}.", type, hostname);

            RelatedTask = XenAPI.SR.async_probe(Session, Helpers.GetMaster(Connection).opaque_ref,
                                                dconf, type.ToString(), new Dictionary <String, String>());
            this.PollToCompletion();
            srs = XenAPI.SR.ParseSRListXML(this.Result);

            log.DebugFormat("Attempting to find aggregates on {0} filer {1}.", type, hostname);

            try
            {
                RelatedTask = XenAPI.SR.async_create(Session, hostname, dconf, 0,
                                                     Helpers.GuiTempObjectPrefix, "", type.ToString(), "", true,
                                                     new Dictionary <String, String>());

                this.PollToCompletion(50, 100);

                throw new BadServerResponse(hostname);
            }
            catch (Failure exn)
            {
                if (exn.ErrorDescription.Count < 1)
                {
                    throw new BadServerResponse(hostname);
                }

                // We expect a particular sort of failure, whose error details contain
                // the list of aggregates on the filer in XML.

                switch (exn.ErrorDescription[0])
                {
                case "SR_BACKEND_FAILURE_123":
                    // We want a custom error if the server returns no iqns.
                    if (exn.ErrorDescription.Count < 4 || exn.ErrorDescription[3].Length == 0)
                    {
                        break;
                    }

                    aggregates = ParseAggregateXML(exn.ErrorDescription[3], hostname);

                    break;

                case "SR_BACKEND_FAILURE_163":
                    // We want a custom error if the server returns no iqns.
                    if (exn.ErrorDescription.Count < 4 || exn.ErrorDescription[3].Length == 0)
                    {
                        break;
                    }

                    storagePools = ParseDellStoragePoolsXML(exn.ErrorDescription[3], hostname);

                    break;

                default:
                    throw;
                }

                if (ListIsNullOrEmpty(srs) &&
                    ListIsNullOrEmpty(aggregates) &&
                    ListIsNullOrEmpty(storagePools))
                {
                    throw new NoExistingAndNowhereToCreateException(hostname);
                }
            }
        }
Exemple #8
0
        protected override void Run()
        {
            log.Debug("Running SR.Create()");
            log.DebugFormat("host='{0}'", Host.Name);
            log.DebugFormat("name='{0}'", _srName);
            log.DebugFormat("description='{0}'", _srDescription);
            log.DebugFormat("type='{0}'", _srType);
            log.DebugFormat("content type='{0}'", _srContentType);
            log.DebugFormat("is shared='{0}'", _srIsShared);

            string secretuuid = null;

            if (Helpers.MidnightRideOrGreater(Connection))
            {
                string value;
                if (_dconf.TryGetValue("cifspassword", out value))
                {
                    secretuuid = CreateSecret("cifspassword", value);
                }
                else if (_dconf.TryGetValue("password", out value))
                {
                    secretuuid = CreateSecret("password", value);
                }
                else if (_dconf.TryGetValue("chappassword", out value))
                {
                    secretuuid = CreateSecret("chappassword", value);
                }
            }

            if (_srType == SR.SRTypes.cslg && !Helpers.BostonOrGreater(Connection))
            {
                // make sure this connection is added to the storagelink service.
                StorageLinkConnection slCon = _SLConnection;
                if (slCon != null)
                {
                    slCon.AddXenConnection(Connection);
                }
            }

            Description = Messages.ACTION_SR_CREATING;
            XenRef <SR> sr;

            try
            {
                sr = XenAPI.SR.create(Session, Host.opaque_ref, _dconf, 0,
                                      _srName, _srDescription, _srType.ToString().ToLowerInvariant(),
                                      _srContentType,
                                      _srIsShared, new Dictionary <string, string>());
                Result = sr;
            }
            catch
            {
                if (!string.IsNullOrEmpty(secretuuid))
                {
                    string opaqref = Secret.get_by_uuid(Session, secretuuid);
                    Secret.destroy(Session, opaqref);
                }
                throw;
            }
            finally
            {
                // Destroy secret after the SR creation is complete. This is safe
                // since all PBDs will have duplicated the secret (CA-113396).
                if (!string.IsNullOrEmpty(secretuuid) && Helpers.AugustaOrGreater(Connection))
                {
                    string opaqref = Secret.get_by_uuid(Session, secretuuid);
                    Secret.destroy(Session, opaqref);
                }
            }

            log.Debug("Checking that SR.create() actually succeeded");
            foreach (XenRef <PBD> pbdRef in XenAPI.SR.get_PBDs(Session, sr.opaque_ref))
            {
                if (!XenAPI.PBD.get_currently_attached(Session, pbdRef))
                {
                    // The automatic plug done by the SR.create has failed to plug this PDB:
                    // try the plug manually, and report the failure. Roll back the operation
                    // by forgetting the SR.
                    try
                    {
                        XenAPI.PBD.plug(this.Session, pbdRef);
                    }
                    catch (Exception exn)
                    {
                        if (exn is Failure)
                        {
                            Failure f = (Failure)exn;
                            if (f.ErrorDescription[0] == Failure.HOST_OFFLINE ||
                                f.ErrorDescription[0] == Failure.HOST_STILL_BOOTING)
                            {
                                log.Warn("Unable to check storage settings, due to host being down", f);
                            }
                        }
                        else
                        {
                            log.Debug("Plug failed on a PBD: performing SR.forget");
                            ForgetFailedSR(sr);
                            throw;
                        }
                    }
                }
            }

            Dictionary <string, string> other_config = new Dictionary <string, string>();

            other_config.Add("auto-scan", _srContentType == XenAPI.SR.Content_Type_ISO ? "true" : "false");
            XenAPI.SR.set_other_config(Session, Result, other_config);

            if (isFirstSharedNonISOSR())
            {
                SR new_sr = Connection.WaitForCache(new XenRef <SR>(Result), GetCancelling);
                if (Cancelling)
                {
                    throw new CancelledException();
                }
                if (new_sr == null)
                {
                    throw new Failure(Failure.HANDLE_INVALID, "SR", Result);
                }

                // Set this SR to be the default
                new SrAction(SrActionKind.SetAsDefault, new_sr).RunExternal(Session);
            }

            Description = Messages.ACTION_SR_CREATE_SUCCESSFUL;
        }