3 from twisted.python import usage
4 from allmydata.scripts.common import BasedirMixin, NoDefaultBasedirMixin
6 class CreateClientOptions(BasedirMixin, usage.Options):
8 ("basedir", "C", None, "which directory to create the node in"),
9 # we provide 'create-node'-time options for the most common
10 # configuration knobs. The rest can be controlled by editing
11 # tahoe.cfg before node startup.
12 ("nickname", "n", None, "nickname for this node"),
13 ("introducer", "i", None, "introducer FURL to use"),
14 ("webport", "p", "tcp:3456:interface=127.0.0.1",
15 "which TCP port to run the HTTP interface on. Use 'none' to disable."),
18 class CreateNodeOptions(CreateClientOptions):
20 ("no-storage", None, "do not offer storage service to other nodes"),
23 class CreateIntroducerOptions(NoDefaultBasedirMixin, usage.Options):
25 ["basedir", "C", None, "which directory to create the introducer in"],
32 pkg_resources.require('allmydata-tahoe')
33 pkg_resources.require('twisted')
34 from allmydata import client
35 from twisted.application import service
39 application = service.Application("allmydata_client")
40 c.setServiceParent(application)
47 pkg_resources.require('allmydata-tahoe')
48 pkg_resources.require('twisted')
49 from allmydata import introducer
50 from twisted.application import service
52 c = introducer.IntroducerNode()
54 application = service.Application("allmydata_introducer")
55 c.setServiceParent(application)
58 def write_node_config(c, config):
59 # this is shared between clients and introducers
60 c.write("# -*- mode: conf; coding: utf-8 -*-\n")
62 c.write("# This file controls the configuration of the Tahoe node that\n")
63 c.write("# lives in this directory. It is only read at node startup.\n")
64 c.write("# For details about the keys that can be set here, please\n")
65 c.write("# read the 'docs/configuration.txt' file that came with your\n")
66 c.write("# Tahoe installation.\n")
70 c.write("nickname = %s\n" % config.get("nickname", "")) #TODO: utf8 in argv?
71 webport = config.get("webport", "none")
72 if webport.lower() == "none":
74 c.write("web.port = %s\n" % webport)
75 c.write("web.static = public_html\n")
76 c.write("#tub.port =\n")
77 c.write("#tub.location = \n")
78 c.write("#log_gatherer.furl =\n")
79 c.write("#timeout.keepalive =\n")
80 c.write("#timeout.disconnect =\n")
81 c.write("#ssh.port = 8022\n")
82 c.write("#ssh.authorized_keys_file = ~/.ssh/authorized_keys\n")
86 def create_node(basedir, config, out=sys.stdout, err=sys.stderr):
87 if os.path.exists(basedir):
88 if os.listdir(basedir):
89 print >>err, "The base directory \"%s\", which is \"%s\" is not empty." % (basedir, os.path.abspath(basedir))
90 print >>err, "To avoid clobbering anything, I am going to quit now."
91 print >>err, "Please use a different directory, or empty this one."
93 # we're willing to use an empty directory
96 f = open(os.path.join(basedir, "tahoe-client.tac"), "w")
100 c = open(os.path.join(basedir, "tahoe.cfg"), "w")
102 write_node_config(c, config)
104 c.write("[client]\n")
105 c.write("introducer.furl = %s\n" % config.get("introducer", ""))
106 c.write("helper.furl =\n")
107 c.write("#key_generator.furl =\n")
108 c.write("#stats_gatherer.furl =\n")
109 c.write("#shares.needed = 3\n")
110 c.write("#shares.happy = 7\n")
111 c.write("#shares.total = 10\n")
114 boolstr = {True:"true", False:"false"}
115 c.write("[storage]\n")
116 storage_enabled = not config.get("no-storage", None)
117 c.write("enabled = %s\n" % boolstr[storage_enabled])
118 c.write("#readonly =\n")
119 c.write("#reserved_space =\n")
120 c.write("#expire.enabled =\n")
121 c.write("#expire.mode =\n")
124 c.write("[helper]\n")
125 c.write("enabled = false\n")
130 from allmydata.util import fileutil
131 fileutil.make_dirs(os.path.join(basedir, "private"), 0700)
132 print >>out, "Node created in %s" % basedir
133 if not config.get("introducer", ""):
134 print >>out, " Please set [client]introducer.furl= in tahoe.cfg!"
135 print >>out, " The node cannot connect to a grid without it."
136 if not config.get("nickname", ""):
137 print >>out, " Please set [node]nickname= in tahoe.cfg"
140 def create_client(basedir, config, out=sys.stdout, err=sys.stderr):
141 config['no-storage'] = True
142 return create_node(basedir, config, out=out, err=err)
145 def create_introducer(basedir, config, out=sys.stdout, err=sys.stderr):
146 if os.path.exists(basedir):
147 if os.listdir(basedir):
148 print >>err, "The base directory \"%s\", which is \"%s\" is not empty." % (basedir, os.path.abspath(basedir))
149 print >>err, "To avoid clobbering anything, I am going to quit now."
150 print >>err, "Please use a different directory, or empty this one."
152 # we're willing to use an empty directory
155 f = open(os.path.join(basedir, "tahoe-introducer.tac"), "w")
156 f.write(introducer_tac)
159 c = open(os.path.join(basedir, "tahoe.cfg"), "w")
160 write_node_config(c, config)
163 print >>out, "Introducer created in %s" % basedir
167 ["create-node", None, CreateNodeOptions, "Create a node that acts as a client, server or both."],
168 ["create-client", None, CreateClientOptions, "Create a client node (with storage initially disabled)."],
169 ["create-introducer", None, CreateIntroducerOptions, "Create an introducer node."],
173 "create-node": create_node,
174 "create-client": create_client,
175 "create-introducer": create_introducer,