Blame SOURCES/0014-Introduce-auxiliary-function-ovirt_sub_collection_ne.patch

4dfa2a
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2bd53e
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
2bd53e
Date: Thu, 18 May 2017 16:45:37 -0300
2bd53e
Subject: [PATCH] Introduce auxiliary function
2bd53e
 ovirt_sub_collection_new_from_resource()
2bd53e
2bd53e
This function eliminates duplication of code used to create a
2bd53e
subcollection from a resource. Users are updated accordingly.
2bd53e
2bd53e
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2bd53e
---
4dfa2a
 govirt/ovirt-api.c                | 50 +++++++++++--------------------
2bd53e
 govirt/ovirt-collection-private.h |  5 ++++
4dfa2a
 govirt/ovirt-collection.c         | 15 ++++++++++
4dfa2a
 govirt/ovirt-storage-domain.c     | 18 ++++-------
4dfa2a
 govirt/ovirt-vm.c                 | 18 ++++-------
2bd53e
 5 files changed, 50 insertions(+), 56 deletions(-)
2bd53e
2bd53e
diff --git a/govirt/ovirt-api.c b/govirt/ovirt-api.c
4dfa2a
index 001ee42..37c0935 100644
2bd53e
--- a/govirt/ovirt-api.c
2bd53e
+++ b/govirt/ovirt-api.c
4dfa2a
@@ -123,18 +123,14 @@ OvirtApi *ovirt_api_new(void)
2bd53e
  */
2bd53e
 OvirtCollection *ovirt_api_get_vms(OvirtApi *api)
2bd53e
 {
2bd53e
-    const char *href;
2bd53e
-
2bd53e
     g_return_val_if_fail(OVIRT_IS_API(api), NULL);
2bd53e
 
2bd53e
-    if (api->priv->vms != NULL)
2bd53e
-        return api->priv->vms;
2bd53e
-
2bd53e
-    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(api), "vms");
2bd53e
-    if (href == NULL)
2bd53e
-        return NULL;
2bd53e
-
2bd53e
-    api->priv->vms = ovirt_collection_new(href, "vms", OVIRT_TYPE_VM, "vm");
2bd53e
+    if (api->priv->vms == NULL)
2bd53e
+        api->priv->vms = ovirt_sub_collection_new_from_resource(OVIRT_RESOURCE(api),
2bd53e
+                                                                "vms",
2bd53e
+                                                                "vms",
2bd53e
+                                                                OVIRT_TYPE_VM,
2bd53e
+                                                                "vm");
2bd53e
 
2bd53e
     return api->priv->vms;
2bd53e
 }
4dfa2a
@@ -151,18 +147,14 @@ OvirtCollection *ovirt_api_get_vms(OvirtApi *api)
2bd53e
  */
2bd53e
 OvirtCollection *ovirt_api_get_vm_pools(OvirtApi *api)
2bd53e
 {
2bd53e
-    const char *href;
2bd53e
-
2bd53e
     g_return_val_if_fail(OVIRT_IS_API(api), NULL);
2bd53e
 
2bd53e
-    if (api->priv->vm_pools != NULL)
2bd53e
-        return api->priv->vm_pools;
2bd53e
-
2bd53e
-    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(api), "vmpools");
2bd53e
-    if (href == NULL)
2bd53e
-        return NULL;
2bd53e
-
2bd53e
-    api->priv->vm_pools = ovirt_collection_new(href, "vmpools", OVIRT_TYPE_VM_POOL, "vmpool");
2bd53e
+    if (api->priv->vm_pools == NULL)
2bd53e
+        api->priv->vm_pools = ovirt_sub_collection_new_from_resource(OVIRT_RESOURCE(api),
2bd53e
+                                                                     "vmpools",
2bd53e
+                                                                     "vmpools",
2bd53e
+                                                                     OVIRT_TYPE_VM_POOL,
2bd53e
+                                                                     "vmpool");
2bd53e
 
2bd53e
     return api->priv->vm_pools;
2bd53e
 }
4dfa2a
@@ -180,20 +172,14 @@ OvirtCollection *ovirt_api_get_vm_pools(OvirtApi *api)
2bd53e
  */
2bd53e
 OvirtCollection *ovirt_api_get_storage_domains(OvirtApi *api)
2bd53e
 {
2bd53e
-    const char *href;
2bd53e
-
2bd53e
     g_return_val_if_fail(OVIRT_IS_API(api), NULL);
2bd53e
 
2bd53e
-    if (api->priv->storage_domains != NULL)
2bd53e
-        return api->priv->storage_domains;
2bd53e
-
2bd53e
-    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(api), "storagedomains");
2bd53e
-    if (href == NULL)
2bd53e
-        return NULL;
2bd53e
-
2bd53e
-    api->priv->storage_domains = ovirt_collection_new(href, "storage_domains",
2bd53e
-                                                      OVIRT_TYPE_STORAGE_DOMAIN,
2bd53e
-                                                      "storage_domain");
2bd53e
+    if (api->priv->storage_domains == NULL)
2bd53e
+        api->priv->storage_domains = ovirt_sub_collection_new_from_resource(OVIRT_RESOURCE(api),
2bd53e
+                                                                            "storagedomains",
2bd53e
+                                                                            "storage_domains",
2bd53e
+                                                                            OVIRT_TYPE_STORAGE_DOMAIN,
2bd53e
+                                                                            "storage_domain");
2bd53e
 
2bd53e
     return api->priv->storage_domains;
2bd53e
 }
2bd53e
diff --git a/govirt/ovirt-collection-private.h b/govirt/ovirt-collection-private.h
2bd53e
index 5bc294f..d955fc6 100644
2bd53e
--- a/govirt/ovirt-collection-private.h
2bd53e
+++ b/govirt/ovirt-collection-private.h
2bd53e
@@ -41,6 +41,11 @@ OvirtCollection *ovirt_collection_new_from_xml(RestXmlNode *root_node,
2bd53e
                                                GType resource_type,
2bd53e
                                                const char *resource_name,
2bd53e
                                                GError **error);
2bd53e
+OvirtCollection *ovirt_sub_collection_new_from_resource(OvirtResource *resource,
2bd53e
+                                                        const char *href,
2bd53e
+                                                        const char *collection_name,
2bd53e
+                                                        GType resource_type,
2bd53e
+                                                        const char *resource_name);
2bd53e
 
2bd53e
 G_END_DECLS
2bd53e
 
2bd53e
diff --git a/govirt/ovirt-collection.c b/govirt/ovirt-collection.c
4dfa2a
index a3b0f3f..6ec1c6e 100644
2bd53e
--- a/govirt/ovirt-collection.c
2bd53e
+++ b/govirt/ovirt-collection.c
4dfa2a
@@ -344,6 +344,21 @@ OvirtCollection *ovirt_collection_new_from_xml(RestXmlNode *root_node,
2bd53e
 }
2bd53e
 
2bd53e
 
2bd53e
+OvirtCollection *ovirt_sub_collection_new_from_resource(OvirtResource *resource,
2bd53e
+                                                        const char *href,
2bd53e
+                                                        const char *collection_name,
2bd53e
+                                                        GType resource_type,
2bd53e
+                                                        const char *resource_name)
2bd53e
+{
2bd53e
+    const char *link = ovirt_resource_get_sub_collection(resource, href);
2bd53e
+
2bd53e
+    if (link == NULL)
2bd53e
+        return NULL;
2bd53e
+
2bd53e
+    return ovirt_collection_new(link, collection_name, resource_type, resource_name);
2bd53e
+}
2bd53e
+
2bd53e
+
2bd53e
 /**
2bd53e
  * ovirt_collection_fetch:
2bd53e
  * @collection: a #OvirtCollection
2bd53e
diff --git a/govirt/ovirt-storage-domain.c b/govirt/ovirt-storage-domain.c
2bd53e
index 0582203..38c4a62 100644
2bd53e
--- a/govirt/ovirt-storage-domain.c
2bd53e
+++ b/govirt/ovirt-storage-domain.c
2bd53e
@@ -317,20 +317,14 @@ OvirtStorageDomain *ovirt_storage_domain_new(void)
2bd53e
  */
2bd53e
 OvirtCollection *ovirt_storage_domain_get_files(OvirtStorageDomain *domain)
2bd53e
 {
2bd53e
-    const char *href;
2bd53e
-
2bd53e
     g_return_val_if_fail(OVIRT_IS_STORAGE_DOMAIN(domain), NULL);
2bd53e
 
2bd53e
-    if (domain->priv->files != NULL)
2bd53e
-        return domain->priv->files;
2bd53e
-
2bd53e
-    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(domain), "files");
2bd53e
-    if (href == NULL)
2bd53e
-        return NULL;
2bd53e
-
2bd53e
-    domain->priv->files = ovirt_collection_new(href, "files",
2bd53e
-                                               OVIRT_TYPE_RESOURCE,
2bd53e
-                                               "file");
2bd53e
+    if (domain->priv->files == NULL)
2bd53e
+        domain->priv->files = ovirt_sub_collection_new_from_resource(OVIRT_RESOURCE(domain),
2bd53e
+                                                                     "files",
2bd53e
+                                                                     "files",
2bd53e
+                                                                     OVIRT_TYPE_RESOURCE,
2bd53e
+                                                                     "file");
2bd53e
 
2bd53e
     return domain->priv->files;
2bd53e
 }
2bd53e
diff --git a/govirt/ovirt-vm.c b/govirt/ovirt-vm.c
4dfa2a
index 9a07c2f..3d64649 100644
2bd53e
--- a/govirt/ovirt-vm.c
2bd53e
+++ b/govirt/ovirt-vm.c
4dfa2a
@@ -329,20 +329,14 @@ gboolean ovirt_vm_refresh_finish(OvirtVm *vm,
2bd53e
  */
2bd53e
 OvirtCollection *ovirt_vm_get_cdroms(OvirtVm *vm)
2bd53e
 {
2bd53e
-    const char *href;
2bd53e
-
2bd53e
     g_return_val_if_fail(OVIRT_IS_VM(vm), NULL);
2bd53e
 
2bd53e
-    if (vm->priv->cdroms != NULL)
2bd53e
-        return vm->priv->cdroms;
2bd53e
-
2bd53e
-    href = ovirt_resource_get_sub_collection(OVIRT_RESOURCE(vm), "cdroms");
2bd53e
-    if (href == NULL)
2bd53e
-        return NULL;
2bd53e
-
2bd53e
-    vm->priv->cdroms =  ovirt_collection_new(href, "cdroms",
2bd53e
-                                             OVIRT_TYPE_CDROM,
2bd53e
-                                             "cdrom");
2bd53e
+    if (vm->priv->cdroms == NULL)
2bd53e
+        vm->priv->cdroms = ovirt_sub_collection_new_from_resource(OVIRT_RESOURCE(vm),
2bd53e
+                                                                  "cdroms",
2bd53e
+                                                                  "cdroms",
2bd53e
+                                                                  OVIRT_TYPE_CDROM,
2bd53e
+                                                                  "cdrom");
2bd53e
 
2bd53e
     return vm->priv->cdroms;
2bd53e
 }