Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 17 additions & 2 deletions src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def poll_status(cmd, request_url): # pylint: disable=inconsistent-return-statem
r = send_raw_request(cmd.cli_ctx, "GET", request_url)

while r.status_code in [200] and start < end:
time.sleep(POLLING_SECONDS)
time.sleep(_extract_delay(r))
animation.tick()
r = send_raw_request(cmd.cli_ctx, "GET", request_url)
response_body = json.loads(r.text)
Expand Down Expand Up @@ -121,7 +121,7 @@ def poll_results(cmd, request_url): # pylint: disable=inconsistent-return-state
r = send_raw_request(cmd.cli_ctx, "GET", request_url)

while r.status_code in [202] and start < end:
time.sleep(POLLING_SECONDS)
time.sleep(_extract_delay(r))
animation.tick()
r = send_raw_request(cmd.cli_ctx, "GET", request_url)
start = time.time()
Expand All @@ -131,6 +131,21 @@ def poll_results(cmd, request_url): # pylint: disable=inconsistent-return-state
return json.loads(r.text)


def _extract_delay(response):
try:
retry_after = response.headers.get("retry-after")
if retry_after:
return int(retry_after)
for ms_header in ["retry-after-ms", "x-ms-retry-after-ms"]:
retry_after = response.headers.get(ms_header)
if retry_after:
parsed_retry_after = int(retry_after)
return parsed_retry_after / 1000.0
except ValueError:
pass
return POLLING_SECONDS


class ContainerAppClient():
@classmethod
def create_or_update(cls, cmd, resource_group_name, name, container_app_envelope, no_wait=False):
Expand Down
2 changes: 1 addition & 1 deletion src/containerapp/azext_containerapp/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
"location": None,
"identity": None, # ManagedServiceIdentity
"properties": {
"managedEnvironmentId": None,
"environmentId": None,
"configuration": None, # Configuration
"template": None # Template
},
Expand Down
4 changes: 2 additions & 2 deletions src/containerapp/azext_containerapp/_sdk_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ class ContainerApp(TrackedResource):
'location': {'key': 'location', 'type': 'str'},
'identity': {'key': 'identity', 'type': 'ManagedServiceIdentity'},
'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'},
'managed_environment_id': {'key': 'properties.managedEnvironmentId', 'type': 'str'},
'environment_id': {'key': 'properties.environmentId', 'type': 'str'},
'latest_revision_name': {'key': 'properties.latestRevisionName', 'type': 'str'},
'latest_revision_fqdn': {'key': 'properties.latestRevisionFqdn', 'type': 'str'},
'custom_domain_verification_id': {'key': 'properties.customDomainVerificationId', 'type': 'str'},
Expand All @@ -1006,7 +1006,7 @@ def __init__(self, **kwargs):
super(ContainerApp, self).__init__(**kwargs)
self.identity = kwargs.get('identity', None)
self.provisioning_state = None
self.managed_environment_id = kwargs.get('managed_environment_id', None)
self.environment_id = kwargs.get('environment_id', None)
self.latest_revision_name = None
self.latest_revision_fqdn = None
self.custom_domain_verification_id = None
Expand Down
4 changes: 2 additions & 2 deletions src/containerapp/azext_containerapp/_up_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,14 @@ def _get_app_env_and_group(
if not resource_group.name and not resource_group.exists:
matched_apps = [c for c in list_containerapp(cmd) if c["name"].lower() == name.lower()]
if env.name:
matched_apps = [c for c in matched_apps if parse_resource_id(c["properties"]["managedEnvironmentId"])["name"].lower() == env.name.lower()]
matched_apps = [c for c in matched_apps if parse_resource_id(c["properties"]["environmentId"])["name"].lower() == env.name.lower()]
if location:
matched_apps = [c for c in matched_apps if c["location"].lower() == location.lower()]
if len(matched_apps) == 1:
resource_group.name = parse_resource_id(matched_apps[0]["id"])[
"resource_group"
]
env.set_name(matched_apps[0]["properties"]["managedEnvironmentId"])
env.set_name(matched_apps[0]["properties"]["environmentId"])
elif len(matched_apps) > 1:
raise ValidationError(
f"There are multiple containerapps with name {name} on the subscription. "
Expand Down
4 changes: 2 additions & 2 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ def get_custom_domains(cmd, resource_group_name, name, location=None, environmen
_ensure_location_allowed(cmd, location, "Microsoft.App", "containerApps")
if _normalize_location(cmd, app["location"]) != _normalize_location(cmd, location):
raise ResourceNotFoundError('Container app {} is not in location {}.'.format(name, location))
if environment and (_get_name(environment) != _get_name(app["properties"]["managedEnvironmentId"])):
if environment and (_get_name(environment) != _get_name(app["properties"]["environmentId"])):
raise ResourceNotFoundError('Container app {} is not under environment {}.'.format(name, environment))
custom_domains = safe_get(app, "properties", "configuration", "ingress", "customDomains", default=[])
except CLIError as e:
Expand Down Expand Up @@ -1591,7 +1591,7 @@ def _azure_monitor_quickstart(cmd, name, resource_group_name, storage_account, l
logger.warning("Storage accounts only accepted for Azure Monitor logs destination. Ignoring storage account value.")
return
if not storage_account:
logger.warning("Azure monitor must be set up manually. Run `az monitor diagnostic-settings create --name mydiagnosticsettings --resource myManagedEnvironmentId --storage-account myStorageAccountId --logs myJsonLogSettings` to set up Azure Monitor diagnostic settings on your storage account.")
logger.warning("Azure monitor must be set up manually. Run `az monitor diagnostic-settings create --name mydiagnosticsettings --resource myEnvironmentId --storage-account myStorageAccountId --logs myJsonLogSettings` to set up Azure Monitor diagnostic settings on your storage account.")
return

from azure.cli.command_modules.monitor.operations.diagnostics_settings import create_diagnostics_settings
Expand Down
20 changes: 12 additions & 8 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,18 @@ def process_loaded_yaml(yaml_containerapp):
if not yaml_containerapp.get('properties'):
yaml_containerapp['properties'] = {}

nested_properties = ["provisioningState", "managedEnvironmentId", "latestRevisionName", "latestRevisionFqdn",
nested_properties = ["provisioningState", "managedEnvironmentId", "environmentId", "latestRevisionName", "latestRevisionFqdn",
"customDomainVerificationId", "configuration", "template", "outboundIPAddresses"]
for nested_property in nested_properties:
tmp = yaml_containerapp.get(nested_property)
if tmp:
yaml_containerapp['properties'][nested_property] = tmp
del yaml_containerapp[nested_property]

if "managedEnvironmentId" in yaml_containerapp['properties']:
yaml_containerapp['properties']["environmentId"] = yaml_containerapp['properties']['managedEnvironmentId']
del yaml_containerapp['properties']['managedEnvironmentId']

return yaml_containerapp


Expand Down Expand Up @@ -257,10 +261,10 @@ def create_containerapp_yaml(cmd, name, resource_group_name, file_name, no_wait=
_remove_readonly_attributes(containerapp_def)

# Validate managed environment
if not containerapp_def["properties"].get('managedEnvironmentId'):
raise RequiredArgumentMissingError('managedEnvironmentId 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.')
if not 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 = containerapp_def["properties"]['managedEnvironmentId']
env_id = containerapp_def["properties"]['environmentId']
env_name = None
env_rg = None
env_info = None
Expand All @@ -270,7 +274,7 @@ def create_containerapp_yaml(cmd, name, resource_group_name, file_name, no_wait=
env_name = parsed_managed_env['name']
env_rg = parsed_managed_env['resource_group']
else:
raise ValidationError('Invalid managedEnvironmentId specified. Environment not found')
raise ValidationError('Invalid environmentId specified. Environment not found')

try:
env_info = ManagedEnvironmentClient.show(cmd=cmd, resource_group_name=env_rg, name=env_name)
Expand Down Expand Up @@ -529,7 +533,7 @@ def create_containerapp(cmd,
containerapp_def = ContainerAppModel
containerapp_def["location"] = location
containerapp_def["identity"] = identity_def
containerapp_def["properties"]["managedEnvironmentId"] = managed_env
containerapp_def["properties"]["environmentId"] = managed_env
containerapp_def["properties"]["configuration"] = config_def
containerapp_def["properties"]["template"] = template_def
containerapp_def["tags"] = tags
Expand Down Expand Up @@ -974,9 +978,9 @@ def list_containerapp(cmd, resource_group_name=None, managed_env=None):
env_name = parse_resource_id(managed_env)["name"].lower()
if "resource_group" in parse_resource_id(managed_env):
ManagedEnvironmentClient.show(cmd, parse_resource_id(managed_env)["resource_group"], parse_resource_id(managed_env)["name"])
containerapps = [c for c in containerapps if c["properties"]["managedEnvironmentId"].lower() == managed_env.lower()]
containerapps = [c for c in containerapps if c["properties"]["environmentId"].lower() == managed_env.lower()]
else:
containerapps = [c for c in containerapps if parse_resource_id(c["properties"]["managedEnvironmentId"])["name"].lower() == env_name]
containerapps = [c for c in containerapps if parse_resource_id(c["properties"]["environmentId"])["name"].lower() == env_name]

return containerapps
except CLIError as e:
Expand Down
Loading