예제 #1
0
        public DestroyDiskAction(VDI disk)
            : base(disk.Connection, string.Format(Messages.ACTION_DISK_DELETING_TITLE, disk.Name, disk.Connection.Resolve<SR>(disk.SR).NameWithoutHost), false)
        {
            Disk = disk;
            Disk.Locked = true;

            #region RBAC Dependencies
            ApiMethodsToRoleCheck.Add("vbd.unplug");
            ApiMethodsToRoleCheck.Add("vbd.destroy");
            ApiMethodsToRoleCheck.Add("vdi.destroy");
            #endregion

            SR = Connection.Resolve(Disk.SR);

            // If there is only one VM involved here we can filter it under the VM
            // Otherwise just filter under the SR
            VM relevantVM = null;
            foreach (VBD vbd in SR.Connection.ResolveAll(Disk.VBDs))
            {
                VM vm = SR.Connection.Resolve<VM>(vbd.VM);
                if (vm == null)
                    continue;
                if (relevantVM == null)
                    relevantVM = vm;
                else
                {
                    // more than one relevant VM, just give it the SR as an owner
                    relevantVM = null;
                    break;
                }
            }
            if (relevantVM != null)
                VM = relevantVM;
        }
예제 #2
0
        protected override void Run()
        {
            Description     = string.Format(Messages.ACTION_MOVING_VDI_STATUS, Helpers.GetName(vdi));
            PercentComplete = 10;
            log.DebugFormat("Moving VDI '{0}'", Helpers.GetName(vdi));
            RelatedTask = XenAPI.VDI.async_copy(Session, vdi.opaque_ref, SR.opaque_ref);
            PollToCompletion(PercentComplete, 60);
            XenAPI.VDI newVDI = Connection.WaitForCache(new XenRef <VDI>(Result));

            // if the original is a suspend VDI, link the suspended VM to the new VDI
            if (vdi.type == vdi_type.suspend)
            {
                var suspendedVm = (from vm in Connection.Cache.VMs
                                   let suspendVdi = Connection.Resolve <VDI>(vm.suspend_VDI)
                                                    where suspendVdi != null && suspendVdi.uuid == vdi.uuid
                                                    select vm).FirstOrDefault();
                if (suspendedVm != null)
                {
                    XenAPI.VM.set_suspend_VDI(Session, suspendedVm.opaque_ref, newVDI.opaque_ref);
                }
            }
            PercentComplete = 70;

            XenAPI.VDI.destroy(Session, vdi.opaque_ref);
            PercentComplete = 100;
            Description     = Messages.COMPLETED;
            log.DebugFormat("Moved VDI '{0}'", Helpers.GetName(vdi));
        }
예제 #3
0
 public MigrateVirtualDiskAction(IXenConnection connection, VDI vdi, SR sr)
     : base(connection, string.Format(Messages.ACTION_MOVING_VDI_TITLE, Helpers.GetName(vdi), Helpers.GetName(sr)))
 {
     Description = Messages.ACTION_PREPARING;
     this.vdi = vdi;
     SR = sr;
 }
예제 #4
0
        protected override void Run()
        {
            // check the xstools sr is present, if not try and repair it
            foreach (SR sr in VM.Connection.Cache.SRs)
            {
                if (sr.IsToolsSR && sr.IsBroken())
                {
                    try
                    {
                        SrRepairAction action = new SrRepairAction(sr.Connection, sr, false);
                        action.RunExternal(Session);
                    }
                    catch (Failure)
                    {
                        _xsToolsNotFound();
                    }
                }
            }

            // Check the version (if any) of the PV tools already on this host...
            VM_guest_metrics guestMetrics = Connection.Resolve(VM.guest_metrics);

            if (guestMetrics != null && !VM.HasNewVirtualisationStates && guestMetrics.PV_drivers_up_to_date)
            {
                this.Description = Messages.INSTALLTOOLS_EXIST;
                return;
            }

            // Check that the VM has a cd-rom...
            XenAPI.VBD cdrom = VM.FindVMCDROM();
            if (cdrom == null)
            {
                Description = Messages.INSTALLTOOLS_COULDNOTFIND_CD;
                return;
            }

            // Find the tools ISO...
            XenAPI.VDI winIso = findWinISO(_searchHiddenIsOs);
            if (winIso == null)
            {
                // Could not find the windows PV drivers ISO.
                Description = Messages.INSTALLTOOLS_COULDNOTFIND_WIN;
                return;
            }

            Description = Messages.INSTALLTOOLS_STARTING;

            // Eject anything that's currently in the cd-rom...
            if (!cdrom.empty)
            {
                XenAPI.VBD.eject(Session, cdrom.opaque_ref);
            }

            // Insert the tools ISO...
            XenAPI.VBD.insert(Session, cdrom.opaque_ref, winIso.opaque_ref);

            // done(ish)...
            Description = Messages.INSTALLTOOLS_DONE;
        }
예제 #5
0
 public VdiOpenDatabaseAction(IXenConnection connection, VDI vdi)
     : base(connection, String.Format(Messages.ACTION_VDI_OPEN_DATABASE_TITLE, connection.Resolve(vdi.SR).Name))
 {
     _vdi = vdi;
     #region RBAC Dependencies
     ApiMethodsToRoleCheck.Add("VDI.open_database");
     ApiMethodsToRoleCheck.Add("Session.get_record");
     #endregion
 }
 public VDIRow(XenAPI.VDI vdi, bool showStorageLink)
 {
     this.showStorageLink = showStorageLink;
     this.VDI             = vdi;
     for (int i = 0; i < 5; i++)
     {
         base.Cells.Add(new DataGridViewTextBoxCell());
         base.Cells[i].Value = this.GetCellText(i);
     }
 }
예제 #7
0
 public MoveVirtualDiskDialog(VDI vdi) : this(vdi.Connection)
 {
     this.vdi = vdi;
     srPicker1.SetUsageAsMovingVDI(new[] {vdi});
     srPicker1.SrHint.Visible = false;
     srPicker1.Connection = vdi.Connection;
     srPicker1.DiskSize = vdi.virtual_size;
     srPicker1.srListBox.Invalidate();
     srPicker1.selectDefaultSROrAny();
     SetupEventHandlers();
 }
예제 #8
0
파일: LocalCD.cs 프로젝트: huizh/xenadmin
        protected override AsyncAction CreateAction(out bool cancelled)
        {
            cancelled = false;
            VBD cddrive = VM.FindVMCDROM();

            if (cddrive != null)
            {
                LoadedCD = VM.Connection.Resolve(cddrive.VDI);
            }

            return new ChangeVMISOAction(VM.Connection, VM, null, cddrive);
        }
예제 #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="vm"></param>
        /// <param name="vdi">May be null, indicating that the CD should be ejected (i.e. set to empty).</param>
        /// <param name="cdrom">Must not be null.</param>
        public ChangeVMISOAction(IXenConnection connection, VM vm,
            VDI vdi, VBD cdrom)
            : base(connection, vdi == null ? String.Format(Messages.ISO_UNLOADING, vm.Name) :
            String.Format(Messages.ISO_LOADING, vdi.Name, vm.Name))
        {
            this.VM = vm;
            this.vdi = vdi;
            this.cdrom = cdrom;

            System.Diagnostics.Trace.Assert(this.cdrom != null, "ChangeVMISOAction ctor: cdrom vbd must not be null");
            System.Diagnostics.Trace.Assert(this.VM != null, "ChangeVMISOAction ctor: VM must not be null");
        }
예제 #10
0
 public MoveVirtualDiskAction(IXenConnection connection, XenAPI.VDI vdi, SR sr)
     : base(connection, string.Format(Messages.ACTION_MOVING_VDI_TITLE, Helpers.GetName(vdi), Helpers.GetName(sr)))
 {
     this.vdi = vdi;
     SR = sr;
     vdi.Locked = true;
     sr.Locked = true;
     ApiMethodsToRoleCheck.Add("vdi.destroy");
     ApiMethodsToRoleCheck.Add("vdi.copy");
     if (vdi.type == vdi_type.suspend)
         ApiMethodsToRoleCheck.Add("vm.set_suspend_VDI");
     ApiMethodsToRoleCheck.AddRange(Role.CommonTaskApiList);
     ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList);
 }
예제 #11
0
        /// <summary>
        /// Arguments should never be null
        /// </summary>
        public VBDRow(VBD vbd, VDI vdi, SR sr)
        {
            Debug.Assert(vbd != null && vdi != null && sr != null, "vbd, vdi and sr must be set to a non-null value");

            VBD = vbd;
            VDI = vdi;
            SR = sr;

            for (int i = 0; i < 10; i++)
            {
                DataGridViewTextBoxCell c = new DataGridViewTextBoxCell();
                c.Value = CellValue(i);
                Cells.Add(c);
            }
        }
 public MoveVirtualDiskAction(IXenConnection connection, XenAPI.VDI vdi, SR sr)
     : base(connection, string.Format(Messages.ACTION_MOVING_VDI_TO_SR, Helpers.GetName(vdi), Helpers.GetName(sr)))
 {
     this.vdi   = vdi;
     SR         = sr;
     vdi.Locked = true;
     sr.Locked  = true;
     ApiMethodsToRoleCheck.Add("vdi.destroy");
     ApiMethodsToRoleCheck.Add("vdi.copy");
     if (vdi.type == vdi_type.suspend)
     {
         ApiMethodsToRoleCheck.Add("vm.set_suspend_VDI");
     }
     ApiMethodsToRoleCheck.AddRange(Role.CommonTaskApiList);
     ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList);
 }
        private void ProcessRecordSnapshotOf(string vdi)
        {
            RunApiCall(() =>
            {
                string objRef = XenAPI.VDI.get_snapshot_of(session, vdi);

                XenAPI.VDI obj = null;

                if (objRef != "OpaqueRef:NULL")
                {
                    obj            = XenAPI.VDI.get_record(session, objRef);
                    obj.opaque_ref = objRef;
                }

                WriteObject(obj, true);
            });
        }
        private void ProcessRecordRedoLogVdi(string pool)
        {
            RunApiCall(() =>
            {
                string objRef = XenAPI.Pool.get_redo_log_vdi(session, pool);

                XenAPI.VDI obj = null;

                if (objRef != "OpaqueRef:NULL")
                {
                    obj            = XenAPI.VDI.get_record(session, objRef);
                    obj.opaque_ref = objRef;
                }

                WriteObject(obj, true);
            });
        }
예제 #15
0
        private void ProcessRecordVDI(string pvs_cache_storage)
        {
            RunApiCall(() =>
            {
                string objRef = XenAPI.PVS_cache_storage.get_VDI(session, pvs_cache_storage);

                XenAPI.VDI obj = null;

                if (objRef != "OpaqueRef:NULL")
                {
                    obj            = XenAPI.VDI.get_record(session, objRef);
                    obj.opaque_ref = objRef;
                }

                WriteObject(obj, true);
            });
        }
예제 #16
0
        private void ProcessRecordPoolMigrate(string vdi)
        {
            if (!ShouldProcess(vdi, "VDI.pool_migrate"))
            {
                return;
            }

            RunApiCall(() =>
            {
                var contxt = _context as XenVDIActionPoolMigrateDynamicParameters;

                if (contxt != null && contxt.Async)
                {
                    taskRef = XenAPI.VDI.async_pool_migrate(session, vdi, contxt.SR, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(contxt.Options));

                    if (PassThru)
                    {
                        XenAPI.Task taskObj = null;
                        if (taskRef != "OpaqueRef:NULL")
                        {
                            taskObj            = XenAPI.Task.get_record(session, taskRef.opaque_ref);
                            taskObj.opaque_ref = taskRef.opaque_ref;
                        }

                        WriteObject(taskObj, true);
                    }
                }
                else
                {
                    string objRef = XenAPI.VDI.pool_migrate(session, vdi, contxt.SR, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(contxt.Options));

                    if (PassThru)
                    {
                        XenAPI.VDI obj = null;

                        if (objRef != "OpaqueRef:NULL")
                        {
                            obj            = XenAPI.VDI.get_record(session, objRef);
                            obj.opaque_ref = objRef;
                        }

                        WriteObject(obj, true);
                    }
                }
            });
        }
예제 #17
0
        private void ProcessRecordCopy(string vdi)
        {
            if (!ShouldProcess(vdi, "VDI.copy"))
            {
                return;
            }

            RunApiCall(() =>
            {
                var contxt = _context as XenVDIActionCopyDynamicParameters;

                if (contxt != null && contxt.Async)
                {
                    taskRef = XenAPI.VDI.async_copy(session, vdi, contxt.SR, contxt.BaseVdi, contxt.IntoVdi);

                    if (PassThru)
                    {
                        XenAPI.Task taskObj = null;
                        if (taskRef != "OpaqueRef:NULL")
                        {
                            taskObj            = XenAPI.Task.get_record(session, taskRef.opaque_ref);
                            taskObj.opaque_ref = taskRef.opaque_ref;
                        }

                        WriteObject(taskObj, true);
                    }
                }
                else
                {
                    string objRef = XenAPI.VDI.copy(session, vdi, contxt.SR, contxt.BaseVdi, contxt.IntoVdi);

                    if (PassThru)
                    {
                        XenAPI.VDI obj = null;

                        if (objRef != "OpaqueRef:NULL")
                        {
                            obj            = XenAPI.VDI.get_record(session, objRef);
                            obj.opaque_ref = objRef;
                        }

                        WriteObject(obj, true);
                    }
                }
            });
        }
예제 #18
0
        private void ProcessRecordDbIntroduce(string vdi)
        {
            if (!ShouldProcess(vdi, "VDI.db_introduce"))
            {
                return;
            }

            RunApiCall(() =>
            {
                var contxt = _context as XenVDIActionDbIntroduceDynamicParameters;

                if (contxt != null && contxt.Async)
                {
                    taskRef = XenAPI.VDI.async_db_introduce(session, contxt.UuidParam, contxt.NameLabel, contxt.NameDescription, contxt.SR, contxt.Type, contxt.Sharable, contxt.ReadOnly, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(contxt.OtherConfig), contxt.Location, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(contxt.XenstoreData), CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(contxt.SmConfig), contxt.Managed, contxt.VirtualSize, contxt.PhysicalUtilisation, contxt.MetadataOfPool, contxt.IsASnapshot, contxt.SnapshotTime, contxt.SnapshotOf, contxt.CbtEnabled);

                    if (PassThru)
                    {
                        XenAPI.Task taskObj = null;
                        if (taskRef != "OpaqueRef:NULL")
                        {
                            taskObj            = XenAPI.Task.get_record(session, taskRef.opaque_ref);
                            taskObj.opaque_ref = taskRef.opaque_ref;
                        }

                        WriteObject(taskObj, true);
                    }
                }
                else
                {
                    string objRef = XenAPI.VDI.db_introduce(session, contxt.UuidParam, contxt.NameLabel, contxt.NameDescription, contxt.SR, contxt.Type, contxt.Sharable, contxt.ReadOnly, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(contxt.OtherConfig), contxt.Location, CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(contxt.XenstoreData), CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(contxt.SmConfig), contxt.Managed, contxt.VirtualSize, contxt.PhysicalUtilisation, contxt.MetadataOfPool, contxt.IsASnapshot, contxt.SnapshotTime, contxt.SnapshotOf, contxt.CbtEnabled);

                    if (PassThru)
                    {
                        XenAPI.VDI obj = null;

                        if (objRef != "OpaqueRef:NULL")
                        {
                            obj            = XenAPI.VDI.get_record(session, objRef);
                            obj.opaque_ref = objRef;
                        }

                        WriteObject(obj, true);
                    }
                }
            });
        }
예제 #19
0
        private void ProcessRecordVDI(string crashdump)
        {
            RunApiCall(() =>
            {
                string objRef = XenAPI.Crashdump.get_VDI(session, crashdump);

                XenAPI.VDI obj = null;

                if (objRef != "OpaqueRef:NULL")
                {
                    obj            = XenAPI.VDI.get_record(session, objRef);
                    obj.opaque_ref = objRef;
                }

                WriteObject(obj, true);
            });
        }
예제 #20
0
 /// <summary>
 /// Detaches a virtual disk
 /// </summary>
 /// <param name="disk">The VDI to detach</param>
 /// <param name="vm">The VM to detach it from</param>
 /// <param name="takeVDILock">Whether it is necessary to lock the VDI (we may be part of another disk action)</param>
 public DetachVirtualDiskAction(VDI disk, VM vm, bool takeVDILock)
     : base(disk.Connection, string.Format(Messages.ACTION_DISK_DETACHING_TITLE, disk.Name, vm.Name, false))
 {
     this.takeVDILock = takeVDILock;
     vdi = disk;
     if (takeVDILock)
         vdi.Locked = true;
     VM = vm;
     VM.Locked = true;
     foreach (VBD v in Connection.ResolveAll<VBD>(VM.VBDs))
     {
         if (v.VDI.opaque_ref == vdi.opaque_ref)
         {
             vbd = v;
             vbd.Locked = true;
         }
     }
 }
예제 #21
0
        public virtual void SelectCD()
        {
            if (selectedCD == null)
            {
                if (Items.Count > 0)
                {
                    this.SelectedIndex = 0;
                }
                else
                {
                    this.SelectedIndex = -1;
                }

                return;
            }

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

                if (vdiNameWrapper == null)
                {
                    continue;
                }

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

                if (iso == selectedCD)
                {
                    this.SelectedItem = o;
                    break;
                }
            }
        }
        private void InstallSuppPack(Host host, VDI vdi)
        {
            // Set the correct connection object, for RecomputeCanCancel
            Connection = host.Connection;
            Session session = host.Connection.DuplicateSession();

            try
            {
                Description = String.Format(Messages.APPLYING_PATCH, vdi.Name, host.Name);
                Host.call_plugin(session, host.opaque_ref, "install-supp-pack", "install", new Dictionary<string, string> { { "vdi", vdi.uuid } });
                Description = String.Format(Messages.PATCH_APPLIED, vdi.Name, host.Name);
            }
            catch (Failure failure)
            {
                log.ErrorFormat("Plugin call install-supp-pack.install({0}) on {1} failed with {2}", vdi.uuid, host.Name, failure.Message);
                log.ErrorFormat("Supplemental pack installation error description: {0}", string.Join(";", failure.ErrorDescription));
                throw new SupplementalPackInstallFailedException(string.Format(Messages.SUPP_PACK_INSTALL_FAILED, vdi.Name, host.Name), failure);
            }
            finally
            {
                Connection = null;
            }
        }
        private void InstallSuppPack(Host host, VDI vdi)
        {
            // Set the correct connection object, for RecomputeCanCancel
            Connection = host.Connection;
            Session session = host.Connection.DuplicateSession();

            try
            {
                Description = String.Format(Messages.APPLYING_PATCH, vdi.Name, host.Name);
                Host.call_plugin(session, host.opaque_ref, "install-supp-pack", "install", new Dictionary<string, string> { { "vdi", vdi.uuid } });
                Description = String.Format(Messages.PATCH_APPLIED, vdi.Name, host.Name);
            }
            catch (Failure failure)
            {
                log.WarnFormat("Plugin call install-supp-pack.install({0}) on {1} failed with {2}", vdi.uuid, host.Name,
                               failure.Message);
                throw;
            }
            finally
            {
                Connection = null;
            }
        }
예제 #24
0
 private SR GetSR(VDI vdi)
 {
     return vdi.Connection.Resolve(vdi.SR);
 }
예제 #25
0
 public MigrateVirtualDiskCommand(IMainWindow mainWindow, VDI vdi)
     : base(mainWindow, vdi)
 {
 }
예제 #26
0
 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;
 }
예제 #27
0
파일: PBD.cs 프로젝트: wranders/xenadmin
        public static void CheckPlugPBDsForVMs(IXenConnection connection, List <XenRef <VM> > vmRefs, bool ignoreFailure = false)
        {
            var pbds = new List <PBD>();

            foreach (XenRef <VM> vmRef in vmRefs)
            {
                VM vm = connection.TryResolveWithTimeout(vmRef);

                foreach (var vbdRef in vm.VBDs)
                {
                    var vbd = connection.Resolve(vbdRef);
                    if (vbd == null)
                    {
                        continue;
                    }

                    VDI vdi = connection.Resolve(vbd.VDI);
                    if (vdi == null)
                    {
                        continue;
                    }

                    SR sr = connection.Resolve(vdi.SR);
                    if (sr == null)
                    {
                        continue;
                    }

                    foreach (var pbdRef in sr.PBDs)
                    {
                        var pbd = connection.Resolve(pbdRef);
                        if (pbd != null && !pbds.Contains(pbd))
                        {
                            pbds.Add(pbd);
                        }
                    }
                }
            }

            foreach (PBD pbd in pbds)
            {
                Session session = pbd.Connection.DuplicateSession();

                log.DebugFormat("Waiting for PBDs {0} to become plugged", pbd.Name());
                // Wait 2 min for PBD to become plugged
                if (WaitForPlug(session, pbd.opaque_ref))
                {
                    continue;
                }

                // if it's still unplugged, try plugging it - this will probably
                // fail, but at least we'll get a better error message.
                try
                {
                    log.DebugFormat("Plugging PBD {0}", pbd.Name());
                    plug(session, pbd.opaque_ref);
                }
                catch (Exception e)
                {
                    log.Debug(string.Format("Error plugging PBD {0}", pbd.Name()), e);

                    if (!ignoreFailure)
                    {
                        throw;
                    }
                }
            }
        }
예제 #28
0
        private bool CanBeMoved(VDI vdi)
        {
            if (vdi == null || vdi.is_a_snapshot || vdi.Locked || vdi.IsHaType)
                return false;
            if (vdi.VBDs.Count != 0)
                return false;

            SR sr = vdi.Connection.Resolve(vdi.SR);
            if (sr == null || sr.HBALunPerVDI)
                return false;

            return true;
        }
예제 #29
0
파일: SR.cs 프로젝트: robhoes/xenadmin
        public Dictionary <VM, Dictionary <VDI, String> > GetMultiPathStatusLunPerVDI()
        {
            Dictionary <VM, Dictionary <VDI, String> > result =
                new Dictionary <VM, Dictionary <VDI, String> >();

            if (Connection == null)
            {
                return(result);
            }

            foreach (PBD pbd in Connection.ResolveAll(PBDs))
            {
                if (!pbd.MultipathActive)
                {
                    continue;
                }

                foreach (KeyValuePair <String, String> kvp in pbd.other_config)
                {
                    if (!kvp.Key.StartsWith(MPATH))
                    {
                        continue;
                    }

                    int current;
                    int max;
                    if (!PBD.ParsePathCounts(kvp.Value, out current, out max))
                    {
                        continue;
                    }

                    String scsiIdKey = String.Format("scsi-{0}", kvp.Key.Substring(MPATH.Length + 1));
                    if (!sm_config.ContainsKey(scsiIdKey))
                    {
                        continue;
                    }

                    String vdiUUID = sm_config[scsiIdKey];
                    VDI    vdi     = null;

                    foreach (VDI candidate in Connection.ResolveAll(VDIs))
                    {
                        if (candidate.uuid != vdiUUID)
                        {
                            continue;
                        }

                        vdi = candidate;
                        break;
                    }

                    if (vdi == null)
                    {
                        continue;
                    }

                    foreach (VBD vbd in Connection.ResolveAll(vdi.VBDs))
                    {
                        VM vm = Connection.Resolve(vbd.VM);
                        if (vm == null)
                        {
                            continue;
                        }

                        if (vm.power_state != vm_power_state.Running)
                        {
                            continue;
                        }

                        if (!result.ContainsKey(vm))
                        {
                            result[vm] = new Dictionary <VDI, String>();
                        }

                        result[vm][vdi] = kvp.Value;
                    }
                }
            }

            return(result);
        }
예제 #30
0
        private void LoadPoolMetadata(VDI vdi)
        {
            Session metadataSession = null;
            try
            {
                VdiLoadMetadataAction action = new VdiLoadMetadataAction(Connection, vdi);
                ActionProgressDialog dialog = new ActionProgressDialog(action, ProgressBarStyle.Marquee);
                dialog.ShowDialog(this); //Will block until dialog closes, action completed

                if (action.Succeeded && action.MetadataSession != null)
                {
                    metadataSession = action.MetadataSession;
                    XenRef<VDI> vdiRef = new XenRef<VDI>(vdi);
                    if (action.PoolMetadata != null && !allPoolMetadata.ContainsKey(vdiRef))
                    {
                        allPoolMetadata.Add(vdiRef, action.PoolMetadata);
                    }
                }

            }
            finally
            {
                if (metadataSession != null)
                    metadataSession.logout();
            }
        }
예제 #31
0
        public static string vdiMemoryUsageString(VDI vdi)
        {
            long total = vdi.virtual_size;

            if (total == 0)
                return Messages.HYPHEN;

            return Util.MemorySizeString(total);
        }
예제 #32
0
 public LunPerVdiPickerItemWrapper(SR LUNsourceSr, VDI vdi) : base(LUNsourceSr, vdi)
 {
 }
예제 #33
0
        public DiskGridRowItem(IXenConnection connection, VDI vdi, VBD vbd, bool isNew, Host affinity)
        {
            SourceDisk = vdi;
            Disk = new VDI();
            Device = new VBD();
            Connection = connection;

            Disk.virtual_size = vdi.virtual_size;
            SR sr = GetBeskDiskStorage(Connection, Disk.virtual_size, affinity, Connection.Resolve(vdi.SR));
            Disk.SR = new XenRef<SR>(sr != null ? sr.opaque_ref : Helper.NullOpaqueRef);
            Disk.type = vdi.type;
            Device.userdevice = vbd.userdevice;
            Device.bootable = vbd.bootable;

            Disk.name_label = vdi.name_label;
            Disk.read_only = vdi.read_only;
            Disk.name_description = vdi.name_description;
            Device.mode = vbd.mode;

            CanDelete = Disk.type == vdi_type.user && isNew;
            CanResize = isNew;
            MinSize = 0;

            AddCells();
        }
예제 #34
0
        private XenRef<VDI> CreateVDI(Session xenSession, string sruuid, string label, long capacity, string description)
        {
            Hashtable vdiHash = new Hashtable();
            vdiHash.Add("uuid", Guid.NewGuid().ToString());
            vdiHash.Add("name_label", label);
            vdiHash.Add("name_description", description);
            if (sruuid.ToLower().StartsWith("opaque"))
            {
                vdiHash.Add("SR", sruuid);
            }
            else
            {
                vdiHash.Add("SR", SR.get_by_uuid(xenSession, sruuid).opaque_ref);
            }
            vdiHash.Add("virtual_size", Convert.ToString(capacity));
            vdiHash.Add("physical_utilisation", Convert.ToString(capacity));
            vdiHash.Add("type", "user");
            vdiHash.Add("shareable", false);
            vdiHash.Add("read_only", false);
            vdiHash.Add("storage_lock", false);
            vdiHash.Add("managed", true);
            vdiHash.Add("is_a_snapshot", false);

            VDI vdi = new VDI(vdiHash);
            XenRef<VDI> vdiRef = null;
            try
            {
                // Note that XenServer will round the capacity up to the nearest multiple of a 2 MB block.
                vdiRef = VDI.create(xenSession, vdi);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("{0} {1}", Messages.ERROR_CANNOT_CREATE_VDI, ex.Message);
                throw new Exception(Messages.ERROR_CANNOT_CREATE_VDI, ex);
            }
            log.Debug("Import.CeateVDI::VDI Created");
            return vdiRef;
        }
예제 #35
0
파일: SrPicker.cs 프로젝트: ktz666/xenadmin
 public void SetUsageAsMigrateVDI(VDI[] vdis)
 {
     usage = SRPickerType.Migrate;
     existingVDIs = vdis;
 }
예제 #36
0
 public static Icons GetIconFor(VDI vdi)
 {
     if (vdi.is_a_snapshot)
         return Icons.VDISnapshot;
     else
         return Icons.VDI;
 }
예제 #37
0
 public VDIRow(VDI vdi, bool showStorageLink)
 {
     this.showStorageLink = showStorageLink;
     VDI = vdi;
     for (int i = 0; i < 5; i++)
     {
         Cells.Add(new DataGridViewTextBoxCell());
         Cells[i].Value = GetCellText(i);
     }
 }
예제 #38
0
 public LunPerVdiPickerItem(SR LUNsourceSr, VDI vdi)
 {
     Vdi = vdi;
     Sr = LUNsourceSr;
     LunConstraints = new List<Predicate<VDI>> { v => Vdi != null && v.virtual_size < Vdi.virtual_size };
 }
예제 #39
0
        private XenRef<VDI> UploadRawVDI(Session xenSession, string sruuid, string label, Stream filestream, long capacity, string description)
        {
            log.Debug("OVF.Import.UploadRawVDI Enter");
            log.DebugFormat("OVF.Import.UpdoadRadVDI SRUUID: {0}", sruuid);
            log.DebugFormat("OVF.Import.UpdoadRadVDI Label: {0}", label);
            log.DebugFormat("OVF.Import.UpdoadRadVDI Capacity: {0}", capacity);

            #region CREATE A VDI
            Hashtable vdiHash = new Hashtable();
            vdiHash.Add("uuid", Guid.NewGuid().ToString());
            vdiHash.Add("name_label", label);
            vdiHash.Add("name_description", description);
            if (sruuid.ToLower().StartsWith("opaque"))
            {
                vdiHash.Add("SR", sruuid);
            }
            else
            {
                vdiHash.Add("SR", SR.get_by_uuid(xenSession, sruuid).opaque_ref);
            }
            vdiHash.Add("virtual_size", Convert.ToString(capacity + (2 * MB))); // Add 2MB, VDIs appear to round down making it too small.
            vdiHash.Add("physical_utilisation", Convert.ToString(capacity + (2 * MB)));
            vdiHash.Add("type", "user");
            vdiHash.Add("shareable", false);
            vdiHash.Add("read_only", false);
            vdiHash.Add("storage_lock", false);
            vdiHash.Add("managed", true);
            vdiHash.Add("is_a_snapshot", false);

            VDI vdi = new VDI(vdiHash);
            XenRef<VDI> vdiRef = null;
            try
            {
                vdiRef = VDI.create(xenSession, vdi);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("{0} {1}", Messages.ERROR_CANNOT_CREATE_VDI, ex.Message);
                throw new Exception(Messages.ERROR_CANNOT_CREATE_VDI, ex);
            }
            log.Debug("Import.UploadRawVDI::VDI Created");
            #endregion

            #region UPLOAD HTTP STREAM
            XenRef<Task> taskRef = Task.create(xenSession, "UpdateStream", "UpdateStream");
            string p2VUri = string.Format("/import_raw_vdi?session_id={0}&task_id={1}&vdi={2}", xenSession.uuid, taskRef.opaque_ref, vdiRef.opaque_ref);
            NameValueCollection headers = new NameValueCollection();
            headers.Add("Content-Length", Convert.ToString(capacity));
            headers.Add("Content-Type", "application/octet-stream");
            headers.Add("Expect", "100-continue");
            headers.Add("Accept", "*/*");
            headers.Add("Connection", "close");
            headers.Add("User-Agent", "XenP2VClient/1.5");
            try
            {
                http.Put(filestream, _XenServer, p2VUri, headers, 0, capacity, false);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("{0} {1}", Messages.ERROR_HTTP_UPLOAD_FAILED, ex.Message);
                if (vdiRef != null)
                    RemoveVDI(xenSession, vdiRef);
                vdiRef = null;
                throw new Exception(Messages.ERROR_HTTP_UPLOAD_FAILED, ex);
            }
            log.Debug("Import.UploadRawVDI::http.put complete");
            #endregion

            // give it time to catch up.
            Thread.Sleep(new TimeSpan(0, 0, 5));
            log.Debug("OVF.UploadRawVDI Leave");
            return vdiRef;
        }
예제 #40
0
 public LunComboBoxItem(VDI vdi)
 {
     Debug.Assert(vdi != null, "VDI passed to combobox was null");
     Vdi = vdi;
     AdditionalConstraints = new List<Predicate<VDI>>();
 }
예제 #41
0
        public DiskGridRowItem(IXenConnection connection, XmlNode diskNode, string vmName, Host affinity)
        {
            Disk = new VDI();
            Device = new VBD();
            Connection = connection;

            Disk.virtual_size = long.Parse(diskNode.Attributes["size"].Value);
            SR sruuid = connection.Cache.Find_By_Uuid<SR>(diskNode.Attributes["sr"].Value);
            SR sr = GetBeskDiskStorage(Connection, Disk.virtual_size, affinity, sruuid == null ? null : sruuid);
            Disk.SR = new XenRef<SR>(sr != null ? sr.opaque_ref : Helper.NullOpaqueRef);
            Disk.type = (vdi_type)Enum.Parse(typeof(vdi_type), diskNode.Attributes["type"].Value);
            Device.userdevice = diskNode.Attributes["device"].Value;
            Device.bootable = diskNode.Attributes["bootable"].Value == "true";

            Disk.name_label = string.Format(Messages.NEWVMWIZARD_STORAGEPAGE_VDINAME, vmName, Device.userdevice); //Device.userdevice;
            Disk.read_only = false;
            Disk.name_description = Messages.NEWVMWIZARD_STORAGEPAGE_DISK_DESCRIPTION;
            Device.mode = vbd_mode.RW;

            CanDelete = Disk.type == vdi_type.user;
            CanResize = true;
            MinSize = Disk.virtual_size;

            AddCells();
        }
예제 #42
0
 public void SetExistingVDIs(VDI[] vdis)
 {
     existingVDIs = vdis;
 }
        protected override void ProcessRecord()
        {
            GetSession();
            if (Record == null && HashTable == null)
            {
                Record                  = new XenAPI.VDI();
                Record.name_label       = NameLabel;
                Record.name_description = NameDescription;
                Record.SR               = SR == null ? null : new XenRef <XenAPI.SR>(SR.opaque_ref);
                Record.virtual_size     = VirtualSize;
                Record.type             = Type;
                Record.sharable         = Sharable;
                Record.read_only        = ReadOnly;
                Record.other_config     = CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(OtherConfig);
                Record.xenstore_data    = CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(XenstoreData);
                Record.sm_config        = CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(SmConfig);
                Record.tags             = Tags;
            }
            else if (Record == null)
            {
                Record = new XenAPI.VDI(HashTable);
            }

            if (!ShouldProcess(session.Url, "VDI.create"))
            {
                return;
            }

            RunApiCall(() =>
            {
                var contxt = _context as XenServerCmdletDynamicParameters;

                if (contxt != null && contxt.Async)
                {
                    taskRef = XenAPI.VDI.async_create(session, Record);

                    if (PassThru)
                    {
                        XenAPI.Task taskObj = null;
                        if (taskRef != "OpaqueRef:NULL")
                        {
                            taskObj            = XenAPI.Task.get_record(session, taskRef.opaque_ref);
                            taskObj.opaque_ref = taskRef.opaque_ref;
                        }

                        WriteObject(taskObj, true);
                    }
                }
                else
                {
                    string objRef = XenAPI.VDI.create(session, Record);

                    if (PassThru)
                    {
                        XenAPI.VDI obj = null;

                        if (objRef != "OpaqueRef:NULL")
                        {
                            obj            = XenAPI.VDI.get_record(session, objRef);
                            obj.opaque_ref = objRef;
                        }

                        WriteObject(obj, true);
                    }
                }
            });

            UpdateSessions();
        }
예제 #44
0
        public void SetXenObjects(IXenObject orig, IXenObject clone)
        {
            if (!(clone is VDI))
                return;
            vdi = clone as VDI;

            Repopulate();
        }
예제 #45
0
파일: SrPicker.cs 프로젝트: ktz666/xenadmin
 public void SetUsageAsMovingVDI(VDI[] vdis)
 {
     usage = SRPickerType.MoveOrCopy;
     existingVDIs = vdis;
 }
예제 #46
0
 protected override void ProcessRecord()
 {
     XenAPI.Session session = XenObject as XenAPI.Session;
     if (session != null)
     {
         WriteObject(new XenRef <XenAPI.Session>(session));
         return;
     }
     XenAPI.Auth auth = XenObject as XenAPI.Auth;
     if (auth != null)
     {
         WriteObject(new XenRef <XenAPI.Auth>(auth));
         return;
     }
     XenAPI.Subject subject = XenObject as XenAPI.Subject;
     if (subject != null)
     {
         WriteObject(new XenRef <XenAPI.Subject>(subject));
         return;
     }
     XenAPI.Role role = XenObject as XenAPI.Role;
     if (role != null)
     {
         WriteObject(new XenRef <XenAPI.Role>(role));
         return;
     }
     XenAPI.Task task = XenObject as XenAPI.Task;
     if (task != null)
     {
         WriteObject(new XenRef <XenAPI.Task>(task));
         return;
     }
     XenAPI.Event evt = XenObject as XenAPI.Event;
     if (evt != null)
     {
         WriteObject(new XenRef <XenAPI.Event>(evt));
         return;
     }
     XenAPI.Pool pool = XenObject as XenAPI.Pool;
     if (pool != null)
     {
         WriteObject(new XenRef <XenAPI.Pool>(pool));
         return;
     }
     XenAPI.Pool_patch pool_patch = XenObject as XenAPI.Pool_patch;
     if (pool_patch != null)
     {
         WriteObject(new XenRef <XenAPI.Pool_patch>(pool_patch));
         return;
     }
     XenAPI.Pool_update pool_update = XenObject as XenAPI.Pool_update;
     if (pool_update != null)
     {
         WriteObject(new XenRef <XenAPI.Pool_update>(pool_update));
         return;
     }
     XenAPI.VM vm = XenObject as XenAPI.VM;
     if (vm != null)
     {
         WriteObject(new XenRef <XenAPI.VM>(vm));
         return;
     }
     XenAPI.VM_metrics vm_metrics = XenObject as XenAPI.VM_metrics;
     if (vm_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.VM_metrics>(vm_metrics));
         return;
     }
     XenAPI.VM_guest_metrics vm_guest_metrics = XenObject as XenAPI.VM_guest_metrics;
     if (vm_guest_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.VM_guest_metrics>(vm_guest_metrics));
         return;
     }
     XenAPI.VMPP vmpp = XenObject as XenAPI.VMPP;
     if (vmpp != null)
     {
         WriteObject(new XenRef <XenAPI.VMPP>(vmpp));
         return;
     }
     XenAPI.VMSS vmss = XenObject as XenAPI.VMSS;
     if (vmss != null)
     {
         WriteObject(new XenRef <XenAPI.VMSS>(vmss));
         return;
     }
     XenAPI.VM_appliance vm_appliance = XenObject as XenAPI.VM_appliance;
     if (vm_appliance != null)
     {
         WriteObject(new XenRef <XenAPI.VM_appliance>(vm_appliance));
         return;
     }
     XenAPI.DR_task dr_task = XenObject as XenAPI.DR_task;
     if (dr_task != null)
     {
         WriteObject(new XenRef <XenAPI.DR_task>(dr_task));
         return;
     }
     XenAPI.Host host = XenObject as XenAPI.Host;
     if (host != null)
     {
         WriteObject(new XenRef <XenAPI.Host>(host));
         return;
     }
     XenAPI.Host_crashdump host_crashdump = XenObject as XenAPI.Host_crashdump;
     if (host_crashdump != null)
     {
         WriteObject(new XenRef <XenAPI.Host_crashdump>(host_crashdump));
         return;
     }
     XenAPI.Host_patch host_patch = XenObject as XenAPI.Host_patch;
     if (host_patch != null)
     {
         WriteObject(new XenRef <XenAPI.Host_patch>(host_patch));
         return;
     }
     XenAPI.Host_metrics host_metrics = XenObject as XenAPI.Host_metrics;
     if (host_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.Host_metrics>(host_metrics));
         return;
     }
     XenAPI.Host_cpu host_cpu = XenObject as XenAPI.Host_cpu;
     if (host_cpu != null)
     {
         WriteObject(new XenRef <XenAPI.Host_cpu>(host_cpu));
         return;
     }
     XenAPI.Network network = XenObject as XenAPI.Network;
     if (network != null)
     {
         WriteObject(new XenRef <XenAPI.Network>(network));
         return;
     }
     XenAPI.VIF vif = XenObject as XenAPI.VIF;
     if (vif != null)
     {
         WriteObject(new XenRef <XenAPI.VIF>(vif));
         return;
     }
     XenAPI.VIF_metrics vif_metrics = XenObject as XenAPI.VIF_metrics;
     if (vif_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.VIF_metrics>(vif_metrics));
         return;
     }
     XenAPI.PIF pif = XenObject as XenAPI.PIF;
     if (pif != null)
     {
         WriteObject(new XenRef <XenAPI.PIF>(pif));
         return;
     }
     XenAPI.PIF_metrics pif_metrics = XenObject as XenAPI.PIF_metrics;
     if (pif_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.PIF_metrics>(pif_metrics));
         return;
     }
     XenAPI.Bond bond = XenObject as XenAPI.Bond;
     if (bond != null)
     {
         WriteObject(new XenRef <XenAPI.Bond>(bond));
         return;
     }
     XenAPI.VLAN vlan = XenObject as XenAPI.VLAN;
     if (vlan != null)
     {
         WriteObject(new XenRef <XenAPI.VLAN>(vlan));
         return;
     }
     XenAPI.SM sm = XenObject as XenAPI.SM;
     if (sm != null)
     {
         WriteObject(new XenRef <XenAPI.SM>(sm));
         return;
     }
     XenAPI.SR sr = XenObject as XenAPI.SR;
     if (sr != null)
     {
         WriteObject(new XenRef <XenAPI.SR>(sr));
         return;
     }
     XenAPI.LVHD lvhd = XenObject as XenAPI.LVHD;
     if (lvhd != null)
     {
         WriteObject(new XenRef <XenAPI.LVHD>(lvhd));
         return;
     }
     XenAPI.VDI vdi = XenObject as XenAPI.VDI;
     if (vdi != null)
     {
         WriteObject(new XenRef <XenAPI.VDI>(vdi));
         return;
     }
     XenAPI.VBD vbd = XenObject as XenAPI.VBD;
     if (vbd != null)
     {
         WriteObject(new XenRef <XenAPI.VBD>(vbd));
         return;
     }
     XenAPI.VBD_metrics vbd_metrics = XenObject as XenAPI.VBD_metrics;
     if (vbd_metrics != null)
     {
         WriteObject(new XenRef <XenAPI.VBD_metrics>(vbd_metrics));
         return;
     }
     XenAPI.PBD pbd = XenObject as XenAPI.PBD;
     if (pbd != null)
     {
         WriteObject(new XenRef <XenAPI.PBD>(pbd));
         return;
     }
     XenAPI.Crashdump crashdump = XenObject as XenAPI.Crashdump;
     if (crashdump != null)
     {
         WriteObject(new XenRef <XenAPI.Crashdump>(crashdump));
         return;
     }
     XenAPI.VTPM vtpm = XenObject as XenAPI.VTPM;
     if (vtpm != null)
     {
         WriteObject(new XenRef <XenAPI.VTPM>(vtpm));
         return;
     }
     XenAPI.Console console = XenObject as XenAPI.Console;
     if (console != null)
     {
         WriteObject(new XenRef <XenAPI.Console>(console));
         return;
     }
     XenAPI.User user = XenObject as XenAPI.User;
     if (user != null)
     {
         WriteObject(new XenRef <XenAPI.User>(user));
         return;
     }
     XenAPI.Data_source data_source = XenObject as XenAPI.Data_source;
     if (data_source != null)
     {
         WriteObject(new XenRef <XenAPI.Data_source>(data_source));
         return;
     }
     XenAPI.Blob blob = XenObject as XenAPI.Blob;
     if (blob != null)
     {
         WriteObject(new XenRef <XenAPI.Blob>(blob));
         return;
     }
     XenAPI.Message message = XenObject as XenAPI.Message;
     if (message != null)
     {
         WriteObject(new XenRef <XenAPI.Message>(message));
         return;
     }
     XenAPI.Secret secret = XenObject as XenAPI.Secret;
     if (secret != null)
     {
         WriteObject(new XenRef <XenAPI.Secret>(secret));
         return;
     }
     XenAPI.Tunnel tunnel = XenObject as XenAPI.Tunnel;
     if (tunnel != null)
     {
         WriteObject(new XenRef <XenAPI.Tunnel>(tunnel));
         return;
     }
     XenAPI.PCI pci = XenObject as XenAPI.PCI;
     if (pci != null)
     {
         WriteObject(new XenRef <XenAPI.PCI>(pci));
         return;
     }
     XenAPI.PGPU pgpu = XenObject as XenAPI.PGPU;
     if (pgpu != null)
     {
         WriteObject(new XenRef <XenAPI.PGPU>(pgpu));
         return;
     }
     XenAPI.GPU_group gpu_group = XenObject as XenAPI.GPU_group;
     if (gpu_group != null)
     {
         WriteObject(new XenRef <XenAPI.GPU_group>(gpu_group));
         return;
     }
     XenAPI.VGPU vgpu = XenObject as XenAPI.VGPU;
     if (vgpu != null)
     {
         WriteObject(new XenRef <XenAPI.VGPU>(vgpu));
         return;
     }
     XenAPI.VGPU_type vgpu_type = XenObject as XenAPI.VGPU_type;
     if (vgpu_type != null)
     {
         WriteObject(new XenRef <XenAPI.VGPU_type>(vgpu_type));
         return;
     }
     XenAPI.PVS_site pvs_site = XenObject as XenAPI.PVS_site;
     if (pvs_site != null)
     {
         WriteObject(new XenRef <XenAPI.PVS_site>(pvs_site));
         return;
     }
     XenAPI.PVS_server pvs_server = XenObject as XenAPI.PVS_server;
     if (pvs_server != null)
     {
         WriteObject(new XenRef <XenAPI.PVS_server>(pvs_server));
         return;
     }
     XenAPI.PVS_proxy pvs_proxy = XenObject as XenAPI.PVS_proxy;
     if (pvs_proxy != null)
     {
         WriteObject(new XenRef <XenAPI.PVS_proxy>(pvs_proxy));
         return;
     }
     XenAPI.PVS_cache_storage pvs_cache_storage = XenObject as XenAPI.PVS_cache_storage;
     if (pvs_cache_storage != null)
     {
         WriteObject(new XenRef <XenAPI.PVS_cache_storage>(pvs_cache_storage));
         return;
     }
     XenAPI.Feature feature = XenObject as XenAPI.Feature;
     if (feature != null)
     {
         WriteObject(new XenRef <XenAPI.Feature>(feature));
         return;
     }
     XenAPI.SDN_controller sdn_controller = XenObject as XenAPI.SDN_controller;
     if (sdn_controller != null)
     {
         WriteObject(new XenRef <XenAPI.SDN_controller>(sdn_controller));
         return;
     }
     XenAPI.Vdi_nbd_server_info vdi_nbd_server_info = XenObject as XenAPI.Vdi_nbd_server_info;
     if (vdi_nbd_server_info != null)
     {
         WriteObject(new XenRef <XenAPI.Vdi_nbd_server_info>(vdi_nbd_server_info));
         return;
     }
     XenAPI.PUSB pusb = XenObject as XenAPI.PUSB;
     if (pusb != null)
     {
         WriteObject(new XenRef <XenAPI.PUSB>(pusb));
         return;
     }
     XenAPI.USB_group usb_group = XenObject as XenAPI.USB_group;
     if (usb_group != null)
     {
         WriteObject(new XenRef <XenAPI.USB_group>(usb_group));
         return;
     }
     XenAPI.VUSB vusb = XenObject as XenAPI.VUSB;
     if (vusb != null)
     {
         WriteObject(new XenRef <XenAPI.VUSB>(vusb));
         return;
     }
 }