diff --git a/lib/muchos/ec2.py b/lib/muchos/ec2.py index 90cb572e..f4f02a25 100644 --- a/lib/muchos/ec2.py +++ b/lib/muchos/ec2.py @@ -301,6 +301,30 @@ def print_nodes(nodes): node.get("PublicIpAddress", ""), ) + def stop(self): + nodes = self.active_nodes() + print( + "The following {0} nodes in {1} cluster " + "will be stopped:".format(len(nodes), self.config.cluster_name) + ) + ec2 = boto3.client("ec2") + for node in nodes: + ec2.stop_instances(InstanceIds=[node["InstanceId"]]) + self.print_nodes(nodes) + print("Stopped nodes.") + + def start(self): + nodes = self.active_nodes() + print( + "The following {0} nodes in {1} cluster " + "will be started:".format(len(nodes), self.config.cluster_name) + ) + ec2 = boto3.client("ec2") + for node in nodes: + ec2.start_instances(InstanceIds=[node["InstanceId"]]) + self.print_nodes(nodes) + print("Started nodes.") + def terminate(self): nodes = self.active_nodes() print( diff --git a/lib/muchos/existing.py b/lib/muchos/existing.py index bb3c7d3c..df3abc0e 100644 --- a/lib/muchos/existing.py +++ b/lib/muchos/existing.py @@ -228,6 +228,20 @@ def terminate(): "when cluster_type is set to 'existing'" ) + @staticmethod + def stop(): + exit( + "ERROR - 'stop' command cannot be used " + "when cluster_type is set to 'existing'" + ) + + @staticmethod + def start(): + exit( + "ERROR - 'start' command cannot be used " + "when cluster_type is set to 'existing'" + ) + def ssh(self): self.wait_until_proxy_ready() fwd = "" @@ -352,6 +366,10 @@ def perform(self, action): self.sync() elif action == "setup": self.setup() + elif action == "start": + self.start() + elif action == "stop": + self.stop() elif action == "ssh": self.ssh() elif action == "wipe": diff --git a/lib/muchos/util.py b/lib/muchos/util.py index 158ea920..8022d776 100644 --- a/lib/muchos/util.py +++ b/lib/muchos/util.py @@ -156,6 +156,8 @@ def parse_args(hosts_dir, input_args=None): + " sync Sync ansible directory on cluster proxy node\n" + " config Print configuration for that cluster. " "Requires '-p'. Use '-p all' for all config.\n" + + " stop Stops instance\n" + + " start Starts instance\n" + " ssh SSH to cluster proxy node\n" + " kill Kills processes on cluster started by Muchos\n" + " wipe Wipes cluster data and kills processes\n"