def main():
    """Pattoo CLI script.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    _help = 'This program is the CLI interface to configuring the linux agent'
    template_dir = os.path.join(ROOT_DIR, 'setup/systemd/system')
    daemon_list = [
        'pattoo_agent_linux_autonomousd', 'pattoo_agent_linux_spoked',
        'pattoo_agent_linux_hubd'
    ]

    # Ensure user is running as root or travis
    check_user()

    # Process the CLI
    _parser = Parser(additional_help=_help)
    (args, parser) = _parser.args()

    # Process CLI options
    if args.action == 'install':

        # Installs all linux agent components
        if args.qualifier == 'all':
            print('Installing everything')
            configure.install(daemon_list)
            packages.install(ROOT_DIR)
            systemd.install(daemon_list=daemon_list,
                            template_dir=template_dir,
                            installation_dir=ROOT_DIR)

        # Sets up configuration for linux agent
        elif args.qualifier == 'configuration':
            print('Installing configuration')
            configure.install(daemon_list)

        # Installs necessary pip packages
        elif args.qualifier == 'pip':
            print('Installing pip packages')
            packages.install(ROOT_DIR, args.verbose)

        # Installs and runs system daemons
        elif args.qualifier == 'systemd':
            print('Installing and running system daemons')
            systemd.install(daemon_list=daemon_list,
                            template_dir=template_dir,
                            installation_dir=ROOT_DIR)

        else:
            parser.print_help(sys.stderr)
            sys.exit(1)

        # Done
        print('Done')
예제 #2
0
    def test_install(self):
        """Unittest to test the install function."""
        # Test with undefined requirements directory
        with self.subTest():
            with self.assertRaises(SystemExit) as cm_:
                requirements_dir = data.hashstring(str(random()))
                install(requirements_dir, self.venv_dir)
            self.assertEqual(cm_.exception.code, 3)

        # Test with default expected behaviour
        with self.subTest():
            # At least one expected package
            expected_package = 'Flask'
            expected = True

            # Create temporary directory
            result = install(ROOT_DIR, self.venv_dir)

            # Get raw packages in requirements format
            packages = shared.run_script('python3 -m pip freeze')[1]

            # Get packages with versions removed
            installed_packages = [
                package.decode().split('==')[0]
                for package in packages.split()
            ]
            result = expected_package in installed_packages
            self.assertEqual(result, expected)
def install(requirements_dir, installation_dir, verbose=False):
    """Ensure packages necessary for starting the snmp agent are installed.

    Args:
        requirements_dir: The directory with the pip_requirements.txt file

    Returns:
        None
    """
    # Install easysnmp dependencies
    install_dependencies()

    # Install pip packages
    packages.install(requirements_dir, installation_dir, verbose=verbose)
예제 #4
0
파일: install.py 프로젝트: gill876/pattoo
def main():
    """Pattoo CLI script.

        None

    Returns:
        None

    """
    # Initialize key variables
    _help = 'This program is the CLI interface to configuring pattoo'
    daemon_list = ['pattoo_apid', 'pattoo_api_agentd', 'pattoo_ingesterd']
    template_dir = os.path.join(ROOT_DIR, 'setup/systemd/system')

    # Process the CLI
    _parser = Parser(additional_help=_help)
    (args, parser) = _parser.args()

    # Perform checks
    checks.parser_check(_parser.args()[1], _parser.args()[0])
    checks.pattoo_shared_check()
    checks.venv_check()

    # Import packages that depend on pattoo shared
    from _pattoo import configure
    from pattoo_shared.installation import packages, systemd, environment

    # Set up essentials for creating the virtualenv
    pattoo_home = get_pattoo_home()
    venv_dir = os.path.join(pattoo_home, 'pattoo-venv')
    if getpass.getuser() != 'travis':
        environment.environment_setup(venv_dir)
    venv_interpreter = os.path.join(venv_dir, 'bin/python3')
    installation_dir = '{} {}'.format(venv_interpreter, ROOT_DIR)

    # Installs all pattoo components
    if args.qualifier == 'all':
        print('Installing everything')
        configure.install(pattoo_home)
        packages.install(ROOT_DIR, venv_dir, args.verbose)

        # Import db after pip3 packages are installed
        from _pattoo import db
        db.install()
        if shared.root_check() is True and args.action != 'developer':
            systemd.install(daemon_list=daemon_list,
                            template_dir=template_dir,
                            installation_dir=installation_dir,
                            verbose=args.verbose)

    # Configures pattoo and sets up database tables
    elif args.qualifier == 'database':
        print('Installing database tables')
        configure.install(pattoo_home)
        packages.install(ROOT_DIR, venv_dir)
        # Import db after pip3 packages are installed
        from _pattoo import db
        db.install()

    # Installs and starts system daemons
    elif args.qualifier == 'systemd':
        print('Installing systemd daemons')
        if shared.root_check() is True:
            systemd.install(daemon_list=daemon_list,
                            template_dir=template_dir,
                            installation_dir=installation_dir,
                            verbose=True)
        else:
            shared.log('You need to be running as root to install the daemons')

    elif args.qualifier == 'pip':
        # Installs additionally required pip3 packages
        packages.install(ROOT_DIR, venv_dir, args.verbose)

    # Sets up the configuration for pattoo
    elif args.qualifier == 'configuration':
        configure.install(pattoo_home)

    # Print help if no argument options were triggered
    else:
        parser.print_help(sys.stderr)
        sys.exit(1)

        # Done
        print('Done')
예제 #5
0
def main():
    """Pattoo CLI script.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    _help = 'This program is the CLI interface to configuring pattoo web'
    template_dir = os.path.join(ROOT_DIR, 'setup/systemd/system')
    daemon_list = ['pattoo_webd']
    config_files = [
        'pattoo.yaml', 'pattoo_server.yaml', 'pattoo_agent.yaml',
        'pattoo_webd.yaml'
    ]

    # Ensure user is running as root or travis
    installation_checks()

    # Process the CLI
    _parser = Parser(additional_help=_help)
    (args, parser) = _parser.args()

    # Process CLI options
    if args.action == 'install':
        # Do package checks
        pattoo_shared_check()
        venv_check()

        # Import packages that depend on pattoo shared
        from _pattoo_web import configure, docker
        from pattoo_shared.installation import packages, systemd, environment

        # Setup virtual environment
        if getpass.getuser() != 'travis':
            pattoo_home = get_pattoo_home()
            venv_dir = os.path.join(pattoo_home, 'pattoo-venv')
            environment.environment_setup(venv_dir)
            venv_interpreter = os.path.join(venv_dir, 'bin/python3')
            installation_dir = '{} {}'.format(venv_interpreter, ROOT_DIR)
        else:
            # Set default directories for travis
            pattoo_home = os.path.join(os.path.expanduser('~'), 'pattoo')
            venv_dir = DEFAULT_PATH
            installation_dir = ROOT_DIR

        # Installs all pattoo webd agent components
        if args.qualifier == 'all':
            print('Installing everything')
            configure.install(pattoo_home)
            packages.install(ROOT_DIR, venv_dir, verbose=args.verbose)
            systemd.install(daemon_list=daemon_list,
                            template_dir=template_dir,
                            installation_dir=installation_dir,
                            verbose=args.verbose)

        # Sets up configuration for agent
        elif args.qualifier == 'configuration':
            print('Installing configuration')
            configure.install(pattoo_home)

        # Installs pip packages
        elif args.qualifier == 'pip':
            print('Installing pip packages')
            packages.install(ROOT_DIR, venv_dir, verbose=args.verbose)

        # Installs and runs system daemons in the daemon list
        elif args.qualifier == 'systemd':
            print('Installing and running system daemons')
            systemd.install(daemon_list=daemon_list,
                            template_dir=template_dir,
                            installation_dir=installation_dir,
                            verbose=args.verbose)
        elif args.qualifier == 'docker':
            docker.install('pattoo-web', config_files)

        else:
            parser.print_help(sys.stderr)
            sys.exit(1)

        # Done
        print('Done')
예제 #6
0
def main():
    """Pattoo CLI script.

    Args:
        None

    Returns:
        None

    """
    # Initialize key variables
    _help = 'This program is the CLI interface to configuring the bacnet agent'
    template_dir = os.path.join(ROOT_DIR, 'setup/systemd/system')
    daemon_list = ['pattoo_agent_bacnetipd']

    # Perform checks
    checks.installation_checks()
    checks.pattoo_shared_check()
    checks.venv_check()

    # Process the CLI
    _parser = Parser(additional_help=_help)
    (args, parser) = _parser.args()

    # Import packages that depend on pattoo shared
    from _pattoo_agent_bacnet import configure
    from pattoo_shared.installation import packages, systemd, environment

    # Set up essentials for creating the virtualenv
    pattoo_home = get_pattoo_home()
    venv_dir = os.path.join(pattoo_home, 'pattoo-venv')
    if getpass.getuser() != 'travis':
        environment.environment_setup(venv_dir)
    venv_interpreter = os.path.join(venv_dir, 'bin/python3')
    installation_dir = '{} {}'.format(venv_interpreter, ROOT_DIR)

    if args.action == 'install':
        # Installs all linux agent components
        if args.qualifier == 'all':
            print('Installing everything')
            configure.install(pattoo_home)
            packages.install(ROOT_DIR, venv_dir, args.verbose)
            systemd.install(daemon_list=daemon_list,
                            template_dir=template_dir,
                            installation_dir=installation_dir)

        # Sets up configuration for linux agent
        elif args.qualifier == 'configuration':
            print('Installing configuration')
            configure.install(pattoo_home)

        # Installs necessary pip packages
        elif args.qualifier == 'pip':
            print('Installing pip packages')
            packages.install(ROOT_DIR, venv_dir, args.verbose)

        # Installs and runs system daemons
        elif args.qualifier == 'systemd':
            print('Installing and running system daemons')
            systemd.install(daemon_list=daemon_list,
                            template_dir=template_dir,
                            installation_dir=installation_dir)

        else:
            parser.print_help(sys.stderr)
            sys.exit(1)

        # Done
        print('Done')