1 from completers import ClusterCompleter
2
3
5 """
6 addnode [options] <cluster_tag>
7
8 Add a node to a running cluster
9
10 Examples:
11
12 $ starcluster addnode mycluster
13
14 This will launch a new node and add it to mycluster. The node's alias will
15 be autogenerated based on the existing node aliases in the cluster.
16
17 If you want to provide your own alias for the node use the -a option:
18
19 $ starcluster addnode -a mynode mycluster
20
21 This will add a new node called 'mynode' to mycluster.
22
23 You can also add multiple nodes using the -n option:
24
25 $ starcluster addnode -n 3 mycluster
26
27 The above example will add three new nodes to mycluster with autogenerated
28 aliases. If you'd rather provide your own aliases:
29
30 $ starcluster addnode -a mynode1,mynode2,mynode3 mycluster
31
32 This will add three new nodes to mycluster named mynode1, mynode2, and
33 mynode3.
34
35 If you've previously attempted to add a node and it failed due to a plugin
36 error or other bug or if you used the 'removenode' command with the '-k'
37 option and wish to re-add the node to the cluster without launching a new
38 instance you can use the '-x' option:
39
40 $ starcluster addnode -x -a mynode1 mycluster
41
42 NOTE: The -x option requires the -a option
43
44 This will add 'mynode1' to mycluster using the existing instance. If no
45 instance exists with the alias specified by the '-a' option an error is
46 reported. You can also do this for multiple nodes:
47
48 $ starcluster addnode -x -a mynode1,mynode2,mynode3 mycluster
49 """
50 names = ['addnode', 'an']
51
52 tag = None
53
55 parser.add_option("-a", "--alias", dest="alias",
56 action="append", type="string", default=[],
57 help="alias to give to the new node "
58 "(e.g. node007, mynode, etc.)")
59 parser.add_option("-n", "--num-nodes", dest="num_nodes",
60 action="store", type="int", default=1,
61 help="number of new nodes to launch")
62 parser.add_option("-x", "--no-create", dest="no_create",
63 action="store_true", default=False,
64 help="do not launch new EC2 instances when "
65 "adding nodes (use existing instances instead)")
66
68 d = {}
69 for item in lst:
70 if item in d:
71 return item
72 else:
73 d[item] = 0
74
76 if len(args) != 1:
77 self.parser.error("please specify a cluster <cluster_tag>")
78 tag = self.tag = args[0]
79 aliases = []
80 for alias in self.opts.alias:
81 aliases.extend(alias.split(','))
82 if 'master' in aliases:
83 self.parser.error("'master' is a reserved alias")
84 num_nodes = self.opts.num_nodes
85 if num_nodes == 1 and aliases:
86 num_nodes = len(aliases)
87 if num_nodes > 1 and aliases and len(aliases) != num_nodes:
88 self.parser.error("you must specify the same number of aliases "
89 "(-a) as nodes (-n)")
90 dupe = self._get_duplicate(aliases)
91 if dupe:
92 self.parser.error("cannot have duplicate aliases (duplicate: %s)" %
93 dupe)
94 if not self.opts.alias and self.opts.no_create:
95 self.parser.error("you must specify one or more node aliases via "
96 "the -a option when using -x")
97 self.cm.add_nodes(tag, num_nodes, aliases=aliases,
98 no_create=self.opts.no_create)
99