Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
Update bosh client to return task_id on post
Browse files Browse the repository at this point in the history
  • Loading branch information
danhigham committed Aug 9, 2016
1 parent 9b32238 commit f4a9cce
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions install_steps/bosh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ def post(self, url, data, content_type):

s.headers.update({'Authorization': "Basic %s" % base64string})
result = s.post(url, data=data, verify=False, allow_redirects=False)
return result

if result.status_code == 302:
m = re.search('\/tasks\/(\d+)', result.headers['location'])
task_id = m.group(1)

return task_id
else:
return result.text

def wait_for_task(self, task_id):
events = []
Expand Down Expand Up @@ -97,8 +104,7 @@ def get_deployments(self):
def create_deployment(self, manifest):
deployments_url = "{0}/deployments".format(self.bosh_url)
result = self.post(deployments_url, manifest, 'text/yaml')
task_id = json.loads(result.read())["id"]
return task_id
return result

def run_errand(self, deployment_name, errand_name):
errand_url = "{0}/deployments/{1}/errands/{2}/runs".format(
Expand All @@ -107,8 +113,7 @@ def run_errand(self, deployment_name, errand_name):
errand_name
)
result = self.post(errand_url, "{}", 'application/json')
task_id = json.loads(result.read())["id"]
return task_id
return result

def get_task(self, task_id):
task_url = "{0}/tasks/{1}".format(
Expand All @@ -135,25 +140,13 @@ def upload_stemcell(self, stemcell_url):
stemcells_url = "{0}/stemcells".format(self.bosh_url)
payload = '{"location":"%s"}' % stemcell_url
result = self.post(stemcells_url, payload, 'application/json')
if result.status_code == 302:
m = re.search('\/tasks\/(\d+)', result.headers['location'])
task_id = m.group(1)

return task_id
else:
return None
return result

def upload_release(self, release_url):
releases_url = "{0}/releases".format(self.bosh_url)
payload = '{"location":"%s"}' % release_url
result = self.post(releases_url, payload, 'application/json')
if result.status_code == 302:
m = re.search('\/tasks\/(\d+)', result.headers['location'])
task_id = m.group(1)

return task_id
else:
return None
return result

def ip_table(self, deployment_name):
url = "{0}/deployments/{1}/vms?format=full".format(
Expand Down

0 comments on commit f4a9cce

Please sign in to comment.