Commit aa358bc8 authored by Łukasz Nowak's avatar Łukasz Nowak

Import toolbox codebase.

parent 8f3f960c
1.0-dev (unreleased)
--------------------
include CHANGES.txt
recursive-include src/slapos/tool/builder/templates *.in
include src/slapos/tool/builder/scripts/slapos
include src/slapos/tool/builder/scripts/slapos_firstboot
slapbuilder
===========
slapbuilder is a program to install a slapos image.
Mirror of files from http://susestudio.com/appliance/
#!/bin/bash
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
#
# This script is executed at the end of appliance creation. Here you can do
# one-time actions to modify your appliance before it is ever used, like
# removing files and directories to make it smaller, creating symlinks,
# generating indexes, etc.
#
# The 'kiwi_type' variable will contain the format of the appliance (oem =
# disk image, vmx = VMware, iso = CD/DVD, xen = Xen).
#
# read in some variables
. /studio/profile
# Removing eth0 config file which became unecessary with the bridge creation
rm -f /etc/sysconfig/network/ifcfg-eth0
#!/bin/bash
### BEGIN INIT INFO
# Provides: suse_studio_custom
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:
# Description: Script run whenever the appliance boots
### END INIT INFO
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
#
# This script is executed whenever your appliance boots. Here you can add
# commands to be executed before the system enters the first runlevel. This
# could include loading kernel modules, starting daemons that aren't managed
# by init files, asking questions at the console, etc.
#
# The 'kiwi_type' variable will contain the format of the appliance (oem =
# disk image, vmx = VMware, iso = CD/DVD, xen = Xen).
#
#
# read in some variables
. /studio/profile
if [ -f /etc/init.d/suse_studio_firstboot ]
then
/etc/init.d/slapos_firstboot
elif [ -f /token_second_boot ]; then
/etc/init.d/slapos_secondboot
fi
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
import os
name = 'slapos.tool.builder'
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
long_description=(
read('README.txt')
+ '\n' +
read('CHANGES.txt')
)
setup(
name = name,
version = '1.0-dev-2',
description = "slapos - partitioning tools for servers",
long_description=long_description,
license = "GPLv3",
keywords = "slapos server builder",
include_package_data = True,
packages = find_packages('src'),
package_dir = {'':'src'},
namespace_packages = ['slapos'],
# slapgos use this to create a clean ouput
install_requires = [
'setuptools', # namespace
],
entry_points = """
[console_scripts]
slapbuilder = %s:main
""" % name,
)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
This diff is collapsed.
#!/bin/sh
### BEGIN INIT INFO
# Provides: slapos
# Required-Start: $network $remote_fs
# Required-Stop: $network $remote_fs
# Default-Start: 3 5
# Default-Stop:
# Description: Run SlapOS
### END INIT INFO
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
case "$1" in
start)
# clean the system
for service in rpcbind network-remotefs postfix ; do
chkconfig --del $service
/etc/init.d/$service stop
done
# set random root password
pwgen -sync 512 1 | passwd --stdin root
SLAP_INSTALL_LOG=/opt/slapos/slapos-install.log
if [ ! -f /opt/slapos/bin/slapformat ] ; then
while [ ! -f /opt/slapos/bin/slapformat ] ; do
echo -n "Installing SlapOS, log availble at ${SLAP_INSTALL_LOG}..."
# software not detected, force forever installation
mkdir -p /opt/slapos
(python -S -c \
'import urllib2;print urllib2.urlopen("http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py").read()' \
| python -S - -c /etc/slapos/software.cfg buildout:directory=/opt/slapos \
>> ${SLAP_INSTALL_LOG} 2>&1 && /opt/slapos/bin/buildout -c \
/etc/slapos/software.cfg buildout:directory=/opt/slapos >> \
${SLAP_INSTALL_LOG} 2>&1 ) && (echo "done.") || (echo \
"failed, retrying, the last error was:." ; tail -n 20 ${SLAP_INSTALL_LOG} ; rm -f /opt/slapos/bin/slapformat)
done
fi
# software detected, ready to run
# Set up cron
echo """# BEWARE: This file will be automatically regenerated on each boot
SHELL=/bin/sh
PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin
MAILTO=root
0 0 * * * root /opt/slapos/bin/slapformat --verbose --log_file=/opt/slapos/slapformat.log /etc/slapos/slapos.cfg >> /opt/slapos/slapformat.log 2>&1
*/5 * * * * root /opt/slapos/bin/slapgrid-cp --verbose --logfile=/opt/slapos/slapgrid-cp.log --pidfile=/opt/slapos/slapgrid-cp.pid /etc/slapos/slapos.cfg >> /opt/slapos/slapgrid-cp.log 2>&1
*/5 * * * * root /opt/slapos/bin/slapgrid-sr --verbose --logfile=/opt/slapos/slapgrid-sr.log --pidfile=/opt/slapos/slapgrid-sr.pid /etc/slapos/slapos.cfg >> /opt/slapos/slapgrid-sr.log 2>&1
0 0 * * * root /opt/slapos/bin/slapgrid-ur --verbose --logfile=/opt/slapos/slapgrid-ur.log --pidfile=/opt/slapos/slapgrid-ur.pid /etc/slapos/slapos.cfg >> /opt/slapos/slapgrid-ur.log 2>&1
""" > /etc/cron.d/slapos
# Execute slapformat
echo -n "Running slapformat..."
/opt/slapos/bin/slapformat --verbose --console /etc/slapos/slapos.cfg
echo "done."
# Set kvm up
modprobe kvm_intel
chmod 666 /dev/kvm
# Enable noop scheduler for disk which have SLAPOS labeled partition
disk=`blkid -L SLAPOS | sed -r -e 's/(\/dev\/|[0-9]*$)//g'`
echo noop > /sys/block/$disk/queue/scheduler
;;
esac
#
# hosts This file describes a number of hostname-to-address
# mappings for the TCP/IP subsystem. It is mostly
# used at boot time, when no name servers are running.
# On small systems, this file can be used instead of a
# "named" name server.
# Syntax:
#
# IP-Address Full-Qualified-Hostname Short-Hostname
#
127.0.0.1 %(computer_id)s localhost
# special IPv6 addresses
::1 %(computer_id)s localhost ipv6-localhost ipv6-loopback
fe00::0 ipv6-localnet
ff00::0 ipv6-mcastprefix
ff02::1 ipv6-allnodes
ff02::2 ipv6-allrouters
ff02::3 ipv6-allhosts
BOOTPROTO='dhcp'
BRIDGE='yes'
BRIDGE_FORWARDDELAY='0'
BRIDGE_PORTS='eth0'
BRIDGE_STP='off'
BROADCAST=''
ETHTOOL_OPTIONS=''
IPADDR=''
MTU=''
NAME=''
NETMASK=''
NETWORK=''
REMOTE_IPADDR=''
STARTMODE='auto'
USERCONTROL='no'
[slapos]
software_root = /opt/slapgrid
instance_root = /srv/slapgrid
master_url = %(master_url)s
computer_id = %(computer_id)s
key_file = %(key_file)s
cert_file = %(cert_file)s
certificate_repository_path = %(certificate_repository_path)s
[slapformat]
computer_xml = /opt/slapos/slapos.xml
partition_amount = 200
bridge_name = br0
partition_base_name = slappart
user_base_name = slapuser
tap_base_name = slaptap
ipv4_local_network = 10.0.0.0/16
PermitRootLogin yes
AllowUsers root
AddressFamily inet6
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys
# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no
PasswordAuthentication no
X11Forwarding yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL
Subsystem sftp /usr/lib64/ssh/sftp-server
UsePAM yes
0.0.2 (unreleased)
------------------
0.0.1 (2010-10-22)
------------------
- working version
[Lukasz Nowak]
[egg_info]
tag_build = .dev
tag_svn_revision = 1
from setuptools import setup, find_packages
import os
name = "slapos.tool.cloudmgr"
version = '0.0.2'
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
long_description=(
read('README.txt')
+ '\n' +
read('CHANGES.txt')
)
setup(
name = name,
version = version,
author = 'Lukasz Nowak',
author_email = 'luke@nexedi.com',
description = "cloudmgr -- tools to manage clouds by using libcloud",
long_description=long_description,
license = "GPL",
keywords = "cloud libcloud manager",
classifiers=[
],
packages = find_packages('src'),
include_package_data = True,
package_dir = {'':'src'},
namespace_packages = [ 'slapos', 'slapos.tool' ],
install_requires = [
'setuptools', # namespaces
'paramiko',
'apache_libcloud>=0.4.0', #False name, 0.4.0 is not yet released on pypi
# and erpypi does not support names with "-"
],
url='https://svn.erp5.org/repos/vifib/trunk/utils/slapos.tool.cloudmgr/',
zip_safe=True,
entry_points = """
[console_scripts]
cloudmgr=slapos.tool.cloudmgr.cloudmgr:main
cloudlist=slapos.tool.cloudmgr.list:main
clouddestroy=slapos.tool.cloudmgr.destroy:main
cloudstart=slapos.tool.cloudmgr.start:main
cloudstop=slapos.tool.cloudmgr.stop:main
cloudgetprivatekey=slapos.tool.cloudmgr.getprivatekey:main
cloudgetpubliciplist=slapos.tool.cloudmgr.getpubliciplist:main
""" % dict(name=name),
)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
from update import update
from destroy import destroy
from start import start
from stop import stop
from list import uuidlist
from getpubliciplist import getpubliciplist
class NodeInterface:
def __init__(self, key, secret, service, location, node_uuid=None,
ssh_key=None):
self.key = key
self.location = location
self.node_uuid = node_uuid
self.ssh_key = ssh_key
self.secret = secret
self.service = service
def update(self, image, size, security_group):
result = update(self.key, self.secret, self.service, self.location,
self.node_uuid, self.ssh_key, image, size, security_group)
self.node_uuid = result['node_uuid']
self.ssh_key = result['ssh_key']
return result
def stop(self):
stop(self.key, self.secret, self.service, self.node_uuid, self.ssh_key)
def start(self):
start(self.key, self.secret, self.service, self.node_uuid)
def destroy(self):
destroy(self.key, self.secret, self.service, self.node_uuid)
def getPublicIpList(self):
return getpubliciplist(self.key, self.secret, self.service, self.node_uuid)
def getNodeUuidList(self):
return uuidlist(self.key, self.secret, self.service)
import sys
import time
from cloudinterface import NodeInterface
class CloudManager:
def __init__(self, configuration_file):
self.configuration_file = configuration_file
self.initialiseConfiguration()
def initialiseConfiguration(self):
self.configuration_dict = {}
try:
external_eval = file(self.configuration_file).read()
except IOError:
pass
else:
try:
self.configuration_dict = eval(external_eval)
except:
pass
if type(self.configuration_dict) != type({}):
self.configuration_dict = {}
for k in 'key', 'secret':
if k not in self.configuration_dict:
self.configuration_dict[k] = ''
elif type(self.configuration_dict[k]) != type(''):
self.configuration_dict[k] = ''
if 'node_list' not in self.configuration_dict:
self.configuration_dict['node_list'] = []
if type(self.configuration_dict['node_list']) != type([]):
self.configuration_dict['node_list'] = []
def run(self):
print 'Run begin...'
started = stopped = destroyed = unsupported = 0
self.key = self.configuration_dict['key']
self.secret = self.configuration_dict['secret']
for node in self.configuration_dict['node_list']:
node_object = NodeInterface(self.key, self.secret, node['service'],
node['location'], node['node_uuid'], node['ssh_key'])
if node['requested_state'] == 'started':
print 'Starting %r' % node['node_uuid']
if node_object.start():
started += 1
else:
unsupported += 1
elif node['requested_state'] == 'stopped':
print 'Stopping %r' % node['node_uuid']
if node_object.stop():
stopped += 1
else:
unsupported += 1
elif node['requested_state'] == 'destroyed':
print 'Destroying %r' % node['node_uuid']
if node_object.destroy():
destroyed +=1
else:
unsupported += 1
else:
print 'Unsupported state %r for node %r' % (node['requested_state'],
node['node_uuid'])
unsupported += 1
print 'Run finished', dict(started=started, stopped=stopped,
destroyed=destroyed, unsupported=unsupported)
def main():
while True:
CloudManager(sys.argv[1]).run()
time.sleep(5)
from slapos.tool.cloudmgr.lib import getDriverInstance, getNode
from libcloud.types import NodeState
import sys
def destroy(key, secret, service, node_uuid):
driver = getDriverInstance(service, key, secret)
node = getNode(driver, node_uuid)
if node is None:
return False
if node.state in [NodeState.RUNNING, NodeState.REBOOTING, NodeState.PENDING]:
return node.destroy()
else:
return False
def main():
print destroy(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
import sys
def getprivatekey(key, secret, service, node_uuid):
"""Fetches private key of node"""
raise NotImplementedError('Cedric implement')
return dict(
ssh_key = ssh_key,
)
def main():
getprivatekey(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
from slapos.tool.cloudmgr.lib import getDriverInstance, getNode
from libcloud.types import NodeState
import time
import sys
def getpubliciplist(key, secret, service, node_uuid):
"""Gets public ip(s), can wait for the first IP to appear"""
public_ip_list = []
for i in range(100):
driver = getDriverInstance(service, key, secret)
node = getNode(driver, node_uuid)
if node.state not in [NodeState.RUNNING, NodeState.REBOOTING,
NodeState.PENDING]:
break
if node.public_ip[0]:
public_ip_list = node.public_ip
break
else:
time.sleep(5)
return dict(
public_ip_list = public_ip_list
)
def main():
print getpubliciplist(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
from libcloud.types import Provider
from libcloud.providers import get_driver
import paramiko
import StringIO
driver_list = {
'DUMMY': get_driver(Provider.DUMMY),
'EC2_US_EAST': get_driver(Provider.EC2_US_EAST),
'EC2_US_WEST': get_driver(Provider.EC2_US_WEST),
'EC2_EU_WEST': get_driver(Provider.EC2_EU_WEST),
'RACKSPACE': get_driver(Provider.RACKSPACE),
'SLICEHOST': get_driver(Provider.SLICEHOST),
'GOGRID': get_driver(Provider.GOGRID),
'VPSNET': get_driver(Provider.VPSNET),
'LINODE': get_driver(Provider.LINODE),
'VCLOUD': get_driver(Provider.VCLOUD),
'RIMUHOSTING': get_driver(Provider.RIMUHOSTING),
'ECP': get_driver(Provider.ECP),
'IBM': get_driver(Provider.IBM),
'OPENNEBULA': get_driver(Provider.OPENNEBULA),
'DREAMHOST': get_driver(Provider.DREAMHOST),
}
def getDriverInstance(driverName, key, secret=None, secure=True, host=None,
port=None):
return driver_list.get(driverName)(key, secret, secure, host, port)
def getSSHConnection(driver, hostname, private_key):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
#TODO if exception : try DSSKey
pkey = paramiko.RSAKey.from_private_key(StringIO.StringIO(private_key))
client.connect(hostname=hostname, username='root', pkey=pkey,
look_for_keys=False)
return client
def getNode(driver, node_uuid):
node_list = [node for node in driver.list_nodes() if node_uuid in node.uuid]
if len(node_list) == 0:
return None
if len(node_list) != 1:
raise IndexError('Several nodes with the uuid %r exist.' % node_uuid)
return node_list[0]
# Original work by Cedric de Saint Martin, adapted by Lukasz Nowak
import sys
from slapos.tool.cloudmgr.lib import getDriverInstance
def nodelist(key, secret, service):
driver = getDriverInstance(service, key, secret)
node_list = driver.list_nodes()
return node_list
def uuidlist(key, secret, service):
return [q.uuid for q in nodelist(key, secret, service)]
def main():