def Filter(self, context, args): java.RequireJavaInstalled(datastore_util.DATASTORE_TITLE) if args.legacy: util.EnsureComponentIsInstalled('gcd-emulator', datastore_util.DATASTORE_TITLE) else: util.EnsureComponentIsInstalled('cloud-datastore-emulator', datastore_util.DATASTORE_TITLE) if not args.data_dir: args.data_dir = datastore_util.GetDataDir()
def Filter(self, context, args): java.RequireJavaInstalled(pubsub_util.PUBSUB_TITLE) util.EnsureComponentIsInstalled('pubsub-emulator', pubsub_util.PUBSUB_TITLE) if not args.data_dir: args.data_dir = pubsub_util.GetDataDir()
def IsCloudFirestoreEmulatorComponentInstalled(): try: util.EnsureComponentIsInstalled('cloud-firestore-emulator', firestore_util.FIRESTORE_TITLE) except: # pylint:disable=bare-except return False return True
def Filter(self, context, args): java.RequireJavaInstalled(datastore_util.DATASTORE_TITLE, min_version=8) util.EnsureComponentIsInstalled('cloud-datastore-emulator', datastore_util.DATASTORE_TITLE) if not args.data_dir: args.data_dir = datastore_util.GetDataDir()
def IsCloudDatastoreEmulatorComponentInstalled(): try: util.EnsureComponentIsInstalled('cloud-datastore-emulator', datastore_util.DATASTORE_TITLE) except: # pylint:disable=bare-except return False return True
def Filter(self, context, args): current_os = platforms.OperatingSystem.Current() if current_os is platforms.OperatingSystem.LINUX: util.EnsureComponentIsInstalled( spanner_util.SPANNER_EMULATOR_COMPONENT_ID, spanner_util.SPANNER_EMULATOR_TITLE) else: _RequireDockerInstalled()
def Run(self, args): if 'all' in args.emulators: if len(args.emulators) > 1: raise util.EmulatorArgumentsError( "Cannot specify 'all' with other emulators") if args.route_to_public: raise util.EmulatorArgumentsError( 'Cannot specify --route-to-public and --emulators=all') else: unknown_emulators = [x for x in args.emulators if x not in config.EMULATORS] if unknown_emulators: raise util.EmulatorArgumentsError('Specified unrecognized emulators: ' ','.join(unknown_emulators)) proxy_port = args.proxy_port if args.proxy_port is None: proxy_port = util.DefaultPortIfAvailable() if not portpicker.is_port_free(proxy_port): raise util.EmulatorArgumentsError( 'Specified proxy port [{}] is not available'.format(proxy_port)) util.EnsureComponentIsInstalled('emulator-reverse-proxy', 'gcloud emulators start') for flag, emulator in six.iteritems(config.EMULATORS): title = emulator.emulator_title component = emulator.emulator_component if (args.emulators is not None and (flag in args.emulators or 'all' in args.emulators)): java.RequireJavaInstalled(title) util.EnsureComponentIsInstalled(component, title) with contextlib.ExitStack() as stack: local_emulator_ports = {} for emulator in args.emulators: port = portpicker.pick_unused_port() local_emulator_ports[emulator] = port stack.enter_context(config.EMULATORS[emulator].Start(port)) _, routes_config_file = tempfile.mkstemp() config.WriteRoutesConfig(config.EMULATORS, routes_config_file) log.status.Print( 'routes configuration written to file: {}'.format(routes_config_file)) proxy_config = config.ProxyConfiguration(local_emulator_ports, args.route_to_public, proxy_port) _, proxy_config_file = tempfile.mkstemp() proxy_config.WriteJsonToFile(proxy_config_file) log.status.Print( 'proxy configuration written to file: {}'.format(proxy_config_file)) # TODO(b/35872500) for some reason, in this case, this will block. Maybe # we need to flush something, maybe not. Regardless, this is fine for # now, but would be nice for it to not block like everything else with proxy_util.StartEmulatorProxy( args=[routes_config_file, proxy_config_file]) as proxy_process: # This will block the console util.PrefixOutput(proxy_process, 'emulator-reverse-proxy')
def Filter(self, context, args): util.EnsureComponentIsInstalled(bigtable_util.BIGTABLE, bigtable_util.BIGTABLE_TITLE)
def RunBetaConnectCommand(args, supports_database=False): """Connects to a Cloud SQL instance through the Cloud SQL Proxy. Args: args: argparse.Namespace, The arguments that this command was invoked with. supports_database: Whether or not the `--database` flag needs to be accounted for. 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. SqlClientNotFoundError: A local SQL client could not be found. ConnectionError: An error occurred while trying to connect to the instance. """ client = api_util.SqlClient(api_util.API_VERSION_DEFAULT) sql_client = client.sql_client sql_messages = client.sql_messages instance_ref = instances_command_util.GetInstanceRef(args, client) instance_info = sql_client.instances.Get( sql_messages.SqlInstancesGetRequest(project=instance_ref.project, instance=instance_ref.instance)) if not instances_api_util.IsInstanceV2(instance_info): # The Cloud SQL Proxy does not support V1 instances. return RunConnectCommand(args, supports_database) # If the instance is V2, keep going with the proxy. util.EnsureComponentIsInstalled('cloud_sql_proxy', '`sql connect` command') # 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.SqlClientNotFoundError( '{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)) # Start the Cloud SQL Proxy and wait for it to be ready to accept connections. port = six.text_type(args.port) proxy_process = instances_api_util.StartCloudSqlProxy(instance_info, port) atexit.register(proxy_process.kill) # 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'], '127.0.0.1', flags['port'], port] sql_args.extend([flags['user'], sql_user]) sql_args.append(flags['password']) if supports_database: sql_args.extend(instances_command_util.GetDatabaseArgs(args, flags)) instances_command_util.ConnectToInstance(sql_args, sql_user) proxy_process.kill()
def Filter(self, context, args): java.RequireJavaInstalled(firestore_util.FIRESTORE_TITLE, min_version=8) util.EnsureComponentIsInstalled('cloud-firestore-emulator', firestore_util.FIRESTORE_TITLE)
def testEnsureComponentIsInstalled(self): ensure_mock = self.StartObjectPatch(util.update_manager.UpdateManager, 'EnsureInstalledAndRestart') util.EnsureComponentIsInstalled('foo', 'bar') ensure_mock.assert_called_with( ['foo'], msg='You need the [foo] component to use the bar.')