<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Python help]]></title><description><![CDATA[<p dir="auto">All I want to do is be able to send force shut offs</p>
<p dir="auto">Am i able to get help here?</p>
<pre><code>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()
</code></pre>
<p dir="auto">what am i doing wrong ahhahahahaha</p>
]]></description><link>https://xcp-ng.org/forum/topic/10622/python-help</link><generator>RSS for Node</generator><lastBuildDate>Wed, 13 May 2026 10:22:16 GMT</lastBuildDate><atom:link href="https://xcp-ng.org/forum/topic/10622.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Mar 2025 00:08:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Python help on Mon, 14 Apr 2025 23:48:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a> 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<br />
raise ProtocolError(code, message, data)<br />
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'})</p>
]]></description><link>https://xcp-ng.org/forum/post/91926</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91926</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Mon, 14 Apr 2025 23:48:32 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Mon, 14 Apr 2025 23:45:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/gurve" aria-label="Profile: Gurve">@<bdi>Gurve</bdi></a> '''def shutdown_vm_hosts(host_id,xo_url,auth_token,use_force):</p>
<pre><code>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 &lt;module&gt;
        
            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'))
</code></pre>
<p dir="auto">I tried that and that is the error code I get</p>
]]></description><link>https://xcp-ng.org/forum/post/91925</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91925</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Mon, 14 Apr 2025 23:45:34 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Sun, 30 Mar 2025 18:11:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a> should be available in XO vm, it was atleast for me, I just used the XO installer script from github.</p>
<p dir="auto">I did a quick search with xo cli now</p>
<blockquote>
<p dir="auto">xo-cli list-commands | egrep 'host.'</p>
</blockquote>
<p dir="auto">in case it looks weird "\." is just to escape the "." which just tells regex I am looking for an actual "."</p>
<pre><code class="language-python">import aiohttp
import asyncio

from jsonrpc_websocket import Server

async def routine():
    async with aiohttp.ClientSession() as client:
        server = Server('ws://[yourXO]/api/', client)

        await server.ws_connect()

        # signIn required
        result = await server.session.signIn(username='[yourXOusername]', password='[yourXOPassword]') # email attribute is working in place of username
        
        #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)

asyncio.get_event_loop().run_until_complete(routine())
</code></pre>
<p dir="auto">I just built all examples into one, here in the end is the host.stop example also</p>
]]></description><link>https://xcp-ng.org/forum/post/91341</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91341</guid><dc:creator><![CDATA[Gurve]]></dc:creator><pubDate>Sun, 30 Mar 2025 18:11:13 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Sun, 30 Mar 2025 17:10:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/gurve" aria-label="Profile: Gurve">@<bdi>Gurve</bdi></a> Do i have to enable the xo-cli?</p>
]]></description><link>https://xcp-ng.org/forum/post/91339</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91339</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Sun, 30 Mar 2025 17:10:52 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Sun, 30 Mar 2025 17:09:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a> Sorry, must have somehow read another reply about vm and mixed them. But pretty sure you should be able to utilise the steps I did for host shutdown</p>
<p dir="auto">xo-cli to get relevant api endpoints, xo-cli to get parameters for said endpoint and then press play</p>
]]></description><link>https://xcp-ng.org/forum/post/91338</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91338</guid><dc:creator><![CDATA[Gurve]]></dc:creator><pubDate>Sun, 30 Mar 2025 17:09:09 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Sun, 30 Mar 2025 03:20:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/gurve" aria-label="Profile: Gurve">@<bdi>Gurve</bdi></a> Is this for the vm's on the server or the host itself i need the host itself</p>
]]></description><link>https://xcp-ng.org/forum/post/91324</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91324</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Sun, 30 Mar 2025 03:20:13 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Fri, 28 Mar 2025 19:24:45 GMT]]></title><description><![CDATA[<p dir="auto">Did some "kicking" around in python, I don't python that much so "readers beware"</p>
<p dir="auto">How did i figure it out, the french blog from <a href="https://xcp-ng.org/forum/topic/4538/xoa-json-rpc-call-basic-exemple/12">here</a> was useful, but only showed listing methods. I was still very confused as to how to call the vm.stop and which parameters it took.</p>
<h2>Enter xo-cli <img src="https://xcp-ng.org/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/2764.png?v=ab1daa29750" class="not-responsive emoji emoji-android emoji--heart" style="height:23px;width:auto;vertical-align:middle" title="&lt;3" alt="❤" /></h2>
<p dir="auto">xo-cli uses jsonrpc but is CLi only, but you can get very nice info from it just have to register and call  "list-methods". should be available on your xo VM</p>
<pre><code class="language-bash">xo-cli register http://[yourXO].example.com [yourusername]
#after registering/authenticating
xo-cli list-commands | egrep 'vm\.' --color=always
</code></pre>
<p dir="auto">here you will get a nice list of all "methods" in jsonrpc related to vm and a line about vm.stop:</p>
<blockquote>
<p dir="auto">vm.stop id=&lt;string&gt; [force=&lt;boolean&gt;] [forceShutdownDelay=&lt;number&gt;] [bypassBlockedOperation=&lt;boolean&gt;]</p>
</blockquote>
<p dir="auto">which was enough information to alter the french guy's (Baron) example into this:</p>
<pre><code class="language-python">import aiohttp
import asyncio

from jsonrpc_websocket import Server

async def routine():
    async with aiohttp.ClientSession() as client:
        server = Server('ws://[yourXO]/api/', client)

        await server.ws_connect()

        # signIn required
        result = await server.session.signIn(username='[xoAdmin]', password='[xoAdmin]') # email attribute is working in place of username
        
        #hard shutdown
        #result = await server.vm.stop(id='3f32beeb-ab3f-a8ac-087d-fdc7ed061b58', force=(bool(1)))
        
        #clean Shutdown
        result = await server.vm.stop(id='3f32beeb-ab3f-a8ac-087d-fdc7ed061b58', force=(bool(0)))
        
        print (result)

asyncio.get_event_loop().run_until_complete(routine())


</code></pre>
]]></description><link>https://xcp-ng.org/forum/post/91298</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91298</guid><dc:creator><![CDATA[Gurve]]></dc:creator><pubDate>Fri, 28 Mar 2025 19:24:45 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Wed, 26 Mar 2025 22:08:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/thenorthernlight" aria-label="Profile: TheNorthernLight">@<bdi>TheNorthernLight</bdi></a> Well could you do it in a language you know and maybe i would be able to convert it&gt;?</p>
]]></description><link>https://xcp-ng.org/forum/post/91200</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91200</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Wed, 26 Mar 2025 22:08:03 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Wed, 26 Mar 2025 16:14:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a> Sadly, I dont know squat about python, sorry!</p>
]]></description><link>https://xcp-ng.org/forum/post/91188</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91188</guid><dc:creator><![CDATA[TheNorthernLight]]></dc:creator><pubDate>Wed, 26 Mar 2025 16:14:26 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Tue, 25 Mar 2025 22:47:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/thenorthernlight" aria-label="Profile: TheNorthernLight">@<bdi>TheNorthernLight</bdi></a> Finally someone gets the reference But what do u think I am doing wrong</p>
]]></description><link>https://xcp-ng.org/forum/post/91146</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91146</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Tue, 25 Mar 2025 22:47:07 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Tue, 25 Mar 2025 18:14:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a> LOL at "ThePlague"... (hackers unite!)</p>
]]></description><link>https://xcp-ng.org/forum/post/91142</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91142</guid><dc:creator><![CDATA[TheNorthernLight]]></dc:creator><pubDate>Tue, 25 Mar 2025 18:14:51 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Tue, 25 Mar 2025 17:51:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a> That is what i did and it still does not work I get a status code 200 but it never shuts the host off</p>
]]></description><link>https://xcp-ng.org/forum/post/91139</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91139</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Tue, 25 Mar 2025 17:51:45 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Tue, 25 Mar 2025 17:12:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/butcat" aria-label="Profile: Butcat">@<bdi>Butcat</bdi></a> def shutdown_vm_hosts(host_id,xo_url,auth_token,use_force):<br />
root_dir = os.path.dirname(os.path.abspath(<strong>file</strong>))<br />
file_path = os.path.join((root_dir),"Certs\fullchain.pem")</p>
<pre><code>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
</code></pre>
]]></description><link>https://xcp-ng.org/forum/post/91138</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91138</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Tue, 25 Mar 2025 17:12:54 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Tue, 25 Mar 2025 09:40:26 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a>,</p>
<p dir="auto">You’re right—some actions (like certain host operations) aren’t fully available in the REST API yet. Right now, most "GET" methods work, and some actions (like those for VMs and snapshots) are implemented. However, the REST API is still a work in progress.</p>
<p dir="auto">The Xen Orchestra team is currently focusing on:</p>
<ul>
<li>
<p dir="auto">Non-admin user management (coming soon).</p>
</li>
<li>
<p dir="auto">Save/backup functionality (planned for the next few months).</p>
</li>
</ul>
<p dir="auto">Since not everything is ready in REST yet, you might need to use both REST and JSON-RPC to access all operations.</p>
<p dir="auto">For JSON-RPC, check out:</p>
<p dir="auto"><a href="https://docs.xcp-ng.org/management/manage-at-scale/xo-api/#-json-rpc-over-websockets" target="_blank" rel="noopener noreferrer nofollow ugc">Official JSON-RPC Documentation<br />
</a></p>
<p dir="auto"><a href="https://xcp-ng.org/forum/topic/4538/xoa-json-rpc-call-basic-exemple">Basic JSON-RPC Examples (Forum Discussion)</a></p>
]]></description><link>https://xcp-ng.org/forum/post/91124</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91124</guid><dc:creator><![CDATA[Butcat]]></dc:creator><pubDate>Tue, 25 Mar 2025 09:40:26 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Fri, 21 Mar 2025 13:08:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/butcat" aria-label="Profile: Butcat">@<bdi>Butcat</bdi></a> This was very very very helpful. <a href="https://192.168.100.30:2223/rest/v0/host/d2f1374c-728d-4905-85cc-e0d7166a3fbf/actions" target="_blank" rel="noopener noreferrer nofollow ugc">https://192.168.100.30:2223/rest/v0/host/d2f1374c-728d-4905-85cc-e0d7166a3fbf/actions</a> 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?</p>
]]></description><link>https://xcp-ng.org/forum/post/91051</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91051</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Fri, 21 Mar 2025 13:08:41 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Fri, 21 Mar 2025 07:34:23 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a>, welcome!</p>
<p dir="auto">The provided python code will resembled yes however the path will be specific to the type and actions you need to perform. Also the returned payload will also be different.<br />
You can find bellow some informations that can help you understand and use the Xen Orchestra API.</p>
<p dir="auto">Here is a summary provided when searching with google about REST APIs patterns:</p>
<p dir="auto"><strong>Understanding REST: A Guide to API Design Patterns</strong></p>
<p dir="auto"><strong>REST (Representational State Transfer) is a widely-used software architectural style that defines how APIs should be designed. It emphasizes simplicity, scalability, and efficiency, making it a popular choice for building web services and applications. REST APIs use standard HTTP methods (such as GET, POST, PUT, and DELETE) to interact with resources, which are identified by URLs. This approach makes REST APIs intuitive and easy to work with.</strong></p>
<p dir="auto">To get the most out of REST, it’s important to understand its patterns and conventions. These patterns will not only improve your foundational knowledge but also help you interact with APIs.</p>
<p dir="auto">REST API Path Structure</p>
<p dir="auto">A typical REST API path follows a structured format, often resembling this pattern:</p>
<pre><code>http://host_or_domain_name/&lt;types&gt;/&lt;id&gt;/&lt;action_verb&gt;
</code></pre>
<p dir="auto">Here’s a breakdown of the components:</p>
<ul>
<li>
<p dir="auto">&lt;types&gt;: Represents the type of resource you’re interacting with (e.g., vms, users, networks).</p>
</li>
<li>
<p dir="auto">&lt;id&gt;: A unique identifier for a specific resource (e.g., a VM ID or user ID).</p>
</li>
<li>
<p dir="auto">&lt;action_verb&gt;: Specifies the action to be performed on the resource (e.g., actions, start, stop).</p>
</li>
</ul>
<p dir="auto"><strong>HTTP Methods in REST</strong></p>
<p dir="auto">REST APIs use specific HTTP methods to perform operations on resources:</p>
<ul>
<li>
<p dir="auto">GET: Retrieves data. For example, fetching a list of resources or details of a specific resource.</p>
</li>
<li>
<p dir="auto">POST: Creates a new resource.</p>
</li>
<li>
<p dir="auto">PUT: Replaces or updates an entire resource.</p>
</li>
<li>
<p dir="auto">PATCH: Updates specific parts of a resource.</p>
</li>
<li>
<p dir="auto">DELETE: Removes a resource.</p>
</li>
</ul>
<p dir="auto">Example: REST API Paths for Virtual Machines (VMs)<br />
Let’s look at some examples using a vms resource type:</p>
<p dir="auto">List all VMs:</p>
<pre><code>GET http://host/rest/v0/vms
</code></pre>
<p dir="auto">This returns a list of VM IDs.</p>
<p dir="auto">Get details of a specific VM:</p>
<pre><code>GET http://host/rest/v0/vms/&lt;id&gt;
</code></pre>
<p dir="auto">This returns detailed information about the VM with the specified ID.</p>
<p dir="auto">List available actions for a VM:</p>
<pre><code>GET http://host/rest/v0/vms/&lt;id&gt;/actions
</code></pre>
<p dir="auto">This returns all actions that can be performed on the specified VM (e.g., start, stop, reboot).</p>
<p dir="auto">Perform an action on a VM:</p>
<pre><code>POST http://host/rest/v0/vms/&lt;id&gt;/actions/&lt;your-action&gt;
</code></pre>
<p dir="auto">This performs the specified action (e.g., start, stop) on the VM.</p>
<p dir="auto">Exploring Available REST Endpoints<br />
If you’re working with a REST API like Xen Orchestra, you can explore the available endpoints by navigating to the base URL in your browser or using a tool like Postman. For example:</p>
<pre><code>GET http://host/rest/v0
</code></pre>
<p dir="auto">This will return a list of available resource types and operations, such as:</p>
<pre><code>[
  "/rest/v0/hosts",
  "/rest/v0/messages",
  "/rest/v0/networks",
  "/rest/v0/pifs",
  "/rest/v0/pools",
  "/rest/v0/srs",
  "/rest/v0/vbds",
  "/rest/v0/vdi-snapshots",
  "/rest/v0/vdis",
  "/rest/v0/vifs",
  "/rest/v0/vm-controllers",
  "/rest/v0/vm-snapshots",
  "/rest/v0/vm-templates",
  "/rest/v0/vms",
  "/rest/v0/backup",
  "/rest/v0/groups",
  "/rest/v0/restore",
  "/rest/v0/tasks",
  "/rest/v0/servers",
  "/rest/v0/users",
  "/rest/v0/dashboard",
  "/rest/v0/alarms",
  "/rest/v0/docs"
]
</code></pre>
<p dir="auto">From here, you can follow the REST patterns described above to query specific resources or perform actions.</p>
<p dir="auto">Hope this help! <img src="https://xcp-ng.org/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=ab1daa29750" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:23px;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
]]></description><link>https://xcp-ng.org/forum/post/91035</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91035</guid><dc:creator><![CDATA[Butcat]]></dc:creator><pubDate>Fri, 21 Mar 2025 07:34:23 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Thu, 20 Mar 2025 22:16:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a> said in <a href="/forum/post/91028">Python help</a>:</p>
<blockquote>
<p dir="auto">Reply</p>
</blockquote>
<p dir="auto">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?</p>
]]></description><link>https://xcp-ng.org/forum/post/91030</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91030</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Thu, 20 Mar 2025 22:16:20 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Thu, 20 Mar 2025 21:52:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/butcat" aria-label="Profile: Butcat">@<bdi>Butcat</bdi></a> It worked thank you so much I never really worked with api's before so I am learning</p>
]]></description><link>https://xcp-ng.org/forum/post/91028</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/91028</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Thu, 20 Mar 2025 21:52:41 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Wed, 19 Mar 2025 14:06:45 GMT]]></title><description><![CDATA[<p dir="auto">Hi there <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a> ,</p>
<p dir="auto">I've looked at your code and identified a few issues:</p>
<ol>
<li>You're trying to use basic auth (username/password), but Xen Orchestra's API typically uses token authentication through cookies</li>
<li>You're making a GET request to the base URL instead of a specific API endpoint</li>
<li>You're not using the <code>/vms/{vm_id}/actions/hard_shutdown</code> or <code>/vms/{vm_id}/actions/clean_shutdown</code> endpoints</li>
</ol>
<p dir="auto">I was able to call successfully the shutdown endpoints but with verify off.  Also FYI, I was using a lab and I did not build it from source however if you are using the latest version the API should be available.</p>
<p dir="auto">Link for the swagger documentation is:  <a href="http://host/rest/v0/docs/" target="_blank" rel="noopener noreferrer nofollow ugc">http://host/rest/v0/docs/</a></p>
<pre><code class="language-python">#!/usr/bin/env python3

import requests
import os
import sys
from urllib3.exceptions import InsecureRequestWarning

# Disable insecure HTTPS warnings.
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

def shutdown_vm(vm_id, xo_url, auth_token, use_force=True):
    action = "hard_shutdown" if use_force else "clean_shutdown"

    endpoint = f"{xo_url}/rest/v0/vms/{vm_id}/actions/{action}"
    
    print(f"Sending {action} request for VM {vm_id}...")
    
    headers = {
        'Cookie': f'authenticationToken={auth_token}',
        'Content-Type': 'application/json'
    }
    
    try:
        response = requests.post(
            endpoint,
            headers=headers,
            verify=False
        )
        
        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

VM_ID = 'your_vm_id_here'
XO_URL = 'https://your_xo_url_here'
# You can navigate to the XO GUI and in the user section create an auth token. 
AUTH_TOKEN = 'your_auth_token_here'

shutdown_vm(VM_ID, XO_URL, AUTH_TOKEN)
</code></pre>
<p dir="auto">I hope it will help you fix the issue on your side. Please let me know if I can help with anything else.</p>
]]></description><link>https://xcp-ng.org/forum/post/90945</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/90945</guid><dc:creator><![CDATA[Butcat]]></dc:creator><pubDate>Wed, 19 Mar 2025 14:06:45 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Wed, 19 Mar 2025 13:06:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a> <a href="http://stromfamily.net" target="_blank" rel="noopener noreferrer nofollow ugc">stromfamily.net</a>'. Adding certificate verification is strongly advised. See: <a href="https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings" target="_blank" rel="noopener noreferrer nofollow ugc">https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings</a><br />
warnings.warn(<br />
Error: 401 - Unauthorized<br />
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</p>
]]></description><link>https://xcp-ng.org/forum/post/90940</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/90940</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Wed, 19 Mar 2025 13:06:21 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Wed, 19 Mar 2025 13:04:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/studmuffn1134" aria-label="Profile: Studmuffn1134">@<bdi>Studmuffn1134</bdi></a></p>
<pre><code class="language-import">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()```</code></pre>
]]></description><link>https://xcp-ng.org/forum/post/90939</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/90939</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Wed, 19 Mar 2025 13:04:10 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Wed, 19 Mar 2025 12:48:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/olivierlambert" aria-label="Profile: olivierlambert">@<bdi>olivierlambert</bdi></a> how do i  use the mark down tool hear do i do the '''?</p>
]]></description><link>https://xcp-ng.org/forum/post/90936</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/90936</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Wed, 19 Mar 2025 12:48:07 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Wed, 19 Mar 2025 10:30:36 GMT]]></title><description><![CDATA[<p dir="auto">Please use the markdown syntax (I edited your post) otherwise it's impossible to read your code.</p>
<p dir="auto">Also please paste the error. I'm asking the DevOps Tool team to take a look.</p>
]]></description><link>https://xcp-ng.org/forum/post/90926</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/90926</guid><dc:creator><![CDATA[olivierlambert]]></dc:creator><pubDate>Wed, 19 Mar 2025 10:30:36 GMT</pubDate></item><item><title><![CDATA[Reply to Python help on Wed, 19 Mar 2025 10:29:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/olivierlambert" aria-label="Profile: olivierlambert">@<bdi>olivierlambert</bdi></a> import requests</p>
<pre><code>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()
</code></pre>
<p dir="auto">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</p>
]]></description><link>https://xcp-ng.org/forum/post/90917</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/90917</guid><dc:creator><![CDATA[Studmuffn1134]]></dc:creator><pubDate>Wed, 19 Mar 2025 10:29:32 GMT</pubDate></item></channel></rss>