Mercurial > hg > Applications > virsh-wrapper
view vagrant_newvm.py @ 24:e372e7648da0
remove test vms, and add managers vms
author | taiki <taiki@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 21 Jul 2014 09:05:59 -1000 |
parents | fb9f3738a8e6 |
children |
line wrap: on
line source
#!/usr/bin/python # -*- encoding: utf-8 -*- import shutil import sys,os from optparse import OptionParser FILE = "metadata.json" PROVIDER_VB = "virtualbox" PROVIDER_KVM = "kvm" BASE_DIR = "/root/.vagrant.d/boxes/" # read json file # return list of file contents def change_kvm_metadata(): box_base = os.path.join(BASE_DIR, name) dir_name = os.path.join(box_base, PROVIDER_KVM) return os.path.join(dir_name, FILE) def read_metadata_json(): metadata = change_kvm_metadata() f = open(metadata, 'r') result = [] for l in f: result.append(l) f.close() return result # write json file def write_metadata_json(data): metadata = change_kvm_metadata() f = open(metadata, 'w') for l in data: f.write(l) f.close() def replace_data(data): data1 = [] for l in data: if 'provider' in l: data1.append(l.replace(PROVIDER_VB, PROVIDER_KVM)) else: data1.append(l) return data1 def fix_provider_name(name): box_base = os.path.join(BASE_DIR, name) before_name = os.path.join(box_base, PROVIDER_VB) if not os.path.exists(before_name): print(before_name + "not found.") return after_name = os.path.join(box_base, PROVIDER_KVM) shutil.move(before_name, after_name) parser = OptionParser() parser.add_option("-n", "--name", dest="name", help="VM name") (options, args) = parser.parse_args() name = options.name fix_provider_name(name) data = read_metadata_json() data1 = replace_data(data) write_metadata_json(data1)