GeezerVison is showing github.com — Disk objects aren't deleted when the VM is deleted · Issue #927 · googleapis/google-cloud-node
Disk objects aren't deleted when the VM is deleted #927Labels api: computeIssues related to the Compute Engine API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DescriptionThere seems to be an issue with the VM instances when recycling the names. In the below example I create, delete and create again an instance using the same name. The error is shown in the output snippet below.
var BUILDER_MACHINE_NAME = "image2";
var BUILDER_MACHINE_CONFIG = {
os: "ubuntu",
machineType: "g1-small"
};
var gce = gcloud.compute();
var zone = gce.zone(zone);
zone.createVM(BUILDER_MACHINE_NAME, BUILDER_MACHINE_CONFIG, function(err, vm, operation, apiResponse) {
if (err) { return callback(err); }
console.dir(apiResponse);
console.log("1 --------------");
operation.onComplete(function(err, metadata) {
if (err) { return callback(err); }
console.dir(metadata);
console.log("2 --------------");
vm.delete(function(err, operation, apiResponse) {
if (err) { return callback(err); }
console.dir(apiResponse);
console.log("3 --------------");
operation.onComplete(function(err, metadata) {
if (err) { return callback(err); }
console.dir(metadata);
console.log("4 --------------");
zone.createVM(BUILDER_MACHINE_NAME, BUILDER_MACHINE_CONFIG, function(err, vm, operation, apiResponse) {
if (err) { return callback(err); }
console.dir(apiResponse);
console.log("5 --------------");
operation.onComplete(function(err, metadata) {
if (err) { return callback(err); }
console.dir(metadata);
});
});
});
});
});
});
The operation after the 2nd createVM call will issue the error:
...
4 --------------
{ kind: 'compute#operation',
id: '1947681473087096016',
name: 'operation-1447083184520-5241d4f2c7b41-6718dbc3-790a19cf',
zone: 'https://www.googleapis.com/compute/v1/projects/sigma-cairn-99810/zones/europe-west1-c',
operationType: 'insert',
targetLink: 'https://www.googleapis.com/compute/v1/projects/sigma-cairn-99810/zones/europe-west1-c/instances/image2',
status: 'PENDING',
user: '262451203973-qh79osjjiu4p1m535ctcu8easjdqsqq3@developer.gserviceaccount.com',
progress: 0,
insertTime: '2015-11-09T07:33:05.005-08:00',
startTime: '2015-11-09T07:33:05.367-08:00',
selfLink: 'https://www.googleapis.com/compute/v1/projects/sigma-cairn-99810/zones/europe-west1-c/operations/operation-1447083184520-5241d4f2c7b41-6718dbc3-790a19cf' }
5 --------------
{ errors:
[ { code: 'RESOURCE_ALREADY_EXISTS',
message: 'The resource \'projects/sigma-cairn-99810/zones/europe-west1-c/disks/image2\' already exists' } ] }
Can the VM instance names be reused? (Can you please point me to the documentation, if there is smth like this specified)
Thanks! Activitystephenplusplus commented on Nov 9, 2015 Found the issue! Our API allows you to provide the os config property, which we then turn into a full object the API call to create the VM actually wants:
{
name: 'image2',
machineType: 'zones/us-central1-a/machineTypes/g1-small',
// ...
disks: [
{
boot: true,
initializeParams: {
sourceImage: 'https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-1504-vivid-v20150616a'
}
}
]
}
The problem is that a disk is automatically created for your VM. When you delete the VM, by default, it thinks you won't want the disk to be deleted as well. Here's what we need to do to change that:
disks: [
{
+ autoDelete: true,
boot: true,
I'll put a PR that defaults autoDelete to true, but if you need this behavior now, you'll need to manually form the configuration object with the help of gce-images:
var config = { keyFilename: '', projectId: '' } // must be provided to gceImages
var gcloud = require('gcloud')(config)
var gceImages = require('gce-images')(config)
gceImages.getLatest('ubuntu', function (err, image) {
if (err) // ...
var cfg = {
machineType: 'g1-small',
disks: [
{
autoDelete: true,
boot: true,
initializeParams: {
sourceImage: image.selfLink
}
}
]
}
zone.createVM('vm-name', cfg, function () {})
})
Good catch, by the way. I had quite a few lingering disks in my test project :) added type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. on Nov 9, 2015stephenplusplus commented on Nov 9, 2015 Sorry, my last post had some bugs I just fixed. Refresh if you have already read it to get the latest. gabipetrovay commented on Nov 9, 2015 gabipetrovay commented on Nov 9, 2015 😜 👍 🎉
Same here with the disks. :) gabipetrovay commented on Nov 9, 2015 Stumbling upon a new error when building the images object:
{ [Error: Scopes are required for this request.] code: 'MISSING_SCOPE' }
I assume this has to do with the authentication. I am initialising gce-images with:
var gceImages = require("gce-images");
var images = gceImages({ keyFile: "/Users/gabriel/Work/gcloud/keyfile.json"});
This last line is missing from your example above (gceImages has no getLatest method). stephenplusplus commented on Nov 9, 2015 Sorry, try un- and re-installing gce-images (so that you get 0.2.1). Pushed a fix! gabipetrovay commented on Nov 9, 2015 Ok, I am further. 😄
Next one:
{ [ApiError: Invalid value for field 'resource.disks': ''. At most one persistent disk can be marked as a boot device.]
errors:
[ { domain: 'global',
reason: 'invalid',
message: 'Invalid value for field \'resource.disks\': \'\'. At most one persistent disk can be marked as a boot device.' } ],
code: 400,
message: 'Invalid value for field \'resource.disks\': \'\'. At most one persistent disk can be marked as a boot device.',
response: undefined }
I try to build the VM instance using this config:
var BUILDER_MACHINE_CONFIG = {
os: "ubuntu",
machineType: "g1-small",
disks: [{
autoDelete: true,
boot: true,
initializeParams: {
sourceImage: sourceImage
}
}]
}; stephenplusplus commented on Nov 9, 2015 Thanks for being patient with me :) Remove the os from the BUILDER_MACHINE_CONFIG object. gabipetrovay commented on Nov 9, 2015 Makes sense because the sourceImage URL has the info ... gabipetrovay commented on Nov 9, 2015 Ok, we're flying! 🚀
Thanks also for help. I'll bug you later. No worries! 😝
You can close this issue is you don't have anything to track further. changed the title [-]Reusing VM instance names: RESOURCE_ALREADY_EXISTS[/-] [+]Disk objects aren't deleted when the VM is deleted[/+] on Nov 9, 2015stephenplusplus commented on Nov 9, 2015 Thanks again for catching this! I'll keep this open to make sure we don't forget to set autoDelete to true.
MetadataMetadataapi: computeIssues related to the Compute Engine API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DevelopmentNo branches or pull requestsIssue actions
|