本文整理汇总了Python中cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider.add_secgroup_rule方法的典型用法代码示例。如果您正苦于以下问题:Python CloudProvider.add_secgroup_rule方法的具体用法?Python CloudProvider.add_secgroup_rule怎么用?Python CloudProvider.add_secgroup_rule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider
的用法示例。
在下文中一共展示了CloudProvider.add_secgroup_rule方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_rule
# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import add_secgroup_rule [as 别名]
def add_rule(cls, cloud, secgroup, from_port, to_port, protocol, cidr):
try:
# Get the nova client object
cloud_provider = CloudProvider(cloud).provider
# Create add secgroup rules to the cloud
args = {
'uuid': secgroup.uuid,
'protocol': protocol,
'from_port': from_port,
'to_port': to_port,
'cidr': cidr
}
rule_id = cloud_provider.add_secgroup_rule(**args)
# create local db record
ruleObj = cls.cm_db.db_obj_dict("secgrouprule",
uuid=str(rule_id),
name=secgroup.name,
groupid=secgroup.uuid,
category=secgroup.category,
user=secgroup.user,
project=secgroup.project,
fromPort=from_port,
toPort=to_port,
protocol=protocol,
cidr=cidr)
cls.cm_db.add_obj(ruleObj)
cls.cm_db.save()
Console.ok("Added rule [{} | {} | {} | {}] to secgroup [{}]"
.format(from_port, to_port, protocol, cidr,
secgroup.name))
except Exception as ex:
if "This rule already exists" in ex.message:
Console.ok("Rule already exists. Added rule.")
return
else:
Console.error(ex.message, ex)
return
示例2: add_rule_cloud
# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import add_secgroup_rule [as 别名]
def add_rule_cloud(cls, cloud, groupname, rulename):
ret = None
provider = CloudProvider(cloud).provider
# fetch rule from db
db_rule = cls.cm.find(kind="secgrouprule",
category="general",
group=groupname,
name=rulename,
scope='first',
output='dict')
kwargs = {}
kwargs["protocol"] = db_rule["protocol"]
kwargs["cidr"] = db_rule["cidr"]
kwargs["from_port"] = db_rule["fromPort"]
kwargs["to_port"] = db_rule["toPort"]
group = cls.get_group_cloud(cloud, groupname)
if group:
groupid = group["id"]
kwargs["uuid"] = groupid
ret = provider.add_secgroup_rule(**kwargs)
return ret
示例3: add_rule
# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import add_secgroup_rule [as 别名]
def add_rule(cls, cloud, secgroup_uuid, from_port, to_port, protocol, cidr):
try:
# Get the nova client object
cloud_provider = CloudProvider(cloud).provider
# Create add secgroup rules to the cloud
args = {
'uuid': secgroup_uuid,
'protocol': protocol,
'from_port': from_port,
'to_port': to_port,
'cidr': cidr
}
rule_id = cloud_provider.add_secgroup_rule(**args)
# create local db record
rule = {"kind": "secgrouprule",
"uuid": str(rule_id),
"category": cloud,
"fromPort": from_port,
"toPort": to_port,
"protocol": protocol,
"cidr": cidr}
"""
cls.cm.add(**rule)
cls.cm.save()
"""
Console.ok("Added rule {category} {uuid} {fromPort} {toPort} {protocol} {cidr}"
.format(**rule))
except Exception as ex:
if "This rule already exists" in ex.message:
Console.ok("Rule already exists. Added rule.")
return
else:
Console.error(ex.message, ex)
return