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 | 7e0decbb40fcb779f8e4c4b0fd3718022f3cdd88 (patch) | |
tree | b172d488c274ea7f00223d05ad228c35c6e7cb92 | |
parent | bfcf3a24c78de00293c3ca59dabf8d3c31711fd8 (diff) | |
download | definitions-7e0decbb40fcb779f8e4c4b0fd3718022f3cdd88.tar.gz |
Can define version by the environment variable 'VERSION'
If the version already exists on the device, deployment is aborted
-rwxr-xr-x | nfsboot.write | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/nfsboot.write b/nfsboot.write index e2ce7db2..cfc3fc32 100755 --- a/nfsboot.write +++ b/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: |