Compare commits
No commits in common. "3898468084d70fbd01ef1a5adf6ff47ed9e09013" and "92583345836d734dba46831238de53e5dc07be69" have entirely different histories.
3898468084
...
9258334583
24
twvdscli.py
24
twvdscli.py
@ -1,8 +1,6 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import sys
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import typer
|
import typer
|
||||||
import os
|
import os
|
||||||
@ -22,8 +20,6 @@ class Server:
|
|||||||
url=url,
|
url=url,
|
||||||
headers=reqHeader
|
headers=reqHeader
|
||||||
)
|
)
|
||||||
if not result.ok:
|
|
||||||
return None
|
|
||||||
return result.json()
|
return result.json()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -51,35 +47,20 @@ class Server:
|
|||||||
return result.json()
|
return result.json()
|
||||||
|
|
||||||
|
|
||||||
@app.command("balance")
|
|
||||||
def get_balance():
|
def get_balance():
|
||||||
response = requests.get("https://public-api.timeweb.com/api/v1/accounts/finances", headers=reqHeader)
|
response = requests.get("https://public-api.timeweb.com/api/v1/accounts/finances", headers=reqHeader)
|
||||||
if not response.ok:
|
return response.json()
|
||||||
print(typer.style("Error", fg=typer.colors.RED))
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
response = response.json()
|
|
||||||
print('{0:6} {1:}'.format('balance', 'monthly_cost'))
|
|
||||||
print('{0:6} {1:}'.format(response['finances']['balance'], response['finances']['monthly_cost']))
|
|
||||||
|
|
||||||
|
|
||||||
@servers_app.command("start")
|
@servers_app.command("start")
|
||||||
def vds_start(vds_id: int = typer.Argument(...)):
|
def vds_start(vds_id: int = typer.Argument(...)):
|
||||||
result = Server.start(vds_id)
|
result = Server.start(vds_id)
|
||||||
if result is None:
|
|
||||||
print(typer.style("Error", fg=typer.colors.RED))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
|
|
||||||
@servers_app.command("stop")
|
@servers_app.command("stop")
|
||||||
def vds_stop(vds_id: int = typer.Argument(...)):
|
def vds_stop(vds_id: int = typer.Argument(...)):
|
||||||
result = Server.stop(vds_id)
|
result = Server.stop(vds_id)
|
||||||
if result is None:
|
|
||||||
print(typer.style("Error", fg=typer.colors.RED))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
|
|
||||||
@ -87,9 +68,6 @@ def vds_stop(vds_id: int = typer.Argument(...)):
|
|||||||
def vds_list():
|
def vds_list():
|
||||||
list_of_servers = Server.get_list()
|
list_of_servers = Server.get_list()
|
||||||
# print('{0:7} {1:17} {5:16} {2:2} {3:5} {4:4}'.format('state', 'name', 'vcpus', 'memory', 'disk', 'ip'))
|
# print('{0:7} {1:17} {5:16} {2:2} {3:5} {4:4}'.format('state', 'name', 'vcpus', 'memory', 'disk', 'ip'))
|
||||||
if list_of_servers is None:
|
|
||||||
print(typer.style("Error", fg=typer.colors.RED))
|
|
||||||
sys.exit(1)
|
|
||||||
for i in list_of_servers['servers']:
|
for i in list_of_servers['servers']:
|
||||||
if i['status'] == 'on':
|
if i['status'] == 'on':
|
||||||
state = typer.style("Running", fg=typer.colors.GREEN)
|
state = typer.style("Running", fg=typer.colors.GREEN)
|
||||||
|
Loading…
Reference in New Issue
Block a user