Skip to content

Commit 9e4e5eb

Browse files
committed
vcenter cluster sample
1 parent 42efaed commit 9e4e5eb

File tree

7 files changed

+65
-0
lines changed

7 files changed

+65
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SERVER = "<CS_HOST>"
2+
USER = "<CS_USER>"
3+
PASSWORD = "<CS_PASSWORD>"
4+
DOMAIN = "<CS_DOMAIN>"
5+
6+
VCENTER_DATASTORE = "<MY_DATASTORE>"
7+
SANDBOX_ID = "<SANDBOX_ID>"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
vcenter shell command reference
3+
https://github.com/QualiSystems/VMware-vCenter-Cloud-Provider-Shell-2G/blob/166724df98e0d6c67b16c047f8fb58de431ea4b3/src/drivermetadata.xml#L46
4+
"""
5+
from cloudshell.api.cloudshell_api import CloudShellAPISession, InputNameValue
6+
import config
7+
8+
api = CloudShellAPISession(host=config.SERVER,
9+
username=config.USER,
10+
password=config.PASSWORD,
11+
domain=config.DOMAIN)
12+
13+
sb_details = api.GetReservationDetails(config.SANDBOX_ID, disableCache=True).ReservationDescription
14+
resources = sb_details.Resources
15+
deployed_apps = [x for x in resources if x.VmDetails]
16+
cloud_provider = deployed_apps[0].VmDetails.CloudProviderFullName
17+
command_inputs = [InputNameValue("datastore_name", config.VCENTER_DATASTORE)]
18+
cluster_details = api.ExecuteCommand(reservationId=config.SANDBOX_ID,
19+
targetName=cloud_provider,
20+
targetType="Resource",
21+
commandName="get_cluster_usage",
22+
commandInputs=command_inputs,
23+
printOutput=True).Output
24+
print(cluster_details)

generic-orchestration-samples/setup/activate_topology_setup/__init__.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from cloudshell.workflow.orchestration.sandbox import Sandbox
2+
from cloudshell.workflow.orchestration.setup.default_setup_orchestrator import DefaultSetupWorkflow
3+
from check_vcenter_cluster import validate_cluster_flow
4+
5+
sandbox = Sandbox()
6+
DefaultSetupWorkflow().register(sandbox)
7+
sandbox.workflow.add_to_preparation(validate_cluster_flow)
8+
sandbox.execute_setup()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from cloudshell.workflow.orchestration.sandbox import Sandbox
2+
from cloudshell.helpers.sandbox_reporter.reporter import SandboxReporter
3+
4+
5+
def validate_cluster_flow(sandbox, components=None):
6+
"""
7+
Workflow functions must have (sandbox, components) signature
8+
:param Sandbox sandbox:
9+
"""
10+
api = sandbox.automation_api
11+
sb_id = sandbox.id
12+
logger = sandbox.logger
13+
reporter = SandboxReporter(api, sb_id, logger) # logs to file and print to sandbox console
14+
15+
reporter.warning("Validating Vcenter Cluster...")
16+
17+
sb_details = api.GetReservationDetails(reservationId=sb_id, disableCache=True).ReservationDescription
18+
apps = sb_details.Apps
19+
default_deployment = [x for x in apps[0].DeploymentPaths if x.IsDefault][0]
20+
cloud_provider = default_deployment.DeploymentService.CloudProvider
21+
api.ExecuteCommand()
22+
reporter.info(f"Resource count in sandbox: {len(resources)}")
23+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cloudshell-orch-core
2+
cloudshell-sandbox-reporter
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

0 commit comments

Comments
 (0)