Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
add digital ocean provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Fisher committed Oct 29, 2013
1 parent c9127c1 commit 1ca8d84
Show file tree
Hide file tree
Showing 10 changed files with 429 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -6,3 +6,4 @@ gem 'berkshelf'

gem 'knife-ec2'
gem 'knife-rackspace'
gem 'knife-digital_ocean'
64 changes: 64 additions & 0 deletions Gemfile.lock
Expand Up @@ -8,6 +8,9 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
addressable (2.3.5)
akami (1.2.0)
gyoku (>= 0.4.0)
nokogiri (>= 1.4.0)
atomic (1.1.14)
berkshelf (1.2.1)
activesupport
Expand Down Expand Up @@ -47,10 +50,24 @@ GEM
activesupport (>= 3.2.0)
hashie (>= 2.0.2)
multi_json (>= 1.3.0)
digital_ocean (1.2.0)
faraday (~> 0.8.7)
faraday_middleware (~> 0.9.0)
json
rash
em-winrm (0.5.4)
eventmachine (= 1.0.0.beta.3)
mixlib-log (>= 1.3.0)
uuidtools (~> 2.1.1)
winrm (~> 1.1.0)
erubis (2.7.0)
eventmachine (1.0.0.beta.3)
excon (0.25.3)
faraday (0.8.8)
multipart-post (~> 1.2.0)
faraday_middleware (0.9.0)
faraday (>= 0.7.4, < 0.9)
ffi (1.9.1)
fog (1.15.0)
builder
excon (~> 0.25.0)
Expand All @@ -63,14 +80,35 @@ GEM
ruby-hmac
foodcritic (0.2.0)
formatador (0.2.4)
gssapi (1.0.3)
ffi (>= 1.0.1)
gyoku (1.1.0)
builder (>= 2.1.2)
hashie (2.0.5)
highline (1.6.19)
httpclient (2.3.4.1)
httpi (0.9.7)
rack
i18n (0.6.5)
ipaddress (0.8.0)
json (1.7.7)
knife-digital_ocean (0.2.0)
chef (>= 10.18)
digital_ocean (~> 1.2.0)
highline
knife-ec2 (0.6.4)
chef (>= 0.10.10)
fog (~> 1.6)
knife-rackspace (0.8.1)
chef (>= 0.10.10)
fog (~> 1.12)
knife-windows
knife-windows (0.5.12)
em-winrm (= 0.5.4)
little-plugger (1.1.3)
logging (1.8.1)
little-plugger (>= 1.1.3)
multi_json (>= 1.3.6)
mime-types (1.25)
mini_portile (0.5.1)
minitar (0.5.4)
Expand All @@ -95,6 +133,7 @@ GEM
net-ssh-gateway (>= 0.99.0)
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
nori (1.1.5)
ohai (6.18.0)
ipaddress
mixlib-cli
Expand All @@ -103,6 +142,9 @@ GEM
mixlib-shellout
systemu
yajl-ruby
rack (1.5.2)
rash (0.4.0)
hashie (~> 2.0.0)
rest-client (1.6.7)
mime-types (>= 1.16)
retryable (1.3.3)
Expand All @@ -124,13 +166,33 @@ GEM
retryable
solve (>= 0.4.1)
ruby-hmac (0.4.0)
rubyntlm (0.1.1)
savon (0.9.5)
akami (~> 1.0)
builder (>= 2.1.2)
gyoku (>= 0.4.0)
httpi (~> 0.9)
nokogiri (>= 1.4.0)
nori (~> 1.0)
wasabi (~> 1.0)
solve (0.8.1)
systemu (2.5.2)
thor (0.16.0)
thread_safe (0.1.3)
atomic
timers (1.1.0)
tzinfo (0.3.37)
uuidtools (2.1.4)
wasabi (1.0.0)
nokogiri (>= 1.4.0)
winrm (1.1.3)
gssapi (~> 1.0.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (~> 1.6, >= 1.6.1)
nokogiri (~> 1.5)
rubyntlm (~> 0.1.1)
savon (= 0.9.5)
uuidtools (~> 2.1.2)
yajl-ruby (1.1.0)

PLATFORMS
Expand All @@ -140,4 +202,6 @@ DEPENDENCIES
berkshelf
chef
foodcritic
knife-digital_ocean
knife-ec2
knife-rackspace
1 change: 1 addition & 0 deletions api/models.py
Expand Up @@ -109,6 +109,7 @@ class Provider(UuidAuditedModel):
('mock', 'Mock Reference Provider'),
('rackspace', 'Rackspace Open Cloud'),
('static', 'Static Node'),
('digitalocean', 'Digital Ocean'),
)

owner = models.ForeignKey(settings.AUTH_USER_MODEL)
Expand Down
32 changes: 30 additions & 2 deletions client/deis.py
Expand Up @@ -1657,6 +1657,14 @@ def providers_create(self, args):
'api_key': os.environ['RACKSPACE_API_KEY'],
'identity_type': os.environ.get('CLOUD_ID_TYPE', 'rackspace'),
}
elif type == 'digitalocean':
# read creds from envvars
for k in ('DIGITALOCEAN_CLIENT_ID', 'DIGITALOCEAN_API_KEY'):
if not k in os.environ:
msg = "Missing environment variable: {}".format(k)
raise EnvironmentError(msg)
creds = {'client_id': os.environ['DIGITALOCEAN_CLIENT_ID'],
'api_key': os.environ['DIGITALOCEAN_API_KEY']}
else:
creds = json.loads(args.get('<creds>'))
id = args.get('<id>') # @ReservedAssignment
Expand Down Expand Up @@ -1701,7 +1709,7 @@ def providers_discover(self, args):
else:
raise ResponseError(response)
else:
print('No credentials discovered, did you install the EC2 Command Line tools?')
print('No EC2 credentials discovered. Did you install the EC2 Command Line tools?')
if 'RACKSPACE_API_KEY' in os.environ and 'RACKSPACE_USERNAME' in os.environ:
print("Found Rackspace credentials: {}".format(os.environ['RACKSPACE_API_KEY']))
inp = raw_input('Import these credentials? (y/n) : ')
Expand All @@ -1721,7 +1729,27 @@ def providers_discover(self, args):
else:
raise ResponseError(response)
else:
print('No Rackspace credentials discovered')
print('No Rackspace credentials discovered.')
if 'DIGITALOCEAN_API_KEY' in os.environ and 'DIGITALOCEAN_CLIENT_ID' in os.environ:
print("Found Digitalocean credentials: {}".format(os.environ['DIGITALOCEAN_CLIENT_ID']))
inp = raw_input('Import these credentials? (y/n) : ')
if inp.lower().strip('\n') != 'y':
print('Aborting.')
else:
creds = {'client_id': os.environ['DIGITALOCEAN_CLIENT_ID'],
'api_key': os.environ['DIGITALOCEAN_API_KEY'],
}
body = {'creds': json.dumps(creds)}
sys.stdout.write('Uploading Digitalocean credentials... ')
sys.stdout.flush()
response = self._dispatch('patch', 'api/providers/digitalocean',
json.dumps(body))
if response.status_code == requests.codes.ok: # @UndefinedVariable
print('done')
else:
raise ResponseError(response)
else:
print('No Digitalocean credentials discovered.')

def providers_info(self, args):
"""
Expand Down
34 changes: 34 additions & 0 deletions contrib/digitalocean/README.md
@@ -0,0 +1,34 @@
How to Provision a Deis Controller on Digital Ocean
===================================================

Here are the steps to get started on Digital Ocean:

* install [knife-digital_ocean][kdo]

```
bundle install
```

* install python requirements

```
pip install -r requirements.txt
```

* add the following to ~/.chef/knife.rb

```
knife[:digital_ocean_client_id] = "your digital ocean client ID"
knife[:digital_ocean_api_key] = "your digital ocean API key"
```

* Follow the steps provided in contrib/digitalocean/prepare-digitalocean-snapshot.sh
* Run this command to start the provisioning process

```
./contrib/digitalocean/provision-digitalocean-controller.sh
```

This script will read from your knife config file, create a new SSH key for the controller, upload the SSH key to digital ocean, and provision a Deis Controller from the snapshot created.

[kdo]: https://github.com/rmoriz/knife-digital_ocean
71 changes: 71 additions & 0 deletions contrib/digitalocean/prepare-digitalocean-snapshot.sh
@@ -0,0 +1,71 @@
#!/bin/bash -ex

#
# Prepare a Deis-optimized snapshot from a vanilla Ubuntu 12.04.3 droplet.
#
# Instructions:
#
# 1. Launch a vanilla Ubuntu 12.04.3 droplet (64-bit)
# 2. Run this script (as root!) to install the packages necessary for faster boot times
# 3. Create a new snapshot of this droplet with the name 'deis-base'
# 4. Create/update your Deis flavors to use your new snapshot
#

THIS_DIR=$(cd $(dirname $0); pwd) # absolute path
CONTRIB_DIR=$(dirname $THIS_DIR)

# upgrade to latest packages
apt-get update
apt-get upgrade -yq

# install HTTPS transport support
apt-get install -qy apt-transport-https

# install docker's dependencies
apt-get install python-software-properties -y

# Add the Docker repository key to your local keychain
# using apt-key finger you can check the fingerprint matches 36A1 D786 9245 C895 0F96 6E92 D857 6A8B A88D 21E9
curl https://get.docker.io/gpg | apt-key add -

# Add the Docker repository to your apt sources list.
echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list

# upgrade to latest packages
apt-get update
apt-get -qy upgrade

# install required packages
apt-get install lxc-docker curl git make python-setuptools python-pip -yq

# create buildstep docker image
git clone -b deis https://github.com/opdemand/buildstep.git
cd buildstep
git checkout deis
make
cd ..
rm -rf buildstep

# install chef 11.x deps
apt-get install -yq ruby1.9.1 ruby1.9.1-dev make
update-alternatives --set ruby /usr/bin/ruby1.9.1
update-alternatives --set gem /usr/bin/gem1.9.1

# clean and remove old packages
apt-get clean
apt-get autoremove -yq

# reset cloud-init
rm -rf /var/lib/cloud

# purge SSH authorized keys
rm -f /root/.ssh/authorized_keys

# ssh host keys are automatically regenerated
# on system boot by ubuntu cloud init

# purge /var/log
find /var/log -type f | xargs rm

# flush writes to block storage
sync

0 comments on commit 1ca8d84

Please sign in to comment.