From 65cab0d0e8adf4fac88ee0f3e909131273d4d45f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 28 Nov 2013 14:18:24 +0100 Subject: [PATCH] add "preos" subcommand to generate preos Signed-off-by: Nico Schottelius --- cdist/preos.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/cdist | 10 +++++++++ 2 files changed, 71 insertions(+) create mode 100644 cdist/preos.py diff --git a/cdist/preos.py b/cdist/preos.py new file mode 100644 index 00000000..29181057 --- /dev/null +++ b/cdist/preos.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# +# 2013 Nico Schottelius (nico-cdist at schottelius.org) +# +# This file is part of cdist. +# +# cdist 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. +# +# cdist 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 cdist. If not, see . +# +# + +import logging +import os +import subprocess + +# initialise cdist +import cdist.exec.local + +import cdist.config + +log = logging.getLogger(__name__) + +class PreOS(object): + + def __init__(self, target_dir, arch="amd64"): + + self.target_dir = target_dir + self.arch = arch + + self.command = "debootstrap" + self.suite = "wheezy" + self.options = [ "--include=openssh-server", + "--arch=%s" % self.arch ] + + def run(self): + cmd = [ self.command ] + cmd.extend(self.options) + cmd.append(self.suite) + cmd.append(self.target_dir) + + log.debug("Bootstrap: %s" % cmd) + + subprocess.call(cmd) + + + @classmethod + def commandline(cls, args): + print(args) + self = cls(target_dir=args.target_dir[0], + arch=args.arch) + self.run() diff --git a/scripts/cdist b/scripts/cdist index 39449666..f4d4ce93 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -26,6 +26,7 @@ def commandline(): import cdist.banner import cdist.config + import cdist.preos import cdist.shell # Construct parser others can reuse @@ -83,6 +84,15 @@ def commandline(): default=cdist.REMOTE_EXEC) parser['config'].set_defaults(func=cdist.config.Config.commandline) + # PreOS + parser['preos'] = parser['sub'].add_parser('preos', + parents=[parser['loglevel']]) + parser['preos'].add_argument('-a', '--arch', + help='Select architecture for preos', default="amd64") + parser['preos'].add_argument('target_dir', nargs=1, + help='Select target directory') + parser['preos'].set_defaults(func=cdist.preos.PreOS.commandline) + # Shell parser['shell'] = parser['sub'].add_parser('shell', parents=[parser['loglevel']])