The following patch stubs out virDomainRename() as an available API function. I'm just making sure I'm doing this right. I know there were some plans to include documentation about adding API to the website but I don't see it. The included patch does not include my example driver for qemu and test.
Just looking for a thumbs up/down whether I should continue or not and whether I'm adding it right. -- Doug Goldstein
diff --git a/docs/libvirt-api.xml b/docs/libvirt-api.xml index fc85acd..ec4131d 100644 --- a/docs/libvirt-api.xml +++ b/docs/libvirt-api.xml @@ -202,6 +202,7 @@ <exports symbol='virDomainCreateLinux' type='function'/> <exports symbol='virNodeDeviceGetXMLDesc' type='function'/> <exports symbol='virEventUpdateHandleFunc' type='function'/> + <exports symbol='virDomainRename' type='function'/> <exports symbol='virDomainDestroy' type='function'/> <exports symbol='virConnectNumOfNetworks' type='function'/> <exports symbol='virStoragePoolLookupByUUIDString' type='function'/> @@ -1131,6 +1132,12 @@ see note above'/> <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/> <arg name='xml' type='const char *' info='the XML description for the domain, preferably in UTF-8'/> </function> + <function name='virDomainRename' file='libvirt' module='libvirt'> + <info>Rename the domain to the requested name. This function may require privileged access</info> + <return type='int' info='0 in case of success and -1 in case of failure.'/> + <arg name='domain' type='virDomainPtr' info='a domain object'/> + <arg name='name' type='const char *' info='new name to rename domain to'/> + </function> <function name='virDomainDestroy' file='libvirt' module='libvirt'> <info>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</info> <return type='int' info='0 in case of success and -1 in case of failure.'/> diff --git a/docs/libvirt-refs.xml b/docs/libvirt-refs.xml index 7d28d42..f983209 100644 --- a/docs/libvirt-refs.xml +++ b/docs/libvirt-refs.xml @@ -247,6 +247,7 @@ <reference name='virDomainCreateLinux' href='html/libvirt-libvirt.html#virDomainCreateLinux'/> <reference name='virDomainCreateXML' href='html/libvirt-libvirt.html#virDomainCreateXML'/> <reference name='virDomainDefineXML' href='html/libvirt-libvirt.html#virDomainDefineXML'/> + <reference name='virDomainRename' href='html/libvirt-libvirt.html#virDomainRename'/> <reference name='virDomainDestroy' href='html/libvirt-libvirt.html#virDomainDestroy'/> <reference name='virDomainDetachDevice' href='html/libvirt-libvirt.html#virDomainDetachDevice'/> <reference name='virDomainEventDefinedDetailType' href='html/libvirt-libvirt.html#virDomainEventDefinedDetailType'/> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 869c361..1c35ed1 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -518,6 +518,8 @@ virDomainPtr virDomainLookupByUUIDString (virConnectPtr conn, int virDomainShutdown (virDomainPtr domain); int virDomainReboot (virDomainPtr domain, unsigned int flags); +int virDomainRename (virDomainPtr domain, + const char *name); int virDomainDestroy (virDomainPtr domain); int virDomainRef (virDomainPtr domain); int virDomainFree (virDomainPtr domain); diff --git a/qemud/remote_protocol.x b/qemud/remote_protocol.x index 56385f4..860e317 100644 --- a/qemud/remote_protocol.x +++ b/qemud/remote_protocol.x @@ -460,6 +460,11 @@ struct remote_domain_reboot_args { int flags; }; +struct remote_domain_rename_args { + remote_nonnull_domain dom; + remote_nonnull_string name; +}; + struct remote_domain_destroy_args { remote_nonnull_domain dom; }; diff --git a/src/driver.h b/src/driver.h index ef81af2..c810505 100644 --- a/src/driver.h +++ b/src/driver.h @@ -126,6 +126,9 @@ typedef int (*virDrvDomainReboot) (virDomainPtr domain, unsigned int flags); typedef int + (*virDrvDomainRename) (virDomainPtr domain, + const char *name); +typedef int (*virDrvDomainDestroy) (virDomainPtr domain); typedef char * (*virDrvDomainGetOSType) (virDomainPtr domain); diff --git a/src/libvirt.c b/src/libvirt.c index 2623447..1572dad 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1832,6 +1832,51 @@ error: } /** + * virDomainRename: + * @domain: a domain object + * @name: new name for the domain + * + * Try to rename the domain to the requested domain name. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainRename(virDomainPtr domain, const char *name) +{ + virConnectPtr conn; + + DEBUG("domain=%p", domain); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { + virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + return (-1); + } + + conn = domain->conn; + if (conn->flags & VIR_CONNECT_RO) { + virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__); + goto error; + } + + if (conn->driver->domainRename) { + int ret; + ret = conn->driver->domainRename(domain, name); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + /* Copy to connection error object for back compatability */ + virSetConnError(conn); + return (-1); +} + +/** * virDomainDestroy: * @domain: a domain object * diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 3f0f4bc..0c1fd70 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -285,4 +285,9 @@ LIBVIRT_0.6.4 { virConnectDomainXMLToNative; } LIBVIRT_0.6.3; +LIBVIRT_0.6.5 { + global: + virDomainRename; +} LIBVIRT_0.6.4; + # .... define new API here using predicted next version number .... diff --git a/src/lxc_driver.c b/src/lxc_driver.c index f2279a7..3d73d93 100644 --- a/src/lxc_driver.c +++ b/src/lxc_driver.c @@ -1455,6 +1455,7 @@ static virDriver lxcDriver = { NULL, /* domainResume */ lxcDomainShutdown, /* domainShutdown */ NULL, /* domainReboot */ + NULL, /* domainRename */ lxcDomainDestroy, /* domainDestroy */ lxcGetOSType, /* domainGetOSType */ NULL, /* domainGetMaxMemory */ diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c index 70da4fa..87eeddb 100644 --- a/src/opennebula/one_driver.c +++ b/src/opennebula/one_driver.c @@ -733,6 +733,7 @@ static virDriver oneDriver = { oneDomainResume, /* domainResume */ oneDomainShutdown, /* domainShutdown */ NULL, /* domainReboot */ + NULL, /* domainRename */ oneDomainDestroy, /* domainDestroy */ oneGetOSType, /* domainGetOSType */ NULL, /* domainGetMaxMemory */ diff --git a/src/openvz_driver.c b/src/openvz_driver.c index 4c0fc5f..d78f2b8 100644 --- a/src/openvz_driver.c +++ b/src/openvz_driver.c @@ -1323,6 +1323,7 @@ static virDriver openvzDriver = { NULL, /* domainResume */ openvzDomainShutdown, /* domainShutdown */ openvzDomainReboot, /* domainReboot */ + NULL, /* domainRename */ openvzDomainShutdown, /* domainDestroy */ openvzGetOSType, /* domainGetOSType */ NULL, /* domainGetMaxMemory */ diff --git a/src/proxy_internal.c b/src/proxy_internal.c index 5b92ad8..3eb4835 100644 --- a/src/proxy_internal.c +++ b/src/proxy_internal.c @@ -59,6 +59,7 @@ struct xenUnifiedDriver xenProxyDriver = { NULL, /* domainResume */ NULL, /* domainShutdown */ NULL, /* domainReboot */ + NULL, /* domainRename */ NULL, /* domainDestroy */ xenProxyDomainGetOSType, /* domainGetOSType */ xenProxyDomainGetMaxMemory, /* domainGetMaxMemory */ diff --git a/src/qemu_driver.c b/src/qemu_driver.c index a7bea7d..c909ba5 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -5281,6 +5281,7 @@ static virDriver qemuDriver = { qemudDomainResume, /* domainResume */ qemudDomainShutdown, /* domainShutdown */ NULL, /* domainReboot */ + NULL, /* domainRename */ qemudDomainDestroy, /* domainDestroy */ qemudDomainGetOSType, /* domainGetOSType */ qemudDomainGetMaxMemory, /* domainGetMaxMemory */ diff --git a/src/remote_internal.c b/src/remote_internal.c index 0363ba4..7801303 100644 --- a/src/remote_internal.c +++ b/src/remote_internal.c @@ -7347,6 +7347,7 @@ static virDriver driver = { remoteDomainResume, /* domainResume */ remoteDomainShutdown, /* domainShutdown */ remoteDomainReboot, /* domainReboot */ + NULL, /* domainRename */ remoteDomainDestroy, /* domainDestroy */ remoteDomainGetOSType, /* domainGetOSType */ remoteDomainGetMaxMemory, /* domainGetMaxMemory */ diff --git a/src/test.c b/src/test.c index ba9ad66..8d1af4d 100644 --- a/src/test.c +++ b/src/test.c @@ -3575,6 +3575,7 @@ static virDriver testDriver = { testResumeDomain, /* domainResume */ testShutdownDomain, /* domainShutdown */ testRebootDomain, /* domainReboot */ + NULL, /* domainRename */ testDestroyDomain, /* domainDestroy */ testGetOSType, /* domainGetOSType */ testGetMaxMemory, /* domainGetMaxMemory */ diff --git a/src/uml_driver.c b/src/uml_driver.c index 98540e3..a2e1868 100644 --- a/src/uml_driver.c +++ b/src/uml_driver.c @@ -1794,6 +1794,7 @@ static virDriver umlDriver = { NULL, /* domainResume */ umlDomainShutdown, /* domainShutdown */ NULL, /* domainReboot */ + NULL, /* domainRename */ umlDomainDestroy, /* domainDestroy */ umlDomainGetOSType, /* domainGetOSType */ umlDomainGetMaxMemory, /* domainGetMaxMemory */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 3208f03..a4b829c 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -4918,6 +4918,7 @@ virDriver NAME(Driver) = { vboxDomainResume, /* domainResume */ vboxDomainShutdown, /* domainShutdown */ vboxDomainReboot, /* domainReboot */ + NULL, /* domainRename */ vboxDomainDestroy, /* domainDestroy */ vboxDomainGetOSType, /* domainGetOSType */ NULL, /* domainGetMaxMemory */ diff --git a/src/xen_inotify.c b/src/xen_inotify.c index f4716ca..39939aa 100644 --- a/src/xen_inotify.c +++ b/src/xen_inotify.c @@ -63,7 +63,7 @@ struct xenUnifiedDriver xenInotifyDriver = { NULL, /* domainResume */ NULL, /* domainShutdown */ NULL, /* domainReboot */ - NULL, /* domainDestroy */ + NULL, /* domainRename */ NULL, /* domainGetOSType */ NULL, /* domainGetMaxMemory */ NULL, /* domainSetMaxMemory */ diff --git a/src/xen_unified.c b/src/xen_unified.c index 57efb40..ed37772 100644 --- a/src/xen_unified.c +++ b/src/xen_unified.c @@ -1655,6 +1655,7 @@ static virDriver xenUnifiedDriver = { xenUnifiedDomainResume, /* domainResume */ xenUnifiedDomainShutdown, /* domainShutdown */ xenUnifiedDomainReboot, /* domainReboot */ + NULL, /* domainRename */ xenUnifiedDomainDestroy, /* domainDestroy */ xenUnifiedDomainGetOSType, /* domainGetOSType */ xenUnifiedDomainGetMaxMemory, /* domainGetMaxMemory */
-- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list