Brian Racer
2013-04-16 23:24:29 UTC
Just a heads up you need to add "'virtualName' => 'VirtualName'," to the
name_mapping hash.
name_mapping hash.
I wasn't able to get it to start up with the larger volume, but i was able
to get something similar done by using aws command line tools.
Thanks for your help!
-karl
your
device> on
to get something similar done by using aws command line tools.
Thanks for your help!
-karl
That looks about right to me. I would probably take a running version
of it and do a lookup (so that I could see the format of the block
device mapping). Then you can shut it down and restart with the same
block device mapping setting (with a modified size attribute). I
think that is all it should take on the api side, though as peter
mentioned you may need to run stuff on the instance itself so that it
will recognize the change properly.
Thanks!
wes
mayof it and do a lookup (so that I could see the format of the block
device mapping). Then you can shut it down and restart with the same
block device mapping setting (with a modified size attribute). I
think that is all it should take on the api side, though as peter
mentioned you may need to run stuff on the instance itself so that it
will recognize the change properly.
Thanks!
wes
Below is a partial code snippet that does something similar, but there
be a easier way. Maybe someone else has something better. Depending on
distribution and version you may need to run resize2fs /dev/<root
the instance once it is up.
def create_instance(connection, options)
image = connection.images.get(options[:ami])
block_device_mapping =
create_block_device_mapping(image.block_device_mapping)
set_root_device_size(block_device_mapping, image.root_device_name,
options[:root_device_size])
server = connection.servers.create(image_id: options[:ami],
flavor_id: options[:flavor],
block_device_mapping,
key_name: options[:name],
groups: options[:name],
'ClientToken' =>
SimpleUUID::UUID.new.to_guid)
connection.tags.create(key: 'Name', value: options[:name],
server.id)
server.wait_for { printf '.'; ready? }
server.wait_for { printf '*'; console_output.body['output'] =~
/^cloud-init boot finished/ }
puts
server
end
def create_block_device_mapping(image_mappings)
block_device_mapping = []
name_mapping = {
'deviceName' => 'DeviceName',
'snapshotId' => 'Ebs.SnapshotId',
'volumeSize' => 'Ebs.VolumeSize',
'deleteOnTermination' => 'Ebs.DeleteOnTermination',
}
image_mappings.each do |image_mapping|
mapping = {}
name_mapping.each do |key, value|
mapping[value] = image_mapping[key]
end
block_device_mapping << mapping
end
block_device_mapping
end
def set_root_device_size(block_device_mapping, root_device_name,
root_device_size)
root_device = block_device_mapping.find { |mapping|
mapping['DeviceName'] == root_device_name }
root_device['Ebs.VolumeSize'] = root_device_size
block_device_mapping
end
def create_instance(connection, options)
image = connection.images.get(options[:ami])
block_device_mapping =
create_block_device_mapping(image.block_device_mapping)
set_root_device_size(block_device_mapping, image.root_device_name,
options[:root_device_size])
server = connection.servers.create(image_id: options[:ami],
flavor_id: options[:flavor],
block_device_mapping,
key_name: options[:name],
groups: options[:name],
'ClientToken' =>
SimpleUUID::UUID.new.to_guid)
connection.tags.create(key: 'Name', value: options[:name],
server.id)
server.wait_for { printf '.'; ready? }
server.wait_for { printf '*'; console_output.body['output'] =~
/^cloud-init boot finished/ }
puts
server
end
def create_block_device_mapping(image_mappings)
block_device_mapping = []
name_mapping = {
'deviceName' => 'DeviceName',
'snapshotId' => 'Ebs.SnapshotId',
'volumeSize' => 'Ebs.VolumeSize',
'deleteOnTermination' => 'Ebs.DeleteOnTermination',
}
image_mappings.each do |image_mapping|
mapping = {}
name_mapping.each do |key, value|
mapping[value] = image_mapping[key]
end
block_device_mapping << mapping
end
block_device_mapping
end
def set_root_device_size(block_device_mapping, root_device_name,
root_device_size)
root_device = block_device_mapping.find { |mapping|
mapping['DeviceName'] == root_device_name }
root_device['Ebs.VolumeSize'] = root_device_size
block_device_mapping
end
--
You received this message because you are subscribed to the Google Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-fog+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "ruby-fog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-fog+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.