def Args(parser): """Args is called by calliope to gather arguments for this command. Args: parser: An argparse parser that you can use to add arguments that go on the command line after this command. Positional arguments are allowed. """ base.ASYNC_FLAG.AddToParser(parser) parser.add_argument('instance', type=validate.InstanceNameRegexpValidator(), completion_resource='sql.instances', help='Cloud SQL instance ID.') password_group = parser.add_mutually_exclusive_group(required=True) password_group.add_argument( '--password', '-p', help= 'The password for the root user. WARNING: Setting password using ' 'this option can potentially expose the password to other users ' 'of this machine. Instead, you can use --password-file to get the' ' password from a file.') password_group.add_argument( '--password-file', help= 'The path to the filename which has the password to be set. The ' 'first line of the file will be interpreted as the password to be set.' ) password_group.add_argument( '--prompt-for-password', action='store_true', help=( 'Prompt for the Cloud SQL user\'s password with character echo ' 'disabled. The password is all typed characters up to but not ' 'including the RETURN or ENTER key.'))
def AddBaseArgs(parser): """Declare flag and positional arguments for this command parser.""" # TODO(b/35705305): move common flags to command_lib.sql.flags base.ASYNC_FLAG.AddToParser(parser) parser.display_info.AddFormat(flags.GetInstanceListFormat()) flags.AddActivationPolicy(parser) flags.AddAssignIp(parser) flags.AddAuthorizedGAEApps(parser) flags.AddAuthorizedNetworks(parser) flags.AddAvailabilityType(parser) parser.add_argument('--backup', required=False, action='store_true', default=True, help='Enables daily backup.') flags.AddBackupStartTime(parser) flags.AddCPU(parser) flags.AddDatabaseFlags(parser) flags.AddEnableBinLog(parser, show_negated_in_help=False) parser.add_argument( '--failover-replica-name', required=False, help='Also create a failover replica with the specified name.') parser.add_argument( '--follow-gae-app', required=False, help=('First Generation instances only. The App Engine app this ' 'instance should follow. It must be in the same region as ' 'the instance.')) parser.add_argument('instance', type=command_validate.InstanceNameRegexpValidator(), help='Cloud SQL instance ID.') flags.AddMaintenanceReleaseChannel(parser) flags.AddMaintenanceWindowDay(parser) flags.AddMaintenanceWindowHour(parser) parser.add_argument( '--main-instance-name', required=False, help=('Name of the instance which will act as main in the ' 'replication setup. The newly created instance will be a read ' 'replica of the specified main instance.')) flags.AddMemory(parser) parser.add_argument( '--pricing-plan', '-p', required=False, choices=['PER_USE', 'PACKAGE'], default='PER_USE', help=('First Generation instances only. The pricing plan for this ' 'instance.')) # TODO(b/31989340): add remote completion # TODO(b/73362371): Make specifying a location required. location_group = parser.add_mutually_exclusive_group() location_group.add_argument( '--region', required=False, default='us-central', help=('Regional location (e.g. asia-east1, us-east1). See the full ' 'list of regions at ' 'https://cloud.google.com/sql/docs/instance-locations.')) flags.AddZone( location_group, help_text=('Preferred Compute Engine zone (e.g. us-central1-a, ' 'us-central1-b, etc.).')) parser.add_argument('--replica-type', choices=['READ', 'FAILOVER'], help='The type of replica to create.') flags.AddReplication(parser) parser.add_argument( '--require-ssl', required=False, action='store_true', default=None, help='Specified if users connecting over IP must use SSL.') flags.AddRootPassword(parser) flags.AddStorageAutoIncrease(parser) flags.AddStorageSize(parser) parser.add_argument( '--storage-type', required=False, choices=['SSD', 'HDD'], default=None, help='The storage type for the instance. The default is SSD.') flags.AddTier(parser)
def AddBaseArgs(parser): """Declare flag and positional arguments for this command parser.""" # TODO(b/35705305): move common flags to command_lib.sql.flags base.ASYNC_FLAG.AddToParser(parser) parser.display_info.AddFormat(flags.INSTANCES_FORMAT_BETA) flags.AddActivationPolicy(parser) flags.AddAssignIp(parser) flags.AddAuthorizedGAEApps(parser) flags.AddAuthorizedNetworks(parser) parser.add_argument( '--backup', required=False, action='store_true', default=True, help='Enables daily backup.') flags.AddBackupStartTime(parser) flags.AddCPU(parser) flags.AddDatabaseFlags(parser) parser.add_argument( '--database-version', required=False, default='MYSQL_5_6', choices=['MYSQL_5_5', 'MYSQL_5_6', 'MYSQL_5_7', 'POSTGRES_9_6'], help='The database engine type and version.') flags.AddEnableBinLog(parser) parser.add_argument( '--failover-replica-name', required=False, help='Also create a failover replica with the specified name.') parser.add_argument( '--follow-gae-app', required=False, help=('First Generation instances only. The App Engine app this ' 'instance should follow. It must be in the same region as ' 'the instance.')) parser.add_argument( '--gce-zone', required=False, help=('The preferred Compute Engine zone (e.g. us-central1-a, ' 'us-central1-b, etc.).')) parser.add_argument( 'instance', type=command_validate.InstanceNameRegexpValidator(), help='Cloud SQL instance ID.') flags.AddMaintenanceReleaseChannel(parser) flags.AddMaintenanceWindowDay(parser) flags.AddMaintenanceWindowHour(parser) parser.add_argument( '--master-instance-name', required=False, help=('Name of the instance which will act as master in the ' 'replication setup. The newly created instance will be a read ' 'replica of the specified master instance.')) flags.AddMemory(parser) parser.add_argument( '--on-premises-host-port', required=False, help=argparse.SUPPRESS) parser.add_argument( '--pricing-plan', '-p', required=False, choices=['PER_USE', 'PACKAGE'], default='PER_USE', help=('First Generation instances only. The pricing plan for this ' 'instance.')) # TODO(b/31989340): add remote completion parser.add_argument( '--region', required=False, default='us-central', help=('The regional location (e.g. asia-east1, us-east1). See the full ' 'list of regions at ' 'https://cloud.google.com/sql/docs/instance-locations.')) parser.add_argument( '--replica-type', choices=['READ', 'FAILOVER'], help='The type of replica to create.') flags.AddReplication(parser) parser.add_argument( '--require-ssl', required=False, action='store_true', default=None, # Tri-valued: None => don't change the setting. help='Specified if users connecting over IP must use SSL.') flags.AddStorageAutoIncrease(parser) flags.AddStorageSize(parser) parser.add_argument( '--storage-type', required=False, choices=['SSD', 'HDD'], default=None, help='The storage type for the instance.') parser.add_argument( '--tier', '-t', required=False, help=('The tier for this instance. For Second Generation instances, ' 'TIER is the instance\'s machine type (e.g., db-n1-standard-1). ' 'For PostgreSQL instances, only shared-core machine types ' '(e.g., db-f1-micro) apply. A complete list of tiers is ' 'available here: https://cloud.google.com/sql/pricing.'))
def testShowHelpfulMessageForColon(self): validator = validate.InstanceNameRegexpValidator() with self.assertRaises(exceptions.ToolException): validator("my-project:instance-name")
def Args(cls, parser): """Declare flag and positional arguments for this command parser.""" # TODO(b/35705305): move common flags to command_lib.sql.flags base.ASYNC_FLAG.AddToParser(parser) parser.add_argument( '--activation-policy', required=False, choices=['ALWAYS', 'NEVER', 'ON_DEMAND'], default=None, help= 'The activation policy for this instance. This specifies when the ' 'instance should be activated and is applicable only when the ' 'instance state is RUNNABLE. More information on activation policies ' 'can be found here: https://cloud.google.com/sql/faq#activation_policy' ) parser.add_argument( '--assign-ip', required=False, action='store_true', default=None, # Tri-valued: None => don't change the setting. help='Specified if the instance must be assigned an IP address.') parser.add_argument( '--authorized-gae-apps', type=arg_parsers.ArgList(min_length=1), metavar='APP', required=False, default=[], help='List of App Engine app IDs that can access this instance.') parser.add_argument( '--authorized-networks', type=arg_parsers.ArgList(min_length=1), metavar='NETWORK', required=False, default=[], help= 'The list of external networks that are allowed to connect to the' ' instance. Specified in CIDR notation, also known as \'slash\' ' 'notation (e.g. 192.168.100.0/24).') parser.add_argument( '--backup-start-time', required=False, help= 'The start time of daily backups, specified in the 24 hour format ' '- HH:MM, in the UTC timezone.') parser.add_argument('--backup', required=False, action='store_true', default=True, help='Enables daily backup.') parser.add_argument( '--database-version', required=False, default='MYSQL_5_6', help='The database engine type and version. Can be MYSQL_5_5, ' 'MYSQL_5_6, or MYSQL_5_7.') parser.add_argument( '--enable-bin-log', required=False, action='store_true', default=None, # Tri-valued: None => don't change the setting. help='Specified if binary log should be enabled. If backup ' 'configuration is disabled, binary log must be disabled as well.') parser.add_argument( '--follow-gae-app', required=False, help='The App Engine app this instance should follow. It must be in ' 'the same region as the instance.') parser.add_argument( '--gce-zone', required=False, help='The preferred Compute Engine zone (e.g. us-central1-a, ' 'us-central1-b, etc.).') parser.add_argument( 'instance', type=command_validate.InstanceNameRegexpValidator(), help='Cloud SQL instance ID.') parser.add_argument( '--master-instance-name', required=False, help= 'Name of the instance which will act as master in the replication ' 'setup. The newly created instance will be a read replica of the ' 'specified master instance.') parser.add_argument('--on-premises-host-port', required=False, help=argparse.SUPPRESS) parser.add_argument('--pricing-plan', '-p', required=False, choices=['PER_USE', 'PACKAGE'], default='PER_USE', help='The pricing plan for this instance.') # TODO(b/31989340): add remote completion parser.add_argument( '--region', required=False, default='us-central', help='The regional location ' '(e.g. asia-east1, us-east1). See the full list of regions at ' 'https://cloud.google.com/sql/docs/instance-locations.') parser.add_argument('--replication', required=False, choices=['SYNCHRONOUS', 'ASYNCHRONOUS'], default=None, help='The type of replication this instance uses.') parser.add_argument( '--require-ssl', required=False, action='store_true', default=None, # Tri-valued: None => don't change the setting. help='Specified if users connecting over IP must use SSL.') parser.add_argument( '--tier', '-t', required=False, help= 'The tier for first generation Cloud SQL instances, for example ' ' D0, D1, D2. A complete list of tiers is available here: ' 'https://cloud.google.com/sql/pricing#packages') parser.add_argument( '--database-flags', type=arg_parsers.ArgDict(min_length=1), metavar='FLAG=VALUE', required=False, help= 'A comma-separated list of database flags to set on the instance. ' 'Use an equals sign to separate flag name and value. Flags without ' 'values, like skip_grant_tables, can be written out without a value ' 'after, e.g., `skip_grant_tables=`. Use on/off for ' 'booleans. View the Instance Resource API for allowed flags. ' '(e.g., `--database-flags max_allowed_packet=55555,skip_grant_tables=,' 'log_output=1`)')
def testRegexpAcceptsGoodChars(self): validator = validate.InstanceNameRegexpValidator() validator("valid-instance5")
def testRegexpRejectsBadChars(self): validator = validate.InstanceNameRegexpValidator() with self.assertRaises(arg_parsers.ArgumentTypeError): validator("INVALID_CHARS")
def AddBaseArgs(parser, is_alpha=False): """Declare flag and positional arguments for this command parser.""" # TODO(b/35705305): move common flags to command_lib.sql.flags base.ASYNC_FLAG.AddToParser(parser) parser.display_info.AddFormat(flags.GetInstanceListFormat()) flags.AddActivationPolicy(parser) flags.AddActiveDirectoryDomain(parser) flags.AddAssignIp(parser) flags.AddAuthorizedNetworks(parser) flags.AddAvailabilityType(parser) parser.add_argument( '--backup', required=False, action='store_true', default=True, help='Enables daily backup.') flags.AddBackupStartTime(parser) flags.AddBackupLocation(parser, allow_empty=False) flags.AddCPU(parser) flags.AddInstanceCollation(parser) flags.AddDatabaseFlags(parser) flags.AddEnableBinLog(parser, show_negated_in_help=False) flags.AddRetainedBackupsCount(parser) flags.AddRetainedTransactionLogDays(parser) parser.add_argument( '--failover-replica-name', required=False, help='Also create a failover replica with the specified name.') parser.add_argument( 'instance', type=command_validate.InstanceNameRegexpValidator(), help='Cloud SQL instance ID.') flags.AddMaintenanceReleaseChannel(parser) flags.AddMaintenanceWindowDay(parser) flags.AddMaintenanceWindowHour(parser) flags.AddDenyMaintenancePeriodStartDate(parser) flags.AddDenyMaintenancePeriodEndDate(parser) flags.AddDenyMaintenancePeriodTime(parser) flags.AddInsightsConfigQueryInsightsEnabled(parser, show_negated_in_help=True) flags.AddInsightsConfigQueryStringLength(parser) flags.AddInsightsConfigRecordApplicationTags( parser, show_negated_in_help=True) flags.AddInsightsConfigRecordClientAddress(parser, show_negated_in_help=True) flags.AddInsightsConfigQueryPlansPerMinute(parser) parser.add_argument( '--master-instance-name', required=False, help=('Name of the instance which will act as master in the ' 'replication setup. The newly created instance will be a read ' 'replica of the specified master instance.')) flags.AddMemory(parser) flags.AddPasswordPolicyMinLength(parser) flags.AddPasswordPolicyComplexity(parser) flags.AddPasswordPolicyReuseInterval(parser) flags.AddPasswordPolicyDisallowUsernameSubstring(parser) flags.AddPasswordPolicyPasswordChangeInterval(parser) flags.AddPasswordPolicyEnablePasswordPolicy(parser) parser.add_argument( '--replica-type', choices=['READ', 'FAILOVER'], help='The type of replica to create.') flags.AddReplication(parser) parser.add_argument( '--require-ssl', required=False, action='store_true', default=None, help='Specified if users connecting over IP must use SSL.') flags.AddRootPassword(parser) flags.AddStorageAutoIncrease(parser) flags.AddStorageSize(parser) parser.add_argument( '--storage-type', required=False, choices=['SSD', 'HDD'], default=None, help='The storage type for the instance. The default is SSD.') flags.AddTier(parser, is_alpha=is_alpha) kms_flag_overrides = { 'kms-key': '--disk-encryption-key', 'kms-keyring': '--disk-encryption-key-keyring', 'kms-location': '--disk-encryption-key-location', 'kms-project': '--disk-encryption-key-project' } kms_resource_args.AddKmsKeyResourceArg( parser, 'instance', flag_overrides=kms_flag_overrides) flags.AddEnablePointInTimeRecovery(parser) flags.AddNetwork(parser)
def AddBaseArgs(parser): """Declare flag and positional arguments for this command parser.""" # TODO(b/35705305): move common flags to command_lib.sql.flags base.ASYNC_FLAG.AddToParser(parser) parser.display_info.AddFormat(flags.INSTANCES_FORMAT_BETA) parser.add_argument( '--activation-policy', required=False, choices=['ALWAYS', 'NEVER', 'ON_DEMAND'], default=None, help=('The activation policy for this instance. This specifies when ' 'the instance should be activated and is applicable only when ' 'the instance state is RUNNABLE. More information on activation ' 'policies can be found here: ' 'https://cloud.google.com/sql/faq#activation_policy')) parser.add_argument( '--assign-ip', required=False, action='store_true', default=None, # Tri-valued: None => don't change the setting. help='Specified if the instance must be assigned an IP address.') parser.add_argument( '--authorized-gae-apps', type=arg_parsers.ArgList(min_length=1), metavar='APP', required=False, default=[], help=('First Generation instances only. List of IDs for App Engine ' 'applications running in the Standard environment that can ' 'access this instance.')) parser.add_argument( '--authorized-networks', type=arg_parsers.ArgList(min_length=1), metavar='NETWORK', required=False, default=[], help=('The list of external networks that are allowed to connect to ' 'the instance. Specified in CIDR notation, also known as ' '\'slash\' notation (e.g. 192.168.100.0/24).')) parser.add_argument('--backup', required=False, action='store_true', default=True, help='Enables daily backup.') parser.add_argument( '--backup-start-time', required=False, help=('The start time of daily backups, specified in the 24 hour ' 'format - HH:MM, in the UTC timezone.')) parser.add_argument( '--cpu', type=int, required=False, help=('A whole number value indicating how many cores are desired in ' 'the machine. Both --cpu and --memory must be specified if a ' 'custom machine type is desired, and the --tier flag must be ' 'omitted.')) parser.add_argument( '--database-flags', type=arg_parsers.ArgDict(min_length=1), metavar='FLAG=VALUE', required=False, help=( 'A comma-separated list of database flags to set on the ' 'instance. Use an equals sign to separate flag name and value. ' 'Flags without values, like skip_grant_tables, can be written ' 'out without a value after, e.g., `skip_grant_tables=`. Use ' 'on/off for booleans. View the Instance Resource API for allowed ' 'flags. (e.g., `--database-flags max_allowed_packet=55555,' 'skip_grant_tables=,log_output=1`)')) parser.add_argument( '--database-version', required=False, default='MYSQL_5_6', choices=['MYSQL_5_5', 'MYSQL_5_6', 'MYSQL_5_7', 'POSTGRES_9_6'], help='The database engine type and version.') parser.add_argument( '--enable-bin-log', required=False, action='store_true', default=None, # Tri-valued: None => don't change the setting. help=( 'Specified if binary log should be enabled. If backup ' 'configuration is disabled, binary log must be disabled as well.')) parser.add_argument( '--failover-replica-name', required=False, help='Also create a failover replica with the specified name.') parser.add_argument( '--follow-gae-app', required=False, help=('First Generation instances only. The App Engine app this ' 'instance should follow. It must be in the same region as ' 'the instance.')) parser.add_argument( '--gce-zone', required=False, help=('The preferred Compute Engine zone (e.g. us-central1-a, ' 'us-central1-b, etc.).')) parser.add_argument('instance', type=command_validate.InstanceNameRegexpValidator(), help='Cloud SQL instance ID.') parser.add_argument( '--maintenance-release-channel', choices={ 'production': 'Production updates are stable and recommended ' 'for applications in production.', 'preview': 'Preview updates release prior to production ' 'updates. You may wish to use the preview channel ' 'for dev/test applications so that you can preview ' 'their compatibility with your application prior ' 'to the production release.' }, type=str.lower, help="Which channel's updates to apply during the maintenance window.") parser.add_argument( '--maintenance-window-day', choices=arg_parsers.DayOfWeek.DAYS, type=arg_parsers.DayOfWeek.Parse, help='Day of week for maintenance window, in UTC time zone.') parser.add_argument( '--maintenance-window-hour', type=arg_parsers.BoundedInt(lower_bound=0, upper_bound=23), help='Hour of day for maintenance window, in UTC time zone.') parser.add_argument( '--master-instance-name', required=False, help=('Name of the instance which will act as master in the ' 'replication setup. The newly created instance will be a read ' 'replica of the specified master instance.')) parser.add_argument( '--memory', type=arg_parsers.BinarySize(), required=False, help=('A whole number value indicating how much memory is desired in ' 'the machine. A size unit should be provided (eg. 3072MiB or ' '9GiB) - if no units are specified, GiB is assumed. Both --cpu ' 'and --memory must be specified if a custom machine type is ' 'desired, and the --tier flag must be omitted.')) parser.add_argument('--on-premises-host-port', required=False, help=argparse.SUPPRESS) parser.add_argument( '--pricing-plan', '-p', required=False, choices=['PER_USE', 'PACKAGE'], default='PER_USE', help=('First Generation instances only. The pricing plan for this ' 'instance.')) # TODO(b/31989340): add remote completion parser.add_argument( '--region', required=False, default='us-central', help=( 'The regional location (e.g. asia-east1, us-east1). See the full ' 'list of regions at ' 'https://cloud.google.com/sql/docs/instance-locations.')) parser.add_argument('--replica-type', choices=['READ', 'FAILOVER'], help='The type of replica to create.') parser.add_argument('--replication', required=False, choices=['SYNCHRONOUS', 'ASYNCHRONOUS'], default=None, help='The type of replication this instance uses.') parser.add_argument( '--require-ssl', required=False, action='store_true', default=None, # Tri-valued: None => don't change the setting. help='Specified if users connecting over IP must use SSL.') parser.add_argument( '--storage-auto-increase', action='store_true', default=None, help=('Storage size can be increased, but it cannot be decreased; ' 'storage increases are permanent for the life of the instance. ' 'With this setting enabled, a spike in storage requirements ' 'can result in permanently increased storage costs for your ' 'instance. However, if an instance runs out of available space, ' 'it can result in the instance going offline, dropping existing ' 'connections.')) parser.add_argument( '--storage-size', type=arg_parsers.BinarySize(lower_bound='10GB', upper_bound='10230GB', suggested_binary_size_scales=['GB']), help=( 'Amount of storage allocated to the instance. Must be an integer ' 'number of GB between 10GB and 10230GB inclusive.')) parser.add_argument('--storage-type', required=False, choices=['SSD', 'HDD'], default=None, help='The storage type for the instance.') parser.add_argument( '--tier', '-t', required=False, help=('The tier for this instance. For Second Generation instances, ' 'TIER is the instance\'s machine type (e.g., db-n1-standard-1). ' 'For PostgreSQL instances, only shared-core machine types ' '(e.g., db-f1-micro) apply. A complete list of tiers is ' 'available here: https://cloud.google.com/sql/pricing.'))
def AddBaseArgs(parser): """Declare flag and positional arguments for this command parser.""" # TODO(b/35705305): move common flags to command_lib.sql.flags base.ASYNC_FLAG.AddToParser(parser) parser.display_info.AddFormat(flags.GetInstanceListFormat()) flags.AddActivationPolicy(parser) flags.AddAssignIp(parser) flags.AddAuthorizedNetworks(parser) flags.AddAvailabilityType(parser) parser.add_argument('--backup', required=False, action='store_true', default=True, help='Enables daily backup.') flags.AddBackupStartTime(parser) flags.AddBackupLocation(parser, allow_empty=False) flags.AddCPU(parser) flags.AddInstanceCollation(parser) flags.AddDatabaseFlags(parser) flags.AddEnableBinLog(parser, show_negated_in_help=False) parser.add_argument( '--failover-replica-name', required=False, help='Also create a failover replica with the specified name.') parser.add_argument('instance', type=command_validate.InstanceNameRegexpValidator(), help='Cloud SQL instance ID.') flags.AddMaintenanceReleaseChannel(parser) flags.AddMaintenanceWindowDay(parser) flags.AddMaintenanceWindowHour(parser) flags.AddDenyMaintenancePeriodStartDate(parser) flags.AddDenyMaintenancePeriodEndDate(parser) flags.AddDenyMaintenancePeriodTime(parser) parser.add_argument( '--master-instance-name', required=False, help=('Name of the instance which will act as master in the ' 'replication setup. The newly created instance will be a read ' 'replica of the specified master instance.')) flags.AddMemory(parser) # TODO(b/31989340): add remote completion # TODO(b/73362371): Make specifying a location required. location_group = parser.add_mutually_exclusive_group() location_group.add_argument( '--region', required=False, default='us-central', help=('Regional location (e.g. asia-east1, us-east1). See the full ' 'list of regions at ' 'https://cloud.google.com/sql/docs/instance-locations.')) flags.AddZone( location_group, help_text=('Preferred Compute Engine zone (e.g. us-central1-a, ' 'us-central1-b, etc.).')) parser.add_argument('--replica-type', choices=['READ', 'FAILOVER'], help='The type of replica to create.') flags.AddReplication(parser) parser.add_argument( '--require-ssl', required=False, action='store_true', default=None, help='Specified if users connecting over IP must use SSL.') flags.AddRootPassword(parser) flags.AddStorageAutoIncrease(parser) flags.AddStorageSize(parser) parser.add_argument( '--storage-type', required=False, choices=['SSD', 'HDD'], default=None, help='The storage type for the instance. The default is SSD.') flags.AddTier(parser) kms_flag_overrides = { 'kms-key': '--disk-encryption-key', 'kms-keyring': '--disk-encryption-key-keyring', 'kms-location': '--disk-encryption-key-location', 'kms-project': '--disk-encryption-key-project' } kms_resource_args.AddKmsKeyResourceArg(parser, 'instance', flag_overrides=kms_flag_overrides) flags.AddEnablePointInTimeRecovery(parser)