@Studmuffn1134 I changed my link from ws:// to https:// and it now gives me this error File "Z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms.venv\Lib\site-packages\jsonrpc_base\jsonrpc.py", line 213, in parse_response
raise ProtocolError(code, message, data)
jsonrpc_base.jsonrpc.ProtocolError: (10, 'invalid parameters', {'error': {'message': 'invalid parameters', 'code': 10, 'data': {'errors': [{'instancePath': '/id', 'schemaPath': '#/properties/id/type', 'keyword': 'type', 'params': {'type': 'string'}, 'message': 'must be string'}]}}, 'id': '0a11ec72-9300-4030-a5d2-a5c0286f3811', 'jsonrpc': '2.0'})
Posts
-
RE: Python help
-
RE: Python help
@Gurve '''def shutdown_vm_hosts(host_id,xo_url,auth_token,use_force):
async def routine(): async with aiohttp.ClientSession() as client: server = Server('ws://192.168.100.30:2223/api/', client) await server.ws_connect() # signIn required result = await server.session.signIn(username='ThePlague', password='No') # email attribute is working in place of username hostUUID ="d2f1374c-728d-4905-85cc-e0d7166a3fbf" #hard shutdown VM #result = await server.vm.stop(id='3f32beeb-ab3f-a8ac-087d-fdc7ed061b58', force=(bool(1))) #clean Shutdown VM #result = await server.vm.stop(id='3f32beeb-ab3f-a8ac-087d-fdc7ed061b58', force=(bool(0))) #bypassbackup and bypassevacuate set off by default but include for wholeness of parameters result = await server.host.stop(id=[hostUUID],bypassBackupCheck=(bool(0)),bypassEvacuate=bool(0)) print (result)''' Traceback (most recent call last): File "z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms\Shutdowntest.py", line 72, in <module> main() # second part of calling the main function ~~~~^^ File "z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms\Shutdowntest.py", line 70, in main shutdown_vm_hosts(l,XO_URL,AUTH_TOKEN,use_force=False) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms\Shutdowntest.py", line 29, in shutdown_vm_hosts asyncio.get_event_loop().run_until_complete(routine()) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^ File "C:\Users\ThePlague\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms\Shutdowntest.py", line 13, in routine await server.ws_connect() File "Z:\Valera\School\Lakeland University\Finished\Programming 2\Python Programs\StudsPrograms\.venv\Lib\site-packages\jsonrpc_websocket\jsonrpc.py", line 68, in ws_connect raise TransportError('Error connecting to server', None, exc) jsonrpc_base.jsonrpc.TransportError: ('Error connecting to server', ServerDisconnectedError('Server disconnected'))
I tried that and that is the error code I get
-
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 -
RE: Python help
import os from requests.auth import HTTPBasicAuth # Path to the certificate root_dir = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.join(root_dir, "Certs\\fullchain.pem") # Define the Xen Orchestra API endpoint # Define the ID of the VM you want to shut down (you can get this from the XO UI or API) VM_ID = '573914d5-69c4-9041-6d3f-6d01f6d29d69' def make_get_request(): USERNAME = 'ThePlague' PASSWORD = 'NO' XO_SERVER_URL = 'https://nordstromfamily.net:2223/rest/v0' BEARER_TOKEN = "NO" try: # Make the GET request using Basic Authentication response = requests.get(XO_SERVER_URL, auth=HTTPBasicAuth(USERNAME, PASSWORD), verify=False) # Set verify=False if you have SSL issues if response.status_code == 200: print("Response from the API:", response.json()) # Print the API response (if JSON) else: print(f"Error: {response.status_code} - {response.text}") # Print error if authentication fails except requests.exceptions.RequestException as e: print(f"Request failed: {e}") if __name__ == '__main__': make_get_request()```
-
RE: Python help
@olivierlambert how do i use the mark down tool hear do i do the '''?
-
RE: Python help
@olivierlambert import requests
import os from requests.auth import HTTPBasicAuth # Path to the certificate root_dir = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.join(root_dir, "Certs\\fullchain.pem") # Define the Xen Orchestra API endpoint # Define the ID of the VM you want to shut down (you can get this from the XO UI or API) VM_ID = '573914d5-69c4-9041-6d3f-6d01f6d29d69' def make_get_request(): USERNAME = 'ThePlague' PASSWORD = 'NO' XO_SERVER_URL = 'https://nordstromfamily.net:2223/rest/v0' BEARER_TOKEN = "NO" try: # Make the GET request using Basic Authentication response = requests.get(XO_SERVER_URL, auth=HTTPBasicAuth(USERNAME, PASSWORD), verify=False) # Set verify=False if you have SSL issues if response.status_code == 200: print("Response from the API:", response.json()) # Print the API response (if JSON) else: print(f"Error: {response.status_code} - {response.text}") # Print error if authentication fails except requests.exceptions.RequestException as e: print(f"Request failed: {e}") if __name__ == '__main__': make_get_request()
Would code like that work i keep getting an authorizaiton error an i know for a fact that my username password or token are working
-
Python help
All I want to do is be able to send force shut offs
Am i able to get help here?
def force_shutdown_vm(vm_uuid): XO_URL = "https://192.168.100.30:2223/" username = "ThePlague" password = "NO" context = ssl._create_unverified_context() try: session = XenAPI.Session(XO_URL,ignore_ssl=True) session.set_ssl_context(context) session.xenapi.login_with_password(username,password) vm_ref = session.xenapi.VM.get_by_uuid(vm_uuid) session.xenapi.VM.Clean_shutdown(vm_ref) print("The VM Shutdown Successfully.") except Exception as e: print(f"Error: {e}") finally: session.xenapi.session.logout()
what am i doing wrong ahhahahahaha
-
Building Xen Orchestra 6 from scratch
How would I build XO 6 from scratch is it similar to the process for XO 5?
-
RE: VM Graceful shutdown using apc network shutdown
@olivierlambert Ihave been tryign to get graceful power off to work with my nas whcih is Truenas by the way but i havent gotten it to work yet oddly i cant seem to get them talking yet
-
RE: VM Graceful shutdown using apc network shutdown
@vmpr So you dont really shutdown the hosts as much as just shutdown the vm's running on the hosts
What is Puppet?
and what i am really worried about is not the vm's themselves per say it is the fact that they are connected over NFS and what would a sudden power loss do to an nfs share would it corrupt it?