+ # get ports and port_bindings from the port and publish fields of CNFD
+ # see: https://github.com/containernet/containernet/wiki/Exposing-and-mapping-network-ports
+ ports = list() # Containernet naming
+ port_bindings = dict()
+ for i in intfs:
+ if i.get("port"): # field with a single port
+ if not isinstance(i.get("port"), int):
+ LOG.info("Field 'port' is no int CP: {}".format(i))
+ else:
+ ports.append(i.get("port")) # collect all ports
+ if i.get("ports"): # list with multiple ports
+ if not isinstance(i.get("ports"), list):
+ LOG.info("Field 'port' is no list CP: {}".format(i))
+ else:
+ for p in i.get("ports"):
+ if not isinstance(p, int):
+ # do some parsing
+ try:
+ if "/udp" in p:
+ p = tuple(p.split("/"))
+ else:
+ p = int(p)
+ ports.append(p) # collect all ports
+ except BaseException as ex:
+ LOG.error(
+ "Could not parse ports list: {}".format(p))
+ LOG.error(ex)
+ else:
+ ports.append(p) # collect all ports
+ if i.get("publish"):
+ if not isinstance(i.get("publish"), dict):
+ LOG.info("Field 'publish' is no dict CP: {}".format(i))
+ else:
+ port_bindings.update(i.get("publish"))
+ # update port mapping for cases where service is deployed > 1 times
+ port_bindings = update_port_mapping_multi_instance(ssiid, port_bindings)
+ if len(ports) > 0:
+ LOG.info("{} exposes ports: {}".format(vnf_container_instance_name, ports))
+ if len(port_bindings) > 0:
+ LOG.info("{} publishes ports: {}".format(vnf_container_instance_name, port_bindings))
+