1+ import json
2+
13from cloudshell .workflow .orchestration .sandbox import Sandbox
24from 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 )
0 commit comments