Пример #1
0
    def _validate_blueprint_size(self, path, tempdir, skip_size_limit):
        blueprint_directory = os.path.dirname(path) or os.getcwd()
        size, files = utils.get_folder_size_and_files(blueprint_directory)

        try:
            config = self.api.get('/config', params={'scope': 'rest'})
        except CloudifyClientError as err:
            if err.status_code == 404:
                config = {}
            else:
                raise

        size_limit = config.get('blueprint_folder_max_size_mb', {}).get(
            'value', 50)
        files_limit = config.get('blueprint_folder_max_files', {}).get(
            'value', 10000)

        if not skip_size_limit:
            error_message = '{0}, move some resources from the blueprint ' \
                            'folder to an external location or upload the ' \
                            'blueprint folder as a zip file.'
            if size > size_limit * 1000000:
                raise Exception(error_message.format(
                    'Blueprint folder size exceeds {} MB'.format(size_limit)))
            if files > files_limit:
                raise Exception(error_message.format(
                    'Number of files in blueprint folder exceeds {}'.format(
                        files_limit)))
        tar_path = utils.tar_blueprint(path, tempdir)
        return tar_path, os.path.basename(path)
Пример #2
0
    def upload(self,
               blueprint_path,
               blueprint_id,
               private_resource=False,
               progress_callback=None):
        """
        Uploads a blueprint to Cloudify's manager.

        :param blueprint_path: Main blueprint yaml file path.
        :param blueprint_id: Id of the uploaded blueprint.
        :param private_resource: Whether the blueprint should be private
        :param progress_callback: Progress bar callback method
        :return: Created blueprint.

        Blueprint path should point to the main yaml file of the blueprint
        to be uploaded. Its containing folder will be packed to an archive
        and get uploaded to the manager.
        Blueprint ID parameter is available for specifying the
        blueprint's unique Id.
        """
        tempdir = tempfile.mkdtemp()
        try:
            tar_path = utils.tar_blueprint(blueprint_path, tempdir)
            application_file = os.path.basename(blueprint_path)

            blueprint = self._upload(tar_path,
                                     blueprint_id=blueprint_id,
                                     application_file_name=application_file,
                                     private_resource=private_resource,
                                     progress_callback=progress_callback)
            return Blueprint(blueprint)
        finally:
            shutil.rmtree(tempdir)
Пример #3
0
 def calc_size(blueprint_path):
     tempdir = tempfile.mkdtemp()
     try:
         tar_path = utils.tar_blueprint(blueprint_path, tempdir)
         size = os.path.getsize(tar_path)
     finally:
         shutil.rmtree(tempdir)
     return size
Пример #4
0
 def _validate_blueprint_size(self, path, tempdir, skip_size_limit):
     tar_path = utils.tar_blueprint(path, tempdir)
     if not skip_size_limit and os.path.getsize(tar_path) > 30000000:
         raise Exception('Blueprint folder exceeds 30 MB, '
                         'move some resources from the blueprint '
                         'folder to an external location or upload'
                         ' the blueprint folder as a zip file.')
     return tar_path, os.path.basename(path)
 def calc_size(blueprint_path):
     tempdir = tempfile.mkdtemp()
     try:
         tar_path = utils.tar_blueprint(blueprint_path, tempdir)
         size = os.path.getsize(tar_path)
     finally:
         shutil.rmtree(tempdir)
     return size
Пример #6
0
    def upload(self,
               path,
               entity_id,
               visibility=VisibilityState.TENANT,
               progress_callback=None,
               skip_size_limit=True):
        """
        Uploads a blueprint to Cloudify's manager.

        :param path: Main blueprint yaml file path.
        :param entity_id: Id of the uploaded blueprint.
        :param visibility: The visibility of the blueprint, can be 'private',
                           'tenant' or 'global'.
        :param progress_callback: Progress bar callback method
        :param skip_size_limit: Indicator whether to check size limit on
                           blueprint folder
        :return: Created response.

        Blueprint path should point to the main yaml file of the response
        to be uploaded. Its containing folder will be packed to an archive
        and get uploaded to the manager.
        Blueprint ID parameter is available for specifying the
        response's unique Id.
        """
        tempdir = tempfile.mkdtemp()
        try:
            tar_path = utils.tar_blueprint(path, tempdir)
            if not skip_size_limit and os.path.getsize(tar_path) > 30000000:
                raise Exception('Blueprint folder exceeds 30 MB, '
                                'move some resources from the blueprint '
                                'folder to an external location or upload'
                                ' the blueprint folder as a zip file.')
            application_file = os.path.basename(path)

            blueprint = self._upload(
                tar_path,
                blueprint_id=entity_id,
                application_file_name=application_file,
                visibility=visibility,
                progress_callback=progress_callback)
            return self._wrapper_cls(blueprint)
        finally:
            shutil.rmtree(tempdir)
    def upload(self,
               path,
               entity_id,
               visibility=VisibilityState.TENANT,
               progress_callback=None,
               skip_size_limit=True):
        """
        Uploads a blueprint to Cloudify's manager.

        :param path: Main blueprint yaml file path.
        :param entity_id: Id of the uploaded blueprint.
        :param visibility: The visibility of the blueprint, can be 'private',
                           'tenant' or 'global'.
        :param progress_callback: Progress bar callback method
        :param skip_size_limit: Indicator whether to check size limit on
                           blueprint folder
        :return: Created response.

        Blueprint path should point to the main yaml file of the response
        to be uploaded. Its containing folder will be packed to an archive
        and get uploaded to the manager.
        Blueprint ID parameter is available for specifying the
        response's unique Id.
        """
        tempdir = tempfile.mkdtemp()
        try:
            tar_path = utils.tar_blueprint(path, tempdir)
            if not skip_size_limit and os.path.getsize(tar_path) > 30000000:
                raise Exception('Blueprint folder exceeds 30 MB, '
                                'move some resources from the blueprint '
                                'folder to an external location or upload'
                                ' the blueprint folder as a zip file.')
            application_file = os.path.basename(path)

            blueprint = self._upload(
                tar_path,
                blueprint_id=entity_id,
                application_file_name=application_file,
                visibility=visibility,
                progress_callback=progress_callback)
            return self._wrapper_cls(blueprint)
        finally:
            shutil.rmtree(tempdir)
    def _update_from_blueprint(self,
                               deployment_id,
                               blueprint_path,
                               inputs=None):
        """Create a deployment update transaction for blueprint app.

        :param deployment_id: The deployment id
        :param blueprint_path: the path of the blueprint to stage
        """
        assert deployment_id

        tempdir = tempfile.mkdtemp()
        try:
            tar_path = utils.tar_blueprint(blueprint_path, tempdir)
            application_filename = os.path.basename(blueprint_path)

            return self._update_from_archive(deployment_id,
                                             tar_path,
                                             application_filename,
                                             inputs=inputs)
        finally:
            shutil.rmtree(tempdir)