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


Python CloudProvider.list_image方法代码示例

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


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

示例1: refresh

# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import list_image [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

示例2: refresh

# 需要导入模块: from cloudmesh_client.cloud.iaas.CloudProvider import CloudProvider [as 别名]
# 或者: from cloudmesh_client.cloud.iaas.CloudProvider.CloudProvider import list_image [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"]:

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

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

                if kind == "flavor":
                    flavors = provider.list_flavor(name)
                    for flavor in flavors.values():
                        flavor["uuid"] = flavor["id"]
                        flavor["type"] = "string"
                        flavor["cloud"] = 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 images.values():
                        image["uuid"] = image["id"]
                        image["type"] = "string"
                        image["cloud"] = 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 vms.values():
                        vm["uuid"] = vm["id"]
                        vm["type"] = "string"
                        vm["cloud"] = name
                        vm["user"] = user
                        db_obj = {0: {kind: vm}}

                        self.add_obj(db_obj)
                        self.save()
                    return True
            elif kind in ["batchjob"]:

                # provider = BatchProvider(name).provider
                # provider = BatchProvider(name)

                from cloudmesh_client.cloud.hpc.BatchProvider import BatchProvider

                provider = BatchProvider(name)

                vms = provider.list_job(name)
                for vm in vms.values():
                    vm["uuid"] = vm["id"]
                    vm["type"] = "string"
                    vm["cloud"] = name
                    vm["user"] = user
                    db_obj = {0: {kind: vm}}

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

            else:
                Console.error("refresh not supported for this kind: {}".format(kind))

        except Exception as ex:
            Console.error(ex.message)
            return False
开发者ID:atavism,项目名称:client,代码行数:91,代码来源:CloudmeshDatabase.py


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