Skip to content

kennymuli/createVMs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

createVMs

INTRODUCTION

This is the start of a project/hobby because I just want a simple script that will be able to provison machines on some of the large IaaS providers like Amazon, Rackspace, Microsoft, Digital Ocean... Current version only supports Digital Ocean, but later other providers will be added in. Feel free to contribute.

=================================================

AMAZON AWS INSTRUCTIONS (Use amazon.py)

=================================================

SETTING UP/GETTING STARTED

This project uses Boto, Amazon AWS's Python SDK. This version can provision any type of OS or AWS Machine Image (AMI) in any region, but you have to do the research and find the ID of that OS/AMI. Maybe I'll include it in future versions, or maybe I won't... Isn't the suspense killing you?!

There are a few things you'll need to get started. Depending on your familiarity with AWS, it may or may not be annoying. It's not hard, just time-consuming.

GENERATING YOUR AWS ACCESS KEY AND SECRET ACCESS KEY

A lot of thought went into naming those keys, definitely. Luckily, a lot more thought went into AWS's super-awesome instruction manual(s). So to generate your access key if you don't know how to already, check it out here: http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html

You will enter the two keys into their respective locations on Line 7 and Line 8.

CREATING YOUR SSH KEY ON EC2 AND DOWNLOADING IT

If you lose this key, it will be impossible to log into your AWS instances. Also, only computers/servers that have this key will be able to log into the AWS instances. If you need to generate a new SSH Key:

  1. Log into your AWS account.
  2. Click "EC2" under the "Services" tab on the left of the top header.
  3. Under "Resources" in the main screen, you will see "# Key Pairs" <-- Click it.
  4. Select the "Create Key Pair" button in the new screen. It is blue and on the top left.
  5. Give it a key pair name. It can be anything. Remember it.
  6. You will insert this name into Line 11 for aws_keypair

SELECTING YOUR REGION

Sorry, I was too lazy to make a whole choice list of regions, and I figured you would appreciate as well if you could hard-code it. That would save you a keystroke! Anyway, enter your region into Line 23. Don't worry, all the regions and their IDs are listed in the commented lines above.

FINALLY, ENTER YOUR AMI ID

This part is a bit annoying. The AMI is what you use as the Instance image. It comes in paravirtual (PV) and hardware-assisted virtual machines (HVM). Linux comes in different flavors and each flavor has multiple versions, and Windows has different OS versions as well, which come with or without versions of SQL. Each AMI also has a unique ID that is dependent on the geographical location (region) of the instance. It is up to you to find the ID and plug it into Line 26. AWS documentation provides a very comprehensive tutorial on different ways to find the AMI: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/finding-an-ami.html

SETTING UP THE HOST MACHINE

In order to use this script, you have to make sure you have Amazon AWS's Python SDK, Boto. You can install it with the command below: ```python pip install boto ``` If you do not have pip, please install it by using the command below: ```python sudo apt-get install python-pip ```






===================================================

DIGITAL OCEAN INSTRUCTIONS (Use digitalocean.py)

===================================================

SETTING UP/GETTING STARTED

This project is based on koalalorenzo's python-digitalocean. Currently, this version provisions only Ubuntu 14.04 (x64).

There are two things you need to get from your Digital Ocean account to get started:

GENERATING YOUR DIGITAL OCEAN TOKEN

You should create one by going into your control panel at cloud.digitalocean.com. Once you log in, click Apps & APIs on the left-hand menu at the bottom. Click "Generate a New Token" in the "Personal Access Tokens" section of the new screen. Record the token code, it will not show up again. Put that token into Line 6 of "digitalocean.py" (remember to keep the quotes, it is a string input).

GENERATING YOUR SSH KEY AND ADDING IT INTO YOUR DIGITAL OCEAN ACCOUNT.

Well, technically this program can run just fine without an SSH key, but it just makes your life easier. See below if you need to create an SSH Key and pair it with your Digital Ocean account.

Generate an SSH Key with the following command below if you do not already have one yet. ```python ssh-keygen -t rsa -C 'YOUR@EMAIL.COM' ``` It will ask you to save it somewhere. Just saving hitting Enter is fine, unless you have a specific directory. Same with passwords.

Afterwards, you'll want to read the file and copy all of its contents. To read the file, use the command below. Then highlight the output and copy it. ``` cat ~/.ssh/id_rsa.pub ```

Go into your Digital Ocean control panel and click on "SSH Keys" on the left side. Click "Add SSH Key" on the top right of the new screen. For a name, put in one that you can associate with the computer you generated the SSH Key with (only the computers with the same SSH key will be able to use that key to get into the server).

You will now need to get your SSH Key's ID. Unfortunately, the only way I know how to do it is by inspecting element:

  1. In the same SSH Key screen, right click your SSH Key and select "Inspect Element."
  2. A screen should emerge below, that has the "Element" tab active. Find the line that says something like: li class="ssh key"
  3. Expand it and look for this line: div class="collapse" id="edit_#" (The # is an ordered list, so if you have 3 total keys and the one you're looking for is the last key, the line would read "edit_2" because the count starts at 0).
  4. Expand that and another line will pop up the begins with 'form.' In that line, look for the line that begins with id= and should end with a string that says something along the lines of "edit_ssh_key_######" and the "######" is the SSH Key ID.


SETTING UP THE HOST MACHINE

In order to use this script, you have to make sure you have koalalorenzo's python-digitalocean package. You can get it by installing it with the command below. ```python pip install digitalocean ``` If you do not have pip, please install it by using the command below: ```python sudo apt-get install python-pip ```

SETTING UP DIGITALOCEAN.PY

There are three lines that you must edit in the code:
  1. Line 6: do_token: insert your Digital Ocean token here
  2. Line 7: key: insert your Digital Ocean SSH Key ID here
  3. Line 13: image_name: insert the name of the image you want to install for the Droplet. A list of available images are on https://assets.digitalocean.com/oslist.png and directions for how to format the name is listed on Lines 10-12.


RUNNING THE SCRIPT

Make sure you have Python installed. To run the script, you can navigate to the folder and type in the following command: ```shell python digitalocean.py ```

About

For people who don't really like clicking interfaces...

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages