Add Start and Stop options (#360)
* Add Start and Stop options
diff --git a/lib/muchos/ec2.py b/lib/muchos/ec2.py
index 90cb572..f4f02a2 100644
--- a/lib/muchos/ec2.py
+++ b/lib/muchos/ec2.py
@@ -301,6 +301,30 @@
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 bb3c7d3..df3abc0 100644
--- a/lib/muchos/existing.py
+++ b/lib/muchos/existing.py
@@ -228,6 +228,20 @@
"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 @@
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 158ea92..8022d77 100644
--- a/lib/muchos/util.py
+++ b/lib/muchos/util.py
@@ -156,6 +156,8 @@
+ " 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"