Skip to content

Commit

Permalink
Update checkout_account.py to not reuse connections (kubernetes-sigs#700
Browse files Browse the repository at this point in the history
)
  • Loading branch information
detiber committed May 2, 2019
1 parent e898d84 commit 72bebae
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions hack/checkout_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
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,
Expand All @@ -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']
Expand Down

0 comments on commit 72bebae

Please sign in to comment.