openstack driver can create node from bootable vol#1362
Merged
Kami merged 1 commit intoapache:trunkfrom Nov 1, 2019
Merged
Conversation
Currently it is not possible to use the create_node method without
specifying an image. This is because in the OpenStack_1_1_NodeDriver
create_node converts the server_params like:
```
server_params = self._create_args_to_params(None, **kwargs)
```
but in case when there is no image to boot from like when you are
booting from an already existing bootable volume (which could have been
created from an image earlier), then _create_args_to_params will try to
access node.extra in order to get the imageRef, and node is None:
```
if 'image' in kwargs:
server_params['imageRef'] = kwargs.get('image').id
else:
server_params['imageRef'] = node.extra.get('imageId')
```
Booting an instance from a previously existing bootable volume like this
would fail:
```
In [36]: conn.create_node(ex_availability_zone='R123', port='8487d948-0840-4205-8b31-7f705a19e7f4', name='r123apitestnode', ex_keyname
...: ='rick', size='e55a2688-ef74-44cf-b302-9a6f960c3d74', ex_blockdevicemappings=[{'boot_index': 0, 'uuid': 'be7ee330-b454-4414-8
...: e9f-c70c558dd3af', 'source_type': 'volume', 'destination_type': 'volume', 'delete_on_termination': False}])
```
with:
```
/usr/local/venv/hypernode-control/src/apache-libcloud/libcloud/compute/drivers/openstack.pyc in _create_args_to_params(self, node, **kwargs)
1495 server_params['imageRef'] = kwargs.get('image').id
1496 else:
-> 1497 server_params['imageRef'] = node.extra.get('imageId')
1498
1499 if 'size' in kwargs:
AttributeError: 'NoneType' object has no attribute 'extra'
```
This could be circumvented by specifying `image=''`:
```
In [39]: conn.create_node(ex_availability_zone='R123', port='8487d948-0840-4205-8b31-7f705a19e7f4', image='', name='r123apitestnode',
...: ex_keyname='rick', size='e55a2688-ef74-44cf-b302-9a6f960c3d74', ex_blockdevicemappings=[{'boot_index': 0, 'uuid': 'be7ee330-b
...: 454-4414-8e9f-c70c558dd3af', 'source_type': 'volume', 'destination_type': 'volume', 'delete_on_termination': False}])
```
This PR also changes the default imageRef to empty string '' instead of None to prevent the API from responding with an error like this when the .get would default to None so that `image=''` will now no longer have to be specified.
```
BaseHTTPError: 400 Bad Request Invalid input for field/attribute imageRef. Value: None. u'None' is not valid under any of the given schemas
```
e2c114a to
114f09f
Compare
Member
Author
|
force-pushed to rebuild, failed on the seemingly unrelated: https://travis-ci.org/apache/libcloud/jobs/604933686?utm_medium=notification&utm_source=github_status in https://travis-ci.org/apache/libcloud/builds/604933683?utm_source=github_status&utm_medium=notification |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently it is not possible to use the create_node method without
specifying an image. This is because in the OpenStack_1_1_NodeDriver
create_node converts the server_params like:
but in case when there is no image to boot from like when you are
booting from an already existing bootable volume (which could have been
created from an image earlier), then _create_args_to_params will try to
access node.extra in order to get the imageRef, and node is None:
Booting an instance from a previously existing bootable volume like this
would fail:
with:
This could be circumvented by specifying
image='':This PR also changes the default imageRef to empty string '' instead of None to prevent the API from responding with an error like this when the .get would default to None so that
image=''will now no longer have to be specified.For more information see https://docs.openstack.org/api-ref/compute/?expanded=create-server-detail#create-server