implemented dbs goto

This commit is contained in:
Lulzette 2022-04-23 11:58:36 +03:00
parent a08e62e619
commit 731b8c5cd4

View File

@ -383,7 +383,7 @@ def get_balance():
@dbs_app.command("list")
def list_dbs():
def dbs_list():
"""
Show list of DBs
ID, State, Name, IP, local IP, Password, Type
@ -421,6 +421,31 @@ def list_dbs():
print(x)
@dbs_app.command("goto")
def dbs_connect(db_id: Optional[int] = typer.Argument(None)):
"""
Connect to DB CLI
"""
cmd_mysql = "mysql -u gen_user -p{password} -h {ip} -P 3306 -D default_db"
cmd_psql = "psql -d default_db -U gen_user -W -p 5432 -h {ip}"
# Get DB ID if not specified
if db_id is None:
dbs_list()
db_id = input("Enter DB ID: ")
# Get type of DB, password, IP
db_data = Dbaas.get(db_id)
db_type = db_data['db']['type']
db_pass = db_data['db']['password']
db_ip = db_data['db']['ip']
if db_type == 'mysql' or db_type == 'mysql5':
os.system(cmd_mysql.format(ip=db_ip, password=db_pass))
elif db_type == 'postgres':
print("Password: ", db_pass)
os.system(cmd_psql.format(ip=db_ip))
@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.")):