Cloning
This commit is contained in:
parent
ceeddaca7d
commit
bc3510b937
40
twvdscli.py
40
twvdscli.py
@ -84,6 +84,21 @@ class Server:
|
|||||||
else:
|
else:
|
||||||
return result.json()
|
return result.json()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def clone(vds_id):
|
||||||
|
"""
|
||||||
|
Clone VDS
|
||||||
|
"""
|
||||||
|
uri = "https://public-api.timeweb.com/api/v1/vds/{id}/{action}"
|
||||||
|
result = requests.post(
|
||||||
|
uri.format(id=vds_id, action='clone'),
|
||||||
|
headers=reqHeader
|
||||||
|
)
|
||||||
|
if not result.ok:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return result.json()
|
||||||
|
|
||||||
|
|
||||||
@app.command("balance")
|
@app.command("balance")
|
||||||
def get_balance():
|
def get_balance():
|
||||||
@ -148,6 +163,31 @@ def vds_stop(vds_id: Optional[int] = typer.Argument(None)):
|
|||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
|
@servers_app.command("clone")
|
||||||
|
def vds_clone(vds_id: Optional[int] = typer.Argument(None)):
|
||||||
|
"""
|
||||||
|
Clone VDS, show cute spinner until VDS stops
|
||||||
|
"""
|
||||||
|
if vds_id is None:
|
||||||
|
vds_list()
|
||||||
|
vds_id = input("Enter VDS ID: ")
|
||||||
|
new_vds = Server.clone(vds_id)
|
||||||
|
if new_vds is None:
|
||||||
|
print(typer.style("Error", fg=typer.colors.RED))
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
new_vds = new_vds['server']
|
||||||
|
|
||||||
|
for frame in cycle(r'-\|/'):
|
||||||
|
state = Server.get_vds(new_vds['id'])
|
||||||
|
if state:
|
||||||
|
if state['server']['status'] == 'on':
|
||||||
|
print(typer.style("\nCloned: " + new_vds['configuration']['caption'], fg=typer.colors.GREEN))
|
||||||
|
break
|
||||||
|
print('\r', frame, sep='', end='', flush=True)
|
||||||
|
sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
@servers_app.command("list")
|
@servers_app.command("list")
|
||||||
def vds_list():
|
def vds_list():
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user