Repository: libcloud Updated Branches: refs/heads/trunk 5abd001df -> f23a6468b
[google] fixing demo script and multi-node create Signed-off-by: Eric Johnson <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/f23a6468 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f23a6468 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f23a6468 Branch: refs/heads/trunk Commit: f23a6468b7af4c5170c64c1d26c3a4b12124ca37 Parents: 5abd001 Author: Eric Johnson <[email protected]> Authored: Mon Jul 13 20:11:42 2015 +0000 Committer: Eric Johnson <[email protected]> Committed: Tue Jul 14 16:31:12 2015 +0000 ---------------------------------------------------------------------- demos/gce_demo.py | 26 +++++++------- libcloud/compute/drivers/gce.py | 68 +++++++++++++++++++++--------------- 2 files changed, 53 insertions(+), 41 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/f23a6468/demos/gce_demo.py ---------------------------------------------------------------------- diff --git a/demos/gce_demo.py b/demos/gce_demo.py index cde874f..6c15907 100755 --- a/demos/gce_demo.py +++ b/demos/gce_demo.py @@ -159,10 +159,10 @@ def display(title, resource_list=[]): else: print(' name=%s, dnsname=%s' % (item.id, item.domain)) elif hasattr(item, 'name'): - if item.domain.startswith(DEMO_BASE_NAME): - print('=> %s' % item.domain) + if item.name.startswith(DEMO_BASE_NAME): + print('=> %s' % item.name) else: - print(' %s' % item.domain) + print(' %s' % item.name) else: if item.startswith(DEMO_BASE_NAME): print('=> %s' % item) @@ -202,17 +202,17 @@ def clean_up(gce, base_name, node_list=None, resource_list=None): display(' Failed to delete %s' % del_nodes[i].name) # Destroy everything else with just the destroy method - for resource in resource_list: - if resource.name.startswith(base_name): + for resrc in resource_list: + if resrc.name.startswith(base_name): try: - resource.destroy() + resrc.destroy() except ResourceNotFoundError: - display(' Not found: %s(%s)' % (resource.name, - resource.__class__.__name__)) + display(' Not found: %s (%s)' % (resrc.name, + resrc.__class__.__name__)) except: - class_name = resource.__class__.__name__ - display(' Failed to Delete %s(%s)' % (resource.name, - class_name)) + class_name = resrc.__class__.__name__ + display(' Failed to Delete %s (%s)' % (resrc.name, + class_name)) raise @@ -272,7 +272,7 @@ def main_compute(): name = '%s-gstruct' % DEMO_BASE_NAME img_url = "projects/debian-cloud/global/images/" img_url += "backports-debian-7-wheezy-v20141205" - disk_type_url = "projects/graphite-demos/zones/us-central1-f/" + disk_type_url = "projects/%s/zones/us-central1-f/" % project.name disk_type_url += "diskTypes/local-ssd" gce_disk_struct = [ { @@ -474,11 +474,13 @@ def main_load_balancer(): image = gce.ex_get_image('debian-7') size = gce.ex_get_size('n1-standard-1') number = 3 + display('Creating %d nodes' % number) metadata = {'items': [{'key': 'startup-script', 'value': startup_script}]} lb_nodes = gce.ex_create_multiple_nodes(base_name, size, image, number, ex_tags=[tag], ex_metadata=metadata, + ex_disk_auto_delete=True, ignore_errors=False) display('Created Nodes', lb_nodes) http://git-wip-us.apache.org/repos/asf/libcloud/blob/f23a6468/libcloud/compute/drivers/gce.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py index 0ade024..246bbd6 100644 --- a/libcloud/compute/drivers/gce.py +++ b/libcloud/compute/drivers/gce.py @@ -2321,7 +2321,7 @@ class GCENodeDriver(NodeDriver): 'ex_network'. See the GCE docs for details. :type ex_nic_gce_struct: ``list`` or ``None`` -n + :keyword ex_on_host_maintenance: Defines whether node should be terminated or migrated when host machine goes down. Acceptable values @@ -2518,7 +2518,7 @@ n 'ex_network'. See the GCE docs for details. :type ex_nic_gce_struct: ``list`` or ``None`` -n + :keyword ex_on_host_maintenance: Defines whether node should be terminated or migrated when host machine goes down. Acceptable values @@ -2538,6 +2538,10 @@ n :return: A list of Node objects for the new nodes. :rtype: ``list`` of :class:`Node` """ + if image and ex_disks_gce_struct: + raise ValueError("Cannot specify both 'image' and " + "'ex_disks_gce_struct'.") + location = location or self.zone if not hasattr(location, 'name'): location = self.ex_get_zone(location) @@ -2568,25 +2572,16 @@ n 'ex_nic_gce_struct': ex_nic_gce_struct, 'ex_on_host_maintenance': ex_on_host_maintenance, 'ex_automatic_restart': ex_automatic_restart} - # List for holding the status information for disk/node creation. status_list = [] for i in range(number): name = '%s-%03d' % (base_name, i) - status = {'name': name, 'node_response': None, - 'node': None, - 'disk_response': None, - 'disk': None} - + 'node': None} status_list.append(status) - # Create disks for nodes - for status in status_list: - self._multi_create_disk(status, node_attrs) - start_time = time.time() complete = False while not complete: @@ -2596,13 +2591,8 @@ n complete = True time.sleep(poll_interval) for status in status_list: - # If disk does not yet exist, check on its status - if not status['disk']: - self._multi_check_disk(status, node_attrs) - - # If disk exists, but node does not, create the node or check - # on its status if already in progress. - if status['disk'] and not status['node']: + # Create the node or check status if already in progress. + if not status['node']: if not status['node_response']: self._multi_create_node(status, node_attrs) else: @@ -4622,7 +4612,7 @@ n 'ex_network'. See the GCE docs for details. :type ex_nic_gce_struct: ``list`` or ``None`` -n + :keyword ex_on_host_maintenance: Defines whether node should be terminated or migrated when host machine goes down. Acceptable values @@ -4707,6 +4697,26 @@ n if ex_disks_gce_struct: node_data['disks'] = ex_disks_gce_struct + if image and ('disks' not in node_data or not node_data['disks']): + if not hasattr(image, 'name'): + image = self.ex_get_image(image) + if not ex_disk_type: + ex_disk_type = 'pd-standard' + if not hasattr(ex_disk_type, 'name'): + ex_disk_type = self.ex_get_disktype(ex_disk_type) + disks = [{'boot': True, + 'type': 'PERSISTENT', + 'mode': 'READ_WRITE', + 'deviceName': name, + 'autoDelete': ex_disk_auto_delete, + 'zone': location.name, + 'initializeParams': { + 'diskName': name, + 'diskType': ex_disk_type.extra['selfLink'], + 'sourceImage': image.extra['selfLink'], + }}] + node_data['disks'] = disks + if ex_nic_gce_struct is not None: if hasattr(external_ip, 'address'): raise ValueError("Cannot specify both a static IP address " @@ -4829,7 +4839,7 @@ n def _multi_create_node(self, status, node_attrs): """Create node for ex_create_multiple_nodes. - :param status: Dictionary for holding node/disk creation status. + :param status: Dictionary for holding node creation status. (This dictionary is modified by this method) :type status: ``dict`` @@ -4837,10 +4847,6 @@ n (size, image, location, etc.) :type node_attrs: ``dict`` """ - # If disk has an error, set the node as failed and return - if hasattr(status['disk'], 'error'): - status['node'] = status['disk'] - return # Create node and return response object in status dictionary. # Or, if there is an error, mark as failed. @@ -4865,8 +4871,7 @@ n error = e.value code = e.code node_res = None - status['node'] = GCEFailedNode(status['name'], - error, code) + status['node'] = GCEFailedNode(status['name'], error, code) status['node_response'] = node_res def _multi_check_node(self, status, node_attrs): @@ -4889,14 +4894,19 @@ n error = e.value code = e.code response = {'status': 'DONE'} + except ResourceNotFoundError: + return if response['status'] == 'DONE': status['node_response'] = None if error: status['node'] = GCEFailedNode(status['name'], error, code) else: - status['node'] = self.ex_get_node(status['name'], - node_attrs['location']) + try: + status['node'] = self.ex_get_node(status['name'], + node_attrs['location']) + except ResourceNotFoundError: + return def _create_vol_req(self, size, name, location=None, snapshot=None, image=None, ex_disk_type='pd-standard'):
