mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 02:30:03 +01:00
Add network.destroy() to XenAPI
signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
This commit is contained in:
1 parent
faae093917
commit
15ef31e0c5
4 files changed
+37
-2
No files matched your search
@@ -90,6 +90,9 @@ class XendBase:
|
||||
# Finally register it
|
||||
XendAPIStore.register(uuid, self.getClass(), self)
|
||||
|
||||
def destroy(self):
|
||||
XendAPIStore.deregister(self.get_uuid(), self.getClass())
|
||||
|
||||
def get_uuid(self):
|
||||
return self.__uuid
|
||||
|
||||
|
||||
@@ -162,6 +162,18 @@ class VLANTagInvalid(XendAPIError):
|
||||
|
||||
def __str__(self):
|
||||
return 'VLAN_TAG_INVALID: %s' % self.vlan
|
||||
|
||||
class NetworkError(XendAPIError):
|
||||
def __init__(self, error, network):
|
||||
XendAPIError.__init__(self)
|
||||
self.network = network
|
||||
self.error = error
|
||||
|
||||
def get_api_error(self):
|
||||
return ['NETWORK_ERROR', self.error, self.network]
|
||||
|
||||
def __str__(self):
|
||||
return 'NETWORK_ERROR: %s %s' % (self.error, self.network)
|
||||
|
||||
XEND_ERROR_AUTHENTICATION_FAILED = ('ELUSER', 'Authentication Failed')
|
||||
XEND_ERROR_SESSION_INVALID = ('EPERMDENIED', 'Session Invalid')
|
||||
|
||||
@@ -60,7 +60,8 @@ class XendNetwork(XendBase):
|
||||
|
||||
def getMethods(self):
|
||||
methods = ['add_to_other_config',
|
||||
'remove_from_other_config']
|
||||
'remove_from_other_config',
|
||||
'destroy']
|
||||
return XendBase.getMethods() + methods
|
||||
|
||||
def getFuncs(self):
|
||||
@@ -128,6 +129,8 @@ class XendNetwork(XendBase):
|
||||
# Create the bridge
|
||||
Brctl.bridge_create(network.name_label)
|
||||
|
||||
XendNode.instance().save_networks()
|
||||
|
||||
return uuid
|
||||
|
||||
create_phy = classmethod(create_phy)
|
||||
@@ -141,6 +144,20 @@ class XendNetwork(XendBase):
|
||||
# XenAPI Mehtods
|
||||
#
|
||||
|
||||
def destroy(self):
|
||||
# check no VIFs or PIFs attached
|
||||
if len(self.get_VIFs()) > 0:
|
||||
raise NetworkError("Cannot destroy network with VIFs attached",
|
||||
self.get_name_label())
|
||||
|
||||
if len(self.get_PIFs()) > 0:
|
||||
raise NetworkError("Cannot destroy network with PIFs attached",
|
||||
self.get_name_label())
|
||||
|
||||
XendBase.destroy(self)
|
||||
Brctl.bridge_del(self.get_name_label())
|
||||
XendNode.instance().save_networks()
|
||||
|
||||
def get_name_label(self):
|
||||
return self.name_label
|
||||
|
||||
|
||||
@@ -87,4 +87,7 @@ msgid "IMPLEMENTATION_ERROR"
|
||||
msgstr "Class %s does not implement %s"
|
||||
|
||||
msgid "VLAN_TAG_INVALID"
|
||||
msgstr "VLAN tag invalid %s"
|
||||
msgstr "VLAN tag invalid %s"
|
||||
|
||||
msgid "NETWORK_ERROR"
|
||||
msgstr "Network Error: %s - %s"
|
||||