diff options
author | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-09-19 15:48:54 +0800 |
---|---|---|
committer | ying.yunlong <ying.yunlong@zte.com.cn> | 2017-09-19 16:22:10 +0800 |
commit | 2eb7aa0f39ab0e56d7703d7adf5bd8b7514f971c (patch) | |
tree | 8cba520595fad1534442ec9d546d69c62a959311 | |
parent | 3707098bb78ceb5dfa2e88f61ba4bd82ad7f632c (diff) |
Add nfvo-lcm customer relationship operation
Change-Id: Ie19022662e4951faf58b67c43b232eab8fb90eb2
Issue-ID: VFC-385
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r-- | lcm/ns/ns_delete.py | 5 | ||||
-rw-r--r-- | lcm/ns/ns_terminate.py | 20 | ||||
-rw-r--r-- | lcm/pub/msapi/aai.py | 157 |
3 files changed, 104 insertions, 78 deletions
diff --git a/lcm/ns/ns_delete.py b/lcm/ns/ns_delete.py index 0883cf2a..52b0df84 100644 --- a/lcm/ns/ns_delete.py +++ b/lcm/ns/ns_delete.py @@ -19,8 +19,7 @@ import traceback from lcm.pub.config.config import REPORT_TO_AAI from lcm.pub.database.models import DefPkgMappingModel, InputParamMappingModel, ServiceBaseInfoModel from lcm.pub.database.models import NSInstModel -from lcm.pub.msapi.aai import get_customer_aai, delete_customer_aai - +from lcm.pub.msapi.aai import delete_customer_aai, query_customer_aai logger = logging.getLogger(__name__) @@ -55,7 +54,7 @@ class DeleteNsService(object): global_customer_id = "global-customer-id-" + self.ns_inst_id # query ns instance in aai, get resource_version - customer_info = get_customer_aai(global_customer_id) + customer_info = query_customer_aai(global_customer_id) resource_version = customer_info["resource-version"] # delete ns instance from aai diff --git a/lcm/ns/ns_terminate.py b/lcm/ns/ns_terminate.py index dd8a267a..2a79fb31 100644 --- a/lcm/ns/ns_terminate.py +++ b/lcm/ns/ns_terminate.py @@ -11,19 +11,19 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import math -import traceback -import logging + import json +import logging +import math import threading import time +import traceback + from lcm.ns.vnfs.wait_job import wait_job_finish from lcm.pub.database.models import NSInstModel, VLInstModel, FPInstModel, NfInstModel -from lcm.pub.database.models import DefPkgMappingModel, InputParamMappingModel, ServiceBaseInfoModel -from lcm.pub.msapi.aai import get_customer_aai, delete_customer_aai -from lcm.pub.utils.jobutil import JOB_MODEL_STATUS, JobUtil from lcm.pub.exceptions import NSLCMException from lcm.pub.msapi.nslcm import call_from_ns_cancel_resource +from lcm.pub.utils.jobutil import JOB_MODEL_STATUS, JobUtil from lcm.pub.utils.values import ignore_case_get JOB_ERROR = 255 @@ -192,10 +192,10 @@ class TerminateNsService(threading.Thread): NSInstModel.objects.filter(id=self.ns_inst_id).update(status='null') JobUtil.add_job_status(self.job_id, 100, "ns terminate ends.", '') - # @staticmethod - # def call_vnfm_to_cancel_resource(res_type, instid): - # ret = call_from_ns_cancel_resource(res_type, instid) - # return ret + @staticmethod + def call_vnfm_to_cancel_resource(res_type, instid): + ret = call_from_ns_cancel_resource(res_type, instid) + return ret def add_progress(self, progress, status_decs, error_code=""): JobUtil.add_job_status(self.job_id, progress, status_decs, error_code) diff --git a/lcm/pub/msapi/aai.py b/lcm/pub/msapi/aai.py index ae76e8d8..4be1ff7e 100644 --- a/lcm/pub/msapi/aai.py +++ b/lcm/pub/msapi/aai.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - import json import logging import uuid @@ -40,6 +39,7 @@ def call_aai(resource, method, content=''): content, additional_headers) + def create_customer_aai(global_customer_id, data): resource = "/business/customers/customer/%s" % global_customer_id ret = call_aai(resource, "PUT", data) @@ -49,13 +49,13 @@ def create_customer_aai(global_customer_id, data): return json.JSONDecoder().decode(ret[1]), ret[2] -def get_customer_aai(global_customer_id): +def query_customer_aai(global_customer_id): resource = "/business/customers/customer/%s?depth=all" % global_customer_id ret = call_aai(resource, "GET") if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) raise NSLCMException("Get customer info exception in AAI") - return json.JSONDecoder().decode(ret[1]) + return json.JSONDecoder().decode(ret[1]), ret[2] def delete_customer_aai(global_customer_id, resource_version=""): @@ -69,6 +69,24 @@ def delete_customer_aai(global_customer_id, resource_version=""): return json.JSONDecoder().decode(ret[1]), ret[2] +def put_customer_relationship(global_customer_id, data): + resource = "/business/customers/customer/{global-customer-id}/relationship-list/relationship" % global_customer_id + ret = call_aai(resource, "PUT", data) + if ret[0] != 0: + logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) + raise NSLCMException("Put or update customer relationship exception in AAI") + return json.JSONDecoder().decode(ret[1]), ret[2] + + +def delete_customer_relationship(global_customer_id): + resource = "/business/customers/customer/{global-customer-id}/relationship-list/relationship" % global_customer_id + ret = call_aai(resource, "DELETE") + if ret[0] != 0: + logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) + raise NSLCMException("Delete customer relationship exception in AAI") + return json.JSONDecoder().decode(ret[1]), ret[2] + + def create_ns_aai(global_customer_id, service_type, service_instance_id, data): resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \ "%s/service-instances/service-instance/%s" % \ @@ -79,6 +97,18 @@ def create_ns_aai(global_customer_id, service_type, service_instance_id, data): raise NSLCMException("Ns instance creation exception in AAI") return json.JSONDecoder().decode(ret[1]), ret[2] + +def query_ns_aai(global_customer_id, service_type, service_instance_id): + resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \ + "%s/service-instances/service-instance/%s?depth=all" % \ + (global_customer_id, service_type, service_instance_id) + ret = call_aai(resource, "GET") + if ret[0] != 0: + logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) + raise NSLCMException("Ns instance query exception in AAI") + return json.JSONDecoder().decode(ret[1]) + + def delete_ns_aai(global_customer_id, service_type, service_instance_id, resource_version=""): resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \ "%s/service-instances/service-instance/%s" % \ @@ -89,17 +119,30 @@ def delete_ns_aai(global_customer_id, service_type, service_instance_id, resourc if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) raise NSLCMException("Ns instance delete exception in AAI") - return json.JSONDecoder().decode(ret[1]) + return json.JSONDecoder().decode(ret[1]), ret[2] + -def query_ns_aai(global_customer_id, service_type, service_instance_id, data): +def put_ns_relationship(global_customer_id, service_type, service_instance_id, data): resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \ - "%s/service-instances/service-instance/%s?depth=all" % \ + "%s/service-instances/service-instance/%s/relationship-list/relationship" % \ (global_customer_id, service_type, service_instance_id) - ret = call_aai(resource, "GET", data) + ret = call_aai(resource, "PUT", data) if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) - raise NSLCMException("Ns instance query exception in AAI") - return json.JSONDecoder().decode(ret[1]) + raise NSLCMException("Put or update ns instance relationship exception in AAI") + return json.JSONDecoder().decode(ret[1]), ret[2] + + +def delete_ns_relationship(global_customer_id, service_type, service_instance_id): + resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \ + "%s/service-instances/service-instance/%s/relationship-list/relationship" % \ + (global_customer_id, service_type, service_instance_id) + ret = call_aai(resource, "DELETE") + if ret[0] != 0: + logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) + raise NSLCMException("Delete ns instance relationship exception in AAI") + return json.JSONDecoder().decode(ret[1]), ret[2] + def create_vnf_aai(vnf_id, data): resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id @@ -109,6 +152,16 @@ def create_vnf_aai(vnf_id, data): raise NSLCMException("Vnf instance creation exception in AAI") return json.JSONDecoder().decode(ret[1]), ret[2] + +def query_vnf_aai(vnf_id): + resource = "/network/generic-vnfs/generic-vnf/%s?depth=all" % vnf_id + ret = call_aai(resource, "GET") + if ret[0] != 0: + logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) + raise NSLCMException("Vnf instance query exception in AAI") + return json.JSONDecoder().decode(ret[1]) + + def delete_vnf_aai(vnf_id, resource_version=""): resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id if resource_version: @@ -119,13 +172,24 @@ def delete_vnf_aai(vnf_id, resource_version=""): raise NSLCMException("Vnf instance delete exception in AAI") return json.JSONDecoder().decode(ret[1]), ret[2] -def query_vnf_aai(vnf_id): - resource = "/network/generic-vnfs/generic-vnf/%s?depth=all" % vnf_id - ret = call_aai(resource, "GET") + +def put_vnf_relationship(vnf_id, data): + resource = "/network/generic-vnfs/generic-vnf/%s/relationship-list/relationship" % vnf_id + ret = call_aai(resource, "PUT", data) if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) - raise NSLCMException("Vnf instance query exception in AAI") - return json.JSONDecoder().decode(ret[1]) + raise NSLCMException("Put or update vnf instance relationship exception in AAI") + return json.JSONDecoder().decode(ret[1]), ret[2] + + +def delete_vnf_relationship(vnf_id): + resource = "/network/generic-vnfs/generic-vnf/%s/relationship-list/relationship" % vnf_id + ret = call_aai(resource, "DELETE") + if ret[0] != 0: + logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) + raise NSLCMException("Delete vnf instance relationship exception in AAI") + return json.JSONDecoder().decode(ret[1]), ret[2] + def create_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, data): resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \ @@ -137,6 +201,18 @@ def create_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, data raise NSLCMException("Vserver creation exception in AAI") return json.JSONDecoder().decode(ret[1]), ret[2] + +def query_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id): + resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \ + "%s/tenants/tenant/%s/vservers/vserver/%s?depth=all" % \ + (cloud_owner, cloud_region_id, tenant_id, vserver_id) + ret = call_aai(resource, "GET") + if ret[0] != 0: + logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) + raise NSLCMException("Vserver query exception in AAI") + return json.JSONDecoder().decode(ret[1]) + + def delete_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, resource_version=""): resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \ "%s/tenants/tenant/%s/vservers/vserver/%s" % \ @@ -149,15 +225,6 @@ def delete_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, reso raise NSLCMException("Vserver delete exception in AAI") return json.JSONDecoder().decode(ret[1]), ret[2] -def query_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id): - resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \ - "%s/tenants/tenant/%s/vservers/vserver/%s?depth=all" % \ - (cloud_owner, cloud_region_id, tenant_id, vserver_id) - ret = call_aai(resource, "GET") - if ret[0] != 0: - logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) - raise NSLCMException("Vserver query exception in AAI") - return json.JSONDecoder().decode(ret[1]) def put_vserver_relationship(cloud_owner, cloud_region_id, tenant_id, vserver_id, data): resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \ @@ -167,7 +234,7 @@ def put_vserver_relationship(cloud_owner, cloud_region_id, tenant_id, vserver_id if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) raise NSLCMException("Put or update vserver relationship exception in AAI") - return json.JSONDecoder().decode(ret[1]) + return json.JSONDecoder().decode(ret[1]), ret[2] def delete_vserver_relationship(cloud_owner, cloud_region_id, tenant_id, vserver_id): @@ -178,44 +245,4 @@ def delete_vserver_relationship(cloud_owner, cloud_region_id, tenant_id, vserver if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) raise NSLCMException("Delete vserver relationship exception in AAI") - return json.JSONDecoder().decode(ret[1]) - - -def put_vnf_relationship(vnf_id, data): - resource = "/network/generic-vnfs/generic-vnf/%s/relationship-list/relationship" % vnf_id - ret = call_aai(resource, "PUT", data) - if ret[0] != 0: - logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) - raise NSLCMException("Put or update vnf instance relationship exception in AAI") - return json.JSONDecoder().decode(ret[1]) - - -def delete_vnf_relationship(vnf_id): - resource = "/network/generic-vnfs/generic-vnf/%s/relationship-list/relationship" % vnf_id - ret = call_aai(resource, "DELETE") - if ret[0] != 0: - logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) - raise NSLCMException("Delete vnf instance relationship exception in AAI") - return json.JSONDecoder().decode(ret[1]) - - -def put_ns_relationship(global_customer_id, service_type, service_instance_id, data): - resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \ - "%s/service-instances/service-instance/%s/relationship-list/relationship" % \ - (global_customer_id, service_type, service_instance_id) - ret = call_aai(resource, "PUT", data) - if ret[0] != 0: - logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) - raise NSLCMException("Put or update ns instance relationship exception in AAI") - return json.JSONDecoder().decode(ret[1]) - - -def delete_ns_relationship(global_customer_id, service_type, service_instance_id): - resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \ - "%s/service-instances/service-instance/%s/relationship-list/relationship" % \ - (global_customer_id, service_type, service_instance_id) - ret = call_aai(resource, "DELETE") - if ret[0] != 0: - logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) - raise NSLCMException("Delete ns instance relationship exception in AAI") - return json.JSONDecoder().decode(ret[1]) + return json.JSONDecoder().decode(ret[1]), ret[2] |