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 libvirt C# bindings class library exposes the Libvirt namespace. This namespace exposes all of the needed types (enum, struct), plus many classes exposing the libvirt API methods.

These classes are grouped into functional areas, with each class exposing libvirt methods related to that area.

For example, the libvirt methods related to connections, such as virConnectOpenAuth and virConnectNumOfDomains, are in the Connect class.
They are accessed as Connect.OpenAuth, and Connect.NumOfDomains respectively.

In the same manner, the other class name mappings are:

Name of libvirt functionC# class name
virDomain...Domain
virEvent...Event
virInterface...Interface
virNetwork...Network
virNode...Node
virSecret...Secret
virStoragePool...StoragePool
virStorageVolume...StorageVolume
virStream...Stream

There are some additions as well:

 

Authors

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

 

Test Configuration

Testing is performed using the following configurations:

 

Type Coverage

Coverage of the libvirt types is:

TypeNameBinding?Tested?Sample Code?Works?Tested .Net/Windows Works?Tested Mono (32-bit)/Windows Works?Tested Mono (64-bit)/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      
enumvirDomainEventDefinedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
structvirDomainEventGraphicsAddressNo      
enumvirDomainEventGraphicsAddressTypeNo      
enumvirDomainEventGraphicsPhaseNo      
structvirDomainEventGraphicsSubjectNo      
structvirDomainEventGraphicsSubjectIdentityNo      
enumvirDomainEventIDNo      
enumvirDomainEventIOErrorActionNo      
enumvirDomainEventResumedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventStartedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventStoppedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventSuspendedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventUndefinedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventWatchdogActionNo      
structvirDomainInfoYesYes Yes   
structvirDomainInterfaceStatsStructYesNo Maybe   
structvirDomainJobInfoNo      
enumvirDomainJobTypeNo      
enumvirDomainMemoryFlagsNo      
structvirDomainMemoryStatStructNo      
enumvirDomainMemoryStatTagsYesNo Maybe   
enumvirDomainMigrateFlagsNo      
structvirDomainSnapshotNo      
enumvirDomainSnapshotDeleteFlags       
enumvirDomainStateYesYes Yes   
enumvirDomainXMLFlagsYesYes Yes   
enumvirEventHandleTypeYesYesvirEventRegisterImplYesYesYesYes
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      
enumvirStoragePoolBuildFlagsYesNo Maybe   
enumvirStoragePoolDeleteFlagsYesNo Maybe   
structvirStoragePoolInfoYesYes Yes   
structvirStoragePoolYes, an IntPtr as the struct is not public      
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 (32-bit)/Windows Works?Tested Mono (64-bit)/Linux Works?
virConnectAuthCallbackYesdelegateYesvirConnectOpenAuthYesYesYesYes
virConnectBaselineCPUNofunction      
virConnectCloseYesfunctionYesvirConnectOpenAuthYesYesYesYes
virConnectCompareCPUNofunction      
virConnectDomainEventCallbackYesdelegateYes Yes   
virConnectDomainEventDeregisterNofunction      
virConnectDomainEventDeregisterAnyNofunction      
virConnectDomainEventGenericCallbackNodelegate      
virConnectDomainEventGraphicsCallbackNodelegate      
virConnectDomainEventIOErrorCallbackNodelegate      
virConnectDomainEventIOErrorReasonCallbackNodelegate      
virConnectDomainEventRTCChangeCallbackNodelegate      
virConnectDomainEventRegisterYesfunctionYesvirEventRegisterImplYesYesYesYes
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 handle the method   
virConnectListNWFilters Nofunction      
virConnectListNetworksYesfunctionYes Yes   
virConnectListSecretsYesfunctionNo Maybe   
virConnectListStoragePoolsYesfunctionYesvirConnectOpenYesYesYesYes
virConnectNumOfDefinedDomainsYesfunctionYesvirConnectOpenAuthYesYesYesYes
virConnectNumOfDefinedInterfacesYesfunctionNo Maybe   
virConnectNumOfDefinedNetworksYesfunctionYes Yes   
virConnectNumOfDefinedStoragePoolsYesfunctionYes Yes   
virConnectNumOfDomainsYesfunctionYesvirConnectOpenAuthYesYesYesYes
virConnectNumOfInterfacesYesfunctionNo Maybe   
virConnectNumOfNWFiltersNofunction      
virConnectNumOfNetworks YesfunctionYes Yes   
virConnectNumOfSecretsYesfunctionNo Maybe   
virConnectNumOfStoragePoolsYesfunctionYesvirConnectOpenYesYesYesYes
virConnectOpenYesfunctionYesvirConnectOpen, virEventRegisterImplYesYesYesYes
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      
virDomainInterfaceStats Nofunction      
virDomainIsActiveYesfunctionYes Yes   
virDomainIsPersistentYesfunctionNo Maybe   
virDomainLookupByIDYesfunctionYesvirConnectOpenAuthYesYesYesYes
virDomainLookupByNameYesfunctionYes Yes   
virDomainLookupByUUIDYesfunctionNo Maybe   
virDomainLookupByUUIDStringYesfunctionNo Maybe   
virDomainManagedSave Nofunction      
virDomainManagedSaveRemoveNofunction      
virDomainMemoryPeekNofunction      
virDomainMemoryStatsNofunction      
virDomainMigrateNofunction      
virDomainMigrateSetMaxDowntimeNofunction      
virDomainMigrateToURI Nofunction      
virDomainPinVcpuNofunction      
virDomainRebootYesfunctionYes Yes   
virDomainRef YesfunctionNo Maybe   
virDomainRestoreYes functionNo Maybe   
virDomainResume YesfunctionYes Yes   
virDomainRevertToSnapshotNofunction      
virDomainSaveYesfunctionNo Maybe   
virDomainSetAutostartYesfunctionNo Maybe   
virDomainSetMaxMemory YesfunctionNo 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   
virEventHandleCallbackYesdelegateYesvirEventRegisterImplYesYesYesYes
virEventRegisterImplYesfunctionYesvirEventRegisterImplYesYesYesYes
virEventRemoveHandleFuncYesdelegateYes Yes   
virEventRemoveTimeoutFuncYesdelegateYes Yes   
virEventTimeoutCallbackYesdelegateYesvirEventRegisterImplYesYesYesYes
virEventUpdateHandleFuncYesdelegateYes Yes   
virEventUpdateTimeoutFuncYesdelegateYes Yes   
virFreeCallbackYesfunctionYesvirEventRegisterImplYesYesYesYes
virGetVersionYesfunctionYes Yes   
virInitializeYesfunctionYes Yes   
virInterfaceCreateNofunction      
virInterfaceDefineXMLNofunction      
virInterfaceDestroyNofunction      
virInterfaceFreeNofunction      
virInterfaceGetConnectNofunction      
virInterfaceGetMACStringNofunction      
virInterfaceGetNameNofunction      
virInterfaceGetXMLDescNofunction      
virInterfaceIsActiveNofunction      
virInterfaceLookupByMACStringNofunction      
virInterfaceLookupByNameNofunction      
virInterfaceRef Nofunction      
virInterfaceUndefineNofunction      
virNWFilterDefineXMLNofunction      
virNWFilterFreeNofunction      
virNWFilterGetNameNofunction      
virNWFilterGetUUIDNofunction      
virNWFilterGetUUIDStringNofunction      
virNWFilterGetXMLDescNofunction      
virNWFilterLookupByName Nofunction      
virNWFilterLookupByUUIDNofunction      
virNWFilterLookupByUUIDStringNofunction      
virNWFilterRef Nofunction      
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      
virSecretFree Nofunction      
virSecretGetConnectNofunction      
virSecretGetUUIDNofunction      
virSecretGetUUIDString Nofunction      
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      
virStreamAbort Nofunction      
virStreamEventAddCallbackNofunction      
virStreamEventCallbackNodelegate      
virStreamEventRemoveCallbackNofunction      
virStreamEventUpdateCallbackNofunction      
virStreamFinish Nofunction      
virStreamFree Nofunction      
virStreamNewNofunction      
virStreamRecvNofunction      
virStreamRecvAllNofunction      
virStreamRefNofunction      
virStreamSendNofunction      
virStreamSendAllNofunction      
virStreamSinkFuncNodelegate      
virStreamSourceFuncNodelegate