Pyrax API: Error in creating Compute/Memory flavors with boot-volumes

92 views Asked by At

For background knowledge: Compute/Memory nova instances in Rackspace don't come with a local root volume, Rackspace has a policy to create them with an external SSD bootable volumes. Now the question: I am trying to create a Compute flavor instance in Rackspace using pyrax api, in a way that Rackspace does in its UI(https://support.rackspace.com/how-to/boot-a-server-from-a-cloud-block-storage-volume/) as follows:

    pyrax.cloudservers.servers.create(hostname,image.id, 
                                      flavor.id,block_device_mapping,
                                      security_groups=security_groups,     
                                      nics=networks, key_name=key)

where block_device_mapping = {"vda": "59fb72d5-0b33-46c2-b10b-33fed25c5f74:::1"}, the long 32 digit number is the volume_id of the volume I create before server creation using

pyrax.cloud_blockstorage.create(name=volume_name, size=volume_size,     
                                 volume_type=volume_type).

I get an error saying:

Policy doesn't allow memory_flavor:create:image_backed to be performed.(HTTP 403).

Also for other flavors which come with a local root volume(needless to say I don't have reference those with 'block_device_mapping' param), the pyrax api for instance creation works fine. Here is a little thread on the topic in the pyrax/rackspace repo on github: https://github.com/rackspace/pyrax/issues/484 that discusses about the issue. Is there something I am missing?

1

There are 1 answers

0
shunya On BEST ANSWER

When a bootable volume is created, image_id(OS image id) should be specified to boot the volume:

pyrax.cloud_blockstorage.create(name=volume_name, size=volume_size,  
                              volume_type=volume_type,image=image.id)

Also The block_device_map needs some more params:

block_device_map = [{
                            'boot_index': '0',
                            'source_type': 'image',
                            'destination_type': 'volume',
                            'delete_on_termination': True,
                            'uuid': image.id,
                            'volume_size': int(requested_size),
                            'device_name': 'vda'
                   }]                  

And here's the final catch in actually not getting a 403 Forbidden error: While creating a server instance, don't specify the image id again in the pyrax call params, otherwise pyrax gets confused with what image to boot the instance. Hence just put a None to image_id in the params for pyrax.cloudservers.servers.create() as:

pyrax.cloudservers.servers.create(
            hostname,
            image=None,
            flavor=flavor.id,
            block_device_mapping_v2=block_device_map,
            security_groups=security_groups,
            nics=networks,
            key_name=key)