GCP Compute Engine Python API 创建客户端的正确方法
GCP Compute Engine Python API proper way to create clients
在 python 中创建 gcp 计算客户端的当前“标准”方法是什么?我都看过:
import googleapiclient.discovery
service = googleapiclient.discovery.build(
'container', 'v1', credentials=credentials)
body = {
"autoCreateSubnetworks": False,
"description": "",
"mtu": 1460.0,
"name": "test_network",
"routingConfig": {
"routingMode": "REGIONAL"
}
}
network = compute.networks().insert(project=project_id, body=body, requestId=str(uuid.uuid4())).execute()
和:
from google.cloud import compute_v1
compute = compute_v1.InstancesClient(credentials=credentials)
net = compute.Network()
net.auto_create_subnetworks = False
net.description = ""
net.mtu = 1460.0
net.name = "test_network"
net.routing_config = {
"routingMode": "REGIONAL"
}
request = InsertNetworkRequest()
request.project = project_id
request.request_id = str(uuid.uuid4())
request.network_resource = net
network = compute.NetworksClient().insert(request=request)
Google 是否计划在未来某个地方只支持一个?
根据此存储库 google-api-python-client 库,其中解释说目前支持它,但还没有停止更新的日期。
This library is considered complete and is in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.
建议使用存储库 google-cloud-python,它有 3 个开发分支,GA(通用可用性)、Beta 支持和 Alpha 支持。
在 python 中创建 gcp 计算客户端的当前“标准”方法是什么?我都看过:
import googleapiclient.discovery
service = googleapiclient.discovery.build(
'container', 'v1', credentials=credentials)
body = {
"autoCreateSubnetworks": False,
"description": "",
"mtu": 1460.0,
"name": "test_network",
"routingConfig": {
"routingMode": "REGIONAL"
}
}
network = compute.networks().insert(project=project_id, body=body, requestId=str(uuid.uuid4())).execute()
和:
from google.cloud import compute_v1
compute = compute_v1.InstancesClient(credentials=credentials)
net = compute.Network()
net.auto_create_subnetworks = False
net.description = ""
net.mtu = 1460.0
net.name = "test_network"
net.routing_config = {
"routingMode": "REGIONAL"
}
request = InsertNetworkRequest()
request.project = project_id
request.request_id = str(uuid.uuid4())
request.network_resource = net
network = compute.NetworksClient().insert(request=request)
Google 是否计划在未来某个地方只支持一个?
根据此存储库 google-api-python-client 库,其中解释说目前支持它,但还没有停止更新的日期。
This library is considered complete and is in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.
建议使用存储库 google-cloud-python,它有 3 个开发分支,GA(通用可用性)、Beta 支持和 Alpha 支持。