Skip to content

Commit 42284da

Browse files
committed
packaging api
1 parent ace9fee commit 42284da

File tree

7 files changed

+89
-15
lines changed

7 files changed

+89
-15
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from cloudshell.api.cloudshell_api import CloudShellAPISession
2+
3+
# set domain values
4+
SOURCE_DOMAIN = "QA"
5+
TARGET_DOMAIN = "SE"
6+
7+
8+
# start session
9+
api = CloudShellAPISession(host="localhost", username="admin", password="admin", domain="Global")
10+
11+
# find resources of target model
12+
domain_details = api.GetDomainDetails(domainName=TARGET_DOMAIN)
13+
resources = domain_details.Resources
14+
resource_names = [x.Name for x in resources]
15+
16+
blueprints = domain_details.Topologies
17+
blueprint_names = [x.Name for x in blueprints]
18+
19+
# add resources
20+
print(f"adding {len(resources)} resources")
21+
api.AddResourcesToDomain(domainName=TARGET_DOMAIN,
22+
resourcesNames=resource_names,
23+
includeDecendants=True)
24+
25+
print("adding topologies")
26+
api.AddTopologiesToDomain(domainName=TARGET_DOMAIN,
27+
topologyNames=blueprint_names)
28+
29+
print("script done")
Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
from cloudshell.api.cloudshell_api import CloudShellAPISession
22

3-
# add credentials
4-
user = "admin"
5-
password = "admin"
6-
server = "localhost"
7-
domain = "Global"
8-
93
# start session
10-
api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)
11-
4+
api = CloudShellAPISession(host="localhost", username="admin", password="admin", domain="Global")
125

13-
app = 'mock_1'
14-
# find resources of target model
15-
res_details = api.GetResourceDetails(resourceFullPath=app)
16-
x = api.GetResourceAvailability([app])
17-
pass
6+
# find resources in DB - specify models / family / attributes etc
7+
all_resources = api.FindResources(resourceModel="Putshell").Resources
8+
print(f"resource count found: {len(all_resources)}")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from cloudshell.api.cloudshell_api import CloudShellAPISession
2+
3+
user = "admin"
4+
password = "admin"
5+
server = "localhost"
6+
domain = "Global"
7+
8+
api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)
9+
10+
users = api.GetAllUsersDetails().Users
11+
print(f"total users in system: {len(users)}")
12+
pass

packaging-api-samples/packaging_api_demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# p.create(package_path)
1515

1616
# Load the package and prepare for edit
17+
p.top
1718
p.load(package_path)
1819
TopologyApp()
1920

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from quali_utils.quali_packaging import PackageEditor, TopologyApp, AppResource, AppResourceInner, DeploymentService
2+
3+
4+
PACKAGE_PATH = r"C:\Users\natti.k\Downloads\CloudShell Sandbox Template2\CloudShell Sandbox Template2.zip"
5+
LONG_ALIAS = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
6+
7+
p = PackageEditor()
8+
9+
p.load(PACKAGE_PATH)
10+
11+
bp_name = p.get_topology_names()[0]
12+
p.add_visual_connector(topology_name=bp_name,
13+
connector_alias=LONG_ALIAS,
14+
resource_source_name="BlueTeam Win10",
15+
resource_target_name="AppTestBase",
16+
source_family_type="Resource",
17+
target_family_type="Resource",
18+
direction="Bi")
19+
pass
20+
21+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import requests
2+
3+
4+
PACKAGE_PATH = r"C:\Users\natti.k\Downloads\CloudShell Sandbox Template2\CloudShell Sandbox Template2.zip"
5+
CS_SERVER = "192.168.85.74"
6+
7+
# login get token
8+
r = requests.put(f'http://{CS_SERVER}:9000/Api/Auth/Login', {"username": "admin", "password": "admin", "domain": "Global"})
9+
authcode = "Basic " + r.text[1:-1]
10+
11+
12+
# 2 Open the package before import
13+
fileobj = open(PACKAGE_PATH, 'rb')
14+
15+
# 3 Send to CloudShell by calling Import Package REST API
16+
r = requests.post(f'http://{CS_SERVER}:9000/API/Package/ImportPackage',
17+
headers={"Authorization": authcode},
18+
files={"file": fileobj})
19+
print(r.text)
20+
print(r.ok)

quali_api/suite_data.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"SuiteTemplateName": "uat demo",
2+
"SuiteTemplateName": "test suite",
33
"SuiteName": "Quali API Suite",
44
"Description": "this is a suite ran through API",
55
"Type": "TestShell",
@@ -18,7 +18,7 @@
1818
"StopOnError": false,
1919
"Tests": [
2020
{
21-
"TestPath": "TestShell\\Tests\\Shared\\Demo\\input_demo",
21+
"TestPath": "TestShell\\Tests\\Shared\\hello world",
2222
"State": null,
2323
"StartTime": null,
2424
"EndTime": null,

0 commit comments

Comments
 (0)