Update checkout_account.py to not reuse connections
@@ -27,7 +27,8 @@ BOSKOS_HOST=os.environ.get("BOSKOS_HOST", "boskos")
RESOURCE_TYPE = "aws-account"
USER = "cluster-api-provider-aws"
-def post_request(conn, input_state = "free"):
+def post_request(host, input_state = "clean"):
+ conn = httplib.HTTPConnection(host)
conn.request("POST", "/acquire?%s" % urllib.urlencode({
'type': RESOURCE_TYPE,
'owner': USER,
@@ -36,22 +37,25 @@ def post_request(conn, input_state = "free"):
})
)
- return conn.getresponse()
+ resp = conn.getresponse()
+ status = resp.status
+ reason = resp.reason
+ body = resp.read()
+ conn.close()
+ return status, reason, body
if __name__ == "__main__":
- conn = httplib.HTTPConnection(BOSKOS_HOST)
-
- resp = post_request(conn)
+ status, reason, result = post_request(BOSKOS_HOST)
# we're working around an issue with the data in boskos.
# We'll remove the code that tries both free and clean once all the data is good.
- if resp.status == 404:
- resp = post_request(conn, "clean")
+ # Afterwards we should just check for free
+ if status == 404:
+ status, reason, result = post_request(BOSKOS_HOST, "free")
- if resp.status != 200:
- sys.exit("Got invalid response %d: %s" % (resp.status, resp.reason))
+ if status != 200:
+ sys.exit("Got invalid response %d: %s" % (status, reason))
- body = json.load(resp)
- conn.close()
+ body = json.load(result)
print 'export BOSKOS_RESOURCE_NAME="%s";' % body['name']
print 'export AWS_ACCESS_KEY_ID="%s";' % body['userdata']['access-key-id']
print 'export AWS_SECRET_ACCESS_KEY="%s";' % body['userdata']['secret-access-key']
