Devices API

The chapter9_6.py file starts with the necessary imports. Note that the following request import is the request object from the client and not the requests package that we were using in the previous chapters:

from flask import Flask, url_for, jsonify, requestfrom flask_sqlalchemy import SQLAlchemy# The following is deprecated but still used in some examples# from flask.ext.sqlalchemy import SQLAlchemy

We declared a database object with its id as the primary key and string fields for hostname, loopback, mgmt_ip, role, vendor, and os:

class Device(db.Model):    __tablename__ = 'devices'    id = db.Column(db.Integer, primary_key=True)    hostname = db.Column(db.String(64), unique=True)    loopback = db.Column(db.String(120), unique=True) mgmt_ip ...

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.