def _check_delete_network(self, context, network): network_id = network["id"] # NOTE(ft): check non default routes not longer exists # must be done for internet routes routes, dummy = self._sync_routes(context) for route in routes.itervalues(): if (route["network_id"] == network_id and not route["is_default"]): raise exception.InvalidInput(_("Network contains routes")) # NOTE(ft): check invisible routes not longer exists # must be done for routes on non default subnet and other non GCE stuff client = clients.neutron(context) checked_routers = set() subnets = client.list_subnets(network_id=network_id)["subnets"] cidrs = [netaddr.IPNetwork(subnet["cidr"]) for subnet in subnets] ports = client.list_ports( network_id=network["id"], device_owner="network:router_interface")["ports"] for port in ports: if port["device_id"] in checked_routers: continue checked_routers.add(port["device_id"]) router = client.show_router(port["device_id"])["router"] for route in router["routes"]: nexthop = netaddr.IPAddress(route["nexthop"]) if any(nexthop in cidr for cidr in cidrs): raise exception.InvalidInput(_("Network contains routes"))
def delete_item(self, context, name, scope=None): routes, aliased_routes = self._sync_routes(context) route = routes[name] if route.get("nexthop") is None: raise exception.InvalidInput( _("The local route cannot be deleted.")) destination = route["destination"] nexthop = route["nexthop"] # NOTE(ft): delete OS route only if it doesn't have aliases # at the moment client = clients.neutron(context) operation_util.start_operation(context) if self._get_route_key(route) not in aliased_routes: dummy, router = self._get_network_objects(client, route["network"]) if "external_gateway_info" in route: client.remove_gateway_router(router["id"]) else: routes = [ r for r in router["routes"] if (destination != r["destination"] or nexthop != r["nexthop"]) ] client.update_router(router["id"], { "router": { "routes": routes, }, }) self._delete_db_item(context, route)
def add_item(self, context, name, body, scope=None): client = clients.nova(context) if any(x["name"] == name for x in self._get_floating_ips(client, context, scope)): raise exception.InvalidInput( _("The resource '%s' already exists.") % name) operation_util.start_operation(context) result = client.floating_ips.create() floating_ip = self._prepare_floating_ip(client, context, result, scope) floating_ip["name"] = body["name"] if "description" in body: floating_ip["description"] = body["description"] floating_ip = self._add_db_item(context, floating_ip) return floating_ip
def __init__(self, name, app, host='0.0.0.0', port=0, pool_size=None, protocol=eventlet.wsgi.HttpProtocol, backlog=128, use_ssl=False, max_url_len=None): """Initialize, but do not start, a WSGI server. :param name: Pretty name for logging. :param app: The WSGI application to serve. :param host: IP address to serve the application. :param port: Port number to server the application. :param pool_size: Maximum number of eventlets to spawn concurrently. :param backlog: Maximum number of queued connections. :param max_url_len: Maximum length of permitted URLs. :returns: None :raises: gceapi.exception.InvalidInput """ self.name = name self.app = app self._server = None self._protocol = protocol self._pool = eventlet.GreenPool(pool_size or self.default_pool_size) self._logger = logging.getLogger("gceapi.%s.wsgi.server" % self.name) self._use_ssl = use_ssl self._max_url_len = max_url_len if backlog < 1: raise exception.InvalidInput( reason='The backlog must be more than 1') bind_addr = (host, port) # TODO(dims): eventlet's green dns/socket module does not actually # support IPv6 in getaddrinfo(). We need to get around this in the # future or monitor upstream for a fix try: info = socket.getaddrinfo(bind_addr[0], bind_addr[1], socket.AF_UNSPEC, socket.SOCK_STREAM)[0] family = info[0] bind_addr = info[-1] except Exception: family = socket.AF_INET self._socket = eventlet.listen(bind_addr, family, backlog=backlog) (self.host, self.port) = self._socket.getsockname()[0:2] LOG.info(_("%(name)s listening on %(host)s:%(port)s") % self.__dict__)
def add_item(self, context, name, body, scope=None): routes, dummy = self._sync_routes(context) if name in routes: raise exception.InvalidInput( _("The resource '%s' already exists.") % name) # NOTE(ft): check network is plugged to router network_name = utils._extract_name_from_url(body["network"]) network = network_api.API().get_item(context, network_name) nexthop = body.get("nextHopGateway") if (nexthop is not None and (utils._extract_name_from_url(nexthop) == "default-internet-gateway") and # NOTE(ft): OS doesn't support IP mask for external gateway body.get("destRange") == ALL_IP_CIDR): operation_util.start_operation(context) return self._create_internet_route(context, network, body) nexthop = body.get("nextHopIp") if nexthop is not None: operation_util.start_operation(context) return self._create_custom_route(context, network, body) raise exception.InvalidInput(_("Unsupported route."))
def add_item(self, context, name, body, scope=None): if any(x["name"] == name for x in self._get_floating_ips(context, scope)): raise exception.InvalidInput( _("The resource '%s' already exists.") % name) public_network_id = network_api.API().get_public_network_id(context) operation_util.start_operation(context) floating_ip = clients.neutron(context).create_floatingip( {"floatingip": { "floating_network_id": public_network_id }}) floating_ip = self._prepare_floating_ip(clients.nova(context), floating_ip["floatingip"], scope) floating_ip["name"] = body["name"] if "description" in body: floating_ip["description"] = body["description"] floating_ip = self._add_db_item(context, floating_ip) return floating_ip
def add_item(self, context, name, body, scope_id=None): raise exception.InvalidInput(reason=NOT_SUPPORTED_MESSAGE)
def get_items(self, context, scope_id=None): raise exception.InvalidInput(reason=NOT_SUPPORTED_MESSAGE)