使用 API 管理连接配置文件

概览

RESTgcloud

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • region:项目区域
  • connection-profile-id:连接配置文件 ID
  • connection-profile-display-name:连接配置文件显示名称
  • host-ip-address:来源 IP 地址
  • username:数据库用户名
  • password:数据库用户密码

HTTP 方法和网址:

POST https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles?connectionProfileId=connection-profile-id

请求 JSON 正文:

如需发送您的请求,请展开以下选项之一:

将请求正文保存在名为 request.json 的文件中,然后执行以下命令:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles?connectionProfileId=connection-profile-id"

将请求正文保存在名为 request.json 的文件中,然后执行以下命令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles?connectionProfileId=connection-profile-id" | Select-Object -Expand Content

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/project-id/locations/region/operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata",
    "createTime": "2020-06-12T14:46:01.744267779Z",
    "target": "projects/project-id/locations/region/connectionProfiles/connection-profile-id",
    "verb": "create",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": false
}

如需查看有关使用 gcloud 创建 Database Migration Service 连接配置文件的概要信息,请点击此处

创建后,您可以调用 connectionProfiles/get 方法来查看连接配置文件的相关信息。

RESTgcloud

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • region:项目区域
  • connection-profile-id:连接配置文件 ID

HTTP 方法和网址:

GET https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id

如需发送您的请求,请展开以下选项之一:

执行以下命令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id"

执行以下命令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id" | Select-Object -Expand Content

您应该收到类似以下内容的 JSON 响应:

如需详细了解如何使用 gcloud 检索连接配置文件的相关信息,请点击此处

获取连接配置文件的相关信息

RESTgcloud

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • region:项目区域
  • connection-profile-id:连接配置文件 ID

HTTP 方法和网址:

GET https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id

如需发送您的请求,请展开以下选项之一:

执行以下命令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id"

执行以下命令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id" | Select-Object -Expand Content

您应该收到类似以下内容的 JSON 响应:

如需详细了解如何使用 gcloud 检索连接配置文件的相关信息,请点击此处

列出连接配置文件

以下代码展示了一个检索所有连接配置文件的相关信息的请求。

RESTgcloud

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • region:项目区域
您还可以过滤 Database Migration Service 检索到的连接配置文件列表,方法如下:

  • orderBy: 使用此过滤条件可按字母顺序检索特定区域的所有连接配置文件列表。例如,orderBy=name 过滤条件会按名称的字母顺序返回所有连接个人资料。
  • pageSize: 使用此过滤条件可指定 Database Migration Service 在页面上检索和显示的连接配置文件的数量上限。例如,通过设置 pageSize=10,Database Migration Service 最多会针对网页返回 10 个连接配置文件。

  • 如果连接配置文件超过 10 个,则会显示在其他页面上。每个页面末尾都会显示 nextPageToken 参数和唯一标识符。使用该标识符检索以下页面的连接配置文件列表。

HTTP 方法和网址:

GET https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles

如需发送您的请求,请展开以下选项之一:

执行以下命令:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles"

执行以下命令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles" | Select-Object -Expand Content

您应该收到类似以下内容的 JSON 响应:

如需详细了解如何使用 gcloud 检索所有连接配置文件的相关信息,请点击此处

更新连接配置文件

以下示例展示了用于更新现有连接配置文件的用户名和密码字段的请求。通过在请求中使用 updateMask 参数,使只有这些字段需要包含在请求正文中。

RESTgcloud

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • region:项目区域
  • connection-profile-id:连接配置文件 ID
  • username:数据库用户名
  • password:数据库用户密码

HTTP 方法和网址:

PATCH 

请求 JSON 正文:

如需发送您的请求,请展开以下选项之一:

将请求正文保存在名为 request.json 的文件中,然后执行以下命令:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
""

将请求正文保存在名为 request.json 的文件中,然后执行以下命令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "" | Select-Object -Expand Content

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/project-id/locations/region/operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata",
    "createTime": "2020-06-12T14:46:01.744267779Z",
    "target": "projects/project-id/locations/region/connectionProfiles/connection-profile-id",
    "verb": "update",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": false
}

如需详细了解如何使用 gcloud 更新连接配置文件,请点击此处

删除连接配置文件

RESTgcloud

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • region:项目区域
  • connection-profile-id:连接配置文件 ID

HTTP 方法和网址:

DELETE https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id

如需发送您的请求,请展开以下选项之一:

执行以下命令:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id"

执行以下命令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id" | Select-Object -Expand Content

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/project-id/locations/region/operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata",
    "createTime": "2020-06-12T14:46:01.744267779Z",
    "target": "projects/project-id/locations/region/connectionProfiles/connection-profile-id",
    "verb": "delete",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": false
}

如需详细了解如何使用 gcloud 删除连接配置文件,请点击此处

RESTgcloud

在使用任何请求数据之前,请先进行以下替换:

  • project-id:项目 ID
  • region:项目区域
  • connection-profile-id:连接配置文件 ID

HTTP 方法和网址:

DELETE https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id?force=true

如需发送您的请求,请展开以下选项之一:

执行以下命令:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id?force=true"

执行以下命令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://datamigration.googleapis.com/v1/projects/project-id/locations/region/connectionProfiles/connection-profile-id?force=true" | Select-Object -Expand Content

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/project-id/locations/region/operations/operation-1591973161667-5a7e422cb0ba4-3004980d-2ae97165",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.clouddms.v1.OperationMetadata",
    "createTime": "2020-06-12T14:46:01.744267779Z",
    "target": "projects/project-id/locations/region/connectionProfiles/connection-profile-id",
    "verb": "create",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": false
}

如需详细了解如何使用 gcloud 同时删除连接配置文件和关联的实例,请点击此处