ia64/xen-unstable

changeset 19330:8401a1f14759

xend: Allow off-line NIC removal

Match a MAC address so device_destroy can remove off-line NICs.

Signed-off-by: John Levon <john.levon@sun.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Mar 12 10:59:53 2009 +0000 (2009-03-12)
parents 728df5693cd2
children db53046ca5f0
files tools/python/xen/xend/server/netif.py
line diff
     1.1 --- a/tools/python/xen/xend/server/netif.py	Thu Mar 12 10:59:19 2009 +0000
     1.2 +++ b/tools/python/xen/xend/server/netif.py	Thu Mar 12 10:59:53 2009 +0000
     1.3 @@ -24,7 +24,7 @@ import os
     1.4  import random
     1.5  import re
     1.6  
     1.7 -from xen.xend import XendOptions
     1.8 +from xen.xend import XendOptions, sxp
     1.9  from xen.xend.server.DevController import DevController
    1.10  from xen.xend.XendError import VmError
    1.11  from xen.xend.XendXSPolicyAdmin import XSPolicyAdminInstance
    1.12 @@ -196,3 +196,23 @@ class NetifController(DevController):
    1.13                  result[x] = y
    1.14  
    1.15          return result
    1.16 +
    1.17 +    # match a VIF ID from xenstore, or a MAC address stored in the domain config
    1.18 +    def convertToDeviceNumber(self, devid):
    1.19 +        try:
    1.20 +            return int(devid)
    1.21 +        except ValueError:
    1.22 +            if type(devid) is not str:
    1.23 +                raise VmError("devid %s is wrong type" % str(devid))
    1.24 +            try:
    1.25 +                dev = devid.split('/')[-1]
    1.26 +                return (int(dev))
    1.27 +            except ValueError:
    1.28 +                devs = [d for d in self.vm.info.all_devices_sxpr()
    1.29 +                    if d[0] == 'vif']
    1.30 +                for nr in range(len(devs)):
    1.31 +                    dev_type, dev_info = devs[nr]
    1.32 +                    if (sxp.child_value(dev_info, 'mac').lower() ==
    1.33 +                        devid.lower()):
    1.34 +                        return nr
    1.35 +                raise VmError("unknown devid %s" % str(devid))