Skip to content

Commit 22ecced

Browse files
committed
updated ansible json sample
1 parent 726c96c commit 22ecced

File tree

17 files changed

+55
-566
lines changed

17 files changed

+55
-566
lines changed

automation_api_scripts/save_app_cp_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
server = "54.200.66.175"
1111
domain = "Global"
1212

13-
RESOURCE_NAME = "CentOS_ansible_test i-07997fdc8ccedb9a3"
14-
SANDBOX_ID = "63bba51e-7a67-4ff6-bd19-4268e477513a"
13+
RESOURCE_NAME = "CentOS_no_config_2G_Test i-095fe8bd6200b8854"
14+
SANDBOX_ID = "4814527a-139b-46a9-a9c5-b91d0ae33466"
1515

1616
api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)
1717

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import json
2+
3+
from cloudshell.api.cloudshell_api import ConfigParam, CloudShellAPISession, AppConfiguration
4+
5+
# static environment data - this will be pulled dynamically from sandbox in orchestration script
6+
DEPLOYED_APP_NAME = "<MY_APP_NAME>"
7+
JSON_PAYLOAD_PARAM_NAME = "<MY_JSON_PARAM>"
8+
SANDBOX_ID = "<LIVE_SANDBOX_ID>"
9+
10+
api = CloudShellAPISession(host="localhost", username="admin", password="admin", domain="Global")
11+
12+
# some mock data to forward as json
13+
my_data_dict = {
14+
"key1": "value1",
15+
"key2": "value2",
16+
}
17+
18+
# serialize to json
19+
my_json = json.dumps(my_data_dict)
20+
21+
# explicitly wrap with single quotes to be valid json when written to playbook vars file
22+
ansible_json_var = "'{}'".format(my_json)
23+
24+
config_params = [ConfigParam(Name=JSON_PAYLOAD_PARAM_NAME, Value=ansible_json_var)]
25+
config = AppConfiguration(AppName=DEPLOYED_APP_NAME, ConfigParams=config_params)
26+
api.ConfigureApps(reservationId=SANDBOX_ID, appConfigurations=[config], printOutput=True)

generic-orchestration-samples/show_sandbox_data/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

generic-orchestration-samples/show_sandbox_data/DEBUG.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

generic-orchestration-samples/show_sandbox_data/DEBUG_GLOBALS.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

generic-orchestration-samples/show_sandbox_data/README.md

Lines changed: 0 additions & 36 deletions
This file was deleted.

generic-orchestration-samples/show_sandbox_data/__init__.py

Whitespace-only changes.
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
from cloudshell.workflow.orchestration.sandbox import Sandbox
2-
from first_module import first_module_flow
2+
from cloudshell.api.cloudshell_api import CloudShellAPISession
3+
import json
4+
35

46
sandbox = Sandbox()
57

6-
first_module_flow(sandbox=sandbox, components=None)
8+
9+
def print_sandbox_data_keys(api: CloudShellAPISession, res_id: str):
10+
data = api.GetSandboxData(res_id)
11+
api.WriteMessageToReservationOutput(res_id, "=== All Sandbox Keys ===")
12+
for data in data.SandboxDataKeyValues:
13+
14+
# pretty print the JSON if valid
15+
try:
16+
data_val = json.dumps(json.loads(data.Value), indent=4)
17+
except Exception:
18+
data_val = data.Value
19+
outp = f"sb_data_key: {data.Key}\n{data_val}"
20+
21+
api.WriteMessageToReservationOutput(res_id, outp)
22+
api.WriteMessageToReservationOutput(res_id, "=========================")
23+
24+
25+
print_sandbox_data_keys(sandbox.automation_api, sandbox.id)

generic-orchestration-samples/show_sandbox_data/credentials.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

generic-orchestration-samples/show_sandbox_data/first_module.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)