Aug 21, 2014

Developing with the New Codero API



Over the past few months, we’ve been working hard to release the Codero API. Now that it’s available to the public, developers and DevOps teams can now easily automate their Codero infrastructure with a few API calls. You can scale on the fly when needed, not when it’s too late. You can quickly and easily build your apps with API integration and automation tools. And best of all? It’s RESTful, simple, and incredibly easy to use. Here are some other benefits of the Codero Cloud API:

  • Infrastructure monitoring with tools like NewRelic. When load is getting too high or has died down, use automation tools to call the Codero API to scale up or down the infrastructure.
  • Automation through tools like Chef and Saltstack. No longer do you have to login to a portal to create an instance, wait for the password, then login. The API helps you take control and streamline your processes.
  • Ease of use. We made it easy to integrate with our API. Standard RESTful implementation, not something that calls itself RESTful and turns out to be something totally different. Relative URLs allow for you to quickly control the next steps available for a given action.


Using the Codero API – Demo

To demonstrate how easy it is to use our API, I decided to create a project called the “1 Hour Cloud“. The concept is simple: Create a VM with any name you would like, deploy your application or test out some code, then in one hour the VM will destroy itself. (Or you can destroy it if you don’t want to wait the full hour.)



Below is the simple python model (or library, as some may call it) that interacts with the Codero API. It just requires you to import a few libraries: requests ( and json. I used Flask ( as my framework since I wanted something quick and easy to get off the ground. And within an hour, my app was running and deploying VMs. Once included, just add your key and it’s off to the races.
import requests, json
from app import app

class codero_api():
def __init__(self):
self.api_key = app.config['CODERO_API_KEY']
self.url = app.config['CODERO_API_URL']

def api_request(self, command, request_type = 'GET', data=''):
if request_type == 'POST':

return"%s%s" % (self.url, command),data=json.dumps(data),headers={'Authorization':'%s' % self.api_key, 'Content-Type':'application/json'})
elif request_type == 'DELETE':
return requests.delete("%s%s/%s" % (self.url, command, data), headers={'Authorization': '%s' % self.api_key})
return requests.get("%s%s" % (self.url, command), headers={'Authorization': '%s' % self.api_key})

def list_running(self):
return self.api_request('servers').json()

def create_vm(self, hostname, email):
data = {
'name': hostname,
'codelet': app.config['CODERO_API_CODELET'],
'billing': app.config['CODERO_API_BILLING_TYPE']
self.api_request('servers', 'POST', data)

def delete_vm(self, vm_id):
self.api_request('servers', 'DELETE', vm_id)



Getting started with the Codero API

Using our new API, spinning up and spinning down servers has never been easier. Now that you’ve seen our API in action, give it a try and let us know what you think. For more information on the Codero API, refer to our API documentation here.



Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedIn