ia64/xen-unstable

changeset 14955:16e38247dee8

Add network.destroy() to XenAPI

signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Tom Wilkie <tom.wilkie@gmail.com>
date Thu Apr 26 15:39:30 2007 +0100 (2007-04-26)
parents 58205257517d
children a9b9847d97bb
files tools/python/xen/xend/XendBase.py tools/python/xen/xend/XendError.py tools/python/xen/xend/XendNetwork.py tools/python/xen/xm/messages/en/xen-xm.po
line diff
     1.1 --- a/tools/python/xen/xend/XendBase.py	Thu Apr 26 15:42:49 2007 +0100
     1.2 +++ b/tools/python/xen/xend/XendBase.py	Thu Apr 26 15:39:30 2007 +0100
     1.3 @@ -90,6 +90,9 @@ class XendBase:
     1.4          # Finally register it
     1.5          XendAPIStore.register(uuid, self.getClass(), self)
     1.6  
     1.7 +    def destroy(self):
     1.8 +        XendAPIStore.deregister(self.get_uuid(), self.getClass())
     1.9 +
    1.10      def get_uuid(self):
    1.11          return self.__uuid
    1.12  
     2.1 --- a/tools/python/xen/xend/XendError.py	Thu Apr 26 15:42:49 2007 +0100
     2.2 +++ b/tools/python/xen/xend/XendError.py	Thu Apr 26 15:39:30 2007 +0100
     2.3 @@ -162,6 +162,18 @@ class VLANTagInvalid(XendAPIError):
     2.4  
     2.5      def __str__(self):
     2.6          return 'VLAN_TAG_INVALID: %s' % self.vlan
     2.7 +
     2.8 +class NetworkError(XendAPIError):
     2.9 +    def __init__(self, error, network):
    2.10 +        XendAPIError.__init__(self)
    2.11 +        self.network = network
    2.12 +        self.error = error
    2.13 +
    2.14 +    def get_api_error(self):
    2.15 +        return ['NETWORK_ERROR', self.error, self.network]
    2.16 +
    2.17 +    def __str__(self):
    2.18 +        return 'NETWORK_ERROR: %s %s' % (self.error, self.network)
    2.19      
    2.20  XEND_ERROR_AUTHENTICATION_FAILED = ('ELUSER', 'Authentication Failed')
    2.21  XEND_ERROR_SESSION_INVALID       = ('EPERMDENIED', 'Session Invalid')
     3.1 --- a/tools/python/xen/xend/XendNetwork.py	Thu Apr 26 15:42:49 2007 +0100
     3.2 +++ b/tools/python/xen/xend/XendNetwork.py	Thu Apr 26 15:39:30 2007 +0100
     3.3 @@ -60,7 +60,8 @@ class XendNetwork(XendBase):
     3.4  
     3.5      def getMethods(self):
     3.6          methods = ['add_to_other_config',
     3.7 -                   'remove_from_other_config']
     3.8 +                   'remove_from_other_config',
     3.9 +                   'destroy']
    3.10          return XendBase.getMethods() + methods
    3.11  
    3.12      def getFuncs(self):
    3.13 @@ -128,6 +129,8 @@ class XendNetwork(XendBase):
    3.14          # Create the bridge
    3.15          Brctl.bridge_create(network.name_label)
    3.16  
    3.17 +        XendNode.instance().save_networks()
    3.18 +
    3.19          return uuid
    3.20  
    3.21      create_phy  = classmethod(create_phy)
    3.22 @@ -141,6 +144,20 @@ class XendNetwork(XendBase):
    3.23      # XenAPI Mehtods
    3.24      #
    3.25  
    3.26 +    def destroy(self):
    3.27 +        # check no VIFs or PIFs attached
    3.28 +        if len(self.get_VIFs()) > 0:
    3.29 +            raise NetworkError("Cannot destroy network with VIFs attached",
    3.30 +                               self.get_name_label())
    3.31 +
    3.32 +        if len(self.get_PIFs()) > 0:
    3.33 +            raise NetworkError("Cannot destroy network with PIFs attached",
    3.34 +                               self.get_name_label())        
    3.35 +        
    3.36 +        XendBase.destroy(self)
    3.37 +        Brctl.bridge_del(self.get_name_label())
    3.38 +        XendNode.instance().save_networks()
    3.39 +
    3.40      def get_name_label(self):
    3.41          return self.name_label
    3.42  
     4.1 --- a/tools/python/xen/xm/messages/en/xen-xm.po	Thu Apr 26 15:42:49 2007 +0100
     4.2 +++ b/tools/python/xen/xm/messages/en/xen-xm.po	Thu Apr 26 15:39:30 2007 +0100
     4.3 @@ -87,4 +87,7 @@ msgid "IMPLEMENTATION_ERROR"
     4.4  msgstr "Class %s does not implement %s"
     4.5  
     4.6  msgid "VLAN_TAG_INVALID"
     4.7 -msgstr "VLAN tag invalid %s"
     4.8 \ No newline at end of file
     4.9 +msgstr "VLAN tag invalid %s"
    4.10 +
    4.11 +msgid "NETWORK_ERROR"
    4.12 +msgstr "Network Error: %s - %s"
    4.13 \ No newline at end of file