Gopi Desaboyina Solaris Blogs

Just another WordPress.com weblog

Parsing ldom-db.xml

In case if you don’t have existing output of ldm ls -l o/p. You can use below python script to parse the existing ldm-db.xml and generate commands for you.

Usage : ./ldom-parse.py ldom-db.xml

#!/usr/bin/env python
# Author - Gopi Desaboyina

#from elementtree import ElementTree as ET
from xml.etree import ElementTree as ET
import sys

# Print usage if ldom-db.xml file is not passed as argument.
if (len(sys.argv)<2 ):
print “Usage : “+sys.argv[0],”ldom-db.xml”
sys.exit(1)
# create a file object by opening it.
xmlfile=open(sys.argv[1])
tree = ET.parse(xmlfile)
#
ldms=tree.findall(‘ldom’)
#
for ldm in ldms: #{A
domain=ldm.find(‘ldom_name’).text
cpus=ldm.find(‘cpu/number’).text
mau=ldm.find(‘mau/number’).text
mem=ldm.find(‘memory/size’).text
print “\n\n\n”
print “LDOM Name: “+domain
print “CPUS : “+cpus
print “MAU : “+mau
print “Memory : “+mem
print “# ldm add-domain”,domain
print “# ldm set-vcpu”,cpus,domain
print “# ldm set-mem”,mem,domain
print “# ldm set-crypto”,mau,domain
#
for pvcc in ldm.findall(‘vcc/vcc_instance’):#{
vcc_name=pvcc.find(‘service_name’).text
min_port=pvcc.find(‘min_port’).text
max_port=pvcc.find(‘max_port’).text
print “\nConsole :\t”+vcc_name,min_port+”-“+max_port
print “# ldm add-vcc port-range=”+min_port+”-“+max_port,vcc_name,domain
#}
for gvcc in ldm.findall(‘console/console_instance’):#{
gvccport=gvcc.find(‘port’).text
print “\nConsole:”+gvccport
print “# ldm set-vcons port=”+gvccport,domain
#}
if ldm.find(‘ldom_name’).text == “primary”:
print “Primary Network :”
for vsws in ldm.findall(‘vsw/vsw_instance’): #{
vsw=vsws.find(‘service_name’).text
netdev=vsws.find(‘dev_path’).text
defvlanid=vsws.find(‘default-vlan-id’).text
defpvid=vsws.find(‘pvid’).text
print “\t\t”, ” Service:”+vsw+\
” Device:”+netdev+\
” VLAN ID:”+defvlanid+\
” PVID:”+defpvid
print “# ldm add-vsw default-vlan-id=”+defvlanid,”pvid=”+defpvid,”net-dev=”+netdev,vsw,domain
print “\nPrimary Disks :”
#}
for pvds in ldm.findall(‘vds/vds_instance’): #{
vdsserver=pvds.find(‘service_name’).text
print “\t VDS Service :”,vdsserver
print “# ldm add-vds”,vdsserver,domain
for pvol in pvds.findall(‘vds_volumes/vds_volume’): #{
phy=pvol.find(‘block_dev’).text
vol=pvol.find(‘vol_name’).text
print “Physical:Volume “+phy,vol
print “# ldm add-vdsdev”,phy,vol+”@”+vdsserver+”\n”
#}}
print “\nGuest Net:”
for nets in ldm.findall(‘network/network_instance’):#{
gvsw=nets.find(‘service_name’).text
gvnet=nets.find(‘vnet_name’).text
vid=” ”
pvid=” ”
if nets.find(‘vid’).text is not None:
vid=nets.find(‘vid’).text
if nets.find(‘pvid’).text is not None:
pvid=nets.find(‘pvid’).text
print “\t\t\t”+”vnet:”+gvnet+” vid:”+vid+” pvid:”+pvid
print “# ldm add-vnet”,”pvid=”+pvid,”vid=”+vid,gvnet,gvsw,domain+” #Caution pvid/vid can be NULL sometimes.So remove them if any of them NULL”
#}
print “\nGuest Disks :”
for vdisks in ldm.findall(‘disk/disk_instance’): #{
gvdisk=vdisks.find(‘vdisk_name’).text
gvds=vdisks.find(‘service_name’).text
gvol=vdisks.find(‘vol_name’).text
print “\t\t\t”,”vdisk:”,gvdisk,”VDS:”+gvds,”Vol:”+gvol
print “# ldm add-vdisk”,gvdisk,gvol+”@”+gvds,domain
#}
print “\nVariables : # ldm set-var … You gotta do yourself buddy”
for vars in ldm.findall(‘variables/var’):#{
print “\t”+vars.find(‘name’).text+”: \””+vars.find(‘value’).text+”\””
#}

#}
# Close the xmlfile which we opened in the starting.
xmlfile.close

 

August 3, 2012 Posted by | Solaris | 1 Comment