in mds_plugin/mysql_database_service.py [0:0]
def update_db_system(**kwargs):
"""Updates the DbSystem with the given id
If no id is given, it will prompt the user for the id.
Args:
**kwargs: Optional parameters
Keyword Args:
db_system_name (str): The name of the DB System.
db_system_id (str): OCID of the DbSystem.
ignore_current (bool): Whether to not default to the current bastion.
new_name (str): The new name
new_description (str): The new description
new_freeform_tags (str): The new freeform_tags formatted as string
compartment_id (str): OCID of the parent compartment
config (dict): An OCI config object or None
config_profile (str): The name of an OCI config profile
interactive (bool): Indicates whether to execute in interactive mode
raise_exceptions (bool): If true exceptions are raised
Returns:
None
"""
db_system_name = kwargs.get("db_system_name")
db_system_id = kwargs.get("db_system_id")
ignore_current = kwargs.get("ignore_current", False)
new_name = kwargs.get("new_name")
new_description = kwargs.get("new_description")
new_freeform_tags = kwargs.get("new_freeform_tags")
compartment_id = kwargs.get("compartment_id")
config = kwargs.get("config")
config_profile = kwargs.get("config_profile")
interactive = kwargs.get("interactive", core.get_interactive_default())
raise_exceptions = kwargs.get("raise_exceptions", not interactive)
# Get the active config and compartment
try:
config = configuration.get_current_config(
config=config, config_profile=config_profile,
interactive=interactive)
compartment_id = configuration.get_current_compartment_id(
compartment_id=compartment_id, config=config)
current_db_system_id = configuration.get_current_db_system_id(
config=config)
if (not ignore_current and db_system_name is None
and db_system_id is None and current_db_system_id):
db_system_id = current_db_system_id
import oci.identity
import oci.mysql
import mysqlsh
import json
try:
# Get the db_system based on input params
db_system = get_db_system(
db_system_name=db_system_name, db_system_id=db_system_id,
compartment_id=compartment_id, config=config,
interactive=interactive, raise_exceptions=True,
return_python_object=True)
if db_system is None:
if db_system_name or db_system_id:
raise ValueError("DB System not found.")
else:
raise Exception("Cancelling operation.")
if not new_name and interactive:
# Prompt the user for the new values
new_name = mysqlsh.globals.shell.prompt(
f"Please enter a new name for the DbSystem "
f"[{db_system.display_name}]: ",
{'defaultValue': db_system.display_name}).strip()
if not new_description and interactive:
new_description = mysqlsh.globals.shell.prompt(
"Please enter a new description for the DbSystem "
"[current description]: ",
{'defaultValue': db_system.description
if db_system.description is not None else ''}).strip()
if not new_freeform_tags and interactive:
new_freeform_tags = mysqlsh.globals.shell.prompt(
f"Please enter new freeform_tags for the DbSystem "
f"[{str(db_system.freeform_tags)}]: ",
{'defaultValue': json.dumps(db_system.freeform_tags)
if db_system.freeform_tags is not None else ''}).strip()
if new_freeform_tags and isinstance(new_freeform_tags, str):
new_freeform_tags = json.loads(new_freeform_tags)
if not new_name and not new_freeform_tags and not new_freeform_tags:
raise ValueError("Nothing to update.")
# Initialize the DbSystem client
db_sys = core.get_oci_db_system_client(config=config)
update_details = oci.mysql.models.UpdateDbSystemDetails(
display_name=new_name,
description=new_description,
freeform_tags=new_freeform_tags
)
db_sys.update_db_system(db_system.id, update_details)
if interactive:
print(f"DbSystem {db_system.display_name} is being updated.")
except oci.exceptions.ServiceError as e:
if raise_exceptions:
raise
print(f'ERROR: {e.message}. (Code: {e.code}; Status: {e.status})')
except (ValueError, oci.exceptions.ClientError) as e:
if raise_exceptions:
raise
print(f'ERROR: {e}')