Also, among with this new API new ACL that restricts rename capability
is invented too.
Signed-off-by: Tomas Meszaros <exo(a)tty.sk>
---
include/libvirt/libvirt-domain.h | 2 ++
src/access/viraccessperm.c | 3 ++-
src/access/viraccessperm.h | 6 ++++++
src/driver-hypervisor.h | 5 +++++
src/libvirt-domain.c | 31 +++++++++++++++++++++++++++++++
src/libvirt_public.syms | 5 +++++
src/remote/remote_driver.c | 1 +
src/remote/remote_protocol.x | 18 +++++++++++++++++-
src/remote_protocol-structs | 8 ++++++++
9 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index e8202cf..2ddc47d 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -3837,4 +3837,6 @@ int virDomainSetUserPassword(virDomainPtr dom,
const char *password,
unsigned int flags);
+int virDomainRename(virDomainPtr dom, const char *new_name);
+
#endif /* __VIR_LIBVIRT_DOMAIN_H__ */
diff --git a/src/access/viraccessperm.c b/src/access/viraccessperm.c
index 0f58290..bdc7f60 100644
--- a/src/access/viraccessperm.c
+++ b/src/access/viraccessperm.c
@@ -43,7 +43,8 @@ VIR_ENUM_IMPL(virAccessPermDomain,
"fs_trim", "fs_freeze",
"block_read", "block_write", "mem_read",
"open_graphics", "open_device",
"screenshot",
- "open_namespace", "set_time",
"set_password");
+ "open_namespace", "set_time",
"set_password",
+ "rename");
VIR_ENUM_IMPL(virAccessPermInterface,
VIR_ACCESS_PERM_INTERFACE_LAST,
diff --git a/src/access/viraccessperm.h b/src/access/viraccessperm.h
index 1817da7..6ae4ee7 100644
--- a/src/access/viraccessperm.h
+++ b/src/access/viraccessperm.h
@@ -306,6 +306,12 @@ typedef enum {
*/
VIR_ACCESS_PERM_DOMAIN_SET_PASSWORD,
+ /**
+ * @desc: Rename domain
+ * @message: Renaming the domain requires authorization
+ */
+ VIR_ACCESS_PERM_DOMAIN_RENAME,
+
VIR_ACCESS_PERM_DOMAIN_LAST,
} virAccessPermDomain;
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 3275343..e8c8c2a 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -650,6 +650,10 @@ typedef int
(*virDrvDomainIsActive)(virDomainPtr dom);
typedef int
+(*virDrvDomainRename)(virDomainPtr dom,
+ const char *new_name);
+
+typedef int
(*virDrvDomainIsPersistent)(virDomainPtr dom);
typedef int
@@ -1347,6 +1351,7 @@ struct _virHypervisorDriver {
virDrvConnectIsEncrypted connectIsEncrypted;
virDrvConnectIsSecure connectIsSecure;
virDrvDomainIsActive domainIsActive;
+ virDrvDomainRename domainRename;
virDrvDomainIsPersistent domainIsPersistent;
virDrvDomainIsUpdated domainIsUpdated;
virDrvConnectCompareCPU connectCompareCPU;
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 837933f..c200965 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -8774,6 +8774,37 @@ virDomainIsPersistent(virDomainPtr dom)
return -1;
}
+/**
+ * virDomainRename:
+ * @dom: pointer to the domain object
+ * @new_name: new domain name
+ *
+ * Rename an inactive domain. New domain name is specified in the second
+ * argument.
+ *
+ * Returns 0 if renamed, -1 on error
+ */
+int
+virDomainRename(virDomainPtr dom, const char *new_name)
+{
+ VIR_DEBUG("dom=%p, new_name=%s", dom, NULLSTR(new_name));
+
+ virResetLastError();
+ virCheckDomainReturn(dom, -1);
+ virCheckNonNullArgGoto(new_name, error);
+
+ if (dom->conn->driver->domainRename) {
+ int ret = dom->conn->driver->domainRename(dom, new_name);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virReportUnsupportedError();
+ error:
+ virDispatchError(dom->conn);
+ return -1;
+}
/**
* virDomainIsUpdated:
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 2c653f2..dd94191 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -720,4 +720,9 @@ LIBVIRT_1.2.17 {
virTypedParamsAddStringList;
} LIBVIRT_1.2.16;
+LIBVIRT_1.2.19 {
+ global:
+ virDomainRename;
+} LIBVIRT_1.2.17;
+
# .... define new API here using predicted next version number ....
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 5c4cf7c..ec26ebe 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8391,6 +8391,7 @@ static virHypervisorDriver hypervisor_driver = {
.domainGetFSInfo = remoteDomainGetFSInfo, /* 1.2.11 */
.domainInterfaceAddresses = remoteDomainInterfaceAddresses, /* 1.2.14 */
.domainSetUserPassword = remoteDomainSetUserPassword, /* 1.2.16 */
+ .domainRename = remoteDomainRename, /* 1.2.19 */
};
static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 9f1be6b..0f26793 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -3230,6 +3230,14 @@ struct remote_domain_set_user_password_args {
unsigned int flags;
};
+struct remote_domain_rename_args {
+ remote_nonnull_domain dom;
+ remote_string new_name;
+};
+
+struct remote_domain_rename_ret {
+ int rename;
+};
/*----- Protocol. -----*/
@@ -5696,5 +5704,13 @@ enum remote_procedure {
* @generate:both
* @acl: domain:set_password
*/
- REMOTE_PROC_DOMAIN_SET_USER_PASSWORD = 357
+ REMOTE_PROC_DOMAIN_SET_USER_PASSWORD = 357,
+
+ /**
+ * @generate: both
+ * @acl: domain:rename
+ * @acl: domain:write
+ * @acl: domain:save
+ */
+ REMOTE_PROC_DOMAIN_RENAME = 358
};
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 48c3bd8..1fdaa55 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2684,6 +2684,13 @@ struct remote_domain_set_user_password_args {
remote_string password;
u_int flags;
};
+struct remote_domain_rename_args {
+ remote_nonnull_domain dom;
+ remote_string new_name;
+};
+struct remote_domain_rename_ret {
+ int rename;
+};
enum remote_procedure {
REMOTE_PROC_CONNECT_OPEN = 1,
REMOTE_PROC_CONNECT_CLOSE = 2,
@@ -3042,4 +3049,5 @@ enum remote_procedure {
REMOTE_PROC_DOMAIN_ADD_IOTHREAD = 355,
REMOTE_PROC_DOMAIN_DEL_IOTHREAD = 356,
REMOTE_PROC_DOMAIN_SET_USER_PASSWORD = 357,
+ REMOTE_PROC_DOMAIN_RENAME = 358,
};
--
2.1.0