ia64/xen-unstable

changeset 14737:e5931b5e6cc5

Remove docs and bindings for unimplemented SR.{create,destroy,clone}.
Implement PBD class, matching existing docs and bindings.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Apr 04 14:49:38 2007 +0100 (2007-04-04)
parents 14c25e48a557
children 610dcfb3c164
files docs/xen-api/xenapi-datamodel.tex tools/libxen/include/xen_sr.h tools/libxen/src/xen_sr.c tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendLocalStorageRepo.py tools/python/xen/xend/XendNode.py tools/python/xen/xend/XendPBD.py tools/python/xen/xend/XendQCoWStorageRepo.py tools/python/xen/xend/XendStateStore.py tools/python/xen/xend/XendStorageRepository.py
line diff
     1.1 --- a/docs/xen-api/xenapi-datamodel.tex	Thu Apr 05 09:10:33 2007 +0100
     1.2 +++ b/docs/xen-api/xenapi-datamodel.tex	Wed Apr 04 14:49:38 2007 +0100
     1.3 @@ -9190,51 +9190,35 @@ Quals & Field & Type & Description \\
     1.4  $\mathit{RO}_\mathit{run}$ &  {\tt physical\_utilisation} & int & physical space currently utilised on this storage repository (in bytes). Note that for sparse disk formats, physical\_utilisation may be less than virtual\_allocation \\
     1.5  $\mathit{RO}_\mathit{ins}$ &  {\tt physical\_size} & int & total physical size of the repository (in bytes) \\
     1.6  $\mathit{RO}_\mathit{ins}$ &  {\tt type} & string & type of the storage repository \\
     1.7 -$\mathit{RO}_\mathit{ins}$ &  {\tt location} & string & a string that uniquely determines the location of the storage repository; the format of this string depends on the repository's type \\
     1.8 +$\mathit{RO}_\mathit{ins}$ &  {\tt content\_type} & string & the type of the SR's content, if required (e.g. ISOs) \\
     1.9  \hline
    1.10  \end{longtable}
    1.11  \subsection{RPCs associated with class: SR}
    1.12 -\subsubsection{RPC name:~clone}
    1.13 -
    1.14 -{\bf Overview:} 
    1.15 -Take an exact copy of the Storage Repository;
    1.16 -        the cloned storage repository has the same type as its parent
    1.17 -
    1.18 - \noindent {\bf Signature:} 
    1.19 -\begin{verbatim} (SR ref) clone (session_id s, SR ref sr, string loc, string name)\end{verbatim}
    1.20 -
    1.21 -
    1.22 -\noindent{\bf Arguments:}
    1.23 -
    1.24 - 
    1.25 -\vspace{0.3cm}
    1.26 -\begin{tabular}{|c|c|p{7cm}|}
    1.27 - \hline
    1.28 -{\bf type} & {\bf name} & {\bf description} \\ \hline
    1.29 -{\tt SR ref } & sr & The Storage Repository to clone \\ \hline 
    1.30 -
    1.31 -{\tt string } & loc & The location string that defines where the new storage repository will be located \\ \hline 
    1.32 -
    1.33 -{\tt string } & name & The name of the new storage repository \\ \hline 
    1.34 -
    1.35 -\end{tabular}
    1.36 -
    1.37 -\vspace{0.3cm}
    1.38 -
    1.39 - \noindent {\bf Return Type:} 
    1.40 -{\tt 
    1.41 -SR ref
    1.42 -}
    1.43 -
    1.44 -
    1.45 -The ID of the newly created Storage Repository.
    1.46 +\subsubsection{RPC name:~get\_supported\_types}
    1.47 +
    1.48 +{\bf Overview:} 
    1.49 +Return a set of all the SR types supported by the system.
    1.50 +
    1.51 + \noindent {\bf Signature:} 
    1.52 +\begin{verbatim} (string Set) get_supported_types (session_id s)\end{verbatim}
    1.53 +
    1.54 +
    1.55 +\vspace{0.3cm}
    1.56 +
    1.57 + \noindent {\bf Return Type:} 
    1.58 +{\tt 
    1.59 +string Set
    1.60 +}
    1.61 +
    1.62 +
    1.63 +the supported SR types
    1.64  \vspace{0.3cm}
    1.65  \vspace{0.3cm}
    1.66  \vspace{0.3cm}
    1.67  \subsubsection{RPC name:~get\_all}
    1.68  
    1.69  {\bf Overview:} 
    1.70 -Return a list of all the Storage Repositories known to the system
    1.71 +Return a list of all the SRs known to the system.
    1.72  
    1.73   \noindent {\bf Signature:} 
    1.74  \begin{verbatim} ((SR ref) Set) get_all (session_id s)\end{verbatim}
    1.75 @@ -9248,7 +9232,7 @@ Return a list of all the Storage Reposit
    1.76  }
    1.77  
    1.78  
    1.79 -A list of all the IDs of all the Storage Repositories
    1.80 +references to all objects
    1.81  \vspace{0.3cm}
    1.82  \vspace{0.3cm}
    1.83  \vspace{0.3cm}
    1.84 @@ -9608,13 +9592,13 @@ value of the field
    1.85  \vspace{0.3cm}
    1.86  \vspace{0.3cm}
    1.87  \vspace{0.3cm}
    1.88 -\subsubsection{RPC name:~get\_location}
    1.89 -
    1.90 -{\bf Overview:} 
    1.91 -Get the location field of the given SR.
    1.92 -
    1.93 - \noindent {\bf Signature:} 
    1.94 -\begin{verbatim} string get_location (session_id s, SR ref self)\end{verbatim}
    1.95 +\subsubsection{RPC name:~get\_content\_type}
    1.96 +
    1.97 +{\bf Overview:} 
    1.98 +Get the content\_type field of the given SR.
    1.99 +
   1.100 + \noindent {\bf Signature:} 
   1.101 +\begin{verbatim} string get_content_type (session_id s, SR ref self)\end{verbatim}
   1.102  
   1.103  
   1.104  \noindent{\bf Arguments:}
   1.105 @@ -9640,70 +9624,6 @@ value of the field
   1.106  \vspace{0.3cm}
   1.107  \vspace{0.3cm}
   1.108  \vspace{0.3cm}
   1.109 -\subsubsection{RPC name:~create}
   1.110 -
   1.111 -{\bf Overview:} 
   1.112 -Create a new SR instance, and return its handle.
   1.113 -
   1.114 - \noindent {\bf Signature:} 
   1.115 -\begin{verbatim} (SR ref) create (session_id s, SR record args)\end{verbatim}
   1.116 -
   1.117 -
   1.118 -\noindent{\bf Arguments:}
   1.119 -
   1.120 - 
   1.121 -\vspace{0.3cm}
   1.122 -\begin{tabular}{|c|c|p{7cm}|}
   1.123 - \hline
   1.124 -{\bf type} & {\bf name} & {\bf description} \\ \hline
   1.125 -{\tt SR record } & args & All constructor arguments \\ \hline 
   1.126 -
   1.127 -\end{tabular}
   1.128 -
   1.129 -\vspace{0.3cm}
   1.130 -
   1.131 - \noindent {\bf Return Type:} 
   1.132 -{\tt 
   1.133 -SR ref
   1.134 -}
   1.135 -
   1.136 -
   1.137 -reference to the newly created object
   1.138 -\vspace{0.3cm}
   1.139 -\vspace{0.3cm}
   1.140 -\vspace{0.3cm}
   1.141 -\subsubsection{RPC name:~destroy}
   1.142 -
   1.143 -{\bf Overview:} 
   1.144 -Destroy the specified SR instance.
   1.145 -
   1.146 - \noindent {\bf Signature:} 
   1.147 -\begin{verbatim} void destroy (session_id s, SR ref self)\end{verbatim}
   1.148 -
   1.149 -
   1.150 -\noindent{\bf Arguments:}
   1.151 -
   1.152 - 
   1.153 -\vspace{0.3cm}
   1.154 -\begin{tabular}{|c|c|p{7cm}|}
   1.155 - \hline
   1.156 -{\bf type} & {\bf name} & {\bf description} \\ \hline
   1.157 -{\tt SR ref } & self & reference to the object \\ \hline 
   1.158 -
   1.159 -\end{tabular}
   1.160 -
   1.161 -\vspace{0.3cm}
   1.162 -
   1.163 - \noindent {\bf Return Type:} 
   1.164 -{\tt 
   1.165 -void
   1.166 -}
   1.167 -
   1.168 -
   1.169 -
   1.170 -\vspace{0.3cm}
   1.171 -\vspace{0.3cm}
   1.172 -\vspace{0.3cm}
   1.173  \subsubsection{RPC name:~get\_by\_uuid}
   1.174  
   1.175  {\bf Overview:} 
   1.176 @@ -11988,7 +11908,7 @@ Quals & Field & Type & Description \\
   1.177  $\mathit{RO}_\mathit{run}$ &  {\tt uuid} & string & unique identifier/object reference \\
   1.178  $\mathit{RO}_\mathit{ins}$ &  {\tt host} & host ref & physical machine on which the pbd is available \\
   1.179  $\mathit{RO}_\mathit{ins}$ &  {\tt SR} & SR ref & the storage repository that the pbd realises \\
   1.180 -$\mathit{RO}_\mathit{ins}$ &  {\tt device\_config} & (string $\rightarrow$ string) Map & a config string that is provided to the host's SR-backend-driver \\
   1.181 +$\mathit{RO}_\mathit{ins}$ &  {\tt device\_config} & (string $\rightarrow$ string) Map & a config string to string map that is provided to the host's SR-backend-driver \\
   1.182  $\mathit{RO}_\mathit{run}$ &  {\tt currently\_attached} & bool & is the SR currently attached on this host? \\
   1.183  \hline
   1.184  \end{longtable}
     2.1 --- a/tools/libxen/include/xen_sr.h	Thu Apr 05 09:10:33 2007 +0100
     2.2 +++ b/tools/libxen/include/xen_sr.h	Wed Apr 04 14:49:38 2007 +0100
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 2006, XenSource Inc.
     2.6 + * Copyright (c) 2006-2007, XenSource Inc.
     2.7   *
     2.8   * This library is free software; you can redistribute it and/or
     2.9   * modify it under the terms of the GNU Lesser General Public
    2.10 @@ -22,6 +22,7 @@
    2.11  #include "xen_common.h"
    2.12  #include "xen_pbd_decl.h"
    2.13  #include "xen_sr_decl.h"
    2.14 +#include "xen_string_set.h"
    2.15  #include "xen_vdi_decl.h"
    2.16  
    2.17  
    2.18 @@ -72,7 +73,7 @@ typedef struct xen_sr_record
    2.19      int64_t physical_utilisation;
    2.20      int64_t physical_size;
    2.21      char *type;
    2.22 -    char *location;
    2.23 +    char *content_type;
    2.24  } xen_sr_record;
    2.25  
    2.26  /**
    2.27 @@ -169,20 +170,6 @@ xen_sr_get_by_uuid(xen_session *session,
    2.28  
    2.29  
    2.30  /**
    2.31 - * Create a new SR instance, and return its handle.
    2.32 - */
    2.33 -extern bool
    2.34 -xen_sr_create(xen_session *session, xen_sr *result, xen_sr_record *record);
    2.35 -
    2.36 -
    2.37 -/**
    2.38 - * Destroy the specified SR instance.
    2.39 - */
    2.40 -extern bool
    2.41 -xen_sr_destroy(xen_session *session, xen_sr sr);
    2.42 -
    2.43 -
    2.44 -/**
    2.45   * Get all the SR instances with the given label.
    2.46   */
    2.47  extern bool
    2.48 @@ -253,10 +240,10 @@ xen_sr_get_type(xen_session *session, ch
    2.49  
    2.50  
    2.51  /**
    2.52 - * Get the location field of the given SR.
    2.53 + * Get the content_type field of the given SR.
    2.54   */
    2.55  extern bool
    2.56 -xen_sr_get_location(xen_session *session, char **result, xen_sr sr);
    2.57 +xen_sr_get_content_type(xen_session *session, char **result, xen_sr sr);
    2.58  
    2.59  
    2.60  /**
    2.61 @@ -274,11 +261,10 @@ xen_sr_set_name_description(xen_session 
    2.62  
    2.63  
    2.64  /**
    2.65 - * Take an exact copy of the Storage Repository; the cloned storage
    2.66 - * repository has the same type as its parent
    2.67 + * Return a set of all the SR types supported by the system.
    2.68   */
    2.69  extern bool
    2.70 -xen_sr_clone(xen_session *session, xen_sr *result, xen_sr sr, char *loc, char *name);
    2.71 +xen_sr_get_supported_types(xen_session *session, struct xen_string_set **result);
    2.72  
    2.73  
    2.74  /**
     3.1 --- a/tools/libxen/src/xen_sr.c	Thu Apr 05 09:10:33 2007 +0100
     3.2 +++ b/tools/libxen/src/xen_sr.c	Wed Apr 04 14:49:38 2007 +0100
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 2006, XenSource Inc.
     3.6 + * Copyright (c) 2006-2007, XenSource Inc.
     3.7   *
     3.8   * This library is free software; you can redistribute it and/or
     3.9   * modify it under the terms of the GNU Lesser General Public
    3.10 @@ -65,9 +65,9 @@ static const struct_member xen_sr_record
    3.11          { .key = "type",
    3.12            .type = &abstract_type_string,
    3.13            .offset = offsetof(xen_sr_record, type) },
    3.14 -        { .key = "location",
    3.15 +        { .key = "content_type",
    3.16            .type = &abstract_type_string,
    3.17 -          .offset = offsetof(xen_sr_record, location) }
    3.18 +          .offset = offsetof(xen_sr_record, content_type) }
    3.19      };
    3.20  
    3.21  const abstract_type xen_sr_record_abstract_type_ =
    3.22 @@ -94,7 +94,7 @@ xen_sr_record_free(xen_sr_record *record
    3.23      xen_vdi_record_opt_set_free(record->vdis);
    3.24      xen_pbd_record_opt_set_free(record->pbds);
    3.25      free(record->type);
    3.26 -    free(record->location);
    3.27 +    free(record->content_type);
    3.28      free(record);
    3.29  }
    3.30  
    3.31 @@ -140,37 +140,6 @@ xen_sr_get_by_uuid(xen_session *session,
    3.32  
    3.33  
    3.34  bool
    3.35 -xen_sr_create(xen_session *session, xen_sr *result, xen_sr_record *record)
    3.36 -{
    3.37 -    abstract_value param_values[] =
    3.38 -        {
    3.39 -            { .type = &xen_sr_record_abstract_type_,
    3.40 -              .u.struct_val = record }
    3.41 -        };
    3.42 -
    3.43 -    abstract_type result_type = abstract_type_string;
    3.44 -
    3.45 -    *result = NULL;
    3.46 -    XEN_CALL_("SR.create");
    3.47 -    return session->ok;
    3.48 -}
    3.49 -
    3.50 -
    3.51 -bool
    3.52 -xen_sr_destroy(xen_session *session, xen_sr sr)
    3.53 -{
    3.54 -    abstract_value param_values[] =
    3.55 -        {
    3.56 -            { .type = &abstract_type_string,
    3.57 -              .u.string_val = sr }
    3.58 -        };
    3.59 -
    3.60 -    xen_call_(session, "SR.destroy", param_values, 1, NULL, NULL);
    3.61 -    return session->ok;
    3.62 -}
    3.63 -
    3.64 -
    3.65 -bool
    3.66  xen_sr_get_by_name_label(xen_session *session, struct xen_sr_set **result, char *label)
    3.67  {
    3.68      abstract_value param_values[] =
    3.69 @@ -239,6 +208,23 @@ xen_sr_get_vdis(xen_session *session, st
    3.70  
    3.71  
    3.72  bool
    3.73 +xen_sr_get_pbds(xen_session *session, struct xen_pbd_set **result, xen_sr sr)
    3.74 +{
    3.75 +    abstract_value param_values[] =
    3.76 +        {
    3.77 +            { .type = &abstract_type_string,
    3.78 +              .u.string_val = sr }
    3.79 +        };
    3.80 +
    3.81 +    abstract_type result_type = abstract_type_string_set;
    3.82 +
    3.83 +    *result = NULL;
    3.84 +    XEN_CALL_("SR.get_PBDs");
    3.85 +    return session->ok;
    3.86 +}
    3.87 +
    3.88 +
    3.89 +bool
    3.90  xen_sr_get_virtual_allocation(xen_session *session, int64_t *result, xen_sr sr)
    3.91  {
    3.92      abstract_value param_values[] =
    3.93 @@ -304,7 +290,7 @@ xen_sr_get_type(xen_session *session, ch
    3.94  
    3.95  
    3.96  bool
    3.97 -xen_sr_get_location(xen_session *session, char **result, xen_sr sr)
    3.98 +xen_sr_get_content_type(xen_session *session, char **result, xen_sr sr)
    3.99  {
   3.100      abstract_value param_values[] =
   3.101          {
   3.102 @@ -315,7 +301,7 @@ xen_sr_get_location(xen_session *session
   3.103      abstract_type result_type = abstract_type_string;
   3.104  
   3.105      *result = NULL;
   3.106 -    XEN_CALL_("SR.get_location");
   3.107 +    XEN_CALL_("SR.get_content_type");
   3.108      return session->ok;
   3.109  }
   3.110  
   3.111 @@ -353,22 +339,13 @@ xen_sr_set_name_description(xen_session 
   3.112  
   3.113  
   3.114  bool
   3.115 -xen_sr_clone(xen_session *session, xen_sr *result, xen_sr sr, char *loc, char *name)
   3.116 +xen_sr_get_supported_types(xen_session *session, struct xen_string_set **result)
   3.117  {
   3.118 -    abstract_value param_values[] =
   3.119 -        {
   3.120 -            { .type = &abstract_type_string,
   3.121 -              .u.string_val = sr },
   3.122 -            { .type = &abstract_type_string,
   3.123 -              .u.string_val = loc },
   3.124 -            { .type = &abstract_type_string,
   3.125 -              .u.string_val = name }
   3.126 -        };
   3.127  
   3.128 -    abstract_type result_type = abstract_type_string;
   3.129 +    abstract_type result_type = abstract_type_string_set;
   3.130  
   3.131      *result = NULL;
   3.132 -    XEN_CALL_("SR.clone");
   3.133 +    xen_call_(session, "SR.get_supported_types", NULL, 0, &result_type, result);
   3.134      return session->ok;
   3.135  }
   3.136  
     4.1 --- a/tools/python/xen/xend/XendAPI.py	Thu Apr 05 09:10:33 2007 +0100
     4.2 +++ b/tools/python/xen/xend/XendAPI.py	Wed Apr 04 14:49:38 2007 +0100
     4.3 @@ -26,20 +26,22 @@ import threading
     4.4  import time
     4.5  import xmlrpclib
     4.6  
     4.7 -from xen.xend import XendDomain, XendDomainInfo, XendNode, XendDmesg
     4.8 -from xen.xend import XendLogging, XendTaskManager
     4.9 -
    4.10 -from xen.xend.XendAPIVersion import *
    4.11 -from xen.xend.XendAuthSessions import instance as auth_manager
    4.12 -from xen.xend.XendError import *
    4.13 -from xen.xend.XendClient import ERROR_INVALID_DOMAIN
    4.14 -from xen.xend.XendLogging import log
    4.15 -from xen.xend.XendNetwork import XendNetwork
    4.16 -from xen.xend.XendTask import XendTask
    4.17 -from xen.xend.XendPIFMetrics import XendPIFMetrics
    4.18 -from xen.xend.XendVMMetrics import XendVMMetrics
    4.19 -
    4.20 -from xen.xend.XendAPIConstants import *
    4.21 +import XendDomain, XendDomainInfo, XendNode, XendDmesg
    4.22 +import XendLogging, XendTaskManager
    4.23 +
    4.24 +from XendAPIVersion import *
    4.25 +from XendAuthSessions import instance as auth_manager
    4.26 +from XendError import *
    4.27 +from XendClient import ERROR_INVALID_DOMAIN
    4.28 +from XendLogging import log
    4.29 +from XendNetwork import XendNetwork
    4.30 +from XendTask import XendTask
    4.31 +from XendPIFMetrics import XendPIFMetrics
    4.32 +from XendVMMetrics import XendVMMetrics
    4.33 +
    4.34 +import XendPBD
    4.35 +
    4.36 +from XendAPIConstants import *
    4.37  from xen.util.xmlrpclib2 import stringify
    4.38  
    4.39  from xen.util.blkif import blkdev_name_to_number
    4.40 @@ -394,6 +396,17 @@ def valid_sr(func):
    4.41             _check_ref(lambda r: XendNode.instance().is_valid_sr,
    4.42                        'SR', func, *args, **kwargs)
    4.43  
    4.44 +def valid_pbd(func):
    4.45 +    """Decorator to verify if pbd_ref is valid before calling
    4.46 +    method.
    4.47 +
    4.48 +    @param func: function with params: (self, session, pbd_ref)
    4.49 +    @rtype: callable object
    4.50 +    """
    4.51 +    return lambda *args, **kwargs: \
    4.52 +           _check_ref(lambda r: r in XendPBD.get_all_refs(),
    4.53 +                      'PBD', func, *args, **kwargs)
    4.54 +
    4.55  def valid_pif(func):
    4.56      """Decorator to verify if pif_ref is valid before calling
    4.57      method.
    4.58 @@ -479,6 +492,7 @@ classes = {
    4.59      'VTPM'         : valid_vtpm,
    4.60      'console'      : valid_console,
    4.61      'SR'           : valid_sr,
    4.62 +    'PBD'          : valid_pbd,
    4.63      'PIF'          : valid_pif,
    4.64      'PIF_metrics'  : valid_pif_metrics,
    4.65      'task'         : valid_task,
    4.66 @@ -488,6 +502,7 @@ classes = {
    4.67  autoplug_classes = {
    4.68      'network'     : XendNetwork,
    4.69      'VM_metrics'  : XendVMMetrics,
    4.70 +    'PBD'         : XendPBD.XendPBD,
    4.71      'PIF_metrics' : XendPIFMetrics,
    4.72  }
    4.73  
    4.74 @@ -843,6 +858,7 @@ class XendAPI(object):
    4.75  
    4.76      host_attr_ro = ['software_version',
    4.77                      'resident_VMs',
    4.78 +                    'PBDs',
    4.79                      'PIFs',
    4.80                      'host_CPUs',
    4.81                      'cpu_configuration',
    4.82 @@ -913,6 +929,8 @@ class XendAPI(object):
    4.83          return xen_api_success(XendNode.instance().xen_version())
    4.84      def host_get_resident_VMs(self, session, host_ref):
    4.85          return xen_api_success(XendDomain.instance().get_domain_refs())
    4.86 +    def host_get_PBDs(self, _, ref):
    4.87 +        return xen_api_success(XendPBD.get_all_refs())
    4.88      def host_get_PIFs(self, session, ref):
    4.89          return xen_api_success(XendNode.instance().get_PIF_refs())
    4.90      def host_get_host_CPUs(self, session, host_ref):
    4.91 @@ -2434,18 +2452,17 @@ class XendAPI(object):
    4.92                    'physical_utilisation',
    4.93                    'physical_size',
    4.94                    'type',
    4.95 -                  'location']
    4.96 +                  'content_type']
    4.97      
    4.98      SR_attr_rw = ['name_label',
    4.99                    'name_description']
   4.100      
   4.101      SR_attr_inst = ['physical_size',
   4.102                      'type',
   4.103 -                    'location',
   4.104                      'name_label',
   4.105                      'name_description']
   4.106      
   4.107 -    SR_methods = [('clone', 'SR'), ('destroy', None)]
   4.108 +    SR_methods = []
   4.109      SR_funcs = [('get_by_name_label', 'Set(SR)'),
   4.110                  ('get_by_uuid', 'SR')]
   4.111  
   4.112 @@ -2456,15 +2473,10 @@ class XendAPI(object):
   4.113      def SR_get_by_name_label(self, session, label):
   4.114          return xen_api_success(XendNode.instance().get_sr_by_name(label))
   4.115      
   4.116 -    def SR_create(self, session):
   4.117 -        return xen_api_error(XEND_ERROR_UNSUPPORTED)
   4.118 +    def SR_get_supported_types(self, _):
   4.119 +        return xen_api_success(['local', 'qcow_file'])
   4.120  
   4.121      # Class Methods
   4.122 -    def SR_clone(self, session, sr_ref):
   4.123 -        return xen_api_error(XEND_ERROR_UNSUPPORTED)
   4.124 -    
   4.125 -    def SR_destroy(self, session, sr_ref):
   4.126 -        return xen_api_error(XEND_ERROR_UNSUPPORTED)
   4.127      
   4.128      def SR_get_record(self, session, sr_ref):
   4.129          sr = XendNode.instance().get_sr(sr_ref)
   4.130 @@ -2497,8 +2509,8 @@ class XendAPI(object):
   4.131      def SR_get_type(self, _, ref):
   4.132          return self._get_SR_attr(ref, 'type')
   4.133  
   4.134 -    def SR_get_location(self, _, ref):
   4.135 -        return self._get_SR_attr(ref, 'location')
   4.136 +    def SR_get_content_type(self, _, ref):
   4.137 +        return self._get_SR_attr(ref, 'content_type')
   4.138  
   4.139      def SR_get_name_label(self, _, ref):
   4.140          return self._get_SR_attr(ref, 'name_label')
   4.141 @@ -2521,6 +2533,33 @@ class XendAPI(object):
   4.142          return xen_api_success_void()
   4.143  
   4.144  
   4.145 +    # Xen API: Class PBD
   4.146 +    # ----------------------------------------------------------------
   4.147 +
   4.148 +    PBD_attr_ro = ['host',
   4.149 +                   'SR',
   4.150 +                   'device_config',
   4.151 +                   'currently_attached']
   4.152 +    PBD_attr_rw = []
   4.153 +    PBD_methods = [('destroy', None)]
   4.154 +    PBD_funcs   = [('create', None)]
   4.155 +
   4.156 +    def PBD_get_all(self, _):
   4.157 +        return xen_api_success(XendPBD.get_all_refs())
   4.158 +
   4.159 +    def _PBD_get(self, _, ref):
   4.160 +        return XendPBD.get(ref)
   4.161 +
   4.162 +    def PBD_create(self, _, record):
   4.163 +        if 'uuid' in record:
   4.164 +            return xen_api_error(['VALUE_NOT_SUPPORTED',
   4.165 +                                  'uuid', record['uuid'],
   4.166 +                                  'You may not specify a UUID on creation'])
   4.167 +        new_uuid = XendPBD.XendPBD(record).get_uuid()
   4.168 +        XendNode.instance().save()
   4.169 +        return xen_api_success(new_uuid)
   4.170 +
   4.171 +
   4.172      # Xen API: Class event
   4.173      # ----------------------------------------------------------------
   4.174  
     5.1 --- a/tools/python/xen/xend/XendLocalStorageRepo.py	Thu Apr 05 09:10:33 2007 +0100
     5.2 +++ b/tools/python/xen/xend/XendLocalStorageRepo.py	Wed Apr 04 14:49:38 2007 +0100
     5.3 @@ -30,13 +30,13 @@ import sys
     5.4  import struct
     5.5  
     5.6  from xen.util import mkdir
     5.7 -from xen.xend import uuid
     5.8 -from xen.xend.XendError import XendError
     5.9 -from xen.xend.XendVDI import *
    5.10 -from xen.xend.XendTask import XendTask
    5.11 -from xen.xend.XendStorageRepository import XendStorageRepository
    5.12 -from xen.xend.XendStateStore import XendStateStore
    5.13 -from xen.xend.XendOptions import instance as xendoptions
    5.14 +import uuid
    5.15 +from XendError import XendError
    5.16 +from XendVDI import *
    5.17 +from XendTask import XendTask
    5.18 +from XendStorageRepository import XendStorageRepository
    5.19 +from XendStateStore import XendStateStore
    5.20 +from XendOptions import instance as xendoptions
    5.21  
    5.22  MB = 1024 * 1024
    5.23  
    5.24 @@ -58,8 +58,7 @@ class XendLocalStorageRepo(XendStorageRe
    5.25          """
    5.26  
    5.27          XendStorageRepository.__init__(self, sr_uuid, sr_type,
    5.28 -                                       name_label, name_description,
    5.29 -                                       '/')
    5.30 +                                       name_label, name_description)
    5.31          
    5.32          self.state = XendStateStore(xendoptions().get_xend_state_path()
    5.33                                      + '/local_sr')
     6.1 --- a/tools/python/xen/xend/XendNode.py	Thu Apr 05 09:10:33 2007 +0100
     6.2 +++ b/tools/python/xen/xend/XendNode.py	Wed Apr 04 14:49:38 2007 +0100
     6.3 @@ -22,17 +22,18 @@ import xen.lowlevel.xc
     6.4  
     6.5  from xen.util import Brctl
     6.6  
     6.7 -from xen.xend import uuid, arch
     6.8 -from xen.xend.XendError import *
     6.9 -from xen.xend.XendOptions import instance as xendoptions
    6.10 -from xen.xend.XendQCoWStorageRepo import XendQCoWStorageRepo
    6.11 -from xen.xend.XendLocalStorageRepo import XendLocalStorageRepo
    6.12 -from xen.xend.XendLogging import log
    6.13 -from xen.xend.XendPIF import *
    6.14 -from xen.xend.XendPIFMetrics import XendPIFMetrics
    6.15 -from xen.xend.XendNetwork import *
    6.16 -from xen.xend.XendStateStore import XendStateStore
    6.17 -from xen.xend.XendMonitor import XendMonitor
    6.18 +import uuid, arch
    6.19 +import XendPBD
    6.20 +from XendError import *
    6.21 +from XendOptions import instance as xendoptions
    6.22 +from XendQCoWStorageRepo import XendQCoWStorageRepo
    6.23 +from XendLocalStorageRepo import XendLocalStorageRepo
    6.24 +from XendLogging import log
    6.25 +from XendPIF import *
    6.26 +from XendPIFMetrics import XendPIFMetrics
    6.27 +from XendNetwork import *
    6.28 +from XendStateStore import XendStateStore
    6.29 +from XendMonitor import XendMonitor
    6.30  
    6.31  class XendNode:
    6.32      """XendNode - Represents a Domain 0 Host."""
    6.33 @@ -193,13 +194,14 @@ class XendNode:
    6.34          saved_srs = self.state_store.load_state('sr')
    6.35          if saved_srs:
    6.36              for sr_uuid, sr_cfg in saved_srs.items():
    6.37 +                log.error("SAved SRS %s %s", sr_uuid, sr_cfg['type'])
    6.38                  if sr_cfg['type'] == 'qcow_file':
    6.39                      self.srs[sr_uuid] = XendQCoWStorageRepo(sr_uuid)
    6.40 -                elif sr_cfg['type'] == 'local_image':
    6.41 +                elif sr_cfg['type'] == 'local':
    6.42                      self.srs[sr_uuid] = XendLocalStorageRepo(sr_uuid)
    6.43  
    6.44          # Create missing SRs if they don't exist
    6.45 -        if not self.get_sr_by_type('local_image'):
    6.46 +        if not self.get_sr_by_type('local'):
    6.47              image_sr_uuid = uuid.createString()
    6.48              self.srs[image_sr_uuid] = XendLocalStorageRepo(image_sr_uuid)
    6.49              
    6.50 @@ -207,6 +209,11 @@ class XendNode:
    6.51              qcow_sr_uuid = uuid.createString()
    6.52              self.srs[qcow_sr_uuid] = XendQCoWStorageRepo(qcow_sr_uuid)
    6.53  
    6.54 +        saved_pbds = self.state_store.load_state('pbd')
    6.55 +        if saved_pbds:
    6.56 +            for pbd_uuid, pbd_cfg in saved_pbds.items():
    6.57 +                pbd_cfg['uuid'] = pbd_uuid
    6.58 +                XendPBD.XendPBD(pbd_cfg)
    6.59  
    6.60  
    6.61      def network_create(self, record, persist = True, net_uuid = None):
    6.62 @@ -280,6 +287,7 @@ class XendNode:
    6.63          self.state_store.save_state('cpu', self.cpus)
    6.64          self.save_PIFs()
    6.65          self.save_networks()
    6.66 +        self.save_PBDs()
    6.67          self.save_SRs()
    6.68  
    6.69      def save_PIFs(self):
    6.70 @@ -292,6 +300,11 @@ class XendNode:
    6.71                              for k, v in self.networks.items()])
    6.72          self.state_store.save_state('network', net_records)
    6.73  
    6.74 +    def save_PBDs(self):
    6.75 +        pbd_records = dict([(v.get_uuid(), v.get_record())
    6.76 +                            for v in XendPBD.get_all()])
    6.77 +        self.state_store.save_state('pbd', pbd_records)
    6.78 +
    6.79      def save_SRs(self):
    6.80          sr_records = dict([(k, v.get_record(transient = False))
    6.81                              for k, v in self.srs.items()])
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/python/xen/xend/XendPBD.py	Wed Apr 04 14:49:38 2007 +0100
     7.3 @@ -0,0 +1,79 @@
     7.4 +#============================================================================
     7.5 +# This library is free software; you can redistribute it and/or
     7.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
     7.7 +# License as published by the Free Software Foundation.
     7.8 +#
     7.9 +# This library is distributed in the hope that it will be useful,
    7.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.12 +# Lesser General Public License for more details.
    7.13 +#
    7.14 +# You should have received a copy of the GNU Lesser General Public
    7.15 +# License along with this library; if not, write to the Free Software
    7.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.17 +#============================================================================
    7.18 +# Copyright (c) 2007 Xensource Inc.
    7.19 +#============================================================================
    7.20 +
    7.21 +
    7.22 +import uuid
    7.23 +from XendLogging import log
    7.24 +
    7.25 +
    7.26 +attr_inst = ['uuid',
    7.27 +             'host',
    7.28 +             'SR',
    7.29 +             'device_config']
    7.30 +attr_ro = attr_inst + ['currently_attached']
    7.31 +
    7.32 +
    7.33 +_all = {}
    7.34 +
    7.35 +
    7.36 +def get(ref):
    7.37 +    return _all[ref]
    7.38 +
    7.39 +
    7.40 +def get_all():
    7.41 +    return _all.values()
    7.42 +
    7.43 +
    7.44 +def get_all_refs():
    7.45 +    return _all.keys()
    7.46 +
    7.47 +
    7.48 +def get_by_SR(sr_ref):
    7.49 +    return [k for (k, v) in _all.items() if v.get_SR() == sr_ref]
    7.50 +
    7.51 +
    7.52 +class XendPBD:
    7.53 +    """Physical block devices."""
    7.54 +    
    7.55 +    def __init__(self, record):
    7.56 +        if 'uuid' not in record:
    7.57 +            record['uuid'] = uuid.createString()
    7.58 +
    7.59 +        import XendAPI
    7.60 +        for v in attr_inst:
    7.61 +            setattr(self, v, record[v])
    7.62 +        self.currently_attached = True
    7.63 +        _all[record['uuid']] = self
    7.64 +
    7.65 +
    7.66 +    def destroy(self):
    7.67 +        if self.uuid in _all:
    7.68 +            del _all[self.uuid]
    7.69 +
    7.70 +
    7.71 +    def get_record(self):
    7.72 +        import XendAPI
    7.73 +        result = {}
    7.74 +        for v in attr_ro:
    7.75 +            result[v] = getattr(self, v)
    7.76 +        return result
    7.77 +
    7.78 +
    7.79 +for v in attr_ro:
    7.80 +    def f(v_):
    7.81 +        setattr(XendPBD, 'get_' + v_, lambda s: getattr(s, v_))
    7.82 +    f(v)
     8.1 --- a/tools/python/xen/xend/XendQCoWStorageRepo.py	Thu Apr 05 09:10:33 2007 +0100
     8.2 +++ b/tools/python/xen/xend/XendQCoWStorageRepo.py	Wed Apr 04 14:49:38 2007 +0100
     8.3 @@ -29,12 +29,13 @@ import sys
     8.4  import struct
     8.5  
     8.6  from xen.util import mkdir
     8.7 -from xen.xend import uuid
     8.8 -from xen.xend.XendError import XendError
     8.9 -from xen.xend.XendVDI import *
    8.10 -from xen.xend.XendTask import XendTask
    8.11 -from xen.xend.XendStorageRepository import XendStorageRepository
    8.12 -from xen.xend.XendOptions import instance as xendoptions
    8.13 +import uuid
    8.14 +import XendPBD
    8.15 +from XendError import XendError
    8.16 +from XendVDI import *
    8.17 +from XendTask import XendTask
    8.18 +from XendStorageRepository import XendStorageRepository
    8.19 +from XendOptions import instance as xendoptions
    8.20  
    8.21  XEND_STORAGE_NO_MAXIMUM = sys.maxint
    8.22  XEND_STORAGE_QCOW_FILENAME = "%s.qcow"
    8.23 @@ -72,7 +73,6 @@ class XendQCoWStorageRepo(XendStorageRep
    8.24                   sr_type = "qcow_file",
    8.25                   name_label = "QCoW",
    8.26                   name_description = "Xend QCoW Storage Repository",
    8.27 -                 location = xendoptions().get_xend_storage_path(),
    8.28                   storage_max = XEND_STORAGE_NO_MAXIMUM):
    8.29          """
    8.30          @keyword storage_max: Maximum disk space to use in bytes.
    8.31 @@ -85,9 +85,9 @@ class XendQCoWStorageRepo(XendStorageRep
    8.32          """
    8.33  
    8.34          XendStorageRepository.__init__(self, sr_uuid, sr_type, name_label,
    8.35 -                                       name_description, location,
    8.36 -                                       storage_max)
    8.37 +                                       name_description, storage_max)
    8.38          self.storage_free = 0
    8.39 +        self.location = xendoptions().get_xend_storage_path()
    8.40          self._refresh()
    8.41  
    8.42      def get_record(self, transient = True):
    8.43 @@ -98,8 +98,9 @@ class XendQCoWStorageRepo(XendStorageRep
    8.44                    'physical_utilisation': self.physical_utilisation,
    8.45                    'physical_size': self.physical_size,
    8.46                    'type': self.type,
    8.47 -                  'location': self.location,
    8.48 -                  'VDIs': self.images.keys()}
    8.49 +                  'content_type': self.content_type,
    8.50 +                  'VDIs': self.images.keys(),
    8.51 +                  'PBDs': XendPBD.get_by_SR(self.uuid)}
    8.52          
    8.53          if self.physical_size == XEND_STORAGE_NO_MAXIMUM:
    8.54              stfs = os.statvfs(self.location)
     9.1 --- a/tools/python/xen/xend/XendStateStore.py	Thu Apr 05 09:10:33 2007 +0100
     9.2 +++ b/tools/python/xen/xend/XendStateStore.py	Wed Apr 04 14:49:38 2007 +0100
     9.3 @@ -204,7 +204,7 @@ class XendStateStore:
     9.4                  if type(val) == dict:
     9.5                      for val_uuid in val.keys():
     9.6                          val_node = doc.createElement(key)
     9.7 -                        if key == 'other_config':
     9.8 +                        if key in ['other_config', 'device_config']:
     9.9                              val_node.setAttribute('key', str(val_uuid))
    9.10                              val_node.setAttribute('value', str(val[val_uuid]))
    9.11                          else:
    10.1 --- a/tools/python/xen/xend/XendStorageRepository.py	Thu Apr 05 09:10:33 2007 +0100
    10.2 +++ b/tools/python/xen/xend/XendStorageRepository.py	Wed Apr 04 14:49:38 2007 +0100
    10.3 @@ -22,8 +22,9 @@
    10.4  import threading
    10.5  import sys
    10.6  
    10.7 -from xen.xend.XendError import XendError
    10.8 -from xen.xend.XendVDI import *
    10.9 +from XendError import XendError
   10.10 +from XendVDI import *
   10.11 +import XendPBD
   10.12  
   10.13  XEND_STORAGE_NO_MAXIMUM = sys.maxint
   10.14  
   10.15 @@ -34,7 +35,6 @@ class XendStorageRepository:
   10.16                   sr_type = "unknown",
   10.17                   name_label = 'Unknown',
   10.18                   name_description = 'Not Implemented',
   10.19 -                 location = '',
   10.20                   storage_max = XEND_STORAGE_NO_MAXIMUM):
   10.21          """
   10.22          @keyword storage_max: Maximum disk space to use in bytes.
   10.23 @@ -49,7 +49,6 @@ class XendStorageRepository:
   10.24          # XenAPI Parameters
   10.25          self.uuid = uuid
   10.26          self.type = sr_type
   10.27 -        self.location = location
   10.28          self.name_label = name_label
   10.29          self.name_description = name_description
   10.30          self.images = {}
   10.31 @@ -57,6 +56,7 @@ class XendStorageRepository:
   10.32          self.physical_size = storage_max
   10.33          self.physical_utilisation = 0
   10.34          self.virtual_allocation = 0
   10.35 +        self.content_type = ''
   10.36   
   10.37          self.lock = threading.RLock()
   10.38  
   10.39 @@ -68,9 +68,10 @@ class XendStorageRepository:
   10.40                    'physical_utilisation': self.physical_utilisation,
   10.41                    'physical_size': self.physical_size,
   10.42                    'type': self.type,
   10.43 -                  'location': self.location,
   10.44 +                  'content_type': self.content_type,
   10.45                    'VDIs': self.images.keys()}
   10.46 -
   10.47 +        if not transient:
   10.48 +            retval ['PBDs'] = XendPBD.get_by_SR(self.uuid)
   10.49          return retval
   10.50  
   10.51