Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

containerapp refactor managed env show/list/delete/create/update #6568

Merged
merged 7 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use constants and fix static analysis
  • Loading branch information
Greedygre committed Jul 31, 2023
commit d88fbf33afbfe391db3a51503ad9ab86d69df17f
2 changes: 2 additions & 0 deletions src/containerapp/azext_containerapp/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

ACR_IMAGE_SUFFIX = ".azurecr.io"

CONTAINER_APPS_SDK_MODELS = "azext_containerapp._sdk_models"

LOG_ANALYTICS_RP = "Microsoft.OperationalInsights"
CONTAINER_APPS_RP = "Microsoft.App"
SERVICE_LINKER_RP = "Microsoft.ServiceLinker"
Expand Down
30 changes: 12 additions & 18 deletions src/containerapp/azext_containerapp/containerapp_env_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,19 @@ def validate_arguments(self):
def create(self):
try:
return self.client.create(cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(),
name=self.get_argument_name(), managed_environment_envelope=self.managed_env_def,no_wait=self.get_argument_no_wait())
name=self.get_argument_name(), managed_environment_envelope=self.managed_env_def, no_wait=self.get_argument_no_wait())
except Exception as e:
handle_raw_exception(e)

def post_process(self, r):
_azure_monitor_quickstart(self.cmd, self.get_argument_name(), self.get_argument_resource_group_name(), self.get_argument_storage_account(), self.get_argument_logs_destination())

# return ENV
if "properties" in r and "provisioningState" in r["properties"] and r["properties"][
"provisioningState"].lower() != "succeeded" and not self.get_argument_no_wait():
not self.get_argument_disable_warnings() and logger.warning(
'Containerapp environment creation in progress. Please monitor the creation using `az containerapp env show -n {} -g {}`'.format(
self.get_argument_name(), self.get_argument_resource_group_name()))
if "properties" in r and "provisioningState" in r["properties"] and r["properties"]["provisioningState"].lower() != "succeeded" and not self.get_argument_no_wait():
not self.get_argument_disable_warnings() and logger.warning('Containerapp environment creation in progress. Please monitor the creation using `az containerapp env show -n {} -g {}`'.format(self.get_argument_name(), self.get_argument_resource_group_name()))

if "properties" in r and "provisioningState" in r["properties"] and r["properties"][
"provisioningState"].lower() == "succeeded":
not self.get_argument_disable_warnings() and logger.warning(
"\nContainer Apps environment created. To deploy a container app, use: az containerapp create --help\n")
if "properties" in r and "provisioningState" in r["properties"] and r["properties"]["provisioningState"].lower() == "succeeded":
not self.get_argument_disable_warnings() and logger.warning("\nContainer Apps environment created. To deploy a container app, use: az containerapp create --help\n")

return r

Expand All @@ -177,12 +172,12 @@ def construct_payload(self):

# Custom domains
if self.get_argument_hostname():
customDomain = CustomDomainConfigurationModel
custom_domain = CustomDomainConfigurationModel
blob, _ = load_cert_file(self.get_argument_certificate_file(), self.get_argument_certificate_password())
customDomain["dnsSuffix"] = self.get_argument_hostname()
customDomain["certificatePassword"] = self.get_argument_certificate_password()
customDomain["certificateValue"] = blob
self.managed_env_def["properties"]["customDomainConfiguration"] = customDomain
custom_domain["dnsSuffix"] = self.get_argument_hostname()
custom_domain["certificatePassword"] = self.get_argument_certificate_password()
custom_domain["certificateValue"] = blob
self.managed_env_def["properties"]["customDomainConfiguration"] = custom_domain

if self.get_argument_instrumentation_key() is not None:
self.managed_env_def["properties"]["daprAIInstrumentationKey"] = self.get_argument_instrumentation_key()
Expand Down Expand Up @@ -331,16 +326,15 @@ def set_up_workload_profiles(self, r):
if not update:
workload_profiles.append(profile)
else:
idx = \
[i for i, p in enumerate(workload_profiles) if p["name"].lower() == workload_profile_name.lower()][0]
idx = [i for i, p in enumerate(workload_profiles) if p["name"].lower() == workload_profile_name.lower()][0]
workload_profiles[idx] = profile

safe_set(self.managed_env_def, "properties", "workloadProfiles", value=workload_profiles)

def update(self):
try:
return self.client.update(cmd=self.cmd, resource_group_name=self.get_argument_resource_group_name(),
name=self.get_argument_name(), managed_environment_envelope=self.managed_env_def,no_wait=self.get_argument_no_wait())
name=self.get_argument_name(), managed_environment_envelope=self.managed_env_def, no_wait=self.get_argument_no_wait())
except Exception as e:
handle_raw_exception(e)

Expand Down
34 changes: 17 additions & 17 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
NAME_INVALID, NAME_ALREADY_EXISTS, ACR_IMAGE_SUFFIX, HELLO_WORLD_IMAGE, LOG_TYPE_SYSTEM, LOG_TYPE_CONSOLE,
MANAGED_CERTIFICATE_RT, PRIVATE_CERTIFICATE_RT, PENDING_STATUS, SUCCEEDED_STATUS, DEV_POSTGRES_IMAGE, DEV_POSTGRES_SERVICE_TYPE,
DEV_POSTGRES_CONTAINER_NAME, DEV_REDIS_IMAGE, DEV_REDIS_SERVICE_TYPE, DEV_REDIS_CONTAINER_NAME, DEV_KAFKA_CONTAINER_NAME,
DEV_KAFKA_IMAGE, DEV_KAFKA_SERVICE_TYPE, DEV_SERVICE_LIST)
DEV_KAFKA_IMAGE, DEV_KAFKA_SERVICE_TYPE, DEV_SERVICE_LIST, CONTAINER_APPS_SDK_MODELS)

logger = get_logger(__name__)

Expand Down Expand Up @@ -168,7 +168,7 @@ def create_deserializer():
from msrest import Deserializer
import inspect

sdkClasses = inspect.getmembers(sys.modules["azext_containerapp._sdk_models"])
sdkClasses = inspect.getmembers(sys.modules[CONTAINER_APPS_SDK_MODELS])
deserializer = {}

for sdkClass in sdkClasses:
Expand Down Expand Up @@ -459,7 +459,7 @@ def create_containerapp(cmd,
cmd=cmd,
client=ContainerAppClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_create_decorator.register_provider(CONTAINER_APPS_RP)
containerapp_create_decorator.validate_arguments()
Expand Down Expand Up @@ -1004,7 +1004,7 @@ def show_containerapp(cmd, name, resource_group_name, show_secrets=False):
cmd=cmd,
client=ContainerAppClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_base_decorator.validate_subscription_registered(CONTAINER_APPS_RP)

Expand All @@ -1017,7 +1017,7 @@ def list_containerapp(cmd, resource_group_name=None, managed_env=None):
cmd=cmd,
client=ContainerAppClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_base_decorator.validate_subscription_registered(CONTAINER_APPS_RP)

Expand All @@ -1030,7 +1030,7 @@ def delete_containerapp(cmd, name, resource_group_name, no_wait=False):
cmd=cmd,
client=ContainerAppClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_base_decorator.validate_subscription_registered(CONTAINER_APPS_RP)

Expand Down Expand Up @@ -1065,7 +1065,7 @@ def create_managed_environment(cmd,
cmd=cmd,
client=ManagedEnvironmentClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_env_create_decorator.validate_arguments()
containerapp_env_create_decorator.register_provider(CONTAINER_APPS_RP)
Expand Down Expand Up @@ -1099,7 +1099,7 @@ def update_managed_environment(cmd,
cmd=cmd,
client=ManagedEnvironmentClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_env_update_decorator.validate_arguments()
containerapp_env_update_decorator.construct_payload()
Expand All @@ -1115,7 +1115,7 @@ def show_managed_environment(cmd, name, resource_group_name):
cmd=cmd,
client=ManagedEnvironmentClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_env_decorator.validate_subscription_registered(CONTAINER_APPS_RP)

Expand All @@ -1128,7 +1128,7 @@ def list_managed_environments(cmd, resource_group_name=None):
cmd=cmd,
client=ManagedEnvironmentClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_env_decorator.validate_subscription_registered(CONTAINER_APPS_RP)

Expand All @@ -1141,7 +1141,7 @@ def delete_managed_environment(cmd, name, resource_group_name, no_wait=False):
cmd=cmd,
client=ManagedEnvironmentClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_env_decorator.validate_subscription_registered(CONTAINER_APPS_RP)

Expand Down Expand Up @@ -1189,7 +1189,7 @@ def create_containerappsjob(cmd,
cmd=cmd,
client=ContainerAppsJobClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_job_create_decorator.register_provider(CONTAINER_APPS_RP)
containerapp_job_create_decorator.validate_arguments()
Expand All @@ -1208,7 +1208,7 @@ def show_containerappsjob(cmd, name, resource_group_name):
cmd=cmd,
client=ContainerAppsJobClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_job_decorator.validate_subscription_registered(CONTAINER_APPS_RP)

Expand All @@ -1221,7 +1221,7 @@ def list_containerappsjob(cmd, resource_group_name=None):
cmd=cmd,
client=ContainerAppsJobClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_job_decorator.validate_subscription_registered(CONTAINER_APPS_RP)

Expand All @@ -1234,7 +1234,7 @@ def delete_containerappsjob(cmd, name, resource_group_name, no_wait=False):
cmd=cmd,
client=ContainerAppsJobClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)
containerapp_job_decorator.validate_subscription_registered(CONTAINER_APPS_RP)

Expand Down Expand Up @@ -5019,7 +5019,7 @@ def update_auth_config(cmd, resource_group_name, name, set_string=None, enabled=
cmd=cmd,
client=AuthClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)

containerapp_auth_decorator.construct_payload()
Expand All @@ -5032,7 +5032,7 @@ def show_auth_config(cmd, resource_group_name, name):
cmd=cmd,
client=AuthClient,
raw_parameters=raw_parameters,
models="azext_containerapp._sdk_models"
models=CONTAINER_APPS_SDK_MODELS
)

return containerapp_auth_decorator.show()
Expand Down