本文整理汇总了Python中cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider.get_ips方法的典型用法代码示例。如果您正苦于以下问题:Python CloudProvider.get_ips方法的具体用法?Python CloudProvider.get_ips怎么用?Python CloudProvider.get_ips使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider
的用法示例。
在下文中一共展示了CloudProvider.get_ips方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_vm
# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import get_ips [as 别名]
#.........这里部分代码省略.........
"Floating IP assigned to {:} successfully and it is: {:}".format(
sname, floating_ip))
msg = "info. OK."
Console.ok(msg)
except Exception as e:
Error.traceback(e)
Console.error("Problem assigning floating ips.")
elif arguments["ip"] and arguments["show"]:
vmids = arguments["NAME"]
# If names not provided, take the last vm from DB.
if vmids is None or len(vmids) == 0:
last_vm = Vm.get_last_vm(cloud=cloud)
if last_vm is None:
Console.error("No VM records in database. Please run vm refresh.")
return ""
name = last_vm["name"]
vmids = list()
vmids.append(name)
group = arguments["--group"]
output_format = arguments["--format"] or "table"
refresh = arguments["--refresh"]
# if default cloud not set, return error
if not cloud:
Console.error("Default cloud not set.")
return ""
try:
cloud_provider = CloudProvider(cloud).provider
for server in vmids:
ip_addr = cloud_provider.get_ips(server)
ipaddr_dict = Vm.construct_ip_dict(ip_addr, cloud)
print(
"IP Addresses of instance {:} are as follows:-".format(
server))
print(_print_dict_ip(ipaddr_dict, format=output_format))
msg = "info. OK."
Console.ok(msg)
except Exception as e:
Error.traceback(e)
Console.error(
"Problem getting ip addresses for instance {:}".format(id))
elif arguments["login"]:
vm_names = arguments["NAME"]
# If names not provided, take the last vm from DB.
if vm_names is None or len(vm_names) == 0:
last_vm = Vm.get_last_vm(cloud=cloud)
if last_vm is None:
Console.error("No VM records in database. Please run vm refresh.")
return ""
name = last_vm["name"]
else:
name = vm_names[0]
print("Logging in into {:} machine...".format(name))
user = arguments["--user"]
# Get user if user argument not specified.
示例2: do_vm
# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import get_ips [as 别名]
#.........这里部分代码省略.........
'username': arg.username,
'cloud': arg.cloud,
'command': arg.command
})
_print("login {cloud}:{username}@{name}".format(**data))
vm = Vm.get(data.name, category=data.cloud)
Vm.set_login_user(name=data.name, cloud=data.cloud, username=data.username)
data.floating_ip = vm.floating_ip
data.key = arguments["--key"] or Default.key
_print(Printer.attribute(data))
'''
if vm.username is None:
user_from_db = Vm.get_login_user(vm.name, vm.cloud)
user_suggest = user_from_db or Default.user
username = input("Username (Default: {}):".format(user_suggest)) or user_suggest
Vm.set_login_user(name=data.name, cloud=cloud, username=data.username)
'''
ip = arguments["--ip"]
commands = arguments["--command"]
ip_addresses = []
cloud_provider = CloudProvider(cloud).provider
ip_addr = cloud_provider.get_ips(vm.name)
ipaddr_dict = Vm.construct_ip_dict(ip_addr, cloud)
for entry in ipaddr_dict:
ip_addresses.append(ipaddr_dict[entry]["addr"])
if len(ip_addresses) > 0:
if ip is not None:
if ip not in ip_addresses:
Console.error("IP Address specified does not match with the host.", traceflag=False)
return ""
else:
_print("Determining IP Address to use with a ping test.")
# This part assumes that the ping is allowed to the machine.
for ipadd in ip_addresses:
_print("Checking {:}...".format(ipadd))
try:
# Evading ping test, as ping is not enabled for VMs on Azure cloud
# socket.gethostbyaddr(ipadd)
# ip will be set if above command is successful.
ip = ipadd
except socket.herror:
_print("Cannot reach {:}.".format(ipadd))
if ip is None:
_print("Unable to connect to the machine")
return ""
else:
_print("IP to be used is: {:}".format(ip))
#
# TODO: is this correctly implemented
#
示例3: CloudProvider
# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import get_ips [as 别名]
elif arguments["ip_show"]:
id = arguments["NAME"]
group = arguments["--group"]
output_format = arguments["--format"] or "table"
refresh = arguments["--refresh"]
# if default cloud not set, return error
if not cloud:
Console.error("Default cloud not set.")
return ""
try:
cloud_provider = CloudProvider(cloud).provider
for server in id:
ip_addr = cloud_provider.get_ips(server)
ipaddr_dict = Vm.construct_ip_dict(ip_addr, cloud)
print(
"IP Addresses of instance {:} are as follows:-".format(
server))
print(_print_dict_ip(ipaddr_dict, format=output_format))
msg = "info. OK."
Console.ok(msg)
except Exception, e:
import traceback
print(traceback.format_exc())
print(e)
Console.error(
"Problem getting ip addresses for instance {:}".format(id))