Skip to content

Commit

Permalink
Merge pull request #6 from andreasjansson/boot2docker
Browse files Browse the repository at this point in the history
support for boot2docker local dev
  • Loading branch information
andreasjansson committed Dec 7, 2015
2 parents 3654ffb + 5395c59 commit 938cd60
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
71 changes: 71 additions & 0 deletions headintheclouds/boot2docker.py
@@ -0,0 +1,71 @@
import os
import sys
from fabric.api import * # pylint: disable=W0614,W0401
import fabric.api as fab

import headintheclouds
from headintheclouds import util

__all__ = []

def terminate():
raise NotImplementedError()

def pricing(sort=None):
print 'No pricing for boot2docker'

def rename():
raise NotImplementedError()

def nodes():
nodes = all_nodes()
util.print_table(nodes, ['ip'])

def create_servers(*args, **kwargs):
raise NotImplementedError()

def validate_create_options(ip):
return {'running': True}

def equivalent_create_options(options1, options2):
return options1['ip'] == options2['ip']

create_server_defaults = {
'ip': None
}

def get_boot2docker_ip():
with hide('everything'):
return local('boot2docker ip', capture=True)

def get_boot2docker_ssh_port():
return 22
# TODO:
# with hide('everything'):
# return local("boot2docker config | awk '/SSHPort/ { print $3 }'", capture=True)

def get_boot2docker_ssh_key():
with hide('everything'):
key = local("boot2docker config | awk '/SSHKey/ { print $3 }'", capture=True)
return key.replace('"', '')

def all_nodes():
name = 'boot2docker'
ip = get_boot2docker_ip()
nodes = [{
'name': name,
'ip': ip,
'internal_address': ip,
'internal_ip': ip,
'running': True,
}]
return nodes

settings = {
'user': 'docker',
'key_filename': get_boot2docker_ssh_key(),
'port': get_boot2docker_ssh_port(),
'shell': '/bin/sh -c',
}

headintheclouds.add_provider('boot2docker', sys.modules[__name__])
7 changes: 6 additions & 1 deletion headintheclouds/docker.py
Expand Up @@ -57,7 +57,7 @@ def setup(docker_mount=None, force=False):
* docker_mount=None: Partition that will be mounted as /var/lib/docker
'''

if not is_ubuntu():
if not is_ubuntu() and not is_boot2docker():
raise Exception('Head In The Clouds Docker is only supported on Ubuntu')

# a bit hacky
Expand Down Expand Up @@ -509,6 +509,11 @@ def is_ubuntu():
with settings(hide('everything'), warn_only=True):
return not fab.run('which apt-get').failed

def is_boot2docker():
with hide('everything'):
hostname = fab.run('hostname')
return hostname.startswith('boot2docker')

def install_sshpass_from_source():
run('mkdir tmpbuild')
with cd('tmpbuild'):
Expand Down
9 changes: 8 additions & 1 deletion headintheclouds/ensemble/parse.py
Expand Up @@ -54,13 +54,20 @@ def parse_server(server_name, spec, templates):
count = 1

if 'provider' not in spec:
spec['provider'] = 'unmanaged'
if server_name == 'boot2docker':
spec['provider'] = 'boot2docker'
else:
spec['provider'] = 'unmanaged'

for i in range(count):
if spec['provider'] == 'unmanaged':
name = spec['ip'] = server_name
if 'ip' in spec and spec['ip'] != name:
raise ConfigException('No need to specify ip for unmanaged servers, but if you do, the ip must match the name of the server')
elif server_name == 'boot2docker':
from headintheclouds import boot2docker
name = server_name
spec['ip'] = boot2docker.get_boot2docker_ip()
else:
if i == 0:
name = server_name
Expand Down

0 comments on commit 938cd60

Please sign in to comment.