@@ -57,15 +57,7 @@ def set_endpoint(
57
57
self , name = "docker" , host = None , tls_cfg = None ,
58
58
skip_tls_verify = False , def_namespace = None ):
59
59
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
- >> >> >> > 64 fdb32 ... Implement context management , lifecycle and unittests .
66
- == == == =
67
60
"Host" : get_context_host (host , not skip_tls_verify ),
68
- >> >> >> > 3 ce2d89 ... Specify when to use `tls` on Context constructor
69
61
"SkipTLSVerify" : skip_tls_verify
70
62
}
71
63
if def_namespace :
@@ -79,27 +71,20 @@ def inspect(self):
79
71
80
72
@classmethod
81
73
def load_context (cls , name ):
82
- < << << << HEAD
83
74
meta = Context ._load_meta (name )
84
75
if meta :
85
76
instance = cls (
86
77
meta ["Name" ],
87
78
orchestrator = meta ["Metadata" ].get ("StackOrchestrator" , None ),
88
79
endpoints = meta .get ("Endpoints" , None ))
89
80
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
- > >> >> >> 64 fdb32 ... Implement context management , lifecycle and unittests .
95
81
instance ._load_certs ()
96
82
instance .meta_path = get_meta_dir (name )
97
83
return instance
98
84
return None
99
85
100
86
@classmethod
101
87
def _load_meta (cls , name ):
102
- < << << << HEAD
103
88
meta_file = get_meta_file (name )
104
89
if not os .path .isfile (meta_file ):
105
90
return None
@@ -124,27 +109,6 @@ def _load_meta(cls, name):
124
109
v .get ("SkipTLSVerify" , True ))
125
110
126
111
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
- >> >> >> > 64 fdb32 ... Implement context management , lifecycle and unittests .
148
112
149
113
def _load_certs (self ):
150
114
certs = {}
@@ -213,18 +177,16 @@ def __call__(self):
213
177
result .update (self .Storage )
214
178
return result
215
179
216
- << << << < HEAD
217
180
def is_docker_host (self ):
218
181
return self .context_type is None
219
182
220
- == == == =
221
- >> >> >> > 64 fdb32 ... Implement context management , lifecycle and unittests .
222
183
@property
223
184
def Name (self ):
224
185
return self .name
225
186
226
187
@property
227
188
def Host (self ):
189
+ < << << << HEAD
228
190
< << << << HEAD
229
191
if not self .orchestrator or self .orchestrator == "swarm" :
230
192
endpoint = self .endpoints .get ("docker" , None )
@@ -235,6 +197,9 @@ def Host(self):
235
197
return self .endpoints [self .orchestrator ].get ("Host" , None )
236
198
== == == =
237
199
if self .orchestrator == "swarm" :
200
+ == == == =
201
+ if not self .orchestrator or self .orchestrator == "swarm" :
202
+ > >> >> >> 1e11 ece ... Make orchestrator field optional
238
203
return self .endpoints ["docker" ]["Host" ]
239
204
return self .endpoints [self .orchestrator ]["Host" ]
240
205
> >> >> >> 64 fdb32 ... Implement context management , lifecycle and unittests .
@@ -245,6 +210,7 @@ def Orchestrator(self):
245
210
246
211
@property
247
212
def Metadata (self ):
213
+ < << << << HEAD
248
214
< << << << HEAD
249
215
meta = {}
250
216
if self .orchestrator :
@@ -259,17 +225,29 @@ def Metadata(self):
259
225
"StackOrchestrator" : self .orchestrator
260
226
},
261
227
>> >> >> > 64 fdb32 ... 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
+ >> >> >> > 1e11 ece ... Make orchestrator field optional
262
236
"Endpoints" : self .endpoints
263
237
}
264
238
265
239
@property
266
240
def TLSConfig (self ):
267
241
key = self .orchestrator
242
+ << << < << HEAD
268
243
<< < << << HEAD
269
244
if not key or key == "swarm" :
270
245
== == == =
271
246
if key == "swarm" :
272
247
>> >> >> > 64 fdb32 ... Implement context management , lifecycle and unittests .
248
+ == == == =
249
+ if not key or key == "swarm" :
250
+ >> >> >> > 1e11 ece ... Make orchestrator field optional
273
251
key = "docker"
274
252
if key in self .tls_cfg .keys ():
275
253
return self .tls_cfg [key ]
0 commit comments