コード例 #1
0
ファイル: update.py プロジェクト: 47lining/nucleator-core
    def update_sources(self, **kwargs):
        """
        update Nucleator stacksets specified in sources.yml
        pull each one into ~/.nucleator/contrib/
        """
        sources = os.path.join(properties.NUCLEATOR_CONFIG_DIR, "sources.yml")
        utils.write("\nUpdating nucleator commands from sources in {0}\n".format(sources))
        try:
            roles_path_tmp=os.path.join(properties.NUCLEATOR_CONFIG_DIR, "-".join( [ "contrib", str(uuid.uuid4()) ] ))
            update_command = [
                "ansible-galaxy", "install",
                "--force",
                "--role-file", sources,
                "--roles-path", roles_path_tmp,
            ]
            utils.write(" ".join(update_command) + "\n")

            os.environ["PYTHONUNBUFFERED"]="1"
            update_process=usp.Popen(
                update_command,
                shell=False,
                stdout=usp.PIPE,
                stderr=usp.PIPE
            )
            update_out, update_err = update_process.communicate()
            update_rc = update_process.returncode

        except Exception, e:
            utils.write_err("Exception while updating nucleator commands from specified sources:\n{0}".format(e), False)
            raise e
コード例 #2
0
ファイル: cli.py プロジェクト: 47lining/nucleator-core
 def dump(self):
     utils.write("{0}{1}".format(self.current_command_name(), os.linesep))
     import json
     utils.write("{0}{1}".format(
         json.dumps(
             {k: v
              for (k, v) in self.opts.iteritems() if k != "cli"},
             self.opts,
             sort_keys=True,
             indent=4,
             separators=(',', ': ')), os.linesep))
コード例 #3
0
ファイル: update.py プロジェクト: 47lining/nucleator-core
 def show_versions(self):
     """
     show version of each Nucleator stackset specified in sources.yml
     pull each one into ~/.nucleator/contrib/
     """
     from nucleator import __version__
     utils.write("Your Nucleator core is version "+__version__+"\n\n")
     path = os.path.join(properties.NUCLEATOR_CONFIG_DIR, "contrib")
     # iterate through nucleator command definitions found as immediate subdirs of path
     for command_dir in next(os.walk(path))[1]:
         candidate_location = os.path.join(path, command_dir, "__version__")
         if os.path.isfile(candidate_location):
             with open(candidate_location, 'r') as f:
                 read_data = f.read()
             utils.write("Version of "+command_dir+"\n"+read_data)
     return 0
コード例 #4
0
ファイル: update.py プロジェクト: 47lining/nucleator-core
    def update(self, **kwargs):
        """
        The update command:

          - Pulls and installs Nucleator Cage and Stackset modules to contrib dir in 
            Nucleator configuration directory, as specified in manifest

          - Recursively pulls dependent modules specified in module dependencies for 
            each module in manifest
        """
        if kwargs.get("version"):
            self.show_versions()
            return
        self.update_sources(**kwargs)
        self.update_roles(**kwargs)

        utils.write("SUCCESS - successfully updated nucleator sources and ansible roles, placed in {0}\n\n".format(properties.contrib_path()))
コード例 #5
0
ファイル: update.py プロジェクト: 47lining/nucleator-core
    def write_versions(self):
        """
        show version of each Nucleator stackset specified in sources.yml
        pull each one into ~/.nucleator/contrib/
        """
        sources = os.path.join(properties.NUCLEATOR_CONFIG_DIR, "sources.yml")
        stream = open(sources, 'r')
        slist = yaml.load(stream)
        stream.close()
        path = os.path.join(properties.NUCLEATOR_CONFIG_DIR, "contrib")
        for sname in slist:
            # sname['name'] == "siteconfig":
            # sname['src']
            # sname['version']
            # git ls-remote http://www.kernel.org/pub/scm/git/git.git master
            src = sname['src']
            if src.startswith("git+"):
                src = src[4:]
            update_command = [ "git", "ls-remote", src ]
            if 'version' in sname:
                update_command.append(sname['version'])
            utils.write(" ".join(update_command) + "\n")

            os.environ["PYTHONUNBUFFERED"]="1"
            update_process=usp.Popen(
                update_command,
                shell=False,
                stdout=usp.PIPE,
                stderr=usp.PIPE
            )
            update_out, update_err = update_process.communicate()
            update_rc = update_process.returncode
            if update_rc == 0:
                vers_location = os.path.join(path, sname['name'], "__version__")
                with open(vers_location, 'w') as f:
                    f.write("Remote Location: "+sname['src']+"\n")
                    f.write("Remote Branch: ")
                    f.write("(not specified)" if 'version' not in sname else sname['version'])
                    commit = update_out.split(" ")
                    f.write("\nLast Commit: "+commit[0]+"\n")
コード例 #6
0
ファイル: update.py プロジェクト: 47lining/nucleator-core
    def update_roles(self, **kwargs):
        """
        Use ansible-galaxy to install Ansible roles and any role dependencies
        specified in ansible/roles/roles.yml for any installed Nucleator Stackset.
        """

        utils.write("\nUpdating ansible roles specified in installed Nucleator Stacksets using ansible-galaxy.\n")
        cli=Command.get_cli(kwargs)
        cli.import_commands(os.path.join(properties.NUCLEATOR_CONFIG_DIR,"contrib"))
        
        path_list = cli.ansible_path_list("roles", isdir=True)
        for roles_path in path_list:
            sources = os.path.join(roles_path, "roles.yml")
            if os.path.isfile(sources):
                # import roles using ansible galaxy
                update_command = [
                    "ansible-galaxy", "install",
                    "--force",
                    "--role-file", sources,
                    "--roles-path", roles_path,
                ]
                utils.write(" ".join(update_command) + "\n")
                os.environ["PYTHONUNBUFFERED"]="1"
                try:
                    update_process=usp.Popen(
                    update_command,
                    shell=False,
                    stdout=usp.PIPE,
                    stderr=usp.PIPE
                    )
                    update_out, update_err = update_process.communicate()
                    update_rc = update_process.returncode

                except Exception, e:
                    utils.write_err("Exception while updating ansible roles from specified sources:\n{0}".format(e), False)
                    raise e

                if update_rc != 0:
                    utils.write_err("Received non-zero return code {0} while attempting to update ansible roles from specified sources using command: {1}\n\ncaptured stderr:\n{2}\n\n exiting with return code 1...".format(update_rc, " ".join(update_command), update_err))
コード例 #7
0
ファイル: init.py プロジェクト: 47lining/nucleator-core
    def check_prerequisites(self):
        """Check that nucleator pre-requisites are in place"""

        # graffiti monkey
        utils.write("\nChecking graffiti monkey installation...\n")
        try:
            import graffiti_monkey
            from graffiti_monkey.core import GraffitiMonkey
            no_graffiti_monkey=False
        except ImportError:
            no_graffiti_monkey=True
            msg="Prerequisite graffiti_monkey not found.\nNucleator requires graffiti_monkey to run. " \
                "You can install it via:\n" \
                "\tpip install graffiti_monkey==0.7"
            utils.write_err(msg, False)
            utils.write_err("Missing pre-requisite, exiting")
            return

        # paramiko
        utils.write("\nChecking paramiko installation...\n")
        try:
            import paramiko
            no_paramiko=False
        except ImportError:
            no_paramiko=True
            msg="Prerequisite paramiko not found.\nNucleator requires paramiko to run. " \
                "You can install it via:\n" \
                "\tpip install paramiko"
            utils.write_err(msg, False)
            utils.write_err("Missing pre-requisite, exiting")
            return

        # pyyaml
        utils.write("\nChecking pyyaml installation...\n")
        try:
            import yaml
            no_yaml=False
        except ImportError:
            no_yaml=True
            msg="Prerequisite pyyaml not found.\nNucleator requires pyyaml to run. " \
                "You can install it via:\n" \
                "\tpip install pyyaml"
            utils.write_err(msg, False)
            utils.write_err("Missing pre-requisite, exiting")
            return

        # jinja2
        utils.write("\nChecking jinja2 installation...\n")
        try:
            import jinja2
            no_jinja2=False
        except ImportError:
            no_jinja2=True
            msg="Prerequisite jinja2 not found.\nNucleator requires jinja2 to run. " \
                "You can install it via:\n" \
                "\tpip install jinja2"
            utils.write_err(msg, False)
            utils.write_err("Missing pre-requisite, exiting")
            return

        # ansible
        utils.write("\nChecking ansible Installation\n")
        try:
            utils.write(subprocess.check_output(["ansible-playbook", "--version"]))
            no_ansible=False
        except OSError:
            no_ansible=True
        if no_ansible:
            msg="Prerequisite ansible not found.\nNucleator requires ansible to run. " \
                "You can install it with all 47Lining pull requests via:\n" \
                "\tgit clone --recursive --depth 1 -b nucleator_distribution https://github.com/47lining/ansible.git\n" \
                "\tcd ansible; sudo python setup.py install"
            utils.write_err(msg, False)

        # aws CLI
        utils.write("\nChecking aws CLI installation...\n")
        try:
            utils.write(subprocess.check_output(["aws", "--version"]))
            no_aws=False
        except OSError:
            no_aws=True
        if no_aws:
            msg="Prerequisite aws not found.\nNucleator requires aws to run. " \
                "You can install it via:\n" \
                "\tpip install awscli"
            utils.write_err(msg, False)

        # httplib2
        utils.write("\nChecking httplib2 installation...\n")
        try:
            import httplib2
            no_httplib2=False
        except ImportError:
            no_httplib2=True
            msg="Prerequisite httplib2 not found.\nNucleator requires httplib2 to run. " \
                "You can install it via:\n" \
                "\tpip install httplib2"
            utils.write_err(msg, False)
        
        # winrm
        utils.write("\nChecking winrm installation...\n")
        try:
            from winrm import Response
            from winrm.exceptions import WinRMTransportError
            from winrm.protocol import Protocol
        except ImportError:
            msg="Prerequisite winrm not found.\nNucleator requires winrm to run when configuring Windows instances. Ignore this if you are not using any Windows instances. " \
                "You can install it via:\n" \
                "\tpip install pywinrm"
            utils.write(msg)

        # boto
        utils.write("\nChecking boto installation...\n")
        try:
            import boto
            utils.write(boto.Version + "\n")
            no_boto=False
            if not StrictVersion(boto.Version) >= StrictVersion('2.38.0'):
                msg="Prerequisite boto not up to date.\nNucleator requires boto version 2.38.0 or greater to run. " \
                "You can install it via:\n" \
                "\tpip install boto"
                utils.write_err(msg, False)
                no_boto = True
        except ImportError:
            no_boto=True
            msg="Prerequisite boto not found.\nNucleator requires boto to run. " \
                "You can install it via:\n" \
                "\tpip install boto"
            utils.write_err(msg, False)

        if no_ansible or no_aws or no_boto or no_paramiko or no_yaml or no_jinja2 or no_httplib2:
            utils.write_err("Missing pre-requisite, exiting")
コード例 #8
0
ファイル: update.py プロジェクト: 47lining/nucleator-core
class Update(Command):
    
    name = "update"
    
    def parser_init(self, subparsers):
        """
        Initialize parsers for this command.
        """
        init_parser = subparsers.add_parser('update')
        init_parser.add_argument("--version", required=False, help="Show versions of components", action='store_true')

    def update(self, **kwargs):
        """
        The update command:

          - Pulls and installs Nucleator Cage and Stackset modules to contrib dir in 
            Nucleator configuration directory, as specified in manifest

          - Recursively pulls dependent modules specified in module dependencies for 
            each module in manifest
        """
        if kwargs.get("version"):
            self.show_versions()
            return
        self.update_sources(**kwargs)
        self.update_roles(**kwargs)

        utils.write("SUCCESS - successfully updated nucleator sources and ansible roles, placed in {0}\n\n".format(properties.contrib_path()))

    def write_versions(self):
        """
        show version of each Nucleator stackset specified in sources.yml
        pull each one into ~/.nucleator/contrib/
        """
        sources = os.path.join(properties.NUCLEATOR_CONFIG_DIR, "sources.yml")
        stream = open(sources, 'r')
        slist = yaml.load(stream)
        stream.close()
        path = os.path.join(properties.NUCLEATOR_CONFIG_DIR, "contrib")
        for sname in slist:
            # sname['name'] == "siteconfig":
            # sname['src']
            # sname['version']
            # git ls-remote http://www.kernel.org/pub/scm/git/git.git master
            src = sname['src']
            if src.startswith("git+"):
                src = src[4:]
            update_command = [ "git", "ls-remote", src ]
            if 'version' in sname:
                update_command.append(sname['version'])
            utils.write(" ".join(update_command) + "\n")

            os.environ["PYTHONUNBUFFERED"]="1"
            update_process=usp.Popen(
                update_command,
                shell=False,
                stdout=usp.PIPE,
                stderr=usp.PIPE
            )
            update_out, update_err = update_process.communicate()
            update_rc = update_process.returncode
            if update_rc == 0:
                vers_location = os.path.join(path, sname['name'], "__version__")
                with open(vers_location, 'w') as f:
                    f.write("Remote Location: "+sname['src']+"\n")
                    f.write("Remote Branch: ")
                    f.write("(not specified)" if 'version' not in sname else sname['version'])
                    commit = update_out.split(" ")
                    f.write("\nLast Commit: "+commit[0]+"\n")

    def show_versions(self):
        """
        show version of each Nucleator stackset specified in sources.yml
        pull each one into ~/.nucleator/contrib/
        """
        from nucleator import __version__
        utils.write("Your Nucleator core is version "+__version__+"\n\n")
        path = os.path.join(properties.NUCLEATOR_CONFIG_DIR, "contrib")
        # iterate through nucleator command definitions found as immediate subdirs of path
        for command_dir in next(os.walk(path))[1]:
            candidate_location = os.path.join(path, command_dir, "__version__")
            if os.path.isfile(candidate_location):
                with open(candidate_location, 'r') as f:
                    read_data = f.read()
                utils.write("Version of "+command_dir+"\n"+read_data)
        return 0

    def update_sources(self, **kwargs):
        """
        update Nucleator stacksets specified in sources.yml
        pull each one into ~/.nucleator/contrib/
        """
        sources = os.path.join(properties.NUCLEATOR_CONFIG_DIR, "sources.yml")
        utils.write("\nUpdating nucleator commands from sources in {0}\n".format(sources))
        try:
            roles_path_tmp=os.path.join(properties.NUCLEATOR_CONFIG_DIR, "-".join( [ "contrib", str(uuid.uuid4()) ] ))
            update_command = [
                "ansible-galaxy", "install",
                "--force",
                "--role-file", sources,
                "--roles-path", roles_path_tmp,
            ]
            utils.write(" ".join(update_command) + "\n")

            os.environ["PYTHONUNBUFFERED"]="1"
            update_process=usp.Popen(
                update_command,
                shell=False,
                stdout=usp.PIPE,
                stderr=usp.PIPE
            )
            update_out, update_err = update_process.communicate()
            update_rc = update_process.returncode

        except Exception, e:
            utils.write_err("Exception while updating nucleator commands from specified sources:\n{0}".format(e), False)
            raise e

        # move new contrib stacksets into place
        utils.write("\nMoving updated nucleator commands into place\n")

        try:
            # test for existence of config dir
            roles_path=os.path.join(properties.NUCLEATOR_CONFIG_DIR, "contrib")
            if not os.path.isdir(roles_path):
                move_sequence = "mv {1} {0}".format(roles_path, roles_path_tmp)
            else:
                bak_dir=os.path.join(properties.NUCLEATOR_CONFIG_DIR, "contrib.bak")
                roles_path_bak=os.path.join(bak_dir, "-".join( [ "contrib.bak", str(uuid.uuid4()) ]))
                move_sequence = "mkdir -p {0} && mkdir -p {1} && mv {1} {2} && mv {3} {1}".format(bak_dir, roles_path, roles_path_bak, roles_path_tmp)

            utils.write(move_sequence + "\n")
            os.environ["PYTHONUNBUFFERED"]="1"
            move_process=usp.Popen(
                move_sequence,
                shell=True,
                stdout=usp.PIPE,
                stderr=usp.PIPE
            )
            move_out, move_err = move_process.communicate()
            move_rc = move_process.returncode
        except Exception, e:
            utils.write_err("Exception while moving updated nucleator commands into place:\n{0}".format(e), False)
            raise e