requirements.txt and README.md

This commit is contained in:
Lulzette 2022-04-08 15:20:33 +03:00
parent 6e203a5b5a
commit eeeded888f
3 changed files with 55 additions and 1 deletions

16
README.md Normal file
View File

@ -0,0 +1,16 @@
twvdscli
====
Это утилита для управления серверами и сервисами в Timeweb Cloud.
# Установка
Потребуются пакеты typer, prettytable, requests. Ставим их из файла:
```commandline
pip3 install --user -r requirements.txt
```
# Запуск
При первом запуске утилита спросит логин и пароль, после чего запишет их в ~/.config/twvdscli.ini в формате base64 через знак ":".

7
requirements.txt Normal file
View File

@ -0,0 +1,7 @@
click==8.0.4
pip==22.0.4
prettytable==3.2.0
setuptools==60.9.3
typer==0.4.0
wcwidth==0.2.5
wheel==0.37.1

View File

@ -18,6 +18,8 @@ from time import sleep
app = typer.Typer() app = typer.Typer()
servers_app = typer.Typer() servers_app = typer.Typer()
app.add_typer(servers_app, name='vds') app.add_typer(servers_app, name='vds')
backups_app = typer.Typer()
servers_app.add_typer(backups_app, name='backup')
class Server: class Server:
@ -115,6 +117,36 @@ class Server:
return result.json() return result.json()
class Backups:
@staticmethod
def create(vds_id):
disk_id = Server.get_vds(vds_id)['server']['disk_stats']['disk_id']
uri = "https://public-api.timeweb.com/api/v1/backups/vds/{id}/drive/{disk_id}"
result = requests.post(
uri.format(id=vds_id, disk_id=disk_id),
headers=reqHeader
)
if result.ok:
return result.json()
else:
return None
@backups_app.command("create")
def create_backup(vds_id: Optional[int] = typer.Argument(None)):
"""
Create backup of main disk
"""
if vds_id is None:
vds_list()
vds_id = input("Enter VDS ID: ")
result = Backups.create(vds_id)
if result is None:
print(typer.style("Error", fg=typer.colors.RED))
sys.exit(1)
print(result.json())
@app.command("balance") @app.command("balance")
def get_balance(): def get_balance():
@ -297,5 +329,4 @@ if __name__ == '__main__':
print(typer.style("Auth Error", fg=typer.colors.RED)) print(typer.style("Auth Error", fg=typer.colors.RED))
sys.exit(1) sys.exit(1)
reqHeader = {"Authorization": "Bearer " + apikey} reqHeader = {"Authorization": "Bearer " + apikey}
app() app()