本文整理汇总了Python中cloudmesh_client.common.Printer.Printer.write方法的典型用法代码示例。如果您正苦于以下问题:Python Printer.write方法的具体用法?Python Printer.write怎么用?Python Printer.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudmesh_client.common.Printer.Printer
的用法示例。
在下文中一共展示了Printer.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def get(cls, **kwargs):
"""
This method queries the database to fetch group(s)
with given name filtered by cloud.
:param name:
:param cloud:
:return:
"""
query = dict(kwargs)
if 'output' in kwargs:
for key, value in kwargs.items():
if value is None:
query[key] = "None"
del query['output']
try:
print("QQQ"), query
group = cls.cm.find(kind="group", **query)
print("gggg", group)
if group is not None \
and "output" in kwargs:
d = {"0": group}
group = Printer.write(d)
return group
except Exception as ex:
Console.error(ex.message)
示例2: list
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def list(cls, cloud=None, names=None, output='table', live=False):
try:
if live:
cls.refresh(cloud)
elements = cls.cm.find(kind="vm", category=cloud)
result = []
if "all" in names:
for element in elements:
result.append(element)
elif names is not None:
for element in elements:
if element["name"] in names:
result.append(element)
(order, header) = CloudProvider(cloud).get_attributes("ip")
return Printer.write(result,
order=order,
header=header,
output=output)
except Exception as ex:
Console.error(ex.message)
示例3: list
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def list(cls, name, live=False, format="table"):
"""
This method lists all workflows of the cloud
:param cloud: the cloud name
"""
# Console.TODO("this method is not yet implemented")
# return
try:
elements = cls.cm.find(kind="workflow", category='general')
# pprint(elements)
# (order, header) = CloudProvider(cloud).get_attributes("workflow")
order = None
header= None
# Console.msg(elements)
return Printer.write(elements,
order=order,
header=header,
output=format)
except Exception as ex:
Console.error(ex.message)
示例4: get_info
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def get_info(cls, category="general", name=None, output="table"):
"""
Method to get info about a group
:param cloud:
:param name:
:param output:
:return:
"""
try:
cloud = category or Default.cloud
args = {
"category": category
}
if name is not None:
args["name"] = name
group = cls.cm.find(kind="group", output="dict", **args)
return Printer.write(group,
order=cls.order,
output=output)
except Exception as ex:
Console.error(ex.message)
示例5: dict_choice
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def dict_choice(d):
if d is None:
return None
elements = dict(d)
i = 1
for e in d:
elements[e]["id"] = i
i += 1
# pprint(d)
if elements != {}:
# noinspection PyPep8
print(Printer.write(elements,
order=["id",
"name",
"comment",
"uri",
"fingerprint",
"source"],
output="table",
sort_keys=True))
else:
print("ERROR: No keys in the database")
return
n = num_choice(i - 1, tries=10) + 1
element = None
for e in elements:
if str(elements[e]["id"]) is str(n):
element = elements[e]
break
return element
示例6: list_unused_floating_ip
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def list_unused_floating_ip(cls, cloudname, output='table'):
"""
Method to list unused floating ips
These floating ips are not associated with any instance
:param cloudname:
:return: floating ip list
"""
try:
# fetch unused floating ips
floating_ips = cls.get_unused_floating_ip_list(cloudname)
# print the output
return Printer.write(floating_ips,
order=[
"ip",
"pool",
"id",
"cloud"
],
header=[
"floating_ip",
"floating_ip_pool",
"floating_ip_id",
"cloud"
],
output=output)
except Exception as ex:
Console.error(ex.message)
return
示例7: list
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def list(self, format='dict', sort_keys=True, order=None):
if order is None:
order = self.order
return Printer.write(self.data,
order=order,
output=format,
sort_keys=sort_keys)
示例8: details
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def details(self, kind, category, id, format="table"):
from cloudmesh_client.db.CloudmeshDatabase import CloudmeshDatabase
cm = CloudmeshDatabase()
try:
if kind not in self.kind:
raise ValueError('{} not defined'.format(kind))
elements = None
for idkey in ["cm_id", "name", "uuid", "id", "cm_id"]:
s = {idkey: id}
try:
elements = cm.find(kind=kind, category=category, **s)
except:
pass
if elements is not None:
break
if elements is None:
return None
if len(elements) > 0:
element = elements[0]
if format == "table":
return Printer.attribute(element)
else:
return Printer.write(element,
output=format)
else:
return None
except Exception as ex:
Console.error(ex.message)
示例9: list
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def list(cls,
order=None,
header=None,
output='table'):
"""
lists the default values in the specified format.
TODO: This method has a bug as it uses format and output,
only one should be used.
:param category: the category of the default value. If general is used
it is a special category that is used for global values.
:param format: json, table, yaml, dict, csv
:param order: The order in which the attributes are returned
:param output: The output format.
:return:
"""
if order is None:
order, header = None, None
# order, header = Attributes(cls.__kind__, provider=cls.__provider__)
try:
result = cls.cm.all(provider=cls.__provider__, kind=cls.__kind__)
return (Printer.write(result,
order=order,
output=output))
except Exception as e:
Console.error("Error creating list", traceflag=False)
Console.error(e.message)
return None
示例10: list
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def list(cls, category=None, live=False, output="table"):
"this does not work only returns all ceys in the db"
(order, header) = CloudProvider(category).get_attributes("key")
d = cls.cm.find(kind="key", scope="all", output=output)
return Printer.write(d,
order=order,
header=header,
output=output)
示例11: list
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def list(cls, cloud, start=None, end=None, tenant=None, format="table"):
# set the environment variables
set_os_environ(cloud)
try:
# execute the command
args = ["usage"]
if start is not None:
args.extend(["--start", start])
if end is not None:
args.extend(["--end", end])
if tenant is not None:
args.extend(["--tenant", tenant])
result = Shell.execute("nova", args)
result = Nova.remove_subjectAltName_warning(result)
lines = result.splitlines()
dates = lines[0]
# TODO: as stated below, nova returns additional lines,
# on my pc, SecurityWarning is returned, so filtering..
for l in lines[1:]:
if l.__contains__("SecurityWarning"):
lines.remove(l)
table = '\n'.join(lines[1:])
dates = dates.replace("Usage from ", "").replace("to", "").replace(" +", " ")[:-1].split()
#
# TODO: for some reason the nova command has returned not the
# first + char, so we could not ignore the line we may set - as
# additional comment char, but that did not work
#
d = TableParser.convert(table, comment_chars="+#")
# d["0"]["start"] = "start"
# d["0"]["end"] = "end"
d["0"]["start"] = dates[0]
d["0"]["end"] = dates[1]
# del d['0']
return Printer.write(d,
order=["start",
"end",
"servers",
"cpu hours",
"ram mb-hours",
"disk gb-hours"],
output=format)
except Exception as e:
return e
示例12: details
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def details(cls, cloud, id, live=False, format="table"):
elements = cls.cm.find(kind="workflow", category='general' ,cm_id =id)
Console.msg(elements)
order = None
header= None
# Console.TODO("this method is not yet implemented")
return Printer.write(elements,
order=order,
header=header,
output=format)
示例13: _LIST_PRINT
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def _LIST_PRINT(l, output, order=None):
if output in ["yaml", "dict", "json"]:
l = _convert(l)
result = Printer.write(l,
order=order,
output=output)
if output in ["table", "yaml", "json", "csv"]:
print(result)
else:
pprint(result)
示例14: list
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def list(cls, name=None, output='table'):
# ignore names for now
try:
elements = cls.cm.find(kind="launcher", category='general', scope="all", output="dict")
order = None
header = None
return Printer.write(elements,
order=order,
header=header,
output=output)
except Exception as ex:
Console.error(ex.message)
return ""
示例15: _print_dict
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import write [as 别名]
def _print_dict(d, header=None, format='table'):
msg = Printer.write(d,
order=["name",
"comment",
"uri",
"fingerprint",
"source"],
output=format,
sort_keys=True)
if msg is None:
Console.error("No keys found.", traceflag=False)
return None
else:
return msg