コード例 #1
0
ファイル: test_bconsole.py プロジェクト: redguy-p2pu/almir
    def test_from_temp_config(self):
        output = \
"""# generated by almir, you should never edit this file. Do:
# vim buildout.cfg
# bin/buildout
# bin/supervisorctl restart all

Director {
    Name = test
    DIRport = 12345
    address = add
    Password = "******"
}
"""
        with BConsole.from_temp_config(
            name='test',
            address='add',
            port='12345',
            password='******'
        ) as b:
            expected = open(b.config_file).read()
            self.assertEqual(expected.replace(' ', ''), output.replace(' ', ''))
コード例 #2
0
    def test_from_temp_config(self):
        output = \
"""# generated by almir, you should never edit this file. Do:
# vim buildout.cfg
# bin/buildout
# bin/supervisorctl restart all

Director {
    Name = test
    DIRport = 12345
    address = add
    Password = "******"
}
"""
        with BConsole.from_temp_config(name='test',
                                       address='add',
                                       port='12345',
                                       password='******') as b:
            expected = open(b.config_file).read()
            self.assertEqual(
                expected.replace(' ', '').replace('\r', ''),
                output.replace(' ', '').replace('\r', ''))
コード例 #3
0
ファイル: configure_deploy.py プロジェクト: gypsymauro/almir
def main():
    """Entry point of this script"""
    print '\n\nConfiguring almir ... If you want to use the default value (where possible), press enter.\n'

    options = {}
    options['host'] = ask_question('Host to listen on (default: 127.0.0.1): ', default='127.0.0.1')
    options['port'] = ask_question('Port to listen on (default: 2500): ', default='2500', validator=validate_open_port)

    print 'Define SQL database connection to bacula catalog as specified in http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls'
    print 'For example:'
    print '    postgresql+pg8000://<user>:<password>@<hostname>/<database>'
    print '    mysql+mysqlconnector://<user>:<password>@<hostname>/<database>'
    print '    sqlite:////var/lib/bacula/bacula.db'
    print '    sqlite:///bacula.db'
    print
    options['engine'] = ask_question('SQL connection string: ', validator=validate_engine)

    print 'Timezone of director in format of TZ* column in table https://en.wikipedia.org/wiki/List_of_tz_database_time_zones'
    print 'For example:'
    print '    Europe/Ljubljana'
    print '    CET'
    print

    try:
        default_timezone = " (default: %s)" % pytz.timezone(time.tzname[0])
    except:
        default_timezone = ''
    options['timezone'] = ask_question('Timezone%s' % default_timezone, default='', validator=validate_timezone)

    # TODO: in future we may extract this from bconsole config file?
    print 'Almost finished, we just need bconsole parameters to connect to director!'
    print 'Normally you will find needed information in /etc/bacula/bconsole.conf'
    print

    try:
        output = subprocess.Popen(['which', 'bconsole'], stdout=subprocess.PIPE).communicate()[0].strip()
    except subprocess.CalledProcessError:
        print 'WARNING: bconsole command is not executable from current user!'
    else:
        if not os.access(output, os.X_OK):
            print 'WARNING: bconsole command is not executable from current user!'

    bconsole_running = False
    while not bconsole_running:
        options['director_name'] = ask_question('Name of director to connect to (default: localhost-dir): ', default='localhost-dir')
        options['director_address'] = ask_question('Address of director to connect to (default: localhost): ', default='localhost')
        options['director_port'] = ask_question('Port of director to connect to (default: 9101): ', default='9101', validator=validate_open_port)
        options['director_password'] = ask_question('Password of director to connect to: ', func=getpass.getpass)

        print 'Connecting director with bconsole to verify configuration ...'

        # need a way to generate bconsole config before running this
        with BConsole.from_temp_config(name=options['director_name'],
                                       address=options['director_address'],
                                       port=options['director_port'],
                                       password=options['director_password']) as bconsole:
            if bconsole.is_running():
                print 'OK!'
                bconsole_running = True
            else:
                print 'ERROR: Could not connect to director %s, verify configuration and try again!' % options['director_name']  # PRAGMA: no cover

    with open(OUTPUT, 'w') as f:
        f.write(TEMPLATE % options)

    print
    print 'Written to %s.' % os.path.realpath(OUTPUT)
コード例 #4
0
def main():
    """Entry point of this script"""
    print '\n\nConfiguring almir ... If you want to use the default value (where possible), press enter.\n'

    options = {}
    options['host'] = ask_question('Host to listen on (default: 127.0.0.1): ',
                                   default='127.0.0.1')
    options['port'] = ask_question('Port to listen on (default: 2500): ',
                                   default='2500',
                                   validator=validate_open_port)

    print 'Define SQL database connection to bacula catalog as specified in http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls'
    print 'For example:'
    print '    postgresql+pg8000://<user>:<password>@<hostname>/<database>'
    print '    mysql+mysqlconnector://<user>:<password>@<hostname>/<database>'
    print '    sqlite:////var/lib/bacula/bacula.db'
    print '    sqlite:///bacula.db'
    print
    options['engine'] = ask_question('SQL connection string: ',
                                     validator=validate_engine)

    print 'Timezone of director in format of TZ* column in table https://en.wikipedia.org/wiki/List_of_tz_database_time_zones'
    print 'For example:'
    print '    Europe/Ljubljana'
    print '    CET'
    print

    try:
        default_timezone = " (default: %s)" % pytz.timezone(time.tzname[0])
    except:
        default_timezone = ''
    options['timezone'] = ask_question('Timezone%s' % default_timezone,
                                       default='',
                                       validator=validate_timezone)

    # TODO: in future we may extract this from bconsole config file?
    print 'Almost finished, we just need bconsole parameters to connect to director!'
    print 'Normally you will find needed information in /etc/bacula/bconsole.conf'
    print

    try:
        output = subprocess.Popen(
            ['which', 'bconsole'],
            stdout=subprocess.PIPE).communicate()[0].strip()
    except subprocess.CalledProcessError:
        print 'WARNING: bconsole command is not executable from current user!'
    else:
        if not os.access(output, os.X_OK):
            print 'WARNING: bconsole command is not executable from current user!'

    bconsole_running = False
    while not bconsole_running:
        options['director_name'] = ask_question(
            'Name of director to connect to (default: localhost-dir): ',
            default='localhost-dir')
        options['director_address'] = ask_question(
            'Address of director to connect to (default: localhost): ',
            default='localhost')
        options['director_port'] = ask_question(
            'Port of director to connect to (default: 9101): ',
            default='9101',
            validator=validate_open_port)
        options['director_password'] = ask_question(
            'Password of director to connect to: ', func=getpass.getpass)

        print 'Connecting director with bconsole to verify configuration ...'

        # need a way to generate bconsole config before running this
        with BConsole.from_temp_config(
                name=options['director_name'],
                address=options['director_address'],
                port=options['director_port'],
                password=options['director_password']) as bconsole:
            if bconsole.is_running():
                print 'OK!'
                bconsole_running = True
            else:
                print 'ERROR: Could not connect to director %s, verify configuration and try again!' % options[
                    'director_name']  # PRAGMA: no cover

    with open(OUTPUT, 'w') as f:
        f.write(TEMPLATE % options)

    print
    print 'Written to %s.' % os.path.realpath(OUTPUT)