mirror of https://github.com/docker/docker-py.git
Make orchestrator field optional
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
0268b02351
commit
9bb7c20938
|
|
@ -38,13 +38,7 @@ class ContextAPI(object):
|
||||||
>>> print(ctx.Metadata)
|
>>> print(ctx.Metadata)
|
||||||
{
|
{
|
||||||
"Name": "test",
|
"Name": "test",
|
||||||
<<<<<<< HEAD
|
|
||||||
"Metadata": {},
|
"Metadata": {},
|
||||||
=======
|
|
||||||
"Metadata": {
|
|
||||||
"StackOrchestrator": "swarm"
|
|
||||||
},
|
|
||||||
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
|
|
||||||
"Endpoints": {
|
"Endpoints": {
|
||||||
"docker": {
|
"docker": {
|
||||||
"Host": "unix:///var/run/docker.sock",
|
"Host": "unix:///var/run/docker.sock",
|
||||||
|
|
@ -61,13 +55,9 @@ class ContextAPI(object):
|
||||||
ctx = Context.load_context(name)
|
ctx = Context.load_context(name)
|
||||||
if ctx:
|
if ctx:
|
||||||
raise errors.ContextAlreadyExists(name)
|
raise errors.ContextAlreadyExists(name)
|
||||||
<<<<<<< HEAD
|
|
||||||
endpoint = "docker"
|
endpoint = "docker"
|
||||||
if orchestrator and orchestrator != "swarm":
|
if orchestrator and orchestrator != "swarm":
|
||||||
endpoint = orchestrator
|
endpoint = orchestrator
|
||||||
=======
|
|
||||||
endpoint = "docker" if orchestrator == "swarm" else orchestrator
|
|
||||||
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
|
|
||||||
ctx = Context(name, orchestrator)
|
ctx = Context(name, orchestrator)
|
||||||
ctx.set_endpoint(
|
ctx.set_endpoint(
|
||||||
endpoint, host, tls_cfg,
|
endpoint, host, tls_cfg,
|
||||||
|
|
@ -89,13 +79,7 @@ class ContextAPI(object):
|
||||||
>>> print(ctx.Metadata)
|
>>> print(ctx.Metadata)
|
||||||
{
|
{
|
||||||
"Name": "test",
|
"Name": "test",
|
||||||
<<<<<<< HEAD
|
|
||||||
"Metadata": {},
|
"Metadata": {},
|
||||||
=======
|
|
||||||
"Metadata": {
|
|
||||||
"StackOrchestrator": "swarm"
|
|
||||||
},
|
|
||||||
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
|
|
||||||
"Endpoints": {
|
"Endpoints": {
|
||||||
"docker": {
|
"docker": {
|
||||||
"Host": "unix:///var/run/docker.sock",
|
"Host": "unix:///var/run/docker.sock",
|
||||||
|
|
|
||||||
|
|
@ -57,15 +57,7 @@ class Context:
|
||||||
self, name="docker", host=None, tls_cfg=None,
|
self, name="docker", host=None, tls_cfg=None,
|
||||||
skip_tls_verify=False, def_namespace=None):
|
skip_tls_verify=False, def_namespace=None):
|
||||||
self.endpoints[name] = {
|
self.endpoints[name] = {
|
||||||
<<<<<<< HEAD
|
|
||||||
<<<<<<< HEAD
|
|
||||||
"Host": get_context_host(host, not skip_tls_verify),
|
"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
|
"SkipTLSVerify": skip_tls_verify
|
||||||
}
|
}
|
||||||
if def_namespace:
|
if def_namespace:
|
||||||
|
|
@ -79,7 +71,6 @@ class Context:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_context(cls, name):
|
def load_context(cls, name):
|
||||||
<<<<<<< HEAD
|
|
||||||
meta = Context._load_meta(name)
|
meta = Context._load_meta(name)
|
||||||
if meta:
|
if meta:
|
||||||
instance = cls(
|
instance = cls(
|
||||||
|
|
@ -87,11 +78,6 @@ class Context:
|
||||||
orchestrator=meta["Metadata"].get("StackOrchestrator", None),
|
orchestrator=meta["Metadata"].get("StackOrchestrator", None),
|
||||||
endpoints=meta.get("Endpoints", None))
|
endpoints=meta.get("Endpoints", None))
|
||||||
instance.context_type = meta["Metadata"].get("Type", 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._load_certs()
|
||||||
instance.meta_path = get_meta_dir(name)
|
instance.meta_path = get_meta_dir(name)
|
||||||
return instance
|
return instance
|
||||||
|
|
@ -99,7 +85,6 @@ class Context:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _load_meta(cls, name):
|
def _load_meta(cls, name):
|
||||||
<<<<<<< HEAD
|
|
||||||
meta_file = get_meta_file(name)
|
meta_file = get_meta_file(name)
|
||||||
if not os.path.isfile(meta_file):
|
if not os.path.isfile(meta_file):
|
||||||
return None
|
return None
|
||||||
|
|
@ -124,27 +109,6 @@ class Context:
|
||||||
v.get("SkipTLSVerify", True))
|
v.get("SkipTLSVerify", True))
|
||||||
|
|
||||||
return metadata
|
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):
|
def _load_certs(self):
|
||||||
certs = {}
|
certs = {}
|
||||||
|
|
@ -213,18 +177,16 @@ class Context:
|
||||||
result.update(self.Storage)
|
result.update(self.Storage)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
def is_docker_host(self):
|
def is_docker_host(self):
|
||||||
return self.context_type is None
|
return self.context_type is None
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
|
|
||||||
@property
|
@property
|
||||||
def Name(self):
|
def Name(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def Host(self):
|
def Host(self):
|
||||||
|
<<<<<<< HEAD
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
if not self.orchestrator or self.orchestrator == "swarm":
|
if not self.orchestrator or self.orchestrator == "swarm":
|
||||||
endpoint = self.endpoints.get("docker", None)
|
endpoint = self.endpoints.get("docker", None)
|
||||||
|
|
@ -235,6 +197,9 @@ class Context:
|
||||||
return self.endpoints[self.orchestrator].get("Host", None)
|
return self.endpoints[self.orchestrator].get("Host", None)
|
||||||
=======
|
=======
|
||||||
if self.orchestrator == "swarm":
|
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["docker"]["Host"]
|
||||||
return self.endpoints[self.orchestrator]["Host"]
|
return self.endpoints[self.orchestrator]["Host"]
|
||||||
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
|
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
|
||||||
|
|
@ -245,6 +210,7 @@ class Context:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def Metadata(self):
|
def Metadata(self):
|
||||||
|
<<<<<<< HEAD
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
meta = {}
|
meta = {}
|
||||||
if self.orchestrator:
|
if self.orchestrator:
|
||||||
|
|
@ -259,17 +225,29 @@ class Context:
|
||||||
"StackOrchestrator": self.orchestrator
|
"StackOrchestrator": self.orchestrator
|
||||||
},
|
},
|
||||||
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
|
>>>>>>> 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
|
"Endpoints": self.endpoints
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def TLSConfig(self):
|
def TLSConfig(self):
|
||||||
key = self.orchestrator
|
key = self.orchestrator
|
||||||
|
<<<<<<< HEAD
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
if not key or key == "swarm":
|
if not key or key == "swarm":
|
||||||
=======
|
=======
|
||||||
if key == "swarm":
|
if key == "swarm":
|
||||||
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
|
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
|
||||||
|
=======
|
||||||
|
if not key or key == "swarm":
|
||||||
|
>>>>>>> 1e11ece... Make orchestrator field optional
|
||||||
key = "docker"
|
key = "docker"
|
||||||
if key in self.tls_cfg.keys():
|
if key in self.tls_cfg.keys():
|
||||||
return self.tls_cfg[key]
|
return self.tls_cfg[key]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue