Skip to content

Commit

Permalink
Update Azure SqlServer databases with a generic name, which can be re…
Browse files Browse the repository at this point in the history
…named.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=300583536
  • Loading branch information
NathanTeeuwen authored and bvliu committed Mar 12, 2020
1 parent bdd046c commit d17bffd
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion perfkitbenchmarker/providers/azure/azure_relational_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from perfkitbenchmarker.providers.azure import azure_network
from perfkitbenchmarker.providers.azure import util

DEFAULT_DATABASE_NAME = 'database'

FLAGS = flags.FLAGS

DEFAULT_MYSQL_VERSION = '5.7'
Expand Down Expand Up @@ -144,6 +146,30 @@ def GetAzCommandForEngine(self):
raise relational_db.RelationalDbEngineNotFoundException(
'Unsupported engine {0}'.format(engine))

def RenameDatabase(self, new_name):
"""Renames an the database instace."""
engine = self.spec.engine
if engine == relational_db.SQLSERVER:
cmd = [
azure.AZURE_PATH,
self.GetAzCommandForEngine(),
'db',
'rename',
'--resource-group',
self.resource_group.name,
'--server',
self.instance_id,
'--name',
self.database_name,
'--new-name',
new_name
]
vm_util.IssueCommand(cmd)
self.database_name = new_name
else:
raise relational_db.RelationalDbEngineNotFoundException(
'Unsupported engine {0}'.format(engine))

def _ApplyManagedMysqlFlags(self):
"""Applies the MySqlFlags to a managed instance."""
for flag in FLAGS.mysql_flags:
Expand Down Expand Up @@ -230,7 +256,7 @@ def _CreateSqlServerInstance(self):
'--server',
self.instance_id,
'--name',
'tpcc',
DEFAULT_DATABASE_NAME,
'--edition',
self.spec.db_spec.tier,
'--capacity',
Expand All @@ -239,6 +265,7 @@ def _CreateSqlServerInstance(self):
'true' if self.spec.high_availability else 'false'
]
vm_util.IssueCommand(cmd)
self.database_name = DEFAULT_DATABASE_NAME

def _CreateAzureManagedSqlInstance(self):
"""Creates an Azure Sql Instance from a managed service."""
Expand Down

0 comments on commit d17bffd

Please sign in to comment.