def shutdown(): """ Shutdown the instance where this method is called. Returns: True if there are no errors. """ try: auth = Auth() instance = _get(_INSTANCE + "hostname").split(".")[0] zone = _get(_INSTANCE + "zone").split("/")[-1] project = _get(_PROJECT + "project-id") logging.info("Instance %s will be shut down.", instance) sp = discovery.build("compute", "v1") req = sp.instances().delete(project=project, zone=zone, instance=instance) # pylint: disable=no-member req.headers["Authorization"] = auth.header_str() req.execute() return True except urllib2.URLError as e: LOGGER.warning("Shutdown was interrupted. (%s)", e) return False