incubator-tashi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strou...@apache.org
Subject svn commit: r1363496 - in /incubator/tashi/trunk: .gitignore INSTALL src/tashi/nodemanager/nodemanagerservice.py
Date Thu, 19 Jul 2012 19:30:37 GMT
Author: stroucki
Date: Thu Jul 19 19:30:37 2012
New Revision: 1363496

URL: http://svn.apache.org/viewvc?rev=1363496&view=rev
Log:
Merge branch 'dgomes-network' of https://github.com/stroucki/tashi into dgomes-network

Conflicts:
	INSTALL

Added:
    incubator/tashi/trunk/.gitignore
Modified:
    incubator/tashi/trunk/INSTALL
    incubator/tashi/trunk/src/tashi/nodemanager/nodemanagerservice.py

Added: incubator/tashi/trunk/.gitignore
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/.gitignore?rev=1363496&view=auto
==============================================================================
--- incubator/tashi/trunk/.gitignore (added)
+++ incubator/tashi/trunk/.gitignore Thu Jul 19 19:30:37 2012
@@ -0,0 +1 @@
+*.pyc
\ No newline at end of file

Modified: incubator/tashi/trunk/INSTALL
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/INSTALL?rev=1363496&r1=1363495&r2=1363496&view=diff
==============================================================================
--- incubator/tashi/trunk/INSTALL (original)
+++ incubator/tashi/trunk/INSTALL Thu Jul 19 19:30:37 2012
@@ -81,6 +81,12 @@ http://sourceforge.net/projects/rpyc/fil
 If you wish to run the Tashi components in debugging mode, you
 will want iPython from http://ipython.org/.
 
+You will also need pycap from http://code.google.com/p/pypcap/ and dpkt
+from http://code.google.com/p/dpkt/, although they usually come with
+your Linux distribution. Debian packages are python-pypcap and
+python-dpkt. Optionally, you can install them using easy_install or
+pip (Python package managers).
+
 Prepare a virtual machine image in qcow2 format for Tashi to deploy. You 
 can create this with practically any consumer or professional 
 virtualization system, by converting the resulting disk image via 

Modified: incubator/tashi/trunk/src/tashi/nodemanager/nodemanagerservice.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/nodemanager/nodemanagerservice.py?rev=1363496&r1=1363495&r2=1363496&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/nodemanager/nodemanagerservice.py (original)
+++ incubator/tashi/trunk/src/tashi/nodemanager/nodemanagerservice.py Thu Jul 19 19:30:37
2012
@@ -19,6 +19,8 @@ import logging
 import socket
 import threading
 import time
+import dpkt, pcap
+from struct import pack
 
 from tashi.rpycservices.rpyctypes import InstanceState, TashiException, Errors, Instance
 from tashi import boolean, vmStates, ConnectionManager
@@ -77,6 +79,7 @@ class NodeManagerService(object):
 		# start service threads
 		threading.Thread(name="registerWithClusterManager", target=self.__registerWithClusterManager).start()
 		threading.Thread(name="statsThread", target=self.__statsThread).start()
+		threading.Thread(name="arpMonitorThread", target=self.__arpMonitorThread, args=(config,)).start()
 
 	def __initAccounting(self):
 		self.accountBuffer = []
@@ -198,6 +201,52 @@ class NodeManagerService(object):
 			if (toSleep > 0):
 				time.sleep(toSleep)
 
+	#Convert a string of 6 characters of ethernet address into a colon separated hex string
+	def __stringToMac(self, a):
+		# XXXstroucki: enforce string length?
+		b = ":".join(s.encode("hex") for s in a)
+		return b
+
+	def __updateInstance(self, mac, ip):
+		for vmId in self.instances.keys():
+			try:
+				instance = self.instances.get(vmId, None)
+				if (not instance):
+					continue
+				for i in range(0, len(instance.nics)): 
+					nic = instance.nics[i]
+					if (nic.mac == mac):
+						self.log.debug('Detected IP address: %s for hardware address: %s' % (ip, mac))
+						nic.ip = ip
+			except:
+				self.log.exception('updateInstance threw an exception (vmid %d)' % vmId)
+
+	# service thread function
+	def __arpMonitorThread(self, conf):
+		try:
+			pc = pcap.pcap()
+			# Look for ARP or DHCP traffic
+			pc.setfilter('arp or udp port 67')
+	
+			for ts, pkt in pc:
+				e = dpkt.ethernet.Ethernet(pkt)
+				if e.type == dpkt.ethernet.ETH_TYPE_IP:
+					ip = e.data
+					udp = ip.data
+					dhcp = dpkt.dhcp.DHCP(udp.data)
+					if dhcp.op == dpkt.dhcp.DHCPACK or dhcp.op == dpkt.dhcp.DHCPOFFER:
+						macaddress = self.__stringToMac(dhcp.chaddr)
+						ipaddress = socket.inet_ntoa(pack("!I",dhcp.ciaddr))
+						self.__updateInstance(macaddress, ipaddress)
+				elif e.type == dpkt.ethernet.ETH_TYPE_ARP:
+					a = e.data
+					if a.op == dpkt.arp.ARP_OP_REPLY:
+						ipaddress = socket.inet_ntoa(a.spa)
+						macaddress = self.__stringToMac(a.sha)
+						self.__updateInstance(macaddress, ipaddress)
+		except:
+			self.log.exception('arpMonitorThread threw an exception')
+
 	# service thread function
 	def __statsThread(self):
 		if (self.statsInterval == 0):



Mime
View raw message