[libgovirt] Implement ovirt_resource_update()



commit 85b7af8930ca1da7e1b2b36aabceeb60c22cb6e0
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Thu Aug 29 20:59:55 2013 +0200

    Implement ovirt_resource_update()
    
    For resources that can be serialized to XML, this sync call will
    try to update the corresponding resource on the oVirt instance.

 govirt/govirt.sym               |    2 +
 govirt/ovirt-resource-private.h |    3 ++
 govirt/ovirt-resource.c         |   64 +++++++++++++++++++++++++++++++++++++++
 govirt/ovirt-resource.h         |    4 ++
 4 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/govirt/govirt.sym b/govirt/govirt.sym
index b48e531..9b1867e 100644
--- a/govirt/govirt.sym
+++ b/govirt/govirt.sym
@@ -66,6 +66,8 @@ GOVIRT_0.2.1 {
         ovirt_proxy_fetch_api_async;
         ovirt_proxy_fetch_api_finish;
 
+        ovirt_resource_update;
+
         ovirt_storage_domain_get_type;
         ovirt_storage_domain_state_get_type;
         ovirt_storage_domain_format_version_get_type;
diff --git a/govirt/ovirt-resource-private.h b/govirt/ovirt-resource-private.h
index 28bd251..4485589 100644
--- a/govirt/ovirt-resource-private.h
+++ b/govirt/ovirt-resource-private.h
@@ -29,6 +29,9 @@ G_BEGIN_DECLS
 const char *ovirt_resource_get_action(OvirtResource *resource,
                                       const char *action);
 char *ovirt_resource_to_xml(OvirtResource *resource);
+gboolean ovirt_resource_rest_call(OvirtResource *resource, OvirtProxy *proxy,
+                                  const char *method, const char *href,
+                                  GError **error);
 
 G_END_DECLS
 
diff --git a/govirt/ovirt-resource.c b/govirt/ovirt-resource.c
index c127a7c..9234506 100644
--- a/govirt/ovirt-resource.c
+++ b/govirt/ovirt-resource.c
@@ -470,3 +470,67 @@ char *ovirt_resource_to_xml(OvirtResource *resource)
 
     return klass->to_xml(resource);
 }
+
+
+G_GNUC_INTERNAL gboolean ovirt_resource_rest_call(OvirtResource *resource,
+                                                  OvirtProxy *proxy,
+                                                  const char *method,
+                                                  const char *href,
+                                                  GError **error)
+{
+    RestProxyCall *call;
+    const char *function;
+
+    g_return_val_if_fail(href != NULL, FALSE);
+
+    function = ovirt_utils_strip_api_base_dir(href);
+
+    call = REST_PROXY_CALL(ovirt_resource_rest_call_new(REST_PROXY(proxy), resource));
+    rest_proxy_call_set_method(call, method);
+    rest_proxy_call_set_function(call, function);
+    rest_proxy_call_add_param(call, "async", "false");
+
+    if (!rest_proxy_call_sync(call, error)) {
+        RestXmlNode *root;
+        GError *local_error = NULL;
+
+        root = ovirt_rest_xml_node_from_call(call);
+        ovirt_utils_gerror_from_xml_fault(root, &local_error);
+        if (local_error != NULL) {
+            g_clear_error(error);
+            g_propagate_error(error, local_error);
+        }
+        g_warning("Error while updating %p (%s)", resource, function);
+        g_warning("message: %s", (*error)->message);
+        g_object_unref(G_OBJECT(call));
+
+        return FALSE;
+    }
+
+    g_object_unref(G_OBJECT(call));
+
+    return TRUE;
+}
+
+
+gboolean ovirt_resource_update(OvirtResource *resource,
+                               OvirtProxy *proxy,
+                               GError **error)
+{
+    char *href;
+    gboolean call_successful;
+
+    g_return_val_if_fail(OVIRT_IS_RESOURCE(resource), FALSE);
+    g_return_val_if_fail(OVIRT_IS_PROXY(proxy), FALSE);
+    g_return_val_if_fail((error == NULL) || (*error == NULL), FALSE);
+
+
+    g_object_get(G_OBJECT(resource), "href", &href, NULL);
+    g_return_val_if_fail(href != NULL, FALSE);
+    call_successful = ovirt_resource_rest_call(resource, proxy,
+                                               "PUT", href,
+                                               error);
+    g_free(href);
+
+    return call_successful;
+}
diff --git a/govirt/ovirt-resource.h b/govirt/ovirt-resource.h
index d48d8a9..20795fe 100644
--- a/govirt/ovirt-resource.h
+++ b/govirt/ovirt-resource.h
@@ -66,6 +66,10 @@ GType ovirt_resource_get_type(void);
 const char *ovirt_resource_get_sub_collection(OvirtResource *resource,
                                               const char *sub_collection);
 
+gboolean ovirt_resource_update(OvirtResource *resource,
+                               OvirtProxy *proxy,
+                               GError **error);
+
 G_END_DECLS
 
 #endif /* __OVIRT_RESOURCE_H__ */


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