MSV FM

[email protected]: ~ $
Path : /lib/fm-agent/library/
File Upload :
Current < : //lib/fm-agent/library/container_discovery.py

import logging
import os.path
import sys

from agent_util import UnixHTTPConnection, json_loads

logger = logging.getLogger('Containers')


def check_access():
    if not os.path.exists('/var/run/docker.sock'):
        return 'no-docker'

    try:
        conn = UnixHTTPConnection('/var/run/docker.sock')
        conn.request('GET', '/containers/json', headers={'Host': 'localhost'})
        conn.getresponse()
    except Exception:
        return 'no-permission'

    return 'success'


def discover_docker_containers(config, plugins, existing_containers, rebuild=False):
    conn = UnixHTTPConnection('/var/run/docker.sock')
    conn.request('GET', '/containers/json?all=true', headers={'Host': 'localhost'})
    r = conn.getresponse().read()
    j = json_loads(r)

    if not len(j):
        return []

    app_mapping = {}

    if config.has_section('docker_image_mapping'):
        items = config.items('docker_image_mapping')
        for app, image in items:
            app_mapping.setdefault(image, []).append(app)

    containers = []
    for container in j:
        short_id = container["Id"][:12]
        state = container["State"]

        existing_container = existing_containers.get(short_id)

        if not existing_container and state != "running":
            # Don't send stopped containers that we've never seen
            continue

        if existing_container and not rebuild:
            changed_state = existing_container["State"] != container["State"]
            existing_container.update(container)
            if changed_state:
                # Flag this container as updated
                existing_container["updated"] = True
            container = existing_container
        else:
            # Only fetch metadata for new containers
            container["container_platform"] = "docker"

            app_image = container["Image"]
            applications = []
            if app_image in app_mapping:
                applications.extend(app_mapping[app_image])
            container["applications"] = applications

            app_metadata = {}
            for app in ["docker"] + applications:
                try:
                    plugin = plugins.plugins.get(app)
                    if not plugin:
                        logger.error("Unknown/unloaded docker plugin '%s'", app)
                        continue
                    metadata = plugin.get_metadata_docker(container, plugins.config.get(app, {})) or {}
                    logger.info('Container %s: %d textkeys for %s', short_id, len(metadata.keys()), app)
                    plugin_label = getattr(plugin, 'label', plugin.textkey)
                    app_metadata[app] = (plugin_label, metadata)
                except Exception:
                    t, e = sys.exc_info()[:2]
                    logging.exception(e)
                    continue
            container["app_metadata"] = app_metadata

        containers.append(container)

    return containers

def find_docker_container(container_id):
    conn = UnixHTTPConnection('/var/run/docker.sock')
    conn.request('GET', '/containers/json?all=true', headers={'Host': 'localhost'})
    r = conn.getresponse().read()
    container_list = json_loads(r)

    for container in container_list:
        short_id = container["Id"][:12]
        if short_id == container_id:
            return container

    return None
Bethany
Bethany
0%

THE FINEST HOTEL NEAR LAKE KIVU

The Perfect Base For You

Required fields are followed by *





EC1A68011

About Us

Delicious Interior With The Pinch Of Everything

Bethany Investment group is Presbyterian church in Rwanda(EPR) company that manage Hotel and Guest house in Karongi (Bethany Hotel), ISANO branch in GIKONDO(Kigali), Kiyovu branch(Kigali), AMIZERO branch(Nyagatare-East) and Gisenyi Branch(Rubavu).

Accomodation

Get a Comfortable Room
Feel The Comfort

Get a comfortable room and feel our hotel’s comfort. Bethany Hotel features a variety of fully furnished rooms with extra space, Executive rooms, Deluxe rooms with a beautiful lake view and garden space, Deluxe rooms, comfort rooms, family rooms and standard rooms at your service.

Standard Single

Services

We Provide Top Class Facility
Especially For You

Beach BBQ Party

Kick back on the beach& and enjoy our berbecue from our masterchef

Breakfast

Kick back at our hotels& enjoy our breakfast from our masterchef

Conference Hall

Kick back at our hotels& enjoy our conference halls from all bethany branches

Enjoy with your partner

Honeymoon Package

80%

Get In Touch

Don’t Miss Any Update

    +

    Search your Room

    Required fields are followed by *