or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

async-operations.mdindex.mdoperations-management.mdservice-discovery.mdservice-management.md

service-management.mddocs/

0

# Service Management Operations

1

2

Core service lifecycle operations for managing Google Cloud services within projects. These operations handle enabling, disabling, and batch management of services.

3

4

## Capabilities

5

6

### Enable Service

7

8

Enables a Google Cloud service for use by a project. This is an asynchronous operation that returns a long-running operation.

9

10

```python { .api }

11

def enable_service(

12

request: EnableServiceRequest,

13

*,

14

retry: OptionalRetry = gapic_v1.method.DEFAULT,

15

timeout: Optional[float] = None,

16

metadata: Sequence[Tuple[str, str]] = ()

17

) -> Operation[EnableServiceResponse, OperationMetadata]:

18

"""

19

Enable a service for a project.

20

21

Args:

22

request: The request object containing the service name to enable

23

retry: Retry configuration for the request

24

timeout: Request timeout in seconds

25

metadata: Additional metadata for the request

26

27

Returns:

28

Long-running operation that resolves to EnableServiceResponse

29

30

Raises:

31

google.api_core.exceptions.GoogleAPICallError: If the request fails

32

"""

33

```

34

35

Usage example:

36

37

```python

38

from google.cloud import service_usage

39

40

client = service_usage.ServiceUsageClient()

41

42

# Enable Cloud Storage API for a project

43

service_name = "projects/my-project-id/services/storage.googleapis.com"

44

request = service_usage.EnableServiceRequest(name=service_name)

45

46

operation = client.enable_service(request=request)

47

print(f"Operation name: {operation.name}")

48

49

# Wait for completion

50

result = operation.result(timeout=300) # 5 minute timeout

51

print(f"Service enabled: {result.service.name}")

52

print(f"Service state: {result.service.state}")

53

```

54

55

### Disable Service

56

57

Disables a Google Cloud service for a project. This is an asynchronous operation that returns a long-running operation.

58

59

```python { .api }

60

def disable_service(

61

request: DisableServiceRequest,

62

*,

63

retry: OptionalRetry = gapic_v1.method.DEFAULT,

64

timeout: Optional[float] = None,

65

metadata: Sequence[Tuple[str, str]] = ()

66

) -> Operation[DisableServiceResponse, OperationMetadata]:

67

"""

68

Disable a service for a project.

69

70

Args:

71

request: The request object containing the service name and options

72

retry: Retry configuration for the request

73

timeout: Request timeout in seconds

74

metadata: Additional metadata for the request

75

76

Returns:

77

Long-running operation that resolves to DisableServiceResponse

78

79

Raises:

80

google.api_core.exceptions.GoogleAPICallError: If the request fails

81

"""

82

```

83

84

Usage example:

85

86

```python

87

from google.cloud import service_usage

88

89

client = service_usage.ServiceUsageClient()

90

91

# Disable a service (be careful with dependent services)

92

service_name = "projects/my-project-id/services/storage.googleapis.com"

93

request = service_usage.DisableServiceRequest(

94

name=service_name,

95

disable_dependent_services=False # Set to True to disable dependents

96

)

97

98

operation = client.disable_service(request=request)

99

result = operation.result()

100

print(f"Service disabled: {result.service.name}")

101

```

102

103

### Batch Enable Services

104

105

Enables multiple services simultaneously for a project. This is more efficient than individual enable operations.

106

107

```python { .api }

108

def batch_enable_services(

109

request: BatchEnableServicesRequest,

110

*,

111

retry: OptionalRetry = gapic_v1.method.DEFAULT,

112

timeout: Optional[float] = None,

113

metadata: Sequence[Tuple[str, str]] = ()

114

) -> Operation[BatchEnableServicesResponse, OperationMetadata]:

115

"""

116

Enable multiple services for a project in a single operation.

117

118

Args:

119

request: The request object containing parent and service IDs

120

retry: Retry configuration for the request

121

timeout: Request timeout in seconds

122

metadata: Additional metadata for the request

123

124

Returns:

125

Long-running operation that resolves to BatchEnableServicesResponse

126

127

Raises:

128

google.api_core.exceptions.GoogleAPICallError: If the request fails

129

"""

130

```

131

132

Usage example:

133

134

```python

135

from google.cloud import service_usage

136

137

client = service_usage.ServiceUsageClient()

138

139

# Enable multiple services at once

140

parent = "projects/my-project-id"

141

service_ids = [

142

"storage.googleapis.com",

143

"compute.googleapis.com",

144

"bigquery.googleapis.com"

145

]

146

147

request = service_usage.BatchEnableServicesRequest(

148

parent=parent,

149

service_ids=service_ids

150

)

151

152

operation = client.batch_enable_services(request=request)

153

result = operation.result()

154

155

print(f"Enabled {len(result.services)} services:")

156

for service in result.services:

157

print(f" - {service.name}")

158

159

# Check for any failures

160

if result.failures:

161

print("Failures:")

162

for failure in result.failures:

163

print(f" - {failure.service_id}: {failure.error_message}")

164

```

165

166

## Request Types

167

168

```python { .api }

169

class EnableServiceRequest:

170

"""Request to enable a service."""

171

name: str # Format: "projects/{project}/services/{service}"

172

173

class DisableServiceRequest:

174

"""Request to disable a service."""

175

name: str # Format: "projects/{project}/services/{service}"

176

disable_dependent_services: bool

177

178

class BatchEnableServicesRequest:

179

"""Request to enable multiple services."""

180

parent: str # Format: "projects/{project}"

181

service_ids: List[str] # Service names without project prefix

182

```

183

184

## Response Types

185

186

```python { .api }

187

class EnableServiceResponse:

188

"""Response from enabling a service."""

189

service: Service # The service after enabling

190

191

class DisableServiceResponse:

192

"""Response from disabling a service."""

193

service: Service # The service after disabling

194

195

class BatchEnableServicesResponse:

196

"""Response from batch enabling services."""

197

services: List[Service] # Successfully enabled services

198

failures: List[BatchEnableServicesResponse.EnableFailure] # Failed services

199

200

class EnableFailure:

201

"""Information about a failed service enable."""

202

service_id: str

203

error_message: str

204

```