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


Python SOAPProxy.list方法代码示例

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


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

示例1: __init__

# 需要导入模块: from SOAPpy import SOAPProxy [as 别名]
# 或者: from SOAPpy.SOAPProxy import list [as 别名]
class VMRC:
    """ Class to connect with the VMRC server """
    # define the namespace
    namespace = 'http://ws.vmrc.grycap.org/'
    server = None

    def __init__(self, url, user=None, passwd=None):
        if user is None:
            self.server = SOAPProxy(url)
        else:
            self.server = SOAPProxy(url, transport=HTTPHeaderTransport, namespace=self.namespace)
            self.server.transport.headers = {'Username': user,
                                             'Password': passwd}

        # if you want to see the SOAP message exchanged
        # uncomment the two following lines
        # self.server.config.dumpSOAPOut = 1
        # self.server.config.dumpSOAPIn = 1
        # self.server.config.dumpHeadersOut = 1

    @staticmethod
    def _toRADLSystem(vmi):

        # Pass common features
        VMRC_RADL_MAP = {
            'hypervisor': ('virtual_system_type', str),
            'diskSize': ('disk.0.size', int),
            'arch': ('cpu.arch', str),
            'location': ('disk.0.image.url', str),
            'name': ('disk.0.image.name', str),
            'userLogin': ('disk.0.os.credentials.username', str),
            'userPassword': ('disk.0.os.credentials.password', str)
        }
        fs = [Feature(VMRC_RADL_MAP[prop][0], "=", VMRC_RADL_MAP[prop][1](getattr(vmi, prop)))
              for prop in VMRC_RADL_MAP if hasattr(vmi, prop) and getattr(vmi, prop)]
        fs.extend([Feature("disk.0.os." + prop, "=", getattr(vmi.os, prop))
                   for prop in ['name', "flavour", "version"]])

        if not hasattr(vmi, 'applications'):
            return system("", fs)

        # vmi.applications can store the attributes of a single application
        # or can be a list of objects.
        if vmi.applications and isinstance(vmi.applications[0], str):
            apps = [vmi.applications]
        else:
            apps = vmi.applications

        for app in apps:
            OS_VMRC_RADL_PROPS = ["name", "version", "path"]
            fs.append(Feature("disk.0.applications", "contains", FeaturesApp(
                [Feature(prop, "=", getattr(app, prop))
                    for prop in OS_VMRC_RADL_PROPS] +
                [Feature("preinstalled", "=", "yes")])))
        return system("", fs)

    def list_vm(self):
        """Get a list of all the VM registered in the catalog."""

        try:
            vmrc_res = self.server.list()
        except Exception:
            return None

        if len(vmrc_res) > 0:
            if isinstance(vmrc_res, list):
                return [VMRC._toRADLSystem(vmi) for vmi in vmrc_res]
            else:
                return [VMRC._toRADLSystem(vmrc_res)]
        else:
            return []

    def search_vm(self, radl_system):
        """
        Get a list of the most suitable VM according to the requirements
        expressed by the user.

        Args:

        - radl_system(system): system that VMRC will search compatible configurations.

        Return(None or list of system): available virtual machines
        """

        # If an images is already set, VMRC service is not asked
        if radl_system.getValue("disk.0.image.url"):
            return []

        vmi_desc_str_val = VMRC._generateVMRC(radl_system.features).strip()
        try:
            vmrc_res = self.server.search(vmiDescStr=vmi_desc_str_val)
        except Exception:
            return []

        if len(vmrc_res) > 0:
            if isinstance(vmrc_res, list):
                return [VMRC._toRADLSystem(vmi) for vmi in vmrc_res]
            else:
                return [VMRC._toRADLSystem(vmrc_res)]
        else:
#.........这里部分代码省略.........
开发者ID:buweixiaomi,项目名称:im,代码行数:103,代码来源:VMRC.py


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