コード例 #1
0
    def test_get_shell_from_definition_with_hard_reload(self):
        # Arrange
        self.fs.CreateFile('work/nut-shell/TOSCA-Metadata/TOSCA.meta',
                           contents='TOSCA-Meta-File-Version: 1.0\n'
                           'CSAR-Version: 0.1.0\n'
                           'Created-By: Anonymous\n'
                           'Entry-Definitions: shell-definition.yaml')
        self.fs.CreateFile(
            'work/nut-shell/shell-definition.yaml',
            contents='tosca_definitions_version: tosca_simple_yaml_1_0\n'
            'metadata:\n'
            '  template_name: NutShell\n'
            '  template_author: Anonymous\n'
            '  template_version: 1.0.0\n'
            'node_types:\n'
            '  vendor.switch.NXOS:\n'
            '    derived_from: cloudshell.nodes.Switch\n'
            '    artifacts:\n'
            '      icon:\n'
            '        file: nxos.png\n'
            '        type: tosca.artifacts.File\n'
            '      driver:\n'
            '        file: NutShellDriver.zip\n'
            '        type: tosca.artifacts.File')

        shell_package = ShellPackage('work/nut-shell')
        shell_package.real_shell_name = "something"

        # Act
        shell_name = shell_package.get_name_from_definition(should_reload=True)

        # Assert
        self.assertEqual(shell_name, 'NutShell')
コード例 #2
0
    def generate(self):
        """
        Generates Python driver by connecting to CloudShell server
        :return:
        """
        current_path = os.getcwd()
        shell_package = ShellPackage(current_path)
        if not shell_package.is_tosca():
            click.echo('Code generation supported in TOSCA based shells only',
                       err=True)
            return

        shell_name = shell_package.get_shell_name()
        shell_filename = shell_name + '.zip'
        package_full_path = path.join(current_path, 'dist', shell_filename)
        destination_path = path.join(current_path, 'src')

        cloudshell_config = self.cloudshell_config_reader.read()

        click.echo('Connecting to Cloudshell server ...')

        self.driver_generator.generate_driver(
            cloudshell_config=cloudshell_config,
            destination_path=destination_path,
            package_full_path=package_full_path,
            shell_filename=shell_filename,
            shell_name=shell_name)
コード例 #3
0
    def pack(self, path):
        """
        Creates TOSCA based Shell package
        :return:
        """
        shell_package = ShellPackage(path)
        shell_name = shell_package.get_shell_name()
        with TempDirContext(shell_name) as package_path:

            self._copy_tosca_meta(package_path, '')
            tosca_meta = self._read_tosca_meta(path)

            shell_definition_path = tosca_meta['Entry-Definitions']

            self._copy_shell_definition(package_path, '', shell_definition_path)
            self._create_driver('', os.curdir, shell_name)

            with open(shell_definition_path) as shell_definition_file:
                shell_definition = yaml.load(shell_definition_file)

                if 'template_icon' in shell_definition['metadata']:
                    self._copy_artifact(shell_definition['metadata']['template_icon'], package_path)

                for node_type in shell_definition['node_types'].values():
                    if 'artifacts' not in node_type:
                        continue
                    for artifact in node_type['artifacts'].values():
                        self._copy_artifact(artifact['file'], package_path)

            zip_path = self._zip_package(package_path, '', shell_name)

            click.echo(u'Shell package was successfully created: ' + zip_path)
コード例 #4
0
 def _read_tosca_meta(self, path):
     tosca_meta = {}
     shell_package = ShellPackage(path)
     with open(shell_package.get_metadata_path()) as meta_file:
         for meta_line in meta_file:
             (key, val) = meta_line.split(":")
             tosca_meta[key] = val.strip()
     return tosca_meta
コード例 #5
0
 def install(self):
     current_path = os.getcwd()
     shell_package = ShellPackage(current_path)
     if shell_package.is_tosca():
         self.shell_package_installer.install(current_path)
     else:
         self._install_old_school_shell()
     click.secho('Successfully installed shell', fg='green')
コード例 #6
0
    def test_get_shell_name_should_be_capitalized(self):
        # Arrange
        shell_package = ShellPackage('work/folders/nut-shell')

        # Act
        shell_name = shell_package.get_shell_name()

        # Assert
        self.assertEqual(shell_name, 'NutShell')
コード例 #7
0
    def pack(self):

        current_path = os.getcwd()

        shell_package = ShellPackage(current_path)
        if shell_package.is_tosca():
            self.shell_package_builder.pack(current_path)
        else:
            self._pack_old_school_shell(current_path)
コード例 #8
0
 def install(self):
     current_path = os.getcwd()
     shell_package = ShellPackage(current_path)
     if shell_package.is_layer_one():
         click.secho("Installing a L1 shell directly via shellfoundry is not supported. "
                     "Please follow the L1 shell import procedure described in help.quali.com.", fg="yellow")
     else:
         if shell_package.is_tosca():
             self.shell_package_installer.install(current_path)
         else:
             self._install_old_school_shell()
         click.secho('Successfully installed shell', fg='green')
コード例 #9
0
    def pack(self, path):
        """
        Creates TOSCA based Shell package
        :return:
        """

        self._remove_all_pyc(path)
        shell_package = ShellPackage(path)
        shell_name = shell_package.get_shell_name()
        shell_real_name = shell_package.get_name_from_definition()
        with TempDirContext(shell_name) as package_path:
            self._copy_tosca_meta(package_path, "")
            tosca_meta = self._read_tosca_meta(path)

            shell_definition_path = tosca_meta["Entry-Definitions"]

            self._copy_shell_definition(package_path, "",
                                        shell_definition_path)

            with open(shell_definition_path) as shell_definition_file:
                shell_definition = yaml.load(shell_definition_file)

                if "template_icon" in shell_definition["metadata"]:
                    self._copy_artifact(
                        shell_definition["metadata"]["template_icon"],
                        package_path)

                for node_type in shell_definition["node_types"].values():
                    if "artifacts" not in node_type:
                        continue

                    for artifact_name, artifact in node_type[
                            "artifacts"].iteritems():
                        if artifact_name == "driver":
                            self._create_driver(path="",
                                                package_path=os.curdir,
                                                dir_path=self.DRIVER_DIR,
                                                driver_name=os.path.basename(
                                                    artifact["file"]))
                        elif artifact_name == "deployment":
                            self._create_driver(path="",
                                                package_path=os.curdir,
                                                dir_path=self.DEPLOY_DIR,
                                                driver_name=os.path.basename(
                                                    artifact["file"]),
                                                mandatory=False)

                        self._copy_artifact(artifact["file"], package_path)

            zip_path = self._zip_package(package_path, "", shell_real_name)

            click.echo(u"Shell package was successfully created: " + zip_path)
コード例 #10
0
    def pack(self):

        current_path = os.getcwd()

        shell_package = ShellPackage(current_path)
        if shell_package.is_layer_one():
            click.secho(
                "Packaging a L1 shell directly via shellfoundry is not supported.",
                fg="yellow")
        elif shell_package.is_tosca():
            self.shell_package_builder.pack(current_path)
        else:
            self._pack_old_school_shell(current_path)
コード例 #11
0
    def install(self, path):
        shell_package = ShellPackage(path)
        shell_filename = shell_package.get_shell_name() + '.zip'
        package_full_path = os.path.join(path, 'dist', shell_filename)

        cloudshell_config = self.cloudshell_config_reader.read()

        cs_connection_label = 'Connecting to CloudShell at {}:{}'.format(
            cloudshell_config.host, cloudshell_config.port)
        with click.progressbar(length=CloudShell_Max_Retries,
                               show_eta=False,
                               label=cs_connection_label) as pbar:
            try:
                client = self._open_connection_to_quali_server(
                    cloudshell_config, pbar, retry=CloudShell_Max_Retries)
            finally:
                self._render_pbar_finish(pbar)

        pbar_install_shell_len = 2  # amount of possible actions (update and add)
        installation_label = 'Installing shell into CloudShell'.ljust(
            len(cs_connection_label))
        with click.progressbar(length=pbar_install_shell_len,
                               show_eta=False,
                               label=installation_label) as pbar:
            try:
                client.update_shell(package_full_path)
            except ShellNotFoundException:
                self._increase_pbar(pbar, Default_Time_Wait)
                self._add_new_shell(client, package_full_path)
            except Exception as e:
                self._increase_pbar(pbar, Default_Time_Wait)
                raise FatalError(
                    self._parse_installation_error('Failed to update shell',
                                                   e))
            finally:
                self._render_pbar_finish(pbar)
コード例 #12
0
 def _copy_tosca_meta(self, package_path, path):
     shell_package = ShellPackage(path)
     self._copy_file(src_file_path=shell_package.get_metadata_path(),
                     dest_dir_path=os.path.join(package_path,
                                                "TOSCA-Metadata"))
コード例 #13
0
    def install(self, path):
        """ Install new or Update existed Shell """

        shell_package = ShellPackage(path)
        # shell_name = shell_package.get_shell_name()
        shell_name = shell_package.get_name_from_definition()
        shell_filename = shell_name + ".zip"
        package_full_path = os.path.join(path, "dist", shell_filename)

        cloudshell_config = self.cloudshell_config_reader.read()

        if cloudshell_config.domain != self.GLOBAL_DOMAIN:
            raise click.UsageError(
                "Gen2 shells could not be installed into non Global domain.")

        cs_connection_label = "Connecting to CloudShell at {}:{}".format(
            cloudshell_config.host, cloudshell_config.port)
        with click.progressbar(length=CLOUDSHELL_MAX_RETRIES,
                               show_eta=False,
                               label=cs_connection_label) as pbar:
            try:
                client = self._open_connection_to_quali_server(
                    cloudshell_config, pbar, retry=CLOUDSHELL_MAX_RETRIES)
            finally:
                self._render_pbar_finish(pbar)

        try:
            is_official = client.get_shell(shell_name=shell_name).get(
                SHELL_IS_OFFICIAL_FLAG, False)

            if is_official:
                click.confirm(
                    text=
                    "Upgrading to a custom version of the shell will limit you "
                    "only to customized versions of this shell from now on. "
                    "You won't be able to upgrade it to an official version of the shell in the future."
                    "\nDo you wish to continue?",
                    abort=True)

        except FeatureUnavailable:
            # try to update shell first
            pass
        except ShellNotFoundException:
            # try to install shell
            pass
        except click.Abort:
            raise
        except Exception as e:
            raise FatalError(
                self._parse_installation_error(
                    "Failed to get information about installed shell", e))

        pbar_install_shell_len = 2  # amount of possible actions (update and add)
        installation_label = "Installing shell into CloudShell".ljust(
            len(cs_connection_label))
        with click.progressbar(length=pbar_install_shell_len,
                               show_eta=False,
                               label=installation_label) as pbar:
            try:
                client.update_shell(package_full_path)
            except ShellNotFoundException:
                self._increase_pbar(pbar, DEFAULT_TIME_WAIT)
                self._add_new_shell(client, package_full_path)
            except Exception as e:
                self._increase_pbar(pbar, DEFAULT_TIME_WAIT)
                raise FatalError(
                    self._parse_installation_error("Failed to update shell",
                                                   e))
            finally:
                self._render_pbar_finish(pbar)
コード例 #14
0
    def test_is_layer_one(self):
        # Arrange
        shell_package = ShellPackage('work/folders/cloudshell-L1-test')

        # Assert
        self.assertTrue(shell_package.is_layer_one())