Example #1
0
    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)
Example #2
0
    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)
    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)
    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)
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
 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))