Commit ce595b49 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

ECOC F5GA Telemetry Demo:

- Updated subscribe telemetry script to use long-term GET requests
parent acf4d381
Loading
Loading
Loading
Loading
+22 −21
Original line number Diff line number Diff line
@@ -13,10 +13,11 @@
# limitations under the License.


import requests, websocket
import requests
from requests.auth import HTTPBasicAuth


RESTCONF_ADDRESS = '0.0.0.0'
RESTCONF_ADDRESS = '127.0.0.1'
RESTCONF_PORT = 80
TARGET_SIMAP_NAME = 'e2e'
TARGET_LINK_NAME  = 'E2E-L1'
@@ -37,23 +38,24 @@ REQUEST = {
}


def on_open(ws):
    print('### Opened stream ###')

def on_message(ws, message):
    print(message)

def on_error(ws, error):
    print(error)

def on_close(ws, close_status_code, close_msg):
    print('### Closed stream ###')

def main() -> None:
    print('[E2E] Subscribe Telemetry slice1...')
    reply = requests.get(SUBSCRIBE_URL, json=REQUEST, allow_redirects=True)
    assert reply.is_json
    headers = {'accept': 'application/json'}
    auth = HTTPBasicAuth('admin', 'admin')
    print(SUBSCRIBE_URL)
    print(REQUEST)
    reply = requests.post(
        SUBSCRIBE_URL, headers=headers, json=REQUEST, auth=auth,
        verify=False, allow_redirects=True, timeout=30
    )
    content_type = reply.headers.get('Content-Type', '')
    if 'application/json' not in content_type:
        raise Exception('Not JSON:', reply.content.decode('UTF-8'))
    try:
        reply_data = reply.json()
    except ValueError as e:
        str_error = 'Invalid JSON: {:s}'.format(str(reply.content.decode('UTF-8')))
        raise Exception(str_error) from e

    if 'uri' not in reply_data:
        raise Exception('Unexpected Reply: {:s}'.format(str(reply_data)))
@@ -62,10 +64,9 @@ def main() -> None:
    stream_url = 'http://{:s}:{:d}{:s}'.format(RESTCONF_ADDRESS, RESTCONF_PORT, subscription_uri)
    print('Opening stream "{:s}" (press Ctrl+C to stop)...'.format(stream_url))

    ws = websocket.WebSocketApp(
        stream_url, on_open=on_open, on_message=on_message, on_error=on_error, on_close=on_close
    )
    ws.run_forever()
    with requests.get(stream_url, stream=True) as resp:
        for line in resp.iter_lines(decode_unicode=True):
            print(line)

if __name__ == '__main__':
    main()