Fix bugs in Modules as part of inclusion discussion (#20)
* Remove hosted instance limited reached * Updated bug fixes for stack and contactPoint * indentation fixes * indetation fixes * Fix contactPoint out of scope issue * Fix stack_found usecase * Update cloud_stack.py * Update cloud_stack.py * Fix for sanity check * fixes * fix * fix sanity Co-authored-by: Ishan Jain <ishan.jain@gmail.com>
This commit is contained in:
parent
993776a3a8
commit
e103856767
@ -148,8 +148,7 @@ def present_alert_contact_point(module):
|
||||
if result.status_code == 202:
|
||||
return False, True, result.json()
|
||||
elif result.status_code == 500:
|
||||
api_url = 'https://' + module.params['stack_slug'] + '.grafana.net/api/v1/provisioning/contact-points/' + \
|
||||
module.params['uid']
|
||||
api_url = 'https://' + module.params['stack_slug'] + '.grafana.net/api/v1/provisioning/contact-points/' + module.params['uid']
|
||||
|
||||
result = requests.put(api_url, json=body, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
||||
|
||||
@ -158,9 +157,17 @@ def present_alert_contact_point(module):
|
||||
|
||||
result = requests.get(api_url, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
||||
|
||||
contactPointFound = False
|
||||
contactPointInfo = {}
|
||||
|
||||
for contact_points in result.json():
|
||||
if contact_points['uid'] == module.params['uid']:
|
||||
return False, True, contact_points
|
||||
contactPointFound = True
|
||||
contactPointInfo = contact_points
|
||||
if contactPointFound:
|
||||
return False, True, contactPointInfo
|
||||
else:
|
||||
return True, False, "Contact Point not found"
|
||||
else:
|
||||
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
||||
|
||||
|
@ -148,18 +148,24 @@ def present_cloud_stack(module):
|
||||
api_url = 'https://grafana.com/api/instances'
|
||||
|
||||
result = requests.post(api_url, json=body, headers={"Authorization": 'Bearer ' + module.params['cloud_api_key']})
|
||||
|
||||
if result.status_code == 200:
|
||||
return False, True, result.json()
|
||||
|
||||
elif result.status_code in [409, 403] and result.json()['message'] in ["That url is not available", "Hosted instance limit reached"]:
|
||||
api_url = 'https://grafana.com/api/orgs/' + module.params['org_slug'] + '/instances'
|
||||
|
||||
result = requests.get(api_url, headers={"Authorization": 'Bearer ' + module.params['cloud_api_key']})
|
||||
|
||||
for stack in result.json()['items']:
|
||||
if stack['slug'] == module.params['stack_slug']:
|
||||
return False, False, stack
|
||||
stack_found = False
|
||||
if result.json['message'] == "That url is not available":
|
||||
api_url = 'https://grafana.com/api/orgs/' + module.params['org_slug'] + '/instances'
|
||||
result = requests.get(api_url, headers={"Authorization": 'Bearer ' + module.params['cloud_api_key']})
|
||||
stackInfo = {}
|
||||
for stack in result.json()['items']:
|
||||
if stack['slug'] == module.params['stack_slug']:
|
||||
stack_found = True
|
||||
stackInfo = stack
|
||||
if stack_found:
|
||||
return False, False, stackInfo
|
||||
else:
|
||||
return True, False, "Stack is not found under your org"
|
||||
elif result.json['message'] == "Hosted instance limit reached":
|
||||
return True, False, "You have reached Maximum number of Cloud Stacks in your Org."
|
||||
else:
|
||||
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user