我正在尝试构建一个将启动(除其他外)启动 Azure VM 的节点应用程序。
我目前可以毫无问题地登录 Azure,但是当我像下面 github 上的示例页面所示那样启动 VM 时,我得到了错误TypeError: Cannot read property 'virtualMachines' of undefined
,我不确定为什么考虑到我实际上是从我找到的示例中获取代码。
https://github.com/Azure/azure-sdk-for-node/blob/master/examples/ARM/compute/vm-sample.js
'use strict';
// Packages
const cron = require("cron"),
util = require('util'),
path = require('path'),
async = require('async'),
Azure = require("azure"),
msRestAzure = require('ms-rest-azure'),
ComputeManagementClient = require('azure-arm-compute'),
StorageManagementClient = require('azure-arm-storage'),
NetworkManagementClient = require('azure-arm-network'),
ResourceManagementClient = require('azure-arm-resource').ResourceManagementClient,
SubscriptionManagementClient = require('azure-arm-resource').SubscriptionClient;
// Config
const config = require("./config.js");
var subscriptionId = config.azure_creds.AZURE_SUBSCRIPTION_ID;
var AZURE_USER = config.azure_creds.AZURE_USER;
var AZURE_PASS = config.azure_creds.AZURE_PASS;
console.log('Starting application...');
msRestAzure.loginWithUsernamePassword(AZURE_USER, AZURE_PASS, (err, credentials) => {
if (err) throw err;
// let storageClient = Azure.createStorageManagementClient(credentials, subscriptionId);
var computeClient;
var resourceGroupName = 'testing-resourceGroup';
var vmName = 'vm-test-1';
console.log('Logged into Azure...');
console.log('Starting VM...');
computeClient.virtualMachines.start(resourceGroupName, vmName, function (err, result) {
if (err) {
console.log(util.format('\n???????Error while starting the VM:\n%s',
util.inspect(err, { depth: null })));
console.log(err);
throw(err);
} else {
console.log(util.format('\n######Start the VM is successful.\n%s',
util.inspect(result, { depth: null })));
console.log(result);
}
});
computeClient = new ComputeManagementClient(credentials, subscriptionId);
});
我希望该程序能够运行并启动我指定的 Azure VM,但它甚至无法正确运行该程序,让其启动 VM。以下是我运行程序时的输出
Starting application...
Logged into Azure...
Starting VM...
/home/ec2-user/environment/start-stop/app.js:43
computeClient.virtualMachines.start(resourceGroupName, vmName, function (err, result) {
^
TypeError: Cannot read property 'virtualMachines' of undefined
at msRestAzure.loginWithUsernamePassword (/home/ec2-user/environment/start-stop/app.js:43:14)
at /home/ec2-user/environment/start-stop/node_modules/ms-rest-azure/lib/login.js:361:14
at /home/ec2-user/environment/start-stop/node_modules/async/dist/async.js:473:16
at next (/home/ec2-user/environment/start-stop/node_modules/async/dist/async.js:5315:29)
at /home/ec2-user/environment/start-stop/node_modules/async/dist/async.js:958:16
at /home/ec2-user/environment/start-stop/node_modules/ms-rest-azure/lib/login.js:121:5
at /home/ec2-user/environment/start-stop/node_modules/async/dist/async.js:473:16
at iterateeCallback (/home/ec2-user/environment/start-stop/node_modules/async/dist/async.js:976:17)
at /home/ec2-user/environment/start-stop/node_modules/async/dist/async.js:958:16
at /home/ec2-user/environment/start-stop/node_modules/ms-rest-azure/lib/login.js:118:14