【发布时间】:2019-06-11 08:55:44
【问题描述】:
我将尝试在 Google Compute Engine 实例上设置磁盘标签。基本上这里记录的内容:
https://cloud.google.com/compute/docs/reference/rest/v1/disks/setLabels
不幸的是也使用了谷歌提供的简单代码:
require_once __DIR__ . '/vendor/autoload.php';
$client = new Google_Client();
$client->setApplicationName('Google-ComputeSample/0.1');
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/cloud-platform');
$service = new Google_Service_Compute($client);
$project = 'my-project';
$zone = 'my-zone';
$resource = 'my-resource'; // here i set the disk name
$requestBody = new Google_Service_Compute_ZoneSetLabelsRequest();
$response = $service->disks->setLabels($project, $zone, $resource, $requestBody);
echo '<pre>', var_export($response, true), '</pre>', "\n";
?>
我总是遇到 500 错误:
未捕获的 Google_Service_Exception: { "error": { "errors": [ { "domain": "global", "reason": "conditionNotMet", "message": "标签指纹无效或资源标签已更改", “locationType”:“header”,“location”:“If-Match”}],“code”:412,“message”:“标签指纹无效或资源标签已更改”}}
我想我有错误的标签语法。但是在label方法中,我尝试了几种语法:
$requestBody->setLabels(array("mylabel"=>"1"));
$requestBody->setLabels(serialize(array("mylabel"=>"1")));
$requestBody->setLabels('"mylabel":"1"');
$requestBody->setLabels('{"mylabel":"1"}');
但没有任何工作。并且什么都没有改变(总是 500 错误,同样的例外)。我做错了什么?
【问题讨论】: