Branch: refs/heads/master
  Home:   https://github.com/NixOS/charon
  Commit: c2119e6ac4f3c12996083b664366b689b1990fc4
      
https://github.com/NixOS/charon/commit/c2119e6ac4f3c12996083b664366b689b1990fc4
  Author: Eelco Dolstra <[email protected]>
  Date:   2012-04-25 (Wed, 25 Apr 2012)

  Changed paths:
    M charon/backends/virtualbox.py
    M examples/trivial-vbox.nix
    M nix/options.nix

  Log Message:
  -----------
  Add support for running VirtualBox instances in headless mode

Fixes #16.


diff --git a/charon/backends/virtualbox.py b/charon/backends/virtualbox.py
index ae2a806..9bf01eb 100644
--- a/charon/backends/virtualbox.py
+++ b/charon/backends/virtualbox.py
@@ -21,8 +21,9 @@ def __init__(self, xml):
         MachineDefinition.__init__(self, xml)
         x = xml.find("attrs/attr[@name='virtualbox']/attrs")
         assert x is not None
-        self._base_image = 
x.find("attr[@name='baseImage']/string").get("value")
-        self._memory_size = x.find("attr[@name='memorySize']/int").get("value")
+        self.base_image = x.find("attr[@name='baseImage']/string").get("value")
+        self.memory_size = x.find("attr[@name='memorySize']/int").get("value")
+        self.headless = x.find("attr[@name='headless']/bool").get("value") == 
"true"
 
     def make_state():
         return MachineState()
@@ -145,7 +146,7 @@ def create(self, defn, check):
 
             disk = vm_dir + "/disk1.vdi"
 
-            base_image = defn._base_image
+            base_image = defn.base_image
             if base_image == "drv":
                 try:
                     base_image = subprocess.check_output(
@@ -190,7 +191,7 @@ def create(self, defn, check):
         if not self._started:
             res = subprocess.call(
                 ["VBoxManage", "modifyvm", self._vm_id,
-                 "--memory", defn._memory_size, "--vram", "10",
+                 "--memory", defn.memory_size, "--vram", "10",
                  "--nictype1", "virtio", "--nictype2", "virtio",
                  "--nic2", "hostonly", "--hostonlyadapter2", "vboxnet0",
                  "--nestedpaging", "off"])
@@ -199,8 +200,8 @@ def create(self, defn, check):
             res = subprocess.call(
                 ["VBoxManage", "guestproperty", "set", self._vm_id, 
"/VirtualBox/GuestInfo/Net/1/V4/IP", ''])
             if res != 0: raise Exception("unable to clear IP address of 
VirtualBox VM ‘{0}’".format(self.name))
-            
-            res = subprocess.call(["VBoxManage", "startvm", self._vm_id])
+
+            res = subprocess.call(["VBoxManage", "startvm", self._vm_id] + 
(["--type", "headless"] if defn.headless else []))
             if res != 0: raise Exception("unable to start VirtualBox VM 
‘{0}’".format(self.name))
 
             self._started = True
diff --git a/examples/trivial-vbox.nix b/examples/trivial-vbox.nix
index 6607c08..0244686 100644
--- a/examples/trivial-vbox.nix
+++ b/examples/trivial-vbox.nix
@@ -1,5 +1,6 @@
 {
   machine =
     { deployment.targetEnv = "virtualbox";
+      #deployment.virtualbox.headless = true;
     };
 }
diff --git a/nix/options.nix b/nix/options.nix
index 56fb8e5..4b77de6 100644
--- a/nix/options.nix
+++ b/nix/options.nix
@@ -320,12 +320,21 @@ in
 
     deployment.virtualbox.memorySize = mkOption {
       default = 512;
-      example = 512;
+      type = types.int;
       description = ''
         Memory size (M) of virtual machine.
       '';
     };
 
+    deployment.virtualbox.headless = mkOption {
+      default = false;
+      description = ''
+        If set, the VirtualBox instance is started in headless mode,
+        i.e., without a visible display on the host's desktop.
+      '';
+    };
+
+    
     # Computed options useful for referring to other machines in
     # network specifications.
 


================================================================

_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits

Reply via email to