def PatchApplication(self, split_health_checks=None): """Updates an application. Args: split_health_checks: Boolean, whether to enable split health checks by default. Returns: Long running operation. """ # Create a configuration update request. application_update = self.messages.Application() update_mask = '' if split_health_checks is not None: update_mask = 'featureSettings' application_update.featureSettings = self.messages.FeatureSettings( splitHealthChecks=split_health_checks) update_request = self.messages.AppengineAppsPatchRequest( name=self._FormatApp(), application=application_update, updateMask=update_mask) operation = requests.MakeRequest(self.client.apps.Patch, update_request) log.debug('Received operation: [{operation}]'.format( operation=operation.name)) return operations_util.WaitForOperation(self.client.apps_operations, operation)
def CreateApp(self, location): """Creates an App Engine app within the current cloud project. Creates a new singleton app within the currently selected Cloud Project. The action is one-time and irreversible. Args: location: str, The location (region) of the app, i.e. "us-central" Raises: googlecloudsdk.api_lib.app.exceptions.ConflictError if app already exists Returns: A long running operation. """ create_request = self.messages.Application(id=self.project, locationId=location) operation = requests.MakeRequest(self.client.apps.Create, create_request) log.debug('Received operation: [{operation}]'.format( operation=operation.name)) message = ( 'Creating App Engine application in project [{project}] and ' 'region [{region}].'.format(project=self.project, region=location)) return operations_util.WaitForOperation(self.client.apps_operations, operation, message=message)
def DeployModule(self, module_name, version_id, module_config, manifest, image): """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. image: The name of the container image. Returns: A Version resource representing the deployed version. """ version_resource = self._CreateVersionResource(module_config, manifest, version_id, image) 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 UpdateDomainMapping(self, domain, certificate_id, no_certificate_id): """Updates a domain mapping for the given application. Args: domain: str, the custom domain string. certificate_id: str, a certificate id for the domain. no_certificate_id: boolean, remove the certificate id from the domain. Returns: The updated DomainMapping object. """ mask_fields = [] if certificate_id or no_certificate_id: mask_fields.append('sslSettings.certificateId') ssl = self.messages.SslSettings(certificateId=certificate_id) domain_mapping = self.messages.DomainMapping(id=domain, sslSettings=ssl) if not mask_fields: raise exceptions.MinimumArgumentException( 'Please specify at least one attribute to the domain-mapping update.') request = self.messages.AppengineAppsDomainMappingsPatchRequest( name=self._FormatDomainMapping(domain), domainMapping=domain_mapping, updateMask=','.join(mask_fields)) operation = requests.MakeRequest(self.client.apps_domainMappings.Patch, request) return operations_util.WaitForOperation(self.client.apps_operations, operation).response
def SetServingStatus(self, service_name, version_id, serving_status, block=True): """Sets the serving status of the specified version. Args: service_name: str, The service name version_id: str, The version to delete. serving_status: The serving status to set. block: bool, whether to block on the completion of the operation Returns: The completed Operation if block is True, or the Operation to wait on otherwise. """ patch_request = self.messages.AppengineAppsServicesVersionsPatchRequest( name=self._FormatVersion(service_name=service_name, version_id=version_id), version=self.messages.Version(servingStatus=serving_status), updateMask='servingStatus') operation = requests.MakeRequest( self.client.apps_services_versions.Patch, patch_request) if block: return operations_util.WaitForOperation( self.client.apps_operations, operation) else: return operation
def SetTrafficSplit(self, module_name, allocations, shard_by='UNSPECIFIED', migrate=False): """Sets the traffic split of the given modules. Args: module_name: str, The module name allocations: A dict mapping version ID to traffic split. shard_by: A ShardByValuesEnum value specifying how to shard the traffic. migrate: Whether or not to migrate traffic. Returns: Long running operation. """ # Create a traffic split where 100% of traffic goes to the specified # version. traffic_split = encoding.PyValueToMessage(self.messages.TrafficSplit, { 'allocations': allocations, 'shardBy': shard_by }) update_module_request = self.messages.AppengineAppsModulesPatchRequest( name=self._FormatModule(app_id=self.project, module_name=module_name), module=self.messages.Module(split=traffic_split), migrateTraffic=migrate, mask='split') operation = requests.MakeRequest(self.client.apps_modules.Patch, update_module_request) return operations.WaitForOperation(self.client.apps_operations, operation)
def CreateDomainMapping(self, domain, certificate_id, no_managed_certificate): """Creates a domain mapping for the given application. Args: domain: str, the custom domain string. certificate_id: str, a certificate id for the new domain. no_managed_certificate: bool, don't automatically provision a certificate. Returns: The created DomainMapping object. """ ssl = self.messages.SslSettings(certificateId=certificate_id) domain_mapping = self.messages.DomainMapping(id=domain, sslSettings=ssl) request = self.messages.AppengineAppsDomainMappingsCreateRequest( parent=self._FormatApp(), domainMapping=domain_mapping, noManagedCertificate=no_managed_certificate) operation = requests.MakeRequest( self.client.apps_domainMappings.Create, request) return operations_util.WaitForOperation(self.client.apps_operations, operation).response
def CreateSslCertificate(self, display_name, cert_path, private_key_path): """Creates a certificate for the given application. Args: display_name: str, the display name for the new certificate. cert_path: str, location on disk to a certificate file. private_key_path: str, location on disk to a private key file. Returns: The created AuthorizedCertificate object. Raises: Error if the file does not exist or can't be opened/read. """ certificate_data = files.GetFileContents(cert_path) private_key_data = files.GetFileContents(private_key_path) cert = self.messages.CertificateRawData( privateKey=private_key_data, publicCertificate=certificate_data) auth_cert = self.messages.AuthorizedCertificate( displayName=display_name, certificateRawData=cert) request = self.messages.AppengineAppsAuthorizedCertificatesCreateRequest( parent=self._FormatApp(), authorizedCertificate=auth_cert) return requests.MakeRequest( self.client.apps_authorizedCertificates.Create, request)
def CreateDomainMapping(self, domain, certificate_id, management_type): """Creates a domain mapping for the given application. Args: domain: str, the custom domain string. certificate_id: str, a certificate id for the new domain. management_type: SslSettings.SslManagementTypeValueValuesEnum, AUTOMATIC or MANUAL certificate provisioning. Returns: The created DomainMapping object. """ ssl = self.messages.SslSettings(certificateId=certificate_id, sslManagementType=management_type) domain_mapping = self.messages.DomainMapping(id=domain, sslSettings=ssl) request = self.messages.AppengineAppsDomainMappingsCreateRequest( parent=self._FormatApp(), domainMapping=domain_mapping) operation = requests.MakeRequest( self.client.apps_domainMappings.Create, request) return operations_util.WaitForOperation(self.client.apps_operations, operation).response
def UpdateSslCertificate(self, cert_id, display_name=None, cert_path=None, private_key_path=None): """Updates a certificate for the given application. One of display_name, cert_path, or private_key_path should be set. Omitted fields will not be updated from their current value. Any invalid arguments will fail the entire command. Args: cert_id: str, the id of the certificate to update. display_name: str, the display name for a new certificate. cert_path: str, location on disk to a certificate file. private_key_path: str, location on disk to a private key file. Returns: The created AuthorizedCertificate object. Raises: InvalidInputError if the user does not specify both cert and key. """ if bool(cert_path) ^ bool(private_key_path): raise exceptions.RequiredArgumentException( 'The certificate and the private key must both be updated together.' ) mask_fields = [] if display_name: mask_fields.append('displayName') cert_data = None if cert_path and private_key_path: certificate = files.GetFileContents(cert_path) private_key = files.GetFileContents(private_key_path) cert_data = self.messages.CertificateRawData( privateKey=private_key, publicCertificate=certificate) mask_fields.append('certificateRawData') auth_cert = self.messages.AuthorizedCertificate( displayName=display_name, certificateRawData=cert_data) if not mask_fields: raise exceptions.MinimumArgumentException([ '--certificate', '--private-key', '--display-name' ], 'Please specify at least one attribute to the certificate update.' ) request = self.messages.AppengineAppsAuthorizedCertificatesPatchRequest( name=self._FormatSslCert(cert_id), authorizedCertificate=auth_cert, updateMask=','.join(mask_fields)) return requests.MakeRequest( self.client.apps_authorizedCertificates.Patch, request)
def DeleteSslCertificate(self, cert_id): """Deletes an authorized certificate for the given application. Args: cert_id: str, the id of the certificate to delete. """ request = self.messages.AppengineAppsAuthorizedCertificatesDeleteRequest( name=self._FormatSslCert(cert_id)) requests.MakeRequest(self.client.apps_authorizedCertificates.Delete, request)
def Delete(self, resource): """Deletes a firewall rule for the given application. Args: resource: str, the resource path to the firewall rule. """ request = self.messages.AppengineAppsFirewallIngressRulesDeleteRequest( name=resource.RelativeName()) requests.MakeRequest(self.client.apps_firewall_ingressRules.Delete, request)
def GetApplication(self): """Retrieves the application resource.""" request = self.messages.AppengineAppsGetRequest( name=self._FormatApp(app_id=self.project), ensureResourcesExist=True) try: return requests.MakeRequest(self.client.apps.Get, request) except calliope_exceptions.HttpException as e: if e.status_code == 404: raise exceptions.AppNotFoundError() raise # re-raise
def GetApplication(self): """Retrieves the application resource. Returns: An app resource representing the project's app. Raises: googlecloudsdk.api_lib.app.exceptions.NotFoundError if app doesn't exist """ request = self.messages.AppengineAppsGetRequest(name=self._FormatApp()) return requests.MakeRequest(self.client.apps.Get, request)
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 GetServiceResource(self, service): """Describe the given service. Args: service: str, the ID of the service Returns: Service resource object from the API """ request = self.messages.AppengineAppsServicesGetRequest( name=self._GetServiceRelativeName(service)) return requests.MakeRequest(self.client.apps_services.Get, request)
def Poll(self, operation_ref): """Overrides. Args: operation_ref: googlecloudsdk.core.resources.Resource. Returns: fetched operation message. """ request_type = self.operation_service.GetRequestType('Get') request = request_type(name=operation_ref.RelativeName()) return requests.MakeRequest(self.operation_service.Get, request)
def ListDomainMappings(self): """Lists all domain mappings for the given application. Returns: A list of DomainMapping objects. """ request = self.messages.AppengineAppsDomainMappingsListRequest( parent=self._FormatApp()) response = requests.MakeRequest(self.client.apps_domainMappings.List, request) return response.domainMappings
def ListSslCertificates(self): """Lists all authorized certificates for the given application. Returns: A list of AuthorizedCertificate objects. """ request = self.messages.AppengineAppsAuthorizedCertificatesListRequest( parent=self._FormatApp()) response = requests.MakeRequest( self.client.apps_authorizedCertificates.List, request) return response.certificates
def ListVerifiedDomains(self): """Lists all domains verified by the current user. Returns: A list of AuthorizedDomain objects. """ request = self.messages.AppengineAppsAuthorizedDomainsListRequest( parent=self._FormatApp()) response = requests.MakeRequest( self.client.apps_authorizedDomains.List, request) return response.domains
def DeleteDomainMapping(self, domain): """Deletes a domain mapping for the given application. Args: domain: str, the domain to delete. """ request = self.messages.AppengineAppsDomainMappingsDeleteRequest( name=self._FormatDomainMapping(domain)) operation = requests.MakeRequest(self.client.apps_domainMappings.Delete, request) operations_util.WaitForOperation(self.client.apps_operations, operation)
def GetDomainMapping(self, domain): """Gets a domain mapping for the given application. Args: domain: str, the domain to retrieve. Returns: The retrieved DomainMapping object. """ request = self.messages.AppengineAppsDomainMappingsGetRequest( name=self._FormatDomainMapping(domain)) return requests.MakeRequest(self.client.apps_domainMappings.Get, request)
def GetOperation(self, op_id): """Grabs details about a particular gcloud operation. Args: op_id: str, ID of operation. Returns: Operation resource object from API call. """ request = self.messages.AppengineAppsOperationsGetRequest( name=self._FormatOperation(op_id)) return requests.MakeRequest(self.client.apps_operations.Get, request)
def GetInstanceResource(self, res): """Describe the given instance of the given version of the given service. Args: res: A googleclousdk.core.Resource object. Returns: Version resource object from the API """ request = self.messages.AppengineAppsServicesVersionsInstancesGetRequest( name=res.RelativeName()) return requests.MakeRequest( self.client.apps_services_versions_instances.Get, request)
def DeleteService(self, service_name): """Deletes the specified service. Args: service_name: str, Name of the service to delete. Returns: The completed Operation. """ delete_request = self.messages.AppengineAppsServicesDeleteRequest( name=self._GetServiceRelativeName(service_name=service_name)) operation = requests.MakeRequest(self.client.apps_services.Delete, delete_request) return operations_util.WaitForOperation(self.client.apps_operations, operation)
def GetVersionResource(self, service, version): """Describe the given version of the given service. Args: service: str, the ID of the service for the version to describe. version: str, the ID of the version to describe. Returns: Version resource object from the API. """ request = self.messages.AppengineAppsServicesVersionsGetRequest( name=self._FormatVersion(service, version), view=(self.messages. AppengineAppsServicesVersionsGetRequest.ViewValueValuesEnum.FULL)) return requests.MakeRequest(self.client.apps_services_versions.Get, request)
def DeleteInstance(self, res): """Delete a Flexible instance. Args: res: A googlecloudsdk.core.Resource object. Returns: The completed Operation. """ request = self.messages.AppengineAppsServicesVersionsInstancesDeleteRequest( name=res.RelativeName()) operation = requests.MakeRequest( self.client.apps_services_versions_instances.Delete, request) return operations_util.WaitForOperation(self.client.apps_operations, operation)
def ListOperations(self, op_filter=None): """Lists all operations for the given application. Args: op_filter: String to filter which operations to grab. Returns: A list of opeartion_util.Operation objects. """ request = self.messages.AppengineAppsOperationsListRequest( name=self._FormatApp(), filter=op_filter) response = requests.MakeRequest(self.client.apps_operations.List, request) return [operations_util.Operation(op) for op in response.operations]
def DeleteService(self, service_name): """Deletes the specified service. Args: service_name: str, Name of the service to delete. Returns: The completed Operation. """ delete_request = self.messages.AppengineAppsModulesDeleteRequest( name=self._FormatModule(app_id=self.project, module_name=service_name)) operation = requests.MakeRequest(self.client.apps_modules.Delete, delete_request) return operations.WaitForOperation(self.client.apps_operations, operation)
def GetInstanceResource(self, service, version, instance): """Describe the given instance of the given version of the given service. Args: service: str, the ID of the service version: str, the ID of the version instance: str, the ID of the instance Returns: Version resource object from the API """ request = self.messages.AppengineAppsServicesVersionsInstancesGetRequest( name=self._FormatInstance(self.project, service, version, instance)) return requests.MakeRequest( self.client.apps_services_versions_instances.Get, request)