Skip to content

Commit

Permalink
[Spring-Cloud] Enable deployment input for az spring-cloud app logs (A…
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyi-joffre authored Jan 19, 2021
1 parent 8bc446f commit 7968fe0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/spring-cloud/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Release History
===============
2.1.2
-----
* Add optional '--deployment' to 'az spring-cloud app logs' command

2.1.1
-----
* Remove preview parameter '--enable-java-agent' from 'az spring-cloud update'.
Expand Down
4 changes: 4 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ def load_arguments(self, _):
c.argument('follow', options_list=['--follow ', '-f'], help='Specify if the logs should be streamed.', action='store_true')
c.argument('since', help='Only return logs newer than a relative duration like 5s, 2m, or 1h. Maximum is 1h', validator=validate_log_since)
c.argument('limit', type=int, help='Maximum kilobytes of logs to return. Ceiling number is 2048.', validator=validate_log_limit)
c.argument('deployment', options_list=[
'--deployment', '-d'], help='Name of an existing deployment of the app. Default to the production deployment if not specified.', validator=validate_deployment_name)

with self.argument_context('spring-cloud app log tail') as c:
c.argument('instance', options_list=['--instance', '-i'], help='Name of an existing instance of the deployment.')
c.argument('lines', type=int, help='Number of lines to show. Maximum is 10000', validator=validate_log_lines)
c.argument('follow', options_list=['--follow ', '-f'], help='Specify if the logs should be streamed.', action='store_true')
c.argument('since', help='Only return logs newer than a relative duration like 5s, 2m, or 1h. Maximum is 1h', validator=validate_log_since)
c.argument('limit', type=int, help='Maximum kilobytes of logs to return. Ceiling number is 2048.', validator=validate_log_limit)
c.argument('deployment', options_list=[
'--deployment', '-d'], help='Name of an existing deployment of the app. Default to the production deployment if not specified.', validator=validate_deployment_name)

with self.argument_context('spring-cloud app set-deployment') as c:
c.argument('deployment', options_list=[
Expand Down
24 changes: 12 additions & 12 deletions src/spring-cloud/azext_spring_cloud/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,21 +529,21 @@ def app_get_build_log(cmd, client, resource_group, service, name, deployment=Non
return stream_logs(client.deployments, resource_group, service, name, deployment)


def app_tail_log(cmd, client, resource_group, service, name, instance=None, follow=False, lines=50, since=None, limit=2048):
def app_tail_log(cmd, client, resource_group, service, name, deployment=None, instance=None, follow=False, lines=50, since=None, limit=2048):
if not instance:
deployment_name = client.apps.get(
resource_group, service, name).properties.active_deployment_name
if not deployment_name:
raise CLIError(
"No production deployment found for app '{}'".format(name))
deployment = client.deployments.get(
resource_group, service, name, deployment_name)
if not deployment.properties.instances:
if deployment is None:
deployment = client.apps.get(
resource_group, service, name).properties.active_deployment_name
if not deployment:
raise CLIError(NO_PRODUCTION_DEPLOYMENT_ERROR)
deployment_properties = client.deployments.get(
resource_group, service, name, deployment).properties
if not deployment_properties.instances:
raise CLIError("No instances found for deployment '{0}' in app '{1}'".format(
deployment_name, name))
instances = deployment.properties.instances
deployment, name))
instances = deployment_properties.instances
if len(instances) > 1:
logger.warning("Mulitple app instances found:")
logger.warning("Multiple app instances found:")
for temp_instance in instances:
logger.warning("{}".format(temp_instance.name))
logger.warning("Please use '-i/--instance' parameter to specify the instance name")
Expand Down

0 comments on commit 7968fe0

Please sign in to comment.