コード例 #1
0
def set_service_status(data):
    command = data.get("command")
    service = data.get("service")
    service_ports = config.parse_service_ports()
    if command == "start":
        existing = service_ports.get(service)
        port = DEFAULT_SERVICE_PORTS.get(service)
        if existing:
            status = get_service_status(service, port)
            if status == "running":
                return
        key_upper = service.upper().replace("-", "_")
        port_variable = "PORT_%s" % key_upper
        service_list = os.environ.get("SERVICES", "").strip()
        services = [e for e in re.split(r"[\s,]+", service_list) if e]
        contained = [s for s in services if s.startswith(service)]
        if not contained:
            services.append(service)
        config_listener.update_config_variable(port_variable, port)
        new_service_list = ",".join(services)
        os.environ["SERVICES"] = new_service_list
        # TODO: expensive operation - check if we need to do this here for each service, should be optimized!
        config.populate_configs()
        LOG.info("Starting service %s on port %s" % (service, port))
        SERVICE_PLUGINS[service].start(asynchronous=True)
    return {}
コード例 #2
0
ファイル: infra.py プロジェクト: xKeyOPS/localstack
def set_service_status(data):
    command = data.get('command')
    service = data.get('service')
    service_ports = config.parse_service_ports()
    if command == 'start':
        existing = service_ports.get(service)
        port = DEFAULT_SERVICE_PORTS.get(service)
        if existing:
            status = get_service_status(service, port)
            if status == 'running':
                return
        key_upper = service.upper().replace('-', '_')
        port_variable = 'PORT_%s' % key_upper
        service_list = os.environ.get('SERVICES', '').strip()
        services = [e for e in re.split(r'[\s,]+', service_list) if e]
        contained = [s for s in services if s.startswith(service)]
        if not contained:
            services.append(service)
        update_config_variable(port_variable, port)
        new_service_list = ','.join(services)
        os.environ['SERVICES'] = new_service_list
        config.populate_configs()
        LOG.info('Starting service %s on port %s' % (service, port))
        SERVICE_PLUGINS[service].start(asynchronous=True)
    return {}
コード例 #3
0
    def test_custom_port_mapping(self):
        with temporary_env({"SERVICES": "foobar", "FOOBAR_PORT": "1234"}):
            result = config.parse_service_ports()

        assert len(result) == 1
        assert "foobar" not in config.DEFAULT_SERVICE_PORTS
        assert "foobar" in result
        assert result["foobar"] == 1234
コード例 #4
0
ファイル: infra.py プロジェクト: rajdeepsharma17/localstack
def get_services_status():
    result = {}
    for service, port in config.parse_service_ports().items():
        status = get_service_status(service, port)
        result[service] = {
            'port': port,
            'status': status
        }
    return result
コード例 #5
0
ファイル: bootstrap.py プロジェクト: loftwah/localstack
def get_enabled_apis() -> Set[str]:
    """
    Returns the list of APIs that are enabled through the SERVICES variable. If the SERVICES variable is empty,
    then it will return all available services. Meta-services like "serverless" or "cognito", and dependencies are
    resolved.

    The result is cached, so it's safe to call. Clear the cache with get_enabled_apis.cache_clear().
    """
    return resolve_apis(config.parse_service_ports().keys())
コード例 #6
0
    def test_custom_port_mapping_in_services_env(self):
        with temporary_env({"SERVICES": "foobar:1235"}):
            result = config.parse_service_ports()

        assert len(result) == 1
        assert "foobar" not in config.DEFAULT_SERVICE_PORTS
        assert "foobar" in result
        # FOOBAR_PORT cannot be parsed
        assert result["foobar"] == 1235
コード例 #7
0
    def test_custom_service_default_port(self):
        with temporary_env({"SERVICES": "foobar"}):
            result = config.parse_service_ports()

        assert len(result) == 1
        assert "foobar" not in config.DEFAULT_SERVICE_PORTS
        assert "foobar" in result
        # foobar is not a default service so it is assigned 0
        assert result["foobar"] == 0
コード例 #8
0
    def test_with_service_subset(self):
        with temporary_env({"SERVICES": "s3,sqs"}):
            result = config.parse_service_ports()

        assert len(result) == 2
        assert "s3" in result
        assert "sqs" in result
        assert result["s3"] == 4566
        assert result["sqs"] == 4566
コード例 #9
0
ファイル: infra.py プロジェクト: xKeyOPS/localstack
def get_service_status(service, port=None):
    port = port or config.parse_service_ports().get(service)
    status = 'disabled' if (
        port or 0) <= 0 else 'running' if is_port_open(port) else 'stopped'
    return status
コード例 #10
0
 def test_returns_default_service_ports(self):
     result = config.parse_service_ports()
     assert result == config.DEFAULT_SERVICE_PORTS
コード例 #11
0
def get_service_status(service, port=None):
    port = port or config.parse_service_ports().get(service)
    status = "disabled" if (
        port or 0) <= 0 else "running" if is_port_open(port) else "stopped"
    return status
コード例 #12
0
#!/usr/bin/python3.6

# return ports needed for services defined in SERVICES

from localstack import config, constants

for service, ports in config.parse_service_ports().items():
    backend_port_varname = 'DEFAULT_PORT_' + service.upper() + '_BACKEND'
    if (hasattr(constants, backend_port_varname)):
        backend_port = getattr(constants, backend_port_varname)
        ports = str(ports) + ' ' + str(backend_port)
    print(service, ports)