@Gurve Do i have to enable the xo-cli?
Latest posts made by Studmuffn1134
-
RE: Python help
@Gurve Is this for the vm's on the server or the host itself i need the host itself
-
RE: Python help
@TheNorthernLight Well could you do it in a language you know and maybe i would be able to convert it>?
-
RE: Python help
@TheNorthernLight Finally someone gets the reference But what do u think I am doing wrong
-
RE: Python help
@Studmuffn1134 That is what i did and it still does not work I get a status code 200 but it never shuts the host off
-
RE: Python help
@Butcat def shutdown_vm_hosts(host_id,xo_url,auth_token,use_force):
root_dir = os.path.dirname(os.path.abspath(file))
file_path = os.path.join((root_dir),"Certs\fullchain.pem")headers = { 'Content-Type':'application/json', 'Authorization':f'Bearer {auth_token}' } data = { "jsonrpc":"2.0", "method":"host.shutdown", "params":[host_id], "id":1 } try: response = requests.post( xo_url, headers=headers,data=json.dumps(data), verify=file_path ) print(f"Status code: {response.status_code}") if response.status_code in [200, 202, 204]: print(f"✓ Successfully initiated {'force' if use_force else 'clean'} shutdown") return True else: print(f"Error: {response.text}") return False except requests.exceptions.RequestException as e: print(f"Request failed: {e}") return False
-
RE: Python help
@Butcat This was very very very helpful. https://192.168.100.30:2223/rest/v0/host/d2f1374c-728d-4905-85cc-e0d7166a3fbf/actions is there no way to turn off a single host through the api. The interesting part is I have no actions in the host section with that host id?
-
RE: Python help
@Studmuffn1134 said in Python help:
Reply
Is it the same code for the hosts or do I have to use different api links for host actions can you help me with that?
-
RE: Python help
@Butcat It worked thank you so much I never really worked with api's before so I am learning
-
RE: Python help
@Studmuffn1134 stromfamily.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
warnings.warn(
Error: 401 - Unauthorized
That is the output i know about the cert warnings so dont worry about that it is a red herring the 401 though i cant get it to pass any sort of username password or token. I built xo from sources so is there any thing i have to do to enable the rest api and or tell the api to transmit on that dedicated port