Allow labels for NetVM/ProxyVM. Require it in qvm-create.

This commit is contained in:
Marek Marczykowski 2011-03-15 18:28:28 +01:00
parent 588f4b91c8
commit 993d34e7d5
2 changed files with 38 additions and 22 deletions

View File

@ -1098,6 +1098,7 @@ class QubesNetVm(QubesCowVm):
updateable=str(self.updateable),
private_img=self.private_img,
installed_by_rpm=str(self.installed_by_rpm),
label=self.label.name,
)
return element
@ -1242,6 +1243,7 @@ class QubesProxyVm(QubesNetVm):
netvm_qid=str(self.netvm_vm.qid) if self.netvm_vm is not None else "none",
private_img=self.private_img,
installed_by_rpm=str(self.installed_by_rpm),
label=self.label.name,
)
return element
@ -1593,12 +1595,13 @@ class QubesVmCollection(dict):
def add_new_netvm(self, name, template_vm,
dir_path = None, conf_file = None,
private_img = None):
private_img = None,
label = None):
qid = self.get_new_unused_qid()
netid = self.get_new_unused_netid()
vm = QubesNetVm (qid=qid, name=name, template_vm=template_vm,
netid=netid,
netid=netid, label=label,
private_img=private_img,
dir_path=dir_path, conf_file=conf_file)
@ -1613,12 +1616,13 @@ class QubesVmCollection(dict):
def add_new_proxyvm(self, name, template_vm,
dir_path = None, conf_file = None,
private_img = None):
private_img = None,
label = None):
qid = self.get_new_unused_qid()
netid = self.get_new_unused_netid()
vm = QubesProxyVm (qid=qid, name=name, template_vm=template_vm,
netid=netid,
netid=netid, label=label,
private_img=private_img,
dir_path=dir_path, conf_file=conf_file,
netvm_vm = self.get_default_fw_netvm_vm())
@ -1836,7 +1840,7 @@ class QubesVmCollection(dict):
try:
kwargs = {}
attr_list = ("qid", "netid", "name", "dir_path", "conf_file",
"private_img", "template_qid", "updateable",
"private_img", "template_qid", "updateable", "label",
)
for attribute in attr_list:
@ -1855,6 +1859,13 @@ class QubesVmCollection(dict):
kwargs["template_vm"] = template_vm
kwargs["netid"] = int(kwargs["netid"])
if kwargs["label"] is not None:
if kwargs["label"] not in QubesVmLabels:
print "ERROR: incorrect label for VM '{0}'".format(kwargs["name"])
kwargs.pop ("label")
else:
kwargs["label"] = QubesVmLabels[kwargs["label"]]
vm = QubesNetVm(**kwargs)
self[vm.qid] = vm
@ -1869,7 +1880,7 @@ class QubesVmCollection(dict):
try:
kwargs = {}
attr_list = ("qid", "netid", "name", "dir_path", "conf_file", "updateable",
"private_img", "template_qid")
"private_img", "template_qid", "label")
for attribute in attr_list:
kwargs[attribute] = element.get(attribute)
@ -1887,6 +1898,13 @@ class QubesVmCollection(dict):
kwargs["template_vm"] = template_vm
kwargs["netid"] = int(kwargs["netid"])
if kwargs["label"] is not None:
if kwargs["label"] not in QubesVmLabels:
print "ERROR: incorrect label for VM '{0}'".format(kwargs["name"])
kwargs.pop ("label")
else:
kwargs["label"] = QubesVmLabels[kwargs["label"]]
vm = QubesProxyVm(**kwargs)
self[vm.qid] = vm

View File

@ -67,21 +67,19 @@ def main():
if options.netvm and options.proxyvm:
parser.error ("You must specify at most one of --proxy and --net")
label = None
if not options.proxyvm and not options.netvm:
if options.label is None:
print "You must choose a label for the new VM by passing the --label option."
print "Possible values are:"
for l in QubesVmLabels.values():
print "* {0}".format(l.name)
exit (1)
if options.label is None:
print "You must choose a label for the new VM by passing the --label option."
print "Possible values are:"
for l in QubesVmLabels.values():
print "* {0}".format(l.name)
exit (1)
if options.label not in QubesVmLabels:
print "Wrong label name, supported values are the following:"
for l in QubesVmLabels.values():
print "* {0}".format(l.name)
exit (1)
label = QubesVmLabels[options.label]
if options.label not in QubesVmLabels:
print "Wrong label name, supported values are the following:"
for l in QubesVmLabels.values():
print "* {0}".format(l.name)
exit (1)
label = QubesVmLabels[options.label]
qvm_collection = QubesVmCollection()
qvm_collection.lock_db_for_writing()
@ -113,7 +111,7 @@ def main():
vm = None
if options.netvm:
vm = qvm_collection.add_new_netvm(vmname, template_vm)
vm = qvm_collection.add_new_netvm(vmname, template_vm, label = label)
net_devices = find_net_devices()
print "Found the following net devices in your system:"
@ -126,7 +124,7 @@ def main():
vm.pcidevs = dev_str
elif options.proxyvm:
vm = qvm_collection.add_new_proxyvm(vmname, template_vm)
vm = qvm_collection.add_new_proxyvm(vmname, template_vm, label = label)
else:
vm = qvm_collection.add_new_appvm(vmname, template_vm, label = label)
try: