Changeset 5dbcc93 for fedd


Ignore:
Timestamp:
Jan 21, 2013 11:49:03 AM (12 years ago)
Author:
Ted Faber <faber@…>
Branches:
master
Children:
06a2b49
Parents:
2dc99e3
Message:

Last few tricks. Manage hosts, make whole script sudo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/desktop_access.py

    r2dc99e3 r5dbcc93  
    276276                        'FreeBSD will not route based on src address')
    277277            elif gw is not None:
    278                 print >>script, 'sudo route add %s %s' % (dest, gw)
     278                print >>script, 'route add %s %s' % (dest, gw)
    279279        elif sys.platform.startswith('linux'):
    280280            if src is not None and gw is not None:
    281                 print >>script, 'sudo ip route add %s via %s src %s' % \
     281                print >>script, 'ip route add %s via %s src %s' % \
    282282                        (dest, gw, src)
    283283            elif src is not None:
    284                 print >>script, 'sudo ip route add %s src %s' % \
     284                print >>script, 'ip route add %s src %s' % \
    285285                        (dest, src)
    286286            elif gw is not None:
    287                 print >>script, 'sudo ip route add %s via %s' % (dest, gw)
     287                print >>script, 'ip route add %s via %s' % (dest, gw)
    288288        else:
    289289            raise service_error(service_error.internal,
     
    293293        rv = 0
    294294        if sys.platform.startswith('freebsd'):
    295             print >>script, 'sudo route delete %s' % dest
     295            print >>script, 'route delete %s' % dest
    296296        elif sys.platform.startswith('linux'):
    297             print >>script, 'sudo ip route delete %s' % dest
     297            print >>script, 'ip route delete %s' % dest
    298298
    299299    def find_a_peer(self, addr):
     
    368368        cscript = os.path.join(self.localdir, 'connect')
    369369        dscript = os.path.join(self.localdir, 'disconnect')
     370        local_hosts = os.path.join(self.localdir, 'hosts')
    370371        try:
    371372            f = open(cscript, 'w')
     
    379380            print >>f,'while ! /usr/bin/scp -o "StrictHostKeyChecking no" -i %s %s:/usr/local/federation/etc/prep_done /dev/null; do' % (self.ssh_identity, peer)
    380381            print >>f, 'sleep 60; done'
    381             print >>f, ('sudo ssh -w 0:0 -p %s -o "Tunnel ethernet" ' + \
     382            print >>f, ('ssh -w 0:0 -p %s -o "Tunnel ethernet" ' + \
    382383                    '-o "StrictHostKeyChecking no" -i %s %s perl -I/usr/local/federation/lib /usr/local/federation/bin/setup_bridge.pl --tapno=0 --addr=%s &') % \
    383384                    (port, self.ssh_identity, peer, my_addr)
    384385            # This should give the tap a a chance to come up
    385386            print >>f,'sleep 10'
    386             # Assign its address and route connections through it.
    387             print >>f, 'sudo ifconfig tap0 %s netmask 255.255.255.0 up' % \
     387            # Add experiment nodes to hosts
     388            print >>f, 'cp /etc/hosts /etc/hosts.DETER.fedd.hold'
     389            print >>f, 'echo "#--- BEGIN FEDD ADDITIONS ---" >> /etc/hosts'
     390            print >>f, 'cat %s >> /etc/hosts' % local_hosts
     391            print >>f, 'echo "#--- END FEDD ADDITIONS ---" >> /etc/hosts'
     392            # Assign tap address and route experiment connections through it.
     393            print >>f, 'ifconfig tap0 %s netmask 255.255.255.0 up' % \
    388394                    my_addr
    389395            self.set_route('10.0.0.0/8', f, exp_peer)
     
    392398            f = open(dscript, 'w')
    393399            print >>f, '#!/bin/sh'
    394             print >>f, 'sudo ifconfig tap0 destroy'
     400            print >>f, 'ifconfig tap0 destroy'
    395401            self.unset_route(peer, f)
    396402            self.unset_route('10.0.0.0/8', f)
     403            print >>f, 'mv /etc/hosts.DETER.fedd.hold /etc/hosts'
    397404            f.close()
    398405            os.chmod(dscript, 0755)
     
    400407            raise service_error(service_error.internal,
    401408                    'Cannot create connect %s: %s' % (e.filename, e.strerror))
    402         #subprocess.call(['/bin/sh', cscript])
     409        script_log = open('/tmp/connect.log', 'w')
     410        subprocess.Popen(['sudo', '/bin/sh', cscript], stdout=script_log, stderr=script_log)
    403411        return True
    404412
     
    537545        cscript = os.path.join(self.localdir, 'connect')
    538546        dscript = os.path.join(self.localdir, 'disconnect')
    539         # XXX restore this
    540         #if os.path.exists(dscript):
    541             #self.log.debug('calling %s' % dscript)
    542             #rv = subprocess.call(['/bin/sh', dscript])
    543             #if rv != 0:
    544                 #self.log.warning('%s had an error: %d' % (dscript, rv))
    545         #else:
    546             #self.log.warn('No disconnection script!?')
     547        # Do the work of disconnecting
     548        if os.path.exists(dscript):
     549            self.log.debug('calling %s' % dscript)
     550            rv = subprocess.call(['sudo', '/bin/sh', dscript])
     551            if rv != 0:
     552                self.log.warning('%s had an error: %d' % (dscript, rv))
     553        else:
     554            self.log.warn('No disconnection script!?')
    547555
    548556        try:
Note: See TracChangeset for help on using the changeset viewer.