@@ -1126,7 +1126,7 @@ def start(self, container, *args, **kwargs):
11261126 self ._raise_for_status (res )
11271127
11281128 @utils .check_resource ('container' )
1129- def stats (self , container , decode = None , stream = True ):
1129+ def stats (self , container , decode = None , stream = True , one_shot = None ):
11301130 """
11311131 Stream statistics for a specific container. Similar to the
11321132 ``docker stats`` command.
@@ -1138,23 +1138,39 @@ def stats(self, container, decode=None, stream=True):
11381138 False by default.
11391139 stream (bool): If set to false, only the current stats will be
11401140 returned instead of a stream. True by default.
1141+ one_shot (bool): If set to true, Only get a single stat instead of
1142+ waiting for 2 cycles. Must be used with stream=false. False by
1143+ default.
11411144
11421145 Raises:
11431146 :py:class:`docker.errors.APIError`
11441147 If the server returns an error.
11451148
11461149 """
11471150 url = self ._url ("/containers/{0}/stats" , container )
1151+ params = {
1152+ 'stream' : stream
1153+ }
1154+ if one_shot is not None :
1155+ if utils .version_lt (self ._version , '1.41' ):
1156+ raise errors .InvalidVersion (
1157+ 'one_shot is not supported for API version < 1.41'
1158+ )
1159+ params ['one-shot' ] = one_shot
11481160 if stream :
1149- return self ._stream_helper (self ._get (url , stream = True ),
1161+ if one_shot :
1162+ raise errors .InvalidArgument (
1163+ 'one_shot is only available in conjunction with '
1164+ 'stream=False'
1165+ )
1166+ return self ._stream_helper (self ._get (url , params = params ),
11501167 decode = decode )
11511168 else :
11521169 if decode :
11531170 raise errors .InvalidArgument (
11541171 "decode is only available in conjunction with stream=True"
11551172 )
1156- return self ._result (self ._get (url , params = {'stream' : False }),
1157- json = True )
1173+ return self ._result (self ._get (url , params = params ), json = True )
11581174
11591175 @utils .check_resource ('container' )
11601176 def stop (self , container , timeout = None ):
0 commit comments