+ # Either the machine isn't running, or the route is missing. We can
+ # fix the latter.
+ try:
+ xsc = xs.xs()
+ domid = xsc.read('', '/vm/%s/device/vif/0/frontend-id' % (nic.machine.uuid))
+ # If we didn't find the domid, the machine is either off or the
+ # UUID in xenstore isn't right. Try slightly harder.
+ if not domid:
+ for uuid in xsc.ls('', '/vm'):
+ if xsc.read('', '/vm/%s/name' % (uuid)) == 'd_' + nic.machine.name:
+ domid = xsc.read('', '/vm/%s/device/vif/0/frontend-id' % (uuid))
+ if not domid:
+ xsc.close()
+ return None
+ for vifnum in xsc.ls('', '/local/domain/0/backend/vif/%s' % (domid)):
+ if xsc.read('', '/local/domain/0/backend/vif/%s/%s/mac' % (domid, vifnum)) == nic.mac_addr:
+ # Prefer the tap if it exists; paravirtualized HVMs will
+ # have already unplugged it, so if it's there, it's the one
+ # in use.
+ for viftype in ('tap', 'vif'):
+ vif = '%s%s.%s' % (viftype, domid, vifnum)
+ if Interfaces.exists(vif):
+ self.add_route_and_arp(nic.ip, vif, nic.gateway)
+ xsc.close()
+ return vif
+ xsc.close()
+ except Exception as e:
+ try:
+ xsc.close()
+ except Exception as e2:
+ s.syslog(s.LOG_ERR, "Could not close connection to xenstore: %s" % (e2))
+ s.syslog(s.LOG_ERR, "Could not find interface and add missing route: %s" % (e))