Skip to content

Commit c4e3b3e

Browse files
committed
updated configure apps sample
1 parent f6026b5 commit c4e3b3e

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from cloudshell.workflow.orchestration.sandbox import Sandbox
2+
from cloudshell.workflow.orchestration.setup.default_setup_orchestrator import DefaultSetupWorkflow
3+
from configure_apps import configure_sandbox_owner_mail_on_app
4+
5+
sandbox = Sandbox()
6+
7+
DefaultSetupWorkflow().register(sandbox, enable_configuration=False)
8+
sandbox.workflow.add_to_configuration(configure_sandbox_owner_mail_on_app)
9+
sandbox.execute_setup()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from cloudshell.workflow.orchestration.sandbox import Sandbox
2+
from cloudshell.api.cloudshell_api import AppConfiguration, ConfigParam
3+
4+
TARGET_RESOURCE_BOOL_ATTRIBUTE = "Update Mail"
5+
APP_CONFIG_PARAM = "USER_MAIL"
6+
7+
8+
def configure_sandbox_owner_mail_on_app(sandbox, components=None):
9+
"""
10+
get user email and run configure apps on apps matching boolean attribute True on resource
11+
:param Sandbox sandbox:
12+
:param components:
13+
:return:
14+
"""
15+
api = sandbox.automation_api
16+
sb_id = sandbox.id
17+
sandbox_owner = sandbox.reservation_description.Owner
18+
owner_mail = api.GetUserDetails(sandbox_owner).Email
19+
if not owner_mail:
20+
raise ValueError("No email configured for user: {}".format(sandbox_owner))
21+
22+
# find apps with target attribute
23+
all_resources = api.GetReservationDetails(reservationId=sb_id, disableCache=True).ReservationDescription.Resources
24+
target_resources = []
25+
for curr_resource in all_resources:
26+
details = api.GetResourceDetails(curr_resource.Name)
27+
attrs = details.ResourceAttributes
28+
attr_search = [x for x in attrs if x.Name == TARGET_RESOURCE_BOOL_ATTRIBUTE]
29+
if attr_search:
30+
attr_value = attr_search[0].Value
31+
if attr_value.lower() == "true":
32+
target_resources.append(curr_resource)
33+
if not target_resources:
34+
api.WriteMessageToReservationOutput(sb_id, "No target resources found to set mail on")
35+
return
36+
37+
app_configurations = []
38+
for resource in target_resources:
39+
app_configurations.append(AppConfiguration(AppName=resource.Name,
40+
ConfigParams=[ConfigParam(APP_CONFIG_PARAM, owner_mail)]))
41+
api.WriteMessageToReservationOutput(sb_id, "Configuring Apps with forwarded sandbox owner email: {}".format(sandbox_owner))
42+
api.ConfigureApps(reservationId=sb_id, appConfigurations=app_configurations, printOutput=True)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cloudshell-orch-core>=3.4.0.0,<3.5.0.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

0 commit comments

Comments
 (0)