本文整理汇总了Python中cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider.get_floating_ip方法的典型用法代码示例。如果您正苦于以下问题:Python CloudProvider.get_floating_ip方法的具体用法?Python CloudProvider.get_floating_ip怎么用?Python CloudProvider.get_floating_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider
的用法示例。
在下文中一共展示了CloudProvider.get_floating_ip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_floating_ip
# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import get_floating_ip [as 别名]
def get_floating_ip(cls, cloudname, floating_ip_or_id):
"""
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 floating_ips.values():
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 attribute_printer(result, header=["name", "value"])
except Exception as ex:
# auto detect floating-ip-id
floating_ips = cls.get_floating_ip_list(cloudname)
# for each floating-ip from list
for floating_ip in floating_ips.values():
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 = raw_input().lower()
# if yes, return dict
if choice == "y":
return attribute_printer(floating_ip, header=["name", "value"])
# Console.error(ex.message)
return
示例2: delete_floating_ip
# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import get_floating_ip [as 别名]
def delete_floating_ip(cls, cloudname, floating_ip_or_id):
"""
Method to delete a floating ip address
:param cloudname:
:param floating_ip_or_id:
:return:
"""
try:
cloud_provider = CloudProvider(cloudname).provider
floating_ip_dict = 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:
floating_ip_dict = floating_ip
break
else:
# find by floating ip uuid
floating_ip_dict = cloud_provider.get_floating_ip(floating_ip_id=floating_ip_or_id)
# Could not find floating IP from given args
if floating_ip_dict is None:
return None
# Delete the floating ip; returns None if success
result = cloud_provider.delete_floating_ip(floating_ip_dict["id"])
if not result:
return "Floating IP [{}] deleted successfully!" \
.format(floating_ip_dict["ip"])
except Exception as ex:
Console.error(ex.message)
return