diff options
author | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2013-05-16 15:14:14 +0000 |
---|---|---|
committer | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2013-05-20 17:31:57 +0100 |
commit | fa71f8b06cbf0199c7bc2aab7090e62a21e3f4b8 (patch) | |
tree | 1be48377be5eb571ddaa7cd9fd44566e335da354 | |
parent | d9be3d12be5d385332445cd1c1b60552afe86e29 (diff) | |
download | morph-fa71f8b06cbf0199c7bc2aab7090e62a21e3f4b8.tar.gz |
Can define version by the environment variable 'VERSION'
If the version already exists on the device, deployment is aborted
-rwxr-xr-x | morphlib/exts/nfsboot.write | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/morphlib/exts/nfsboot.write b/morphlib/exts/nfsboot.write index e2ce7db2..cfc3fc32 100755 --- a/morphlib/exts/nfsboot.write +++ b/morphlib/exts/nfsboot.write @@ -66,14 +66,27 @@ class NFSBootWriteExtension(morphlib.writeexts.WriteExtension): 'with hostname "baserock"') self.test_good_server(location) - version = 'version1' + version = os.environ['VERSION'] or 'version1' versioned_root = os.path.join(self._nfsboot_root, hostname, 'systems', version) + if self.version_exists(versioned_root, location): + raise cliapp.AppException('Version %s already exists on' + ' this device. Deployment aborted' + % version) self.copy_rootfs(temp_root, location, versioned_root, hostname) self.copy_kernel(temp_root, location, versioned_root, version, hostname) self.configure_nfs(location, hostname) + def version_exists(self, versioned_root, location): + try: + cliapp.ssh_runcmd('root@%s' % location, + ['test', '-d', versioned_root]) + except cliapp.AppException: + return False + + return True + def get_hostname(self, temp_root): hostnamepath = os.path.join(temp_root, 'etc', 'hostname') with open(hostnamepath) as f: |