Therefore I started to develop a basic discovery script, which should discover all important information of our Solaris and Linux servers and feeds the info in our CMDB. Most of the stuff is straight forward and at best a opportunity to improve my Regex skills, but there are also some challenges which could be interesting for others.
For example, finding out the hostname of a guest ldom (now called Oracle VM Server for SPARC guest VM), which is configured inside the ldom. The real hostname is much more interesting for us than the name of the virtual hardware.
In Solaris 10 update9 you have now the virtinfo utility, which is sometimes able to display the name of the control domain from inside the guest domain, you could use this information to create a mapping.
For our use case this method does not really help, the only possible solution I could find, was by connecting directly with telnet to the console of the guest ldoms. As you can see in the following listening, the hostname "virtualserver1" is printed in the login prompt.
telnet localhost 5000 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Connecting to console "ldom1" in group "ldom1" .... Press ~? for control options .. virtualserver1 console login:
Telnet is not the most friendly and stable interface to script, but with python it's quickly done.
ldm_list_raw = exec_cl("ldm list -p | grep state=active")
consoles = re.findall(r'cons=([0-9]+)', ldm_list_raw)
print "Console: \tHostname of guest ldom"
print "-------- \t----------------------"
for console in consoles:
tn = telnetlib.Telnet("127.0.0.1",console)
tn.write("\n\n\n")
mo = tn.expect([r' (\S*) console login',r'} (ok)'],2)
tn.close()
if mo[1]:
ldom_hostname = mo[1].group(1)
if ldom_hostname == 'ok':
print "%s: \t\tOBP" % console
else:
print "%s: \t\t%s" % (console,ldom_hostname)
This basic script generates the following simple output, if executed from the control domain:
python list-ldom-hostnames.py Console: Hostname of guest ldom -------- ---------------------- 5000: virtualserver1 5002: OBP 5003: virtualserver3 5004: Virtualserver4
Now you can also see a limitation of this method, if the operating system is not running, you won't get the hostname. E.g. the guest ldom on console 5002 from the example is turned on but not booted, it's waiting in the OBP.
Full prove of concept script: list-ldom-hostnames.py
0 comments:
Post a Comment