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


Python XMLBuilder.host方法代码示例

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


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

示例1: build_network_xml

# 需要导入模块: from xmlbuilder import XMLBuilder [as 别名]
# 或者: from xmlbuilder.XMLBuilder import host [as 别名]
    def build_network_xml(self, network):
        """
        :type network: Network
            :rtype : String
        """
        network_xml = XMLBuilder('network')
        network_xml.name(self._get_name(
            network.environment and network.environment.name or '',
            network.name))
        if not (network.forward is None):
            network_xml.forward(mode=network.forward)
        if not (network.ip_network is None):
            ip_network = IPNetwork(network.ip_network)
            with network_xml.ip(address=str(ip_network[1]), prefix=str(ip_network.prefixlen)):
                if network.has_pxe_server:
                    network_xml.tftp(root=network.tftp_root_dir)
                if network.has_dhcp_server:
                    with network_xml.dhcp:
                        network_xml.range(start=str(network.ip_pool_start),
                                          end=str(network.ip_pool_end))
                        for interface in network.interfaces:
                            for address in interface.addresses:
                                if IPAddress(address.ip_address) in ip_network:
                                    network_xml.host(
                                        mac=str(interface.mac_address),
                                        ip=str(address.ip_address),
                                        name=interface.node.name
                                    )
                        if network.has_pxe_server:
                            network_xml.bootp(file="pxelinux.0")

        return str(network_xml)
开发者ID:korshenin,项目名称:devops,代码行数:34,代码来源:libvirt_xml_builder.py

示例2: build_network_xml

# 需要导入模块: from xmlbuilder import XMLBuilder [as 别名]
# 或者: from xmlbuilder.XMLBuilder import host [as 别名]
    def build_network_xml(self, network):
        """Generate network XML

        :type network: Network
            :rtype : String
        """
        network_xml = XMLBuilder('network')
        network_xml.name(self._get_name(
            network.environment and network.environment.name or '',
            network.name))

        stp_val = 'off'
        if self.driver.stp:
            stp_val = 'on'
        network_xml.bridge(
            name="fuelbr{0}".format(network.id),
            stp=stp_val, delay="0")

        if network.forward is not None:
            network_xml.forward(mode=network.forward)
        if network.ip_network is not None:
            ip_network = IPNetwork(network.ip_network)
            with network_xml.ip(
                    address=str(ip_network[1]),
                    prefix=str(ip_network.prefixlen)):
                if network.has_pxe_server:
                    network_xml.tftp(root=network.tftp_root_dir)
                if network.has_dhcp_server:
                    with network_xml.dhcp:
                        network_xml.range(start=str(network.ip_pool_start),
                                          end=str(network.ip_pool_end))
                        for interface in network.interfaces:
                            for address in interface.addresses:
                                if IPAddress(address.ip_address) in ip_network:
                                    network_xml.host(
                                        mac=str(interface.mac_address),
                                        ip=str(address.ip_address),
                                        name=interface.node.name
                                    )
                        if network.has_pxe_server:
                            network_xml.bootp(file="pxelinux.0")

        return str(network_xml)
开发者ID:asledzinskiy,项目名称:fuel-devops,代码行数:45,代码来源:libvirt_xml_builder.py

示例3: build_network_xml

# 需要导入模块: from xmlbuilder import XMLBuilder [as 别名]
# 或者: from xmlbuilder.XMLBuilder import host [as 别名]
    def build_network_xml(self, network):
        network_xml = XMLBuilder('network')
        network_xml.name(network.id)
        if not network.forward is None:
            network_xml.forward(mode=network.forward)

        if hasattr(network, 'ip_addresses') and not network.ip_addresses is None:
            with network_xml.ip(
                address=str(network.ip_addresses[1]),
                prefix=str(network.ip_addresses.prefixlen)
            ):
                if network.pxe:
                    network_xml.tftp(root=network.tftp_root_dir)
                if network.dhcp_server:
                    with network_xml.dhcp:
                        if hasattr(network, 'dhcp_dynamic_address_start'):
                            start = network.dhcp_dynamic_address_start
                        else:
                            start = network.ip_addresses[2]

                        if hasattr(network, 'dhcp_dynamic_address_end'):
                            end = network.dhcp_dynamic_address_end
                        else:
                            end = network.ip_addresses[
                                network.ip_addresses.numhosts - 2]
                        allowed_addresses = list(network.ip_addresses)[2: network.ip_addresses.numhosts - 2]
                        network_xml.range(start=str(start), end=str(end))
                        for interface in network.interfaces:
                            address = find(
                                lambda ip: ip in allowed_addresses,
                                interface.ip_addresses)
                            if address and interface.mac_address:
                                network_xml.host(
                                    mac=str(interface.mac_address),
                                    ip=str(address), name=interface.node.name)
                        if network.pxe:
                            network_xml.bootp(file="pxelinux.0")

        return str(network_xml)
开发者ID:akolinko,项目名称:product,代码行数:41,代码来源:libvirt.py

示例4: update_dhcpd

# 需要导入模块: from xmlbuilder import XMLBuilder [as 别名]
# 或者: from xmlbuilder.XMLBuilder import host [as 别名]
 def update_dhcpd(self):
   mac = re.sub('-',':',self.fuel['mac'])
   fuel = self.fuel
   ip = vlans[self.vlan]['network']
   filename = "/tmp/deploy." + str(os.getpid())
   x = XMLBuilder('network')
   x.name("lab" + str(self.vlan))
   x.bridge(name = "br"+self.vlan, stp="off", delay="0")
   with x.forward(mode = "route", dev="eth0"):
     x.interface(dev="eth0")
   with x.ip(address = str(ip.ip+1), netmask="255.255.255.192"):
     with x.dhcp:
       x.host(mac=mac, ip=str(ip.ip+2))
       x.bootp(file="pxelinux.0")
     x.tftp(root="/var/lib/tftpboot")
   print str(x)+"\n"
   f=open(filename,"w")
   f.write(str(x)+"\n")
   f.close()
   os.system("sudo ifconfig br%s down" % self.vlan)
   os.system("virsh net-destroy lab%s" % self.vlan)
   os.system("virsh net-create %s" % filename)
   os.system("sudo brctl addif br%s eth1.%s" % (self.vlan, self.vlan))
开发者ID:Mirantis,项目名称:puppet-manifests,代码行数:25,代码来源:deploy.py


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