From ef6a3e576b3cd591821792e16adf47de02bdf1e3 Mon Sep 17 00:00:00 2001 From: Marek Marczykowski Date: Wed, 16 Mar 2011 13:39:54 -0400 Subject: [PATCH] Parse tags %MEM% and %VCPUS% in {app,net}vm-template.conf (#115) --- dom0/qvm-core/qubes.py | 35 +++++++++++++++++++++++++++++++++-- dom0/qvm-tools/qvm-create | 11 +++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/dom0/qvm-core/qubes.py b/dom0/qvm-core/qubes.py index 65c56b75..13722c18 100755 --- a/dom0/qvm-core/qubes.py +++ b/dom0/qvm-core/qubes.py @@ -68,6 +68,8 @@ default_templatevm_conf_template = "templatevm.conf" # needed for TemplateVM clo default_appmenus_templates_subdir = "apps.templates" default_kernels_subdir = "kernels" default_firewall_conf_file = "firewall.xml" +default_memory = 400 +default_servicevm_vcpus = 1 # do not allow to start a new AppVM if Dom0 mem was to be less than this dom0_min_memory = 700*1024*1024 @@ -174,7 +176,9 @@ class QubesVm(object): netvm_vm = None, installed_by_rpm = False, updateable = False, - label = None): + label = None, + memory = default_memory, + vcpus = None): assert qid < qubes_max_qid, "VM id out of bounds!" @@ -209,6 +213,15 @@ class QubesVm(object): # PCI devices - used only by NetVM self.pcidevs = "" + self.memory = memory + + # By default allow use all VCPUs + if vcpus is None: + qubes_host = QubesHost() + self.vcpus = qubes_host.no_cpus + else: + self.vcpus = vcpus + if not dry_run and xend_session.session is not None: self.refresh_xend_session() @@ -685,9 +698,13 @@ class QubesTemplateVm(QubesVm): conf_templatevm_template = open (src_template_vm.templatevm_conf_template, "r") conf_file = open(self.conf_file, "w") rx_templatename = re.compile (r"%TEMPLATENAME%") + rx_mem = re.compile (r"%MEM%") + rx_vcpus = re.compile (r"%VCPUS%") for line in conf_templatevm_template: line = rx_templatename.sub (self.name, line) + line = rx_mem.sub (str(self.memory), line) + line = rx_vcpus.sub (str(self.vcpus), line) conf_file.write(line) conf_templatevm_template.close() @@ -906,12 +923,16 @@ class QubesCowVm(QubesVm): rx_vmdir = re.compile (r"%VMDIR%") rx_template = re.compile (r"%TEMPLATEDIR%") rx_pcidevs = re.compile (r"%PCIDEVS%") + rx_mem = re.compile (r"%MEM%") + rx_vcpus = re.compile (r"%VCPUS%") for line in conf_template: line = rx_vmname.sub (self.name, line) line = rx_vmdir.sub (self.dir_path, line) line = rx_template.sub (self.template_vm.dir_path, line) line = rx_pcidevs.sub (self.pcidevs, line) + line = rx_mem.sub (str(self.memory), line) + line = rx_vcpus.sub (str(self.vcpus), line) conf_appvm.write(line) conf_template.close() @@ -1036,6 +1057,9 @@ class QubesNetVm(QubesCowVm): if "label" not in kwargs or kwargs["label"] is None: kwargs["label"] = default_servicevm_label + + if "vcpus" not in kwargs or kwargs["vcpus"] is None: + kwargs["vcpus"] = default_servicevm_vcpus super(QubesNetVm, self).__init__(**kwargs) @property @@ -1117,6 +1141,8 @@ class QubesNetVm(QubesCowVm): private_img=self.private_img, installed_by_rpm=str(self.installed_by_rpm), label=self.label.name, + memory=str(self.memory), + vcpus=str(self.vcpus), ) return element @@ -1262,6 +1288,8 @@ class QubesProxyVm(QubesNetVm): private_img=self.private_img, installed_by_rpm=str(self.installed_by_rpm), label=self.label.name, + memory=str(self.memory), + vcpus=str(self.vcpus), ) return element @@ -1507,7 +1535,10 @@ class QubesAppVm(QubesCowVm): private_img=self.private_img, installed_by_rpm=str(self.installed_by_rpm), updateable=str(self.updateable), - label=self.label.name) + label=self.label.name, + memory=str(self.memory), + vcpus=str(self.vcpus), + ) return element def start(self, debug_console = False, verbose = False, preparing_dvm = False): diff --git a/dom0/qvm-tools/qvm-create b/dom0/qvm-tools/qvm-create index a16f19ba..efdf7aae 100755 --- a/dom0/qvm-tools/qvm-create +++ b/dom0/qvm-tools/qvm-create @@ -57,6 +57,10 @@ def main(): help="Create ProxyVM") parser.add_option ("-n", "--net", action="store_true", dest="netvm", default=False, help="Create NetVM") + parser.add_option ("-m", "--mem", dest="mem", default=None, + help="Initial memory size (in MB)") + parser.add_option ("-c", "--vcpus", dest="vcpus", default=None, + help="VCPUs count") parser.add_option ("-q", "--quiet", action="store_false", dest="verbose", default=True) (options, args) = parser.parse_args () @@ -127,6 +131,13 @@ def main(): vm = qvm_collection.add_new_proxyvm(vmname, template_vm, label = label) else: vm = qvm_collection.add_new_appvm(vmname, template_vm, label = label) + + if options.mem is not None: + vm.memory = options.mem + + if options.vcpus is not None: + vm.vcpus = options.vcpus + try: vm.create_on_disk(verbose=options.verbose) vm.add_to_xen_storage()