summaryrefslogtreecommitdiff
path: root/ssh-rsync.check
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2015-06-02 13:52:51 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2015-06-02 13:52:51 +0000
commit0cd8880023fc65ec581da95dd49a58b5996a1279 (patch)
treeab2c40dd442b044e12b4338fd55cab2dabf031c6 /ssh-rsync.check
parent4f43fdd08770c113f7443fecbda43d4316091d4b (diff)
parent30cba5d9a8757f6bafc8079377aa3d6705e8364c (diff)
downloaddefinitions-0cd8880023fc65ec581da95dd49a58b5996a1279.tar.gz
Put the deployment extensions from morphlib in definitions
This merge commit merges the deployment extensions and all relevant history from morphlib into definitions.
Diffstat (limited to 'ssh-rsync.check')
-rwxr-xr-xssh-rsync.check64
1 files changed, 64 insertions, 0 deletions
diff --git a/ssh-rsync.check b/ssh-rsync.check
new file mode 100755
index 00000000..c3bdfd29
--- /dev/null
+++ b/ssh-rsync.check
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+# Copyright (C) 2014-2015 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+'''Preparatory checks for Morph 'ssh-rsync' write extension'''
+
+import cliapp
+
+import os
+
+import morphlib.writeexts
+
+class SshRsyncCheckExtension(morphlib.writeexts.WriteExtension):
+ def process_args(self, args):
+ if len(args) != 1:
+ raise cliapp.AppException('Wrong number of command line args')
+
+ upgrade = self.get_environment_boolean('UPGRADE')
+ if not upgrade:
+ raise cliapp.AppException(
+ 'The ssh-rsync write is for upgrading existing remote '
+ 'Baserock machines. It cannot be used for an initial '
+ 'deployment.')
+
+ if os.environ.get('VERSION_LABEL', '') == '':
+ raise cliapp.AppException(
+ 'A VERSION_LABEL must be set when deploying an upgrade.')
+
+ location = args[0]
+ self.check_ssh_connectivity(location)
+ self.check_is_baserock_system(location)
+
+ # The new system that being deployed as an upgrade must contain
+ # baserock-system-config-sync and system-version-manager. However, the
+ # old system simply needs to have SSH and rsync.
+ self.check_command_exists(location, 'rsync')
+
+ def check_is_baserock_system(self, location):
+ output = cliapp.ssh_runcmd(location, ['sh', '-c',
+ 'test -d /baserock || echo -n dirnotfound'])
+ if output == 'dirnotfound':
+ raise cliapp.AppException('%s is not a baserock system'
+ % location)
+
+ def check_command_exists(self, location, command):
+ test = 'type %s > /dev/null 2>&1 || echo -n cmdnotfound' % command
+ output = cliapp.ssh_runcmd(location, ['sh', '-c', test])
+ if output == 'cmdnotfound':
+ raise cliapp.AppException(
+ "%s does not have %s" % (location, command))
+
+
+SshRsyncCheckExtension().run()