Ejemplo n.º 1
0
        private bool ShowNetwork(object targetRef, XenAPI.Network network, string vsId)
        {
            if (network.IsSriov() && !AllowSriovNetwork(network, vsId))
            {
                return(false);
            }

            if (!network.Show(Properties.Settings.Default.ShowHiddenVMs))
            {
                return(false);
            }

            if (network.IsSlave())
            {
                return(false);
            }

            var  targetHostRef = targetRef as XenRef <Host>;
            Host targetHost    = targetHostRef == null ? null : TargetConnection.Resolve(targetHostRef);

            if (targetHost != null && !targetHost.CanSeeNetwork(network))
            {
                return(false);
            }

            if (targetHost == null && !network.AllHostsCanSeeNetwork())
            {
                return(false);
            }

            return(true);
        }
        protected DataGridViewComboBoxCell FillGridComboBox(object xenRef)
        {
            var cb = new DataGridViewComboBoxCell {
                FlatStyle = FlatStyle.Flat, Sorted = true
            };

            XenRef <Host> hostRef = xenRef as XenRef <Host>;
            Host          host    = TargetConnection.Resolve(hostRef);

            var availableNetworks = TargetConnection.Cache.Networks.Where(net => ShowNetwork(host, net));

            foreach (XenAPI.Network netWork in availableNetworks)
            {
                if (!Messages.IMPORT_SELECT_NETWORK_PAGE_NETWORK_FILTER.Contains(netWork.Name))
                {
                    var wrapperItem = new ToStringWrapper <XenAPI.Network>(netWork, netWork.Name);

                    if (!cb.Items.Contains(wrapperItem))
                    {
                        cb.Items.Add(wrapperItem);
                    }
                }
            }

            return(cb);
        }
Ejemplo n.º 3
0
        protected override void FinishWizard()
        {
            foreach (KeyValuePair <string, VmMapping> pair in m_vmMappings)
            {
                VM vm = xenConnection.Resolve(new XenRef <VM>(pair.Key));

                Host target = TargetConnection.Resolve(m_vmMappings[pair.Key].XenRef as XenRef <Host>);

                //if a pool has been selected but no specific homeserver Key is the pool opaque ref
                if (target == null)
                {
                    Pool targetPool = TargetConnection.Resolve(m_vmMappings[pair.Key].XenRef as XenRef <Pool>);

                    if (targetPool == null)
                    {
                        ShowErrorMessageBox(Messages.CPM_WIZARD_ERROR_TARGET_DISCONNECTED);
                        base.FinishWizard();
                        return;
                    }

                    target = TargetConnection.Resolve(targetPool.master);
                }

                if (target == null)
                {
                    throw new ApplicationException("Cannot resolve the target host");
                }

                new VMCrossPoolMigrateAction(vm, target, SelectedTransferNetwork, pair.Value).RunAsync();
            }

            base.FinishWizard();
        }
Ejemplo n.º 4
0
        protected override void FinishWizard()
        {
            if (!AllVMsAvailable(m_vmMappings, xenConnection))
            {
                base.FinishWizard();
                return;
            }

            if (wizardMode == WizardMode.Copy && m_pageCopyMode.IntraPoolCopySelected)
            {
                var copyAction = m_pageIntraPoolCopy.GetCopyAction();
                if (copyAction != null)
                {
                    copyAction.RunAsync();
                }
                base.FinishWizard();
                return;
            }

            foreach (KeyValuePair <string, VmMapping> pair in m_vmMappings)
            {
                VM vm = xenConnection.Resolve(new XenRef <VM>(pair.Key));

                Host target = TargetConnection.Resolve(m_vmMappings[pair.Key].XenRef as XenRef <Host>);

                //if a pool has been selected but no specific homeserver Key is the pool opaque ref
                if (target == null)
                {
                    Pool targetPool = TargetConnection.Resolve(m_vmMappings[pair.Key].XenRef as XenRef <Pool>);

                    if (targetPool == null)
                    {
                        ShowErrorMessageBox(Messages.CPM_WIZARD_ERROR_TARGET_DISCONNECTED);
                        base.FinishWizard();
                        return;
                    }

                    target = TargetConnection.Resolve(targetPool.master);
                }

                if (target == null)
                {
                    throw new ApplicationException("Cannot resolve the target host");
                }

                if (wizardMode == WizardMode.Move && IsIntraPoolMove(pair))
                {
                    new VMMoveAction(vm, pair.Value.Storage, target).RunAsync();
                }
                else
                {
                    new VMCrossPoolMigrateAction(vm, target, SelectedTransferNetwork, pair.Value, wizardMode == WizardMode.Copy).RunAsync();
                }
            }

            base.FinishWizard();
        }
        private DataGridViewComboBoxCell FillGridComboBox(object xenRef, List<object> targetRefs, IStorageResource resource, ref List<ToStringWrapper<SR>> commonSRs)
        {
            var cb = new DataGridViewComboBoxCell { FlatStyle = FlatStyle.Flat };

            foreach (var pbd in TargetConnection.Cache.PBDs)
            {
                if (pbd.SR == null)
                    continue;

                var sr = TargetConnection.Resolve(pbd.SR);
                if (sr == null || sr.IsDetached() || !sr.Show(XenAdminConfigManager.Provider.ShowHiddenVMs))
                    continue;

                if ((sr.content_type.ToLower() == "iso" || sr.type.ToLower() == "iso") && !resource.SRTypeInvalid)
                    continue;
                if (sr.content_type.ToLower() != "iso" && resource.SRTypeInvalid)
                    continue;

                bool srOnHost = pbd.host != null && pbd.host.Equals(xenRef);

                if ((sr.shared || srOnHost) &&
                    (!IsExtraSpaceNeeded(resource.SR, sr) ||
                     resource.TryCalcRequiredDiskCapacity(out ulong capacity) && (ulong)sr.FreeSpace() > capacity &&
                     SrsAreSuitable(resource.SR, sr)))
                {
                    var count = (from ToStringWrapper<SR> existingItem in cb.Items
                                 where existingItem.item.opaque_ref == sr.opaque_ref
                                 select existingItem).Count();
                    if (count > 0)
                        continue; //iterating through pbds

                    var newItem = new ToStringWrapper<SR>(sr, GetSRDropDownItemDisplayString);
                    cb.Items.Add(newItem);

                    if (SR.IsDefaultSr(sr))
                        cb.Value = newItem;

                    //store items to populate the m_comboBoxSr

                    if ((sr.shared || (targetRefs.Count == 1 && srOnHost && targetRefs[0].Equals(xenRef))))
                    {
                        var num = (from ToStringWrapper<SR> existingItem in commonSRs
                                   where existingItem.item.opaque_ref == sr.opaque_ref
                                   select existingItem).Count();
                        if (num <= 0)
                            commonSRs.Add(newItem);
                    }
                }
            }
            return cb;
        }
Ejemplo n.º 6
0
        private bool IsIntraPoolMigration(KeyValuePair <string, VmMapping> mapping)
        {
            VM vm = xenConnection.Resolve(new XenRef <VM>(mapping.Key));

            if (vm.resident_on == mapping.Value.XenRef)
            {
                return(true);
            }

            Pool pool = Helpers.GetPool(vm.Connection);

            if (mapping.Value.XenRef is XenRef <Pool> )
            {
                Pool targetPool = TargetConnection.Resolve(mapping.Value.XenRef as XenRef <Pool>);
                if (pool == targetPool)
                {
                    return(true);
                }
            }

            Host host = xenConnection.Resolve(vm.resident_on) ?? Helpers.GetMaster(xenConnection);

            if (mapping.Value.XenRef is XenRef <Host> )
            {
                Host targetHost = TargetConnection.Resolve(mapping.Value.XenRef as XenRef <Host>);
                Pool targetPool = Helpers.GetPool(targetHost.Connection);

                // 2 stand alone hosts
                if (pool == null && targetPool == null)
                {
                    if (targetHost == host)
                    {
                        return(true);
                    }

                    return(false);
                }

                if (pool == targetPool)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 7
0
        private DataGridViewComboBoxCell FillGridComboBox(object xenRef, List <object> targetRefs, IStorageResource resource, ref List <ToStringWrapper <SR> > commonSRs)
        {
            var cb = new DataGridViewComboBoxCell {
                FlatStyle = FlatStyle.Flat
            };

            foreach (var pbd in TargetConnection.Cache.PBDs)
            {
                if (pbd.SR == null)
                {
                    continue;
                }

                var sr = TargetConnection.Resolve(pbd.SR);
                if (sr == null || sr.IsDetached)
                {
                    continue;
                }

                if ((sr.content_type.ToLower() == "iso" || sr.type.ToLower() == "iso") && !resource.SRTypeInvalid)
                {
                    continue;
                }
                if (sr.content_type.ToLower() != "iso" && resource.SRTypeInvalid)
                {
                    continue;
                }

                bool srOnHost = pbd.host != null && pbd.host.Equals(xenRef);

                if ((sr.shared || srOnHost) && (ulong)sr.FreeSpace > resource.RequiredDiskCapacity && SrIsSuitable(sr))
                {
                    var count = (from ToStringWrapper <SR> existingItem in cb.Items
                                 where existingItem.item.opaque_ref == sr.opaque_ref
                                 select existingItem).Count();
                    if (count > 0)
                    {
                        continue;                         //iterating through pbds
                    }
                    var newItem = new ToStringWrapper <SR>(sr, GetSRDropDownItemDisplayString);
                    cb.Items.Add(newItem);

                    if (SR.IsDefaultSr(sr))
                    {
                        cb.Value = newItem;
                    }

                    //store items to populate the m_comboBoxSr
                    //note that at this point the m_totalSpaceRequired is not the final value yet,
                    //but we can add the check to get a smaller list

                    if ((sr.shared || (targetRefs.Count == 1 && srOnHost && targetRefs[0].Equals(xenRef))))
                    {
                        var num = (from ToStringWrapper <SR> existingItem in commonSRs
                                   where existingItem.item.opaque_ref == sr.opaque_ref
                                   select existingItem).Count();
                        if (num <= 0)
                        {
                            commonSRs.Add(newItem);
                        }
                    }
                }
            }
            return(cb);
        }
Ejemplo n.º 8
0
        protected override void FinishWizard()
        {
            if (!AllVMsAvailable(m_vmMappings, xenConnection))
            {
                base.FinishWizard();
                return;
            }

            if (wizardMode == WizardMode.Copy && m_pageCopyMode.IntraPoolCopySelected)
            {
                if (m_pageIntraPoolCopy.CloneVM)
                {
                    new VMCloneAction(m_pageIntraPoolCopy.TheVM, m_pageIntraPoolCopy.NewVmName, m_pageIntraPoolCopy.NewVMmDescription).RunAsync();
                }

                else if (m_pageIntraPoolCopy.SelectedSR != null)
                {
                    new VMCopyAction(m_pageIntraPoolCopy.TheVM, m_pageIntraPoolCopy.TheVM.GetStorageHost(false),
                                     m_pageIntraPoolCopy.SelectedSR, m_pageIntraPoolCopy.NewVmName, m_pageIntraPoolCopy.NewVMmDescription).RunAsync();
                }

                base.FinishWizard();
                return;
            }

            foreach (KeyValuePair <string, VmMapping> pair in m_vmMappings)
            {
                VM vm = xenConnection.Resolve(new XenRef <VM>(pair.Key));

                Host target = TargetConnection.Resolve(m_vmMappings[pair.Key].XenRef as XenRef <Host>);

                //if a pool has been selected but no specific homeserver Key is the pool opaque ref
                if (target == null)
                {
                    Pool targetPool = TargetConnection.Resolve(m_vmMappings[pair.Key].XenRef as XenRef <Pool>);

                    if (targetPool == null)
                    {
                        ShowErrorMessageBox(Messages.CPM_WIZARD_ERROR_TARGET_DISCONNECTED);
                        base.FinishWizard();
                        return;
                    }

                    target = TargetConnection.Resolve(targetPool.master);
                }

                if (target == null)
                {
                    throw new ApplicationException("Cannot resolve the target host");
                }

                if (wizardMode == WizardMode.Move && IsIntraPoolMove(pair))
                {
                    new VMMoveAction(vm, pair.Value.Storage, target).RunAsync();
                }
                else
                {
                    var isCopy        = wizardMode == WizardMode.Copy;
                    var migrateAction =
                        new VMCrossPoolMigrateAction(vm, target, SelectedTransferNetwork, pair.Value, isCopy, m_pageDestination.IsMigrateEncryption());

                    if (_resumeAfterMigrate)
                    {
                        var title            = VMCrossPoolMigrateAction.GetTitle(vm, target, isCopy);
                        var startDescription = isCopy ? Messages.ACTION_VM_COPYING: Messages.ACTION_VM_MIGRATING;
                        var endDescription   = isCopy ? Messages.ACTION_VM_COPIED: Messages.ACTION_VM_MIGRATED;

                        var actions = new List <AsyncAction>()
                        {
                            migrateAction,
                            new ResumeAndStartVMsAction(vm.Connection, target, new List <VM> {
                                vm
                            }, new List <VM>(), null, null)
                        };

                        new MultipleAction(vm.Connection, title, startDescription, endDescription,
                                           actions, true, false, true).RunAsync();
                    }
                    else
                    {
                        migrateAction.RunAsync();
                    }
                }
            }

            base.FinishWizard();
        }