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))
def build_node_xml(self, node, spec): node_xml = XMLBuilder("domain", type=spec.hypervisor) node_xml.name(node.id) node_xml.vcpu(str(node.cpu)) node_xml.memory(str(node.memory * 1024), unit='KiB') with node_xml.os: node_xml.type(spec.os_type, arch=node.arch) for boot_dev in node.boot: if boot_dev == 'disk': node_xml.boot(dev="hd") else: node_xml.boot(dev=boot_dev) ide_disk_names = deque( ['hd' + c for c in list('abcdefghijklmnopqrstuvwxyz')]) serial_disk_names = deque( ['sd' + c for c in list('abcdefghijklmnopqrstuvwxyz')]) def disk_name(bus='ide'): if str(bus) == 'ide': return ide_disk_names.popleft() return serial_disk_names.popleft() with node_xml.devices: node_xml.emulator(spec.emulator) if len(node.disks) > 0: node_xml.controller(type="ide") for disk in node.disks: with node_xml.disk(type="file", device="disk"): node_xml.driver( name="qemu", type=disk.format, cache="unsafe") node_xml.source(file=disk.path) node_xml.target(dev=disk_name(disk.bus), bus=disk.bus) if node.cdrom: with node_xml.disk(type="file", device="cdrom"): node_xml.driver(name="qemu", type="raw") node_xml.source(file=node.cdrom.isopath) node_xml.target( dev=disk_name(node.cdrom.bus), bus=node.cdrom.bus) for interface in node.interfaces: with node_xml.interface(type="network"): node_xml.source(network=interface.network.id) if not (interface.type is None): node_xml.model(type=interface.type) for interface in node.bridged_interfaces: with node_xml.interface(type="bridge"): node_xml.source(bridge=interface.bridge) if not (interface.type is None): node_xml.model(type=interface.type) if node.vnc: node_xml.graphics(type='vnc', listen='0.0.0.0', autoport='yes') return str(node_xml)
def build_node_xml(self, node, spec): node_xml = XMLBuilder("domain", type=spec.hypervisor) node_xml.name(node.id) node_xml.vcpu(str(node.cpu)) node_xml.memory(str(node.memory * 1024), unit='KiB') with node_xml.os: node_xml.type(spec.os_type, arch=node.arch) for boot_dev in node.boot: if boot_dev == 'disk': node_xml.boot(dev="hd") else: node_xml.boot(dev=boot_dev) ide_disk_names = deque( ['hd' + c for c in list('abcdefghijklmnopqrstuvwxyz')]) serial_disk_names = deque( ['sd' + c for c in list('abcdefghijklmnopqrstuvwxyz')]) def disk_name(bus='ide'): if str(bus) == 'ide': return ide_disk_names.popleft() return serial_disk_names.popleft() with node_xml.devices: node_xml.emulator(spec.emulator) if len(node.disks) > 0: node_xml.controller(type="ide") for disk in node.disks: with node_xml.disk(type="file", device="disk"): node_xml.driver(name="qemu", type=disk.format, cache="unsafe") node_xml.source(file=disk.path) node_xml.target(dev=disk_name(disk.bus), bus=disk.bus) if node.cdrom: with node_xml.disk(type="file", device="cdrom"): node_xml.driver(name="qemu", type="raw") node_xml.source(file=node.cdrom.isopath) node_xml.target(dev=disk_name(node.cdrom.bus), bus=node.cdrom.bus) for interface in node.interfaces: with node_xml.interface(type="network"): node_xml.source(network=interface.network.id) if not (interface.type is None): node_xml.model(type=interface.type) for interface in node.bridged_interfaces: with node_xml.interface(type="bridge"): node_xml.source(bridge=interface.bridge) if not (interface.type is None): node_xml.model(type=interface.type) if node.vnc: node_xml.graphics(type='vnc', listen='0.0.0.0', autoport='yes') return str(node_xml)