コード例 #1
0
    def on_get(self, request):
        from localstack.utils import diagnose

        return {
            "version": {
                "image-version": call_safe(diagnose.get_docker_image_details),
                "localstack-version":
                call_safe(diagnose.get_localstack_version),
                "host": {
                    "kernel": call_safe(diagnose.get_host_kernel_version),
                },
            },
            "services":
            call_safe(diagnose.get_service_stats),
            "config":
            call_safe(diagnose.get_localstack_config),
            "docker-inspect":
            call_safe(diagnose.inspect_main_container),
            "docker-dependent-image-hashes":
            call_safe(diagnose.get_important_image_hashes),
            "file-tree":
            call_safe(diagnose.get_file_tree),
            "important-endpoints":
            call_safe(diagnose.resolve_endpoints),
            "logs":
            call_safe(diagnose.get_localstack_logs),
        }
コード例 #2
0
ファイル: metadata.py プロジェクト: rdkamali/localstack
def get_machine_id() -> str:
    cache_path = os.path.join(config.dirs.cache, "machine.json")
    doc = FileMappedDocument(cache_path)

    if "machine_id" not in doc:
        # generate a machine id
        doc["machine_id"] = _generate_machine_id()
        # try to cache the machine ID
        call_safe(doc.save)

    return doc["machine_id"]
コード例 #3
0
 def __init__(
     self,
     name,
     start=_default,
     check=_default,
     listener=None,
     active=False,
     stop=None,
     lifecycle_hook: ServiceLifecycleHook = None,
 ):
     self.plugin_name = name
     self.start_function = start
     self.listener = listener
     self.check_function = check if check is not _default else local_api_checker(
         name)
     self.default_active = active
     self.stop_function = stop
     self.lifecycle_hook = lifecycle_hook or ServiceLifecycleHook()
     call_safe(self.lifecycle_hook.on_after_init)
コード例 #4
0
    def start(self, asynchronous):
        call_safe(self.lifecycle_hook.on_before_start)

        if not self.start_function:
            return

        if self.start_function is _default:
            # fallback start method that simply adds the listener function to the list of proxy listeners if it exists
            if not self.listener:
                return

            from localstack.services.infra import add_service_proxy_listener

            add_service_proxy_listener(self.plugin_name, self.listener)
            return

        kwargs = {"asynchronous": asynchronous}
        if self.listener:
            kwargs["update_listener"] = self.listener
        return self.start_function(**kwargs)
コード例 #5
0
def wait_container_is_ready(timeout: Optional[float] = None):
    """Blocks until the localstack main container is running and the ready marker has been printed."""
    container_name = config.MAIN_CONTAINER_NAME
    started = time.time()

    def is_container_running():
        return DOCKER_CLIENT.is_container_running(container_name)

    if not poll_condition(is_container_running, timeout=timeout):
        return False

    stream = DOCKER_CLIENT.stream_container_logs(container_name)

    # create a timer that will terminate the log stream after the remaining timeout
    timer = None
    if timeout:
        waited = time.time() - started
        remaining = timeout - waited
        # check the rare case that the timeout has already been reached
        if remaining <= 0:
            stream.close()
            return False
        timer = threading.Timer(remaining, stream.close)
        timer.start()

    try:
        for line in stream:
            line = line.decode("utf-8").strip()
            if line == constants.READY_MARKER_OUTPUT:
                return True

        # EOF was reached or the stream was closed
        return False
    finally:
        call_safe(stream.close)
        if timer:
            # make sure the timer is stopped (does nothing if it has already run)
            timer.cancel()
コード例 #6
0
ファイル: iam.py プロジェクト: localstack/localstack
    def _pre_delete(resource_id, resources, resource_type, func, stack_name):
        """detach managed policies from role before deleting"""
        iam_client = aws_stack.connect_to_service("iam")
        resource = resources[resource_id]
        props = resource["Properties"]
        role_name = props["RoleName"]

        try:
            # TODO: this should probably only remove the policies that are specified in the stack (verify with AWS)
            # detach managed policies
            for policy in iam_client.list_attached_role_policies(
                    RoleName=role_name).get("AttachedPolicies", []):
                call_safe(
                    iam_client.detach_role_policy,
                    kwargs={
                        "RoleName": role_name,
                        "PolicyArn": policy["PolicyArn"]
                    },
                )

            # delete inline policies
            for inline_policy_name in iam_client.list_role_policies(
                    RoleName=role_name).get("PolicyNames", []):
                call_safe(
                    iam_client.delete_role_policy,
                    kwargs={
                        "RoleName": role_name,
                        "PolicyName": inline_policy_name
                    },
                )

            # TODO: potentially remove this when stack resource deletion order is fixed (check AWS behavior first)
            # cleanup instance profile
            rs = iam_client.list_instance_profiles_for_role(RoleName=role_name)
            for instance_profile in rs["InstanceProfiles"]:
                ip_name = instance_profile["InstanceProfileName"]
                call_safe(
                    iam_client.remove_role_from_instance_profile,
                    kwargs={
                        "InstanceProfileName": ip_name,
                        "RoleName": role_name
                    },
                )
        except Exception as e:
            if "NoSuchEntity" not in str(e):
                raise
コード例 #7
0
 def stop(self):
     call_safe(self.lifecycle_hook.on_before_stop)
     if not self.stop_function:
         return
     return self.stop_function()