Exemplo n.º 1
0
def map_segment_to_hosts(context, segment_id, hosts):
    """Map segment to a collection of hosts."""
    with db_api.CONTEXT_WRITER.using(context):
        for host in hosts:
            network.SegmentHostMapping(context,
                                       segment_id=segment_id,
                                       host=host).create()
Exemplo n.º 2
0
def map_segment_to_hosts(context, segment_id, hosts):
    """Map segment to a collection of hosts."""
    with db_api.context_manager.writer.using(context):
        for host in hosts:
            network.SegmentHostMapping(context,
                                       segment_id=segment_id,
                                       host=host).create()
Exemplo n.º 3
0
def map_segment_to_hosts(context, segment_id, hosts):
    """Map segment to a collection of hosts."""
    with db_api.autonested_transaction(context.session):
        for host in hosts:
            network.SegmentHostMapping(context,
                                       segment_id=segment_id,
                                       host=host).create()
Exemplo n.º 4
0
def update_segment_host_mapping(context, host, current_segment_ids):
    with db_api.CONTEXT_WRITER.using(context):
        segment_host_mapping = network.SegmentHostMapping.get_objects(
            context, host=host)
        previous_segment_ids = {
            seg_host['segment_id'] for seg_host in segment_host_mapping}
        for segment_id in current_segment_ids - previous_segment_ids:
            network.SegmentHostMapping(
                context, segment_id=segment_id, host=host).create()
        stale_segment_ids = previous_segment_ids - current_segment_ids
        if stale_segment_ids:
            for entry in segment_host_mapping:
                if entry.segment_id in stale_segment_ids:
                    entry.delete()
Exemplo n.º 5
0
def update_segment_host_mapping(context, host, current_segment_ids):
    with context.session.begin(subtransactions=True):
        segment_host_mapping = network.SegmentHostMapping.get_objects(
            context, host=host)
        previous_segment_ids = {
            seg_host['segment_id'] for seg_host in segment_host_mapping}
        for segment_id in current_segment_ids - previous_segment_ids:
            network.SegmentHostMapping(
                context, segment_id=segment_id, host=host).create()
        stale_segment_ids = previous_segment_ids - current_segment_ids
        if stale_segment_ids:
            for entry in segment_host_mapping:
                if entry.segment_id in stale_segment_ids:
                    entry.delete()
Exemplo n.º 6
0
def update_segment_host_mapping(context, host, current_segment_ids):
    with db_api.CONTEXT_WRITER.using(context):
        segment_host_mapping = network.SegmentHostMapping.get_objects(
            context, host=host)
        previous_segment_ids = {
            seg_host['segment_id']
            for seg_host in segment_host_mapping
        }
        segment_ids = current_segment_ids - previous_segment_ids
        for segment_id in segment_ids:
            network.SegmentHostMapping(context,
                                       segment_id=segment_id,
                                       host=host).create()
        LOG.debug('Segments %s mapped to the host %s', segment_ids, host)
        stale_segment_ids = previous_segment_ids - current_segment_ids
        if stale_segment_ids:
            for entry in segment_host_mapping:
                if entry.segment_id in stale_segment_ids:
                    entry.delete()
                    LOG.debug('Segment %s unmapped from host %s',
                              entry.segment_id, entry.host)