0

挖掘代码(例如考虑this),我发现我可以使用以下方法读取属性:

instance.block_device_mapping['/dev/sdz'].delete_on_termination

...并使用以下方法切换它:

instance.modify_attribute('blockdevicemapping', ['/dev/sdz=1']) # toggle on
instance.modify_attribute('blockdevicemapping', ['/dev/sdz']) # toggle off

但它是不对称的,我觉得我缺少一些更高级别的功能。

不应该更像:

block_device_type = instance.block_device_mapping['/dev/sdz']
block_device_type.delete_on_termination = True
block_device_type.save() # I made this API up

?

4

1 回答 1

3

You turn this setting on and off with a list of the formatted string '%s=%d'.

Switch to on

>>> inst.modify_attribute('blockDeviceMapping', ['/dev/sda1=1'])

Switch to off

>>> inst.modify_attribute('blockDeviceMapping', ['/dev/sda1=0'])

I verified changes outside of python after each attempt to change the setting using:

$ aws ec2 describe-instance-attribute --instance-id i-7890abcd --attribute blockDeviceMapping
  1. Calling inst.modify_attribute('blockDeviceMapping', ['/dev/sda1']) (the string lacks =0) did not produce any change.
  2. Assigning to inst.block_device_mapping['/dev/sda1'].delete_on_termination also did not produce any change.

After calling modify_attribute, the value of delete_on_termination on local block device objects is unchanged.


I walk through the whole process at:
http://f06mote.com/post/77239804736/amazon-ec2-instance-safety-tweak-turn-off-delete-on

于 2014-02-20T03:47:18.643 回答