Skip to content
Snippets Groups Projects
Commit 5a15c97e authored by Shayan Hajipour's avatar Shayan Hajipour
Browse files

debug:

- app_flow_name retrieval from config rule fixed
parent 91b779d7
No related branches found
No related tags found
2 merge requests!359Release TeraFlowSDN 5.0,!304Resolve "(CTTC) Driver required to interact with NCE controller"
...@@ -128,20 +128,14 @@ class NCEDriver(_Driver): ...@@ -128,20 +128,14 @@ class NCEDriver(_Driver):
return results return results
def Connect(self) -> bool: def Connect(self) -> bool:
url = (
self.__tfs_nbi_root + "/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services"
)
with self.__lock: with self.__lock:
if self.__started.is_set(): if self.__started.is_set():
return True return True
try: try:
# requests.get(url, timeout=self.__timeout)
... ...
except requests.exceptions.Timeout: except requests.exceptions.Timeout:
LOGGER.exception("Timeout connecting {:s}".format(url))
return False return False
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
LOGGER.exception("Exception connecting {:s}".format(url))
return False return False
else: else:
self.__started.set() self.__started.set()
...@@ -206,6 +200,7 @@ class NCEDriver(_Driver): ...@@ -206,6 +200,7 @@ class NCEDriver(_Driver):
with self.__lock: with self.__lock:
for resource in resources: for resource in resources:
resource_key, resource_value = resource resource_key, resource_value = resource
LOGGER.debug("resource = {:s}".format(str(resource)))
if RE_NCE_APP_FLOW_OPERATION.match(resource_key): if RE_NCE_APP_FLOW_OPERATION.match(resource_key):
operation_type = json.loads(resource_value)["type"] operation_type = json.loads(resource_value)["type"]
results.append((resource_key, True)) results.append((resource_key, True))
...@@ -224,7 +219,7 @@ class NCEDriver(_Driver): ...@@ -224,7 +219,7 @@ class NCEDriver(_Driver):
elif operation_type == "delete": elif operation_type == "delete":
app_flow_name = resource_value["huawei-nce-app-flow:app-flows"][ app_flow_name = resource_value["huawei-nce-app-flow:app-flows"][
"app-flow" "app-flow"
][0]["name"] ][0]["app-name"]
self.nce.delete_app_flow(app_flow_name) self.nce.delete_app_flow(app_flow_name)
LOGGER.debug(f"app_flow_datamodel {resource_value}") LOGGER.debug(f"app_flow_datamodel {resource_value}")
results.append((resource_key, True)) results.append((resource_key, True))
......
...@@ -12,11 +12,14 @@ ...@@ -12,11 +12,14 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging
from typing import Optional from typing import Optional
import requests import requests
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
LOGGER = logging.getLogger(__name__)
NCE_FAN_URL = "{:s}://{:s}:{:d}/restconf/v1/data" NCE_FAN_URL = "{:s}://{:s}:{:d}/restconf/v1/data"
TIMEOUT = 30 TIMEOUT = 30
...@@ -48,6 +51,7 @@ MAPPING_DRIVER = { ...@@ -48,6 +51,7 @@ MAPPING_DRIVER = {
"DEVICEDRIVER_OC": 11, "DEVICEDRIVER_OC": 11,
} }
HEADERS = {'Content-Type': 'application/json'}
class NCEClient: class NCEClient:
def __init__( def __init__(
...@@ -65,20 +69,24 @@ class NCEClient: ...@@ -65,20 +69,24 @@ class NCEClient:
try: try:
app_data = app_flow_data["huawei-nce-app-flow:app-flows"]["applications"] app_data = app_flow_data["huawei-nce-app-flow:app-flows"]["applications"]
app_url = self._nce_fan_url + "/app-flows/apps" app_url = self._nce_fan_url + "/app-flows/apps"
requests.post(app_url, json=app_data) LOGGER.info(f'Creating app: {app_data} URL: {app_url}')
# requests.post(app_url, json=app_data, headers=HEADERS)
app_flow_data = { app_flow_data = {
"app-flow": app_flow_data["huawei-nce-app-flow:app-flows"]["app-flow"] "app-flow": app_flow_data["huawei-nce-app-flow:app-flows"]["app-flow"]
} }
app_flow_url = self._nce_fan_url + "/app-flows" app_flow_url = self._nce_fan_url + "/app-flows"
requests.post(app_flow_url, json=app_flow_data) LOGGER.info(f'Creating app flow: {app_flow_data} URL: {app_flow_url}')
# requests.post(app_flow_url, json=app_flow_data, headers=HEADERS)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
raise Exception("faild to send post requests to NCE FAN") raise Exception("faild to send post requests to NCE FAN")
def delete_app_flow(self, app_flow_name: str) -> None: def delete_app_flow(self, app_flow_name: str) -> None:
try: try:
app_url = self._nce_fan_url + f"/app-flows/apps/application={app_flow_name}" app_url = self._nce_fan_url + f"/app-flows/apps/application={app_flow_name}"
requests.delete(app_url) LOGGER.info(f'Deleting app: {app_flow_name} URL: {app_url}')
# requests.delete(app_url)
app_flow_url = self._nce_fan_url + f"/app-flows/app-flow={app_flow_name}" app_flow_url = self._nce_fan_url + f"/app-flows/app-flow={app_flow_name}"
requests.delete(app_flow_url) LOGGER.info(f'Deleting app flow: {app_flow_name} URL: {app_flow_url}')
# requests.delete(app_flow_url)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
raise Exception("faild to send delete request to NCE FAN") raise Exception("faild to send delete request to NCE FAN")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment