Exemplo n.º 1
0
def command():
    # bootsrap <name> -i <ip>[:<port>] [-l <logpath>] [-k <keypath>] [-f]
    args = parser.parse_args()
    default_logpath = os.path.join(defaults.dir, 'logs', args.name)
    logpath = args.logpath or default_logpath
    port = args.port or get_port(args.name)
    utils.create_logdir(logpath, default_logpath, args.force)
    keys = []
    for keypath in args.keypaths.split(','):
        if not os.path.isfile(keypath):
            sys.stderr.write("Error: bootsraping keypath %s does not exist.\n" % keypath)
            sys.exit(2)
        keys.append(Key.load(keypath))
    log = Log(logpath) # TODO, name=args.name)
    ips = []
    for ip in args.ips.split(','):
        if ':' not in ip:
            ip += ':%i' % port
        ips.append(ip)
    log.bootstrap(keys, ips)
    config = get_or_create_config(defaults)
    if args.name not in config:
        config[args.name] = {}
    config[args.name].update({
        'logpath': logpath,
        'port': str(port),
    })
    config.save()
    sys.stdout.write('Created log file %s\n' % logpath)
    sys.stdout.write('Network bootstraping will happen at:\n  %s\n' % '\n  '.join(ips))
    sys.exit(0)
Exemplo n.º 2
0
 def setUp(self):
     __, self.logpath = tempfile.mkstemp()
     __, self.logpath_b = tempfile.mkstemp()
     self.addCleanup(os.remove, self.logpath)
     self.addCleanup(os.remove, self.logpath_b)
     __, self.keypath = tempfile.mkstemp()
     self.addCleanup(os.remove, self.keypath)
     self.port = random.randint(40000, 50000-1)
     self.port_b = random.randint(50000, 60000)
     
     log = Log(self.logpath)
     root_key = Key.generate()
     log.bootstrap([root_key], ['127.0.0.1:%i' % self.port])
     root_key.save(self.keypath)
     shutil.copy2(self.logpath, self.logpath_b)
     self.hostname = utils.random_ascii(10)
     self.hostname_b = utils.random_ascii(10)
     self.mountpath = tempfile.mkdtemp()
     self.mountpath_b = tempfile.mkdtemp()
     context = {
         'mountpath': self.mountpath,
         'logpath': self.logpath,
         'keypath': self.keypath,
         'port': self.port,
         'hostname': self.hostname,
     }
     cmd = 'basefs mount %(logpath)s %(mountpath)s -k %(keypath)s -p %(port)s -n %(hostname)s'
     proc = subprocess.Popen(cmd % context, shell=True)
     self.addCleanup(proc.kill)
     time.sleep(1)
     self.addCleanup(proc.kill)
     context.update({
         'mountpath': self.mountpath_b,
         'logpath': self.logpath_b,
         'port': self.port_b,
         'hostname': self.hostname_b,
     })
     proc = subprocess.Popen(cmd % context, shell=True)
     self.addCleanup(proc.kill)
     self.addCleanup(time.sleep, 1)
     self.addCleanup(proc.kill)
     self.addCleanup(shutil.rmtree, self.mountpath)
     self.addCleanup(shutil.rmtree, self.mountpath_b)
     time.sleep(1)
Exemplo n.º 3
0
def bootstrap(logpath):
    log = Log(logpath)
    root_key = Key.generate()
    ip = '127.0.0.1'
    log.bootstrap([root_key], [ip])
    return log, root_key
Exemplo n.º 4
0
def bootstrap(logpath):
    log = Log(logpath)
    root_key = Key.generate()
    ip = '127.0.0.1'
    log.bootstrap([root_key], [ip])
    return log, root_key