Example #1
0
 def delete_vnf_instance_resource(self, context, vnf_instance,
                                  vim_connection_info, vnf_resource):
     LOG.info(
         "Deleting resource '%(name)s' of type ' %(type)s' for vnf"
         "%(id)s", {
             "type": vnf_resource.resource_type,
             "name": vnf_resource.resource_name,
             "id": vnf_instance.id
         })
     glance_client = gc.GlanceClient(vim_connection_info)
     try:
         glance_client.delete(vnf_resource.resource_identifier)
         LOG.info(
             "Deleted resource '%(name)s' of type ' %(type)s' for vnf"
             "%(id)s", {
                 "type": vnf_resource.resource_type,
                 "name": vnf_resource.resource_name,
                 "id": vnf_instance.id
             })
     except Exception:
         LOG.info(
             "Failed to delete resource '%(name)s' of type"
             " %(type)s' for vnf %(id)s", {
                 "type": vnf_resource.resource_type,
                 "name": vnf_resource.resource_name,
                 "id": vnf_instance.id
             })
Example #2
0
    def pre_instantiation_vnf(self, context, vnf_instance, vim_connection_info,
                              vnf_software_images):
        glance_client = gc.GlanceClient(vim_connection_info)
        vnf_resources = {}

        def _roll_back_images():
            # Delete all previously created images for vnf
            for key, resources in vnf_resources.items():
                for vnf_resource in resources:
                    try:
                        glance_client.delete(vnf_resource.resource_identifier)
                    except Exception:
                        LOG.error(
                            "Failed to delete image %(uuid)s "
                            "for vnf %(id)s", {
                                "uuid": vnf_resource.resource_identifier,
                                "id": vnf_instance.id
                            })

        for node_name, vnf_sw_image in vnf_software_images.items():
            name = vnf_sw_image.name
            image_path = vnf_sw_image.image_path
            is_url = utils.is_url(image_path)

            if not is_url:
                filename = image_path
            else:
                filename = None

            try:
                LOG.info("Creating image %(name)s for vnf %(id)s", {
                    "name": name,
                    "id": vnf_instance.id
                })

                image_data = {
                    "min_disk": vnf_sw_image.min_disk,
                    "min_ram": vnf_sw_image.min_ram,
                    "disk_format": vnf_sw_image.disk_format,
                    "container_format": vnf_sw_image.container_format,
                    "visibility": "private"
                }

                if filename:
                    image_data.update({"filename": filename})

                image = glance_client.create(name, **image_data)

                LOG.info("Image %(name)s created successfully for vnf %(id)s",
                         {
                             "name": name,
                             "id": vnf_instance.id
                         })
            except Exception as exp:
                with excutils.save_and_reraise_exception():
                    exp.reraise = False
                    LOG.error(
                        "Failed to create image %(name)s for vnf %(id)s"
                        "due to error: %(error)s", {
                            "name": name,
                            "id": vnf_instance.id,
                            "error": encodeutils.exception_to_unicode(exp)
                        })

                    # Delete previously created images
                    _roll_back_images()

                    raise exceptions.VnfPreInstantiationFailed(
                        id=vnf_instance.id,
                        error=encodeutils.exception_to_unicode(exp))
            try:
                if is_url:
                    glance_client.import_image(image, image_path)

                self._image_create_wait(image.id, vnf_sw_image.hash,
                                        glance_client, 'active',
                                        vnflcm.ImageCreateWaitFailed)

                vnf_resource = objects.VnfResource(
                    context=context,
                    vnf_instance_id=vnf_instance.id,
                    resource_name=name,
                    resource_type="image",
                    resource_status="CREATED",
                    resource_identifier=image.id)
                vnf_resources[node_name] = [vnf_resource]
            except Exception as exp:
                with excutils.save_and_reraise_exception():
                    exp.reraise = False
                    LOG.error(
                        "Image %(name)s not active for vnf %(id)s"
                        "error: %(error)s", {
                            "name": name,
                            "id": vnf_instance.id,
                            "error": encodeutils.exception_to_unicode(exp)
                        })

                    err_msg = "Failed to delete image %(uuid)s for vnf %(id)s"
                    # Delete the image
                    try:
                        glance_client.delete(image.id)
                    except Exception:
                        LOG.error(err_msg, {
                            "uuid": image.id,
                            "id": vnf_instance.id
                        })

                    # Delete all previously created images for vnf
                    _roll_back_images()

                    raise exceptions.VnfPreInstantiationFailed(
                        id=vnf_instance.id,
                        error=encodeutils.exception_to_unicode(exp))

        return vnf_resources