Ejemplo n.º 1
0
        public static void CheckPlugPBDsForVMs(IXenConnection connection, List <XenRef <VM> > vmRefs, bool ignoreFailure = false)
        {
            var pbds = new List <PBD>();

            foreach (XenRef <VM> vmRef in vmRefs)
            {
                VM vm = connection.TryResolveWithTimeout(vmRef);

                foreach (var vbdRef in vm.VBDs)
                {
                    var vbd = connection.Resolve(vbdRef);
                    if (vbd == null)
                    {
                        continue;
                    }

                    VDI vdi = connection.Resolve(vbd.VDI);
                    if (vdi == null)
                    {
                        continue;
                    }

                    SR sr = connection.Resolve(vdi.SR);
                    if (sr == null)
                    {
                        continue;
                    }

                    foreach (var pbdRef in sr.PBDs)
                    {
                        var pbd = connection.Resolve(pbdRef);
                        if (pbd != null && !pbds.Contains(pbd))
                        {
                            pbds.Add(pbd);
                        }
                    }
                }
            }

            foreach (PBD pbd in pbds)
            {
                Session session = pbd.Connection.DuplicateSession();

                log.DebugFormat("Waiting for PBDs {0} to become plugged", pbd.Name());
                // Wait 2 min for PBD to become plugged
                if (WaitForPlug(session, pbd.opaque_ref))
                {
                    continue;
                }

                // if it's still unplugged, try plugging it - this will probably
                // fail, but at least we'll get a better error message.
                try
                {
                    log.DebugFormat("Plugging PBD {0}", pbd.Name());
                    plug(session, pbd.opaque_ref);
                }
                catch (Exception e)
                {
                    log.Debug(string.Format("Error plugging PBD {0}", pbd.Name()), e);

                    if (!ignoreFailure)
                    {
                        throw;
                    }
                }
            }
        }