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

  Changed paths:
    M charon/backends/ec2.py

  Log Message:
  -----------
  Prevent attaching non-ephemeral devices to /dev/xvd[a-e]

Our initrd does magic things with /dev/xvd[a-e] that you wouldn't want
with an EBS volume.


diff --git a/charon/backends/ec2.py b/charon/backends/ec2.py
index d75f61a..66b8957 100644
--- a/charon/backends/ec2.py
+++ b/charon/backends/ec2.py
@@ -2,6 +2,7 @@
 
 import os
 import sys
+import re
 import time
 import subprocess
 import shutil
@@ -269,6 +270,8 @@ def create(self, defn, check):
             devmap = boto.ec2.blockdevicemapping.BlockDeviceMapping()
             devs_mapped = {}
             for k, v in defn.block_device_mapping.iteritems():
+                if re.match("/dev/sd[a-e]", k) and not 
v['disk'].startswith("ephemeral"):
+                    raise Exception("non-ephemeral disk not allowed on device 
‘{0}’; use /dev/xvdf or higher".format(_sd_to_xvd(k)))
                 if v['disk'] == '':
                     if ami.root_device_type == "ebs":
                         devmap[k] = 
boto.ec2.blockdevicemapping.BlockDeviceType(size=v['size'], 
delete_on_termination=True)
@@ -372,7 +375,7 @@ def create(self, defn, check):
         # Attach missing volumes.
         for k, v in defn.block_device_mapping.iteritems():
             if k not in self._block_device_mapping:
-                print >> sys.stderr, "attaching volume ‘{0}’ to EC2 machine 
‘{1}’ as ‘{2}’...".format(v['disk'], self.name, k)
+                print >> sys.stderr, "attaching volume ‘{0}’ to EC2 machine 
‘{1}’ as ‘{2}’...".format(v['disk'], self.name, _sd_to_xvd(k))
                 self.connect()
                 if v['disk'].startswith("vol-"):
                     self._conn.attach_volume(v['disk'], self._instance_id, k)
@@ -383,10 +386,10 @@ def create(self, defn, check):
 
         for k, v in self._block_device_mapping.items():
             if v.get('needsAttach', False):
-                print >> sys.stderr, "attaching volume ‘{0}’ to EC2 machine 
‘{1}’ as ‘{2}’...".format(v['volumeId'], self.name, k)
+                print >> sys.stderr, "attaching volume ‘{0}’ to EC2 machine 
‘{1}’ as ‘{2}’...".format(v['volumeId'], self.name, _sd_to_xvd(k))
                 self.connect()
 
-                volume_tags = {'Name': "{0} [{1} - 
{2}]".format(self.depl.description, self.name, k)}
+                volume_tags = {'Name': "{0} [{1} - 
{2}]".format(self.depl.description, self.name, _sd_to_xvd(k))}
                 volume_tags.update(common_tags)
                 self._conn.create_tags([v['volumeId']], volume_tags)
                 
@@ -404,7 +407,7 @@ def check_dev():
         # Detach volumes that are no longer in the deployment spec.
         for k, v in self._block_device_mapping.items():
             if k not in defn.block_device_mapping:
-                print >> sys.stderr, "detaching device ‘{0}’ from EC2 machine 
‘{1}’...".format(k, self.name)
+                print >> sys.stderr, "detaching device ‘{0}’ from EC2 machine 
‘{1}’...".format(_sd_to_xvd(k), self.name)
                 self.connect()
                 volumes = self._conn.get_all_volumes([], 
filters={'attachment.instance-id': self._instance_id, 'attachment.device': k})
                 assert len(volumes) <= 1
@@ -423,7 +426,7 @@ def check_dev():
         # Format volumes that need it.
         for k, v in self._block_device_mapping.items():
             if v.get('needsInit', None) == 1:
-                print >> sys.stderr, "formatting device ‘{0}’ on EC2 machine 
‘{1}’...".format(k, self.name)
+                print >> sys.stderr, "formatting device ‘{0}’ on EC2 machine 
‘{1}’...".format(_sd_to_xvd(k), self.name)
                 self.run_command("mkfs.{0} {1}".format(v['fsType'], 
_sd_to_xvd(k)))
                 del v['needsInit']
                 self.write()


================================================================
  Commit: 86a59f8920df184223182a090916756592e842ba
      
https://github.com/NixOS/charon/commit/86a59f8920df184223182a090916756592e842ba
  Author: Eelco Dolstra <[email protected]>
  Date:   2012-04-13 (Fri, 13 Apr 2012)

  Changed paths:
    M nix/options.nix

  Log Message:
  -----------
  Allow EC2 disks to be specified in "fileSystems"

Example (to create a 1 GiB ext4 EBS volume on /data):

  fileSystems =
    [ { mountPoint = "/data";
    autocreate = true;
    device = "/dev/xvdf";
    ec2.size = 1;
  }
    ];

This is short for:

  fileSystems =
    [ { mountPoint = "/data";
    autocreate = true;
    device = "/dev/xvdf";
  }
    ];

  deployment.ec2.blockDeviceMapping."/dev/xvdf".size = 1;

And a shoutout to Nicolas Pierron for allowing options to be extended
across modules :-)


diff --git a/nix/options.nix b/nix/options.nix
index ea6e50d..f9f2cdb 100644
--- a/nix/options.nix
+++ b/nix/options.nix
@@ -2,7 +2,45 @@
 
 with pkgs.lib;
 
-let cfg = config.deployment; in
+let
+
+  cfg = config.deployment;
+
+  ec2DiskOptions = {
+      
+    disk = mkOption {
+      default = "";
+      example = "vol-d04895b8";
+      type = types.uniq types.string;
+      description = ''
+        EC2 identifier of the disk to be mounted.  This can be an
+        ephemeral disk (e.g. <literal>ephemeral0</literal>), a
+        snapshot ID (e.g. <literal>snap-1cbda474</literal>) or a
+        volume ID (e.g. <literal>vol-d04895b8</literal>).  Leave
+        empty to create an EBS volume automatically.
+      '';
+    };
+
+    size = mkOption {
+      default = 0;
+      type = types.uniq types.int;
+      description = ''
+        Filesystem size (in gigabytes) for automatically created
+        EBS volumes.
+      '';
+    };
+
+    fsType = mkOption {
+      default = "ext4";
+      type = types.uniq types.string;
+      description = ''
+        Filesystem type for automatically created EBS volumes.
+      '';
+    };
+
+  };
+
+in
 
 {
   options = {
@@ -144,44 +182,27 @@ let cfg = config.deployment; in
       default = { };
       example = { "/dev/xvdb".disk = "ephemeral0"; "/dev/xvdg".disk = 
"vol-d04895b8"; };
       type = types.attrsOf types.optionSet;
+      options = ec2DiskOptions;
       description = ''
         Block device mapping.  Currently only supports ephemeral devices.
       '';
+    };
 
+    
+    fileSystems = mkOption {
       options = {
-      
-        disk = mkOption {
-          default = "";
-          example = "vol-d04895b8";
-          type = types.uniq types.string;
+        ec2 = mkOption {
+          default = null;
+          type = types.uniq (types.nullOr types.optionSet);
+          options = ec2DiskOptions;
           description = ''
-            EC2 identifier of the disk to be mounted.  This can be an
-            ephemeral disk (e.g. <literal>ephemeral0</literal>), a
-            snapshot ID (e.g. <literal>snap-1cbda474</literal>) or a
-            volume ID (e.g. <literal>vol-d04895b8</literal>).  Leave
-            empty to create an EBS volume automatically.
+            EC2 disk to be attached to this mount point.  This is
+            shorthand for defining a separate
+            <option>deployment.ec2.blockDeviceMapping</option>
+            attribute.
           '';
         };
-        
-        size = mkOption {
-          default = 0;
-          type = types.uniq types.int;
-          description = ''
-            Filesystem size (in gigabytes) for automatically created
-            EBS volumes.
-          '';
-        };
-
-        fsType = mkOption {
-          default = "ext4";
-          type = types.uniq types.string;
-          description = ''
-            Filesystem type for automatically created EBS volumes.
-          '';
-        };
-        
       };
-      
     };
 
     
@@ -288,6 +309,14 @@ let cfg = config.deployment; in
         #throw "I don't know an AMI for region ‘${cfg.ec2.region}’ and 
platform type ‘${config.nixpkgs.system}’"
         "");
 
+      blockDeviceMapping = listToAttrs
+        (map (fs: nameValuePair fs.device
+          { disk = fs.ec2.disk;
+            size = fs.ec2.size;
+            fsType = if fs.fsType != "auto" then fs.fsType else fs.ec2.fsType;
+          })
+         (filter (fs: fs.ec2 != null) config.fileSystems));
+
     };
 
     deployment.virtualbox = {


================================================================
  Commit: f1ed6b4f94e9c69bbb60f56be486be787aa5d4c2
      
https://github.com/NixOS/charon/commit/f1ed6b4f94e9c69bbb60f56be486be787aa5d4c2
  Author: Eelco Dolstra <[email protected]>
  Date:   2012-04-13 (Fri, 13 Apr 2012)

  Changed paths:
    A examples/trivial-ec2-ebs.nix

  Log Message:
  -----------
  EBS example


diff --git a/examples/trivial-ec2-ebs.nix b/examples/trivial-ec2-ebs.nix
new file mode 100644
index 0000000..cbc12b2
--- /dev/null
+++ b/examples/trivial-ec2-ebs.nix
@@ -0,0 +1,30 @@
+{
+  machine =
+    { deployment.targetEnv = "ec2";
+      deployment.ec2.region = "eu-west-1";
+      deployment.ec2.instanceType = "m1.small";
+      deployment.ec2.keyPair = "eelco";
+      deployment.ec2.securityGroups = [ "eelco-test" ];
+      deployment.ec2.ebsBoot = true;
+      
+      fileSystems =
+        [ # Mount a 1 GiB EBS volume on /data.  It's created and
+          # formatted when the machine is deployed, and destroyed when
+          # the machine is destroyed.
+          { mountPoint = "/data";
+            autocreate = true;
+            fsType = "ext3"; # default is "ext4"
+            device = "/dev/xvdf";
+            ec2.size = 1;
+          }
+          # Or to mount an existing volume or snapshot:
+          /*
+          { mountPoint = "/data2";
+            autocreate = true;
+            device = "/dev/xvdg";
+            ec2.disk = "snap-b82666d1"; # or "vol-5aa77f32"
+          }
+          */
+        ];
+    };
+}


================================================================
Compare: https://github.com/NixOS/charon/compare/24f8767...f1ed6b4
_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits

Reply via email to