components/docker/files/docker-support
changeset 7794 4953ab4958ad
parent 7177 86d14f182e82
equal deleted inserted replaced
7793:d390406a8e3f 7794:4953ab4958ad
     1 #!/usr/bin/python2.7
     1 #!/usr/bin/python2.7
     2 #
     2 #
     3 # Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
     3 # Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
     4 #
     4 #
     5 
     5 
     6 import argparse
     6 import argparse
     7 import httplib
     7 import httplib
     8 import json
     8 import json
    37 def do_api_get(url):
    37 def do_api_get(url):
    38     try:
    38     try:
    39         con = HTTPConnectionSocket(DOCKER_SOCK)
    39         con = HTTPConnectionSocket(DOCKER_SOCK)
    40         con.request("GET", url)
    40         con.request("GET", url)
    41         resp = con.getresponse()
    41         resp = con.getresponse()
    42     except httplib.HTTPException as err:
    42     except (socket.error, httplib.HTTPException) as err:
    43         raise RuntimeError("unable to call API: %s" % err)
    43         raise RuntimeError("unable to call API: %s" % err)
    44 
    44 
    45     # expect standard success status
    45     # expect standard success status
    46     if resp.status != 200:
    46     if resp.status != 200:
    47         raise RuntimeError("Unable to query Docker API: status [%s] "
    47         raise RuntimeError("Unable to query Docker API: status [%s] "
   167 def get_running_container_ids():
   167 def get_running_container_ids():
   168     try:
   168     try:
   169         return [container['Id'] for container in
   169         return [container['Id'] for container in
   170             do_api_get("http:/containers/json")]
   170             do_api_get("http:/containers/json")]
   171     except RuntimeError as e:
   171     except RuntimeError as e:
   172         print "unable to query api for container list: %s" % e
   172         raise SystemExit("unable to query api for container list: %s" % e)
   173 
   173 
   174 
   174 
   175 def kill_container(cid):
   175 def kill_container(cid):
   176     try:
   176     try:
   177         do_api_post("http:/containers/%s/kill" % cid)
   177         do_api_post("http:/containers/%s/kill" % cid)