Added plan list
This commit is contained in:
parent
1436a8d777
commit
975dab4bc5
46
twvdscli.py
46
twvdscli.py
@ -16,19 +16,26 @@ from time import sleep
|
|||||||
|
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
|
# twvdscli dbs
|
||||||
dbs_app = typer.Typer()
|
dbs_app = typer.Typer()
|
||||||
app.add_typer(dbs_app, name='dbs', help='Control Managed databases')
|
app.add_typer(dbs_app, name='dbs', help='Control Managed databases')
|
||||||
|
|
||||||
|
# twvdscli vds
|
||||||
servers_app = typer.Typer()
|
servers_app = typer.Typer()
|
||||||
app.add_typer(servers_app, name='vds', help='Control VDS Servers, their snapshots and backups')
|
app.add_typer(servers_app, name='vds', help='Control VDS Servers, their snapshots and backups')
|
||||||
|
|
||||||
|
# twvdscli vds backups
|
||||||
backups_app = typer.Typer()
|
backups_app = typer.Typer()
|
||||||
servers_app.add_typer(backups_app, name='backup', help='Create/Delete backup')
|
servers_app.add_typer(backups_app, name='backup', help='Create/Delete backup')
|
||||||
|
|
||||||
|
# twvdscli vds snap
|
||||||
snapshot_app = typer.Typer()
|
snapshot_app = typer.Typer()
|
||||||
servers_app.add_typer(snapshot_app, name='snap', help='Create/Rollback/Delete snapshot')
|
servers_app.add_typer(snapshot_app, name='snap', help='Create/Rollback/Delete snapshot')
|
||||||
|
|
||||||
|
# twvdscli vds info
|
||||||
|
vds_info_app = typer.Typer()
|
||||||
|
servers_app.add_typer(vds_info_app, name='info', help='Get info about plans and os\'es')
|
||||||
|
|
||||||
|
|
||||||
class Dbaas:
|
class Dbaas:
|
||||||
"""
|
"""
|
||||||
@ -495,6 +502,43 @@ def dbs_connect(db_id: Optional[int] = typer.Argument(None)):
|
|||||||
os.system(cmd_psql.format(ip=db_ip, login=db_user))
|
os.system(cmd_psql.format(ip=db_ip, login=db_user))
|
||||||
|
|
||||||
|
|
||||||
|
@vds_info_app.command("plans")
|
||||||
|
def vds_plans(raw: bool = typer.Option(False, help="Get result as raw json"),
|
||||||
|
sort_by: str = typer.Option(None, help="sort results by value/cpu/ram/disk")):
|
||||||
|
uri = "https://public-api.timeweb.com/api/v1/presets"
|
||||||
|
result = requests.get(uri, headers=reqHeader)
|
||||||
|
|
||||||
|
if not result.ok:
|
||||||
|
print('Error')
|
||||||
|
sys.exit(1)
|
||||||
|
# If raw - print raw result and exit
|
||||||
|
if raw:
|
||||||
|
print(result.text)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# else print pretty
|
||||||
|
x = PrettyTable()
|
||||||
|
x.field_names = ['id', 'cpus', 'ram', 'disk', 'value', 'name', 'description']
|
||||||
|
result = result.json()
|
||||||
|
print("Total: "+ str(result['meta']['total']))
|
||||||
|
# result = result
|
||||||
|
for i in result['presets']:
|
||||||
|
x.add_row([
|
||||||
|
i['id'],
|
||||||
|
i['cpu'],
|
||||||
|
i['ram'],
|
||||||
|
i['drive'],
|
||||||
|
i['discount_value'],
|
||||||
|
i['name'],
|
||||||
|
i['description']
|
||||||
|
])
|
||||||
|
if sort_by in ('cpus', 'ram', 'disk', 'value'):
|
||||||
|
x.sortby = sort_by
|
||||||
|
elif not sort_by is None:
|
||||||
|
print("No such sort")
|
||||||
|
print(x)
|
||||||
|
|
||||||
|
|
||||||
@servers_app.command("create")
|
@servers_app.command("create")
|
||||||
def vds_create(
|
def vds_create(
|
||||||
name: str = typer.Option(..., help="VDS Name"),
|
name: str = typer.Option(..., help="VDS Name"),
|
||||||
|
Loading…
Reference in New Issue
Block a user