Skip to content

Instantly share code, notes, and snippets.

@kenee
Created August 11, 2014 14:45
Show Gist options
  • Save kenee/f47d88ca723e01ca7979 to your computer and use it in GitHub Desktop.
Save kenee/f47d88ca723e01ca7979 to your computer and use it in GitHub Desktop.
# -*- coding: UTF-8 -*-
import XenAPI
import os
class XenController():
def __init__(self, URL, UserName, Password):
self.session = XenAPI.Session(URL)
self.session.xenapi.login_with_password(UserName, Password)
def GET_VM_IP(self):
vms = self.session.xenapi.VM.get_all()
vm_name = ""
vm_uuid = ""
vm_ref = ""
my_snapshot = ""
for vm in vms:
record = self.session.xenapi.VM.get_record(vm)
vm_name = record["name_label"]
vm_uuid = record["uuid"]
#print "vm_name == ", vm_name
#print "vm_uuid == ", vm_uuid
#print "vm == ", vm
if vm_name == "EN_Win2008_X32_TVM":
vm_ref = vm
break
for VIF in self.session.xenapi.VM.get_VIFs(vm_ref):
allVIF = self.session.xenapi.VIF.get_record(VIF)
CNetwork = allVIF["metrics"]
print "myPIF == ", allVIF
print "MAC == ", allVIF["MAC"]
#print "VM == ", allVIF["VM"]
#VM_Network = self.session.xenapi.network.get_record(CNetwork)
vgm = self.session.xenapi.VM.get_guest_metrics(vm_ref)
#os = self.session.xenapi.VM_guest_metrics.get_os_version(vgm)
os = self.session.xenapi.VM_guest_metrics.get_networks(vgm)
#print type(os["name"].encode("cp950"))
#print os["name"].encode("utf-8")
if "0/ip" in os.keys():
print os["0/ip"]
print os
def main2():
URL = "http://192.168.3.3"
UserName = "root"
Password = "moldex3d"
xen = XenController(URL, UserName, Password)
xen.GET_VM_IP()
if __name__ == "__main__":
main2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment