[Erp5-report] r45224 luke - in /slapos/trunk/util/slapos.tool.builder: ./ appliance/ src/ s...

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Apr 8 11:29:03 CEST 2011


Author: luke
Date: Fri Apr  8 11:29:02 2011
New Revision: 45224

URL: http://svn.erp5.org?rev=45224&view=rev
Log:
 - SlapOS node builder

Added:
    slapos/trunk/util/slapos.tool.builder/
    slapos/trunk/util/slapos.tool.builder/CHANGES.txt
    slapos/trunk/util/slapos.tool.builder/MANIFEST.in
    slapos/trunk/util/slapos.tool.builder/README.txt
    slapos/trunk/util/slapos.tool.builder/appliance/
    slapos/trunk/util/slapos.tool.builder/appliance/README.txt
    slapos/trunk/util/slapos.tool.builder/appliance/builds_end_script.sh
    slapos/trunk/util/slapos.tool.builder/appliance/each_boot_script.sh
    slapos/trunk/util/slapos.tool.builder/setup.cfg
    slapos/trunk/util/slapos.tool.builder/setup.py
    slapos/trunk/util/slapos.tool.builder/src/
    slapos/trunk/util/slapos.tool.builder/src/slapos/
    slapos/trunk/util/slapos.tool.builder/src/slapos/__init__.py
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/__init__.py
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/__init__.py
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos   (with props)
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos_firstboot   (with props)
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/hosts.in
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/ifcfg-br0.in
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/slapos.cfg.in
    slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/sshd_config.in

Added: slapos/trunk/util/slapos.tool.builder/CHANGES.txt
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/CHANGES.txt?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/CHANGES.txt (added)
+++ slapos/trunk/util/slapos.tool.builder/CHANGES.txt [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,2 @@
+1.0 (unreleased)
+----------------

Added: slapos/trunk/util/slapos.tool.builder/MANIFEST.in
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/MANIFEST.in?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/MANIFEST.in (added)
+++ slapos/trunk/util/slapos.tool.builder/MANIFEST.in [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,4 @@
+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

Added: slapos/trunk/util/slapos.tool.builder/README.txt
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/README.txt?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/README.txt (added)
+++ slapos/trunk/util/slapos.tool.builder/README.txt [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,4 @@
+slapbuilder
+===========
+
+slapbuilder is a program to install a slapos image.

Added: slapos/trunk/util/slapos.tool.builder/appliance/README.txt
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/appliance/README.txt?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/appliance/README.txt (added)
+++ slapos/trunk/util/slapos.tool.builder/appliance/README.txt [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1 @@
+Mirror of files from http://susestudio.com/appliance/

Added: slapos/trunk/util/slapos.tool.builder/appliance/builds_end_script.sh
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/appliance/builds_end_script.sh?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/appliance/builds_end_script.sh (added)
+++ slapos/trunk/util/slapos.tool.builder/appliance/builds_end_script.sh [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,43 @@
+#!/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

Added: slapos/trunk/util/slapos.tool.builder/appliance/each_boot_script.sh
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/appliance/each_boot_script.sh?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/appliance/each_boot_script.sh (added)
+++ slapos/trunk/util/slapos.tool.builder/appliance/each_boot_script.sh [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,54 @@
+#!/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

Added: slapos/trunk/util/slapos.tool.builder/setup.cfg
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/setup.cfg?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/setup.cfg (added)
+++ slapos/trunk/util/slapos.tool.builder/setup.cfg [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,3 @@
+[egg_info]
+tag_build = .dev
+tag_svn_revision = 1

Added: slapos/trunk/util/slapos.tool.builder/setup.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/setup.py?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/setup.py (added)
+++ slapos/trunk/util/slapos.tool.builder/setup.py [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,35 @@
+# -*- 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',
+    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,
+    )

Added: slapos/trunk/util/slapos.tool.builder/src/slapos/__init__.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/src/slapos/__init__.py?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/src/slapos/__init__.py (added)
+++ slapos/trunk/util/slapos.tool.builder/src/slapos/__init__.py [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,7 @@
+# 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__)
+

Added: slapos/trunk/util/slapos.tool.builder/src/slapos/tool/__init__.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/src/slapos/tool/__init__.py?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/src/slapos/tool/__init__.py (added)
+++ slapos/trunk/util/slapos.tool.builder/src/slapos/tool/__init__.py [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,7 @@
+# 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__)
+

Added: slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/__init__.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/__init__.py?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/__init__.py (added)
+++ slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/__init__.py [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,332 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# 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 adviced 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.
+#
+##############################################################################
+import os
+import sys
+from optparse import OptionParser, Option
+from subprocess import call as subprocessCall
+from stat import S_ISBLK, ST_MODE
+from tempfile import mkdtemp
+import shutil
+import pkg_resources
+
+class SlapError(Exception):
+  """
+  Slap error
+  """
+  def __init__(self, message):
+    self.msg = message
+
+class UsageError(SlapError):
+  pass
+
+class ExecError(SlapError):
+  pass
+
+def rootRightsNeeded(func):
+  "Decorator for permissions checking"
+  def wrapped(*args, **kwargs):
+    if os.getuid() != 0:
+      raise UsageError("You need to be root to run this script !")
+    return func(*args, **kwargs)
+  return wrapped
+
+def _call(cmd_args, stdout=None, stderr=None, dry_run=False):
+  """
+  Wrapper for subprocess.call() which'll secure the usage of external program's.
+
+  Args:
+    cmd_args: list of strings representing the command and all it's needed args
+    stdout/stderr: only precise PIPE (from subprocess) if you don't want the
+        command to create output on the regular stream
+  """
+  print "Calling: %s" % ' '.join(cmd_args)
+  if not dry_run:
+    try:
+      if subprocessCall(cmd_args, stdout=stdout, stderr=stderr) != 0:
+        raise ValueError('Issues during running %r' % cmd_args)
+    except OSError as e:
+      raise ExecError('Process respond:"%s" when calling "%s"' % \
+                      (str(e), ' '.join(cmd_args)))
+
+class Parser(OptionParser):
+  """
+  Parse all arguments.
+  """
+  def __init__(self, usage=None, version=None):
+    """
+    Initialize all options possibles.
+    """
+    OptionParser.__init__(self, usage=usage, version=version,
+                          option_list=[
+      Option("-c", "--slapos_configuration",
+             help="The path of the slapos configuration directory",
+             default='/etc/slapos/',
+             type=str),
+      Option("-o", "--hostname_path",
+             help="The hostname configuration path",
+             default='/etc/HOSTNAME',
+             type=str),
+      Option("-s", "--host_path",
+             help="The hosts configuration path",
+             default='/etc/hosts',
+             type=str),
+      Option("-n", "--dry_run",
+             help="Simulate the execution steps",
+             default=False,
+             action="store_true"),
+      Option(None, "--no_usb", default=False, action="store_true",
+        help="Do not write on USB.")
+    ])
+
+  def check_args(self):
+    """
+    Check arguments
+    """
+    (options, args) = self.parse_args()
+    if len(args) != 8:
+      self.error("Incorrect number of arguments")
+    system_path, device_path, computer_id, key_path, master_url, \
+        slapos_software_profile, cert_file, key_file = args
+
+    system_path = os.path.abspath(system_path)
+    if not os.path.isfile(system_path):
+      self.error("%s isn't valid. The first argument must be the raw " \
+                 "slapos file" % system_path)
+
+    device_path = os.path.abspath(device_path)
+    if not options.no_usb:
+      mode = os.stat(device_path)[ST_MODE]
+      if not S_ISBLK(mode):
+        self.error("%s isn't a valid block file. Please enter as second " \
+                 "argument a valid block file for the raw to be copied on " \
+                 "it" % device_path)
+
+    for path in key_path, slapos_software_profile:
+      path = os.path.abspath(path)
+      if not os.path.isfile(path):
+        self.error("%r file not found" % path)
+
+    return options, system_path, device_path, computer_id, key_path,\
+        master_url, slapos_software_profile, cert_file, key_file
+
+ at rootRightsNeeded
+def run(config):
+  dry_run = config.dry_run
+  print "Creating temp directory"
+  if not dry_run:
+    mount_dir_path = mkdtemp()
+  else:
+    mount_dir_path = "/tmp/a_generated_directory"
+  try:
+    _call(['mount', '-o', 'loop,offset=32256', config.system_path,
+           mount_dir_path], dry_run=dry_run)
+    try:
+      # Create slapos configuration directory if needed
+      slap_configuration_directory = os.path.normpath('/'.join([mount_dir_path,
+                                              config.slapos_configuration]))
+      slap_configuration_file = os.path.normpath('/'.join([
+        slap_configuration_directory, 'slapos.cfg']))
+      if not os.path.exists(slap_configuration_directory):
+        print "Creating directory: %s" % slap_configuration_directory
+        if not dry_run:
+          os.mkdir(slap_configuration_directory, 0711)
+
+      slap_key_repository = os.path.normpath('/'.join([mount_dir_path,
+                                              config.slapos_configuration,
+                                              'pki']))
+      if not os.path.exists(slap_key_repository):
+        print "Creating directory: %s" % slap_key_repository
+        if not dry_run:
+          os.mkdir(slap_key_repository, 0711)
+      certificate_repository_path = os.path.join(config.slapos_configuration,
+          'pki')
+      key_file = os.path.join(certificate_repository_path, 'computer.key')
+      cert_file = os.path.join(certificate_repository_path, 'computer.crt')
+      key_file_dest = os.path.normpath('/'.join([mount_dir_path,
+                                              key_file]))
+      cert_file_dest = os.path.normpath('/'.join([mount_dir_path,
+                                              cert_file]))
+      for (src, dst) in [(config.key_file, key_file_dest), (config.cert_file,
+        cert_file_dest)]:
+        print "Coping %r to %r, and setting minimum privileges" % (src, dst)
+        if not dry_run:
+          shutil.copy(src, dst)
+          os.chmod(dst, 0600)
+          os.chown(dst, 0, 0)
+
+      # Put slapgrid configuration file
+      print "Creating slap configuration: %s" % slap_configuration_file
+      if not dry_run:
+        open(slap_configuration_file, 'w').write(
+          pkg_resources.resource_stream(__name__,
+            'templates/slapos.cfg.in').read() % dict(
+              computer_id=config.computer_id, master_url=config.master_url,
+              key_file=key_file, cert_file=cert_file,
+              certificate_repository_path=certificate_repository_path
+            ))
+
+      hostname_path = os.path.normpath('/'.join([mount_dir_path,
+                                              config.hostname_path]))
+      print "Setting hostname in : %s" % hostname_path
+      if not dry_run:
+        open(hostname_path, 'w').write("%s\n" % config.computer_id)
+
+      # Adding the hostname as a valid address 
+      host_path = os.path.normpath('/'.join([mount_dir_path,
+                                             config.host_path]))
+      print "Creating %r" % host_path
+      if not dry_run:
+        open(host_path, 'w').write(
+          pkg_resources.resource_stream(__name__,
+            'templates/hosts.in').read() % dict(
+              computer_id=config.computer_id))
+
+      # Creating safe sshd_config
+      sshd_path = os.path.normpath('/'.join([mount_dir_path, 'etc', 'ssh',
+        'sshd_config']))
+      print "Creating %r" % sshd_path
+      if not dry_run:
+        open(sshd_path, 'w').write(
+          pkg_resources.resource_stream(__name__,
+            'templates/sshd_config.in').read())
+        os.chmod(sshd_path, 0600)
+
+      # Creating default bridge config
+      br0_path = os.path.normpath('/'.join([mount_dir_path, 'etc',
+        'sysconfig', 'network', 'ifcfg-br0']))
+      print "Creating %r" % br0_path
+      if not dry_run:
+        open(br0_path, 'w').write(
+          pkg_resources.resource_stream(__name__,
+            'templates/ifcfg-br0.in').read())
+
+      # Writing ssh key
+
+      user_path = os.path.normpath('/'.join([mount_dir_path, 'root']))
+      ssh_key_directory = os.path.normpath('/'.join([user_path, '.ssh']))
+      ssh_key_path = os.path.normpath('/'.join([ssh_key_directory,
+        'authorized_keys']))
+      stat_info = os.stat(user_path)
+      uid, gid = stat_info.st_uid, stat_info.st_gid
+      ssh_key_directory = os.path.dirname(ssh_key_path)
+      if not os.path.exists(ssh_key_directory):
+        print "Creating ssh directory: %s" % ssh_key_directory
+        if not dry_run:
+          os.mkdir(ssh_key_directory)
+      if not dry_run:
+        print "Setting uid:gid of %r to %s:%s" % (ssh_key_directory, uid, gid)
+        os.chown(ssh_key_directory, uid, gid)
+        os.chmod(ssh_key_directory, 0700)
+
+      print "Creating file: %s" % ssh_key_path
+      if not dry_run:
+        shutil.copyfile(config.key_path, ssh_key_path)
+
+      if not dry_run:
+        print "Setting uid:gid of %r to %s:%s" % (ssh_key_path, uid, gid)
+        os.chown(ssh_key_path, uid, gid)
+        os.chmod(ssh_key_path, 0600)
+
+      # slapos buildout profile
+      slapos_software_file = os.path.normpath('/'.join([mount_dir_path,
+                                              config.slapos_configuration,
+                                              'software.cfg']))
+      print "Creating slapos software profile: %s" % slapos_software_file
+      if not dry_run:
+        shutil.copyfile(config.slapos_software_profile, slapos_software_file)
+        os.chmod(slapos_software_file, 0644)
+
+      # Creating boot scripts
+      for script in ['slapos_firstboot', 'slapos']:
+        path = os.path.join(mount_dir_path, 'etc', 'init.d', script)
+        print "Creating %r" % path
+        if not dry_run:
+          open(path, 'w').write(pkg_resources.resource_stream(__name__,
+            'scripts/%s' % script).read())
+          os.chmod(path, 0755)
+    finally:
+      _call(['umount', mount_dir_path], dry_run=dry_run)
+  finally:
+    # Always delete temporary directory
+    print "Deleting temp directory: %s" % mount_dir_path
+    if not dry_run:
+      shutil.rmtree(mount_dir_path)
+
+  # Copying
+  if not config.no_usb:
+    print "\nStarting the copy of the raw file, it may take some time...\n"
+    _call(['dd', "if=%s" % config.system_path, "of=%s" % config.device_path], dry_run=dry_run)
+    _call(['sync'])
+    print "\n... copy finished! You may now take the usb key back."
+
+  return 0
+
+class Config:
+  def setConfig(self, option_dict, system_path, device_path, computer_id,
+                key_path, master_url, slapos_software_profile, cert_file,
+                key_file):
+    """
+    Set options given by parameters.
+    """
+    # Set options parameters
+    for option, value in option_dict.__dict__.items():
+      setattr(self, option, value)
+    self.system_path = system_path
+    self.device_path = device_path
+    self.computer_id = computer_id
+    self.key_path = key_path
+    self.master_url = master_url
+    self.slapos_software_profile = slapos_software_profile
+    self.key_file = key_file
+    self.cert_file = cert_file
+
+def main():
+  "Run default configuration."
+  usage = "usage: %s [options] SYSTEM_FILE OUTPUT_DEVICE " \
+          "COMPUTER_ID SSH_KEY_FILE MASTER_URL SLAPOS_SOFTWARE_PROFILE "\
+          "COMPUTER_CERTIFICATE COMPUTER_KEY" % sys.argv[0]
+
+  try:
+    # Parse arguments
+    config = Config()
+    config.setConfig(*Parser(usage=usage).check_args())
+
+    run(config)
+    return_code = 0
+  except UsageError, err:
+    print >>sys.stderr, err.msg
+    print >>sys.stderr, "For help use --help"
+    return_code = 16
+  except ExecError, err:
+    print >>sys.stderr, err.msg
+    return_code = 16
+  except SystemExit, err:
+    # Catch exception raise by optparse
+    return_code = err
+
+  sys.exit(return_code)

Added: slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos (added)
+++ slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,92 @@
+#!/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 --log_file=/opt/slapos/slapformat.log /etc/slapos/slapos.cfg >> /opt/slapos/slapformat.log 2>&1
+*/5 * * * * root /opt/slapos/bin/slapgrid-cp --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 --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 --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 -c /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

Propchange: slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos
------------------------------------------------------------------------------
    svn:executable = *

Added: slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos_firstboot
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos_firstboot?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos_firstboot (added)
+++ slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos_firstboot [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,314 @@
+#!/usr/bin/python
+### BEGIN INIT INFO
+# Provides: slapos_firstboot
+# Required-Start:
+# Required-Stop:
+# Default-Start:
+# Default-Stop:
+# Description: Configures first boot of 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.
+#
+##############################################################################
+import os
+import shutil
+import subprocess
+import tempfile
+import time
+
+# some constants
+LABEL="SLAPOS"
+MINIMUM_FREE_SPACE_GB=60
+MINIMUM_FREE_SPACE=MINIMUM_FREE_SPACE_GB * 1024 * 1024 * 1024
+SLAPOS_MARK='# Added by SlapOS\n'
+
+def callWithCheck(args):
+  """Calls args in subprocesses, rasies ValueError if command failed"""
+  if subprocess.call(args) != 0:
+    raise ValueError
+
+def callWithIgnore(args):
+  """Calls args in subprocess, ignores issues"""
+  subprocess.call(args)
+
+def partprobe():
+  """Calls partprobe utility"""
+  callWithIgnore("partprobe")
+
+def env():
+  """Returns language neutreal environment"""
+  env = {}
+  for k, v in os.environ.iteritems():
+    if 'LANG' not in k:
+      env[k] = v
+  env['LANG'] = 'C'
+  env['LANGUAGE'] = 'C'
+  return env
+
+def getPartitionList(path):
+  """Returns list of all partitions found on disk"""
+  partprobe()
+  result = subprocess.Popen(['fdisk', '-l', path], env=env(),
+        stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
+  partition_list = []
+  for l in result.split('\n'):
+    if l.startswith(path):
+      partition_list.append(l.split()[0])
+  return partition_list
+
+def setupFilesystem(path):
+  """Setups partition on path"""
+  print "Setting up filesystem on %r" % path
+  partprobe()
+  callWithCheck(["mkfs", "-m", "1", "-L", LABEL, "-t", "ext4", path])
+  partprobe()
+
+def prepareDisk(path):
+  """Prepares disk and creates partition"""
+  callWithCheck(["parted", "--script", path, "mklabel", "msdos"])
+  callWithCheck(["parted", "--script", '--', path, "mkpart", "primary",
+    "ext2", "0", "-1"])
+  partition = path + '1'
+  setupFilesystem(partition)
+
+def findEmptyDisk():
+  """Tries to find not configured yet disk"""
+  result = subprocess.Popen(['parted', '--script', '-l'], env=env(),
+      stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
+  for line in result.split('\n'):
+    if 'unrecognised disk label' in line:
+      disk = line.split(':')[1].strip()
+      fdisk = subprocess.Popen(['fdisk', '-l', disk], env=env(),
+        stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
+      size = 0
+      for l in fdisk.split('\n'):
+        if l.startswith('Disk %s:' % disk):
+          size = int(l.split(' ')[4])
+          break
+      if size > MINIMUM_FREE_SPACE:
+        return disk
+
+def deactivateSwap():
+  """Disactivates swap in /etc/fstab and turns off any existing"""
+  old_fstab = open('/etc/fstab', 'r').readlines()
+  fstab = open('/etc/fstab', 'w')
+  for line in old_fstab:
+    if 'swap' in line:
+      line = '#deactivated by slapos#' + line
+    fstab.write(line)
+  fstab.close()
+  callWithIgnore(['swapoff', '-a'])
+
+def prepareSlapOSPartition(mount_point):
+  """Prepare SlapOS partitioning"""
+  new_fstab = open('/etc/fstab', 'r').readlines()
+  a = new_fstab.append
+  d = dict(label=LABEL)
+  a(SLAPOS_MARK)
+  a('LABEL=%(label)s /mnt/%(label)s ext4 defaults,noatime 0 0\n'%
+      d)
+  a("/mnt/%(label)s/opt /opt none bind 0 0\n" % d)
+  a("/mnt/%(label)s/tmp /tmp none bind 0 0\n" % d)
+  a("/mnt/%(label)s/srv /srv none bind 0 0\n" % d)
+  open('/etc/fstab', 'w').write(''.join(new_fstab))
+  partprobe()
+  retry = 10
+  while True:
+    try:
+      print 'Trying to mount new partition, %s to go.' % retry
+      callWithCheck(['mount', '/mnt/'+LABEL])
+    except ValueError:
+      if retry > 0:
+        retry -= 1
+        # give some time
+        time.sleep(2)
+      else:
+        raise
+    else:
+      break
+  for d in ['opt', 'srv', 'tmp']:
+    p = '/mnt/'+LABEL+'/'+d
+    if not os.path.exists(p):
+      os.mkdir(p)
+      os.chmod(p, 0755)
+  os.chmod('/mnt/'+LABEL+'/tmp', 01777)
+  callWithCheck(['mount', '/opt'])
+  callWithCheck(['mount', '/tmp'])
+  callWithCheck(['mount', '/srv'])
+
+def configureNtp():
+  """Configures NTP daemon"""
+  server = "server pool.ntp.org"
+  old_ntp = open('/etc/ntp.conf', 'r').readlines()
+  new_ntp = open('/etc/ntp.conf', 'w')
+  for line in old_ntp:
+    if line.startswith('server'):
+      continue
+    new_ntp.write(line)
+  new_ntp.write(SLAPOS_MARK)
+  new_ntp.write(server+'\n')
+  new_ntp.close()
+  callWithIgnore(['chkconfig', '--add', 'ntp'])
+
+def getMountedPartitionList():
+  partition_list = []
+  for line in open('/etc/mtab', 'r').readlines():
+    if line.startswith('/dev'):
+      partition_list.append(line.split(' ')[0])
+  return partition_list
+
+def getWidestFreeSpaceList(disk_dict):
+  free_space_disk_dict = {}
+  for disk in disk_dict.iterkeys():
+    v = disk_dict[disk]
+    for l in v:
+      size = int(l.split(':')[3].rstrip('B'))
+      free_space_disk_dict.setdefault(size, [])
+      free_space_disk_dict[size].append(dict(disk=disk, info=l))
+  if free_space_disk_dict:
+    m = max(free_space_disk_dict)
+    if m > MINIMUM_FREE_SPACE:
+      return free_space_disk_dict[max(free_space_disk_dict)]
+  return []
+
+def findAndPrepareFreeSpace():
+  """Finds free space, ignoring / mounted device
+  Prefers disk with correct empty partition table"""
+  mounted_partition_list = getMountedPartitionList()
+  disk_dict = {}
+  parted = subprocess.Popen(['parted', '--script', '-lm'], env=env(),
+      stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
+  for line in parted.split('\n'):
+    line = line.strip()
+    if line.startswith('/dev'):
+      disk = line.split(':')[0]
+      if any([q.startswith(disk) for q in mounted_partition_list]):
+        continue
+      # disk found, time to fetch free space
+      disk_dict[disk] = []
+      free = subprocess.Popen(['parted', '--script', '-m', disk, 'unit', 'B', 'print',
+        'free'], env=env(),
+        stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
+      for f in free.split('\n'):
+        if ':free;' in f:
+          disk_dict[disk].append(f.strip())
+
+  disk_space_list = getWidestFreeSpaceList(disk_dict)
+  if len(disk_space_list) == 0:
+    raise ValueError('Minumum of free space %sGB not found' % MINIMUM_FREE_SPACE_GB)
+  disk = disk_space_list[0]
+  beg = disk['info'].split(':')[1].rstrip('B')
+  end = disk['info'].split(':')[2].rstrip('B')
+  before = getPartitionList(disk['disk'])
+  callWithCheck(['parted', '--script', '-m', '-a', 'optimal', '--',
+    disk['disk'], 'unit', 'B', 'mkpart', 'primary', 'ext2', beg, end])
+  after = getPartitionList(disk['disk'])
+  new = [q for q in after if q not in before]
+  setupFilesystem(new[0])
+  return disk['disk']
+
+def configureGrub(mount_point, slapos_label_file):
+  """Configures grub on mount_point using disk"""
+  boot = os.path.join(mount_point, 'boot')
+  grub = os.path.join(boot, 'grub')
+  if not os.path.exists(boot):
+    os.mkdir(boot)
+  if os.path.exists(grub):
+    shutil.rmtree(grub)
+  shutil.copytree('/boot/grub', grub)
+  open(os.path.join(grub, 'menu.lst'), 'w').write("""timeout 3600
+title SlapOS Error: The USB key is not first and bootable device
+root (hd0,1)
+chainloader +1
+title Solution: Put the USB key
+root (hd0,1)
+chainloader +1
+title Solution: Configure BIOS -- boot from USB key
+root (hd0,1)
+chainloader +1
+title Solution: Configure BIOS -- USB key as first device
+root (hd0,1)
+chainloader +1
+""")
+
+  new_map_path = tempfile.mkstemp()[1]
+  new_map = open(new_map_path, 'w')
+  disk = os.path.realpath(os.path.join(os.path.dirname(slapos_label_file),
+      os.readlink(slapos_label_file)))
+  # this represents /dev/sdXN, so simply let's remove all possible numbers
+  # from right
+  # Note: This method's perfectioness is same as rest in this script, high
+  # dependency on system configuration
+  disk = disk.rstrip('0123456789')
+  new_map.write(open('/boot/grub/device.map').read() + '\n(hd1) %s'% disk)
+  new_map.close()
+  grub_install = subprocess.Popen(['grub', '--batch', '--device-map=%s' %
+    new_map], stdin=subprocess.PIPE)
+  grub_install.communicate("""root (hd1,0)
+setup (hd1)
+quit
+""")
+  os.unlink(new_map_path)
+  if grub_install.returncode is None or grub_install.returncode != 0:
+    raise ValueError('Issue during grub installation')
+
+def run():
+  """Prepares machine to run SlapOS"""
+  print "Running SUSE Studio first boot script..."
+  callWithIgnore("chkconfig --add slapos".split(' '))
+  partprobe()
+  slapos_label_file='/dev/disk/by-label/' + LABEL
+  if not os.path.exists(slapos_label_file):
+    empty_disk = findEmptyDisk()
+    if empty_disk is not None:
+      print "Found empty disk %r, configuring it" % empty_disk
+      prepareDisk(empty_disk)
+    else:
+      print "No empty disk found, trying to find the biggest possible free space"
+      findAndPrepareFreeSpace()
+  deactivateSwap()
+  mount_point = '/mnt/' + LABEL
+  if not os.path.exists(mount_point):
+    os.mkdir(mount_point)
+  os.chmod(mount_point, 0755)
+  print 'Reconfiguring fstab'
+  prepareSlapOSPartition(mount_point)
+  print "Configuring fallback grub information"
+  configureGrub(mount_point, slapos_label_file)
+  configureNtp()
+
+if __name__ == '__main__':
+  try:
+    run()
+  except:
+    import traceback
+    sleep = 120
+    print "There was uncaught issue with SlapOS configuration"
+    print "System will be restarted in %ss" % sleep
+    print "Below traceback might be useful:"
+    traceback.print_exc()
+    time.sleep(sleep)
+    callWithIgnore(['init', '6'])

Propchange: slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/scripts/slapos_firstboot
------------------------------------------------------------------------------
    svn:executable = *

Added: slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/hosts.in
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/hosts.in?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/hosts.in (added)
+++ slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/hosts.in [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,23 @@
+#
+# 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
+

Added: slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/ifcfg-br0.in
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/ifcfg-br0.in?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/ifcfg-br0.in (added)
+++ slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/ifcfg-br0.in [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,15 @@
+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'

Added: slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/slapos.cfg.in
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/slapos.cfg.in?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/slapos.cfg.in (added)
+++ slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/slapos.cfg.in [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,17 @@
+[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

Added: slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/sshd_config.in
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/sshd_config.in?rev=45224&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/sshd_config.in (added)
+++ slapos/trunk/util/slapos.tool.builder/src/slapos/tool/builder/templates/sshd_config.in [utf8] Fri Apr  8 11:29:02 2011
@@ -0,0 +1,22 @@
+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



More information about the Erp5-report mailing list