def resource_list(self, up=None): with session_scope() as session: resources = QResources(session) if up: resources = resources.up() else: resources = resources.on() for resource in resources.all(): msg = "{id} - {name} pool={pool} tags={tags} status={status}" tags = ','.join(list(resource.tag_set)) print( msg.format( id=resource.id, name=resource.name, pool=resource.pool, tags=tags, status=resource.state, ))
def foreach_resource(self, args): """ Execute shell command for each resource """ command = args.command with session_scope() as session: resources = QResources(session) for resource in resources.on().all(): try: utf_data = "" if resource.data: utf_data = resource.data.decode("utf8") command = args.command.format( name=resource.name, state=resource.state, data_utf8=utf_data, ) except KeyError as err: sys.stderr.write(str(err)) subprocess.call(command, shell=True)
def resource_list(self, up=None): with session_scope() as session: resources = QResources(session) if up: resources = resources.up() else: resources = resources.on() for resource in resources.all(): msg = ("{id} - {name} pool={pool} tags={tags} status={status} " "releases={releases} ticket={ticket}") tags = ','.join(list(resource.tag_set)) print( msg.format( id=resource.id, name=resource.name, pool=resource.pool, tags=tags, status=resource.state, releases=resource.releases_counter, ticket=resource.ticket.id if resource.ticket else 'NULL', ))