ia64/xen-unstable

changeset 13743:4637dfae0856

Added host_metrics class.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Jan 30 13:46:46 2007 +0000 (2007-01-30)
parents 69c5afd5ab08
children a9912f2e472b
files docs/xen-api/xenapi-datamodel.tex tools/libxen/include/xen_host.h tools/libxen/include/xen_host_metrics.h tools/libxen/include/xen_host_metrics_decl.h tools/libxen/src/xen_host.c tools/libxen/src/xen_host_metrics.c tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendNode.py tools/python/xen/xm/messages/en/xen-xm.po
line diff
     1.1 --- a/docs/xen-api/xenapi-datamodel.tex	Tue Jan 30 12:43:40 2007 +0000
     1.2 +++ b/docs/xen-api/xenapi-datamodel.tex	Tue Jan 30 13:46:46 2007 +0000
     1.3 @@ -26,6 +26,7 @@ Name & Description \\
     1.4  {\tt task} & A long-running asynchronous task \\
     1.5  {\tt VM} & A virtual machine (or 'guest') \\
     1.6  {\tt host} & A physical host \\
     1.7 +{\tt host\_metrics} & The metrics associated with a host \\
     1.8  {\tt host\_cpu} & A physical CPU \\
     1.9  {\tt network} & A virtual network \\
    1.10  {\tt VIF} & A virtual network interface \\
    1.11 @@ -57,6 +58,7 @@ VBD.VM & VM.VBDs & one-to-many\\
    1.12  crashdump.VM & VM.crash\_dumps & one-to-many\\
    1.13  VIF.VM & VM.VIFs & one-to-many\\
    1.14  VIF.network & network.VIFs & one-to-many\\
    1.15 +host.metrics & host\_metrics.host & one-to-one\\
    1.16  PIF.metrics & PIF\_metrics.PIF & one-to-one\\
    1.17  PIF.host & host.PIFs & one-to-many\\
    1.18  PIF.network & network.PIFs & one-to-many\\
    1.19 @@ -3835,6 +3837,7 @@ Quals & Field & Type & Description \\
    1.20  $\mathit{RW}$ &  {\tt crash\_dump\_sr} & SR ref & The SR in which VDIs for crash dumps are created \\
    1.21  $\mathit{RO}_\mathit{run}$ &  {\tt PBDs} & (PBD ref) Set & physical blockdevices \\
    1.22  $\mathit{RO}_\mathit{run}$ &  {\tt host\_CPUs} & (host\_cpu ref) Set & The physical CPUs on this host \\
    1.23 +$\mathit{RO}_\mathit{ins}$ &  {\tt metrics} & host\_metrics ref & metrics associated with this host. \\
    1.24  \hline
    1.25  \end{longtable}
    1.26  \subsection{Additional RPCs associated with class: host}
    1.27 @@ -4720,6 +4723,38 @@ value of the field
    1.28  \vspace{0.3cm}
    1.29  \vspace{0.3cm}
    1.30  \vspace{0.3cm}
    1.31 +\subsubsection{RPC name:~get\_metrics}
    1.32 +
    1.33 +{\bf Overview:} 
    1.34 +Get the metrics field of the given host.
    1.35 +
    1.36 + \noindent {\bf Signature:} 
    1.37 +\begin{verbatim} (host_metrics ref) get_metrics (session_id s, host ref self)\end{verbatim}
    1.38 +
    1.39 +
    1.40 +\noindent{\bf Arguments:}
    1.41 +
    1.42 + 
    1.43 +\vspace{0.3cm}
    1.44 +\begin{tabular}{|c|c|p{7cm}|}
    1.45 + \hline
    1.46 +{\bf type} & {\bf name} & {\bf description} \\ \hline
    1.47 +{\tt host ref } & self & reference to the object \\ \hline 
    1.48 +
    1.49 +\end{tabular}
    1.50 +
    1.51 +\vspace{0.3cm}
    1.52 +
    1.53 + \noindent {\bf Return Type:} 
    1.54 +{\tt 
    1.55 +host\_metrics ref
    1.56 +}
    1.57 +
    1.58 +
    1.59 +value of the field
    1.60 +\vspace{0.3cm}
    1.61 +\vspace{0.3cm}
    1.62 +\vspace{0.3cm}
    1.63  \subsubsection{RPC name:~create}
    1.64  
    1.65  {\bf Overview:} 
    1.66 @@ -4883,6 +4918,218 @@ references to objects with match names
    1.67  
    1.68  \vspace{1cm}
    1.69  \newpage
    1.70 +\section{Class: host\_metrics}
    1.71 +\subsection{Fields for class: host\_metrics}
    1.72 +\begin{longtable}{|lllp{0.38\textwidth}|}
    1.73 +\hline
    1.74 +\multicolumn{1}{|l}{Name} & \multicolumn{3}{l|}{\bf host\_metrics} \\
    1.75 +\multicolumn{1}{|l}{Description} & \multicolumn{3}{l|}{\parbox{11cm}{\em
    1.76 +The metrics associated with a host.}} \\
    1.77 +\hline
    1.78 +Quals & Field & Type & Description \\
    1.79 +\hline
    1.80 +$\mathit{RO}_\mathit{run}$ &  {\tt uuid} & string & unique identifier/object reference \\
    1.81 +$\mathit{RO}_\mathit{ins}$ &  {\tt host} & host ref & Host to which these metrics apply \\
    1.82 +$\mathit{RO}_\mathit{run}$ &  {\tt memory/total} & int & Host's total memory (bytes) \\
    1.83 +$\mathit{RO}_\mathit{run}$ &  {\tt memory/free} & int & Host's free memory (bytes) \\
    1.84 +\hline
    1.85 +\end{longtable}
    1.86 +\subsection{Additional RPCs associated with class: host\_metrics}
    1.87 +\subsubsection{RPC name:~get\_uuid}
    1.88 +
    1.89 +{\bf Overview:} 
    1.90 +Get the uuid field of the given host\_metrics.
    1.91 +
    1.92 + \noindent {\bf Signature:} 
    1.93 +\begin{verbatim} string get_uuid (session_id s, host_metrics ref self)\end{verbatim}
    1.94 +
    1.95 +
    1.96 +\noindent{\bf Arguments:}
    1.97 +
    1.98 + 
    1.99 +\vspace{0.3cm}
   1.100 +\begin{tabular}{|c|c|p{7cm}|}
   1.101 + \hline
   1.102 +{\bf type} & {\bf name} & {\bf description} \\ \hline
   1.103 +{\tt host\_metrics ref } & self & reference to the object \\ \hline 
   1.104 +
   1.105 +\end{tabular}
   1.106 +
   1.107 +\vspace{0.3cm}
   1.108 +
   1.109 + \noindent {\bf Return Type:} 
   1.110 +{\tt 
   1.111 +string
   1.112 +}
   1.113 +
   1.114 +
   1.115 +value of the field
   1.116 +\vspace{0.3cm}
   1.117 +\vspace{0.3cm}
   1.118 +\vspace{0.3cm}
   1.119 +\subsubsection{RPC name:~get\_host}
   1.120 +
   1.121 +{\bf Overview:} 
   1.122 +Get the host field of the given host\_metrics.
   1.123 +
   1.124 + \noindent {\bf Signature:} 
   1.125 +\begin{verbatim} (host ref) get_host (session_id s, host_metrics ref self)\end{verbatim}
   1.126 +
   1.127 +
   1.128 +\noindent{\bf Arguments:}
   1.129 +
   1.130 + 
   1.131 +\vspace{0.3cm}
   1.132 +\begin{tabular}{|c|c|p{7cm}|}
   1.133 + \hline
   1.134 +{\bf type} & {\bf name} & {\bf description} \\ \hline
   1.135 +{\tt host\_metrics ref } & self & reference to the object \\ \hline 
   1.136 +
   1.137 +\end{tabular}
   1.138 +
   1.139 +\vspace{0.3cm}
   1.140 +
   1.141 + \noindent {\bf Return Type:} 
   1.142 +{\tt 
   1.143 +host ref
   1.144 +}
   1.145 +
   1.146 +
   1.147 +value of the field
   1.148 +\vspace{0.3cm}
   1.149 +\vspace{0.3cm}
   1.150 +\vspace{0.3cm}
   1.151 +\subsubsection{RPC name:~get\_memory\_total}
   1.152 +
   1.153 +{\bf Overview:} 
   1.154 +Get the memory/total field of the given host\_metrics.
   1.155 +
   1.156 + \noindent {\bf Signature:} 
   1.157 +\begin{verbatim} int get_memory_total (session_id s, host_metrics ref self)\end{verbatim}
   1.158 +
   1.159 +
   1.160 +\noindent{\bf Arguments:}
   1.161 +
   1.162 + 
   1.163 +\vspace{0.3cm}
   1.164 +\begin{tabular}{|c|c|p{7cm}|}
   1.165 + \hline
   1.166 +{\bf type} & {\bf name} & {\bf description} \\ \hline
   1.167 +{\tt host\_metrics ref } & self & reference to the object \\ \hline 
   1.168 +
   1.169 +\end{tabular}
   1.170 +
   1.171 +\vspace{0.3cm}
   1.172 +
   1.173 + \noindent {\bf Return Type:} 
   1.174 +{\tt 
   1.175 +int
   1.176 +}
   1.177 +
   1.178 +
   1.179 +value of the field
   1.180 +\vspace{0.3cm}
   1.181 +\vspace{0.3cm}
   1.182 +\vspace{0.3cm}
   1.183 +\subsubsection{RPC name:~get\_memory\_free}
   1.184 +
   1.185 +{\bf Overview:} 
   1.186 +Get the memory/free field of the given host\_metrics.
   1.187 +
   1.188 + \noindent {\bf Signature:} 
   1.189 +\begin{verbatim} int get_memory_free (session_id s, host_metrics ref self)\end{verbatim}
   1.190 +
   1.191 +
   1.192 +\noindent{\bf Arguments:}
   1.193 +
   1.194 + 
   1.195 +\vspace{0.3cm}
   1.196 +\begin{tabular}{|c|c|p{7cm}|}
   1.197 + \hline
   1.198 +{\bf type} & {\bf name} & {\bf description} \\ \hline
   1.199 +{\tt host\_metrics ref } & self & reference to the object \\ \hline 
   1.200 +
   1.201 +\end{tabular}
   1.202 +
   1.203 +\vspace{0.3cm}
   1.204 +
   1.205 + \noindent {\bf Return Type:} 
   1.206 +{\tt 
   1.207 +int
   1.208 +}
   1.209 +
   1.210 +
   1.211 +value of the field
   1.212 +\vspace{0.3cm}
   1.213 +\vspace{0.3cm}
   1.214 +\vspace{0.3cm}
   1.215 +\subsubsection{RPC name:~get\_by\_uuid}
   1.216 +
   1.217 +{\bf Overview:} 
   1.218 +Get a reference to the host\_metrics instance with the specified UUID.
   1.219 +
   1.220 + \noindent {\bf Signature:} 
   1.221 +\begin{verbatim} (host_metrics ref) get_by_uuid (session_id s, string uuid)\end{verbatim}
   1.222 +
   1.223 +
   1.224 +\noindent{\bf Arguments:}
   1.225 +
   1.226 + 
   1.227 +\vspace{0.3cm}
   1.228 +\begin{tabular}{|c|c|p{7cm}|}
   1.229 + \hline
   1.230 +{\bf type} & {\bf name} & {\bf description} \\ \hline
   1.231 +{\tt string } & uuid & UUID of object to return \\ \hline 
   1.232 +
   1.233 +\end{tabular}
   1.234 +
   1.235 +\vspace{0.3cm}
   1.236 +
   1.237 + \noindent {\bf Return Type:} 
   1.238 +{\tt 
   1.239 +host\_metrics ref
   1.240 +}
   1.241 +
   1.242 +
   1.243 +reference to the object
   1.244 +\vspace{0.3cm}
   1.245 +\vspace{0.3cm}
   1.246 +\vspace{0.3cm}
   1.247 +\subsubsection{RPC name:~get\_record}
   1.248 +
   1.249 +{\bf Overview:} 
   1.250 +Get a record containing the current state of the given host\_metrics.
   1.251 +
   1.252 + \noindent {\bf Signature:} 
   1.253 +\begin{verbatim} (host_metrics record) get_record (session_id s, host_metrics ref self)\end{verbatim}
   1.254 +
   1.255 +
   1.256 +\noindent{\bf Arguments:}
   1.257 +
   1.258 + 
   1.259 +\vspace{0.3cm}
   1.260 +\begin{tabular}{|c|c|p{7cm}|}
   1.261 + \hline
   1.262 +{\bf type} & {\bf name} & {\bf description} \\ \hline
   1.263 +{\tt host\_metrics ref } & self & reference to the object \\ \hline 
   1.264 +
   1.265 +\end{tabular}
   1.266 +
   1.267 +\vspace{0.3cm}
   1.268 +
   1.269 + \noindent {\bf Return Type:} 
   1.270 +{\tt 
   1.271 +host\_metrics record
   1.272 +}
   1.273 +
   1.274 +
   1.275 +all fields from the object
   1.276 +\vspace{0.3cm}
   1.277 +\vspace{0.3cm}
   1.278 +\vspace{0.3cm}
   1.279 +
   1.280 +\vspace{1cm}
   1.281 +\newpage
   1.282  \section{Class: host\_cpu}
   1.283  \subsection{Fields for class: host\_cpu}
   1.284  \begin{longtable}{|lllp{0.38\textwidth}|}
   1.285 @@ -10849,6 +11096,16 @@ The handle parameter echoes the bad valu
   1.286  \begin{verbatim}HOST_HANDLE_INVALID(handle)\end{verbatim}
   1.287  \begin{center}\rule{10em}{0.1pt}\end{center}
   1.288  
   1.289 +\subsubsection{HOST\_METRICS\_HANDLE\_INVALID}
   1.290 +
   1.291 +You gave an invalid host\_metrics handle.  The host\_metrics may have
   1.292 +recently been deleted.  The handle parameter echoes the bad value given.
   1.293 +
   1.294 +\vspace{0.3cm}
   1.295 +{\bf Signature:}
   1.296 +\begin{verbatim}HOST_METRICS_HANDLE_INVALID(handle)\end{verbatim}
   1.297 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.298 +
   1.299  \subsubsection{INTERNAL\_ERROR}
   1.300  
   1.301  The server failed to handle your request, due to an internal error.  The
     2.1 --- a/tools/libxen/include/xen_host.h	Tue Jan 30 12:43:40 2007 +0000
     2.2 +++ b/tools/libxen/include/xen_host.h	Tue Jan 30 13:46:46 2007 +0000
     2.3 @@ -22,6 +22,7 @@
     2.4  #include "xen_common.h"
     2.5  #include "xen_host_cpu_decl.h"
     2.6  #include "xen_host_decl.h"
     2.7 +#include "xen_host_metrics_decl.h"
     2.8  #include "xen_pbd_decl.h"
     2.9  #include "xen_pif_decl.h"
    2.10  #include "xen_sr_decl.h"
    2.11 @@ -79,6 +80,7 @@ typedef struct xen_host_record
    2.12      struct xen_sr_record_opt *crash_dump_sr;
    2.13      struct xen_pbd_record_opt_set *pbds;
    2.14      struct xen_host_cpu_record_opt_set *host_cpus;
    2.15 +    struct xen_host_metrics_record_opt *metrics;
    2.16  } xen_host_record;
    2.17  
    2.18  /**
    2.19 @@ -280,6 +282,13 @@ xen_host_get_host_cpus(xen_session *sess
    2.20  
    2.21  
    2.22  /**
    2.23 + * Get the metrics field of the given host.
    2.24 + */
    2.25 +extern bool
    2.26 +xen_host_get_metrics(xen_session *session, xen_host_metrics *result, xen_host host);
    2.27 +
    2.28 +
    2.29 +/**
    2.30   * Set the name/label field of the given host.
    2.31   */
    2.32  extern bool
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/libxen/include/xen_host_metrics.h	Tue Jan 30 13:46:46 2007 +0000
     3.3 @@ -0,0 +1,193 @@
     3.4 +/*
     3.5 + * Copyright (c) 2006, XenSource Inc.
     3.6 + *
     3.7 + * This library is free software; you can redistribute it and/or
     3.8 + * modify it under the terms of the GNU Lesser General Public
     3.9 + * License as published by the Free Software Foundation; either
    3.10 + * version 2.1 of the License, or (at your option) any later version.
    3.11 + *
    3.12 + * This library is distributed in the hope that it will be useful,
    3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.15 + * Lesser General Public License for more details.
    3.16 + *
    3.17 + * You should have received a copy of the GNU Lesser General Public
    3.18 + * License along with this library; if not, write to the Free Software
    3.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
    3.20 + */
    3.21 +
    3.22 +#ifndef XEN_HOST_METRICS_H
    3.23 +#define XEN_HOST_METRICS_H
    3.24 +
    3.25 +#include "xen_common.h"
    3.26 +#include "xen_host_decl.h"
    3.27 +#include "xen_host_metrics_decl.h"
    3.28 +
    3.29 +
    3.30 +/*
    3.31 + * The host_metrics class.
    3.32 + * 
    3.33 + * The metrics associated with a host.
    3.34 + */
    3.35 +
    3.36 +
    3.37 +/**
    3.38 + * Free the given xen_host_metrics.  The given handle must have been
    3.39 + * allocated by this library.
    3.40 + */
    3.41 +extern void
    3.42 +xen_host_metrics_free(xen_host_metrics host_metrics);
    3.43 +
    3.44 +
    3.45 +typedef struct xen_host_metrics_set
    3.46 +{
    3.47 +    size_t size;
    3.48 +    xen_host_metrics *contents[];
    3.49 +} xen_host_metrics_set;
    3.50 +
    3.51 +/**
    3.52 + * Allocate a xen_host_metrics_set of the given size.
    3.53 + */
    3.54 +extern xen_host_metrics_set *
    3.55 +xen_host_metrics_set_alloc(size_t size);
    3.56 +
    3.57 +/**
    3.58 + * Free the given xen_host_metrics_set.  The given set must have been
    3.59 + * allocated by this library.
    3.60 + */
    3.61 +extern void
    3.62 +xen_host_metrics_set_free(xen_host_metrics_set *set);
    3.63 +
    3.64 +
    3.65 +typedef struct xen_host_metrics_record
    3.66 +{
    3.67 +    xen_host_metrics handle;
    3.68 +    char *uuid;
    3.69 +    struct xen_host_record_opt *host;
    3.70 +    int64_t memory_total;
    3.71 +    int64_t memory_free;
    3.72 +} xen_host_metrics_record;
    3.73 +
    3.74 +/**
    3.75 + * Allocate a xen_host_metrics_record.
    3.76 + */
    3.77 +extern xen_host_metrics_record *
    3.78 +xen_host_metrics_record_alloc(void);
    3.79 +
    3.80 +/**
    3.81 + * Free the given xen_host_metrics_record, and all referenced values. 
    3.82 + * The given record must have been allocated by this library.
    3.83 + */
    3.84 +extern void
    3.85 +xen_host_metrics_record_free(xen_host_metrics_record *record);
    3.86 +
    3.87 +
    3.88 +typedef struct xen_host_metrics_record_opt
    3.89 +{
    3.90 +    bool is_record;
    3.91 +    union
    3.92 +    {
    3.93 +        xen_host_metrics handle;
    3.94 +        xen_host_metrics_record *record;
    3.95 +    } u;
    3.96 +} xen_host_metrics_record_opt;
    3.97 +
    3.98 +/**
    3.99 + * Allocate a xen_host_metrics_record_opt.
   3.100 + */
   3.101 +extern xen_host_metrics_record_opt *
   3.102 +xen_host_metrics_record_opt_alloc(void);
   3.103 +
   3.104 +/**
   3.105 + * Free the given xen_host_metrics_record_opt, and all referenced
   3.106 + * values.  The given record_opt must have been allocated by this library.
   3.107 + */
   3.108 +extern void
   3.109 +xen_host_metrics_record_opt_free(xen_host_metrics_record_opt *record_opt);
   3.110 +
   3.111 +
   3.112 +typedef struct xen_host_metrics_record_set
   3.113 +{
   3.114 +    size_t size;
   3.115 +    xen_host_metrics_record *contents[];
   3.116 +} xen_host_metrics_record_set;
   3.117 +
   3.118 +/**
   3.119 + * Allocate a xen_host_metrics_record_set of the given size.
   3.120 + */
   3.121 +extern xen_host_metrics_record_set *
   3.122 +xen_host_metrics_record_set_alloc(size_t size);
   3.123 +
   3.124 +/**
   3.125 + * Free the given xen_host_metrics_record_set, and all referenced
   3.126 + * values.  The given set must have been allocated by this library.
   3.127 + */
   3.128 +extern void
   3.129 +xen_host_metrics_record_set_free(xen_host_metrics_record_set *set);
   3.130 +
   3.131 +
   3.132 +
   3.133 +typedef struct xen_host_metrics_record_opt_set
   3.134 +{
   3.135 +    size_t size;
   3.136 +    xen_host_metrics_record_opt *contents[];
   3.137 +} xen_host_metrics_record_opt_set;
   3.138 +
   3.139 +/**
   3.140 + * Allocate a xen_host_metrics_record_opt_set of the given size.
   3.141 + */
   3.142 +extern xen_host_metrics_record_opt_set *
   3.143 +xen_host_metrics_record_opt_set_alloc(size_t size);
   3.144 +
   3.145 +/**
   3.146 + * Free the given xen_host_metrics_record_opt_set, and all referenced
   3.147 + * values.  The given set must have been allocated by this library.
   3.148 + */
   3.149 +extern void
   3.150 +xen_host_metrics_record_opt_set_free(xen_host_metrics_record_opt_set *set);
   3.151 +
   3.152 +
   3.153 +/**
   3.154 + * Get a record containing the current state of the given host_metrics.
   3.155 + */
   3.156 +extern bool
   3.157 +xen_host_metrics_get_record(xen_session *session, xen_host_metrics_record **result, xen_host_metrics host_metrics);
   3.158 +
   3.159 +
   3.160 +/**
   3.161 + * Get a reference to the host_metrics instance with the specified
   3.162 + * UUID.
   3.163 + */
   3.164 +extern bool
   3.165 +xen_host_metrics_get_by_uuid(xen_session *session, xen_host_metrics *result, char *uuid);
   3.166 +
   3.167 +
   3.168 +/**
   3.169 + * Get the uuid field of the given host_metrics.
   3.170 + */
   3.171 +extern bool
   3.172 +xen_host_metrics_get_uuid(xen_session *session, char **result, xen_host_metrics host_metrics);
   3.173 +
   3.174 +
   3.175 +/**
   3.176 + * Get the host field of the given host_metrics.
   3.177 + */
   3.178 +extern bool
   3.179 +xen_host_metrics_get_host(xen_session *session, xen_host *result, xen_host_metrics host_metrics);
   3.180 +
   3.181 +
   3.182 +/**
   3.183 + * Get the memory/total field of the given host_metrics.
   3.184 + */
   3.185 +extern bool
   3.186 +xen_host_metrics_get_memory_total(xen_session *session, int64_t *result, xen_host_metrics host_metrics);
   3.187 +
   3.188 +
   3.189 +/**
   3.190 + * Get the memory/free field of the given host_metrics.
   3.191 + */
   3.192 +extern bool
   3.193 +xen_host_metrics_get_memory_free(xen_session *session, int64_t *result, xen_host_metrics host_metrics);
   3.194 +
   3.195 +
   3.196 +#endif
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/libxen/include/xen_host_metrics_decl.h	Tue Jan 30 13:46:46 2007 +0000
     4.3 @@ -0,0 +1,30 @@
     4.4 +/*
     4.5 + * Copyright (c) 2006, XenSource Inc.
     4.6 + *
     4.7 + * This library is free software; you can redistribute it and/or
     4.8 + * modify it under the terms of the GNU Lesser General Public
     4.9 + * License as published by the Free Software Foundation; either
    4.10 + * version 2.1 of the License, or (at your option) any later version.
    4.11 + *
    4.12 + * This library is distributed in the hope that it will be useful,
    4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.15 + * Lesser General Public License for more details.
    4.16 + *
    4.17 + * You should have received a copy of the GNU Lesser General Public
    4.18 + * License along with this library; if not, write to the Free Software
    4.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
    4.20 + */
    4.21 +
    4.22 +#ifndef XEN_HOST_METRICS_DECL_H
    4.23 +#define XEN_HOST_METRICS_DECL_H
    4.24 +
    4.25 +typedef void *xen_host_metrics;
    4.26 +
    4.27 +struct xen_host_metrics_set;
    4.28 +struct xen_host_metrics_record;
    4.29 +struct xen_host_metrics_record_set;
    4.30 +struct xen_host_metrics_record_opt;
    4.31 +struct xen_host_metrics_record_opt_set;
    4.32 +
    4.33 +#endif
     5.1 --- a/tools/libxen/src/xen_host.c	Tue Jan 30 12:43:40 2007 +0000
     5.2 +++ b/tools/libxen/src/xen_host.c	Tue Jan 30 13:46:46 2007 +0000
     5.3 @@ -23,6 +23,7 @@
     5.4  #include "xen_common.h"
     5.5  #include "xen_host.h"
     5.6  #include "xen_host_cpu.h"
     5.7 +#include "xen_host_metrics.h"
     5.8  #include "xen_internal.h"
     5.9  #include "xen_pbd.h"
    5.10  #include "xen_pif.h"
    5.11 @@ -77,7 +78,10 @@ static const struct_member xen_host_reco
    5.12            .offset = offsetof(xen_host_record, pbds) },
    5.13          { .key = "host_CPUs",
    5.14            .type = &abstract_type_ref_set,
    5.15 -          .offset = offsetof(xen_host_record, host_cpus) }
    5.16 +          .offset = offsetof(xen_host_record, host_cpus) },
    5.17 +        { .key = "metrics",
    5.18 +          .type = &abstract_type_ref,
    5.19 +          .offset = offsetof(xen_host_record, metrics) }
    5.20      };
    5.21  
    5.22  const abstract_type xen_host_record_abstract_type_ =
    5.23 @@ -110,6 +114,7 @@ xen_host_record_free(xen_host_record *re
    5.24      xen_sr_record_opt_free(record->crash_dump_sr);
    5.25      xen_pbd_record_opt_set_free(record->pbds);
    5.26      xen_host_cpu_record_opt_set_free(record->host_cpus);
    5.27 +    xen_host_metrics_record_opt_free(record->metrics);
    5.28      free(record);
    5.29  }
    5.30  
    5.31 @@ -390,6 +395,23 @@ xen_host_get_host_cpus(xen_session *sess
    5.32  
    5.33  
    5.34  bool
    5.35 +xen_host_get_metrics(xen_session *session, xen_host_metrics *result, xen_host host)
    5.36 +{
    5.37 +    abstract_value param_values[] =
    5.38 +        {
    5.39 +            { .type = &abstract_type_string,
    5.40 +              .u.string_val = host }
    5.41 +        };
    5.42 +
    5.43 +    abstract_type result_type = abstract_type_string;
    5.44 +
    5.45 +    *result = NULL;
    5.46 +    XEN_CALL_("host.get_metrics");
    5.47 +    return session->ok;
    5.48 +}
    5.49 +
    5.50 +
    5.51 +bool
    5.52  xen_host_set_name_label(xen_session *session, xen_host host, char *label)
    5.53  {
    5.54      abstract_value param_values[] =
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/libxen/src/xen_host_metrics.c	Tue Jan 30 13:46:46 2007 +0000
     6.3 @@ -0,0 +1,172 @@
     6.4 +/*
     6.5 + * Copyright (c) 2006, XenSource Inc.
     6.6 + *
     6.7 + * This library is free software; you can redistribute it and/or
     6.8 + * modify it under the terms of the GNU Lesser General Public
     6.9 + * License as published by the Free Software Foundation; either
    6.10 + * version 2.1 of the License, or (at your option) any later version.
    6.11 + *
    6.12 + * This library is distributed in the hope that it will be useful,
    6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.15 + * Lesser General Public License for more details.
    6.16 + *
    6.17 + * You should have received a copy of the GNU Lesser General Public
    6.18 + * License along with this library; if not, write to the Free Software
    6.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
    6.20 + */
    6.21 +
    6.22 +
    6.23 +#include <stddef.h>
    6.24 +#include <stdlib.h>
    6.25 +
    6.26 +#include "xen_common.h"
    6.27 +#include "xen_host.h"
    6.28 +#include "xen_host_metrics.h"
    6.29 +#include "xen_internal.h"
    6.30 +
    6.31 +
    6.32 +XEN_FREE(xen_host_metrics)
    6.33 +XEN_SET_ALLOC_FREE(xen_host_metrics)
    6.34 +XEN_ALLOC(xen_host_metrics_record)
    6.35 +XEN_SET_ALLOC_FREE(xen_host_metrics_record)
    6.36 +XEN_ALLOC(xen_host_metrics_record_opt)
    6.37 +XEN_RECORD_OPT_FREE(xen_host_metrics)
    6.38 +XEN_SET_ALLOC_FREE(xen_host_metrics_record_opt)
    6.39 +
    6.40 +
    6.41 +static const struct_member xen_host_metrics_record_struct_members[] =
    6.42 +    {
    6.43 +        { .key = "uuid",
    6.44 +          .type = &abstract_type_string,
    6.45 +          .offset = offsetof(xen_host_metrics_record, uuid) },
    6.46 +        { .key = "host",
    6.47 +          .type = &abstract_type_ref,
    6.48 +          .offset = offsetof(xen_host_metrics_record, host) },
    6.49 +        { .key = "memory_total",
    6.50 +          .type = &abstract_type_int,
    6.51 +          .offset = offsetof(xen_host_metrics_record, memory_total) },
    6.52 +        { .key = "memory_free",
    6.53 +          .type = &abstract_type_int,
    6.54 +          .offset = offsetof(xen_host_metrics_record, memory_free) }
    6.55 +    };
    6.56 +
    6.57 +const abstract_type xen_host_metrics_record_abstract_type_ =
    6.58 +    {
    6.59 +       .typename = STRUCT,
    6.60 +       .struct_size = sizeof(xen_host_metrics_record),
    6.61 +       .member_count =
    6.62 +           sizeof(xen_host_metrics_record_struct_members) / sizeof(struct_member),
    6.63 +       .members = xen_host_metrics_record_struct_members
    6.64 +    };
    6.65 +
    6.66 +
    6.67 +void
    6.68 +xen_host_metrics_record_free(xen_host_metrics_record *record)
    6.69 +{
    6.70 +    if (record == NULL)
    6.71 +    {
    6.72 +        return;
    6.73 +    }
    6.74 +    free(record->handle);
    6.75 +    free(record->uuid);
    6.76 +    xen_host_record_opt_free(record->host);
    6.77 +    free(record);
    6.78 +}
    6.79 +
    6.80 +
    6.81 +bool
    6.82 +xen_host_metrics_get_record(xen_session *session, xen_host_metrics_record **result, xen_host_metrics host_metrics)
    6.83 +{
    6.84 +    abstract_value param_values[] =
    6.85 +        {
    6.86 +            { .type = &abstract_type_string,
    6.87 +              .u.string_val = host_metrics }
    6.88 +        };
    6.89 +
    6.90 +    abstract_type result_type = xen_host_metrics_record_abstract_type_;
    6.91 +
    6.92 +    *result = NULL;
    6.93 +    XEN_CALL_("host_metrics.get_record");
    6.94 +
    6.95 +    if (session->ok)
    6.96 +    {
    6.97 +       (*result)->handle = xen_strdup_((*result)->uuid);
    6.98 +    }
    6.99 +
   6.100 +    return session->ok;
   6.101 +}
   6.102 +
   6.103 +
   6.104 +bool
   6.105 +xen_host_metrics_get_by_uuid(xen_session *session, xen_host_metrics *result, char *uuid)
   6.106 +{
   6.107 +    abstract_value param_values[] =
   6.108 +        {
   6.109 +            { .type = &abstract_type_string,
   6.110 +              .u.string_val = uuid }
   6.111 +        };
   6.112 +
   6.113 +    abstract_type result_type = abstract_type_string;
   6.114 +
   6.115 +    *result = NULL;
   6.116 +    XEN_CALL_("host_metrics.get_by_uuid");
   6.117 +    return session->ok;
   6.118 +}
   6.119 +
   6.120 +
   6.121 +bool
   6.122 +xen_host_metrics_get_host(xen_session *session, xen_host *result, xen_host_metrics host_metrics)
   6.123 +{
   6.124 +    abstract_value param_values[] =
   6.125 +        {
   6.126 +            { .type = &abstract_type_string,
   6.127 +              .u.string_val = host_metrics }
   6.128 +        };
   6.129 +
   6.130 +    abstract_type result_type = abstract_type_string;
   6.131 +
   6.132 +    *result = NULL;
   6.133 +    XEN_CALL_("host_metrics.get_host");
   6.134 +    return session->ok;
   6.135 +}
   6.136 +
   6.137 +
   6.138 +bool
   6.139 +xen_host_metrics_get_memory_total(xen_session *session, int64_t *result, xen_host_metrics host_metrics)
   6.140 +{
   6.141 +    abstract_value param_values[] =
   6.142 +        {
   6.143 +            { .type = &abstract_type_string,
   6.144 +              .u.string_val = host_metrics }
   6.145 +        };
   6.146 +
   6.147 +    abstract_type result_type = abstract_type_int;
   6.148 +
   6.149 +    XEN_CALL_("host_metrics.get_memory_total");
   6.150 +    return session->ok;
   6.151 +}
   6.152 +
   6.153 +
   6.154 +bool
   6.155 +xen_host_metrics_get_memory_free(xen_session *session, int64_t *result, xen_host_metrics host_metrics)
   6.156 +{
   6.157 +    abstract_value param_values[] =
   6.158 +        {
   6.159 +            { .type = &abstract_type_string,
   6.160 +              .u.string_val = host_metrics }
   6.161 +        };
   6.162 +
   6.163 +    abstract_type result_type = abstract_type_int;
   6.164 +
   6.165 +    XEN_CALL_("host_metrics.get_memory_free");
   6.166 +    return session->ok;
   6.167 +}
   6.168 +
   6.169 +
   6.170 +bool
   6.171 +xen_host_metrics_get_uuid(xen_session *session, char **result, xen_host_metrics host_metrics)
   6.172 +{
   6.173 +    *result = session->ok ? xen_strdup_((char *)host_metrics) : NULL;
   6.174 +    return session->ok;
   6.175 +}
     7.1 --- a/tools/python/xen/xend/XendAPI.py	Tue Jan 30 12:43:40 2007 +0000
     7.2 +++ b/tools/python/xen/xend/XendAPI.py	Tue Jan 30 13:46:46 2007 +0000
     7.3 @@ -158,6 +158,17 @@ def valid_host(func):
     7.4             _check_ref(XendNode.instance().is_valid_host,
     7.5                        'HOST_HANDLE_INVALID', func, *args, **kwargs)
     7.6  
     7.7 +def valid_host_metrics(func):
     7.8 +    """Decorator to verify if host_metrics_ref is valid before calling
     7.9 +    method.
    7.10 +
    7.11 +    @param func: function with params: (self, session, host_metrics_ref)
    7.12 +    @rtype: callable object
    7.13 +    """
    7.14 +    return lambda *args, **kwargs: \
    7.15 +           _check_ref(lambda r: r == XendNode.instance().host_metrics_uuid,
    7.16 +                      'HOST_METRICS_HANDLE_INVALID', func, *args, **kwargs)
    7.17 +
    7.18  def valid_host_cpu(func):
    7.19      """Decorator to verify if host_cpu_ref is valid before calling method.
    7.20  
    7.21 @@ -360,21 +371,22 @@ class XendAPI(object):
    7.22          """
    7.23          global_validators = [session_required, catch_typeerror]
    7.24          classes = {
    7.25 -            'session' : None,
    7.26 -            'host'    : valid_host,
    7.27 -            'host_cpu': valid_host_cpu,
    7.28 -            'network' : valid_network,
    7.29 -            'VM'      : valid_vm,
    7.30 -            'VBD'     : valid_vbd,
    7.31 -            'VIF'     : valid_vif,
    7.32 -            'VDI'     : valid_vdi,
    7.33 -            'VTPM'    : valid_vtpm,
    7.34 -            'console' : valid_console,
    7.35 -            'SR'      : valid_sr,
    7.36 -            'PIF'     : valid_pif,
    7.37 -            'PIF_metrics': valid_pif_metrics,
    7.38 -            'task'    : valid_task,
    7.39 -            'debug'   : valid_debug,
    7.40 +            'session'      : None,
    7.41 +            'host'         : valid_host,
    7.42 +            'host_cpu'     : valid_host_cpu,
    7.43 +            'host_metrics' : valid_host_metrics,
    7.44 +            'network'      : valid_network,
    7.45 +            'VM'           : valid_vm,
    7.46 +            'VBD'          : valid_vbd,
    7.47 +            'VIF'          : valid_vif,
    7.48 +            'VDI'          : valid_vdi,
    7.49 +            'VTPM'         : valid_vtpm,
    7.50 +            'console'      : valid_console,
    7.51 +            'SR'           : valid_sr,
    7.52 +            'PIF'          : valid_pif,
    7.53 +            'PIF_metrics'  : valid_pif_metrics,
    7.54 +            'task'         : valid_task,
    7.55 +            'debug'        : valid_debug,
    7.56          }
    7.57  
    7.58          # Cheat methods
    7.59 @@ -573,12 +585,13 @@ class XendAPI(object):
    7.60      def task_get_by_name_label(self, session, name):
    7.61          return xen_api_success(XendTaskManager.get_task_by_name(name))
    7.62  
    7.63 -    # Xen API: Class Host
    7.64 +    # Xen API: Class host
    7.65      # ----------------------------------------------------------------    
    7.66  
    7.67      host_attr_ro = ['software_version',
    7.68                      'resident_VMs',
    7.69 -                    'host_CPUs']
    7.70 +                    'host_CPUs',
    7.71 +                    'metrics']
    7.72      
    7.73      host_attr_rw = ['name_label',
    7.74                      'name_description',
    7.75 @@ -627,6 +640,8 @@ class XendAPI(object):
    7.76          return xen_api_success(XendDomain.instance().get_domain_refs())
    7.77      def host_get_host_CPUs(self, session, host_ref):
    7.78          return xen_api_success(XendNode.instance().get_host_cpu_refs())
    7.79 +    def host_get_metrics(self, _, ref):
    7.80 +        return xen_api_success(XendNode.instance().host_metrics_uuid)
    7.81  
    7.82      # object methods
    7.83      def host_destroy(self, session, host_ref):
    7.84 @@ -645,6 +660,7 @@ class XendAPI(object):
    7.85          if not XendDomain.instance().allow_new_domains():
    7.86              return xen_api_error(XEND_ERROR_HOST_RUNNING)
    7.87          return xen_api_error(XEND_ERROR_UNSUPPORTED)        
    7.88 +
    7.89      def host_get_record(self, session, host_ref):
    7.90          node = XendNode.instance()
    7.91          dom = XendDomain.instance()
    7.92 @@ -653,7 +669,8 @@ class XendAPI(object):
    7.93                    'name_description': '',
    7.94                    'software_version': node.xen_version(),
    7.95                    'resident_VMs': dom.get_domain_refs(),
    7.96 -                  'host_CPUs': node.get_host_cpu_refs()}
    7.97 +                  'host_CPUs': node.get_host_cpu_refs(),
    7.98 +                  'metrics': node.host_metrics_uuid}
    7.99          return xen_api_success(record)
   7.100  
   7.101      # class methods
   7.102 @@ -667,7 +684,7 @@ class XendAPI(object):
   7.103          return xen_api_success([])
   7.104      
   7.105  
   7.106 -    # Xen API: Class Host_CPU
   7.107 +    # Xen API: Class host_CPU
   7.108      # ----------------------------------------------------------------
   7.109  
   7.110      host_cpu_attr_ro = ['host',
   7.111 @@ -700,6 +717,44 @@ class XendAPI(object):
   7.112          return xen_api_success(XendNode.instance().get_host_cpu_refs())
   7.113  
   7.114  
   7.115 +    # Xen API: Class host_metrics
   7.116 +    # ----------------------------------------------------------------
   7.117 +
   7.118 +    host_metrics_attr_ro = ['memory_total',
   7.119 +                            'memory_free',
   7.120 +                            'host']
   7.121 +    host_metrics_attr_rw = []
   7.122 +    host_methods = []
   7.123 +
   7.124 +    def _host_metrics_get(self, ref, f):
   7.125 +        return xen_api_success(getattr(node, f)())
   7.126 +
   7.127 +    def host_metrics_get_record(self, _, ref):
   7.128 +        return xen_api_success({
   7.129 +            'uuid'         : ref,
   7.130 +            'host'         : XendNode.instance().uuid,
   7.131 +            'memory_total' : self._host_metrics_get_memory_total(),
   7.132 +            'memory_free'  : self._host_metrics_get_memory_free(),
   7.133 +            })
   7.134 +
   7.135 +    def host_metrics_get_host(self, _, ref):
   7.136 +        return xen_api_success(XendNode.instance().uuid)
   7.137 +
   7.138 +    def host_metrics_get_memory_total(self, _, ref):
   7.139 +        return xen_api_success(self._host_metrics_get_memory_total())
   7.140 +
   7.141 +    def host_metrics_get_memory_free(self, _, ref):
   7.142 +        return xen_api_success(self._host_metrics_get_memory_free())
   7.143 +
   7.144 +    def _host_metrics_get_memory_total(self):
   7.145 +        node = XendNode.instance()
   7.146 +        return node.xc.physinfo()['total_memory'] * 1024
   7.147 +
   7.148 +    def _host_metrics_get_memory_free(self):
   7.149 +        node = XendNode.instance()
   7.150 +        return node.xc.physinfo()['free_memory'] * 1024
   7.151 +
   7.152 +
   7.153      # Xen API: Class network
   7.154      # ----------------------------------------------------------------
   7.155  
     8.1 --- a/tools/python/xen/xend/XendNode.py	Tue Jan 30 12:43:40 2007 +0000
     8.2 +++ b/tools/python/xen/xend/XendNode.py	Tue Jan 30 13:46:46 2007 +0000
     8.3 @@ -40,10 +40,12 @@ class XendNode:
     8.4      def __init__(self):
     8.5          """Initalises the state of all host specific objects such as
     8.6  
     8.7 -        * Host
     8.8 -        * Host_CPU
     8.9 +        * host
    8.10 +        * host_CPU
    8.11 +        * host_metrics
    8.12          * PIF
    8.13 -        * Network
    8.14 +        * PIF_metrics
    8.15 +        * network
    8.16          * Storage Repository
    8.17          """
    8.18          
    8.19 @@ -59,6 +61,8 @@ class XendNode:
    8.20              host = saved_host[self.uuid]
    8.21              self.name = host.get('name_label', socket.gethostname())
    8.22              self.desc = host.get('name_description', '')
    8.23 +            self.host_metrics_uuid = host.get('metrics_uuid',
    8.24 +                                              uuid.createString())
    8.25              try:
    8.26                  self.other_config = eval(host['other_config'])
    8.27              except:
    8.28 @@ -229,6 +233,7 @@ class XendNode:
    8.29          # save state
    8.30          host_record = {self.uuid: {'name_label':self.name,
    8.31                                     'name_description':self.desc,
    8.32 +                                   'metrics_uuid': self.host_metrics_uuid,
    8.33                                     'other_config': repr(self.other_config)}}
    8.34          self.state_store.save_state('host',host_record)
    8.35          self.state_store.save_state('cpu', self.cpus)
     9.1 --- a/tools/python/xen/xm/messages/en/xen-xm.po	Tue Jan 30 12:43:40 2007 +0000
     9.2 +++ b/tools/python/xen/xm/messages/en/xen-xm.po	Tue Jan 30 13:46:46 2007 +0000
     9.3 @@ -19,7 +19,7 @@
     9.4  msgid ""
     9.5  msgstr ""
     9.6  "Project-Id-Version: Xen-xm 3.0\n"
     9.7 -"PO-Revision-Date: 2007-01-29 18:50+0000\n"
     9.8 +"PO-Revision-Date: 2007-01-30 12:49+0000\n"
     9.9  "Last-Translator: Ewan Mellor <ewan@xensource.com>\n"
    9.10  "Language-Team: xen-devel <xen-devel@lists.xensource.com>\n"
    9.11  "MIME-Version: 1.0\n"
    9.12 @@ -47,6 +47,9 @@ msgstr "The host_cpu handle %(1)s is inv
    9.13  msgid "HOST_HANDLE_INVALID"
    9.14  msgstr "The host handle %(1)s is invalid."
    9.15  
    9.16 +msgid "HOST_METRICS_HANDLE_INVALID"
    9.17 +msgstr "The host_metrics handle %(1)s is invalid."
    9.18 +
    9.19  msgid "PIF_HANDLE_INVALID"
    9.20  msgstr "The PIF handle %(1)s is invalid."
    9.21