aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-10-11 17:02:43 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-10-11 17:02:43 +0800
commitcbadbd1e580799450c5c776988a6ed22a8321f5c (patch)
treec5acb844de6de83574e105339395165063b30ce8
parenteb81ed139205528aca0085d8f8012230eff9deb4 (diff)
Add exception protection in vfc-nfvo-lcm
Add exception protection in vfc-nfvo-lcm aai resource operation code Change-Id: I346f40972dee3afd0fcf29a37d53ca0acd3bf27d Issue-ID: VFC-525 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--lcm/ns/ns_create.py76
-rw-r--r--lcm/ns/ns_delete.py56
-rw-r--r--lcm/ns/vls/create_vls.py8
-rw-r--r--lcm/ns/vnfs/create_vnfs.py135
-rw-r--r--lcm/ns/vnfs/terminate_nfs.py80
5 files changed, 193 insertions, 162 deletions
diff --git a/lcm/ns/ns_create.py b/lcm/ns/ns_create.py
index de6bac6b..ade97621 100644
--- a/lcm/ns/ns_create.py
+++ b/lcm/ns/ns_create.py
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
+import traceback
import uuid
from lcm.pub.config.config import REPORT_TO_AAI
@@ -75,38 +76,43 @@ class CreateNSService(object):
def create_ns_in_aai(self):
logger.debug("CreateNSService::create_ns_in_aai::report ns instance[%s] to aai." % self.ns_inst_id)
- # global_customer_id = "global-customer-id-" + self.ns_inst_id
- # data = {
- # "global-customer-id": "global-customer-id-" + self.ns_inst_id,
- # "subscriber-name": "subscriber-name-" + self.ns_inst_id,
- # "subscriber-type": "subscriber-type-" + self.ns_inst_id,
- # "service-subscriptions": {
- # "service-subscription": [
- # {
- # "service-type": "Network",
- # "service-instances": {
- # "service-instance": [
- # {
- # "service-instance-id": self.ns_inst_id,
- # "service-instance-name": self.ns_name,
- # "service-type": "Network",
- # "service-role": "service-role-" + self.ns_inst_id
- # }
- # ]
- # }
- # }
- # ]
- # }
- # }
- # resp_data, resp_status = create_customer_aai(global_customer_id, data)
- data = {
- "service-instance-id": self.ns_inst_id,
- "service-instance-name": self.ns_name,
- "service-type": "Network",
- "service-role": "service-role-" + self.ns_inst_id
- }
- resp_data, resp_status = create_ns_aai(self.global_customer_id, self.service_type, self.ns_inst_id, data)
- if resp_data:
- logger.debug("Fail to create ns[%s] to aai: [%s].", self.ns_inst_id, resp_status)
- else:
- logger.debug("Success to create ns[%s] to aai: [%s].", self.ns_inst_id, resp_status)
+ try:
+ # global_customer_id = "global-customer-id-" + self.ns_inst_id
+ # data = {
+ # "global-customer-id": "global-customer-id-" + self.ns_inst_id,
+ # "subscriber-name": "subscriber-name-" + self.ns_inst_id,
+ # "subscriber-type": "subscriber-type-" + self.ns_inst_id,
+ # "service-subscriptions": {
+ # "service-subscription": [
+ # {
+ # "service-type": "Network",
+ # "service-instances": {
+ # "service-instance": [
+ # {
+ # "service-instance-id": self.ns_inst_id,
+ # "service-instance-name": self.ns_name,
+ # "service-type": "Network",
+ # "service-role": "service-role-" + self.ns_inst_id
+ # }
+ # ]
+ # }
+ # }
+ # ]
+ # }
+ # }
+ # resp_data, resp_status = create_customer_aai(global_customer_id, data)
+ data = {
+ "service-instance-id": self.ns_inst_id,
+ "service-instance-name": self.ns_name,
+ "service-type": "Network",
+ "service-role": "service-role-" + self.ns_inst_id
+ }
+ resp_data, resp_status = create_ns_aai(self.global_customer_id, self.service_type, self.ns_inst_id, data)
+ if resp_data:
+ logger.debug("Fail to create ns[%s] to aai: [%s].", self.ns_inst_id, resp_status)
+ else:
+ logger.debug("Success to create ns[%s] to aai: [%s].", self.ns_inst_id, resp_status)
+ except NSLCMException as e:
+ logger.debug("Fail to createns[%s] to aai, detail message: %s" % (self.ns_inst_id, e.message))
+ except:
+ logger.error(traceback.format_exc())
diff --git a/lcm/ns/ns_delete.py b/lcm/ns/ns_delete.py
index 4c10a57e..a4ecab36 100644
--- a/lcm/ns/ns_delete.py
+++ b/lcm/ns/ns_delete.py
@@ -19,6 +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.exceptions import NSLCMException
from lcm.pub.msapi.aai import query_ns_aai, delete_ns_aai
logger = logging.getLogger(__name__)
@@ -51,30 +52,35 @@ class DeleteNsService(object):
def delete_ns_in_aai(self):
logger.debug("DeleteNsService::delete_ns_in_aai::delete ns instance[%s] in aai." % self.ns_inst_id)
- # global_customer_id = "global-customer-id-" + self.ns_inst_id
- #
- # # query ns instance in aai, get resource_version
- # customer_info = query_customer_aai(global_customer_id)
- # resource_version = customer_info["resource-version"]
- #
- # # delete ns instance from aai
- # resp_data, resp_status = delete_customer_aai(global_customer_id, resource_version)
+ try:
+ # global_customer_id = "global-customer-id-" + self.ns_inst_id
+ #
+ # # query ns instance in aai, get resource_version
+ # customer_info = query_customer_aai(global_customer_id)
+ # resource_version = customer_info["resource-version"]
+ #
+ # # delete ns instance from aai
+ # resp_data, resp_status = delete_customer_aai(global_customer_id, resource_version)
- ns_insts = NSInstModel.objects.filter(id=self.ns_inst_id)
- self.global_customer_id = ns_insts[0].global_customer_id
- self.service_type = ns_insts[0].service_type
- # query ns instance in aai, get resource_version
- logger.debug("self.global_customer_id=[%s], self.service_type=[%s], self.ns_inst_id=[%s]"
- % (self.global_customer_id, self.service_type, self.ns_inst_id))
- ns_info = query_ns_aai(self.global_customer_id, self.service_type, self.ns_inst_id)
- resource_version = ns_info["resource-version"]
+ ns_insts = NSInstModel.objects.filter(id=self.ns_inst_id)
+ self.global_customer_id = ns_insts[0].global_customer_id
+ self.service_type = ns_insts[0].service_type
+ # query ns instance in aai, get resource_version
+ logger.debug("self.global_customer_id=[%s], self.service_type=[%s], self.ns_inst_id=[%s]"
+ % (self.global_customer_id, self.service_type, self.ns_inst_id))
+ ns_info = query_ns_aai(self.global_customer_id, self.service_type, self.ns_inst_id)
+ resource_version = ns_info["resource-version"]
- # delete ns instance from aai
- logger.debug("ns instance resource_version=[%s]" % resource_version)
- resp_data, resp_status = delete_ns_aai(self.global_customer_id, self.service_type,
- self.ns_inst_id, resource_version)
- if resp_data:
- logger.debug("Fail to delete ns instance[%s] from aai, resp_status: [%s]." % (self.ns_inst_id, resp_status))
- else:
- logger.debug("Success to delete ns instance[%s] from aai, resp_status: [%s]."
- % (self.ns_inst_id, resp_status))
+ # delete ns instance from aai
+ logger.debug("ns instance resource_version=[%s]" % resource_version)
+ resp_data, resp_status = delete_ns_aai(self.global_customer_id, self.service_type,
+ self.ns_inst_id, resource_version)
+ if resp_data:
+ logger.debug("Fail to delete ns[%s] from aai, resp_status: [%s]." % (self.ns_inst_id, resp_status))
+ else:
+ logger.debug("Success to delete ns[%s] from aai, resp_status: [%s]."
+ % (self.ns_inst_id, resp_status))
+ except NSLCMException as e:
+ logger.debug("Fail to delete ns[%s] from aai, detail message: %s" % (self.ns_inst_id, e.message))
+ except:
+ logger.error(traceback.format_exc())
diff --git a/lcm/ns/vls/create_vls.py b/lcm/ns/vls/create_vls.py
index 9d338388..15dee547 100644
--- a/lcm/ns/vls/create_vls.py
+++ b/lcm/ns/vls/create_vls.py
@@ -199,10 +199,10 @@ class CreateVls(object):
data = {
"network-id": self.vl_inst_id,
"network-name": self.vl_inst_name,
- "is-bound-to-vpn": "false",
- "is-provider-network": "true",
- "is-shared-network": "true",
- "is-external-network": "true",
+ "is-bound-to-vpn": False,
+ "is-provider-network": True,
+ "is-shared-network": True,
+ "is-external-network": True,
"relationship-list": {
"relationship": [
{
diff --git a/lcm/ns/vnfs/create_vnfs.py b/lcm/ns/vnfs/create_vnfs.py
index f7b94911..083131ca 100644
--- a/lcm/ns/vnfs/create_vnfs.py
+++ b/lcm/ns/vnfs/create_vnfs.py
@@ -277,80 +277,93 @@ class CreateVnfs(Thread):
def create_vnf_in_aai(self):
logger.debug("CreateVnfs::create_vnf_in_aai::report vnf instance[%s] to aai." % self.nf_inst_id)
- data = {
- "vnf-id": self.nf_inst_id,
- "vnf-name": self.vnf_inst_name,
- "vnf-type": "vnf-type-test111",
- "service-id": self.ns_inst_id,
- "in-maint": True,
- "is-closed-loop-disabled": False,
- "relationship-list": {
- "relationship": [
- {
- "related-to": "service-instance",
- "relationship-data": [
- {
- "relationship-key": "customer.global-customer-id",
- "relationship-value": "global-customer-id-" + self.ns_inst_id
- },
- {
- "relationship-key": "service-subscription.service-type",
- "relationship-value": "Network"
- },
- {
- "relationship-key": "service-instance.service-instance-id",
- "relationship-value": self.ns_inst_id
- }
- ]
- }
- ]
- }
- }
- resp_data, resp_status = create_vnf_aai(self.nf_inst_id, data)
- if resp_data:
- logger.debug("Fail to create vnf instance[%s] to aai, vnf instance=[%s], resp_status: [%s]."
- % (self.nf_inst_id, self.ns_inst_id, resp_status))
- else:
- logger.debug("Success to create vnf instance[%s] to aai, vnf instance=[%s], resp_status: [%s]."
- % (self.nf_inst_id, self.ns_inst_id, resp_status))
-
- def create_vserver_in_aai(self):
- logger.debug("CreateVnfs::create_vserver_in_aai::report vserver instance to aai.")
- cloud_owner, cloud_region_id = split_vim_to_owner_region(self.vim_id)
-
- # query vim_info from aai
- vim_info = get_vim_by_id(self.vim_id)
- tenant_id = vim_info["tenant"]
- vm_inst_infos = VmInstModel.objects.filter(insttype=INST_TYPE.VNF, instid=self.nf_inst_id)
- for vm_inst_info in vm_inst_infos:
- vserver_id = vm_inst_info.resouceid
+ try:
data = {
- "vserver-id": vm_inst_info.resouceid,
- "vserver-name": vm_inst_info.vmname,
- "prov-status": "ACTIVE",
- "vserver-selflink": "",
+ "vnf-id": self.nf_inst_id,
+ "vnf-name": self.vnf_inst_name,
+ "vnf-type": "vnf-type-test111",
+ "service-id": self.ns_inst_id,
"in-maint": True,
"is-closed-loop-disabled": False,
"relationship-list": {
"relationship": [
{
- "related-to": "generic-vnf",
+ "related-to": "service-instance",
"relationship-data": [
{
- "relationship-key": "generic-vnf.vnf-id",
- "relationship-value": self.nf_inst_id
+ "relationship-key": "customer.global-customer-id",
+ "relationship-value": "global-customer-id-" + self.ns_inst_id
+ },
+ {
+ "relationship-key": "service-subscription.service-type",
+ "relationship-value": "Network"
+ },
+ {
+ "relationship-key": "service-instance.service-instance-id",
+ "relationship-value": self.ns_inst_id
}
]
}
]
}
}
-
- # create vserver instance in aai
- resp_data, resp_status = create_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, data)
+ resp_data, resp_status = create_vnf_aai(self.nf_inst_id, data)
if resp_data:
- logger.debug("Fail to create vserver instance[%s] to aai, vnf instance=[%s], resp_status: [%s]."
- % (vserver_id, self.nf_inst_id, resp_status))
+ logger.debug("Fail to create vnf[%s] to aai, ns instance=[%s], resp_status: [%s]."
+ % (self.nf_inst_id, self.ns_inst_id, resp_status))
else:
- logger.debug("Success to create vserver instance[%s] to aai, vnf instance=[%s], resp_status: [%s]."
- % (vserver_id, self.nf_inst_id, resp_status))
+ logger.debug("Success to create vnf[%s] to aai, ns instance=[%s], resp_status: [%s]."
+ % (self.nf_inst_id, self.ns_inst_id, resp_status))
+ except NSLCMException as e:
+ logger.debug("Fail to create vnf[%s] to aai, ns instance=[%s], detail message: %s"
+ % (self.nf_inst_id, self.ns_inst_id, e.message))
+ except:
+ logger.error(traceback.format_exc())
+
+ def create_vserver_in_aai(self):
+ logger.debug("CreateVnfs::create_vserver_in_aai::report vserver instance to aai.")
+ try:
+ cloud_owner, cloud_region_id = split_vim_to_owner_region(self.vim_id)
+
+ # query vim_info from aai
+ vim_info = get_vim_by_id(self.vim_id)
+ tenant_id = vim_info["tenant"]
+ vm_inst_infos = VmInstModel.objects.filter(insttype=INST_TYPE.VNF, instid=self.nf_inst_id)
+ for vm_inst_info in vm_inst_infos:
+ vserver_id = vm_inst_info.resouceid
+ data = {
+ "vserver-id": vm_inst_info.resouceid,
+ "vserver-name": vm_inst_info.vmname,
+ "prov-status": "ACTIVE",
+ "vserver-selflink": "",
+ "in-maint": True,
+ "is-closed-loop-disabled": False,
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "generic-vnf",
+ "relationship-data": [
+ {
+ "relationship-key": "generic-vnf.vnf-id",
+ "relationship-value": self.nf_inst_id
+ }
+ ]
+ }
+ ]
+ }
+ }
+
+ # create vserver instance in aai
+ resp_data, resp_status = create_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, data)
+ if resp_data:
+ logger.debug("Fail to create vserver[%s] to aai, vnf instance=[%s], resp_status: [%s]."
+ % (vserver_id, self.nf_inst_id, resp_status))
+ else:
+ logger.debug("Success to create vserver[%s] to aai, vnf instance=[%s], resp_status: [%s]."
+ % (vserver_id, self.nf_inst_id, resp_status))
+ logger.debug("Success to create all vserver to aai.")
+ except NSLCMException as e:
+ logger.debug("Fail to create vserver to aai, vnf instance=[%s], detail message: %s"
+ % (self.nf_inst_id, e.message))
+ except:
+ logger.error(traceback.format_exc())
diff --git a/lcm/ns/vnfs/terminate_nfs.py b/lcm/ns/vnfs/terminate_nfs.py
index d641debc..595470e6 100644
--- a/lcm/ns/vnfs/terminate_nfs.py
+++ b/lcm/ns/vnfs/terminate_nfs.py
@@ -135,45 +135,51 @@ class TerminateVnfs(threading.Thread):
def delete_vnf_in_aai(self):
logger.debug("TerminateVnfs::delete_vnf_in_aai::delete vnf instance[%s] in aai." % self.vnf_inst_id)
+ try:
+ # query vnf instance in aai, get resource_version
+ customer_info = query_vnf_aai(self.vnf_inst_id)
+ resource_version = customer_info["resource-version"]
- # query vnf instance in aai, get resource_version
- customer_info = query_vnf_aai(self.vnf_inst_id)
- resource_version = customer_info["resource-version"]
-
- # delete vnf instance from aai
- resp_data, resp_status = delete_vnf_aai(self.vnf_inst_id, resource_version)
- if resp_data:
- logger.debug("Fail to delete vnf instance[%s] from aai, resp_status: [%s]."
- % (self.vnf_inst_id, resp_status))
- else:
- logger.debug(
- "Success to delete vnf instance[%s] from aai, resp_status: [%s]." % (self.vnf_inst_id, resp_status))
-
- def delete_vserver_in_aai(self):
- logger.debug("delete_vserver_in_aai start!")
-
- vm_inst_infos = VmInstModel.objects.filter(insttype=INST_TYPE.VNF, instid=self.vnf_inst_id)
- for vm_inst_info in vm_inst_infos:
- vserver_id = vm_inst_info.resouceid
- vim_id = vm_inst_info.vimid
- cloud_owner, cloud_region_id = split_vim_to_owner_region(vim_id)
- # query vim_info from aai, get tenant
- vim_info = get_vim_by_id(vim_id)
- tenant_id = vim_info["tenant"]
-
- # query vserver instance in aai, get resource_version
- vserver_info = query_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id)
- resource_version = vserver_info["resource-version"]
-
- # delete vserver instance from aai
- resp_data, resp_status = delete_vserver_aai(cloud_owner, cloud_region_id,
- tenant_id, vserver_id, resource_version)
+ # delete vnf instance from aai
+ resp_data, resp_status = delete_vnf_aai(self.vnf_inst_id, resource_version)
if resp_data:
- logger.debug("Fail to delete vserver instance[%s] from aai, resp_status: [%s]." %
- (vserver_id, resp_status))
+ logger.debug("Fail to delete vnf[%s] from aai, resp_status: [%s]." % (self.vnf_inst_id, resp_status))
else:
logger.debug(
- "Success to delete vserver instance[%s] from aai, resp_status: [%s]." %
- (vserver_id, resp_status))
+ "Success to delete vnf[%s] from aai, resp_status: [%s]." % (self.vnf_inst_id, resp_status))
+ except NSLCMException as e:
+ logger.debug("Fail to delete vnf from aai[%s], detail message: %s" % (self.vnf_inst_id, e.message))
+ except:
+ logger.error(traceback.format_exc())
- logger.debug("delete_vserver_in_aai end!")
+ def delete_vserver_in_aai(self):
+ logger.debug("delete_vserver_in_aai start!")
+ try:
+ vm_inst_infos = VmInstModel.objects.filter(insttype=INST_TYPE.VNF, instid=self.vnf_inst_id)
+ for vm_inst_info in vm_inst_infos:
+ vserver_id = vm_inst_info.resouceid
+ vim_id = vm_inst_info.vimid
+ cloud_owner, cloud_region_id = split_vim_to_owner_region(vim_id)
+ # query vim_info from aai, get tenant
+ vim_info = get_vim_by_id(vim_id)
+ tenant_id = vim_info["tenant"]
+
+ # query vserver instance in aai, get resource_version
+ vserver_info = query_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id)
+ resource_version = vserver_info["resource-version"]
+
+ # delete vserver instance from aai
+ resp_data, resp_status = delete_vserver_aai(cloud_owner, cloud_region_id,
+ tenant_id, vserver_id, resource_version)
+ if resp_data:
+ logger.debug("Fail to delete vserver instance[%s] from aai, resp_status: [%s]." %
+ (vserver_id, resp_status))
+ else:
+ logger.debug(
+ "Success to delete vserver instance[%s] from aai, resp_status: [%s]." %
+ (vserver_id, resp_status))
+ logger.debug("delete_vserver_in_aai end!")
+ except NSLCMException as e:
+ logger.debug("Fail to delete vserver from aai, detail message: %s" % e.message)
+ except:
+ logger.error(traceback.format_exc())