如何使用雾库运行带有附加临时磁盘的AWS实例

时间:2013-06-20 18:07:23

标签: ruby amazon-web-services amazon-ec2 fog

我想知道ec2-run-instances命令行中是否存在“--block-device-mapping”的等效选项,以便在具有雾库的AWS实例上附加短暂磁盘。

雾源代码中有BlockDeviceMappings的引用。但由于文档有点简洁,我不是红宝石专家,欢迎任何帮助!

1 个答案:

答案 0 :(得分:2)

看起来命令行等于<devicename>=<blockdevice>。所以我们应该能够通过几种方式在雾中做到这一点。使用您的值的模型版本将类似于:

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'
)

或者更低级别,更直接的路径可能如下所示:

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' },
  ]
)

我会推荐更高级别的,因为它更容易使用/理解(并为您设置一些不错的默认值)。希望能为您找到更好的解决方案,但很高兴继续讨论。