Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix account fetching logic in create environment to use cluster uuid instead of cluster name #15

Open
wants to merge 1 commit into
base: release/calm-3.7.2.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tenant_onboarding/Tenant Onboarding with AD.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Tenant_onboarding/Tenant Onboarding with IDP.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions scripts/Tenant_onboarding_IDP/create_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def _build_url(scheme, resource_type, host=PC_IP, **params):
else:
url += "/{0}".format(resource_type)
return url

def get_cluster_account_uuid():
cluster_name = "@@{cluster_name}@@".strip()
cluster_uuid = "@@{cluster_uuid}@@".strip()
account_name = "@@{account_name}@@".strip()
url = _build_url(scheme="https",host="localhost",resource_type="/accounts/list")
data = requests.post(url, json={"kind":"account","length": 250},
Expand All @@ -31,19 +31,19 @@ def get_cluster_account_uuid():
if not data.ok:
print("Error while fetching account details. -->", data.json())
exit(1)

if account_name in str(data.json()):
for new_data in data.json()['entities']:
if new_data['metadata']['name'] == account_name:
for _cluster in new_data["status"]["resources"]["data"]["cluster_account_reference_list"]:
if _cluster["resources"]["data"]["cluster_name"] == cluster_name:
return _cluster["uuid"]
for _account in new_data["status"]["resources"]["data"]["cluster_account_reference_list"]:
if _account["resources"]["data"]["cluster_uuid"] == cluster_uuid:
return _account["uuid"]
print("Error : %s account not present on %s"%(account_name,PC_IP))
exit(1)
else:
print("Error : %s account not present on %s"%(account_name,PC_IP))
exit(1)

def _get_spec():
tenantuuid = "@@{tenant_uuid}@@"
account = get_cluster_account_uuid()
Expand All @@ -54,21 +54,21 @@ def _get_spec():
project_subnet = @@{overlay_subnet_details}@@
env_memory = (@@{project_memory}@@ / 2) * 1024
subnet_references = []

connection_type = "POWERSHELL"
connection_port = 5985
connection_protocol = "http"
if "@@{environment_os}@@" == "Linux":
connection_type = "SSH"
connection_port = 22
connection_protocol = ""

nic_list = []
nics = {}
nics['subnet_reference'] = {'uuid': project_subnet["uuid"]}
subnet_references.append({'uuid': project_subnet["uuid"]})
nic_list.append(nics)

url = _build_url(scheme="https",
resource_type="/idempotence_identifiers")
data = requests.post(url, json={"count": 2,"valid_duration_in_minutes": 527040},
Expand All @@ -95,7 +95,7 @@ def _get_spec():
},
"uuid": creds_uuid
}]

if _creds_type == "KEY":
_pass = {"passphrase": {
"attrs": {
Expand Down Expand Up @@ -143,7 +143,7 @@ def _get_spec():

serial_port = []
serial_port.append({"index": 0, "is_connected": True})

return ({
"api_version": "3.0",
"metadata": {
Expand Down Expand Up @@ -191,7 +191,7 @@ def _get_spec():
"num_vcpus_per_socket": 1,
"memory_size_mib": env_memory,
"account_uuid": account

},
"categories": {"TenantName":"@@{tenant_name}@@".strip()}
},
Expand Down Expand Up @@ -239,13 +239,13 @@ def create_env():
guest_customization = {"cloud_init":{"user_data": """@@{guest_customization_script}@@"""}}
payload['spec']['resources']['substrate_definition_list'][0]['create_spec']\
['resources']['guest_customization'] = guest_customization

url = _build_url(scheme="https",host="localhost", resource_type="/environments")
data = requests.post(url, json=payload,
auth=HTTPBasicAuth(management_username,management_password),
timeout=None, verify=False)
if not data.ok:
print("Error while creating environment ---> ",data.json().get('message_list',
print("Error while creating environment ---> ",data.json().get('message_list',
data.json().get('error_detail', data.json())))
exit(1)
return {"uuid": data.json()['metadata']['uuid'],
Expand All @@ -254,4 +254,4 @@ def create_env():
environment = {}
if "@@{create_environment}@@".lower() == "yes":
environment = create_env()
print("environment_details={}".format(environment))
print("environment_details={}".format(environment))
30 changes: 15 additions & 15 deletions scripts/Tenant_onboarding_runbook/create_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def _build_url(scheme, resource_type, host=PC_IP, **params):
else:
url += "/{0}".format(resource_type)
return url

def get_cluster_account_uuid():
cluster_name = "@@{cluster_name}@@".strip()
cluster_uuid = "@@{cluster_uuid}@@".strip()
account_name = "@@{account_name}@@".strip()
url = _build_url(scheme="https",host="localhost",resource_type="/accounts/list")
data = requests.post(url, json={"kind":"account","length": 250},
Expand All @@ -31,19 +31,19 @@ def get_cluster_account_uuid():
if not data.ok:
print("Error while fetching account details. -->", data.json())
exit(1)

if account_name in str(data.json()):
for new_data in data.json()['entities']:
if new_data['metadata']['name'] == account_name:
for _cluster in new_data["status"]["resources"]["data"]["cluster_account_reference_list"]:
if _cluster["resources"]["data"]["cluster_name"] == cluster_name:
return _cluster["uuid"]
for _account in new_data["status"]["resources"]["data"]["cluster_account_reference_list"]:
if _account["resources"]["data"]["cluster_uuid"] == cluster_uuid:
return _account["uuid"]
print("Error : %s account not present on %s"%(account_name,PC_IP))
exit(1)
else:
print("Error : %s account not present on %s"%(account_name,PC_IP))
exit(1)

def _get_spec():
tenantuuid = "@@{tenant_uuid}@@"
account = get_cluster_account_uuid()
Expand All @@ -54,21 +54,21 @@ def _get_spec():
project_subnet = @@{overlay_subnet_details}@@
env_memory = (@@{project_memory}@@ / 2) * 1024
subnet_references = []

connection_type = "POWERSHELL"
connection_port = 5985
connection_protocol = "http"
if "@@{environment_os}@@" == "Linux":
connection_type = "SSH"
connection_port = 22
connection_protocol = ""

nic_list = []
nics = {}
nics['subnet_reference'] = {'uuid': project_subnet["uuid"]}
subnet_references.append({'uuid': project_subnet["uuid"]})
nic_list.append(nics)

url = _build_url(scheme="https",
resource_type="/idempotence_identifiers")
data = requests.post(url, json={"count": 2,"valid_duration_in_minutes": 527040},
Expand All @@ -95,7 +95,7 @@ def _get_spec():
},
"uuid": creds_uuid
}]

if _creds_type == "KEY":
_pass = {"passphrase": {
"attrs": {
Expand Down Expand Up @@ -143,7 +143,7 @@ def _get_spec():

serial_port = []
serial_port.append({"index": 0, "is_connected": True})

return ({
"api_version": "3.0",
"metadata": {
Expand Down Expand Up @@ -191,7 +191,7 @@ def _get_spec():
"num_vcpus_per_socket": 1,
"memory_size_mib": env_memory,
"account_uuid": account

},
"categories": {"TenantName":"@@{tenant_name}@@".strip()}
},
Expand Down Expand Up @@ -239,13 +239,13 @@ def create_env():
guest_customization = {"cloud_init":{"user_data": """@@{guest_customization_script}@@"""}}
payload['spec']['resources']['substrate_definition_list'][0]['create_spec']\
['resources']['guest_customization'] = guest_customization

url = _build_url(scheme="https",host="localhost", resource_type="/environments")
data = requests.post(url, json=payload,
auth=HTTPBasicAuth(management_username,management_password),
timeout=None, verify=False)
if not data.ok:
print("Error while creating environment ---> ",data.json().get('message_list',
print("Error while creating environment ---> ",data.json().get('message_list',
data.json().get('error_detail', data.json())))
exit(1)
return {"uuid": data.json()['metadata']['uuid'],
Expand Down