Skip to content

Commit 3999707

Browse files
author
aiordache
committed
Make orchestrator field optional
Signed-off-by: aiordache <[email protected]>
1 parent 2e274d0 commit 3999707

File tree

2 files changed

+17
-55
lines changed

2 files changed

+17
-55
lines changed

docker/context/api.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ def create_context(
3838
>>> print(ctx.Metadata)
3939
{
4040
"Name": "test",
41-
<<<<<<< HEAD
4241
"Metadata": {},
43-
=======
44-
"Metadata": {
45-
"StackOrchestrator": "swarm"
46-
},
47-
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
4842
"Endpoints": {
4943
"docker": {
5044
"Host": "unix:///var/run/docker.sock",
@@ -61,13 +55,9 @@ def create_context(
6155
ctx = Context.load_context(name)
6256
if ctx:
6357
raise errors.ContextAlreadyExists(name)
64-
<<<<<<< HEAD
6558
endpoint = "docker"
6659
if orchestrator and orchestrator != "swarm":
6760
endpoint = orchestrator
68-
=======
69-
endpoint = "docker" if orchestrator == "swarm" else orchestrator
70-
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
7161
ctx = Context(name, orchestrator)
7262
ctx.set_endpoint(
7363
endpoint, host, tls_cfg,
@@ -89,13 +79,7 @@ def get_context(cls, name=None):
8979
>>> print(ctx.Metadata)
9080
{
9181
"Name": "test",
92-
<<<<<<< HEAD
9382
"Metadata": {},
94-
=======
95-
"Metadata": {
96-
"StackOrchestrator": "swarm"
97-
},
98-
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
9983
"Endpoints": {
10084
"docker": {
10185
"Host": "unix:///var/run/docker.sock",

docker/context/context.py

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,7 @@ def set_endpoint(
5757
self, name="docker", host=None, tls_cfg=None,
5858
skip_tls_verify=False, def_namespace=None):
5959
self.endpoints[name] = {
60-
<<<<<<< HEAD
61-
<<<<<<< HEAD
62-
"Host": get_context_host(host, not skip_tls_verify),
63-
=======
64-
"Host": get_context_host(host),
65-
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
66-
=======
6760
"Host": get_context_host(host, not skip_tls_verify),
68-
>>>>>>> 3ce2d89... Specify when to use `tls` on Context constructor
6961
"SkipTLSVerify": skip_tls_verify
7062
}
7163
if def_namespace:
@@ -79,27 +71,20 @@ def inspect(self):
7971

8072
@classmethod
8173
def load_context(cls, name):
82-
<<<<<<< HEAD
8374
meta = Context._load_meta(name)
8475
if meta:
8576
instance = cls(
8677
meta["Name"],
8778
orchestrator=meta["Metadata"].get("StackOrchestrator", None),
8879
endpoints=meta.get("Endpoints", None))
8980
instance.context_type = meta["Metadata"].get("Type", None)
90-
=======
91-
name, orchestrator, endpoints = Context._load_meta(name)
92-
if name:
93-
instance = cls(name, orchestrator, endpoints=endpoints)
94-
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
9581
instance._load_certs()
9682
instance.meta_path = get_meta_dir(name)
9783
return instance
9884
return None
9985

10086
@classmethod
10187
def _load_meta(cls, name):
102-
<<<<<<< HEAD
10388
meta_file = get_meta_file(name)
10489
if not os.path.isfile(meta_file):
10590
return None
@@ -124,27 +109,6 @@ def _load_meta(cls, name):
124109
v.get("SkipTLSVerify", True))
125110

126111
return metadata
127-
=======
128-
metadata = {}
129-
meta_file = get_meta_file(name)
130-
if os.path.isfile(meta_file):
131-
with open(meta_file) as f:
132-
try:
133-
with open(meta_file) as f:
134-
metadata = json.load(f)
135-
for k, v in metadata["Endpoints"].items():
136-
metadata["Endpoints"][k]["SkipTLSVerify"] = bool(
137-
v["SkipTLSVerify"])
138-
except (IOError, KeyError, ValueError) as e:
139-
# unknown format
140-
raise Exception("""Detected corrupted meta file for
141-
context {} : {}""".format(name, e))
142-
143-
return (
144-
metadata["Name"], metadata["Metadata"]["StackOrchestrator"],
145-
metadata["Endpoints"])
146-
return None, None, None
147-
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
148112

149113
def _load_certs(self):
150114
certs = {}
@@ -213,18 +177,16 @@ def __call__(self):
213177
result.update(self.Storage)
214178
return result
215179

216-
<<<<<<< HEAD
217180
def is_docker_host(self):
218181
return self.context_type is None
219182

220-
=======
221-
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
222183
@property
223184
def Name(self):
224185
return self.name
225186

226187
@property
227188
def Host(self):
189+
<<<<<<< HEAD
228190
<<<<<<< HEAD
229191
if not self.orchestrator or self.orchestrator == "swarm":
230192
endpoint = self.endpoints.get("docker", None)
@@ -235,6 +197,9 @@ def Host(self):
235197
return self.endpoints[self.orchestrator].get("Host", None)
236198
=======
237199
if self.orchestrator == "swarm":
200+
=======
201+
if not self.orchestrator or self.orchestrator == "swarm":
202+
>>>>>>> 1e11ece... Make orchestrator field optional
238203
return self.endpoints["docker"]["Host"]
239204
return self.endpoints[self.orchestrator]["Host"]
240205
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
@@ -245,6 +210,7 @@ def Orchestrator(self):
245210

246211
@property
247212
def Metadata(self):
213+
<<<<<<< HEAD
248214
<<<<<<< HEAD
249215
meta = {}
250216
if self.orchestrator:
@@ -259,17 +225,29 @@ def Metadata(self):
259225
"StackOrchestrator": self.orchestrator
260226
},
261227
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
228+
=======
229+
meta = {}
230+
if self.orchestrator:
231+
meta = {"StackOrchestrator": self.orchestrator}
232+
return {
233+
"Name": self.name,
234+
"Metadata": meta,
235+
>>>>>>> 1e11ece... Make orchestrator field optional
262236
"Endpoints": self.endpoints
263237
}
264238

265239
@property
266240
def TLSConfig(self):
267241
key = self.orchestrator
242+
<<<<<<< HEAD
268243
<<<<<<< HEAD
269244
if not key or key == "swarm":
270245
=======
271246
if key == "swarm":
272247
>>>>>>> 64fdb32... Implement context management, lifecycle and unittests.
248+
=======
249+
if not key or key == "swarm":
250+
>>>>>>> 1e11ece... Make orchestrator field optional
273251
key = "docker"
274252
if key in self.tls_cfg.keys():
275253
return self.tls_cfg[key]

0 commit comments

Comments
 (0)