0.0.32 • Published 8 years ago

azure-api v0.0.32

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

azure-api

A really simple promise-based NodeJS API for creation and configuration of Azure resources.

You must have azure-cli installed and authenticated to use this.

This API is used in my MEAN stack provisioning script. It's a good example of how to use this.

Todo (please join the effort!):

  • Support for certificates/keys.
  • Functions to delete networks and VMs.

To install:

npm install --save azure-api

Then in your NodeJS script:

var config = {
	verbose: true
};
var azure = require('azure-api')(config);

To create a network:

var networkName = "somenetwork";
var location = "Australia East";

azure.createNetwork(networkName, location)
	.then(function () {
		// network was created sucessfully.
	})
	.catch(function (err) {
		// some error occurred.
	}); 

To create a VM:

var vm = {
	name: "somevm",
	networkName: "somenetwork",
	imageName: "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu_DAILY_BUILD-trusty-14_04_2-LTS-amd64-server-20150708-en-us-30GB",
	user: "username", // User name for the VM.
	pass: "password", // Password for the VM.
	endpoints: ... list of end points ...
};

azure.createVM(vm)
	.then(function () {
		// VM was created sucessfully.
	})
	.catch(function (err) {
		// some error occurred.
	}); 

End points are specified as follows:

var endpoints = [
	{
		name: 'HTTP',
		externalPort: 80,
		internalPort: 3000,						
	},
	// etc, etc
],

To run a provisioning shell script on the remote machine:

var host = "somevm.cloudapp.net";
var user = "username";
var pass = "password";
var scriptFile = "provision.sh"; // The named script must exist on the local machine.

azure.runSshScript(host, user, pass, scriptFile)
	.then(function () {
		// the script completed successfully.
	})
	.catch(function (err) {
		// some error occurred.
	});

You can also call a function that waits for you VM to have started:

var vmName = "somevm";

azure.waitVmRunning(vmName)
	.then(function () {
		// vm has started.
	})
	.catch(function (err) {
		// some error occurred.
	});

The end result is you can wire all these functions together to provision your cloud:

var networkName = "somenetwork";
var location = "Australia East";
var host = vmName + ".cloudapp.net";

var vm = {
	name: "somevm",
	networkName: networkName,
	imageName: "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu_DAILY_BUILD-trusty-14_04_2-LTS-amd64-server-20150708-en-us-30GB",
	user: "username", // User name for the VM.
	pass: "password", // Password for the VM.
	endpoints: ... list of end points ...
};

var provisionScriptFile = "provision.sh";

azure.createNetwork(networkName, location)
	.then(function () {
		return azure.createVM(vm);
	})
	.then(function () {
		return azure.waitVmRunning(vm.name);
	})
	.then(function () {
		return azure.runSshScript(host, vm.user, vm.pass, provisionScriptFile)
	})
	.then(function () {
		// provisioning completed successfully.
	})
	.catch(function (err) {
		// some error occurred.
	}); 

Or you could just call provisionVM:

var networkName = "somenetwork";
var location = "Australia East";

var vm = {
	name: "somevm",
	networkName: networkName,
	imageName: "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu_DAILY_BUILD-trusty-14_04_2-LTS-amd64-server-20150708-en-us-30GB",
	user: "username", // User name for the VM.
	pass: "password", // Password for the VM.
	endpoints: ... list of end points ...
	provisionScript: "provision.sh",
};

var provisionScriptFile = "provision.sh";

azure.createNetwork(networkName, location)
	.then(function () {
		return azure.provisionVM(vm);
	})
	.then(function () {
		// provisioning completed successfully.
	})
	.catch(function (err) {
		// some error occurred.
	}); 

Have fun! Thanks for coming to the party.

0.0.32

8 years ago

0.0.31

10 years ago

0.0.30

10 years ago

0.0.29

10 years ago

0.0.28

10 years ago

0.0.27

10 years ago

0.0.26

10 years ago

0.0.25

10 years ago

0.0.24

10 years ago

0.0.23

10 years ago

0.0.22

10 years ago

0.0.21

10 years ago

0.0.20

10 years ago

0.0.18

10 years ago

0.0.17

10 years ago

0.0.16

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago