Commits

stacklet committed b6fcdb0

Added debootstrap task as an alternate to old-style bootstrap; remove ssh keys in cleanup task

Comments (0)

Files changed (1)

src/stacklet/task/distro/debu.py

 
 import ConfigParser
 import string
-import re
+import fnmatch, re
+
+class _XO_debootstrap(_XO_, StackTask):
+    """Debootstrap a debian or ubuntu image.  Image will be chrootable upon completion
+       of this task with network access to a package repository.
+
+
+    Task Arguments:
+    arch -- the architecture eg 'amd64'.
+    codename -- what to install, eg 'quantal''
+    proxy -- (optional) proxyhost[:port]
+
+    """
+    _TASK_NAME = 'debootstrap'
+
+    def __init__(self):
+        pass
+
+    def process(self, buildContext):
+        try:
+            try:
+                self._buildContext = buildContext
+                self.log_info(buildContext, 'entering')
+                self.precheck(buildContext)
+
+
+                env = {'http_proxy': self._proxy, 'PATH': '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'}
+
+                cmd = 'debootstrap --arch=%s --verbose --keep-debootstrap-dir %s %s' % (self._arch, self._codename, buildContext.mountPoint)
+                self.exec_command(buildContext, cmd, env=env)
+
+
+            except TaskError, taskErr:
+
+                taskErr.criticality = TaskError.ABORT_BUILD
+                raise
+        finally:
+            self.log_info(buildContext, 'leaving')
+
+    def precheck(self, buildContext):
+        self.is_valid_build_context(buildContext)
+
+        self._arch = self.get_value('arch')
+        self._codename = self.get_value('codename')
+        self._proxy = self.get_value('proxy')
+
+        if self.is_empty(self._arch):
+            raise FieldError(self._TASK_NAME, TaskError.ABORT_TASK, 'arch is required')
+
+        if self.is_empty(self._codename):
+            raise FieldError(self._TASK_NAME, TaskError.ABORT_TASK, 'codename is required')
+
 
 class _XO_bootstrap(_XO_, StackTask):
     """Bootstrap a debian or ubuntu image.  Image will be chrootable upon completion
             raise BuildError(self._TASK_NAME, TaskError.ABORT_TASK, 'Could not find ' + self._bootstrapConfig)
 
     def extract(self, debs, env):
+        debs = fnmatch.filter(os.listdir(self._buildContext.mountPoint + '/bootstrap/'), "*.deb")
         for deb in debs:
             cmd = 'ar -p ' + self._buildContext.mountPoint + '/bootstrap/' + deb + ' data.tar.gz | zcat | tar -C ' + self._buildContext.mountPoint +  ' -xf - '
             self.exec_command(self._buildContext, cmd, env=env)
                 cmds.append('rm -f /root/.nano_history')
                 cmds.append('rm -f /etc/resolv.conf')
                 cmds.append('rm -rf /bootstrap')
+                cmds.append('rm -rf /debootstrap')
+                cmds.append('rm -f /etc/ssh/*key*')
                 cmds.append('rm -rf /tmp/*')
 
                 self.exec_command_chroot(buildContext, cmds, checkReturnValue=False)
 
 stacklet.util.objectify._XO_bootstrap = _XO_bootstrap
 stacklet.util.objectify._XO_stk_bootstrap = _XO_bootstrap
+stacklet.util.objectify._XO_stk_debootstrap = _XO_debootstrap
 stacklet.util.objectify._XO_package = _XO_package
 stacklet.util.objectify._XO_stk_package = _XO_package
 stacklet.util.objectify._XO_service = _XO_service
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.