ch: refactor virCHMonitorSaveVM

Remove the unwanted utility function and make api calls directly from
virCHMonitorSaveVM fn

Signed-off-by: Purna Pavan Chandra <paekkaladevi@linux.microsoft.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Purna Pavan Chandra 2024-08-05 14:40:58 +00:00 committed by Michal Privoznik
parent fd34fbed79
commit 4ae70b7c2d
2 changed files with 10 additions and 21 deletions

View File

@ -927,8 +927,9 @@ virCHMonitorResumeVM(virCHMonitor *mon)
return virCHMonitorPutNoContent(mon, URL_VM_RESUME);
}
static int
virCHMonitorSaveRestoreVM(virCHMonitor *mon, const char *path, bool save)
int
virCHMonitorSaveVM(virCHMonitor *mon,
const char *to)
{
g_autofree char *url = NULL;
int responseCode = 0;
@ -938,22 +939,15 @@ virCHMonitorSaveRestoreVM(virCHMonitor *mon, const char *path, bool save)
struct curl_slist *headers = NULL;
struct curl_data data = {0};
if (save)
url = g_strdup_printf("%s/%s", URL_ROOT, URL_VM_SAVE);
else
url = g_strdup_printf("%s/%s", URL_ROOT, URL_VM_RESTORE);
url = g_strdup_printf("%s/%s", URL_ROOT, URL_VM_SAVE);
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/json");
path_url = g_strdup_printf("file://%s", path);
if (save) {
if (virCHMonitorBuildKeyValueStringJson(&payload, "destination_url", path_url) != 0)
return -1;
} else {
if (virCHMonitorBuildKeyValueStringJson(&payload, "source_url", path_url) != 0)
return -1;
}
path_url = g_strdup_printf("file://%s", to);
if (virCHMonitorBuildKeyValueStringJson(&payload, "destination_url", path_url) != 0)
return -1;
VIR_WITH_OBJECT_LOCK_GUARD(mon) {
/* reset all options of a libcurl session handle at first */
@ -986,12 +980,6 @@ virCHMonitorSaveRestoreVM(virCHMonitor *mon, const char *path, bool save)
return ret;
}
int
virCHMonitorSaveVM(virCHMonitor *mon, const char *to)
{
return virCHMonitorSaveRestoreVM(mon, to, true);
}
int
virCHMonitorBuildRestoreJson(const char *from,
char **jsonstr)

View File

@ -114,7 +114,8 @@ int virCHMonitorShutdownVM(virCHMonitor *mon);
int virCHMonitorRebootVM(virCHMonitor *mon);
int virCHMonitorSuspendVM(virCHMonitor *mon);
int virCHMonitorResumeVM(virCHMonitor *mon);
int virCHMonitorSaveVM(virCHMonitor *mon, const char *to);
int virCHMonitorSaveVM(virCHMonitor *mon,
const char *to);
int virCHMonitorGetInfo(virCHMonitor *mon, virJSONValue **info);
void virCHMonitorCPUInfoFree(virCHMonitorCPUInfo *cpus);