Solved

JSON Formatting for Calm Variables

  • 10 August 2020
  • 8 replies
  • 1147 views

 

I need to define a NIC for my windows substrate as a variable.

current workflow:

User selects subnet string from predefined variable >

Pre-Create Parses and sets the subnet variable to the json from previous step.

 

The NIC can be connected to

one of n(x) subnets that are defined in the following escript:

subnet1 = {	"name": "name",    "uuid": "redacted_uuid"    }subnet2 = {	"name": "name",    "uuid": "redacted_uuid"    }subnet3 = {	"name": "name",    "uuid": "redacted_uuid"    }subnets = {    "Preprod": subnet1,    "Preprod": subnet2,    "Prod-IaaS": subnet3      }print("{}".format(json.dumps(subnets.get("@@{appSubnet}@@"))))

Output: @@{setSubnet}@@

Profile Configuration: 

 

This is where it breaks:

 

icon

Best answer by charan-49230 12 August 2020, 10:23

View original

This topic has been closed for comments

8 replies

Userlevel 1

Hey, 

Before printing the subnet json, do a json.dumps and print the same.

nic1=<value>

print “nic1=”,json.dumps(nic1)

 

I have formatted the output as you recommended. I am still seeing this issue.

Hey, 

Before printing the subnet json, do a json.dumps and print the same.

nic1=<value>

print “nic1=”,json.dumps(nic1)

 

I guess my question is if I only wanted to set my NIC as a variable that is plain text/json what would that look like?  because I set a variable to the following:

setSubnet:nic1="{"name": "BD-CTXApp-Prod-IaaS", "uuid": "015157ec-9c42-42d4-99ce-d5dcaef86dca"}"

and I set the NIC configuration to the same vairable and I got the same JSON failed to load issue.

Userlevel 1

Hey,

I used a precreate task and just did as below 

 

network_1 = {"name":"VLAN101","uuid":"e37b22d1-45be-49f6-8bf3-0c5dc69d68cf"}
print "network1={}".format(json.dumps(network_1))

 

This works for me. I could not attach the BP here. but the launch works without failure of load json.

Charan, Can you share the BP with me another way I am still unable to get this to work.

Userlevel 1
{"status":{},"contains_secrets":false,"product_version":"3.0.0.2","spec":{"description":"","resources":{"client_attrs":{"ebfd9773_deployment":{"y":172.5,"x":491.5}},"service_definition_list":[{"singleton":false,"action_list":[{"description":"System action for creating an application","type":"system","critical":false,"runbook":{"task_definition_list":[{"target_any_local_reference":{"kind":"app_service","name":"Service1"},"retries":"0","description":"","child_tasks_local_reference_list":[],"name":"76391e99_dag","attrs":{"edges":[],"type":""},"timeout_secs":"0","type":"DAG","variable_list":[]}],"description":"","name":"f4953dcc_runbook","main_task_local_reference":{"kind":"app_task","name":"76391e99_dag"},"variable_list":[]},"name":"action_create"},{"description":"System action for deleting an application. Deletes created VMs as well","type":"system","critical":false,"runbook":{"task_definition_list":[{"target_any_local_reference":{"kind":"app_service","name":"Service1"},"retries":"0","description":"","child_tasks_local_reference_list":[],"name":"898b4e91_dag","attrs":{"edges":[],"type":""},"timeout_secs":"0","type":"DAG","variable_list":[]}],"description":"","name":"866e0e5c_runbook","main_task_local_reference":{"kind":"app_task","name":"898b4e91_dag"},"variable_list":[]},"name":"action_delete"},{"description":"System action for starting an application","type":"system","critical":false,"runbook":{"task_definition_list":[{"target_any_local_reference":{"kind":"app_service","name":"Service1"},"retries":"0","description":"","child_tasks_local_reference_list":[],"name":"204e3ed0_dag","attrs":{"edges":[],"type":""},"timeout_secs":"0","type":"DAG","variable_list":[]}],"description":"","name":"89543b31_runbook","main_task_local_reference":{"kind":"app_task","name":"204e3ed0_dag"},"variable_list":[]},"name":"action_start"},{"description":"System action for stopping an application","type":"system","critical":false,"runbook":{"task_definition_list":[{"target_any_local_reference":{"kind":"app_service","name":"Service1"},"retries":"0","description":"","child_tasks_local_reference_list":[],"name":"6652ba34_dag","attrs":{"edges":[],"type":""},"timeout_secs":"0","type":"DAG","variable_list":[]}],"description":"","name":"0956ac06_runbook","main_task_local_reference":{"kind":"app_task","name":"6652ba34_dag"},"variable_list":[]},"name":"action_stop"},{"description":"System action for restarting an application","type":"system","critical":false,"runbook":{"task_definition_list":[{"target_any_local_reference":{"kind":"app_service","name":"Service1"},"retries":"0","description":"","child_tasks_local_reference_list":[],"name":"c5caff42_dag","attrs":{"edges":[],"type":""},"timeout_secs":"0","type":"DAG","variable_list":[]}],"description":"","name":"5e6e99ef_runbook","main_task_local_reference":{"kind":"app_task","name":"c5caff42_dag"},"variable_list":[]},"name":"action_restart"}],"depends_on_list":[],"name":"Service1","port_list":[],"tier":"","variable_list":[],"description":""}],"substrate_definition_list":[{"description":"","action_list":[{"description":"","type":"fragment","critical":false,"runbook":{"task_definition_list":[{"target_any_local_reference":{"kind":"app_substrate","name":"VM1"},"retries":"0","description":"","child_tasks_local_reference_list":[{"kind":"app_task","name":"Pre_create task1"}],"name":"79e9db74_dag","attrs":{"edges":[],"type":""},"timeout_secs":"0","type":"DAG","variable_list":[]},{"target_any_local_reference":{"kind":"app_substrate","name":"VM1"},"retries":"0","description":"","child_tasks_local_reference_list":[],"name":"Pre_create task1","attrs":{"exit_status":[],"script":"network_1 = {\"name\":\"VLAN101\",\"uuid\":\"e37b22d1-45be-49f6-8bf3-0c5dc69d68cf\"}\nprint \"network1={}\".format(json.dumps(network_1))","eval_variables":["network1"],"eval_scope":"local","type":"","script_type":"static"},"timeout_secs":"0","type":"SET_VARIABLE","variable_list":[]}],"description":"","name":"045282d5_runbook","main_task_local_reference":{"kind":"app_task","name":"79e9db74_dag"},"variable_list":[]},"name":"pre_action_create"},{"description":"","type":"fragment","critical":false,"runbook":{"task_definition_list":[{"target_any_local_reference":{"kind":"app_substrate","name":"VM1"},"retries":"0","description":"","child_tasks_local_reference_list":[],"name":"34b370a0_dag","attrs":{"edges":[],"type":""},"timeout_secs":"0","type":"DAG","variable_list":[]}],"description":"","name":"dfbe8681_runbook","main_task_local_reference":{"kind":"app_task","name":"34b370a0_dag"},"variable_list":[]},"name":"post_action_delete"}],"type":"AHV_VM","name":"VM1","readiness_probe":{"connection_type":"SSH","retries":"5","connection_protocol":"","connection_port":22,"address":"@@{platform.status.resources.nic_list[0].ip_endpoint_list[0].ip}@@","delay_secs":"60","disable_readiness_probe":false},"editables":{"create_spec":{"resources":{"nic_list":{},"serial_port_list":{}}}},"os_type":"Linux","create_spec":{"name":"vm-@@{calm_array_index}@@-@@{calm_time}@@","resources":{"nic_list":[{"nic_type":"NORMAL_NIC","ip_endpoint_list":[],"network_function_chain_reference":null,"network_function_nic_type":"INGRESS","mac_address":"","subnet_reference":{"kind":"subnet","type":"","name":"","uuid":"@@{network1.uuid}@@"},"type":""}],"serial_port_list":[],"guest_tools":null,"num_vcpus_per_socket":2,"num_sockets":1,"gpu_list":[],"memory_size_mib":4096,"parent_reference":null,"hardware_clock_timezone":"","guest_customization":null,"power_state":"ON","type":"","account_uuid":"bfd02a2b-1c42-41bc-8a4c-2999753d3142","boot_config":{"boot_device":{"type":"","disk_address":{"type":"","device_index":0,"adapter_type":"SCSI"}},"type":"","boot_type":"","mac_address":""},"disk_list":[{"data_source_reference":{"kind":"image","type":"","name":"CentOS-7-x86_64-1810","uuid":"653cda0e-f15f-4dfc-995b-04abd1bb1bd8"},"type":"","disk_size_mib":0,"volume_group_reference":null,"device_properties":{"type":"","disk_address":{"type":"","device_index":0,"adapter_type":"SCSI"},"device_type":"DISK"}}]},"availability_zone_reference":null,"backup_policy":null,"type":"","cluster_reference":null,"categories":""},"variable_list":[]}],"credential_definition_list":[{"username":"root","description":"","type":"PASSWORD","secret":{"attrs":{"is_secret_modified":false,"secret_reference":{}}},"name":"cred1"}],"package_definition_list":[{"description":"","action_list":[],"type":"DEB","service_local_reference_list":[{"kind":"app_service","name":"Service1"}],"name":"Package1","version":"","options":{"install_runbook":{"task_definition_list":[{"target_any_local_reference":{"kind":"app_package","name":"Package1"},"retries":"0","description":"","child_tasks_local_reference_list":[],"name":"f1c89927_dag","attrs":{"edges":[],"type":""},"timeout_secs":"0","type":"DAG","variable_list":[]}],"description":"","name":"23d26e27_runbook","main_task_local_reference":{"kind":"app_task","name":"f1c89927_dag"},"variable_list":[]},"type":"","uninstall_runbook":{"task_definition_list":[{"target_any_local_reference":{"kind":"app_package","name":"Package1"},"retries":"0","description":"","child_tasks_local_reference_list":[],"name":"fd446470_dag","attrs":{"edges":[],"type":""},"timeout_secs":"0","type":"DAG","variable_list":[]}],"description":"","name":"e8c6fdf8_runbook","main_task_local_reference":{"kind":"app_task","name":"fd446470_dag"},"variable_list":[]}},"variable_list":[]}],"app_profile_list":[{"deployment_create_list":[{"type":"GREENFIELD","action_list":[],"name":"ebfd9773_deployment","min_replicas":"1","default_replicas":"1","depends_on_list":[],"published_service_local_reference_list":[],"max_replicas":"1","package_local_reference_list":[{"kind":"app_package","name":"Package1"}],"substrate_local_reference":{"kind":"app_substrate","name":"VM1"},"variable_list":[],"description":""}],"description":"","action_list":[],"name":"Default","variable_list":[]}],"published_service_definition_list":[],"default_credential_local_reference":{"kind":"app_credential","name":"cred1"},"type":"USER"},"name":"MultiVMNicCreate"},"api_version":"3.0","metadata":{"last_update_time":"1597219714205178","kind":"blueprint","spec_version":4,"creation_time":"1597219520986477","name":"MultiVMNicCreate"}}

 

Userlevel 1

Uploaded the BP . can you check and let me know.

Charan,

 

I was not setting the variable correctly. The set variable task creates a new instance of a variable it does not overwrite any existing variables.

 

Once I properly configured the variable it accepted the json value.

Userlevel 1

Thanks for the update. Good to know now you are unblocked.