Skip to content

Commit 9050bd5

Browse files
committed
updated readme
1 parent c4e3b3e commit 9050bd5

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

generic-orchestration-samples/setup_set_user_mail_on_apps/configure_apps.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
13
from cloudshell.workflow.orchestration.sandbox import Sandbox
24
from cloudshell.api.cloudshell_api import AppConfiguration, ConfigParam
35

@@ -14,6 +16,7 @@ def configure_sandbox_owner_mail_on_app(sandbox, components=None):
1416
"""
1517
api = sandbox.automation_api
1618
sb_id = sandbox.id
19+
logger = sandbox.logger
1720
sandbox_owner = sandbox.reservation_description.Owner
1821
owner_mail = api.GetUserDetails(sandbox_owner).Email
1922
if not owner_mail:
@@ -30,13 +33,23 @@ def configure_sandbox_owner_mail_on_app(sandbox, components=None):
3033
attr_value = attr_search[0].Value
3134
if attr_value.lower() == "true":
3235
target_resources.append(curr_resource)
36+
3337
if not target_resources:
34-
api.WriteMessageToReservationOutput(sb_id, "No target resources found to set mail on")
35-
return
38+
warn_msg = "No target resources found to set mail on"
39+
api.WriteMessageToReservationOutput(sb_id, warn_msg)
40+
logger.warn(warn_msg)
3641

42+
updated_app_names = [x.Name for x in target_resources]
43+
all_other_apps = [x for x in all_resources if x.Name not in updated_app_names and x.CreatedInReservation]
3744
app_configurations = []
3845
for resource in target_resources:
3946
app_configurations.append(AppConfiguration(AppName=resource.Name,
4047
ConfigParams=[ConfigParam(APP_CONFIG_PARAM, owner_mail)]))
41-
api.WriteMessageToReservationOutput(sb_id, "Configuring Apps with forwarded sandbox owner email: {}".format(sandbox_owner))
48+
for resource in all_other_apps:
49+
app_configurations.append(AppConfiguration(AppName=resource.Name, ConfigParams=[]))
50+
51+
config_msg = "Configuring following apps with sandbox owner email: {}\n{}".format(sandbox_owner,
52+
json.dumps(updated_app_names, indent=4))
53+
logger.info(config_msg)
54+
api.WriteMessageToReservationOutput(sb_id, config_msg)
4255
api.ConfigureApps(reservationId=sb_id, appConfigurations=app_configurations, printOutput=True)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Setup set user mail on apps
2+
This is sample script for getting user email and updating config parameter on target apps
3+
4+
## To use
5+
Set the following attribute on Generic Attribute Family
6+
`Update Mail`
7+
- boolean, default false
8+
9+
App param should be the following:
10+
`USER_MAIL`
11+
12+
Upload script as setup, python 2 or 3 both fine, and replace setup on target blueprint.
13+
14+
Note in main.py how default config is disabled and this is replacing it

0 commit comments

Comments
 (0)