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