commit d278629910422efd2ed8540a55d913b022c7c3ab Author: Arnaud Date: Wed Oct 6 15:47:23 2010 +0200 Signed-off-by: Arnaud diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96a9b41 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ + +_ReSharper* +*.obj +*.pdb +Thumbs.db +*.dll +obj/ +[Bb]in/ +[Dd]ebug +*.suo +[Rr]elease/ \ No newline at end of file diff --git a/Libvirt.cs b/Libvirt.cs new file mode 100644 index 0000000..287a953 --- /dev/null +++ b/Libvirt.cs @@ -0,0 +1,2149 @@ +/* + * Copyright (C) + * Arnaud Champion + * Jaromír Červenka + * + * See COPYING.LIB for the License of this software + */ + +using System; +using System.Runtime.InteropServices; + +namespace LibvirtBindings +{ + /// + /// Libvirt Binding class + /// + public class libVirt + { + private const int MaxStringLength = 1024; + + #region Connect + /// + /// This function closes the connection to the Hypervisor. This should not be called if further interaction with the Hypervisor are needed especially if there is running domain which need further monitoring by the application. + /// + /// pointer to the hypervisor connection + /// 0 in case of success or -1 in case of error. + [DllImport("libvirt-0.dll")] + public static extern int virConnectClose(IntPtr conn); + /// + /// Provides capabilities of the hypervisor / driver. + /// + /// pointer to the hypervisor connection + /// NULL in case of error, or an XML string defining the capabilities. The client must free the returned string after use. + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virConnectGetCapabilities(IntPtr conn); + /// + /// This returns the system hostname on which the hypervisor is running (the result of the gethostname system call). If we are connected to a remote system, then this returns the hostname of the remote system. + /// + /// pointer to a hypervisor connection + /// the hostname which must be freed by the caller, or NULL if there was an error. + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virConnectGetHostname(IntPtr conn); + /// + /// Provides @libVer, which is the version of libvirt used by the daemon running on the @conn host + /// + /// pointer to the hypervisor connection + /// returns the libvirt library version used on the connection (OUT) + /// -1 in case of failure, 0 otherwise, and values for @libVer have the format major * 1,000,000 + minor * 1,000 + release. + [DllImport("libvirt-0.dll")] + public static extern int virConnectGetLibVersion(IntPtr conn, ref ulong libVer); + /// + /// Provides the maximum number of virtual CPUs supported for a guest VM of a specific type. The 'type' parameter here corresponds to the 'type' attribute in the domain element of the XML. + /// + /// pointer to the hypervisor connection + /// value of the 'type' attribute in the domain element + /// the maximum of virtual CPU or -1 in case of error. + [DllImport("libvirt-0.dll")] + public static extern int virConnectGetMaxVcpus(IntPtr conn, string type); + /// + /// Get the name of the Hypervisor software used. + /// + /// pointer to the hypervisor connection + /// NULL in case of error, a static zero terminated string otherwise. See also: http://www.redhat.com/archives/libvir-list/2007-February/msg00096.html + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virConnectGetType(IntPtr conn); + /// + /// This returns the Uri (name) of the hypervisor connection. Normally this is the same as or similar to the string passed to the virConnectOpen/virConnectOpenReadOnly call, but the driver may make the Uri canonical. If name == NULL was passed to virConnectOpen, then the driver will return a non-NULL Uri which can be used to connect to the same hypervisor later. + /// + /// pointer to a hypervisor connection + /// the Uri string which must be freed by the caller, or NULL if there was an error. + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virConnectGetURI(IntPtr conn); + /// + /// Get the version level of the Hypervisor running. This may work only with hypervisor call, i.e. with privileged access to the hypervisor, not with a Read-Only connection. + /// + /// pointer to the hypervisor connection + /// return value for the version of the running hypervisor (OUT) + /// -1 in case of error, 0 otherwise. if the version can't be extracted by lack of capacities returns 0 and @hvVer is 0, otherwise @hvVer value is major * 1,000,000 + minor * 1,000 + release + [DllImport("libvirt-0.dll")] + public static extern int virConnectGetVersion(IntPtr conn, ref ulong hvVer); + /// + /// Determine if the connection to the hypervisor is encrypted + /// + /// pointer to the connection object + /// 1 if encrypted, 0 if not encrypted, -1 on error + [DllImport("libvirt-0.dll")] + public static extern int virConnectIsEncrypted(IntPtr conn); + /// + /// Determine if the connection to the hypervisor is secure A connection will be classed as secure if it is either encrypted, or running over a channel which is not exposed to eavesdropping (eg a UNIX domain socket, or pipe) + /// + /// pointer to the connection object + /// 1 if secure, 0 if secure, -1 on error + [DllImport("libvirt-0.dll")] + public static extern int virConnectIsSecure(IntPtr conn); + /// + /// list the defined but inactive domains, stores the pointers to the names in @names + /// + /// pointer to the hypervisor connection + /// pointer to an array to store the names + /// size of the array + /// the number of names provided in the array or -1 in case of error + [DllImport("libvirt-0.dll")] + private static extern int virConnectListDefinedDomains(IntPtr conn, IntPtr names, int maxnames); + /// + /// list the defined but inactive domains, stores the pointers to the names in @names + /// + /// pointer to the hypervisor connection + /// pointer to an array to store the names + /// size of the array + /// the number of names provided in the array or -1 in case of error + public static int virConnectListDefinedDomains(IntPtr conn, ref string[] names, int maxnames) + { + IntPtr namesPtr = Marshal.AllocHGlobal(MaxStringLength); + int count = virConnectListDefinedDomains(conn, namesPtr, maxnames); + if (count > 0) + names = ptrToStringArray(namesPtr, count); + Marshal.FreeHGlobal(namesPtr); + return count; + } + /// + /// Collect the list of defined (inactive) physical host interfaces, and store their names in @names. + /// + /// pointer to the hypervisor connection + /// array to collect the list of names of interfaces + /// size of @names + /// the number of interfaces found or -1 in case of error + [DllImport("libvirt-0.dll")] + private static extern int virConnectListDefinedInterfaces(IntPtr conn, IntPtr names, int maxnames); + /// + /// Collect the list of defined (inactive) physical host interfaces, and store their names in @names. + /// + ///pointer to the hypervisor connection + ///array to collect the list of names of interfaces + ///size of @names + ///the number of interfaces found or -1 in case of error + public static int virConnectListDefinedInterfaces(IntPtr conn, ref string[] names, int maxnames) + { + IntPtr namesPtr = Marshal.AllocHGlobal(MaxStringLength); + int count = virConnectListDefinedInterfaces(conn, namesPtr, maxnames); + if (count > 0) + names = ptrToStringArray(namesPtr, count); + Marshal.FreeHGlobal(namesPtr); + return count; + } + /// + /// list the inactive networks, stores the pointers to the names in @names + /// + /// pointer to the hypervisor connection + /// pointer to an array to store the names + /// size of the array + /// the number of names provided in the array or -1 in case of error + [DllImport("libvirt-0.dll")] + private static extern int virConnectListDefinedNetworks(IntPtr conn, IntPtr names, int maxnames); + /// + /// list the inactive networks, stores the pointers to the names in @names + /// + /// pointer to the hypervisor connection + /// pointer to an array to store the names + /// size of the array + /// the number of names provided in the array or -1 in case of error + public static int virConnectListDefinedNetworks(IntPtr conn, ref string[] names, int maxnames) + { + IntPtr namesPtr = Marshal.AllocHGlobal(MaxStringLength); + int count = virConnectListDefinedNetworks(conn, namesPtr, maxnames); + if (count > 0) + names = ptrToStringArray(namesPtr, count); + Marshal.FreeHGlobal(namesPtr); + return count; + } + /// + /// Provides the list of names of inactive storage pools upto maxnames. If there are more than maxnames, the remaining names will be silently ignored. + /// + /// pointer to hypervisor connection + /// array of char * to fill with pool names (allocated by caller) + /// size of the names array + /// 0 on success, -1 on error + [DllImport("libvirt-0.dll")] + private static extern int virConnectListDefinedStoragePools(IntPtr conn, IntPtr names, int maxnames); + /// + /// Provides the list of names of inactive storage pools upto maxnames. If there are more than maxnames, the remaining names will be silently ignored. + /// + /// pointer to hypervisor connection + /// array of char * to fill with pool names (allocated by caller) + /// size of the names array + /// 0 on success, -1 on error + public static int virConnectListDefinedStoragePools(IntPtr conn, ref string[] names, int maxnames) + { + IntPtr namesPtr = Marshal.AllocHGlobal(MaxStringLength); + int count = virConnectListDefinedStoragePools(conn, namesPtr, maxnames); + if (count > 0) + names = ptrToStringArray(namesPtr, count); + Marshal.FreeHGlobal(namesPtr); + return count; + } + /// + /// Collect the list of active domains, and store their ID in @maxids + /// + /// pointer to the hypervisor connection + /// array to collect the list of IDs of active domains + /// size of @ids + /// the number of domain found or -1 in case of error + [DllImport("libvirt-0.dll")] + public static extern int virConnectListDomains(IntPtr conn, int[] ids, int maxids); + /// + /// Collect the list of active physical host interfaces, and store their names in @names + /// + /// pointer to the hypervisor connection + /// array to collect the list of names of interfaces + /// size of @names + /// the number of interfaces found or -1 in case of error + [DllImport("libvirt-0.dll")] + private static extern int virConnectListInterfaces(IntPtr conn, IntPtr names, int maxnames); + /// + /// Collect the list of active physical host interfaces, and store their names in @names + /// + /// pointer to the hypervisor connection + /// array to collect the list of names of interfaces + /// size of @names + /// the number of interfaces found or -1 in case of error + public static int virConnectListInterfaces(IntPtr conn, ref string[] names, int maxnames) + { + IntPtr namesPtr = Marshal.AllocHGlobal(MaxStringLength); + int count = virConnectListInterfaces(conn, namesPtr, maxnames); + if (count > 0) + names = ptrToStringArray(namesPtr, count); + Marshal.FreeHGlobal(namesPtr); + return count; + } + /// + /// Collect the list of active networks, and store their names in @names + /// + /// pointer to the hypervisor connection + /// array to collect the list of names of active networks + /// size of @names + /// the number of networks found or -1 in case of error + [DllImport("libvirt-0.dll")] + private static extern int virConnectListNetworks(IntPtr conn, IntPtr names, int maxnames); + /// + /// Collect the list of active networks, and store their names in @names + /// + /// pointer to the hypervisor connection + /// array to collect the list of names of active networks + /// size of @names + /// the number of networks found or -1 in case of error + public static int virConnectListNetworks(IntPtr conn, ref string[] names, int maxnames) + { + IntPtr namesPtr = Marshal.AllocHGlobal(MaxStringLength); + int count = virConnectListNetworks(conn, namesPtr, maxnames); + if (count > 0) + names = ptrToStringArray(namesPtr, count); + Marshal.FreeHGlobal(namesPtr); + return count; + } + /// + /// List UUIDs of defined secrets, store pointers to names in uuids. + /// + /// virConnect connection + /// Pointer to an array to store the UUIDs + /// size of the array. + /// the number of UUIDs provided in the array, or -1 on failure. + [DllImport("libvirt-0.dll")] + private static extern int virConnectListSecrets(IntPtr conn, IntPtr uuids, int maxuuids); + /// + /// List UUIDs of defined secrets, store pointers to names in uuids. + /// + /// virConnect connection + /// Pointer to an array to store the UUIDs + /// size of the array. + /// the number of UUIDs provided in the array, or -1 on failure. + public static int virConnectListSecrets(IntPtr conn, ref string[] uuids, int maxuuids) + { + IntPtr namesPtr = Marshal.AllocHGlobal(MaxStringLength); + int count = virConnectListSecrets(conn, namesPtr, maxuuids); + if (count > 0) + uuids = ptrToStringArray(namesPtr, count); + Marshal.FreeHGlobal(namesPtr); + return count; + } + /// + /// Provides the list of names of active storage pools upto maxnames. If there are more than maxnames, the remaining names will be silently ignored. + /// + /// pointer to hypervisor connection + /// array of char * to fill with pool names (allocated by caller) + /// size of the names array + /// 0 on success, -1 on error + [DllImport("libvirt-0.dll")] + private static extern int virConnectListStoragePools(IntPtr conn, IntPtr names, int maxnames); + /// + /// Provides the list of names of active storage pools upto maxnames. If there are more than maxnames, the remaining names will be silently ignored. + /// + /// pointer to hypervisor connection + /// array of char * to fill with pool names (allocated by caller) + /// size of the names array + /// 0 on success, -1 on error + public static int virConnectListStoragePools(IntPtr conn, ref string[] names, int maxnames) + { + IntPtr namesPtr = Marshal.AllocHGlobal(MaxStringLength); + int count = virConnectListStoragePools(conn, namesPtr, maxnames); + if (count > 0) + names = ptrToStringArray(namesPtr, count); + Marshal.FreeHGlobal(namesPtr); + return count; + } + /// + /// Provides the number of defined but inactive domains. + /// + /// pointer to the hypervisor connection + /// the number of domain found or -1 in case of error + [DllImport("libvirt-0.dll")] + public static extern int virConnectNumOfDefinedDomains(IntPtr conn); + /// + /// Provides the number of defined (inactive) interfaces on the physical host. + /// + /// pointer to the hypervisor connection + /// the number of defined interface found or -1 in case of error + [DllImport("libvirt-0.dll")] + public static extern int virConnectNumOfDefinedInterfaces(IntPtr conn); + /// + /// Provides the number of inactive networks. + /// + /// pointer to the hypervisor connection + /// the number of networks found or -1 in case of error + [DllImport("libvirt-0.dll")] + public static extern int virConnectNumOfDefinedNetworks(IntPtr conn); + /// + /// Provides the number of inactive storage pools + /// + /// pointer to hypervisor connection + /// the number of pools found, or -1 on error + [DllImport("libvirt-0.dll")] + public static extern int virConnectNumOfDefinedStoragePools(IntPtr conn); + /// + /// Provides the number of active domains. + /// + /// pointer to the hypervisor connection + /// the number of domain found or -1 in case of error + [DllImport("libvirt-0.dll")] + public static extern int virConnectNumOfDomains(IntPtr conn); + /// + /// Provides the number of active interfaces on the physical host. + /// + /// pointer to the hypervisor connection + /// the number of active interfaces found or -1 in case of error + [DllImport("libvirt-0.dll")] + public static extern int virConnectNumOfInterfaces(IntPtr conn); + /// + /// Provides the number of active networks. + /// + /// pointer to the hypervisor connection + /// the number of network found or -1 in case of error + [DllImport("libvirt-0.dll")] + public static extern int virConnectNumOfNetworks(IntPtr conn); + /// + /// Fetch number of currently defined secrets. + /// + /// virConnect connection + /// the number currently defined secrets. + [DllImport("libvirt-0.dll")] + public static extern int virConnectNumOfSecrets(IntPtr conn); + /// + /// Provides the number of active storage pools + /// + /// pointer to hypervisor connection + /// the number of pools found, or -1 on error + [DllImport("libvirt-0.dll")] + public static extern int virConnectNumOfStoragePools(IntPtr conn); + /// + /// This function should be called first to get a connection to the Hypervisor and xen store + /// + /// Uri of the hypervisor + /// pointer to the connection + [DllImport("libvirt-0.dll")] + public static extern IntPtr virConnectOpen(string name); + + /// + /// This function should be called first to get a connection to the Hypervisor. If necessary, authentication will be performed fetching credentials via the callback See virConnectOpen for notes about environment variables which can have an effect on opening drivers + /// + ///URI of the hypervisor + ///Authenticate callback parameters + ///Open flags + ///a pointer to the hypervisor connection or NULL in case of error URIs are documented at http://libvirt.org/uri.html + [DllImport("libvirt-0.dll")] + public static extern IntPtr virConnectOpenAuth(string name, [In] ref virConnectAuth auth, int flags); + + /// + /// This function should be called first to get a restricted connection to the library functionalities. The set of APIs usable are then restricted on the available methods to control the domains. See virConnectOpen for notes about environment variables which can have an effect on opening drivers + /// + /// Uri of the hypervisor + /// a pointer to the hypervisor connection or NULL in case of error URIs are documented at http://libvirt.org/uri.html + [DllImport("libvirt-0.dll")] + public static extern IntPtr virConnectOpenReadOnly(string name); + /// + /// Increment the reference count on the connection. For each additional call to this method, there shall be a corresponding call to virConnectClose to release the reference count, once the caller no longer needs the reference to this object. This method is typically useful for applications where multiple threads are using a connection, and it is required that the connection remain open until all threads have finished using it. ie, each new thread using a connection would increment the reference count. + /// + /// the connection to hold a reference on + /// 0 in case of success, -1 in case of failure + [DllImport("libvirt-0.dll")] + public static extern int virConnectRef(IntPtr conn); + #endregion + + #region Domain + /// + /// Create a virtual device attachment to backend. This function, having hotplug semantics, is only allowed on an active domain. + /// + /// pointer to domain object + /// pointer to XML description of one device + /// 0 in case of success, -1 in case of failure. + [DllImport("libvirt-0.dll")] + public static extern int virDomainAttachDevice(IntPtr domain, string xml); + /// + /// Attach a virtual device to a domain, using the flags parameter to control how the device is attached. VIR_DOMAIN_DEVICE_MODIFY_CURRENT specifies that the device allocation is made based on current domain state. VIR_DOMAIN_DEVICE_MODIFY_LIVE specifies that the device shall be allocated to the active domain instance only and is not added to the persisted domain configuration. VIR_DOMAIN_DEVICE_MODIFY_CONFIG specifies that the device shall be allocated to the persisted domain configuration only. Note that the target hypervisor must return an error if unable to satisfy flags. E.g. the hypervisor driver will return failure if LIVE is specified but it only supports modifying the persisted device allocation. + /// + /// pointer to domain object + /// pointer to XML description of one device + /// an OR'ed set of virDomainDeviceModifyFlags + /// 0 in case of success, -1 in case of failure. + [DllImport("libvirt-0.dll")] + public static extern int virDomainAttachDeviceFlags(IntPtr domain, string xml, uint flags); + + // TODO virDomainBlockPeek + + /// + /// This function returns block device (disk) stats for block devices attached to the domain. The path parameter is the name of the block device. Get this by calling virDomainGetXMLDesc and finding the target dev='...' attribute within //domain/devices/disk. (For example, "xvda"). Domains may have more than one block device. To get stats for each you should make multiple calls to this function. Individual fields within the stats structure may be returned as -1, which indicates that the hypervisor does not support that particular statistic. + /// + /// pointer to the domain object + /// path to the block device + /// block device stats (returned) + /// size of stats structure + /// 0 in case of success or -1 in case of failure. + [DllImport("libvirt-0.dll")] + public static extern int virDomainBlockStats(IntPtr dom, string path, virDomainBlockStatsStruct stats, int size); + /// + /// This method will dump the core of a domain on a given file for analysis. Note that for remote Xen Daemon the file path will be interpreted in the remote host. + /// + /// a domain object + /// path for the core file + /// extra flags, currently unused + /// 0 in case of success and -1 in case of failure. + [DllImport("libvirt-0.dll")] + public static extern int virDomainCoreDump(IntPtr domain, string to, int flags); + /// + /// Launch a defined domain. If the call succeed the domain moves from the defined to the running domains pools. + /// + /// + /// A pointer to a defined domain. + /// + /// + /// 0 in case of success, -1 in case of error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainCreate(IntPtr domain); + /// + /// Launch a new guest domain, based on an XML description similar to the one returned by virDomainGetXMLDesc(). + /// This function may requires privileged access to the hypervisor. The domain is not persistent, + /// so its definition will disappear when it is destroyed, or if the host is restarted (see virDomainDefineXML() to define persistent domains). + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// A string containing an XML description of the domain. + /// + /// + /// Callers should always pass 0. + /// + /// + /// A new domain object or NULL in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virDomainCreateXML(IntPtr conn, string xmlDesc, uint flags); + /// + /// Define a domain, but does not start it. This definition is persistent, until explicitly undefined with virDomainUndefine(). + /// A previous definition for this domain would be overriden if it already exists. + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// The XML description for the domain, preferably in UTF-8. + /// + /// + /// NULL in case of error, a pointer to the domain otherwise. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virDomainDefineXML(IntPtr conn, string xml); + /// + /// Destroy the domain object. The running instance is shutdown if not down already + /// and all resources used by it are given back to the hypervisor. + /// This does not free the associated virDomainPtr object. This function may require privileged access + /// + /// + /// A domain object. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainDestroy(IntPtr domain); + /// + /// Destroy a virtual device attachment to backend. + /// + /// + /// A pointer to domain object. + /// + /// + /// Pointer to XML description of one device. + /// + /// + /// 0 in case of success, -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainDetachDevice(IntPtr domain, string xml); + /// + /// Detach a virtual device from a domain, using the flags parameter to control how the device is detached. VIR_DOMAIN_DEVICE_MODIFY_CURRENT specifies that the device allocation is removed based on current domain state. VIR_DOMAIN_DEVICE_MODIFY_LIVE specifies that the device shall be deallocated from the active domain instance only and is not from the persisted domain configuration. VIR_DOMAIN_DEVICE_MODIFY_CONFIG specifies that the device shall be deallocated from the persisted domain configuration only. Note that the target hypervisor must return an error if unable to satisfy flags. E.g. the hypervisor driver will return failure if LIVE is specified but it only supports removing the persisted device allocation. + /// + /// pointer to domain object + /// pointer to XML description of one device + /// an OR'ed set of virDomainDeviceModifyFlags + /// 0 in case of success, -1 in case of failure. + [DllImport("libvirt-0.dll")] + public static extern int virDomainDetachDeviceFlags(IntPtr domain, string xml, uint flags); + /// + /// Free the domain object. The running instance is kept alive. The data structure is freed and should not be used thereafter. + /// + /// + /// A domain object. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainFree(IntPtr domain); + /// + /// Provides a boolean value indicating whether the domain configured to be automatically started when the host machine boots. + /// + /// + /// A domain object. + /// + /// + /// The value returned. + /// + /// + /// -1 in case of error, 0 in case of success. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainGetAutostart(IntPtr domain, out int autostart); + /// + /// Provides the connection pointer associated with a domain. + /// The reference counter on the connection is not increased by this call. + /// WARNING: When writing libvirt bindings in other languages, do not use this function. + /// Instead, store the connection and the domain object together. + /// + /// + /// A pointer to a domain. + /// + /// + /// The or NULL in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virDomainGetConnect(IntPtr dom); + /// + /// Get the hypervisor ID number for the domain. + /// + /// + /// A domain object. + /// + /// + /// The domain ID number or (unsigned int) -1 in case of error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainGetID(IntPtr domain); + /// + /// Extract information about a domain. Note that if the connection used to get the domain is limited only a + /// partial set of the information can be extracted. + /// + /// + /// A domain object. + /// + /// + /// Pointer to a virDomainInfo structure allocated by the user. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainGetInfo(IntPtr domain, [Out] virDomainInfo info); + /// + /// Retrieve the maximum amount of physical memory allocated to a domain. + /// If domain is NULL, then this get the amount of memory reserved to Domain0 i.e. the domain where the application runs. + /// + /// + /// A domain object or NULL. + /// + /// + /// the memory size in kilobytes or 0 in case of error. + /// + [DllImport("libvirt-0.dll")] + public static extern ulong virDomainGetMaxMemory(IntPtr domain); + /// + /// Provides the maximum number of virtual CPUs supported for the guest VM. + /// If the guest is inactive, this is basically the same as virConnectGetMaxVcpus. + /// If the guest is running this will reflect the maximum number of virtual CPUs the guest was booted with. + /// + /// + /// A pointer to domain object. + /// + /// + /// The maximum of virtual CPU or -1 in case of error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainGetMaxVcpus(IntPtr domain); + /// + /// Get the public name for that domain. + /// + /// + /// A domain object. + /// + /// + /// Pointer to the name or NULL, the string need not be deallocated its lifetime will be the same as the domain object. + /// + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virDomainGetName(IntPtr domain); + /// + /// Get the type of domain operation system. + /// + /// + /// A domain object. + /// + /// + /// The new string or NULL in case of error, the string must be freed by the caller. + /// + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virDomainGetOSType(IntPtr domain); + + // TODO virDomainGetSchedulerParameters + + // TODO virDomainGetSchedulerType + + // TODO virDomainGetSecurityLabel + + /// + /// Get the UUID for a domain. + /// + /// + /// A a domain object. + /// + /// + /// A pointer to a VIR_UUID_BUFLEN bytes array. + /// + /// + /// A -1 in case of error, 0 in case of success. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainGetUUID(IntPtr domain, [Out] char[] uuid); + /// + /// Get the UUID for a domain as string. For more information about UUID see RFC4122. + /// + /// + /// A domain object. + /// + /// + /// Pointer to a VIR_UUID_STRING_BUFLEN bytes array. + /// + /// + /// -1 in case of error, 0 in case of success. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainGetUUIDString(IntPtr domain, [Out] IntPtr buf); + + // TODO virDomainGetVcpus + + /// + /// Provide an XML description of the domain. The description may be reused later to relaunch the domain with virDomainCreateXML(). + /// + /// + /// A a domain object. + /// + /// + /// An OR'ed set of virDomainXMLFlags. + /// + /// + /// A 0 terminated UTF-8 encoded XML instance, or NULL in case of error. the caller must free() the returned value. + /// + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virDomainGetXMLDesc(IntPtr domain, int flags); + /// + /// This function returns network interface stats for interfaces attached to the domain. + /// The path parameter is the name of the network interface. Domains may have more than one network interface. + /// To get stats for each you should make multiple calls to this function. + /// Individual fields within the stats structure may be returned as -1, + /// which indicates that the hypervisor does not support that particular statistic. + /// + /// + /// A pointer to the domain object. + /// + /// + /// Path to the interface. + /// + /// + /// A network interface stats (returned). + /// + /// + /// Size of stats structure. + /// + /// + /// 0 in case of success or -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainInterfaceStats(IntPtr dom, string path, virDomainInterfaceStatsStruct stats, int size); + /// + /// Determine if the domain is currently running. + /// + /// + /// A pointer to the domain object. + /// + /// + /// 1 if running, 0 if inactive, -1 on error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainIsActive(IntPtr dom); + + /// + /// Determine if the domain has a persistent configuration which means it will still exist after shutting down. + /// + /// + /// A pointer to the domain object. + /// + /// + /// 1 if persistent, 0 if transient, -1 on error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainIsPersistent(IntPtr dom); + + /// + /// Try to find a domain based on the hypervisor ID number. + /// Note that this won't work for inactive domains which have an ID of -1, + /// in that case a lookup based on the Name or UUId need to be done instead. + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// The domain ID number. + /// + /// + /// A new domain object or NULL in case of failure. If the domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virDomainLookupByID(IntPtr conn, int id); + + /// + /// Try to lookup a domain on the given hypervisor based on its name. + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// A name for the domain. + /// + /// + /// A new domain object or NULL in case of failure. If the domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virDomainLookupByName(IntPtr conn, string name); + + /// + /// Try to lookup a domain on the given hypervisor based on its UUID. + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// A the raw UUID for the domain. + /// + /// + /// A new domain object or NULL in case of failure. If the domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virDomainLookupByUUID(IntPtr conn, char[] uuid); + + /// + /// Try to lookup a domain on the given hypervisor based on its UUID. + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// The string UUID for the domain. + /// + /// + /// A new domain object or NULL in case of failure. If the domain cannot be found, then VIR_ERR_NO_DOMAIN error is raised. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virDomainLookupByUUIDString(IntPtr conn, string uuidstr); + + // TODO virDomainMemoryPeek + + // TODO virDomainMigrate + + // TODO virDomainMigrateToURI + + // TODO virDomainPinVcpu + + // TODO virDomainMemoryStats + + /// + /// Reboot a domain, the domain object is still usable there after but the domain OS is being stopped for a restart. + /// Note that the guest OS may ignore the request. + /// + /// + /// A domain object. + /// + /// + /// Extra flags for the reboot operation, not used yet. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainReboot(IntPtr domain, uint flags); + + /// + /// Increment the reference count on the domain. For each additional call to this method, + /// there shall be a corresponding call to virDomainFree to release the reference count, + /// once the caller no longer needs the reference to this object. + /// This method is typically useful for applications where multiple threads are using a connection, + /// and it is required that the connection remain open until all threads have finished using it. ie, + /// each new thread using a domain would increment the reference count. + /// + /// + /// A the domain to hold a reference on. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainRef(IntPtr domain); + + /// + /// This method will restore a domain saved to disk by virDomainSave(). + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// Path to the file with saved domain. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainRestore(IntPtr conn, string from); + + /// + /// Resume a suspended domain, the process is restarted from the state where it was frozen by calling virSuspendDomain(). + /// This function may requires privileged access + /// + /// + /// A domain object. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainResume(IntPtr domain); + + /// + /// This method will suspend a domain and save its memory contents to a file on disk. After the call, if successful, + /// the domain is not listed as running anymore (this may be a problem). Use virDomainRestore() to restore a domain after saving. + /// + /// + /// A domain object. + /// + /// + /// Path for the output file. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainSave(IntPtr domain, string to); + + /// + /// Configure the domain to be automatically started when the host machine boots. + /// + /// + /// A domain object. + /// + /// + /// Whether the domain should be automatically started 0 or 1. + /// + /// + /// -1 in case of error, 0 in case of success. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainSetAutostart(IntPtr domain, int autostart); + + /// + /// Dynamically change the maximum amount of physical memory allocated to a domain. + /// If domain is NULL, then this change the amount of memory reserved to Domain0 i.e. + /// the domain where the application runs. This function requires privileged access to the hypervisor. + /// + /// + /// A domain object or NULL. + /// + /// + /// The memory size in kilobytes. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainSetMaxMemory(IntPtr domain, ulong memory); + + /// + /// Dynamically change the target amount of physical memory allocated to a domain. + /// If domain is NULL, then this change the amount of memory reserved to Domain0 i.e. + /// the domain where the application runs. This function may requires privileged access to the hypervisor. + /// + /// + /// A domain object or NULL. + /// + /// + /// The memory size in kilobytes. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainSetMemory(IntPtr domain, ulong memory); + + // TODO virDomainSetSchedulerParameters + + /// + /// Dynamically change the number of virtual CPUs used by the domain. + /// Note that this call may fail if the underlying virtualization hypervisor does not support it + /// or if growing the number is arbitrary limited. This function requires privileged access to the hypervisor. + /// + /// + /// Pointer to domain object, or NULL for Domain0 + /// + /// + /// The new number of virtual CPUs for this domain. + /// + /// + /// 0 in case of success, -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainSetVcpus(IntPtr domain, uint nvcpus); + + /// + /// Shutdown a domain, the domain object is still usable there after but the domain OS is being stopped. + /// Note that the guest OS may ignore the request. + /// + /// + /// A domain object. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainShutdown(IntPtr domain); + + /// + /// Suspends an active domain, the process is frozen without further access to CPU resources and I/O + /// but the memory used by the domain at the hypervisor level will stay allocated. + /// Use virDomainResume() to reactivate the domain. This function may requires privileged access. + /// + /// + /// A domain object. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainSuspend(IntPtr domain); + + /// + /// Undefine a domain but does not stop it if it is running. + /// + /// + /// A pointer to a defined domain. + /// + /// + /// 0 in case of success, -1 in case of error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virDomainUndefine(IntPtr domain); + #endregion + + #region Events + + /// + /// Function to install callbacks + /// + ///the virEventAddHandleFunc which will be called (a delegate) + ///the virEventUpdateHandleFunc which will be called (a delegate) + ///the virEventRemoveHandleFunc which will be called (a delegate) + ///the virEventAddTimeoutFunc which will be called (a delegate) + ///the virEventUpdateTimeoutFunc which will be called (a delegate) + ///the virEventRemoveTimeoutFunc which will be called (a delegate) + [DllImport("libvirt-0.dll")] + public static extern void virEventRegisterImpl([MarshalAs(UnmanagedType.FunctionPtr)]virEventAddHandleFunc addHandle, + [MarshalAs(UnmanagedType.FunctionPtr)]virEventUpdateHandleFunc updateHandle, + [MarshalAs(UnmanagedType.FunctionPtr)]virEventRemoveHandleFunc removeHandle, + [MarshalAs(UnmanagedType.FunctionPtr)]virEventAddTimeoutFunc addTimeout, + [MarshalAs(UnmanagedType.FunctionPtr)]virEventUpdateTimeoutFunc updateTimeout, + [MarshalAs(UnmanagedType.FunctionPtr)]virEventRemoveTimeoutFunc removeTimeout); + #endregion + + #region Library + /// + /// Provides two information back, @libVer is the version of the library while @typeVer will be the version of the hypervisor + /// type @type against which the library was compiled. If @type is NULL, "Xen" is assumed, + /// if @type is unknown or not available, an error code will be returned and @typeVer will be 0. + /// + /// + /// A return value for the library version (OUT). + /// + /// + /// A the type of connection/driver looked at. + /// + /// + /// A return value for the version of the hypervisor (OUT). + /// + /// + /// -1 in case of failure, 0 otherwise, and values for @libVer and @typeVer have the format major * 1,000,000 + minor * 1,000 + release. + /// + [DllImport("libvirt-0.dll")] + public static extern int virGetVersion([Out] out ulong libVer, [In] string type, [Out] out ulong typeVer); + /// + /// Initialize the library. It's better to call this routine at startup in multithreaded applications to avoid + /// potential race when initializing the library. + /// + /// + /// 0 in case of success, -1 in case of error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virInitialize(); + #endregion + + #region Interface + + // TODO virInterfaceCreate + + // TODO virInterfaceDefineXML + + // TODO virInterfaceDestroy + + // TODO virInterfaceFree + + // TODO virInterfaceGetConnect + + // TODO virInterfaceGetMACString + + // TODO virInterfaceGetName + + // TODO virInterfaceGetXMLDesc + + // TODO virInterfaceIsActive + + // TODO virInterfaceLookupByMACString + + // TODO virInterfaceLookupByName + + // TODO virInterfaceRef + + // TODO virInterfaceUndefine + + /// + /// Increment the reference count on the network. For each additional call to this method, + /// there shall be a corresponding call to virNetworkFree to release the reference count, + /// once the caller no longer needs the reference to this object. + /// This method is typically useful for applications where multiple threads are using a connection, + /// and it is required that the connection remain open until all threads have finished using it. ie, + /// each new thread using a network would increment the reference count. + /// + /// + /// A the network to hold a reference on. + /// + /// + /// 0 in case of success, -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virNetworkRef(IntPtr network); + + // TODO virNetworkSetAutostart + + // TODO virNetworkUndefine + #endregion + + #region Node + + // TODO virNodeDeviceCreateXML + + // TODO virNodeDeviceDestroy + + // TODO virNodeDeviceDettach + + // TODO virNodeDeviceFree + + // TODO virNodeDeviceGetName + + // TODO virNodeDeviceGetParent + + /// + /// Fetch an XML document describing all aspects of the device. + /// + /// pointer to the node device + /// flags for XML generation (unused, pass 0) + /// the XML document, or NULL on error + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virNodeDeviceGetXMLDesc(IntPtr dev, uint flags); + + // TODO virNodeDeviceListCaps + + /// + /// Lookup a node device by its name. + /// + /// pointer to the hypervisor connection + /// unique device name + /// a virNodeDevicePtr if found, NULL otherwise. + [DllImport("libvirt-0.dll")] + public static extern IntPtr virNodeDeviceLookupByName(IntPtr conn, string name); + // TODO virNodeDeviceNumOfCaps + + // TODO virNodeDeviceReAttach + + // TODO virNodeDeviceRef + + // TODO virNodeDeviceReset + + // TODO virNodeGetCellsFreeMemory + + /// + /// Provides the free memory available on the Node Note: most libvirt APIs provide memory sizes in kilobytes, + /// but in this function the returned value is in bytes. Divide by 1024 as necessary. + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// The available free memory in bytes or 0 in case of error. + /// + [DllImport("libvirt-0.dll")] + public static extern ulong virNodeGetFreeMemory(IntPtr conn); + /// + /// Extract hardware information about the node. + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// Pointer to a virNodeInfo structure allocated by the user. + /// + /// + /// 0 in case of success and -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virNodeGetInfo(IntPtr h, [Out] virNodeInfo info); + + // TODO virNodeGetSecurityModel + + /// + /// Collect the list of node devices, and store their names in @names. + /// If the optional 'cap' argument is non-NULL, then the count will be restricted to devices with the specified capability. + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// Capability name. + /// + /// + /// Array to collect the list of node device names. + /// + /// + /// Size of @names. + /// + /// + /// Flags (unused, pass 0). + /// + /// + /// The number of node devices found or -1 in case of error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virNodeListDevices(IntPtr conn, string cap, IntPtr names, int maxnames, uint flags); + /// + /// Collect the list of node devices, and store their names in @names. + /// If the optional 'cap' argument is non-NULL, then the count will be restricted to devices with the specified capability. + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// Capability name. + /// + /// + /// Array to collect the list of node device names. + /// + /// + /// Size of @names. + /// + /// + /// Flags (unused, pass 0). + /// + /// + /// The number of node devices found or -1 in case of error. + /// + public static int virNodeListDevices(IntPtr conn, string cap, ref string[] names, int maxnames, uint flags) + { + IntPtr namesPtr = Marshal.AllocHGlobal(MaxStringLength); + int count = virNodeListDevices(conn, cap, namesPtr, maxnames, 0); + if (count > 0) + names = ptrToStringArray(namesPtr, count); + Marshal.FreeHGlobal(namesPtr); + return count; + } + /// + /// Provides the number of node devices. If the optional 'cap' argument is non-NULL, + /// then the count will be restricted to devices with the specified capability. + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// A capability name. + /// + /// + /// A flags (unused, pass 0). + /// + /// + /// The number of node devices or -1 in case of error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virNodeNumOfDevices(IntPtr conn, string cap, uint flags); + #endregion + + #region Secret + + // TODO virSecretDefineXML + + // TODO virSecretFree + + // TODO virSecretGetConnect + + // TODO virSecretGetUUID + + // TODO virSecretGetUUIDString + + // TODO virSecretGetUsageID + + // TODO virSecretGetUsageType + + // TODO virSecretGetValue + + // TODO virSecretGetXMLDesc + + // TODO virSecretLookupByUUID + + // TODO virSecretLookupByUUIDString + + // TODO virSecretLookupByUsage + + // TODO virSecretRef + + // TODO virSecretSetValue + + // TODO virSecretUndefine + #endregion + + #region Storage pool + + /// + /// Build the underlying storage pool. + /// + /// + /// A pointer to storage pool. + /// + /// + /// Future flags, use 0 for now. + /// + /// + /// 0 on success, or -1 upon failure + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolBuild(IntPtr pool, virStoragePoolBuildFlags flags); + + /// + /// Starts an inactive storage pool. + /// + /// + /// A pointer to storage pool. + /// + /// + /// Future flags, use 0 for now. + /// + /// + /// 0 on success, or -1 if it could not be started. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolCreate(IntPtr pool, uint flags); + + /// + /// Create a new storage based on its XML description. The pool is not persistent, + /// so its definition will disappear when it is destroyed, or if the host is restarted + /// + /// + /// A pointer to hypervisor connection. + /// + /// + /// A XML description for new pool. + /// + /// + /// A future flags, use 0 for now. + /// + /// + /// A virStoragePoolPtr object, or NULL if creation failed. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStoragePoolCreateXML(IntPtr conn, string xmlDesc, uint flags); + + /// + /// Define a new inactive storage pool based on its XML description. The pool is persistent, + /// until explicitly undefined. + /// + /// + /// A pointer to hypervisor connection. + /// + /// + /// A XML description for new pool. + /// + /// + /// A future flags, use 0 for now. + /// + /// + /// A virStoragePoolPtr object, or NULL if creation failed. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStoragePoolDefineXML(IntPtr conn, string xml, uint flags); + + /// + /// Delete the underlying pool resources. This is a non-recoverable operation. The virStoragePoolPtr object itself is not free'd. + /// + /// + /// A pointer to storage pool. + /// + /// + /// A flags for obliteration process. + /// + /// + /// 0 on success, or -1 if it could not be obliterate. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolDelete(IntPtr pool, virStoragePoolDeleteFlags flags); + + /// + /// Destroy an active storage pool. This will deactivate the pool on the host, + /// but keep any persistent config associated with it. + /// If it has a persistent config it can later be restarted with virStoragePoolCreate(). + /// This does not free the associated virStoragePoolPtr object. + /// + /// + /// A pointer to storage pool. + /// + /// + /// 0 on success, or -1 if it could not be destroyed. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolDestroy(IntPtr pool); + + /// + /// Free a storage pool object, releasing all memory associated with it. Does not change the state of the pool on the host. + /// + /// + /// A pointer to storage pool. + /// + /// + /// 0 on success, or -1 if it could not be free'd. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolFree(IntPtr pool); + + /// + /// Fetches the value of the autostart flag, which determines whether the pool is automatically started at boot time. + /// + /// + /// A pointer to storage pool. + /// + /// + /// + /// 0 on success, -1 on failure + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolGetAutostart(IntPtr pool, out int autotart); + + /// + /// Provides the connection pointer associated with a storage pool. The reference counter on the connection is not increased by this call. + /// WARNING: When writing libvirt bindings in other languages, do not use this function. Instead, store the connection and the pool object together. + /// + /// + /// A pointer to a pool. + /// + /// + /// A the virConnectPtr or NULL in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStoragePoolGetConnect(IntPtr pool); + + /// + /// Get volatile information about the storage pool such as free space / usage summary. + /// + /// + /// A pointer to storage pool. + /// + /// + /// Pointer at which to store info. + /// + /// + /// 0 on success, or -1 on failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolGetInfo(IntPtr pool, ref virStoragePoolInfo info); + + /// + /// Fetch the locally unique name of the storage pool. + /// + /// + /// A pointer to storage pool. + /// + /// + /// The name of the pool, or NULL on error. + /// + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virStoragePoolGetName(IntPtr pool); + + /// + /// Fetch the globally unique ID of the storage pool. + /// + /// + /// A Pointer to storage pool. + /// + /// + /// Buffer of VIR_UUID_BUFLEN bytes in size. + /// + /// + /// 0 on success, or -1 on error + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolGetUUID(IntPtr pool, [Out] char[] uuid); + + /// + /// Fetch the globally unique ID of the storage pool as a string. + /// + /// + /// A pointer to storage pool. + /// + /// + /// A buffer of VIR_UUID_STRING_BUFLEN bytes in size. + /// + /// + /// 0 on success, or -1 on error. + /// + [DllImport("libvirt-0.dll")] + private static extern int virStoragePoolGetUUIDString(IntPtr pool, [Out] char[] uuid); + + /// + /// Fetch the globally unique ID of the storage pool as a string. + /// + /// + /// A pointer to storage pool. + /// + ///the storage pool UUID + public static string virStoragePoolGetUUIDString(IntPtr pool) + { + char[] uuidArray = new char[36]; + virStoragePoolGetUUIDString(pool, uuidArray); + return new string(uuidArray); + } + /// + /// Fetch an XML document describing all aspects of the storage pool. + /// This is suitable for later feeding back into the virStoragePoolCreateXML method. + /// + /// + /// A pointer to storage pool. + /// + /// + /// Flags for XML format options (set of virDomainXMLFlags). + /// + /// + /// A XML document, or NULL on error. + /// + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virStoragePoolGetXMLDesc(IntPtr pool, virDomainXMLFlags flags); + + /// + /// Determine if the storage pool is currently running. + /// + /// + /// A pointer to the storage pool object. + /// + /// + /// 1 if running, 0 if inactive, -1 on error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolIsActive(IntPtr pool); + + /// + /// Determine if the storage pool has a persistent configuration which means it will still exist after shutting down. + /// + /// + /// A pointer to the storage pool object. + /// + /// + /// 1 if persistent, 0 if transient, -1 on error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolIsPersistent(IntPtr pool); + + /// + /// Fetch list of storage volume names, limiting to at most maxnames. + /// + /// + /// A pointer to storage pool. + /// + /// + /// A array in which to storage volume names. + /// + /// + /// A size of names array. + /// + /// + /// The number of names fetched, or -1 on error. + /// + [DllImport("libvirt-0.dll")] + private static extern int virStoragePoolListVolumes(IntPtr pool, IntPtr names, int maxnames); + /// + /// Fetch list of storage volume names, limiting to at most maxnames. + /// + /// + /// A pointer to storage pool. + /// + /// + /// A array in which to storage volume names. + /// + /// + /// A size of names array. + /// + /// + /// The number of names fetched, or -1 on error. + /// + public static int virStoragePoolListVolumes(IntPtr pool, ref string[] names, int maxnames) + { + IntPtr namesPtr = Marshal.AllocHGlobal(MaxStringLength); + int count = virStoragePoolListVolumes(pool, namesPtr, maxnames); + if (count > 0) + names = ptrToStringArray(namesPtr, count); + Marshal.FreeHGlobal(namesPtr); + return count; + } + /// + /// Fetch a storage pool based on its unique name. + /// + /// + /// A pointer to hypervisor connection. + /// + /// + /// Name of pool to fetch. + /// + /// + /// A virStoragePoolPtr object, or NULL if no matching pool is found. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStoragePoolLookupByName(IntPtr conn, string name); + + /// + /// Fetch a storage pool based on its globally unique id. + /// + /// + /// A pointer to hypervisor connection. + /// + /// + /// Globally unique id of pool to fetch. + /// + /// + /// A virStoragePoolPtr object, or NULL if no matching pool is found + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStoragePoolLookupByUUID(IntPtr conn, char[] uuid); + + /// + /// Fetch a storage pool based on its globally unique id. + /// + /// + /// A pointer to hypervisor connection. + /// + /// + /// A globally unique id of pool to fetch. + /// + /// + /// A object, or NULL if no matching pool is found. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStoragePoolLookupByUUIDString(IntPtr conn, string uuidstr); + + /// + /// Fetch a storage pool which contains a particular volume. + /// + /// + /// A pointer to storage volume. + /// + /// + /// A object, or NULL if no matching pool is found. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStoragePoolLookupByVolume(IntPtr vol); + + /// + /// Fetch the number of storage volumes within a pool. + /// + /// + /// A pointer to storage pool. + /// + /// + /// A the number of storage pools, or -1 on failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolNumOfVolumes(IntPtr pool); + + /// + /// Increment the reference count on the pool. For each additional call to this method, + /// there shall be a corresponding call to virStoragePoolFree to release the reference count, + /// once the caller no longer needs the reference to this object. + /// This method is typically useful for applications where multiple threads are using a connection, + /// and it is required that the connection remain open until all threads have finished using it. ie, + /// each new thread using a pool would increment the reference count. + /// + /// + /// The pool to hold a reference on. + /// + /// + /// 0 in case of success, -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolRef(IntPtr pool); + + /// + /// Request that the pool refresh its list of volumes. This may involve communicating with a remote server, + /// and/or initializing new devices at the OS layer. + /// + /// + /// A pointer to storage pool. + /// + /// + /// A flags to control refresh behaviour (currently unused, use 0). + /// + /// + /// 0 if the volume list was refreshed, -1 on failure. + /// + [DllImport("virtlib-0.dll")] + public static extern int virStoragePoolRefresh(IntPtr pool, uint flags); + + /// + /// Sets the autostart flag. + /// + /// + /// A pointer to storage pool. + /// + /// + /// A new flag setting. + /// + /// + /// 0 on success, -1 on failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolSetAutostart(IntPtr pool, int autostart); + + /// + /// Undefine an inactive storage pool. + /// + /// + /// A pointer to storage pool. + /// + /// + /// 0 on success, -1 on failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStoragePoolUndefine(IntPtr pool); + #endregion + + #region Volumes + + /// + /// Create a storage volume within a pool based on an XML description. Not all pools support creation of volumes. + /// + /// + /// A pointer to storage pool. + /// + /// + /// A description of volume to create. + /// + /// + /// A flags for creation (unused, pass 0). + /// + /// + /// The storage volume, or NULL on error. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStorageVolCreateXML(IntPtr pool, string xmldesc, uint flags); + + /// + /// Create a storage volume in the parent pool, using the 'clonevol' volume as input. + /// Information for the new volume (name, perms) are passed via a typical volume XML description. + /// + /// + /// A pointer to parent pool for the new volume. + /// + /// + /// A description of volume to create. + /// + /// + /// A storage volume to use as input. + /// + /// + /// A flags for creation (unused, pass 0). + /// + /// + /// A the storage volume, or NULL on error. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStorageVolCreateXMLFrom(IntPtr pool, string xmldesc, IntPtr clonevol, uint flags); + + /// + /// Delete the storage volume from the pool. + /// + /// + /// A pointer to storage volume. + /// + /// + /// A future flags, use 0 for now. + /// + /// + /// 0 on success, or -1 on error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStorageVolDelete(IntPtr vol, uint flags); + + /// + /// Release the storage volume handle. The underlying storage volume continues to exist. + /// + /// + /// A pointer to storage volume. + /// + /// + /// 0 on success, or -1 on error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStorageVolFree(IntPtr vol); + + /// + /// Provides the connection pointer associated with a storage volume. + /// The reference counter on the connection is not increased by this call. + /// WARNING: When writing libvirt bindings in other languages, do not use this function. + /// Instead, store the connection and the volume object together. + /// + /// + /// A + /// + /// + /// A + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStorageVolGetConnect(IntPtr vol); + + /// + /// Fetches volatile information about the storage volume such as its current allocation. + /// + /// + /// A pointer to storage volume. + /// + /// + /// A pointer at which to store info. + /// + /// + /// 0 on success, or -1 on failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStorageVolGetInfo(IntPtr vol, ref virStorageVolInfo info); + + /// + /// Fetch the storage volume key. + /// This is globally unique, so the same volume will have the same key no matter what host it is accessed from + /// + /// + /// A pointer to storage volume. + /// + /// + /// The volume key, or NULL on error. + /// + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virStorageVolGetKey(IntPtr vol); + + /// + /// Fetch the storage volume name. This is unique within the scope of a pool. + /// + /// + /// A pointer to storage volume. + /// + /// + /// The volume name, or NULL on error. + /// + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virStorageVolGetName(IntPtr vol); + + /// + /// Fetch the storage volume path. + /// Depending on the pool configuration this is either persistent across hosts, + /// or dynamically assigned at pool startup. + /// Consult pool documentation for information on getting the persistent naming. + /// + /// + /// A pointer to storage volume. + /// + /// + /// The storage volume path, or NULL on error. + /// + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virStorageVolGetPath(IntPtr vol); + + /// + /// Fetch an XML document describing all aspects of the storage volume. + /// + /// + /// A pointer to storage volume. + /// + /// + /// A flags for XML generation (unused, pass 0). + /// + /// + /// The XML document, or NULL on error. + /// + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virStorageVolGetXMLDesc(IntPtr vol, uint flags); + + /// + /// Fetch a pointer to a storage volume based on its globally unique key. + /// + /// + /// A pointer to hypervisor connection. + /// + /// + /// A globally unique key. + /// + /// + /// A storage volume, or NULL if not found / error. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStorageVolLookupByKey(IntPtr conn, string key); + + /// + /// Fetch a pointer to a storage volume based on its name within a pool. + /// + /// + /// A pointer to storage pool. + /// + /// + /// A name of storage volume. + /// + /// + /// A storage volume, or NULL if not found / error. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStorageVolLookupByName(IntPtr pool, string name); + + /// + /// Fetch a pointer to a storage volume based on its locally (host) unique path. + /// + /// + /// A pointer to hypervisor connection. + /// + /// + /// A locally unique path. + /// + /// + /// A storage volume, or NULL if not found / error. + /// + [DllImport("libvirt-0.dll")] + public static extern IntPtr virStorageVolLookupByPath(IntPtr conn, string path); + + /// + /// Increment the reference count on the vol. For each additional call to this method, + /// there shall be a corresponding call to virStorageVolFree to release the reference count, + /// once the caller no longer needs the reference to this object. + /// This method is typically useful for applications where multiple threads are using a connection, + /// and it is required that the connection remain open until all threads have finished using it. ie, + /// each new thread using a vol would increment the reference count. + /// + /// + /// A the vol to hold a reference on. + /// + /// + /// A 0 in case of success, -1 in case of failure. + /// + [DllImport("libvirt-0.dll")] + public static extern int virStorageVolRef(IntPtr vol); + + #endregion + + #region Streams + + // TODO virStreamAbort + + // TODO virStreamEventAddCallback + + // TODO virStreamEventCallback + + // TODO virStreamEventRemoveCallback + + // TODO virStreamEventUpdateCallback + + // TODO virStreamFinish + + // TODO virStreamFree + + // TODO virStreamNew + + // TODO virStreamRecv + + // TODO virStreamRecvAll + + // TODO virStreamRef + + // TODO virStreamSend + + // TODO virStreamSendAll + + // TODO virStreamSinkFunc + + // TODO virStreamSourceFunc + + /// + /// A callback function to be registered, and called when a domain event occurs + /// + /// virConnect connection + /// The domain on which the event occured + /// The specfic virDomainEventType which occured + /// event specific detail information + /// opaque user data + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void virConnectDomainEventCallback(IntPtr conn, IntPtr dom, virDomainEventType evt, int detail, IntPtr opaque); + /// + /// Adds a callback to receive notifications of domain lifecycle events occurring on a connection Use of this method is no longer recommended. Instead applications should try virConnectDomainEventRegisterAny which has a more flexible API contract The virDomainPtr object handle passed into the callback upon delivery of an event is only valid for the duration of execution of the callback. If the callback wishes to keep the domain object after the callback + /// + /// pointer to the connection + /// callback to the function handling domain events + /// opaque data to pass on to the callback + /// optional function to deallocate opaque when not used anymore + /// t shall take a reference to it, by calling virDomainRef. The reference can be released once the object is no longer required by calling virDomainFree. Returns 0 on success, -1 on failure + [DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl)] + public static extern int virConnectDomainEventRegister(IntPtr conn, [MarshalAs(UnmanagedType.FunctionPtr)] virConnectDomainEventCallback cb, + IntPtr opaque, [MarshalAs(UnmanagedType.FunctionPtr)] virFreeCallback ff); + + #endregion + + #region Network + + /// + /// Create and start a defined network. If the call succeed the network moves from the defined to the running networks pools. + /// + /// pointer to a defined network + /// 0 in case of success, -1 in case of error + [DllImport("libvirt-0.dll")] + public static extern int virNetworkCreate(IntPtr network); + /// + /// Create and start a new virtual network, based on an XML description similar to the one returned by virNetworkGetXMLDesc() + /// + /// pointer to the hypervisor connection + /// an XML description of the network + /// a new network object or NULL in case of failure + [DllImport("libvirt-0.dll")] + public static extern IntPtr virNetworkCreateXML(IntPtr conn, string xmlDesc); + /// + /// Define a network, but does not create it + /// + /// pointer to the hypervisor connection + /// the XML description for the network, preferably in UTF-8 + /// NULL in case of error, a pointer to the network otherwise + [DllImport("libvirt-0.dll")] + public static extern IntPtr virNetworkDefineXML(IntPtr conn, string xmlDesc); + /// + /// Destroy the network object. The running instance is shutdown if not down already and all resources used by it are given back to the hypervisor. This does not free the associated virNetworkPtr object. This function may require privileged access + /// + /// a network object + /// 0 in case of success and -1 in case of failure. + [DllImport("libvirt-0.dll")] + public static extern int virNetworkDestroy(IntPtr network); + /// + /// Free the network object. The running instance is kept alive. The data structure is freed and should not be used thereafter. + /// + /// a network object + /// 0 in case of success and -1 in case of failure + [DllImport("libvirt-0.dll")] + public static extern int virNetworkFree(IntPtr network); + /// + /// Provides a boolean value indicating whether the network configured to be automatically started when the host machine boots. + /// + /// a network object + /// the value returned + /// -1 in case of error, 0 in case of success + [DllImport("libvirt-0.dll")] + public static extern int virNetworkGetAutostart(IntPtr network, int autostart); + /// + /// Provides a bridge interface name to which a domain may connect a network interface in order to join the network. + /// + /// a network object + /// a 0 terminated interface name, or NULL in case of error. the caller must free() the returned value + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virNetworkGetBridgeName(IntPtr network); + /// + /// Provides the connection pointer associated with a network. The reference counter on the connection is not increased by this call. WARNING: When writing libvirt bindings in other languages, do not use this function. Instead, store the connection and the network object together + /// + /// pointer to a network + /// the virConnectPtr or NULL in case of failure + [DllImport("libvirt-0.dll")] + public static extern IntPtr virNetworkGetConnect(IntPtr network); + /// + /// Get the public name for that network + /// + /// a network object + /// a pointer to the name or NULL, the string need not be deallocated its lifetime will be the same as the network object + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virNetworkGetName(IntPtr network); + /// + /// Get the UUID for a network as string + /// + /// a network object + /// string of the uuid + /// -1 in case of error, 0 in case of success + [DllImport("libvirt-0.dll")] + private static extern int virNetworkGetUUIDString(IntPtr network, [Out] char[] uuid); + + /// + /// Get the UUID for a network as string + /// + ///a network object, a netowrk IntPtr + ///string of the uuid + public static string virNetworkGetUUIDString(IntPtr network) + { + char[] uuidArray = new char[36]; + virNetworkGetUUIDString(network, uuidArray); + return new string(uuidArray); + } + /// + /// Provide an XML description of the network. The description may be reused later to relaunch the network with virNetworkCreateXML(). + /// + /// a network object + /// an OR'ed set of extraction flags, not used yet + /// a 0 terminated UTF-8 encoded XML instance, or NULL in case of error. the caller must free() the returned value + [DllImport("libvirt-0.dll")] + [return: MarshalAs(UnmanagedType.AnsiBStr)] + public static extern string virNetworkGetXMLDesc(IntPtr network, int flags); + /// + /// Determine if the network is currently running + /// + /// pointer to the network object + /// 1 if running, 0 if inactive, -1 on error + [DllImport("libvirt-0.dll")] + public static extern int virNetworkIsActive(IntPtr network); + /// + /// Determine if the network has a persistent configuration which means it will still exist after shutting down + /// + /// pointer to the network object + /// x1 if persistent, 0 if transient, -1 on error + [DllImport("libvirt-0.dll")] + public static extern int virNetworkIsPersistent(IntPtr network); + /// + /// Try to lookup a network on the given hypervisor based on its name. + /// + /// pointer to the hypervisor connection + /// name for the network + /// a new network object or NULL in case of failure. If the network cannot be found, then VIR_ERR_NO_NETWORK error is raised + [DllImport("libvirt-0.dll")] + public static extern IntPtr virNetworkLookupByName(IntPtr conn, string name); + /// + /// Try to lookup a network on the given hypervisor based on its UUID + /// + /// pointer to the hypervisor connection + /// the string UUID for the network + /// a new network object or NULL in case of failure. If the network cannot be found, then VIR_ERR_NO_NETWORK error is raised + [DllImport("libvirt-0.dll")] + public static extern IntPtr virNetworkLookupByUUIDString(IntPtr conn, string uuidstr); + /// + /// Configure the network to be automatically started when the host machine boots + /// + /// a network object + /// whether the network should be automatically started 0 or 1 + /// -1 in case of error, 0 in case of success + [DllImport("libvirt-0.dll")] + public static extern int virNetworkSetAutostart(IntPtr network, int autostart); + /// + /// Undefine a network but does not stop it if it is running + /// + /// pointer to a defined network + /// 0 in case of success, -1 in case of error + [DllImport("libvirt-0.dll")] + public static extern int virNetworkUndefine(IntPtr network); + + #endregion + + #region Helpers + + private static string[] ptrToStringArray(IntPtr stringPtr, int stringCount) + { + string[] members = new string[stringCount]; + for (int i = 0; i < stringCount; ++i) + { + IntPtr s = Marshal.ReadIntPtr(stringPtr, i * IntPtr.Size); + members[i] = Marshal.PtrToStringAnsi(s); + } + return members; + } + +// ReSharper disable UnusedMember.Local + private static string ptrToString(IntPtr stringPtr) +// ReSharper restore UnusedMember.Local + { + IntPtr s = Marshal.ReadIntPtr(stringPtr, IntPtr.Size); + return Marshal.PtrToStringAnsi(s); + } + + #endregion + } +} diff --git a/LibvirtBindings.csproj b/LibvirtBindings.csproj new file mode 100644 index 0000000..7ddaa82 --- /dev/null +++ b/LibvirtBindings.csproj @@ -0,0 +1,63 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {61AF36A9-0D6C-4E02-9B9B-39908463A82E} + Library + Properties + LibvirtBindings + LibvirtBindings + v3.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + bin\Debug\LibvirtBindings.XML + AnyCPU + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LibvirtBindings.sln b/LibvirtBindings.sln new file mode 100644 index 0000000..cfa349c --- /dev/null +++ b/LibvirtBindings.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibvirtBindings", "LibvirtBindings.csproj", "{61AF36A9-0D6C-4E02-9B9B-39908463A82E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {61AF36A9-0D6C-4E02-9B9B-39908463A82E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {61AF36A9-0D6C-4E02-9B9B-39908463A82E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {61AF36A9-0D6C-4E02-9B9B-39908463A82E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {61AF36A9-0D6C-4E02-9B9B-39908463A82E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/LibvirtError.cs b/LibvirtError.cs new file mode 100644 index 0000000..eaab401 --- /dev/null +++ b/LibvirtError.cs @@ -0,0 +1,683 @@ +/* + * Copyright (C) + * Arnaud Champion + * Jaromír Červenka + * + * See COPYING.LIB for the License of this software + */ + + +using System; +using System.Runtime.InteropServices; + +namespace LibvirtBindings +{ + /// + /// class for libvirt errors binding + /// + public class libvirtError + { + /// + /// Signature of a function to use when there is an error raised by the library. + /// + ///user provided data for the error callback + ///the error being raised. + public delegate void virErrorFunc(IntPtr userData, virError error); + + /// + /// Enumerate errors + /// + public enum virErrorNumber + { + /// + /// No error + /// + VIR_ERR_OK = 0, + /// + /// Internal error + /// + VIR_ERR_INTERNAL_ERROR = 1, + /// + /// Memory allocation failure + /// + VIR_ERR_NO_MEMORY = 2, + /// + /// No support for this function + /// + VIR_ERR_NO_SUPPORT = 3, + /// + /// Could not resolve hostname + /// + VIR_ERR_UNKNOWN_HOST = 4, + /// + /// Can't connect to hypervisor + /// + VIR_ERR_NO_CONNECT = 5, + /// + /// Invalid connection object + /// + VIR_ERR_INVALID_CONN = 6, + /// + /// Invalid domain object + /// + VIR_ERR_INVALID_DOMAIN = 7, + /// + /// Invalid function argument + /// + VIR_ERR_INVALID_ARG = 8, + /// + /// A command to hypervisor failed + /// + VIR_ERR_OPERATION_FAILED = 9, + /// + /// A HTTP GET command to failed + /// + VIR_ERR_GET_FAILED = 10, + /// + /// A HTTP POST command to failed + /// + VIR_ERR_POST_FAILED = 11, + /// + /// Unexpected HTTP error code + /// + VIR_ERR_HTTP_ERROR = 12, + /// + /// Failure to serialize an S-Expr + /// + VIR_ERR_SEXPR_SERIAL = 13, + /// + /// Could not open Xen hypervisor control + /// + VIR_ERR_NO_XEN = 14, + /// + /// Failure doing an hypervisor call + /// + VIR_ERR_XEN_CALL = 15, + /// + /// Unknown OS type + /// + VIR_ERR_OS_TYPE = 16, + /// + /// Missing kernel information + /// + VIR_ERR_NO_KERNEL = 17, + /// + /// Missing root device information + /// + VIR_ERR_NO_ROOT = 18, + /// + /// Missing source device information + /// + VIR_ERR_NO_SOURCE = 19, + /// + /// Missing target device information + /// + VIR_ERR_NO_TARGET = 20, + /// + /// Missing domain name information + /// + VIR_ERR_NO_NAME = 21, + /// + /// Missing domain OS information + /// + VIR_ERR_NO_OS = 22, + /// + /// Missing domain devices information + /// + VIR_ERR_NO_DEVICE = 23, + /// + /// Could not open Xen Store control + /// + VIR_ERR_NO_XENSTORE = 24, + /// + /// Too many drivers registered + /// + VIR_ERR_DRIVER_FULL = 25, + /// + /// Not supported by the drivers (DEPRECATED) + /// + VIR_ERR_CALL_FAILED = 26, + /// + /// An XML description is not well formed or broken + /// + VIR_ERR_XML_ERROR = 27, + /// + /// The domain already exist + /// + VIR_ERR_DOM_EXIST = 28, + /// + /// Operation forbidden on read-only connections + /// + VIR_ERR_OPERATION_DENIED = 29, + /// + /// Failed to open a conf file + /// + VIR_ERR_OPEN_FAILED = 30, + /// + /// Failed to read a conf file + /// + VIR_ERR_READ_FAILED = 31, + /// + /// Failed to parse a conf file + /// + VIR_ERR_PARSE_FAILED = 32, + /// + /// Failed to parse the syntax of a conf file + /// + VIR_ERR_CONF_SYNTAX = 33, + /// + /// Failed to write a conf file + /// + VIR_ERR_WRITE_FAILED = 34, + /// + /// Detail of an XML error + /// + VIR_ERR_XML_DETAIL = 35, + /// + /// Invalid network object + /// + VIR_ERR_INVALID_NETWORK = 36, + /// + /// The network already exist + /// + VIR_ERR_NETWORK_EXIST = 37, + /// + /// General system call failure + /// + VIR_ERR_SYSTEM_ERROR = 38, + /// + /// Some sort of RPC error + /// + VIR_ERR_RPC = 39, + /// + /// Error from a GNUTLS call + /// + VIR_ERR_GNUTLS_ERROR = 40, + /// + /// Failed to start network + /// + VIR_WAR_NO_NETWORK = 41, + /// + /// Domain not found or unexpectedly disappeared + /// + VIR_ERR_NO_DOMAIN = 42, + /// + /// Network not found + /// + VIR_ERR_NO_NETWORK = 43, + /// + /// Invalid MAC address + /// + VIR_ERR_INVALID_MAC = 44, + /// + /// Authentication failed + /// + VIR_ERR_AUTH_FAILED = 45, + /// + /// Invalid storage pool object + /// + VIR_ERR_INVALID_STORAGE_POOL = 46, + /// + /// Invalid storage vol object + /// + VIR_ERR_INVALID_STORAGE_VOL = 47, + /// + /// Failed to start storage + /// + VIR_WAR_NO_STORAGE = 48, + /// + /// Storage pool not found + /// + VIR_ERR_NO_STORAGE_POOL = 49, + /// + /// Storage pool not found + /// + VIR_ERR_NO_STORAGE_VOL = 50, + /// + /// Failed to start node driver + /// + VIR_WAR_NO_NODE = 51, + /// + /// Invalid node device object + /// + VIR_ERR_INVALID_NODE_DEVICE = 52, + /// + /// Node device not found + /// + VIR_ERR_NO_NODE_DEVICE = 53, + /// + /// Security model not found + /// + VIR_ERR_NO_SECURITY_MODEL = 54, + /// + /// Operation is not applicable at this time + /// + VIR_ERR_OPERATION_INVALID = 55, + /// + /// Failed to start interface driver + /// + VIR_WAR_NO_INTERFACE = 56, + /// + /// Interface driver not running + /// + VIR_ERR_NO_INTERFACE = 57, + /// + /// Invalid interface object + /// + VIR_ERR_INVALID_INTERFACE = 58, + /// + /// More than one matching interface found + /// + VIR_ERR_MULTIPLE_INTERFACES = 59, + /// + /// Failed to start secret storage + /// + VIR_WAR_NO_SECRET = 60, + /// + /// Invalid secret + /// + VIR_ERR_INVALID_SECRET = 61, + /// + /// Secret not found + /// + VIR_ERR_NO_SECRET = 62, + /// + /// Unsupported configuration construct + /// + VIR_ERR_CONFIG_UNSUPPORTED = 63, + /// + /// Timeout occurred during operation + /// + VIR_ERR_OPERATION_TIMEOUT = 64, + /// + /// A migration worked, but making the VM persist on the dest host failed + /// + VIR_ERR_MIGRATE_PERSIST_FAILED = 65, + } + + /// + /// Enumrate types of domain errors + /// + public enum virErrorDomain + { + /// + /// None + /// + VIR_FROM_NONE = 0, + /// + /// Error at Xen hypervisor layer + /// + VIR_FROM_XEN = 1, + /// + /// Error at connection with xend daemon + /// + VIR_FROM_XEND = 2, + /// + /// Error at connection with xen store + /// + VIR_FROM_XENSTORE = 3, + /// + /// Error in the S-Expression code + /// + VIR_FROM_SEXPR = 4, + /// + /// Error in the XML code + /// + VIR_FROM_XML = 5, + /// + /// Error when operating on a domain + /// + VIR_FROM_DOM = 6, + /// + /// Error in the XML-RPC code + /// + VIR_FROM_RPC = 7, + /// + /// Error in the proxy code + /// + VIR_FROM_PROXY = 8, + /// + /// Error in the configuration file handling + /// + VIR_FROM_CONF = 9, + /// + /// Error at the QEMU daemon + /// + VIR_FROM_QEMU = 10, + /// + /// Error when operating on a network + /// + VIR_FROM_NET = 11, + /// + /// Error from test driver + /// + VIR_FROM_TEST = 12, + /// + /// Error from remote driver + /// + VIR_FROM_REMOTE = 13, + /// + /// Error from OpenVZ driver + /// + VIR_FROM_OPENVZ = 14, + /// + /// Error at Xen XM layer + /// + VIR_FROM_XENXM = 15, + /// + /// Error in the Linux Stats code + /// + VIR_FROM_STATS_LINUX = 16, + /// + /// Error from Linux Container driver + /// + VIR_FROM_LXC = 17, + /// + /// Error from storage driver + /// + VIR_FROM_STORAGE = 18, + /// + /// Error from network config + /// + VIR_FROM_NETWORK = 19, + /// + /// Error from domain config + /// + VIR_FROM_DOMAIN = 20, + /// + /// Error at the UML driver + /// + VIR_FROM_UML = 21, + /// + /// Error from node device monitor + /// + VIR_FROM_NODEDEV = 22, + /// + /// Error from xen inotify layer + /// + VIR_FROM_XEN_INOTIFY = 23, + /// + /// Error from security framework + /// + VIR_FROM_SECURITY = 24, + /// + /// Error from VirtualBox driver + /// + VIR_FROM_VBOX = 25, + /// + /// Error when operating on an interface + /// + VIR_FROM_INTERFACE = 26, + /// + /// Error from OpenNebula driver + /// + VIR_FROM_ONE = 27, + /// + /// Error from ESX driver + /// + VIR_FROM_ESX = 28, + /// + /// Error from IBM power hypervisor + /// + VIR_FROM_PHYP = 29, + /// + /// Error from secret storage + /// + VIR_FROM_SECRET = 30, + /// + /// Error from CPU driver + /// + VIR_FROM_CPU = 31, + /// + /// Error from XenAPI + /// + VIR_FROM_XENAPI = 32, + /// + /// Error from network filter driver + /// + VIR_FROM_NWFILTER = 33, + /// + /// Error from Synchronous hooks + /// + VIR_FROM_HOOK = 34, + /// + /// Error from domain snapshot + /// + VIR_FROM_DOMAIN_SNAPSHOT = 35 + } + + /// + /// Enumerate the error levels + /// + public enum virErrorLevel + { + /// + /// No error + /// + VIR_ERR_NONE = 0, + /// + /// A simple warning. + /// + VIR_ERR_WARNING = 1, + /// + /// An error. + /// + VIR_ERR_ERROR = 2, + } + + /// + /// the virError object + /// + [StructLayout(LayoutKind.Sequential)] + public class virError + { + /// + /// The error code, a virErrorNumber. + /// + [MarshalAs(UnmanagedType.I4)] + public virErrorNumber code; + /// + /// What part of the library raised this error. + /// + [MarshalAs(UnmanagedType.I4)] + public int domain; + /// + /// Human-readable informative error message. + /// + [MarshalAs(UnmanagedType.SysInt)] +#pragma warning disable 649 + private IntPtr message; +#pragma warning restore 649 + /// + /// Human-readable informative error message. + /// +// ReSharper disable InconsistentNaming + public string Message +// ReSharper restore InconsistentNaming + { + get { return Marshal.PtrToStringAnsi(message); } + } + + /// + /// How consequent is the error. + /// + [MarshalAs(UnmanagedType.I4)] + public virErrorLevel level; + /// + /// Connection if available, deprecated see note above. + /// + [MarshalAs(UnmanagedType.SysInt)] + public IntPtr conn; + /// + /// Domain if available, deprecated see note above. + /// + [MarshalAs(UnmanagedType.SysInt)] + public IntPtr dom; + /// + /// Extra string information. + /// + [MarshalAs(UnmanagedType.SysInt)] +#pragma warning disable 649 + private IntPtr str1; +#pragma warning restore 649 + /// + /// Extra string information. + /// +// ReSharper disable InconsistentNaming + public string Str1 { get { return Marshal.PtrToStringAnsi(str1); } } +// ReSharper restore InconsistentNaming + /// + /// Extra string information. + /// + [MarshalAs(UnmanagedType.SysInt)] +#pragma warning disable 649 + private IntPtr str2; +#pragma warning restore 649 + /// + /// Extra string information. + /// +// ReSharper disable InconsistentNaming + public string Str2 { get { return Marshal.PtrToStringAnsi(str2); } } +// ReSharper restore InconsistentNaming + /// + /// Extra string information. + /// + [MarshalAs(UnmanagedType.SysInt)] +#pragma warning disable 649 + private IntPtr str3; +#pragma warning restore 649 + /// + /// Extra string information. + /// +// ReSharper disable InconsistentNaming + public string Str3 { get { return Marshal.PtrToStringAnsi(str3); } } +// ReSharper restore InconsistentNaming + /// + /// Extra number information. + /// + [MarshalAs(UnmanagedType.I4)] + public int int1; + /// + /// Extra number information. + /// + [MarshalAs(UnmanagedType.I4)] + public int int2; + /// + /// Network if available, deprecated see note above. + /// + [MarshalAs(UnmanagedType.SysInt)] + public IntPtr net; + } + + + // virConnCopyLastError - Deprecated + // virConnGetLastError - Deprecated + + /// + /// The error object is kept in thread local storage, so separate threads can safely access this concurrently. + /// Reset the last error caught on that connection. + /// + /// + /// A pointer to the hypervisor connection. + /// + [DllImport("libvirt-0.dll")] + public static extern void virConnResetLastError(IntPtr conn); + + /// + /// Set a connection error handling function, if @handler is NULL it will reset to default + /// which is to pass error back to the global library handler. + /// + /// + /// A pointer to the hypervisor connection. + /// + /// + /// A pointer to the user data provided in the handler callback. + /// + /// + /// A function to get called in case of error or NULL + /// + [DllImport("libvirt-0.dll")] + public static extern void virConnSetErrorFunc(IntPtr conn, IntPtr userData, [MarshalAs(UnmanagedType.FunctionPtr)]virErrorFunc handler); + + /// + /// Copy the content of the last error caught at the library level. + /// The error object is kept in thread local storage, so separate threads can safely access this concurrently. + /// One will need to free the result with virResetError(). + /// + /// + /// A target to receive the copy. + /// + /// + /// 0 if no error was found and the error code otherwise and -1 in case of parameter error. + /// + [DllImport("libvirt-0.dll")] + public static extern int virCopyLastError([Out] virError to); + + /// + /// Default routine reporting an error to stderr. + /// + /// + /// A pointer to the error. + /// + [DllImport("libvirt-0.dll")] + public static extern void virDefaultErrorFunc([In] virError err); + + /// + /// Resets and frees the given error. + /// + /// + /// A error to free. + /// + [DllImport("libvirt-0.dll")] + public static extern void virFreeError(virError err); // Does not work, anybody know why? + + /// + /// Provide a pointer to the last error caught at the library level. + /// The error object is kept in thread local storage, so separate threads can safely access this concurrently. + /// + /// + /// A pointer to the last error or NULL if none occurred. + /// + [DllImport("libvirt-0.dll")] + public static extern int virGetLastError(); + + /// + /// Reset the error being pointed to. + /// + /// + /// A pointer to the to clean up. + /// + [DllImport("libvirt-0.dll")] + public static extern void virResetError(virError err); + + /// + /// Reset the last error caught at the library level. The error object is kept in thread local storage, + /// so separate threads can safely access this concurrently, only resetting their own error object. + /// + [DllImport("libvirt-0.dll")] + public static extern void virResetLastError(); + + /// + /// Save the last error into a new error object. + /// + /// + /// A pointer to the copied error or NULL if allocation failed. + /// It is the caller's responsibility to free the error with virFreeError(). + /// + [DllImport("libvirt-0.dll")] + public static extern virError virSaveLastError(); + + /// + /// Set a library global error handling function, if @handler is NULL, it will reset to default printing on stderr. + /// The error raised there are those for which no handler at the connection level could caught. + /// + /// + /// A pointer to the user data provided in the handler callback. + /// + /// + /// A function to get called in case of error or NULL. + /// + [DllImport("libvirt-0.dll")] + public static extern void virSetErrorFunc(IntPtr userData, [MarshalAs(UnmanagedType.FunctionPtr)]virErrorFunc handler); + } +} diff --git a/LibvirtTypes.cs b/LibvirtTypes.cs new file mode 100644 index 0000000..121c746 --- /dev/null +++ b/LibvirtTypes.cs @@ -0,0 +1,725 @@ +/* + * Copyright (C) + * Arnaud Champion + * Jaromír Červenka + * + * See COPYING.LIB for the License of this software + */ + +using System; +using System.Runtime.InteropServices; + +namespace LibvirtBindings +{ + + #region delegates + /// + /// Callback for receiving file handle events. The callback will be invoked once for each event which is pending. + /// + ///watch on which the event occurred + ///file handle on which the event occurred + ///bitset of events from virEventHandleType constants + ///user data registered with handle + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void virEventHandleCallback(int watch, int fd, int events, IntPtr opaque); + /// + /// Free callbacks + /// + ///user data registered with handle + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void virFreeCallback(IntPtr opaque); + /// + /// Part of the EventImpl, this callback Adds a file handle callback to listen for specific events. The same file handle can be registered multiple times provided the requested event sets are non-overlapping If the opaque user data requires free'ing when the handle is unregistered, then a 2nd callback can be supplied for this purpose. + /// + ///file descriptor to listen on + ///bitset of events on which to fire the callback + ///the callback to be called when an event occurrs + ///user data to pass to the callback + ///the callback invoked to free opaque data blob + ///a handle watch number to be used for updating and unregistering for events + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate int virEventAddHandleFunc(int fd, int events, virEventHandleCallback cb, IntPtr opaque, virFreeCallback ff); + /// + /// Part of the EventImpl, this user-provided callback is notified when events to listen on change + /// + ///file descriptor watch to modify + ///new events to listen on + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void virEventUpdateHandleFunc(int watch, int events); + /// + /// Part of the EventImpl, this user-provided callback is notified when an fd is no longer being listened on. If a virEventHandleFreeFunc was supplied when the handle was registered, it will be invoked some time during, or after this function call, when it is safe to release the user data. + /// + ///file descriptor watch to stop listening on + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate int virEventRemoveHandleFunc(int watch); + /// + /// callback for receiving timer events + /// + ///timer id emitting the event + ///user data registered with handle + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void virEventTimeoutCallback(int timer, IntPtr opaque); + /// + /// Part of the EventImpl, this user-defined callback handles adding an event timeout. If the opaque user data requires free'ing when the handle is unregistered, then a 2nd callback can be supplied for this purpose. + /// + ///The timeout to monitor + ///the callback to call when timeout has expired + ///user data to pass to the callback + ///the callback invoked to free opaque data blob + /// A timer value + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate int virEventAddTimeoutFunc(int timeout, virEventTimeoutCallback cb, IntPtr opaque, virFreeCallback ff); + /// + /// Part of the EventImpl, this user-defined callback updates an event timeout. + /// + ///the timer to modify + ///the new timeout value + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void virEventUpdateTimeoutFunc(int timer, int timeout); + /// + /// Part of the EventImpl, this user-defined callback removes a timer If a virEventTimeoutFreeFunc was supplied when the handle was registered, it will be invoked some time during, or after this function call, when it is safe to release the user data. + /// + ///the timer to remove + /// 0 on success, -1 on failure + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate int virEventRemoveTimeoutFunc(int timer); + /// + /// Authentication callback + /// + ///Pointer to a virConnectCredential array + ///number of virConnectCredential in cred + ///user data passed to callback + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate int virConnectAuthCallbackPtr([In, Out] IntPtr cred, uint ncred, IntPtr cbdata); + #endregion + + #region structs + /// + /// Blocks domain statistics + /// + [StructLayout(LayoutKind.Sequential)] + public struct virDomainBlockStatsStruct + { + /// + /// Number of read requests. + /// + public long rd_req; + /// + /// Number of read bytes. + /// + public long rd_bytes; + /// + /// Number of write requests. + /// + public long wr_req; + /// + /// Number of written bytes. + /// + public long wr_bytes; + /// + /// In Xen this returns the mysterious 'oo_req'. + /// + public long errs; + } + + /// + /// Domain interface statistics + /// + [StructLayout(LayoutKind.Sequential)] + public struct virDomainInterfaceStatsStruct + { + /// + /// Bytes received + /// + public long rx_bytes; + /// + /// Packets received + /// + public long rx_packets; + /// + /// Errors received + /// + public long rx_errs; + /// + /// Drops received + /// + public long rx_drop; + /// + /// Bytes sended + /// + public long tx_bytes; + /// + /// Packets sended + /// + public long tx_packets; + /// + /// Errors sended + /// + public long tx_errs; + /// + /// Drops sended + /// + public long tx_drop; + } + + /// + /// Structure to handle connection authentication + /// + [StructLayout(LayoutKind.Sequential)] + public struct virConnectAuth + { + /// + /// List of supported virConnectCredentialType values, should be a IntPtr to an int array or to a virConnectCredentialType array + /// + public IntPtr credtypes; + /// + /// Number of virConnectCredentialType in credtypes + /// + [MarshalAs(UnmanagedType.I4)] + public int ncredtype; + /// + /// Callback used to collect credentials, a virConnectAuthCallback delegate in bindings + /// + [MarshalAs(UnmanagedType.FunctionPtr)] + public virConnectAuthCallbackPtr cb; + /// + /// Data transported with callback, should be a IntPtr on what you want + /// + public IntPtr cbdata; + } + + /// + /// Credential structure + /// + [StructLayout(LayoutKind.Sequential, Pack = 4)] + public struct virConnectCredential + { + /// + /// One of virConnectCredentialType constants + /// + [MarshalAs(UnmanagedType.I4)] + public virConnectCredentialType type; + /// + /// Prompt to show to user + /// + [MarshalAs(UnmanagedType.LPStr)] + public string prompt; + /// + /// Additional challenge to show + /// + [MarshalAs(UnmanagedType.LPStr)] + public string challenge; + /// + /// Optional default result + /// + [MarshalAs(UnmanagedType.LPStr)] + public string defresult; + /// + /// Result to be filled with user response (or defresult). An IntPtr to a marshalled allocated string + /// + public IntPtr result; + /// + /// Length of the result + /// + [MarshalAs(UnmanagedType.U4)] + public uint resultlen; + } + + /// + /// Structure for domain memory statistics + /// + [StructLayout(LayoutKind.Sequential)] + public struct virDomainMemoryStat + { + /// + /// Tag + /// + [MarshalAs(UnmanagedType.I4)] + public virDomainMemoryStatTags tag; + /// + /// Value + /// + [MarshalAs(UnmanagedType.I8)] + public ulong val; + } + + /// + /// Structure to handle volume informations + /// + [StructLayout(LayoutKind.Sequential)] + public struct virStorageVolInfo + { + /// + /// virStorageVolType flags. + /// + [MarshalAs(UnmanagedType.I4)] + public virStorageVolType type; + /// + /// Logical size bytes. + /// + [MarshalAs(UnmanagedType.U8)] + public ulong capacity; + /// + /// Current allocation bytes. + /// + [MarshalAs(UnmanagedType.U8)] + public ulong allocation; + } + + /// + /// Structure to handle storage pool informations + /// + [StructLayout(LayoutKind.Sequential)] + public struct virStoragePoolInfo + { + /// + /// virStoragePoolState flags + /// + [MarshalAs(UnmanagedType.I4)] + public virStoragePoolState state; + /// + /// Logical size bytes + /// + [MarshalAs(UnmanagedType.U8)] + public ulong capacity; + /// + /// Current allocation bytes. + /// + [MarshalAs(UnmanagedType.U8)] + public ulong allocation; + /// + /// Remaining free space bytes. + /// + [MarshalAs(UnmanagedType.U8)] + public ulong available; + } + + /// + /// Structure to handle node informations + /// + public struct virNodeInfo + { + /// + /// String indicating the CPU model. + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] + public string model; + /// + /// Memory size in kilobytes + /// + public ulong memory; + /// + /// The number of active CPUs. + /// + public uint cpus; + /// + /// Expected CPU frequency. + /// + public uint mhz; + /// + /// The number of NUMA cell, 1 for uniform mem access. + /// + public uint nodes; + /// + /// Number of CPU socket per node. + /// + public uint sockets; + /// + /// Number of core per socket. + /// + public uint cores; + /// + /// Number of threads per core. + /// + public uint threads; + } + /// + /// Structure tu handle domain informations + /// + [StructLayout(LayoutKind.Sequential)] + public struct virDomainInfo + { + /// + /// The running state, one of virDomainState. + /// + public virDomainState state; + /// + /// The maximum memory in KBytes allowed. + /// + public ulong maxMem; + /// + /// The memory in KBytes used by the domain. + /// + public ulong memory; + /// + /// The number of virtual CPUs for the domain. + /// + public ushort nrVirtCpu; + /// + /// The CPU time used in nanoseconds. + /// + public ulong cpuTime; + } + #endregion + + #region enums + /// + /// Type of handles for callback + /// + [Flags] + public enum virEventHandleType + { + /// + /// None + /// + NONE = 0, + /// + /// Readable handle + /// + VIR_EVENT_HANDLE_READABLE = 1, + /// + /// Writable handle + /// + VIR_EVENT_HANDLE_WRITABLE = 2, + /// + /// Error handle + /// + VIR_EVENT_HANDLE_ERROR = 4, + /// + /// Hangup handle + /// + VIR_EVENT_HANDLE_HANGUP = 8 + } + + /// + /// Memory statistics tags + /// + [Flags] + public enum virDomainMemoryStatTags + { + /// + /// The total amount of memory written out to swap space (in kB). + /// + VIR_DOMAIN_MEMORY_STAT_SWAP_IN = 0, + /// + /// * Page faults occur when a process makes a valid access to virtual memory * that is not available. When servicing the page fault, if disk IO is * required, it is considered a major fault. If not, it is a minor fault. * These are expressed as the number of faults that have occurred. * + /// + VIR_DOMAIN_MEMORY_STAT_SWAP_OUT = 1, +#pragma warning disable 1591 + VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT = 2, +#pragma warning restore 1591 + /// + /// * The amount of memory left completely unused by the system. Memory that * is available but used for reclaimable caches should NOT be reported as * free. This value is expressed in kB. * + /// + VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT = 3, + /// + /// * The total amount of usable memory as seen by the domain. This value * may be less than the amount of memory assigned to the domain if a * balloon driver is in use or if the guest OS does not initialize all * assigned pages. This value is expressed in kB. * + /// + VIR_DOMAIN_MEMORY_STAT_UNUSED = 4, + /// + /// * The number of statistics supported by this version of the interface. * To add new statistics, add them to the enum and increase this value. * + /// + VIR_DOMAIN_MEMORY_STAT_AVAILABLE = 5, +#pragma warning disable 1591 + VIR_DOMAIN_MEMORY_STAT_NR = 6 +#pragma warning restore 1591 + } + + /// + /// Types of storage volume + /// + public enum virStorageVolType + { + /// + /// Regular file based volumes. + /// + VIR_STORAGE_VOL_FILE = 0, + /// + /// Block based volumes. + /// + VIR_STORAGE_VOL_BLOCK = 1 + } + + /// + /// States of storage pool + /// + public enum virStoragePoolState + { + /// + /// Not running. + /// + VIR_STORAGE_POOL_INACTIVE = 0, + /// + /// Initializing pool, not available. + /// + VIR_STORAGE_POOL_BUILDING = 1, + /// + /// Running normally. + /// + VIR_STORAGE_POOL_RUNNING = 2, + /// + /// Running degraded. + /// + VIR_STORAGE_POOL_DEGRADED = 3, + } + /// + /// Flasg for XML domain rendering + /// + [Flags] + public enum virDomainXMLFlags + { + /// + /// Dump security sensitive information too. + /// + VIR_DOMAIN_XML_SECURE = 1, + /// + /// Dump inactive domain information. + /// + VIR_DOMAIN_XML_INACTIVE = 2 + } + + /// + /// Details on the caused of the 'defined' lifecycle event + /// + public enum virDomainEventDefinedDetailType + { + /// + /// Newly created config file + /// + VIR_DOMAIN_EVENT_DEFINED_ADDED = 0, + /// + /// Changed config file + /// + VIR_DOMAIN_EVENT_DEFINED_UPDATED = 1 + } + + /// + /// Details on the caused of the 'undefined' lifecycle event + /// + public enum virDomainEventUndefinedDetailType + { + /// + /// Deleted the config file + /// + VIR_DOMAIN_EVENT_UNDEFINED_REMOVED = 0 + } + /// + /// Details on the caused of the 'started' lifecycle event + /// + public enum virDomainEventStartedDetailType + { + /// + /// Normal startup from boot + /// + VIR_DOMAIN_EVENT_STARTED_BOOTED = 0, + /// + /// Incoming migration from another host + /// + VIR_DOMAIN_EVENT_STARTED_MIGRATED = 1, + /// + /// Restored from a state file + /// + VIR_DOMAIN_EVENT_STARTED_RESTORED = 2 + } + /// + /// Details on the caused of the 'suspended' lifecycle event + /// + public enum virDomainEventSuspendedDetailType + { + /// + /// Normal suspend due to admin pause + /// + VIR_DOMAIN_EVENT_SUSPENDED_PAUSED = 0, + /// + /// Suspended for offline migration + /// + VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED = 1 + } + /// + /// Details on the caused of the 'resumed' lifecycle event + /// + public enum virDomainEventResumedDetailType + { + /// + /// Normal resume due to admin unpause + /// + VIR_DOMAIN_EVENT_RESUMED_UNPAUSED = 0, + /// + /// Resumed for completion of migration + /// + VIR_DOMAIN_EVENT_RESUMED_MIGRATED = 1 + } + /// + /// Details on the caused of the 'stopped' lifecycle event + /// + public enum virDomainEventStoppedDetailType + { + /// + /// Normal shutdown + /// + VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN = 0, + /// + /// Forced poweroff from host + /// + VIR_DOMAIN_EVENT_STOPPED_DESTROYED = 1, + /// + /// Guest crashed + /// + VIR_DOMAIN_EVENT_STOPPED_CRASHED = 2, + /// + /// Migrated off to another host + /// + VIR_DOMAIN_EVENT_STOPPED_MIGRATED = 3, + /// + /// Saved to a state file + /// + VIR_DOMAIN_EVENT_STOPPED_SAVED = 4, + /// + /// Host emulator/mgmt failed + /// + VIR_DOMAIN_EVENT_STOPPED_FAILED = 5 + } + + /// + /// Types of domain events + /// + public enum virDomainEventType + { + /// + /// Domain defined + /// + VIR_DOMAIN_EVENT_DEFINED = 0, + /// + /// Domain undefined + /// + VIR_DOMAIN_EVENT_UNDEFINED = 1, + /// + /// Domain started + /// + VIR_DOMAIN_EVENT_STARTED = 2, + /// + /// Domain suspended + /// + VIR_DOMAIN_EVENT_SUSPENDED = 3, + /// + /// Domain resumed + /// + VIR_DOMAIN_EVENT_RESUMED = 4, + /// + /// Domain stopped + /// + VIR_DOMAIN_EVENT_STOPPED = 5 + } + + /// + /// Flags for storage pool building + /// + public enum virStoragePoolBuildFlags + { + /// + /// Regular build from scratch. + /// + VIR_STORAGE_POOL_BUILD_NEW = 0, + /// + /// Repair / reinitialize. + /// + VIR_STORAGE_POOL_BUILD_REPAIR = 1, + /// + /// Extend existing pool. + /// + VIR_STORAGE_POOL_BUILD_RESIZE = 2 + } + + /// + /// Flags for storage pool deletion + /// + public enum virStoragePoolDeleteFlags + { + /// + /// Delete metadata only (fast). + /// + VIR_STORAGE_POOL_DELETE_NORMAL = 0, + /// + /// Clear all data to zeros (slow). + /// + VIR_STORAGE_POOL_DELETE_ZEROED = 1 + } + /// + /// Types of credentials + /// + public enum virConnectCredentialType + { + /// + /// Identity to act as + /// + VIR_CRED_USERNAME = 1, + /// + /// Identify to authorize as + /// + VIR_CRED_AUTHNAME = 2, + /// + /// RFC 1766 languages, comma separated + /// + VIR_CRED_LANGUAGE = 3, + /// + /// client supplies a nonce + /// + VIR_CRED_CNONCE = 4, + /// + /// Passphrase secret + /// + VIR_CRED_PASSPHRASE = 5, + /// + /// Challenge response + /// + VIR_CRED_ECHOPROMPT = 6, + /// + /// Challenge response + /// + VIR_CRED_NOECHOPROMPT = 7, + /// + /// Authentication realm + /// + VIR_CRED_REALM = 8, + /// + /// Externally managed credential More may be added - expect the unexpected + /// + VIR_CRED_EXTERNAL = 9 + } + + /// + /// States of a domain + /// + public enum virDomainState + { + /// + /// No state. + /// + VIR_DOMAIN_NOSTATE = 0, + /// + /// The domain is running. + /// + VIR_DOMAIN_RUNNING = 1, + /// + /// The domain is blocked on resource. + /// + VIR_DOMAIN_BLOCKED = 2, + /// + /// The domain is paused by user. + /// + VIR_DOMAIN_PAUSED = 3, + /// + /// The domain is being shut down. + /// + VIR_DOMAIN_SHUTDOWN = 4, + /// + /// The domain is shut off. + /// + VIR_DOMAIN_SHUTOFF = 5, + /// + /// The domain is crashed. + /// + VIR_DOMAIN_CRASHED = 6 + } + #endregion +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..025692b --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Les informations générales relatives à un assembly dépendent de +// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations +// associées à un assembly. +[assembly: AssemblyTitle("LibvirtBindings")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("LibvirtBindings")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly +// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de +// COM, affectez la valeur true à l'attribut ComVisible sur ce type. +[assembly: ComVisible(false)] + +// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM +[assembly: Guid("16f4aacb-8e02-4c2d-902f-e83f0a7c0570")] + +// Les informations de version pour un assembly se composent des quatre valeurs suivantes : +// +// Version principale +// Version secondaire +// Numéro de build +// Révision +// +// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut +// en utilisant '*', comme indiqué ci-dessous : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]