private List <AsyncAction> getDestroyVDIAction(VDI vdi, List <VM> deletedVMSnapshots) { List <AsyncAction> actions = new List <AsyncAction>(); // Destroy the entire snapshot if it exists. Else destroy disk if (vdi.is_a_snapshot && vdi.GetVMs().Count >= 1) { foreach (VM vm in vdi.GetVMs()) { if (!vm.is_a_snapshot || deletedVMSnapshots.Contains(vm)) { continue; } AsyncAction action = new VMSnapshotDeleteAction(vm); actions.Add(action); deletedVMSnapshots.Add(vm); } } else { SR sr = vdi.Connection.Resolve(vdi.SR); if (sr == null) { // Nothing we can do here, but this should have been caught in the getcantexecutereason method and prompted return(actions); } DestroyDiskAction a = new DestroyDiskAction(vdi); a.AllowRunningVMDelete = AllowRunningVMDelete; actions.Add(a); } return(actions); }
private bool VDIIsSuitable(VDI vdi) { if (vdi == null) { return(false); } if (vdi.is_a_snapshot) { return(false); } if (vdi.Locked) { return(false); } if (vdi.IsHaType) { return(false); } if (vdi.Connection.ResolveAll(vdi.VBDs).Count < 1) { return(false); } if (vdi.GetVMs().Any(vm => !vm.IsRunning) && !Helpers.DundeeOrGreater(vdi.Connection)) { return(false); } SR sr = GetSR(vdi); if (sr == null || sr.HBALunPerVDI) { return(false); } return(true); }
private bool CanBeMigrated(VDI vdi) { if (vdi == null || vdi.is_a_snapshot || vdi.Locked || vdi.IsHaType() || vdi.cbt_enabled) { return(false); } if (vdi.Connection.ResolveAll(vdi.VBDs).Count == 0) { return(false); } if (vdi.GetVMs().Any(vm => !vm.IsRunning()) && !Helpers.DundeeOrGreater(vdi.Connection)) { return(false); } SR sr = vdi.Connection.Resolve(vdi.SR); if (sr == null || sr.HBALunPerVDI()) { return(false); } if (Helpers.DundeePlusOrGreater(vdi.Connection) && !sr.allowed_operations.Contains(storage_operations.vdi_mirror)) { return(false); } return(true); }
private void PopulatePage() { currentValue = VDI.get_allow_caching(this.vdi.Connection.Session, this.vdi.opaque_ref); useSSDCacheCheckBox.Checked = currentValue; var vms = vdi.GetVMs(); useSSDCacheCheckBox.Enabled = !(vms.Any(vm => vm.IsRunning)) && ShowSSDCache(vdi); }
/// <summary> /// We can move VDIs to a local SR only if the VDI is attached to VMs /// that have a home server that can see the SR /// </summary> private static bool HomeHostCanSeeTargetSr(VDI vdi, SR targetSr) { var vms = vdi.GetVMs(); var homeHosts = (from VM vm in vms let host = vm.Home() where host != null select host).ToList(); return(homeHosts.Count > 0 && homeHosts.All(targetSr.CanBeSeenFrom)); }
/// <summary> /// If the VM has a home host, we can move VDIs to a local SR only /// if the latter belongs to the VM's home host /// </summary> private bool HomeHostCanSeeTargetSr(VDI vdi) { var vms = vdi.GetVMs(); var homeHosts = (from VM vm in vms let host = vm.Home() where host != null select host).ToList(); return(homeHosts.Count == 0 || homeHosts.Any(TheSR.CanBeSeenFrom)); }
protected override string GetCantExecuteReasonCore(SelectedItem item) { VDI vdi = item.XenObject as VDI; if (vdi == null) { return(base.GetCantExecuteReasonCore(item)); } if (vdi.is_a_snapshot) { return(Messages.CANNOT_MOVE_VDI_IS_SNAPSHOT); } if (vdi.Locked) { return(Messages.CANNOT_MOVE_VDI_IN_USE); } if (vdi.IsHaType()) { return(Messages.CANNOT_MOVE_HA_VD); } if (vdi.cbt_enabled) { return(Messages.CANNOT_MOVE_CBT_ENABLED_VDI); } if (vdi.IsMetadataForDR()) { return(Messages.CANNOT_MOVE_DR_VD); } if (vdi.GetVMs().Any(vm => !vm.IsRunning()) && !Helpers.DundeeOrGreater(vdi.Connection)) { return(Messages.CANNOT_MIGRATE_VDI_NON_RUNNING_VM); } SR sr = vdi.Connection.Resolve(vdi.SR); if (sr == null) { return(base.GetCantExecuteReasonCore(item)); } if (sr.HBALunPerVDI()) { return(Messages.UNSUPPORTED_SR_TYPE); } if (Helpers.DundeePlusOrGreater(vdi.Connection) && !sr.allowed_operations.Contains(storage_operations.vdi_mirror)) { return(Messages.UNSUPPORTED_SR_TYPE); } return(base.GetCantExecuteReasonCore(item)); }
private bool ShowSSDCache(VDI vdi) { var vms = vdi.GetVMs(); SR vmsr = vdi.Connection.Resolve <SR>(vdi.SR); if (!vmsr.IsLocalSR && vmsr.GetSRType(true) != SR.SRTypes.nfs) { return(false); } var Affinity = vms.Count == 0 ? null : (vms[0] == null ? null : vms[0].GetStorageHost(true)); List <SR> AllSRs = new List <SR>(vdi.Connection.Cache.SRs); List <SR> srs; if (Affinity != null) { srs = new List <SR>(); foreach (SR sr in AllSRs) { if (sr.GetStorageHost() == Affinity) { srs.Add(sr); } } } else { srs = AllSRs; } foreach (SR sr in srs) { if (sr == null || sr.IsToolsSR || !sr.Show(Properties.Settings.Default.ShowHiddenVMs)) { continue; } if (sr.GetSRType(true) == SR.SRTypes.ext && SR.get_local_cache_enabled(vdi.Connection.Session, sr.opaque_ref)) { return(true); } } return(false); }
protected override string GetCantExecuteReasonCore(SelectedItem item) { VDI vdi = item.XenObject as VDI; if (vdi == null) { return(base.GetCantExecuteReasonCore(item)); } if (vdi.is_a_snapshot) { return(Messages.CANNOT_MOVE_VDI_IS_SNAPSHOT); } if (vdi.Locked) { return(Messages.CANNOT_MOVE_VDI_IN_USE); } if (vdi.IsHaType) { return(Messages.CANNOT_MOVE_HA_VD); } if (vdi.IsMetadataForDR) { return(Messages.CANNOT_MOVE_DR_VD); } if (vdi.GetVMs().Any(vm => !vm.IsRunning) && !Helpers.DundeeOrGreater(vdi.Connection)) { return(Messages.CANNOT_MIGRATE_VDI_NON_RUNNING_VM); } SR sr = GetSR(vdi); if (sr == null) { return(base.GetCantExecuteReasonCore(item)); } if (sr.HBALunPerVDI) { return(Messages.UNSUPPORTED_SR_TYPE); } return(base.GetCantExecuteReasonCore(item)); }
private bool CanBeMoved(VDI vdi) { if (vdi == null || vdi.is_a_snapshot || vdi.Locked || vdi.IsHaType() || vdi.cbt_enabled) { return(false); } SR sr = vdi.Connection.Resolve(vdi.SR); if (sr == null || sr.HBALunPerVDI()) { return(false); } if (vdi.GetVMs().Any(vm => vm.power_state != vm_power_state.Halted)) { return(false); } return(true); }
public ConfirmVMDeleteDialog(IEnumerable <VM> vms) { Util.ThrowIfParameterNull(vms, "vms"); InitializeComponent(); pictureBox1.Image = SystemIcons.Warning.ToBitmap(); HelpButton = true; // We have to set the header text again here because they're in base64 // encoding in the resx, so can't be easily localised: see CA-43371. listView.Groups["listViewGroupAttachedDisks"].Header = Messages.ATTACHED_VIRTUAL_DISKS; listView.Groups["listViewGroupSnapshots"].Header = Messages.SNAPSHOTS; List <VM> vmList = new List <VM>(vms); if (vmList.Count == 1) { String type = vmList[0].is_a_template ? Messages.TEMPLATE : Messages.VM; Text = String.Format(Messages.CONFIRM_DELETE_TITLE, type); } else { Text = Messages.CONFIRM_DELETE_ITEMS_TITLE; } List <VDI> sharedVDIsCouldBeDelete = new List <VDI>(); foreach (VM vm in vmList) { foreach (VBD vbd in vm.Connection.ResolveAll(vm.VBDs)) { if (!vbd.IsCDROM) { VDI vdi = vbd.Connection.Resolve(vbd.VDI); if (vdi != null) { IList <VM> VMsUsingVDI = vdi.GetVMs(); bool allTheVMsAreDeleted = true; if (VMsUsingVDI.Count > 1) { foreach (VM vmUsingVdi in VMsUsingVDI) { if (!vmList.Contains(vmUsingVdi)) { allTheVMsAreDeleted = false; break; } } if (allTheVMsAreDeleted && !sharedVDIsCouldBeDelete.Contains(vdi)) { sharedVDIsCouldBeDelete.Add(vdi); } } else { ListViewItem item = new ListViewItem(); item.Text = vdi.Name; item.SubItems.Add(vm.Name); item.Group = listView.Groups["listViewGroupAttachedDisks"]; item.Tag = vbd; item.Checked = vbd.IsOwner; foreach (ListViewItem.ListViewSubItem subitem in item.SubItems) { subitem.Tag = subitem.Text; } listView.Items.Add(item); } } } } foreach (VM snapshot in vm.Connection.ResolveAll(vm.snapshots)) { ListViewItem item = new ListViewItem(); item.Text = snapshot.Name; item.SubItems.Add(vm.Name); item.Tag = snapshot; item.Group = listView.Groups["listViewGroupSnapshots"]; foreach (ListViewItem.ListViewSubItem subitem in item.SubItems) { subitem.Tag = subitem.Text; } listView.Items.Add(item); } } foreach (VDI vdi in sharedVDIsCouldBeDelete) { ListViewItem item = new ListViewItem(); item.Text = vdi.Name; item.SubItems.Add(vdi.VMsOfVDI); item.Group = listView.Groups["listViewGroupAttachedDisks"]; item.Tag = vdi.Connection.ResolveAll(vdi.VBDs); item.Checked = false; foreach (ListViewItem.ListViewSubItem subitem in item.SubItems) { subitem.Tag = subitem.Text; } listView.Items.Add(item); } EnableSelectAllClear(); EllipsizeStrings(); }
/// <summary> /// We can only move VDIs to a local SR if that local SR belongs /// to the host on which the VM is running. /// </summary> private bool SrIsLocalToTheHostOnWhichTheVmIsRunning(SR sr, VDI vdi) { List <Host> hostOfVdi = vdi.GetVMs().Select(vm => vm.Home()).ToList(); return(hostOfVdi.Any(sr.CanBeSeenFrom)); }