From a661f5c588a443c9d9426f70db04f041e95ccbce Mon Sep 17 00:00:00 2001 From: Rahul Paigavan Date: Tue, 9 Jan 2018 17:19:49 +0530 Subject: [PATCH 1/2] [LIBCLOUD-973] Support disk_size parameter for boot disk while creating instances in ex_create_multiple_nodes API call. --- libcloud/compute/drivers/gce.py | 34 ++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py index 395cc365ab..a3dcba6564 100644 --- a/libcloud/compute/drivers/gce.py +++ b/libcloud/compute/drivers/gce.py @@ -4146,7 +4146,7 @@ def _create_instance_properties( preemptible=None, tags=None, metadata=None, description=None, disks_gce_struct=None, nic_gce_struct=None, use_selflinks=True, labels=None, accelerator_type=None, - accelerator_count=None): + accelerator_count=None, disk_size=None): """ Create the GCE instance properties needed for instance templates. @@ -4273,6 +4273,9 @@ def _create_instance_properties( None. :type accelerator_count: ``int`` 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`` @@ -4304,7 +4307,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: @@ -4426,9 +4430,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: @@ -4715,7 +4720,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. @@ -4858,6 +4863,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` @@ -4910,7 +4919,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 = [] @@ -7825,7 +7835,8 @@ def _create_node_req( 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_accelerator_type=None, ex_accelerator_count=None): + ex_accelerator_type=None, ex_accelerator_count=None, + ex_disk_size=None): """ Returns a request and body to create a new node. @@ -7943,6 +7954,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`` @@ -7986,7 +8001,7 @@ def _create_node_req( nic_gce_struct=ex_nic_gce_struct, accelerator_type=ex_accelerator_type, accelerator_count=ex_accelerator_count, - use_selflinks=use_selflinks) + use_selflinks=use_selflinks, disk_size=ex_disk_size) node_data['name'] = name request = '/zones/%s/instances' % (location.name) @@ -8091,7 +8106,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: From 0107f8af7a5582ee474168ad4e3812cce236c8f4 Mon Sep 17 00:00:00 2001 From: Rahul Paigavan Date: Thu, 25 Jan 2018 21:12:49 +0530 Subject: [PATCH 2/2] Added tests. --- libcloud/test/compute/fixtures/gce/aggregated_disks.json | 4 ++-- libcloud/test/compute/test_gce.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libcloud/test/compute/fixtures/gce/aggregated_disks.json b/libcloud/test/compute/fixtures/gce/aggregated_disks.json index e8849400d8..4103785207 100644 --- a/libcloud/test/compute/fixtures/gce/aggregated_disks.json +++ b/libcloud/test/compute/fixtures/gce/aggregated_disks.json @@ -107,7 +107,7 @@ "description": "I'm a happy little persistent disk", "type": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/diskTypes/pd-standard", "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/disks/lcnode-000", - "sizeGb": "10", + "sizeGb": "25", "sourceImage": "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20131120", "sourceImageId": "17312518942796567789", "status": "READY", @@ -122,7 +122,7 @@ "description": "I'm a happy little persistent disk", "type": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/diskTypes/pd-standard", "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/disks/lcnode-001", - "sizeGb": "10", + "sizeGb": "25", "sourceImage": "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20131120", "sourceImageId": "17312518942796567791", "status": "READY", diff --git a/libcloud/test/compute/test_gce.py b/libcloud/test/compute/test_gce.py index f9e33ff069..bf9128f404 100644 --- a/libcloud/test/compute/test_gce.py +++ b/libcloud/test/compute/test_gce.py @@ -1293,13 +1293,16 @@ def test_ex_create_multiple_nodes(self): image = self.driver.ex_get_image('debian-7') size = self.driver.ex_get_size('n1-standard-1') number = 2 + disk_size = "25" nodes = self.driver.ex_create_multiple_nodes(base_name, size, image, - number) + number, ex_disk_size=disk_size) self.assertEqual(len(nodes), 2) self.assertTrue(isinstance(nodes[0], Node)) self.assertTrue(isinstance(nodes[1], Node)) self.assertEqual(nodes[0].name, '%s-000' % base_name) self.assertEqual(nodes[1].name, '%s-001' % base_name) + self.assertEqual(nodes[0].extra['boot_disk'].size, disk_size) + self.assertEqual(nodes[1].extra['boot_disk'].size, disk_size) def test_ex_create_multiple_nodes_image_family(self): base_name = 'lcnode'