Skip to content

Latest commit

 

History

History
144 lines (104 loc) · 5.49 KB

getting-started.mkdn

File metadata and controls

144 lines (104 loc) · 5.49 KB

MCloud Getting Started Guide

To get started with MCloud you can download the compiled binary and all its dependencies here: http://github.com/jacksonh/MCloud/downloads once you have MCloud downloaded you can reference MCloud.dll in your .net project.

A sample application is available in the samples directory.

Creating accounts

MCloud is a managed interface to various cloud providers. To do anything useful with MCloud you will need to have accounts with at least one of these cloud providers.

Currently the two supported cloud providers are Linode and EC2:

EC2

EC2 users should # at http://aws.amazon.com. Once you are signed up you can get your access key and your secret access key by clicking Account and then SecurityCredentials. In this guide we will refer to the Access Key ID as your user ID and the Secret Access Key as your user key.

Linode

Linode users should # at http://linode.com. Once you are signed up you can get your key by clicking the My Profile link and scrolling down to the API key. The API key is a unique ID that acts as a username AND password. Since the API key refers to both your username and password, it as used as a NodeAuth.Username in MCloud.

Logging in to your cloud provider

MCloud uses an abstract Driver type for interacting with your cloud provider. To create a Driver you just instantiate one of the Driver types:

NodeDriver driver = new MCloud.Linode.LinodeDriver (api_key); OR: NodeDriver driver = new MCloud.EC2.EC2Driver (access_id, secret_access_id);

Listing your cloud providers available packages

Once you have created an instance of a Driver you can query your cloud provider to see what sort of node you can create. Here are the things you can query for with MCloud:

Returns a list of images such as "Open Suse 11.2" or "Red Hat".

 driver.ListImages ();
 { NodeImage id="54" name="Slackware 12.2" driver="Linode", NodeImage id="41" name="Ubuntu 8.04 LTS" driver="Linode" }

Returns a list of the geographical data center locations.

driver.ListLocations ();
{ NodeLocation id="2" name="Dallas, TX, USA" driver="Linode" Country="US", NodeLocation id="3" name="Fremont, CA, USA" driver="Linode" Country="US", }

Returns a list of the available sizes (packages of ram, gb, transfer for set prices).

driver.ListSizes ()
{ NodeSize id="1" name="Linode 512" driver="Linode" ram="512" disk="16384" bandwidth="200" price="1995", NodeSize id="2" name="Linode 768" driver="Linode" ram="768" disk="24576" bandwidth="300" price="2995"}

Interacting with Nodes

You can get a list of your nodes with the Driver.ListNodes method. Once you have an instance of your nodes, you can check the state of the node, check its IP addresses, reboot and terminate your nodes.

List<Node> nodes = driver.ListNodes ();
// print the state of all of the nodes
nodes.ForEach (n => Console.WriteLine ("node state:  {0}", n.State));

// reboot all the nodes
nodes.ForEach (n => n.Reboot ());

// destroy all the nodes
nodes.ForEach (n => n.Destroy ());

Properties of the node can change between the time you got a reference to the node and now. To get the update properties of the node use the Update () method.

   node.Reboot ();
   while (node.State == NodeState.ShuttingDown) {
   	   node.Update ();
   }

Creating new Nodes

Once you have found an image, size and location that meet your needs you can create a new node with the CreateNode method. This is a synchronous method that will create a new node on the cloud provider and return once the node has been created. Nodes will not be immediately available after being created as they still have to wait for their boot proccess to finish.

NodeAuth auth = new NodeAuth (NodeAuthType.Password, "root", "mypassword");
Node node = driver.CreateNode ("My Node", size, image, location, auth);

The NodeAuth object passed to CreateNode is used to create a login to the machine once it is booted. So if you use a NodeAuthType.Password the root user password will be set to that value. If you use a NodeAuthType.SSHKey the supplied keypath will be used for login. If your image is preconfigured with a authorization method, you can use the NodeAuthType.None.

Deploying your node

Once a node is create you can use Deployment objects from the MCloud.Deploy namespace to setup your node. The best way to do this is to create a MultistepDeployment and adding each of your steps to it in the collection initializer.

   MultiStepDeployment md = new MultiStepDeployment () {
       new RunScript ("setup_db.sh"),
       new RunScript ("setup_webserver.sh"),
       new PutDirectory ("/src/thesite", "/srv/www/thesite"),
       new RunCommand ("service apache2 restart")
   }
   nodes.ForEach (n => n.Deploy (md, auth));

The following deployment steps are available:

  • CreateUser: Create a new user on the node
  • MultiStepDeployment: Used to run a series of deployments.
  • PushPgsqlDB: Push the specified postgresql database and all of its data to the server.
  • PutFile: Put a single file on the node.
  • PutFiles: Put a list of files on the node.
  • PutDirectory: Recursively copy a directory to the node.
  • PutSSHKeys: Copy a users ssh key to the node.
  • RunScript: Copy a local script to the node and run it.
  • RunCommand: Run a single unix command on the node.