本文整理汇总了Python中snf_django.management.utils.pprint_table函数的典型用法代码示例。如果您正苦于以下问题:Python pprint_table函数的具体用法?Python pprint_table怎么用?Python pprint_table使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pprint_table函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pprint_port_in_ganeti
def pprint_port_in_ganeti(port, stdout=None, title=None):
if stdout is None:
stdout = sys.stdout
if title is None:
title = "State of Port %s in Ganeti" % port.id
vm = port.machine
if vm is None:
stdout.write("Port is not attached to any instance.\n")
return
client = vm.get_client()
try:
vm_info = client.GetInstance(vm.backend_vm_id)
except GanetiApiError as e:
if e.code == 404:
stdout.write("Port seems attached to server %s, but"
" server does not exist in backend.\n"
% vm)
return
raise e
nics = nics_from_instance(vm_info)
try:
gnt_nic = filter(lambda nic: nic.get("name") == port.backend_uuid,
nics)[0]
gnt_nic["instance"] = vm_info["name"]
except IndexError:
stdout.write("Port %s is not attached to instance %s\n" %
(port.id, vm.id))
return
pprint_table(stdout, gnt_nic.items(), None, separator=" | ",
title=title)
vm.put_client(client)
示例2: pprint_volume
def pprint_volume(volume, display_mails=False, stdout=None, title=None):
if stdout is None:
stdout = sys.stdout
if title is None:
title = "State of volume %s in DB" % volume.id
ucache = UserCache(ASTAKOS_AUTH_URL, ASTAKOS_TOKEN)
userid = volume.userid
volume_type = volume.volume_type
volume_dict = OrderedDict([
("id", volume.id),
("size", volume.size),
("disk_template", volume_type.template),
("disk_provider", volume_type.provider),
("server_id", volume.machine_id),
("userid", volume.userid),
("project", volume.project),
("username", ucache.get_name(userid) if display_mails else None),
("index", volume.index),
("name", volume.name),
("state", volume.status),
("delete_on_termination", volume.delete_on_termination),
("deleted", volume.deleted),
("backendjobid", volume.backendjobid),
])
pprint_table(stdout, volume_dict.items(), None, separator=" | ",
title=title)
示例3: handle
def handle(self, *args, **options):
write = self.stderr.write
userid = options['userid']
project = options["project"]
# Get holdings from Cyclades DB
db_holdings = util.get_db_holdings(user=userid, project=project)
db_project_holdings = util.get_db_holdings(project=project,
for_users=False)
# Get holdings from QuotaHolder
try:
qh_holdings = util.get_qh_users_holdings(
[userid] if userid is not None else None,
[project] if project is not None else None)
qh_project_holdings = util.get_qh_project_holdings(
[project] if project is not None else None)
except errors.AstakosClientException as e:
raise CommandError(e)
unsynced_users, users_pending, users_unknown =\
reconcile.check_users(self.stderr, quotas.RESOURCES,
db_holdings, qh_holdings)
unsynced_projects, projects_pending, projects_unknown =\
reconcile.check_projects(self.stderr, quotas.RESOURCES,
db_project_holdings, qh_project_holdings)
pending_exists = users_pending or projects_pending
unknown_exists = users_unknown or projects_unknown
headers = ("Type", "Holder", "Source", "Resource",
"Database", "Quotaholder")
unsynced = unsynced_users + unsynced_projects
if unsynced:
pprint_table(self.stdout, unsynced, headers)
if options["fix"]:
qh = quotas.Quotaholder.get()
force = options["force"]
name = ("client: reconcile-resources-cyclades, time: %s"
% datetime.now())
user_provisions = reconcile.create_user_provisions(
unsynced_users)
project_provisions = reconcile.create_project_provisions(
unsynced_projects)
try:
qh.issue_commission_generic(
user_provisions, project_provisions,
name=name, force=force,
auto_accept=True)
except quotas.errors.QuotaLimit:
write("Reconciling failed because a limit has been "
"reached. Use --force to ignore the check.\n")
return
write("Fixed unsynced resources\n")
if pending_exists:
write("Found pending commissions. Run 'snf-manage"
" reconcile-commissions-cyclades'\n")
elif not (unsynced or unknown_exists):
write("Everything in sync.\n")
示例4: pretty_print_stats
def pretty_print_stats(stats, stdout, cluster_details=True):
newline = lambda: stdout.write("\n")
_datetime = stats.get("datetime")
stdout.write("datetime: %s\n" % _datetime)
newline()
servers = stats.get("servers")
if servers is not None:
pprint_servers(servers, stdout)
newline()
networks = stats.get("networks")
if networks is not None:
pprint_networks(networks, stdout)
newline()
ip_pools = stats.get("ip_pools")
if ip_pools is not None:
pprint_ip_pools(ip_pools, stdout)
newline()
images = stats.get("images")
if images is not None:
pprint_table(stdout, sorted(images.items()), separator=" | ",
title="Statistics for Images")
newline()
clusters = stats.get("clusters")
if clusters is not None:
pprint_clusters(clusters, stdout, detail=cluster_details)
示例5: set_container_quota
def set_container_quota(args):
try:
utils = ManageAccounts()
try:
quota = int(args.quota)
except:
raise ValueError('Invalid quota')
accounts = [args.account] if args.account \
else utils.existing_accounts()
failed = []
def update_container_policy(account):
trans = utils.backend.wrapper.conn.begin()
try:
utils.backend.update_container_policy(
account, account, args.container, {'quota': quota}
)
if args.dry:
print "Skipping database commit."
trans.rollback()
else:
trans.commit()
except Exception, e:
failed.append((account, e))
map(update_container_policy, accounts)
if failed and args.report:
sys.stdout.write(
'Failed for the following accounts:\n'
)
pprint_table(sys.stdout, failed, headers=[])
示例6: pprint_network
def pprint_network(network, display_mails=False, stdout=None, title=None):
if stdout is None:
stdout = sys.stdout
if title is None:
title = "State of Network %s in DB" % network.id
ucache = UserCache(ASTAKOS_AUTH_URL, ASTAKOS_TOKEN)
userid = network.userid
db_network = OrderedDict([
("name", network.name),
("backend-name", network.backend_id),
("state", network.state),
("userid", userid),
("username", ucache.get_name(userid) if display_mails else None),
("public", network.public),
("floating_ip_pool", network.floating_ip_pool),
("external_router", network.external_router),
("drained", network.drained),
("MAC prefix", network.mac_prefix),
("flavor", network.flavor),
("link", network.link),
("mode", network.mode),
("deleted", network.deleted),
("tags", "), ".join(network.backend_tag)),
("action", network.action)])
pprint_table(stdout, db_network.items(), None, separator=" | ",
title=title)
示例7: pprint_floating_ip
def pprint_floating_ip(ip, display_mails=False, stdout=None, title=None):
if stdout is None:
stdout = sys.stdout
if title is None:
title = "Floating IP %s" % ip.id
ucache = UserCache(ASTAKOS_AUTH_URL, ASTAKOS_TOKEN)
userid = ip.userid
vtype_info = OrderedDict([
("id", ip.id),
("address", ip.address),
("network", ip.network_id),
("port", ip.nic_id),
("server", ip.nic.machine_id),
("userid", userid),
("username", ucache.get_name(userid) if (display_mails and userid is
not None) else None),
("project", ip.project),
("shared_to_project", ip.shared_to_project),
("deleted", ip.deleted),
("created", ip.created),
("updated", ip.updated),
])
pprint_table(stdout, vtype_info.items(), separator=" | ", title=title)
示例8: pprint_ippool
def pprint_ippool(subnet, stdout=None, title=None):
"""Pretty print IP Pools of a subnet. Only IPv4 subnets have IP Pools"""
if int(subnet.ipversion) != 4:
return 0
if stdout is None:
stdout = sys.stdout
stdout.write("IP Pools of subnet %s:\n\n" % subnet.id)
for pool in subnet.get_ip_pools():
size = pool.pool_size
available = pool.available.count()
info = OrderedDict([("First_IP", pool.return_start()),
("Last_IP", pool.return_end()),
("Size", size),
("Available", available)])
pprint_table(stdout, info.items(), None, separator=" | ", title=None)
reserved = [pool.index_to_value(index)
for index, ip in enumerate(pool.reserved[:size])
if ip is False]
if reserved != []:
stdout.write("\nExternally Reserved IPs:\n\n")
stdout.write(", ".join(reserved) + "\n")
ip_sum = pool.available[:size] & pool.reserved[:size]
pprint_pool(None, bitarray_to_map(ip_sum), 80, stdout)
stdout.write("\n\n")
示例9: handle
def handle(self, *args, **options):
write = self.stderr.write
fix = options['fix']
check_unexpected = options["include_unexpected_holdings"]
projects = Project.objects.all()
local_proj_quotas, local_user_quotas = \
quotas.astakos_project_quotas(projects)
qh_proj_quotas, qh_user_quotas = \
quotas.get_projects_quota_limits()
unsynced, unexpected = differences(local_proj_quotas, qh_proj_quotas)
unsync_u, unexpect_u = differences(local_user_quotas, qh_user_quotas)
unsynced += unsync_u
unexpected += unexpect_u
headers = ("Holder", "Source", "Resource", "Astakos", "Quotaholder")
if not unsynced and (not check_unexpected or not unexpected):
write("Everything in sync.\n")
return
printable = (unsynced if not check_unexpected
else unsynced + unexpected)
pprint_table(self.stdout, printable, headers, title="Inconsistencies")
if fix:
to_sync = []
for holder, source, resource, value, qh_value in unsynced:
to_sync.append(((holder, source, resource), value))
quotas.qh.set_quota(to_sync)
if check_unexpected:
to_del = []
for holder, source, resource, value, qh_value in unexpected:
to_del.append((holder, source, resource))
quotas.qh.delete_quota(to_del)
示例10: pprint_networks
def pprint_networks(networks, stdout):
values = []
for flavor, stats in sorted(networks.items()):
active = int(stats.get("active", 0))
error = int(stats.get("error", 0))
values.append((flavor, active + error, active, error))
headers = ("Flavor", "Total", "Active", "Error")
pprint_table(stdout, values, headers, separator=" | ",
title="Statistics for Networks")
stdout.write("\n")
示例11: pprint_port_ips
def pprint_port_ips(port, stdout=None, title=None):
if stdout is None:
stdout = sys.stdout
if title is None:
title = "IP Addresses of Port %s" % port.id
ips = list(port.ips.values_list("address", "network_id", "subnet_id",
"subnet__cidr", "floating_ip"))
headers = ["Address", "Network", "Subnet", "CIDR", "is_floating"]
pprint_table(stdout, ips, headers, separator=" | ",
title=title)
示例12: pprint_ip_pools
def pprint_ip_pools(ip_pools, stdout):
values = []
for state, stats in sorted(ip_pools.items()):
count = stats["count"]
free = stats["free"]
total = stats["total"]
values.append((state, count, free, total))
headers = ("State", "Number", "Free IPs", "Total IPs")
pprint_table(stdout, values, headers, separator=" | ",
title="Statistics for Public IPv4 Pools")
stdout.write("\n")
示例13: print_expired
def print_expired(self, projects, execute):
length = len(projects)
if length == 0:
s = "No expired projects.\n"
self.stderr.write(s)
return
labels = ("Project", "Name", "Status", "Expiration date")
utils.pprint_table(self.stdout, projects, labels, self.output_format, title="Expired projects")
if execute:
self.stderr.write("%d projects have been terminated.\n" % (length,))
示例14: pretty_print_stats
def pretty_print_stats(stats, stdout):
newline = lambda: stdout.write("\n")
_datetime = stats.get("datetime")
stdout.write("datetime: %s\n" % _datetime)
newline()
clusters = stats.get("clusters")
if clusters is not None:
fields = ["total", "drained", "offline"]
table = columns_from_fields(fields, clusters)
pprint_table(stdout, table, None,
title="Statistics for Ganeti Clusters")
newline()
servers = stats.get("servers")
if servers is not None:
fields = ["total", "STARTED", "STOPPED", "BUILD", "ERROR", "DESTROYED"]
table = columns_from_fields(fields, servers)
pprint_table(stdout, table, None,
title="Statistics for Virtual Servers")
newline()
networks = stats.get("networks")
if networks is not None:
public_ips = networks.pop("public_ips")
networks["total_public_ips"] = public_ips.get("total", 0)
networks["free_public_ips"] = public_ips.get("free", 0)
fields = ["total", "ACTIVE", "DELETED", "ERROR", "total_public_ips",
"free_public_ips"]
table = columns_from_fields(fields, networks)
pprint_table(stdout, table, None,
title="Statistics for Virtual Networks")
newline()
resources = stats.get("resources")
if resources is not None:
for resource_name, resource in sorted(resources.items()):
fields = ["total", "allocated"]
for res, num in sorted(resource.pop("servers", {}).items()):
name = "servers_with_%s" % res
resource[name] = num
fields.append(name)
table = columns_from_fields(fields, resource)
pprint_table(stdout, table, None,
title="Statistics for %s" % resource_name)
newline()
images = stats.get("images")
if images is not None:
pprint_table(stdout, sorted(images.items()), None,
title="Statistics for Images")
newline()
示例15: pprint_network_backends
def pprint_network_backends(network, stdout=None, title=None):
if stdout is None:
stdout = sys.stdout
if title is None:
title = "State of Network %s in DB for each backend" % network.id
bnets = list(network.backend_networks.values_list(
"backend__clustername",
"operstate", "deleted", "backendjobid",
"backendopcode", "backendjobstatus"))
headers = ["Backend", "State", "Deleted", "JobID", "Opcode",
"JobStatus"]
pprint_table(stdout, bnets, headers, separator=" | ",
title=title)