aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxen
diff options
context:
space:
mode:
authorEwan Mellor <ewan@xensource.com>2007-03-26 00:08:13 +0100
committerEwan Mellor <ewan@xensource.com>2007-03-26 00:08:13 +0100
commit9c052c30d622e56b466870e0084d943508676e3f (patch)
tree49e641759b3a988eead407751fd85f919067256d /tools/libxen
parent231f7bf638ac8c7349000f942065b2bb6eadaa3d (diff)
downloadxen-9c052c30d622e56b466870e0084d943508676e3f.tar.gz
xen-9c052c30d622e56b466870e0084d943508676e3f.tar.bz2
xen-9c052c30d622e56b466870e0084d943508676e3f.zip
Implement session.last_active, session.this_host, session.get_record,
session.get_uuid. Signed-off-by: Ewan Mellor <ewan@xensource.com>
Diffstat (limited to 'tools/libxen')
-rw-r--r--tools/libxen/include/xen_common.h65
-rw-r--r--tools/libxen/src/xen_common.c117
-rw-r--r--tools/libxen/test/test_bindings.c50
3 files changed, 225 insertions, 7 deletions
diff --git a/tools/libxen/include/xen_common.h b/tools/libxen/include/xen_common.h
index 9f157bc5b3..688df1c686 100644
--- a/tools/libxen/include/xen_common.h
+++ b/tools/libxen/include/xen_common.h
@@ -51,6 +51,30 @@ typedef struct
} xen_session;
+typedef struct xen_session_record
+{
+ char *uuid;
+ struct xen_host_record_opt *this_host;
+ char *this_user;
+ time_t last_active;
+} xen_session_record;
+
+
+/**
+ * Allocate a xen_session_record.
+ */
+extern xen_session_record *
+xen_session_record_alloc(void);
+
+
+/**
+ * Free the given xen_session_record, and all referenced values. The
+ * given record must have been allocated by this library.
+ */
+extern void
+xen_session_record_free(xen_session_record *record);
+
+
struct xen_task_;
typedef struct xen_task_ * xen_task_id;
@@ -136,10 +160,45 @@ xen_session_logout(xen_session *session);
/**
- * Set *result to be a handle to the host to which this session is connected.
+ * Get the UUID of the second given session. Set *result to point at a
+ * string, yours to free.
+ */
+extern bool
+xen_session_get_uuid(xen_session *session, char **result,
+ xen_session *self_session);
+
+
+/**
+ * Get the this_host field of the second given session. Set *result to be a
+ * handle to that host.
+ */
+extern bool
+xen_session_get_this_host(xen_session *session, xen_host *result,
+ xen_session *self_session);
+
+
+/**
+ * Get the this_user field of the second given session. Set *result to point
+ * at a string, yours to free.
+ */
+extern bool
+xen_session_get_this_user(xen_session *session, char **result,
+ xen_session *self_session);
+
+
+/**
+ * Get the last_active field of the given session, and place it in *result.
+ */
+extern bool
+xen_session_get_last_active(xen_session *session, time_t *result,
+ xen_session *self_session);
+
+/**
+ * Get a record containing the current state of the second given session.
*/
-extern int
-xen_session_get_this_host(xen_session *session, xen_host *result);
+extern bool
+xen_session_get_record(xen_session *session, xen_session_record **result,
+ xen_session *self_session);
#endif
diff --git a/tools/libxen/src/xen_common.c b/tools/libxen/src/xen_common.c
index a22456c85e..b9cd200048 100644
--- a/tools/libxen/src/xen_common.c
+++ b/tools/libxen/src/xen_common.c
@@ -32,6 +32,7 @@
#include <libxml/xpath.h>
#include "xen_common.h"
+#include "xen_host.h"
#include "xen_internal.h"
#include "xen_int_float_map.h"
#include "xen_string_string_map.h"
@@ -138,6 +139,20 @@ xen_fini(void)
}
+void
+xen_session_record_free(xen_session_record *record)
+{
+ if (record == NULL)
+ {
+ return;
+ }
+ free(record->uuid);
+ xen_host_record_opt_free(record->this_host);
+ free(record->this_user);
+ free(record);
+}
+
+
xen_session *
xen_session_login_with_password(xen_call_func call_func, void *handle,
const char *uname, const char *pwd)
@@ -187,19 +202,115 @@ xen_session_logout(xen_session *session)
}
-int
-xen_session_get_this_host(xen_session *session, xen_host *result)
+bool
+xen_session_get_uuid(xen_session *session, char **result,
+ xen_session *self_session)
+{
+ abstract_value params[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = self_session->session_id }
+ };
+
+ xen_call_(session, "session.get_uuid", params, 1,
+ &abstract_type_string, result);
+ return session->ok;
+}
+
+
+bool
+xen_session_get_this_host(xen_session *session, xen_host *result,
+ xen_session *self_session)
+{
+ abstract_value params[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = self_session->session_id }
+ };
+
+ xen_call_(session, "session.get_this_host", params, 1,
+ &abstract_type_string, result);
+ return session->ok;
+}
+
+
+bool
+xen_session_get_this_user(xen_session *session, char **result,
+ xen_session *self_session)
{
abstract_value params[] =
{
+ { .type = &abstract_type_string,
+ .u.string_val = self_session->session_id }
};
- xen_call_(session, "session.get_this_host", params, 0,
+ xen_call_(session, "session.get_this_user", params, 1,
&abstract_type_string, result);
return session->ok;
}
+bool
+xen_session_get_last_active(xen_session *session, time_t *result,
+ xen_session *self_session)
+{
+ abstract_value params[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = self_session->session_id }
+ };
+
+ xen_call_(session, "session.get_last_active", params, 1,
+ &abstract_type_datetime, result);
+ return session->ok;
+}
+
+
+static const struct_member xen_session_record_struct_members[] =
+ {
+ { .key = "uuid",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_session_record, uuid) },
+ { .key = "this_host",
+ .type = &abstract_type_ref,
+ .offset = offsetof(xen_session_record, this_host) },
+ { .key = "this_user",
+ .type = &abstract_type_string,
+ .offset = offsetof(xen_session_record, this_user) },
+ { .key = "last_active",
+ .type = &abstract_type_datetime,
+ .offset = offsetof(xen_session_record, last_active) },
+ };
+
+const abstract_type xen_session_record_abstract_type_ =
+ {
+ .typename = STRUCT,
+ .struct_size = sizeof(xen_session_record),
+ .member_count =
+ sizeof(xen_session_record_struct_members) / sizeof(struct_member),
+ .members = xen_session_record_struct_members
+ };
+
+
+bool
+xen_session_get_record(xen_session *session, xen_session_record **result,
+ xen_session *self_session)
+{
+ abstract_value param_values[] =
+ {
+ { .type = &abstract_type_string,
+ .u.string_val = self_session->session_id }
+ };
+
+ abstract_type result_type = xen_session_record_abstract_type_;
+
+ *result = NULL;
+ XEN_CALL_("session.get_record");
+
+ return session->ok;
+}
+
+
#define X "%02x"
#define UUID_FORMAT X X X X "-" X X "-" X X "-" X X "-" X X X X X X
diff --git a/tools/libxen/test/test_bindings.c b/tools/libxen/test/test_bindings.c
index 922518fe8a..bc4d875160 100644
--- a/tools/libxen/test/test_bindings.c
+++ b/tools/libxen/test/test_bindings.c
@@ -17,6 +17,7 @@
*/
#define _GNU_SOURCE
+#include <assert.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
@@ -61,6 +62,7 @@ typedef struct
static xen_vm create_new_vm(xen_session *session, bool hvm);
+static void print_session_info(xen_session *session);
static void print_vm_power_state(xen_session *session, xen_vm vm);
static void print_vm_metrics(xen_session *session, xen_vm vm);
@@ -144,6 +146,14 @@ int main(int argc, char **argv)
xen_session *session =
xen_session_login_with_password(call_func, NULL, username, password);
+ print_session_info(session);
+ if (!session->ok)
+ {
+ /* Error has been logged, just clean up. */
+ CLEANUP;
+ return 1;
+ }
+
xen_vm vm;
if (!xen_vm_get_by_uuid(session, &vm,
"00000000-0000-0000-0000-000000000000"))
@@ -184,7 +194,7 @@ int main(int argc, char **argv)
}
xen_host host;
- if (!xen_session_get_this_host(session, &host))
+ if (!xen_session_get_this_host(session, &host, session))
{
print_error(session);
xen_vm_record_free(vm_record);
@@ -583,6 +593,44 @@ static size_t my_strftime(char *s, size_t max, const char *fmt,
/**
+ * Print some session details.
+ */
+static void print_session_info(xen_session *session)
+{
+ xen_session_record *record;
+ if (!xen_session_get_record(session, &record, session))
+ {
+ print_error(session);
+ return;
+ }
+
+ printf("Session UUID: %s.\n", record->uuid);
+ printf("Session user: %s.\n", record->this_user);
+ char time[256];
+ struct tm *tm = localtime(&record->last_active);
+ my_strftime(time, 256, "Session last active: %c, local time.\n", tm);
+ printf(time);
+
+ char *uuid = NULL;
+ char *this_user = NULL;
+ xen_session_get_uuid(session, &uuid, session);
+ xen_session_get_this_user(session, &this_user, session);
+
+ if (!session->ok)
+ {
+ xen_session_record_free(record);
+ print_error(session);
+ return;
+ }
+
+ assert(!strcmp(record->uuid, uuid));
+ assert(!strcmp(record->this_user, this_user));
+
+ xen_session_record_free(record);
+}
+
+
+/**
* Print the metrics for the given VM.
*/
static void print_vm_metrics(xen_session *session, xen_vm vm)