Removes listing of inaccessible subnets

- Related-Bug: 1709249
 - Basicaly implementing @Aloga's suggestion
 - No Exception, logging
 - minor fix for pep8 compliance
 - Adjusting logging level as suggested by Jerome Pansanel

Change-Id: I22fd07025300127d411803d4ea0351eb09c1ce64
This commit is contained in:
Luís Alves 2017-08-09 16:53:02 +01:00
parent 8f3a0de485
commit d5ab0ba7d2
1 changed files with 21 additions and 5 deletions

View File

@ -14,8 +14,11 @@
from ooi.api import helpers
from ooi import exception
from ooi.log import log as logging
from ooi.openstack import helpers as os_helpers
LOG = logging.getLogger(__name__)
class OpenStackNeutron(helpers.BaseHelper):
"""Class to interact with the neutron API."""
@ -275,19 +278,32 @@ class OpenStackNeutron(helpers.BaseHelper):
:param req: the incoming network
:param id: net identification
"""
is_public_network = False
if id == os_helpers.PUBLIC_NETWORK:
id = self._get_public_network(req)
is_public_network = True
path = "/networks/%s" % id
req = self._make_get_request(req, path)
response = req.get_response()
net = self.get_from_response(response, "network", {})
# subnet
if "subnets" in net:
path = "/subnets/%s" % net["subnets"][0]
req_subnet = self._make_get_request(req, path)
response_subnet = req_subnet.get_response()
net["subnet_info"] = self.get_from_response(
response_subnet, "subnet", {})
try:
path = "/subnets/%s" % net["subnets"][0]
req_subnet = self._make_get_request(req, path)
response_subnet = req_subnet.get_response()
net["subnet_info"] = self.get_from_response(
response_subnet, "subnet", {})
except Exception:
if is_public_network:
LOG.info(
"No details from PUBLIC_NETWORK subnet can be fetched"
)
else:
LOG.error(
"No details from the requested subnet can be fetched"
)
ooi_networks = self._build_networks([net])