Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #19 from ashcrow/bootstrap
Browse files Browse the repository at this point in the history
LGTM
  • Loading branch information
cooktheryan committed Feb 5, 2016
2 parents e2633aa + 6b10286 commit dcb8735
Show file tree
Hide file tree
Showing 20 changed files with 599 additions and 110 deletions.
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
gevent==1.1rc3
falcon>=0.3
requests
bcrypt
python-etcd==0.4.2
ansible>=2.0.0.1
setuptools
ansible>=2.0.0.2
jinja2
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def extract_requirements(filename):
tests_require=test_require,
package_dir={'': 'src'},
packages=find_packages('src'),
package_data={
'': ['data/templates/*'],
},
entry_points={
'console_scripts': [
'commissaire = commissaire.script:main',
Expand Down
2 changes: 2 additions & 0 deletions src/commissaire/data/templates/docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OPTIONS='--registry-mirror=http://{{ docker_registry_host }}:{{ docker_registry_port }} --selinux-enabled --log-driver=journald'
DOCKER_CERT_PATH=/etc/docker
2 changes: 2 additions & 0 deletions src/commissaire/data/templates/flanneld
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FLANNEL_ETCD="http://{{ etcd_host }}:{{ etcd_port }}"
FLANNEL_ETCD_KEY="{{ flannel_key }}"
1 change: 1 addition & 0 deletions src/commissaire/data/templates/kube_config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KUBE_MASTER="--master=http://{{ kubernetes_api_server_host }}:{{ kubernetes_api_server_port }}"
3 changes: 3 additions & 0 deletions src/commissaire/data/templates/kubelet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
KUBELET_ADDRESS="--address={{ bootstrap_ip }}"
KUBELET_HOSTNAME="--hostname_override={{ bootstrap_ip }}"
KUBELET_API_SERVER="--api_servers=http://{{ kubernetes_api_server_host }}:{{ kubernetes_api_server_port }}"
84 changes: 71 additions & 13 deletions src/commissaire/jobs/investigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,31 @@
import datetime
import json
import logging
import os
import sys
import tempfile

from commissaire.transport import ansibleapi
from commissaire.compat.b64 import base64
from commissaire.oscmd import get_oscmd
from commissaire.transport import ansibleapi


def clean_up_key(key_file):
"""
Remove the key file.
:param key_file: Full path to the key_file
:type key_file: str
"""
logger = logging.getLogger('investigator')
try:
os.unlink(key_file)
logger.debug('Removed temporary key file {0}'.format(key_file))
except:
exc_type, exc_msg, tb = sys.exc_info()
logger.warn(
'Unable to remove the temporary key file: '
'{0}. Exception:{1}'.format(key_file, exc_msg))


def investigator(queue, store, run_once=False):
Expand All @@ -34,15 +55,18 @@ def investigator(queue, store, run_once=False):
:param store: Data store to place results.
:type store: etcd.Client
"""
# TODO: Add coverage and testing.
# TODO: Change this to be watch and etcd "queue" and kick off a function
# similar to clusterpoolexec
logger = logging.getLogger('investigator')
logger.info('Investigator started')

transport = ansibleapi.Transport()
while True:
# Statuses follow:
# http://commissaire.readthedocs.org/en/latest/enums.html#host-statuses
to_investigate, ssh_priv_key = queue.get()
address = to_investigate['address']
logger.info('Investigating {0}...'.format(address))
logger.info('{0} is now in investigating.'.format(address))
logger.debug('Investigation details: key={0}, data={1}'.format(
to_investigate, ssh_priv_key))

Expand All @@ -67,20 +91,54 @@ def investigator(queue, store, run_once=False):
except:
logger.warn('Getting info failed for {0}'.format(address))
data['status'] = 'failed'
finally:
try:
f.unlink(key_file)
logger.debug('Removed temporary key file {0}'.format(key_file))
except:
logger.warn(
'Unable to remove the temporary key file: {0}'.format(
key_file))
store.set(key, json.dumps(data))
exc_type, exc_msg, tb = sys.exc_info()
logger.debug('{0} Exception: {1}'.format(address, exc_msg))
clean_up_key(key_file)
if run_once:
break
continue

store.set(key, json.dumps(data))
logging.debug('Finished investigation update for {0}: {1}'.format(
address, data))
logger.info(
'Finished and stored investigation data for {0}'.format(address))
logger.debug('Finished investigation update for {0}: {1}'.format(
address, data))
# --
logger.info('{0} is now in bootstrapping'.format(address))
oscmd = get_oscmd(data['os'])()
try:
result, facts = transport.bootstrap(
address, key_file, (store.host, store.port), oscmd)
data['status'] = 'inactive'
store.set(key, json.dumps(data))
except:
logger.warn('Unable to bootstrap {0}'.format(address))
exc_type, exc_msg, tb = sys.exc_info()
logger.debug('{0} Exception: {1}'.format(address, exc_msg))
data['status'] = 'disassociated'
store.set(key, json.dumps(data))
clean_up_key(key_file)
if run_once:
break
continue
# # Associate with the container manager
# try:
# result, facts = transport.associate(address, key_file, oscmd)
# data['status'] = 'active'
# except:
# logger.warn('Unable to bootstrap {0}'.format(address))
# exc = sys.exc_info()[0]
# logger.debug('{0} Exception: {1}'.format(address, exc))
# data['status'] = 'inactive'
# store.set(key, json.dumps(data))
# logger.info(
# 'Finished bootstrapping for {0}'.format(address))
# logging.debug('Finished bootstrapping for {0}: {1}'.format(
# address, data))
# # ---

clean_up_key(key_file)
if run_once:
logger.info('Exiting due to run_once request.')
break
Expand Down
74 changes: 74 additions & 0 deletions src/commissaire/oscmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class OSCmdBase:

#: The type of Operating System
os_type = None
#: Full path to docker configuration file
docker_config = '/etc/sysconfig/docker'
#: Full path to the flanneld configuration file
flanneld_config = '/etc/sysconfig/flanneld'
#: Full path to kubernetes configuration file
kubernetes_config = '/etc/kubernetes/config'
#: Full path to kubelet configuration file
kubelet_config = '/etc/kubernetes/kubelet'

def restart(self):
"""
Expand All @@ -45,6 +53,72 @@ def upgrade(self):
raise NotImplementedError('{0}.upgrade() must be overriden.'.format(
self.__class__.__name__))

def install_docker(self):
"""
Install Docker command. Must be overriden.
:return: The command to execute as a list
:rtype: list
"""
raise NotImplementedError(
'{0}.install_docker() must be overriden.'.format(
self.__class__.__name__))

def start_docker(self):
"""
Start Docker command. Must be overriden.
:return: The command to execute as a list
:rtype: list
"""
raise NotImplementedError(
'{0}.start_docker() must be overriden.'.format(
self.__class__.__name__))

def install_flannel(self):
"""
Install Flannel command. Must be overriden.
:return: The command to execute as a list
:rtype: list
"""
raise NotImplementedError(
'{0}.install_flannel() must be overriden.'.format(
self.__class__.__name__))

def start_flannel(self):
"""
Start Flannel command. Must be overriden.
:return: The command to execute as a list
:rtype: list
"""
raise NotImplementedError(
'{0}.start_flannel() must be overriden.'.format(
self.__class__.__name__))

def install_kube(self):
"""
Install Kube command. Must be overriden.
:return: The command to execute as a list
:rtype: list
"""
raise NotImplementedError(
'{0}.install_kube() must be overriden.'.format(
self.__class__.__name__))

def start_kube(self):
"""
Start Kube command. Must be overriden.
:return: The command to execute as a list
:rtype: list
"""
raise NotImplementedError(
'{0}.start_kube() must be overriden.'.format(
self.__class__.__name__))


def get_oscmd(os_type):
"""
Expand Down
54 changes: 54 additions & 0 deletions src/commissaire/oscmd/atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,57 @@ def upgrade(self):
:rtype: list
"""
return ['rpm-ostree', 'upgrade']

def install_docker(self):
"""
Atomic install docker command.
:return: The command to execute as a list
:rtype: list
"""
return ['true']

def start_docker(self):
"""
Atomic start docker command..
:return: The command to execute as a list
:rtype: list
"""
return ['systemctl', 'start', 'docker']

def install_flannel(self):
"""
Atomic install flannel command.
:return: The command to execute as a list
:rtype: list
"""
return ['true']

def start_flannel(self):
"""
Atomic start flannel command..
:return: The command to execute as a list
:rtype: list
"""
return ['systemctl', 'start', 'flanneld']

def install_kube(self):
"""
Atomic install Kube command.
:return: The command to execute as a list
:rtype: list
"""
return ['true']

def start_kube(self):
"""
Atomic start kube command.
:return: The command to execute as a list
:rtype: list
"""
return ['systemctl', 'start', 'kubelet']
54 changes: 54 additions & 0 deletions src/commissaire/oscmd/fedora.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,57 @@ def upgrade(self):
:rtype: list
"""
return ['dnf', 'update', '-y']

def install_docker(self):
"""
Fedora install docker command.
:return: The command to execute as a list
:rtype: list
"""
return ['dnf', 'install', '-y', 'docker']

def start_docker(self):
"""
Fedora start docker command..
:return: The command to execute as a list
:rtype: list
"""
return ['systemctl', 'start', 'docker']

def install_flannel(self):
"""
Fedora install flannel command.
:return: The command to execute as a list
:rtype: list
"""
return ['dnf', 'install', '-y', 'flannel']

def start_flannel(self):
"""
Fedora start flannel command..
:return: The command to execute as a list
:rtype: list
"""
return ['systemctl', 'start', 'flanneld']

def install_kube(self):
"""
Fedora install Kube command.
:return: The command to execute as a list
:rtype: list
"""
return ['dnf', 'install', '-y', 'kubernetes-node']

def start_kube(self):
"""
Fedora start kube command.
:return: The command to execute as a list
:rtype: list
"""
return ['systemctl', 'start', 'kubelet']
28 changes: 28 additions & 0 deletions src/commissaire/oscmd/redhat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2016 Red Hat, Inc
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://
"""
'Red Hat' commands.
"""

from commissaire.oscmd.rhel import OSCmd as OSCmdBase


class OSCmd(OSCmdBase):
"""
Commmands for RHEL.
"""

#: The type of Operating System
os_type = 'redhat'

0 comments on commit dcb8735

Please sign in to comment.