コード例 #1
0
def main():
    logs_path = utils.GetMetadataParam('daisy-logs-path',
                                       raise_on_not_found=True)
    outs_path = utils.GetMetadataParam('daisy-outs-path',
                                       raise_on_not_found=True)

    # 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'])
コード例 #2
0
 async def on_ready(self):
     await self.bot.prepared.wait()
     if len(self.players) > 0:
         return
     # log.debug("INIT")
     self.ignored_channels = list(map(int, await self.bot.redis.smembers("channel_ignore")))
     self.ignored_guilds = list(map(int, await self.bot.redis.smembers("guild_ignore")))
     for data in await self.fetch_players():
         owner_id, name, map_id, created, explored, exp, compendium, gold, *_ = data
         # log.debug("DATA %s", data)
         user = self.bot.get_user(owner_id)
         if not user:
             log.warning("Unknown user id %s. Skipping initialization. (%s)", owner_id, len(self.bot.users))
             continue
         status = await self.bot.redis.get(f"status_{user.id}")
         if status:
             status = utils.Status(int(status))
         else:
             status = utils.Status.idle
         player = utils.Player(
             owner=user,
             bot=self.bot,
             name=name,
             created_at=created,
             explored=list(map(self.bot.map_manager.get_map, explored)),
             status=status,
             exp=exp,
             next_map=await self.bot.redis.get(f"next_map_{user.id}"),
             compendium=compendium,
             gold=gold
         )
         player.map = map_id
         self.players.append(player)
         log.info("Player \"%s\" (%s) initialized at map \"%s\".", player.name, str(player.owner), player.map)
コード例 #3
0
ファイル: misc.py プロジェクト: pharmac1st/Adventure
 async def recover(self, ctx):
     """Attempts to re-cache your player, if it isn't.
     You will be alerted to use this if you do have a player, but it hasn't been loaded."""
     pm = self.bot.player_manager
     if pm.get_player(ctx.author):
         return await ctx.send(
             f"{blobs.BLOB_ANGERY} Your player is already cached!")
     data = await self.bot.db.fetchrow(
         "SELECT * FROM players WHERE owner_id=$1;", ctx.author.id)
     if not data:
         return await ctx.send(
             f"{blobs.BLOB_SAD} Couldn't find any data for you."
             f"\nIf you did have a player, then I'm afraid it's gone now.")
     owner_id, name, map_id, created, explored, exp, compendium, gold, *_ = data
     user = self.bot.get_user(owner_id)
     status = await self.bot.redis.get(f"status_{owner_id}")
     if status:
         status = utils.Status(int(status))
     else:
         status = utils.Status.idle
     player = utils.Player(owner=user,
                           bot=self.bot,
                           name=name,
                           created_at=created,
                           explored=list(
                               map(self.bot.map_manager.get_map, explored)),
                           status=status,
                           exp=exp,
                           next_map=await
                           self.bot.redis.get(f"next_map_{user.id}"),
                           compendium=compendium,
                           gold=gold)
     player.map = map_id
     pm.players.append(player)
     log.info("Recovered player %s (%s).", player.name, ctx.author)
     await ctx.send(
         f"{blobs.BLOB_PARTY} Success! {player.name} has been revived!")
コード例 #4
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])
コード例 #5
0
def main():
  # Get Parameters.
  bvz_manifest = utils.GetMetadataParam(
      'bootstrap_vz_manifest', raise_on_not_found=True)
  bvz_version = utils.GetMetadataParam(
      'bootstrap_vz_version', raise_on_not_found=True)
  repo = utils.GetMetadataParam('google_cloud_repo', raise_on_not_found=True)
  image_dest = utils.GetMetadataParam('image_dest', raise_on_not_found=True)
  outs_path = utils.GetMetadataParam('daisy-outs-path', raise_on_not_found=True)
  if repo not in REPOS:
    raise ValueError(
        'Metadata "google_cloud_repo" must be one of %s.' % REPOS)

  utils.Status('Bootstrap_vz manifest: %s' % bvz_manifest)
  utils.Status('Bootstrap_vz version: %s' % bvz_version)
  utils.Status('Google Cloud repo: %s' % repo)

  # Download and setup bootstrap_vz.
  bvz_url = 'https://github.com/andsens/bootstrap-vz/archive/%s.zip'
  bvz_url %= bvz_version
  bvz_zip_dir = 'bvz_zip'
  utils.Status('Downloading bootstrap-vz at commit %s' % bvz_version)
  urllib.urlretrieve(bvz_url, 'bvz.zip')
  with zipfile.ZipFile('bvz.zip', 'r') as z:
    z.extractall(bvz_zip_dir)
  utils.Status('Downloaded and extracted %s to bvz.zip.' % bvz_url)
  bvz_zip_contents = [d for d in os.listdir(bvz_zip_dir)]
  bvz_zip_subdir = os.path.join(bvz_zip_dir, bvz_zip_contents[0])
  utils.Execute(['mv', bvz_zip_subdir, BVZ_DIR])
  utils.Status('Moved bootstrap_vz from %s to %s.' % (bvz_zip_subdir, BVZ_DIR))
  bvz_bin = os.path.join(BVZ_DIR, 'bootstrap-vz')
  utils.MakeExecutable(bvz_bin)
  utils.Status('Made %s executable.' % bvz_bin)
  bvz_manifest_file = os.path.join(BVZ_DIR, 'manifests', bvz_manifest)

  # Inject Google Cloud test repo plugin if using staging or unstable repos.
  # This is used to test new package releases in images.
  if repo is not 'stable':
    utils.Status('Adding Google Cloud test repos plugin for bootstrapvz.')
    repo_plugin_dir = '/build_files/google_cloud_test_repos'
    bvz_plugins = os.path.join(BVZ_DIR, 'bootstrapvz', 'plugins')
    shutil.move(repo_plugin_dir, bvz_plugins)

    with open(bvz_manifest_file, 'r+') as manifest_file:
      manifest_data = yaml.load(manifest_file)
      manifest_plugins = manifest_data['plugins']
      manifest_plugins['google_cloud_test_repos'] = {repo: True}
      manifest_yaml = yaml.dump(manifest_data, default_flow_style=False)
      manifest_file.write(manifest_yaml)

  # Run bootstrap_vz build.
  cmd = [bvz_bin, '--debug', bvz_manifest_file]
  utils.Status('Starting build in %s with params: %s' % (BVZ_DIR, str(cmd)))
  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])
コード例 #6
0
def main():
    # Get Parameters
    repo = utils.GetMetadataParam('google_cloud_repo', raise_on_not_found=True)
    release = utils.GetMetadataParam('el_release', raise_on_not_found=True)
    savelogs = utils.GetMetadataParam('el_savelogs', raise_on_not_found=False)
    savelogs = savelogs == 'true'
    byol = utils.GetMetadataParam('rhel_byol', raise_on_not_found=False)
    byol = byol == 'true'
    sap_hana = utils.GetMetadataParam('rhel_sap_hana',
                                      raise_on_not_found=False)
    sap_hana = sap_hana == 'true'
    sap_apps = utils.GetMetadataParam('rhel_sap_apps',
                                      raise_on_not_found=False)
    sap_apps = sap_apps == 'true'

    utils.Status('EL Release: %s' % release)
    utils.Status('Google Cloud repo: %s' % repo)
    utils.Status('Build working directory: %s' % os.getcwd())

    iso_file = 'installer.iso'

    # Necessary libs and tools to build the installer disk.
    utils.AptGetInstall(['extlinux', 'rsync'])

    # Build the kickstart file.
    ks_content = ks_helpers.BuildKsConfig(release, repo, byol, sap_hana,
                                          sap_apps)
    ks_cfg = 'ks.cfg'
    utils.WriteFile(ks_cfg, ks_content)

    # Write the installer disk. Write extlinux MBR, create partition,
    # copy installer ISO and ISO boot files over.
    utils.Status('Writing installer disk.')
    utils.Execute(['parted', '/dev/sdb', 'mklabel', 'msdos'])
    utils.Execute(['sync'])
    utils.Execute(['parted', '/dev/sdb', 'mkpart', 'primary', '1MB', '100%'])
    utils.Execute(['sync'])
    utils.Execute(['parted', '/dev/sdb', 'set', '1', 'boot', 'on'])
    utils.Execute(['sync'])
    utils.Execute(['dd', 'if=/usr/lib/EXTLINUX/mbr.bin', 'of=/dev/sdb'])
    utils.Execute(['sync'])
    utils.Execute(['mkfs.ext4', '-L', 'INSTALLER', '/dev/sdb1'])
    utils.Execute(['sync'])
    utils.Execute(['mkdir', 'iso', 'installer'])
    utils.Execute(['mount', '-o', 'ro,loop', '-t', 'iso9660', iso_file, 'iso'])
    utils.Execute(['mount', '-t', 'ext4', '/dev/sdb1', 'installer'])
    utils.Execute(
        ['rsync', '-Pav', 'iso/images', 'iso/isolinux', 'installer/'])
    utils.Execute(['cp', iso_file, 'installer/'])
    utils.Execute(['cp', ks_cfg, 'installer/'])

    # Modify boot files on installer disk.
    utils.Execute(['mv', 'installer/isolinux', 'installer/extlinux'])
    utils.Execute([
        'mv', 'installer/extlinux/isolinux.cfg',
        'installer/extlinux/extlinux.conf'
    ])

    # Modify boot config.
    with open('installer/extlinux/extlinux.conf', 'r+') as f:
        oldcfg = f.read()
        cfg = re.sub(r'^default.*', r'default linux', oldcfg, count=1)

        # Change boot args.
        args = ' '.join([
            'text',
            'ks=hd:/dev/sda1:/%s' % ks_cfg, 'console=ttyS0,38400n8', 'sshd=1',
            'loglevel=debug'
        ])
        # 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'])