예제 #1
0
def do_sync(charm_conf, status_exchange):

    # NOTE(beisner): the user_agent variable was an unused assignment (lint).
    # It may be worth re-visiting its usage, intent and benefit with the
    # UrlMirrorReader call below at some point.  Leaving it disabled for now,
    # and not assigning it since it is not currently utilized.
    # user_agent = charm_conf.get("user_agent")

    for mirror_info in charm_conf['mirror_list']:
        mirror_url, initial_path = path_from_mirror_url(
            mirror_info['url'], mirror_info['path'])

        log.info("configuring sync for url {}".format(mirror_info))

        smirror = UrlMirrorReader(mirror_url, policy=policy)

        if charm_conf['use_swift']:
            store = SwiftObjectStore(SWIFT_DATA_DIR)
        else:
            # Use the local apache server to serve product streams
            store = FileStore(prefix=APACHE_DATA_DIR)

        content_id = charm_conf['content_id_template'].format(
            region=charm_conf['region'])

        config = {
            'max_items': mirror_info['max'],
            'modify_hook': charm_conf['modify_hook_scripts'],
            'keep_items': True,
            'content_id': content_id,
            'cloud_name': charm_conf['cloud_name'],
            'item_filters': mirror_info['item_filters'],
            'hypervisor_mapping': charm_conf.get('hypervisor_mapping', False)
        }

        mirror_args = dict(config=config,
                           objectstore=store,
                           name_prefix=charm_conf['name_prefix'])
        mirror_args['custom_properties'] = charm_conf.get(
            'custom_properties', False)

        if SIMPLESTREAMS_HAS_PROGRESS:
            log.info("Calling DryRun mirror to get item list")

            drmirror = glance.ItemInfoDryRunMirror(config=config,
                                                   objectstore=store)
            drmirror.sync(smirror, path=initial_path)
            p = StatusMessageProgressAggregator(drmirror.items,
                                                status_exchange.send_message)
            mirror_args['progress_callback'] = p.progress_callback
        else:
            log.info("Detected simplestreams version without progress"
                     " update support. Only limited feedback available.")

        tmirror = GlanceMirrorWithCustomProperties(**mirror_args)

        log.info("calling GlanceMirror.sync")
        tmirror.sync(smirror, path=initial_path)
def do_sync(charm_conf, status_exchange):

    for mirror_info in charm_conf['mirror_list']:
        mirror_url, initial_path = path_from_mirror_url(
            mirror_info['url'], mirror_info['path'])

        log.info("configuring sync for url {}".format(mirror_info))

        smirror = UrlMirrorReader(mirror_url, policy=policy)

        if charm_conf['use_swift']:
            store = SwiftObjectStore(SWIFT_DATA_DIR)
        else:
            store = None

        content_id = charm_conf['content_id_template'].format(
            region=charm_conf['region'])

        config = {
            'max_items': mirror_info['max'],
            'modify_hook': charm_conf['modify_hook_scripts'],
            'keep_items': False,
            'content_id': content_id,
            'cloud_name': charm_conf['cloud_name'],
            'item_filters': mirror_info['item_filters']
        }

        mirror_args = dict(config=config,
                           objectstore=store,
                           name_prefix=charm_conf['name_prefix'])

        if SIMPLESTREAMS_HAS_PROGRESS:
            log.info("Calling DryRun mirror to get item list")

            drmirror = glance.ItemInfoDryRunMirror(config=config,
                                                   objectstore=store)
            drmirror.sync(smirror, path=initial_path)
            p = StatusMessageProgressAggregator(drmirror.items,
                                                status_exchange.send_message)
            mirror_args['progress_callback'] = p.progress_callback
        else:
            log.info("Detected simplestreams version without progress"
                     " update support. Only limited feedback available.")

        tmirror = glance.GlanceMirror(**mirror_args)

        log.info("calling GlanceMirror.sync")
        tmirror.sync(smirror, path=initial_path)