def Run(self, args):
        """Displays configuration and metadata about a Cloud SQL instance.

    Information such as instance name, IP address, region, the CA certificate
    and configuration settings will be displayed.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      A dict object representing the instance resource if fetching the instance
      was successful.
    Raises:
      HttpException: A http error response was received while executing api
          request.
    ResourceNotFoundError: The SQL instance was not found.
    """
        client = api_util.SqlClient(api_util.API_VERSION_DEFAULT)
        sql_client = client.sql_client
        sql_messages = client.sql_messages

        validate.ValidateInstanceName(args.instance)
        instance_ref = client.resource_parser.Parse(
            args.instance,
            params={'project': properties.VALUES.core.project.GetOrFail},
            collection='sql.instances')

        try:
            instance = sql_client.instances.Get(
                sql_messages.SqlInstancesGetRequest(
                    project=instance_ref.project,
                    instance=instance_ref.instance))
            instance.state = instance_api_util.GetInstanceState(instance)
            # TODO(b/122660263): Remove when V1 instances are no longer supported.
            if instance_api_util.IsInstanceV1(instance):
                instance_command_util.ShowV1DeprecationWarning()
            return instance
        except apitools_exceptions.HttpError as error:
            if error.status_code == six.moves.http_client.FORBIDDEN:
                raise exceptions.ResourceNotFoundError(
                    'There was no instance found at {} or you are not authorized to '
                    'access it.'.format(instance_ref.RelativeName()))
            raise calliope_exceptions.HttpException(error)
def RunBasePatchCommand(args, release_track):
    """Updates settings of a Cloud SQL instance using the patch api method.

  Args:
    args: argparse.Namespace, The arguments that this command was invoked with.
    release_track: base.ReleaseTrack, the release track that this was run under.

  Returns:
    A dict object representing the operations resource describing the patch
    operation if the patch was successful.
  Raises:
    CancelledError: The user chose not to continue.
  """
    if args.diff and not args.IsSpecified('format'):
        args.format = 'diff(old, new)'

    client = common_api_util.SqlClient(common_api_util.API_VERSION_DEFAULT)
    sql_client = client.sql_client
    sql_messages = client.sql_messages

    validate.ValidateInstanceName(args.instance)
    instance_ref = client.resource_parser.Parse(
        args.instance,
        params={'project': properties.VALUES.core.project.GetOrFail},
        collection='sql.instances')

    # If --authorized-networks is used, confirm that the user knows the networks
    # will get overwritten.
    if args.authorized_networks:
        api_util.InstancesV1Beta4.PrintAndConfirmAuthorizedNetworksOverwrite()

    original_instance_resource = sql_client.instances.Get(
        sql_messages.SqlInstancesGetRequest(project=instance_ref.project,
                                            instance=instance_ref.instance))

    patch_instance = command_util.InstancesV1Beta4.ConstructPatchInstanceFromArgs(
        sql_messages,
        args,
        original=original_instance_resource,
        release_track=release_track)
    patch_instance.project = instance_ref.project
    patch_instance.name = instance_ref.instance

    # TODO(b/122660263): Remove when V1 instances are no longer supported.
    # V1 deprecation notice.
    if api_util.IsInstanceV1(sql_messages, original_instance_resource):
        command_util.ShowV1DeprecationWarning()

    cleared_fields = _GetConfirmedClearedFields(args, patch_instance,
                                                original_instance_resource)
    # beta only
    if args.maintenance_window_any:
        cleared_fields.append('settings.maintenanceWindow')

    with sql_client.IncludeFields(cleared_fields):
        result_operation = sql_client.instances.Patch(
            sql_messages.SqlInstancesPatchRequest(
                databaseInstance=patch_instance,
                project=instance_ref.project,
                instance=instance_ref.instance))

    operation_ref = client.resource_parser.Create(
        'sql.operations',
        operation=result_operation.name,
        project=instance_ref.project)

    if args.async_:
        return sql_client.operations.Get(
            sql_messages.SqlOperationsGetRequest(
                project=operation_ref.project,
                operation=operation_ref.operation))

    operations.OperationsV1Beta4.WaitForOperation(
        sql_client, operation_ref, 'Patching Cloud SQL instance')

    log.UpdatedResource(instance_ref)

    changed_instance_resource = sql_client.instances.Get(
        sql_messages.SqlInstancesGetRequest(project=instance_ref.project,
                                            instance=instance_ref.instance))
    return _Result(changed_instance_resource, original_instance_resource)