Exemplo n.º 1
0
    def _add_attributes(self, shell_path, attribute_names, modificator=None):
        """ Add a commented out attributes to the shell definition """

        if not modificator:
            modificator = DefinitionModification(shell_path)

        modificator.add_properties(attribute_names=attribute_names)
Exemplo n.º 2
0
    def _add_based_on(self, shell_path, modificator=None):
        """ Add Based_ON field to shell-definition.yaml file """

        if not modificator:
            modificator = DefinitionModification(shell_path)

        modificator.add_field_to_definition(field=TEMPLATE_BASED_ON)
Exemplo n.º 3
0
    def _unpack_driver_archive(self, shell_path, modificator=None):
        """ Unpack driver files from ZIP-archive """

        if not modificator:
            modificator = DefinitionModification(shell_path)

        artifacts = modificator.get_artifacts_files(
            artifact_name_list=self.ARTIFACTS.keys())

        for artifact_name, artifact_path in artifacts.iteritems():

            artifact_path = os.path.join(shell_path, artifact_path)

            if os.path.exists(artifact_path):
                self.repository_downloader.repo_extractor.extract_to_folder(
                    artifact_path,
                    os.path.join(shell_path, self.ARTIFACTS[artifact_name]))
                os.remove(artifact_path)
Exemplo n.º 4
0
    def _change_author(self, shell_path, modificator=None):
        """ Change shell authoring """

        author = self.cloudshell_config_reader.read().author

        if not modificator:
            modificator = DefinitionModification(shell_path)

        modificator.edit_definition(field=TEMPLATE_AUTHOR_FIELD, value=author)
        modificator.edit_tosca_meta(field=METADATA_AUTHOR_FIELD, value=author)
Exemplo n.º 5
0
    def extend(self, source, attribute_names):
        """ Create a new shell based on an already existing shell
        :param str source: The path to the existing shell. Can be a url or local path
        :param tuple attribute_names: Sequence of attribute names that should be added
        """

        with TempDirContext("Extended_Shell_Temp_Dir") as temp_dir:
            try:
                if self._is_local(source):
                    temp_shell_path = self._copy_local_shell(
                        self._remove_prefix(
                            source,
                            ExtendCommandExecutor.LOCAL_TEMPLATE_URL_PREFIX),
                        temp_dir)
                else:
                    temp_shell_path = self._copy_online_shell(source, temp_dir)
            except VersionRequestException as err:
                raise click.ClickException(err.message)
            except Exception:
                # raise
                raise click.BadParameter(
                    u"Check correctness of entered attributes")

            # Remove shell version from folder name
            shell_path = re.sub(r"-\d+(\.\d+)*/?$", "", temp_shell_path)
            os.rename(temp_shell_path, shell_path)

            if not self.shell_gen_validations.validate_2nd_gen(shell_path):
                raise click.ClickException(u"Invalid second generation Shell.")

            modificator = DefinitionModification(shell_path)
            self._unpack_driver_archive(shell_path, modificator)
            self._remove_quali_signature(shell_path)
            self._change_author(shell_path, modificator)
            self._add_based_on(shell_path, modificator)
            self._add_attributes(shell_path, attribute_names)

            try:
                # pass
                shutil.move(shell_path, os.path.curdir)
            except shutil.Error as err:
                raise click.BadParameter(err.message)

        click.echo("Created shell based on source {}".format(source))