def __init__(self, name, root, tpl, addr, gw, cpus=None): self.name = name self.root = root self.addr = addr self.gw = gw self.tpl = tpl self.mac = gen_mac() self.started = False self.cpus = cpus self.rpc = None vms.append(self)
def main(): parser = argparse.ArgumentParser(description="Create template") parser.add_argument("--path", required=True, help="path to store config") parser.add_argument("--name", required=True, help="container name") parser.add_argument("--root", required=True, help="rootfs location") parser.add_argument("--mac", default="random", help="mac address") parser.add_argument("--gw", default="172.16.5.1", help="default gaeway") parser.add_argument("--addr", default="172.16.5.10/24", help="ipv4 address") args = parser.parse_args() print("passed args:", args) if args.mac == "random": args.mac = gen_mac() print(args.mac) with open(args.path + "/config", "w") as fd: cfg = TPL.format(**vars(args)) fd.write(cfg)