Feature: Include cluster creation time in cluster list and cluster get output (#678)

* Include cluster creation time in cluster list and info

* Make helper function for formatting

* Make yapf happy
This commit is contained in:
Emlyn Corrin 2018-11-02 18:11:21 +00:00 коммит произвёл Jacob Freck
Родитель 385040d7b1
Коммит a0bc2f0f09
1 изменённых файлов: 13 добавлений и 5 удалений

Просмотреть файл

@ -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)
@ -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))
@ -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]):