Example #1
0
def service_read_all(task):
    datastore = task['inputData'].get('datastore', 'actual')
    if datastore not in ['intent', 'actual']:
        return common_worker.fail('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):
        return common_worker.fail('Unable to read uniconfig', response=response)

    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']

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

        node_id = node[0]
        bis = node[1]
        dev = Service.parse_from_openconfig_network(node_id, bis[0], bis[1], bis[2])
        if dev is not None:
            devices.extend(dev)

    device_final = [dev.to_dict() for dev in devices]
    return common_worker.complete('BI instances found successfully', services=device_final)
Example #2
0
def service_create_vll_remote(task):
    service = RemoteService.parse_from_task(task)
    device_1 = service.devices[0]
    device_2 = service.devices[1]

    if service.is_local():
        raise Exception('For remote VLL service, 2 different devices are expected. Received: %s' % (service.device_ids()))

    response1 = vll_worker.device_create_vll_remote({'inputData': {
        'id': device_1.id,
        'service_id': service.id,
        'vccid': service.vccid,
        'interface': device_1.interface,
        'vlan': device_1.vlan,
        'remote_ip': device_2.remote_ip,
        'mtu': service.mtu if service.mtu is not None else 0
    }})
    if common_worker.task_failed(response1):
        return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL' % service.id, response=response1)

    response2 = vll_worker.device_create_vll_remote({'inputData': {
        'id': device_2.id,
        'service_id': service.id,
        'vccid': service.vccid,
        'interface': device_2.interface,
        'vlan': device_2.vlan,
        'remote_ip': device_1.remote_ip,
        'mtu': service.mtu if service.mtu is not None else 0
    }})
    if common_worker.task_failed(response2):
        return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL' % service.id, response1=response1, response2=response2)

    return common_worker.complete('VLL instance: %s configured in uniconfig successfully' % service.id, response1=response1, response2=response2)
Example #3
0
def device_delete_bi_instance(task):
    service = Service.parse_from_task(task)

    ifc_responses = []
    ve_ifc_responses = []
    vlan_responses = []
    for device in service.devices:
        response = delete_ve_interface(device)
        if common_worker.task_failed(response):
            return common_worker.fail('BI interface %s removal in uniconfig FAIL' % device.ve_interface, response=response)
        ve_ifc_responses.append(response)

        response = vll_service_worker.put_minimal_interface(device)
        if common_worker.task_failed(response):
            return common_worker.fail('BI interface %s removal in uniconfig FAIL' % device.interface, response=response)
        ifc_responses.append(response)

        response = delete_vlan(device)
        if common_worker.task_failed(response):
            return common_worker.fail('BI vlan %s removal in uniconfig FAIL' % device.vlan, response=response)
        vlan_responses.append(response)

    return common_worker.complete('BI instance: %s removed in uniconfig successfully' % service.id,
                                  ifc_response=ifc_responses,
                                  ve_ifc_response=ve_ifc_responses,
                                  vlan_response=vlan_responses)
Example #4
0
def service_read_all(task):
    remote_services = read_remote_services(task)

    services = map(lambda service: service.to_dict(), remote_services)
    return common_worker.complete('VPLS instances found successfully: %s' %
                                  len(services),
                                  services=services)
Example #5
0
def service_delete_vll_local(task):
    service = Service.parse_from_task(task)

    if not service.is_local():
        raise Exception('For remote VLL service, 1 device are expected. Received: %s' % service.device_ids())

    response = remove_device_vll(service.devices[0].id, service.id)
    if common_worker.task_failed(response):
        return common_worker.fail('VLL instance: %s removal in uniconfig FAIL' % service.id, response=response)

    return common_worker.complete('VLL instance: %s removed in uniconfig successfully' % service.id, response=response)
Example #6
0
def service_read_all(task):
    # TODO add vll-local vs vll selections

    datastore = task['inputData'].get('datastore', 'actual')
    strategy, reconciliation = get_filter_strategy(task)
    if datastore not in ['intent', 'actual']:
        return common_worker.fail('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):
        return common_worker.fail('Unable to read uniconfig', response=response)

    if reconciliation not in ['name', 'vccid']:
        return common_worker.fail('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']

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

    local_services = []
    remote_services = []
    for node in node_2_l2p2p:

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

        for l2p2p in l2p2ps:
            if vll_type(l2p2p) == 'LOCAL':
                local_services.append(LocalService.parse_from_openconfig_network(node_id, l2p2p, default_ni, ifcs))
            elif vll_type(l2p2p) == 'REMOTE':
                remote_services.append(RemoteService.parse_from_openconfig_network(node_id, l2p2p, default_ni, ifcs))
            else:
                # incomplete configuration or unknown flavour of l2p2p
                continue

    remote_services = aggregate_l2p2p_remote(remote_services) if reconciliation == 'name' \
        else aggregate_l2p2p_remote(remote_services, lambda service: service.vccid)

    services = local_services + remote_services
    services = map(lambda service: service.to_dict(), services)
    return common_worker.complete('VLL instances found successfully: %s' % len(services), services=services)
Example #7
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)
Example #8
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)
Example #9
0
def service_create_vll_local(task):
    service = LocalService.parse_from_task(task)
    device_1 = service.devices[0]
    device_2 = service.devices[1]

    if not service.is_local():
        'For local VLL service, 1 device is expected. Received: %s' % (service.device_ids())

    response1 = vll_worker.device_create_vll_local({'inputData': {
        'id': device_1.id,
        'service_id': service.id,
        'interface_1': device_1.interface,
        'vlan_1': device_1.vlan,
        'interface_2': device_2.interface,
        'vlan_2': device_2.vlan,
        'mtu': service.mtu if service.mtu is not None else 0
    }})
    if common_worker.task_failed(response1):
        return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL' % service.id, response=response1)

    return common_worker.complete('VLL instance: %s configured in uniconfig successfully' % service.id, response=response1)