Skip to content

Commit

Permalink
Merge PR #219
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardomurri committed Jan 5, 2016
2 parents e524e57 + 4707c13 commit 08dbd12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion elasticluster/cluster.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python
#
# Copyright (C) 2013, 2015 S3IT, University of Zurich
# Copyright (C) 2013-2016 S3IT, University of Zurich
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
22 changes: 10 additions & 12 deletions elasticluster/providers/gce.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2013, 2015 S3IT, University of Zurich
# Copyright (C) 2013, 2015, 2016 S3IT, University of Zurich
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -212,7 +212,7 @@ def start_instance(self,
username=None,
# these params are specific to the
# GoogleCloudProvider
instance_name=None,
node_name=None,
boot_disk_type='pd-standard',
boot_disk_size=10,
tags=None,
Expand All @@ -230,12 +230,8 @@ def start_instance(self,
:param str image_id: image type (os) to use for the instance
:param str image_userdata: command to execute after startup
:param str username: username for the given ssh key, default None
:param str instance_name: name of the instance
:param str node_name: name of the instance
:param str tags: comma-separated list of "tags" to label the instance
:param str scheduling: scheduling option to use for the instance ("preemptible")
:param str scheduling: scheduling option to use for the instance ("preemptible")
:return: str - instance id of the started instance
Expand Down Expand Up @@ -286,13 +282,15 @@ def start_instance(self,
raise InstanceError("Unknown scheduling option: '%s'" % scheduling)

# construct the request body
if instance_name is None:
instance_name = 'elasticluster-%s' % uuid.uuid4()
if node_name:
instance_id = node_name.lower().replace('_', '-') # GCE doesn't allow "_"
else:
instance_id = 'elasticluster-%s' % uuid.uuid4()

public_key_content = file(public_key_path).read()

instance = {
'name': instance_name,
'name': instance_id,
'machineType': machine_type_url,
'tags': {
'items': tags.split(',') if tags else None
Expand All @@ -303,7 +301,7 @@ def start_instance(self,
'boot': 'true',
'type': 'PERSISTENT',
'initializeParams' : {
'diskName': "%s-disk" % instance_name,
'diskName': "%s-disk" % instance_id,
'diskType': boot_disk_type_url,
'diskSizeGb': boot_disk_size_gb,
'sourceImage': image_url
Expand Down Expand Up @@ -339,7 +337,7 @@ def start_instance(self,
response = self._execute_request(request)
response = self._wait_until_done(response)
self._check_response(response)
return instance_name
return instance_id
except (HttpError, CloudProviderError) as e:
log.error("Error creating instance `%s`" % e)
raise InstanceError("Error creating instance `%s`" % e)
Expand Down

0 comments on commit 08dbd12

Please sign in to comment.