libvirt commit
http://libvirt.org/git/?p=libvirt.git;a=commit;h=e2c41e486018ee74f6a75c1f...
strongly hints that driver type for a disk domain should be an
enum rather than a raw string. Since we already have setters/getters
for this attribute, we can't use the same name as in the XML. However,
as Daniel Berrangé pointed out,
gvir_config_domain_disk_[gs]et_driver_format is a better name for this,
so we add the API accepting an enum under this name.
I did not set "Rename to: gvir_config_domain_disk_[gs]et_driver_format"
in a gtk-doc comment to force bindings to use this better version
as this would break Boxes for example.
---
examples/config-demo.py | 2 +-
libvirt-gconfig/libvirt-gconfig-compat.h | 20 ++++++++++++++
libvirt-gconfig/libvirt-gconfig-domain-disk.c | 38 +++++++++++++++++++++++++++
libvirt-gconfig/libvirt-gconfig-domain-disk.h | 5 ++++
libvirt-gconfig/libvirt-gconfig.sym | 2 ++
libvirt-gconfig/tests/test-domain-create.c | 6 ++---
6 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/examples/config-demo.py b/examples/config-demo.py
index 268c439..09b9e89 100644
--- a/examples/config-demo.py
+++ b/examples/config-demo.py
@@ -28,7 +28,7 @@ disk.set_type(LibvirtGConfig.DomainDiskType.FILE)
disk.set_guest_device_type(LibvirtGConfig.DomainDiskGuestDeviceType.DISK)
disk.set_source("/tmp/foo/bar")
disk.set_driver_name("qemu")
-disk.set_driver_type("qcow2")
+disk.set_driver_format(LibvirtGConfig.DriverType.QCOW2)
disk.set_target_bus(LibvirtGConfig.DomainDiskBus.IDE)
disk.set_target_dev("hda")
domain.add_device(disk)
diff --git a/libvirt-gconfig/libvirt-gconfig-compat.h
b/libvirt-gconfig/libvirt-gconfig-compat.h
index c9ac645..fbf552c 100644
--- a/libvirt-gconfig/libvirt-gconfig-compat.h
+++ b/libvirt-gconfig/libvirt-gconfig-compat.h
@@ -25,6 +25,26 @@
#include <glib-object.h>
+#if !GLIB_CHECK_VERSION(2,32,0)
+
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
+#define G_DEPRECATED __attribute__((__deprecated__))
+#elif defined(_MSC_VER) && (_MSC_VER >= 1300)
+#define G_DEPRECATED __declspec(deprecated)
+#else
+#define G_DEPRECATED
+#endif
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f
"' instead")))
+#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
+#define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f
"' instead"))
+#else
+#define G_DEPRECATED_FOR(f) G_DEPRECATED
+#endif
+
+#endif
+
#if GLIB_CHECK_VERSION(2, 35, 0)
#define g_type_init()
#endif
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c
b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
index a167141..4f85262 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
@@ -173,6 +173,12 @@ void gvir_config_domain_disk_set_driver_name(GVirConfigDomainDisk
*disk,
"driver", "name",
driver_name);
}
+/**
+ * gvir_config_domain_disk_set_driver_type:
+ *
+ * Deprecated: 0.1.7: Use gvir_config_domain_disk_set_driver_format()
+ * instead
+ */
void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk,
const char *driver_type)
{
@@ -181,6 +187,18 @@ void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk
*disk,
"driver", "type",
driver_type);
}
+
+void gvir_config_domain_disk_set_driver_format(GVirConfigDomainDisk *disk,
+ GVirConfigDomainDiskFormat format)
+{
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk));
+ gvir_config_object_add_child_with_attribute_enum(GVIR_CONFIG_OBJECT(disk),
+ "driver",
"type",
+
GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT,
+ format);
+}
+
+
void gvir_config_domain_disk_set_driver_cache(GVirConfigDomainDisk *disk,
GVirConfigDomainDiskCacheType cache_type)
{
@@ -294,6 +312,12 @@ gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk)
"driver", "name");
}
+/**
+ * gvir_config_domain_disk_get_driver_type:
+ *
+ * Deprecated: 0.1.7: Use gvir_config_domain_disk_get_driver_format()
+ * instead
+ */
const char *
gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk)
{
@@ -303,6 +327,20 @@ gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk)
"driver", "type");
}
+
+GVirConfigDomainDiskFormat
+gvir_config_domain_disk_get_driver_format(GVirConfigDomainDisk *disk)
+{
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk),
+ GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW);
+
+ return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(disk),
+ "driver", "type",
+ GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT,
+ GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW);
+}
+
+
GVirConfigDomainDiskCacheType
gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk)
{
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.h
b/libvirt-gconfig/libvirt-gconfig-domain-disk.h
index e80a2fc..3b82eb5 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.h
@@ -141,8 +141,11 @@ void gvir_config_domain_disk_set_driver_cache(GVirConfigDomainDisk
*disk,
GVirConfigDomainDiskCacheType cache_type);
void gvir_config_domain_disk_set_driver_name(GVirConfigDomainDisk *disk,
const char *driver_name);
+G_DEPRECATED_FOR(gvir_config_domain_disk_set_driver_format)
void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk,
const char *driver_type);
+void gvir_config_domain_disk_set_driver_format(GVirConfigDomainDisk *disk,
+ GVirConfigDomainDiskFormat format);
void gvir_config_domain_disk_set_target_bus(GVirConfigDomainDisk *disk,
GVirConfigDomainDiskBus bus);
void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk *disk,
@@ -155,7 +158,9 @@ GVirConfigDomainDiskStartupPolicy
gvir_config_domain_disk_get_startup_policy(GVi
const char *gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk);
GVirConfigDomainDiskCacheType
gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk);
const char *gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk);
+G_DEPRECATED_FOR(gvir_config_domain_disk_get_driver_format)
const char *gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk);
+GVirConfigDomainDiskFormat gvir_config_domain_disk_get_driver_format(GVirConfigDomainDisk
*disk);
GVirConfigDomainDiskBus gvir_config_domain_disk_get_target_bus(GVirConfigDomainDisk
*disk);
const char *gvir_config_domain_disk_get_target_dev(GVirConfigDomainDisk *disk);
void gvir_config_domain_disk_set_readonly(GVirConfigDomainDisk *disk,
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index ccca05f..4e12fb2 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -518,6 +518,8 @@ LIBVIRT_GCONFIG_0.1.7 {
gvir_config_domain_channel_get_target_type;
gvir_config_domain_disk_format_get_type;
+ gvir_config_domain_disk_get_driver_format;
+ gvir_config_domain_disk_set_driver_format;
gvir_config_domain_graphics_desktop_get_type;
gvir_config_domain_graphics_desktop_new;
diff --git a/libvirt-gconfig/tests/test-domain-create.c
b/libvirt-gconfig/tests/test-domain-create.c
index 51ece7b..ae0b248 100644
--- a/libvirt-gconfig/tests/test-domain-create.c
+++ b/libvirt-gconfig/tests/test-domain-create.c
@@ -240,10 +240,10 @@ int main(int argc, char **argv)
gvir_config_domain_disk_set_source(disk, "/tmp/foo/bar");
gvir_config_domain_disk_set_startup_policy (disk,
GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_REQUISITE);
gvir_config_domain_disk_set_driver_name(disk, "foo");
- gvir_config_domain_disk_set_driver_type(disk, "bar");
+ gvir_config_domain_disk_set_driver_format(disk,
GVIR_CONFIG_DOMAIN_DISK_FORMAT_BOCHS);
gvir_config_domain_disk_set_driver_name(disk, "qemu");
gvir_config_domain_disk_set_driver_cache(disk, GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE);
- gvir_config_domain_disk_set_driver_type(disk, "qcow2");
+ gvir_config_domain_disk_set_driver_format(disk,
GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW2);
gvir_config_domain_disk_set_target_bus(disk, GVIR_CONFIG_DOMAIN_DISK_BUS_IDE);
gvir_config_domain_disk_set_target_dev(disk, "hda");
devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(disk));
@@ -254,7 +254,7 @@ int main(int argc, char **argv)
g_str_const_check(gvir_config_domain_disk_get_source(disk),
"/tmp/foo/bar");
g_assert(gvir_config_domain_disk_get_driver_cache(disk) ==
GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE);
g_str_const_check(gvir_config_domain_disk_get_driver_name(disk), "qemu");
- g_str_const_check(gvir_config_domain_disk_get_driver_type(disk), "qcow2");
+ g_assert(gvir_config_domain_disk_get_driver_format(disk) ==
GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW2);
g_assert(gvir_config_domain_disk_get_target_bus(disk) ==
GVIR_CONFIG_DOMAIN_DISK_BUS_IDE);
g_str_const_check(gvir_config_domain_disk_get_target_dev(disk), "hda");
--
1.8.2.1