added stop
This commit is contained in:
parent
cec099b97e
commit
a58f272bf7
22
main.py
22
main.py
@ -30,6 +30,17 @@ class Servers:
|
|||||||
)
|
)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def stop(name):
|
||||||
|
endpoint = 'https://api.cloudvps.reg.ru/v1/reglets/{id}/actions'
|
||||||
|
data = {"type": "stop"}
|
||||||
|
list_of_servers = Servers.list()
|
||||||
|
for i in list_of_servers['reglets']:
|
||||||
|
if i['name'] == name:
|
||||||
|
result = requests.post(endpoint.format(id=i['id']), headers=reqHeader, json=data)
|
||||||
|
return result.json()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_balance():
|
def get_balance():
|
||||||
response = requests.get("https://api.cloudvps.reg.ru/v1/balance_data", headers=reqHeader)
|
response = requests.get("https://api.cloudvps.reg.ru/v1/balance_data", headers=reqHeader)
|
||||||
@ -37,7 +48,7 @@ def get_balance():
|
|||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def get_tariffs():
|
def list_plans():
|
||||||
response = requests.get("https://api.cloudvps.reg.ru/v1/prices", headers=reqHeader)
|
response = requests.get("https://api.cloudvps.reg.ru/v1/prices", headers=reqHeader)
|
||||||
print('{0:17} {1:5} {2:5} {3:6}'.format('name', 'hour', 'month', 'unit'))
|
print('{0:17} {1:5} {2:5} {3:6}'.format('name', 'hour', 'month', 'unit'))
|
||||||
for i in response.json()['prices']:
|
for i in response.json()['prices']:
|
||||||
@ -51,7 +62,7 @@ def balance():
|
|||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def list_servers():
|
def servers_list():
|
||||||
list_of_servers = Servers.list()
|
list_of_servers = Servers.list()
|
||||||
print('{0:7} {1:17} {2:2} {3:5} {4:4}'.format('state', 'name', 'vcpus', 'memory', 'disk'))
|
print('{0:7} {1:17} {2:2} {3:5} {4:4}'.format('state', 'name', 'vcpus', 'memory', 'disk'))
|
||||||
for i in list_of_servers['reglets']:
|
for i in list_of_servers['reglets']:
|
||||||
@ -70,10 +81,15 @@ def list_os():
|
|||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def create_server(name: str = typer.Option(...), tariff: str = typer.Option(...), image: str = typer.Option(...)):
|
def servers_create(name: str = typer.Option(...), tariff: str = typer.Option(...), image: str = typer.Option(...)):
|
||||||
print(Servers.create(name=name, tariff=tariff, image=image))
|
print(Servers.create(name=name, tariff=tariff, image=image))
|
||||||
|
|
||||||
|
|
||||||
|
@app.command()
|
||||||
|
def servers_stop(name: str = typer.Option(...)):
|
||||||
|
print(Servers.stop(name=name))
|
||||||
|
|
||||||
|
|
||||||
def get_api_key():
|
def get_api_key():
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(os.path.join(os.getenv('HOME'), '.config', 'regructl.ini'))
|
config.read(os.path.join(os.getenv('HOME'), '.config', 'regructl.ini'))
|
||||||
|
Loading…
Reference in New Issue
Block a user