mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
Add a 1-PIF-per-network limit.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
1 parent
a80a083a0e
commit
1238c75163
5 files changed
+61
-24
No files matched your search
@@ -540,16 +540,20 @@ class XendAPI:
|
||||
return XendNode.instance().pifs[ref]
|
||||
|
||||
def PIF_create(self, _, name, network_uuid, host_uuid, mac, mtu, vlan):
|
||||
node = XendNode.instance()
|
||||
if host_uuid != node.uuid:
|
||||
return xen_api_error([HOST_HANDLE_INVALID, host_uuid])
|
||||
try:
|
||||
node = XendNode.instance()
|
||||
if host_uuid != node.uuid:
|
||||
return xen_api_error([HOST_HANDLE_INVALID, host_uuid])
|
||||
|
||||
elif _is_valid_ref(network_uuid, node.is_valid_network):
|
||||
network = node.get_network(network_uuid)
|
||||
return xen_api_success(node.PIF_create(name, mtu, vlan, mac,
|
||||
network))
|
||||
else:
|
||||
return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
|
||||
elif _is_valid_ref(network_uuid, node.is_valid_network):
|
||||
network = node.get_network(network_uuid)
|
||||
return xen_api_success(node.PIF_create(name, mtu, vlan, mac,
|
||||
network))
|
||||
else:
|
||||
return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
|
||||
except NetworkAlreadyConnected, exn:
|
||||
return xen_api_error(['NETWORK_ALREADY_CONNECTED',
|
||||
network_uuid, exn.pif_uuid])
|
||||
|
||||
def PIF_destroy(self, _, ref):
|
||||
return xen_api_success(XendNode.instance().PIF_destroy(ref))
|
||||
@@ -595,11 +599,15 @@ class XendAPI:
|
||||
return xen_api_success(self._get_PIF(ref).set_mtu(name))
|
||||
|
||||
def PIF_create_VLAN(self, _, ref, network, vlan):
|
||||
if _is_valid_ref(network, XendNode.instance().is_valid_network):
|
||||
return xen_api_success(XendNode.instance().PIF_create_VLAN(
|
||||
ref, network, vlan))
|
||||
else:
|
||||
return xen_api_error([NETWORK_HANDLE_INVALID, network_uuid])
|
||||
try:
|
||||
if _is_valid_ref(network, XendNode.instance().is_valid_network):
|
||||
return xen_api_success(XendNode.instance().PIF_create_VLAN(
|
||||
ref, network, vlan))
|
||||
else:
|
||||
return xen_api_error([NETWORK_HANDLE_INVALID, network])
|
||||
except NetworkAlreadyConnected, exn:
|
||||
return xen_api_error(['NETWORK_ALREADY_CONNECTED',
|
||||
network, exn.pif_uuid])
|
||||
|
||||
|
||||
# Xen API: Class VM
|
||||
|
||||
@@ -1969,9 +1969,16 @@ class XendDomainInfo:
|
||||
config['device'] = ''
|
||||
|
||||
if not config.has_key('network'):
|
||||
config['network'] = \
|
||||
XendNode.instance().bridge_to_network(
|
||||
config.get('bridge')).uuid
|
||||
try:
|
||||
config['network'] = \
|
||||
XendNode.instance().bridge_to_network(
|
||||
config.get('bridge')).uuid
|
||||
except Exception:
|
||||
log.exception('bridge_to_network')
|
||||
# Ignore this for now -- it may happen if the device
|
||||
# has been specified using the legacy methods, but at
|
||||
# some point we're going to have to figure out how to
|
||||
# handle that properly.
|
||||
|
||||
config['MTU'] = 1500 # TODO
|
||||
config['io_read_kbs'] = 0.0
|
||||
|
||||
@@ -33,14 +33,15 @@ class XendError(Fault):
|
||||
return self.value
|
||||
|
||||
class VMBadState(XendError):
|
||||
|
||||
def __init__(self, value, expected, actual):
|
||||
XendError.__init__(self, value)
|
||||
self.expected = expected
|
||||
self.actual = actual
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
class NetworkAlreadyConnected(XendError):
|
||||
def __init__(self, pif_uuid):
|
||||
XendError.__init__(self, 'Network already connected')
|
||||
self.pif_uuid = pif_uuid
|
||||
|
||||
class VmError(XendError):
|
||||
"""Vm construction error."""
|
||||
|
||||
@@ -23,7 +23,7 @@ import xen.lowlevel.xc
|
||||
from xen.util import Brctl
|
||||
|
||||
from xen.xend import uuid
|
||||
from xen.xend.XendError import XendError
|
||||
from xen.xend.XendError import XendError, NetworkAlreadyConnected
|
||||
from xen.xend.XendRoot import instance as xendroot
|
||||
from xen.xend.XendStorageRepository import XendStorageRepository
|
||||
from xen.xend.XendLogging import log
|
||||
@@ -105,8 +105,13 @@ class XendNode:
|
||||
for pif_uuid, pif in saved_pifs.items():
|
||||
if pif['network'] in self.networks:
|
||||
network = self.networks[pif['network']]
|
||||
self.PIF_create(pif['name'], pif['MTU'], pif['VLAN'],
|
||||
pif['MAC'], network, False, pif_uuid)
|
||||
try:
|
||||
self.PIF_create(pif['name'], pif['MTU'], pif['VLAN'],
|
||||
pif['MAC'], network, False, pif_uuid)
|
||||
except NetworkAlreadyConnected, exn:
|
||||
log.error('Cannot load saved PIF %s, as network %s ' +
|
||||
'is already connected to PIF %s',
|
||||
pif_uuid, pif['network'], exn.pif_uuid)
|
||||
else:
|
||||
for name, mtu, mac in linux_get_phy_ifaces():
|
||||
network = self.networks.values()[0]
|
||||
@@ -143,6 +148,10 @@ class XendNode:
|
||||
|
||||
def PIF_create(self, name, mtu, vlan, mac, network, persist = True,
|
||||
pif_uuid = None):
|
||||
for pif in self.pifs.values():
|
||||
if pif.network == network:
|
||||
raise NetworkAlreadyConnected(pif.uuid)
|
||||
|
||||
if pif_uuid is None:
|
||||
pif_uuid = uuid.createString()
|
||||
self.pifs[pif_uuid] = XendPIF(pif_uuid, name, mtu, vlan, mac, network,
|
||||
@@ -290,6 +299,15 @@ class XendNode:
|
||||
return self.networks[network_ref]
|
||||
|
||||
def bridge_to_network(self, bridge):
|
||||
"""
|
||||
Determine which network a particular bridge is attached to.
|
||||
|
||||
@param bridge The name of the bridge. If empty, the default bridge
|
||||
will be used instead (the first one in the list returned by brctl
|
||||
show); this is the behaviour of the vif-bridge script.
|
||||
@return The XendNetwork instance to which this bridge is attached.
|
||||
@raise Exception if the interface is not connected to a network.
|
||||
"""
|
||||
if not bridge:
|
||||
rc, bridge = commands.getstatusoutput(
|
||||
'brctl show | cut -d "\n" -f 2 | cut -f 1')
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Xen-xm 3.0\n"
|
||||
"PO-Revision-Date: 2006-12-25 19:24+0000\n"
|
||||
"PO-Revision-Date: 2006-12-28 15:43+0000\n"
|
||||
"Last-Translator: Ewan Mellor <ewan@xensource.com>\n"
|
||||
"Language-Team: xen-devel <xen-devel@lists.xensource.com>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
@@ -65,5 +65,8 @@ msgstr "The VM handle %(1)s is invalid."
|
||||
msgid "VTPM_HANDLE_INVALID"
|
||||
msgstr "The VTPM handle %(1)s is invalid."
|
||||
|
||||
msgid "NETWORK_ALREADY_CONNECTED"
|
||||
msgstr "The network you specified already has a PIF attached to it, and so another one may not be attached."
|
||||
|
||||
msgid "VM_BAD_POWER_STATE"
|
||||
msgstr "The VM must be %(2)s to perform the requested operation (it is currently %(3)s)."
|
||||