
from fabric.api import task, run

def _generate_password():
    import string
    from random import sample
    chars = string.letters + string.digits
    return ''.join(sample(chars, 8))


def create_mysql_instance(mysql_user, mysql_password, instance_code):
    user = instance_code
    password = _generate_password()
    cmd = "/usr/bin/mysql -h localhost -u '%s' '--password=%s' -P %s -e \"create database %s; grant all on %s.* to '%s'@'%%' identified by '%s'\"" % (
        mysql_user, mysql_password, 3306,
        user, user, user, password,)
    return run(cmd)



# Local Variables: **
# comment-column: 56 **
# indent-tabs-mode: nil **
# python-indent: 4 **
# End: **


from fabric.api import run

def _generate_password():
    import string
    from random import sample
    chars = string.letters + string.digits
    return ''.join(sample(chars, 8))


def create_mysql_instance(mysql_user, mysql_password, instance_code):
    user = instance_code
    password = _generate_password()
    cmd_create_database = "/usr/bin/mysql -h localhost -u '%s' '--password=%s' -P %s -e \"create database %s;\"" % (
        mysql_user, mysql_password, 3306,
        user,)
    cmd_create_user = "/usr/bin/mysql -h localhost -u '%s' '--password=%s' -P %s -e \"grant all on %s.* to '%s'@'%%' identified by '%s';\"" % (
        mysql_user, mysql_password, 3306,
        user, user, password,)

    run(cmd_create_database)
    run(cmd_create_user)



# Local Variables: **
# comment-column: 56 **
# indent-tabs-mode: nil **
# python-indent: 4 **
# End: **

Split create database and create user into to individual commands
Split create database and create user into to individual commands

  
- from fabric.api import task, run
+ from fabric.api import run
  
  def _generate_password():
      import string
      from random import sample
      chars = string.letters + string.digits
      return ''.join(sample(chars, 8))
  
  
  def create_mysql_instance(mysql_user, mysql_password, instance_code):
      user = instance_code
      password = _generate_password()
-     cmd = "/usr/bin/mysql -h localhost -u '%s' '--password=%s' -P %s -e \"create database %s; grant all on %s.* to '%s'@'%%' identified by '%s'\"" % (
+     cmd_create_database = "/usr/bin/mysql -h localhost -u '%s' '--password=%s' -P %s -e \"create database %s;\"" % (
          mysql_user, mysql_password, 3306,
+         user,)
+     cmd_create_user = "/usr/bin/mysql -h localhost -u '%s' '--password=%s' -P %s -e \"grant all on %s.* to '%s'@'%%' identified by '%s';\"" % (
+         mysql_user, mysql_password, 3306,
-         user, user, user, password,)
+         user, user, password,)
-     return run(cmd)
+ 
+     run(cmd_create_database)
+     run(cmd_create_user)
  
  
  
  # Local Variables: **
  # comment-column: 56 **
  # indent-tabs-mode: nil **
  # python-indent: 4 **
  # End: **
  
Split create database and create user into to individual commands
## Code Before:

from fabric.api import task, run

def _generate_password():
    import string
    from random import sample
    chars = string.letters + string.digits
    return ''.join(sample(chars, 8))


def create_mysql_instance(mysql_user, mysql_password, instance_code):
    user = instance_code
    password = _generate_password()
    cmd = "/usr/bin/mysql -h localhost -u '%s' '--password=%s' -P %s -e \"create database %s; grant all on %s.* to '%s'@'%%' identified by '%s'\"" % (
        mysql_user, mysql_password, 3306,
        user, user, user, password,)
    return run(cmd)



# Local Variables: **
# comment-column: 56 **
# indent-tabs-mode: nil **
# python-indent: 4 **
# End: **

## Instruction:
Split create database and create user into to individual commands
## Code After:

from fabric.api import run

def _generate_password():
    import string
    from random import sample
    chars = string.letters + string.digits
    return ''.join(sample(chars, 8))


def create_mysql_instance(mysql_user, mysql_password, instance_code):
    user = instance_code
    password = _generate_password()
    cmd_create_database = "/usr/bin/mysql -h localhost -u '%s' '--password=%s' -P %s -e \"create database %s;\"" % (
        mysql_user, mysql_password, 3306,
        user,)
    cmd_create_user = "/usr/bin/mysql -h localhost -u '%s' '--password=%s' -P %s -e \"grant all on %s.* to '%s'@'%%' identified by '%s';\"" % (
        mysql_user, mysql_password, 3306,
        user, user, password,)

    run(cmd_create_database)
    run(cmd_create_user)



# Local Variables: **
# comment-column: 56 **
# indent-tabs-mode: nil **
# python-indent: 4 **
# End: **
