Skip to content

Instantly share code, notes, and snippets.

@jk0
Created October 8, 2014 03:56
Show Gist options
  • Select an option

  • Save jk0/055bf48125f3f8483c07 to your computer and use it in GitHub Desktop.

Select an option

Save jk0/055bf48125f3f8483c07 to your computer and use it in GitHub Desktop.
import XenAPI
XENAPI_SESSION = None
def get_session():
xen_api_url = "http://0.0.0.0"
xen_username = "username"
xen_password = "password"
try:
session = XenAPI.Session(xen_api_url)
session.xenapi.login_with_password(xen_username, xen_password)
except XenAPI.Failure as e:
raise SystemExit(e.details[2])
return session
def call_xenapi(method, *args):
# NOTE(jk0): I hate using globals but this will have to do for now.
global XENAPI_SESSION
if XENAPI_SESSION is None:
XENAPI_SESSION = get_session()
return XENAPI_SESSION.xenapi_request(method, args)
vm_ref = call_xenapi("VM.get_by_name_label", "pre-install 6")
print call_xenapi("VM.revert", vm_ref)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment