3 from allmydata.scripts.common import BasedirOptions
4 from allmydata.util.assertutil import precondition
5 from allmydata.util.encodingutil import listdir_unicode, argv_to_unicode, quote_output
8 class CreateClientOptions(BasedirOptions):
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 def getSynopsis(self):
20 return "Usage: %s create-client [options] [NODEDIR]" % (self.command_name,)
23 class CreateNodeOptions(CreateClientOptions):
25 ("no-storage", None, "Do not offer storage service to other nodes."),
28 def getSynopsis(self):
29 return "Usage: %s create-node [options] [NODEDIR]" % (self.command_name,)
32 class CreateIntroducerOptions(BasedirOptions):
33 default_nodedir = None
35 def getSynopsis(self):
36 return "Usage: %s create-introducer [options] NODEDIR" % (self.command_name,)
43 pkg_resources.require('%s')
44 pkg_resources.require('twisted')
45 from allmydata import client
46 from twisted.application import service
50 application = service.Application("allmydata_client")
51 c.setServiceParent(application)
52 """ % (allmydata.__appname__,)
58 pkg_resources.require('%s')
59 pkg_resources.require('twisted')
60 from allmydata import introducer
61 from twisted.application import service
63 c = introducer.IntroducerNode()
65 application = service.Application("allmydata_introducer")
66 c.setServiceParent(application)
67 """ % (allmydata.__appname__,)
69 def write_node_config(c, config):
70 # this is shared between clients and introducers
71 c.write("# -*- mode: conf; coding: utf-8 -*-\n")
73 c.write("# This file controls the configuration of the Tahoe node that\n")
74 c.write("# lives in this directory. It is only read at node startup.\n")
75 c.write("# For details about the keys that can be set here, please\n")
76 c.write("# read the 'docs/configuration.rst' file that came with your\n")
77 c.write("# Tahoe installation.\n")
81 nickname = argv_to_unicode(config.get("nickname") or "")
82 c.write("nickname = %s\n" % (nickname.encode('utf-8'),))
84 # TODO: validate webport
85 webport = argv_to_unicode(config.get("webport") or "none")
86 if webport.lower() == "none":
88 c.write("web.port = %s\n" % (webport.encode('utf-8'),))
89 c.write("web.static = public_html\n")
90 c.write("#tub.port =\n")
91 c.write("#tub.location = \n")
92 c.write("#log_gatherer.furl =\n")
93 c.write("#timeout.keepalive =\n")
94 c.write("#timeout.disconnect =\n")
95 c.write("#ssh.port = 8022\n")
96 c.write("#ssh.authorized_keys_file = ~/.ssh/authorized_keys\n")
100 def create_node(config, out=sys.stdout, err=sys.stderr):
101 basedir = config['basedir']
102 # This should always be called with an absolute Unicode basedir.
103 precondition(isinstance(basedir, unicode), basedir)
105 if os.path.exists(basedir):
106 if listdir_unicode(basedir):
107 print >>err, "The base directory %s is not empty." % quote_output(basedir)
108 print >>err, "To avoid clobbering anything, I am going to quit now."
109 print >>err, "Please use a different directory, or empty this one."
111 # we're willing to use an empty directory
114 f = open(os.path.join(basedir, "tahoe-client.tac"), "w")
118 c = open(os.path.join(basedir, "tahoe.cfg"), "w")
120 write_node_config(c, config)
122 c.write("[client]\n")
123 c.write("# Which services should this client connect to?\n")
124 c.write("introducer.furl = %s\n" % config.get("introducer", ""))
125 c.write("helper.furl =\n")
126 c.write("#key_generator.furl =\n")
127 c.write("#stats_gatherer.furl =\n")
129 c.write("# What encoding parameters should this client use for uploads?\n")
130 c.write("#shares.needed = 3\n")
131 c.write("#shares.happy = 7\n")
132 c.write("#shares.total = 10\n")
135 boolstr = {True:"true", False:"false"}
136 c.write("[storage]\n")
137 c.write("# Shall this node provide storage service?\n")
138 storage_enabled = not config.get("no-storage", None)
139 c.write("enabled = %s\n" % boolstr[storage_enabled])
140 c.write("#readonly =\n")
141 c.write("reserved_space = 1G\n")
142 c.write("#expire.enabled =\n")
143 c.write("#expire.mode =\n")
146 c.write("[helper]\n")
147 c.write("# Shall this node run a helper service that clients can use?\n")
148 c.write("enabled = false\n")
151 c.write("[drop_upload]\n")
152 c.write("# Shall this node automatically upload files created or modified in a local directory?\n")
153 c.write("enabled = false\n")
154 c.write("# To specify the target of uploads, a mutable directory writecap URI must be placed\n"
155 "# in 'private/drop_upload_dircap'.\n")
156 c.write("local.directory = ~/drop_upload\n")
161 from allmydata.util import fileutil
162 fileutil.make_dirs(os.path.join(basedir, "private"), 0700)
163 print >>out, "Node created in %s" % quote_output(basedir)
164 if not config.get("introducer", ""):
165 print >>out, " Please set [client]introducer.furl= in tahoe.cfg!"
166 print >>out, " The node cannot connect to a grid without it."
167 if not config.get("nickname", ""):
168 print >>out, " Please set [node]nickname= in tahoe.cfg"
171 def create_client(config, out=sys.stdout, err=sys.stderr):
172 config['no-storage'] = True
173 return create_node(config, out=out, err=err)
176 def create_introducer(config, out=sys.stdout, err=sys.stderr):
177 basedir = config['basedir']
178 # This should always be called with an absolute Unicode basedir.
179 precondition(isinstance(basedir, unicode), basedir)
181 if os.path.exists(basedir):
182 if listdir_unicode(basedir):
183 print >>err, "The base directory %s is not empty." % quote_output(basedir)
184 print >>err, "To avoid clobbering anything, I am going to quit now."
185 print >>err, "Please use a different directory, or empty this one."
187 # we're willing to use an empty directory
190 f = open(os.path.join(basedir, "tahoe-introducer.tac"), "w")
191 f.write(introducer_tac)
194 c = open(os.path.join(basedir, "tahoe.cfg"), "w")
195 write_node_config(c, config)
198 print >>out, "Introducer created in %s" % quote_output(basedir)
203 ["create-node", None, CreateNodeOptions, "Create a node that acts as a client, server or both."],
204 ["create-client", None, CreateClientOptions, "Create a client node (with storage initially disabled)."],
205 ["create-introducer", None, CreateIntroducerOptions, "Create an introducer node."],
209 "create-node": create_node,
210 "create-client": create_client,
211 "create-introducer": create_introducer,