GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #927

New issue
Copy link
New issue
Copy link
Closed
Closed
Disk objects aren't deleted when the VM is deleted#927
Copy link
Assignees
stephenplusplus
Labels
api: computeIssues related to the Compute Engine API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@gabipetrovay
gabipetrovay
opened on Nov 9, 2015
Issue body actions

There 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!

Activity

  1. stephenplusplus commented on Nov 9, 2015

    @stephenplusplus
    stephenplusplus
    on Nov 9, 2015
    Contributor
    More actions

    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 :)

  2. stephenplusplus
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: computeIssues related to the Compute Engine API.
    on Nov 9, 2015
  3. stephenplusplus commented on Nov 9, 2015

    @stephenplusplus
    stephenplusplus
    on Nov 9, 2015
    Contributor
    More actions

    Sorry, my last post had some bugs I just fixed. Refresh if you have already read it to get the latest.

  4. gabipetrovay commented on Nov 9, 2015

    @gabipetrovay
    gabipetrovay
    on Nov 9, 2015
    Author
    More actions

    I am trying it out now.

  5. gabipetrovay commented on Nov 9, 2015

    @gabipetrovay
    gabipetrovay
    on Nov 9, 2015
    Author
    More actions

    😜 👍 🎉

    Same here with the disks. :)

  6. gabipetrovay commented on Nov 9, 2015

    @gabipetrovay
    gabipetrovay
    on Nov 9, 2015
    Author
    More actions

    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).

  7. stephenplusplus commented on Nov 9, 2015

    @stephenplusplus
    stephenplusplus
    on Nov 9, 2015
    Contributor
    More actions

    Sorry, try un- and re-installing gce-images (so that you get 0.2.1). Pushed a fix!

  8. gabipetrovay commented on Nov 9, 2015

    @gabipetrovay
    gabipetrovay
    on Nov 9, 2015
    Author
    More actions

    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
            }
        }]
    };  
  9. stephenplusplus commented on Nov 9, 2015

    @stephenplusplus
    stephenplusplus
    on Nov 9, 2015
    Contributor
    More actions

    Thanks for being patient with me :) Remove the os from the BUILDER_MACHINE_CONFIG object.

  10. gabipetrovay commented on Nov 9, 2015

    @gabipetrovay
    gabipetrovay
    on Nov 9, 2015
    Author
    More actions

    Makes sense because the sourceImage URL has the info ...

  11. gabipetrovay commented on Nov 9, 2015

    @gabipetrovay
    gabipetrovay
    on Nov 9, 2015
    Author
    More actions

    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.

  12. stephenplusplus
    changed the title [-]Reusing VM instance names: RESOURCE_ALREADY_EXISTS[/-] [+]Disk objects aren't deleted when the VM is deleted[/+] on Nov 9, 2015
  13. stephenplusplus commented on Nov 9, 2015

    @stephenplusplus
    stephenplusplus
    on Nov 9, 2015
    Contributor
    More actions

    Thanks again for catching this! I'll keep this open to make sure we don't forget to set autoDelete to true.

  14. stephenplusplus
    closed this as completedin #930on Nov 10, 2015
  15. JustinBeckwith
    assigned
    stephenplusplus
    on Feb 1, 2021
  16. sofisl
    added a commit that references this issue on Nov 11, 2022

    chore: update v2.12.0 gapic-generator-typescript (#927)

    c82318a
  17. sofisl
    added a commit that references this issue on Jan 17, 2023

    chore: release 2.3.6 (#927)

    4ba6ed8
  18. miguelvelezsa
    added a commit that references this issue on Jan 28, 2026

    chore: Change the Codeowner to cloud-native-db-dpes (#927)

    1b22746
  19. sofisl
    added a commit that references this issue on Feb 5, 2026

    chore: Change the Codeowner to cloud-native-db-dpes (#927)

    afc628e
  20. sofisl
    added a commit that references this issue on Feb 17, 2026

    chore: Change the Codeowner to cloud-native-db-dpes (#927)

    173e801
  21. GautamSharda
    added a commit that references this issue on Mar 11, 2026

    docs: document version support goals (#927)

    a359b4b
  22. GautamSharda
    added 4 commits that reference this issue on Mar 23, 2026

    fix(deps): google-gax v2.24.1 (#927)

    f60fcbe

    chore: release 3.6.0 (#929)

    e342538

    fix(deps): google-gax v2.24.1 (#927)

    74bd70f

    chore: release 3.6.0 (#929)

    5bb983a
  23. shivanee-p
    added 2 commits that reference this issue on Mar 27, 2026

    fix(deps): google-gax v2.24.1 (#927)

    581640b

    chore: release 3.6.0 (#929)

    d063d9c
  24. thiyaguk09
    added 2 commits that reference this issue on May 5, 2026

    fix(deps): google-gax v2.24.1 (googleapis#927)

    84b0ff4

    chore: release 3.6.0 (googleapis#929)

    48df888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @stephenplusplus
    stephenplusplus

Labels

api: computeIssues related to the Compute Engine API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.