Skip to content

Commit 2666853

Browse files
committed
added py3 support to quali api wrapper
1 parent 0102fd1 commit 2666853

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+891
-400
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ DEBUG/
33
quali_api_sanity_exe/
44
*.zip
55
Orchestration-Templates/
6-
Bug-exploration/
6+
Bug-exploration/
7+
*.pyc

automation_api_scripts/delete-sandboxes/delete_ALL_sandboxes.py

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

automation_api_scripts/delete-sandboxes/delete_sandboxes_with_target_users.py

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

automation_api_scripts/refresh_apps_from_template.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
server = "localhost"
66
domain = "Global"
77

8-
api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)
8+
SANDBOX_ID = "3bac3765-ba86-4ad3-819b-3a2127c1cbef"
99

10-
res_id = "3bac3765-ba86-4ad3-819b-3a2127c1cbef"
11-
blueprint_name = "L1 connectivity - 9.2 Ogura Test"
10+
api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)
1211

13-
res = api.ActivateTopology(reservationId=res_id, topologyFullPath=blueprint_name)
14-
pass
12+
api
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import time
2+
import json
3+
from cloudshell.api.cloudshell_api import CloudShellAPISession, CloudShellAPIError
4+
import xml.etree.ElementTree as ET
5+
import datetime
6+
7+
user = "admin"
8+
password = "HVUUZ0e2FwAEyGoC5kKp"
9+
# server = "localhost"
10+
server = "54.200.66.175"
11+
domain = "Global"
12+
13+
RESOURCE_NAME = "CentOS_ansible_test i-07997fdc8ccedb9a3"
14+
SANDBOX_ID = "63bba51e-7a67-4ff6-bd19-4268e477513a"
15+
16+
api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)
17+
18+
result = json.loads(api.ExecuteResourceConnectedCommand(reservationId=SANDBOX_ID,
19+
resourceFullPath=RESOURCE_NAME,
20+
commandName='save_app',
21+
commandTag='remote_connectivity',
22+
parameterValues=[],
23+
connectedPortsFullPath=[],
24+
printOutput=True).Output)
25+
print(result)

automation_api_scripts/set_key_and_rerun_setup_to_set_as_active.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@
55
server = "localhost"
66
domain = "Global"
77

8-
SANDBOX_ID = "bf3e93a5-5221-4f7d-acac-cf6876f17fe5"
8+
SANDBOX_ID = "b8e1aea9-4d65-43c9-ac0d-227842fe5773"
99

1010
api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)
1111

12-
# SET DATA
13-
data1 = SandboxDataKeyValue("Key1", "my info 1")
14-
data2 = SandboxDataKeyValue("Key2", "my info 2")
15-
data_list = [data1, data2]
16-
api.SetSandboxData(reservationId=SANDBOX_ID, sandboxDataKeyValues=data_list)
17-
18-
# GET DATA
19-
sb_data = api.GetSandboxData(SANDBOX_ID).SandboxDataKeyValues
20-
for item in sb_data:
21-
print("Key: {}, Value: {}".format(item.Key, item.Value))
12+
api.ExecuteEnvironmentCommand(reservationId=SANDBOX_ID,
13+
commandName="Setup")
14+
15+
api
16+
# # SET DATA
17+
# data1 = SandboxDataKeyValue("Key1", "my info 1")
18+
# data2 = SandboxDataKeyValue("Key2", "my info 2")
19+
# data_list = [data1, data2]
20+
# api.SetSandboxData(reservationId=SANDBOX_ID, sandboxDataKeyValues=data_list)
21+
#
22+
# # GET DATA
23+
# sb_data = api.GetSandboxData(SANDBOX_ID).SandboxDataKeyValues
24+
# for item in sb_data:
25+
# print("Key: {}, Value: {}".format(item.Key, item.Value))
2226

2327

2428

automation_api_scripts/set_resource_address.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
user = "admin"
44
password = "admin"
55
server = "localhost"
6+
domain = "Global"
67

7-
my_resources = ["myAzure", "myVcenter"]
8+
RESOURCE_NAME = "mock1"
9+
TARGET_IP = "192.168.5.1"
810

9-
api = CloudShellAPISession(host=server, username=user, password=password, domain="Global")
11+
api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)
1012

11-
print("setting Live statuses....")
13+
print("Setting resource '{}' to IP '{}'".format(RESOURCE_NAME, TARGET_IP))
1214

13-
for resource_name in my_resources:
14-
api.SetResourceLiveStatus(resourceFullName=resource_name, liveStatusName="Online",
15-
additionalInfo="This was set by admin script")
16-
17-
print("Done.")
15+
api.UpdateResourceAddress(resourceFullPath=RESOURCE_NAME,
16+
resourceAddress=TARGET_IP)
1817

18+
print("done.")

automation_api_scripts/set_sandbox_resources_status_online.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33
user = "admin"
44
password = "admin"
55
server = "localhost"
6+
domain = "Global"
67

7-
my_resources = ["myAzure", "myVcenter"]
8+
SANDBOX_ID = "b8e1aea9-4d65-43c9-ac0d-227842fe5773"
89

9-
api = CloudShellAPISession(host=server, username=user, password=password, domain="Global")
10+
api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)
1011

11-
print("setting Live statuses....")
12+
sandbox_details = api.GetReservationDetails(reservationId=SANDBOX_ID, disableCache=True).ReservationDescription
1213

13-
for resource_name in my_resources:
14-
api.SetResourceLiveStatus(resourceFullName=resource_name, liveStatusName="Online",
15-
additionalInfo="This was set by admin script")
14+
print("setting Live statuses on resources in sandbox '{}'....".format(sandbox_details.Name))
15+
16+
for resource in sandbox_details.Resources:
17+
print("Setting resource '{}'...".format(resource.Name))
18+
api.SetResourceLiveStatus(resourceFullName=resource.Name,
19+
liveStatusName="Online",
20+
additionalInfo="Resource is online")
1621

1722
print("Done.")
1823

automation_api_scripts/set_sandbox_stage_to_end.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
server = "localhost"
66
domain = "Global"
77

8-
SANDBOX_ID = "b8e1aea9-4d65-43c9-ac0d-227842fe5773"
8+
SANDBOX_ID = "fbdd8ce6-d68f-424c-a520-234547a07f2c"
99

1010
api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)
1111

1212
sandbox_details = api.GetReservationDetails(reservationId=SANDBOX_ID, disableCache=True).ReservationDescription
1313

14-
print("setting Live statuses on resources in sandbox '{}'....".format(sandbox_details.Name))
14+
print("setting sandbox stage to end in sandbox '{}'....".format(sandbox_details.Name))
1515

16-
for resource in sandbox_details.Resources:
17-
print("Setting resource '{}'...".format(resource.Name))
18-
api.SetResourceLiveStatus(resourceFullName=resource.Name,
19-
liveStatusName="Online",
20-
additionalInfo="Resource is online")
16+
api.SetSetupStage(setupStage="Ended", reservationId=SANDBOX_ID)
2117

2218
print("Done.")
2319

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from cloudshell.api.cloudshell_api import CloudShellAPISession, UpdateTopologyGlobalInputsRequest
2+
3+
# cloudshel credentials
4+
user = "admin"
5+
password = "admin"
6+
server = "localhost"
7+
domain = "Global"
8+
9+
TARGET_BLUEPRINT = "qualix tag dev"
10+
11+
api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)
12+
13+
global_inputs = [UpdateTopologyGlobalInputsRequest(ParamName="My Input", Value="whatever")]
14+
15+
try:
16+
response = api.CreateImmediateTopologyReservation(reservationName="test sandbox",
17+
owner="admin",
18+
durationInMinutes=60,
19+
notifyOnStart=True,
20+
notifyOnEnd=True,
21+
notificationMinutesBeforeEnd=10,
22+
topologyFullPath=TARGET_BLUEPRINT,
23+
globalInputs=global_inputs,
24+
notifyOnSetupComplete=True).Reservation
25+
except Exception as e:
26+
exc_msg = "'{}' blueprint start failed.\n{}: {}".format(TARGET_BLUEPRINT, type(e).__name__, str(e))
27+
raise Exception(exc_msg)
28+
29+
print("Sandbox {} started".format(response.Id))
30+
31+

0 commit comments

Comments
 (0)