@@ -41,44 +41,51 @@ def getEnv(self, key):
41
41
class Composition :
42
42
43
43
def __init__ (self , context , composeFilesYaml , projectName = None ,
44
- force_recreate = True , components = []):
44
+ force_recreate = True , components = [], startContainers = True ):
45
45
if not projectName :
46
46
projectName = str (uuid .uuid1 ()).replace ('-' ,'' )
47
47
self .projectName = projectName
48
48
self .context = context
49
49
self .containerDataList = []
50
50
self .composeFilesYaml = composeFilesYaml
51
- self .serviceNames = []
52
- self .serviceNames = self ._collectServiceNames ()
53
- self .up (context , force_recreate , components )
51
+ if startContainers :
52
+ self .up (force_recreate , components )
54
53
55
- def _collectServiceNames (self ):
54
+ def collectServiceNames (self ):
56
55
'First collect the services names.'
57
56
servicesList = [service for service in self .issueCommand (["config" , "--services" ]).splitlines () if "WARNING" not in service ]
58
57
return servicesList
59
58
60
- def up (self , context , force_recreate = True , components = []):
61
- self .serviceNames = self ._collectServiceNames ()
59
+ def up (self , force_recreate = True , components = []):
60
+ self .serviceNames = self .collectServiceNames ()
62
61
command = ["up" , "-d" ]
63
62
if force_recreate :
64
63
command += ["--force-recreate" ]
65
64
self .issueCommand (command + components )
66
65
67
- def scale (self , context , serviceName , count = 1 ):
68
- self .serviceNames = self ._collectServiceNames ()
66
+ def scale (self , serviceName , count = 1 ):
67
+ self .serviceNames = self .collectServiceNames ()
69
68
command = ["scale" , "%s=%d" % (serviceName , count )]
70
69
self .issueCommand (command )
71
70
72
- def stop (self , context , components = []):
73
- self .serviceNames = self ._collectServiceNames ()
71
+ def stop (self , components = []):
72
+ self .serviceNames = self .collectServiceNames ()
74
73
command = ["stop" ]
75
74
self .issueCommand (command , components )
76
75
77
- def start (self , context , components = []):
78
- self .serviceNames = self ._collectServiceNames ()
76
+ def start (self , components = []):
77
+ self .serviceNames = self .collectServiceNames ()
79
78
command = ["start" ]
80
79
self .issueCommand (command , components )
81
80
81
+ def docker_exec (self , command , components = []):
82
+ results = {}
83
+ updatedCommand = " " .join (command )
84
+ for component in components :
85
+ execCommand = ["exec" , component , updatedCommand ]
86
+ results [component ] = self .issueCommand (execCommand , [])
87
+ return results
88
+
82
89
def parseComposeFilesArg (self , composeFileArgs ):
83
90
composeFileList = []
84
91
for composeFile in composeFileArgs .split ():
@@ -138,7 +145,8 @@ def issueCommand(self, command, components=[]):
138
145
cmdArgs = command + componentList
139
146
cmd = ["docker" ] + cmdArgs
140
147
141
- output = subprocess .check_output (cmd , env = self .getEnv ())
148
+ process = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , env = self .getEnv ())
149
+ output , _error = process .communicate ()
142
150
143
151
# Don't rebuild if ps command
144
152
if command [0 ] != "ps" and command [0 ] != "config" :
0 commit comments