예제 #1
0
def BuildKsConfig(release, google_cloud_repo, byol, sap_hana, sap_apps):
  """Builds kickstart config from shards.

  Args:
    release: string; image from metadata.
    google_cloud_repo: string; expects 'stable', 'unstable', or 'staging'.
    byol: bool; true if using a BYOL RHEL license.
    sap_hana: bool; true if building RHEL for SAP HANA
    sap_apps: bool; true is building RHEL for SAP Apps

  Returns:
    string; a valid kickstart config.
  """

  # This is where we put the kickstart config together. There are three sections
  # in a kickstart config. Sections are:
  # Commands and options
  # Packages
  # pre and post
  # Each section must be in a specific order, but items in that section do not
  # have to be.

  # Common
  ks_packages = FetchConfigPart('common-packages.cfg')
  # For BYOL RHEL, don't remove subscription-manager.
  if byol:
    utils.Status('Building RHEL BYOL image.')
    rhel_byol_post = FetchConfigPart('rhel-byol-post.cfg')

  if release == 'rhel6':
    utils.Status('Building RHEL 6 image.')
    ks_options = FetchConfigPart('el6-options.cfg')
    custom_post = FetchConfigPart('el6-post.cfg')
    if byol:
      custom_post = '\n'.join([custom_post, rhel_byol_post])
    cleanup = FetchConfigPart('el6-cleanup.cfg')
    repo_version = 'el6'
  elif release == "centos6":
    utils.Status('Building CentOS 6 image.')
    ks_options = FetchConfigPart('el6-options.cfg')
    custom_post = FetchConfigPart('co6-post.cfg')
    cleanup = FetchConfigPart('el6-cleanup.cfg')
    repo_version = 'el6'
  elif release == "rhel7":
    utils.Status('Building RHEL 7 image.')
    ks_options = FetchConfigPart('el7-options.cfg')
    custom_post = FetchConfigPart('el7-post.cfg')
    if byol:
      custom_post = '\n'.join([custom_post, rhel_byol_post])
    elif sap_hana:
      utils.Status('Building RHEL 7 for SAP Hana')
      custom_post = FetchConfigPart('rhel7-sap-hana-post.cfg')
    elif sap_apps:
      utils.Status('Building RHEL 7 for SAP Apps')
      custom_post = FetchConfigPart('rhel7-sap-apps-post.cfg')
    cleanup = FetchConfigPart('el7-cleanup.cfg')
    repo_version = 'el7'
  elif release == "centos7":
    utils.Status('Building CentOS 7 image.')
    ks_options = FetchConfigPart('el7-options.cfg')
    custom_post = FetchConfigPart('co7-post.cfg')
    cleanup = FetchConfigPart('el7-cleanup.cfg')
    repo_version = 'el7'
  elif release == "oraclelinux6":
    utils.Status('Building Oracle Linux 6 image.')
    ks_options = FetchConfigPart('el6-options.cfg')
    custom_post = FetchConfigPart('ol6-post.cfg')
    cleanup = FetchConfigPart('el6-cleanup.cfg')
    repo_version = 'el6'
  elif release == "oraclelinux7":
    utils.Status('Building Oracle Linux 7 image.')
    ks_options = FetchConfigPart('el7-options.cfg')
    custom_post = FetchConfigPart('ol7-post.cfg')
    cleanup = FetchConfigPart('el7-cleanup.cfg')
    repo_version = 'el7'
  else:
    utils.Fail('Unknown Image Name: %s' % release)

  ks_post = BuildPost(custom_post, cleanup, repo_version, google_cloud_repo)

  # This list should be in the order that you want each section to appear in the
  # Kickstart config.
  return '\n'.join([ks_options, ks_packages, ks_post])
예제 #2
0
  utils.Execute(cmd, cwd=BVZ_DIR)

  # Upload tar.
  image_tar_gz = '/target/disk.tar.gz'
  if os.path.exists(image_tar_gz):
    image_tar_gz_dest = os.path.join(image_dest, 'root.tar.gz')
    utils.Status('Saving %s to %s' % (image_tar_gz, image_tar_gz_dest))
    utils.Gsutil(['cp', image_tar_gz, image_tar_gz_dest])

  # Create and upload the synopsis of the image.
  utils.Status('Creating image synopsis.')
  synopsis = {}
  packages = collections.OrderedDict()
  _, output, _ = utils.Execute(['dpkg-query', '-W'], capture_output=True)
  for line in output.split('\n')[:-1]:  # Last line is an empty line.
    parts = line.split()
    packages[parts[0]] = parts[1]
  synopsis['installed_packages'] = packages
  with open('/tmp/synopsis.json', 'w') as f:
    f.write(json.dumps(synopsis))
  utils.Status('Uploading image synopsis.')
  synopsis_dest = os.path.join(outs_path, 'synopsis.json')
  utils.Gsutil(['cp', '/tmp/synopsis.json', synopsis_dest])

if __name__ == '__main__':
  try:
    main()
    utils.Success('Debian build was successful!')
  except:
    utils.Fail('Debian build failed!')
예제 #3
0
    # Mount the installer disk.
    utils.Execute(['mount', '-t', 'ext4', '/dev/sdb1', '/mnt'])

    utils.Status('Installer root: %s' % os.listdir('/mnt'))
    utils.Status('Build logs: %s' % os.listdir('/mnt/build-logs'))

    # For some reason we need to remove the gsutil credentials.
    utils.Execute(['rm', '-Rf', '/root/.gsutil'])
    utils.Execute(['gsutil', 'cp', '/mnt/ks.cfg',
                   '%s/' % logs_path],
                  raise_errors=False)
    utils.Execute(['gsutil', 'cp', '/mnt/build-logs/*',
                   '%s/' % logs_path],
                  raise_errors=False)
    utils.Execute([
        'gsutil', 'cp', '/mnt/build-logs/synopsis.json',
        '%s/synopsis.json' % outs_path
    ],
                  raise_errors=False)

    utils.Execute(['umount', '-l', '/mnt'])


if __name__ == '__main__':
    try:
        main()
        utils.Success('Build logs successfully saved.')
    except:
        utils.Fail('Failed to save build logs.')
예제 #4
0
        ])
        # Tell Anaconda not to store its logs in the installed image,
        # unless requested to keep them for debugging.
        if not savelogs:
            args += ' inst.nosave=all'
        cfg = re.sub(r'append initrd=initrd\.img.*', r'\g<0> %s' % args, cfg)

        # Change labels to explicit partitions.
        if release in ['centos7', 'rhel7', 'oraclelinux7']:
            cfg = re.sub(r'LABEL=[^ ]+', 'LABEL=INSTALLER', cfg)

        # Print out a the modifications.
        diff = difflib.Differ().compare(oldcfg.splitlines(1),
                                        cfg.splitlines(1))
        utils.Status('Modified extlinux.conf:\n%s' % '\n'.join(diff))

        f.seek(0)
        f.write(cfg)
        f.truncate()

    # Activate extlinux.
    utils.Execute(['extlinux', '--install', 'installer/extlinux'])


if __name__ == '__main__':
    try:
        main()
        utils.Success('EL Installer build successful!')
    except:
        utils.Fail('EL Installer build failed!')