From 9bb7c20938c22ce86c12bb1f6637ca6dfae3cc65 Mon Sep 17 00:00:00 2001 From: aiordache Date: Sat, 30 May 2020 11:01:22 +0200 Subject: [PATCH] Make orchestrator field optional Signed-off-by: aiordache --- docker/context/api.py | 16 ----------- docker/context/context.py | 56 ++++++++++++--------------------------- 2 files changed, 17 insertions(+), 55 deletions(-) diff --git a/docker/context/api.py b/docker/context/api.py index d903d9c6..c45115bc 100644 --- a/docker/context/api.py +++ b/docker/context/api.py @@ -38,13 +38,7 @@ class ContextAPI(object): >>> print(ctx.Metadata) { "Name": "test", -<<<<<<< HEAD "Metadata": {}, -======= - "Metadata": { - "StackOrchestrator": "swarm" - }, ->>>>>>> 64fdb32... Implement context management, lifecycle and unittests. "Endpoints": { "docker": { "Host": "unix:///var/run/docker.sock", @@ -61,13 +55,9 @@ class ContextAPI(object): ctx = Context.load_context(name) if ctx: raise errors.ContextAlreadyExists(name) -<<<<<<< HEAD endpoint = "docker" if orchestrator and orchestrator != "swarm": endpoint = orchestrator -======= - endpoint = "docker" if orchestrator == "swarm" else orchestrator ->>>>>>> 64fdb32... Implement context management, lifecycle and unittests. ctx = Context(name, orchestrator) ctx.set_endpoint( endpoint, host, tls_cfg, @@ -89,13 +79,7 @@ class ContextAPI(object): >>> print(ctx.Metadata) { "Name": "test", -<<<<<<< HEAD "Metadata": {}, -======= - "Metadata": { - "StackOrchestrator": "swarm" - }, ->>>>>>> 64fdb32... Implement context management, lifecycle and unittests. "Endpoints": { "docker": { "Host": "unix:///var/run/docker.sock", diff --git a/docker/context/context.py b/docker/context/context.py index 026a6941..8158803d 100644 --- a/docker/context/context.py +++ b/docker/context/context.py @@ -57,15 +57,7 @@ class Context: self, name="docker", host=None, tls_cfg=None, skip_tls_verify=False, def_namespace=None): self.endpoints[name] = { -<<<<<<< HEAD -<<<<<<< HEAD "Host": get_context_host(host, not skip_tls_verify), -======= - "Host": get_context_host(host), ->>>>>>> 64fdb32... Implement context management, lifecycle and unittests. -======= - "Host": get_context_host(host, not skip_tls_verify), ->>>>>>> 3ce2d89... Specify when to use `tls` on Context constructor "SkipTLSVerify": skip_tls_verify } if def_namespace: @@ -79,7 +71,6 @@ class Context: @classmethod def load_context(cls, name): -<<<<<<< HEAD meta = Context._load_meta(name) if meta: instance = cls( @@ -87,11 +78,6 @@ class Context: orchestrator=meta["Metadata"].get("StackOrchestrator", None), endpoints=meta.get("Endpoints", None)) instance.context_type = meta["Metadata"].get("Type", None) -======= - name, orchestrator, endpoints = Context._load_meta(name) - if name: - instance = cls(name, orchestrator, endpoints=endpoints) ->>>>>>> 64fdb32... Implement context management, lifecycle and unittests. instance._load_certs() instance.meta_path = get_meta_dir(name) return instance @@ -99,7 +85,6 @@ class Context: @classmethod def _load_meta(cls, name): -<<<<<<< HEAD meta_file = get_meta_file(name) if not os.path.isfile(meta_file): return None @@ -124,27 +109,6 @@ class Context: v.get("SkipTLSVerify", True)) return metadata -======= - metadata = {} - meta_file = get_meta_file(name) - if os.path.isfile(meta_file): - with open(meta_file) as f: - try: - with open(meta_file) as f: - metadata = json.load(f) - for k, v in metadata["Endpoints"].items(): - metadata["Endpoints"][k]["SkipTLSVerify"] = bool( - v["SkipTLSVerify"]) - except (IOError, KeyError, ValueError) as e: - # unknown format - raise Exception("""Detected corrupted meta file for - context {} : {}""".format(name, e)) - - return ( - metadata["Name"], metadata["Metadata"]["StackOrchestrator"], - metadata["Endpoints"]) - return None, None, None ->>>>>>> 64fdb32... Implement context management, lifecycle and unittests. def _load_certs(self): certs = {} @@ -213,18 +177,16 @@ class Context: result.update(self.Storage) return result -<<<<<<< HEAD def is_docker_host(self): return self.context_type is None -======= ->>>>>>> 64fdb32... Implement context management, lifecycle and unittests. @property def Name(self): return self.name @property def Host(self): +<<<<<<< HEAD <<<<<<< HEAD if not self.orchestrator or self.orchestrator == "swarm": endpoint = self.endpoints.get("docker", None) @@ -235,6 +197,9 @@ class Context: return self.endpoints[self.orchestrator].get("Host", None) ======= if self.orchestrator == "swarm": +======= + if not self.orchestrator or self.orchestrator == "swarm": +>>>>>>> 1e11ece... Make orchestrator field optional return self.endpoints["docker"]["Host"] return self.endpoints[self.orchestrator]["Host"] >>>>>>> 64fdb32... Implement context management, lifecycle and unittests. @@ -245,6 +210,7 @@ class Context: @property def Metadata(self): +<<<<<<< HEAD <<<<<<< HEAD meta = {} if self.orchestrator: @@ -259,17 +225,29 @@ class Context: "StackOrchestrator": self.orchestrator }, >>>>>>> 64fdb32... Implement context management, lifecycle and unittests. +======= + meta = {} + if self.orchestrator: + meta = {"StackOrchestrator": self.orchestrator} + return { + "Name": self.name, + "Metadata": meta, +>>>>>>> 1e11ece... Make orchestrator field optional "Endpoints": self.endpoints } @property def TLSConfig(self): key = self.orchestrator +<<<<<<< HEAD <<<<<<< HEAD if not key or key == "swarm": ======= if key == "swarm": >>>>>>> 64fdb32... Implement context management, lifecycle and unittests. +======= + if not key or key == "swarm": +>>>>>>> 1e11ece... Make orchestrator field optional key = "docker" if key in self.tls_cfg.keys(): return self.tls_cfg[key]