fix: Remove invalid count of ports list
Neutron does not supply the count of ports from list ports api. So we need to remove invalid count of ports list api from skyline. Closes-Bug: #1948615 Change-Id: I8858c242957a6cda47c08efa1e1d233db15cad18
This commit is contained in:
parent
e50d2a6bc5
commit
4b35a82ea3
@ -2192,11 +2192,6 @@
|
||||
],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"count": {
|
||||
"title": "Count",
|
||||
"type": "integer",
|
||||
"default": 0
|
||||
},
|
||||
"ports": {
|
||||
"title": "Ports",
|
||||
"type": "array",
|
||||
|
@ -21,16 +21,15 @@ from functools import reduce
|
||||
from typing import List
|
||||
|
||||
from dateutil import parser
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException, Query, status
|
||||
from fastapi import APIRouter, Depends, Header, Query, status
|
||||
from skyline_apiserver import schemas
|
||||
from skyline_apiserver.api import deps
|
||||
from skyline_apiserver.api.v1.openstack.base import OSPort, OSServer, OSVolume, OSVolumeSnapshot
|
||||
from skyline_apiserver.api.v1.utils import Port, Server, Service, Volume, VolumeSnapshot
|
||||
from skyline_apiserver.client import utils
|
||||
from skyline_apiserver.client.openstack import cinder, glance, keystone, neutron, nova
|
||||
from skyline_apiserver.client.utils import generate_session, get_endpoint, get_system_session
|
||||
from skyline_apiserver.client.utils import generate_session, get_system_session
|
||||
from skyline_apiserver.config import CONF
|
||||
from skyline_apiserver.network.neutron import get_ports
|
||||
from skyline_apiserver.schemas import common
|
||||
from skyline_apiserver.types import constants
|
||||
from skyline_apiserver.utils.roles import assert_system_admin_or_reader, is_system_reader_no_admin
|
||||
@ -874,7 +873,6 @@ async def list_volume_snapshots(
|
||||
"/extension/ports",
|
||||
description="List Ports.",
|
||||
responses={
|
||||
200: {"model": schemas.ExtListPortsResponse},
|
||||
401: {"model": common.UnauthorizedMessage},
|
||||
403: {"model": common.ForbiddenMessage},
|
||||
500: {"model": common.InternalServerErrorMessage},
|
||||
@ -986,24 +984,17 @@ async def list_ports(
|
||||
kwargs["sort_dir"] = sort_dir
|
||||
kwargs["sort_key"] = sort_keys
|
||||
|
||||
try:
|
||||
neutron_endpoint = await get_endpoint(profile.region, "neutron", current_session)
|
||||
except Exception as ex:
|
||||
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(ex))
|
||||
|
||||
ports = await get_ports(
|
||||
neutron_endpoint,
|
||||
profile.keystone_token,
|
||||
ports = await neutron.list_ports(
|
||||
current_session,
|
||||
profile.region,
|
||||
x_openstack_request_id,
|
||||
kwargs,
|
||||
**kwargs,
|
||||
)
|
||||
ports_count = ports.get("count", 0)
|
||||
ports = ports["ports"]
|
||||
|
||||
server_ids = []
|
||||
network_ids = []
|
||||
result = []
|
||||
for port in ports:
|
||||
for port in ports.get("ports", []):
|
||||
origin_data = OSPort(port).to_dict()
|
||||
port = Port(port).to_dict()
|
||||
port["origin_data"] = origin_data
|
||||
@ -1064,7 +1055,7 @@ async def list_ports(
|
||||
for port in result:
|
||||
port["server_name"] = ser_mappings.get(port["device_id"])
|
||||
port["network_name"] = network_mappings.get(port["network_id"])
|
||||
return {"count": ports_count, "ports": result}
|
||||
return {"ports": result}
|
||||
|
||||
|
||||
@router.get(
|
||||
|
@ -47,3 +47,28 @@ async def list_networks(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=str(e),
|
||||
)
|
||||
|
||||
|
||||
async def list_ports(
|
||||
session: Session,
|
||||
region_name: str,
|
||||
global_request_id: str,
|
||||
**kwargs: Any,
|
||||
) -> Any:
|
||||
try:
|
||||
nc = await utils.neutron_client(
|
||||
session=session,
|
||||
region=region_name,
|
||||
global_request_id=global_request_id,
|
||||
)
|
||||
return await run_in_threadpool(nc.list_ports, **kwargs)
|
||||
except Unauthorized as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail=str(e),
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=str(e),
|
||||
)
|
||||
|
@ -1,56 +0,0 @@
|
||||
# Copyright 2021 99cloud
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
from skyline_apiserver.types import constants
|
||||
from skyline_apiserver.utils.httpclient import get_assert_200
|
||||
|
||||
|
||||
async def get_ports(
|
||||
neutron_endpoint: str,
|
||||
keystone_token: str,
|
||||
global_request_id: str,
|
||||
search_opts: Dict[str, Any],
|
||||
) -> Dict[str, Any]:
|
||||
"""Get the ports in the environment .
|
||||
|
||||
:param neutron_endpoint: Nova endpoint in specified region.
|
||||
:type neutron_endpoint: str
|
||||
:param keystone_token: Keystone token.
|
||||
:type keystone_token: str
|
||||
:param search_opts: Search opts.
|
||||
:type search_opts: dict
|
||||
:return: ports.
|
||||
:rtype: Dict[str, Any]
|
||||
"""
|
||||
url = neutron_endpoint + constants.NEUTRON_PORTS_API
|
||||
qparams = {}
|
||||
for opt, val in search_opts.items():
|
||||
if val:
|
||||
if isinstance(val, six.text_type):
|
||||
val = val.encode("utf-8")
|
||||
if isinstance(val, list):
|
||||
val = [v.encode("utf-8") for v in val]
|
||||
qparams[opt] = val
|
||||
url += "?%s" % parse.urlencode(qparams, doseq=True)
|
||||
resp = await get_assert_200(
|
||||
url,
|
||||
headers={"X-Auth-Token": keystone_token, constants.INBOUND_HEADER: global_request_id},
|
||||
)
|
||||
return resp.json()
|
@ -506,7 +506,6 @@ class ExtListPortsBaseResponse(BaseModel):
|
||||
|
||||
|
||||
class ExtListPortsResponse(BaseModel):
|
||||
count: int = 0
|
||||
ports: List[ExtListPortsBaseResponse]
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user