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] Added host_metrics class.

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Added host_metrics class.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 31 Jan 2007 07:05:18 -0800
Delivery-date: Wed, 31 Jan 2007 07:07:49 -0800
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 1170164806 0
# Node ID 4637dfae085676891e8abb48deedc95fcff85467
# Parent  69c5afd5ab08446f11ede88574a8a8f06ac5b4cb
Added host_metrics class.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 docs/xen-api/xenapi-datamodel.tex            |  257 +++++++++++++++++++++++++++
 tools/libxen/include/xen_host.h              |    9 
 tools/libxen/include/xen_host_metrics.h      |  193 ++++++++++++++++++++
 tools/libxen/include/xen_host_metrics_decl.h |   30 +++
 tools/libxen/src/xen_host.c                  |   24 ++
 tools/libxen/src/xen_host_metrics.c          |  172 ++++++++++++++++++
 tools/python/xen/xend/XendAPI.py             |   93 +++++++--
 tools/python/xen/xend/XendNode.py            |   11 -
 tools/python/xen/xm/messages/en/xen-xm.po    |    5 
 9 files changed, 770 insertions(+), 24 deletions(-)

diff -r 69c5afd5ab08 -r 4637dfae0856 docs/xen-api/xenapi-datamodel.tex
--- a/docs/xen-api/xenapi-datamodel.tex Tue Jan 30 12:43:40 2007 +0000
+++ b/docs/xen-api/xenapi-datamodel.tex Tue Jan 30 13:46:46 2007 +0000
@@ -26,6 +26,7 @@ Name & Description \\
 {\tt task} & A long-running asynchronous task \\
 {\tt VM} & A virtual machine (or 'guest') \\
 {\tt host} & A physical host \\
+{\tt host\_metrics} & The metrics associated with a host \\
 {\tt host\_cpu} & A physical CPU \\
 {\tt network} & A virtual network \\
 {\tt VIF} & A virtual network interface \\
@@ -57,6 +58,7 @@ crashdump.VM & VM.crash\_dumps & one-to-
 crashdump.VM & VM.crash\_dumps & one-to-many\\
 VIF.VM & VM.VIFs & one-to-many\\
 VIF.network & network.VIFs & one-to-many\\
+host.metrics & host\_metrics.host & one-to-one\\
 PIF.metrics & PIF\_metrics.PIF & one-to-one\\
 PIF.host & host.PIFs & one-to-many\\
 PIF.network & network.PIFs & one-to-many\\
@@ -3835,6 +3837,7 @@ Quals & Field & Type & Description \\
 $\mathit{RW}$ &  {\tt crash\_dump\_sr} & SR ref & The SR in which VDIs for 
crash dumps are created \\
 $\mathit{RO}_\mathit{run}$ &  {\tt PBDs} & (PBD ref) Set & physical 
blockdevices \\
 $\mathit{RO}_\mathit{run}$ &  {\tt host\_CPUs} & (host\_cpu ref) Set & The 
physical CPUs on this host \\
+$\mathit{RO}_\mathit{ins}$ &  {\tt metrics} & host\_metrics ref & metrics 
associated with this host. \\
 \hline
 \end{longtable}
 \subsection{Additional RPCs associated with class: host}
@@ -4720,6 +4723,38 @@ value of the field
 \vspace{0.3cm}
 \vspace{0.3cm}
 \vspace{0.3cm}
+\subsubsection{RPC name:~get\_metrics}
+
+{\bf Overview:} 
+Get the metrics field of the given host.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} (host_metrics ref) get_metrics (session_id s, host ref 
self)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt host ref } & self & reference to the object \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+host\_metrics ref
+}
+
+
+value of the field
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
 \subsubsection{RPC name:~create}
 
 {\bf Overview:} 
@@ -4877,6 +4912,218 @@ Get all the host instances with the give
 
 
 references to objects with match names
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+
+\vspace{1cm}
+\newpage
+\section{Class: host\_metrics}
+\subsection{Fields for class: host\_metrics}
+\begin{longtable}{|lllp{0.38\textwidth}|}
+\hline
+\multicolumn{1}{|l}{Name} & \multicolumn{3}{l|}{\bf host\_metrics} \\
+\multicolumn{1}{|l}{Description} & \multicolumn{3}{l|}{\parbox{11cm}{\em
+The metrics associated with a host.}} \\
+\hline
+Quals & Field & Type & Description \\
+\hline
+$\mathit{RO}_\mathit{run}$ &  {\tt uuid} & string & unique identifier/object 
reference \\
+$\mathit{RO}_\mathit{ins}$ &  {\tt host} & host ref & Host to which these 
metrics apply \\
+$\mathit{RO}_\mathit{run}$ &  {\tt memory/total} & int & Host's total memory 
(bytes) \\
+$\mathit{RO}_\mathit{run}$ &  {\tt memory/free} & int & Host's free memory 
(bytes) \\
+\hline
+\end{longtable}
+\subsection{Additional RPCs associated with class: host\_metrics}
+\subsubsection{RPC name:~get\_uuid}
+
+{\bf Overview:} 
+Get the uuid field of the given host\_metrics.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} string get_uuid (session_id s, host_metrics ref 
self)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt host\_metrics ref } & self & reference to the object \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+string
+}
+
+
+value of the field
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~get\_host}
+
+{\bf Overview:} 
+Get the host field of the given host\_metrics.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} (host ref) get_host (session_id s, host_metrics ref 
self)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt host\_metrics ref } & self & reference to the object \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+host ref
+}
+
+
+value of the field
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~get\_memory\_total}
+
+{\bf Overview:} 
+Get the memory/total field of the given host\_metrics.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} int get_memory_total (session_id s, host_metrics ref 
self)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt host\_metrics ref } & self & reference to the object \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+int
+}
+
+
+value of the field
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~get\_memory\_free}
+
+{\bf Overview:} 
+Get the memory/free field of the given host\_metrics.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} int get_memory_free (session_id s, host_metrics ref 
self)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt host\_metrics ref } & self & reference to the object \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+int
+}
+
+
+value of the field
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~get\_by\_uuid}
+
+{\bf Overview:} 
+Get a reference to the host\_metrics instance with the specified UUID.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} (host_metrics ref) get_by_uuid (session_id s, string 
uuid)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt string } & uuid & UUID of object to return \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+host\_metrics ref
+}
+
+
+reference to the object
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
+\subsubsection{RPC name:~get\_record}
+
+{\bf Overview:} 
+Get a record containing the current state of the given host\_metrics.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} (host_metrics record) get_record (session_id s, host_metrics 
ref self)\end{verbatim}
+
+
+\noindent{\bf Arguments:}
+
+ 
+\vspace{0.3cm}
+\begin{tabular}{|c|c|p{7cm}|}
+ \hline
+{\bf type} & {\bf name} & {\bf description} \\ \hline
+{\tt host\_metrics ref } & self & reference to the object \\ \hline 
+
+\end{tabular}
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+host\_metrics record
+}
+
+
+all fields from the object
 \vspace{0.3cm}
 \vspace{0.3cm}
 \vspace{0.3cm}
@@ -10849,6 +11096,16 @@ The handle parameter echoes the bad valu
 \begin{verbatim}HOST_HANDLE_INVALID(handle)\end{verbatim}
 \begin{center}\rule{10em}{0.1pt}\end{center}
 
+\subsubsection{HOST\_METRICS\_HANDLE\_INVALID}
+
+You gave an invalid host\_metrics handle.  The host\_metrics may have
+recently been deleted.  The handle parameter echoes the bad value given.
+
+\vspace{0.3cm}
+{\bf Signature:}
+\begin{verbatim}HOST_METRICS_HANDLE_INVALID(handle)\end{verbatim}
+\begin{center}\rule{10em}{0.1pt}\end{center}
+
 \subsubsection{INTERNAL\_ERROR}
 
 The server failed to handle your request, due to an internal error.  The
diff -r 69c5afd5ab08 -r 4637dfae0856 tools/libxen/include/xen_host.h
--- a/tools/libxen/include/xen_host.h   Tue Jan 30 12:43:40 2007 +0000
+++ b/tools/libxen/include/xen_host.h   Tue Jan 30 13:46:46 2007 +0000
@@ -22,6 +22,7 @@
 #include "xen_common.h"
 #include "xen_host_cpu_decl.h"
 #include "xen_host_decl.h"
+#include "xen_host_metrics_decl.h"
 #include "xen_pbd_decl.h"
 #include "xen_pif_decl.h"
 #include "xen_sr_decl.h"
@@ -79,6 +80,7 @@ typedef struct xen_host_record
     struct xen_sr_record_opt *crash_dump_sr;
     struct xen_pbd_record_opt_set *pbds;
     struct xen_host_cpu_record_opt_set *host_cpus;
+    struct xen_host_metrics_record_opt *metrics;
 } xen_host_record;
 
 /**
@@ -280,6 +282,13 @@ xen_host_get_host_cpus(xen_session *sess
 
 
 /**
+ * Get the metrics field of the given host.
+ */
+extern bool
+xen_host_get_metrics(xen_session *session, xen_host_metrics *result, xen_host 
host);
+
+
+/**
  * Set the name/label field of the given host.
  */
 extern bool
diff -r 69c5afd5ab08 -r 4637dfae0856 tools/libxen/include/xen_host_metrics.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxen/include/xen_host_metrics.h   Tue Jan 30 13:46:46 2007 +0000
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+
+#ifndef XEN_HOST_METRICS_H
+#define XEN_HOST_METRICS_H
+
+#include "xen_common.h"
+#include "xen_host_decl.h"
+#include "xen_host_metrics_decl.h"
+
+
+/*
+ * The host_metrics class.
+ * 
+ * The metrics associated with a host.
+ */
+
+
+/**
+ * Free the given xen_host_metrics.  The given handle must have been
+ * allocated by this library.
+ */
+extern void
+xen_host_metrics_free(xen_host_metrics host_metrics);
+
+
+typedef struct xen_host_metrics_set
+{
+    size_t size;
+    xen_host_metrics *contents[];
+} xen_host_metrics_set;
+
+/**
+ * Allocate a xen_host_metrics_set of the given size.
+ */
+extern xen_host_metrics_set *
+xen_host_metrics_set_alloc(size_t size);
+
+/**
+ * Free the given xen_host_metrics_set.  The given set must have been
+ * allocated by this library.
+ */
+extern void
+xen_host_metrics_set_free(xen_host_metrics_set *set);
+
+
+typedef struct xen_host_metrics_record
+{
+    xen_host_metrics handle;
+    char *uuid;
+    struct xen_host_record_opt *host;
+    int64_t memory_total;
+    int64_t memory_free;
+} xen_host_metrics_record;
+
+/**
+ * Allocate a xen_host_metrics_record.
+ */
+extern xen_host_metrics_record *
+xen_host_metrics_record_alloc(void);
+
+/**
+ * Free the given xen_host_metrics_record, and all referenced values. 
+ * The given record must have been allocated by this library.
+ */
+extern void
+xen_host_metrics_record_free(xen_host_metrics_record *record);
+
+
+typedef struct xen_host_metrics_record_opt
+{
+    bool is_record;
+    union
+    {
+        xen_host_metrics handle;
+        xen_host_metrics_record *record;
+    } u;
+} xen_host_metrics_record_opt;
+
+/**
+ * Allocate a xen_host_metrics_record_opt.
+ */
+extern xen_host_metrics_record_opt *
+xen_host_metrics_record_opt_alloc(void);
+
+/**
+ * Free the given xen_host_metrics_record_opt, and all referenced
+ * values.  The given record_opt must have been allocated by this library.
+ */
+extern void
+xen_host_metrics_record_opt_free(xen_host_metrics_record_opt *record_opt);
+
+
+typedef struct xen_host_metrics_record_set
+{
+    size_t size;
+    xen_host_metrics_record *contents[];
+} xen_host_metrics_record_set;
+
+/**
+ * Allocate a xen_host_metrics_record_set of the given size.
+ */
+extern xen_host_metrics_record_set *
+xen_host_metrics_record_set_alloc(size_t size);
+
+/**
+ * Free the given xen_host_metrics_record_set, and all referenced
+ * values.  The given set must have been allocated by this library.
+ */
+extern void
+xen_host_metrics_record_set_free(xen_host_metrics_record_set *set);
+
+
+
+typedef struct xen_host_metrics_record_opt_set
+{
+    size_t size;
+    xen_host_metrics_record_opt *contents[];
+} xen_host_metrics_record_opt_set;
+
+/**
+ * Allocate a xen_host_metrics_record_opt_set of the given size.
+ */
+extern xen_host_metrics_record_opt_set *
+xen_host_metrics_record_opt_set_alloc(size_t size);
+
+/**
+ * Free the given xen_host_metrics_record_opt_set, and all referenced
+ * values.  The given set must have been allocated by this library.
+ */
+extern void
+xen_host_metrics_record_opt_set_free(xen_host_metrics_record_opt_set *set);
+
+
+/**
+ * Get a record containing the current state of the given host_metrics.
+ */
+extern bool
+xen_host_metrics_get_record(xen_session *session, xen_host_metrics_record 
**result, xen_host_metrics host_metrics);
+
+
+/**
+ * Get a reference to the host_metrics instance with the specified
+ * UUID.
+ */
+extern bool
+xen_host_metrics_get_by_uuid(xen_session *session, xen_host_metrics *result, 
char *uuid);
+
+
+/**
+ * Get the uuid field of the given host_metrics.
+ */
+extern bool
+xen_host_metrics_get_uuid(xen_session *session, char **result, 
xen_host_metrics host_metrics);
+
+
+/**
+ * Get the host field of the given host_metrics.
+ */
+extern bool
+xen_host_metrics_get_host(xen_session *session, xen_host *result, 
xen_host_metrics host_metrics);
+
+
+/**
+ * Get the memory/total field of the given host_metrics.
+ */
+extern bool
+xen_host_metrics_get_memory_total(xen_session *session, int64_t *result, 
xen_host_metrics host_metrics);
+
+
+/**
+ * Get the memory/free field of the given host_metrics.
+ */
+extern bool
+xen_host_metrics_get_memory_free(xen_session *session, int64_t *result, 
xen_host_metrics host_metrics);
+
+
+#endif
diff -r 69c5afd5ab08 -r 4637dfae0856 
tools/libxen/include/xen_host_metrics_decl.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxen/include/xen_host_metrics_decl.h      Tue Jan 30 13:46:46 
2007 +0000
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+
+#ifndef XEN_HOST_METRICS_DECL_H
+#define XEN_HOST_METRICS_DECL_H
+
+typedef void *xen_host_metrics;
+
+struct xen_host_metrics_set;
+struct xen_host_metrics_record;
+struct xen_host_metrics_record_set;
+struct xen_host_metrics_record_opt;
+struct xen_host_metrics_record_opt_set;
+
+#endif
diff -r 69c5afd5ab08 -r 4637dfae0856 tools/libxen/src/xen_host.c
--- a/tools/libxen/src/xen_host.c       Tue Jan 30 12:43:40 2007 +0000
+++ b/tools/libxen/src/xen_host.c       Tue Jan 30 13:46:46 2007 +0000
@@ -23,6 +23,7 @@
 #include "xen_common.h"
 #include "xen_host.h"
 #include "xen_host_cpu.h"
+#include "xen_host_metrics.h"
 #include "xen_internal.h"
 #include "xen_pbd.h"
 #include "xen_pif.h"
@@ -77,7 +78,10 @@ static const struct_member xen_host_reco
           .offset = offsetof(xen_host_record, pbds) },
         { .key = "host_CPUs",
           .type = &abstract_type_ref_set,
-          .offset = offsetof(xen_host_record, host_cpus) }
+          .offset = offsetof(xen_host_record, host_cpus) },
+        { .key = "metrics",
+          .type = &abstract_type_ref,
+          .offset = offsetof(xen_host_record, metrics) }
     };
 
 const abstract_type xen_host_record_abstract_type_ =
@@ -110,6 +114,7 @@ xen_host_record_free(xen_host_record *re
     xen_sr_record_opt_free(record->crash_dump_sr);
     xen_pbd_record_opt_set_free(record->pbds);
     xen_host_cpu_record_opt_set_free(record->host_cpus);
+    xen_host_metrics_record_opt_free(record->metrics);
     free(record);
 }
 
@@ -390,6 +395,23 @@ xen_host_get_host_cpus(xen_session *sess
 
 
 bool
+xen_host_get_metrics(xen_session *session, xen_host_metrics *result, xen_host 
host)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = host }
+        };
+
+    abstract_type result_type = abstract_type_string;
+
+    *result = NULL;
+    XEN_CALL_("host.get_metrics");
+    return session->ok;
+}
+
+
+bool
 xen_host_set_name_label(xen_session *session, xen_host host, char *label)
 {
     abstract_value param_values[] =
diff -r 69c5afd5ab08 -r 4637dfae0856 tools/libxen/src/xen_host_metrics.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxen/src/xen_host_metrics.c       Tue Jan 30 13:46:46 2007 +0000
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2006, XenSource Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "xen_common.h"
+#include "xen_host.h"
+#include "xen_host_metrics.h"
+#include "xen_internal.h"
+
+
+XEN_FREE(xen_host_metrics)
+XEN_SET_ALLOC_FREE(xen_host_metrics)
+XEN_ALLOC(xen_host_metrics_record)
+XEN_SET_ALLOC_FREE(xen_host_metrics_record)
+XEN_ALLOC(xen_host_metrics_record_opt)
+XEN_RECORD_OPT_FREE(xen_host_metrics)
+XEN_SET_ALLOC_FREE(xen_host_metrics_record_opt)
+
+
+static const struct_member xen_host_metrics_record_struct_members[] =
+    {
+        { .key = "uuid",
+          .type = &abstract_type_string,
+          .offset = offsetof(xen_host_metrics_record, uuid) },
+        { .key = "host",
+          .type = &abstract_type_ref,
+          .offset = offsetof(xen_host_metrics_record, host) },
+        { .key = "memory_total",
+          .type = &abstract_type_int,
+          .offset = offsetof(xen_host_metrics_record, memory_total) },
+        { .key = "memory_free",
+          .type = &abstract_type_int,
+          .offset = offsetof(xen_host_metrics_record, memory_free) }
+    };
+
+const abstract_type xen_host_metrics_record_abstract_type_ =
+    {
+       .typename = STRUCT,
+       .struct_size = sizeof(xen_host_metrics_record),
+       .member_count =
+           sizeof(xen_host_metrics_record_struct_members) / 
sizeof(struct_member),
+       .members = xen_host_metrics_record_struct_members
+    };
+
+
+void
+xen_host_metrics_record_free(xen_host_metrics_record *record)
+{
+    if (record == NULL)
+    {
+        return;
+    }
+    free(record->handle);
+    free(record->uuid);
+    xen_host_record_opt_free(record->host);
+    free(record);
+}
+
+
+bool
+xen_host_metrics_get_record(xen_session *session, xen_host_metrics_record 
**result, xen_host_metrics host_metrics)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = host_metrics }
+        };
+
+    abstract_type result_type = xen_host_metrics_record_abstract_type_;
+
+    *result = NULL;
+    XEN_CALL_("host_metrics.get_record");
+
+    if (session->ok)
+    {
+       (*result)->handle = xen_strdup_((*result)->uuid);
+    }
+
+    return session->ok;
+}
+
+
+bool
+xen_host_metrics_get_by_uuid(xen_session *session, xen_host_metrics *result, 
char *uuid)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = uuid }
+        };
+
+    abstract_type result_type = abstract_type_string;
+
+    *result = NULL;
+    XEN_CALL_("host_metrics.get_by_uuid");
+    return session->ok;
+}
+
+
+bool
+xen_host_metrics_get_host(xen_session *session, xen_host *result, 
xen_host_metrics host_metrics)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = host_metrics }
+        };
+
+    abstract_type result_type = abstract_type_string;
+
+    *result = NULL;
+    XEN_CALL_("host_metrics.get_host");
+    return session->ok;
+}
+
+
+bool
+xen_host_metrics_get_memory_total(xen_session *session, int64_t *result, 
xen_host_metrics host_metrics)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = host_metrics }
+        };
+
+    abstract_type result_type = abstract_type_int;
+
+    XEN_CALL_("host_metrics.get_memory_total");
+    return session->ok;
+}
+
+
+bool
+xen_host_metrics_get_memory_free(xen_session *session, int64_t *result, 
xen_host_metrics host_metrics)
+{
+    abstract_value param_values[] =
+        {
+            { .type = &abstract_type_string,
+              .u.string_val = host_metrics }
+        };
+
+    abstract_type result_type = abstract_type_int;
+
+    XEN_CALL_("host_metrics.get_memory_free");
+    return session->ok;
+}
+
+
+bool
+xen_host_metrics_get_uuid(xen_session *session, char **result, 
xen_host_metrics host_metrics)
+{
+    *result = session->ok ? xen_strdup_((char *)host_metrics) : NULL;
+    return session->ok;
+}
diff -r 69c5afd5ab08 -r 4637dfae0856 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Tue Jan 30 12:43:40 2007 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Tue Jan 30 13:46:46 2007 +0000
@@ -158,6 +158,17 @@ def valid_host(func):
            _check_ref(XendNode.instance().is_valid_host,
                       'HOST_HANDLE_INVALID', func, *args, **kwargs)
 
+def valid_host_metrics(func):
+    """Decorator to verify if host_metrics_ref is valid before calling
+    method.
+
+    @param func: function with params: (self, session, host_metrics_ref)
+    @rtype: callable object
+    """
+    return lambda *args, **kwargs: \
+           _check_ref(lambda r: r == XendNode.instance().host_metrics_uuid,
+                      'HOST_METRICS_HANDLE_INVALID', func, *args, **kwargs)
+
 def valid_host_cpu(func):
     """Decorator to verify if host_cpu_ref is valid before calling method.
 
@@ -360,21 +371,22 @@ class XendAPI(object):
         """
         global_validators = [session_required, catch_typeerror]
         classes = {
-            'session' : None,
-            'host'    : valid_host,
-            'host_cpu': valid_host_cpu,
-            'network' : valid_network,
-            'VM'      : valid_vm,
-            'VBD'     : valid_vbd,
-            'VIF'     : valid_vif,
-            'VDI'     : valid_vdi,
-            'VTPM'    : valid_vtpm,
-            'console' : valid_console,
-            'SR'      : valid_sr,
-            'PIF'     : valid_pif,
-            'PIF_metrics': valid_pif_metrics,
-            'task'    : valid_task,
-            'debug'   : valid_debug,
+            'session'      : None,
+            'host'         : valid_host,
+            'host_cpu'     : valid_host_cpu,
+            'host_metrics' : valid_host_metrics,
+            'network'      : valid_network,
+            'VM'           : valid_vm,
+            'VBD'          : valid_vbd,
+            'VIF'          : valid_vif,
+            'VDI'          : valid_vdi,
+            'VTPM'         : valid_vtpm,
+            'console'      : valid_console,
+            'SR'           : valid_sr,
+            'PIF'          : valid_pif,
+            'PIF_metrics'  : valid_pif_metrics,
+            'task'         : valid_task,
+            'debug'        : valid_debug,
         }
 
         # Cheat methods
@@ -573,12 +585,13 @@ class XendAPI(object):
     def task_get_by_name_label(self, session, name):
         return xen_api_success(XendTaskManager.get_task_by_name(name))
 
-    # Xen API: Class Host
+    # Xen API: Class host
     # ----------------------------------------------------------------    
 
     host_attr_ro = ['software_version',
                     'resident_VMs',
-                    'host_CPUs']
+                    'host_CPUs',
+                    'metrics']
     
     host_attr_rw = ['name_label',
                     'name_description',
@@ -627,6 +640,8 @@ class XendAPI(object):
         return xen_api_success(XendDomain.instance().get_domain_refs())
     def host_get_host_CPUs(self, session, host_ref):
         return xen_api_success(XendNode.instance().get_host_cpu_refs())
+    def host_get_metrics(self, _, ref):
+        return xen_api_success(XendNode.instance().host_metrics_uuid)
 
     # object methods
     def host_destroy(self, session, host_ref):
@@ -645,6 +660,7 @@ class XendAPI(object):
         if not XendDomain.instance().allow_new_domains():
             return xen_api_error(XEND_ERROR_HOST_RUNNING)
         return xen_api_error(XEND_ERROR_UNSUPPORTED)        
+
     def host_get_record(self, session, host_ref):
         node = XendNode.instance()
         dom = XendDomain.instance()
@@ -653,7 +669,8 @@ class XendAPI(object):
                   'name_description': '',
                   'software_version': node.xen_version(),
                   'resident_VMs': dom.get_domain_refs(),
-                  'host_CPUs': node.get_host_cpu_refs()}
+                  'host_CPUs': node.get_host_cpu_refs(),
+                  'metrics': node.host_metrics_uuid}
         return xen_api_success(record)
 
     # class methods
@@ -667,7 +684,7 @@ class XendAPI(object):
         return xen_api_success([])
     
 
-    # Xen API: Class Host_CPU
+    # Xen API: Class host_CPU
     # ----------------------------------------------------------------
 
     host_cpu_attr_ro = ['host',
@@ -698,6 +715,44 @@ class XendAPI(object):
     # class methods
     def host_cpu_get_all(self, session):
         return xen_api_success(XendNode.instance().get_host_cpu_refs())
+
+
+    # Xen API: Class host_metrics
+    # ----------------------------------------------------------------
+
+    host_metrics_attr_ro = ['memory_total',
+                            'memory_free',
+                            'host']
+    host_metrics_attr_rw = []
+    host_methods = []
+
+    def _host_metrics_get(self, ref, f):
+        return xen_api_success(getattr(node, f)())
+
+    def host_metrics_get_record(self, _, ref):
+        return xen_api_success({
+            'uuid'         : ref,
+            'host'         : XendNode.instance().uuid,
+            'memory_total' : self._host_metrics_get_memory_total(),
+            'memory_free'  : self._host_metrics_get_memory_free(),
+            })
+
+    def host_metrics_get_host(self, _, ref):
+        return xen_api_success(XendNode.instance().uuid)
+
+    def host_metrics_get_memory_total(self, _, ref):
+        return xen_api_success(self._host_metrics_get_memory_total())
+
+    def host_metrics_get_memory_free(self, _, ref):
+        return xen_api_success(self._host_metrics_get_memory_free())
+
+    def _host_metrics_get_memory_total(self):
+        node = XendNode.instance()
+        return node.xc.physinfo()['total_memory'] * 1024
+
+    def _host_metrics_get_memory_free(self):
+        node = XendNode.instance()
+        return node.xc.physinfo()['free_memory'] * 1024
 
 
     # Xen API: Class network
diff -r 69c5afd5ab08 -r 4637dfae0856 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Tue Jan 30 12:43:40 2007 +0000
+++ b/tools/python/xen/xend/XendNode.py Tue Jan 30 13:46:46 2007 +0000
@@ -40,10 +40,12 @@ class XendNode:
     def __init__(self):
         """Initalises the state of all host specific objects such as
 
-        * Host
-        * Host_CPU
+        * host
+        * host_CPU
+        * host_metrics
         * PIF
-        * Network
+        * PIF_metrics
+        * network
         * Storage Repository
         """
         
@@ -59,6 +61,8 @@ class XendNode:
             host = saved_host[self.uuid]
             self.name = host.get('name_label', socket.gethostname())
             self.desc = host.get('name_description', '')
+            self.host_metrics_uuid = host.get('metrics_uuid',
+                                              uuid.createString())
             try:
                 self.other_config = eval(host['other_config'])
             except:
@@ -229,6 +233,7 @@ class XendNode:
         # save state
         host_record = {self.uuid: {'name_label':self.name,
                                    'name_description':self.desc,
+                                   'metrics_uuid': self.host_metrics_uuid,
                                    'other_config': repr(self.other_config)}}
         self.state_store.save_state('host',host_record)
         self.state_store.save_state('cpu', self.cpus)
diff -r 69c5afd5ab08 -r 4637dfae0856 tools/python/xen/xm/messages/en/xen-xm.po
--- a/tools/python/xen/xm/messages/en/xen-xm.po Tue Jan 30 12:43:40 2007 +0000
+++ b/tools/python/xen/xm/messages/en/xen-xm.po Tue Jan 30 13:46:46 2007 +0000
@@ -19,7 +19,7 @@ msgid ""
 msgid ""
 msgstr ""
 "Project-Id-Version: Xen-xm 3.0\n"
-"PO-Revision-Date: 2007-01-29 18:50+0000\n"
+"PO-Revision-Date: 2007-01-30 12:49+0000\n"
 "Last-Translator: Ewan Mellor <ewan@xxxxxxxxxxxxx>\n"
 "Language-Team: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>\n"
 "MIME-Version: 1.0\n"
@@ -46,6 +46,9 @@ msgstr "The host_cpu handle %(1)s is inv
 
 msgid "HOST_HANDLE_INVALID"
 msgstr "The host handle %(1)s is invalid."
+
+msgid "HOST_METRICS_HANDLE_INVALID"
+msgstr "The host_metrics handle %(1)s is invalid."
 
 msgid "PIF_HANDLE_INVALID"
 msgstr "The PIF handle %(1)s is invalid."

_______________________________________________
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] Added host_metrics class., Xen patchbot-unstable <=