Hi all. I’m using opennebula 6.8.0.
I wrote a script that gives me information about virtual machine number 6.
I want to modify it so that information about the last created virtual machine (the machine with the highest ID value) is displayed. Help me do this.
The script:
import requests
import xml.etree.ElementTree as ET
import html
url = ‘http://IP:2633/RPC2’
headers = {‘Content-Type’: ‘application/xml’}
username = ‘oneadmin’
password = ‘passwd’
auth = (username, password)
xml_request = <?xml version="1.0"?>
< methodCall>
< methodName>one.vm.info< /methodName>
< params>
< param>
< value>< string>oneadmin:passwd< /string>< /value>
< /param>
< param>
< value>< int>6< /int>< /value>
< /param>
< /params>
</ methodCall>
response = requests.post(url, headers=headers, auth=auth, data=xml_request)
decoded_response = html.unescape(response.text)
root = ET.fromstring(decoded_response)
creator_tag = root.find(“.//UNAME”)
if creator_tag is not None:
creator = creator_tag.text
else:
creator = “CREATOR INFO NOT FOUND.”
vnc_port_tag = root.find(“.//PORT”)
if vnc_port_tag is not None and vnc_port_tag.text:
vnc_port = vnc_port_tag.text
else:
vnc_port = “VNC INFO NOT FOUND.”
print(f"VM CREATOR: {creator}“)
print(f"PORT VNC: {vnc_port}”)