Lines Matching +full:project +full:- +full:name
1 # -*- coding: utf-8 -*-
3 # Use of this source code is governed by a BSD-style license that can be
44 errors, i.e., 500 status codes. Call it with a non-zero value of
65 - a list of key-value pairs.
66 key: name of the key.
78 """Updates a single key-value pair in a metadata object.
82 - a list of key-value pairs.
83 key: name of the key.
115 _DEFAULT_MACHINE_TYPE = 'n1-standard-8'
117 # Project default service account and scopes.
130 def __init__(self, project, zone, credentials, thread_safe=False): argument
134 project: The GCP project to create instances in.
139 self.project = project
153 def ForServiceAccount(cls, project, zone, json_key_file): argument
157 https://developers.google.com/api-client-library/python/auth/service-accounts
160 project: The GCP project to create images and instances in.
169 return GceContext(project, zone, credentials)
172 def ForServiceAccountThreadSafe(cls, project, zone, json_key_file): argument
173 """Creates a thread-safe GceContext using service account credentials.
176 https://developers.google.com/api-client-library/python/auth/service-accounts
179 project: The GCP project to create images and instances in.
188 return GceContext(project, zone, credentials, thread_safe=True)
190 def CreateAddress(self, name, region=None): argument
194 name: The name to assign to the address.
201 'name': name,
204 project=self.project,
208 operation['name'], region,
212 project=self.project,
214 address=name).execute()
218 def DeleteAddress(self, name, region=None): argument
222 name: The name of the address.
226 project=self.project,
228 address=name).execute()
230 operation['name'], region=region or self.region,
234 """Resolves name of the region that a zone belongs to.
240 Name of the region corresponding to the zone.
243 project=self.project,
245 return zone_resource['region'].split('/')[-1]
247 def CreateInstance(self, name, image, zone=None, network=None, subnet=None, argument
253 name: Instance name.
255 'global/images/my-private-image', or for images from a
256 publicly-available project,
257 'projects/debian-cloud/global/images/debian-7-wheezy-vYYYYMMDD'.
273 positinal arguments, i.e., name, image, zone, network and
279 logging.info('Creating instance "%s" with image "%s" ...', name, image)
291 'name': name,
308 'name': 'External NAT',
325 project=self.project,
329 operation['name'],
331 timeout_handler=lambda: self.DeleteInstance(name))
334 def DeleteInstance(self, name, zone=None): argument
335 """Deletes an instance with the name and waits until it's done.
338 name: Name of the instance to delete.
341 logging.info('Deleting instance "%s" ...', name)
343 project=self.project,
345 instance=name).execute()
347 operation['name'], timeout_sec=self.INSTANCE_OPERATIONS_TIMEOUT_SEC)
349 def StartInstance(self, name, zone=None): argument
350 """Starts an instance with the name and waits until it's done.
353 name: Name of the instance to start.
356 logging.info('Starting instance "%s" ...', name)
358 project=self.project,
360 instance=name).execute()
362 operation['name'], timeout_sec=self.INSTANCE_OPERATIONS_TIMEOUT_SEC)
364 def StopInstance(self, name, zone=None): argument
365 """Stops an instance with the name and waits until it's done.
368 name: Name of the instance to stop.
371 logging.info('Stopping instance "%s" ...', name)
373 project=self.project,
375 instance=name).execute()
377 operation['name'], timeout_sec=self.INSTANCE_OPERATIONS_TIMEOUT_SEC)
379 def CreateImage(self, name, source): argument
383 name: Name of the image to be created.
386 'https://storage.googleapis.com/my-gcs-bucket/test_image.tar.gz'.
391 logging.info('Creating image "%s" with "source" %s ...', name, source)
393 'name': name,
399 project=self.project,
401 self._WaitForGlobalOperation(operation['name'],
403 timeout_handler=lambda: self.DeleteImage(name))
406 def DeleteImage(self, name): argument
410 name: Name of the image to delete.
412 logging.info('Deleting image "%s" ...', name)
414 project=self.project,
415 image=name).execute()
416 self._WaitForGlobalOperation(operation['name'],
429 result = self.gce_client.instances().list(project=self.project,
439 result = self.gce_client.images().list(project=self.project).execute()
443 """Gets an Instance Resource by name and zone.
446 instance: Name of the instance.
457 return self.gce_client.instances().get(project=self.project,
463 'Instance "%s" for project "%s" in zone "%s" was not found.' %
464 (instance, self.project, zone or self.zone))
472 instance: Name of the instance to get IP for.
496 """Gets an Image Resource by name.
499 image: Name of the image to look for.
508 return self.gce_client.images().get(project=self.project,
512 raise ResourceNotFoundError('Image "%s" for project "%s" was not found.'
513 % (image, self.project))
518 """Checks if an instance exists in the current project.
521 instance: Name of the instance to check existence of.
533 """Checks if an image exists in the current project.
536 image: Name of the image to check existence of.
547 """Looks up a single project metadata value.
550 key: Metadata key name.
556 project=self.project).execute()
561 """Sets a single project metadata value.
568 project=self.project).execute()
572 project=self.project,
574 self._WaitForGlobalOperation(operation['name'])
580 instance: Name of the instance.
581 key: Metadata key name.
594 instance: Name of the instance.
602 project=self.project,
606 self._WaitForZoneOperation(operation['name'])
622 project=self.project, zone=zone or self.zone, operation=operation)
640 project=self.project, region=region or self.region, operation=operation)
656 get_request = self.gce_client.globalOperations().get(project=self.project,
702 thread_safe: Whether or not the request needs to be thread-safe.