Skip to content

Commit

Permalink
[LIBCLOUD-973] Support disk_size parameter for boot disk while creati…
Browse files Browse the repository at this point in the history
…ng instances in ex_create_multiple_nodes API call.
  • Loading branch information
Rahul-CSI committed Jan 9, 2018
1 parent 7088567 commit 81b58ae
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions libcloud/compute/drivers/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -4105,7 +4105,7 @@ def _create_instance_properties(
on_host_maintenance=None, automatic_restart=None,
preemptible=None, tags=None, metadata=None,
description=None, disks_gce_struct=None, nic_gce_struct=None,
use_selflinks=True, labels=None):
use_selflinks=True, labels=None, disk_size=None):
"""
Create the GCE instance properties needed for instance templates.
Expand Down Expand Up @@ -4221,6 +4221,10 @@ def _create_instance_properties(
:type labels: Labels dict for instance
:type labels: ``dict`` or ``None``
:keyword disk_size: Specify size of the boot disk.
Integer in gigabytes.
:type disk_size: ``int`` or ``None``
:return: A dictionary formatted for use with the GCE API.
:rtype: ``dict``
"""
Expand Down Expand Up @@ -4251,7 +4255,8 @@ def _create_instance_properties(
device_name, source=source, disk_type=disk_type, image=image,
disk_name=disk_name, usage_type='PERSISTENT',
mount_mode='READ_WRITE', auto_delete=disk_auto_delete,
is_boot=True, use_selflinks=use_selflinks)]
is_boot=True, use_selflinks=use_selflinks,
disk_size=disk_size)]

# build network interfaces
if nic_gce_struct is not None:
Expand Down Expand Up @@ -4367,9 +4372,10 @@ def _build_disk_gce_struct(
if not isinstance(auto_delete, bool):
raise ValueError("auto_delete field is not a bool.")

if disk_size is not None and not disk_size.isdigit():
if disk_size is not None \
and(not isinstance(disk_size, int)and not disk_size.isdigit()):
raise ValueError("disk_size must be a digit, '%s' provided." %
(disk_size))
str(disk_size))

mount_modes = ['READ_WRITE', 'READ_ONLY']
if mount_mode not in mount_modes:
Expand Down Expand Up @@ -4656,7 +4662,7 @@ def ex_create_multiple_nodes(
description=None, ex_can_ip_forward=None, ex_disks_gce_struct=None,
ex_nic_gce_struct=None, ex_on_host_maintenance=None,
ex_automatic_restart=None, ex_image_family=None,
ex_preemptible=None, ex_labels=None):
ex_preemptible=None, ex_labels=None, ex_disk_size=None):
"""
Create multiple nodes and return a list of Node objects.
Expand Down Expand Up @@ -4799,6 +4805,10 @@ def ex_create_multiple_nodes(
:param ex_labels: Label dict for node.
:type ex_labels: ``dict``
:keyword ex_disk_size: Defines size of the boot disk.
Integer in gigabytes.
:type ex_disk_size: ``int`` or ``None``
:return: A list of Node objects for the new nodes.
:rtype: ``list`` of :class:`Node`
Expand Down Expand Up @@ -4851,7 +4861,8 @@ def ex_create_multiple_nodes(
'ex_on_host_maintenance': ex_on_host_maintenance,
'ex_automatic_restart': ex_automatic_restart,
'ex_preemptible': ex_preemptible,
'ex_labels': ex_labels}
'ex_labels': ex_labels,
'ex_disk_size': ex_disk_size}
# List for holding the status information for disk/node creation.
status_list = []

Expand Down Expand Up @@ -7744,7 +7755,8 @@ def _create_node_req(
description=None, ex_can_ip_forward=None,
ex_disks_gce_struct=None, ex_nic_gce_struct=None,
ex_on_host_maintenance=None, ex_automatic_restart=None,
ex_preemptible=None, ex_subnetwork=None, ex_labels=None):
ex_preemptible=None, ex_subnetwork=None, ex_labels=None,
ex_disk_size=None):
"""
Returns a request and body to create a new node.
Expand Down Expand Up @@ -7862,6 +7874,10 @@ def _create_node_req(
:param ex_subnetwork: The network to associate with the node.
:type ex_subnetwork: :class:`GCESubnetwork`
:keyword ex_disk_size: Specify the size of boot disk.
Integer in gigabytes.
:type ex_disk_size: ``int`` or ``None``
:param ex_labels: Label dict for node.
:type ex_labels: ``dict`` or ``None``
Expand Down Expand Up @@ -7894,7 +7910,8 @@ def _create_node_req(
automatic_restart=ex_automatic_restart, preemptible=ex_preemptible,
tags=tags, metadata=metadata, labels=ex_labels,
description=description, disks_gce_struct=ex_disks_gce_struct,
nic_gce_struct=ex_nic_gce_struct, use_selflinks=use_selflinks)
nic_gce_struct=ex_nic_gce_struct, use_selflinks=use_selflinks,
disk_size=ex_disk_size)
node_data['name'] = name

request = '/zones/%s/instances' % (location.name)
Expand Down Expand Up @@ -7999,7 +8016,8 @@ def _multi_create_node(self, status, node_attrs):
ex_automatic_restart=node_attrs['ex_automatic_restart'],
ex_subnetwork=node_attrs['subnetwork'],
ex_preemptible=node_attrs['ex_preemptible'],
ex_labels=node_attrs['ex_labels']
ex_labels=node_attrs['ex_labels'],
ex_disk_size=node_attrs['ex_disk_size']
)

try:
Expand Down

0 comments on commit 81b58ae

Please sign in to comment.