Anthony Xu 0366dd093c use slaveconnection instead of masterconnection for all host plugin calls.
tested by creating domr and user vm and migrating them

1. if you add host for kvm , you need specify kvm://ip_address, otherwiset there is no to differ kvm and xenserver hosts, edison cloud you please test this, may need some minor fixes.

2. if you want to session inside your plugin call, you can not use the one which is passed in, due to it is a slavesession, you need to call get_xapi_session() to get a new local session and use it. I have modified some of these, I may ignore some. Please let me know if you see XENAPI_PLUGIN_EXCEPTION.
2010-08-23 18:01:39 -07:00

37 lines
1.2 KiB
Python

#!/usr/bin/python
# $Id: hostvmstats.py 10054 2010-06-29 22:09:31Z abhishek $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/hypervisor/xenserver/hostvmstats.py $
import XenAPI
import urllib
import time
import logging
logging.basicConfig(filename='/tmp/xapilog',level=logging.DEBUG)
def get_stats(session, collect_host_stats, consolidation_function, interval, start_time):
try:
if collect_host_stats == "true" :
url = "http://localhost/rrd_updates?"
url += "session_id=" + session
url += "&host=" + collect_host_stats
url += "&cf=" + consolidation_function
url += "&interval=" + str(interval)
url += "&start=" + str(int(time.time())-100)
else :
url = "http://localhost/rrd_updates?"
url += "session_id=" + session
url += "&host=" + collect_host_stats
url += "&cf=" + consolidation_function
url += "&interval=" + str(interval)
url += "&start=" + str(int(time.time())-100)
logging.debug("Calling URL: %s",url)
sock = urllib.URLopener().open(url)
xml = sock.read()
sock.close()
logging.debug("Size of returned XML: %s",len(xml))
return xml
except Exception,e:
logging.exception("get_stats() failed")
raise