def DeployModule(self, module_name, version_id, module_config, manifest): """Updates and deploys new app versions based on given config. Args: module_name: str, The module to deploy. version_id: str, The version of the module to deploy. module_config: AppInfoExternal, Module info parsed from a module yaml file. manifest: Dictionary mapping source files to Google Cloud Storage locations. Returns: A Version resource representing the deployed version. """ version_resource = self._CreateVersionResource(module_config, manifest, version_id) create_request = self.messages.AppengineAppsModulesVersionsCreateRequest( name=self._FormatModule(app_id=self.project, module_name=module_name), version=version_resource) operation = requests.MakeRequest( self.client.apps_modules_versions.Create, create_request) log.debug('Received operation: [{operation}]'.format( operation=operation.name)) return operations.WaitForOperation(self.client.apps_operations, operation)
def GetApplicationCodeBucket(self): """Retrieves the default code bucket associated with the application.""" request = self.messages.AppengineAppsGetRequest( name=self._FormatApp(app_id=self.project), ensureResourcesExist=True) try: application = requests.MakeRequest(self.client.apps.Get, request) except exceptions.HttpException, e: log.error(e) return ''
def DeleteVersion(self, module_name, version_id): """Deletes the specified version of the given module. Args: module_name: str, The module name version_id: str, The version to set as default. Returns: A Version resource representing the deleted version. """ delete_request = self.messages.AppengineAppsModulesVersionsDeleteRequest( name=self._FormatVersion(app_id=self.project, module_name=module_name, version_id=version_id)) operation = requests.MakeRequest( self.client.apps_modules_versions.Delete, delete_request) return operations.WaitForOperation(self.client.apps_operations, operation)
def _PollUntilDone(operation_service, operation, max_retries, retry_interval): """Polls the operation resource until it is complete or times out.""" if operation.done: return operation request_type = operation_service.GetRequestType('Get') request = request_type(name=operation.name) for _ in xrange(max_retries): operation = requests.MakeRequest(operation_service.Get, request) if operation.done: log.debug('Operation [{0}] complete. Result: {1}'.format( operation.name, json.dumps(encoding.MessageToDict(operation), indent=4))) return operation log.debug('Operation [{0}] not complete. Waiting {1}s.'.format( operation.name, retry_interval)) time.sleep(retry_interval) return None
def SetDefaultVersion(self, module_name, version_id): """Sets the default serving version of the given modules. Args: module_name: str, The module name version_id: str, The version to set as default. """ # Create a traffic split where 100% of traffic goes to the specified # version. allocations = {version_id: 1.0} traffic_split = encoding.PyValueToMessage(self.messages.TrafficSplit, {'allocations': allocations}) update_module_request = self.messages.AppengineAppsModulesPatchRequest( name=self._FormatModule(app_id=self.project, module_name=module_name), module=self.messages.Module(split=traffic_split), mask='split') # TODO(user) Convert this to poll a long running operation. requests.MakeRequest(self.client.apps_modules.Patch, update_module_request)