]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/scripts/create_node.py
create_node: use a webport by default, on localhost:8011
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / create_node.py
1
2 import os, sys
3 from twisted.python import usage
4 from allmydata.scripts.common import BasedirMixin, NoDefaultBasedirMixin
5
6 class CreateClientOptions(BasedirMixin, usage.Options):
7     optParameters = [
8         ["basedir", "C", None, "which directory to create the client in"],
9         ["webport", "p", "tcp:8011:interface=127.0.0.1",
10          "which TCP port to run the HTTP interface on. Use 'none' to disable."],
11         ]
12
13 class CreateIntroducerOptions(NoDefaultBasedirMixin, usage.Options):
14     optParameters = [
15         ["basedir", "C", None, "which directory to create the introducer in"],
16         ]
17
18 client_tac = """
19 # -*- python -*-
20
21 from allmydata import client
22 from twisted.application import service
23
24 c = client.Client()
25
26 application = service.Application("allmydata_client")
27 c.setServiceParent(application)
28 """
29
30 introducer_tac = """
31 # -*- python -*-
32
33 from allmydata import introducer_and_vdrive
34 from twisted.application import service
35
36 c = introducer_and_vdrive.IntroducerAndVdrive()
37
38 application = service.Application("allmydata_introducer")
39 c.setServiceParent(application)
40 """
41
42 def create_client(basedir, config, out=sys.stdout, err=sys.stderr):
43     if os.path.exists(basedir):
44         if os.listdir(basedir):
45             print >>err, "The base directory already exists: %s" % basedir
46             print >>err, "To avoid clobbering anything, I am going to quit now"
47             print >>err, "Please use a different directory, or delete this one"
48             return -1
49         # we're willing to use an empty directory
50     else:
51         os.mkdir(basedir)
52     f = open(os.path.join(basedir, "client.tac"), "w")
53     f.write(client_tac)
54     f.close()
55     if config['webport'].lower() != "none":
56         f = open(os.path.join(basedir, "webport"), "w")
57         f.write(config['webport'] + "\n")
58         f.close()
59     print >>out, "client created in %s" % basedir
60     print >>out, " please copy introducer.furl and vdrive.furl into the directory"
61
62 def create_introducer(basedir, config, out=sys.stdout, err=sys.stderr):
63     if os.path.exists(basedir):
64         if os.listdir(basedir):
65             print >>err, "The base directory already exists: %s" % basedir
66             print >>err, "To avoid clobbering anything, I am going to quit now"
67             print >>err, "Please use a different directory, or delete this one"
68             return -1
69         # we're willing to use an empty directory
70     else:
71         os.mkdir(basedir)
72     f = open(os.path.join(basedir, "introducer.tac"), "w")
73     f.write(introducer_tac)
74     f.close()
75     print >>out, "introducer created in %s" % basedir
76
77 subCommands = [
78     ["create-client", None, CreateClientOptions, "Create a client node."],
79     ["create-introducer", None, CreateIntroducerOptions, "Create a introducer node."],
80
81 ]
82
83 dispatch = {
84     "create-client": create_client,
85     "create-introducer": create_introducer,
86     }