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
-
@Studmuffn1134 LOL at "ThePlague"... (hackers unite!)
-
@TheNorthernLight Finally someone gets the reference But what do u think I am doing wrong
-
@Studmuffn1134 Sadly, I dont know squat about python, sorry!
-
@TheNorthernLight Well could you do it in a language you know and maybe i would be able to convert it>?
-
Did some "kicking" around in python, I don't python that much so "readers beware"
How did i figure it out, the french blog from here 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.
Enter xo-cli
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
xo-cli register http://[yourXO].example.com [yourusername] #after registering/authenticating xo-cli list-commands | egrep 'vm\.' --color=always
here you will get a nice list of all "methods" in jsonrpc related to vm and a line about vm.stop:
vm.stop id=<string> [force=<boolean>] [forceShutdownDelay=<number>] [bypassBlockedOperation=<boolean>]
which was enough information to alter the french guy's (Baron) example into this:
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())
-
@Gurve Is this for the vm's on the server or the host itself i need the host itself
-
@Studmuffn1134 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
xo-cli to get relevant api endpoints, xo-cli to get parameters for said endpoint and then press play
-
@Gurve Do i have to enable the xo-cli?
-
@Studmuffn1134 should be available in XO vm, it was atleast for me, I just used the XO installer script from github.
I did a quick search with xo cli now
xo-cli list-commands | egrep 'host.'
in case it looks weird "\." is just to escape the "." which just tells regex I am looking for an actual "."
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())
I just built all examples into one, here in the end is the host.stop example also