Esempio n. 1
0
def safe_copy_vdis(session, sr_path, vdi_uuids, uuid_stack):
    staging_path = utils.make_staging_area(sr_path)
    try:
        _copy_vdis(sr_path, staging_path, vdi_uuids)
        return utils.import_vhds(sr_path, staging_path, uuid_stack)
    finally:
        utils.cleanup_staging_area(staging_path)
Esempio n. 2
0
def inject(session, sr_path, vdi_uuid, boot_menu_url, ip_address, netmask,
           gateway, dns, mkisofs_cmd):

    iso_filename = '%s.img' % os.path.join(sr_path, 'iso', vdi_uuid)

    # Create staging area so we have a unique path but remove it since
    # shutil.copytree will recreate it
    staging_path = utils.make_staging_area(sr_path)
    utils.cleanup_staging_area(staging_path)

    try:
        _unbundle_iso(sr_path, iso_filename, staging_path)

        # Write Configs
        _write_file(
            os.path.join(staging_path, 'netcfg.ipxe'), NETCFG_IPXE % {
                "ip_address": ip_address,
                "netmask": netmask,
                "gateway": gateway,
                "dns": dns,
                "boot_menu_url": boot_menu_url
            })

        _write_file(os.path.join(staging_path, 'isolinux.cfg'), ISOLINUX_CFG)

        _create_iso(mkisofs_cmd, iso_filename, staging_path)
    finally:
        utils.cleanup_staging_area(staging_path)
Esempio n. 3
0
def inject(session, sr_path, vdi_uuid, boot_menu_url, ip_address, netmask,
           gateway, dns, mkisofs_cmd):

    iso_filename = '%s.img' % os.path.join(sr_path, 'iso', vdi_uuid)

    # Create staging area so we have a unique path but remove it since
    # shutil.copytree will recreate it
    staging_path = utils.make_staging_area(sr_path)
    utils.cleanup_staging_area(staging_path)

    try:
        _unbundle_iso(sr_path, iso_filename, staging_path)

        # Write Configs
        _write_file(os.path.join(staging_path, 'netcfg.ipxe'),
                    NETCFG_IPXE % {"ip_address": ip_address,
                                   "netmask": netmask,
                                   "gateway": gateway,
                                   "dns": dns,
                                   "boot_menu_url": boot_menu_url})

        _write_file(os.path.join(staging_path, 'isolinux.cfg'),
                    ISOLINUX_CFG)

        _create_iso(mkisofs_cmd, iso_filename, staging_path)
    finally:
        utils.cleanup_staging_area(staging_path)
Esempio n. 4
0
def download_vhd2(session,
                  image_id,
                  endpoint,
                  uuid_stack,
                  sr_path,
                  extra_headers,
                  api_version=1):
    """Download an image from Glance v2, unbundle it, and then deposit the
    VHDs into the storage repository.
    """
    staging_path = utils.make_staging_area(sr_path)
    try:
        # Download tarball into staging area and extract it
        # TODO(mfedosin): remove this check when v1 is deprecated.
        if api_version == 1:
            _download_tarball_by_url_v1(sr_path, staging_path, image_id,
                                        endpoint, extra_headers)
        else:
            _download_tarball_by_url_v2(sr_path, staging_path, image_id,
                                        endpoint, extra_headers)

        # Move the VHDs from the staging area into the storage repository
        return utils.import_vhds(sr_path, staging_path, uuid_stack)
    finally:
        utils.cleanup_staging_area(staging_path)
Esempio n. 5
0
def safe_copy_vdis(session, sr_path, vdi_uuids, uuid_stack):
    staging_path = utils.make_staging_area(sr_path)
    try:
        _copy_vdis(sr_path, staging_path, vdi_uuids)
        return utils.import_vhds(sr_path, staging_path, uuid_stack)
    finally:
        utils.cleanup_staging_area(staging_path)
Esempio n. 6
0
def transfer_vhd(session, instance_uuid, host, vdi_uuid, sr_path, seq_num):
    """Rsyncs a VHD to an adjacent host."""
    staging_path = utils.make_staging_area(sr_path)
    try:
        utils.prepare_staging_area(sr_path, staging_path, [vdi_uuid],
                                   seq_num=seq_num)
        _rsync_vhds(instance_uuid, host, staging_path)
    finally:
        utils.cleanup_staging_area(staging_path)
Esempio n. 7
0
def transfer_vhd(session, instance_uuid, host, vdi_uuid, sr_path, seq_num):
    """Rsyncs a VHD to an adjacent host."""
    staging_path = utils.make_staging_area(sr_path)
    try:
        utils.prepare_staging_area(
                sr_path, staging_path, [vdi_uuid], seq_num=seq_num)
        _rsync_vhds(instance_uuid, host, staging_path)
    finally:
        utils.cleanup_staging_area(staging_path)
Esempio n. 8
0
def _unbundle_iso(sr_path, filename, path):
    logging.debug("Unbundling ISO '%s'" % filename)
    read_only_path = utils.make_staging_area(sr_path)
    try:
        utils.run_command(['mount', '-o', 'loop', filename, read_only_path])
        try:
            shutil.copytree(read_only_path, path)
        finally:
            utils.run_command(['umount', read_only_path])
    finally:
        utils.cleanup_staging_area(read_only_path)
Esempio n. 9
0
def _unbundle_iso(sr_path, filename, path):
    logging.debug("Unbundling ISO '%s'" % filename)
    read_only_path = utils.make_staging_area(sr_path)
    try:
        utils.run_command(['mount', '-o', 'loop', filename, read_only_path])
        try:
            shutil.copytree(read_only_path, path)
        finally:
            utils.run_command(['umount', read_only_path])
    finally:
        utils.cleanup_staging_area(read_only_path)
Esempio n. 10
0
def upload_vhd2(session, vdi_uuids, image_id, endpoint, sr_path, extra_headers, properties, api_version=1):
    """Bundle the VHDs comprising an image and then stream them into
    Glance.
    """
    staging_path = utils.make_staging_area(sr_path)
    try:
        utils.prepare_staging_area(sr_path, staging_path, vdi_uuids)
        # TODO(mfedosin): remove this check when v1 is deprecated.
        if api_version == 1:
            _upload_tarball_by_url_v1(staging_path, image_id, endpoint, extra_headers, properties)
        else:
            _upload_tarball_by_url_v2(staging_path, image_id, endpoint, extra_headers, properties)
    finally:
        utils.cleanup_staging_area(staging_path)
Esempio n. 11
0
def download_vhd2(session, image_id, endpoint, uuid_stack, sr_path, extra_headers, api_version=1):
    """Download an image from Glance v2, unbundle it, and then deposit the
    VHDs into the storage repository.
    """
    staging_path = utils.make_staging_area(sr_path)
    try:
        # Download tarball into staging area and extract it
        # TODO(mfedosin): remove this check when v1 is deprecated.
        if api_version == 1:
            _download_tarball_by_url_v1(sr_path, staging_path, image_id, endpoint, extra_headers)
        else:
            _download_tarball_by_url_v2(sr_path, staging_path, image_id, endpoint, extra_headers)

        # Move the VHDs from the staging area into the storage repository
        return utils.import_vhds(sr_path, staging_path, uuid_stack)
    finally:
        utils.cleanup_staging_area(staging_path)
Esempio n. 12
0
def download_vhd(session, image_id, torrent_url, torrent_seed_duration,
                 torrent_seed_chance, torrent_max_last_accessed,
                 torrent_listen_port_start, torrent_listen_port_end,
                 torrent_download_stall_cutoff, uuid_stack, sr_path,
                 torrent_max_seeder_processes_per_host):
    """Download an image from BitTorrent, unbundle it, and then deposit the
    VHDs into the storage repository
    """
    seed_cache_path = _make_seed_cache()
    torrent_cache_path = _make_torrent_cache()

    # Housekeeping
    _reap_finished_seeds(seed_cache_path)
    _reap_old_torrent_files(torrent_cache_path, torrent_max_last_accessed)

    torrent_path = _fetch_torrent_file(
            torrent_cache_path, image_id, torrent_url)

    staging_path = utils.make_staging_area(sr_path)
    try:
        tarball_filename = os.path.basename(torrent_path).replace(
                '.torrent', '')
        tarball_path = os.path.join(staging_path, tarball_filename)

        # Download tarball into staging area
        _download(torrent_path, staging_path, torrent_listen_port_start,
                  torrent_listen_port_end, torrent_download_stall_cutoff)

        # Extract the tarball into the staging area
        _extract_tarball(tarball_path, staging_path)

        # Move the VHDs from the staging area into the storage repository
        vdi_list = utils.import_vhds(sr_path, staging_path, uuid_stack)

        # Seed image for others in the swarm
        _seed_if_needed(seed_cache_path, tarball_path, torrent_path,
                        torrent_seed_duration, torrent_seed_chance,
                        torrent_listen_port_start, torrent_listen_port_end,
                        torrent_max_seeder_processes_per_host)
    finally:
        utils.cleanup_staging_area(staging_path)

    return vdi_list
Esempio n. 13
0
def download_vhd(session, image_id, torrent_url, torrent_seed_duration,
                 torrent_seed_chance, torrent_max_last_accessed,
                 torrent_listen_port_start, torrent_listen_port_end,
                 torrent_download_stall_cutoff, uuid_stack, sr_path,
                 torrent_max_seeder_processes_per_host):
    """Download an image from BitTorrent, unbundle it, and then deposit the
    VHDs into the storage repository
    """
    seed_cache_path = _make_seed_cache()
    torrent_cache_path = _make_torrent_cache()

    # Housekeeping
    _reap_finished_seeds(seed_cache_path)
    _reap_old_torrent_files(torrent_cache_path, torrent_max_last_accessed)

    torrent_path = _fetch_torrent_file(torrent_cache_path, image_id,
                                       torrent_url)

    staging_path = utils.make_staging_area(sr_path)
    try:
        tarball_filename = os.path.basename(torrent_path).replace(
            '.torrent', '')
        tarball_path = os.path.join(staging_path, tarball_filename)

        # Download tarball into staging area
        _download(torrent_path, staging_path, torrent_listen_port_start,
                  torrent_listen_port_end, torrent_download_stall_cutoff)

        # Extract the tarball into the staging area
        _extract_tarball(tarball_path, staging_path)

        # Move the VHDs from the staging area into the storage repository
        vdi_list = utils.import_vhds(sr_path, staging_path, uuid_stack)

        # Seed image for others in the swarm
        _seed_if_needed(seed_cache_path, tarball_path, torrent_path,
                        torrent_seed_duration, torrent_seed_chance,
                        torrent_listen_port_start, torrent_listen_port_end,
                        torrent_max_seeder_processes_per_host)
    finally:
        utils.cleanup_staging_area(staging_path)

    return vdi_list
Esempio n. 14
0
def upload_vhd2(session,
                vdi_uuids,
                image_id,
                endpoint,
                sr_path,
                extra_headers,
                properties,
                api_version=1):
    """Bundle the VHDs comprising an image and then stream them into Glance"""
    staging_path = utils.make_staging_area(sr_path)
    try:
        utils.prepare_staging_area(sr_path, staging_path, vdi_uuids)
        # TODO(mfedosin): remove this check when v1 is deprecated.
        if api_version == 1:
            _upload_tarball_by_url_v1(staging_path, image_id, endpoint,
                                      extra_headers, properties)
        else:
            _upload_tarball_by_url_v2(staging_path, image_id, endpoint,
                                      extra_headers, properties)
    finally:
        utils.cleanup_staging_area(staging_path)
Esempio n. 15
0
def move_vhds_into_sr(session, instance_uuid, sr_path, uuid_stack):
    """Moves the VHDs from their copied location to the SR."""
    staging_path = "/images/instance%s" % instance_uuid
    imported_vhds = utils.import_vhds(sr_path, staging_path, uuid_stack)
    utils.cleanup_staging_area(staging_path)
    return imported_vhds
Esempio n. 16
0
def move_vhds_into_sr(session, instance_uuid, sr_path, uuid_stack):
    """Moves the VHDs from their copied location to the SR."""
    staging_path = "/images/instance%s" % instance_uuid
    imported_vhds = utils.import_vhds(sr_path, staging_path, uuid_stack)
    utils.cleanup_staging_area(staging_path)
    return imported_vhds