|
|
546e1e |
From 53fb63d610503679bd3f4e2780989076544ddb14 Mon Sep 17 00:00:00 2001
|
|
|
546e1e |
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
|
|
|
546e1e |
Date: Thu, 4 May 2017 15:54:02 -0300
|
|
|
546e1e |
Subject: [PATCH] cdrom: Set file property using OvirtXmlElement struct
|
|
|
546e1e |
|
|
|
546e1e |
This was the last place left to move to the new automatic parsing
|
|
|
546e1e |
scheme.
|
|
|
546e1e |
|
|
|
546e1e |
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
|
|
|
546e1e |
---
|
|
|
546e1e |
govirt/ovirt-cdrom.c | 57 +++++++++++++++++---------------------------
|
|
|
546e1e |
1 file changed, 22 insertions(+), 35 deletions(-)
|
|
|
546e1e |
|
|
|
546e1e |
diff --git a/govirt/ovirt-cdrom.c b/govirt/ovirt-cdrom.c
|
|
|
546e1e |
index d852403..5bab7d3 100644
|
|
|
546e1e |
--- a/govirt/ovirt-cdrom.c
|
|
|
546e1e |
+++ b/govirt/ovirt-cdrom.c
|
|
|
546e1e |
@@ -28,6 +28,7 @@
|
|
|
546e1e |
#include "ovirt-proxy-private.h"
|
|
|
546e1e |
#include "ovirt-resource-private.h"
|
|
|
546e1e |
#include "ovirt-resource-rest-call.h"
|
|
|
546e1e |
+#include "ovirt-utils.h"
|
|
|
546e1e |
|
|
|
546e1e |
#define OVIRT_CDROM_GET_PRIVATE(obj) \
|
|
|
546e1e |
(G_TYPE_INSTANCE_GET_PRIVATE((obj), OVIRT_TYPE_CDROM, OvirtCdromPrivate))
|
|
|
546e1e |
@@ -95,25 +96,29 @@ static void ovirt_cdrom_finalize(GObject *object)
|
|
|
546e1e |
}
|
|
|
546e1e |
|
|
|
546e1e |
|
|
|
546e1e |
-static gboolean ovirt_cdrom_refresh_from_xml(OvirtCdrom *cdrom,
|
|
|
546e1e |
- RestXmlNode *node)
|
|
|
546e1e |
+static gboolean ovirt_cdrom_init_from_xml(OvirtResource *resource,
|
|
|
546e1e |
+ RestXmlNode *node,
|
|
|
546e1e |
+ GError **error)
|
|
|
546e1e |
{
|
|
|
546e1e |
- RestXmlNode *file_node;
|
|
|
546e1e |
- const char *file;
|
|
|
546e1e |
- const char *file_key = g_intern_string("file");
|
|
|
546e1e |
+ gboolean ret = FALSE;
|
|
|
546e1e |
char *name;
|
|
|
546e1e |
+ OvirtResourceClass *parent_class;
|
|
|
546e1e |
+ OvirtXmlElement cdrom_elements[] = {
|
|
|
546e1e |
+ { .prop_name = "file",
|
|
|
546e1e |
+ .xml_path = "file",
|
|
|
546e1e |
+ .xml_attr = "id",
|
|
|
546e1e |
+ },
|
|
|
546e1e |
+ { NULL , },
|
|
|
546e1e |
+ };
|
|
|
546e1e |
|
|
|
546e1e |
- file_node = g_hash_table_lookup(node->children, file_key);
|
|
|
546e1e |
- if (file_node != NULL) {
|
|
|
546e1e |
- file = rest_xml_node_get_attr(file_node, "id");
|
|
|
546e1e |
- if (g_strcmp0(file, cdrom->priv->file) != 0) {
|
|
|
546e1e |
- g_free(cdrom->priv->file);
|
|
|
546e1e |
- cdrom->priv->file = g_strdup(file);
|
|
|
546e1e |
- g_object_notify(G_OBJECT(cdrom), "file");
|
|
|
546e1e |
- }
|
|
|
546e1e |
- }
|
|
|
546e1e |
+ parent_class = OVIRT_RESOURCE_CLASS(ovirt_cdrom_parent_class);
|
|
|
546e1e |
+
|
|
|
546e1e |
+ if (!parent_class->init_from_xml(resource, node, error))
|
|
|
546e1e |
+ return FALSE;
|
|
|
546e1e |
|
|
|
546e1e |
- g_object_get(G_OBJECT(cdrom), "name", &name, NULL);
|
|
|
546e1e |
+ ovirt_rest_xml_node_parse(node, G_OBJECT(resource), cdrom_elements);
|
|
|
546e1e |
+
|
|
|
546e1e |
+ g_object_get(G_OBJECT(resource), "name", &name, NULL);
|
|
|
546e1e |
if (name == NULL) {
|
|
|
546e1e |
/* Build up fake name as ovirt_collection_refresh_from_xml()
|
|
|
546e1e |
* expects it to be set (it uses it as a hash table key), but
|
|
|
546e1e |
@@ -122,32 +127,14 @@ static gboolean ovirt_cdrom_refresh_from_xml(OvirtCdrom *cdrom,
|
|
|
546e1e |
* enough for now
|
|
|
546e1e |
*/
|
|
|
546e1e |
g_debug("Setting fake 'name' for cdrom resource");
|
|
|
546e1e |
- g_object_set(G_OBJECT(cdrom), "name", "cdrom0", NULL);
|
|
|
546e1e |
- } else {
|
|
|
546e1e |
- g_free(name);
|
|
|
546e1e |
+ g_object_set(G_OBJECT(resource), "name", "cdrom0", NULL);
|
|
|
546e1e |
}
|
|
|
546e1e |
|
|
|
546e1e |
+ g_free(name);
|
|
|
546e1e |
return TRUE;
|
|
|
546e1e |
}
|
|
|
546e1e |
|
|
|
546e1e |
|
|
|
546e1e |
-static gboolean ovirt_cdrom_init_from_xml(OvirtResource *resource,
|
|
|
546e1e |
- RestXmlNode *node,
|
|
|
546e1e |
- GError **error)
|
|
|
546e1e |
-{
|
|
|
546e1e |
- gboolean parsed_ok;
|
|
|
546e1e |
- OvirtResourceClass *parent_class;
|
|
|
546e1e |
-
|
|
|
546e1e |
- parsed_ok = ovirt_cdrom_refresh_from_xml(OVIRT_CDROM(resource), node);
|
|
|
546e1e |
- if (!parsed_ok) {
|
|
|
546e1e |
- return FALSE;
|
|
|
546e1e |
- }
|
|
|
546e1e |
- parent_class = OVIRT_RESOURCE_CLASS(ovirt_cdrom_parent_class);
|
|
|
546e1e |
-
|
|
|
546e1e |
- return parent_class->init_from_xml(resource, node, error);
|
|
|
546e1e |
-}
|
|
|
546e1e |
-
|
|
|
546e1e |
-
|
|
|
546e1e |
static char *ovirt_cdrom_to_xml(OvirtResource *resource)
|
|
|
546e1e |
{
|
|
|
546e1e |
OvirtCdrom *cdrom;
|
|
|
546e1e |
--
|
|
|
546e1e |
2.20.1
|
|
|
546e1e |
|