from lcm.ns.vnfs.wait_job import wait_job_finish
from lcm.pub.database.models import NfPackageModel, NfInstModel, NSInstModel, VmInstModel, VNFFGInstModel, VLInstModel
from lcm.pub.exceptions import NSLCMException
+from lcm.pub.msapi.aai import create_vnf_aai
from lcm.pub.msapi.extsys import get_vnfm_by_id
from lcm.pub.msapi.resmgr import create_vnf, create_vnf_creation_info
from lcm.pub.msapi.vnfmdriver import send_nf_init_request
self.wait_vnfm_job_finish()
self.write_vnf_creation_info()
self.save_info_to_db()
+ self.create_vnf_in_aai()
except NSLCMException as e:
self.vnf_inst_failed_handle(e.message)
except Exception:
raise NSLCMException('Vnffg instance not exist.')
vnf_list = vnffg_inst_infos[0].vnflist
vnffg_inst_infos.update(vnf_list=vnf_list + ',' + self.nf_inst_id if vnf_list else self.nf_inst_id)
+
+
+ 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
+ }
+ 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, resp_status: [%s]." % (self.nf_inst_id, resp_status))
+ else:
+ logger.debug("Success to create vnf instance[%s] to aai, resp_status: [%s]." % (self.nf_inst_id, resp_status))
from lcm.ns.vnfs.wait_job import wait_job_finish
from lcm.pub.database.models import NfInstModel
from lcm.ns.vnfs.const import VNF_STATUS, NFVO_VNF_INST_TIMEOUT_SECOND
+from lcm.pub.msapi.aai import query_vnf_aai, delete_vnf_aai
from lcm.pub.utils.values import ignore_case_get
from lcm.pub.utils.jobutil import JOB_MODEL_STATUS, JobUtil
from lcm.pub.exceptions import NSLCMException
self.wait_vnfm_job_finish()
self.send_terminate_vnf_to_resMgr()
self.delete_data_from_db()
+ self.delete_vnf_in_aai()
except NSLCMException as e:
self.exception(e.message)
except Exception:
def delete_data_from_db(self):
NfInstModel.objects.filter(nfinstid=self.vnf_inst_id).delete()
JobUtil.add_job_status(self.job_id, 100, 'vnf terminate success', 0)
+
+ def delete_vnf_in_aai(self):
+ logger.debug("TerminateVnfs::delete_vnf_in_aai::delete vnf instance[%s] in aai." % self.vnf_inst_id)
+
+ # 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))
if ret[0] != 0:
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
raise NSLCMException("Ns instance creation exception in AAI")
- return json.JSONDecoder().decode(ret[1])
+ return json.JSONDecoder().decode(ret[1]), ret[2]
def delete_ns_aai(global_customer_id, service_type, service_instance_id, resource_version=""):
resource = "/business/customers/customer/%s/service-subscriptions/service-subscription/" \
def query_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" % \
+ "%s/service-instances/service-instance/%s?depth=all" % \
(global_customer_id, service_type, service_instance_id)
ret = call_aai(resource, "GET", data)
if ret[0] != 0:
if ret[0] != 0:
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
raise NSLCMException("Vnf instance creation exception in AAI")
- return json.JSONDecoder().decode(ret[1])
+ return json.JSONDecoder().decode(ret[1]), ret[2]
def delete_vnf_aai(vnf_id, resource_version=""):
resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id
raise NSLCMException("Vnf instance delete exception in AAI")
return json.JSONDecoder().decode(ret[1])
-def query_vnf_aai(vnf_id, data):
- resource = "/network/generic-vnfs/generic-vnf/%s" % vnf_id
- ret = call_aai(resource, "GET", data)
+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")
if ret[0] != 0:
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
raise NSLCMException("Vserver creation exception in AAI")
- return json.JSONDecoder().decode(ret[1])
+ return json.JSONDecoder().decode(ret[1]), ret[2]
def delete_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, resource_version=""):
resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \
def query_vserver_aai(cloud_owner, cloud_region_id, tenant_id, vserver_id, data):
resource = "/cloud-infrastructure/cloud-regions/cloud-region/%s/" \
- "%s/tenants/tenant/%s/vservers/vserver/%s" % \
+ "%s/tenants/tenant/%s/vservers/vserver/%s?depth=all" % \
(cloud_owner, cloud_region_id, tenant_id, vserver_id)
ret = call_aai(resource, "GET", data)
if ret[0] != 0:
# 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 json
import logging
import traceback
from threading import Thread