From 993d34e7d51006060a7daed0ac98e8c1503b06b9 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Tue, 15 Mar 2011 18:28:28 +0100 Subject: [PATCH] Allow labels for NetVM/ProxyVM. Require it in qvm-create. --- dom0/qvm-core/qubes.py | 30 ++++++++++++++++++++++++------ dom0/qvm-tools/qvm-create | 30 ++++++++++++++---------------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/dom0/qvm-core/qubes.py b/dom0/qvm-core/qubes.py index 316c7759..c067e188 100755 --- a/dom0/qvm-core/qubes.py +++ b/dom0/qvm-core/qubes.py @@ -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 diff --git a/dom0/qvm-tools/qvm-create b/dom0/qvm-tools/qvm-create index aa567b98..a16f19ba 100755 --- a/dom0/qvm-tools/qvm-create +++ b/dom0/qvm-tools/qvm-create @@ -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: