def editFiles(mntDir, name, mac): """ Edit files on image @type mntDir: str @param mntDir: mount dir of the VM disk @type name: str @param name: vm name @type mac: str @param mac: mac address @rtype: None @returns: Nothing """ # change hostname print "Image Editing\n\n" print "Changing hostname" hostname = os.path.join(mntDir, "etc/hostname") utils.recordFile(name, hostname) # set network as dhcp print "Set network as DHCP" netconfig = os.path.join(mntDir, "etc/sysconfig/network-scripts/ifcfg-eth0") content = utils.readFile(netconfig) bootproto = re.search("BOOTPROTO=.*",content).group(0) if "dhcp" not in bootproto: utils.sedFile(bootproto, "BOOTPROTO=dhcp", netconfig) # print ip used print "IP: " + IP[mac] print "root password: 60fb619414782814d344e9a08d77101ce31057fec58f35643ad167cf67c5e128ea66c750d08282633bb432619c146e0543ae8d61b885902b9f61302b537aaf07" commom.printSSHPort(mntDir)
def editFiles(mntDir, name, mac): """ Edit files on image @type mntDir: str @param mntDir: mount dir of the VM disk @type name: str @param name: vm name @type mac: str @param mac: mac address @rtype: None @returns: Nothing """ # change hostname print "Image Editing\n\n" print "Changing hostname" hostname = os.path.join(mntDir, "etc/hostname") utils.recordFile(name, hostname) # set network as dhcp print "Set network as DHCP" netconfig = os.path.join(mntDir, "etc/sysconfig/network/ifcfg-eth0") content = utils.readFile(netconfig) bootproto = re.search("BOOTPROTO=.*",content).group(0) if "dhcp" not in bootproto: utils.sedFile(bootproto, "BOOTPROTO=dhcp", netconfig) # print ip used print "IP: " + IP[mac] print "root password: 39af21a2ac52f3d5d0df3400c78342b2af80010e0bf3eb5d9e4a9fb931f0ea13904019853568d66d8428265e43e1d237339fda6f9056cc8eca8a582734e3ee8c" commom.printSSHPort(mntDir)
def editFiles(mntDir, name, mac): """ Edit files on image @type mntDir: str @param mntDir: mount dir of the VM disk @type name: str @param name: vm name @type mac: str @param mac: mac address @rtype: None @returns: Nothing """ # change hostname print "Image Editing\n\n" print "Changing hostname" hostname = os.path.join(mntDir, "etc/hostname") utils.recordFile(name, hostname) # set network as dhcp print "Set network as static" netconfig = os.path.join(mntDir, "etc/network/interfaces") fd = open(netconfig, "a") fd.write("\n" + INTERFACES_CONFIG % {"ip":IP[mac]}) fd.close() # set dns server dnsconfig = os.path.join(mntDir, "etc/resolvconf/resolv.conf.d/tail") if not os.path.exists(os.path.dirname(dnsconfig)): os.makedirs(os.path.dirname(dnsconfig)) fd = open(dnsconfig, "w") fd.write("\n" + RESOLV_CONF) fd.close() # print ip used print "IP: " + IP[mac] print "root password: 481a91e7a60caabd7af6f2ff019d774cfe93376244d46c6347078ea37245890a74dfd6b1559496742b3d117079796e974e858f7a10a216218e1ebc7afc0ea16c" commom.printSSHPort(mntDir)
def createLibvirtXML(name, mac, img, template): """ Creates, define and start VM XML @type name: str @param name: vm name @type mac: str @param mac: mac address of the new VM @type img: str @param img: img path @type template: str @param template: template name @rtype: None @returns: Nothing """ # fill xml file template = os.path.join(os.getcwd(), "distros/", template) newXML = utils.readFile(template) newXML = newXML % {"name": name, "disk_path": img, "mac_address": mac } # write xml file tmpfile = tempfile.mkstemp()[1] utils.recordFile(newXML, tmpfile) # define vm print "Defining new VM %s" % name if 0 != os.system(DEFINE_VM % tmpfile): print "Cannot define %s" % tmpfile sys.exit(1) os.system("rm -f %s" % tmpfile) # start vm os.system(START_VM % name) os.system(AUTOSTART % name)
def editFiles(mntDir, name, mac): """ Edit files on image @type mntDir: str @param mntDir: mount dir of the VM disk @type name: str @param name: vm name @type mac: str @param mac: mac address @rtype: None @returns: Nothing """ # change hostname print "Image Editing\n\n" print "Changing hostname" hostname = os.path.join(mntDir, "etc/hostname") utils.recordFile(name, hostname) # set network as dhcp print "Set network as static" netconfig = os.path.join(mntDir, "etc/network/interfaces") fd = open(netconfig, "a") fd.write("\n" + INTERFACES_CONFIG % {"ip":IP[mac]}) fd.close() # allow password authentication on ssh utils.sedFile("without-password", "yes", os.path.join(mntDir, "etc/ssh/sshd_config")) # print ip used print "IP: " + IP[mac] print "root password: 60fb619414782814d344e9a08d77101ce31057fec58f35643ad167cf67c5e128ea66c750d08282633bb432619c146e0543ae8d61b885902b9f61302b537aaf07" commom.printSSHPort(mntDir)