Question

I would like to know if there is an equivalent option of "--block-device-mapping" in ec2-run-instances command line to attach ephemeral disks on AWS instances with the fog library.

There is a reference on BlockDeviceMappings in the fog source code. But since the documentation is a bit terse and I'm not a ruby expert, any help will be welcome!

Was it helpful?

Solution

Looks like the command line equates to <devicename>=<blockdevice>. So we should be able to do that in fog in one of a couple ways. The model version using your values would be something like:

compute = Fog::Compute.new(...)

compute.servers.create(
  :block_device_mapping => [
    { 'deviceName' => '/dev/sdb', 'virtualName' => 'ephemeral0' },
    { 'deviceName' => '/dev/sdc', 'virtualName' => 'ephemeral1' },
    { 'deviceName' => '/dev/sdd', 'virtualName' => 'ephemeral2' },
    { 'deviceName' => '/dev/sde', 'virtualName' => 'ephemeral3' },
  ],
  :image_id => 'ami-xxxxxxxx'
)

Or the lower level, more direct path might look like:

compute.run_instances(
  'ami-xxxxxxxx',
  1,
  1,
  :block_device_mapping => [
    { 'deviceName' => '/dev/sdb', 'virtualName' => 'ephemeral0' },
    { 'deviceName' => '/dev/sdc', 'virtualName' => 'ephemeral1' },
    { 'deviceName' => '/dev/sdd', 'virtualName' => 'ephemeral2' },
    { 'deviceName' => '/dev/sde', 'virtualName' => 'ephemeral3' },
  ]
)

I would recommend the higher-level one as it is a bit easier to use/understand (and sets some nice defaults for you). Hopefully that gets closer to a good solution for you, but happy to continue discussing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top