protected override void Run()
        {
            log.DebugFormat("Deleting VDI '{0}'", Helpers.GetName(Disk));
            Description = Messages.ACTION_VDI_DELETING;
            foreach (VBD vbd in SR.Connection.ResolveAll(Disk.VBDs))
            {
                VM vm = Connection.Resolve <VM>(vbd.VM);
                if (vm == null)
                {
                    continue;
                }
                if (vbd.currently_attached && !AllowRunningVMDelete)
                {
                    throw new Exception(
                              string.Format(Messages.CANNOT_DELETE_VDI_ACTIVE_ON,
                                            Helpers.GetName(vm).Ellipsise(20)));
                }
                DetachVirtualDiskAction action = new DetachVirtualDiskAction(Disk, vm, false);
                action.RunExternal(Session);
            }

            RelatedTask = XenAPI.VDI.async_destroy(Session, Disk.opaque_ref);
            PollToCompletion();
            Description = Messages.ACTION_VDI_DELETED;
            log.DebugFormat("Deleted VDI '{0}'", Helpers.GetName(Disk));
        }
Exemple #2
0
        protected override void Run()
        {
            log.DebugFormat("Deleting VDI '{0}'", Helpers.GetName(Disk));
            Description = Messages.ACTION_VDI_DELETING;
            foreach (VBD vbd in SR.Connection.ResolveAll(Disk.VBDs))
            {
                VM vm = Connection.Resolve<VM>(vbd.VM);
                if (vm == null)
                    continue;
                if (vbd.currently_attached && !AllowRunningVMDelete)
                {
                    throw new Exception(
                        string.Format(Messages.CANNOT_DELETE_VDI_ACTIVE_ON,
                        Helpers.GetName(vm).Ellipsise(20)));
                }
                DetachVirtualDiskAction action = new DetachVirtualDiskAction(Disk, vm, false);
                action.RunExternal(Session);
            }

            RelatedTask = XenAPI.VDI.async_destroy(Session, Disk.opaque_ref);
            PollToCompletion();
            Description = Messages.ACTION_VDI_DELETED;
            log.DebugFormat("Deleted VDI '{0}'", Helpers.GetName(Disk));
        }
 private List<AsyncAction> getDetachVDIAction(VDI vdi)
 {
     List<AsyncAction> actions = new List<AsyncAction>();
     foreach (VBD vbd in vdi.Connection.ResolveAll<VBD>(vdi.VBDs))
     {
         if (targetVM == null || vbd.VM.opaque_ref == targetVM.opaque_ref)
         {
             VM vm = vdi.Connection.Resolve<VM>(vbd.VM);
             DetachVirtualDiskAction action = new DetachVirtualDiskAction(vdi, vm, true);
             actions.Add(action);
         }
     }
     return actions;
 }