Exemple #1
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)
Exemple #2
0
def service_delete_vll_task(task, commit_type):
    dryrun = bool("dry-run" == commit_type)
    add_debug_info = task['inputData']['service'].get('debug', False)

    service_id = task['inputData']['service']['id']
    services = service_read_all({'inputData': {
        'datastore': 'actual',
        'reconciliation': 'name',
        'name': service_id
    }})
    number_of_services = len(services['output']['services'])
    if number_of_services < 1:
        return common_worker.fail("VLL instance: %s does not exists" % service_id)
    if number_of_services > 1:
        return common_worker.fail("VLL instance: %s is not unique. It occurs %s times." % (service_id, number_of_services))

    service = Service(services['output']['services'][0])
    device_1 = service.devices[0]
    device_2 = service.devices[1]

    response = service_delete_vll({'inputData': {
        'service': service.to_dict()
    }})
    if common_worker.task_failed(response):
        common_worker.replace_cfg_with_oper([device_1.id, device_2.id])
        return common_worker.fail('VLL instance deletion: %s configuration in uniconfig FAIL' % service.id, response=response)

    if dryrun:
        response_dryrun = common_worker.dryrun_commit([device_1.id, device_2.id])
        return common_worker.dryrun_response('VLL instance deletion: %s dryrun FAIL' % service.id, add_debug_info,
                                             response_create_vpn=response,
                                             response_dryrun=response_dryrun)

    response_commit = common_worker.commit([device_1.id, device_2.id])
    return common_worker.commit_response([device_1.id, device_2.id], 'VLL instance deletion: %s commit FAIL' % service.id, add_debug_info,
                                         response_create_vpn=response,
                                         response_commit=response_commit)
Exemple #3
0
def service_create_vll_task(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_1 = service.devices[0]
    device_2 = service.devices[1]

    # Check interfaces exist

    ifc_response = read_interface(device_1)
    if common_worker.task_failed(ifc_response):
        return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s does not exist'
                                  % (service.id, device_1.id, device_1.interface),
                                  response=ifc_response)

    ifc_response = read_interface(device_2)
    if common_worker.task_failed(ifc_response):
        return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s does not exist'
                                  % (service.id, device_2.id, device_2.interface),
                                  response=ifc_response)

    # Reset interfaces if necessary

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

        ifc_delete_response_1 = delete_interface(device_1)
        if common_worker.task_failed(ifc_delete_response_1):
            common_worker.replace_cfg_with_oper([device_1.id, device_2.id])
            return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be reset'
                                      % (service.id, device_1.id, device_1.interface),
                                      response=ifc_delete_response_1)

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

        ifc_delete_response_2 = delete_interface(device_2)
        if common_worker.task_failed(ifc_delete_response_2):
            common_worker.replace_cfg_with_oper([device_1.id, device_2.id])
            return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be reset'
                                      % (service.id, device_2.id, device_2.interface),
                                      response=ifc_delete_response_2)

    if not dryrun and (device_1.interface_reset or device_2.interface_reset):
        response_commit = common_worker.commit([device_1.id, device_2.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_1.id, device_2.id])
            return common_worker.fail('VLL instance: %s commit for interface reset FAIL' % service.id,
                                      response_commit=response_commit)

        response_sync_from_net = common_worker.sync_from_net([device_1.id, device_2.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_1.id, device_2.id])
            return common_worker.fail('VLL instance: %s sync_from_network after interface reset FAIL' % service.id,
                                      response_sync_from_net=response_sync_from_net)

    # Configure interface #1

    ifc_put_response1 = put_interface(service, device_1)
    if common_worker.task_failed(ifc_put_response1):
        common_worker.replace_cfg_with_oper([device_1.id, device_2.id])
        return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be configured' % (service.id, device_1.id, device_1.interface),
                                  response=ifc_put_response1)

    ifc_policy_put_response1 = put_interface_policy(device_1)
    if ifc_policy_put_response1 is not None and common_worker.task_failed(ifc_policy_put_response1):
        common_worker.replace_cfg_with_oper([device_1.id, device_2.id])
        return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface policies %s cannot be configured' % (service.id, device_1.id, device_1.interface),
                                  response=ifc_policy_put_response1)

    ifc_stp_delete_response1 = disable_interface_stp(device_1)

    # Configure interface #2

    ifc_put_response2 = put_interface(service, device_2)
    if common_worker.task_failed(ifc_put_response2):
        common_worker.replace_cfg_with_oper([device_1.id, device_2.id])
        return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface %s cannot be configured' % (service.id, device_2.id, device_2.interface),
                                  response=ifc_put_response2)

    ifc_policy_put_response2 = put_interface_policy(device_2)
    if ifc_policy_put_response2 is not None and common_worker.task_failed(ifc_policy_put_response2):
        common_worker.replace_cfg_with_oper([device_1.id, device_2.id])
        return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL. Device: %s interface policies %s cannot be configured' % (service.id, device_2.id, device_2.interface),
                                  response=ifc_policy_put_response2)

    ifc_stp_delete_response2 = disable_interface_stp(device_2)

    # Configure service

    response = service_create_vll(task)
    if common_worker.task_failed(response):
        common_worker.replace_cfg_with_oper([device_1.id, device_2.id])
        return common_worker.fail('VLL instance: %s configuration in uniconfig FAIL' % service.id, response=response)

    if dryrun:
        response_dryrun = common_worker.dryrun_commit([device_1.id, device_2.id])
        return common_worker.dryrun_response('VLL instance: %s dryrun FAIL' % service.id, add_debug_info,
                                             response_device1_interface=ifc_put_response1,
                                             response_device1_interface_policy=ifc_policy_put_response1,
                                             response_device1_stp_interface=ifc_stp_delete_response1,
                                             response_device2_interface=ifc_put_response2,
                                             response_device2_interface_policy=ifc_policy_put_response2,
                                             response_device2_stp_interface_policy=ifc_stp_delete_response2,
                                             response_create_vpn=response,
                                             response_dryrun=response_dryrun)

    response_commit = common_worker.commit([device_1.id, device_2.id])
    return common_worker.commit_response([device_1.id, device_2.id], 'VLL instance: %s commit FAIL' % service.id, add_debug_info,
                                         response_device1_interface_reset=ifc_delete_response_1,
                                         response_device1_interface_policy_delete=ifc_delete_policy_response_1,
                                         response_device1_interface=ifc_put_response1,
                                         response_device1_interface_policy=ifc_policy_put_response1,
                                         response_device1_stp_interface=ifc_stp_delete_response1,
                                         response_device2_interface_reset=ifc_delete_response_2,
                                         response_device2_interface_policy_delete=ifc_delete_policy_response_2,
                                         response_device2_interface=ifc_put_response2,
                                         response_device2_interface_policy=ifc_policy_put_response2,
                                         response_device2_stp_interface_policy=ifc_stp_delete_response2,
                                         response_create_vpn=response,
                                         response_commit=response_commit)
Exemple #4
0
def service_create_vll(task):
    service = Service.parse_from_task(task)
    return service_create_vll_local(task) if service.is_local() else service_create_vll_remote(task)