Exemple #1
0
def smartstack_check(service, service_path, soa_dir):
    """Check whether smartstack.yaml exists in service directory, and the proxy
    ports are declared.  Print appropriate message depending on outcome.

    :param service: name of service currently being examined
    :param service_path: path to loction of smartstack.yaml file"""
    if is_file_in_dir('smartstack.yaml', service_path):
        paasta_print(PaastaCheckMessages.SMARTSTACK_YAML_FOUND)
        instances = get_all_namespaces_for_service(service=service,
                                                   soa_dir=soa_dir)
        if len(instances) > 0:
            for namespace, config in get_all_namespaces_for_service(
                    service=service,
                    soa_dir=soa_dir,
                    full_name=False,
            ):
                if 'proxy_port' in config:
                    paasta_print(
                        PaastaCheckMessages.smartstack_port_found(
                            namespace,
                            config.get('proxy_port'),
                        ))
                else:
                    paasta_print(PaastaCheckMessages.SMARTSTACK_PORT_MISSING)
        else:
            paasta_print(PaastaCheckMessages.SMARTSTACK_PORT_MISSING)
Exemple #2
0
def _smartstack_rules(conf, soa_dir, synapse_service_dir):
    for dep in conf.get_dependencies():
        namespace = dep.get('smartstack')
        if namespace is None:
            continue

        # TODO: support wildcards

        # synapse backends
        try:
            backends = _synapse_backends(synapse_service_dir, namespace)
        except (OSError, IOError, ValueError):
            # Don't fatal if something goes wrong loading the synapse files
            log.exception('Unable to load backend {}'.format(namespace))
            backends = ()

        for backend in backends:
            yield iptables.Rule(
                protocol='tcp',
                src='0.0.0.0/0.0.0.0',
                dst='{}/255.255.255.255'.format(backend['host']),
                target='ACCEPT',
                matches=(
                    ('comment', (('comment', ('backend ' + namespace, )), )),
                    ('tcp', (('dport', (six.text_type(backend['port']), )), )),
                ),
                target_parameters=(),
            )

        # synapse-haproxy proxy_port
        service, _ = namespace.split('.', 1)
        service_namespaces = get_all_namespaces_for_service(service,
                                                            soa_dir=soa_dir)
        port = dict(service_namespaces)[namespace]['proxy_port']
        yield _yocalhost_rule(port, 'proxy_port ' + namespace)
def _smartstack_rules(conf, soa_dir, synapse_service_dir):
    for dep in conf.get_dependencies() or ():
        namespace = dep.get("smartstack")
        if namespace is None:
            continue

        # TODO: support wildcards

        # synapse backends
        try:
            backends = _synapse_backends(synapse_service_dir, namespace)
        except (OSError, IOError, ValueError):
            # Don't fatal if something goes wrong loading the synapse files
            log.exception(f"Unable to load backend {namespace}")
            backends = ()

        for backend in backends:
            yield iptables.Rule(
                protocol="tcp",
                src="0.0.0.0/0.0.0.0",
                dst="{}/255.255.255.255".format(backend["host"]),
                target="ACCEPT",
                matches=(
                    ("comment", (("comment", ("backend " + namespace, )), )),
                    ("tcp", (("dport", (str(backend["port"]), )), )),
                ),
                target_parameters=(),
            )

        # synapse-haproxy proxy_port
        service, _ = namespace.split(".", 1)
        service_namespaces = get_all_namespaces_for_service(service,
                                                            soa_dir=soa_dir)
        port = dict(service_namespaces)[namespace]["proxy_port"]
        yield _yocalhost_rule(port, "proxy_port " + namespace)
Exemple #4
0
def smartstack_check(service, service_path, soa_dir):
    """Check whether smartstack.yaml exists in service directory, and the proxy
    ports are declared.  Print appropriate message depending on outcome.

    :param service: name of service currently being examined
    :param service_path: path to loction of smartstack.yaml file"""
    if is_file_in_dir("smartstack.yaml", service_path):
        paasta_print(PaastaCheckMessages.SMARTSTACK_YAML_FOUND)
        instances = get_all_namespaces_for_service(service=service, soa_dir=soa_dir)
        if len(instances) > 0:
            for namespace, config in get_all_namespaces_for_service(service=service, soa_dir=soa_dir, full_name=False):
                if "proxy_port" in config:
                    paasta_print(PaastaCheckMessages.smartstack_port_found(namespace, config.get("proxy_port")))
                else:
                    paasta_print(PaastaCheckMessages.SMARTSTACK_PORT_MISSING)
        else:
            paasta_print(PaastaCheckMessages.SMARTSTACK_PORT_MISSING)
Exemple #5
0
def get_smartstack_endpoints(service):
    endpoints = []
    for name, config in get_all_namespaces_for_service(service,
                                                       full_name=False):
        mode = config.get('mode', 'http')
        port = config.get('proxy_port')
        endpoints.append("%s://169.254.255.254:%s (%s)" % (mode, port, name))
    return endpoints
Exemple #6
0
def get_smartstack_endpoints(service, soa_dir):
    endpoints = []
    for name, config in get_all_namespaces_for_service(service, full_name=False, soa_dir=soa_dir):
        mode = config.get('mode', 'http')
        port = config.get('proxy_port')
        endpoints.append("%s://169.254.255.254:%s (%s)" % (
            mode, port, name
        ))
    return endpoints
Exemple #7
0
def get_smartstack_endpoints(service, soa_dir):
    endpoints = []
    for name, config in get_all_namespaces_for_service(service,
                                                       full_name=False,
                                                       soa_dir=soa_dir):
        mode = config.get("mode", "http")
        port = config.get("proxy_port")
        endpoints.append(f"{mode}://169.254.255.254:{port} ({name})")
    return endpoints
def get_service_lines_for_service(service):
    lines = []
    config = service_configuration_lib.read_service_configuration(service)
    port = config.get('port', None)
    if port is not None:
        lines.append("%s (%d/tcp)" % (service, port))

    for namespace, config in get_all_namespaces_for_service(service, full_name=False):
        proxy_port = config.get('proxy_port', None)
        if proxy_port is not None:
            lines.append("%s (%d/tcp)" % (compose_job_id(service, namespace), proxy_port))
    return lines
Exemple #9
0
def get_smartstack_endpoints(service, soa_dir):
    endpoints = []
    for name, config in get_all_namespaces_for_service(service,
                                                       full_name=False,
                                                       soa_dir=soa_dir):
        mode = config.get('mode', 'http')
        port = config.get('proxy_port')
        endpoints.append("{}://169.254.255.254:{} ({})".format(
            mode,
            port,
            name,
        ))
    return endpoints
Exemple #10
0
def get_service_lines_for_service(service):
    lines = []
    config = service_configuration_lib.read_service_configuration(service)
    port = config.get('port', None)
    if port is not None:
        lines.append("%s (%d/tcp)" % (service, port))

    for namespace, config in get_all_namespaces_for_service(service,
                                                            full_name=False):
        proxy_port = config.get('proxy_port', None)
        if proxy_port is not None:
            lines.append("%s (%d/tcp)" %
                         (compose_job_id(service, namespace), proxy_port))
    return lines
def get_service_lines_for_service(service):
    lines = []
    config = service_configuration_lib.read_service_configuration(service)
    port = config.get('port', None)
    description = config.get('description', "No description")

    if port is not None:
        lines.append("%s\t%d/tcp\t# %s" % (service, port, description))

    for namespace, config in get_all_namespaces_for_service(service, full_name=False):
        proxy_port = config.get('proxy_port', None)
        if proxy_port is not None:
            lines.append("%s\t%d/tcp\t# %s" % (compose_job_id(service, namespace), proxy_port, description))
    return [line.encode('utf-8') for line in lines]
Exemple #12
0
def _smartstack_rules(conf, soa_dir):
    for namespace in conf.get_dependencies().get('smartstack', ()):
        # TODO: handle non-synapse-haproxy services
        # TODO: support wildcards?
        service, _ = namespace.split('.', 1)
        service_namespaces = get_all_namespaces_for_service(service,
                                                            soa_dir=soa_dir)
        port = dict(service_namespaces)[namespace]['proxy_port']

        yield iptables.Rule(protocol='tcp',
                            src='0.0.0.0/0.0.0.0',
                            dst='169.254.255.254/255.255.255.255',
                            target='ACCEPT',
                            matches=(('tcp', (('dport',
                                               six.text_type(port)), )), ))