+s_log = logging.getLogger("ovs-external-ids")
+l_handler = logging.handlers.RotatingFileHandler(
+ "/var/log/openvswitch/ovs-external-ids.log")
+l_formatter = logging.Formatter('%(filename)s: %(levelname)s: %(message)s')
+l_handler.setFormatter(l_formatter)
+s_log.addHandler(l_handler)
+s_log.setLevel(logging.INFO)
+
# same as "xs-vif-uuid". This may be overridden by defining a
# "nicira-iface-id" key in the "other_config" field of the VIF
# record of XAPI.
# same as "xs-vif-uuid". This may be overridden by defining a
# "nicira-iface-id" key in the "other_config" field of the VIF
# record of XAPI.
- return default
-
- for n in session.xenapi.VM.get_all():
- if session.xenapi.VM.get_domid(n) == domain:
- vifs = session.xenapi.VM.get_VIFs(n)
- for vif in vifs:
- rec = session.xenapi.VIF.get_record(vif)
- if rec['device'] == device:
- return rec['other_config'].get('nicira-iface-id', default)
- return None
+ s_log.warning("Failed to get interface id %s because"
+ " XAPI session could not be initialized" % if_name)
+ return xs_vif_uuid
+ try:
+ vif = session.xenapi.VIF.get_by_uuid(xs_vif_uuid)
+ rec = session.xenapi.VIF.get_record(vif)
+ return rec['other_config'].get('nicira-iface-id', xs_vif_uuid)
+ except XenAPI.Failure:
+ s_log.warning("Could not find XAPI entry for VIF %s" % if_name)
+ return xs_vif_uuid
def set_external_id(table, record, key, value):
col = 'external-ids:"' + key + '"="' + value + '"'
cmd = [vsctl, "--timeout=30", "-vANY:console:emer", "set", table, record, col]
exitcode = subprocess.call(cmd)
if exitcode != 0:
def set_external_id(table, record, key, value):
col = 'external-ids:"' + key + '"="' + value + '"'
cmd = [vsctl, "--timeout=30", "-vANY:console:emer", "set", table, record, col]
exitcode = subprocess.call(cmd)
if exitcode != 0:
# XAPI on XenServer 5.6 uses the external-id "network-uuids" for internal
# networks, but we now prefer "xs-network-uuids". Look for its use and
# XAPI on XenServer 5.6 uses the external-id "network-uuids" for internal
# networks, but we now prefer "xs-network-uuids". Look for its use and