ia64/xen-unstable

changeset 14740:5dcb272de7e4

Expose the method-listing call as host.list_methods.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Apr 04 18:42:20 2007 +0100 (2007-04-04)
parents 4de1e743a5a8
children 556402cdf011
files docs/xen-api/xenapi-datamodel.tex tools/libxen/include/xen_host.h tools/libxen/src/xen_host.c tools/libxen/test/test_bindings.c tools/python/xen/xend/XendAPI.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/docs/xen-api/xenapi-datamodel.tex	Wed Apr 04 15:00:57 2007 +0100
     1.2 +++ b/docs/xen-api/xenapi-datamodel.tex	Wed Apr 04 18:42:20 2007 +0100
     1.3 @@ -4952,6 +4952,27 @@ dmesg string
     1.4  \vspace{0.3cm}
     1.5  \vspace{0.3cm}
     1.6  \vspace{0.3cm}
     1.7 +\subsubsection{RPC name:~list\_methods}
     1.8 +
     1.9 +{\bf Overview:} 
    1.10 +List all supported methods.
    1.11 +
    1.12 + \noindent {\bf Signature:} 
    1.13 +\begin{verbatim} (string Set) list_methods (session_id s)\end{verbatim}
    1.14 +
    1.15 +
    1.16 +\vspace{0.3cm}
    1.17 +
    1.18 + \noindent {\bf Return Type:} 
    1.19 +{\tt 
    1.20 +string Set
    1.21 +}
    1.22 +
    1.23 +
    1.24 +The name of every supported method.
    1.25 +\vspace{0.3cm}
    1.26 +\vspace{0.3cm}
    1.27 +\vspace{0.3cm}
    1.28  \subsubsection{RPC name:~get\_all}
    1.29  
    1.30  {\bf Overview:} 
     2.1 --- a/tools/libxen/include/xen_host.h	Wed Apr 04 15:00:57 2007 +0100
     2.2 +++ b/tools/libxen/include/xen_host.h	Wed Apr 04 18:42:20 2007 +0100
     2.3 @@ -436,6 +436,13 @@ xen_host_dmesg(xen_session *session, cha
     2.4  
     2.5  
     2.6  /**
     2.7 + * List all supported methods.
     2.8 + */
     2.9 +extern bool
    2.10 +xen_host_list_methods(xen_session *session, struct xen_string_set **result);
    2.11 +
    2.12 +
    2.13 +/**
    2.14   * Return a list of all the hosts known to the system.
    2.15   */
    2.16  extern bool
     3.1 --- a/tools/libxen/src/xen_host.c	Wed Apr 04 15:00:57 2007 +0100
     3.2 +++ b/tools/libxen/src/xen_host.c	Wed Apr 04 18:42:20 2007 +0100
     3.3 @@ -740,6 +740,18 @@ xen_host_dmesg(xen_session *session, cha
     3.4  
     3.5  
     3.6  bool
     3.7 +xen_host_list_methods(xen_session *session, struct xen_string_set **result)
     3.8 +{
     3.9 +
    3.10 +    abstract_type result_type = abstract_type_string_set;
    3.11 +
    3.12 +    *result = NULL;
    3.13 +    xen_call_(session, "host.list_methods", NULL, 0, &result_type, result);
    3.14 +    return session->ok;
    3.15 +}
    3.16 +
    3.17 +
    3.18 +bool
    3.19  xen_host_get_all(xen_session *session, struct xen_host_set **result)
    3.20  {
    3.21  
     4.1 --- a/tools/libxen/test/test_bindings.c	Wed Apr 04 15:00:57 2007 +0100
     4.2 +++ b/tools/libxen/test/test_bindings.c	Wed Apr 04 18:42:20 2007 +0100
     4.3 @@ -64,6 +64,7 @@ typedef struct
     4.4  
     4.5  static xen_vm create_new_vm(xen_session *session, bool hvm);
     4.6  static void print_session_info(xen_session *session);
     4.7 +static void print_methods(xen_session *session);
     4.8  static void print_vm_power_state(xen_session *session, xen_vm vm);
     4.9  static void print_vm_metrics(xen_session *session, xen_vm vm);
    4.10  
    4.11 @@ -166,6 +167,14 @@ int main(int argc, char **argv)
    4.12          return 1;
    4.13      }
    4.14  
    4.15 +    print_methods(session);
    4.16 +    if (!session->ok)
    4.17 +    {
    4.18 +        /* Error has been logged, just clean up. */
    4.19 +        CLEANUP;
    4.20 +        return 1;
    4.21 +    }
    4.22 +
    4.23      xen_vm vm;
    4.24      if (!xen_vm_get_by_uuid(session, &vm,
    4.25                              "00000000-0000-0000-0000-000000000000"))
    4.26 @@ -644,6 +653,40 @@ static void print_session_info(xen_sessi
    4.27  }
    4.28  
    4.29  
    4.30 +static int pstrcmp(const void *p1, const void *p2)
    4.31 +{
    4.32 +    return strcmp(*(char **)p1, *(char **)p2);
    4.33 +}
    4.34 +
    4.35 +
    4.36 +/**
    4.37 + * Print the list of supported methods.
    4.38 + */
    4.39 +static void print_methods(xen_session *session)
    4.40 +{
    4.41 +    xen_string_set *methods;
    4.42 +
    4.43 +    if (!xen_host_list_methods(session, &methods))
    4.44 +    {
    4.45 +        print_error(session);
    4.46 +        goto done;
    4.47 +    }
    4.48 +
    4.49 +    printf("%zd.\n", methods->size);
    4.50 +    qsort(methods->contents, methods->size, sizeof(char *), pstrcmp);
    4.51 +
    4.52 +    printf("Supported methods:\n");
    4.53 +    for (size_t i = 0; i < methods->size; i++)
    4.54 +    {
    4.55 +        printf("  %s\n", methods->contents[i]);
    4.56 +    }
    4.57 +    fflush(stdout);
    4.58 +
    4.59 +done:
    4.60 +    xen_string_set_free(methods);
    4.61 +}
    4.62 +
    4.63 +
    4.64  /**
    4.65   * Print the metrics for the given VM.
    4.66   */
     5.1 --- a/tools/python/xen/xend/XendAPI.py	Wed Apr 04 15:00:57 2007 +0100
     5.2 +++ b/tools/python/xen/xend/XendAPI.py	Wed Apr 04 18:42:20 2007 +0100
     5.3 @@ -886,7 +886,8 @@ class XendAPI(object):
     5.4                      ('get_log', 'String'),
     5.5                      ('send_debug_keys', None)]
     5.6      
     5.7 -    host_funcs = [('get_by_name_label', 'Set(host)')]
     5.8 +    host_funcs = [('get_by_name_label', None),
     5.9 +                  ('list_methods', None)]
    5.10  
    5.11      # attributes
    5.12      def host_get_name_label(self, session, host_ref):
    5.13 @@ -1010,6 +1011,12 @@ class XendAPI(object):
    5.14              return xen_api_success((XendNode.instance().uuid,))
    5.15          return xen_api_success([])
    5.16      
    5.17 +    def host_list_methods(self, _):
    5.18 +        def _funcs():
    5.19 +            return [getattr(XendAPI, x) for x in XendAPI.__dict__]
    5.20 +
    5.21 +        return xen_api_success([x.api for x in _funcs()
    5.22 +                                if hasattr(x, 'api')])
    5.23  
    5.24      # Xen API: Class host_CPU
    5.25      # ----------------------------------------------------------------
    5.26 @@ -2611,15 +2618,6 @@ class XendAPI(object):
    5.27          return xen_api_success({'uuid': debug_ref})
    5.28  
    5.29  
    5.30 -    def list_all_methods(self, _):
    5.31 -        def _funcs():
    5.32 -            return [getattr(XendAPI, x) for x in XendAPI.__dict__]
    5.33 -
    5.34 -        return xen_api_success([x.api for x in _funcs()
    5.35 -                                if hasattr(x, 'api')])
    5.36 -    list_all_methods.api = '_UNSUPPORTED_list_all_methods'
    5.37 -
    5.38 -
    5.39  class XendAPIAsyncProxy:
    5.40      """ A redirector for Async.Class.function calls to XendAPI
    5.41      but wraps the call for use with the XendTaskManager.
     6.1 --- a/tools/python/xen/xm/main.py	Wed Apr 04 15:00:57 2007 +0100
     6.2 +++ b/tools/python/xen/xm/main.py	Wed Apr 04 18:42:20 2007 +0100
     6.3 @@ -591,7 +591,7 @@ class Shell(cmd.Cmd):
     6.4          self.prompt = "xm> "
     6.5          if serverType == SERVER_XEN_API:
     6.6              try:
     6.7 -                res = server.xenapi._UNSUPPORTED_list_all_methods()
     6.8 +                res = server.xenapi.host.list_methods()
     6.9                  for f in res:
    6.10                      setattr(Shell, 'do_' + f + ' ', self.default)
    6.11              except: