예제 #1
0
파일: db.py 프로젝트: bauzaar/django-zilla
def exists():
    """ Check if DB exists """
    with fab_settings(hide('warnings'), warn_only=True):
        result = local(
            'psql --username=%s --dbname=%s --host=%s --command="\q"' %
            (DB['USER'], DB['NAME'], DB['HOST']))
    return result.succeeded
예제 #2
0
def delete_branch(branch_name):
    """ Delete branch """
    if branch_name == get_current_branch():
        abort('You have to switch to another branch')
    with fab_settings(warn_only=True):
        local("git branch -D %s" % branch_name)
        local("git push origin --delete %s" % branch_name)
예제 #3
0
def pull(params=''):
    """ Pull files from the repo -> clean """
    # local("git add --all .") #  F**K!
    if has_uncommitted_changes():
        abort('There are uncommited changes')
    with fab_settings(warn_only=True):
        local("git pull --no-edit origin %s %s" % (get_current_branch(), params))
    local("git clean -d -f --interactive")
    local("git status")
예제 #4
0
def _configure_service(service_name, backup_postfix, single_value_edits,
                       multi_value_edits, template_dir, template_files):
    """
    Configure a service as defined in the supplied params.
    :param service_name: eg: Nova
    :param single_value_edits: dict of configuration instructions
    :param multi_value_edits: dict of configuration instructions
    :param template_dir: directory on calling host where templates are found
    :param template_files: dict of configuration instructions
    :return:
    """

    backed_up_files = []

    with fab_settings(warn_only=True, user="******"):

        print(green("\nConfiguring %s" % service_name))

        # process config changes for single value entries
        for entry in single_value_edits.items():
            file_name = entry[0]
            backed_up_files = _backup_config_file(
                file_name, backup_postfix, backed_up_files)

            # set StrOpt values
            try:
                _set_single_value_configs(file_name, entry[1])
            except IOError:
                pass

        # process config changes for multi value entries
        for entry in multi_value_edits.items():
            file_name = entry[0]
            backed_up_files = _backup_config_file(
                file_name, backup_postfix, backed_up_files)

        # set MultiStrOpt values
            try:
                _set_multi_value_configs(file_name, entry[1])
            except IOError:
                pass

        # upload template files
        for entry in template_files:
            file_name = entry['file']
            template_name = entry['template']
            template_context = entry['context'] if 'context' in entry else {}
            backed_up_files = _backup_config_file(
                file_name, backup_postfix, backed_up_files)

            upload_template(
                template_name,
                file_name,
                context=template_context,
                template_dir=template_dir,
                backup=False)
예제 #5
0
def _configure_service(service_name, backup_postfix, single_value_edits,
                       multi_value_edits, template_dir, template_files):
    """
    Configure a service as defined in the supplied params.
    :param service_name: eg: Nova
    :param single_value_edits: dict of configuration instructions
    :param multi_value_edits: dict of configuration instructions
    :param template_dir: directory on calling host where templates are found
    :param template_files: dict of configuration instructions
    :return:
    """

    backed_up_files = []

    with fab_settings(warn_only=True, user="******"):

        print(green("\nConfiguring %s" % service_name))

        # process config changes for single value entries
        for entry in single_value_edits.items():
            file_name = entry[0]
            backed_up_files = _backup_config_file(file_name, backup_postfix,
                                                  backed_up_files)

            # set StrOpt values
            try:
                _set_single_value_configs(file_name, entry[1])
            except IOError:
                pass

        # process config changes for multi value entries
        for entry in multi_value_edits.items():
            file_name = entry[0]
            backed_up_files = _backup_config_file(file_name, backup_postfix,
                                                  backed_up_files)

            # set MultiStrOpt values
            try:
                _set_multi_value_configs(file_name, entry[1])
            except IOError:
                pass

        # upload template files
        for entry in template_files:
            file_name = entry['file']
            template_name = entry['template']
            template_context = entry['context'] if 'context' in entry else {}
            backed_up_files = _backup_config_file(file_name, backup_postfix,
                                                  backed_up_files)

            upload_template(template_name,
                            file_name,
                            context=template_context,
                            template_dir=template_dir,
                            backup=False)
예제 #6
0
def migrate():
    """ Applies migrations """
    with fab_settings(hide('warnings'), warn_only=True):
        print local('python manage.py migrate')
예제 #7
0
def show():
    """ Shows migrations """
    with fab_settings(hide('warnings'), warn_only=True):
        print local('python manage.py showmigrations')
예제 #8
0
def make():
    """ Makes migrations """
    with fab_settings(hide('warnings'), warn_only=True):
        print local('python manage.py makemigrations')
예제 #9
0
def init():
    """ Makes migrations """
    with fab_settings(hide('warnings'), warn_only=True):
        print local('python manage.py makemigrations %s' %
                    ' '.join(settings.APPS_TO_MIGRATE))
예제 #10
0
def make():
    """ Makes migrations """
    with fab_settings(hide('warnings'), warn_only=True):
        print local('python manage.py makemigrations')
예제 #11
0
파일: db.py 프로젝트: bauzaar/django-zilla
def exists():
    """ Check if DB exists """
    with fab_settings(hide('warnings'), warn_only=True):
        result = local('psql --username=%s --dbname=%s --host=%s --command="\q"'
                       % (DB['USER'], DB['NAME'], DB['HOST']))
    return result.succeeded
예제 #12
0
def configure_stack(goldstone_addr=None, restart_services=None, accept=False,
                    config_loc=PROD_CONFIG):
    """Configures syslog and ceilometer parameters on OpenStack hosts.

    :param goldstone_addr: Goldstone server's hostname or IP accessible to
                           OpenStack hosts
    :type goldstone_addr: str
    :param restart_services: After completion, do you want to restart
                             openstack?
    :type restart_services: boolean
    :param accept: Do you understand that this will change your openstack and
                   syslog configs?
    :type accept: boolean

    """
    import arrow

    if not accept:
        accepted = prompt(cyan(
            "This utility will modify configuration files on the hosts\n"
            "supplied via the -H parameter, and optionally restart\n"
            "OpenStack and syslog services.\n\n"
            "Do you want to continue (yes/no)?"),
            default='yes', validate='yes|no')
    else:
        accepted = 'yes'

    if accepted != 'yes':
        return 0

    if restart_services is None:
        restart_services = prompt(cyan("Restart OpenStack and syslog services "
                                       "after configuration changes(yes/no)?"),
                                  default='yes', validate='yes|no')

    if goldstone_addr is None:
        goldstone_addr = prompt(cyan("Goldstone server's hostname or IP "
                                     "accessible to OpenStack hosts?"))

    backup_timestamp = arrow.utcnow().timestamp

    with fab_settings(warn_only=True, user="******"):

        _configure_rsyslog(
            backup_timestamp,
            goldstone_addr,
            restart=restart_services,
            config_loc=config_loc)

        _configure_ceilometer(
            backup_timestamp,
            goldstone_addr,
            restart=restart_services,
            config_loc=config_loc)

        _configure_nova(
            backup_timestamp,
            restart=restart_services,
            config_loc=config_loc)

        _configure_neutron(
            backup_timestamp,
            restart=restart_services,
            config_loc=config_loc)

        _configure_cinder(
            backup_timestamp,
            restart=restart_services,
            config_loc=config_loc)

        _configure_glance(
            backup_timestamp,
            restart=restart_services,
            config_loc=config_loc)

        _configure_keystone(
            backup_timestamp,
            restart=restart_services,
            config_loc=config_loc)

        print(green("\nFinished"))
예제 #13
0
def migrate():
    """ Applies migrations """
    with fab_settings(hide('warnings'), warn_only=True):
        print local('python manage.py migrate')
예제 #14
0
def show():
    """ Shows migrations """
    with fab_settings(hide('warnings'), warn_only=True):
        print local('python manage.py showmigrations')
예제 #15
0
def commit(message=None):
    """ Add all files in the repo -> commit """
    # local("git add --all .") #  F**K!
    with fab_settings(warn_only=True):
        local("git commit -m '%s'" % message or 'no-msg commit')
예제 #16
0
def configure_stack(goldstone_addr=None,
                    restart_services=None,
                    accept=False,
                    config_loc=PROD_CONFIG):
    """Configures syslog and ceilometer parameters on OpenStack hosts.

    :param goldstone_addr: Goldstone server's hostname or IP accessible to
                           OpenStack hosts
    :type goldstone_addr: str
    :param restart_services: After completion, do you want to restart
                             openstack?
    :type restart_services: boolean
    :param accept: Do you understand that this will change your openstack and
                   syslog configs?
    :type accept: boolean

    """
    import arrow

    if not accept:
        accepted = prompt(cyan(
            "This utility will modify configuration files on the hosts\n"
            "supplied via the -H parameter, and optionally restart\n"
            "OpenStack and syslog services.\n\n"
            "Do you want to continue (yes/no)?"),
                          default='yes',
                          validate='yes|no')
    else:
        accepted = 'yes'

    if accepted != 'yes':
        return 0

    if restart_services is None:
        restart_services = prompt(cyan("Restart OpenStack and syslog services "
                                       "after configuration changes(yes/no)?"),
                                  default='yes',
                                  validate='yes|no')

    if goldstone_addr is None:
        goldstone_addr = prompt(
            cyan("Goldstone server's hostname or IP "
                 "accessible to OpenStack hosts?"))

    backup_timestamp = arrow.utcnow().timestamp

    with fab_settings(warn_only=True, user="******"):

        _configure_rsyslog(backup_timestamp,
                           goldstone_addr,
                           restart=restart_services,
                           config_loc=config_loc)

        _configure_ceilometer(backup_timestamp,
                              goldstone_addr,
                              restart=restart_services,
                              config_loc=config_loc)

        _configure_nova(backup_timestamp,
                        restart=restart_services,
                        config_loc=config_loc)

        _configure_neutron(backup_timestamp,
                           restart=restart_services,
                           config_loc=config_loc)

        _configure_cinder(backup_timestamp,
                          restart=restart_services,
                          config_loc=config_loc)

        _configure_glance(backup_timestamp,
                          restart=restart_services,
                          config_loc=config_loc)

        _configure_keystone(backup_timestamp,
                            restart=restart_services,
                            config_loc=config_loc)

        print(green("\nFinished"))
예제 #17
0
def init():
    """ Makes migrations """
    with fab_settings(hide('warnings'), warn_only=True):
        print local('python manage.py makemigrations %s' % ' '.join(settings.APPS_TO_MIGRATE))