Document existing PIF.create_VLAN, and remove PIF.create (PIFs are implicitly

created from the physical host configuration).

Change PIF.name to PIF.device, for consistency with other uses, and make
PIF.VLAN an int.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
Ewan Mellor committed 2007-01-28 13:40:07 +00:00
1 parent 8359e64538
commit bd16434c05
8 files changed
+230 -194

No files matched your search

+21 -25
View File
@@ -752,7 +752,7 @@ class XendAPI(object):
PIF_attr_ro = ['io_read_kbs',
'io_write_kbs']
PIF_attr_rw = ['name',
PIF_attr_rw = ['device',
'network',
'host',
'MAC',
@@ -766,24 +766,11 @@ class XendAPI(object):
def _get_PIF(self, ref):
return XendNode.instance().pifs[ref]
def PIF_create(self, _, name, network_uuid, host_uuid, mac, mtu, vlan):
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])
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))
try:
return xen_api_success(XendNode.instance().PIF_destroy(ref))
except PIFIsPhysical, exn:
return xen_api_error(['PIF_IS_PHYSICAL', ref])
# object methods
def PIF_get_record(self, _, ref):
@@ -792,8 +779,8 @@ class XendAPI(object):
def PIF_get_all(self, _):
return xen_api_success(XendNode.instance().pifs.keys())
def PIF_get_name(self, _, ref):
return xen_api_success(self._get_PIF(ref).name)
def PIF_get_device(self, _, ref):
return xen_api_success(self._get_PIF(ref).device)
def PIF_get_network(self, _, ref):
return xen_api_success(self._get_PIF(ref).network.uuid)
@@ -816,8 +803,8 @@ class XendAPI(object):
def PIF_get_io_write_kbs(self, _, ref):
return xen_api_success(self._get_PIF(ref).get_io_write_kbs())
def PIF_set_name(self, _, ref, name):
return xen_api_success(self._get_PIF(ref).set_name(name))
def PIF_set_device(self, _, ref, device):
return xen_api_success(self._get_PIF(ref).set_device(device))
def PIF_set_MAC(self, _, ref, mac):
return xen_api_success(self._get_PIF(ref).set_mac(mac))
@@ -827,14 +814,23 @@ class XendAPI(object):
def PIF_create_VLAN(self, _, ref, network, vlan):
try:
if _is_valid_ref(network, XendNode.instance().is_valid_network):
return xen_api_success(XendNode.instance().PIF_create_VLAN(
ref, network, vlan))
vlan = int(vlan)
except:
return xen_api_error(['VLAN_TAG_INVALID', vlan])
try:
node = XendNode.instance()
if _is_valid_ref(network, node.is_valid_network):
return xen_api_success(
node.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])
except VLANTagInvalid:
return xen_api_error(['VLAN_TAG_INVALID', vlan])
# Xen API: Class VM
+8
View File
@@ -43,6 +43,14 @@ class NetworkAlreadyConnected(XendError):
XendError.__init__(self, 'Network already connected')
self.pif_uuid = pif_uuid
class PIFIsPhysical(XendError):
def __init__(self):
XendError.__init__(self, 'PIF is physical')
class VLANTagInvalid(XendError):
def __init__(self):
XendError.__init__(self, 'VLAN tag invalid')
class VmError(XendError):
"""Vm construction error."""
pass
+20 -7
View File
@@ -23,7 +23,7 @@ import xen.lowlevel.xc
from xen.util import Brctl
from xen.xend import uuid
from xen.xend.XendError import XendError, NetworkAlreadyConnected
from xen.xend.XendError import *
from xen.xend.XendOptions import instance as xendoptions
from xen.xend.XendQCoWStorageRepo import XendQCoWStorageRepo
from xen.xend.XendLocalStorageRepo import XendLocalStorageRepo
@@ -111,8 +111,13 @@ class XendNode:
if pif.get('network') in self.networks:
network = self.networks[pif['network']]
try:
self.PIF_create(pif['name'], pif['MTU'], pif['VLAN'],
pif['MAC'], network, False, pif_uuid)
if 'device' not in pif and 'name' in pif:
# Compatibility hack, can go pretty soon.
pif['device'] = pif['name']
self._PIF_create(pif['device'], pif['MTU'],
int(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',
@@ -120,7 +125,7 @@ class XendNode:
else:
for name, mtu, mac in linux_get_phy_ifaces():
network = self.networks.values()[0]
self.PIF_create(name, mtu, '', mac, network, False)
self._PIF_create(name, mtu, -1, mac, network, False)
# initialise storage
saved_srs = self.state_store.load_state('sr')
@@ -161,8 +166,8 @@ class XendNode:
self.save_networks()
def PIF_create(self, name, mtu, vlan, mac, network, persist = True,
pif_uuid = None):
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)
@@ -178,12 +183,20 @@ class XendNode:
def PIF_create_VLAN(self, pif_uuid, network_uuid, vlan):
if vlan < 0 or vlan >= 4096:
raise VLANTagInvalid()
pif = self.pifs[pif_uuid]
network = self.networks[network_uuid]
return self.PIF_create(pif.name, pif.mtu, vlan, pif.mac, network)
return self._PIF_create(pif.device, pif.mtu, vlan, pif.mac, network)
def PIF_destroy(self, pif_uuid):
pif = self.pifs[pif_uuid]
if pif.vlan == -1:
raise PIFIsPhysical()
del self.pifs[pif_uuid]
self.save_PIFs()
+12 -12
View File
@@ -90,18 +90,18 @@ def linux_set_mtu(iface, mtu):
class XendPIF:
"""Representation of a Physical Network Interface."""
def __init__(self, uuid, name, mtu, vlan, mac, network, host):
def __init__(self, uuid, device, mtu, vlan, mac, network, host):
self.uuid = uuid
self.name = name
self.device = device
self.mac = mac
self.mtu = mtu
self.vlan = vlan
self.network = network
self.host = host
def set_name(self, new_name):
self.name = new_name
def set_device(self, new_device):
self.device = new_device
def set_mac(self, new_mac):
success = linux_set_mac(new_mac)
if success:
@@ -116,14 +116,14 @@ class XendPIF:
def get_io_read_kbs(self):
from xen.xend.XendNode import instance as xennode
return xennode().get_pif_util(self.name)[0]
return xennode().get_pif_util(self.device)[0]
def get_io_write_kbs(self):
from xen.xend.XendNode import instance as xennode
return xennode().get_pif_util(self.name)[1]
return xennode().get_pif_util(self.device)[1]
def get_record(self, transient = True):
result = {'name': self.name,
result = {'device': self.device,
'MAC': self.mac,
'MTU': self.mtu,
'VLAN': self.vlan,
@@ -143,10 +143,10 @@ class XendPIF:
# there's nothing we can do -- this should have been set up with
# the network script. Otherwise, we can use vconfig to derive
# a subinterface.
if not self.vlan:
if self.vlan == -1:
return
rc, _ = _cmd('vconfig add %s %s', self.name, self.vlan)
rc, _ = _cmd('vconfig add %s %d', self.device, self.vlan)
if rc != 0:
log.error('Could not refresh %s', ifname)
return
@@ -176,9 +176,9 @@ class XendPIF:
def interface_name(self):
if self.vlan:
return '%s.%s' % (self.name, self.vlan)
return '%s.%d' % (self.device, self.vlan)
else:
return self.name
return self.device
def _cmd(cmd, *args):
+8 -2
View File
@@ -12,14 +12,14 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# ============================================================================
# Copyright (c) 2006 XenSource Inc.
# Copyright (c) 2006-2007 XenSource Inc.
# ============================================================================
#
#
msgid ""
msgstr ""
"Project-Id-Version: Xen-xm 3.0\n"
"PO-Revision-Date: 2006-12-28 15:43+0000\n"
"PO-Revision-Date: 2007-01-28 12:59+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"
@@ -68,5 +68,11 @@ 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 "PIF_IS_PHYSICAL"
msgstr "The PIF %(1)s corresponds to a physical interface, and so may not be destroyed."
msgid "VLAN_TAG_INVALID"
msgstr "The VLAN tag you gave (%(1)s) is invalid -- it must be between 0 and 4095."
msgid "VM_BAD_POWER_STATE"
msgstr "The VM must be %(2)s to perform the requested operation (it is currently %(3)s)."
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.