When running the following which is identical to the documentation provided on git-hub (Minus the ToString() which causes another error) I get the following error.
CODE:
var fs = require('fs'),
computeManagement = require('azure-mgmt-compute');
var computeManagementClient = computeManagement.createComputeManagementClient(computeManagement.createCertificateCloudCredentials({
subscriptionId: 'sub id',
pem: fs.readFileSync('location to pem').toString()
}));
computeManagementClient.virtualMachineImages.list(function(err, result) {
if (err) {
console.error(err);
} else {
console.info(result);
}
});
ERROR:
c:\malum\Custom_Modules\azure-node\lib\index.js:10
computeManagementClient.virtualMachineImages.list(function(err, result)
{
^
TypeError: Cannot call method 'list' of undefined
at c:\malum\Custom_Modules\azure-node\lib\index.js:10:47
at Object.<anonymous> (c:\malum\Custom_Modules\azure-node\lib\index.js:21:2)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at module.exports (c:\malum\applications\deploy\index.js:8:16)
at Function.tokens (c:\malum\app.js:155:56)
Ive console.log()'d the computeManagement object and this is what i get:
{ pipeline:
{ [Function: runFilteredRequest]
add: [Function],
get: [Function],
post: [Function],
delete: [Function],
put: [Function],
merge: [Function],
head: [Function] },
credentials:
{ subscriptionId: 'SUBSCRIPTION ID',
credentials:
{ subscriptionId: 'SUBSCRIPTION ID',
pem: 'PEM CERT INFO',
key: undefined } },
baseUri: 'https://management.core.windows.net',
apiVersion: '2014-05-01',
longRunningOperationInitialTimeout: -1,
longRunningOperationRetryTimeout: -1,
deployments: { client: [Circular] },
extensionImages: { client: [Circular] },
hostedServices: { client: [Circular] },
loadBalancers: { client: [Circular] },
operatingSystems: { client: [Circular] },
serviceCertificates: { client: [Circular] },
virtualMachineDisks: { client: [Circular] },
virtualMachineExtensions: { client: [Circular] },
virtualMachines: { client: [Circular] },
virtualMachineOSImages: { client: [Circular] },
virtualMachineVMImages: { client: [Circular] } }
That doesn't have a virtualMachineImages method which makes sense. Even more interesting is every property is a duplicate of the original computeManagement object, with every property off that a duplicate and so on.
What on earth is going on here? Could anyone enlighten me as to what im doing wrong? The documentation is pitiful on the Compute Management module and even when copied directly doesn't work. I've Googled to my wits end so posting here is a last resort. Everything on Google is regarding running Node on Azure however I want to manage Azure Virtual Machines through Node.JS.
Thanks all
I've decided on a workaround, it would be preferred to use the above module but the time isn't available to spend making it work. Instead I've installed the azure cross platform command line tools Then spawn up a child process to run the commands needed. It's far from ideal but as all I need to do is spin up and down VM's so it performs the job.
EDIT:
I've since managed to get the azure-sdk-for-node Module working.
This also has issues where I appear to be looking at outdated documentation so methods used in examples don't exist. But I delved into the source itself to figure out the various methods. I had an issue with the the authorisation however. It all derives from the publish settings file which can be downloaded through using the command line tools. I've just used the storage management service which requires the account name and key which can be found from the command line tools. As well as the service management service for the vm's. This requires a key and cert file which uses the publish settings file. Using open ssl to convert to different formats to end up with the required pem file. This puts the cert and key into one file, you can split them and specify them separately or specify the single combined file to both properties. Hope this info might be useful.