implemented dbs goto
This commit is contained in:
parent
a08e62e619
commit
731b8c5cd4
31
twvdscli.py
31
twvdscli.py
@ -257,7 +257,7 @@ def get_snap(vds_id: Optional[int] = typer.Argument(None)):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
x = PrettyTable()
|
x = PrettyTable()
|
||||||
x.field_names = ["VDS ID", "ID", "Created" , "Expire"]
|
x.field_names = ["VDS ID", "ID", "Created", "Expire"]
|
||||||
x.add_row([vds_id, result['restore_point']['id'], result['restore_point']['created_at'], result['restore_point']['expired_at']])
|
x.add_row([vds_id, result['restore_point']['id'], result['restore_point']['created_at'], result['restore_point']['expired_at']])
|
||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
@ -383,7 +383,7 @@ def get_balance():
|
|||||||
|
|
||||||
|
|
||||||
@dbs_app.command("list")
|
@dbs_app.command("list")
|
||||||
def list_dbs():
|
def dbs_list():
|
||||||
"""
|
"""
|
||||||
Show list of DBs
|
Show list of DBs
|
||||||
ID, State, Name, IP, local IP, Password, Type
|
ID, State, Name, IP, local IP, Password, Type
|
||||||
@ -421,9 +421,34 @@ def list_dbs():
|
|||||||
print(x)
|
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")
|
@servers_app.command("goto")
|
||||||
def vds_goto(vds_id: Optional[int] = typer.Argument(None),
|
def vds_goto(vds_id: Optional[int] = typer.Argument(None),
|
||||||
port: int = typer.Option(22, help="Specify non standart SSH port.")):
|
port: int = typer.Option(22, help="Specify non standart SSH port.")):
|
||||||
"""
|
"""
|
||||||
Connect via SSH to VDS
|
Connect via SSH to VDS
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user