ia64/xen-unstable

changeset 13191:c1aecee76db5

Fix plumbing for PIF calls. Change xen_api_success to convert None to the
empty string, to make it easier to write setters.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Mon Dec 25 16:56:46 2006 +0000 (2006-12-25)
parents c1fbe291b564
children 159ae46d5e7f
files tools/python/xen/xend/XendAPI.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Mon Dec 25 16:42:24 2006 +0000
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Mon Dec 25 16:56:46 2006 +0000
     1.3 @@ -43,7 +43,11 @@ argcounts = {}
     1.4  
     1.5  def xen_api_success(value):
     1.6      """Wraps a return value in XenAPI format."""
     1.7 -    return {"Status": "Success", "Value": stringify(value)}
     1.8 +    if value is None:
     1.9 +        s = ''
    1.10 +    else:
    1.11 +        s = stringify(value)
    1.12 +    return {"Status": "Success", "Value": s}
    1.13  
    1.14  def xen_api_success_void():
    1.15      """Return success, but caller expects no return value."""
    1.16 @@ -515,59 +519,49 @@ class XendAPI:
    1.17  
    1.18      PIF_attr_inst = PIF_attr_rw
    1.19  
    1.20 +    def _get_PIF(self, ref):
    1.21 +        return XendNode.instance().pifs[ref]
    1.22 +
    1.23      # object methods
    1.24 -    def PIF_get_record(self, session, pif_ref):
    1.25 -        node = XendNode.instance()
    1.26 -        return xen_api_success(node.pifs[pif_ref].get_record())
    1.27 +    def PIF_get_record(self, _, ref):
    1.28 +        return xen_api_success(self._get_PIF(ref).get_record())
    1.29  
    1.30 -    def PIF_get_all(self, session):
    1.31 +    def PIF_get_all(self, _):
    1.32          return xen_api_success(XendNode.instance().pifs.keys())
    1.33  
    1.34 -    def PIF_set_name(self, session, pif_ref, name):
    1.35 -        node = XendNode.instance()
    1.36 -        pif = node.pifs.get(pif_ref)
    1.37 -        if pif:
    1.38 -            pif.set_name(name)
    1.39 -        return xen_api_void()        
    1.40 -
    1.41 -    def PIF_set_mac(self, session, pif_ref, mac):
    1.42 -        node = XendNode.instance()
    1.43 -        pif = node.pifs.get(pif_ref)
    1.44 -        if pif:
    1.45 -            pif.set_mac(mac)
    1.46 -        return xen_api_void()
    1.47 -
    1.48 -    def PIF_set_mtu(self, session, pif_ref, mtu):
    1.49 -        node = XendNode.instance()
    1.50 -        pif = node.pifs.get(pif_ref)
    1.51 -        if pif:
    1.52 -            pif.set_mtu(mtu)
    1.53 -        return xen_api_void()    
    1.54 +    def PIF_get_name(self, session, ref):
    1.55 +        return xen_api_success(self._get_PIF(ref).name)
    1.56  
    1.57 -    def PIF_get_mac(self, session, pif_ref):
    1.58 -        node = XendNode.instance()
    1.59 -        return xen_api_success(node.pifs[pif_ref].get_mac())
    1.60 -
    1.61 -    def PIF_get_mtu(self, session, pif_ref):
    1.62 -        node = XendNode.instance()
    1.63 -        return xen_api_success(node.pifs[pif_ref].get_mtu())
    1.64 -
    1.65 -    def PIF_get_vlan(self, session, pif_ref):
    1.66 -        node = XendNode.instance()
    1.67 -        return xen_api_success(node.pifs[pif_ref].get_vlan())
    1.68 +    def PIF_get_network(self, session, ref):
    1.69 +        return xen_api_success(self._get_PIF(ref).network.uuid)
    1.70  
    1.71 -    def PIF_get_name(self, session, pif_ref):
    1.72 -        node = XendNode.instance()
    1.73 -        return xen_api_success(node.pifs[pif_ref].get_name())
    1.74 +    def PIF_get_host(self, session, ref):
    1.75 +        return xen_api_success(self._get_PIF(ref).host.uuid)
    1.76  
    1.77 -    def PIF_get_io_read_kbs(self, session, pif_ref):
    1.78 -        node = XendNode.instance()
    1.79 -        return xen_api_success(node.pifs[pif_ref].get_io_read_kbs())
    1.80 +    def PIF_get_MAC(self, session, ref):
    1.81 +        return xen_api_success(self._get_PIF(ref).mac)
    1.82  
    1.83 -    def PIF_get_io_write_kbs(self, session, pif_ref):
    1.84 -        node = XendNode.instance()
    1.85 -        return xen_api_success(node.pifs[pif_ref].get_io_write_kbs())    
    1.86 +    def PIF_get_MTU(self, session, ref):
    1.87 +        return xen_api_success(self._get_PIF(ref).mtu)
    1.88 +
    1.89 +    def PIF_get_VLAN(self, session, ref):
    1.90 +        return xen_api_success(self._get_PIF(ref).vlan)
    1.91 +
    1.92 +    def PIF_get_io_read_kbs(self, session, ref):
    1.93 +        return xen_api_success(self._get_PIF(ref).get_io_read_kbs())
    1.94 +
    1.95 +    def PIF_get_io_write_kbs(self, session, ref):
    1.96 +        return xen_api_success(self._get_PIF(ref).get_io_write_kbs())
    1.97      
    1.98 +    def PIF_set_name(self, _, ref, name):
    1.99 +        return xen_api_success(self._get_PIF(ref).set_name(name))
   1.100 +
   1.101 +    def PIF_set_MAC(self, session, ref, mac):
   1.102 +        return xen_api_success(self._get_PIF(ref).set_mac(name))
   1.103 +
   1.104 +    def PIF_set_MTU(self, session, ref, mtu):
   1.105 +        return xen_api_success(self._get_PIF(ref).set_mtu(name))
   1.106 +
   1.107  
   1.108      # Xen API: Class VM
   1.109      # ----------------------------------------------------------------