def main(name, region): qr = QuickRun() # Setup qr.formatter = formatters.fake_shell qr.commands = [ Command(name="List dir", cmd="sudo ls -ld /var/log/tomcat*"), ] qr.servers = Server.from_list( find_instances({'tag:Name': name}, contains=True, region=region)) qr.main() qr.display()
def main(name, region): qr = QuickRun() # Setup qr.formatter = formatters.table qr.commands = [ Command(name="Get openssl version", cmd="openssl version"), ] qr.servers = Server.from_list(find_instances({ 'tag:Name': name }, contains=True, region=region)) qr.main() qr.display()
def __init__(self, name, region="eu-west-2"): super().__init__() # Define our commands self.commands = [ Command( name="Get free memory", cmd="free -h | head -2 | tail -1 | awk '{ print $2 }'", ), Command(name="Get heap size", cmd="grep --color=none -i xmx /etc/default/tomcat"), ] # Define our servers self.servers = Server.from_list( find_instances({'tag:Name': name}, contains=True, region=region))
def main(name, region): qr = QuickRun() # Setup qr.formatter = formatters.fake_shell qr.commands = [ Command(name="List files", cmd="ls -ltr"), ] qr.servers = Server.from_list(find_instances({ 'tag:Name': name }, region=region)) if not challenge(expect=len(qr.servers), msg=f'Running against {len(qr.servers)} servers'): print('Challenge failed') sys.exit(1) qr.main() qr.display()
def main(name, tag, region, sort, json): # Search search = {f'tag:{k}': v for k, v in dict(tag).items()} if name: search['tag:Name'] = name servers = find_instances(search, contains=True, region=region) # JSON mode if json: print(pyjson.dumps(servers, indent=2)) sys.exit(0) # Table mode table = RichTable(title=f'Instances ({region})') fields = ['Name', 'PrivateIp', 'PublicIp', 'InstanceId'] for header in fields: table.add_column(header) for server in sorted(servers, key=lambda k: k[sort]): table.add_row(*[server.get(f) for f in fields]) RichConsole().print(table)