public void BuildList() { PcisdataGridViewExs.Rows.Clear(); if (this.home != null) { string result = XenAPI.Host.call_plugin(home.Connection.Session, home.opaque_ref, "pvusbinfo.py", "list", null); UsbDeviceInfoConfig.PVUsbListResult pvusbresult = null; try { pvusbresult = (UsbDeviceInfoConfig.PVUsbListResult)HalsignUtil.JsonToObject(result, typeof(UsbDeviceInfoConfig.PVUsbListResult)); } catch { return; } for (int i = 0; i < pvusbresult.returnvalue.Count; i++) { PcisdataGridViewExs.Rows.Add(); PcisdataGridViewExs.Rows[i].Tag = pvusbresult.returnvalue[i].id; PcisdataGridViewExs.Rows[i].Cells[0].Value = string.Concat("Bus ", pvusbresult.returnvalue[i].busid); PcisdataGridViewExs.Rows[i].Cells[0].Tag = pvusbresult.returnvalue[i].pciid; PcisdataGridViewExs.Rows[i].Cells[1].Value = pvusbresult.returnvalue[i].shortname + " (" + pvusbresult.returnvalue[i].longname + " )"; if (pvusbresult.returnvalue[i].vm != null) { string vmuuid = pvusbresult.returnvalue[i].vm; VM bindvm = home.Connection.Cache.VMs.First(vm => vm.uuid == vmuuid); PcisdataGridViewExs.Rows[i].Cells[2].Value = bindvm.name_label; PcisdataGridViewExs.Rows[i].Cells[2].Tag = pvusbresult.returnvalue[i].vm; PcisdataGridViewExs.Rows[i].Cells[3].Value = "pvusb"; PcisdataGridViewExs.Rows[i].Cells[3].ReadOnly = true; ((DataGridViewButtonCellEx)(PcisdataGridViewExs.Rows[i].Cells[4])).Bind = false; ((DataGridViewButtonCellEx)(PcisdataGridViewExs.Rows[i].Cells[4])).Enabled = true; } else { VM findvm = home.Connection.Cache.VMs.FirstOrDefault(vm => vm.uuid != null && vm.is_a_real_vm && HalsignHelpers.IsVMShow(vm) && vm.other_config.ContainsKey("pci") && vm.other_config["pci"].Contains(string.Concat("0000:", pvusbresult.returnvalue[i].pciid)) && vm.Home().Equals(home)); if (findvm == null) { PcisdataGridViewExs.Rows[i].Cells[3].Value = "pvusb"; ((DataGridViewButtonCellEx)(PcisdataGridViewExs.Rows[i].Cells[4])).Bind = true; ((DataGridViewButtonCellEx)(PcisdataGridViewExs.Rows[i].Cells[4])).Enabled = true; } else { PcisdataGridViewExs.Rows[i].Cells[2].Value = findvm.name_label; PcisdataGridViewExs.Rows[i].Cells[2].Tag = findvm.uuid; PcisdataGridViewExs.Rows[i].Cells[3].Value = "vt-d"; PcisdataGridViewExs.Rows[i].Cells[3].ReadOnly = true; ((DataGridViewButtonCellEx)(PcisdataGridViewExs.Rows[i].Cells[4])).Bind = false; ((DataGridViewButtonCellEx)(PcisdataGridViewExs.Rows[i].Cells[4])).Enabled = true; } } } } }
void worker_DoWork(object sender, DoWorkEventArgs e) { lock (lockobj) { dtTable.Rows.Clear(); if (this.home != null) { string result = XenAPI.Host.call_plugin(home.Connection.Session, home.opaque_ref, "pvusbinfo.py", "list", null); var ret = (UsbDeviceInfoConfig.PVUsbListResult)HalsignUtil.JsonToObject(result, typeof(UsbDeviceInfoConfig.PVUsbListResult)); foreach (UsbDeviceInfoConfig.USBInfo usbinfo in ret.returnvalue) { DataRow row = dtTable.NewRow(); row["id"] = usbinfo.id; row["pciid"] = usbinfo.pciid; row["bus"] = string.Concat("Bus ", usbinfo.busid); row["devices"] = usbinfo.shortname + " (" + usbinfo.longname + " )"; if (usbinfo.vm != null) { XenRef <VM> vmRef = VM.get_by_uuid(home.Connection.Session, usbinfo.vm); VM bindvm = VM.get_record(home.Connection.Session, vmRef); row["vm_name"] = bindvm.name_label; row["vm_uuid"] = usbinfo.vm; row["usbmode"] = "pvusb"; row["bind"] = false; row["enabled"] = true; } else { VM findvm = home.Connection.Cache.VMs.FirstOrDefault(vm => vm.uuid != null && vm.is_a_real_vm && HalsignHelpers.IsVMShow(vm) && vm.other_config.ContainsKey("pci") && vm.other_config["pci"].Contains(string.Concat("0000:", usbinfo.pciid)) && vm.Home().Equals(home)); if (findvm == null) { row["usbmode"] = "pvusb"; row["bind"] = true; row["enabled"] = true; } else { row["vm_name"] = findvm.name_label; row["vm_uuid"] = findvm.uuid; row["usbmode"] = "vt-d"; row["bind"] = false; row["enabled"] = true; } } dtTable.Rows.Add(row); } } } }
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.Server.Show) { 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); } } } } }
private void BuildVMList(Host home) { VM[] vms = home.Connection.Cache.VMs.Where <VM>(vm => vm.uuid != null && vm.is_a_real_vm && HalsignHelpers.IsVMShow(vm) && (this.mode == "pvusb" ? (home.Connection.Resolve(vm.resident_on) == home) : (vm.Home() == home)) && vm.Home() == home).ToArray(); this.VMsComboBox.DataSource = vms; this.VMsComboBox.DisplayMember = "name_label"; this.VMsComboBox.ValueMember = "uuid"; }
/// <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++; } }