本文整理汇总了Python中cloudmesh_client.common.Printer.Printer.attribute方法的典型用法代码示例。如果您正苦于以下问题:Python Printer.attribute方法的具体用法?Python Printer.attribute怎么用?Python Printer.attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudmesh_client.common.Printer.Printer
的用法示例。
在下文中一共展示了Printer.attribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: details
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [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)
示例2: boot_from_args
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def boot_from_args(arg):
arg.username = arg.username or Image.guess_username(arg.image)
is_name_provided = arg.name is not None
arg.user = Default.user
for index in range(0, arg.count):
vm_details = dotdict({
"cloud": arg.cloud,
"name": Vm.get_vm_name(arg.name, index),
"image": arg.image,
"flavor": arg.flavor,
"key": arg.key,
"secgroup": arg.secgroup,
"group": arg.group,
"username": arg.username,
"user": arg.user
})
# correct the username
vm_details.username = Image.guess_username_from_category(
vm_details.cloud,
vm_details.image,
username=arg.username)
try:
if arg.dryrun:
print(Printer.attribute(vm_details, output=arg.format))
msg = "dryrun info. OK."
Console.ok(msg)
else:
vm_id = Vm.boot(**vm_details)
if vm_id is None:
msg = "info. failed."
Console.error(msg, traceflag=False)
return ""
# set name and counter in defaults
Default.set_vm(value=vm_details.name)
if is_name_provided is False:
Default.incr_counter("name")
# Add to group
if vm_id is not None:
Group.add(name=vm_details.group,
species="vm",
member=vm_details.name,
category=vm_details.cloud)
msg = "info. OK."
Console.ok(msg)
except Exception as e:
Console.error("Problem booting instance {name}".format(**vm_details), traceflag=False)
示例3: node_info
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def node_info(clusterid, nodeid=None, format='table'):
if nodeid:
url = Comet.url("cluster/{}/compute/{}/"
.format(clusterid, nodeid))
else:
url = Comet.url("cluster/{}/frontend/"
.format(clusterid))
r = Comet.get(url)
return Printer.attribute(r,
#order=Cluster.NODEINFO_ORDER,
output=format)
示例4: node_info
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def node_info(clusterid, nodeid=None, format='table'):
if nodeid:
url = Comet.url("cluster/{}/compute/{}/"
.format(clusterid, nodeid))
else:
url = Comet.url("cluster/{}/frontend/"
.format(clusterid))
r = Comet.get(url)
ret = "ERROR: Node not available. Please check the cluster/node name!\n"
if r:
ret = Printer.attribute(r,
#order=Cluster.NODEINFO_ORDER,
output=format)
return ret
示例5: export
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def export(host, output):
config = ConfigDict("cloudmesh.yaml")
credentials = dict(
config["cloudmesh"]["clouds"][host]["credentials"])
if not arguments["--password"]:
credentials["OS_PASSWORD"] = "********"
if output is None:
for attribute, value in credentials.items():
print("export {}={}".format(attribute, value))
elif output == "table":
print(Printer.attribute(credentials))
else:
print(Printer.write(credentials, output=output))
示例6: list
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def list(cls, cloud, tenant, output="table"):
try:
provider = CloudProvider(cloud).provider
result = provider.list_quota(cloud)
(order, header) = CloudProvider(cloud).get_attributes("quota")
return Printer.attribute(result,
header=header,
output=output)
except Exception as e:
import sys
print(sys.exc_info()[0])
return e
示例7: do_info
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def do_info(self, args, arguments):
"""
::
Usage:
info [--cloud=CLOUD] [--format=FORMAT]
Options:
--format=FORMAT the output format [default: table]
--cloud=CLOUD the cloud name
Examples:
cm info
"""
arg = dotdict(arguments)
arg.cloud = arguments["--cloud"] or Default.cloud
arg.FORMAT = arguments["--format"] or "table"
d = {
"cloud": arg.cloud,
"key": Default.key,
"user": Default.user,
"vm": Default.vm,
"group": Default.group,
"secgroup": Default.secgroup,
"counter": Default.get_counter(name="name"),
"image": Default.get_image(category=arg.cloud),
"flavor": Default.get_flavor(category=arg.cloud),
"refresh": str(Default.refresh),
"debug": str(Default.debug),
"interactive": str(Default.interactive),
"purge": str(Default.purge),
}
order = ["cloud", "key", "user", "vm", "group", "secgroup",
"counter", "image", "flavor", "refresh", "debug", "interactive", "purge"]
print(Printer.attribute(d, order=order, output=arg.FORMAT, sort_keys=False))
if d["key"] in ["TBD", ""] or d["user"] in ["TBD", ""]:
msg = "Please replace the TBD values"
msg = msg + "\nSee Also: \n\n" \
+ " cm register profile \n" \
+ " cm default user=YOURUSERNAME\n"
Console.error(msg, traceflag=False)
return ""
示例8: get_fixed_ip
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def get_fixed_ip(cls, cloudname, fixed_ip_addr, output='table'):
"""
Method retrieves fixed ip info
:param cloudname:
:param fixed_ip_addr:
:return: fixed_ip_info
"""
try:
cloud_provider = CloudProvider(cloudname).provider
result = cloud_provider.get_fixed_ip(fixed_ip_addr=fixed_ip_addr)
return Printer.attribute(result,
header=[
"name",
"value"
],
output=output)
except Exception as ex:
Console.error(ex.message)
return
示例9: do_info
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def do_info(self, args, arguments):
"""
::
Usage:
info [--cloud=CLOUD] [--format=FORMAT]
Options:
--format=FORMAT the output format [default: table]
--cloud=CLOUD the cloud name
Examples:
cm info
"""
arg = dotdict(arguments)
arg.cloud = arguments["--cloud"] or Default.cloud
arg.FORMAT = arguments["--format"] or "table"
d = {
"cloud": arg.cloud,
"key": Default.key,
"user": Default.user,
"vm": Default.vm,
"group": Default.group,
"secgroup": Default.secgroup,
"counter": Default.get_counter(name="name"),
"image": Default.get_image(category=arg.cloud),
"flavor": Default.get_flavor(category=arg.cloud),
"refresh": str(Default.refresh),
"debug": str(Default.debug),
"interactive": str(Default.interactive),
"purge": str(Default.purge),
}
order = ["cloud", "key", "user", "vm", "group", "secgroup",
"counter", "image", "flavor", "refresh", "debug", "interactive", "purge"]
print(Printer.attribute(d, order=order, output=arg.FORMAT, sort_keys=False))
return ""
示例10: do_vm
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
#.........这里部分代码省略.........
# if arg.NAMES is not None:
# arg.names = Parameter.expand(arg.NAMES) # gvonlasz[001-002] gives ["gvonlasz-001", "gvonlasz-002"]
# else:
# arg.names = None
#
if arguments["boot"]:
arg.username = arguments["--username"] or Image.guess_username(arg.image)
is_name_provided = arg.name is not None
arg.user = Default.user
for index in range(0, arg.count):
vm_details = dotdict({
"cloud": arg.cloud,
"name": get_vm_name(arg.name, index),
"image": arg.image,
"flavor": arg.flavor,
"key": arg.key,
"secgroup": arg.secgroup,
"group": arg.group,
"username": arg.username,
"user": arg.user
})
# correct the username
vm_details.username = Image.guess_username_from_category(
vm_details.cloud,
vm_details.image,
username=arg.username)
try:
if arg.dryrun:
print(Printer.attribute(vm_details, output=arg.format))
msg = "dryrun info. OK."
Console.ok(msg)
else:
vm_id = Vm.boot(**vm_details)
if vm_id is None:
msg = "info. failed."
Console.error(msg, traceflag=False)
return ""
# set name and counter in defaults
Default.set_vm(value=vm_details.name)
if is_name_provided is False:
Default.incr_counter("name")
# Add to group
if vm_id is not None:
Group.add(name=vm_details.group,
species="vm",
member=vm_details.name,
category=vm_details.cloud)
msg = "info. OK."
Console.ok(msg)
except Exception as e:
Console.error("Problem booting instance {name}".format(**vm_details), traceflag=False)
elif arguments["username"]:
arg.username = arguments["--username"] or Image.guess_username(arg.image)
示例11: do_hpc
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
#.........这里部分代码省略.........
result = batch.queue(cluster, format=format, job=name)
Console.msg(result)
elif arguments["test"]:
time_secs = arguments['--time']
if time_secs:
time = '00:00:' + time_secs
else:
time = '00:00:10' # give a default time of 10 secs
print(batch.test(cluster, time))
elif arguments["run"] and arguments["list"]:
# hpc experiment list [--cluster=CLUSTER]
if arguments["ID"]:
print("# List of experiment {ID} on Cluster {CLUSTER}".format(**arguments))
result = Experiment.list(cluster, id=arguments["ID"], format="list")
if result is not None:
print("\n".join(result))
else:
Console.error("Could not find experiment {ID} on {CLUSTER}".format(**arguments))
else:
print("# List of experiments on Cluster {CLUSTER}".format(**arguments))
ids = Experiment.list(cluster, id=None, format="list")
if ids is not None:
print(", ".join([str(i) for i in ids]))
else:
Console.error("Could not find experiment {ID} on {CLUSTER}".format(**arguments))
elif arguments["run"] and arguments["rm"]:
# hpc experiment list [--cluster=CLUSTER]
if arguments["ID"]:
force = yn_choice("Would you like to delete experiment {ID} on Cluster {CLUSTER}".format(**arguments))
if force:
try:
result = Experiment.rm(cluster, id=arguments["ID"])
Console.ok("Experiment {ID} on Cluster {CLUSTER} deleted".format(**arguments))
except:
Console.error("Could not delete experiment {ID} on {CLUSTER}".format(**arguments))
else:
result = Experiment.list(cluster, id=None, format="list")
if result is not None:
arguments['experiments'] = ", ".join([str(i) for i in result])
else:
Console.error("Could not find experiment {ID} on {CLUSTER}".format(**arguments))
return ""
force = yn_choice("Would you like to delete the experiments {experiments} on Cluster {CLUSTER}".format(
**arguments))
if force:
try:
result = Experiment.rm(cluster, id=None)
Console.ok("Experiments {experiments} on Cluster {CLUSTER} deleted".format(**arguments))
except:
Console.error("Could delete the experiments on {CLUSTER}".format(**arguments))
return ""
elif arguments["run"] and arguments["output"]:
# hpc experiment list [--cluster=CLUSTER]
if arguments["ID"]:
print("# List of experiment {ID} on Cluster {CLUSTER}".format(**arguments))
result = Experiment.output(cluster, id=arguments["ID"], format="list")
if result is not None:
print("\n".join(result))
else:
Console.error("Could not find experiment {ID} on {CLUSTER}".format(**arguments))
else:
print("# List of experiments on Cluster {CLUSTER}".format(**arguments))
ids = Experiment.output(cluster, id=None, format="list")
if ids is not None:
print(", ".join([str(i) for i in ids]))
else:
Console.error("Could not find experiment {ID} on {CLUSTER}".format(**arguments))
elif arguments["run"]:
queue = arguments['--queue'] or Default.get(name='queue')
# if not queue:
# Console.error('set default queue using: default queue=<value>')
# return
group = arguments['--group'] or Default.get(name='group')
if group is None:
Console.error('set default group using: default group=<value> --cloud=general')
return
script = arguments['SCRIPT']
arg_dict = {
'-name': arguments['--name'],
'-p': queue,
'-t': arguments['--t'],
'-N': arguments['--N']
}
result = batch.run(cluster, group, script, **arg_dict)
if isinstance(result, dict):
print(Printer.attribute(result))
Console.ok("Experiment {count}: Started batch job {job_id} on {cluster}".format(**result))
else:
Console.error(result)
return ""
示例12: do_vbox
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def do_vbox(argv):
"""
::
Usage:
vbox version [--format=FORMAT]
vbox image list [--format=FORMAT]
vbox image find NAME
vbox image add NAME
vbox vm list [--format=FORMAT] [-v]
vbox vm delete NAME
vbox vm config NAME
vbox vm ip NAME [--all]
vbox create NAME ([--memory=MEMORY]
[--image=IMAGE]
[--script=SCRIPT] | list)
vbox vm boot NAME ([--memory=MEMORY]
[--image=IMAGE]
[--port=PORT]
[--script=SCRIPT] | list)
vbox vm ssh NAME [-e COMMAND]
"""
arg = dotdict(docopt(do_vbox.__doc__, argv))
arg.format = arg["--format"] or "table"
arg.verbose = arg["-v"]
arg.all = arg["--all"]
if arg.version:
versions = {
"vagrant": {
"attribute": "Vagrant Version",
"version": vagrant.version(),
},
"cloudmesh-vbox": {
"attribute":"cloudmesh vbox Version",
"version": __version__
}
}
_LIST_PRINT(versions, arg.format)
elif arg.image and arg.list:
l = vagrant.image.list(verbose=arg.verbose)
_LIST_PRINT(l, arg.format, order=["name", "provider", "date"])
elif arg.image and arg.add:
l = vagrant.image.add(arg.NAME)
print(l)
elif arg.image and arg.find:
l = vagrant.image.find(arg.NAME)
print(l)
elif arg.vm and arg.list:
l = vagrant.vm.list()
_LIST_PRINT(l,
arg.format,
order=["name", "state", "id", "provider", "directory"])
elif arg.create and arg.list:
result = Shell.cat("{NAME}/Vagrantfile".format(**arg))
print (result)
elif arg.create:
d = defaults()
arg.memory = arg["--memory"] or d.memory
arg.image = arg["--image"] or d.image
arg.script = arg["--script"] or d.script
vagrant.vm.create(
name=arg.NAME,
memory=arg.memory,
image=arg.image,
script=arg.script)
elif arg.config:
# arg.NAME
d = vagrant.vm.info(name=arg.NAME)
result = Printer.attribute(d, output=arg.format)
print (result)
elif arg.ip:
data = []
result = vagrant.vm.execute(arg.NAME, "ifconfig")
if result is not None:
lines = result.splitlines()[:-1]
for line in lines:
if "inet addr" in line:
line = line.replace("inet addr", "ip")
line = ' '.join(line.split())
_adresses = line.split(" ")
address = {}
for element in _adresses:
attribute, value = element.split(":")
#.........这里部分代码省略.........
示例13: list
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def list(cls, **kwargs):
"""
This method lists all VMs of the cloud
"""
arg = dotdict(kwargs)
if "name" in arg:
arg.name = arg.name
arg.output = arg.output or 'table'
# pprint (kwargs)
# prevent circular dependency
def vm_groups(vm):
"""
:param vm: name of the vm
:return: a list of groups the vm is in
"""
try:
query = {
'kind': "group",
'provider': 'general',
"species": "vm",
"member": vm,
"scope": 'all',
"output": 'dict'
}
d = cls.cm.find(**query)
groups_vm = set()
if d is not None and len(d) > 0:
for vm in d:
groups_vm.add(vm['name'])
return list(groups_vm)
except Exception as ex:
Console.error(ex.message)
return []
try:
if "name" in arg and arg.name is not None:
if cls.isUuid(arg.name):
elements = cls.cm.find(kind="vm",
category=arg.category,
uuid=arg.name)
else:
elements = cls.cm.find(kind="vm",
category=arg.category,
label=arg.name)
else:
elements = cls.cm.find(kind="vm",
category=arg.category)
if elements is None or len(elements) == 0:
return None
for elem in elements:
element = elem
name = element["name"]
groups = vm_groups(name)
element["group"] = ','.join(groups)
# print(elements)
# order = ['id', 'uuid', 'name', 'cloud']
(order, header) = CloudProvider(arg.category).get_attributes("vm")
# order = None
if "name" in arg and arg.name is not None:
return Printer.attribute(elements[0],
output=arg.output)
else:
return Printer.write(elements,
order=order,
output=arg.output)
except Exception as ex:
Console.error(ex.message)
示例14: boot
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def boot(cls, **kwargs):
arg = dotdict(kwargs)
for a in ["key", "name", "image", "flavor"]:
if a not in kwargs:
raise ValueError(a + " not in arguments to vm boot")
conf = ConfigDict("cloudmesh.yaml")
arg.username = conf["cloudmesh"]["profile"]["user"]
arg.group = arg.group or Default.group
cloud_provider = CloudProvider(arg.cloud).provider
if "nics" in arg:
nics = arg.nics
else:
nics = None
basic_dict = {
"cloud": arg.cloud,
"name": arg.name,
"image": arg.image,
"flavor": arg.flavor,
"key": arg.key,
"secgroup": [arg.secgroup],
"nics": nics,
"meta": {'kind': 'cloudmesh',
'group': arg.group,
'image': arg.image,
'flavor': arg.flavor,
'key': arg.key,
'category': arg.cloud
}
}
# Special case for Azure where certificate details needs to be added
if arg.cloud == "azure":
kwargs = dict()
kwargs['kind'] = "key_azure"
db_result = cls.cm.find(**kwargs)
# pprint("Key DB results")
key_result = None
try:
for key in db_result:
if key['name'] == arg.key:
pprint("Found the key")
key_result = key
break
if key_result is not None:
new_dict_items = dict()
new_dict_items['cert_thumbprint'] = key_result['fingerprint']
new_dict_items['pub_key_path'] = key_result['key_path']
new_dict_items['cert_path'] = key_result['certificate']
new_dict_items['pfx_path'] = key_result['pfx_path']
basic_dict.update(new_dict_items)
else:
pprint("None found in DB")
except:
traceback.print_exc()
pprint("Exception while processing azure boot arguments")
d = dotdict(basic_dict)
Console.ok("Machine {name} is being booted on cloud {cloud} ...".format(**arg))
print(Printer.attribute(d))
vm = cloud_provider.boot_vm(**d)
if vm is not None:
cls.refresh(cloud=arg.cloud)
cls.cm.set(d.name, "key", d.key, scope="first", kind="vm")
cls.cm.set(d.name, "image", d.image, scope="first", kind="vm")
cls.cm.set(d.name, "flavor", d.flavor, scope="first", kind="vm")
cls.cm.set(d.name, "group", arg.group, scope="first", kind="vm")
cls.cm.set(d.name, "user", arg.user, scope="first", kind="vm")
# update group and key
#
# cls.cm.update("vm", name=data.name)
return vm
示例15: get_floating_ip
# 需要导入模块: from cloudmesh_client.common.Printer import Printer [as 别名]
# 或者: from cloudmesh_client.common.Printer.Printer import attribute [as 别名]
def get_floating_ip(cls, cloudname, floating_ip_or_id, output='table'):
"""
Method to get floating ip info
:param cloudname:
:param floating_ip_or_id:
:return: floating ip info
"""
try:
cloud_provider = CloudProvider(cloudname).provider
result = None
# check if argument is ip or uuid
if cls.isIPAddr(ip_or_id=floating_ip_or_id):
# get floating ip list
floating_ips = cls.get_floating_ip_list(cloudname)
for floating_ip in list(floating_ips):
ip_addr = floating_ip["ip"]
# if argument ip matches floating ip addr
if ip_addr == floating_ip_or_id:
result = floating_ip
break
else:
# find by floating ip uuid
result = cloud_provider.get_floating_ip(floating_ip_id=floating_ip_or_id)
# Could not find floating IP from given args
if result is None:
return None
instance_id = result["instance_id"]
instance_name = None
if instance_id is not None:
# lookup instance_name from id
instance_name = cls.find_instance_name(cloudname=cloudname,
instance_id=instance_id)
# add instance_name to dict
result["instance_name"] = instance_name
# add misc details to response
result["cloud"] = cloudname
result["user"] = cloud_provider.cloud_details["credentials"]["OS_USERNAME"]
result["project"] = cloud_provider.cloud_details["credentials"]["OS_TENANT_NAME"]
return Printer.attribute(result,
header=[
"name",
"value"
],
output=output)
except Exception:
# auto detect floating-ip-id
floating_ips = cls.get_floating_ip_list(cloudname)
# for each floating-ip from list
for floating_ip in list(floating_ips):
if floating_ip["id"].startswith(floating_ip_or_id) or \
floating_ip["ip"].startswith(floating_ip_or_id):
# confirm choice with user
print("Did you mean floating-ip [{}] ? (y/n)".format(floating_ip["ip"]))
choice = input().lower()
# if yes, return dict
if choice == 'y':
return Printer.attribute(floating_ip,
header=[
"name",
"value"
],
output=output)
# Console.error(ex.message)
return