Browse Source

added control to prevent VM start in LCM2, display usage if no argument

Nicolo' Palazzini 5 years ago
parent
commit
f9fe7c32f2
1 changed files with 43 additions and 2 deletions
  1. 43 2
      labcalcoloctl

+ 43 - 2
labcalcoloctl

@@ -13,7 +13,7 @@ from threading import Thread
 from getpass import getpass
 
 choices = ('status','start','stop', 'doctor')
-parser = argparse.ArgumentParser(usage='labcalcolo {'+','.join(choices)+'} [options]')
+parser = argparse.ArgumentParser(description="Simple tool to handle LabCalcolo's VMs.", usage=sys.argv[0]+' {'+','.join(choices)+'} [--options]')
 
 ## positional arguments
 parser.add_argument( 'cmd', nargs="?", choices=choices, default='status',
@@ -171,6 +171,13 @@ Hosts = [
 
 nodes = []
 
+# Show usage if no arguments
+if len(sys.argv) < 2:
+	parser.print_usage()
+	print "\nSimple tool to handle LabCalcolo's VMs."
+	print '\nTry: "'+sys.argv[0]+' --help" to display help message.'
+	sys.exit(1)
+
 # Filter hostlist according to arguments
 if args.lcm:
     nodes  = Hosts
@@ -214,9 +221,43 @@ if args.cmd == 'status':
         print "Down nodes:"
         for i in down :  print '\t',i
 
+#########################################################################################################
+## Since lcm2 nodes have no VMs installed a control is added to make sure operator knows what he's doing.
+## When future (or present?) admins will fix the issue this part should be deleted.
+
 elif args.cmd == 'start':
-    for i in nodes: i.vmstart()
+	yes = {'yes','y','ye'}
+	no = {'no','n'}
+	control = True
+	parsed = False
+	for n in nodes:
+		if n.location == 'LCM2' and parsed == False :
+			print 'You are trying to start a VM on lcm2 nodes. Are you sure you want to continue?'
+			while True:
+				choice = raw_input().lower()
+				if choice in yes:
+					parsed = True
+					break
+				elif choice in no:
+					control = False
+					parsed = True
+					break
+				else:
+					sys.stdout.write("Be kind, respond with 'yes' or 'no'")
+
+	if control == True:
+		for i in nodes: i.vmstart()
+
+#########################################################################################################
+## Uncomment this part when the lcm2 VMs issue will be fixed.
+
+#elif args.cmd == 'start':
+#	for i in nodes: i.vmstart()
+
+#########################################################################################################
+
 elif args.cmd == 'stop':
     for i in nodes: i.vmstop()
+
 elif args.cmd == 'doctor' :
     for i in nodes : i.vmdoctor()