diff --git a/src/containerapp-preview/azext_containerapp_preview/custom.py b/src/containerapp-preview/azext_containerapp_preview/custom.py index 2adeb366350..68903843456 100644 --- a/src/containerapp-preview/azext_containerapp_preview/custom.py +++ b/src/containerapp-preview/azext_containerapp_preview/custom.py @@ -89,8 +89,8 @@ def create_containerapp(cmd, ) containerapp_preview_create_decorator.register_provider() containerapp_preview_create_decorator.validate_arguments() - containerapp_def = containerapp_preview_create_decorator.construct_containerapp() - r = containerapp_preview_create_decorator.create_containerapp(containerapp_def) - containerapp_def = containerapp_preview_create_decorator.construct_containerapp_for_post_process(containerapp_def, r) - r = containerapp_preview_create_decorator.post_process_containerapp(containerapp_def, r) + containerapp_preview_create_decorator.construct_containerapp() + r = containerapp_preview_create_decorator.create_containerapp() + containerapp_preview_create_decorator.construct_containerapp_for_post_process(r) + r = containerapp_preview_create_decorator.post_process_containerapp(r) return r diff --git a/src/containerapp/azext_containerapp/containerapp_decorator.py b/src/containerapp/azext_containerapp/containerapp_decorator.py index 87ce2292714..41992f17198 100644 --- a/src/containerapp/azext_containerapp/containerapp_decorator.py +++ b/src/containerapp/azext_containerapp/containerapp_decorator.py @@ -311,7 +311,7 @@ def __init__( self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str ): super().__init__(cmd, client, raw_parameters, models) - self.containerapp = None + self.containerapp_def = ContainerAppModel def validate_arguments(self): validate_container_app_name(self.get_argument_name(), AppType.ContainerApp.name) @@ -507,29 +507,29 @@ def construct_containerapp(self): if self.get_argument_termination_grace_period() is not None: template_def["terminationGracePeriodSeconds"] = self.get_argument_termination_grace_period() - self.containerapp = ContainerAppModel - self.containerapp["location"] = location - self.containerapp["identity"] = identity_def - self.containerapp["properties"]["environmentId"] = self.get_argument_managed_env() - self.containerapp["properties"]["configuration"] = config_def - self.containerapp["properties"]["template"] = template_def - self.containerapp["tags"] = self.get_argument_tags() + self.containerapp_def = ContainerAppModel + self.containerapp_def["location"] = location + self.containerapp_def["identity"] = identity_def + self.containerapp_def["properties"]["environmentId"] = self.get_argument_managed_env() + self.containerapp_def["properties"]["configuration"] = config_def + self.containerapp_def["properties"]["template"] = template_def + self.containerapp_def["tags"] = self.get_argument_tags() if self.get_argument_workload_profile_name(): - self.containerapp["properties"]["workloadProfileName"] = self.get_argument_workload_profile_name() + self.containerapp_def["properties"]["workloadProfileName"] = self.get_argument_workload_profile_name() ensure_workload_profile_supported(self.cmd, managed_env_name, managed_env_rg, self.get_argument_workload_profile_name(), managed_env_info) if self.get_argument_registry_identity(): if is_registry_msi_system(self.get_argument_registry_identity()): - set_managed_identity(self.cmd, self.get_argument_resource_group_name(), self.containerapp, system_assigned=True) + set_managed_identity(self.cmd, self.get_argument_resource_group_name(), self.containerapp_def, system_assigned=True) else: - set_managed_identity(self.cmd, self.get_argument_resource_group_name(), self.containerapp, user_assigned=[self.get_argument_registry_identity()]) + set_managed_identity(self.cmd, self.get_argument_resource_group_name(), self.containerapp_def, user_assigned=[self.get_argument_registry_identity()]) def create_containerapp(self): try: r = self.client.create_or_update( - cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(), name=self.get_argument_name(), container_app_envelope=self.containerapp, + cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(), name=self.get_argument_name(), container_app_envelope=self.containerapp_def, no_wait=self.get_argument_no_wait()) return r @@ -544,15 +544,15 @@ def construct_containerapp_for_post_process(self, r): logger.info("Creating an acrpull role assignment for the system identity") system_sp = r["identity"]["principalId"] create_acrpull_role_assignment(self.cmd, self.get_argument_registry_server(), registry_identity=None, service_principal=system_sp) - containers_def = safe_get(self.containerapp, "properties", "template", "containers") + containers_def = safe_get(self.containerapp_def, "properties", "template", "containers") containers_def[0]["image"] = self.get_argument_image() - safe_set(self.containerapp, "properties", "template", "revisionSuffix", value=self.get_argument_revision_suffix()) + safe_set(self.containerapp_def, "properties", "template", "revisionSuffix", value=self.get_argument_revision_suffix()) registries_def = RegistryCredentialsModel registries_def["server"] = self.get_argument_registry_server() registries_def["identity"] = self.get_argument_registry_identity() - safe_set(self.containerapp, "properties", "configuration", "registries", value=[registries_def]) + safe_set(self.containerapp_def, "properties", "configuration", "registries", value=[registries_def]) def post_process_containerapp(self, r): if is_registry_msi_system(self.get_argument_registry_identity()): @@ -611,7 +611,7 @@ def set_up_create_containerapp_yaml(self, name, file_name): try: deserializer = create_deserializer(self.models) - self.containerapp = deserializer('ContainerApp', yaml_containerapp) + self.containerapp_def = deserializer('ContainerApp', yaml_containerapp) except DeserializationError as ex: raise ValidationError( 'Invalid YAML provided. Please see https://aka.ms/azure-container-apps-yaml for a valid containerapps YAML spec.') from ex @@ -622,26 +622,26 @@ def set_up_create_containerapp_yaml(self, name, file_name): tags = yaml_containerapp.get('tags') del yaml_containerapp['tags'] - self.containerapp = _convert_object_from_snake_to_camel_case(_object_to_dict(self.containerapp)) - self.containerapp['tags'] = tags + self.containerapp_def = _convert_object_from_snake_to_camel_case(_object_to_dict(self.containerapp_def)) + self.containerapp_def['tags'] = tags # After deserializing, some properties may need to be moved under the "properties" attribute. Need this since we're not using SDK - self.containerapp = process_loaded_yaml(self.containerapp) + self.containerapp_def = process_loaded_yaml(self.containerapp_def) # Remove "additionalProperties" and read-only attributes that are introduced in the deserialization. Need this since we're not using SDK - _remove_additional_attributes(self.containerapp) - _remove_readonly_attributes(self.containerapp) + _remove_additional_attributes(self.containerapp_def) + _remove_readonly_attributes(self.containerapp_def) # Remove extra workloadProfileName introduced in deserialization - if "workloadProfileName" in self.containerapp: - del self.containerapp["workloadProfileName"] + if "workloadProfileName" in self.containerapp_def: + del self.containerapp_def["workloadProfileName"] # Validate managed environment - if not self.containerapp["properties"].get('environmentId'): + if not self.containerapp_def["properties"].get('environmentId'): raise RequiredArgumentMissingError( 'environmentId is required. This can be retrieved using the `az containerapp env show -g MyResourceGroup -n MyContainerappEnvironment --query id` command. Please see https://aka.ms/azure-container-apps-yaml for a valid containerapps YAML spec.') - env_id = self.containerapp["properties"]['environmentId'] + env_id = self.containerapp_def["properties"]['environmentId'] env_name = None env_rg = None env_info = None @@ -662,8 +662,8 @@ def set_up_create_containerapp_yaml(self, name, file_name): raise ValidationError("The environment '{}' in resource group '{}' was not found".format(env_name, env_rg)) # Validate location - if not self.containerapp.get('location'): - self.containerapp['location'] = env_info['location'] + if not self.containerapp_def.get('location'): + self.containerapp_def['location'] = env_info['location'] def set_up_scale_rule(self): scale_def = None