Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Bug: Attaching existing disk when creating a new VM #107

Closed
thoughtspeed7 opened this issue Jun 21, 2018 · 5 comments · Fixed by #371
Closed

Bug: Attaching existing disk when creating a new VM #107

thoughtspeed7 opened this issue Jun 21, 2018 · 5 comments · Fixed by #371
Assignees
Labels
api: compute Issues related to the googleapis/nodejs-compute API. type: docs Improvement to the documentation for an API.

Comments

@thoughtspeed7
Copy link

This is probably a bug. I am trying to create a new VM by attaching an existing disk to it. But I get the Invalid value for field 'resource.disks[0].source': ''. Source url of disk is missing. error when running below code. Get the same error when I pass disk.get() results to the zone.createVM() method if at all that helps. Can someone help? I have a deadline to meet on this piece of functionality. You can also check https://stackoverflow.com/questions/50968528/create-a-new-vm-by-attaching-an-existing-disk-using-node-js-client-library-for-g for discussions on this so far. Thanks in advance!

const main = (req, res) => {

    const Compute = require('@google-cloud/compute');
    const compute = new Compute();
    const zone = compute.zone('us-central1-f');
    let disk;
    const diskName = 'debian-http';
    const vmName = 'debian-http'
    let vm;

    disk = zone.disk(diskName);
    
    zone.createVM(vmName, {
        disks: [disk], 
        http: true, 
        machineType: 'f1-micro'
    })
    .then((data) => {
        vm = data[0];
        const operation = data[1];
        return operation.promise();
    })
    .then(() => {
        console.log('vm created successfully');   
        res.send('vm created successfully');     
    })
    .catch((e) => {
        console.error(e);
        res.send(e.message);
    });    

};
@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Jun 21, 2018
@stephenplusplus
Copy link
Contributor

The input for the disks property to createVM is meant to match what the upstream API expects, which is a Disk resource, and not our custom Disk type.

You can refer to the method's documentation here: https://cloud.google.com/nodejs/docs/reference/compute/0.10.x/Zone#createVM

@stephenplusplus stephenplusplus added type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Jun 21, 2018
@thoughtspeed7
Copy link
Author

Thanks for your input. I've tried passing the expected JSON directly but get the same error. Also, I don't see any property by the name "source" on the Disk resource documentation which is what is expected by the REST API as per the error I get. Can you help me with how to get a reference to an existing disk and pass it to the zone.createVM method? There is no documentation for this. Thanks.

@stephenplusplus
Copy link
Contributor

Sorry for my mistake, it looks like our docs aren't correct. We don't expect a Disk resource as the API describes, but an object formatted according to the specifications under disks here: https://cloud.google.com/compute/docs/reference/rest/v1/instances/insert

We will update our docs to point there instead.

@stephenplusplus stephenplusplus added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. type: docs Improvement to the documentation for an API. and removed type: question Request for information or clarification. Not an issue. labels Jun 21, 2018
@thoughtspeed7
Copy link
Author

Yes, the documentation at https://cloud.google.com/nodejs/docs/reference/compute/0.10.x/Zone#createVM is incorrect. I made this work by passing raw JSON to the zone.createVM method as below:

zone.createVM('debian-http', {
    disks: [{
        boot: true,
        source: 'https://www.googleapis.com/compute/v1/projects/[project-id]/zones/us-central1-f/disks/debian-http'
    }], 
    http: true, 
    machineType: 'f1-micro'
})

More config options for the disks property can be found at https://cloud.google.com/compute/docs/reference/rest/v1/instances/insert. Hope this helps others!

@JustinBeckwith JustinBeckwith added the 🚨 This issue needs some love. label Dec 18, 2018
@sduskis sduskis removed the type: docs Improvement to the documentation for an API. label Feb 5, 2019
@JustinBeckwith JustinBeckwith added type: docs Improvement to the documentation for an API. and removed 🚨 This issue needs some love. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Feb 10, 2019
@bcoe bcoe closed this as completed in #371 Dec 2, 2019
@google-cloud-label-sync google-cloud-label-sync bot added the api: compute Issues related to the googleapis/nodejs-compute API. label Jan 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: compute Issues related to the googleapis/nodejs-compute API. type: docs Improvement to the documentation for an API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants