or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

api-framework.mdcloud-services.mdcommon-types.mdindex.mdmonitoring.mdoperations.mdrpc-status.md

cloud-services.mddocs/

0

# Cloud Services Integration

1

2

Cloud-specific extensions for location services, extended operations, and Google Cloud Platform integration. Provides types for multi-region services, cloud resource management, and platform-specific functionality.

3

4

## Capabilities

5

6

### Cloud Location Services

7

8

Manage and query cloud service locations and regions.

9

10

```python { .api }

11

from google.cloud.location.locations_pb2 import (

12

ListLocationsRequest, ListLocationsResponse,

13

GetLocationRequest, Location

14

)

15

16

class ListLocationsRequest(message.Message):

17

"""Request to list available service locations."""

18

name: str # Parent resource name (e.g., "projects/my-project")

19

filter: str # Filter expression for locations

20

page_size: int # Maximum number of locations to return

21

page_token: str # Page token for pagination

22

23

class ListLocationsResponse(message.Message):

24

"""Response containing available locations."""

25

locations: list[Location] # List of available locations

26

next_page_token: str # Token for next page (if any)

27

28

class GetLocationRequest(message.Message):

29

"""Request to get details of a specific location."""

30

name: str # Location resource name

31

32

class Location(message.Message):

33

"""Cloud service location information."""

34

name: str # Location resource name

35

location_id: str # Location identifier (e.g., "us-central1")

36

display_name: str # Human-readable location name

37

labels: dict[str, str] # Location labels and metadata

38

metadata: Any # Location-specific metadata

39

```

40

41

### Extended Operations

42

43

Extended operation support for complex cloud operations.

44

45

```python { .api }

46

from google.cloud.extended_operations_pb2 import ExtendedOperation

47

48

class ExtendedOperation(message.Message):

49

"""Extended operation with additional cloud-specific fields."""

50

# Inherits basic operation fields and adds:

51

# Additional cloud-specific operation metadata

52

# Enhanced status reporting

53

# Region and zone information

54

# Resource hierarchy context

55

```

56

57

### Client Generation Metadata

58

59

Metadata for generating cloud service client libraries.

60

61

```python { .api }

62

from google.gapic.metadata.gapic_metadata_pb2 import (

63

GapicMetadata, ServiceForTransport, ServiceAsClient, MethodList

64

)

65

66

class GapicMetadata(message.Message):

67

"""Metadata for GAPIC (Generated API Client) libraries."""

68

schema: str # Metadata schema version

69

comment: str # Additional comments

70

language: str # Target programming language

71

proto_package: str # Protocol buffer package name

72

library_package: str # Generated library package name

73

services: dict[str, ServiceForTransport] # Service transport mappings

74

75

class ServiceForTransport(message.Message):

76

"""Service configuration for different transports."""

77

clients: dict[str, ServiceAsClient] # Client configurations

78

79

class ServiceAsClient(message.Message):

80

"""Service as client configuration."""

81

library_client: str # Client class name

82

rpcs: dict[str, MethodList] # RPC method mappings

83

84

class MethodList(message.Message):

85

"""List of methods for a service."""

86

methods: list[str] # Method names

87

```

88

89

## Usage Examples

90

91

### Listing Cloud Locations

92

93

```python

94

from google.cloud.location.locations_pb2 import ListLocationsRequest, ListLocationsResponse

95

96

def list_all_locations(parent: str, client) -> list:

97

"""List all available locations for a service."""

98

request = ListLocationsRequest()

99

request.name = parent # e.g., "projects/my-project"

100

request.page_size = 100

101

102

all_locations = []

103

104

while True:

105

response: ListLocationsResponse = client.list_locations(request)

106

all_locations.extend(response.locations)

107

108

# Check if there are more pages

109

if not response.next_page_token:

110

break

111

112

# Set up next page request

113

request.page_token = response.next_page_token

114

115

return all_locations

116

117

# Example usage

118

locations = list_all_locations("projects/my-project", location_client)

119

for location in locations:

120

print(f"Location: {location.location_id} ({location.display_name})")

121

```

122

123

### Filtering Locations by Region

124

125

```python

126

from google.cloud.location.locations_pb2 import ListLocationsRequest

127

128

def list_locations_by_region(parent: str, client, region_filter: str = None):

129

"""List locations with optional region filtering."""

130

request = ListLocationsRequest()

131

request.name = parent

132

133

if region_filter:

134

# Filter by region (e.g., "us-", "europe-", "asia-")

135

request.filter = f'labels.region:"{region_filter}*"'

136

137

response = client.list_locations(request)

138

return response.locations

139

140

# Examples

141

us_locations = list_locations_by_region("projects/my-project", client, "us")

142

europe_locations = list_locations_by_region("projects/my-project", client, "europe")

143

```

144

145

### Getting Location Details

146

147

```python

148

from google.cloud.location.locations_pb2 import GetLocationRequest, Location

149

150

def get_location_info(location_name: str, client) -> Location:

151

"""Get detailed information about a specific location."""

152

request = GetLocationRequest()

153

request.name = location_name # e.g., "projects/my-project/locations/us-central1"

154

155

location = client.get_location(request)

156

return location

157

158

def print_location_details(location: Location):

159

"""Print detailed location information."""

160

print(f"Location Name: {location.name}")

161

print(f"Location ID: {location.location_id}")

162

print(f"Display Name: {location.display_name}")

163

164

print("Labels:")

165

for key, value in location.labels.items():

166

print(f" {key}: {value}")

167

168

if location.metadata:

169

print(f"Metadata: {location.metadata}")

170

171

# Example usage

172

location = get_location_info("projects/my-project/locations/us-central1", client)

173

print_location_details(location)

174

```

175

176

### Location-Based Resource Selection

177

178

```python

179

from google.cloud.location.locations_pb2 import Location

180

181

def select_optimal_location(locations: list[Location], preferences: dict) -> Location:

182

"""Select optimal location based on preferences."""

183

scored_locations = []

184

185

for location in locations:

186

score = 0

187

188

# Score based on region preference

189

if preferences.get("preferred_region"):

190

if location.location_id.startswith(preferences["preferred_region"]):

191

score += 10

192

193

# Score based on labels

194

for label_key, preferred_value in preferences.get("labels", {}).items():

195

if location.labels.get(label_key) == preferred_value:

196

score += 5

197

198

# Score based on availability zones (if in metadata)

199

if preferences.get("multi_zone") and "zones" in location.labels:

200

zone_count = len(location.labels["zones"].split(","))

201

score += zone_count

202

203

scored_locations.append((location, score))

204

205

# Return location with highest score

206

if scored_locations:

207

return max(scored_locations, key=lambda x: x[1])[0]

208

209

return locations[0] if locations else None

210

211

# Example usage

212

preferences = {

213

"preferred_region": "us-central",

214

"labels": {

215

"tier": "premium"

216

},

217

"multi_zone": True

218

}

219

220

optimal_location = select_optimal_location(locations, preferences)

221

print(f"Selected location: {optimal_location.location_id}")

222

```

223

224

### Working with GAPIC Metadata

225

226

```python

227

from google.gapic.metadata.gapic_metadata_pb2 import GapicMetadata

228

229

def parse_gapic_metadata(metadata: GapicMetadata):

230

"""Parse and display GAPIC metadata information."""

231

print(f"Schema: {metadata.schema}")

232

print(f"Language: {metadata.language}")

233

print(f"Proto Package: {metadata.proto_package}")

234

print(f"Library Package: {metadata.library_package}")

235

236

print("\nServices:")

237

for service_name, service_transport in metadata.services.items():

238

print(f" Service: {service_name}")

239

240

for transport_name, client_config in service_transport.clients.items():

241

print(f" Transport: {transport_name}")

242

print(f" Client: {client_config.library_client}")

243

244

for rpc_name, method_list in client_config.rpcs.items():

245

print(f" RPC: {rpc_name}")

246

for method in method_list.methods:

247

print(f" Method: {method}")

248

```

249

250

### Multi-Region Service Deployment

251

252

```python

253

from google.cloud.location.locations_pb2 import Location

254

255

def plan_multi_region_deployment(locations: list[Location],

256

service_requirements: dict) -> dict:

257

"""Plan multi-region deployment based on requirements."""

258

deployment_plan = {

259

"primary_regions": [],

260

"secondary_regions": [],

261

"backup_regions": []

262

}

263

264

# Group locations by region

265

regions = {}

266

for location in locations:

267

region = location.location_id.split('-')[0] + '-' + location.location_id.split('-')[1]

268

if region not in regions:

269

regions[region] = []

270

regions[region].append(location)

271

272

# Sort regions by preference

273

preferred_regions = service_requirements.get("preferred_regions", [])

274

275

# Select primary regions

276

for region in preferred_regions:

277

if region in regions and len(deployment_plan["primary_regions"]) < 2:

278

deployment_plan["primary_regions"].extend(regions[region][:1])

279

280

# Select secondary regions

281

remaining_regions = [r for r in regions.keys()

282

if r not in [loc.location_id for loc in deployment_plan["primary_regions"]]]

283

284

for region in remaining_regions[:2]:

285

deployment_plan["secondary_regions"].extend(regions[region][:1])

286

287

# Select backup regions

288

for region in remaining_regions[2:4]:

289

deployment_plan["backup_regions"].extend(regions[region][:1])

290

291

return deployment_plan

292

293

# Example usage

294

requirements = {

295

"preferred_regions": ["us-central", "us-east"],

296

"min_regions": 3,

297

"disaster_recovery": True

298

}

299

300

deployment = plan_multi_region_deployment(locations, requirements)

301

print("Deployment Plan:")

302

print(f"Primary: {[loc.location_id for loc in deployment['primary_regions']]}")

303

print(f"Secondary: {[loc.location_id for loc in deployment['secondary_regions']]}")

304

print(f"Backup: {[loc.location_id for loc in deployment['backup_regions']]}")

305

```

306

307

### Location Metadata Processing

308

309

```python

310

from google.cloud.location.locations_pb2 import Location

311

from google.protobuf.struct_pb2 import Struct

312

313

def extract_location_capabilities(location: Location) -> dict:

314

"""Extract service capabilities from location metadata."""

315

capabilities = {

316

"location_id": location.location_id,

317

"display_name": location.display_name,

318

"services": [],

319

"features": {},

320

"zones": []

321

}

322

323

# Extract from labels

324

for key, value in location.labels.items():

325

if key.startswith("service/"):

326

service_name = key.replace("service/", "")

327

if value.lower() == "true":

328

capabilities["services"].append(service_name)

329

elif key.startswith("feature/"):

330

feature_name = key.replace("feature/", "")

331

capabilities["features"][feature_name] = value

332

elif key == "zones":

333

capabilities["zones"] = value.split(",")

334

335

# Extract from metadata if available

336

if location.metadata:

337

# Metadata processing would be service-specific

338

pass

339

340

return capabilities

341

342

# Example usage

343

for location in locations:

344

caps = extract_location_capabilities(location)

345

print(f"\nLocation: {caps['location_id']}")

346

print(f"Services: {', '.join(caps['services'])}")

347

print(f"Zones: {', '.join(caps['zones'])}")

348

if caps['features']:

349

print("Features:")

350

for feature, value in caps['features'].items():

351

print(f" {feature}: {value}")

352

```

353

354

### Region-Based Cost Optimization

355

356

```python

357

def calculate_deployment_cost(locations: list[Location],

358

usage_requirements: dict) -> dict:

359

"""Calculate estimated deployment costs by location."""

360

cost_estimates = {}

361

362

# Sample cost factors (would come from actual pricing data)

363

base_costs = {

364

"us-central": 1.0, # Base cost multiplier

365

"us-east": 0.95, # 5% cheaper

366

"us-west": 1.1, # 10% more expensive

367

"europe-west": 1.2, # 20% more expensive

368

"asia-east": 1.15 # 15% more expensive

369

}

370

371

for location in locations:

372

region_prefix = '-'.join(location.location_id.split('-')[:2])

373

base_multiplier = base_costs.get(region_prefix, 1.0)

374

375

# Calculate costs based on usage

376

compute_cost = usage_requirements.get("compute_hours", 0) * base_multiplier * 0.10

377

storage_cost = usage_requirements.get("storage_gb", 0) * base_multiplier * 0.02

378

network_cost = usage_requirements.get("network_gb", 0) * base_multiplier * 0.08

379

380

total_cost = compute_cost + storage_cost + network_cost

381

382

cost_estimates[location.location_id] = {

383

"compute": compute_cost,

384

"storage": storage_cost,

385

"network": network_cost,

386

"total": total_cost,

387

"multiplier": base_multiplier

388

}

389

390

return cost_estimates

391

392

# Example usage

393

usage = {

394

"compute_hours": 720, # 1 month

395

"storage_gb": 1000, # 1TB

396

"network_gb": 500 # 500GB transfer

397

}

398

399

costs = calculate_deployment_cost(locations, usage)

400

for location_id, cost_info in sorted(costs.items(), key=lambda x: x[1]["total"]):

401

print(f"{location_id}: ${cost_info['total']:.2f}/month")

402

```