def bootstrap(platform, root, img_format='dir', fs_format='ext2', fs_opts=None, arch=None, flavor=None, repo_url=None, static_qemu=None, img_size=None, mount_dir=None, pkg_cache=None, pkgs=None, exclude_pkgs=None, epel_url=EPEL_URL):
 if (img_format not in ('dir', 'sparse')):
  raise SaltInvocationError('The img_format must be "sparse" or "dir"')
 if (img_format == 'dir'):
  if (not __salt__['file.directory_exists'](root)):
   try:
    __salt__['file.mkdir'](root)
   except Exception as exc:
    return {'Error': pprint.pformat(exc)}
 elif (img_format == 'sparse'):
  if (not img_size):
   raise SaltInvocationError('An img_size must be specified for a sparse file')
  if (not mount_dir):
   mount_dir = '/opt/salt-genesis.{0}'.format(uuid.uuid4())
  __salt__['file.mkdir'](mount_dir, 'root', 'root', '755')
  __salt__['cmd.run'](('fallocate', '-l', img_size, root), python_shell=False)
  _mkpart(root, fs_format, fs_opts, mount_dir)
  loop1 = __salt__['cmd.run']('losetup -f')
  log.debug('First loop device is {0}'.format(loop1))
  __salt__['cmd.run']('losetup {0} {1}'.format(loop1, root))
  loop2 = __salt__['cmd.run']('losetup -f')
  log.debug('Second loop device is {0}'.format(loop2))
  start = str((2048 * 2048))
  __salt__['cmd.run']('losetup -o {0} {1} {2}'.format(start, loop2, loop1))
  __salt__['mount.mount'](mount_dir, loop2)
  _populate_cache(platform, pkg_cache, mount_dir)
 if mount_dir:
  root = mount_dir
 if (pkgs is None):
  pkgs = []
 if (exclude_pkgs is None):
  exclude_pkgs = []
 if (platform in ('rpm', 'yum')):
  _bootstrap_yum(root, pkgs=pkgs, exclude_pkgs=exclude_pkgs, epel_url=epel_url)
 elif (platform == 'deb'):
  _bootstrap_deb(root, arch=arch, flavor=flavor, repo_url=repo_url, static_qemu=static_qemu, pkgs=pkgs, exclude_pkgs=exclude_pkgs)
 elif (platform == 'pacman'):
  _bootstrap_pacman(root, img_format=img_format, pkgs=pkgs, exclude_pkgs=exclude_pkgs)
 if (img_format != 'dir'):
  blkinfo = __salt__['disk.blkid'](loop2)
  __salt__['file.replace']('{0}/boot/grub/grub.cfg'.format(mount_dir), 'ad4103fa-d940-47ca-8506-301d8071d467', blkinfo[loop2]['UUID'])
  __salt__['mount.umount'](root)
  __salt__['cmd.run']('losetup -d {0}'.format(loop2))
  __salt__['cmd.run']('losetup -d {0}'.format(loop1))
  __salt__['file.rmdir'](mount_dir)

def bootstrap ( platform , root , img_format = 'dir' , fs_format = 'ext2' , fs_opts = None , arch = None , flavor = None , repo_url = None , static_qemu = None , img_size = None , mount_dir = None , pkg_cache = None , pkgs = None , exclude_pkgs = None , epel_url = EPEL_URL ) : if ( img_format not in ( 'dir' , 'sparse' ) ) : raise SaltInvocationError ( 'The img_format must be "sparse" or "dir"' ) if ( img_format == 'dir' ) : if ( not __salt__ [ 'file.directory_exists' ] ( root ) ) : try : __salt__ [ 'file.mkdir' ] ( root ) except Exception as exc : return { 'Error' : pprint . pformat ( exc ) } elif ( img_format == 'sparse' ) : if ( not img_size ) : raise SaltInvocationError ( 'An img_size must be specified for a sparse file' ) if ( not mount_dir ) : mount_dir = '/opt/salt-genesis.{0}' . format ( uuid . uuid4 ( ) ) __salt__ [ 'file.mkdir' ] ( mount_dir , 'root' , 'root' , '755' ) __salt__ [ 'cmd.run' ] ( ( 'fallocate' , '-l' , img_size , root ) , python_shell = False ) _mkpart ( root , fs_format , fs_opts , mount_dir ) loop1 = __salt__ [ 'cmd.run' ] ( 'losetup -f' ) log . debug ( 'First loop device is {0}' . format ( loop1 ) ) __salt__ [ 'cmd.run' ] ( 'losetup {0} {1}' . format ( loop1 , root ) ) loop2 = __salt__ [ 'cmd.run' ] ( 'losetup -f' ) log . debug ( 'Second loop device is {0}' . format ( loop2 ) ) start = str ( ( 2048 * 2048 ) ) __salt__ [ 'cmd.run' ] ( 'losetup -o {0} {1} {2}' . format ( start , loop2 , loop1 ) ) __salt__ [ 'mount.mount' ] ( mount_dir , loop2 ) _populate_cache ( platform , pkg_cache , mount_dir ) if mount_dir : root = mount_dir if ( pkgs is None ) : pkgs = [ ] if ( exclude_pkgs is None ) : exclude_pkgs = [ ] if ( platform in ( 'rpm' , 'yum' ) ) : _bootstrap_yum ( root , pkgs = pkgs , exclude_pkgs = exclude_pkgs , epel_url = epel_url ) elif ( platform == 'deb' ) : _bootstrap_deb ( root , arch = arch , flavor = flavor , repo_url = repo_url , static_qemu = static_qemu , pkgs = pkgs , exclude_pkgs = exclude_pkgs ) elif ( platform == 'pacman' ) : _bootstrap_pacman ( root , img_format = img_format , pkgs = pkgs , exclude_pkgs = exclude_pkgs ) if ( img_format != 'dir' ) : blkinfo = __salt__ [ 'disk.blkid' ] ( loop2 ) __salt__ [ 'file.replace' ] ( '{0}/boot/grub/grub.cfg' . format ( mount_dir ) , 'ad4103fa-d940-47ca-8506-301d8071d467' , blkinfo [ loop2 ] [ 'UUID' ] ) __salt__ [ 'mount.umount' ] ( root ) __salt__ [ 'cmd.run' ] ( 'losetup -d {0}' . format ( loop2 ) ) __salt__ [ 'cmd.run' ] ( 'losetup -d {0}' . format ( loop1 ) ) __salt__ [ 'file.rmdir' ] ( mount_dir )
bootstrap a new project at a given path .