当前位置: 首页>>代码示例>>Python>>正文


Python CloudProvider.add_secgroup_rule方法代码示例

本文整理汇总了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
开发者ID:alistairking,项目名称:client,代码行数:43,代码来源:secgroup.py

示例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
开发者ID:cloudmesh,项目名称:client,代码行数:23,代码来源:secgroup.py

示例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
开发者ID:cloudmesh,项目名称:client,代码行数:40,代码来源:secgroup.py


注:本文中的cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider.add_secgroup_rule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。