Compare commits
No commits in common. "1436a8d7777e187d8ff5d68a5146e231387e897b" and "efb2fc09ee389a47e006115c32f0083ccee2e6ef" have entirely different histories.
1436a8d777
...
efb2fc09ee
39
twvdscli.py
39
twvdscli.py
@ -498,67 +498,46 @@ def dbs_connect(db_id: Optional[int] = typer.Argument(None)):
|
|||||||
@servers_app.command("create")
|
@servers_app.command("create")
|
||||||
def vds_create(
|
def vds_create(
|
||||||
name: str = typer.Option(..., help="VDS Name"),
|
name: str = typer.Option(..., help="VDS Name"),
|
||||||
os_id: int = typer.Option(..., help="OS ID"),
|
os: int = typer.Option(..., help="OS ID"),
|
||||||
preset: int = typer.Option(17, help="Preset ID"),
|
preset: int = typer.Option(17, help="OS ID"),
|
||||||
comment: str = typer.Option("", help="Comment")
|
comment: str = typer.Option("", help="Comment")
|
||||||
):
|
):
|
||||||
# get user group
|
|
||||||
group_uri = "https://public-api.timeweb.com/api/v1/accounts/{user}/group"
|
|
||||||
# get username from saved base64
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config.read(os.path.join(os.getenv('HOME'), '.config', 'twvdscli.ini'))
|
|
||||||
based = config.get('api', 'key', fallback=None)
|
|
||||||
based = base64.b64decode(based)
|
|
||||||
based = str(based, 'utf-8')
|
|
||||||
user = based.split(':')[0]
|
|
||||||
|
|
||||||
group_id = requests.get(
|
|
||||||
group_uri.format(user=user), headers=reqHeader
|
|
||||||
)
|
|
||||||
# finally get group id
|
|
||||||
if group_id.ok:
|
|
||||||
group_id = group_id.json()['groups'][0]['id']
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"server": {
|
"server": {
|
||||||
"configuration": {
|
"configuration": {
|
||||||
"caption": name,
|
"caption": name,
|
||||||
# "disk_size": 5, # dont give a fuck
|
# "disk_size": 5, # dont give a fuck
|
||||||
# "network_bandwidth": 100, # dont give a fuck
|
# "network_bandwidth": 100, # dont give a fuck
|
||||||
"os": os_id, # 47 - ubuntu 18.04
|
"os": os, # 47 - ubuntu 18.04
|
||||||
# "xen_cpu": 2, # dont give a fuck
|
# "xen_cpu": 2, # dont give a fuck
|
||||||
# "xen_ram": 4096, # dont give a fuck
|
# "xen_ram": 4096, # dont give a fuck
|
||||||
"ddos_guard": False
|
"ddos_guard": False
|
||||||
},
|
},
|
||||||
"comment": comment,
|
"comment": comment,
|
||||||
"group_id": group_id, # https://public-api.timeweb.com/api/v1/accounts/{user}/group
|
"group_id": 350519, # https://public-api.timeweb.com/api/v1/accounts/{user}/group
|
||||||
"name": "string", # what is this for?
|
"name": "string", # what is this for?
|
||||||
"preset_id": preset, # you can not create vds without this, but how to create flexible vds? (preset example: 20)
|
"preset_id": preset, # you can not create vds without this, but how to create flexible vds? (example: 20)
|
||||||
"install_ssh_key": "",
|
"install_ssh_key": "",
|
||||||
"server_id": None,
|
"server_id": None,
|
||||||
"local_networks": []
|
"local_networks": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
print(data)
|
||||||
|
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
"https://public-api.timeweb.com/api/v1/vds",
|
"https://public-api.timeweb.com/api/v1/vds",
|
||||||
headers=reqHeader,
|
headers=reqHeader,
|
||||||
json=data
|
json=data
|
||||||
)
|
)
|
||||||
|
print(response.json)
|
||||||
|
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
print(typer.style("Error", fg=typer.colors.RED))
|
print(typer.style("Error", fg=typer.colors.RED))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
response = response.json()
|
response = response.json()
|
||||||
for frame in cycle(r'-\|/'):
|
print(response)
|
||||||
state = Server.get_vds(response['server']['id'])
|
|
||||||
if state:
|
|
||||||
if state['server']['status'] == 'on':
|
|
||||||
print(typer.style("\nCreated: " + response['server']['configuration']['caption'], fg=typer.colors.GREEN))
|
|
||||||
break
|
|
||||||
print('\r', frame, sep='', end='', flush=True)
|
|
||||||
sleep(0.1)
|
|
||||||
|
|
||||||
|
|
||||||
@servers_app.command("goto")
|
@servers_app.command("goto")
|
||||||
|
Loading…
Reference in New Issue
Block a user