class CreateSubscription:
+ """
+ Subscription Create process
+ """
def __init__(self, data):
self.data = data
)
def check_callback_uri(self):
+ """
+ Check if the callback Uri can access
+ :return:
+ """
logger.debug("SubscribeNotification-post::> Sending GET request to %s" % self.callback_uri)
try:
response = requests.get(self.callback_uri, timeout=2)
return subscription
def check_filter_types(self):
+ """
+ Validate operationTypes and operationStates if exists
+ :return:
+ """
logger.debug("SubscribeNotification--post::> Validating operationTypes and operationStates if exists")
occ_notification = NOTIFICATION_TYPE.NSLCM_OPERATION_OCCURRENCE_NOTIFICATION
if self.operation_types and occ_notification not in self.notification_types:
raise NSLCMException(except_message % occ_notification)
def check_valid_auth_info(self):
+ """
+ Validate Auth details if provided
+ :return:
+ """
logger.debug("SubscribeNotification--post::> Validating Auth details if provided")
auth_type = self.authentication.get("authType")
params_basic = self.authentication.get("paramsBasic")
# Check the notificationTypes, operationTypes, operationStates
for filter_type in FILTER_TYPE:
if not is_filter_type_equal(
- getattr(self, filter_type),
- ast.literal_eval(getattr(sub, filter_type))
+ getattr(self, filter_type),
+ ast.literal_eval(getattr(sub, filter_type))
):
return False
# If all the above types are same then check ns instance filters
ns_filter = json.loads(sub.ns_instance_filter)
for ns_filter_type in NS_FILTER_TYPE:
if not is_filter_type_equal(
- self.ns_filter.get(ns_filter_type, []),
- ns_filter.get(ns_filter_type, [])
+ self.ns_filter.get(ns_filter_type, []),
+ ns_filter.get(ns_filter_type, [])
):
return False
return True
def check_valid(self):
+ """
+ Check DB if callbackUri already exists
+ :return:
+ """
logger.debug("SubscribeNotification--post::> Checking DB if callbackUri already exists")
subscriptions = SubscriptionModel.objects.filter(callback_uri=self.callback_uri)
if not subscriptions.exists():
return False
def save_db(self):
- logger.debug("SubscribeNotification--post::> Saving the subscription(%s) to the database" % self.subscription_id)
+ """
+ Save the subscription(%s) to the database
+ :return:
+ """
+ logger.debug(
+ "SubscribeNotification--post::> Saving the subscription(%s) to the database" % self.subscription_id)
links = {
"self": {
"href": const.SUBSCRIPTION_ROOT_URI % self.subscription_id
class CreateNSService(object):
+ """
+ This class for NS instance Model create
+ """
+
def __init__(self, csar_id, ns_name, description, context):
self.csar_id = csar_id
self.ns_name = ns_name
self.ns_package_id = ''
def do_biz(self):
+ """
+ Create NS instance model
+ :return:
+ """
self.check_nsd_valid()
self.check_ns_inst_name_exist()
self.create_ns_inst()
return self.ns_inst_id
def check_nsd_valid(self):
+ """
+ Check the validation of NSD
+ :return:
+ """
logger.debug("CreateNSService::check_nsd_valid::csar_id=%s" % self.csar_id)
ns_package_info = query_nspackage_by_id(self.csar_id)
if not ns_package_info:
logger.debug("CreateNSService::check_nsd_valid::ns_package_id=%s,nsd_id=%s", self.ns_package_id, self.nsd_id)
def check_ns_inst_name_exist(self):
+ """
+ Check if the ns instance with same name exists
+ :return:
+ """
is_exist = NSInstModel.objects.filter(name=self.ns_name).exclude(status='null').exists()
logger.debug("CreateNSService::check_ns_inst_name_exist::is_exist=%s" % is_exist)
if is_exist:
raise NSLCMException("ns(%s) already existed." % self.ns_name)
def create_ns_inst(self):
+ """
+ Create NS instance Model
+ :return:
+ """
self.ns_inst_id = str(uuid.uuid4())
logger.debug("CreateNSService::create_ns_inst::ns_inst_id=%s" % self.ns_inst_id)
NSInstModel(id=self.ns_inst_id,
service_type=self.service_type).save()
def create_ns_in_aai(self):
+ """
+ Create NS instance record in AAI
+ :return:
+ """
logger.debug("CreateNSService::create_ns_in_aai::report ns instance[%s] to aai." % self.ns_inst_id)
try:
data = {
class DeleteNsService(object):
+ """
+ Class to delete NS instance
+ """
+
def __init__(self, ns_inst_id):
self.ns_inst_id = ns_inst_id
logger.error(traceback.format_exc())
def delete_ns(self):
+ """
+ Delete NS instance model
+ :return:
+ """
logger.debug("delele NSInstModel(%s)", self.ns_inst_id)
NSInstModel.objects.filter(id=self.ns_inst_id).delete()
ServiceBaseInfoModel.objects.filter(service_id=self.ns_inst_id).delete()
def delete_ns_in_aai(self):
+ """
+ Delete NS instance record from AAI
+ :return:
+ """
logger.debug("DeleteNsService::delete_ns_in_aai::delete ns instance[%s] in aai." % self.ns_inst_id)
try:
ns_insts = NSInstModel.objects.filter(id=self.ns_inst_id)
class GetNSInfoService(object):
+ """
+ Get NS instance Model
+ """
+
def __init__(self, ns_filter=None):
self.ns_filter = ns_filter
def get_ns_info(self, is_sol=False):
+ """
+ Get all the ns instance models
+ :param is_sol:
+ :return:
+ """
if self.ns_filter and "ns_inst_id" in self.ns_filter:
ns_inst_id = self.ns_filter["ns_inst_id"]
ns_insts = NSInstModel.objects.filter(id=ns_inst_id)
return result
def get_single_ns_info(self, ns_inst, is_sol=False):
+ """
+ Get a ns instance model
+ :param ns_inst:
+ :param is_sol:
+ :return:
+ """
if is_sol:
nsInstance = {}
nsInstance['id'] = ns_inst.id
@staticmethod
def get_vnf_infos(ns_inst_id, is_sol):
+ """
+ VNF info
+ :param ns_inst_id:
+ :param is_sol:
+ :return:
+ """
vnfs = NfInstModel.objects.filter(ns_inst_id=ns_inst_id)
if is_sol:
return [{
'vnfProfileId': vnf.vnf_id} for vnf in vnfs]
def get_vl_infos(self, ns_inst_id, is_sol):
+ """
+ VL info
+ :param ns_inst_id:
+ :param is_sol:
+ :return:
+ """
vls = VLInstModel.objects.filter(ownertype=OWNER_TYPE.NS, ownerid=ns_inst_id)
if is_sol:
return [
@staticmethod
def get_cp_infos(vl_inst_id):
+ """
+ CP info
+ :param vl_inst_id:
+ :return:
+ """
cps = CPInstModel.objects.filter(relatedvl__icontains=vl_inst_id)
return [{
'cpInstanceId': cp.cpinstanceid,
'cpdId': cp.cpdid} for cp in cps]
def get_vnffg_infos(self, ns_inst_id, nsd_model, is_sol):
+ """
+ VNFFG info
+ :param ns_inst_id:
+ :param nsd_model:
+ :param is_sol:
+ :return:
+ """
vnffgs = VNFFGInstModel.objects.filter(nsinstid=ns_inst_id)
return [{
'vnffgInstanceId': vnffg.vnffginstid,
@staticmethod
def get_pnf_ids(nsd_model):
+ """
+ PNF ids
+ :param nsd_model:
+ :return:
+ """
context = json.loads(nsd_model)
pnfs = context['pnfs']
return [pnf['pnf_id'] for pnf in pnfs]
@staticmethod
def get_pnf_infos(ns_instance_id):
+ """
+ PNF infos
+ :param ns_instance_id:
+ :return:
+ """
pnfs = PNFInstModel.objects.filter(nsInstances__contains=ns_instance_id)
return [pnf.__dict__ for pnf in pnfs]
class NSHealService(threading.Thread):
+ """
+ Heal the NS instance
+ """
+
def __init__(self, ns_instance_id, request_data, job_id):
super(NSHealService, self).__init__()
self.ns_instance_id = ns_instance_id
class InstantNSService(object):
+ """
+ Instantiate NS
+ """
+
def __init__(self, ns_inst_id, plan_content):
self.ns_inst_id = ns_inst_id
self.req_data = plan_content
else:
params_json = json.JSONEncoder().encode({})
- location_constraints = [] if not self.req_data.get('locationConstraints')\
+ location_constraints = [] if not self.req_data.get('locationConstraints') \
else self.req_data['locationConstraints']
vnf_vim = self.get_vnf_vim_info(location_constraints)
return dict(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def start_wso2_workflow(self, job_id, ns_inst, plan_input, occ_id):
+ """
+ Start WSO2 workflow
+ :param job_id:
+ :param ns_inst:
+ :param plan_input:
+ :param occ_id:
+ :return:
+ """
# todo occ_id
servicetemplate_id = get_servicetemplate_id(ns_inst.nsd_id)
process_id = get_process_id('init', servicetemplate_id)
return dict(data={'error': ret['message']}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def start_activiti_workflow(self, job_id, plan_input, occ_id):
+ """
+ Start activiti workflow
+ :param job_id:
+ :param plan_input:
+ :param occ_id:
+ :return:
+ """
# todo occ_id
plans = WFPlanModel.objects.filter()
if not plans:
return dict(data={'error': ret['message']}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def start_buildin_workflow(self, job_id, plan_input, occ_id):
+ """
+ Start buildin workflow
+ :param job_id:
+ :param plan_input:
+ :param occ_id:
+ :return:
+ """
JobUtil.add_job_status(job_id, 10, 'NS inst(%s) buildin workflow started.' % self.ns_inst_id)
BuildInWorkflowThread(plan_input, occ_id).start()
return dict(data={'jobId': job_id}, status=status.HTTP_200_OK, occ_id=occ_id)
class NSManualScaleService(threading.Thread):
+ """
+ Scale the NS instance
+ """
+
def __init__(self, ns_instance_id, request_data, job_id):
super(NSManualScaleService, self).__init__()
self.ns_instance_id = ns_instance_id
raise NSLCMException('Failed to get scaleVnfData parameter')
def do_vnfs_scale(self):
+ """
+ Scale VNF instance
+ :return:
+ """
for i in range(len(self.scale_vnf_data)):
vnf_scale_params = self.prepare_vnf_scale_params(
self.scale_vnf_data[i])
self.update_job(
progress_range[1],
desc='nf[%s] scale handle end' %
- vnf_scale_params.get('vnfInstanceId'))
+ vnf_scale_params.get('vnfInstanceId'))
else:
raise NSLCMException('VNF scale failed')
def prepare_vnf_scale_params(self, vnf_data):
+ """
+ Prepare parameters for VNF instance scale
+ :param vnf_data:
+ :return:
+ """
return {
"vnfInstanceId": ignore_case_get(vnf_data, 'vnfInstanceId'),
"scaleVnfData": ignore_case_get(vnf_data, 'scaleByStepData'),
}
def do_vnf_scale(self, vnf_scale_params, progress_range):
+ """
+ Scale VNF instance
+ :param vnf_scale_params:
+ :param progress_range:
+ :return:
+ """
nf_inst_id = vnf_scale_params.get('vnfInstanceId')
nf_service = NFManualScaleService(nf_inst_id, vnf_scale_params)
nf_service.start()
self.update_job(
progress_range[0],
desc='nf[%s] scale handle start' %
- nf_inst_id)
+ nf_inst_id)
status = self.wait_job_finish(nf_service.job_id)
return status
return JOB_MODEL_STATUS.TIMEOUT
def update_job(self, progress, desc=''):
+ """
+ Update the information of job
+ :param progress:
+ :param desc:
+ :return:
+ """
JobUtil.add_job_status(self.job_id, progress, desc)
def update_ns_status(self, status):
+ """
+ Update NS instance status
+ :param status:
+ :return:
+ """
NSInstModel.objects.filter(
id=self.ns_instance_id).update(
status=status)
class TerminateNsService(threading.Thread):
+ """
+ Terminate the NS instance
+ """
+
def __init__(self, ns_inst_id, job_id, request_data):
threading.Thread.__init__(self)
self.terminate_type = request_data.get('terminationType', 'GRACEFUL')
build_in.post_deal(self.ns_inst_id, "false")
def modify_package_state(self):
+ """
+ Update the state of NS instance model
+ :return:
+ """
ns_inst = NSInstModel.objects.filter(id=self.ns_inst_id)
ns_insts = NSInstModel.objects.filter(nspackage_id=ns_inst[0].nspackage_id)
if len(ns_insts) == 1:
sdc_run_catalog.modify_nsd_state(ns_inst[0].nspackage_id, 0)
def cancel_vl_list(self):
+ """
+ Delete list of VL related
+ :return:
+ """
array_vlinst = VLInstModel.objects.filter(ownertype=OWNER_TYPE.NS, ownerid=self.ns_inst_id)
if not array_vlinst:
logger.info("[cancel_vl_list] no vlinst attatch to ns_inst_id: %s" % self.ns_inst_id)
JobUtil.add_job_status(self.job_id, cur_progress, job_msg)
def cancel_sfc_list(self):
+ """
+ Delete SFC list
+ :return:
+ """
array_sfcinst = FPInstModel.objects.filter(nsinstid=self.ns_inst_id)
if not array_sfcinst:
logger.info("[cancel_sfc_list] no sfcinst attatch to ns_inst_id: %s" % self.ns_inst_id)
JobUtil.add_job_status(self.job_id, cur_progress, job_msg)
def cancel_vnf_list(self):
+ """
+ Delete VNF instance list
+ :return:
+ """
array_vnfinst = NfInstModel.objects.filter(ns_inst_id=self.ns_inst_id)
if not array_vnfinst:
logger.info("[cancel_vnf_list] no vnfinst attatch to ns_inst_id: %s" % self.ns_inst_id)
if not vnfjobid:
continue
is_job_ok = self.wait_delete_vnf_job_finish(vnfjobid)
- msg = "%s to delete VNF(%s)" %\
+ msg = "%s to delete VNF(%s)" % \
("Succeed" if is_job_ok else "Failed", vnfinstid)
logger.debug(msg)
JobUtil.add_job_status(self.job_id, cur_progress, msg)
JobUtil.add_job_status(self.job_id, cur_progress, msg)
def delete_vnf(self, nf_instid):
+ """
+ Delete VNF instance
+ :param nf_instid:
+ :return:
+ """
term_param = {
"terminationType": self.terminate_type
}
return job_end_normal
def cancel_pnf_list(self):
+ """
+ Delete PNF list
+ :return:
+ """
pnfinst_list = PNFInstModel.objects.filter(nsInstances__contains=self.ns_inst_id)
if len(pnfinst_list) > 0:
cur_progress = 90
class NSUpdateService(threading.Thread):
+ """
+ Update NS instance model
+ """
+
def __init__(self, ns_instance_id, request_data, job_id):
super(NSUpdateService, self).__init__()
self.ns_instance_id = ns_instance_id
class QuerySubscription:
+ """
+ Search subscription record
+ """
def __init__(self, data, subscription_id=''):
self.subscription_id = subscription_id
self.params = data
def query_multi_subscriptions(self):
+ """
+ Get multiple subscriptions
+ :return:
+ """
query_data = {}
logger.debug(
"QueryMultiSubscriptions--get--biz::> Check for filters in query params" % self.params)
This task resource represents the "Heal NS" operation.
The client can use this resource to request healing a NS instance.
"""
+
@swagger_auto_schema(
request_body=HealNsReqSerializer(),
responses={
def post(self, request, ns_instance_id):
"""
The POST method requests to heal a NS instance resource.
- :param request:
- :param ns_instance_id:
- :return:
+ :param request:
+ :param ns_instance_id:
+ :return:
"""
logger.debug("Enter HealNSView::post nsInstanceId:%s, request.data:%s" % (ns_instance_id, request.data))
req_serializer = HealNsReqSerializer(data=request.data)