import configparser
import sys
import os

parser = configparser.ConfigParser()
parser.read("../halite.ini")
WORKERS = dict(parser.items("workerIPs"))

command = sys.argv[1]
print(command)
for name in WORKERS:
    print("########"+name+"########")
    print(WORKERS[name])
    os.system("ssh root@"+WORKERS[name]+" '"+command+"'")
    print("################\n")

import pymysql
import configparser
import sys
import os
import os.path

parser = configparser.ConfigParser()
parser.read("../halite.ini")
DB_CONFIG = parser["database"]

keyPath = os.path.join("../", parser["aws"]["keyfilepath"])

db = pymysql.connect(host=DB_CONFIG["hostname"], user=DB_CONFIG['username'], passwd=DB_CONFIG['password'], db=DB_CONFIG['name'], cursorclass=pymysql.cursors.DictCursor)
cursor = db.cursor()

cursor.execute("select * from Worker")
workers = cursor.fetchall()


command = sys.argv[1]
for worker in workers:
    print("########"+worker['ipAddress']+"########")
    os.system("ssh -i \""+keyPath+"\" ubuntu@"+worker['ipAddress']+" '"+command+"'")
    print("################\n")

Switch command runner to using db
Switch command runner to using db

+ import pymysql
  import configparser
  import sys
  import os
+ import os.path
  
  parser = configparser.ConfigParser()
  parser.read("../halite.ini")
- WORKERS = dict(parser.items("workerIPs"))
+ DB_CONFIG = parser["database"]
+ 
+ keyPath = os.path.join("../", parser["aws"]["keyfilepath"])
+ 
+ db = pymysql.connect(host=DB_CONFIG["hostname"], user=DB_CONFIG['username'], passwd=DB_CONFIG['password'], db=DB_CONFIG['name'], cursorclass=pymysql.cursors.DictCursor)
+ cursor = db.cursor()
+ 
+ cursor.execute("select * from Worker")
+ workers = cursor.fetchall()
+ 
  
  command = sys.argv[1]
+ for worker in workers:
- print(command)
- for name in WORKERS:
-     print("########"+name+"########")
+     print("########"+worker['ipAddress']+"########")
+     os.system("ssh -i \""+keyPath+"\" ubuntu@"+worker['ipAddress']+" '"+command+"'")
-     print(WORKERS[name])
-     os.system("ssh root@"+WORKERS[name]+" '"+command+"'")
      print("################\n")
  
Switch command runner to using db
## Code Before:
import configparser
import sys
import os

parser = configparser.ConfigParser()
parser.read("../halite.ini")
WORKERS = dict(parser.items("workerIPs"))

command = sys.argv[1]
print(command)
for name in WORKERS:
    print("########"+name+"########")
    print(WORKERS[name])
    os.system("ssh root@"+WORKERS[name]+" '"+command+"'")
    print("################\n")

## Instruction:
Switch command runner to using db
## Code After:
import pymysql
import configparser
import sys
import os
import os.path

parser = configparser.ConfigParser()
parser.read("../halite.ini")
DB_CONFIG = parser["database"]

keyPath = os.path.join("../", parser["aws"]["keyfilepath"])

db = pymysql.connect(host=DB_CONFIG["hostname"], user=DB_CONFIG['username'], passwd=DB_CONFIG['password'], db=DB_CONFIG['name'], cursorclass=pymysql.cursors.DictCursor)
cursor = db.cursor()

cursor.execute("select * from Worker")
workers = cursor.fetchall()


command = sys.argv[1]
for worker in workers:
    print("########"+worker['ipAddress']+"########")
    os.system("ssh -i \""+keyPath+"\" ubuntu@"+worker['ipAddress']+" '"+command+"'")
    print("################\n")
