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 — vm.detachDisk requires a device name · Issue #922 · googleapis/google-cloud-node

vm.detachDisk requires a device name #922

New issue
Copy link
New issue
Copy link
Closed
Closed
vm.detachDisk requires a device name#922
Copy link
Assignees
yoshi-automation
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

@stephenplusplus
stephenplusplus
opened on Oct 30, 2015
Issue body actions

Right now, we're sending through a disk name, which !== device name.

Here's a fix that will find the device name if the provided device name automatically if a Disk object doesn't have it already:

/**
 * Custom error type for errors related to detaching a disk.
 *
 * @param {string} message - Custom error message.
 * @return {Error}
 */
var DetachDiskError = createErrorClass('DetachDiskError', function(message) {
  this.message = message;
});

VM.prototype.detachDisk = function(deviceName, callback) {
  var self = this;

  if (deviceName instanceof Disk) {
    var disk = deviceName;

    if (disk.metadata.deviceName) {
      self.detachDisk(disk.metadata.deviceName, callback);
      return;
    }

    this.getMetadata(function(err, metadata) {
      if (err) {
        callback(new DetachDiskError(err.message));
        return;
      }

      var deviceName;
      var baseUrl = 'https://www.googleapis.com/compute/v1/';

      // Try to find the deviceName by matching the source of the attached disks
      // to the name of the disk provided by the user.
      for (var i = 0; !deviceName && i < metadata.disks.length; i++) {
        var attachedDisk = metadata.disks[i];
        var source = attachedDisk.source.replace(baseUrl, '');

        if (source === disk.formattedName) {
          deviceName = attachedDisk.deviceName;
        }
      }

      if (deviceName) {
        self.detachDisk(deviceName, callback);
      } else {
        callback(new DetachDiskError('Could not find a deviceName for disk.'));
      }
    });
    return;
  }

  var query = {
    deviceName: deviceName
  };

  this.makeReq_('POST', '/detachDisk', query, null, callback || util.noop);
};

// system test...
it('should attach and detach a disk', function(done) {
  var disk = zone.disk(generateName());

  // This test waits on a lot of operations.
  this.timeout(90000);

  async.series([
    createDisk,
    attachDisk,
    detachDisk
  ], done);

  function createDisk(callback) {
    var config = {
      os: 'ubuntu'
    };

    disk.create(config, execAfterOperationComplete(callback));
  }

  function attachDisk(callback) {
    vm.attachDisk(disk, execAfterOperationComplete(callback));
  }

  function detachDisk(callback) {
    vm.detachDisk(disk, execAfterOperationComplete(callback));
  }
});

Activity

  1. 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 Oct 30, 2015
  2. stephenplusplus
    changed the title [-]zone.detachDisk requires a device name[/-] [+]vm.detachDisk requires a device name[/+] on Oct 30, 2015
  3. callmehiphop
    closed this as completedin #929on Nov 9, 2015
  4. cromwellian commented on Dec 5, 2018

    @cromwellian
    cromwellian
    on Dec 5, 2018
    More actions

    This code fails if the disk is created with the Beta Compute API, then the disk base URL will be https://www.googleapis.com/compute/beta/

  5. JustinBeckwith
    assigned
    yoshi-automation
    on Feb 1, 2021
  6. miguelvelezsa
    added a commit that references this issue on Jul 23, 2025

    chore: release 2.9.1 (#922)

    dc45ffb
  7. sofisl
    added 9 commits that reference this issue on Jan 27, 2026

    chore(deps): update dependency tmp to v0.2.3 (#922)

    eeb7d40

    chore(deps): update dependency tmp to v0.2.3 (#922)

    a67ab55

    chore(deps): update dependency tmp to v0.2.3 (#922)

    5093f4b

    chore(deps): update dependency tmp to v0.2.3 (#922)

    3992ebd

    chore(deps): update dependency tmp to v0.2.3 (#922)

    6df33bb

    chore(deps): update dependency tmp to v0.2.3 (#922)

    e16ba74

    chore(deps): update dependency tmp to v0.2.3 (#922)

    20d9f86

    chore(deps): update dependency tmp to v0.2.3 (#922)

    b013513

    chore: update CODEOWNERS config (#922)

    47daa17
  8. sofisl
    added a commit that references this issue on Feb 25, 2026

    docs: fix rendering for createReadStream method in File class (#922)

    b5d7411
  9. sofisl
    added 2 commits that reference this issue on Mar 13, 2026

    fix: upgrade gaxios (#922)

    69cf5e5

    chore: release main (#931)

    0101134
  10. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    docs: fix rendering for createReadStream method in File class (google…

    6f91cc2
  11. GautamSharda
    added 2 commits that reference this issue on Mar 23, 2026

    chore(nodejs): update client ref docs link in metadata (#922)

    5b08331

    chore(nodejs): update client ref docs link in metadata (#922)

    a250a29
  12. shivanee-p
    added a commit that references this issue on Mar 27, 2026

    chore(nodejs): update client ref docs link in metadata (#922)

    0ad270d
  13. thiyaguk09
    added a commit that references this issue on May 5, 2026

    chore(nodejs): update client ref docs link in metadata (googleapis#922)

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

Metadata

Metadata

Assignees

  • @yoshi-automation
    yoshi-automation

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.