def Run(self, args): if args.run_diagnostics: network_diagnostics.NetworkDiagnostic().RunChecks() return holder = info_holder.InfoHolder(anonymizer=info_holder.Anonymizer( ) if args.anonymize else info_holder.NoopAnonymizer()) return holder
def Run(self, args): if args.run_diagnostics: _RunDiagnostics() return holder = info_holder.InfoHolder( anonymizer=info_holder.Anonymizer() if args.anonymize else None) return holder
def get_google_crc32c_install_command(): """Returns the command to install google-crc32c library.""" sdk_info = info_holder.InfoHolder() sdk_root = sdk_info.installation.sdk_root if sdk_root: third_party_path = os.path.join(sdk_root, 'lib', 'third_party') return '{} -m pip install google-crc32c --target {}'.format( sdk_info.basic.python_location, third_party_path)
def ConnectToInstance(cmd_args, sql_user): """Connects to the instance using the relevant CLI.""" try: log.status.write( 'Connecting to database with SQL user [{0}].'.format(sql_user)) execution_utils.Exec(cmd_args) except OSError: log.error('Failed to execute command "{0}"'.format(' '.join(cmd_args))) log.Print(info_holder.InfoHolder())
def Run(self, args): holder = info_holder.InfoHolder() python_version = platforms.PythonVersion() if not python_version.IsSupported(): log.warn(( 'Only Python version {0} is supported for the Cloud SDK. Many ' 'commands will work with a previous version, but not all.' ).format(python_version.MinSupportedVersionString())) return holder
def Run(self, args): if args.run_diagnostics: passed = _RunDiagnostics(args.ignore_hidden_property_allowlist) if passed: return None else: raise exceptions.Error( 'Some of the checks in diagnostics failed.') return info_holder.InfoHolder( anonymizer=info_holder.Anonymizer() if args.anonymize else None)
def testInfoShowLog(self): contents = 'test log contents' info = info_holder.InfoHolder() info.logs.last_log = 'test.log' info.logs.LastLogContents = lambda: contents self.StartObjectPatch(info_holder, 'InfoHolder', return_value=info) self.Run('info --show-log') self.AssertOutputNotContains('Platform:') self.AssertOutputContains('Contents of log file:') self.AssertOutputContains(contents) self.run_diagnostics.not_called()
def Run(self, args): if args.run_diagnostics: network_diagnostics.NetworkDiagnostic().RunChecks() return holder = info_holder.InfoHolder(anonymizer=info_holder.Anonymizer( ) if args.anonymize else info_holder.NoopAnonymizer()) python_version = platforms.PythonVersion() if not python_version.IsSupported(): log.warning( 'Only Python version {0} is supported for the Cloud SDK. Many ' 'commands will work with a previous version, but not all.'. format(python_version.MinSupportedVersionString())) return holder
def Run(self, args): info = info_holder.InfoHolder() log_data = None if args.log_file: try: log_data = info_holder.LogData.FromFile(args.log_file) except IOError as err: log.warn(u'Error reading the specified file [{0}]: ' u'{1}\n'.format(args.log_file, err)) if args.quiet: _PrintQuiet(unicode(info), log_data) else: log.status.Print(FEEDBACK_MESSAGE) if not log_data: log_data = _SuggestIncludeRecentLogs() if log_data or console_io.PromptContinue(prompt_string=( 'No invocation selected. Would you still like to file ' 'a bug (will open a new browser tab)')): feedback_util.OpenNewIssueInBrowser(info, log_data)
def Run(self, args): """Connects to a Cloud SQL instance. Args: args: argparse.Namespace, The arguments that this command was invoked with. Returns: If no exception is raised this method does not return. A new process is started and the original one is killed. Raises: HttpException: An http error response was received while executing api request. ToolException: An error other than http error occurred while executing the command. """ # TODO(b/62055495): Replace ToolExceptions with specific exceptions. 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') acl_name = _WhitelistClientIP(instance_ref, sql_client, sql_messages, client.resource_parser) # Get the client IP that the server sees. Sadly we can only do this by # checking the name of the authorized network rule. retryer = retry.Retryer(max_retrials=2, exponential_sleep_multiplier=2) try: instance_info, client_ip = retryer.RetryOnResult( _GetClientIP, [instance_ref, sql_client, acl_name], should_retry_if=lambda x, s: x[1] is None, # client_ip is None sleep_ms=500) except retry.RetryException: raise exceptions.ToolException('Could not whitelist client IP. Server ' 'did not reply with the whitelisted IP.') # Check for the mysql or psql executable based on the db version. db_type = instance_info.databaseVersion.split('_')[0] exe_name = constants.DB_EXE.get(db_type, 'mysql') exe = files.FindExecutableOnPath(exe_name) if not exe: raise exceptions.ToolException( '{0} client not found. Please install a {1} client and make sure ' 'it is in PATH to be able to connect to the database instance.' .format(exe_name.title(), exe_name)) # Check the version of IP and decide if we need to add ipv4 support. ip_type = network.GetIpVersion(client_ip) if ip_type == network.IP_VERSION_4: if instance_info.settings.ipConfiguration.ipv4Enabled: ip_address = instance_info.ipAddresses[0].ipAddress else: # TODO(b/36049930): ask user if we should enable ipv4 addressing message = ('It seems your client does not have ipv6 connectivity and ' 'the database instance does not have an ipv4 address. ' 'Please request an ipv4 address for this database instance.') raise exceptions.ToolException(message) elif ip_type == network.IP_VERSION_6: ip_address = instance_info.ipv6Address else: raise exceptions.ToolException('Could not connect to SQL server.') # Determine what SQL user to connect with. sql_user = constants.DEFAULT_SQL_USER[exe_name] if args.user: sql_user = args.user # We have everything we need, time to party! flags = constants.EXE_FLAGS[exe_name] sql_args = [exe_name, flags['hostname'], ip_address] sql_args.extend([flags['user'], sql_user]) sql_args.append(flags['password']) try: log.status.write( 'Connecting to database with SQL user [{0}].'.format(sql_user)) execution_utils.Exec(sql_args) except OSError: log.error('Failed to execute command "{0}"'.format(' '.join(sql_args))) log.Print(info_holder.InfoHolder())
def Run(self, args): if args.run_diagnostics: _RunDiagnostics(args.ignore_hidden_property_whitelist) return None return info_holder.InfoHolder( anonymizer=info_holder.Anonymizer() if args.anonymize else None)