예제 #1
0
def _get_nfvo(nfvo_id) -> Dict:
    try:
        resp = get(f'{url}/nfvOrchestrators/{nfvo_id}', headers=accept_h)
        resp.raise_for_status()
    except HTTPError as e:
        if e.response.status_code == 404:
            raise NfvoNotFound(nfvo_id)
        elif e.response.status_code == 401:
            raise Unauthorized()
        else:
            raise
    return resp.json()
예제 #2
0
def create_subscription(nfvo_id: int, body: Dict):
    try:
        create = post(f'{url}/subscriptions', json=body, headers=accept_h)
        create.raise_for_status()
        associate = put(create.json()['_links']['nfvOrchestrators']['href'],
                        data=f'{url}/nfvOrchestrators/{nfvo_id}',
                        headers={
                            **texturi_h,
                            **accept_h
                        })
        associate.raise_for_status()
    except HTTPError as e:
        if e.response.status_code == 400:
            raise BadRequest(description=e.response.text)
        if e.response.status_code == 404:
            raise NfvoNotFound(nfvo_id)
        if e.response.status_code == 422:
            raise Unprocessable(description=e.response.text)
        else:
            raise
    return create.json()
예제 #3
0
def get_nfvo_cred(nfvo_id: int) -> Dict:
    nfvo_cred = NFVO_CREDENTIALS.query.filter_by(nfvo_id=nfvo_id).first()
    if nfvo_cred is None:
        raise NfvoNotFound(nfvo_id=nfvo_id)
    return nfvo_cred.serialize
예제 #4
0
def get_nfvo_by_id(nfvo_id: int) -> Dict:
    nfvo = NFVO.query.filter_by(id=nfvo_id).first()
    if nfvo is None:
        raise NfvoNotFound(nfvo_id=nfvo_id)
    return nfvo.serialize