def run(self, config, args): envy = cloudenvy.envy.Envy(config) if not envy.server(): logging.info('Triggering Envy boot.') try: envy.build_server() except exceptions.ImageNotFound: logging.error('Could not find image.') return except exceptions.NoIPsAvailable: logging.error('Could not find available IP.') return if not args.no_files: self.commands['files'].run(config, args) if not args.no_provision \ and (envy.project_config.get("auto_provision", True) and 'provision_scripts' in envy.project_config): try: self.commands['provision'].run(config, args) except SystemExit: raise SystemExit('You have not specified any provision ' 'scripts in your Envyfile. ' 'If you would like to run your Envy ' 'without a provision script; use the ' '`--no-provision` command line flag.') if envy.ip(): print envy.ip() else: logging.error('Could not determine IP.')
def run(self, config, args): envy = cloudenvy.envy.Envy(config) if envy.ip(): host_string = '%s@%s' % (envy.remote_user, envy.ip()) temp_tar = tempfile.NamedTemporaryFile(delete=True) with fabric.api.settings(host_string=host_string): if args.files: dotfiles = args.files.split(',') else: dotfiles = config['defaults']['dotfiles'].split(',') dotfiles = [dotfile.strip() for dotfile in dotfiles] with tarfile.open(temp_tar.name, 'w') as archive: for dotfile in dotfiles: path = os.path.expanduser('~/%s' % dotfile) if os.path.exists(path): if not os.path.islink(path): archive.add(path, arcname=dotfile) fabric.operations.put(temp_tar, '~/dotfiles.tar') fabric.operations.run('tar -xvf ~/dotfiles.tar') else: logging.error('Could not determine IP.')
def run(self, config, args): envy = cloudenvy.envy.Envy(config) if envy.ip(): host_string = '%s@%s' % (envy.remote_user, envy.ip()) with fabric.api.settings(host_string=host_string): use_sudo = envy.project_config.get('files_use_sudo', True) files = envy.project_config.get('files', {}).items() files = [(os.path.expanduser(loc), rem) for loc, rem in files] for local_path, remote_path in files: logging.info("Copying file from '%s' to '%s'", local_path, remote_path) if not os.path.exists(local_path): logging.error("Local file '%s' not found.", local_path) dest_dir = _parse_directory(remote_path) if dest_dir: self._create_directory(dest_dir) self._put_file(local_path, remote_path, use_sudo) else: logging.error('Could not determine IP.')
def run(self, config, args): envy = cloudenvy.envy.Envy(config) if envy.ip(): host_string = '%s@%s' % (envy.remote_user, envy.ip()) with fabric.api.settings(host_string=host_string): fabric.operations.run(args.command) else: logging.error('Could not determine IP.')
def run(self, config, args): envy = cloudenvy.envy.Envy(config) if not envy.server(): logging.error('Envy is not running.') elif envy.ip(): print envy.ip() else: logging.error('Could not determine IP.')
def run(self, config, args): envy = cloudenvy.envy.Envy(config) if envy.ip(): host_string = '%s@%s' % (envy.remote_user, envy.ip()) with fabric.api.settings(host_string=host_string): fabric.operations.put(args.source, args.target, mirror_local_mode=True) else: logging.error('Could not determine IP.')
def run(self, config, args): envy = cloudenvy.envy.Envy(config) if envy.ip(): disable_known_hosts = ('-o UserKnownHostsFile=/dev/null' ' -o StrictHostKeyChecking=no') forward_agent = '-o ForwardAgent=yes' options = [disable_known_hosts] if envy.forward_agent: options.append(forward_agent) fabric.operations.local('ssh %s %s@%s' % (' '.join(options), envy.remote_user, envy.ip())) else: logging.error('Could not determine IP.')
def run(self, config, args): envy = cloudenvy.envy.Envy(config) logging.info('Running provision scripts for Envy \'%s\'.' % envy.project_config['name']) if not envy.ip(): logging.error('Could not determine IP.') return with fabric.api.settings( host_string=envy.ip(), user=envy.remote_user, forward_agent=True, disable_known_hosts=True): if args.scripts: scripts = [os.path.expanduser(script) for script in args.scripts] elif 'provision_scripts' in envy.project_config: scripts = [os.path.expanduser(script) for script in envy.project_config['provision_scripts']] elif 'provision_script_path' in envy.project_config: provision_script = envy.project_config['provision_script_path'] scripts = [os.path.expanduser(provision_script)] else: raise SystemExit('Please specify the path to your provision ' 'script(s) by either using the `--scripts` ' 'flag, or by defining the `provision_scripts`' ' config option in your Envyfile.') for script in scripts: logging.info('Running provision script from \'%s\'', script) for i in range(24): try: path = script filename = os.path.basename(script) remote_path = '~/%s' % filename fabric.operations.put(path, remote_path, mode=0755) fabric.operations.run(remote_path) break except fabric.exceptions.NetworkError: logging.debug( 'Unable to upload the provision script ' 'from `%s`. Trying again in 10 seconds.' % path ) time.sleep(10) logging.info('Provision script \'%s\' finished.' % path)
def run(self, config, args): envy = cloudenvy.envy.Envy(config) if envy.ip(): host_string = '%s@%s' % (envy.remote_user, envy.ip()) with fabric.api.settings(host_string=host_string): file_list = [(os.path.expanduser(filename), location) for filename, location in envy.project_config.get('files', {}).iteritems()] for filename, endlocation in file_list: logging.info("Putting file from '%s' to '%s'", filename, endlocation) if os.path.exists(filename): self._put_file(filename, endlocation) else: logging.warning("File '%s' not found.", filename) else: logging.error('Could not determine IP.')