本文整理汇总了Python中cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider.enable_ssh方法的典型用法代码示例。如果您正苦于以下问题:Python CloudProvider.enable_ssh方法的具体用法?Python CloudProvider.enable_ssh怎么用?Python CloudProvider.enable_ssh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider
的用法示例。
在下文中一共展示了CloudProvider.enable_ssh方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: enable_ssh
# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import enable_ssh [as 别名]
def enable_ssh(cls, secgroup_name='default', cloud="general"):
ret = False
if cloud in LibcloudDict.Libcloud_category_list:
Console.info("Creating and adding security group for libcloud")
cloud_provider = CloudProvider(cloud).provider
cloud_provider.create_sec_group(cloud, secgroup_name)
cloud_provider.enable_ssh(cloud, secgroup_name)
else:
cloud_provider = CloudProvider(cloud).provider.provider
secgroups = cloud_provider.security_groups.list()
for asecgroup in secgroups:
if asecgroup.name == secgroup_name:
rules = asecgroup.rules
rule_exists = False
# structure of a secgroup rule:
# {u'from_port': 22, u'group': {}, u'ip_protocol': u'tcp', u'to_port': 22, u'parent_group_id': u'UUIDHERE', u'ip_range': {u'cidr': u'0.0.0.0/0'}, u'id': u'UUIDHERE'}
for arule in rules:
if arule["from_port"] == 22 and \
arule["to_port"] == 22 and \
arule["ip_protocol"] == 'tcp' and \
arule["ip_range"] == {'cidr': '0.0.0.0/0'}:
# print (arule["id"])
rule_exists = True
break
if not rule_exists:
cloud_provider.security_group_rules.create(
asecgroup.id,
ip_protocol='tcp',
from_port=22,
to_port=22,
cidr='0.0.0.0/0')
# else:
# print ("The rule allowing ssh login did exist!")
ret = True
break
# print ("*" * 80)
# d = SecGroup.convert_list_to_dict(secgroups)
# print (d)
return ret