protected override void ProcessRecord()
        {
            GetSession();
            if (Record == null && HashTable == null)
            {
                Record                  = new XenAPI.VM_appliance();
                Record.name_label       = NameLabel;
                Record.name_description = NameDescription;
            }
            else if (Record == null)
            {
                Record = new XenAPI.VM_appliance(HashTable);
            }

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

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

                if (contxt != null && contxt.Async)
                {
                    taskRef = XenAPI.VM_appliance.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.VM_appliance.create(session, Record);

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

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

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

            UpdateSessions();
        }
        private static void Download_VM_appliance(Session session, List <ObjectChange> changes)
        {
            Dictionary <XenRef <VM_appliance>, VM_appliance> records = VM_appliance.get_all_records(session);

            foreach (KeyValuePair <XenRef <VM_appliance>, VM_appliance> entry in records)
            {
                changes.Add(new ObjectChange(typeof(VM_appliance), entry.Key.opaque_ref, entry.Value));
            }
        }
 public AssignVMsToVMApplianceAction(VM_appliance vmAppliance, List<XenRef<VM>> selectedVMs)
     : base(vmAppliance.Connection, selectedVMs.Count == 1 ?
     string.Format(Messages.ASSIGN_VM_TO_VAPP, vmAppliance.Connection.Resolve(selectedVMs[0]), vmAppliance.Name)
     : string.Format(Messages.ASSIGN_VMS_TO_VAPP, vmAppliance.Name))
 {
     _vmAppliance = vmAppliance;
     _selectedVMs = selectedVMs;
     Pool = Helpers.GetPool(vmAppliance.Connection);
 }
Esempio n. 4
0
 public CreateVMApplianceAction(VM_appliance record, List<VM> vms)
     : base(record.Connection, Messages.CREATE_VM_APPLIANCE)
 {
     _record = record;
     _vms = vms;
     Pool = Helpers.GetPool(record.Connection);
     ApiMethodsToRoleCheck.Add("VM_appliance.async_create");
     ApiMethodsToRoleCheck.Add("VM.set_appliance");
 }
Esempio n. 5
0
        public CleanShutDownApplianceAction(VM_appliance appliance)
            : base(appliance.Connection, Messages.VM_APPLIANCE_SHUT_DOWN)
        {
            Pool = Helpers.GetPool(appliance.Connection);
            if (Pool == null)
                Host = Helpers.GetMaster(appliance.Connection);

            ApiMethodsToRoleCheck.Add("VM_appliance.clean_shutdown");

            m_appliance = appliance;
        }
Esempio n. 6
0
        public StartApplianceAction(VM_appliance appliance, bool suspend)
            : base(appliance.Connection, suspend ? Messages.VM_APPLIANCE_START_PAUSED : Messages.VM_APPLIANCE_START)
        {
            Pool = Helpers.GetPool(appliance.Connection);
            if (Pool == null)
                Host = Helpers.GetMaster(appliance.Connection);

            ApiMethodsToRoleCheck.Add("VM_appliance.start");

            m_suspend = suspend;
            m_appliance = appliance;
        }
 public RunningVmApplianceProblem(Check check, VM_appliance vmAppliance, bool hardShutdown)
     : base(check, vmAppliance)
 {
     this.hardShutdown = hardShutdown;
 }
 public ExistingVmApplianceProblem(Check check, VM_appliance vmAppliance, List<VM> vmsToDestroy)
     : base(check, vmAppliance)
 {
     this.vmsToDestroy = vmsToDestroy;
 }
Esempio n. 9
0
 public VmApplianceProblem(Check check, VM_appliance vmAppliance)
     : base(check)
 {
     _vmAppliance = vmAppliance;
 }
Esempio n. 10
0
 private void RefreshTab(VM_appliance vmAppliance)
 {
     textBoxName.Text = vmAppliance.Name;
     textBoxDescription.Text = vmAppliance.Description;
     labelwizard.Visible = false;
 }
 public RemoveVMsFromVMApplianceAction(VM_appliance vmAppliance, List<XenRef<VM>> selectedVMs)
     : base(vmAppliance.Connection, selectedVMs.Count == 1 ?
     string.Format(Messages.REMOVE_VM_FROM_APPLIANCE, vmAppliance.Connection.Resolve(selectedVMs[0]), vmAppliance.Name)
     : string.Format(Messages.REMOVE_VMS_FROM_APPLIANCE, vmAppliance.Name))
 {
     _selectedVMs = selectedVMs;
     Pool = Helpers.GetPool(vmAppliance.Connection);
 }
Esempio n. 12
0
 /// <summary>
 /// Check if an appliance exists in specified pool. 
 /// </summary>
 /// <param name="vmAppliance">the appliance</param>
 /// <param name="vms">vms in this appliance</param>
 /// <param name="pool">the pool on which to check if the specified appliance exists</param>
 public ExistingVmApplianceCheck(VM_appliance vmAppliance, List<VM> vms, Pool pool)
     : base (pool)
 {
     applianceToRecover = vmAppliance;
     vmsToRecover = vms;
 }
 private VirtualTreeNode AddVmApplianceNode(VM_appliance appliance)
 {
     return AddNode(appliance.Name, Images.GetIconFor(appliance), false, appliance);
 }
Esempio n. 14
0
 public ExistingVmApplianceWarning(Check check, VM_appliance vmAppliance)
     : base(check)
 {
     this.vmAppliance = vmAppliance;
 }
 public void SetXenObjects(IXenObject orig, IXenObject clone)
 {
     _clone = (VM_appliance)clone;
     Pool = Helpers.GetPoolOfOne(_clone.Connection);
     //RefreshTab(null);
 }
 /// <summary>
 /// Check if an appliance is running in specified pool. 
 /// </summary>
 /// <param name="vmAppliance">the appliance</param>
 /// <param name="pool">the pool on which to check if the specified appliance is running</param>
 public RunningVmApplianceCheck(VM_appliance vmAppliance, Pool pool)
     : base(pool)
 {
     this.vmAppliance = vmAppliance;
 }
Esempio n. 17
0
        public void Process(Session xenSession, EnvelopeType ovfObj, string pathToOvf, string passcode)
        {
            if (xenSession == null)
                throw new InvalidOperationException(Messages.ERROR_NOT_CONNECTED);

            string ovfname = Guid.NewGuid().ToString();

            vifDeviceIndex = 0;
            string encryptionVersion = null;

            #region CHECK ENCRYPTION
            if (OVF.HasEncryption(ovfObj))
            {
                if (passcode == null)
                {
                    throw new InvalidDataException(Messages.ERROR_NO_PASSWORD);
                }
                string fileuuids = null;
                SecuritySection_Type[] securitysection = OVF.FindSections<SecuritySection_Type>((ovfObj).Sections);
                if (securitysection != null && securitysection.Length >= 0)
                {
                    foreach (Security_Type securitytype in securitysection[0].Security)
                    {
                        if (securitytype.ReferenceList.Items != null && securitytype.ReferenceList.Items.Length > 0)
                        {
                            foreach (XenOvf.Definitions.XENC.ReferenceType dataref in securitytype.ReferenceList.Items)
                            {
                                if (dataref is DataReference)
                                {
                                    fileuuids += ":" + ((DataReference)dataref).ValueType;
                                }
                            }
                        }
                        if (securitytype.EncryptionMethod != null && securitytype.EncryptionMethod.Algorithm != null)
                        {
                            string algoname = (securitytype.EncryptionMethod.Algorithm.Split(new char[] { '#' }))[1].ToLower().Replace('-', '_');
                            object x = OVF.AlgorithmMap(algoname);
                            if (x != null)
                            {
                                EncryptionClass = (string)x;
                                EncryptionKeySize = Convert.ToInt32(securitytype.EncryptionMethod.KeySize);
                            }
                        }

                        if (!string.IsNullOrEmpty(securitytype.version))
                        {
                            encryptionVersion = securitytype.version;
                        }
                    }
                }
            }
            #endregion

            #region FIND DEFAULT SR
            Dictionary<XenRef<Pool>, Pool> pools = Pool.get_all_records(xenSession);
            foreach (XenRef<Pool> pool in pools.Keys)
            {
                DefaultSRUUID = pools[pool].default_SR;
                break;
            }
            #endregion

            //
            // So the process is the same below, change this
            //
            if (ovfObj.Item is VirtualSystem_Type)
            {
                VirtualSystem_Type vstemp = (VirtualSystem_Type)ovfObj.Item;
                ovfObj.Item = new VirtualSystemCollection_Type();
                ((VirtualSystemCollection_Type)ovfObj.Item).Content = new Content_Type[] { vstemp };
            }

            #region Create appliance

            XenRef<VM_appliance> applRef = null;
            if (ApplianceName != null)
            {
                var vmAppliance = new VM_appliance {name_label = ApplianceName, Connection = xenSession.Connection};
                applRef = VM_appliance.create(xenSession, vmAppliance);
            }

            #endregion

            foreach (VirtualSystem_Type vSystem in ((VirtualSystemCollection_Type)ovfObj.Item).Content)
            {
               //FIND/SET THE NAME OF THE VM
                ovfname = OVF.FindSystemName(ovfObj, vSystem.id);
                auditLog.DebugFormat("Import: {0}, {1}", ovfname, pathToOvf);

                VirtualHardwareSection_Type vhs = OVF.FindVirtualHardwareSectionByAffinity(ovfObj, vSystem.id, "xen");

                XenRef<VM> vmRef = DefineSystem(xenSession, vhs, ovfname);
                if (vmRef == null)
                {
                    log.Error(Messages.ERROR_CREATE_VM_FAILED);
                    throw new ImportException(Messages.ERROR_CREATE_VM_FAILED);
                }

                HideSystem(xenSession, vmRef);
                log.DebugFormat("OVF.Import.Process: DefineSystem completed ({0})", VM.get_name_label(xenSession, vmRef));

                #region Set appliance
                if (applRef != null)
                    VM.set_appliance(xenSession, vmRef.opaque_ref, applRef.opaque_ref);

                if (ovfObj.Sections != null)
                {
                    StartupSection_Type[] startUpArray = OVF.FindSections<StartupSection_Type>(ovfObj.Sections);
                    if (startUpArray != null && startUpArray.Length > 0)
                    {
                        var startupSection = startUpArray[0];
                        var itemList = startupSection.Item;

                        if (itemList != null)
                        {
                            var item = itemList.FirstOrDefault(it => it.id == vSystem.id);

                            if (item != null)
                            {
                                VM.set_start_delay(xenSession, vmRef.opaque_ref, item.startDelay);
                                VM.set_shutdown_delay(xenSession, vmRef.opaque_ref, item.stopDelay);
                                VM.set_order(xenSession, vmRef.opaque_ref, item.order);
                            }
                        }
                    }
                }

                #endregion

                #region set has_vendor_device

                if (Helpers.DundeeOrGreater(xenSession.Connection))
                {
                    var data = vhs.VirtualSystemOtherConfigurationData;
                    if (data != null)
                    {
                        var datum = data.FirstOrDefault(s => s.Name == "VM_has_vendor_device");
                        if (datum != null)
                        {
                            bool hasVendorDevice;
                            if (bool.TryParse(datum.Value.Value, out hasVendorDevice) && hasVendorDevice)
                                VM.set_has_vendor_device(xenSession, vmRef.opaque_ref, hasVendorDevice);
                        }
                    }
                }

                #endregion

                #region Set vgpu

                GPU_group gpuGroup;
                VGPU_type vgpuType;
                FindGpuGroupAndVgpuType(xenSession, vhs, out gpuGroup, out vgpuType);

                if (gpuGroup != null)
                {
                    var other_config = new Dictionary<string, string>();

                    if (Helpers.FeatureForbidden(xenSession, Host.RestrictVgpu))
                        VGPU.create(xenSession, vmRef.opaque_ref, gpuGroup.opaque_ref, "0", other_config);
                    else if (vgpuType != null)
                        VGPU.create(xenSession, vmRef.opaque_ref, gpuGroup.opaque_ref, "0", other_config, vgpuType.opaque_ref);
                }

                #endregion

                SetDeviceConnections(ovfObj, vhs);
                try
                {
                    foreach (RASD_Type rasd in vhs.Item)
                    {
                        string thisPassCode = null;
                        // Check to see if THIS rasd is encrypted, if so, set the passcode.
                        if (OVF.IsThisEncrypted(ovfObj, rasd))
                            thisPassCode = passcode;

                        string compression = "None";
                        if (rasd.ResourceType.Value == 17 || rasd.ResourceType.Value == 19 || rasd.ResourceType.Value == 21)
                        {
                            bool skip = Tools.ValidateProperty("Caption", rasd) &&
                                 (
                                  rasd.Caption.Value.ToUpper().Contains("COM") ||
                                  rasd.Caption.Value.ToUpper().Contains("FLOPPY") ||
                                  rasd.Caption.Value.ToUpper().Contains("ISO")
                                 );

                            if (!skip)
                            {
                                File_Type file = OVF.FindFileReferenceByRASD(ovfObj, rasd);
                                if (file == null)
                                    continue;

                                if (IsKnownURIType(file.href))
                                    _filedownloadsize = file.size;

                                VirtualDiskDesc_Type vdisk = OVF.FindDiskReference(ovfObj, rasd);
                                SetIfDeviceIsBootable(ovfObj, rasd);
                                AdditionalSpace = OVF.ComputeCapacity(Convert.ToInt64(vdisk.capacity), vdisk.capacityAllocationUnits);  // used in Wim file imports only.
                                AddResourceSettingData(xenSession, vmRef, rasd, pathToOvf, OVF.FindRasdFileName(ovfObj, rasd, out compression), compression, encryptionVersion, thisPassCode);
                            }
                        }
                        else
                        {
                            AddResourceSettingData(xenSession, vmRef, rasd, pathToOvf, OVF.FindRasdFileName(ovfObj, rasd, out compression), compression, encryptionVersion, thisPassCode);
                        }
                    }

                    InstallSection_Type[] installSection = OVF.FindSections<InstallSection_Type>(vSystem.Items);

                    if (installSection != null && installSection.Length == 1)
                    {
                        OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOn, "Import", Messages.START_POST_INSTALL_INSTRUCTIONS));
                        OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.ImportProgress, "Import", Messages.START_POST_INSTALL_INSTRUCTIONS));
                        HandleInstallSection(xenSession, vmRef, installSection[0]);
                    }
                    ShowSystem(xenSession, vmRef);
                }
                catch (Exception ex)
                {
                    if (ex is OperationCanceledException)
                        throw;
                    log.Error(Messages.ERROR_IMPORT_FAILED);
                    throw new Exception(Messages.ERROR_IMPORT_FAILED, ex);
                }
            }

            OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.MarqueeOff, "Import", ""));
            int _processId = System.Diagnostics.Process.GetCurrentProcess().Id;
            string _touchFile = Path.Combine(pathToOvf, "xen__" + _processId);
            //added check again as Delete needs write permissions and even if the file does not exist import will fail if the user has read only permissions
            if (File.Exists(_touchFile))
                File.Delete(_touchFile);

            OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.ImportThreadComplete, "Import", Messages.COMPLETED_IMPORT));
        }
Esempio n. 18
0
        protected override void FinishWizard()
        {
            var vmAppliance = new VM_appliance
            {
                name_label = xenTabPageName.VMApplianceName,
                name_description = xenTabPageName.VMApplianceDescription,
                Connection = Pool.Connection
            };

            var action = new CreateVMApplianceAction(vmAppliance, xenTabPageVMs.SelectedVMs);
            action.RunAsync();

            var vmSettings = xenTabPageVMOrderAndDelays.getCurrentSettings();
            if (vmSettings != null && vmSettings.Count > 0)
                new SetVMStartupOptionsAction(Pool.Connection, xenTabPageVMOrderAndDelays.getCurrentSettings(), false).RunAsync();

            base.FinishWizard();
        }
Esempio n. 19
0
        private bool CanShutDownAppliance(VM_appliance app)
		{
		    return app != null && (app.allowed_operations.Contains(vm_appliance_operation.clean_shutdown)
		           || app.allowed_operations.Contains(vm_appliance_operation.hard_shutdown));
		}
Esempio n. 20
0
        private void RefreshButtons()
        {
            if (dataGridViewVMAppliances.SelectedRows.Count == 1 && dataGridViewVMAppliances.SelectedRows[0] is VMApplianceRow)
            {
                currentSelected = (VM_appliance)((VMApplianceRow)dataGridViewVMAppliances.SelectedRows[0]).VMAppliance;
                toolStripButtonEdit.Enabled = true;
            }
            else
            {
                if (dataGridViewVMAppliances.SelectedRows.Count == 0)
                    currentSelected = null;
                toolStripButtonEdit.Enabled = false;
            }
            toolStripButtonDelete.Enabled = (dataGridViewVMAppliances.SelectedRows.Count != 0);

        	toolStripButtonExport.Enabled = currentSelected != null && currentSelected.VMs.TrueForAll(vmRef =>
        	                                                                                          	{
        	                                                                                          		var vm = currentSelected.Connection.Resolve(vmRef);
        	                                                                                          		return vm != null
        	                                                                                          		       && !vm.is_a_template
        	                                                                                          		       && !vm.Locked
        	                                                                                          		       && vm.allowed_operations != null
        	                                                                                          		       && vm.allowed_operations.Contains(vm_operations.export);
        	                                                                                          	});

			if (currentSelected == null)
			{
				toolStripButtonStart.Enabled = toolStripButtonShutdown.Enabled = false;
			}
			else
			{
				toolStripButtonStart.Enabled = currentSelected.allowed_operations.Contains(vm_appliance_operation.start);

				toolStripButtonShutdown.Enabled = currentSelected.allowed_operations.Contains(vm_appliance_operation.clean_shutdown)
				                                  || currentSelected.allowed_operations.Contains(vm_appliance_operation.hard_shutdown);
    		}

            tableLayoutPanel2.Visible = (currentSelected != null);
            tableLayoutPanel1.ColumnStyles[1].Width = currentSelected == null ? 0 : 200;
        }
Esempio n. 21
0
 public VMApplianceRow(VM_appliance vmAppliance)
 {
     Cells.Add(_nameCell);
     Cells.Add(_descriptionCell);
     Cells.Add(_numVMsCell);
     VMAppliance = vmAppliance;
     CreateVmItems();
     RefreshRow();
 }
Esempio n. 22
0
 private bool CanStartAppliance(VM_appliance app)
 {
     return app != null && app.allowed_operations.Contains(vm_appliance_operation.start);
 }
Esempio n. 23
0
 public static List <XenRef <SR> > GetDRMissingSRs(Session session, string vm, Session sessionTo)
 {
     return(Helpers.CreedenceOrGreater(sessionTo.Connection)
                ? VM_appliance.get_SRs_required_for_recovery(session, vm, sessionTo.uuid)
                : null);
 }
 private VirtualTreeNode AddVmApplianceNode(VirtualTreeNode parent, int index, VM_appliance appliance)
 {
     return AddNode(parent, index, appliance.Name, Images.GetIconFor(appliance), false, appliance);
 }
Esempio n. 25
0
 public static Icons GetIconFor(VM_appliance appl)
 {
     return Icons.VmAppliance;
 }
Esempio n. 26
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;
     }
 }