|
Packit |
6a6550 |
/*
|
|
Packit |
6a6550 |
* ovirt-proxy-deprecated.c: Deprecated OvirtProxy methods
|
|
Packit |
6a6550 |
*
|
|
Packit |
6a6550 |
* Copyright (C) 2011, 2013 Red Hat, Inc.
|
|
Packit |
6a6550 |
*
|
|
Packit |
6a6550 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
6a6550 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6a6550 |
* License as published by the Free Software Foundation; either
|
|
Packit |
6a6550 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6a6550 |
*
|
|
Packit |
6a6550 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
6a6550 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6a6550 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6a6550 |
* Lesser General Public License for more details.
|
|
Packit |
6a6550 |
*
|
|
Packit |
6a6550 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6a6550 |
* License along with this library. If not, see
|
|
Packit |
6a6550 |
* <http://www.gnu.org/licenses/>.
|
|
Packit |
6a6550 |
*
|
|
Packit |
6a6550 |
* Author: Christophe Fergeau <cfergeau@redhat.com>
|
|
Packit |
6a6550 |
*/
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
#undef OVIRT_DEBUG
|
|
Packit |
6a6550 |
#include <config.h>
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
#include "govirt.h"
|
|
Packit |
6a6550 |
#include "govirt-private.h"
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
#include <rest/rest-xml-node.h>
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
gboolean ovirt_proxy_fetch_vms(OvirtProxy *proxy, GError **error)
|
|
Packit |
6a6550 |
{
|
|
Packit |
6a6550 |
OvirtCollection *vms;
|
|
Packit |
6a6550 |
OvirtApi *api;
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
api = ovirt_proxy_fetch_api(proxy, error);
|
|
Packit |
6a6550 |
if (api == NULL)
|
|
Packit |
6a6550 |
return FALSE;
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
vms = ovirt_api_get_vms(api);
|
|
Packit |
6a6550 |
if (vms == NULL)
|
|
Packit |
6a6550 |
return FALSE;
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
return ovirt_collection_fetch(vms, proxy, error);
|
|
Packit |
6a6550 |
}
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
typedef struct {
|
|
Packit |
6a6550 |
GCancellable *cancellable;
|
|
Packit |
6a6550 |
GAsyncReadyCallback callback;
|
|
Packit |
6a6550 |
gpointer user_data;
|
|
Packit |
6a6550 |
} ApiAsyncData;
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
static void fetch_api_async_cb(GObject *source_object,
|
|
Packit |
6a6550 |
GAsyncResult *result,
|
|
Packit |
6a6550 |
gpointer user_data)
|
|
Packit |
6a6550 |
{
|
|
Packit |
6a6550 |
ApiAsyncData *data = user_data;
|
|
Packit |
6a6550 |
OvirtProxy *proxy = OVIRT_PROXY(source_object);
|
|
Packit |
6a6550 |
OvirtApi *api;
|
|
Packit |
6a6550 |
GError *error = NULL;
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
api = ovirt_proxy_fetch_api_finish(proxy, result, &error);
|
|
Packit |
6a6550 |
if (api == NULL) {
|
|
Packit Service |
72652d |
g_task_report_new_error(source_object,
|
|
Packit Service |
72652d |
data->callback, data->user_data,
|
|
Packit Service |
72652d |
fetch_api_async_cb,
|
|
Packit Service |
72652d |
OVIRT_ERROR, OVIRT_ERROR_FAILED,
|
|
Packit Service |
72652d |
"Could not fetch API endpoint");
|
|
Packit |
6a6550 |
} else {
|
|
Packit |
6a6550 |
OvirtCollection *vms;
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
vms = ovirt_api_get_vms(api);
|
|
Packit |
6a6550 |
g_return_if_fail(vms != NULL);
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
ovirt_collection_fetch_async(vms, proxy, data->cancellable,
|
|
Packit |
6a6550 |
data->callback, data->user_data);
|
|
Packit |
6a6550 |
}
|
|
Packit |
6a6550 |
g_free(data);
|
|
Packit |
6a6550 |
}
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
/**
|
|
Packit |
6a6550 |
* ovirt_proxy_fetch_vms_async:
|
|
Packit |
6a6550 |
* @proxy: a #OvirtProxy
|
|
Packit |
6a6550 |
* @callback: (scope async): completion callback
|
|
Packit |
6a6550 |
* @user_data: (closure): opaque data for callback
|
|
Packit |
6a6550 |
*/
|
|
Packit |
6a6550 |
void ovirt_proxy_fetch_vms_async(OvirtProxy *proxy,
|
|
Packit |
6a6550 |
GCancellable *cancellable,
|
|
Packit |
6a6550 |
GAsyncReadyCallback callback,
|
|
Packit |
6a6550 |
gpointer user_data)
|
|
Packit |
6a6550 |
{
|
|
Packit |
6a6550 |
OvirtApi *api;
|
|
Packit |
6a6550 |
OvirtCollection *vms;
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
g_return_if_fail(OVIRT_IS_PROXY(proxy));
|
|
Packit |
6a6550 |
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
api = ovirt_proxy_get_api(proxy);
|
|
Packit |
6a6550 |
if (api == NULL) {
|
|
Packit |
6a6550 |
ApiAsyncData *data = g_new0(ApiAsyncData, 1);
|
|
Packit |
6a6550 |
data->cancellable = cancellable;
|
|
Packit |
6a6550 |
data->callback = callback;
|
|
Packit |
6a6550 |
data->user_data = user_data;
|
|
Packit |
6a6550 |
ovirt_proxy_fetch_api_async(proxy, cancellable,
|
|
Packit |
6a6550 |
fetch_api_async_cb, data);
|
|
Packit |
6a6550 |
return;
|
|
Packit |
6a6550 |
}
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
vms = ovirt_api_get_vms(api);
|
|
Packit |
6a6550 |
g_return_if_fail(vms != NULL);
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
return ovirt_collection_fetch_async(vms, proxy, cancellable,
|
|
Packit |
6a6550 |
callback, user_data);
|
|
Packit |
6a6550 |
}
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
/**
|
|
Packit |
6a6550 |
* ovirt_proxy_fetch_vms_finish:
|
|
Packit |
6a6550 |
* @proxy: a #OvirtProxy
|
|
Packit |
6a6550 |
* @result: (transfer none): async method result
|
|
Packit |
6a6550 |
*
|
|
Packit |
6a6550 |
* Return value: (transfer container) (element-type OvirtVm): the list of
|
|
Packit |
6a6550 |
* #OvirtVm associated with #OvirtProxy.
|
|
Packit |
6a6550 |
* The returned list should be freed with g_list_free(), and can become
|
|
Packit |
6a6550 |
* invalid any time a #OvirtProxy call completes.
|
|
Packit |
6a6550 |
*/
|
|
Packit |
6a6550 |
GList *
|
|
Packit |
6a6550 |
ovirt_proxy_fetch_vms_finish(OvirtProxy *proxy,
|
|
Packit |
6a6550 |
GAsyncResult *result,
|
|
Packit |
6a6550 |
GError **err)
|
|
Packit |
6a6550 |
{
|
|
Packit |
6a6550 |
g_return_val_if_fail(OVIRT_IS_PROXY(proxy), NULL);
|
|
Packit |
6a6550 |
|
|
Packit Service |
72652d |
if (g_task_had_error(G_TASK(result)))
|
|
Packit |
6a6550 |
return NULL;
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
return ovirt_proxy_get_vms_internal(proxy);
|
|
Packit |
6a6550 |
}
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
/**
|
|
Packit |
6a6550 |
* ovirt_proxy_lookup_vm:
|
|
Packit |
6a6550 |
* @proxy: a #OvirtProxy
|
|
Packit |
6a6550 |
* @vm_name: name of the virtual machine to lookup
|
|
Packit |
6a6550 |
*
|
|
Packit |
6a6550 |
* Looks up a virtual machine whose name is @name. If it cannot be found,
|
|
Packit |
6a6550 |
* NULL is returned. This method does not initiate any network activity,
|
|
Packit |
6a6550 |
* the remote VM list must have been fetched with ovirt_proxy_fetch_vms()
|
|
Packit |
6a6550 |
* or ovirt_proxy_fetch_vms_async() before calling this function.
|
|
Packit |
6a6550 |
*
|
|
Packit |
6a6550 |
* Return value: (transfer full): a #OvirtVm whose name is @name or NULL
|
|
Packit |
6a6550 |
*/
|
|
Packit |
6a6550 |
OvirtVm *ovirt_proxy_lookup_vm(OvirtProxy *proxy, const char *vm_name)
|
|
Packit |
6a6550 |
{
|
|
Packit |
6a6550 |
OvirtApi *api;
|
|
Packit |
6a6550 |
OvirtCollection *vm_collection;
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
g_return_val_if_fail(OVIRT_IS_PROXY(proxy), NULL);
|
|
Packit |
6a6550 |
g_return_val_if_fail(vm_name != NULL, NULL);
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
api = ovirt_proxy_get_api(proxy);
|
|
Packit |
6a6550 |
if (api == NULL)
|
|
Packit |
6a6550 |
return NULL;
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
vm_collection = ovirt_api_get_vms(api);
|
|
Packit |
6a6550 |
if (vm_collection == NULL)
|
|
Packit |
6a6550 |
return NULL;
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
return OVIRT_VM(ovirt_collection_lookup_resource(vm_collection, vm_name));
|
|
Packit |
6a6550 |
}
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
|
|
Packit |
6a6550 |
/**
|
|
Packit |
6a6550 |
* ovirt_proxy_get_vms:
|
|
Packit |
6a6550 |
*
|
|
Packit |
6a6550 |
* Gets the list of remote VMs from the proxy object.
|
|
Packit |
6a6550 |
* This method does not initiate any network activity, the remote VM list
|
|
Packit |
6a6550 |
* must have been fetched with ovirt_proxy_fetch_vms() or
|
|
Packit |
6a6550 |
* ovirt_proxy_fetch_vms_async() before calling this function.
|
|
Packit |
6a6550 |
*
|
|
Packit |
6a6550 |
* Return value: (transfer container) (element-type OvirtVm): the list of
|
|
Packit |
6a6550 |
* #OvirtVm associated with #OvirtProxy.
|
|
Packit |
6a6550 |
* The returned list should be freed with g_list_free(), and can become
|
|
Packit |
6a6550 |
* invalid any time a #OvirtProxy call completes.
|
|
Packit |
6a6550 |
*/
|
|
Packit |
6a6550 |
GList *ovirt_proxy_get_vms(OvirtProxy *proxy)
|
|
Packit |
6a6550 |
{
|
|
Packit |
6a6550 |
return ovirt_proxy_get_vms_internal(proxy);
|
|
Packit |
6a6550 |
}
|