Exemplo n.º 1
0
        private void AddVMsToTree(TreeNode parent, ref int index, IXenConnection connection, VM[] vms, Host TheHost, bool IsPool)
        {
            foreach (VM vm in vms)
            {
                bool is_snapshot = (!vm.is_a_template && HalsignHelpers.IsVMShow(vm) && !(vm.snapshots != null && vm.snapshots.Count > 0) && vm.allowed_operations.Count > 0);
                if (switchSnapshot)
                {
                    is_snapshot = (!vm.is_a_template && HalsignHelpers.IsVMShow(vm) && !(vm.snapshots != null && vm.snapshots.Count > 0) && vm.allowed_operations.Count > 0);
                }
                else
                {
                    is_snapshot = (!vm.is_a_template && HalsignHelpers.IsVMShow(vm) && vm.allowed_operations.Count > 0);
                }

                if (is_snapshot)
                {
                    if ((HalsignHelpers.VMHome(vm) == TheHost) || !IsPool)
                    {
                        if (!vm.name_label.StartsWith("__gui__"))
                        {
                            if (switchSnapshot)
                            {
                                bool hasParent = false;
                                foreach (VBD vbd in vm.Connection.ResolveAll <VBD>(vm.VBDs))
                                {
                                    if (HalsignHelpers.IsCDROM(vbd))
                                    {
                                        continue;
                                    }

                                    VDI vdi = vm.Connection.Resolve <VDI>(vbd.VDI);
                                    if (vdi != null && vdi.Show(true))
                                    {
                                        if (vdi.sm_config.ContainsKey("vhd-parent") && !string.IsNullOrEmpty(vdi.sm_config["vhd-parent"]))
                                        {
                                            hasParent = true;
                                            break;
                                        }
                                    }
                                }
                                if (hasParent)
                                {
                                    continue;
                                }
                            }

                            this.AddVMNode(parent, index, vm);
                            index++;
                            //vmList.Add(vm.uuid, vm);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public virtual void SelectCD()
        {
            if (selectedCD == null)
            {
                if (Items.Count > 0)
                {
                    SelectedIndex = 0;
                }
                else
                {
                    SelectedIndex = -1;
                }

                return;
            }

            foreach (object o in Items)
            {
                ToStringWrapper <VDI> vdiNameWrapper = o as ToStringWrapper <VDI>;

                if (vdiNameWrapper == null)
                {
                    continue;
                }

                VDI iso = vdiNameWrapper.item;
                if (iso == null || !iso.Show(Properties.Settings.Default.ShowHiddenVMs))
                {
                    continue;
                }

                if (iso == selectedCD)
                {
                    SelectedItem = o;
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private void BuildList()
        {
            Program.AssertOnEventThread();
            if (!this.Visible)
            {
                return;
            }
            try
            {
                dataGridViewStorage.SuspendLayout();
                DataGridViewSelectedRowCollection vbdSavedItems = dataGridViewStorage.SelectedRows;

                dataGridViewStorage.Rows.Clear();

                if (vm == null)
                {
                    return;
                }

                bool storageLinkColumnVisible = false;

                List <bool> devices_in_use = new List <bool>();
                foreach (VBD vbd in vm.Connection.ResolveAll(vm.VBDs))
                {
                    vbd.PropertyChanged -= new PropertyChangedEventHandler(vbd_PropertyChanged);
                    vbd.PropertyChanged += new PropertyChangedEventHandler(vbd_PropertyChanged);

                    if (!vbd.IsCDROM && !vbd.IsFloppyDrive)
                    {
                        VDI vdi = vm.Connection.Resolve(vbd.VDI);
                        if (vdi == null || !vdi.Show(Properties.Settings.Default.ShowHiddenVMs))
                        {
                            continue;
                        }

                        SR sr = vm.Connection.Resolve(vdi.SR);
                        if (sr == null || sr.IsToolsSR)
                        {
                            continue;
                        }

                        storageLinkColumnVisible = vdi.sm_config.ContainsKey("SVID");

                        vdi.PropertyChanged -= new PropertyChangedEventHandler(vdi_PropertyChanged);
                        vdi.PropertyChanged += new PropertyChangedEventHandler(vdi_PropertyChanged);

                        dataGridViewStorage.Rows.Add(new VBDRow(vbd, vdi, sr));

                        int i;
                        if (int.TryParse(vbd.userdevice, out i))
                        {
                            while (devices_in_use.Count <= i)
                            {
                                devices_in_use.Add(false);
                            }
                            devices_in_use[i] = true;
                        }
                    }

                    //CA-47050: the dnsColumn should be autosized to Fill, but should not become smaller than a minimum
                    //width, which is chosen to be the column's contents (including header) width. To find what this is
                    //set temporarily the column's autosize mode to AllCells.
                    HelpersGUI.ResizeLastGridViewColumn(ColumnDevicePath);
                }


                storageLinkColumn.Visible = storageLinkColumnVisible;
                dataGridViewStorage.Sort(dataGridViewStorage.SortedColumn, dataGridViewStorage.SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending);

                IEnumerable <VBD> vbdsSelected = from VBDRow row in vbdSavedItems select row.VBD;
                foreach (VBDRow row in dataGridViewStorage.Rows)
                {
                    row.Selected = vbdsSelected.Contains(row.VBD);
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("Exception building VM storage list: {0}", e.Message);
            }
            finally
            {
                dataGridViewStorage.ResumeLayout();
            }
            UpdateButtons();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 1. Check that how many VDIs were checked for replication
        /// 2. Check whether the vms on destination host have the same amount of vdis on destination host
        /// 3. Check whether the vdis have key "src_vdi_uuid"
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="index"></param>
        /// <param name="vms"></param>
        private void AddVmsToTree(TreeNode parent, ref int index, List <VM> vms)
        {
            VM[] vMs =
                this.selected_xenConnection.Cache.VMs.Where(
                    vm =>
                    (vm.uuid != null && vm.is_a_real_vm && HalsignHelpers.VMHome(vm) != null &&
                     HalsignHelpers.VMHome(vm) == this.selected_host)).ToArray();

            foreach (VM vm in vms)
            {
                TreeNode nodeSelectedVM = this.AddVMNodes(parent, index, vm);
                TreeNode newNode        = new TreeNode(Messages.NEW_REPLICATION);
                newNode.ImageIndex         = 999;
                newNode.SelectedImageIndex = 999;
                newNode.Tag     = "new";
                newNode.Checked = true;
                nodeSelectedVM.Nodes.Add(newNode);
                List <string> sourceVdiList = this.vdiCheckedDic[vm.uuid].Split(new string[] { "@" }, StringSplitOptions.RemoveEmptyEntries).ToList <string>();

                foreach (VM tempVm in vMs)
                {
                    bool isOperationAllowed = (!tempVm.is_a_template && HalsignHelpers.IsVMShow(tempVm) && tempVm.allowed_operations.Count > 0);
                    if (isOperationAllowed)
                    {
                        List <VDI> destVdiList = new List <VDI>();
                        foreach (VBD vbd in tempVm.Connection.ResolveAll <VBD>(tempVm.VBDs).ToArray())
                        {
                            if (HalsignHelpers.IsCDROM(vbd))
                            {
                                continue;
                            }
                            VDI vdi = tempVm.Connection.Resolve(vbd.VDI);
                            SR  sr  = tempVm.Connection.Resolve(vdi.SR);
                            if (vdi != null && vdi.Show(true) && !string.IsNullOrEmpty(vdi.uuid) && (sr != null && sr.uuid == this.selected_sr_uuid))
                            {
                                if (null != vdi.uuid && !vdi.uuid.Equals(""))
                                {
                                    destVdiList.Add(vdi);
                                }
                            }
                        }
                        if (sourceVdiList.Count == destVdiList.Count)
                        {
                            int vdiiNo = 0;
                            foreach (VDI vdii in destVdiList)
                            {
                                if (vdii.other_config.ContainsKey("src_vdi_uuid"))
                                {
                                    foreach (string uuid in sourceVdiList)
                                    {
                                        if (vdii.other_config["src_vdi_uuid"].Equals(uuid))
                                        {
                                            vdiiNo++;
                                        }
                                    }
                                }
                            }
                            if (vdiiNo == destVdiList.Count)
                            {
                                TreeNode nodeTemp = new TreeNode(tempVm.name_label);
                                nodeTemp.ImageIndex         = 999;
                                nodeTemp.SelectedImageIndex = 999;
                                nodeTemp.Tag = new ReplicatedVmState(tempVm.uuid, tempVm.power_state == vm_power_state.Running);
                                nodeSelectedVM.Nodes.Add(nodeTemp);
                            }
                        }
                    }
                }
                index++;
            }
        }