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 gitlab.com:

git clone https://gitlab.com/libvirt/libvirt-csharp.git

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 publicYesYes
structvirConnectAuthYesYesvirConnectOpenAuthYesYesYesYes
structvirConnectCredentialYesYesvirConnectOpenAuthYesYesYesYes
enumvirConnectCredentialTypeYesYesvirConnectOpenAuthYesYesYesYes
enumvirConnectFlagsNo
structvirDomainYes, an IntPtr as the struct is not public
structvirDomainBlockInfoNo
structvirDomainBlockStatsInfoYesYesvirDomainStatsYesYesYesYes
enumvirDomainCoreDumpFlagsNo
enumvirDomainCreateFlagsNo
enumvirDomainDeviceModifyFlagsNo
enumvirDomainEventDefinedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
structvirDomainEventGraphicsAddressNo
enumvirDomainEventGraphicsAddressTypeNo
enumvirDomainEventGraphicsPhaseNo
structvirDomainEventGraphicsSubjectNo
structvirDomainEventGraphicsSubjectIdentityNo
enumvirDomainEventIDNo
enumvirDomainEventIOErrorActionNo
enumvirDomainEventResumedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventStartedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventStoppedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventSuspendedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventUndefinedDetailTypeYesYesvirEventRegisterImplYesYesYesYes
enumvirDomainEventWatchdogActionNo
structvirDomainInfoYesYesvirConnectSetErrorFunc, virDomainStatsYesYesYesYes
structvirDomainInterfaceStatsStructYesYesvirDomainStatsYesYesYesYes
structvirDomainJobInfoNo
enumvirDomainJobTypeNo
enumvirDomainMemoryFlagsNo
structvirDomainMemoryStatStructNo
enumvirDomainMemoryStatTagsYesNoMaybe
enumvirDomainMigrateFlagsNo
structvirDomainSnapshotNo
enumvirDomainSnapshotDeleteFlags
enumvirDomainStateYesYesYes
enumvirDomainXMLFlagsYesYesYes
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
structvirNodeInfoYesNoMaybe
structvirSchedParameterNo
enumvirSchedParameterTypeNo
structvirSecretNo
enumvirSecretUsageTypeNo
structvirSecurityLabelNo
structvirSecurityModelNo
enumvirStoragePoolBuildFlagsYesNoMaybe
enumvirStoragePoolDeleteFlagsYesNoMaybe
structvirStoragePoolInfoYesYesYes
structvirStoragePoolYes, an IntPtr as the struct is not public
enumvirStoragePoolStateYesYesYes
structvirStorageVolYes, an IntPtr as the struct is not public
enumvirStorageVolDeleteFlagsNo
structvirStorageVolInfoYesYesYes
enumvirStorageVolTypeYesYesYes
structvirStreamNo
enumvirStreamEventTypeNo
enumvirStreamFlagsNo
structvirVcpuInfoNo
enumvirVcpuStateNo
structvirErrorYesYesvirConnectSetErrorFunc, virDomainStatsYesYesYesYes

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
virConnectDomainEventCallbackYesdelegateYesYes
virConnectDomainEventDeregisterNofunction
virConnectDomainEventDeregisterAnyNofunction
virConnectDomainEventGenericCallbackNodelegate
virConnectDomainEventGraphicsCallbackNodelegate
virConnectDomainEventIOErrorCallbackNodelegate
virConnectDomainEventIOErrorReasonCallbackNodelegate
virConnectDomainEventRTCChangeCallbackNodelegate
virConnectDomainEventRegisterYesfunctionYesvirEventRegisterImplYesYesYesYes
virConnectDomainEventRegisterAnyNofunction
virConnectDomainEventWatchdogCallbackNodelegate
virConnectDomainXMLFromNativeNofunction
virConnectDomainXMLToNativeNofunction
virConnectFindStoragePoolSourcesNofunction
virConnectGetCapabilitiesYesfunctionYesYes
virConnectGetHostnameYesfunctionYes
virConnectGetLibVersionYesfunctionNoMaybe
virConnectGetMaxVcpusYesfunctionNoMaybe
virConnectGetTypeYesfunctionNoMaybe
virConnectGetURIYesfunctionYesYes
virConnectGetVersionYesfunctionNoMaybe
virConnectIsEncryptedYesfunctionNoMaybe
virConnectIsSecureYesfunctionNoMaybe
virConnectListDefinedDomainsYesfunctionYesvirConnectOpenAuthYesYesYesYes
virConnectListDefinedInterfaces YesfunctionYesYes
virConnectListDefinedNetworksYesfunctionYesYes
virConnectListDefinedStoragePoolsYesfunctionYesYes
virConnectListDomainsYesfunctionYesvirConnectOpenAuth, virDomainInfosYesYesYesYes
virConnectListInterfacesYesfunctionYesYes, if the host handle the method
virConnectListNWFilters Nofunction
virConnectListNetworksYesfunctionYesYes
virConnectListSecretsYesfunctionNoMaybe
virConnectListStoragePoolsYesfunctionYesvirConnectOpenYesYesYesYes
virConnectNumOfDefinedDomainsYesfunctionYesvirConnectOpenAuthYesYesYesYes
virConnectNumOfDefinedInterfacesYesfunctionNoMaybe
virConnectNumOfDefinedNetworksYesfunctionYesYes
virConnectNumOfDefinedStoragePoolsYesfunctionYesYes
virConnectNumOfDomainsYesfunctionYesvirConnectOpenAuth, virDomainInfosYesYesYesYes
virConnectNumOfInterfacesYesfunctionNoMaybe
virConnectNumOfNWFiltersNofunction
virConnectNumOfNetworks YesfunctionYesYes
virConnectNumOfSecretsYesfunctionNoMaybe
virConnectNumOfStoragePoolsYesfunctionYesvirConnectOpenYesYesYesYes
virConnectOpenYesfunctionYesvirConnectOpen, virEventRegisterImpl, virDomainInfosYesYesYesYes
virConnectOpenAuthYesfunctionYesvirConnectOpenAuthYesYesYesYes
virConnectOpenReadOnlyYesfunctionNoMaybe
virConnectRefYesfunctionNoMaybe
virDomainAbortJobNofunction
virDomainAttachDeviceYesfunctionNoMaybe
virDomainAttachDeviceFlagsYesfunctionNoMaybe
virDomainBlockPeekNofunction
virDomainBlockStatsYesfunctionYesvirDomainInfosYesYesYesYes
virDomainCoreDumpYesfunctionNoMaybe
virDomainCreateYesfunctionYesYes
virDomainCreateLinuxNofunction
virDomainCreateWithFlagsNofunction
virDomainCreateXMLYesfunctionNoMaybe
virDomainDefineXMLYesfunctionYesYes
virDomainDestroyYesfunctionYesYes
virDomainDetachDeviceYesfunctionNoMaybe
virDomainDetachDeviceFlagsYesfunctionNoMaybe
virDomainFreeYesfunctionYesYes
virDomainGetAutostartYesfunctionNoMaybe
virDomainGetBlockInfoNofunction
virDomainGetConnectYesfunctionNoMaybe
virDomainGetIDYesfunctionNoMaybe
virDomainGetInfoYesfunctionYesvirDomainInfosYesYesYesYes
virDomainGetJobInfoNofunction
virDomainGetMaxMemoryYesfunctionNoMaybe
virDomainGetMaxVcpusYesfunctionNoMaybe
virDomainGetNameYesfunctionYesvirConnectOpenAuth, virDomainInfosYesYesYesYes
virDomainGetOSTypeYesfunctionNoMaybe
virDomainGetSchedulerParametersNofunction
virDomainGetSchedulerTypeNofunction
virDomainGetSecurityLabelNofunction
virDomainGetUUIDYesfunctionNoMaybe
virDomainGetUUIDStringYesfunctionNoMaybe
virDomainGetVcpusNofunction
virDomainGetXMLDescYesfunctionYesvirDomainInfosYesYesYesYes
virDomainHasCurrentSnapshotNofunction
virDomainHasManagedSaveImageNofunction
virDomainInterfaceStats NofunctionYesvirDomainInfosYesYesYesYes
virDomainIsActiveYesfunctionYesYes
virDomainIsPersistentYesfunctionNoMaybe
virDomainLookupByIDYesfunctionYesvirConnectOpenAuth, virDomainInfosYesYesYesYes
virDomainLookupByNameYesfunctionYesvirDomainInfosYesYesYesYes
virDomainLookupByUUIDYesfunctionNoMaybe
virDomainLookupByUUIDStringYesfunctionNoMaybe
virDomainManagedSave Nofunction
virDomainManagedSaveRemoveNofunction
virDomainMemoryPeekNofunction
virDomainMemoryStatsNofunction
virDomainMigrateNofunction
virDomainMigrateSetMaxDowntimeNofunction
virDomainMigrateToURI Nofunction
virDomainPinVcpuNofunction
virDomainRebootYesfunctionYesYes
virDomainRef YesfunctionNoMaybe
virDomainRestoreYes functionNoMaybe
virDomainResume YesfunctionYesYes
virDomainRevertToSnapshotNofunction
virDomainSaveYesfunctionNoMaybe
virDomainSetAutostartYesfunctionNoMaybe
virDomainSetMaxMemory YesfunctionNoMaybe
virDomainSetMemoryYesfunctionNoMaybe
virDomainSetSchedulerParametersNofunction
virDomainSetVcpusYesfunctionNoMaybe
virDomainShutdownYesfunctionYesYes
virDomainSnapshotCreateXMLNofunction
virDomainSnapshotCurrentNofunction
virDomainSnapshotDeleteNofunction
virDomainSnapshotFreeNofunction
virDomainSnapshotGetXMLDescNofunction
virDomainSnapshotListNamesNofunction
virDomainSnapshotLookupByNameNofunction
virDomainSnapshotNumNofunction
virDomainSuspendYesfunctionYesYes
virDomainUndefineYesfunctionYesYes
virDomainUpdateDeviceFlagsNofunction
virEventAddHandleFuncYesdelegateYesYes
virEventAddTimeoutFuncYesdelegateYesYes
virEventHandleCallbackYesdelegateYesvirEventRegisterImplYesYesYesYes
virEventRegisterImplYesfunctionYesvirEventRegisterImplYesYesYesYes
virEventRemoveHandleFuncYesdelegateYesYes
virEventRemoveTimeoutFuncYesdelegateYesYes
virEventTimeoutCallbackYesdelegateYesvirEventRegisterImplYesYesYesYes
virEventUpdateHandleFuncYesdelegateYesYes
virEventUpdateTimeoutFuncYesdelegateYesYes
virFreeCallbackYesfunctionYesvirEventRegisterImplYesYesYesYes
virGetVersionYesfunctionYesYes
virInitializeYesfunctionYesYes
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
virNetworkCreateYesfunctionYesYes
virNetworkCreateXMLYesfunctionNoMaybe
virNetworkDefineXMLYesfunctionYesYes
virNetworkDestroyYesfunctionYesYes
virNetworkFreeYesfunctionYesYes
virNetworkGetAutostartYesfunctionNoMaybe
virNetworkGetBridgeNameYesfunctionNoMaybe
virNetworkGetConnectYesfunctionNoMaybe
virNetworkGetNameYesfunctionNoMaybe
virNetworkGetUUIDNofunction
virNetworkGetUUIDString YesfunctionYesYes
virNetworkGetXMLDescYesfunctionYesYes
virNetworkIsActiveYesfunctionYesYes
virNetworkIsPersistentYesfunctionYesYes
virNetworkLookupByNameYesfunctionYesYes
virNetworkLookupByUUIDYesfunctionNoMaybe
virNetworkLookupByUUIDStringYesfunctionNoMaybe
virNetworkRefYesfunctionNoMaybe
virNetworkSetAutostartYesfunctionYesYes
virNetworkUndefineYesfunctionYesYes
virNodeDeviceCreateXMLNofunction
virNodeDeviceDestroyNofunction
virNodeDeviceDettachNofunction
virNodeDeviceFreeNofunction
virNodeDeviceGetNameNofunction
virNodeDeviceGetParentNofunction
virNodeDeviceGetXMLDescYesfunctionYesYes
virNodeDeviceListCapsNofunction
virNodeDeviceLookupByNameYesfunctionYesYes
virNodeDeviceNumOfCapsNofunction
virNodeDeviceReAttachNofunction
virNodeDeviceRefNofunction
virNodeDeviceResetNofunction
virNodeGetCellsFreeMemoryNofunction
virNodeGetFreeMemoryYesfunctionNoMaybe
virNodeGetInfoYesfunctionNoMaybe
virNodeGetSecurityModel Nofunction
virNodeListDevicesYesfunctionYesYes
virNodeNumOfDevicesYesfunctionYesYes
virSecretDefineXMLNofunction
virSecretFree Nofunction
virSecretGetConnectNofunction
virSecretGetUUIDNofunction
virSecretGetUUIDString Nofunction
virSecretGetUsageIDNofunction
virSecretGetUsageTypeNofunction
virSecretGetValueNofunction
virSecretGetXMLDescNofunction
virSecretLookupByUUIDNofunction
virSecretLookupByUUIDStringNofunction
virSecretLookupByUsageNofunction
virSecretRefNofunction
virSecretSetValueNofunction
virSecretUndefineNofunction
virStoragePoolBuildYesfunctionNoMaybe
virStoragePoolCreateYesfunctionYesYes
virStoragePoolCreateXML YesfunctionNoMaybe
virStoragePoolDefineXMLYesfunctionYesYes
virStoragePoolDeleteYesfunctionNoMaybe
virStoragePoolDestroyYesfunctionYesYes
virStoragePoolFreeYesfunctionYesYes
virStoragePoolGetAutostartYesfunctionNoMaybe
virStoragePoolGetConnectYesfunctionNoMaybe
virStoragePoolGetInfoYesfunctionYesYes
virStoragePoolGetNameYesfunctionYesYes
virStoragePoolGetUUIDYesfunctionNoMaybe
virStoragePoolGetUUIDStringYesfunctionYesYes
virStoragePoolGetXMLDescYesfunctionYesYes
virStoragePoolIsActiveYesfunctionYesYes
virStoragePoolIsPersistentYesfunctionYesYes
virStoragePoolListVolumesYesfunctionYesYes
virStoragePoolLookupByNameYesfunctionYesYes
virStoragePoolLookupByUUIDYesfunctionNoMaybe
virStoragePoolLookupByUUIDStringYesfunctionNoMaybe
virStoragePoolLookupByVolumeYesfunctionNoMaybe
virStoragePoolNumOfVolumesYesfunctionYesYes
virStoragePoolRefYesfunctionNoMaybe
virStoragePoolRefreshYesfunctionNoMaybe
virStoragePoolSetAutostartYesfunctionYesYes
virStoragePoolUndefineYesfunctionYesYes
virStorageVolCreateXMLYesfunctionYesYes
virStorageVolCreateXMLFromYesfunctionNoMaybe
virStorageVolDeleteYesfunctionYesYes
virStorageVolFreeYesfunctionNoMaybe
virStorageVolGetConnect YesfunctionNoMaybe
virStorageVolGetInfoYesfunctionYesYes
virStorageVolGetKeyYesfunctionYesYes
virStorageVolGetNameYesfunctionYesYes
virStorageVolGetPathYesfunctionYesYes
virStorageVolGetXMLDesc YesfunctionYesYes
virStorageVolLookupByKeyYesfunctionYesYes
virStorageVolLookupByNameYesfunctionYesYes
virStorageVolLookupByPathYesfunctionYesYes
virStorageVolRefYesfunctionNoNo
virStorageVolWipeNofunction
virStreamAbort Nofunction
virStreamEventAddCallbackNofunction
virStreamEventCallbackNodelegate
virStreamEventRemoveCallbackNofunction
virStreamEventUpdateCallbackNofunction
virStreamFinish Nofunction
virStreamFree Nofunction
virStreamNewNofunction
virStreamRecvNofunction
virStreamRecvAllNofunction
virStreamRefNofunction
virStreamSendNofunction
virStreamSendAllNofunction
virStreamSinkFuncNodelegate
virStreamSourceFuncNodelegate
virGetLastErrorYesfunctionYesvirConnectSetErrorFuncYesYesYesYes
virConnSetErrorFuncYesfunctionYesvirConnectSetErrorFuncYesYesYesYes
virErrorFuncYesdelegateYesvirConnectSetErrorFunc, virDomainInfosYesYesYesYes