def bundle(rootfs, region, bucket=None, size=10, filesystem='ext4'): _get_amitools_path() pems = _get_pem_paths() log.info('creating loopback, formatting and mounting') image_path = rootfs + '.img' image_mount = rootfs + '.img.mount' utils.mkdir(image_mount) executil.system('dd if=/dev/null of=%s bs=1 seek=%dG' % (image_path, size)) executil.system('mkfs.' + filesystem, '-F', '-j', image_path) executil.system('mount -o loop', image_path, image_mount) log.info('syncing rootfs to loopback') utils.rsync(rootfs, image_mount) log.debug('umounting loopback') executil.system('umount', '-d', image_mount) os.removedirs(image_mount) log.debug('getting unique ami name') app = utils.get_turnkey_version(rootfs) ami_name = utils.get_uniquename(region, app + '.s3') log.info('target ami_name - %s ', ami_name) log.info('bundling loopback into ami') arch = utils.parse_imagename(ami_name)['architecture'] _bundle_image(region, image_path, ami_name, arch, pems) os.remove(image_path) log.info('uploading bundled ami') bucket = bucket if bucket else "turnkeylinux-" + region _bundle_upload(region, ami_name, bucket) log.info("complete - %s %s", bucket, ami_name) return bucket, ami_name
def bundle(rootfs, size=10, filesystem='ext4'): log.debug('getting unique snapshot name') app = utils.get_turnkey_version(rootfs) snapshot_name = utils.get_uniquename(utils.get_region(), app + '.ebs') log.info('target snapshot - %s ', snapshot_name) log.info('creating volume, attaching, formatting and mounting') volume = Volume() volume.create(size) device = Device() volume.attach(utils.get_instanceid(), device) device.mkfs(filesystem) mount_path = rootfs + '.mount' device.mount(mount_path) log.info('syncing rootfs to volume') utils.rsync(rootfs, mount_path) device.umount() volume.detach() os.removedirs(mount_path) log.info('creating snapshot from volume') snapshot = Snapshot() snapshot.create(volume.vol.id, snapshot_name) volume.delete() log.info("complete - %s %s", snapshot.snap.id, snapshot.snap.description) return snapshot.snap.id, snapshot.snap.description
def bundle(rootfs, snapshot_name, size=10, filesystem='ext4'): log.info('target snapshot - %s ', snapshot_name) log.info('creating volume, attaching, formatting and mounting') volume = Volume() volume.create(size) device = Device() volume.attach(utils.get_instanceid(), device) log.info('creating partitions') device.mkpart() device.mkfs(filesystem) mount_path = rootfs + '.mount' device.mount(mount_path) log.info('syncing rootfs to partition') utils.rsync(rootfs, mount_path) log.info('installing GRUB on volume') submounts = ['/sys', '/proc', '/dev'] for s in submounts: executil.system('mount', '--bind', '--make-rslave', s, mount_path + s) executil.system('chroot', mount_path, 'grub-install', device.root_path) executil.system('chroot', mount_path, 'update-grub') executil.system('chroot', mount_path, 'update-initramfs', '-u') submounts.reverse() for s in submounts: executil.system('umount', '-l', mount_path + s) device.umount() volume.detach() os.removedirs(mount_path) log.info('creating snapshot from volume') snapshot = Snapshot() snapshot.create(volume.vol.id, snapshot_name) volume._wait("available") volume.delete() log.info("complete - %s %s", snapshot.snap.id, snapshot.snap.description) return snapshot.snap.id, snapshot.snap.description
import os import utils BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) if __name__ == '__main__': user_name = 'ubuntu' host_name = 'ec2-52-35-185-162.us-west-2.compute.amazonaws.com' source_dir = BASE_DIR target_parent_dir = '/home/ubuntu' utils.collectStatic() utils.rsync(user_name, host_name, source_dir, target_parent_dir, ignore=['db.sqllite3', '.git', '.gitignore']) utils.remoteApache2(user_name, host_name, 'restart')
from utils import lock_instance, is_valid_interval, send_email, list_files_with_size, rsync, is_changed from configs import SERVER_NAME, SERVER_PATH, LOCAL_PATH with lock_instance(): is_valid_interval() rsync( '{}:{}'.format(SERVER_NAME, SERVER_PATH), LOCAL_PATH ) files = list_files_with_size(LOCAL_PATH) msg = '' for file in files: msg += '\n{}. {} -> {}'.format(*file) if is_changed(msg): send_email( '*****@*****.**', 'Sync home with server', 'Downloaded list: \n{}'.format(msg) ) else: print('there is no change!')