@@ -57,7 +57,11 @@ 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
60
61
"Host" : get_context_host (host , not skip_tls_verify ),
62
+ == == == =
63
+ "Host" : get_context_host (host ),
64
+ >> >> >> > 64 fdb32 ... Implement context management , lifecycle and unittests .
61
65
"SkipTLSVerify" : skip_tls_verify
62
66
}
63
67
if def_namespace :
@@ -71,20 +75,27 @@ def inspect(self):
71
75
72
76
@classmethod
73
77
def load_context (cls , name ):
78
+ < << << << HEAD
74
79
meta = Context ._load_meta (name )
75
80
if meta :
76
81
instance = cls (
77
82
meta ["Name" ],
78
83
orchestrator = meta ["Metadata" ].get ("StackOrchestrator" , None ),
79
84
endpoints = meta .get ("Endpoints" , None ))
80
85
instance .context_type = meta ["Metadata" ].get ("Type" , None )
86
+ == == == =
87
+ name , orchestrator , endpoints = Context ._load_meta (name )
88
+ if name :
89
+ instance = cls (name , orchestrator , endpoints = endpoints )
90
+ > >> >> >> 64 fdb32 ... Implement context management , lifecycle and unittests .
81
91
instance ._load_certs ()
82
92
instance .meta_path = get_meta_dir (name )
83
93
return instance
84
94
return None
85
95
86
96
@classmethod
87
97
def _load_meta (cls , name ):
98
+ < << << << HEAD
88
99
meta_file = get_meta_file (name )
89
100
if not os .path .isfile (meta_file ):
90
101
return None
@@ -109,6 +120,27 @@ def _load_meta(cls, name):
109
120
v .get ("SkipTLSVerify" , True ))
110
121
111
122
return metadata
123
+ == == == =
124
+ metadata = {}
125
+ meta_file = get_meta_file (name )
126
+ if os .path .isfile (meta_file ):
127
+ with open (meta_file ) as f :
128
+ try :
129
+ with open (meta_file ) as f :
130
+ metadata = json .load (f )
131
+ for k , v in metadata ["Endpoints" ].items ():
132
+ metadata ["Endpoints" ][k ]["SkipTLSVerify" ] = bool (
133
+ v ["SkipTLSVerify" ])
134
+ except (IOError , KeyError , ValueError ) as e :
135
+ # unknown format
136
+ raise Exception ("""Detected corrupted meta file for
137
+ context {} : {}""" .format (name , e ))
138
+
139
+ return (
140
+ metadata ["Name" ], metadata ["Metadata" ]["StackOrchestrator" ],
141
+ metadata ["Endpoints" ])
142
+ return None , None , None
143
+ >> >> >> > 64 fdb32 ... Implement context management , lifecycle and unittests .
112
144
113
145
def _load_certs (self ):
114
146
certs = {}
@@ -177,42 +209,63 @@ def __call__(self):
177
209
result .update (self .Storage )
178
210
return result
179
211
212
+ << << << < HEAD
180
213
def is_docker_host (self ):
181
214
return self .context_type is None
182
215
216
+ == == == =
217
+ >> >> >> > 64 fdb32 ... Implement context management , lifecycle and unittests .
183
218
@property
184
219
def Name (self ):
185
220
return self .name
186
221
187
222
@property
188
223
def Host (self ):
224
+ < << << << HEAD
189
225
if not self .orchestrator or self .orchestrator == "swarm" :
190
226
endpoint = self .endpoints .get ("docker" , None )
191
227
if endpoint :
192
228
return endpoint .get ("Host" , None )
193
229
return None
194
230
195
231
return self .endpoints [self .orchestrator ].get ("Host" , None )
232
+ == == == =
233
+ if self .orchestrator == "swarm" :
234
+ return self .endpoints ["docker" ]["Host" ]
235
+ return self .endpoints [self .orchestrator ]["Host" ]
236
+ >> >> >> > 64 fdb32 ... Implement context management , lifecycle and unittests .
196
237
197
238
@property
198
239
def Orchestrator (self ):
199
240
return self .orchestrator
200
241
201
242
@property
202
243
def Metadata (self ):
244
+ < << << << HEAD
203
245
meta = {}
204
246
if self .orchestrator :
205
247
meta = {"StackOrchestrator" : self .orchestrator }
206
248
return {
207
249
"Name" : self .name ,
208
250
"Metadata" : meta ,
251
+ == == == =
252
+ return {
253
+ "Name" : self .name ,
254
+ "Metadata" : {
255
+ "StackOrchestrator" : self .orchestrator
256
+ },
257
+ >> >> >> > 64 fdb32 ... Implement context management , lifecycle and unittests .
209
258
"Endpoints" : self .endpoints
210
259
}
211
260
212
261
@property
213
262
def TLSConfig (self ):
214
263
key = self .orchestrator
264
+ << < << << HEAD
215
265
if not key or key == "swarm" :
266
+ == == == =
267
+ if key == "swarm" :
268
+ >> >> >> > 64 fdb32 ... Implement context management , lifecycle and unittests .
216
269
key = "docker"
217
270
if key in self .tls_cfg .keys ():
218
271
return self .tls_cfg [key ]
0 commit comments