Merge branch 'SmithSamuelM-2014.7_sam3' into 2014.7

This commit is contained in:
Thomas S Hatch 2014-09-17 13:49:48 -06:00
commit d35e38907f
13 changed files with 739 additions and 493 deletions

View File

@ -283,8 +283,8 @@ class RAETCaller(ZeroMQCaller):
'''
mid = opts['id']
sockdirpath = opts['sock_dir']
yid = nacling.uuid(size=18)
name = 'caller' + yid
uid = nacling.uuid(size=18)
name = 'caller' + uid
stack = LaneStack(name=name,
lanename=mid,
sockdirpath=sockdirpath)

View File

@ -51,17 +51,17 @@ class LocalClient(salt.client.LocalClient):
jid=jid,
timeout=timeout,
**kwargs)
yid = nacling.uuid(size=18)
uid = nacling.uuid(size=18)
stack = LaneStack(
name=('client' + yid),
yid=yid,
name=('client' + uid),
uid=uid,
lanename='master',
sockdirpath=self.opts['sock_dir'])
stack.Pk = raeting.packKinds.pack
router_yard = RemoteYard(
stack=stack,
lanename='master',
yid=0,
uid=0,
name='manor',
dirpath=self.opts['sock_dir'])
stack.addRemote(router_yard)

View File

@ -243,7 +243,13 @@ VALID_OPTS = {
'ssh_sudo': bool,
'ssh_timeout': float,
'ssh_user': str,
'ioflo_verbose': int,
'ioflo_period': float,
'ioflo_realtime': bool,
'ioflo_console_logdir': str,
'raet_port': int,
'raet_mutable': bool,
'raet_main': bool,
'sqlite_queue_dir': str,
'queue_dirs': list,
'restart_on_error': bool,
@ -371,7 +377,10 @@ DEFAULT_MINION_OPTS = {
'ioflo_verbose': 0,
'ioflo_period': 0.1,
'ioflo_realtime': True,
'ioflo_console_logdir': '',
'raet_port': 4510,
'raet_mutable': False,
'raet_main': False,
'restart_on_error': False,
'ping_interval': 0,
'username': None,
@ -531,7 +540,10 @@ DEFAULT_MASTER_OPTS = {
'ioflo_verbose': 0,
'ioflo_period': 0.01,
'ioflo_realtime': True,
'ioflo_console_logdir': '',
'raet_port': 4506,
'raet_mutable': False,
'raet_main': True,
'sqlite_queue_dir': os.path.join(salt.syspaths.CACHE_DIR, 'master', 'queues'),
'queue_dirs': [],
'cli_summary': False,

View File

@ -21,7 +21,7 @@ import salt.utils.args
import salt.transport
from raet import raeting, nacling
from raet.road.stacking import RoadStack
from raet.road.estating import LocalEstate
from raet.road.estating import RemoteEstate
from raet.lane.stacking import LaneStack
from raet.lane.yarding import RemoteYard
@ -110,8 +110,8 @@ class SaltRaetRoadStackSetup(ioflo.base.deeding.Deed):
'local': {'ipath': 'local',
'ival': {'name': 'master',
'main': False,
'auto': None,
'eid': 0,
'mutable': False,
'uid': None,
'sigkey': None,
'prikey': None}},
}
@ -134,35 +134,32 @@ class SaltRaetRoadStackSetup(ioflo.base.deeding.Deed):
name = self.opts.value.get('id', self.local.data.name)
sigkey = self.local.data.sigkey
prikey = self.local.data.prikey
auto = self.local.data.auto
main = self.local.data.main
eid = self.local.data.eid
main = self.opts.value.get('raet_main', self.local.data.main)
mutable = self.opts.value.get('raet_mutable', self.local.data.mutable)
always = self.opts.value.get('open_mode', False)
mutable = mutable or always # open_made when True takes precedence
uid = self.local.data.uid
ha = (self.opts.value['interface'], self.opts.value['raet_port'])
basedirpath = os.path.abspath(os.path.join(self.opts.value['cachedir'], 'raet'))
local = LocalEstate(
eid=eid,
name=name,
main=main,
ha=ha,
sigkey=sigkey,
prikey=prikey)
txMsgs = self.txmsgs.value
rxMsgs = self.rxmsgs.value
keep = salting.SaltKeep(opts=self.opts.value,
basedirpath=basedirpath,
stackname=name,
auto=auto)
stackname=name)
self.stack.value = RoadStack(
local=local,
store=self.store,
name=name,
main=main,
self.stack.value = RoadStack(store=self.store,
keep=keep,
name=name,
uid=uid,
ha=ha,
sigkey=sigkey,
prikey=prikey,
main=main,
mutable=mutable,
txMsgs=txMsgs,
rxMsgs=rxMsgs,
period=3.0,
@ -213,7 +210,12 @@ class SaltRaetRoadStackJoiner(ioflo.base.deeding.Deed):
'''
stack = self.stack.value
if stack and isinstance(stack, RoadStack):
stack.join(ha=self.mha, timeout=0.0)
if not stack.remotes:
stack.addRemote(RemoteEstate(stack=stack,
fuid=0, # vacuous join
sid=0, # always 0 for join
ha=self.mha))
stack.join(uid=stack.remotes.values()[0].uid, timeout=0.0)
class SaltRaetRoadStackJoined(ioflo.base.deeding.Deed):
@ -580,11 +582,11 @@ class SaltManorLaneSetup(ioflo.base.deeding.Deed):
#name = "{0}{1}".format(self.opts.value.get('id', self.local.data.name), 'lane')
name = 'manor'
lanename = self.opts.value.get('id', self.local.data.lanename)
yid = self.local.data.yid
#yid = self.local.data.yid
self.stack.value = LaneStack(
name=name,
lanename=lanename,
yid=0,
uid=0,
sockdirpath=self.opts.value['sock_dir'])
self.stack.value.Pk = raeting.packKinds.pack
self.event_yards.value = set()
@ -745,7 +747,8 @@ class Router(ioflo.base.deeding.Deed):
elif d_share == 'remote_cmd':
# Send it to a remote worker
if 'load' in msg:
msg['load']['id'] = sender
role = self.udp_stack.value.nameRemotes[sender].role
msg['load']['id'] = role # sender # should this be role XXXX
self.uxd_stack.value.transmit(msg,
self.uxd_stack.value.fetchUidByName(next(self.workers.value)))
elif d_share == 'fun':
@ -770,8 +773,8 @@ class Router(ioflo.base.deeding.Deed):
pass
elif d_estate != self.udp_stack.value.local:
# Forward to the correct estate
eid = self.udp_stack.value.fetchUidByName(d_estate)
self.udp_stack.value.message(msg, eid)
uid = self.udp_stack.value.fetchUidByName(d_estate)
self.udp_stack.value.message(msg, uid)
return
if d_share == 'pub_ret':
if msg.get('__worker_verify') == self.worker_verify.value:
@ -891,13 +894,13 @@ class SaltPublisher(ioflo.base.deeding.Deed):
# only publish to available minions by intersecting sets
minions = self.availables.value & set(self.stack.value.nameRemotes.keys())
for minion in minions:
eid = self.stack.value.fetchUidByName(minion)
if eid:
uid = self.stack.value.fetchUidByName(minion)
if uid:
route = {
'dst': (minion, None, 'fun'),
'src': (self.stack.value.local.name, None, None)}
msg = {'route': route, 'pub': pub_data['pub']}
self.stack.value.message(msg, eid)
self.stack.value.message(msg, uid)
def action(self):
'''
@ -943,8 +946,8 @@ class NixExecutor(ioflo.base.deeding.Deed):
'''
mid = self.opts['id']
yid = nacling.uuid(size=18)
name = 'jobber' + yid
uid = nacling.uuid(size=18)
name = 'jobber' + uid
stack = LaneStack(
name=name,
lanename=mid,

View File

@ -2,7 +2,7 @@
house master
init .raet.udp.stack.local to eid 1 main true name "master"
init .raet.udp.stack.local to main true name "master"
init .salt.uxd.stack.local to yid 0 name "master" lanename "master"

View File

@ -118,12 +118,12 @@ class WorkerSetup(ioflo.base.deeding.Deed):
self.stack.value = LaneStack(
name=name,
lanename=lanename,
yid=self.yid.value,
uid=self.yid.value,
sockdirpath=self.opts.value['sock_dir'])
self.stack.value.Pk = raeting.packKinds.pack
manor_yard = RemoteYard(
stack=self.stack.value,
yid=0,
uid=0,
name='manor',
lanename=lanename,
dirpath=self.opts.value['sock_dir'])

View File

@ -35,12 +35,16 @@ class SaltKeep(Keep):
estate.name.ext
estate.name.ext
'''
LocalFields = ['uid', 'name', 'ha', 'main', 'sid', 'neid', 'sighex', 'prihex', 'auto', 'role']
LocalDumpFields = ['uid', 'name', 'ha', 'main', 'sid', 'neid', 'role']
RemoteFields = ['uid', 'name', 'ha', 'sid', 'joined', 'acceptance', 'verhex', 'pubhex', 'role']
RemoteDumpFields = ['uid', 'name', 'ha', 'sid', 'joined', 'role']
Auto = False #auto accept
LocalFields = ['name', 'uid', 'ha', 'iha', 'natted', 'fqdn', 'dyned', 'sid',
'puid', 'aha', 'role', 'sighex','prihex']
LocalDumpFields = ['name', 'uid', 'ha', 'iha', 'natted', 'fqdn', 'dyned', 'sid',
'puid', 'aha', 'role']
RemoteFields = ['name', 'uid', 'fuid', 'ha', 'iha', 'natted', 'fqdn', 'dyned',
'sid', 'main', 'application', 'joined',
'role', 'acceptance', 'verhex', 'pubhex']
RemoteDumpFields = ['name', 'uid', 'fuid', 'ha', 'iha', 'natted', 'fqdn', 'dyned',
'sid', 'main', 'application', 'joined', 'role']
Auto = raeting.autoModes.never #auto accept
def __init__(self, opts, prefix='estate', basedirpath='', auto=None, **kwa):
'''
@ -48,23 +52,51 @@ class SaltKeep(Keep):
'''
basedirpath = basedirpath or os.path.join(opts['cache_dir'], 'raet')
super(SaltKeep, self).__init__(prefix=prefix, basedirpath=basedirpath, **kwa)
self.auto = auto if auto is not None else opts['auto_accept']
self.auto = (auto if auto is not None else
(raeting.autoModes.always if opts['open_mode'] else
(raeting.autoModes.once if opts['auto_accept'] else
raeting.autoModes.never)))
self.saltRaetKey = RaetKey(opts)
def clearAllDir(self):
'''
Clear all keep directories
'''
super(SaltKeep, self).clearAllDir()
self.clearRoleDir()
def clearRoleDir(self):
'''
Clear the Role directory
'''
self.saltRaetKey.delete_pki_dir()
def loadLocalData(self):
'''
Load and Return the data from the local estate
'''
data = super(SaltKeep, self).loadLocalData()
if not data:
return None
srkdata = self.saltRaetKey.read_local()
if not srkdata:
srkdata = dict(sign=None, priv=None)
data.update(sighex=srkdata['sign'], prihex=srkdata['priv'], auto=self.auto)
data.update([('sighex', srkdata['sign']),
('prihex', srkdata['priv'])])
return data
def clearLocalRoleData(self):
'''
Clear the local file
'''
self.saltRaetKey.delete_local()
def clearLocalRoleDir(self):
'''
Clear the Local Role directory
'''
self.saltRaetKey.delete_pki_dir()
def loadRemoteData(self, name):
'''
Load and Return the data from the remote file
@ -81,8 +113,10 @@ class SaltKeep(Keep):
break
if not keydata:
return None
data.update([('acceptance', None),
('verhex', None),
('pubhex', None)])
else:
data.update(acceptance=raeting.ACCEPTANCES[status],
verhex=keydata['verify'],
pubhex=keydata['pub'])
@ -94,6 +128,10 @@ class SaltKeep(Keep):
Load and Return the data from the all the remote estate files
'''
keeps = super(SaltKeep, self).loadAllRemoteData()
for name, data in keeps.items():
keeps[name].update([('acceptance', None),
('verhex', None),
('pubhex', None)])
for status, mids in self.saltRaetKey.list_keys().items():
for mid in mids:
@ -101,29 +139,45 @@ class SaltKeep(Keep):
if keydata:
for name, data in keeps.items():
if data['role'] == mid:
keeps[name].update(acceptance=raeting.ACCEPTANCES[status],
verhex=keydata['verify'],
pubhex=keydata['pub'])
keeps[name].update(
[('acceptance', raeting.ACCEPTANCES[status]),
('verhex', keydata['verify']),
('pubhex', keydata['pub'])])
return keeps
def clearAllRemoteData(self):
def clearRemoteRoleData(self, role):
'''
Remove all the remote estate files
Clear data from the role data file
'''
self.saltRaetKey.delete_key(role) #now delete role key file
def clearAllRemoteRoleData(self):
'''
Remove all the role data files
'''
super(SaltKeep, self).clearAllRemoteData()
self.saltRaetKey.delete_all()
def clearRemoteRoleDir(self):
'''
Clear the Remote Role directory
'''
self.saltRaetKey.delete_pki_dir()
def dumpLocal(self, local):
'''
Dump local estate
'''
data = odict([
('uid', local.uid),
('name', local.name),
('uid', local.uid),
('ha', local.ha),
('main', local.main),
('iha', local.iha),
('natted', local.natted),
('fqdn', local.fqdn),
('dyned', local.dyned),
('sid', local.sid),
('neid', local.neid),
('puid', local.stack.puid),
('aha', local.stack.aha),
('role', local.role),
])
if self.verifyLocalData(data, localFields =self.LocalDumpFields):
@ -136,53 +190,59 @@ class SaltKeep(Keep):
Dump remote estate
'''
data = odict([
('uid', remote.uid),
('name', remote.name),
('uid', remote.uid),
('fuid', remote.fuid),
('ha', remote.ha),
('iha', remote.iha),
('natted', remote.natted),
('fqdn', remote.fqdn),
('dyned', remote.dyned),
('sid', remote.sid),
('main', remote.main),
('application', remote.application),
('joined', remote.joined),
('role', remote.role),
])
if self.verifyRemoteData(data, remoteFields=self.RemoteDumpFields):
self.dumpRemoteData(data, remote.name)
if remote.pubber.keyhex and remote.verfer.keyhex:
# kludge to persist the keys since no way to write
self.saltRaetKey.status(remote.role,
remote.pubber.keyhex,
remote.verfer.keyhex)
def statusRemote(self, remote, dump=True):
'''
Calls .statusRole on remote role and keys and updates remote.acceptance
dump indicates if statusRole should update persisted values when
appropriate.
def replaceRemoteRole(self, remote, old):
Returns status
Where status is acceptance status of role and keys
and has value from raeting.acceptances
'''
Replace the Salt RaetKey record at old role when remote.role has changed
'''
new = remote.role
if new != old:
#self.dumpRemote(remote)
# manually fix up acceptance if not pending
# will be pending by default unless autoaccept
if remote.acceptance == raeting.acceptances.accepted:
self.acceptRemote(remote)
elif remote.acceptance == raeting.acceptances.rejected:
self.rejectRemote(remote)
status = self.statusRole(role=remote.role,
verhex=remote.verfer.keyhex,
pubhex=remote.pubber.keyhex,
dump=dump)
self.saltRaetKey.delete_key(old) #now delete old key file
remote.acceptance = status
def statusRemote(self, remote, verhex, pubhex, main=True, dump=True):
return status
def statusRole(self, role, verhex, pubhex, dump=True):
'''
Evaluate acceptance status of remote estate per its keys
persist key data differentially based on status
Returns status
Where status is acceptance status of role and keys
and has value from raeting.acceptances
'''
status = raeting.ACCEPTANCES[self.saltRaetKey.status(remote.role,
status = raeting.ACCEPTANCES[self.saltRaetKey.status(role,
pubhex,
verhex)]
if status != raeting.acceptances.rejected:
if (verhex and verhex != remote.verfer.keyhex):
remote.verfer = nacling.Verifier(verhex)
if (pubhex and pubhex != remote.pubber.keyhex):
remote.pubber = nacling.Publican(pubhex)
remote.acceptance = status
return status
def rejectRemote(self, remote):
@ -206,12 +266,3 @@ class SaltKeep(Keep):
mid = remote.role
self.saltRaetKey.accept(match=mid, include_rejected=True)
remote.acceptance = raeting.acceptances.accepted
def clearAllKeep(dirpath):
'''
Convenience function to clear all road keep data in dirpath
'''
road = RoadKeep(dirpath=dirpath)
road.clearLocalData()
road.clearAllRemoteData()

View File

@ -2,7 +2,7 @@
house master
init .raet.udp.stack.local to eid 1 name "master" host "" port 7530 main true
init .raet.udp.stack.local to name "master" host "" port 7530 main true
#init port in .raet.udp.stack.local from value in .salt.etc.raet_port

View File

@ -2,7 +2,7 @@
house minion
init .raet.udp.stack.local to eid 0 name "minion" host "" port 7531 main false
init .raet.udp.stack.local to name "minion" host "" port 7531 main false
#init port in .raet.udp.stack.local from value in .salt.etc.raet_port
#init .salt.etc.master to "127.0.0.1"
@ -12,7 +12,8 @@ init .raet.udp.stack.local to eid 0 name "minion" host "" port 7531 main false
framer minionudpstack be active first start
frame start
do salt raet road stack per inode ".raet.udp.stack"
enter
do salt raet road stack setup per inode ".raet.udp.stack"
exit
do salt raet road stack closer per inode ".raet.udp.stack."

File diff suppressed because it is too large Load Diff

View File

@ -1231,3 +1231,20 @@ class RaetKey(Key):
fp_.write(self.serial.dumps(keydata))
os.chmod(path, stat.S_IRUSR)
os.umask(c_umask)
def delete_local(self):
'''
Delete the local private key file
'''
path = os.path.join(self.opts['pki_dir'], 'local.key')
if os.path.isfile(path):
os.remove(path)
def delete_pki_dir(self):
'''
Delete the private key directory
'''
path = self.opts['pki_dir']
if os.path.exists(path):
#os.rmdir(path)
shutil.rmtree(path)

View File

@ -72,8 +72,8 @@ class RAETChannel(Channel):
'''
mid = self.opts.get('id', 'master')
yid = nacling.uuid(size=18)
name = 'channel' + yid
uid = nacling.uuid(size=18)
name = 'channel' + uid
stack = LaneStack(name=name,
lanename=mid,
sockdirpath=self.opts['sock_dir'])
@ -96,7 +96,7 @@ class RAETChannel(Channel):
self.stack = jobber_stack
else:
self.stack = jobber_stack = self._setup_stack()
log.debug("Using Jobber Stack at = {0}\n".format(self.stack.local.ha))
log.debug("Using Jobber Stack at = {0}\n".format(self.stack.ha))
def crypted_transfer_decode_dictentry(self, load, dictkey=None, tries=3, timeout=60):
'''

View File

@ -47,14 +47,14 @@ class SaltEvent(object):
self.connected = False
self.stack = LaneStack(
name=name,
yid=self.yid,
uid=self.yid,
lanename=self.node,
sockdirpath=self.sock_dir)
self.stack.Pk = raeting.packKinds.pack
self.router_yard = RemoteYard(
stack=self.stack,
lanename=self.node,
yid=0,
uid=0,
name='manor',
dirpath=self.sock_dir)
self.stack.addRemote(self.router_yard)