def sync_sirikata(*args, **kwargs): """ec2 sync sirikata /path/to/installed/sirikata [--puppet-path=/etc/puppet] [--notify-puppets=cluster_name_or_config] Package a version of Sirikata installed in the given path and set it up with Puppet for distribution to puppet agent nodes. If you already have puppets running, add --notify-puppets=cluster_name to trigger a puppet update (runs the equivalent of sirikata-cluster.py puppet slaves restart cluster_name) """ installed_path = arguments.parse_or_die(sync_sirikata, [str], *args) puppet_base_path = config.kwarg_or_get('puppet-path', kwargs, 'PUPPET_PATH', default='/etc/puppet') notify_puppets = config.kwarg_or_default('notify-puppets', kwargs) # Note pemfile is different from other places since it's only required with notify-puppets. pemfile = config.kwarg_or_get('pem', kwargs, 'SIRIKATA_CLUSTER_PEMFILE', default=None) # Generate the archive if given a directory) gen_file = installed_path if os.path.isdir(installed_path): retcode = util_sirikata.package(installed_path) if retcode != 0: return retcode gen_file = os.path.join(installed_path, 'sirikata.tar.bz2') # Make sure we have a place to put the file dest_dir = os.path.join(puppet_base_path, 'modules', 'sirikata', 'files', 'home', 'ubuntu') if not os.path.exists(dest_dir): # Need root for this, so we have to do it through subprocess subprocess.call(['sudo', 'mkdir', '-p', dest_dir]) # And copy it into place print "Copying archive into puppet" dest_file = os.path.join(dest_dir, 'sirikata.tar.bz2') subprocess.call(['sudo', 'cp', gen_file, dest_file]) if notify_puppets: print "Notifying puppets" slaves_restart_kwargs = {} if pemfile is not None: slaves_restart_kwargs['pem'] = pemfile # notify_puppets == cluster name # Nuke old tar.bz2's so new ones will be downloaded nodes.ssh(notify_puppets, 'rm', '-f', 'sirikata.tar.bz2', **slaves_restart_kwargs) puppet.slaves_restart(notify_puppets, **slaves_restart_kwargs)
def sync_sirikata(*args, **kwargs): """adhoc sync sirikata cluster_name_or_config /path/to/installed/sirikata/or/tbz2 Synchronize Sirikata binaries by copying the specified data to this cluster's nodes. """ name_or_config, path = arguments.parse_or_die(sync_sirikata, [object, str], *args) name, cc = name_and_config(name_or_config) # If they specify a directory, package it and replace the path with the package if os.path.isdir(path): retcode = util_sirikata.package(path) if retcode != 0: return retcode path = os.path.join(path, 'sirikata.tar.bz2') sirikata_archive_name = os.path.basename(path) node_archive_path = [os.path.join(cc.workspace_path(node), sirikata_archive_name) for node in cc.nodes] for inst_idx in range(len(cc.nodes)): print "Copying data to node %d" % (inst_idx) cmd = ['rsync', '--progress', path, cc.node_ssh_address(cc.get_node(inst_idx)) + ":" + node_archive_path[inst_idx]] retcode = subprocess.call(cmd) if retcode != 0: print "Failed to rsync from first node to node %d" % (inst_idx) print "Command was:", cmd return retcode for inst_idx,node in enumerate(cc.nodes): print "Extracting data on node %d" % (inst_idx) retcode = node_ssh(cc, inst_idx, 'cd', cc.sirikata_path(node=node), '&&', 'tar', '-xf', node_archive_path[inst_idx]) if retcode != 0: print "Failed to extract archive on node %d" % (inst_idx) return retcode return 0