.. versionadded:: 2019.2.0

    Terminate a circuit on an interface

    circuit
        The name of the circuit
    interface
        The name of the interface to terminate on
    device
        The name of the device the interface belongs to
    speed
        The speed of the circuit, in Kbps
    xconnect_id
        The cross-connect identifier
    term_side
        The side of the circuit termination

    CLI Example:

    .. code-block:: bash

        salt myminion netbox.create_circuit_termination NEW_CIRCUIT_01 xe-0/0/1 myminion 10000 xconnect_id=XCON01

def create_circuit_termination(circuit, interface, device, speed, xconnect_id=None, term_side='A'):
    '''
    .. versionadded:: 2019.2.0

    Terminate a circuit on an interface

    circuit
        The name of the circuit
    interface
        The name of the interface to terminate on
    device
        The name of the device the interface belongs to
    speed
        The speed of the circuit, in Kbps
    xconnect_id
        The cross-connect identifier
    term_side
        The side of the circuit termination

    CLI Example:

    .. code-block:: bash

        salt myminion netbox.create_circuit_termination NEW_CIRCUIT_01 xe-0/0/1 myminion 10000 xconnect_id=XCON01
    '''

    nb_device = get_('dcim', 'devices', name=device)
    nb_interface = get_('dcim', 'interfaces', device_id=nb_device['id'], name=interface)
    nb_circuit = get_('circuits', 'circuits', cid=circuit)
    if nb_circuit and nb_device:
        nb_termination = get_('circuits',
                             'circuit-terminations',
                             q=nb_circuit['cid'])
        if nb_termination:
            return False
        payload = {
            'circuit': nb_circuit['id'],
            'interface': nb_interface['id'],
            'site': nb_device['site']['id'],
            'port_speed': speed,
            'term_side': term_side
        }
        if xconnect_id:
            payload['xconnect_id'] = xconnect_id
        circuit_termination = _add('circuits', 'circuit-terminations', payload)
        if circuit_termination:
            return {'circuits': {'circuit-terminations': {circuit_termination['id']: payload}}}
        else:
            return circuit_termination