def Prepare(self, vm):
    # TODO: Refactor the GCP Cloud SQL instance creation and deletion logic out
    # to a new class called GCPCloudSQLInstance that Inherits from
    # perfkitbenchmarker.resource.BaseResource.

    logging.info('Preparing MySQL Service benchmarks for Google Cloud SQL.')

    vm.db_instance_name = 'pkb%s' % FLAGS.run_uri
    db_tier = 'db-n1-standard-%s' % FLAGS.mysql_svc_db_instance_cores
    # Currently, we create DB instance in the same zone as the test VM.
    db_instance_zone = vm.zone
    # Currently GCP REQUIRES you to connect to the DB instance via external IP
    # (i.e., using external IPs of the DB instance AND the VM instance).
    authorized_network = '%s/32' % vm.ip_address
    create_db_cmd = [FLAGS.gcloud_path,
                     'sql',
                     'instances',
                     'create', vm.db_instance_name,
                     '--quiet',
                     '--format=json',
                     '--async',
                     '--activation-policy=ALWAYS',
                     '--assign-ip',
                     '--authorized-networks=%s' % authorized_network,
                     '--backup-start-time=%s' % DEFAULT_BACKUP_START_TIME,
                     '--enable-bin-log',
                     '--tier=%s' % db_tier,
                     '--gce-zone=%s' % db_instance_zone,
                     '--database-version=%s' % GCP_MY_SQL_VERSION,
                     '--pricing-plan=%s' % GCP_PRICING_PLAN]

    stdout, _, _ = vm_util.IssueCommand(create_db_cmd)
    response = json.loads(stdout)
    if response['operation'] is None or response['operationType'] != 'CREATE':
      raise DBStatusQueryError('Invalid operation or unrecognized '
                               'operationType in DB creation response. '
                               ' stdout is %s' % stdout)

    status_query_cmd = [FLAGS.gcloud_path,
                        'sql',
                        'instances',
                        'describe', vm.db_instance_name,
                        '--format', 'json']

    stdout, _, _ = vm_util.IssueCommand(status_query_cmd)
    response = json.loads(stdout)

    query_count = 1
    while True:
      state = response['state']
      if state is None:
        raise ValueError('Cannot parse response from status query command. '
                         'The state is missing. stdout is %s' % stdout)

      if state == 'RUNNABLE':
        break
      else:
        if query_count > DB_STATUS_QUERY_LIMIT:
          raise DBStatusQueryError('DB creation timed-out, we have '
                                   'waited at least %s * %s seconds.' % (
                                       DB_STATUS_QUERY_INTERVAL,
                                       DB_STATUS_QUERY_LIMIT))

        logging.info('Querying db creation status, current state is %s, query '
                     'count is %d', state, query_count)
        time.sleep(DB_STATUS_QUERY_INTERVAL)

        stdout, _, _ = vm_util.IssueCommand(status_query_cmd)
        response = json.loads(stdout)
        query_count += 1

    logging.info('Successfully created the DB instance. Complete response is '
                 '%s', response)

    vm.db_instance_address = response['ipAddresses'][0]['ipAddress']
    logging.info('DB IP address is: %s', vm.db_instance_address)

    # Set the root password to a common one that can be referred to in common
    # code across providers.
    vm.db_instance_master_user = MYSQL_ROOT_USER
    vm.db_instance_master_password = _GenerateRandomPassword()
    set_password_cmd = [FLAGS.gcloud_path,
                        'sql',
                        'instances',
                        'set-root-password',
                        vm.db_instance_name,
                        '--password', vm.db_instance_master_password]
    stdout, stderr, _ = vm_util.IssueCommand(set_password_cmd)
    logging.info('Set root password completed. Stdout:\n%s\nStderr:\n%s',
                 stdout, stderr)
Prepares the DB and everything for the provider GCP (Cloud SQL)
dataset/ETHPy150Open GoogleCloudPlatform/PerfKitBenchmarker/perfkitbenchmarker/linux_benchmarks/mysql_service_benchmark.py/GoogleCloudSQLBenchmark.Prepare