- for rec in idl.data["Interface"].itervalues():
- name = rec.name.as_scalar()
- xs_vif_uuid = rec.external_ids.get("xs-vif-uuid")
- iface_id = rec.external_ids.get("iface-id")
- new_interfaces[name] = {"xs-vif-uuid": xs_vif_uuid,
- "iface-id": iface_id}
-
- if name.startswith("vif"):
- new_interfaces[name]["iface-status"] = "active"
-
- #Tap devices take their xs-vif-uuid from their corresponding vif and
- #cause that vif to be labled inactive.
- for name in new_interfaces:
- if not name.startswith("tap"):
- continue
-
- vif = name.replace("tap", "vif", 1)
-
- if vif in new_interfaces:
- xs_vif_uuid = new_interfaces[vif]["xs-vif-uuid"]
- new_interfaces[name]["xs-vif-uuid"] = xs_vif_uuid
-
- new_interfaces[vif]["iface-status"] = "inactive"
- new_interfaces[name]["iface-status"] = "active"
-
- if bridges != new_bridges:
- for name,ids in new_bridges.items():
- if name not in bridges:
- update_fail_mode(name)
- update_in_band_mgmt(name)
-
- if (name not in bridges) or (bridges[name] != ids):
- update_bridge_id(name, ids)
-
- bridges = new_bridges
+ for row in idl.tables["Interface"].rows.itervalues():
+ # Match up paired vif and tap devices.
+ if row.name.startswith("vif"):
+ vif = row
+ tap = iface_by_name.get("tap%s" % row.name[3:])
+ elif row.name.startswith("tap"):
+ tap = row
+ vif = iface_by_name.get("vif%s" % row.name[3:])
+ else:
+ tap = vif = None
+
+ # Several tap external-ids need to be copied from the vif.
+ if row == tap and vif:
+ keys = ["attached-mac",
+ "xs-network-uuid",
+ "xs-vif-uuid",
+ "xs-vm-uuid"]
+ for k in keys:
+ set_external_id(row, k, vif.external_ids.get(k))
+
+ # If it's a new interface or its xs-vif-uuid has changed, then
+ # obtain the iface-id from XAPI.
+ #
+ # (A tap's xs-vif-uuid comes from its vif. That falls out
+ # naturally from the copy loop above.)
+ new_xvu = row.external_ids.get("xs-vif-uuid", "")
+ old_xvu = interfaces.get(row.name)
+ if old_xvu != new_xvu:
+ iface_id = get_iface_id(row.name, new_xvu)
+ if iface_id and row.external_ids.get("iface-id") != iface_id:
+ set_external_id(row, "iface-id", iface_id)
+
+ # When there's a vif and a tap, the tap is active (used for
+ # traffic). When there's just a vif, the vif is active.
+ #
+ # A tap on its own shouldn't happen, and we don't know
+ # anything about other kinds of devices, so we don't use
+ # an iface-status for those devices at all.
+ if vif and tap:
+ set_external_id(tap, "iface-status", "active")
+ set_external_id(vif, "iface-status", "inactive")
+ elif vif:
+ set_external_id(vif, "iface-status", "active")
+ else:
+ set_external_id(row, "iface-status", None)
+
+ new_interfaces[row.name] = new_xvu
+ interfaces = new_interfaces
+
+ txn.commit_block()