text
stringlengths
0
828
# application needs to authorize access to the user's
# data. The name of the credentials file is provided. If the
# file does not exist, it is created. This object can only
# hold credentials for a single user. It stores the access
# priviledges for the application, so a user only has to grant
# access through the web interface once.
storage_path = os.path.join(self._storage_path,
self._client_id + '.oauth.dat')
storage = Storage(storage_path)
credentials = storage.get()
if credentials is None or credentials.invalid:
args = argparser.parse_args([])
args.noauth_local_webserver = self._noauth_local_webserver
# try to start a browser to have the user authenticate with Google
# TODO: what kind of exception is raised if the browser
# cannot be started?
try:
credentials = run_flow(flow, storage, flags=args)
except:
import sys
print ""Unexpected error:"", sys.exc_info()[0]
raise
http = httplib2.Http()
self._auth_http = credentials.authorize(http)
self._gce = build(GCE_API_NAME, GCE_API_VERSION, http=http)
return self._gce"
4984,"def start_instance(self,
# these are common to any
# CloudProvider.start_instance() call
key_name, public_key_path, private_key_path,
security_group, flavor, image_id, image_userdata,
username=None,
# these params are specific to the
# GoogleCloudProvider
node_name=None,
boot_disk_type='pd-standard',
boot_disk_size=10,
tags=None,
scheduling=None,
**kwargs):
""""""Starts a new instance with the given properties and returns
the instance id.
:param str key_name: name of the ssh key to connect
:param str public_key_path: path to ssh public key
:param str private_key_path: path to ssh private key
:param str security_group: firewall rule definition to apply on the
instance
:param str flavor: machine type to use for the instance
: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 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|Sequence tags: ""Tags"" to label the instance.
Can be either a single string (individual tags are comma-separated),
or a sequence of strings (each string being a single tag).
:return: str - instance id of the started instance
""""""
# construct URLs
project_url = '%s%s' % (GCE_URL, self._project_id)
machine_type_url = '%s/zones/%s/machineTypes/%s' \
% (project_url, self._zone, flavor)
boot_disk_type_url = '%s/zones/%s/diskTypes/%s' \
% (project_url, self._zone, boot_disk_type)
# FIXME: `conf.py` should ensure that `boot_disk_size` has the right
# type, so there would be no need to convert here
boot_disk_size_gb = int(boot_disk_size)
network_url = '%s/global/networks/%s' % (project_url, self._network)
if image_id.startswith('http://') or image_id.startswith('https://'):
image_url = image_id
else:
# The image names and full resource URLs for several Google-
# provided images (debian, centos, etc.) follow a consistent
# pattern, and so elasticluster supports a short-hand of just
# an image name, such as
# ""debian-7-wheezy-v20150526"".
# The cloud project in this case is then ""debian-cloud"".
#
# Several images do not follow this convention, and so are
# special-cased here:
# backports-debian -> debian-cloud
# ubuntu -> ubuntu-os-cloud
# containter-vm -> google-containers
if image_id.startswith('container-vm-'):
os_cloud = 'google-containers'
elif image_id.startswith('backports-debian-'):
os_cloud = 'debian-cloud'
elif image_id.startswith('ubuntu-'):
os_cloud = 'ubuntu-os-cloud'
else:
os = image_id.split(""-"")[0]
os_cloud = ""%s-cloud"" % os