Skip to content

Commit

Permalink
Merge branch 'dchourasia:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dchourasia authored Nov 5, 2024
2 parents 21eb53d + 7a95cdd commit 51a1fbc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
25 changes: 11 additions & 14 deletions src/check_instances_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,17 @@ def sync_hcp_node_pools(cluster:oc_cluster):
totalNodes += newReplicas
print(f'now total nodes are {totalNodes}')

try:
if cluster.name == 'trustyai-rob':
payload = {'id': id,'labels':{},'taints':[],'replicas': replicas}
response = requests.patch(f'{api_server_base_url}/clusters_mgmt/v1/clusters/{cluster.id}/node_pools/{id}',
data=json.dumps(payload),
headers={'Authorization': f'Bearer {ocm_api_token}', 'Content-Type': 'application/json'})

print(f'reset the machine pool {id} with the original replica count {replicas} for cluster {cluster.name}')
print(response.status_code)
if response.status_code == 200:
totalNodes += replicas - newReplicas
print(f'now total nodes are back to {totalNodes}')
except:
print(traceback.format_exc())
# instantly resetting the node count to avoid additional cost
payload = {'id': id,'labels':{},'taints':[],'replicas': replicas}
response = requests.patch(f'{api_server_base_url}/clusters_mgmt/v1/clusters/{cluster.id}/node_pools/{id}',
data=json.dumps(payload),
headers={'Authorization': f'Bearer {ocm_api_token}', 'Content-Type': 'application/json'})

print(f'reset the machine pool {id} with the original replica count {replicas} for cluster {cluster.name}')
print(response.status_code)
if response.status_code == 200:
totalNodes += replicas - newReplicas
print(f'now total nodes are back to {totalNodes}')

return totalNodes

Expand Down
25 changes: 11 additions & 14 deletions src/resume_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,17 @@ def sync_hcp_node_pools(cluster:oc_cluster):
totalNodes += newReplicas
print(f'now total nodes are {totalNodes}')

try:
if cluster.name == 'trustyai-rob':
payload = {'id': id,'labels':{},'taints':[],'replicas': replicas}
response = requests.patch(f'{api_server_base_url}/clusters_mgmt/v1/clusters/{cluster.id}/node_pools/{id}',
data=json.dumps(payload),
headers={'Authorization': f'Bearer {ocm_api_token}', 'Content-Type': 'application/json'})

print(f'reset the machine pool {id} with the original replica count {replicas} for cluster {cluster.name}')
print(response.status_code)
if response.status_code == 200:
totalNodes += replicas - newReplicas
print(f'now total nodes are back to {totalNodes}')
except:
print(traceback.format_exc())
#instantly resetting the node count to avoid additional cost
payload = {'id': id,'labels':{},'taints':[],'replicas': replicas}
response = requests.patch(f'{api_server_base_url}/clusters_mgmt/v1/clusters/{cluster.id}/node_pools/{id}',
data=json.dumps(payload),
headers={'Authorization': f'Bearer {ocm_api_token}', 'Content-Type': 'application/json'})

print(f'reset the machine pool {id} with the original replica count {replicas} for cluster {cluster.name}')
print(response.status_code)
if response.status_code == 200:
totalNodes += replicas - newReplicas
print(f'now total nodes are back to {totalNodes}')


time.sleep(30)
Expand Down

0 comments on commit 51a1fbc

Please sign in to comment.