text
stringlengths 0
828
|
---|
image_url = '%s%s/global/images/%s' % ( |
GCE_URL, os_cloud, image_id) |
if scheduling is None: |
# use GCE's default |
scheduling_option = {} |
elif scheduling == 'preemptible': |
scheduling_option = { |
'preemptible': True |
} |
else: |
raise InstanceError(""Unknown scheduling option: '%s'"" % scheduling) |
if isinstance(tags, types.StringTypes): |
tags = tags.split(',') |
elif isinstance(tags, collections.Sequence): |
# ok, nothing to do |
pass |
elif tags is not None: |
raise TypeError( |
""The `tags` argument to `gce.start_instance`"" |
"" should be a string or a list, got {T} instead"" |
.format(T=type(tags))) |
# construct the request body |
if node_name: |
instance_id = node_name.lower().replace('_', '-') # GCE doesn't allow ""_"" |
else: |
instance_id = 'elasticluster-%s' % uuid.uuid4() |
with open(public_key_path, 'r') as f: |
public_key_content = f.read() |
instance = { |
'name': instance_id, |
'machineType': machine_type_url, |
'tags': { |
'items': tags, |
}, |
'scheduling': scheduling_option, |
'disks': [{ |
'autoDelete': 'true', |
'boot': 'true', |
'type': 'PERSISTENT', |
'initializeParams' : { |
'diskName': ""%s-disk"" % instance_id, |
'diskType': boot_disk_type_url, |
'diskSizeGb': boot_disk_size_gb, |
'sourceImage': image_url |
} |
}], |
'networkInterfaces': [ |
{'accessConfigs': [ |
{'type': 'ONE_TO_ONE_NAT', |
'name': 'External NAT' |
}], |
'network': network_url |
}], |
'serviceAccounts': [ |
{'email': self._email, |
'scopes': GCE_DEFAULT_SCOPES |
}], |
""metadata"": { |
""kind"": ""compute#metadata"", |
""items"": [ |
{ |
""key"": ""sshKeys"", |
""value"": ""%s:%s"" % (username, public_key_content) |
} |
] |
} |
} |
# create the instance |
gce = self._connect() |
request = gce.instances().insert( |
project=self._project_id, body=instance, zone=self._zone) |
try: |
response = self._execute_request(request) |
response = self._wait_until_done(response) |
self._check_response(response) |
return instance_id |
except (HttpError, CloudProviderError) as e: |
log.error(""Error creating instance `%s`"" % e) |
raise InstanceError(""Error creating instance `%s`"" % e)" |
4985,"def _get_image_url(self, image_id): |
""""""Gets the url for the specified image. Unfortunatly this only works |
for images uploaded by the user. The images provided by google will |
not be found. |
:param str image_id: image identifier |
:return: str - api url of the image |
"""""" |
gce = self._connect() |
filter = ""name eq %s"" % image_id |
request = gce.images().list(project=self._project_id, filter=filter) |
response = self._execute_request(request) |
response = self._wait_until_done(response) |
Subsets and Splits