• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python _compat._StringIO函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中salt._compat._StringIO函数的典型用法代码示例。如果您正苦于以下问题:Python _StringIO函数的具体用法?Python _StringIO怎么用?Python _StringIO使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: get_macs

def get_macs(vm_):
    """
    Return a list off MAC addresses from the named vm

    CLI Example::

        salt '*' virt.get_macs <vm name>
    """
    macs = []
    doc = minidom.parse(_StringIO(get_xml(vm_)))
    for node in doc.getElementsByTagName("devices"):
        i_nodes = node.getElementsByTagName("interface")
        for i_node in i_nodes:
            for v_node in i_node.getElementsByTagName("mac"):
                macs.append(v_node.getAttribute("address"))
    return macs
开发者ID:sijis,项目名称:salt,代码行数:16,代码来源:virt.py


示例2: get_graphics

def get_graphics(vm_):
    """
    Returns the information on vnc for a given vm

    CLI Example::

        salt '*' virt.get_graphics <vm name>
    """
    out = {"autoport": "None", "keymap": "None", "listen": "None", "port": "None", "type": "vnc"}
    xml = get_xml(vm_)
    ssock = _StringIO(xml)
    doc = minidom.parse(ssock)
    for node in doc.getElementsByTagName("domain"):
        g_nodes = node.getElementsByTagName("graphics")
        for g_node in g_nodes:
            for key in g_node.attributes.keys():
                out[key] = g_node.getAttribute(key)
    return out
开发者ID:sijis,项目名称:salt,代码行数:18,代码来源:virt.py


示例3: get_nics

def get_nics(vm_):
    '''
    Return info about the network interfaces of a named vm

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_nics <vm name>
    '''
    nics = {}
    doc = minidom.parse(_StringIO(get_xml(vm_)))
    for node in doc.getElementsByTagName('devices'):
        i_nodes = node.getElementsByTagName('interface')
        for i_node in i_nodes:
            nic = {}
            nic['type'] = i_node.getAttribute('type')
            for v_node in i_node.getElementsByTagName('*'):
                if v_node.tagName == 'mac':
                    nic['mac'] = v_node.getAttribute('address')
                if v_node.tagName == 'model':
                    nic['model'] = v_node.getAttribute('type')
                if v_node.tagName == 'target':
                    nic['target'] = v_node.getAttribute('dev')
                # driver, source, and match can all have optional attributes
                if re.match('(driver|source|address)', v_node.tagName):
                    temp = {}
                    for key in v_node.attributes.keys():
                        temp[key] = v_node.getAttribute(key)
                    nic[str(v_node.tagName)] = temp
                # virtualport needs to be handled separately, to pick up the
                # type attribute of the virtualport itself
                if v_node.tagName == 'virtualport':
                    temp = {}
                    temp['type'] = v_node.getAttribute('type')
                    for key in v_node.attributes.keys():
                        temp[key] = v_node.getAttribute(key)
                    nic['virtualport'] = temp
            if 'mac' not in nic:
                continue
            nics[nic['mac']] = nic
    return nics
开发者ID:jslatts,项目名称:salt,代码行数:42,代码来源:virt.py


示例4: get_nics

def get_nics(vm_):
    """
    Return info about the network interfaces of a named vm

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_nics <vm name>
    """
    nics = {}
    doc = minidom.parse(_StringIO(get_xml(vm_)))
    for node in doc.getElementsByTagName("devices"):
        i_nodes = node.getElementsByTagName("interface")
        for i_node in i_nodes:
            nic = {}
            nic["type"] = i_node.getAttribute("type")
            for v_node in i_node.getElementsByTagName("*"):
                if v_node.tagName == "mac":
                    nic["mac"] = v_node.getAttribute("address")
                if v_node.tagName == "model":
                    nic["model"] = v_node.getAttribute("type")
                if v_node.tagName == "target":
                    nic["target"] = v_node.getAttribute("dev")
                # driver, source, and match can all have optional attributes
                if re.match("(driver|source|address)", v_node.tagName):
                    temp = {}
                    for key in v_node.attributes.keys():
                        temp[key] = v_node.getAttribute(key)
                    nic[str(v_node.tagName)] = temp
                # virtualport needs to be handled separately, to pick up the
                # type attribute of the virtualport itself
                if v_node.tagName == "virtualport":
                    temp = {}
                    temp["type"] = v_node.getAttribute("type")
                    for key in v_node.attributes.keys():
                        temp[key] = v_node.getAttribute(key)
                    nic["virtualport"] = temp
            if "mac" not in nic:
                continue
            nics[nic["mac"]] = nic
    return nics
开发者ID:hulu,项目名称:salt,代码行数:42,代码来源:virt.py


示例5: get_disks

def get_disks(vm_):
    '''
    Return the disks of a named vm

    CLI Example:

    .. code-block:: bash

        salt '*' virt.get_disks <vm name>
    '''
    disks = {}
    doc = minidom.parse(_StringIO(get_xml(vm_)))
    for elem in doc.getElementsByTagName('disk'):
        sources = elem.getElementsByTagName('source')
        targets = elem.getElementsByTagName('target')
        if len(sources) > 0:
            source = sources[0]
        else:
            continue
        if len(targets) > 0:
            target = targets[0]
        else:
            continue
        if target.hasAttribute('dev'):
            qemu_target = ''
            if source.hasAttribute('file'):
                qemu_target = source.getAttribute('file')
            elif source.hasAttribute('dev'):
                qemu_target = source.getAttribute('dev')
            elif source.hasAttribute('protocol') and \
                    source.hasAttribute('name'):  # For rbd network
                qemu_target = '%s:%s' % (
                        source.getAttribute('protocol'),
                        source.getAttribute('name'))
            if qemu_target:
                disks[target.getAttribute('dev')] = {
                    'file': qemu_target}
    for dev in disks:
        try:
            hypervisor = __salt__['config.get']('libvirt:hypervisor', 'kvm')
            if hypervisor not in ['qemu', 'kvm']:
                break

            output = []
            qemu_output = subprocess.Popen(['qemu-img', 'info',
                disks[dev]['file']],
                shell=False,
                stdout=subprocess.PIPE).communicate()[0]
            snapshots = False
            columns = None
            lines = qemu_output.strip().split('\n')
            for line in lines:
                if line.startswith('Snapshot list:'):
                    snapshots = True
                    continue

                # If this is a copy-on-write image, then the backing file
                # represents the base image
                #
                # backing file: base.qcow2 (actual path: /var/shared/base.qcow2)
                elif line.startswith('backing file'):
                    matches = re.match(r'.*\(actual path: (.*?)\)', line)
                    if matches:
                        output.append('backing file: {0}'.format(matches.group(1)))
                    continue

                elif snapshots:
                    if line.startswith('ID'):  # Do not parse table headers
                        line = line.replace('VM SIZE', 'VMSIZE')
                        line = line.replace('VM CLOCK', 'TIME VMCLOCK')
                        columns = re.split(r'\s+', line)
                        columns = [c.lower() for c in columns]
                        output.append('snapshots:')
                        continue
                    fields = re.split(r'\s+', line)
                    for i, field in enumerate(fields):
                        sep = ' '
                        if i == 0:
                            sep = '-'
                        output.append(
                            '{0} {1}: "{2}"'.format(
                                sep, columns[i], field
                            )
                        )
                    continue
                output.append(line)
            output = '\n'.join(output)
            disks[dev].update(yaml.safe_load(output))
        except TypeError:
            disks[dev].update(yaml.safe_load('image: Does not exist'))
    return disks
开发者ID:jslatts,项目名称:salt,代码行数:91,代码来源:virt.py


示例6: get_disks

def get_disks(vm_):
    """
    Return the disks of a named vm

    CLI Example::

        salt '*' virt.get_disks <vm name>
    """
    disks = {}
    doc = minidom.parse(_StringIO(get_xml(vm_)))
    for elem in doc.getElementsByTagName("disk"):
        sources = elem.getElementsByTagName("source")
        targets = elem.getElementsByTagName("target")
        if len(sources) > 0:
            source = sources[0]
        else:
            continue
        if len(targets) > 0:
            target = targets[0]
        else:
            continue
        if target.hasAttribute("dev"):
            qemu_target = ""
            if source.hasAttribute("file"):
                qemu_target = source.getAttribute("file")
            elif source.hasAttribute("dev"):
                qemu_target = source.getAttribute("dev")
            elif source.hasAttribute("protocol") and source.hasAttribute("name"):  # For rbd network
                qemu_target = "%s:%s" % (source.getAttribute("protocol"), source.getAttribute("name"))
            if qemu_target:
                disks[target.getAttribute("dev")] = {"file": qemu_target}
    for dev in disks:
        try:
            hypervisor = __salt__["config.get"]("libvirt:hypervisor", "qemu")
            if hypervisor not in ["qemu", "kvm"]:
                break

            output = []
            qemu_output = subprocess.Popen(
                ["qemu-img", "info", disks[dev]["file"]], shell=False, stdout=subprocess.PIPE
            ).communicate()[0]
            snapshots = False
            columns = None
            lines = qemu_output.strip().split("\n")
            for line in lines:
                if line.startswith("Snapshot list:"):
                    snapshots = True
                    continue
                elif snapshots:
                    if line.startswith("ID"):  # Do not parse table headers
                        line = line.replace("VM SIZE", "VMSIZE")
                        line = line.replace("VM CLOCK", "TIME VMCLOCK")
                        columns = re.split(r"\s+", line)
                        columns = [c.lower() for c in columns]
                        output.append("snapshots:")
                        continue
                    fields = re.split(r"\s+", line)
                    for i, field in enumerate(fields):
                        sep = " "
                        if i == 0:
                            sep = "-"
                        output.append('{0} {1}: "{2}"'.format(sep, columns[i], field))
                    continue
                output.append(line)
            output = "\n".join(output)
            disks[dev].update(yaml.safe_load(output))
        except TypeError:
            disks[dev].update(yaml.safe_load("image: Does not exist"))
    return disks
开发者ID:sijis,项目名称:salt,代码行数:69,代码来源:virt.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python _compat.urlparse函数代码示例发布时间:2022-05-27
下一篇:
Python salome.salome_init函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap