def containerstable(): """ retrieves all containers in table """ config = Kconfig() k = config.k containers = dockerutils.list_containers(k) return render_template('containerstable.html', containers=containers)
def containers(): """ retrieves all containers """ config = Kconfig() k = config.k containers = dockerutils.list_containers(k) return render_template('containers.html', title='Containers', containers=containers, client=config.client)
def list(args): """List hosts, profiles, templates, isos, pools or vms""" hosts = args.hosts profiles = args.profiles templates = args.templates isos = args.isos disks = args.disks pools = args.pools networks = args.networks containers = args.containers images = args.images plans = args.plans filters = args.filters short = args.short global config if config.client == 'all': clis = [] for cli in sorted(config.clients): clientconfig = Kconfig(client=cli) if clientconfig.k is not None: clis.append(clientconfig) else: k = config.k if pools: pools = k.list_pools() if short: poolstable = PrettyTable(["Pool"]) for pool in sorted(pools): poolstable.add_row([pool]) else: poolstable = PrettyTable(["Pool", "Path"]) for pool in sorted(pools): poolpath = k.get_pool_path(pool) poolstable.add_row([pool, poolpath]) poolstable.align["Pool"] = "l" print(poolstable) return if hosts: clientstable = PrettyTable(["Host", "Enabled", "Current"]) clientstable.align["Host"] = "l" for client in sorted(config.clients): enabled = config.ini[client].get('enabled', True) if client == config.client: clientstable.add_row([client, enabled, 'X']) else: clientstable.add_row([client, enabled, '']) print(clientstable) return if networks: networks = k.list_networks() common.pprint("Listing Networks...", color='green') if short: networkstable = PrettyTable(["Network"]) for network in sorted(networks): networkstable.add_row([network]) else: # networkstable = PrettyTable(["Network", "Type", "Cidr", "Dhcp", "Domain", "Mode", "Plan"]) networkstable = PrettyTable( ["Network", "Type", "Cidr", "Dhcp", "Domain", "Mode"]) for network in sorted(networks): networktype = networks[network]['type'] cidr = networks[network]['cidr'] dhcp = networks[network]['dhcp'] mode = networks[network]['mode'] if 'domain' in networks[network]: domain = networks[network]['domain'] else: domain = 'N/A' # if 'plan' in networks[network]: # plan = networks[network]['plan'] # else: # plan = 'N/A' # networkstable.add_row([network, networktype, cidr, dhcp, domain, mode, plan]) networkstable.add_row( [network, networktype, cidr, dhcp, domain, mode]) networkstable.align["Network"] = "l" print(networkstable) return elif profiles: if containers: profiles = config.list_containerprofiles() if short: profilestable = PrettyTable(["Profile"]) for profile in sorted(profiles): profilename = profile[0] profilestable.add_row([profilename]) else: profilestable = PrettyTable( ["Profile", "Image", "Nets", "Ports", "Volumes", "Cmd"]) for profile in sorted(profiles): profilestable.add_row(profile) profilestable.align["Profile"] = "l" print(profilestable) else: profiles = config.list_profiles() if short: profilestable = PrettyTable(["Profile"]) for profile in sorted(profiles): profilename = profile[0] profilestable.add_row([profilename]) else: profilestable = PrettyTable([ "Profile", "Numcpus", "Memory", "Pool", "Disks", "Template", "Nets", "Cloudinit", "Nested", "Reservedns", "Reservehost" ]) for profile in sorted(profiles): profilestable.add_row(profile) profilestable.align["Profile"] = "l" print(profilestable) return elif templates: templatestable = PrettyTable(["Template"]) templatestable.align["Template"] = "l" for template in k.volumes(): templatestable.add_row([template]) print(templatestable) elif isos: isostable = PrettyTable(["Iso"]) isostable.align["Iso"] = "l" for iso in k.volumes(iso=True): isostable.add_row([iso]) print(isostable) elif disks: common.pprint("Listing disks...", color='green') diskstable = PrettyTable(["Name", "Pool", "Path"]) diskstable.align["Name"] = "l" disks = k.list_disks() for disk in sorted(disks): path = disks[disk]['path'] pool = disks[disk]['pool'] diskstable.add_row([disk, pool, path]) print(diskstable) elif containers: common.pprint("Listing containers...", color='green') containers = PrettyTable( ["Name", "Status", "Image", "Plan", "Command", "Ports"]) for container in dockerutils.list_containers(k): if filters: status = container[1] if status == filters: containers.add_row(container) else: containers.add_row(container) print(containers) elif images: common.pprint("Listing images...", color='green') images = PrettyTable(["Name"]) for image in dockerutils.list_images(k): images.add_row([image]) print(images) elif plans: vms = {} plans = PrettyTable(["Name", "Vms"]) for plan in config.list_plans(): planname = plan[0] planvms = plan[1] plans.add_row([planname, planvms]) print(plans) else: if config.client == 'all': vms = PrettyTable([ "Name", "Host", "Status", "Ips", "Source", "Plan", "Profile", "Report" ]) for cli in sorted(clis, key=lambda x: x.client): for vm in sorted(cli.k.list()): vm.insert(1, cli.client) if filters: status = vm[2] if status == filters: vms.add_row(vm) else: vms.add_row(vm) print(vms) return else: vms = PrettyTable([ "Name", "Status", "Ips", "Source", "Plan", "Profile", "Report" ]) for vm in sorted(k.list()): if config.planview and vm[4] != config.currentplan: continue if filters: status = vm[1] if status == filters: vms.add_row(vm) else: vms.add_row(vm) print(vms) return