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
-
Hi,
You are using the XAPI Python SDK, meant to be used against a host, not XO.
Two choices: keep using that but point it to the pool master directly OR use XO API instead (eg the REST API). I would advise for the option 2.
-
@olivierlambert How would I do that with the rest api?
-
Well, you gave such little details that I have no idea about how to answer your question.
If it's just sending a command to force shutdown a VM, you can just do this with the appropriate action in the REST API. See https://docs.xen-orchestra.com/restapi for more details
-
@olivierlambert import requests
import os
from requests.auth import HTTPBasicAuthPath 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 issuesif 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