pycontribs / pyrax

The Python SDK for the Rackspace Cloud
developer.rackspace.com
Apache License 2.0
237 stars 208 forks source link

pyrax.cloudblockstorage.create() does not support creating volumes using an image #564

Closed jimmyc802 closed 9 years ago

jimmyc802 commented 9 years ago

When upgrading a server to a different type or flavor I have run into problems on many occasion when building a new server straight from an image has failed. Rackspace supports recommendation is to create a new volume using that image prior to building the server creating a bootable volume. This is not possible from the gui, but is possible from nova. I was hoping pyrax would support this but the create method of pyrax.cloudblockstorage seems to not have an image parameter. Is there another method I should be using? If not, any chance this is planned in a future version?

Example of nova command: nova volume-create 100 --volume-type=SSD --display-name=BFB-test-SSD --image-id=ff228647-fd57-47fe-b42d-2b7813bb9115

sivel commented 9 years ago

There are 2 ways of building a server with a bootable volume:

Volume First

This requires pyrax 1.9.3 or newer. 1.9.3 was when the image argument was added to the create method for CBS.

cs = pyrax.cloudservers
cbs = pyrax.cloud_blockstorage

image = 'ff228647-fd57-47fe-b42d-2b7813bb9115'
vol = cbs.create('BFB-test-SSD', size=100, volume_type='SSD', image=image)
mapping = [{
    'boot_index': '0',
    'delete_on_termination': True,
    'destination_type': 'volume',
    'uuid': pyrax.utils.get_id(vol),
    'source_type': 'volume'   
}]

server = cs.servers.create('BFB-test', None, 'general1-1',
                           block_device_mapping_v2=mapping)

Create volume and server together

I prefer this method, especially since some flavors require this method such as compute flavors

cs = pyrax.cloudservers

mapping = [{
   'boot_index': '0',
   'delete_on_termination': True,
   'destination_type': 'volume',
   'uuid': 'ff228647-fd57-47fe-b42d-2b7813bb9115',
   'source_type': 'image',
   'volume_size': '100',
}]

server = cs.servers.create('BFB-test', None, 'compute1-4',
                           block_device_mapping_v2=mapping)