[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [libvirt-glib 2/2] Add GVirConfigDomainDisk getters



---
 libvirt-gconfig/libvirt-gconfig-domain-disk.c |  101 +++++++++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain-disk.h |   10 +++
 libvirt-gconfig/libvirt-gconfig.sym           |    8 ++
 3 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
index 1121007..2f659a0 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c
@@ -191,3 +191,104 @@ void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk *disk,
     gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk),
                                                 "target", "dev", dev);
 }
+
+GVirConfigDomainDiskType
+gvir_config_domain_disk_get_disk_type(GVirConfigDomainDisk *disk)
+{
+    return disk->priv->type;
+}
+
+GVirConfigDomainDiskGuestDeviceType
+gvir_config_domain_disk_get_guest_device_type(GVirConfigDomainDisk *disk)
+{
+    g_return_val_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk),
+                         GVIR_CONFIG_DOMAIN_DISK_GUEST_DEVICE_DISK);
+
+    return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(disk),
+                                                  NULL,
+                                                  "device",
+                                                  GVIR_TYPE_CONFIG_DOMAIN_DISK_GUEST_DEVICE_TYPE,
+                                                  GVIR_CONFIG_DOMAIN_DISK_GUEST_DEVICE_DISK);
+}
+
+GVirConfigDomainDiskSnapshotType
+gvir_config_domain_disk_get_snapshot_type(GVirConfigDomainDisk *disk)
+{
+    g_return_val_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk),
+                         GVIR_CONFIG_DOMAIN_DISK_SNAPSHOT_NO);
+
+    return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(disk),
+                                                  NULL,
+                                                  "snapshot",
+                                                  GVIR_TYPE_CONFIG_DOMAIN_DISK_SNAPSHOT_TYPE,
+                                                  GVIR_CONFIG_DOMAIN_DISK_SNAPSHOT_NO);
+}
+
+char *
+gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk)
+{
+    const char *attribute_name;
+
+    g_return_val_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk), NULL);
+
+    switch (disk->priv->type) {
+        case GVIR_CONFIG_DOMAIN_DISK_FILE:
+            attribute_name = "file";
+            break;
+        case GVIR_CONFIG_DOMAIN_DISK_BLOCK:
+            attribute_name = "dev";
+            break;
+        case GVIR_CONFIG_DOMAIN_DISK_DIR:
+            attribute_name = "dir";
+            break;
+        case GVIR_CONFIG_DOMAIN_DISK_NETWORK:
+            attribute_name = "protocol";
+            break;
+        default:
+            g_return_val_if_reached(NULL);
+    }
+    return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(disk),
+                                            "source", attribute_name);
+}
+
+char *
+gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk)
+{
+    g_return_val_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk), NULL);
+
+    return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(disk),
+                                            "driver", "name");
+}
+
+char *
+gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk)
+{
+    g_return_val_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk), NULL);
+
+    return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(disk),
+                                            "driver", "type");
+}
+
+GVirConfigDomainDiskBus
+gvir_config_domain_disk_get_target_bus(GVirConfigDomainDisk *disk)
+{
+    /* FIXME: the default value depends on the "name" attribute, should we
+     * copy what libvirt is doing here?
+     */
+    g_return_val_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk),
+                         GVIR_CONFIG_DOMAIN_DISK_BUS_IDE);
+
+    return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(disk),
+                                                  "target", "snapshot",
+                                                  GVIR_TYPE_CONFIG_DOMAIN_DISK_BUS,
+                                                  GVIR_CONFIG_DOMAIN_DISK_BUS_IDE);
+}
+
+char *
+gvir_config_domain_disk_get_target_dev(GVirConfigDomainDisk *disk)
+{
+    g_return_val_if_fail(GVIR_IS_CONFIG_DOMAIN_DISK(disk), NULL);
+
+    return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(disk),
+                                            "target", "dev");
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-disk.h
index bc63dfe..650bdc6 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-disk.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.h
@@ -108,6 +108,16 @@ void gvir_config_domain_disk_set_target_bus(GVirConfigDomainDisk *disk,
                                             GVirConfigDomainDiskBus bus);
 void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk *disk,
                                             const char *dev);
+
+GVirConfigDomainDiskType gvir_config_domain_disk_get_disk_type(GVirConfigDomainDisk *disk);
+GVirConfigDomainDiskGuestDeviceType gvir_config_domain_disk_get_guest_device_type(GVirConfigDomainDisk *disk);
+GVirConfigDomainDiskSnapshotType gvir_config_domain_disk_get_snapshot_type(GVirConfigDomainDisk *disk);
+char *gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk);
+char *gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk);
+char *gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk);
+GVirConfigDomainDiskBus gvir_config_domain_disk_get_target_bus(GVirConfigDomainDisk *disk);
+char *gvir_config_domain_disk_get_target_dev(GVirConfigDomainDisk *disk);
+
 G_END_DECLS
 
 #endif /* __LIBVIRT_GCONFIG_DOMAIN_DISK_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 7200da5..20dc969 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -61,13 +61,21 @@ LIBVIRT_GCONFIG_0.0.3 {
 	gvir_config_domain_disk_type_get_type;
 	gvir_config_domain_disk_new;
 	gvir_config_domain_disk_new_from_xml;
+	gvir_config_domain_disk_get_driver_name;
 	gvir_config_domain_disk_set_driver_name;
+	gvir_config_domain_disk_get_driver_type;
 	gvir_config_domain_disk_set_driver_type;
+	gvir_config_domain_disk_get_guest_device_type;
 	gvir_config_domain_disk_set_guest_device_type;
+	gvir_config_domain_disk_get_snapshot_type;
 	gvir_config_domain_disk_set_snapshot_type;
+	gvir_config_domain_disk_get_source;
 	gvir_config_domain_disk_set_source;
+	gvir_config_domain_disk_get_target_bus;
 	gvir_config_domain_disk_set_target_bus;
+	gvir_config_domain_disk_get_target_dev;
 	gvir_config_domain_disk_set_target_dev;
+	gvir_config_domain_disk_get_disk_type;
 	gvir_config_domain_disk_set_type;
 
 	gvir_config_domain_filesys_get_type;
-- 
1.7.7.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]