Beispiel #1
0
    def __init__(self,
                 name,
                 orchestrator=None,
                 host=None,
                 endpoints=None,
                 tls=False):
        if not name:
            raise Exception("Name not provided")
        self.name = name
        self.orchestrator = orchestrator
        if not endpoints:
            default_endpoint = "docker" if (
                not orchestrator or orchestrator == "swarm") else orchestrator
            self.endpoints = {
                default_endpoint: {
                    "Host": get_context_host(host, tls),
                    "SkipTLSVerify": not tls
                }
            }
        else:
            for k, v in endpoints.items():
                ekeys = v.keys()
                for param in ["Host", "SkipTLSVerify"]:
                    if param not in ekeys:
                        raise ContextException(
                            "Missing parameter {} from endpoint {}".format(
                                param, k))
            self.endpoints = endpoints

        self.tls_cfg = {}
        self.meta_path = "IN MEMORY"
        self.tls_path = "IN MEMORY"
Beispiel #2
0
    def _load_meta(cls, name):
        meta_file = get_meta_file(name)
        if not os.path.isfile(meta_file):
            return None

        metadata = {}
        try:
            with open(meta_file) as f:
                metadata = json.load(f)
        except (OSError, KeyError, ValueError) as e:
            # unknown format
            raise Exception("""Detected corrupted meta file for
                context {} : {}""".format(name, e))

        # for docker endpoints, set defaults for
        # Host and SkipTLSVerify fields
        for k, v in metadata["Endpoints"].items():
            if k != "docker":
                continue
            metadata["Endpoints"][k]["Host"] = v.get(
                "Host", get_context_host(None, False))
            metadata["Endpoints"][k]["SkipTLSVerify"] = bool(
                v.get("SkipTLSVerify", True))

        return metadata
Beispiel #3
0
    def __init__(self,
                 name,
                 orchestrator=None,
                 host=None,
                 endpoints=None,
                 tls=False):
        if not name:
            raise Exception("Name not provided")
        self.name = name
        self.context_type = None
        self.orchestrator = orchestrator
        self.endpoints = {}
        self.tls_cfg = {}
        self.meta_path = "IN MEMORY"
        self.tls_path = "IN MEMORY"

        if not endpoints:
            # set default docker endpoint if no endpoint is set
            default_endpoint = "docker" if (
                not orchestrator or orchestrator == "swarm") else orchestrator

            self.endpoints = {
                default_endpoint: {
                    "Host": get_context_host(host, tls),
                    "SkipTLSVerify": not tls
                }
            }
            return

        # check docker endpoints
        for k, v in endpoints.items():
            if not isinstance(v, dict):
                # unknown format
                raise ContextException("""Unknown endpoint format for
                    context {}: {}""".format(name, v))

            self.endpoints[k] = v
            if k != "docker":
                continue

            self.endpoints[k]["Host"] = v.get("Host",
                                              get_context_host(host, tls))
            self.endpoints[k]["SkipTLSVerify"] = bool(
                v.get("SkipTLSVerify", not tls))
    def set_endpoint(
            self, name="docker", host=None, tls_cfg=None,
            skip_tls_verify=False, def_namespace=None):
        self.endpoints[name] = {
            "Host": get_context_host(host),
            "SkipTLSVerify": skip_tls_verify
        }
        if def_namespace:
            self.endpoints[name]["DefaultNamespace"] = def_namespace

        if tls_cfg:
            self.tls_cfg[name] = tls_cfg