Exemplo n.º 1
0
def do_cmd(gargs, args, leftovers):
    """Set worker parameters."""

    request = {"version": "1.0", "params": command.get_params(leftovers)}

    headers = command.get_headers(gargs)

    url = '/api/v1/workers/%s' % args.uuid
    command.connect(gargs, ('PUT', url), 204, request, headers=headers)

    url = '/api/v1/workers/%s' % args.uuid
    _, data = command.connect(gargs, ('GET', url), 200, headers=headers)

    accum = []

    accum.append("worker_id ")
    accum.append(data['service_id'])
    accum.append("\n  name ")
    accum.append(data['name'])

    accum.append("\n  params:")

    for k, val in data['params'].items():
        accum.append("\n    %s: %s" % (k, val))

    print(''.join(accum))
Exemplo n.º 2
0
def do_cmd(gargs, args, _):
    """Create/update LTE slice. """

    headers = command.get_headers(gargs)

    request = {
        "version": "1.0",
        "slice_id": args.slice_id,
        "properties": {
            'rbgs': args.rbgs,
            'ue_scheduler': 0
        }
    }

    url = '/api/v1/projects/%s/lte_slices' % args.project_id
    command.connect(gargs, ('POST', url), 201, request, headers=headers)

    url = '/api/v1/projects/%s/lte_slices/%u' % \
        (args.project_id, args.slice_id)
    _, slc = command.connect(gargs, ('GET', url), 200, headers=headers)

    accum = []

    accum.append("slice_id ")
    accum.append(str(slc['slice_id']))

    for k, val in slc['properties'].items():
        accum.append("\n    %s: %s" % (k, val))

    print(''.join(accum))
Exemplo n.º 3
0
def do_cmd(gargs, args, _):
    """Unset worker callback."""

    url = '/api/v1/workers/%s/callbacks/%s' % (args.uuid, args.name)
    command.connect(gargs, ('DELETE', url), 204)

    print("%s %s" % (args.uuid, args.name))
Exemplo n.º 4
0
def do_cmd(gargs, args, _):
    """Unload a worker."""

    url = '/api/v1/workers/%s' % args.uuid
    command.connect(gargs, ('DELETE', url), 204)

    print(args.uuid)
Exemplo n.º 5
0
def do_cmd(gargs, args, leftovers):
    """Load an application. """

    request = {
        "version": "1.0",
        "name": args.name,
        "params": command.get_params(leftovers)
    }

    headers = command.get_headers(gargs)

    url = '/api/v1/projects/%s/apps' % args.project_id
    response, _ = command.connect(gargs, ('POST', url),
                                  201,
                                  request,
                                  headers=headers)

    location = response.headers['Location']
    tokens = location.split("/")
    app_id = tokens[-1]

    url = '/api/v1/projects/%s/apps/%s' % (args.project_id, app_id)
    _, data = command.connect(gargs, ('GET', url), 200, headers=headers)

    print(data['service_id'])
Exemplo n.º 6
0
def do_cmd(gargs, args, _):
    """Unload an application. """

    url = '/api/v1/projects/%s/apps/%s' % (args.project_id, args.app_id)
    command.connect(gargs, ('DELETE', url), 204)

    print(args.app_id)
Exemplo n.º 7
0
def do_cmd(gargs, args, _):
    """Delete LTE slice. """

    url = '/api/v1/projects/%s/lte_slices/%s' % \
        (args.project_id, args.slice_id)
    command.connect(gargs, ('DELETE', url), 204)

    print(args.slice_id)
Exemplo n.º 8
0
def do_cmd(gargs, args, _):
    """ Add a new WTP """

    request = {"addr": args.addr, "desc": args.desc}

    command.connect(gargs, ('POST', '/api/v1/wtps'), 201, request)

    print(args.addr)
Exemplo n.º 9
0
def do_cmd(gargs, args, _):
    """Delete a LoRaWAN lGTW."""

    if args.lgtw_euid:
        url = '/api/v1/lns/lgtws/%s' % args.lgtw_euid
    else:
        url = '/api/v1/lns/lgtws'

    command.connect(gargs, ('DELETE', url), 204)
Exemplo n.º 10
0
def do_cmd(gargs, args, _):
    """Delete a LoRaWAN lEndDev."""

    if args.devEUI:
        url = '/api/v1/lns/lenddevs/%s' % args.devEUI
    else:
        url = '/api/v1/lns/lenddevs'

    command.connect(gargs, ('DELETE', url), 204)
Exemplo n.º 11
0
def do_cmd(gargs, args, _):
    """Unset app callback."""

    url = '/api/v1/projects/%s/apps/%s/callbacks/%s' % \
        (args.project_id, args.app_id, args.name)

    command.connect(gargs, ('DELETE', url), 204)

    print("%s %s %s" % (args.project_id, args.app_id, args.name))
Exemplo n.º 12
0
def do_cmd(gargs, args, _):
    """Add a new lenddevs."""

    headers = command.get_headers(gargs)
    url = '/api/v1/lns/lenddevs/'

    if args.json_file:

        with open(args.json_file, 'r') as file:
            lenddevs = json.load(file)

        for lenddev in lenddevs:
            dev_eui = lenddev.get("devEUI")
            if not dev_eui:
                print("devEUI missing, cannot add device")
                return
            request = dict(version="1.0")
            for key, value in KEYS.items():
                if value in lenddev:
                    request[key] = lenddev[value]
            # url = '/api/v1/lns/lenddevs/%s' % devEUI
            try:
                response, _ = command.connect(gargs, ('POST', url + dev_eui),
                                              201,
                                              request,
                                              headers=headers,
                                              exit_on_err=False)
            except Exception as err:
                print(err)
            else:
                location = response.headers['Location']
                tokens = location.split("/")
                dev_eui = tokens[-1]
                print("lEndDev (%s) added to LNS  Database" % dev_eui)
            print()

    else:

        request = {}
        url += args.devEUI
        try:
            response, _ = command.connect(gargs, ('POST', url),
                                          201,
                                          request,
                                          headers=headers,
                                          exit_on_err=False)
        except Exception as err:
            print(err)
        else:
            location = response.headers['Location']
            tokens = location.split("/")
            dev_eui = tokens[-1]
            print("lEndDev (%s) added to LNS  Database" % dev_eui)
        print()
Exemplo n.º 13
0
def do_cmd(gargs, args, _):
    """Update an existing LNS entry in the database."""

    request = {"version": "1.0", "desc": args.desc, "uri": args.uri}

    if args.lgtws:
        request["lgtws"] = args.lgtws.split(",")

    if args.owner:
        request["owner"] = args.owner

    url = '/api/v1/lnsd/lnss/%s' % args.lns_euid
    command.connect(gargs, ('PUT', url), 204, request)

    print(args.lns_euid)
Exemplo n.º 14
0
def do_cmd(gargs, args, _):
    """Unload all applications. """

    headers = command.get_headers(gargs)

    url = '/api/v1/projects/%s/apps' % args.project_id
    _, data = command.connect(gargs, ('GET', url), 200, headers=headers)

    for entry in data.values():

        app_id = entry['service_id']

        url = '/api/v1/projects/%s/apps/%s' % (args.project_id, app_id)
        command.connect(gargs, ('DELETE', url), 204, headers=headers)

        print(app_id)
Exemplo n.º 15
0
def do_cmd(gargs, args, _):
    """ Add a new Project """

    request = {"desc": args.desc, "owner": args.owner}

    if args.ssid:

        request["wifi_props"] = {
            "bssid_type": args.ssid_type,
            "ssid": args.ssid
        }

    if args.plmnid:

        plmnid = PLMNID(args.plmnid)

        request["lte_props"] = {"plmnid": plmnid.to_str()}

    headers = command.get_headers(gargs)

    url = '/api/v1/projects'
    response, _ = command.connect(gargs, ('POST', url),
                                  201,
                                  request,
                                  headers=headers)

    location = response.headers['Location']
    tokens = location.split("/")
    project_id = tokens[-1]

    print(project_id)
Exemplo n.º 16
0
def do_cmd(gargs, args, _):
    """List lGTWs registered in the LNS."""

    url = '/api/v1/lns/lgtws'
    _, data = command.connect(gargs, ('GET', url), 200)

    for entry in data:
        out = "name "
        out += entry['name']
        out += " lgtw_euid "
        out += entry['lgtw_euid']
        out += " desc "
        out += "'" + entry['desc'] + "'"

        if not args.lgtw_euid:
            print(out)
            if args.config:
                print("config: " + str(entry["lgtw_config"]))

            if args.version:
                print("version: " + str(entry["lgtw_version"]))

        elif entry['lgtw_euid'] == args.lgtw_euid:
            print(out)

            if args.config:
                print("config: " + str(entry["lgtw_config"]))

            if args.version:
                print("version: " + str(entry["lgtw_version"]))
Exemplo n.º 17
0
def do_cmd(gargs, args, _):
    """Update a lgtw."""
    request = {"version": "1.0"}

    if args.name:
        request["name"] = args.name

    if args.desc:
        request["desc"] = args.desc

    if args.owner:
        request["owner"] = args.owner

    headers = command.get_headers(gargs)

    url = '/api/v1/lns/lgtws/%s' % args.lgtw_euid
    response, _ = command.connect(gargs, ('PUT', url),
                                  201,
                                  request,
                                  headers=headers)

    location = response.headers['Location']
    tokens = location.split("/")
    euid = tokens[-1]

    print(euid, " lGTW updated to LNS  Database")
Exemplo n.º 18
0
def do_cmd(gargs, *_):
    """ List the WTPs. """

    _, data = command.connect(gargs, ('GET', '/api/v1/wtps'), 200)

    for entry in data.values():

        accum = []

        accum.append("addr ")
        accum.append(entry['addr'])
        accum.append(" desc \"")
        accum.append(entry['desc'])
        accum.append("\"")

        if 'connection' in entry and entry['connection']:
            accum.append(" seq ")
            accum.append(str(entry['last_seen']))
            accum.append(" ip ")
            accum.append(entry['connection']['addr'][0])
            accum.append(" ifaces {")
            ifaces = [
                "(%s, %s)" % (v['channel'], v['band'])
                for _, v in entry['blocks'].items()
            ]
            accum.append(', '.join(ifaces))
            accum.append("}")

        print(''.join(accum))
Exemplo n.º 19
0
def do_cmd(gargs, *_):
    """List application that can be loaded. """

    _, data = command.connect(gargs, ('GET', '/api/v1/projects/catalog'), 200)

    for entry in data.values():

        accum = []

        accum.append("name ")
        accum.append(entry['name'])
        accum.append("\n")

        accum.append("  desc: ")
        accum.append(entry['desc'])

        accum.append("\n  params:")

        for k, val in entry['params'].items():
            if k in ('service_id', 'project_id'):
                continue
            accum.append("\n    %s: %s" % (k, val['desc']))
            if 'default' in val:
                accum.append(" Default: %s." % val['default'])
            accum.append(" Type: %s." % val['type'])
            accum.append(" Mandatory: %s." % val['mandatory'])

        print(''.join(accum))
Exemplo n.º 20
0
def do_cmd(gargs, *_):
    """Unload all workers. """

    headers = command.get_headers(gargs)

    url = '/api/v1/workers'
    _, data = command.connect(gargs, ('GET', url), 200, headers=headers)

    for entry in data.values():

        worker_id = entry['service_id']

        url = '/api/v1/workers/%s' % worker_id
        command.connect(gargs, ('DELETE', url), 204, headers=headers)

        print(worker_id)
Exemplo n.º 21
0
def do_cmd(gargs, args, _):
    """Set worker callback."""

    request = {
        "version": "1.0",
        "name": args.name,
        "callback_type": CALLBACK_REST,
        "callback": args.callback
    }

    headers = command.get_headers(gargs)
    url = '/api/v1/workers/%s/callbacks' % args.uuid
    command.connect(gargs, ('POST', url), 201, request, headers=headers)

    url = '/api/v1/workers/%s/callbacks/%s' % (args.uuid, args.name)

    _, data = command.connect(gargs, ('GET', url), 200, headers=headers)

    print(data)
Exemplo n.º 22
0
def do_cmd(gargs, args, _):
    """List lEndDevs registered in the LNS."""

    url = '/api/v1/lns/lenddevs/'
    _, data = command.connect(gargs, ('GET', url), 200)

    for entry in data:
        if not args.devEUI:
            print(entry)
        elif entry['DevEUI'] == args.devEUI:
            print(entry)
Exemplo n.º 23
0
def do_cmd(gargs, args, _):
    """List LNSs in the discovery service database."""

    # if args.project_id:
    #   url = '/api/v1/projects/%s/lnss' % args.project_id
    # else:
    #   url = '/api/v1/lnsd/lnss'

    if args.lns_euid:

        url = "/api/v1/lnsd/lnss/" + args.lns_euid
        _, entry = command.connect(gargs, ('GET', url), 200)
        out = ""
        for key in entry:
            value = "None"
            if entry[key]:
                if isinstance(entry[key], list):
                    value = "'" + ",'".join(entry[key]) + "'"
                else:
                    value = "'" + str(entry[key]) + "'"
            out += key + ":" + value + " "
        print(out)

        return

    url = "/api/v1/lnsd/lnss"
    _, data = command.connect(gargs, ('GET', url), 200)
    for entry in data.values():
        out = ""
        for key in entry:
            value = "None"
            if entry[key]:
                if isinstance(entry[key], list):
                    value = "'" + ",'".join(entry[key]) + "'"
                else:
                    value = "'" + str(entry[key]) + "'"
            out += key + ":" + value + " "
        print(out)
Exemplo n.º 24
0
def do_cmd(gargs, *_):
    """List currently running workers."""

    _, data = command.connect(gargs, ('GET', '/api/v1/workers'), 200)

    for entry in data.values():

        accum = []

        accum.append("worker_id ")
        accum.append(entry['service_id'])
        accum.append(" name ")
        accum.append(entry['name'])

        print(''.join(accum))
Exemplo n.º 25
0
def do_cmd(gargs, args, _):
    """List currently running applications. """

    url = '/api/v1/projects/%s/apps' % args.project_id
    _, data = command.connect(gargs, ('GET', url), 200)

    for entry in data.values():

        accum = []

        accum.append("app_id ")
        accum.append(entry['service_id'])
        accum.append(" name ")
        accum.append(entry['name'])

        print(''.join(accum))
Exemplo n.º 26
0
def do_cmd(gargs, args, _):
    """Add a new lgtw."""

    request = {
        "version": "1.0",
        "desc": args.desc
    }

    if args.owner:
        request["owner"] = args.owner

    url = '/api/v1/lns/lgtws/%s' % args.lgtw_euid

    response, _ = command.connect(gargs, ('POST', url), 201, request)

    location = response.headers['Location']
    tokens = location.split("/")
    euid = tokens[-1]

    print("lGTW %s added to LNS Database" % euid)
Exemplo n.º 27
0
def do_cmd(gargs, args, _):
    """List LTE slices."""

    url = '/api/v1/projects/%s/lte_slices' % args.project_id
    _, slcs = command.connect(gargs, ('GET', url), 200)

    accum = []

    accum.append("project id ")
    accum.append(str(args.project_id))

    for slc in slcs.values():

        accum.append("\nslice_id ")
        accum.append(str(slc['slice_id']))

        for k, val in slc['properties'].items():
            accum.append("\n    %s: %s" % (k, val))

    print(''.join(accum))
Exemplo n.º 28
0
def do_cmd(gargs, *_):
    """List projects. """

    _, data = command.connect(gargs, ('GET', '/api/v1/projects'), 200)

    for entry in data.values():

        accum = []

        accum.append("project_id ")

        accum.append(entry['project_id'])

        accum.append(" desc \"%s\"" % entry['desc'])

        if 'wifi_props' in entry and entry['wifi_props']:
            accum.append(" ssid \"%s\"" % entry['wifi_props']['ssid'])

        if 'lte_props' in entry and entry['lte_props']:
            accum.append(" plmnid \"%s\"" % entry['lte_props']['plmnid'])

        print(''.join(accum))
Exemplo n.º 29
0
def do_cmd(gargs, args, _):
    """Add a new LNS."""

    request = {
        "version": "1.0",
        "desc": args.desc,
        "uri": args.uri,
        "euid": args.lns_euid
    }

    if args.lgtws:
        request["lgtws"] = args.lgtws.split(",")

    if args.owner:
        request["owner"] = args.owner

    response, _ = \
        command.connect(gargs, ('POST', '/api/v1/lnsd/lnss/'), 201, request)

    location = response.headers['Location']
    tokens = location.split("/")
    euid = tokens[-1]

    print(euid)
Exemplo n.º 30
0
def do_cmd(gargs, args, _):
    """ Del a VBS """

    command.connect(gargs, ('DELETE', '/api/v1/vbses/%s' % args.addr), 204)
    print(args.addr)