def _get_attachment_from_id(self, req, attachment_id): try: server_id, vol_id = attachment_id.split('_', 1) except ValueError: raise exception.LinkNotFound(link_id=attachment_id) vols = self.os_helper.get_server_volumes_link(req, server_id) for v in vols: if vol_id == v["volumeId"]: return v raise exception.LinkNotFound(link_id=attachment_id)
def _get_interface_from_id(self, req, id): try: server_id, server_addr = id.split('_', 1) except ValueError: raise exception.LinkNotFound(link_id=id) s = self.os_helper.get_server(req, server_id) addresses = s.get("addresses", {}) for addr_set in addresses.values(): for addr in addr_set: if addr["addr"] == server_addr: return self._build_os_net_iface(req, server_id, addr) raise exception.LinkNotFound(link_id=id)
def test_show_invalid_id(self, m_show): tenant = fakes.tenants["foo"] link_id = uuid.uuid4().hex m_show.side_effect = exception.LinkNotFound(link_id=link_id) req = self._build_req("/networklink/%s" % link_id, tenant["id"], method="GET") resp = req.get_response(self.app) self.assertEqual(404, resp.status_code)
def _get_interface_from_id(self, req, id): """Get interface from id :param req: request object :param id: network link identification """ try: server_id, network_id, server_addr = id.split('_', 2) except ValueError: raise exception.LinkNotFound(link_id=id) try: link = self.os_helper.get_compute_net_link(req, server_id, network_id, server_addr) occi_instance = _get_network_link_resources([link])[0] except Exception: raise exception.LinkNotFound(link_id=id) return occi_instance
def _get_interface_from_id(self, req, id): try: server_id, server_addr = id.split('_', 1) except ValueError: raise exception.LinkNotFound(link_id=id) s = self.os_helper.get_server(req, server_id) addresses = s.get("addresses", {}) for addr_set in addresses.values(): for addr in addr_set: if addr["addr"] == server_addr: n, ip_id = self._get_os_network_ip(req, addr) c = compute.ComputeResource(title="Compute", id=server_id) # TODO(enolfc): get the MAC? return os_network.OSNetworkInterface(c, n, "mac", addr["addr"], ip_id) raise exception.LinkNotFound(link_id=id)
def delete_port(self, req, mac): """Delete a port to the subnet Returns the port information :param req: the incoming network :param mac: link mac """ attributes_port = {"mac_address": mac} ports = self.list_resources(req, 'ports', attributes_port) if ports.__len__() == 0: raise exception.LinkNotFound("Interface %s not found" % mac) out = self.delete_resource(req, 'ports', ports[0]['id']) return out
def delete(self, req, id): """Delete security group link :param req: current request :param id: identification """ link_info = self._get_attachment_from_id(req, id) server_id = link_info["server_id"] security_id = link_info["securitygroup_id"] try: self.os_helper.delete_server_security_link(req, server_id, security_id) except Exception: raise exception.LinkNotFound(link_id=id) return []
def show(self, req, id): """Get security group details :param req: request object :param id: security group identification """ try: link_info = self._get_attachment_from_id(req, id) server_id = link_info["server_id"] security_name = link_info["securitygroup_id"] link = self.os_helper.get_server_security_link( req, server_id, security_name) occi_instance = _get_security_link_resources(link)[0] return occi_instance except Exception: raise exception.LinkNotFound(link_id=id)
def delete_port(self, req, compute_id, ip_id): """Delete a port to the subnet Returns the port information :param req: the incoming network :param compute_id: compute id :param ip_id: ip id """ path = "servers/%s/os-interface" % compute_id tenant_id = self.tenant_from_req(req) path = "/%s/%s/%s" % (tenant_id, path, ip_id) os_req = self._get_req(req, path=path, method="DELETE") os_req.get_response(self.app) return [] raise exception.LinkNotFound("Interface %s not found" % ip_id)
def _get_attachment_from_id(self, req, attachment_id): try: server_id, security_id = attachment_id.split('_', 1) return {"server_id": server_id, "securitygroup_id": security_id} except ValueError: raise exception.LinkNotFound(link_id=attachment_id)