incubator-tashi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rg...@apache.org
Subject svn commit: r1161555 - in /incubator/tashi/branches/zoni-dev/trunk: etc/ src/zoni/client/ src/zoni/extra/ src/zoni/hardware/ src/zoni/install/pxe/ src/zoni/system/registration/register/ src/zoni/system/registration/www/
Date Thu, 25 Aug 2011 13:20:58 GMT
Author: rgass
Date: Thu Aug 25 13:20:57 2011
New Revision: 1161555

URL: http://svn.apache.org/viewvc?rev=1161555&view=rev
Log:
util.py
adding a mac normalization function

register_node
Add zoniroot and few other fixes

zoni-register
moving pythonpath setup till after we read the config file

zoniPxeSetup
add registrationBaseDir

dellswitch
add telnet support
add accessmode (ssh/telnet) via config file
removed addition login code and login via the normal method
Use normalize mac since 62xx switches report it differently.
Pull version via snmp instead of through the cli since 62xx and 52xx type switch do it differently

zoni-cli
change supported_hardware var.  This will be changed in the near future

ZoniDefaults
Add dellswitch to the list of hardware examples with accessmode

Modified:
    incubator/tashi/branches/zoni-dev/trunk/etc/ZoniDefaults.cfg
    incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py
    incubator/tashi/branches/zoni-dev/trunk/src/zoni/extra/util.py
    incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/dellswitch.py
    incubator/tashi/branches/zoni-dev/trunk/src/zoni/install/pxe/zoniPxeSetup.py
    incubator/tashi/branches/zoni-dev/trunk/src/zoni/system/registration/register/register_node
    incubator/tashi/branches/zoni-dev/trunk/src/zoni/system/registration/www/zoni-register.php

Modified: incubator/tashi/branches/zoni-dev/trunk/etc/ZoniDefaults.cfg
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/etc/ZoniDefaults.cfg?rev=1161555&r1=1161554&r2=1161555&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/etc/ZoniDefaults.cfg (original)
+++ incubator/tashi/branches/zoni-dev/trunk/etc/ZoniDefaults.cfg Thu Aug 25 13:20:57 2011
@@ -77,7 +77,7 @@ VLAN_MAX = 4095
 
 [hardware]
 #  Hardware control available for the cluster 
-HARDWARE_CONTROL = {"ipmi": {"class":"zoni.hardware.ipmi.Ipmi"}, "drac": {"class":"zoni.hardware.delldrac.dellDrac"},
"pdu":{"class": "zoni.hardware.raritanpdu.raritanDominionPx"}}
+HARDWARE_CONTROL = {"ipmi": {"class":"zoni.hardware.ipmi.Ipmi"}, "drac": {"class":"zoni.hardware.delldrac.dellDrac"},
"pdu":{"class": "zoni.hardware.raritanpdu.raritanDominionPx"}, "dellswitch" : {"class", "zoni.hardware.dellswitch.HwDellSwitch",
"accessmode" : "ssh"}}
 HARDWARE_PDU = "raritan"
 HARDWARE_DRAC = "DELL DRAC"
 

Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py?rev=1161555&r1=1161554&r2=1161555&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/client/zoni-cli.py Thu Aug 25 13:20:57
2011
@@ -617,14 +617,14 @@ def main():
 	#  Register hardware
 	if options.register: 
 
-		supported_hardware = ['dell', 'raritan']
+		supported_hardware = ['dellswitch', 'raritan']
 		if len(args) < 3:
 			mesg = "ERROR:  Expecting username and ip address of hardware to be registered\n"
 			mesg += os.path.basename(sys.argv[0]) + " --register HARDWARE username ipaddr\n"
 			mesg += "Supported hardware " + str(supported_hardware) + "\n"
 			sys.stderr.write(mesg)
 		else:
-			if string.lower(args[0]) == "dell":
+			if string.lower(args[0]) == "dellswitch":
 				HwSwitch = HwDellSwitch
 				hw = HwSwitch(configs)
 			elif string.lower(args[0]) == "raritan":

Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/extra/util.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/extra/util.py?rev=1161555&r1=1161554&r2=1161555&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/extra/util.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/extra/util.py Thu Aug 25 13:20:57 2011
@@ -186,6 +186,10 @@ def validIp(ip):
 			return 0
 	return 1
 
+def normalizeMac(mac):
+	rawmac = re.sub('[.:-]', '', mac)
+	return  string.lower(":".join(["%s%s" % (rawmac[i], rawmac[i+1]) for i in range(0,12,2)]))
+
 def validMac(mac):
 	reg = '([a-fA-F0-9]{2}[:|\\-]?){6}'
 	val = re.compile(reg).search(mac)

Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/dellswitch.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/dellswitch.py?rev=1161555&r1=1161554&r2=1161555&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/dellswitch.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/hardware/dellswitch.py Thu Aug 25 13:20:57
2011
@@ -35,6 +35,7 @@ from zoni.data.resourcequerysql import *
 from zoni.hardware.hwswitchinterface import HwSwitchInterface
 from zoni.data.resourcequerysql import ResourceQuerySql
 from zoni.agents.dhcpdns import DhcpDns
+from zoni.extra.util import *
 
 
 '''  Using pexpect to control switches because couldn't get snmp to work 
@@ -52,14 +53,22 @@ class HwDellSwitch(HwSwitchInterface):
 		self.verbose = verbose
 
 	def __login(self):
-		switchIp = "ssh " +  self.host['hw_userid'] + "@" + self.host['hw_name']
+		# ssh
+		if self.config['hardwareControl']['dellswitch']['accessmode'] == "ssh":
+			switchIp = "ssh " +  self.host['hw_userid'] + "@" + self.host['hw_name']
+		# telnet 
+		else:
+			switchIp = "telnet " +  self.host['hw_name'] 
+
+
+
 		child = pexpect.spawn(switchIp)
 
 		#  Be Verbose and print everything
 		if self.verbose:
 			child.logfile = sys.stdout
 
-		opt = child.expect(['Name:', 'assword:', 'Are you sure.*', pexpect.EOF, pexpect.TIMEOUT])
+		opt = child.expect(['Name:', 'assword:', 'Are you sure.*', 'User:', pexpect.EOF, pexpect.TIMEOUT])
 		#XXX  Doesn't seem to do what I want:(
 		child.setecho(False)
 
@@ -68,11 +77,11 @@ class HwDellSwitch(HwSwitchInterface):
 			child.sendline("yes")
 			opt = child.expect(['Name:', 'assword:', 'Are you sure.*', pexpect.EOF, pexpect.TIMEOUT])
 			
-		if opt == 0:
+		if opt == 0 or opt == 3:
 			child.sendline(self.host['hw_userid'])
 			i = child.expect(['assword:', 'Connection',  pexpect.EOF, pexpect.TIMEOUT])
 			child.sendline(self.host['hw_password'])
-			i=child.expect(['console','#', 'Name:', pexpect.EOF, pexpect.TIMEOUT])
+			i=child.expect(['console','#', 'Name:', '>',pexpect.EOF, pexpect.TIMEOUT])
 			if i == 2:
 				mesg = "ERROR:  Login to %s failed\n" % (self.host['hw_name'])
 				self.log.error(mesg)
@@ -86,7 +95,6 @@ class HwDellSwitch(HwSwitchInterface):
 			child.sendline('enable')
 			i=child.expect(['#', pexpect.EOF, pexpect.TIMEOUT])
 
-
 		return child
 
 	def __getPrsLabel(self):
@@ -139,11 +147,8 @@ class HwDellSwitch(HwSwitchInterface):
 
 	def createVlansThread(self, vlan, switch,host):
 		mesg = "Creating vlan %s on switch %s" % (str(vlan),str(switch))
-		print "host is ", host
 		self.log(mesg)
-		print "create"
 		self.createVlan(vlan)
-		print "cend"
 		self.addVlanToTrunk(vlan);
 		thread.exit()
 
@@ -224,8 +229,6 @@ class HwDellSwitch(HwSwitchInterface):
 		#child.interact(escape_character='\x1d', input_filter=None, output_filter=None)
 
 		child.terminate()
-		#print "before", child.before
-		#print "after", child.after
 
 	def addNodeToVlan(self, vlan):
 		mesg = "Adding Node to vlan %s" % (str(vlan))
@@ -374,6 +377,7 @@ class HwDellSwitch(HwSwitchInterface):
 		child.interact(escape_character='\x1d', input_filter=None, output_filter=None)
 	
 	def registerToZoni(self, user, password, host):
+		self.setVerbose(True)
 		host = string.strip(str(host))
 		#  Get hostname of the switch
 		if len(host.split(".")) == 4:
@@ -394,33 +398,12 @@ class HwDellSwitch(HwSwitchInterface):
 				self.log.critical(mesg)
 				exit()
 
-		switchIp = "ssh " + user + "@" + ip
-		child = pexpect.spawn(switchIp)
-		opt = child.expect(['Name:', 'assword:', 'Are you sure.*', pexpect.EOF, pexpect.TIMEOUT])
-		#XXX  Doesn't seem to do what I want:(
-		child.setecho(False)
-
-		#  Send a yes to register authenticity of host for ssh
-		if opt == 2:
-			child.sendline("yes")
-			opt = child.expect(['Name:', 'assword:', 'Are you sure.*', pexpect.EOF, pexpect.TIMEOUT])
-			
-		if opt == 0:
-			child.sendline(user)
-			i = child.expect(['assword:', 'Connection',  pexpect.EOF, pexpect.TIMEOUT])
-			child.sendline(password)
-			i=child.expect(['console',host, 'Name:', pexpect.EOF, pexpect.TIMEOUT])
-			if i == 2:
-				mesg = "Login to switch %s failed" % (host)
-				self.log.error(mesg)
-				exit(1)
-
-		if opt == 1:
-			child.sendline(password)
-			i=child.expect(['console',host, 'Name:', pexpect.EOF, pexpect.TIMEOUT])
-			#  on the 6448 dell, need to send enable, just send to all
-			child.sendline('enable')
-			i=child.expect(['#', pexpect.EOF, pexpect.TIMEOUT])
+		#  log into the switch
+		self.host = {}
+		self.host['hw_userid'] = user
+		self.host['hw_name'] = host
+		self.host['hw_password'] = password
+		child = self.__login()
 
 		fout = tempfile.TemporaryFile()
 		child.logfile = fout
@@ -428,10 +411,11 @@ class HwDellSwitch(HwSwitchInterface):
 		cmd = "show system"
 		child.sendline(cmd)
 		val = host + "#"
-		i = child.expect([val, '\n\r\n\r', pexpect.EOF, pexpect.TIMEOUT])
+		tval = host + ">"
+		i = child.expect([val, tval, '\n\r\n\r', "--More--",  pexpect.EOF, pexpect.TIMEOUT])
 		cmd = "show version"
 		child.sendline(cmd)
-		i = child.expect([val, '\n\r\n\r', pexpect.EOF, pexpect.TIMEOUT])
+		i = child.expect([val, tval, '\n\r\n\r', pexpect.EOF, pexpect.TIMEOUT])
 
 		fout.seek(0)
 		a={}
@@ -440,10 +424,11 @@ class HwDellSwitch(HwSwitchInterface):
 				datime = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime())
 				val = "Registered by Zoni on : " + datime
 				a['hw_notes'] = val + "; " + string.strip(i.split(':', 1)[1])
-			if "System MAC" in i:
-				a['hw_mac'] = string.strip(i.split(':', 1)[1])
-			if "SW version" in i:
-				a['hw_version_sw'] = string.strip(i.split('   ')[1].split()[0])
+			if "MAC" in i:
+				a['hw_mac'] = normalizeMac(string.strip(i.split(":", 1)[1]))
+			#  moving this capture to snmp 
+			#if "SW version" in i:
+				#a['hw_version_sw'] = string.strip(i.split('   ')[1].split()[0])
 			if "HW version" in i:
 				a['hw_version_fw'] = string.strip(i.split('   ')[1].split()[0])
 				
@@ -467,12 +452,19 @@ class HwDellSwitch(HwSwitchInterface):
 		cmdgen.CommunityData('my-agent', user, 0), \
 		cmdgen.UdpTransportTarget((host, 161)), oid)
 		a['hw_model'] = str(varBinds[0][1])
+
 		oid = eval("1,3,6,1,4,1,674,10895,3000,1,2,100,3,0")
 		errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
\
 		cmdgen.CommunityData('my-agent', user, 0), \
 		cmdgen.UdpTransportTarget((host, 161)), oid)
 		a['hw_make'] = str(varBinds[0][1])
 
+		oid = eval("1,3,6,1,4,1,674,10895,3000,1,2,100,4,0")
+		errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
\
+		cmdgen.CommunityData('my-agent', user, 0), \
+		cmdgen.UdpTransportTarget((host, 161)), oid)
+		a['hw_version_sw'] = str(varBinds[0][1])
+
 		#  Register in dns
 		if self.config['dnsEnabled']:
 			try:

Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/install/pxe/zoniPxeSetup.py
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/install/pxe/zoniPxeSetup.py?rev=1161555&r1=1161554&r2=1161555&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/install/pxe/zoniPxeSetup.py (original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/install/pxe/zoniPxeSetup.py Thu Aug 25
13:20:57 2011
@@ -66,6 +66,7 @@ def ZoniPxeSetup(config):
 	tftpBaseFile = config['tftpBaseFile'] 
 	tftpBaseMenuFile = config['tftpBaseMenuFile'] 
 	installBaseDir = config['installBaseDir']
+	registrationBaseDir = config['registrationBaseDir']
 	
 
 	#  Create the directory structure
@@ -168,11 +169,11 @@ def zoniCreateBaseMenu(config):
 	a += "DISPLAY boot-screens/boot.txt\n\n"
 	a += "LABEL zoni-register-64\n"
 	a += "        kernel builds/amd64/zoni-reg/linux\n"
-	a += "        append initrd=builds/amd64/zoni-reg/initrd.gz pxeserver=" + config['pxeServerIP']
+  " imageserver=" + config['imageServerIP'] + " defaultimage=amd64-tashi_nm registerfile=register_node
mode=register console=tty1 rw --\n"
+	a += "        append initrd=builds/initrd/images/zoni-register-64.gz pxeserver=" + config['pxeServerIP']
+  " imageserver=" + config['imageServerIP'] + " defaultimage=amd64-tashi_nm registerfile=register_node
mode=register image_root=" + config['registrationBaseDir'] + " console=tty1 rw --\n"
 	a += "\n"
 	a += "LABEL zoni-register-64-interactive\n"
 	a += "        kernel builds/amd64/zoni-reg/linux\n"
-	a += "        append initrd=builds/amd64/zoni-reg/initrd_zoni_interactive.gz pxeserver="
+ config['pxeServerIP'] +  " imageserver=" + config['imageServerIP'] + " defaultimage=amd64-tashi_nm
registerfile=register_node mode=register console=tty1 rw --\n"
+	a += "        append initrd=builds/initrd/images/zoni-register-64.gz pxeserver=" + config['pxeServerIP']
+  " imageserver=" + config['imageServerIP'] + " defaultimage=amd64-tashi_nm registerfile=register_node
mode=register verbose=1 image_root=" + config['registrationBaseDir'] + " console=tty1 rw --\n"
 	a += "\n"
 	a += "LABEL localdisk\n"
 	a += "    LOCALBOOT 0\n"

Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/system/registration/register/register_node
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/system/registration/register/register_node?rev=1161555&r1=1161554&r2=1161555&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/system/registration/register/register_node
(original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/system/registration/register/register_node
Thu Aug 25 13:20:57 2011
@@ -27,7 +27,6 @@ DEBUG () {
 }
 
 #  Capture vars passed via kernal args
-VERBOSE=0
 for x in $(cat /proc/cmdline); do
     case $x in
     imagename=*)
@@ -39,8 +38,8 @@ for x in $(cat /proc/cmdline); do
     defaultimage=*)
         DEFAULTIMAGE=${x#defaultimage=}
         ;;
-    image_root=*)
-        IMAGE_ROOT=${x#image_root=}
+    zoniroot=*)
+        ZONIROOT=${x#zoniroot=}
         ;;
     verbose=*)
         VERBOSE=${x#verbose=}
@@ -48,7 +47,8 @@ for x in $(cat /proc/cmdline); do
 	esac
 done
 
-IMAGE_URL="${PXESERVER}/${IMAGE_ROOT}/"
+
+IMAGE_URL="${PXESERVER}/${ZONIROOT}/"
 
 #  Scrape system for specs
 #/sbin/getSystemId > /tmp/sysinfo
@@ -197,7 +197,6 @@ fi
 	#DEBUG "Update ip $ip_addr"
 	#wget -O- "http://${IMAGE_URL}/zoni-register.php?action=addip&mac=$MAC&ip_addr=$ip_addr"
 #fi
-VERBOSE=0
 if [ $location ];then 
 	DEBUG "Set location ${location}"
 	echo "wget -O- http://${IMAGE_URL}/zoni-register.php?action=addlocation&verbose=${VERBOSE}&mac=$MAC&location=$location"
@@ -222,9 +221,11 @@ fi
 	#wget -O- "http://${IMAGE_URL}/zoni-register.php?action=addip&mac=$MAC&ip_addr=$ip_addr"
 #fi
 
-#  Add dns and dhcp
-DEBUG "adding to dhcp and dns"
-wget -O- "http://${IMAGE_URL}/zoni-register.php?action=updatednsdhcp&verbose=${VERBOSE}&mac=${MAC}&location=$location&ip_addr=$IPADDR"
+if [ $location ];then
+	#  Add dns and dhcp
+	DEBUG "adding to dhcp and dns"
+	wget -O- "http://${IMAGE_URL}/zoni-register.php?action=updatednsdhcp&verbose=${VERBOSE}&mac=${MAC}&location=$location&ip_addr=$IPADDR"
+fi
 
 #  Setup the management interface, if any
 
@@ -242,6 +243,7 @@ if [ $? -eq 0 ];then 
 	vlan_disable=$(ipmitool lan print |  grep -i "Vlan" | awk -F ": " '{print $2}')
 
 	#  Add IPMI info 
+	echo "wget -O/outfile.txt 'http://${IMAGE_URL}/zoni-register.php?action=add_ipmi&verbose=${VERBOSE}&mac=$MAC&location=${location}&ip_addr=${IPADDR}&ipmi_mac=${ipmi_mac}&ipmi_ver=${ipmi_ver}&ipmi_rev=${ipmi_rev}'"
 	wget -O/outfile.txt "http://${IMAGE_URL}/zoni-register.php?action=add_ipmi&verbose=${VERBOSE}&mac=$MAC&location=${location}&ip_addr=${IPADDR}&ipmi_mac=${ipmi_mac}&ipmi_ver=${ipmi_ver}&ipmi_rev=${ipmi_rev}"
 	IPMI_ADDR=$(cat /outfile.txt | grep IPMI_ADDR | awk '{print $2}')
 	IPMI_PASSWORD=$(cat /outfile.txt | grep IPMI_PASSWORD | awk '{print $2}')
@@ -269,8 +271,10 @@ if [ $? -eq 0 ];then 
 	ipmitool channel setaccess 1 2 callin=on ipmi=on link=on privilege=4
 	ipmitool user enable 2
 
+	#Already done in add_ipmi
 	#DEBUG "adding to dhcp and dns"
-	#wget -O- "http://${IMAGE_URL}/zoni-register.php?action=updatednsdhcp&verbose=${VERBOSE}&mac=${ipmi_mac}&location=${location}$&ip_addr=${IPMI_ADDR}"
+	#DEBUG "wget -O- http://${IMAGE_URL}/zoni-register.php?action=updatednsdhcp&verbose=${VERBOSE}&mac=${ipmi_mac}&location=${location}$&ip_addr=${IPMI_ADDR}"
+	#wget -O- "http://${IMAGE_URL}/zoni-register.php?action=updatednsdhcp&verbose=${VERBOSE}&mac=${ipmi_mac}&location=${location}&ip_addr=${IPMI_ADDR}"
 
 else
 	DEBUG "IPMI interface not found"

Modified: incubator/tashi/branches/zoni-dev/trunk/src/zoni/system/registration/www/zoni-register.php
URL: http://svn.apache.org/viewvc/incubator/tashi/branches/zoni-dev/trunk/src/zoni/system/registration/www/zoni-register.php?rev=1161555&r1=1161554&r2=1161555&view=diff
==============================================================================
--- incubator/tashi/branches/zoni-dev/trunk/src/zoni/system/registration/www/zoni-register.php
(original)
+++ incubator/tashi/branches/zoni-dev/trunk/src/zoni/system/registration/www/zoni-register.php
Thu Aug 25 13:20:57 2011
@@ -18,11 +18,12 @@
 #
 #  $Id$
 #
+	#  Need to put base directory here 
     include("include/zoni_www_registration.conf");
 	include("include/zoni_functions.php");
-	$PYTHONPATH=$G['ZONI_BASE_DIR'] . "/src"
 
     $G = init_globals();
+	$PYTHONPATH=$G['ZONI_BASE_DIR'] . "/src";
     $verbose = (isset($_GET['verbose'])) ? $_GET['verbose']: 0;
 
     DEBUG($verbose, "<pre>");
@@ -378,6 +379,7 @@
 		DEBUG($verbose, "doing the dns and dhcp updates");
 		#print shell_exec("cd {$G['ZONI_BASE_DIR']}; sudo ./bin/zoni-cli.py --addDns $location
$ip_addr");
 		#print shell_exec("cd {$G['ZONI_BASE_DIR']}; sudo ./bin/zoni-cli.py --addDhcp $location
$ip_addr $mac_addr");
+		#print "location is " + $location + " and ip is " + $ip_addr;
 		print shell_exec("PYTHONPATH=$PYTHONPATH zoni --addDns $location $ip_addr");
 		print shell_exec("PYTHONPATH=$PYTHONPATH zoni --addDhcp $location $ip_addr $mac_addr");
 	}



Mime
View raw message