On Fri, Apr 05, 2013 at 10:57:30AM +0100, Jonathan Maw wrote:
+ '''Create an NFS root and kernel on TFTP during Morph's deployment.
+ The location command line argument is the hostname of the nfsboot server.
+ The user is expected to provide the location argument
+ using the following syntax:
+ * HOST is the host of the nfsboot server
+ The extension will connect to HOST via ssh to copy the kernel and rootfs,
+ and configure the nfs server.
This could mention that the extension connects to root@HOST, and explain why
it needs to have root privs.
+ def get_hostname(self, temp_root):
+ hostnamepath = os.path.join(temp_root, 'etc', 'hostname')
+ with open(hostnamepath) as f:
+ return f.read().strip()
This should probably read only the first line, just in case someone's
gone and shoved more than one line in there.
+ if os.path.exists(os.path.join(bootdir,
+ kernel_src = os.path.join(bootdir, 'vmlinuz')
+ elif os.path.exists(os.path.join(bootdir, 'zImage')):
+ kernel_src = os.path.join(bootdir, 'zImage')
+ elif os.path.exists(os.path.join(bootdir, 'uImage')):
+ kernel_src = os.path.join(bootdir, 'uImage')
+ raise cliapp.AppException('Could not find a kernel in '
+ 'the given system')
I would do this as a data structure and loop, to reduce code
duplication and make it easier to add new ones. Something like:
image_names = ['vmlinuz', 'zImage', 'uImage']
for name in image_names:
fqpn = os.path.join(bootdir, name)
kernel_src = fqpn
'Could not find a kernel in the system: none of '
'%s found' % ', '.join(image_names))
+ kernel_dest = os.path.join('/srv',
'nfsboot', 'tftp', hostname)
Nitpick: join('/', 'srv', ...) would be cleaner, in my opinion.
Or just join('/srv/nfsboot/tftp', hostname) would work too.
+ rsync_dest = 'root@%s:%s' %(location, rootfs_dest)
Add space between % and ( please.
+ ['rsync', '-a', rootfs_src, rsync_dest])
Those look like they could fit on the same line. There's other cases of
that as well.
+ # If that path is not already exported:
+ return_data = cliapp.runcmd_unchecked(['ssh', location,
+ 'grep -q "%s" %s' % (rootfs_dest, exports_path)])
You probably should use cliapp.ssh_runcmd, which escapes the arguments
correctly so they get across ssh properly. It doesn't have a corresponding
ssh_runcmd_unchecked, though, so you'll need to check for the exception
raised by runcmd.
Ditto for other cases where you invoke ssh via runcmd.
http://www.codethink.co.uk/ http://wiki.baserock.org/ http://www.baserock.com/