Compare commits
2 Commits
50f2dd02b6
...
a08e62e619
Author | SHA1 | Date | |
---|---|---|---|
a08e62e619 | |||
8bb993c59d |
31
twvdscli.py
31
twvdscli.py
@ -29,6 +29,7 @@ servers_app.add_typer(backups_app, name='backup', help='Create/Delete backup')
|
|||||||
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')
|
||||||
|
|
||||||
|
|
||||||
class Dbaas:
|
class Dbaas:
|
||||||
"""
|
"""
|
||||||
DataBases As A Service
|
DataBases As A Service
|
||||||
@ -43,6 +44,15 @@ class Dbaas:
|
|||||||
return None
|
return None
|
||||||
return result.json()
|
return result.json()
|
||||||
|
|
||||||
|
def get(db_id):
|
||||||
|
url = 'https://public-api.timeweb.com/api/v1/dbs/{db_id}'
|
||||||
|
result = requests.get(
|
||||||
|
url=url.format(db_id=db_id),
|
||||||
|
headers=reqHeader
|
||||||
|
)
|
||||||
|
if not result.ok:
|
||||||
|
return None
|
||||||
|
return result.json()
|
||||||
|
|
||||||
|
|
||||||
class Server:
|
class Server:
|
||||||
@ -375,8 +385,8 @@ def get_balance():
|
|||||||
@dbs_app.command("list")
|
@dbs_app.command("list")
|
||||||
def list_dbs():
|
def list_dbs():
|
||||||
"""
|
"""
|
||||||
Show list of VDSes
|
Show list of DBs
|
||||||
ID, State, Name, IP, CPUs, Ram, Disk
|
ID, State, Name, IP, local IP, Password, Type
|
||||||
"""
|
"""
|
||||||
list_of_dbaas = Dbaas.list()
|
list_of_dbaas = Dbaas.list()
|
||||||
x = PrettyTable()
|
x = PrettyTable()
|
||||||
@ -387,7 +397,7 @@ def list_dbs():
|
|||||||
for i in list_of_dbaas['dbs']:
|
for i in list_of_dbaas['dbs']:
|
||||||
if i['status'] == 'started':
|
if i['status'] == 'started':
|
||||||
state = typer.style("Running", fg=typer.colors.GREEN)
|
state = typer.style("Running", fg=typer.colors.GREEN)
|
||||||
#elif i['status'] == 'off':
|
# elif i['status'] == 'off':
|
||||||
# state = typer.style('Stopped', fg=typer.colors.RED)
|
# state = typer.style('Stopped', fg=typer.colors.RED)
|
||||||
else:
|
else:
|
||||||
state = i['status']
|
state = i['status']
|
||||||
@ -411,6 +421,21 @@ def list_dbs():
|
|||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
|
|
||||||
|
@servers_app.command("goto")
|
||||||
|
def vds_goto(vds_id: Optional[int] = typer.Argument(None),
|
||||||
|
port: int = typer.Option(22, help="Specify non standart SSH port.")):
|
||||||
|
"""
|
||||||
|
Connect via SSH to VDS
|
||||||
|
"""
|
||||||
|
if vds_id is None:
|
||||||
|
vds_list()
|
||||||
|
vds_id = input("Enter VDS ID: ")
|
||||||
|
|
||||||
|
vds = Server.get_vds(vds_id)
|
||||||
|
ip = vds['server']['ip']
|
||||||
|
|
||||||
|
os.system('ssh -p {port} root@{ip}'.format(port=port, ip=ip))
|
||||||
|
|
||||||
|
|
||||||
@servers_app.command("start")
|
@servers_app.command("start")
|
||||||
def vds_start(vds_id: Optional[int] = typer.Argument(None)):
|
def vds_start(vds_id: Optional[int] = typer.Argument(None)):
|
||||||
|
Loading…
Reference in New Issue
Block a user