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
							
								
									105efa02a9
								
							
						
					
					
						commit
						31276df6a3
					
				|  | @ -14,11 +14,11 @@ class ContextAPI(object): | |||
|     Contains methods for context management: | ||||
|     create, list, remove, get, inspect. | ||||
|     """ | ||||
|     DEFAULT_CONTEXT = Context("default") | ||||
|     DEFAULT_CONTEXT = Context("default", "swarm") | ||||
| 
 | ||||
|     @classmethod | ||||
|     def create_context( | ||||
|             cls, name, orchestrator="swarm", host=None, tls_cfg=None, | ||||
|             cls, name, orchestrator=None, host=None, tls_cfg=None, | ||||
|             default_namespace=None, skip_tls_verify=False): | ||||
|         """Creates a new context. | ||||
|         Returns: | ||||
|  | @ -38,9 +38,7 @@ class ContextAPI(object): | |||
|         >>> print(ctx.Metadata) | ||||
|         { | ||||
|             "Name": "test", | ||||
|             "Metadata": { | ||||
|                 "StackOrchestrator": "swarm" | ||||
|             }, | ||||
|             "Metadata": {}, | ||||
|             "Endpoints": { | ||||
|                 "docker": { | ||||
|                     "Host": "unix:///var/run/docker.sock", | ||||
|  | @ -57,7 +55,9 @@ class ContextAPI(object): | |||
|         ctx = Context.load_context(name) | ||||
|         if ctx: | ||||
|             raise errors.ContextAlreadyExists(name) | ||||
|         endpoint = "docker" if orchestrator == "swarm" else orchestrator | ||||
|         endpoint = "docker" | ||||
|         if orchestrator and orchestrator != "swarm": | ||||
|             endpoint = orchestrator | ||||
|         ctx = Context(name, orchestrator) | ||||
|         ctx.set_endpoint( | ||||
|             endpoint, host, tls_cfg, | ||||
|  | @ -79,9 +79,7 @@ class ContextAPI(object): | |||
|         >>> print(ctx.Metadata) | ||||
|         { | ||||
|             "Name": "test", | ||||
|             "Metadata": { | ||||
|                 "StackOrchestrator": "swarm" | ||||
|             }, | ||||
|             "Metadata": {}, | ||||
|             "Endpoints": { | ||||
|                 "docker": { | ||||
|                 "Host": "unix:///var/run/docker.sock", | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ from docker.context.config import get_context_host | |||
| 
 | ||||
| class Context: | ||||
|     """A context.""" | ||||
|     def __init__(self, name, orchestrator="swarm", host=None, endpoints=None, | ||||
|     def __init__(self, name, orchestrator=None, host=None, endpoints=None, | ||||
|                  tls=False): | ||||
|         if not name: | ||||
|             raise Exception("Name not provided") | ||||
|  | @ -19,7 +19,7 @@ class Context: | |||
|         self.orchestrator = orchestrator | ||||
|         if not endpoints: | ||||
|             default_endpoint = "docker" if ( | ||||
|                 orchestrator == "swarm" | ||||
|                 not orchestrator or orchestrator == "swarm" | ||||
|                 ) else orchestrator | ||||
|             self.endpoints = { | ||||
|                 default_endpoint: { | ||||
|  | @ -85,7 +85,8 @@ class Context: | |||
|                         context {} : {}""".format(name, e)) | ||||
| 
 | ||||
|             return ( | ||||
|                 metadata["Name"], metadata["Metadata"]["StackOrchestrator"], | ||||
|                 metadata["Name"], | ||||
|                 metadata["Metadata"].get("StackOrchestrator", None), | ||||
|                 metadata["Endpoints"]) | ||||
|         return None, None, None | ||||
| 
 | ||||
|  | @ -162,7 +163,7 @@ class Context: | |||
| 
 | ||||
|     @property | ||||
|     def Host(self): | ||||
|         if self.orchestrator == "swarm": | ||||
|         if not self.orchestrator or self.orchestrator == "swarm": | ||||
|             return self.endpoints["docker"]["Host"] | ||||
|         return self.endpoints[self.orchestrator]["Host"] | ||||
| 
 | ||||
|  | @ -172,18 +173,19 @@ class Context: | |||
| 
 | ||||
|     @property | ||||
|     def Metadata(self): | ||||
|         meta = {} | ||||
|         if self.orchestrator: | ||||
|             meta = {"StackOrchestrator": self.orchestrator} | ||||
|         return { | ||||
|             "Name": self.name, | ||||
|             "Metadata": { | ||||
|                 "StackOrchestrator": self.orchestrator | ||||
|             }, | ||||
|             "Metadata": meta, | ||||
|             "Endpoints": self.endpoints | ||||
|         } | ||||
| 
 | ||||
|     @property | ||||
|     def TLSConfig(self): | ||||
|         key = self.orchestrator | ||||
|         if key == "swarm": | ||||
|         if not key or key == "swarm": | ||||
|             key = "docker" | ||||
|         if key in self.tls_cfg.keys(): | ||||
|             return self.tls_cfg[key] | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue