예제 #1
0
 def on_delete(self, request, response, nffg_id):
     try :
         
         user_data = UserAuthentication().authenticateUserFromRESTRequest(request)
                
         controller = UpperLayerOrchestratorController(user_data)
         response.body = controller.delete(nffg_id)
         
     except NoResultFound:
         logging.exception("EXCEPTION - NoResultFound")
         raise falcon.HTTPNotFound()
     except requests.HTTPError as err:
         logging.exception(err.response.text)
         if err.response.status_code == 401:
             raise falcon.HTTPInternalServerError('Unauthorized.',err.message)
         elif err.response.status_code == 403:
             raise falcon.HTTPInternalServerError('Forbidden.',err.message)
         elif err.response.status_code == 404:
             raise falcon.HTTPInternalServerError('Resource Not found.',err.message)
         raise err
     except jsonschema.ValidationError as err:
         logging.exception(err.message)
         raise falcon.HTTPBadRequest('Bad Request',
                                     err.message)
     except sessionNotFound as err:
         logging.exception(err.message)
         raise falcon.HTTPNotFound()
     except ingoingFlowruleMissing as err:
         logging.exception(err.message)
         raise falcon.HTTPInternalServerError('ingoingFlowruleMissing',err.message)
     except ManifestValidationError as err:
         logging.exception(err.message)
         raise falcon.HTTPInternalServerError('ManifestValidationError',err.message)
     except unauthorizedRequest as err:
         logging.debug("Unauthorized access attempt from user "+request.get_header("X-Auth-User"))
         raise falcon.HTTPUnauthorized("Unauthorized", err.message)
     except Exception as ex:
         logging.exception(ex)
         raise falcon.HTTPInternalServerError('Contact the admin. ',ex.message)
'''
Created on Oct 30, 2015

@author: fabiomignini
'''
import requests, logging
from orchestrator_core.controller import UpperLayerOrchestratorController
from orchestrator_core.userAuthentication import UserData

nffg_id = 'isp-00000001'
logging.basicConfig(level=logging.DEBUG)
requests_log = logging.getLogger("requests")
requests_log.setLevel(logging.WARNING)
sqlalchemy_log = logging.getLogger('sqlalchemy.engine')
sqlalchemy_log.setLevel(logging.WARNING)

username = '******'
password = '******'
tenant = 'isp'


controller = UpperLayerOrchestratorController(user_data=UserData(username, password, tenant))
controller.delete(nffg_id)
print('Job completed')
exit()
orchestrator_endpoint = "http://127.0.0.1:9000/NF-FG/isp-00000001"

headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 
           'X-Auth-User': username, 'X-Auth-Pass': password, 'X-Auth-Tenant': tenant}
requests.delete(orchestrator_endpoint, headers=headers)
print('Job completed')
 def delete(self, nffg_id):
     """
     Delete a graph
     ---
     tags:
       - NF-FG   
     parameters:
       - name: nffg_id
         in: path
         description: Graph ID to be deleted
         required: true
         type: string            
       - name: X-Auth-User
         in: header
         description: Username
         required: true
         type: string
       - name: X-Auth-Pass
         in: header
         description: Password
         required: true
         type: string
       - name: X-Auth-Tenant
         in: header
         description: Tenant
         required: true
         type: string          
     responses:
       200:
         description: Graph deleted         
       401:
         description: Unauthorized
       404:
         description: Graph not found
       500:
         description: Internal Error
     """          
     try:
         user_data = UserAuthentication().authenticateUserFromRESTRequest(request)
                
         controller = UpperLayerOrchestratorController(user_data)
         controller.delete(nffg_id)
     
         return ("Session deleted")
         
     except NoResultFound:
         logging.exception("EXCEPTION - NoResultFound")
         return ("EXCEPTION - NoResultFound", 404)
     except requests.HTTPError as err:
         logging.exception(err)
         return (str(err), 500)
     except sessionNotFound as err:
         logging.exception(err.message)
         return (err.message, 404)
     except (unauthorizedRequest, UserNotFound) as err:
         if request.headers.get("X-Auth-User") is not None:
             logging.debug("Unauthorized access attempt from user "+request.headers.get("X-Auth-User"))
         logging.debug(err.message)
         return ("Unauthorized", 401) 
     except Exception as err:
         logging.exception(err)
         return ("Contact the admin: "+ str(err), 500)