Python json.tool() Examples

The following are code examples for showing how to use json.tool(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: cells   Author: AlesTsurko   File: tool.py    MIT License 7 votes vote down vote up
def main():
    prog = 'python -m json.tool'
    description = ('A simple command line interface for json module '
                   'to validate and pretty-print JSON objects.')
    parser = argparse.ArgumentParser(prog=prog, description=description)
    parser.add_argument('infile', nargs='?', type=argparse.FileType(),
                        help='a JSON file to be validated or pretty-printed')
    parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
                        help='write the output of infile to outfile')
    parser.add_argument('--sort-keys', action='store_true', default=False,
                        help='sort the output of dictionaries alphabetically by key')
    options = parser.parse_args()

    infile = options.infile or sys.stdin
    outfile = options.outfile or sys.stdout
    sort_keys = options.sort_keys
    with infile:
        try:
            obj = json.load(infile)
        except ValueError as e:
            raise SystemExit(e)
    with outfile:
        json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
        outfile.write('\n') 
Example 2
Project: NiujiaoDebugger   Author: MrSrc   File: tool.py    GNU General Public License v3.0 6 votes vote down vote up
def main():
    prog = 'python -m json.tool'
    description = ('A simple command line interface for json module '
                   'to validate and pretty-print JSON objects.')
    parser = argparse.ArgumentParser(prog=prog, description=description)
    parser.add_argument('infile', nargs='?', type=argparse.FileType(),
                        help='a JSON file to be validated or pretty-printed')
    parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
                        help='write the output of infile to outfile')
    parser.add_argument('--sort-keys', action='store_true', default=False,
                        help='sort the output of dictionaries alphabetically by key')
    options = parser.parse_args()

    infile = options.infile or sys.stdin
    outfile = options.outfile or sys.stdout
    sort_keys = options.sort_keys
    with infile:
        try:
            obj = json.load(infile)
        except ValueError as e:
            raise SystemExit(e)
    with outfile:
        json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
        outfile.write('\n') 
Example 3
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: tool.py    GNU General Public License v2.0 6 votes vote down vote up
def main():
    prog = 'python -m json.tool'
    description = ('A simple command line interface for json module '
                   'to validate and pretty-print JSON objects.')
    parser = argparse.ArgumentParser(prog=prog, description=description)
    parser.add_argument('infile', nargs='?', type=argparse.FileType(),
                        help='a JSON file to be validated or pretty-printed')
    parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
                        help='write the output of infile to outfile')
    parser.add_argument('--sort-keys', action='store_true', default=False,
                        help='sort the output of dictionaries alphabetically by key')
    options = parser.parse_args()

    infile = options.infile or sys.stdin
    outfile = options.outfile or sys.stdout
    sort_keys = options.sort_keys
    with infile:
        try:
            obj = json.load(infile)
        except ValueError as e:
            raise SystemExit(e)
    with outfile:
        json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
        outfile.write('\n') 
Example 4
Project: luci-py   Author: luci   File: gce.py    Apache License 2.0 6 votes vote down vote up
def get_metadata_uncached():
  """Returns the GCE metadata as a dict.

  Returns None if not running on GCE or if metadata server is unreachable.

  Refs:
    https://cloud.google.com/compute/docs/metadata
    https://cloud.google.com/compute/docs/machine-types

  To get the at the command line from a GCE VM, use:
    curl --silent \
      http://metadata.google.internal/computeMetadata/v1/?recursive=true \
      -H "Metadata-Flavor: Google" | python -m json.tool | less
  """
  raw = _raw_metadata_request('/computeMetadata/v1/?recursive=true')
  return json.loads(raw) if raw else None 
Example 5
Project: deb-ryu   Author: openstack   File: rest_vtep.py    Apache License 2.0 5 votes vote down vote up
def del_speaker(self, **kwargs):
        """
        Shutdowns BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            DELETE  /vtep/speakers
            ======= ================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/speakers |
             python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {},
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_speaker()
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 6
Project: deb-ryu   Author: openstack   File: rest_vtep.py    Apache License 2.0 5 votes vote down vote up
def get_neighbors(self, **kwargs):
        """
        Gets a list of all neighbors.

        Usage:

            ======= ========================
            Method  URI
            ======= ========================
            GET     /vtep/neighbors
            ======= ========================

        Example::

            $ curl -X GET http://localhost:8080/vtep/neighbors |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "up"
                    }
                }
            }
        """
        return self._get_neighbors(**kwargs) 
Example 7
Project: deb-ryu   Author: openstack   File: rest_vtep.py    Apache License 2.0 5 votes vote down vote up
def get_networks(self, **kwargs):
        """
        Gets a list of all networks.

        Usage:

            ======= ===============
            Method  URI
            ======= ===============
            GET     /vtep/networks
            ======= ===============

        Example::

            $ curl -X GET http://localhost:8080/vtep/networks |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {
                            "aa:bb:cc:dd:ee:ff": {
                                "EvpnClient": {
                                    "ip": "10.0.0.1",
                                    "mac": "aa:bb:cc:dd:ee:ff",
                                    "next_hop": "172.17.0.1",
                                    "port": 1
                                }
                            }
                        },
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        return self._get_networks(**kwargs) 
Example 8
Project: aws-lambda-runtime-pypy   Author: uscheller   File: tool.py    Apache License 2.0 5 votes vote down vote up
def main():
    prog = 'python -m json.tool'
    description = ('A simple command line interface for json module '
                   'to validate and pretty-print JSON objects.')
    parser = argparse.ArgumentParser(prog=prog, description=description)
    parser.add_argument('infile', nargs='?', type=argparse.FileType(),
                        help='a JSON file to be validated or pretty-printed')
    parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
                        help='write the output of infile to outfile')
    parser.add_argument('--sort-keys', action='store_true', default=False,
                        help='sort the output of dictionaries alphabetically by key')
    options = parser.parse_args()

    infile = options.infile or sys.stdin
    outfile = options.outfile or sys.stdout
    sort_keys = options.sort_keys
    with infile:
        try:
            if sort_keys:
                obj = json.load(infile)
            else:
                obj = json.load(infile,
                                object_pairs_hook=collections.OrderedDict)
        except ValueError as e:
            raise SystemExit(e)
    with outfile:
        json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
        outfile.write('\n') 
Example 9
Project: options-screener   Author: dcwangmit01   File: datareader.py    MIT License 5 votes vote down vote up
def yahoo_stock_info(self, ticker):
        r = requests.get('http://finance.yahoo.com/quote/AAPL?p=' + ticker)
        soup = BeautifulSoup(r.text)
        tables = soup.find_all('table')[1:]  # drop the first useless table

        # curl 'https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL?modules=summaryProfile%2CfinancialData%2CrecommendationTrend%2CupgradeDowngradeHistory%2Cearnings%2CdefaultKeyStatistics%2CcalendarEvents' | python -m json.tool > tmp2.txt
        print(soup.prettify())
        import pytest
        pytest.set_trace() 
Example 10
Project: setup   Author: mindbender-studio   File: tool.py    MIT License 5 votes vote down vote up
def main():
    prog = 'python -m json.tool'
    description = ('A simple command line interface for json module '
                   'to validate and pretty-print JSON objects.')
    parser = argparse.ArgumentParser(prog=prog, description=description)
    parser.add_argument('infile', nargs='?', type=argparse.FileType(),
                        help='a JSON file to be validated or pretty-printed')
    parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
                        help='write the output of infile to outfile')
    parser.add_argument('--sort-keys', action='store_true', default=False,
                        help='sort the output of dictionaries alphabetically by key')
    options = parser.parse_args()

    infile = options.infile or sys.stdin
    outfile = options.outfile or sys.stdout
    sort_keys = options.sort_keys
    with infile:
        try:
            if sort_keys:
                obj = json.load(infile)
            else:
                obj = json.load(infile,
                                object_pairs_hook=collections.OrderedDict)
        except ValueError as e:
            raise SystemExit(e)
    with outfile:
        json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
        outfile.write('\n') 
Example 11
Project: workspace_2017   Author: nwiizo   File: rest_vtep.py    MIT License 5 votes vote down vote up
def del_speaker(self, **kwargs):
        """
        Shutdowns BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            DELETE  /vtep/speakers
            ======= ================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/speakers |
             python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {},
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_speaker()
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 12
Project: workspace_2017   Author: nwiizo   File: rest_vtep.py    MIT License 5 votes vote down vote up
def get_neighbors(self, **kwargs):
        """
        Gets a list of all neighbors.

        Usage:

            ======= ========================
            Method  URI
            ======= ========================
            GET     /vtep/neighbors
            ======= ========================

        Example::

            $ curl -X GET http://localhost:8080/vtep/neighbors |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "up"
                    }
                }
            }
        """
        return self._get_neighbors(**kwargs) 
Example 13
Project: workspace_2017   Author: nwiizo   File: rest_vtep.py    MIT License 5 votes vote down vote up
def get_networks(self, **kwargs):
        """
        Gets a list of all networks.

        Usage:

            ======= ===============
            Method  URI
            ======= ===============
            GET     /vtep/networks
            ======= ===============

        Example::

            $ curl -X GET http://localhost:8080/vtep/networks |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {
                            "aa:bb:cc:dd:ee:ff": {
                                "EvpnClient": {
                                    "ip": "10.0.0.1",
                                    "mac": "aa:bb:cc:dd:ee:ff",
                                    "next_hop": "172.17.0.1",
                                    "port": 1
                                }
                            }
                        },
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        return self._get_networks(**kwargs) 
Example 14
Project: empower-ryu   Author: clicknf   File: rest_vtep.py    Apache License 2.0 5 votes vote down vote up
def del_speaker(self, **kwargs):
        """
        Shutdowns BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            DELETE  /vtep/speakers
            ======= ================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/speakers |
             python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {},
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_speaker()
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 15
Project: empower-ryu   Author: clicknf   File: rest_vtep.py    Apache License 2.0 5 votes vote down vote up
def get_neighbors(self, **kwargs):
        """
        Gets a list of all neighbors.

        Usage:

            ======= ========================
            Method  URI
            ======= ========================
            GET     /vtep/neighbors
            ======= ========================

        Example::

            $ curl -X GET http://localhost:8080/vtep/neighbors |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "up"
                    }
                }
            }
        """
        return self._get_neighbors(**kwargs) 
Example 16
Project: empower-ryu   Author: clicknf   File: rest_vtep.py    Apache License 2.0 5 votes vote down vote up
def get_networks(self, **kwargs):
        """
        Gets a list of all networks.

        Usage:

            ======= ===============
            Method  URI
            ======= ===============
            GET     /vtep/networks
            ======= ===============

        Example::

            $ curl -X GET http://localhost:8080/vtep/networks |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {
                            "aa:bb:cc:dd:ee:ff": {
                                "EvpnClient": {
                                    "ip": "10.0.0.1",
                                    "mac": "aa:bb:cc:dd:ee:ff",
                                    "next_hop": "172.17.0.1",
                                    "port": 1
                                }
                            }
                        },
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        return self._get_networks(**kwargs) 
Example 17
Project: roi_tag   Author: FNNDSC   File: roi_gcibs.py    MIT License 5 votes vote down vote up
def bootstrap_occurrenceDictionariesBuild(self, **kwargs):
        """Build the occurrence dictionaries:

        This method captures the bootstrap occurrence dictionaries for the
        comparison group as well as the two intra-group variance occurrences.

        """
        str_g1 = self._str_group[0]
        str_g2 = self._str_group[1]
        str_g3 = self._str_group
        l_subgroup = [str_g1, str_g2, str_g3]
        for str_subgroup in l_subgroup:
            os.chdir(self._workingDir)
            if str_subgroup in [str_g1, str_g2]:
                str_g           = "%s000" % str_subgroup
                str_compGroup   = '12'
            else:
                str_g           = '6'
                str_compGroup   = self._str_group
            str_bsDir   = "bootstrap-%s-%s/%s/%s" % (str_g,
                                                    self._str_curvFunc,
                                                    self._str_annotation,
                                                    str_compGroup)
            os.chdir(str_bsDir)
            if self._str_curvFunc == "thickness":
                str_cfilt = "thickness"
            else:
                str_cfilt = "curv"
            self._log('Parsing occurrence data for %2d.%s.%s.%s.%s\n' % (int(str_subgroup), self._str_annotation, self._str_hemi, self._str_surface, self._str_curvFunc))
            OSshell('find . -iname occurence.txt | grep %s | grep %s | grep %s | ../../../../sh/ocfilt.sh -t 0 | python -m json.tool ' % \
                    (str_cfilt, self._str_hemi, self._str_surface))
            self._d_bootstrapOccurrence[str_subgroup][self._str_annotation][self._str_hemi][self._str_surface][self._str_curvFunc] = json.loads(OSshell.stdout())
            spec = self._d_bootstrapOccurrence[str_subgroup][self._str_annotation][self._str_hemi][self._str_surface][self._str_curvFunc].keys()[0]
            self._d_bootstrapOccurrence[str_subgroup][self._str_annotation][self._str_hemi][self._str_surface][self._str_curvFunc][spec].pop("", None)
        return {"return": self._d_bootstrapOccurrence} 
Example 18
Project: docker   Author: getavalon   File: tool.py    MIT License 5 votes vote down vote up
def main():
    prog = 'python -m json.tool'
    description = ('A simple command line interface for json module '
                   'to validate and pretty-print JSON objects.')
    parser = argparse.ArgumentParser(prog=prog, description=description)
    parser.add_argument('infile', nargs='?', type=argparse.FileType(),
                        help='a JSON file to be validated or pretty-printed')
    parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
                        help='write the output of infile to outfile')
    parser.add_argument('--sort-keys', action='store_true', default=False,
                        help='sort the output of dictionaries alphabetically by key')
    options = parser.parse_args()

    infile = options.infile or sys.stdin
    outfile = options.outfile or sys.stdout
    sort_keys = options.sort_keys
    with infile:
        try:
            if sort_keys:
                obj = json.load(infile)
            else:
                obj = json.load(infile,
                                object_pairs_hook=collections.OrderedDict)
        except ValueError as e:
            raise SystemExit(e)
    with outfile:
        json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
        outfile.write('\n') 
Example 19
Project: x-path-walker   Author: Lompik   File: json_Processor.py    MIT License 5 votes vote down vote up
def get_path_line_number(self, path, with_attrs=False):
        path = path.split("| ")[1] if (with_attrs is True) else path

        orig = self.parsed
        path = get_dict_from_path(path, self.separator)
        res = traverse_and_remove_path(orig, path)
        orig = json.dumps(orig, indent=4).split("\n")

        if(len(orig) != self.file_line_number):
            raise ValueError("This json file formatting is not compatible. Please run `python -m json.tool file`")

        with_del = json.dumps(res, indent=4).split("\n")
        return(list_compare_idx(orig, with_del) + 1) 
Example 20
Project: SDN-QoS-Routing   Author: dodoyuan   File: rest_vtep.py    Apache License 2.0 5 votes vote down vote up
def del_speaker(self, **kwargs):
        """
        Shutdowns BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            DELETE  /vtep/speakers
            ======= ================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/speakers |
             python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {},
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_speaker()
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 21
Project: SDN-QoS-Routing   Author: dodoyuan   File: rest_vtep.py    Apache License 2.0 5 votes vote down vote up
def get_neighbors(self, **kwargs):
        """
        Gets a list of all neighbors.

        Usage:

            ======= ========================
            Method  URI
            ======= ========================
            GET     /vtep/neighbors
            ======= ========================

        Example::

            $ curl -X GET http://localhost:8080/vtep/neighbors |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "up"
                    }
                }
            }
        """
        return self._get_neighbors(**kwargs) 
Example 22
Project: SDN-QoS-Routing   Author: dodoyuan   File: rest_vtep.py    Apache License 2.0 5 votes vote down vote up
def get_networks(self, **kwargs):
        """
        Gets a list of all networks.

        Usage:

            ======= ===============
            Method  URI
            ======= ===============
            GET     /vtep/networks
            ======= ===============

        Example::

            $ curl -X GET http://localhost:8080/vtep/networks |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {
                            "aa:bb:cc:dd:ee:ff": {
                                "EvpnClient": {
                                    "ip": "10.0.0.1",
                                    "mac": "aa:bb:cc:dd:ee:ff",
                                    "next_hop": "172.17.0.1",
                                    "port": 1
                                }
                            }
                        },
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        return self._get_networks(**kwargs) 
Example 23
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: tool.py    GNU General Public License v3.0 5 votes vote down vote up
def main():
    prog = 'python -m json.tool'
    description = ('A simple command line interface for json module '
                   'to validate and pretty-print JSON objects.')
    parser = argparse.ArgumentParser(prog=prog, description=description)
    parser.add_argument('infile', nargs='?', type=argparse.FileType(),
                        help='a JSON file to be validated or pretty-printed')
    parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
                        help='write the output of infile to outfile')
    parser.add_argument('--sort-keys', action='store_true', default=False,
                        help='sort the output of dictionaries alphabetically by key')
    options = parser.parse_args()

    infile = options.infile or sys.stdin
    outfile = options.outfile or sys.stdout
    sort_keys = options.sort_keys
    with infile:
        try:
            if sort_keys:
                obj = json.load(infile)
            else:
                obj = json.load(infile,
                                object_pairs_hook=collections.OrderedDict)
        except ValueError as e:
            raise SystemExit(e)
    with outfile:
        json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
        outfile.write('\n') 
Example 24
Project: Sublime-GameMaker-Studio-Language-Bundle   Author: uduse   File: tool.py    Apache License 2.0 5 votes vote down vote up
def main():
    prog = 'python -m json.tool'
    description = ('A simple command line interface for json module '
                   'to validate and pretty-print JSON objects.')
    parser = argparse.ArgumentParser(prog=prog, description=description)
    parser.add_argument('infile', nargs='?', type=argparse.FileType(),
                        help='a JSON file to be validated or pretty-printed')
    parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
                        help='write the output of infile to outfile')
    parser.add_argument('--sort-keys', action='store_true', default=False,
                        help='sort the output of dictionaries alphabetically by key')
    options = parser.parse_args()

    infile = options.infile or sys.stdin
    outfile = options.outfile or sys.stdout
    sort_keys = options.sort_keys
    with infile:
        try:
            if sort_keys:
                obj = json.load(infile)
            else:
                obj = json.load(infile,
                                object_pairs_hook=collections.OrderedDict)
        except ValueError as e:
            raise SystemExit(e)
    with outfile:
        json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
        outfile.write('\n') 
Example 25
Project: deb-ryu   Author: openstack   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def add_speaker(self, **kwargs):
        """
        Creates a new BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            POST    /vtep/speakers
            ======= ================

        Request parameters:

            ========== ============================================
            Attribute  Description
            ========== ============================================
            dpid       ID of Datapath binding to speaker. (e.g. 1)
            as_number  AS number. (e.g. 65000)
            router_id  Router ID. (e.g. "172.17.0.1")
            ========== ============================================

        Example::

            $ curl -X POST -d '{
             "dpid": 1,
             "as_number": 65000,
             "router_id": "172.17.0.1"
             }' http://localhost:8080/vtep/speakers | python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {},
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_speaker(**kwargs)
        except DatapathNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 26
Project: deb-ryu   Author: openstack   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def get_speakers(self, **kwargs):
        """
        Gets the info of BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            GET     /vtep/speakers
            ======= ================

        Example::

            $ curl -X GET http://localhost:8080/vtep/speakers |
             python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {
                            "172.17.0.2": {
                                "EvpnNeighbor": {
                                    "address": "172.17.0.2",
                                    "remote_as": 65000,
                                    "state": "up"
                                }
                            }
                        },
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.get_speaker()
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 27
Project: deb-ryu   Author: openstack   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def add_neighbor(self, **kwargs):
        """
        Registers a new neighbor to the speaker.

        Usage:

            ======= ========================
            Method  URI
            ======= ========================
            POST    /vtep/neighbors
            ======= ========================

        Request parameters:

            ========== ================================================
            Attribute  Description
            ========== ================================================
            address    IP address of neighbor. (e.g. "172.17.0.2")
            remote_as  AS number of neighbor. (e.g. 65000)
            ========== ================================================

        Example::

            $ curl -X POST -d '{
             "address": "172.17.0.2",
             "remote_as": 65000
             }' http://localhost:8080/vtep/neighbors |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "down"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_neighbor(**kwargs)
        except BGPSpeakerNotFound as e:
            return e.to_response(status=400)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 28
Project: deb-ryu   Author: openstack   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def del_neighbor(self, **kwargs):
        """
        Unregister the specified neighbor from the speaker.

        Usage:

            ======= ==================================
            Method  URI
            ======= ==================================
            DELETE  /vtep/speaker/neighbors/{address}
            ======= ==================================

        Request parameters:

            ========== ================================================
            Attribute  Description
            ========== ================================================
            address    IP address of neighbor. (e.g. "172.17.0.2")
            ========== ================================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/speaker/neighbors/172.17.0.2 |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "up"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_neighbor(**kwargs)
        except (BGPSpeakerNotFound, NeighborNotFound) as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 29
Project: deb-ryu   Author: openstack   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def add_network(self, **kwargs):
        """
        Defines a new network.

        Usage:

            ======= ===============
            Method  URI
            ======= ===============
            POST    /vtep/networks
            ======= ===============

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X POST -d '{
             "vni": 10
             }' http://localhost:8080/vtep/networks | python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {},
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_network(**kwargs)
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 30
Project: deb-ryu   Author: openstack   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def get_network(self, **kwargs):
        """
        Gets the network for the specified VNI.

        Usage:

            ======= =====================
            Method  URI
            ======= =====================
            GET     /vtep/networks/{vni}
            ======= =====================

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X GET http://localhost:8080/vtep/networks/10 |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {
                            "aa:bb:cc:dd:ee:ff": {
                                "EvpnClient": {
                                    "ip": "10.0.0.1",
                                    "mac": "aa:bb:cc:dd:ee:ff",
                                    "next_hop": "172.17.0.1",
                                    "port": 1
                                }
                            }
                        },
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        return self._get_networks(**kwargs) 
Example 31
Project: deb-ryu   Author: openstack   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def del_network(self, **kwargs):
        """
        Deletes the network for the specified VNI.

        Usage:

            ======= =====================
            Method  URI
            ======= =====================
            DELETE  /vtep/networks/{vni}
            ======= =====================

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/networks/10 |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "ethernet_tag_id": 10,
                        "clients": [
                            {
                                "EvpnClient": {
                                    "ip": "10.0.0.11",
                                    "mac": "e2:b1:0c:ba:42:ed",
                                    "port": 1
                                }
                            }
                        ],
                        "route_dist": "65000:100",
                        "vni": 10
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_network(**kwargs)
        except (BGPSpeakerNotFound, DatapathNotFound, VniNotFound) as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 32
Project: deb-ryu   Author: openstack   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def del_client(self, **kwargs):
        """
        Registers a new client to the specified network.

        Usage:

            ======= ===================================
            Method  URI
            ======= ===================================
            DELETE  /vtep/networks/{vni}/clients/{mac}
            ======= ===================================

        Request parameters:

            =========== ===============================================
            Attribute   Description
            =========== ===============================================
            vni         Virtual Network Identifier. (e.g. 10)
            mac         Client MAC address to register.
            =========== ===============================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/networks/10/clients/aa:bb:cc:dd:ee:ff |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnClient": {
                        "ip": "10.0.0.1",
                        "mac": "aa:bb:cc:dd:ee:ff",
                        "next_hop": "172.17.0.1",
                        "port": 1
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_client(**kwargs)
        except (BGPSpeakerNotFound, DatapathNotFound,
                VniNotFound, ClientNotFound, ClientNotLocal) as e:
            return Response(body=str(e), status=500)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 33
Project: workspace_2017   Author: nwiizo   File: rest_vtep.py    MIT License 4 votes vote down vote up
def add_speaker(self, **kwargs):
        """
        Creates a new BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            POST    /vtep/speakers
            ======= ================

        Request parameters:

            ========== ============================================
            Attribute  Description
            ========== ============================================
            dpid       ID of Datapath binding to speaker. (e.g. 1)
            as_number  AS number. (e.g. 65000)
            router_id  Router ID. (e.g. "172.17.0.1")
            ========== ============================================

        Example::

            $ curl -X POST -d '{
             "dpid": 1,
             "as_number": 65000,
             "router_id": "172.17.0.1"
             }' http://localhost:8080/vtep/speakers | python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {},
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_speaker(**kwargs)
        except DatapathNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 34
Project: workspace_2017   Author: nwiizo   File: rest_vtep.py    MIT License 4 votes vote down vote up
def get_speakers(self, **kwargs):
        """
        Gets the info of BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            GET     /vtep/speakers
            ======= ================

        Example::

            $ curl -X GET http://localhost:8080/vtep/speakers |
             python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {
                            "172.17.0.2": {
                                "EvpnNeighbor": {
                                    "address": "172.17.0.2",
                                    "remote_as": 65000,
                                    "state": "up"
                                }
                            }
                        },
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.get_speaker()
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 35
Project: workspace_2017   Author: nwiizo   File: rest_vtep.py    MIT License 4 votes vote down vote up
def add_neighbor(self, **kwargs):
        """
        Registers a new neighbor to the speaker.

        Usage:

            ======= ========================
            Method  URI
            ======= ========================
            POST    /vtep/neighbors
            ======= ========================

        Request parameters:

            ========== ================================================
            Attribute  Description
            ========== ================================================
            address    IP address of neighbor. (e.g. "172.17.0.2")
            remote_as  AS number of neighbor. (e.g. 65000)
            ========== ================================================

        Example::

            $ curl -X POST -d '{
             "address": "172.17.0.2",
             "remote_as": 65000
             }' http://localhost:8080/vtep/neighbors |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "down"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_neighbor(**kwargs)
        except BGPSpeakerNotFound as e:
            return e.to_response(status=400)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 36
Project: workspace_2017   Author: nwiizo   File: rest_vtep.py    MIT License 4 votes vote down vote up
def del_neighbor(self, **kwargs):
        """
        Unregister the specified neighbor from the speaker.

        Usage:

            ======= ==================================
            Method  URI
            ======= ==================================
            DELETE  /vtep/speaker/neighbors/{address}
            ======= ==================================

        Request parameters:

            ========== ================================================
            Attribute  Description
            ========== ================================================
            address    IP address of neighbor. (e.g. "172.17.0.2")
            ========== ================================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/speaker/neighbors/172.17.0.2 |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "up"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_neighbor(**kwargs)
        except (BGPSpeakerNotFound, NeighborNotFound) as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 37
Project: workspace_2017   Author: nwiizo   File: rest_vtep.py    MIT License 4 votes vote down vote up
def add_network(self, **kwargs):
        """
        Defines a new network.

        Usage:

            ======= ===============
            Method  URI
            ======= ===============
            POST    /vtep/networks
            ======= ===============

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X POST -d '{
             "vni": 10
             }' http://localhost:8080/vtep/networks | python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {},
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_network(**kwargs)
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 38
Project: workspace_2017   Author: nwiizo   File: rest_vtep.py    MIT License 4 votes vote down vote up
def get_network(self, **kwargs):
        """
        Gets the network for the specified VNI.

        Usage:

            ======= =====================
            Method  URI
            ======= =====================
            GET     /vtep/networks/{vni}
            ======= =====================

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X GET http://localhost:8080/vtep/networks/10 |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {
                            "aa:bb:cc:dd:ee:ff": {
                                "EvpnClient": {
                                    "ip": "10.0.0.1",
                                    "mac": "aa:bb:cc:dd:ee:ff",
                                    "next_hop": "172.17.0.1",
                                    "port": 1
                                }
                            }
                        },
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        return self._get_networks(**kwargs) 
Example 39
Project: workspace_2017   Author: nwiizo   File: rest_vtep.py    MIT License 4 votes vote down vote up
def del_network(self, **kwargs):
        """
        Deletes the network for the specified VNI.

        Usage:

            ======= =====================
            Method  URI
            ======= =====================
            DELETE  /vtep/networks/{vni}
            ======= =====================

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/networks/10 |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "ethernet_tag_id": 10,
                        "clients": [
                            {
                                "EvpnClient": {
                                    "ip": "10.0.0.11",
                                    "mac": "e2:b1:0c:ba:42:ed",
                                    "port": 1
                                }
                            }
                        ],
                        "route_dist": "65000:100",
                        "vni": 10
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_network(**kwargs)
        except (BGPSpeakerNotFound, DatapathNotFound, VniNotFound) as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 40
Project: workspace_2017   Author: nwiizo   File: rest_vtep.py    MIT License 4 votes vote down vote up
def del_client(self, **kwargs):
        """
        Registers a new client to the specified network.

        Usage:

            ======= ===================================
            Method  URI
            ======= ===================================
            DELETE  /vtep/networks/{vni}/clients/{mac}
            ======= ===================================

        Request parameters:

            =========== ===============================================
            Attribute   Description
            =========== ===============================================
            vni         Virtual Network Identifier. (e.g. 10)
            mac         Client MAC address to register.
            =========== ===============================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/networks/10/clients/aa:bb:cc:dd:ee:ff |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnClient": {
                        "ip": "10.0.0.1",
                        "mac": "aa:bb:cc:dd:ee:ff",
                        "next_hop": "172.17.0.1",
                        "port": 1
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_client(**kwargs)
        except (BGPSpeakerNotFound, DatapathNotFound,
                VniNotFound, ClientNotFound, ClientNotLocal) as e:
            return Response(body=str(e), status=500)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 41
Project: empower-ryu   Author: clicknf   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def add_speaker(self, **kwargs):
        """
        Creates a new BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            POST    /vtep/speakers
            ======= ================

        Request parameters:

            ========== ============================================
            Attribute  Description
            ========== ============================================
            dpid       ID of Datapath binding to speaker. (e.g. 1)
            as_number  AS number. (e.g. 65000)
            router_id  Router ID. (e.g. "172.17.0.1")
            ========== ============================================

        Example::

            $ curl -X POST -d '{
             "dpid": 1,
             "as_number": 65000,
             "router_id": "172.17.0.1"
             }' http://localhost:8080/vtep/speakers | python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {},
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_speaker(**kwargs)
        except DatapathNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 42
Project: empower-ryu   Author: clicknf   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def get_speakers(self, **kwargs):
        """
        Gets the info of BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            GET     /vtep/speakers
            ======= ================

        Example::

            $ curl -X GET http://localhost:8080/vtep/speakers |
             python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {
                            "172.17.0.2": {
                                "EvpnNeighbor": {
                                    "address": "172.17.0.2",
                                    "remote_as": 65000,
                                    "state": "up"
                                }
                            }
                        },
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.get_speaker()
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 43
Project: empower-ryu   Author: clicknf   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def add_neighbor(self, **kwargs):
        """
        Registers a new neighbor to the speaker.

        Usage:

            ======= ========================
            Method  URI
            ======= ========================
            POST    /vtep/neighbors
            ======= ========================

        Request parameters:

            ========== ================================================
            Attribute  Description
            ========== ================================================
            address    IP address of neighbor. (e.g. "172.17.0.2")
            remote_as  AS number of neighbor. (e.g. 65000)
            ========== ================================================

        Example::

            $ curl -X POST -d '{
             "address": "172.17.0.2",
             "remote_as": 65000
             }' http://localhost:8080/vtep/neighbors |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "down"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_neighbor(**kwargs)
        except BGPSpeakerNotFound as e:
            return e.to_response(status=400)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 44
Project: empower-ryu   Author: clicknf   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def del_neighbor(self, **kwargs):
        """
        Unregister the specified neighbor from the speaker.

        Usage:

            ======= ==================================
            Method  URI
            ======= ==================================
            DELETE  /vtep/speaker/neighbors/{address}
            ======= ==================================

        Request parameters:

            ========== ================================================
            Attribute  Description
            ========== ================================================
            address    IP address of neighbor. (e.g. "172.17.0.2")
            ========== ================================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/speaker/neighbors/172.17.0.2 |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "up"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_neighbor(**kwargs)
        except (BGPSpeakerNotFound, NeighborNotFound) as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 45
Project: empower-ryu   Author: clicknf   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def add_network(self, **kwargs):
        """
        Defines a new network.

        Usage:

            ======= ===============
            Method  URI
            ======= ===============
            POST    /vtep/networks
            ======= ===============

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X POST -d '{
             "vni": 10
             }' http://localhost:8080/vtep/networks | python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {},
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_network(**kwargs)
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 46
Project: empower-ryu   Author: clicknf   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def get_network(self, **kwargs):
        """
        Gets the network for the specified VNI.

        Usage:

            ======= =====================
            Method  URI
            ======= =====================
            GET     /vtep/networks/{vni}
            ======= =====================

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X GET http://localhost:8080/vtep/networks/10 |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {
                            "aa:bb:cc:dd:ee:ff": {
                                "EvpnClient": {
                                    "ip": "10.0.0.1",
                                    "mac": "aa:bb:cc:dd:ee:ff",
                                    "next_hop": "172.17.0.1",
                                    "port": 1
                                }
                            }
                        },
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        return self._get_networks(**kwargs) 
Example 47
Project: empower-ryu   Author: clicknf   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def del_network(self, **kwargs):
        """
        Deletes the network for the specified VNI.

        Usage:

            ======= =====================
            Method  URI
            ======= =====================
            DELETE  /vtep/networks/{vni}
            ======= =====================

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/networks/10 |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "ethernet_tag_id": 10,
                        "clients": [
                            {
                                "EvpnClient": {
                                    "ip": "10.0.0.11",
                                    "mac": "e2:b1:0c:ba:42:ed",
                                    "port": 1
                                }
                            }
                        ],
                        "route_dist": "65000:100",
                        "vni": 10
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_network(**kwargs)
        except (BGPSpeakerNotFound, DatapathNotFound, VniNotFound) as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 48
Project: empower-ryu   Author: clicknf   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def del_client(self, **kwargs):
        """
        Registers a new client to the specified network.

        Usage:

            ======= ===================================
            Method  URI
            ======= ===================================
            DELETE  /vtep/networks/{vni}/clients/{mac}
            ======= ===================================

        Request parameters:

            =========== ===============================================
            Attribute   Description
            =========== ===============================================
            vni         Virtual Network Identifier. (e.g. 10)
            mac         Client MAC address to register.
            =========== ===============================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/networks/10/clients/aa:bb:cc:dd:ee:ff |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnClient": {
                        "ip": "10.0.0.1",
                        "mac": "aa:bb:cc:dd:ee:ff",
                        "next_hop": "172.17.0.1",
                        "port": 1
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_client(**kwargs)
        except (BGPSpeakerNotFound, DatapathNotFound,
                VniNotFound, ClientNotFound, ClientNotLocal) as e:
            return Response(body=str(e), status=500)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 49
Project: SDN-QoS-Routing   Author: dodoyuan   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def add_speaker(self, **kwargs):
        """
        Creates a new BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            POST    /vtep/speakers
            ======= ================

        Request parameters:

            ========== ============================================
            Attribute  Description
            ========== ============================================
            dpid       ID of Datapath binding to speaker. (e.g. 1)
            as_number  AS number. (e.g. 65000)
            router_id  Router ID. (e.g. "172.17.0.1")
            ========== ============================================

        Example::

            $ curl -X POST -d '{
             "dpid": 1,
             "as_number": 65000,
             "router_id": "172.17.0.1"
             }' http://localhost:8080/vtep/speakers | python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {},
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_speaker(**kwargs)
        except DatapathNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 50
Project: SDN-QoS-Routing   Author: dodoyuan   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def get_speakers(self, **kwargs):
        """
        Gets the info of BGPSpeaker instance.

        Usage:

            ======= ================
            Method  URI
            ======= ================
            GET     /vtep/speakers
            ======= ================

        Example::

            $ curl -X GET http://localhost:8080/vtep/speakers |
             python -m json.tool

        ::

            {
                "172.17.0.1": {
                    "EvpnSpeaker": {
                        "as_number": 65000,
                        "dpid": 1,
                        "neighbors": {
                            "172.17.0.2": {
                                "EvpnNeighbor": {
                                    "address": "172.17.0.2",
                                    "remote_as": 65000,
                                    "state": "up"
                                }
                            }
                        },
                        "router_id": "172.17.0.1"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.get_speaker()
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 51
Project: SDN-QoS-Routing   Author: dodoyuan   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def add_neighbor(self, **kwargs):
        """
        Registers a new neighbor to the speaker.

        Usage:

            ======= ========================
            Method  URI
            ======= ========================
            POST    /vtep/neighbors
            ======= ========================

        Request parameters:

            ========== ================================================
            Attribute  Description
            ========== ================================================
            address    IP address of neighbor. (e.g. "172.17.0.2")
            remote_as  AS number of neighbor. (e.g. 65000)
            ========== ================================================

        Example::

            $ curl -X POST -d '{
             "address": "172.17.0.2",
             "remote_as": 65000
             }' http://localhost:8080/vtep/neighbors |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "down"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_neighbor(**kwargs)
        except BGPSpeakerNotFound as e:
            return e.to_response(status=400)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 52
Project: SDN-QoS-Routing   Author: dodoyuan   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def del_neighbor(self, **kwargs):
        """
        Unregister the specified neighbor from the speaker.

        Usage:

            ======= ==================================
            Method  URI
            ======= ==================================
            DELETE  /vtep/speaker/neighbors/{address}
            ======= ==================================

        Request parameters:

            ========== ================================================
            Attribute  Description
            ========== ================================================
            address    IP address of neighbor. (e.g. "172.17.0.2")
            ========== ================================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/speaker/neighbors/172.17.0.2 |
             python -m json.tool

        ::

            {
                "172.17.0.2": {
                    "EvpnNeighbor": {
                        "address": "172.17.0.2",
                        "remote_as": 65000,
                        "state": "up"
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_neighbor(**kwargs)
        except (BGPSpeakerNotFound, NeighborNotFound) as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 53
Project: SDN-QoS-Routing   Author: dodoyuan   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def add_network(self, **kwargs):
        """
        Defines a new network.

        Usage:

            ======= ===============
            Method  URI
            ======= ===============
            POST    /vtep/networks
            ======= ===============

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X POST -d '{
             "vni": 10
             }' http://localhost:8080/vtep/networks | python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {},
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        try:
            body = self.vtep_app.add_network(**kwargs)
        except BGPSpeakerNotFound as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 54
Project: SDN-QoS-Routing   Author: dodoyuan   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def get_network(self, **kwargs):
        """
        Gets the network for the specified VNI.

        Usage:

            ======= =====================
            Method  URI
            ======= =====================
            GET     /vtep/networks/{vni}
            ======= =====================

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X GET http://localhost:8080/vtep/networks/10 |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "clients": {
                            "aa:bb:cc:dd:ee:ff": {
                                "EvpnClient": {
                                    "ip": "10.0.0.1",
                                    "mac": "aa:bb:cc:dd:ee:ff",
                                    "next_hop": "172.17.0.1",
                                    "port": 1
                                }
                            }
                        },
                        "ethernet_tag_id": 0,
                        "route_dist": "65000:10",
                        "vni": 10
                    }
                }
            }
        """
        return self._get_networks(**kwargs) 
Example 55
Project: SDN-QoS-Routing   Author: dodoyuan   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def del_network(self, **kwargs):
        """
        Deletes the network for the specified VNI.

        Usage:

            ======= =====================
            Method  URI
            ======= =====================
            DELETE  /vtep/networks/{vni}
            ======= =====================

        Request parameters:

            ================ ========================================
            Attribute        Description
            ================ ========================================
            vni              Virtual Network Identifier. (e.g. 10)
            ================ ========================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/networks/10 |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnNetwork": {
                        "ethernet_tag_id": 10,
                        "clients": [
                            {
                                "EvpnClient": {
                                    "ip": "10.0.0.11",
                                    "mac": "e2:b1:0c:ba:42:ed",
                                    "port": 1
                                }
                            }
                        ],
                        "route_dist": "65000:100",
                        "vni": 10
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_network(**kwargs)
        except (BGPSpeakerNotFound, DatapathNotFound, VniNotFound) as e:
            return e.to_response(status=404)

        return Response(content_type='application/json',
                        body=json.dumps(body)) 
Example 56
Project: SDN-QoS-Routing   Author: dodoyuan   File: rest_vtep.py    Apache License 2.0 4 votes vote down vote up
def del_client(self, **kwargs):
        """
        Registers a new client to the specified network.

        Usage:

            ======= ===================================
            Method  URI
            ======= ===================================
            DELETE  /vtep/networks/{vni}/clients/{mac}
            ======= ===================================

        Request parameters:

            =========== ===============================================
            Attribute   Description
            =========== ===============================================
            vni         Virtual Network Identifier. (e.g. 10)
            mac         Client MAC address to register.
            =========== ===============================================

        Example::

            $ curl -X DELETE http://localhost:8080/vtep/networks/10/clients/aa:bb:cc:dd:ee:ff |
             python -m json.tool

        ::

            {
                "10": {
                    "EvpnClient": {
                        "ip": "10.0.0.1",
                        "mac": "aa:bb:cc:dd:ee:ff",
                        "next_hop": "172.17.0.1",
                        "port": 1
                    }
                }
            }
        """
        try:
            body = self.vtep_app.del_client(**kwargs)
        except (BGPSpeakerNotFound, DatapathNotFound,
                VniNotFound, ClientNotFound, ClientNotLocal) as e:
            return Response(body=str(e), status=500)

        return Response(content_type='application/json',
                        body=json.dumps(body))