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


Python CloudProvider.list_secgroup方法代码示例

本文整理汇总了Python中cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider.list_secgroup方法的典型用法代码示例。如果您正苦于以下问题:Python CloudProvider.list_secgroup方法的具体用法?Python CloudProvider.list_secgroup怎么用?Python CloudProvider.list_secgroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider的用法示例。


在下文中一共展示了CloudProvider.list_secgroup方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: list_rules_cloud

# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import list_secgroup [as 别名]
 def list_rules_cloud(cls, cloud, groupname):
     provider = CloudProvider(cloud).provider
     groups = provider.list_secgroup(cloud)
     for id in groups:
         group = groups[id]
         if groupname == group["name"]:
             return group["rules"]
     return None
开发者ID:cloudmesh,项目名称:client,代码行数:10,代码来源:secgroup.py

示例2: get_group_cloud

# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import list_secgroup [as 别名]
 def get_group_cloud(cls, cloud, groupname):
     provider = CloudProvider(cloud).provider
     groups = provider.list_secgroup(cloud)
     ret = None
     for groupkey in groups:
         group = groups[groupkey]
         if group["name"] == groupname:
             ret = group
             break
     return ret
开发者ID:cloudmesh,项目名称:client,代码行数:12,代码来源:secgroup.py

示例3: refresh

# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import list_secgroup [as 别名]
    def refresh(self, kind, name, **kwargs):
        """
        This method refreshes the local database
        with the live cloud details
        :param kind:
        :param name:
        :param kwargs:
        :return:
        """
        try:
            # print(cloudname)
            # get the user
            # TODO: Confirm user
            user = self.user

            if kind in ["flavor", "image", "vm", "secgroup"]:

                # get provider for specific cloud
                provider = CloudProvider(name).provider

                # clear local db records for kind
                self.clear(kind, name)

                # for secgroup, clear rules as well
                if kind == "secgroup":
                    self.clear("secgrouprule", name)

                if kind == "flavor":
                    flavors = provider.list_flavor(name)
                    for flavor in list(flavors.values()):
                        flavor["uuid"] = flavor['id']
                        flavor['type'] = 'string'
                        flavor["category"] = name
                        flavor["user"] = user

                        db_obj = {0: {kind: flavor}}
                        self.add_obj(db_obj)
                        self.save()
                    return True

                elif kind == "image":
                    images = provider.list_image(name)

                    for image in list(images.values()):
                        image['uuid'] = image['id']
                        image['type'] = 'string'
                        image['category'] = name
                        image['user'] = user
                        db_obj = {0: {kind: image}}

                        self.add_obj(db_obj)
                        self.save()
                    return True

                elif kind == "vm":
                    vms = provider.list_vm(name)
                    for vm in list(vms.values()):
                        vm['uuid'] = vm['id']
                        vm['type'] = 'string'
                        vm['category'] = name
                        vm['user'] = user
                        db_obj = {0: {kind: vm}}

                        self.add_obj(db_obj)
                        self.save()
                    return True

                elif kind == "secgroup":
                    secgroups = provider.list_secgroup(name)
                    # pprint(secgroups)
                    for secgroup in list(secgroups.values()):
                        secgroup_db_obj = self.db_obj_dict("secgroup",
                                                           name=secgroup['name'],
                                                           uuid=secgroup['id'],
                                                           category=name,
                                                           project=secgroup['tenant_id'],
                                                           user=user
                                                           )

                        for rule in secgroup['rules']:
                            rule_db_obj = self.db_obj_dict("secgrouprule",
                                                           uuid=rule['id'],
                                                           name=secgroup['name'],
                                                           groupid=rule['parent_group_id'],
                                                           category=name,
                                                           user=user,
                                                           project=secgroup['tenant_id'],
                                                           fromPort=rule['from_port'],
                                                           toPort=rule['to_port'],
                                                           protocol=rule['ip_protocol'])

                            if bool(rule['ip_range']) is not False:
                                rule_db_obj[0]['secgrouprule']['cidr'] = rule['ip_range']['cidr']

                            self.add_obj(rule_db_obj)
                            self.save()
                        # rule-for-loop ends

                        self.add_obj(secgroup_db_obj)
                        self.save()
#.........这里部分代码省略.........
开发者ID:sohiljain,项目名称:client,代码行数:103,代码来源:CloudmeshDatabase.py

示例4: list_groups_cloud

# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import list_secgroup [as 别名]
 def list_groups_cloud(cls, cloud):
     provider = CloudProvider(cloud).provider
     groups = provider.list_secgroup(cloud)
     return groups
开发者ID:cloudmesh,项目名称:client,代码行数:6,代码来源:secgroup.py

示例5: test_003

# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import list_secgroup [as 别名]
    def test_003(self):

        HEADING("secgroup api")

        data = dotdict({
            'cloud': "cm",
            'groupname': 'gvonlasz-default'
        })
        provider = CloudProvider(data.cloud).provider

        groups = None
        rules = provider.list_secgroup(data.cloud)

        """
        # passed
        def add_group(cloud, groupname):
            provider = CloudProvider(cloud).provider
            return provider.create_secgroup(groupname)

        # passed
        def delete_group(cloud, groupname):
            provider = CloudProvider(data.cloud).provider
            return provider.delete_secgroup(groupname)

        # passed
        def add_rule(cloud, groupname, rulename):
            ret = None
            provider = CloudProvider(data.cloud).provider
            # fetch rule from db
            cm = CloudmeshDatabase()
            db_rule = cm.find(kind="secgrouprule", category="general", 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 = get_group(cloud, groupname)
            if group:
                groupid = group["id"]
                kwargs["uuid"] = groupid
                print (kwargs)
                ret = provider.add_secgroup_rule(**kwargs)
            return ret

        # passed
        def delete_rule(cloud, groupname, rulename):
            ret = None
            provider = CloudProvider(data.cloud).provider
            ruleid = get_rule(cloud, groupname, rulename)
            if ruleid:
                ret = provider.delete_secgroup_rule(ruleid)
            else:
                Console.error("Rule does not exist - Rule:{}, Group:{}".format(rulename, groupname))
            return ret

        # passed
        def list_groups(cloud):
            provider = CloudProvider(cloud).provider
            groups = provider.list_secgroup(cloud)
            return groups

        # passed
        def get_group(cloud, groupname):
            provider = CloudProvider(cloud).provider
            groups = provider.list_secgroup(cloud)
            ret = None
            for groupkey in groups:
                group = groups[groupkey]
                if group["name"] == groupname:
                    ret = group
                    break
            return ret

        # passed
        def list_rules(cloud, groupname):
            provider = CloudProvider(cloud).provider
            groups = provider.list_secgroup(cloud)
            for id in groups:
                group = groups[id]
                if groupname == group["name"]:
                    return group["rules"]
            return None

        # passed
        def get_rule(cloud, groupname, rulename):
            rules = list_rules(cloud, groupname)
            # find properties for db rule

            cm = CloudmeshDatabase()
            db_rule = cm.find(kind="secgrouprule", category="general", name=rulename, scope='first', output='dict')

            #db_rule = {u'from_port': 80,
            #          u'ip_protocol': u'tcp',
            #          u'ip_range': {u'cidr': u'0.0.0.0/0'},
            #          u'to_port': 80},
            ruleid = None
            for rule in rules:

                if 'cidr' in rule['ip_range']:
                    if (db_rule["fromPort"] == str(rule['from_port']) and
#.........这里部分代码省略.........
开发者ID:ashwinir20,项目名称:client,代码行数:103,代码来源:test_secgroup.py


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