C# API bindings

Description

The C# libvirt bindings are a class library. They use a Microsoft Visual Studio project architecture, and have been tested with Windows .NET, and Mono, on both Linux and Windows.

Compiling them produces LibvirtBindings.dll, which can be added as a .NET reference to any .NET project needing access to libvirt.

 

Requirements

These bindings depend upon the libvirt libraries being installed. In the .NET case, this is libvirt-0.dll, produced from compiling libvirt for windows.

 

GIT source repository

The C# bindings source code is maintained in a git repository available on libvirt.org:

git clone git://libvirt.org/libvirt-csharp.git

They can also be browsed online:

http://libvirt.org/git/?p=libvirt-csharp.git;a=summary

 

Usage

The class library exposes the LibvirtBindings namespace. This namespace exposes all of the needed types (enum, struct), and 2 main classes, libVirt and libvirtError.

The libVirt class exposes all of the interfaces of the libvirt library for handling virtualized domains.

The libvirtError class exposes all of the interfaces of the libvirt library for handling errors raised while using the library.

 

Authors

The C# bindings are the work of Arnaud Champion <arnaud.champion AT devatom.fr>, based upon the previous work of Jaromír Červenka.

 

Notes on testing

Windows testing is performed on Windows 7, with .NET 4, Visual Studio 2010, and MonoDevelop 2.4.

Linux testing is performed on Fedora 13 i686, with MonoDevelop 2.2.

 

Type Coverage

Coverage of the libvirt types is:

TypeNameBinding?Tested?Sample Code?Works?Tested .Net/Windows Works?Tested Mono/Windows Works?Tested Mono/Linux Works?
enumvirCPUCompareResultNo      
structvirConnectYes, an IntPtr as the struct is not publicYes Yes   
structvirConnectAuthYesYesvirConnectOpenAuthYesYesYesYes
structvirConnectCredentialYesYesvirConnectOpenAuthYesYesYesYes
enumvirConnectCredentialTypeYesYesvirConnectOpenAuthYesYesYesYes
enumvirConnectFlagsNo      
structvirDomainYes, an IntPtr as the struct is not public      
structvirDomainBlockInfoNo      
structvirDomainBlockStatsInfoNo      
enumvirDomainCoreDumpFlagsNo      
enumvirDomainCreateFlagsNo      
enumvirDomainDeviceModifyFlagsNo      
enumvirDomainEventDefinedDetailTypeYes YesYes   
structvirDomainEventGraphicsAddressNo      
enumvirDomainEventGraphicsAddressTypeNo      
enumvirDomainEventGraphicsPhaseNo      
structvirDomainEventGraphicsSubjectNo      
structvirDomainEventGraphicsSubjectIdentityNo      
enumvirDomainEventIDNo      
enumvirDomainEventIOErrorActionNo      
enumvirDomainEventResumedDetailTypeYesYes Yes   
enumvirDomainEventStartedDetailTypeYesYes Yes   
enumvirDomainEventStoppedDetailTypeYesYes Yes   
enumvirDomainEventSuspendedDetailTypeYesYes Yes   
enumvirDomainEventTypeYesYes Yes   
enumvirDomainEventUndefinedDetailTypeYesYes Yes   
enumvirDomainEventWatchdogActionNo      
structvirDomainInfoYesYes Yes   
structvirDomainInterfaceStatsStructYesNo Maybe   
structvirDomainJobInfoNo      
enumvirDomainJobTypeNo      
enumvirDomainMemoryFlagsNo      
structvirDomainMemoryStatStructNo      
enumvirDomainMemoryStatTagsYesNo Maybe   
enumvirDomainMigrateFlagsNo      
structvirDomainSnapshotNo      
enumvirDomainSnapshotDeleteFlags       
enumvirDomainStateYesYes Yes   
enumvirDomainXMLFlagsYesYes Yes   
enumvirEventHandleTypeYesYes Yes   
structvirInterfaceYes, an IntPtr as the struct is not public      
enumvirInterfaceXMLFlagsNo      
structvirNWFilterNo      
structvirNetworkYes, an IntPtr as the struct is not public      
structvirNodeDeviceYes, an IntPtr as the struct is not public      
structvirNodeInfoYesNo Maybe   
structvirSchedParameterNo      
enumvirSchedParameterTypeNo      
structvirSecretNo      
enumvirSecretUsageTypeNo      
structvirSecurityLabelNo      
structvirSecurityModelNo      
structvirStoragePoolYes, an IntPtr as the struct is not public      
enumvirStoragePoolBuildFlagsYesNo Maybe   
enumvirStoragePoolDeleteFlagsYesNo Maybe   
structvirStoragePoolInfoYesYes Yes   
enumvirStoragePoolStateYesYes Yes   
structvirStorageVolYes, an IntPtr as the struct is not public      
enumvirStorageVolDeleteFlagsNo      
structvirStorageVolInfoYesYes Yes   
enumvirStorageVolTypeYesYes Yes   
structvirStreamNo      
enumvirStreamEventTypeNo      
enumvirStreamFlagsNo      
structvirVcpuInfoNo      
enumvirVcpuStateNo      

 

Function Coverage

Coverage of the libvirt functions is:

NameBinding?Type?Tested?Sample Code?Working?Tested .Net/Windows Works?Tested Mono/Windows Works?Tested Mono/Linux Works?
virConnectAuthCallbackPtrYesdelegateYesvirConnectOpenAuthYesYesYes 
virConnectBaselineCPUNofunction      
virConnectCloseYesfunctionYesvirConnectOpenAuth YesYesYes
virConnectCompareCPUNofunction      
virConnectDomainEventCallbackYesdelegateYes Yes   
virConnectDomainEventDeregisterNofunction      
virConnectDomainEventDeregisterAnyNofunction      
virConnectDomainEventGenericCallbackNodelegate      
virConnectDomainEventGraphicsCallbackNodelegate      
virConnectDomainEventIOErrorCallbackNodelegate      
virConnectDomainEventIOErrorReasonCallbackNodelegate      
virConnectDomainEventRTCChangeCallbackNodelegate      
virConnectDomainEventRegisterYesfunctionYes Yes   
virConnectDomainEventRegisterAnyNofunction      
virConnectDomainEventWatchdogCallbackNodelegate      
virConnectDomainXMLFromNativeNofunction      
virConnectDomainXMLToNativeNofunction      
virConnectFindStoragePoolSourcesNofunction      
virConnectGetCapabilitiesYesfunctionYes Yes   
virConnectGetHostnameYesfunctionYes     
virConnectGetLibVersionYesfunctionNo Maybe   
virConnectGetMaxVcpusYesfunctionNo Maybe   
virConnectGetTypeYesfunctionNo Maybe   
virConnectGetURIYesfunctionYes Yes   
virConnectGetVersionYesfunctionNo Maybe   
virConnectIsEncryptedYesfunctionNo Maybe   
virConnectIsSecureYesfunctionNo Maybe   
virConnectListDefinedDomainsYesfunctionYesvirConnectOpenAuthYesYesYesYes
virConnectListDefinedInterfaces YesfunctionYes Yes   
virConnectListDefinedNetworksYesfunctionYes Yes   
virConnectListDefinedStoragePoolsYesfunctionYes Yes   
virConnectListDomainsYesfunctionYesvirConnectOpenAuthYesYesYesYes
virConnectListInterfacesYesfunctionYes Yes, if the host handles the method   
virConnectListNWFilters Nofunction      
virConnectListNetworksYesfunctionYes Yes   
virConnectListSecretsYesfunctionNo Maybe   
virConnectListStoragePoolsYesfunctionYes Yes   
virConnectNumOfDefinedDomainsYesfunctionYesvirConnectOpenAuthYesYesYesYes
virConnectNumOfDefinedInterfacesYesfunctionNo Maybe   
virConnectNumOfDefinedNetworksYesfunctionYes Yes   
virConnectNumOfDefinedStoragePoolsYesfunctionYes Yes   
virConnectNumOfDomainsYesfunctionYesvirConnectOpenAuthYesYesYesYes
virConnectNumOfInterfacesYesfunctionNo Maybe   
virConnectNumOfNWFiltersNofunction      
virConnectNumOfNetworks YesfunctionYes Yes   
virConnectNumOfSecretsYesfunctionNo Maybe   
virConnectNumOfStoragePoolsYesfunctionYes Yes   
virConnectOpenYesfunctionYes Yes   
virConnectOpenAuthYesfunctionYesvirConnectOpenAuthYesYesYesYes
virConnectOpenReadOnlyYesfunctionNo Maybe   
virConnectRefYesfunctionNo Maybe   
virDomainAbortJobNofunction      
virDomainAttachDeviceYesfunctionNo Maybe   
virDomainAttachDeviceFlagsYesfunctionNo Maybe   
virDomainBlockPeekNofunction      
virDomainBlockStatsYesfunctionNo Maybe   
virDomainCoreDumpYesfunctionNo Maybe   
virDomainCreateYesfunctionYes Yes   
virDomainCreateLinuxNofunction      
virDomainCreateWithFlagsNofunction      
virDomainCreateXMLYesfunctionNo Maybe   
virDomainDefineXMLYesfunctionYes Yes   
virDomainDestroyYesfunctionYes Yes   
virDomainDetachDeviceYesfunctionNo Maybe   
virDomainDetachDeviceFlagsYesfunctionNo Maybe   
virDomainFreeYesfunctionYes Yes   
virDomainGetAutostartYesfunctionNo Maybe   
virDomainGetBlockInfoNofunction      
virDomainGetConnectYesfunctionNo Maybe   
virDomainGetIDYesfunctionNo Maybe   
virDomainGetInfoYesfunctionYes Yes   
virDomainGetJobInfoNofunction      
virDomainGetMaxMemoryYesfunctionNo Maybe   
virDomainGetMaxVcpusYesfunctionNo Maybe   
virDomainGetNameYesfunctionYesvirConnectOpenAuthYesYesYesYes
virDomainGetOSTypeYesfunctionNo Maybe   
virDomainGetSchedulerParametersNofunction      
virDomainGetSchedulerTypeNofunction      
virDomainGetSecurityLabelNofunction      
virDomainGetUUIDYesfunctionNo Maybe   
virDomainGetUUIDStringYesfunctionNo Maybe   
virDomainGetVcpusNofunction      
virDomainGetXMLDescYesfunctionYes Yes   
virDomainHasCurrentSnapshotNofunction      
virDomainHasManagedSaveImageNofunction      
virDomainInterfaceStatsNofunction      
virDomainIsActiveYesfunctionYes Yes   
virDomainIsPersistentYesfunctionNo Maybe   
virDomainLookupByIDYesfunctionYesvirConnectOpenAuthYesYesYesYes
virDomainLookupByNameYesfunctionYes Yes   
virDomainLookupByUUIDYesfunctionNo Maybe   
virDomainLookupByUUIDStringYesfunctionNo Maybe   
virDomainManagedSaveNofunction      
virDomainManagedSaveRemoveNofunction      
virDomainMemoryPeekNofunction      
virDomainMemoryStatsNofunction      
virDomainMigrateNofunction      
virDomainMigrateSetMaxDowntimeNofunction      
virDomainMigrateToURINofunction      
virDomainPinVcpuNofunction      
virDomainRebootYesfunctionYes Yes   
virDomainRefYesfunctionNo Maybe   
virDomainRestoreYes functionNo Maybe   
virDomainResumeYesfunctionYes Yes   
virDomainRevertToSnapshotNofunction      
virDomainSaveYesfunctionNo Maybe   
virDomainSetAutostartYesfunctionNo Maybe   
virDomainSetMaxMemoryYesfunctionNo Maybe   
virDomainSetMemoryYesfunctionNo Maybe   
virDomainSetSchedulerParametersNofunction      
virDomainSetVcpusYesfunctionNo Maybe   
virDomainShutdownYesfunctionYes Yes   
virDomainSnapshotCreateXMLNofunction      
virDomainSnapshotCurrentNofunction      
virDomainSnapshotDeleteNofunction      
virDomainSnapshotFreeNofunction      
virDomainSnapshotGetXMLDescNofunction      
virDomainSnapshotListNamesNofunction      
virDomainSnapshotLookupByNameNofunction      
virDomainSnapshotNumNofunction      
virDomainSuspendYesfunctionYes Yes   
virDomainUndefineYesfunctionYes Yes   
virDomainUpdateDeviceFlagsNofunction      
virEventAddHandleFuncYesdelegateYes Yes   
virEventAddTimeoutFuncYesdelegateYes Yes   
virEventHandleCallbackYesdelegateYes Yes   
virEventRegisterImplYesfunctionYes Yes   
virEventRemoveHandleFuncYesdelegateYes Yes   
virEventRemoveTimeoutFuncYesdelegateYes Yes   
virEventTimeoutCallbackYesdelegateYes Yes   
virEventUpdateHandleFuncYesdelegateYes Yes   
virEventUpdateTimeoutFuncYesdelegateYes Yes   
virFreeCallbackYesfunctionYes Yes   
virGetVersionYesfunctionYes Yes   
virInitializeYesfunctionYes Yes   
virInterfaceCreateNofunction      
virInterfaceDefineXMLNofunction      
virInterfaceDestroyNofunction      
virInterfaceFreeNofunction      
virInterfaceGetConnectNofunction      
virInterfaceGetMACStringNofunction      
virInterfaceGetNameNofunction      
virInterfaceGetXMLDescNofunction      
virInterfaceIsActiveNofunction      
virInterfaceLookupByMACStringNofunction      
virInterfaceLookupByNameNofunction      
virInterfaceRefNofunction      
virInterfaceUndefineNofunction      
virNWFilterDefineXMLNofunction      
virNWFilterFreeNofunction      
virNWFilterGetNameNofunction      
virNWFilterGetUUIDNofunction      
virNWFilterGetUUIDStringNofunction      
virNWFilterGetXMLDescNofunction      
virNWFilterLookupByName Nofunction      
virNWFilterLookupByUUIDNofunction      
virNWFilterLookupByUUIDStringNofunction      
virNWFilterRefNofunction      
virNWFilterUndefineNofunction      
virNetworkCreateYesfunctionYes Yes   
virNetworkCreateXMLYesfunctionNo Maybe   
virNetworkDefineXMLYesfunctionYes Yes   
virNetworkDestroyYesfunctionYes Yes   
virNetworkFreeYesfunctionYes Yes   
virNetworkGetAutostartYesfunctionNo Maybe   
virNetworkGetBridgeNameYesfunctionNo Maybe   
virNetworkGetConnectYesfunctionNo Maybe   
virNetworkGetNameYesfunctionNo Maybe   
virNetworkGetUUIDNofunction      
virNetworkGetUUIDString YesfunctionYes Yes   
virNetworkGetXMLDescYesfunctionYes Yes   
virNetworkIsActiveYesfunctionYes Yes   
virNetworkIsPersistentYesfunctionYes Yes   
virNetworkLookupByNameYesfunctionYes Yes   
virNetworkLookupByUUIDYesfunctionNo Maybe   
virNetworkLookupByUUIDStringYesfunctionNo Maybe   
virNetworkRefYesfunctionNo Maybe   
virNetworkSetAutostartYesfunctionYes Yes   
virNetworkUndefineYesfunctionYes Yes   
virNodeDeviceCreateXMLNofunction      
virNodeDeviceDestroyNofunction      
virNodeDeviceDettachNofunction      
virNodeDeviceFreeNofunction      
virNodeDeviceGetNameNofunction      
virNodeDeviceGetParentNofunction      
virNodeDeviceGetXMLDescYesfunctionYes Yes   
virNodeDeviceListCapsNofunction      
virNodeDeviceLookupByNameYesfunctionYes Yes   
virNodeDeviceNumOfCapsNofunction      
virNodeDeviceReAttachNofunction      
virNodeDeviceRefNofunction      
virNodeDeviceResetNofunction      
virNodeGetCellsFreeMemoryNofunction      
virNodeGetFreeMemoryYesfunctionNo Maybe   
virNodeGetInfoYesfunctionNo Maybe   
virNodeGetSecurityModel Nofunction      
virNodeListDevicesYesfunctionYes Yes   
virNodeNumOfDevicesYesfunctionYes Yes   
virSecretDefineXMLNofunction      
virSecretFreeNofunction      
virSecretGetConnectNofunction      
virSecretGetUUIDNofunction      
virSecretGetUUIDStringNofunction      
virSecretGetUsageIDNofunction      
virSecretGetUsageTypeNofunction      
virSecretGetValueNofunction      
virSecretGetXMLDescNofunction      
virSecretLookupByUUIDNofunction      
virSecretLookupByUUIDStringNofunction      
virSecretLookupByUsageNofunction      
virSecretRefNofunction      
virSecretSetValueNofunction      
virSecretUndefineNofunction      
virStoragePoolBuildYesfunctionNo Maybe   
virStoragePoolCreateYesfunctionYes Yes   
virStoragePoolCreateXML YesfunctionNo Maybe   
virStoragePoolDefineXMLYesfunctionYes Yes   
virStoragePoolDeleteYesfunctionNo Maybe   
virStoragePoolDestroyYesfunctionYes Yes   
virStoragePoolFreeYesfunctionYes Yes   
virStoragePoolGetAutostartYesfunctionNo Maybe   
virStoragePoolGetConnectYesfunctionNo Maybe   
virStoragePoolGetInfoYesfunctionYes Yes   
virStoragePoolGetNameYesfunctionYes Yes   
virStoragePoolGetUUIDYesfunctionNo Maybe   
virStoragePoolGetUUIDStringYesfunctionYes Yes   
virStoragePoolGetXMLDescYesfunctionYes Yes   
virStoragePoolIsActiveYesfunctionYes Yes   
virStoragePoolIsPersistentYesfunctionYes Yes   
virStoragePoolListVolumesYesfunctionYes Yes   
virStoragePoolLookupByNameYesfunctionYes Yes   
virStoragePoolLookupByUUIDYesfunctionNo Maybe   
virStoragePoolLookupByUUIDStringYesfunctionNo Maybe   
virStoragePoolLookupByVolumeYesfunctionNo Maybe   
virStoragePoolNumOfVolumesYesfunctionYes Yes   
virStoragePoolRefYesfunctionNo Maybe   
virStoragePoolRefreshYesfunctionNo Maybe   
virStoragePoolSetAutostartYesfunctionYes Yes   
virStoragePoolUndefineYesfunctionYes Yes   
virStorageVolCreateXMLYesfunctionYes Yes   
virStorageVolCreateXMLFromYesfunctionNo Maybe   
virStorageVolDeleteYesfunctionYes Yes   
virStorageVolFreeYesfunctionNo Maybe   
virStorageVolGetConnect YesfunctionNo Maybe   
virStorageVolGetInfoYesfunctionYes Yes   
virStorageVolGetKeyYesfunctionYes Yes   
virStorageVolGetNameYesfunctionYes Yes   
virStorageVolGetPathYesfunctionYes Yes   
virStorageVolGetXMLDesc YesfunctionYes Yes   
virStorageVolLookupByKeyYesfunctionYes Yes   
virStorageVolLookupByNameYesfunctionYes Yes   
virStorageVolLookupByPathYesfunctionYes Yes   
virStorageVolRefYesfunctionNo No   
virStorageVolWipeNofunction      
virStreamAbortNofunction      
virStreamEventAddCallbackNofunction      
virStreamEventCallbackNodelegate      
virStreamEventRemoveCallbackNofunction      
virStreamEventUpdateCallbackNofunction      
virStreamFinish Nofunction      
virStreamFreeNofunction      
virStreamNewNofunction      
virStreamRecvNofunction      
virStreamRecvAllNofunction      
virStreamRefNofunction      
virStreamSendNofunction      
virStreamSendAllNofunction      
virStreamSinkFuncNodelegate      
virStreamSourceFuncNodelegate