From d2f39e771e1a4390a641aad997964fbaf058439b Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sat, 13 Jun 2015 18:32:46 +0100
Subject: [PATCH] set some useful ssh options

---
 noblogsmv/main.py | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/noblogsmv/main.py b/noblogsmv/main.py
index cd69b67..efa76a8 100644
--- a/noblogsmv/main.py
+++ b/noblogsmv/main.py
@@ -17,14 +17,13 @@ MYSQL_URI_RE = re.compile(
 log = logging.getLogger(__name__)
 
 
-def execute_gen(cmd, dry_run = False):
+def execute_gen(cmd, dry_run=False):
     if dry_run:
         log.info("[DR] %s" % cmd)
         return ''
     return subprocess.check_output(cmd)
 
 
-
 def init(blog_id, value, progress):
     return 'move_data'
 
@@ -41,7 +40,6 @@ class MysqlNoblogs(object):
         self.old = self.conn(old_host,old_port,old_user,old_pass, old_db)
         self.new = self.conn(new_host,new_port,new_user,new_pass, new_db)
 
-
     def options(self, conn):
         return '-h%s -P%s -u%s -p%s' % (conn.host,conn.port,
                                         conn.user,conn.password)
@@ -57,20 +55,19 @@ class MysqlNoblogs(object):
     def find_tables(self, blog_id):
         find_tables =['mysql', self.options(self.old), self.old.db, '-NBe',
                        "'show tables like \"wp\\_%s\\_%%\"'" % blog_id]
-        cmd = ['ssh', 'root@%s' % self.old.host,
-               "%s" % ' '.join(find_tables)]
+        cmd = ['ssh', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=no',
+               'root@%s' % self.old.host, '%s' % ' '.join(find_tables)]
         log.debug('Calling %s', ' '.join(cmd))
         raw_tables = subprocess.check_output(cmd)
         self.tables = [ t.strip() for t in raw_tables.splitlines()]
 
 
-
-
 def process_move_data(blog_id, value, progress):
     progress.update('moving blog data')
     log.info('moving data for %s', blog_id)
     blog_dir = os.path.join(BLOGS_DIR, blog_id)
-    cmd = ['ssh', 'root@%s' % value['old_host'], 'rsync', '-az',
+    cmd = ['ssh', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=no',
+           'root@%s' % value['old_host'], 'rsync', '-az',
            '%s/' % blog_dir, 'root@%s:%s' % (value['new_host'], blog_dir)]
     log.debug('Calling %s', ' '.join(cmd))
     try:
@@ -106,7 +103,8 @@ def process_move_db(blog_id, value, progress):
     tables = ' '.join(db.tables)
     move_db = ['mysqldump', '--opt', db.old_options, value['old_db'], tables,
                '|', 'mysql', db.new_options, value['new_db']]
-    cmd = ['ssh', 'root@%s' % value['old_host'], '%s' % ' '.join(move_db)]
+    cmd = ['ssh', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=no',
+           'root@%s' % value['old_host'], '%s' % ' '.join(move_db)]
     log.debug('Calling %s', ' '.join(cmd))
     try:
         execute(cmd)
@@ -137,7 +135,8 @@ def process_rm_db(blog_id, value, progress):
     tables = ', '.join(db.tables)
     drop_db = ['mysql', db.old_options, db.old.db, '-NBe',
                '"DROP TABLE %s"' % tables]
-    cmd = ['ssh', 'root@%s' % value['old_host'], '%s' % ' '.join(drop_db)]
+    cmd = ['ssh', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=no',
+           'root@%s' % value['old_host'], '%s' % ' '.join(drop_db)]
     try:
         execute(cmd)
     except (subprocess.CalledProcessError, OSError), e:
@@ -147,11 +146,13 @@ def process_rm_db(blog_id, value, progress):
     progress.update('removed blog db; Done.')
     return state.STATE_DONE
 
+
 def process_rm_data(blog_id, value, progress):
     progress.update('removing blog data files from old location')
     log.info('Removing blog data files')
     blog_dir = os.path.join(BLOGS_DIR, blog_id)
-    cmd = ['ssh', 'root@%s' % value['old_host'], 'rm', '-rf',
+    cmd = ['ssh', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=no',
+           'root@%s' % value['old_host'], 'rm', '-rf',
            '%s/' % blog_dir]
     log.debug('Calling %s', ' '.join(cmd))
     try:
@@ -231,7 +232,7 @@ use the `--recover' option.
         level=(logging.DEBUG if opts.debug else logging.INFO))
 
     global execute
-    execute = partial(execute_gen, dry_run = opts.dry_run)
+    execute = partial(execute_gen, dry_run=opts.dry_run)
 
     if opts.clean:
         statemachine = NoblogsCleanStateMachine
-- 
GitLab