WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Implement session.last_active, session.th

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Implement session.last_active, session.this_host, session.get_record,
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Sun, 25 Mar 2007 22:00:34 -0700
Delivery-date: Sun, 25 Mar 2007 22:00:16 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Date 1174864093 -3600
# Node ID af07c7b01893c2916060f8f48716de7072a3432f
# Parent  e3e7c59cdba11b600466f4af225b912cbd4cf790
Implement session.last_active, session.this_host, session.get_record,
session.get_uuid.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/libxen/include/xen_common.h |   67 ++++++++++++++++++++-
 tools/libxen/src/xen_common.c     |  117 +++++++++++++++++++++++++++++++++++++-
 tools/libxen/test/test_bindings.c |   50 +++++++++++++++-
 tools/python/xen/xend/XendAPI.py  |   47 ++++++++++-----
 4 files changed, 258 insertions(+), 23 deletions(-)

diff -r e3e7c59cdba1 -r af07c7b01893 tools/libxen/include/xen_common.h
--- a/tools/libxen/include/xen_common.h Sun Mar 25 22:17:30 2007 +0100
+++ b/tools/libxen/include/xen_common.h Mon Mar 26 00:08:13 2007 +0100
@@ -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.
- */
-extern int
-xen_session_get_this_host(xen_session *session, xen_host *result);
+ * 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 bool
+xen_session_get_record(xen_session *session, xen_session_record **result,
+                       xen_session *self_session);
 
 
 #endif
diff -r e3e7c59cdba1 -r af07c7b01893 tools/libxen/src/xen_common.c
--- a/tools/libxen/src/xen_common.c     Sun Mar 25 22:17:30 2007 +0100
+++ b/tools/libxen/src/xen_common.c     Mon Mar 26 00:08:13 2007 +0100
@@ -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,15 +202,111 @@ 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_this_host", params, 0,
+    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_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;
 }
 
diff -r e3e7c59cdba1 -r af07c7b01893 tools/libxen/test/test_bindings.c
--- a/tools/libxen/test/test_bindings.c Sun Mar 25 22:17:30 2007 +0100
+++ b/tools/libxen/test/test_bindings.c Mon Mar 26 00:08:13 2007 +0100
@@ -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_
 
 
 /**
+ * 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)
diff -r e3e7c59cdba1 -r af07c7b01893 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Sun Mar 25 22:17:30 2007 +0100
+++ b/tools/python/xen/xend/XendAPI.py  Mon Mar 26 00:08:13 2007 +0100
@@ -523,8 +523,11 @@ class XendAPI(object):
     # ----------------------------------------------------------------
     # NOTE: Left unwrapped by __init__
 
-    session_attr_ro = ['this_host', 'this_user']
+    session_attr_ro = ['this_host', 'this_user', 'last_active']
     session_methods = [('logout', None)]
+
+    def session_get_all(self, session):
+        return xen_api_success([session])
 
     def session_login_with_password(self, *args):
         if len(args) != 2:
@@ -534,8 +537,8 @@ class XendAPI(object):
         username = args[0]
         password = args[1]
         try:
-            session = (self.auth == AUTH_NONE and
-                       auth_manager().login_unconditionally(username) or
+            session = ((self.auth == AUTH_NONE and
+                        auth_manager().login_unconditionally(username)) or
                        auth_manager().login_with_password(username, password))
             return xen_api_success(session)
         except XendError, e:
@@ -546,26 +549,40 @@ class XendAPI(object):
     def session_logout(self, session):
         auth_manager().logout(session)
         return xen_api_success_void()
-    def session_get_record(self, session):
-        record = {'uuid'     : session,
-                  'this_host': XendNode.instance().uuid,
-                  'this_user': auth_manager().get_user(session)}
+
+    def session_get_record(self, session, self_session):
+        if self_session != session:
+            return xen_api_error(['PERMISSION_DENIED'])
+        record = {'uuid'       : session,
+                  'this_host'  : XendNode.instance().uuid,
+                  'this_user'  : auth_manager().get_user(session),
+                  'last_active': now()}
         return xen_api_success(record)
 
-    def session_get_uuid(self, session):
-        return xen_api_success(session)
-
-    def session_get_by_uuid(self, session):
-        return xen_api_success(session)
+    def session_get_uuid(self, session, self_session):
+        return xen_api_success(self_session)
+
+    def session_get_by_uuid(self, session, self_session):
+        return xen_api_success(self_session)
 
     # attributes (ro)
-    def session_get_this_host(self, session):
+    def session_get_this_host(self, session, self_session):
+        if self_session != session:
+            return xen_api_error(['PERMISSION_DENIED'])
         return xen_api_success(XendNode.instance().uuid)
-    def session_get_this_user(self, session):
+
+    def session_get_this_user(self, session, self_session):
+        if self_session != session:
+            return xen_api_error(['PERMISSION_DENIED'])
         user = auth_manager().get_user(session)
-        if user:
+        if user is not None:
             return xen_api_success(user)
         return xen_api_error(['SESSION_INVALID', session])
+
+    def session_get_last_active(self, session, self_session):
+        if self_session != session:
+            return xen_api_error(['PERMISSION_DENIED'])
+        return xen_api_success(now())
 
 
     # Xen API: Class User

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Implement session.last_active, session.this_host, session.get_record,, Xen patchbot-unstable <=