Implemented the changes for review comments received for PCQE-210 and PCQE-219

Change-Id: Ic0bd316fdbc27f8468cbaae112865d2ba6be84af
This commit is contained in:
Sourav Kumar Sanki 2018-08-08 16:53:37 +05:30
parent 1b10ddc00d
commit b11d0320a1
4 changed files with 63 additions and 30 deletions

View File

@ -386,5 +386,8 @@ class VolumesAPIConfig(ConfigSectionInterface):
@property
def primary_bootable_volume(self):
"""Introducing this property to handle VIRT-3099- SKS 11-JUL-2018."""
"""Introducing this property to handle VIRT-3099- SKS 11-JUL-2018.
Specifies a bootable volume id (UUID) ready to be used to create a
server from.
"""
return self.get("primary_bootable_volume")

View File

@ -17,7 +17,7 @@ limitations under the License.
from cafe.engine.http.client import AutoMarshallingHTTPClient
from cloudcafe.compute.extensions.volumes_boot_api.models.request import \
CreateServerFromVolume, CreateServerFromVolumeVirt2837
CreateServerFromVolume, CreateServerFromVolumeDevMapv1
from cloudcafe.compute.servers_api.models.servers import Server
@ -119,23 +119,23 @@ class VolumesBootClient(AutoMarshallingHTTPClient):
requestslib_kwargs=requestslib_kwargs)
return resp
def create_server_virt2837(self, name, flavor_ref, block_device_mapping_v1,
max_count=None, min_count=None, networks=None,
image_ref=None, personality=None, user_data=None,
metadata=None, accessIPv4=None, accessIPv6=None,
disk_config=None, admin_pass=None, key_name=None,
config_drive=None, scheduler_hints=None,
security_groups=None, requestslib_kwargs=None):
def create_server_device_mapper_v1(
self, name, flavor_ref, block_device_mapping_v1,
max_count=None, min_count=None, networks=None,
image_ref=None, personality=None, user_data=None,
metadata=None, accessIPv4=None, accessIPv6=None,
disk_config=None, admin_pass=None, key_name=None,
config_drive=None, scheduler_hints=None,
security_groups=None, requestslib_kwargs=None):
"""
@summary: Creates an instance of a block Version 2 server given the
@summary: Creates an instance of a block Version 1 server given the
provided parameters
@param name: Name of the server
@type name: String
@param flavor_ref: Identifier for the flavor used to build the server
@type flavor_ref: String
@param block_device_mapping_v2: A list of dictionaries needed for boot
from volume V2 feature
@param block_device_mapping_v1: A list of dictionaries needed for boot
from volume V1 feature
@type block_device_mapping: List
@param max_count: max_count parameter for the server.
@type max_count: String
@ -173,7 +173,7 @@ class VolumesBootClient(AutoMarshallingHTTPClient):
@rtype: Requests.response
"""
server_request_object = CreateServerFromVolumeVirt2837(
server_request_object = CreateServerFromVolumeDevMapv1(
name=name, flavor_ref=flavor_ref,
block_device_mapping=block_device_mapping_v1,
max_count=max_count, min_count=min_count, networks=networks,

View File

@ -24,6 +24,10 @@ from cloudcafe.compute.servers_api.models.requests import Personality
class CreateServerFromVolume(AutoMarshallingModel):
"""
Used for creating server from volume using block device mapping
version 2 API.
"""
def __init__(self, name, flavor_ref, block_device_mapping_v2,
max_count=None, min_count=None, networks=None,
@ -127,8 +131,11 @@ class CreateServerFromVolume(AutoMarshallingModel):
return ''.join([Constants.XML_HEADER, ET.tostring(element)])
class CreateServerFromVolumeVirt2837(AutoMarshallingModel):
class CreateServerFromVolumeDevMapv1(AutoMarshallingModel):
"""
Used for creating server from volume using block device mapping
version 1 API.
"""
def __init__(self, name, flavor_ref, block_device_mapping,
max_count=None, min_count=None, networks=None,
@ -138,7 +145,7 @@ class CreateServerFromVolumeVirt2837(AutoMarshallingModel):
config_drive=None, scheduler_hints=None,
security_groups=None):
super(CreateServerFromVolumeVirt2837, self).__init__()
super(CreateServerFromVolumeDevMapv1, self).__init__()
self.name = name
self.flavor_ref = flavor_ref
self.block_device_mapping = block_device_mapping
@ -205,7 +212,7 @@ class CreateServerFromVolumeVirt2837(AutoMarshallingModel):
element = ET.Element('server')
element.set('xmlns', Constants.XML_API_NAMESPACE)
block_device_ele = ET.Element('block_device_mapping')
block_device_ele.append(BlockDeviceMappingV1VIRT2837._obj_to_xml(
block_device_ele.append(BlockDeviceMappingV1._obj_to_xml(
self.block_device_mapping))
element.append(block_device_ele)
if self.networks is not None:
@ -231,7 +238,8 @@ class CreateServerFromVolumeVirt2837(AutoMarshallingModel):
element = self._set_xml_etree_element(element, elements_dict)
return ''.join([Constants.XML_HEADER, ET.tostring(element)])
class BlockDeviceMappingV1VIRT2837(AutoMarshallingModel):
class BlockDeviceMappingV1(AutoMarshallingModel):
"""
@summary: Block Device Mapping Request Object for Version 1
of boot from volume extension
@ -239,7 +247,7 @@ class BlockDeviceMappingV1VIRT2837(AutoMarshallingModel):
ROOT_TAG = 'block_device_mapping'
def __init__(self, volume_id, device_name, delete_on_termination):
super(BlockDeviceMappingV1VIRT2837, self).__init__()
super(BlockDeviceMappingV1, self).__init__()
self.volume_id = volume_id
self.device_name = device_name
self.delete_on_termination = delete_on_termination
@ -253,13 +261,13 @@ class BlockDeviceMappingV1VIRT2837(AutoMarshallingModel):
}
body = self._remove_empty_values(body)
return json.dumps({'block_device_mapping': body})
return json.dumps({self.ROOT_TAG: body})
@classmethod
def _obj_to_xml(self, list_dicts):
device_dict = None
for device_dict in list_dicts:
device_element = ET.Element('block_device_mapping')
device_element = ET.Element(self.ROOT_TAG)
device_element.set('volume_id', device_dict.get('volume_id'))
device_element.set('device_name', device_dict.get('device_name'))
device_element.set('delete_on_termination',

View File

@ -687,20 +687,16 @@ class ServerBehaviors(BaseComputeBehavior):
"type": type}]
return block_device_mapping_matrix
def create_block_device_mapping_v1_virt2837(self, device_name, volume_id, delete_on_termination):
def create_block_device_mapping_v1_virt2837(self, device_name, volume_id,
delete_on_termination):
"""
@summary: Creates Block Device mapping on the fly
@param device_name: Device name
@type device_name: String
@param volume_id: The uuid of the volume
@type volume_id: String
@param delete_on_termination: True or False also 0 or 1
@type delete_on_termination: Boolean
@param device_name: Device name
@type device_name: String
@param size: Volume Size in GB
@type size: Int
@param type: snap or blank, from where the volume was created
@type type: String
@return: The Block Device Mapping
@rtype: List of dicts
"""
@ -743,3 +739,29 @@ class ServerBehaviors(BaseComputeBehavior):
"destination_type": destination_type,
"delete_on_termination": delete_on_termination}]
return block_device_matrix
def create_block_device_mapping_v2_virt3099(
self, boot_index, uuid,
source_type,
delete_on_termination):
"""
@summary: Creates Block Device on the fly
@param uuid: The uuid of the volume
@type uuid: String
@param delete_on_termination: True or False also 0 or 1
@type delete_on_termination: Boolean
@param boot_index: Used to order the boot disks
@type boot_index: String
@param source_type: snap or blank, from where the volume was created
@type source_type: String
@return: The Block Device Mapping
@rtype: List of dicts
"""
# Creating block device
block_device_matrix = [{
"boot_index": boot_index,
"uuid": uuid,
"source_type": source_type,
"delete_on_termination": delete_on_termination}]
return block_device_matrix