|
43 | 43 | get_container_app_if_exists, |
44 | 44 | trigger_workflow, |
45 | 45 | _ensure_location_allowed, |
46 | | - register_provider_if_needed |
| 46 | + register_provider_if_needed, |
| 47 | + validate_environment_location |
47 | 48 | ) |
48 | 49 |
|
49 | 50 | from ._constants import MAXIMUM_SECRET_LENGTH, LOG_ANALYTICS_RP, CONTAINER_APPS_RP, ACR_IMAGE_SUFFIX, MAXIMUM_CONTAINER_APP_NAME_LENGTH |
@@ -810,58 +811,6 @@ def find_existing_acr(cmd, app: "ContainerApp"): |
810 | 811 | return None, None |
811 | 812 |
|
812 | 813 |
|
813 | | -def validate_environment_location(cmd, location): |
814 | | - from ._constants import MAX_ENV_PER_LOCATION |
815 | | - env_list = list_managed_environments(cmd) |
816 | | - |
817 | | - locations = [loc["location"] for loc in env_list] |
818 | | - locations = list(set(locations)) # remove duplicates |
819 | | - |
820 | | - location_count = {} |
821 | | - for loc in locations: |
822 | | - location_count[loc] = len([e for e in env_list if e["location"] == loc]) |
823 | | - |
824 | | - disallowed_locations = [] |
825 | | - for _, value in enumerate(location_count): |
826 | | - if location_count[value] > MAX_ENV_PER_LOCATION - 1: |
827 | | - disallowed_locations.append(value) |
828 | | - |
829 | | - res_locations = list_environment_locations(cmd) |
830 | | - res_locations = [loc for loc in res_locations if loc not in disallowed_locations] |
831 | | - |
832 | | - allowed_locs = ", ".join(res_locations) |
833 | | - |
834 | | - if location: |
835 | | - try: |
836 | | - _ensure_location_allowed(cmd, location, CONTAINER_APPS_RP, "managedEnvironments") |
837 | | - except Exception as e: # pylint: disable=broad-except |
838 | | - raise ValidationError("You cannot create a Containerapp environment in location {}. List of eligible locations: {}.".format(location, allowed_locs)) from e |
839 | | - |
840 | | - if len(res_locations) > 0: |
841 | | - if not location: |
842 | | - logger.warning("Creating environment on location {}.".format(res_locations[0])) |
843 | | - return res_locations[0] |
844 | | - if location in disallowed_locations: |
845 | | - raise ValidationError("You have more than {} environments in location {}. List of eligible locations: {}.".format(MAX_ENV_PER_LOCATION, location, allowed_locs)) |
846 | | - return location |
847 | | - else: |
848 | | - raise ValidationError("You cannot create any more environments. Environments are limited to {} per location in a subscription. Please specify an existing environment using --environment.".format(MAX_ENV_PER_LOCATION)) |
849 | | - |
850 | | - |
851 | | -def list_environment_locations(cmd): |
852 | | - from ._utils import providers_client_factory |
853 | | - providers_client = providers_client_factory(cmd.cli_ctx, get_subscription_id(cmd.cli_ctx)) |
854 | | - resource_types = getattr(providers_client.get(CONTAINER_APPS_RP), 'resource_types', []) |
855 | | - res_locations = [] |
856 | | - for res in resource_types: |
857 | | - if res and getattr(res, 'resource_type', "") == "managedEnvironments": |
858 | | - res_locations = getattr(res, 'locations', []) |
859 | | - |
860 | | - res_locations = [res_loc.lower().replace(" ", "").replace("(", "").replace(")", "") for res_loc in res_locations if res_loc.strip()] |
861 | | - |
862 | | - return res_locations |
863 | | - |
864 | | - |
865 | 814 | def check_env_name_on_rg(cmd, managed_env, resource_group_name, location): |
866 | 815 | if location: |
867 | 816 | _ensure_location_allowed(cmd, location, CONTAINER_APPS_RP, "managedEnvironments") |
|
0 commit comments