当前位置: 首页>>代码示例>>Python>>正文


Python DeploymentConfig.getBundleServiceDatabasePassword方法代码示例

本文整理汇总了Python中codalabtools.deploy.DeploymentConfig.getBundleServiceDatabasePassword方法的典型用法代码示例。如果您正苦于以下问题:Python DeploymentConfig.getBundleServiceDatabasePassword方法的具体用法?Python DeploymentConfig.getBundleServiceDatabasePassword怎么用?Python DeploymentConfig.getBundleServiceDatabasePassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在codalabtools.deploy.DeploymentConfig的用法示例。


在下文中一共展示了DeploymentConfig.getBundleServiceDatabasePassword方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: install_mysql

# 需要导入模块: from codalabtools.deploy import DeploymentConfig [as 别名]
# 或者: from codalabtools.deploy.DeploymentConfig import getBundleServiceDatabasePassword [as 别名]
def install_mysql(choice="all"):
    """
    Installs a local instance of MySQL of the web instance. This will only work
    if the number of web instances is one.

    choice: Indicates which assets to create/install:
        'mysql'      -> just install MySQL; don't create the databases
        'site_db'    -> just create the site database
        'bundles_db' -> just create the bundle service database
        'all' or ''  -> install all three
    """
    require("configuration")
    if len(env.roledefs["web"]) != 1:
        raise Exception("Task install_mysql requires exactly one web instance.")

    if choice == "mysql":
        choices = {"mysql"}
    elif choice == "site_db":
        choices = {"site_db"}
    elif choice == "bundles_db":
        choices = {"bundles_db"}
    elif choice == "all":
        choices = {"mysql", "site_db", "bundles_db"}
    else:
        raise ValueError("Invalid choice: %s. Valid choices are: 'build', 'web' or 'all'." % (choice))

    configuration = DeploymentConfig(env.cfg_label, env.cfg_path)
    dba_password = configuration.getDatabaseAdminPassword()

    if "mysql" in choices:
        sudo("DEBIAN_FRONTEND=noninteractive apt-get -q -y install mysql-server")
        sudo("mysqladmin -u root password {0}".format(dba_password))

    if "site_db" in choices:
        db_name = configuration.getDatabaseName()
        db_user = configuration.getDatabaseUser()
        db_password = configuration.getDatabasePassword()
        cmds = [
            "create database {0};".format(db_name),
            "create user '{0}'@'localhost' IDENTIFIED BY '{1}';".format(db_user, db_password),
            "GRANT ALL PRIVILEGES ON {0}.* TO '{1}'@'localhost' WITH GRANT OPTION;".format(db_name, db_user),
        ]
        run('mysql --user=root --password={0} --execute="{1}"'.format(dba_password, " ".join(cmds)))

    if "bundles_db" in choices:
        db_name = configuration.getBundleServiceDatabaseName()
        db_user = configuration.getBundleServiceDatabaseUser()
        db_password = configuration.getBundleServiceDatabasePassword()
        cmds = [
            "create database {0};".format(db_name),
            "create user '{0}'@'localhost' IDENTIFIED BY '{1}';".format(db_user, db_password),
            "GRANT ALL PRIVILEGES ON {0}.* TO '{1}'@'localhost' WITH GRANT OPTION;".format(db_name, db_user),
        ]
        run('mysql --user=root --password={0} --execute="{1}"'.format(dba_password, " ".join(cmds)))
开发者ID:javierluraschi,项目名称:codalab,代码行数:56,代码来源:fabfile.py


注:本文中的codalabtools.deploy.DeploymentConfig.getBundleServiceDatabasePassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。