本文整理汇总了Python中rally.cli.cliutils.print_list函数的典型用法代码示例。如果您正苦于以下问题:Python print_list函数的具体用法?Python print_list怎么用?Python print_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: images
def images(self, deployment=None):
"""Display available images.
:param deployment: UUID or name of a deployment
"""
headers = ["UUID", "Name", "Size (B)"]
mixed_case_fields = ["UUID", "Name"]
float_cols = ["Size (B)"]
formatters = dict(zip(float_cols,
[cliutils.pretty_float_formatter(col)
for col in float_cols]))
for endpoint_dict in self._get_endpoints(deployment):
self._print_header("Images", endpoint_dict)
table_rows = []
clients = osclients.Clients(objects.Endpoint(**endpoint_dict))
glance_client = clients.glance()
for image in glance_client.images.list():
data = [image.id, image.name, image.size]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
cliutils.print_list(table_rows,
fields=headers,
formatters=formatters,
mixed_case_fields=mixed_case_fields)
示例2: flavors
def flavors(self, deployment=None):
"""Display available flavors.
:param deployment: UUID or name of a deployment
"""
headers = ["ID", "Name", "vCPUs", "RAM (MB)", "Swap (MB)", "Disk (GB)"]
mixed_case_fields = ["ID", "Name", "vCPUs"]
float_cols = ["RAM (MB)", "Swap (MB)", "Disk (GB)"]
formatters = dict(zip(float_cols,
[cliutils.pretty_float_formatter(col)
for col in float_cols]))
for endpoint_dict in self._get_endpoints(deployment):
self._print_header("Flavors", endpoint_dict)
table_rows = []
clients = osclients.Clients(objects.Endpoint(**endpoint_dict))
nova_client = clients.nova()
for flavor in nova_client.flavors.list():
data = [flavor.id, flavor.name, flavor.vcpus,
flavor.ram, flavor.swap, flavor.disk]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
cliutils.print_list(table_rows,
fields=headers,
formatters=formatters,
mixed_case_fields=mixed_case_fields)
示例3: _print_plugins_list
def _print_plugins_list(plugin_list):
rows = [
utils.Struct(name=f.get_name(), namespace=f.get_namespace(), title=f.get_info()["title"])
for f in plugin_list
]
cliutils.print_list(rows, fields=["name", "namespace", "title"])
示例4: check
def check(self, deployment=None):
"""Check keystone authentication and list all available services.
:param deployment: a UUID or name of the deployment
"""
headers = ["services", "type", "status"]
table_rows = []
try:
deployment = api.Deployment.get(deployment)
except exceptions.DeploymentNotFound:
print(_("Deployment %s is not found.") % deployment)
return(1)
try:
services = api.Deployment.check(deployment)
except keystone_exceptions.ConnectionRefused:
print(_("Unable to connect %s.") % deployment["admin"]["auth_url"])
return(1)
except exceptions.InvalidArgumentsException:
data = ["keystone", "identity", "Error"]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
print(_("Authentication Issues: %s.")
% sys.exc_info()[1])
return(1)
for serv_type, serv in services.items():
data = [serv, serv_type, "Available"]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
print(_("keystone endpoints are valid and following"
" services are available:"))
cliutils.print_list(table_rows, headers)
示例5: show
def show(self, name, namespace=None):
"""Show detailed information about a Rally plugin."""
name_lw = name.lower()
all_plugins = plugin.Plugin.get_all(namespace=namespace)
found = [p for p in all_plugins if name_lw in p.get_name().lower()]
exact_match = [p for p in found if name_lw == p.get_name().lower()]
if not found:
if namespace:
print(
"There is no plugin: %(name)s in %(namespace)s namespace" % {"name": name, "namespace": namespace}
)
else:
print("There is no plugin: %s" % name)
elif len(found) == 1 or exact_match:
plugin_ = found[0] if len(found) == 1 else exact_match[0]
plugin_info = plugin_.get_info()
print(cliutils.make_header(plugin_info["title"]))
print("NAME\n\t%s" % plugin_info["name"])
print("NAMESPACE\n\t%s" % plugin_info["namespace"])
print("MODULE\n\t%s" % plugin_info["module"])
if plugin_info["description"]:
print("DESCRIPTION\n\t", end="")
print(textwrap.fill(plugin_info["description"], subsequent_indent="\t"))
if plugin_info["parameters"]:
print("PARAMETERS")
rows = [utils.Struct(name=p["name"], description="g%s\n" % p["doc"]) for p in plugin_info["parameters"]]
cliutils.print_list(rows, fields=["name", "description"])
else:
print("Multiple plugins found:")
self._print_plugins_list(found)
示例6: check
def check(self, deployment=None):
"""Check keystone authentication and list all available services.
:param deployment: a UUID or name of the deployment
"""
headers = ["services", "type", "status"]
table_rows = []
try:
admin = db.deployment_get(deployment)["admin"]
# TODO(boris-42): make this work for users in future
for endpoint_dict in [admin]:
clients = osclients.Clients(objects.Endpoint(**endpoint_dict))
client = clients.verified_keystone()
print("keystone endpoints are valid and following "
"services are available:")
for service in client.services.list():
data = [service.name, service.type, "Available"]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
except exceptions.InvalidArgumentsException:
data = ["keystone", "identity", "Error"]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
print(_("Authentication Issues: %s.")
% sys.exc_info()[1])
return(1)
cliutils.print_list(table_rows, headers)
示例7: _print_iterations_data
def _print_iterations_data(result):
raw_data = result["data"]["raw"]
headers = ["iteration", "full duration"]
float_cols = ["full duration"]
atomic_actions = []
for row in raw_data:
# find first non-error result to get atomic actions names
if not row["error"] and "atomic_actions" in row:
atomic_actions = row["atomic_actions"].keys()
for row in raw_data:
if row["atomic_actions"]:
for (c, a) in enumerate(atomic_actions, 1):
action = "%(no)i. %(action)s" % {"no": c, "action": a}
headers.append(action)
float_cols.append(action)
break
table_rows = []
formatters = dict(zip(float_cols,
[cliutils.pretty_float_formatter(col, 3)
for col in float_cols]))
for (c, r) in enumerate(raw_data, 1):
dlist = [c]
dlist.append(r["duration"])
if r["atomic_actions"]:
for action in atomic_actions:
dlist.append(r["atomic_actions"].get(action) or 0)
table_rows.append(rutils.Struct(**dict(zip(headers,
dlist))))
cliutils.print_list(table_rows,
fields=headers,
formatters=formatters)
print()
示例8: list
def list(self, api, verifier_id=None, deployment=None, tags=None,
status=None):
"""List all verifications."""
verifications = api.verification.list(verifier_id=verifier_id,
deployment_id=deployment,
tags=tags, status=status)
if verifications:
fields = ["UUID", "Tags", "Verifier name", "Deployment name",
"Started at", "Finished at", "Duration", "Status"]
formatters = {
"Tags": lambda v: ", ".join(v["tags"]) or "-",
"Verifier name": (lambda v: api.verifier.get(
verifier_id=v["verifier_uuid"])["name"]),
"Deployment name": (lambda v: api.deployment.get(
deployment=v["deployment_uuid"])["name"]),
"Started at": lambda v: v["created_at"],
"Finished at": lambda v: v["updated_at"],
"Duration": lambda v: (dt.datetime.strptime(v["updated_at"],
TIME_FORMAT) -
dt.datetime.strptime(v["created_at"],
TIME_FORMAT))
}
cliutils.print_list(verifications, fields, formatters=formatters,
normalize_field_names=True, sortby_index=4)
elif verifier_id or deployment or status or tags:
print("There are no verifications that meet specified criteria.")
else:
print("There are no verifications. You can start verification, "
"using command `rally verify start`.")
示例9: show
def show(self, verification=None, sort_by="name", detailed=False):
"""Display results table of a verification.
:param verification: UUID of a verification
:param sort_by: Sort results by 'name' or 'duration'
:param detailed: Display detailed errors of failed tests
"""
try:
verification = api.Verification.get(verification)
tests = verification.get_results()
except exceptions.NotFoundException as e:
print(six.text_type(e))
return 1
print(_("Total results of verification:\n"))
total_fields = ["UUID", "Deployment UUID", "Set name", "Tests", "Failures", "Created at", "Status"]
cliutils.print_list([verification], fields=total_fields)
print(_("\nTests:\n"))
fields = ["name", "time", "status"]
results = tests["test_cases"]
values = [utils.Struct(**results[test_name]) for test_name in results]
sortby_index = ("name", "duration").index(sort_by)
cliutils.print_list(values, fields, sortby_index=sortby_index)
if detailed:
for test in six.itervalues(tests["test_cases"]):
if test["status"] == "fail":
header = cliutils.make_header(
"FAIL: %(name)s\n" "Time: %(time)s" % {"name": test["name"], "time": test["time"]}
)
formatted_test = "%(header)s%(log)s\n" % {"header": header, "log": test["traceback"]}
print(formatted_test)
示例10: sla_check
def sla_check(self, task_id=None, tojson=False):
"""Display SLA check results table.
:param task_id: Task uuid.
:returns: Number of failed criteria.
"""
results = api.Task.get(task_id).get_results()
failed_criteria = 0
data = []
STATUS_PASS = "PASS"
STATUS_FAIL = "FAIL"
for result in results:
key = result["key"]
for sla in sorted(result["data"]["sla"],
key=lambda x: x["criterion"]):
success = sla.pop("success")
sla["status"] = success and STATUS_PASS or STATUS_FAIL
sla["benchmark"] = key["name"]
sla["pos"] = key["pos"]
failed_criteria += int(not success)
data.append(sla if tojson else rutils.Struct(**sla))
if tojson:
print(json.dumps(data, sort_keys=False))
else:
cliutils.print_list(data, ("benchmark", "pos", "criterion",
"status", "detail"))
return failed_criteria
示例11: list
def list(self, api, deployment=None, all_deployments=False, status=None,
tags=None, uuids_only=False):
"""List tasks, started and finished.
Displayed tasks can be filtered by status or deployment. By
default 'rally task list' will display tasks from the active
deployment without filtering by status.
"""
filters = {}
headers = ["UUID", "Deployment name", "Created at", "Load duration",
"Status", "Tag(s)"]
if status in consts.TaskStatus:
filters["status"] = status
elif status:
print("Error: Invalid task status '%s'.\nAvailable statuses: %s"
% (status, ", ".join(consts.TaskStatus)),
file=sys.stderr)
return(1)
if not all_deployments:
filters["deployment"] = deployment
if tags:
filters["tags"] = tags
task_list = api.task.list(**filters)
if uuids_only:
if task_list:
print("\n".join([t["uuid"] for t in task_list]))
elif task_list:
def tags_formatter(t):
if not t["tags"]:
return ""
return "'%s'" % "', '".join(t["tags"])
formatters = {
"Tag(s)": tags_formatter,
"Load duration": cliutils.pretty_float_formatter(
"task_duration", 3),
"Created at": lambda t: t["created_at"].replace("T", " ")
}
cliutils.print_list(
task_list, fields=headers, normalize_field_names=True,
sortby_index=headers.index("Created at"),
formatters=formatters)
else:
if status:
print("There are no tasks in '%s' status. "
"To run a new task, use:\n\trally task start"
% status)
else:
print("There are no tasks. To run a new task, use:\n"
"\trally task start")
示例12: check
def check(self, api, deployment=None):
"""Check all credentials and list all available services."""
def is_field_there(lst, field):
return bool([item for item in lst if field in item])
def print_error(user_type, error):
print("Error while checking %s credentials:" % user_type)
if logging.is_debug():
print(error["trace"])
else:
print("\t%s: %s" % (error["etype"], error["msg"]))
exit_code = 0
info = api.deployment.check(deployment=deployment)
for platform in info:
for i, credentials in enumerate(info[platform]):
failed = False
n = "" if len(info[platform]) == 1 else " #%s" % (i + 1)
header = "Platform %s%s:" % (platform, n)
print(cliutils.make_header(header))
if "admin_error" in credentials:
print_error("admin", credentials["admin_error"])
failed = True
if "user_error" in credentials:
print_error("users", credentials["user_error"])
failed = True
if not failed:
print("Available services:")
formatters = {
"Service": lambda x: x.get("name"),
"Service Type": lambda x: x.get("type"),
"Status": lambda x: x.get("status", "Available")}
if (is_field_there(credentials["services"], "type") and
is_field_there(credentials["services"], "name")):
headers = ["Service", "Service Type", "Status"]
else:
headers = ["Service", "Status"]
if is_field_there(credentials["services"], "version"):
headers.append("Version")
if is_field_there(credentials["services"], "description"):
headers.append("Description")
cliutils.print_list(credentials["services"], headers,
normalize_field_names=True,
formatters=formatters)
else:
exit_code = 1
print("\n")
return exit_code
示例13: _print_plugins_list
def _print_plugins_list(plugin_list):
formatters = {
"Name": lambda p: p.get_name(),
"Platform": lambda p: p.get_platform(),
"Title": lambda p: p.get_info()["title"],
"Plugin base": lambda p: p._get_base().__name__
}
cliutils.print_list(plugin_list, formatters=formatters,
normalize_field_names=True,
fields=["Plugin base", "Name", "Platform",
"Title"])
示例14: list
def list(self, deployment=None, all_deployments=False, status=None,
uuids_only=False):
"""List tasks, started and finished.
Displayed tasks can be filtered by status or deployment. By
default 'rally task list' will display tasks from the active
deployment without filtering by status.
:param deployment: UUID or name of deployment
:param status: task status to filter by.
Available task statuses are in rally.consts.TaskStatus
:param all_deployments: display tasks from all deployments
:param uuids_only: list task UUIDs only
"""
filters = {}
headers = ["uuid", "deployment_name", "created_at", "duration",
"status", "tag"]
if status in consts.TaskStatus:
filters.setdefault("status", status)
elif status:
print(_("Error: Invalid task status '%s'.\n"
"Available statuses: %s") % (
status, ", ".join(consts.TaskStatus)),
file=sys.stderr)
return(1)
if not all_deployments:
filters.setdefault("deployment", deployment)
task_list = [task.to_dict() for task in api.Task.list(**filters)]
for x in task_list:
x["duration"] = x["updated_at"] - x["created_at"]
if uuids_only:
if task_list:
cliutils.print_list(task_list, ["uuid"],
print_header=False,
print_border=False)
elif task_list:
cliutils.print_list(
task_list,
headers, sortby_index=headers.index("created_at"))
else:
if status:
print(_("There are no tasks in '%s' status. "
"To run a new task, use:\n"
"\trally task start") % status)
else:
print(_("There are no tasks. To run a new task, use:\n"
"\trally task start"))
示例15: _print_tabular_resources
def _print_tabular_resources(resources, table_label):
cliutils.print_list(
objs=[dict(r) for r in resources],
fields=("class", "resource_name", "identifiers"),
field_labels=("service", "resource type", "identifiers"),
table_label=table_label,
formatters={"identifiers":
lambda d: " ".join("%s:%s" % (k, v)
for k, v in d.items()
if k not in ("class", "resource_name"))}
)
print("")