1 # Copyright (c) 2008,2009 Citrix Systems, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU Lesser General Public License as published
5 # by the Free Software Foundation; version 2.1 only. with the special
6 # exception on linking described in file LICENSE.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU Lesser General Public License for more details.
17 from xml.dom.minidom import getDOMImplementation
18 from xml.dom.minidom import parse as parseXML
22 """Returns a string to prefix to all file name references, which
23 is useful for testing."""
24 return the_root_prefix
25 def set_root_prefix(prefix):
26 global the_root_prefix
27 the_root_prefix = prefix
29 log_destination = "syslog"
30 def get_log_destination():
31 """Returns the current log destination.
32 'syslog' means "log to syslog".
33 'stderr' means "log to stderr"."""
34 return log_destination
35 def set_log_destination(dest):
36 global log_destination
37 log_destination = dest
44 if get_log_destination() == 'syslog':
53 class Error(Exception):
54 def __init__(self, msg):
55 Exception.__init__(self)
59 # Run external utilities
62 def run_command(command):
63 log("Running command: " + ' '.join(command))
64 rc = os.spawnl(os.P_WAIT, root_prefix() + command[0], *command)
66 log("Command failed %d: " % rc + ' '.join(command))
71 # Configuration File Handling.
74 class ConfigurationFile(object):
75 """Write a file, tracking old and new versions.
77 Supports writing a new version of a file and applying and
78 reverting those changes.
81 __STATE = {"OPEN":"OPEN",
82 "NOT-APPLIED":"NOT-APPLIED", "APPLIED":"APPLIED",
83 "REVERTED":"REVERTED", "COMMITTED": "COMMITTED"}
85 def __init__(self, path):
86 dirname,basename = os.path.split(path)
88 self.__state = self.__STATE['OPEN']
91 self.__path = os.path.join(dirname, basename)
92 self.__oldpath = os.path.join(dirname, "." + basename + ".xapi-old")
93 self.__newpath = os.path.join(dirname, "." + basename + ".xapi-new")
95 self.__f = open(self.__newpath, "w")
97 def attach_child(self, child):
98 self.__children.append(child)
105 return open(self.path()).readlines()
109 def write(self, args):
110 if self.__state != self.__STATE['OPEN']:
111 raise Error("Attempt to write to file in state %s" % self.__state)
115 if self.__state != self.__STATE['OPEN']:
116 raise Error("Attempt to close file in state %s" % self.__state)
119 self.__state = self.__STATE['NOT-APPLIED']
122 if self.__state != self.__STATE['NOT-APPLIED']:
123 raise Error("Attempt to compare file in state %s" % self.__state)
128 if self.__state != self.__STATE['NOT-APPLIED']:
129 raise Error("Attempt to apply configuration from state %s" % self.__state)
131 for child in self.__children:
134 log("Applying changes to %s configuration" % self.__path)
136 # Remove previous backup.
137 if os.access(self.__oldpath, os.F_OK):
138 os.unlink(self.__oldpath)
140 # Save current configuration.
141 if os.access(self.__path, os.F_OK):
142 os.link(self.__path, self.__oldpath)
143 os.unlink(self.__path)
145 # Apply new configuration.
146 assert(os.path.exists(self.__newpath))
147 os.link(self.__newpath, self.__path)
149 # Remove temporary file.
150 os.unlink(self.__newpath)
152 self.__state = self.__STATE['APPLIED']
155 if self.__state != self.__STATE['APPLIED']:
156 raise Error("Attempt to revert configuration from state %s" % self.__state)
158 for child in self.__children:
161 log("Reverting changes to %s configuration" % self.__path)
163 # Remove existing new configuration
164 if os.access(self.__newpath, os.F_OK):
165 os.unlink(self.__newpath)
167 # Revert new configuration.
168 if os.access(self.__path, os.F_OK):
169 os.link(self.__path, self.__newpath)
170 os.unlink(self.__path)
172 # Revert to old configuration.
173 if os.access(self.__oldpath, os.F_OK):
174 os.link(self.__oldpath, self.__path)
175 os.unlink(self.__oldpath)
177 # Leave .*.xapi-new as an aid to debugging.
179 self.__state = self.__STATE['REVERTED']
182 if self.__state != self.__STATE['APPLIED']:
183 raise Error("Attempt to commit configuration from state %s" % self.__state)
185 for child in self.__children:
188 log("Committing changes to %s configuration" % self.__path)
190 if os.access(self.__oldpath, os.F_OK):
191 os.unlink(self.__oldpath)
192 if os.access(self.__newpath, os.F_OK):
193 os.unlink(self.__newpath)
195 self.__state = self.__STATE['COMMITTED']
198 # Helper functions for encoding/decoding database attributes to/from XML.
201 def _str_to_xml(xml, parent, tag, val):
202 e = xml.createElement(tag)
203 parent.appendChild(e)
204 v = xml.createTextNode(val)
206 def _str_from_xml(n):
207 def getText(nodelist):
209 for node in nodelist:
210 if node.nodeType == node.TEXT_NODE:
213 return getText(n.childNodes).strip()
215 def _bool_to_xml(xml, parent, tag, val):
217 _str_to_xml(xml, parent, tag, "True")
219 _str_to_xml(xml, parent, tag, "False")
220 def _bool_from_xml(n):
227 raise Error("Unknown boolean value %s" % s)
229 def _strlist_to_xml(xml, parent, ltag, itag, val):
230 e = xml.createElement(ltag)
231 parent.appendChild(e)
233 c = xml.createElement(itag)
235 cv = xml.createTextNode(v)
237 def _strlist_from_xml(n, ltag, itag):
239 for n in n.childNodes:
240 if n.nodeName == itag:
241 ret.append(_str_from_xml(n))
244 def _otherconfig_to_xml(xml, parent, val, attrs):
245 otherconfig = xml.createElement("other_config")
246 parent.appendChild(otherconfig)
247 for n,v in val.items():
249 raise Error("Unknown other-config attribute: %s" % n)
250 _str_to_xml(xml, otherconfig, n, v)
251 def _otherconfig_from_xml(n, attrs):
253 for n in n.childNodes:
254 if n.nodeName in attrs:
255 ret[n.nodeName] = _str_from_xml(n)
259 # Definitions of the database objects (and their attributes) used by interface-reconfigure.
261 # Each object is defined by a dictionary mapping an attribute name in
262 # the xapi database to a tuple containing two items:
263 # - a function which takes this attribute and encodes it as XML.
264 # - a function which takes XML and decocdes it into a value.
266 # other-config attributes are specified as a simple array of strings
269 _VLAN_XML_TAG = "vlan"
270 _BOND_XML_TAG = "bond"
271 _NETWORK_XML_TAG = "network"
273 _ETHTOOL_OTHERCONFIG_ATTRS = ['ethtool-%s' % x for x in 'autoneg', 'speed', 'duplex', 'rx', 'tx', 'sg', 'tso', 'ufo', 'gso' ]
275 _PIF_OTHERCONFIG_ATTRS = [ 'domain', 'peerdns', 'defaultroute', 'mtu', 'static-routes' ] + \
276 [ 'bond-%s' % x for x in 'mode', 'miimon', 'downdelay', 'updelay', 'use_carrier' ] + \
277 _ETHTOOL_OTHERCONFIG_ATTRS
279 _PIF_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml),
280 'management': (_bool_to_xml,_bool_from_xml),
281 'network': (_str_to_xml,_str_from_xml),
282 'device': (_str_to_xml,_str_from_xml),
283 'bond_master_of': (lambda x, p, t, v: _strlist_to_xml(x, p, 'bond_master_of', 'slave', v),
284 lambda n: _strlist_from_xml(n, 'bond_master_of', 'slave')),
285 'bond_slave_of': (_str_to_xml,_str_from_xml),
286 'VLAN': (_str_to_xml,_str_from_xml),
287 'VLAN_master_of': (_str_to_xml,_str_from_xml),
288 'VLAN_slave_of': (lambda x, p, t, v: _strlist_to_xml(x, p, 'VLAN_slave_of', 'master', v),
289 lambda n: _strlist_from_xml(n, 'VLAN_slave_Of', 'master')),
290 'ip_configuration_mode': (_str_to_xml,_str_from_xml),
291 'IP': (_str_to_xml,_str_from_xml),
292 'netmask': (_str_to_xml,_str_from_xml),
293 'gateway': (_str_to_xml,_str_from_xml),
294 'DNS': (_str_to_xml,_str_from_xml),
295 'MAC': (_str_to_xml,_str_from_xml),
296 'other_config': (lambda x, p, t, v: _otherconfig_to_xml(x, p, v, _PIF_OTHERCONFIG_ATTRS),
297 lambda n: _otherconfig_from_xml(n, _PIF_OTHERCONFIG_ATTRS)),
299 # Special case: We write the current value
300 # PIF.currently-attached to the cache but since it will
301 # not be valid when we come to use the cache later
302 # (i.e. after a reboot) we always read it as False.
303 'currently_attached': (_bool_to_xml, lambda n: False),
306 _VLAN_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml),
307 'tagged_PIF': (_str_to_xml,_str_from_xml),
308 'untagged_PIF': (_str_to_xml,_str_from_xml),
311 _BOND_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml),
312 'master': (_str_to_xml,_str_from_xml),
313 'slaves': (lambda x, p, t, v: _strlist_to_xml(x, p, 'slaves', 'slave', v),
314 lambda n: _strlist_from_xml(n, 'slaves', 'slave')),
317 _NETWORK_OTHERCONFIG_ATTRS = [ 'mtu', 'static-routes' ] + _ETHTOOL_OTHERCONFIG_ATTRS
319 _NETWORK_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml),
320 'bridge': (_str_to_xml,_str_from_xml),
321 'MTU': (_str_to_xml,_str_from_xml),
322 'PIFs': (lambda x, p, t, v: _strlist_to_xml(x, p, 'PIFs', 'PIF', v),
323 lambda n: _strlist_from_xml(n, 'PIFs', 'PIF')),
324 'other_config': (lambda x, p, t, v: _otherconfig_to_xml(x, p, v, _NETWORK_OTHERCONFIG_ATTRS),
325 lambda n: _otherconfig_from_xml(n, _NETWORK_OTHERCONFIG_ATTRS)),
329 # Database Cache object
335 assert(_db is not None)
338 def db_init_from_cache(cache):
341 _db = DatabaseCache(cache_file=cache)
343 def db_init_from_xenapi(session):
346 _db = DatabaseCache(session_ref=session)
348 class DatabaseCache(object):
349 def __read_xensource_inventory(self):
350 filename = root_prefix() + "/etc/xensource-inventory"
351 f = open(filename, "r")
352 lines = [x.strip("\n") for x in f.readlines()]
355 defs = [ (l[:l.find("=")], l[(l.find("=") + 1):]) for l in lines ]
356 defs = [ (a, b.strip("'")) for (a,b) in defs ]
360 def __pif_on_host(self,pif):
361 return self.__pifs.has_key(pif)
363 def __get_pif_records_from_xapi(self, session, host):
365 for (p,rec) in session.xenapi.PIF.get_all_records().items():
366 if rec['host'] != host:
370 self.__pifs[p][f] = rec[f]
371 self.__pifs[p]['other_config'] = {}
372 for f in _PIF_OTHERCONFIG_ATTRS:
373 if not rec['other_config'].has_key(f): continue
374 self.__pifs[p]['other_config'][f] = rec['other_config'][f]
376 def __get_vlan_records_from_xapi(self, session):
378 for v in session.xenapi.VLAN.get_all():
379 rec = session.xenapi.VLAN.get_record(v)
380 if not self.__pif_on_host(rec['untagged_PIF']):
383 for f in _VLAN_ATTRS:
384 self.__vlans[v][f] = rec[f]
386 def __get_bond_records_from_xapi(self, session):
388 for b in session.xenapi.Bond.get_all():
389 rec = session.xenapi.Bond.get_record(b)
390 if not self.__pif_on_host(rec['master']):
393 for f in _BOND_ATTRS:
394 self.__bonds[b][f] = rec[f]
396 def __get_network_records_from_xapi(self, session):
398 for n in session.xenapi.network.get_all():
399 rec = session.xenapi.network.get_record(n)
400 self.__networks[n] = {}
401 for f in _NETWORK_ATTRS:
403 # drop PIFs on other hosts
404 self.__networks[n][f] = [p for p in rec[f] if self.__pif_on_host(p)]
406 self.__networks[n][f] = rec[f]
407 self.__networks[n]['other_config'] = {}
408 for f in _NETWORK_OTHERCONFIG_ATTRS:
409 if not rec['other_config'].has_key(f): continue
410 self.__networks[n]['other_config'][f] = rec['other_config'][f]
412 def __to_xml(self, xml, parent, key, ref, rec, attrs):
413 """Encode a database object as XML"""
414 e = xml.createElement(key)
415 parent.appendChild(e)
417 e.setAttribute('ref', ref)
419 for n,v in rec.items():
424 raise Error("Unknown attribute %s" % n)
425 def __from_xml(self, e, attrs):
426 """Decode a database object from XML"""
427 ref = e.attributes['ref'].value
429 for n in e.childNodes:
430 if n.nodeName in attrs:
431 _,h = attrs[n.nodeName]
432 rec[n.nodeName] = h(n)
435 def __init__(self, session_ref=None, cache_file=None):
436 if session_ref and cache_file:
437 raise Error("can't specify session reference and cache file")
438 if cache_file == None:
440 session = XenAPI.xapi_local()
443 log("No session ref given on command line, logging in.")
444 session.xenapi.login_with_password("root", "")
446 session._session = session_ref
450 inventory = self.__read_xensource_inventory()
451 assert(inventory.has_key('INSTALLATION_UUID'))
452 log("host uuid is %s" % inventory['INSTALLATION_UUID'])
454 host = session.xenapi.host.get_by_uuid(inventory['INSTALLATION_UUID'])
456 self.__get_pif_records_from_xapi(session, host)
458 self.__get_vlan_records_from_xapi(session)
459 self.__get_bond_records_from_xapi(session)
460 self.__get_network_records_from_xapi(session)
463 session.xenapi.session.logout()
465 log("Loading xapi database cache from %s" % cache_file)
467 xml = parseXML(root_prefix() + cache_file)
474 assert(len(xml.childNodes) == 1)
475 toplevel = xml.childNodes[0]
477 assert(toplevel.nodeName == "xenserver-network-configuration")
479 for n in toplevel.childNodes:
480 if n.nodeName == "#text":
482 elif n.nodeName == _PIF_XML_TAG:
483 (ref,rec) = self.__from_xml(n, _PIF_ATTRS)
484 self.__pifs[ref] = rec
485 elif n.nodeName == _BOND_XML_TAG:
486 (ref,rec) = self.__from_xml(n, _BOND_ATTRS)
487 self.__bonds[ref] = rec
488 elif n.nodeName == _VLAN_XML_TAG:
489 (ref,rec) = self.__from_xml(n, _VLAN_ATTRS)
490 self.__vlans[ref] = rec
491 elif n.nodeName == _NETWORK_XML_TAG:
492 (ref,rec) = self.__from_xml(n, _NETWORK_ATTRS)
493 self.__networks[ref] = rec
495 raise Error("Unknown XML element %s" % n.nodeName)
497 def save(self, cache_file):
499 xml = getDOMImplementation().createDocument(
500 None, "xenserver-network-configuration", None)
501 for (ref,rec) in self.__pifs.items():
502 self.__to_xml(xml, xml.documentElement, _PIF_XML_TAG, ref, rec, _PIF_ATTRS)
503 for (ref,rec) in self.__bonds.items():
504 self.__to_xml(xml, xml.documentElement, _BOND_XML_TAG, ref, rec, _BOND_ATTRS)
505 for (ref,rec) in self.__vlans.items():
506 self.__to_xml(xml, xml.documentElement, _VLAN_XML_TAG, ref, rec, _VLAN_ATTRS)
507 for (ref,rec) in self.__networks.items():
508 self.__to_xml(xml, xml.documentElement, _NETWORK_XML_TAG, ref, rec,
511 f = open(cache_file, 'w')
512 f.write(xml.toprettyxml())
515 def get_pif_by_uuid(self, uuid):
516 pifs = map(lambda (ref,rec): ref,
517 filter(lambda (ref,rec): uuid == rec['uuid'],
518 self.__pifs.items()))
520 raise Error("Unknown PIF \"%s\"" % uuid)
522 raise Error("Non-unique PIF \"%s\"" % uuid)
526 def get_pifs_by_device(self, device):
527 return map(lambda (ref,rec): ref,
528 filter(lambda (ref,rec): rec['device'] == device,
529 self.__pifs.items()))
531 def get_pif_by_bridge(self, bridge):
532 networks = map(lambda (ref,rec): ref,
533 filter(lambda (ref,rec): rec['bridge'] == bridge,
534 self.__networks.items()))
535 if len(networks) == 0:
536 raise Error("No matching network \"%s\"" % bridge)
539 for network in networks:
540 nwrec = self.get_network_record(network)
541 for pif in nwrec['PIFs']:
542 pifrec = self.get_pif_record(pif)
544 raise Error("Multiple PIFs on host for network %s" % (bridge))
547 raise Error("No PIF on host for network %s" % (bridge))
550 def get_pif_record(self, pif):
551 if self.__pifs.has_key(pif):
552 return self.__pifs[pif]
553 raise Error("Unknown PIF \"%s\"" % pif)
554 def get_all_pifs(self):
556 def pif_exists(self, pif):
557 return self.__pifs.has_key(pif)
559 def get_management_pif(self):
560 """ Returns the management pif on host
562 all = self.get_all_pifs()
564 pifrec = self.get_pif_record(pif)
565 if pifrec['management']: return pif
568 def get_network_record(self, network):
569 if self.__networks.has_key(network):
570 return self.__networks[network]
571 raise Error("Unknown network \"%s\"" % network)
573 def get_bond_record(self, bond):
574 if self.__bonds.has_key(bond):
575 return self.__bonds[bond]
579 def get_vlan_record(self, vlan):
580 if self.__vlans.has_key(vlan):
581 return self.__vlans[vlan]
589 def ethtool_settings(oc):
591 if oc.has_key('ethtool-speed'):
592 val = oc['ethtool-speed']
593 if val in ["10", "100", "1000"]:
594 settings += ['speed', val]
596 log("Invalid value for ethtool-speed = %s. Must be 10|100|1000." % val)
597 if oc.has_key('ethtool-duplex'):
598 val = oc['ethtool-duplex']
599 if val in ["10", "100", "1000"]:
600 settings += ['duplex', 'val']
602 log("Invalid value for ethtool-duplex = %s. Must be half|full." % val)
603 if oc.has_key('ethtool-autoneg'):
604 val = oc['ethtool-autoneg']
605 if val in ["true", "on"]:
606 settings += ['autoneg', 'on']
607 elif val in ["false", "off"]:
608 settings += ['autoneg', 'off']
610 log("Invalid value for ethtool-autoneg = %s. Must be on|true|off|false." % val)
612 for opt in ("rx", "tx", "sg", "tso", "ufo", "gso"):
613 if oc.has_key("ethtool-" + opt):
614 val = oc["ethtool-" + opt]
615 if val in ["true", "on"]:
616 offload += [opt, 'on']
617 elif val in ["false", "off"]:
618 offload += [opt, 'off']
620 log("Invalid value for ethtool-%s = %s. Must be on|true|off|false." % (opt, val))
621 return settings,offload
623 # By default the MTU is taken from the Network.MTU setting for VIF,
624 # PIF and Bridge. However it is possible to override this by using
625 # {VIF,PIF,Network}.other-config:mtu.
627 # type parameter is a string describing the object that the oc parameter
628 # is from. e.g. "PIF", "Network"
629 def mtu_setting(nw, type, oc):
632 nwrec = db().get_network_record(nw)
633 if nwrec.has_key('MTU'):
638 if oc.has_key('mtu'):
639 log("Override Network.MTU setting on bridge %s from %s.MTU is %s" % \
640 (nwrec['bridge'], type, mtu))
645 int(mtu) # Check that the value is an integer
647 except ValueError, x:
648 log("Invalid value for mtu = %s" % mtu)
653 # IP Network Devices -- network devices with IP configuration
655 def pif_ipdev_name(pif):
656 """Return the ipdev name associated with pif"""
657 pifrec = db().get_pif_record(pif)
658 nwrec = db().get_network_record(pifrec['network'])
661 # TODO: sanity check that nwrec['bridgeless'] != 'true'
662 return nwrec['bridge']
664 # TODO: sanity check that nwrec['bridgeless'] == 'true'
665 return pif_netdev_name(pif)
668 # Bare Network Devices -- network devices without IP configuration
671 def netdev_exists(netdev):
672 return os.path.exists(root_prefix() + "/sys/class/net/" + netdev)
674 def pif_netdev_name(pif):
675 """Get the netdev name for a PIF."""
677 pifrec = db().get_pif_record(pif)
680 return "%(device)s.%(VLAN)s" % pifrec
682 return pifrec['device']
688 def pif_is_bridged(pif):
689 pifrec = db().get_pif_record(pif)
690 nwrec = db().get_network_record(pifrec['network'])
693 # TODO: sanity check that nwrec['bridgeless'] != 'true'
696 # TODO: sanity check that nwrec['bridgeless'] == 'true'
699 def pif_bridge_name(pif):
700 """Return the bridge name of a pif.
702 PIF must be a bridged PIF."""
703 pifrec = db().get_pif_record(pif)
705 nwrec = db().get_network_record(pifrec['network'])
708 return nwrec['bridge']
710 raise Error("PIF %(uuid)s does not have a bridge name" % pifrec)
715 def pif_is_bond(pif):
716 pifrec = db().get_pif_record(pif)
718 return len(pifrec['bond_master_of']) > 0
720 def pif_get_bond_masters(pif):
721 """Returns a list of PIFs which are bond masters of this PIF"""
723 pifrec = db().get_pif_record(pif)
725 bso = pifrec['bond_slave_of']
727 # bond-slave-of is currently a single reference but in principle a
728 # PIF could be a member of several bonds which are not
729 # concurrently attached. Be robust to this possibility.
730 if not bso or bso == "OpaqueRef:NULL":
732 elif not type(bso) == list:
735 bondrecs = [db().get_bond_record(bond) for bond in bso]
736 bondrecs = [rec for rec in bondrecs if rec]
738 return [bond['master'] for bond in bondrecs]
740 def pif_get_bond_slaves(pif):
741 """Returns a list of PIFs which make up the given bonded pif."""
743 pifrec = db().get_pif_record(pif)
745 bmo = pifrec['bond_master_of']
747 raise Error("Bond-master-of contains too many elements")
752 bondrec = db().get_bond_record(bmo[0])
754 raise Error("No bond record for bond master PIF")
756 return bondrec['slaves']
762 def pif_is_vlan(pif):
763 return db().get_pif_record(pif)['VLAN'] != '-1'
765 def pif_get_vlan_slave(pif):
766 """Find the PIF which is the VLAN slave of pif.
768 Returns the 'physical' PIF underneath the a VLAN PIF @pif."""
770 pifrec = db().get_pif_record(pif)
772 vlan = pifrec['VLAN_master_of']
773 if not vlan or vlan == "OpaqueRef:NULL":
774 raise Error("PIF is not a VLAN master")
776 vlanrec = db().get_vlan_record(vlan)
778 raise Error("No VLAN record found for PIF")
780 return vlanrec['tagged_PIF']
782 def pif_get_vlan_masters(pif):
783 """Returns a list of PIFs which are VLANs on top of the given pif."""
785 pifrec = db().get_pif_record(pif)
786 vlans = [db().get_vlan_record(v) for v in pifrec['VLAN_slave_of']]
787 return [v['untagged_PIF'] for v in vlans if v and db().pif_exists(v['untagged_PIF'])]
790 # Datapath base class
793 class Datapath(object):
794 """Object encapsulating the actions necessary to (de)configure the
795 datapath for a given PIF. Does not include configuration of the
796 IP address on the ipdev.
799 def __init__(self, pif):
802 def configure_ipdev(self, cfg):
803 """Write ifcfg TYPE field for an IPdev, plus any type specific
806 raise NotImplementedError
808 def preconfigure(self, parent):
809 """Prepare datapath configuration for PIF, but do not actually
812 Any configuration files should be attached to parent.
814 raise NotImplementedError
816 def bring_down_existing(self):
817 """Tear down any existing network device configuration which
818 needs to be undone in order to bring this PIF up.
820 raise NotImplementedError
823 """Apply the configuration prepared in the preconfigure stage.
825 Should assume any configuration files changed attached in
826 the preconfigure stage are applied and bring up the
827 necesary devices to provide the datapath for the
830 Should not bring up the IPdev.
832 raise NotImplementedError
835 """Called after the IPdev has been brought up.
837 Should do any final setup, including reinstating any
838 devices which were taken down in the bring_down_existing
841 raise NotImplementedError
843 def bring_down(self):
844 """Tear down and deconfigure the datapath. Should assume the
845 IPdev has already been brought down.
847 raise NotImplementedError
849 def DatapathFactory(pif):
850 # XXX Need a datapath object for bridgeless PIFs
853 network_conf = open(root_prefix() + "/etc/xensource/network.conf", 'r')
854 network_backend = network_conf.readline().strip()
857 raise Error("failed to determine network backend:" + e)
859 if network_backend == "bridge":
860 from InterfaceReconfigureBridge import DatapathBridge
861 return DatapathBridge(pif)
862 elif network_backend == "vswitch":
863 from InterfaceReconfigureVswitch import DatapathVswitch
864 return DatapathVswitch(pif)
866 raise Error("unknown network backend %s" % network_backend)