@@ -44,13 +44,8 @@ async def deploy_static_config_studio_manifest_to_cv(manifest: AvdManifest, depl
4444
4545 # Perform synchronization tasks.
4646 await _sync_configlets (cv_manifest = cv_manifest , deployment_result = deployment_result , cv_client = cv_client )
47- existing_containers_by_id = await _sync_containers (cv_manifest = cv_manifest , deployment_result = deployment_result , cv_client = cv_client )
48- await _sync_studio_roots (
49- cv_manifest = cv_manifest ,
50- deployment_result = deployment_result ,
51- cv_client = cv_client ,
52- existing_containers_by_id = existing_containers_by_id ,
53- )
47+ await _sync_containers (cv_manifest = cv_manifest , deployment_result = deployment_result , cv_client = cv_client )
48+ await _sync_studio_roots (cv_manifest = cv_manifest , deployment_result = deployment_result , cv_client = cv_client )
5449
5550 # Done.
5651 LOGGER .info ("deploy_static_config_studio_manifest_to_cv: Completed manifest deployment for workspace '%s'." , workspace_id )
@@ -83,8 +78,21 @@ async def _sync_containers(cv_manifest: CVManifest, deployment_result: DeployToC
8378 else :
8479 LOGGER .info ("deploy_static_config_studio_manifest_to_cv: No container creations or updates are needed." )
8580
86- # Return all existing containers from CloudVision to be further processed if needed.
87- return existing_containers_by_id
81+ # Delete unused AVD-managed containers.
82+ desired_container_ids = {container .id for container in cv_manifest .containers }
83+ containers_to_delete = {
84+ container_id : cast ("str" , container .display_name )
85+ for container_id , container in existing_containers_by_id .items ()
86+ if container_id .startswith (AVD_ENTITY_PREFIX ) and container_id not in desired_container_ids
87+ }
88+
89+ if containers_to_delete :
90+ LOGGER .info ("deploy_static_config_studio_manifest_to_cv: Removing %d AVD-managed containers which are no longer used." , len (containers_to_delete ))
91+ deployment_result .removed_static_config_containers .extend (containers_to_delete .values ())
92+ # TODO: Build a 'delete_configlet_containers' gRPC API
93+ await gather (* [cv_client .delete_configlet_container (workspace_id = workspace_id , assignment_id = container_id ) for container_id in containers_to_delete ])
94+ else :
95+ LOGGER .info ("deploy_static_config_studio_manifest_to_cv: No AVD-managed container deletions are needed." )
8896
8997
9098async def _sync_configlets (cv_manifest : CVManifest , deployment_result : DeployToCvResult , cv_client : CVClient ) -> None :
@@ -117,11 +125,9 @@ async def _sync_configlets(cv_manifest: CVManifest, deployment_result: DeployToC
117125 LOGGER .info ("deploy_static_config_studio_manifest_to_cv: No AVD-managed configlet deletions are needed." )
118126
119127
120- async def _sync_studio_roots (
121- cv_manifest : CVManifest , deployment_result : DeployToCvResult , cv_client : CVClient , existing_containers_by_id : dict [str , ConfigletAssignment ]
122- ) -> None :
128+ async def _sync_studio_roots (cv_manifest : CVManifest , deployment_result : DeployToCvResult , cv_client : CVClient ) -> None :
123129 """
124- Synchronize Studio root containers. Update root container assignments and delete unused AVD-managed ones .
130+ Synchronize Studio root containers. Update root container assignments.
125131
126132 Note:
127133 During an update, this function reorders root containers. All AVD-managed
@@ -139,17 +145,14 @@ async def _sync_studio_roots(
139145 default_value = [],
140146 )
141147
142- # Calculate which desired roots are missing and which existing AVD-managed roots are stale .
148+ # Calculate which desired roots are missing.
143149 desired_root_ids = [container .id for container in cv_manifest .containers if container .is_root ]
144150 desired_root_ids_set = set (desired_root_ids )
145151 existing_root_ids_set = set (existing_root_ids )
146152 missing_ids = desired_root_ids_set - existing_root_ids_set
147- stale_avd_ids = {
148- container_id for container_id in existing_root_ids_set if container_id .startswith (AVD_ENTITY_PREFIX ) and container_id not in desired_root_ids_set
149- }
150153
151154 # Update the Studio root container list if necessary, preserving any manually added (non-AVD) root containers.
152- if missing_ids or stale_avd_ids :
155+ if missing_ids :
153156 LOGGER .info ("deploy_static_config_studio_manifest_to_cv: Updating Studio root container assignment list..." )
154157 manual_ids = [container_id for container_id in existing_root_ids if not container_id .startswith (AVD_ENTITY_PREFIX )]
155158 new_ordered_ids = desired_root_ids + manual_ids
@@ -162,19 +165,3 @@ async def _sync_studio_roots(
162165 )
163166 else :
164167 LOGGER .info ("deploy_static_config_studio_manifest_to_cv: Studio root container assignments are already in the desired state." )
165-
166- # Delete stale AVD-managed root containers that are no longer needed.
167- if stale_avd_ids :
168- LOGGER .info ("deploy_static_config_studio_manifest_to_cv: Removing %d stale AVD-managed root containers..." , len (stale_avd_ids ))
169- deployment_result .removed_static_config_root_containers .extend (
170- [
171- cast ("str" , existing_container .display_name )
172- for container_id in stale_avd_ids
173- if (existing_container := existing_containers_by_id .get (container_id )) is not None
174- ]
175- )
176-
177- # TODO: Build a 'delete_configlet_containers' gRPC API
178- await gather (* [cv_client .delete_configlet_container (workspace_id = workspace_id , assignment_id = container_id ) for container_id in stale_avd_ids ])
179- else :
180- LOGGER .info ("deploy_static_config_studio_manifest_to_cv: No AVD-managed root container deletions are needed." )
0 commit comments