def _status(self, results=None, final=False): if not final: new = ( green(len(self._completed)), white(len(self._running)), yellow(len(self._queued)), green('finished'), white('running'), yellow('queued'), ) if hasattr(self, 'last_status') and new == self.last_status: return self.last_status = ( green(len(self._completed)), white(len(self._running)), yellow(len(self._queued)), green('finished'), white('running'), yellow('queued'), ) print(WIPE, "[%s/%s/%s] %s, %s, %s" % new) else: print("\n[ %s OK / %s ERROR ] in %s seconds" % ( green(self._num_of_jobs - self._errors, True), red(self._errors), time.time() - self._time_start, )) if self._errors: print(red("Failures:", True)) for job in self._completed: if (job.exitcode != 0 or isinstance( results[job.name]['results'], Exception)): print(red(job.name)) sys.stdout.flush()
def clean_glance(auth_url, tenant_name, username, password, sure='no'): """Clean old images from Glance :param str auth_url: URL for Keystone that is managing auth for Glance :param str tenant_name: OpenStack tenant to authenticate as :param str username: OpenStack user to authenticate as :param str password: OpenStack password to authenticate as :param str sure: 'yes' to not propmt for confirmation before update """ glance = remote_images.Glance( auth_url=auth_url, tenant_name=tenant_name, username=username, password=password, ) glance_up_to_date = remote_images.top_latest(glance) obsolete = sorted(set(glance) - set(glance_up_to_date)) if not obsolete: return puts(yellow("Going to remove {n} images to glance:\n{images}".format( n=len(obsolete), images='\n'.join(' - ' + img.name for img in obsolete) ))) if sure != 'yes' and prompt("Continue (yes|no)? ", default='no') != 'yes': return for img in obsolete: puts(green("Removing: {}".format(img.name))) glance.remove(img)
def update_glance(auth_url, tenant_name, username, password, sure='no'): """Update Glance with new upstream images :param str auth_url: URL for Keystone that is managing auth for Glance :param str tenant_name: OpenStack tenant to authenticate as :param str username: OpenStack user to authenticate as :param str password: OpenStack password to authenticate as :param str sure: 'yes' to not propmt for confirmation before update """ glance = remote_images.Glance( auth_url=auth_url, tenant_name=tenant_name, username=username, password=password, ) missing_images = sorted( set(remote_images.from_all_latest_upstream()) - set(glance) ) if not missing_images: return puts(yellow("Going to upload {n} images to glance:\n{images}".format( n=len(missing_images), images='\n'.join(' - ' + img.name for img in missing_images) ))) if sure != 'yes' and prompt("Continue (yes|no)? ", default='no') != 'yes': return for img in missing_images: puts(green("Uploading: {}".format(img.name))) glance.add(img)
def search(firstcond='', sure='no', foreman=None, user=None, passwd=None, *conds, **kwconds): """ Use the given foreman search result as the hosts list. :param sure: If set to `yes`, it will not ask for confirmation before running. :param foreman: The foreman server url, like 'http://localhost:3000' :param user: Username to use when logging into foreman, default None (do not authenticate) :param password: Password to use when logging into foreman You can specify multiple condition like strings or parameters, that means that passing *fab on.foreman:'name=cinteg'* as a not named parameter or setting *fab on.foreman:name=cinteg* are the same. Any foreman searchstr string can be used. All the conditions will be agreggated with 'or'. """ conds = list(conds) if sure not in ('yes', 'no'): conds.append(sure) if firstcond: conds.append(firstcond) searchstr = ' or '.join(conds) searchstr += ' or '.join('%s=%s' % item for item in kwconds.iteritems()) if user: auth = (user, passwd) else: auth = None frm = frm_cli.Foreman(foreman, auth, api_version=2) for host in frm.index_hosts(search=searchstr, per_page=999).get('results'): env.hosts.append(host['name']) print(yellow("Query used: \n\t\"%s\"" % searchstr)) print( yellow("Got %d hosts: \n\t" % len(env.hosts) + '\n\t'.join(env.hosts))) if sure != 'yes' and not env.parallel: if prompt('Is what you expected? y|n', default='y').lower() == 'n': abort('Ended by user request.')
def search(firstcond="", sure="no", foreman=None, user=None, passwd=None, *conds, **kwconds): """ Use the given foreman search result as the hosts list. :param sure: If set to `yes`, it will not ask for confirmation before running. :param foreman: The foreman server url, like 'http://localhost:3000' :param user: Username to use when logging into foreman, default None (do not authenticate) :param password: Password to use when logging into foreman You can specify multiple condition like strings or parameters, that means that passing *fab on.foreman:'name=cinteg'* as a not named parameter or setting *fab on.foreman:name=cinteg* are the same. Any foreman searchstr string can be used. All the conditions will be agreggated with 'or'. """ conds = list(conds) if sure not in ("yes", "no"): conds.append(sure) if firstcond: conds.append(firstcond) searchstr = " or ".join(conds) searchstr += " or ".join("%s=%s" % item for item in kwconds.iteritems()) if user: auth = (user, passwd) else: auth = None frm = frm_cli.Foreman(foreman, auth, api_version=2) for host in frm.index_hosts(search=searchstr, per_page=999).get("results"): env.hosts.append(host["name"]) print(yellow('Query used: \n\t"%s"' % searchstr)) print(yellow("Got %d hosts: \n\t" % len(env.hosts) + "\n\t".join(env.hosts))) if sure != "yes" and not env.parallel: if prompt("Is what you expected? y|n", default="y").lower() == "n": abort("Ended by user request.")
def _status(self, results=None, final=False): if not final: new = ( green(len(self._completed)), white(len(self._running)), yellow(len(self._queued)), green('finished'), white('running'), yellow('queued'), ) if hasattr(self, 'last_status') and new == self.last_status: return self.last_status = ( green(len(self._completed)), white(len(self._running)), yellow(len(self._queued)), green('finished'), white('running'), yellow('queued'), ) print(WIPE, "[%s/%s/%s] %s, %s, %s" % new) else: print("\n[ %s OK / %s ERROR ] in %s seconds" % ( green(self._num_of_jobs - self._errors, True), red(self._errors), time.time() - self._time_start, )) if self._errors: print(red("Failures:", True)) for job in self._completed: if ( job.exitcode != 0 or isinstance(results[job.name]['results'], Exception) ): print(red(job.name)) sys.stdout.flush()