Merge pull request #10904 from SmithSamuelM/sam_raet_14

Sam raet 14  Fixed naming a couple of places also tested with new ioflo
This commit is contained in:
Samuel Smith 2014-03-03 12:50:47 -07:00
commit 909286ed0e
3 changed files with 85 additions and 7 deletions

View File

@ -503,12 +503,12 @@ class StackUxd(object):
if name is None:
name = yard.name
if name in self.yards:
if name in self.yards or name == self.yard.name:
emsg = "Device with name '{0}' alreadys exists".format(name)
raise raeting.StackError(emsg)
yard.stack = self
self.yards[name] = yard
if yard.ha in self.names:
if yard.ha in self.names or yard.ha == self.yard.ha:
emsg = "Yard with ha '{0}' alreadys exists".format(yard.ha)
raise raeting.StackError(emsg)
self.names[yard.ha] = yard.name

View File

@ -0,0 +1,77 @@
import multiprocessing
import time
from salt.transport.road.raet import stacking
from salt.transport.road.raet import yarding
ESTATE = 'minion1'
def fudal():
'''
Make a single process raet uxd stack
'''
lord_stack = stacking.StackUxd(name='lord', lanename='execute', yid=0, dirpath='/tmp')
serf_stack = stacking.StackUxd(name='serf', lanename='execute', yid=1, dirpath='/tmp')
lord_yard = yarding.Yard(yid=0, prefix='execute', dirpath='/tmp')
#serf_yard = yarding.Yard(name=serf_stack.yard.name, prefix='execute')
serf_stack.addRemoteYard(lord_yard)
#print 'stack: {0}\nyid: {1}\nname: {2}\nha: {3}\ndirpath: {4}'.format(lord_stack.yard.stack, lord_stack.yard.yid, lord_stack.yard.name, lord_stack.yard.ha, lord_stack.yard.dirpath)
#lord_stack.addRemoteYard(serf_yard)
src = (ESTATE, serf_stack.yard.name, None)
dst = (ESTATE, lord_stack.yard.name, None)
route = {'src': src, 'dst': dst}
msg = {'route': route, 'stuff': 'Serf to Lord, I am not a couch'}
serf_stack.transmit(msg=msg)
serf_stack.serviceAll()
lord_stack.serviceAll()
#print lord_stack.rxMsgs
def lord(serfs=5):
'''
Make a lord that can spawn serfs
'''
lord_yid = 0
dirpath = '/tmp'
lord_stack = stacking.StackUxd(name='lord', lanename='execute', yid=lord_yid, dirpath=dirpath)
lord_stack.serviceAll()
for serf_id in range(1, serfs + 1):
serf_yard = yarding.Yard(yid=serf_id, prefix='execute', dirpath=dirpath)
lord_stack.addRemoteYard(serf_yard)
proc = multiprocessing.Process(target=serf, args=(lord_stack.yard.name, lord_yid, serf_id, dirpath))
proc.start()
while True:
lord_stack.serviceAll()
print 'serviced lord stack'
print lord_stack.rxMsgs
for msg in lord_stack.rxMsgs:
print msg
time.sleep(1)
def serf(lord_name, lord_yid, id_, dirpath):
'''
Call to spawn a serf and start sending messages
'''
serf_stack = stacking.StackUxd(
name='serf{0}'.format(id_),
lanename='execute',
yid=id_,
dirpath=dirpath)
lord_yard = yarding.Yard(yid=lord_yid, prefix='execute', dirpath=dirpath)
serf_stack.addRemoteYard(lord_yard)
src = (ESTATE, serf_stack.yard.name, None)
dst = (ESTATE, lord_name, None)
route = {'src': src, 'dst': dst}
msg = {'route': route, 'stuff': 'Serf {0} to Lord, I am not a couch'.format(id_)}
while True:
serf_stack.transmit(msg=msg)
serf_stack.serviceAll()
print 'serf messages transmitted'
time.sleep(1)
if __name__ == '__main__':
lord()
#fudal()

View File

@ -18,7 +18,7 @@ from . import nacling
from ioflo.base.consoling import getConsole
console = getConsole()
YARD_UXD_DIR = os.path.join('/tmp', '.raet')
YARD_UXD_DIR = os.path.join('/tmp', 'raet')
@ -38,20 +38,21 @@ class Yard(object):
'''
Initialize instance
'''
if dirpath is None:
dirpath = YARD_UXD_DIR
self.stack = stack
if yid is None:
yid = Yard.Yid
Yard.Yid += 1
self.yid = yid # yard ID
self.name = name or "yard{0}".format(self.yid)
#self.yid = yid # yard ID
self.name = name or "yard{0}".format(yid)
if " " in self.name:
emsg = "Invalid Yard name '{0}'".format(self.name)
raise raeting.YardError(emsg)
if dirpath is None:
dirpath = YARD_UXD_DIR
self.dirpath = dirpath
if " " in prefix:
emsg = "Invalid prefix '{0}'".format(prefix)
raise raeting.YardError(emsg)