Pilsen
Pilsen

Reputation: 127

Node.js Azure sdk - getting the Virtual Machine state

I've started to look into the azure sdk for node.js (link below) and interestingly enough I've hit a wall in what I'd image would be one of the most common tasks one would want to achieve using Azure's REST endpoints which is checking the status of a virtual machine.

I can easily get a list of all machine, or one in particular but the response from this services don't include the current status of the VM (running,stopped etc.)

There's absolutely no info out there regarding this particular scenario in the docos or the web other than a blog post (https://github.com/Azure/azure-xplat-cli/issues/2565) which is actually in regards of a different library.

Please not that I'm using the azure-arm-compute library which is part of the Node.js azure sdk.

Any help would be very much appreciated

github repo: https://github.com/Azure/azure-sdk-for-node

Upvotes: 1

Views: 1881

Answers (1)

Aaron Chen
Aaron Chen

Reputation: 9950

To get Virtual Machine statuses, please use function get(resourceGroupName, vmName, optionsopt, optionalCallbackopt), and pass the vaule {expand: 'instanceView'} as the options parameter.

var msRestAzure = require('ms-rest-azure');
var computeManagementClient = require('azure-arm-compute');

// Interactive Login
// It provides a url and code that needs to be copied and pasted in a browser and authenticated over there. If successful, 
// the user will get a DeviceTokenCredentials object.
msRestAzure.interactiveLogin(function(err, credentials) {
  var client = new computeManagementClient(credentials, 'ed0caab7***');

  client.virtualMachines.get('<resourceGroupName>', '<vmName>', {expand: 'instanceView'}, function(err, result, request, response) {
    if (err) console.log(err);
    console.log(result.instanceView);
  });
});

enter image description here

Upvotes: 6

Related Questions