예제 #1
0
def create_device_add_to_vpls(task, vpls_config):
    service = filter(lambda s: s.id == task['inputData']['service']['id'],
                     vpls_config)
    if len(service) < 1:
        raise Exception("VPLS '%s' does not exist." %
                        task['inputData']['service']['id'])
    service = service[0]
    service.devices.extend(
        Service.parse_devices(task['inputData']['service']['devices']))

    return service
예제 #2
0
def service_delete_vpls_instance(task):
    service = Service.parse_from_task(task)

    responses = []
    for dev_id in set(service.device_ids()):
        response1 = remove_device_vpls(dev_id, service.id)
        if common_worker.task_failed(response1):
            return common_worker.fail(
                'VPLS instance: %s removal in uniconfig FAIL' % service.id,
                response=response1)
        responses.append(response1)

    return common_worker.complete(
        'VPLS instance: %s removed in uniconfig successfully' % service.id,
        responses=responses)
예제 #3
0
def service_create_vpls_instance(task):
    service = Service.parse_from_task(task)

    responses = []
    for dev_id in set(service.device_ids()):
        if dev_id == "UNKNOWN":
            continue

        task = {
            'inputData': {
                'id': dev_id,
                'service_id': service.id,
                'vccid': service.vccid,
                'interface': [],
                'remote_ip': [],
                'mtu': service.mtu if service.mtu is not None else 0
            }
        }
        for device in service.devices:
            if device.id == dev_id:
                task['inputData']['interface'].append({
                    'interface':
                    device.interface,
                    'vlan':
                    device.vlan,
                    'untagged':
                    device.untagged
                })
            else:
                if device.remote_ip == "UNKNOWN":
                    continue
                task['inputData']['remote_ip'].append(device.remote_ip)

        response1 = vpls_worker.device_create_vpls(task)
        if common_worker.task_failed(response1):
            response1_delete = remove_device_vpls(dev_id, service.id)
            return common_worker.fail(
                'VPLS instance: %s configuration in uniconfig FAIL' %
                service.id,
                response_for_rollback=response1_delete,
                response=response1)
        responses.append(response1)

    return common_worker.complete(
        'VPLS instance: %s configured in uniconfig successfully' % service.id,
        responses=responses)
예제 #4
0
def read_remote_services(task):
    datastore = task['inputData'].get('datastore', 'actual')
    strategy, reconciliation = get_filter_strategy(task)
    if datastore not in ['intent', 'actual']:
        raise Exception('Unable to read uniconfig datastore: %s' % datastore)

    response = uniconfig_worker.execute_read_uniconfig_topology_operational(task) if datastore == 'actual' \
        else uniconfig_worker.execute_read_uniconfig_topology_config(task)

    if common_worker.task_failed(response):
        raise Exception('Unable to read uniconfig', response=response)
    if reconciliation not in ['name', 'vccid']:
        raise Exception('Unable to reconcile with strategy: %s' %
                        reconciliation)

    if 'node' not in response['output']['response_body']['topology'][0]:
        raise Exception("Uniconfig topology is empty.")

    uniconfig_nodes = response['output']['response_body']['topology'][0][
        'node']

    remote_services = []
    for node in map(
            lambda n: (n['node-id'], extract_network_instances(n, strategy)),
            uniconfig_nodes):

        node_id = node[0]
        l2vsis = node[1][0]
        default_ni = node[1][1]
        ifcs = node[1][2]
        if len(l2vsis) is 0:
            continue

        for l2vsi in l2vsis:
            service = Service.parse_from_openconfig_network(
                node_id, l2vsi, default_ni, ifcs)
            if service is not None:
                remote_services.append(service)

    remote_services = aggregate_l2vsi_remote(remote_services) if reconciliation == 'name' \
        else aggregate_l2vsi_remote(remote_services, lambda s: s.vccid)

    return remote_services
예제 #5
0
def service_create_vpls(task, commit_type):
    dryrun = bool("dry-run" == commit_type)
    add_debug_info = task['inputData']['service'].get('debug', False)
    service = Service.parse_from_task(task)

    device_ids = list(set(service.device_ids()))
    if len(device_ids) < 2:
        raise Exception(
            "There is need to have at least 2 devices to configure vpls instance"
        )

    ifc_responses = []
    ifc_put_responses = []
    ifc_policy_put_responses = []
    ifc_disable_stp_responses = []

    for device in service.devices:
        ifc_response = vll_service_worker.read_interface(device)
        if common_worker.task_failed(ifc_response):
            common_worker.replace_cfg_with_oper(device_ids)
            return common_worker.fail(
                'VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface %s does not exist'
                % (service.id, device.id, device.interface),
                response=ifc_response)
        ifc_responses.append(ifc_response)

        if not dryrun and device.interface_reset:
            policy = vll_service_worker.read_interface_policy(device)
            if not common_worker.task_failed(policy):
                ifc_delete_policy = vll_service_worker.delete_interface_policy(
                    device)
                if ifc_delete_policy is not None and common_worker.task_failed(
                        ifc_delete_policy):
                    common_worker.replace_cfg_with_oper([device.id])
                    return common_worker.fail(
                        'VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface policy %s cannot be reset'
                        % (service.id, device.id, device.interface),
                        response=ifc_delete_policy)

            ifc_delete_response = vll_service_worker.delete_interface(device)
            if common_worker.task_failed(ifc_delete_response):
                common_worker.replace_cfg_with_oper([device.id])
                return common_worker.fail(
                    'VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be reset'
                    % (service.id, device.id, device.interface),
                    response=ifc_delete_response)

            response_commit = common_worker.commit([device.id])

            # Check response from commit RPC. The RPC always succeeds but the status field needs to be checked
            if common_worker.task_failed(
                    response_commit) or common_worker.uniconfig_task_failed(
                        response_commit):
                common_worker.replace_cfg_with_oper([device.id])
                return common_worker.fail(
                    'VPLS instance: %s commit for interface reset FAIL' %
                    service.id,
                    response_commit=response_commit)

            response_sync_from_net = common_worker.sync_from_net([device.id])

            # Check response from commit RPC. The RPC always succeeds but the status field needs to be checked
            if common_worker.task_failed(
                    response_sync_from_net
            ) or common_worker.uniconfig_task_failed(response_sync_from_net):
                common_worker.replace_cfg_with_oper([device.id])
                return common_worker.fail(
                    'VPLS instance: %s sync_from_network after interface reset FAIL'
                    % service.id,
                    response_sync_from_net=response_sync_from_net)

        ifc_put_response1 = vll_service_worker.put_interface(service, device)
        if common_worker.task_failed(ifc_put_response1):
            common_worker.replace_cfg_with_oper(device_ids)
            return common_worker.fail(
                'VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be configured'
                % (service.id, device.id, device.interface),
                response=ifc_put_response1)
        ifc_put_responses.append(ifc_put_response1)

        ifc_policy_put_response1 = vll_service_worker.put_interface_policy(
            device)
        if ifc_policy_put_response1 is not None and common_worker.task_failed(
                ifc_policy_put_response1):
            common_worker.replace_cfg_with_oper(device_ids)
            return common_worker.fail(
                'VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface policies %s cannot be configured'
                % (service.id, device.id, device.interface),
                response=ifc_policy_put_response1)
        if ifc_policy_put_response1 is not None:
            ifc_policy_put_responses.append(ifc_policy_put_response1)

        ifc_stp_delete_response1 = vll_service_worker.disable_interface_stp(
            device)
        # return common_worker.fail('VPLS instance: %s configuration in uniconfig FAIL. Device: %s interface STP %s cannot be configured'
        #                           % (service.id, device.id, device.interface), response_delete_stp=ifc_stp_delete_response1)
        # ifc_disable_stp_responses.append(ifc_stp_delete_response1)

    response_create = service_create_vpls_instance(task)
    if common_worker.task_failed(response_create):
        common_worker.replace_cfg_with_oper(device_ids)
        return common_worker.fail(
            'VPLS instance: %s configuration in uniconfig FAIL' % service.id,
            response=response_create)

    # Check response from dryrun RPC. The RPC always succeeds but the status field needs to be checked
    if dryrun:
        response = common_worker.dryrun_commit(device_ids)
        return common_worker.dryrun_response(
            'VPLS instance: %s dry-run FAIL' % service.id,
            add_debug_info,
            response_interface=ifc_put_responses,
            response_interface_policy=ifc_policy_put_responses,
            response_stp_interface_policy=ifc_disable_stp_responses,
            response_network_instance=response_create,
            response_dryrun=response)
    else:
        response = common_worker.commit(device_ids)
        return common_worker.commit_response(
            device_ids,
            'VPLS instance: %s commit FAIL' % service.id,
            add_debug_info,
            response_interface=ifc_put_responses,
            response_interface_policy=ifc_policy_put_responses,
            response_stp_interface_policy=ifc_disable_stp_responses,
            response_network_instance=response_create,
            response_commit=response)