Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWall89 committed Dec 17, 2020
2 parents eb2e87e + 31853ef commit 0b60042
Show file tree
Hide file tree
Showing 27 changed files with 761 additions and 294 deletions.
34 changes: 29 additions & 5 deletions adaptation_layer/driver/ever.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
import logging
import os
import re
from typing import Dict, Tuple
Expand All @@ -29,6 +30,7 @@
TESTING = os.environ.get("TESTING", False)
PRISM_ALIAS = os.environ.get("PRISM_ALIAS", "prism-ever")

logger = logging.getLogger('app.driver.ever')

class EVER(Driver):

Expand All @@ -45,7 +47,8 @@ def __init__(self, rano_cred):
self._base_path = 'http://{0}:{1}'.format(PRISM_ALIAS, 9999)

def _exec_delete(self, url=None, params=None, headers=None):

logger.debug('#############execute delete######')
logger.debug('url= ' + url)
try:
resp = requests.delete(url, params=params, verify=False, headers=headers)
except Exception as e:
Expand All @@ -64,17 +67,26 @@ def _exec_delete(self, url=None, params=None, headers=None):
raise ResourceNotFound()
else:
error = resp.json()
logger.debug('############')
logger.debug('error: ' + error)
logger.debug('###########')
raise ServerError(error)

def _exec_post(self, url=None, data=None, json=None, headers=None):

logger.debug('#############execute post######')
logger.debug('url= ' + url)
try:
resp = requests.post(url, data=data, json=json, verify=False, headers=headers)
except Exception as e:
raise ServerError(str(e))

if resp.status_code in (200, 201, 202, 206):
if 'application/json' in resp.headers['content-type']:
try:
ctype = resp.headers['content-type']
except KeyError:
# success but no content
return None, resp.headers
if 'application/json' in ctype:
return resp.json(), resp.headers
else:
return resp.text, resp.headers
Expand All @@ -89,10 +101,14 @@ def _exec_post(self, url=None, data=None, json=None, headers=None):
error = resp.json()
else:
error = resp.text
logger.debug('############')
logger.debug('error: ' + error)
logger.debug('###########')
raise ServerError(error)

def _exec_get(self, url=None, params=None, headers=None):

logger.debug('#############execute get######')
logger.debug('url= ' + url)
try:
resp = requests.get(url, params=params, verify=False, headers=headers)
except Exception as e:
Expand All @@ -111,6 +127,9 @@ def _exec_get(self, url=None, params=None, headers=None):
raise ResourceNotFound()
else:
error = resp.json()
logger.debug('############')
logger.debug('error: ' + error)
logger.debug('###########')
raise ServerError(error)

# all methods
Expand Down Expand Up @@ -158,9 +177,14 @@ def delete_ns(self, nsId: str, args: Dict = None) -> Tuple[None, Headers]:
def instantiate_ns(self, nsId: str, args=None) -> Tuple[None, Headers]:
_url = '{0}/instantiate/{1}'.format(self._base_path, nsId)
_url = self._build_url_query(_url, args)
instantiate_payload = {}
try:
instantiate_payload['SapData'] = args['payload']['SapData']
except (TypeError, KeyError):
logger.info('no SapData')
try:
empty_body, resp_headers = self._exec_post(
_url, headers={})
_url, json=instantiate_payload, headers={})
except ResourceNotFound:
raise NsNotFound(ns_id=nsId)
headers = self._build_headers(resp_headers)
Expand Down
41 changes: 29 additions & 12 deletions adaptation_layer/driver/fivegr_so.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

from urllib.parse import urlencode

import logging
logger = logging.getLogger('app.driver.fivegr_so')

TESTING = os.environ.get("TESTING", False)
PRISM_ALIAS = os.environ.get("PRISM_ALIAS", "prism-fivegr-so")

Expand All @@ -47,7 +50,7 @@ def __init__(self, nfvo_cred):
self._port = nfvo_cred["port"] if "port" in nfvo_cred else 8080
self._headers = {"Content-Type": "application/json",
"Accept": "application/json"}

logger.debug("_host:{} _port:{}".format(self._host, self._port))
if TESTING is False:
self._base_path = 'http://{0}:{1}/5gt/so/v1'.format(self._host, self._port)
else:
Expand Down Expand Up @@ -163,9 +166,11 @@ def create_ns(self, args: Dict = None) -> Tuple[Body, Headers]:
nsIdRaw, resp_headers = self._exec_post(
_url, json=args['payload'], headers=self._headers)
nsId = nsIdRaw['nsId']
nsInstance, resp_headers = self.get_ns(nsId)
nsInstance["nsInstanceName"] = args['payload']['nsName']
nsInstance["nsInstanceDescription"] = args['payload']['nsDescription']
logger.debug("nsId:{}".format(nsId))
# nsInstance, resp_headers = self.get_ns(nsId) # FIXME get_ns without instantiation does not work in 5gr-so
sol005NsInstance = SOL005NSInstance(id=nsId, nsInstanceName=args['payload']['nsName'], nsInstanceDescription=args['payload']['nsDescription'], nsState="NOT_INSTANTIATED")

nsInstance = to_dict(sol005NsInstance)
except ResourceNotFound:
nsd_Id = args['payload']['nsdId']
raise NsdNotFound(nsd_id=nsd_Id)
Expand All @@ -177,11 +182,9 @@ def get_ns(self, nsId: str, args: Dict = None) -> Tuple[Body, Headers]:
_url = self._build_url_query(_url, args)
try:
nsInfoDict, resp_headers = self._exec_get(_url, headers=self._headers)
status = nsInfoDict.pop('status', None)
nsInfoDict['nsState'] = status
nsInfoDict = nsInfoDict["queryNsResult"][0]
nsInfo = IFA013NsInfo(**nsInfoDict)
nsInstance = ifa013nsinfo_to_sol005nsinstance(nsInfo)
nsInstance.id = nsId # NSInfo does not contain the id of the NS instance
except ResourceNotFound:
raise NsNotFound(ns_id=nsId)
headers = {}
Expand All @@ -194,18 +197,18 @@ def instantiate_ns(self, nsId: str, args: Dict = None) -> Tuple[None, Headers]:
_url = '{0}/ns/{1}/instantiate'.format(self._base_path, nsId)
_url = self._build_url_query(_url, args)
if 'payload' not in args:
raise BadRequest(ns_id=nsId)
raise BadRequest(description="Payload not found for id: {}".format(nsId))
sol005InstantiateNsRequest = SOL005InstantiateNsRequest(**args['payload'])
ifa013InstantiateNsRequest = sol005InstantiateNsRequest_to_ifa013InstantiateNsRequest(sol005InstantiateNsRequest)
ifa013InstantiateNsRequestDict = to_dict(ifa013InstantiateNsRequest)
# print(json.dumps(ifa013InstantiateNsRequestDict, indent=4, sort_keys=True))
try:
operationIdRaw, resp_headers = self._exec_put(
_url, headers=self._headers, json=ifa013InstantiateNsRequestDict)
except ResourceNotFound:
raise NsNotFound(ns_id=nsId)
operationId = operationIdRaw["operationId"]
headers = self._build_lcm_op_occs_header(operationId)
logger.debug("operationId:{}".format(operationId))
return None, headers

def terminate_ns(self, nsId: str, args: Dict = None) -> Tuple[None, Headers]:
Expand All @@ -218,6 +221,7 @@ def terminate_ns(self, nsId: str, args: Dict = None) -> Tuple[None, Headers]:
raise NsNotFound(ns_id=nsId)
operationId = operationIdRaw["operationId"]
headers = self._build_lcm_op_occs_header(operationId)
logger.debug("operationId:{}".format(operationId))
return None, headers

def scale_ns(self, nsId: str, args: Dict = None) -> Tuple[None, Headers]:
Expand All @@ -234,6 +238,7 @@ def scale_ns(self, nsId: str, args: Dict = None) -> Tuple[None, Headers]:
raise NsNotFound(ns_id=id)
operationId = operationIdRaw["operationId"]
headers = self._build_lcm_op_occs_header(operationId)
logger.debug("operationId:{}".format(operationId))
return None, headers

def get_op_list(self, args: Dict = None) -> Tuple[BodyList, Headers]:
Expand Down Expand Up @@ -337,13 +342,22 @@ def __init__(self, nsVirtualLinkDescId="", resourceHandle=None, linkPort=None):
[self.linkPort.append(IFA013NsLinkPort(**element)) for element in linkPort or []]


class UserAccessInfo:
def __init__(self, address="", sapdId="", vnfdId=""):
self.address: str = address
self.sapdId: str = sapdId
self.vnfdId: str = vnfdId


class IFA013SapInfo:
def __init__(self, sapInstanceId="", sapdId="", sapName="", description="", address=""):
def __init__(self, sapInstanceId="", sapdId="", sapName="", description="", address="", userAccessInfo=None):
self.sapInstanceId: str = sapInstanceId
self.sapdId: str = sapdId
self.sapName: str = sapName
self.description: str = description
self.address: str = address
self.userAccessInfo: List[UserAccessInfo] = []
[self.userAccessInfo.append(UserAccessInfo(**element)) for element in userAccessInfo or []]


class IFA013Nfp:
Expand Down Expand Up @@ -728,13 +742,15 @@ def __init__(self, layerProtocol="IP_OVER_ETHERNET", ipOverEthernet=None):


class SOL005SapInfo:
def __init__(self, id="", sapdId="", sapName="", description="", sapProtocolInfo=None):
def __init__(self, id="", sapdId="", sapName="", description="", sapProtocolInfo=None, userAccessInfo=None):
self.id: str = id
self.sapdId: str = sapdId
self.sapName: str = sapName
self.description: str = description
self.sapProtocolInfo: List[SOL005CpProtocolInfo] = []
[self.sapProtocolInfo.append(element) for element in sapProtocolInfo or []]
self.userAccessInfo: List[UserAccessInfo] = []
[self.userAccessInfo.append(element) for element in userAccessInfo or []]


class SOL005NsScaleInfo:
Expand Down Expand Up @@ -1254,6 +1270,7 @@ def ifa013SapInfo_to_sol005Sapinfo(ifaSapInfoArray: List[IFA013SapInfo]) -> List
else: # Mac address
sol005cpProtocolInfo.ipOverEthernet.macAddress = ifaSapInfo.address
sol005SapInfo.sapProtocolInfo.append(sol005cpProtocolInfo)
sol005SapInfo.userAccessInfo = ifaSapInfo.userAccessInfo
sol005SapInfoArray.append(sol005SapInfo)
return sol005SapInfoArray

Expand Down Expand Up @@ -1409,7 +1426,7 @@ def ifa013OperationStatus_to_sol005NsLcmOpOcc(ifa013NSLCMOpId, ifa013OperationSt
SOL: (1)PROCESSING, (2)COMPLETED, PARTIALLY_COMPLETED, FAILED_TEMP, (3)FAILED, ROLLING_BACK, ROLLED_BACK
"""
sol005NsLcmOpOcc = SOL005NsLcmOpOcc()
if ifa013OperationStatus == "SUCCESFULLY_DONE":
if ifa013OperationStatus == "SUCCESSFULLY_DONE":
sol005NsLcmOpOcc.operationState = "COMPLETED"
elif ifa013OperationStatus == "PROCESSING":
sol005NsLcmOpOcc.operationState = "PROCESSING"
Expand Down
6 changes: 5 additions & 1 deletion adaptation_layer/driver/onap.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ def get_ns_list(self, args=None) -> Tuple[BodyList, Headers]:
def create_ns(self, args=None) -> Tuple[Body, Headers]:
_url = '{0}/create'.format(self._base_path)
_url = self._build_url_query(_url, args)

request_body = args['payload']
request_body["vimShortId"] = self._nfvoId

try:
created_ns, resp_headers = self._exec_post(
_url, json=args['payload'], headers=self._headers)
_url, json=request_body, headers=self._headers)
except ResourceNotFound:
nsd_Id = args['payload']['nsdId']
raise NsdNotFound(nsd_id=nsd_Id)
Expand Down
30 changes: 15 additions & 15 deletions adaptation_layer/driver/osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@
import re
from datetime import datetime
from functools import wraps
from typing import Dict, Tuple, List
from typing import Dict, List, Tuple
from urllib.parse import urlencode

import redis
import urllib3
import yaml as YAML
from requests import ConnectionError, Timeout, TooManyRedirects, URLRequired, \
api, HTTPError, get, post, delete
from requests import ConnectionError, HTTPError, Timeout, TooManyRedirects, URLRequired, api, delete, get, post
from urllib3.exceptions import InsecureRequestWarning

from adaptation_layer.error_handler import ResourceNotFound, NsNotFound, \
VnfNotFound, Unauthorized, ServerError, NsOpNotFound, VnfPkgNotFound, \
VimNotFound, NsdNotFound, BadRequest, Forbidden, MethodNotAllowed, \
Unprocessable, Conflict, VimNetworkNotFound
import redis
from adaptation_layer.error_handler import (BadRequest, Conflict, Forbidden, MethodNotAllowed, NsdNotFound, NsNotFound,
NsOpNotFound, ResourceNotFound, ServerError, Unauthorized, Unprocessable,
VimNetworkNotFound, VimNotFound, VnfNotFound, VnfPkgNotFound)
from adaptation_layer.repository import iwf_repository
from .interface import Driver, Headers, BodyList, Body

from .interface import Body, BodyList, Driver, Headers

urllib3.disable_warnings(InsecureRequestWarning)
TESTING = os.getenv('TESTING', 'false').lower()
Expand Down Expand Up @@ -200,11 +199,11 @@ def get_ns_list(self, args=None) -> Tuple[BodyList, Headers]:
def create_ns(self, args=None) -> Tuple[Body, Headers]:
_url = "{0}/nslcm/v1/ns_instances".format(self._base_path)
_url = self._build_url_query(_url, args)
osm_nsdpkg, headers_nsdpkg = self._get_nsdpkg(args={"args": {
"id": args["payload"]["nsdId"]}
})
args["payload"]["nsdId"] = osm_nsdpkg["_id"]
args['payload']['vimAccountId'] = self._select_vim()
try:
args['payload']['vimAccountId']
except (KeyError):
logger.info('no vimAccountId set, select first in NFVO')
args['payload']['vimAccountId'] = self._select_vim()
osm_ns, osm_headers = self._request(
post, _url, json=args['payload'], headers=self._headers)
# Get location header from OSM
Expand Down Expand Up @@ -266,7 +265,8 @@ def instantiate_ns(self, nsId: str, args=None) -> Tuple[None, Headers]:
if additional_params:
if 'vld' in additional_params:
instantiate_payload['vld'] = additional_params['vld']
vnf_items = self._force_float_ip(additional_params['vld'], ns_res)
vnf_items = self._force_float_ip(
additional_params['vld'], ns_res)
self._extend_vnf_add_params(instantiate_payload, vnf_items)
if 'vnf' in additional_params:
mapping = {v: str(i + 1) for i, v in
Expand Down
2 changes: 1 addition & 1 deletion adaptation_layer/error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self):

class VimNetworkNotFound(Error):
def __init__(self, vim_network_name: str, site_name: str):
super().__init__(description=f'{vim_network_name} not found on site {site_name}.')
super().__init__(description=f'Network {vim_network_name} not found on site {site_name}.')


class NsOpNotFound(Error):
Expand Down
9 changes: 9 additions & 0 deletions adaptation_layer/repository/iwf_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ def add_orc_cred_test(orc_type: str, orc_id: int):
resp.raise_for_status()


def add_network_test(json: Dict, site: int):
post_resp = post(f"{url}/networks", json=json)
post_resp.raise_for_status()
put_resp = put(post_resp.json()["_links"]["site"]["href"],
f"{url}/sites/{site}",
headers={"Content-Type": "text/uri-list"})
put_resp.raise_for_status()


@_server_error
def get_site_network(vim_network_name: str, nfvo_id: int):
nfvo = _get_nfvo(nfvo_id)
Expand Down
Loading

0 comments on commit 0b60042

Please sign in to comment.