3 from allmydata.scripts.common import BasedirMixin, BaseOptions
4 from allmydata.util.assertutil import precondition
5 from allmydata.util.encodingutil import listdir_unicode, argv_to_unicode, quote_output
8 class CreateClientOptions(BasedirMixin, BaseOptions):
10 # we provide 'create-node'-time options for the most common
11 # configuration knobs. The rest can be controlled by editing
12 # tahoe.cfg before node startup.
13 ("nickname", "n", None, "Specify the nickname for this node."),
14 ("introducer", "i", None, "Specify the introducer FURL to use."),
15 ("webport", "p", "tcp:3456:interface=127.0.0.1",
16 "Specify which TCP port to run the HTTP interface on. Use 'none' to disable."),
19 class CreateNodeOptions(CreateClientOptions):
21 ("no-storage", None, "Do not offer storage service to other nodes."),
24 class CreateIntroducerOptions(BasedirMixin, BaseOptions):
25 default_nodedir = None
28 ["node-directory", "d", None, "Specify which directory the introducer should be created in. [no default]"],
35 pkg_resources.require('%s')
36 pkg_resources.require('twisted')
37 from allmydata import client
38 from twisted.application import service
42 application = service.Application("allmydata_client")
43 c.setServiceParent(application)
44 """ % (allmydata.__appname__,)
50 pkg_resources.require('%s')
51 pkg_resources.require('twisted')
52 from allmydata import introducer
53 from twisted.application import service
55 c = introducer.IntroducerNode()
57 application = service.Application("allmydata_introducer")
58 c.setServiceParent(application)
59 """ % (allmydata.__appname__,)
61 def write_node_config(c, config):
62 # this is shared between clients and introducers
63 c.write("# -*- mode: conf; coding: utf-8 -*-\n")
65 c.write("# This file controls the configuration of the Tahoe node that\n")
66 c.write("# lives in this directory. It is only read at node startup.\n")
67 c.write("# For details about the keys that can be set here, please\n")
68 c.write("# read the 'docs/configuration.rst' file that came with your\n")
69 c.write("# Tahoe installation.\n")
73 nickname = argv_to_unicode(config.get("nickname") or "")
74 c.write("nickname = %s\n" % (nickname.encode('utf-8'),))
76 # TODO: validate webport
77 webport = argv_to_unicode(config.get("webport") or "none")
78 if webport.lower() == "none":
80 c.write("web.port = %s\n" % (webport.encode('utf-8'),))
81 c.write("web.static = public_html\n")
82 c.write("#tub.port =\n")
83 c.write("#tub.location = \n")
84 c.write("#log_gatherer.furl =\n")
85 c.write("#timeout.keepalive =\n")
86 c.write("#timeout.disconnect =\n")
87 c.write("#ssh.port = 8022\n")
88 c.write("#ssh.authorized_keys_file = ~/.ssh/authorized_keys\n")
92 def create_node(config, out=sys.stdout, err=sys.stderr):
93 basedir = config['basedir']
94 # This should always be called with an absolute Unicode basedir.
95 precondition(isinstance(basedir, unicode), basedir)
97 if os.path.exists(basedir):
98 if listdir_unicode(basedir):
99 print >>err, "The base directory %s is not empty." % quote_output(basedir)
100 print >>err, "To avoid clobbering anything, I am going to quit now."
101 print >>err, "Please use a different directory, or empty this one."
103 # we're willing to use an empty directory
106 f = open(os.path.join(basedir, "tahoe-client.tac"), "w")
110 c = open(os.path.join(basedir, "tahoe.cfg"), "w")
112 write_node_config(c, config)
114 c.write("[client]\n")
115 c.write("introducer.furl = %s\n" % config.get("introducer", ""))
116 c.write("helper.furl =\n")
117 c.write("#key_generator.furl =\n")
118 c.write("#stats_gatherer.furl =\n")
119 c.write("#shares.needed = 3\n")
120 c.write("#shares.happy = 7\n")
121 c.write("#shares.total = 10\n")
124 boolstr = {True:"true", False:"false"}
125 c.write("[storage]\n")
126 storage_enabled = not config.get("no-storage", None)
127 c.write("enabled = %s\n" % boolstr[storage_enabled])
128 c.write("#readonly =\n")
129 c.write("reserved_space = 1G\n")
130 c.write("#expire.enabled =\n")
131 c.write("#expire.mode =\n")
134 c.write("[helper]\n")
135 c.write("enabled = false\n")
140 from allmydata.util import fileutil
141 fileutil.make_dirs(os.path.join(basedir, "private"), 0700)
142 print >>out, "Node created in %s" % quote_output(basedir)
143 if not config.get("introducer", ""):
144 print >>out, " Please set [client]introducer.furl= in tahoe.cfg!"
145 print >>out, " The node cannot connect to a grid without it."
146 if not config.get("nickname", ""):
147 print >>out, " Please set [node]nickname= in tahoe.cfg"
150 def create_client(config, out=sys.stdout, err=sys.stderr):
151 config['no-storage'] = True
152 return create_node(config, out=out, err=err)
155 def create_introducer(config, out=sys.stdout, err=sys.stderr):
156 basedir = config['basedir']
157 # This should always be called with an absolute Unicode basedir.
158 precondition(isinstance(basedir, unicode), basedir)
160 if os.path.exists(basedir):
161 if listdir_unicode(basedir):
162 print >>err, "The base directory %s is not empty." % quote_output(basedir)
163 print >>err, "To avoid clobbering anything, I am going to quit now."
164 print >>err, "Please use a different directory, or empty this one."
166 # we're willing to use an empty directory
169 f = open(os.path.join(basedir, "tahoe-introducer.tac"), "w")
170 f.write(introducer_tac)
173 c = open(os.path.join(basedir, "tahoe.cfg"), "w")
174 write_node_config(c, config)
177 print >>out, "Introducer created in %s" % quote_output(basedir)
182 ["create-node", None, CreateNodeOptions, "Create a node that acts as a client, server or both."],
183 ["create-client", None, CreateClientOptions, "Create a client node (with storage initially disabled)."],
184 ["create-introducer", None, CreateIntroducerOptions, "Create an introducer node."],
188 "create-node": create_node,
189 "create-client": create_client,
190 "create-introducer": create_introducer,