def _port_dict(port, fields=None):
res = {"id": port.get("id"),
"name": port.get("name"),
"network_id": port["network_id"],
"tenant_id": port.get("tenant_id"),
"mac_address": port.get("mac_address"),
"admin_state_up": port.get("admin_state_up"),
"status": "ACTIVE",
"security_groups": [group.get("id", None) for group in
port.get("security_groups", None)],
"device_id": port.get("device_id"),
"device_owner": port.get("device_owner")}
if "mac_address" in res and res["mac_address"]:
mac = str(netaddr.EUI(res["mac_address"])).replace('-', ':')
res["mac_address"] = mac
# NOTE(mdietz): more pythonic key in dict check fails here. Leave as get
if port.get("bridge"):
res["bridge"] = port["bridge"]
# NOTE(ClifHouck): This causes another trip to the DB since tags are
# are not eager loaded. According to mdietz this be a small impact on
# performance, but if the tag system gets used more on ports, we may
# want to eager load the tags.
try:
t = PORT_TAG_REGISTRY.get_all(port)
res.update(t)
except Exception as e:
# NOTE(morgabra) We really don't want to break port-listing if
# this goes sideways here, so we pass.
msg = ("Unknown error loading tags for port %s: %s"
% (port["id"], e))
LOG.exception(msg)
return res
评论列表
文章目录