add "preos" subcommand to generate preos

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
Nico Schottelius 2013-11-28 14:18:24 +01:00
parent 321b39ee89
commit 65cab0d0e8
2 changed files with 71 additions and 0 deletions

61
cdist/preos.py Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
#
#
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()

View file

@ -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']])