-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
SCHERBELBERG | ||
HPC cluster deployment and management for the Hetzner Cloud | ||
https://github.com/pleiszenburg/scherbelberg | ||
src/scherbelberg/_cli/catalog.py: List data centers and available types of servers | ||
Copyright (C) 2021-2022 Sebastian M. Ernst <[email protected]> | ||
<LICENSE_BLOCK> | ||
The contents of this file are subject to the BSD 3-Clause License | ||
("License"). You may not use this file except in | ||
compliance with the License. You may obtain a copy of the License at | ||
https://github.com/pleiszenburg/scherbelberg/blob/master/LICENSE | ||
Software distributed under the License is distributed on an "AS IS" basis, | ||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the | ||
specific language governing rights and limitations under the License. | ||
</LICENSE_BLOCK> | ||
""" | ||
|
||
|
||
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
# IMPORT | ||
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
||
from asyncio import run | ||
from logging import ERROR | ||
|
||
import click | ||
from tabulate import tabulate | ||
|
||
from .._core.catalog import ( | ||
get_datacenters, | ||
get_servertypes, | ||
) | ||
from .._core.const import ( | ||
TOKENVAR, | ||
HETZNER_DATACENTER, | ||
) | ||
from .._core.log import configure_log | ||
|
||
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
# ROUTINES | ||
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
||
@click.command(short_help="create cluster") | ||
@click.option("-t", "--tokenvar", default=TOKENVAR, type=str, show_default=True) | ||
@click.option( | ||
"-d", "--datacenter", default=HETZNER_DATACENTER, type=str, show_default=True | ||
) | ||
@click.option("-l", "--log_level", default=ERROR, type=int, show_default=True) | ||
def catalog( | ||
tokenvar, | ||
datacenter, | ||
log_level, | ||
): | ||
|
||
configure_log(log_level) | ||
|
||
table = run(get_datacenters(tokenvar = tokenvar)) | ||
columns = ( | ||
'name', | ||
'city', | ||
'country', | ||
'description', | ||
'latitude', | ||
'longitude', | ||
'network_zone', | ||
'location_name', | ||
'location_description', | ||
) | ||
table = [ | ||
[row[column] for column in columns] | ||
for row in table | ||
] | ||
click.echo(tabulate( | ||
table, | ||
headers=columns, | ||
tablefmt="github", | ||
)) | ||
|
||
table = run(get_servertypes(datacenter = datacenter, tokenvar = tokenvar)) | ||
columns = ( | ||
'name', | ||
# 'description', | ||
'cores', | ||
'cpu_type', | ||
'memory', | ||
'disk', | ||
'storage_type', | ||
'price_hourly_net', | ||
'price_hourly_gross', | ||
'price_monthly_net', | ||
'price_monthly_gross', | ||
'deprecated', | ||
) | ||
table = [ | ||
[row[column] for column in columns] | ||
for row in table | ||
] | ||
click.echo(tabulate( | ||
table, | ||
headers=columns, | ||
tablefmt="github", | ||
)) |