def _build_link(net_id, compute_id, ip, mac=None, pool=None, state='ACTIVE'): link = {} link['mac'] = mac link['pool'] = pool link['network_id'] = net_id link['compute_id'] = compute_id link['ip'] = ip link['state'] = os_helpers.network_status(state) return link
def list_compute_net_links(self, req, network_id, device_id): """List the network and compute links It lists every private and public ip related to the servers of the tenant :param req: the incoming request :param network_id: id network :param device_id: id device """ param_port = {'device_owner': 'compute:nova', 'device_id': device_id, 'network_id': network_id } link_list = [] try: ports = self.list_resources(req, 'ports', param_port) for port in ports: link_private = self._build_link( port["network_id"], port['device_id'], port["fixed_ips"][0]["ip_address"], mac=port["mac_address"], state=os_helpers.network_status(port["status"])) link_list.append(link_private) # Query public links associated to the port floating_ips = self.list_resources(req, 'floatingips', {"port_id": port['id']}) for f_ip in floating_ips: link_public = self._build_link( port["network_id"], port['device_id'], f_ip['floating_ip_address'], mac=port["mac_address"], pool=f_ip['floating_network_id']) link_list.append(link_public) except Exception: raise exception.NotFound() return link_list
def list_compute_net_links(self, req, network_id, device_id): """List the network and compute links It lists every private and public ip related to the servers of the tenant :param req: the incoming request :param network_id: id network :param device_id: id device """ param_port = { 'device_owner': 'compute:nova', 'device_id': device_id, 'network_id': network_id } link_list = [] try: ports = self.list_resources(req, 'ports', param_port) for port in ports: link_private = self._build_link( port["network_id"], port['device_id'], port["fixed_ips"][0]["ip_address"], mac=port["mac_address"], state=os_helpers.network_status(port["status"])) link_list.append(link_private) # Query public links associated to the port floating_ips = self.list_resources(req, 'floatingips', {"port_id": port['id']}) for f_ip in floating_ips: link_public = self._build_link( port["network_id"], port['device_id'], f_ip['floating_ip_address'], mac=port["mac_address"], pool=f_ip['floating_network_id']) link_list.append(link_public) except Exception: raise exception.NotFound() return link_list
def _build_networks(networks): ooi_net_list = [] for net in networks: ooi_net = {} status = net.get("status", None) ooi_net["state"] = os_helpers.network_status(status) public = net.get('router:external', None) if public: ooi_net["id"] = os_helpers.PUBLIC_NETWORK # TODO(jorgesece): include info about pools else: ooi_net["id"] = net["id"] ooi_net["name"] = net.get("name", None) if "subnet_info" in net: sub = net["subnet_info"] ooi_net["address"] = sub.get("cidr", None) ooi_net["ip_version"] = sub.get("ip_version", None) ooi_net["gateway"] = sub.get("gateway_ip", None) ooi_net_list.append(ooi_net) return ooi_net_list