Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Feature: Include cluster creation time in cluster list and cluster ge…
Browse files Browse the repository at this point in the history
…t output (#678)

* Include cluster creation time in cluster list and info

* Make helper function for formatting

* Make yapf happy
  • Loading branch information
emlyn authored and jafreck committed Nov 2, 2018
1 parent 385040d commit a0bc2f0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions aztk_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def get_ssh_key_or_prompt(ssh_key, username, password, secrets_configuration):
return ssh_key, password


def format_datetime(datetime, include_seconds=True):
format = '%Y-%m-%d %H:%M' + (':%S' if include_seconds else '')
return datetime.strftime(format)


def print_cluster(client, cluster: models.Cluster, internal: bool = False):
node_count = __pretty_node_count(cluster)

Expand All @@ -50,6 +55,7 @@ def print_cluster(client, cluster: models.Cluster, internal: bool = False):
log.info("------------------------------------------")
log.info("State: %s", cluster.state.value)
log.info("Node Size: %s", cluster.vm_size)
log.info("Created: %s", format_datetime(cluster.pool.creation_time))
log.info("Nodes: %s", node_count)
log.info("| Dedicated: %s", __pretty_dedicated_node_count(cluster))
log.info("| Low priority: %s", __pretty_low_pri_node_count(cluster))
Expand Down Expand Up @@ -106,15 +112,17 @@ def __pretty_low_pri_node_count(cluster: models.Cluster) -> str:


def print_clusters(clusters: List[models.Cluster]):
print_format = "{:<34}| {:<10}| {:<20}| {:<7}"
print_format_underline = "{:-<34}|{:-<11}|{:-<21}|{:-<7}"
print_format = "{:<34}| {:<10}| {:<20}| {:<7}| {:<16}"
print_format_underline = "{:-<34}|{:-<11}|{:-<21}|{:-<8}|{:-<17}"

log.info(print_format.format("Cluster", "State", "VM Size", "Nodes"))
log.info(print_format_underline.format("", "", "", ""))
log.info(print_format.format("Cluster", "State", "VM Size", "Nodes", "Created"))
log.info(print_format_underline.format("", "", "", "", ""))
for cluster in clusters:
node_count = __pretty_node_count(cluster)

log.info(print_format.format(cluster.id, cluster.state.value, cluster.vm_size, node_count))
log.info(
print_format.format(cluster.id, cluster.state.value, cluster.vm_size, node_count,
format_datetime(cluster.pool.creation_time, False)))


def print_clusters_quiet(clusters: List[models.Cluster]):
Expand Down

0 comments on commit a0bc2f0

Please sign in to comment.