Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/pyroute2/ndb/__pycache__/schema.cpython-39.pyc
Ðазад
a ]�h,� � @ s d Z ddlZddlZddlZddlZddlZddlZddlZddlm Z ddl mZ ddlm Z ddlmZmZ ddlmZmZmZmZmZmZ zddlZW n ey� dZY n0 eeeeeegad ZG d d� dej�Zdd � ZG dd� de�Z G dd� d�Z!dS )a� Backends -------- NDB stores all the records in an SQL database. By default it uses the SQLite3 module, which is a part of the Python stdlib, so no extra packages are required:: # SQLite3 -- simple in-memory DB ndb = NDB() # SQLite3 -- same as above with explicit arguments ndb = NDB(db_provider='sqlite3', db_spec=':memory:') # SQLite3 -- file DB ndb = NDB(db_provider='sqlite3', db_spec='test.db') It is also possible to use a PostgreSQL database via psycopg2 module:: # PostgreSQL -- local DB ndb = NDB(db_provider='psycopg2', db_spec={'dbname': 'test'}) # PostgreSQL -- remote DB ndb = NDB(db_provider='psycopg2', db_spec={'dbname': 'test', 'host': 'db1.example.com'}) Database backup --------------- Built-in database backup is implemented now only for SQLite3 backend. For the PostgresSQL backend you have to use external utilities like `pg_dump`:: # create an NDB instance ndb = NDB() # the defaults: db_provider='sqlite3', db_spec=':memory:' ... # dump the DB to a file ndb.backup('backup.db') SQL schema ---------- By default NDB deletes the data from the DB upon exit. In order to preserve the data, use `NDB(db_cleanup=False, ...)` Here is an example schema (may be changed with releases):: List of relations Schema | Name | Type | Owner --------+------------------+-------+------- public | addresses | table | root public | af_bridge_fdb | table | root public | af_bridge_ifs | table | root public | af_bridge_vlans | table | root public | enc_mpls | table | root public | ifinfo_bond | table | root public | ifinfo_bridge | table | root public | ifinfo_gre | table | root public | ifinfo_gretap | table | root public | ifinfo_ip6gre | table | root public | ifinfo_ip6gretap | table | root public | ifinfo_ip6tnl | table | root public | ifinfo_ipip | table | root public | ifinfo_ipvlan | table | root public | ifinfo_macvlan | table | root public | ifinfo_macvtap | table | root public | ifinfo_sit | table | root public | ifinfo_tun | table | root public | ifinfo_vlan | table | root public | ifinfo_vrf | table | root public | ifinfo_vti | table | root public | ifinfo_vti6 | table | root public | ifinfo_vxlan | table | root public | interfaces | table | root public | metrics | table | root public | neighbours | table | root public | netns | table | root public | nh | table | root public | p2p | table | root public | routes | table | root public | rules | table | root public | sources | table | root public | sources_options | table | root (33 rows) rtnl=# select f_index, f_ifla_ifname from interfaces; f_index | f_ifla_ifname ---------+--------------- 1 | lo 2 | eth0 28 | ip_vti0 31 | ip6tnl0 32 | ip6_vti0 36445 | br0 11434 | dummy0 3 | eth1 (8 rows) rtnl=# select f_index, f_ifla_br_stp_state from ifinfo_bridge; f_index | f_ifla_br_stp_state ---------+--------------------- 36445 | 0 (1 row) Database upgrade ---------------- There is no DB schema upgrade from release to release. All the data stored in the DB is being fetched from the OS in the runtime, thus no persistence required. If you're using a PostgreSQL DB or a file based SQLite, simply drop all the tables from the DB, and NDB will create them from scratch on startup. � N)�OrderedDict)�partial)�config)� basestring�uuid32� )�address� interface� neighbour�netns�route�rule� c @ s e Zd ZdZdZdd� ZdS )� DBProvider�sqlite3�psycopg2c C s t | �|kS �N��str)�self�r� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/pyroute2/ndb/schema.py�__eq__� s zDBProvider.__eq__N)�__name__� __module__�__qualname__r r r r r r r r � s r c s$ t � t�r� fdd�}|S d� _� S )Nc s � | _ | S r )�publish)�m��fr r �decorate� s zpublish.<locals>.decorateT)� isinstancer r )r r! r r r r � s r c @ sh e Zd Zdd� Zed�dd� �Zed�dd� �Zed �d d� �Zedd � �Zedd� �Z edd� �Z dS )�DBDictc C s || _ || _d S r )�schema�table)r r$ r% r r r �__init__� s zDBDict.__init__�getc C sL | j �d| j� d| j j� d�|f�D ]\}t�|� S td|� d���d S )Nz! SELECT f_value FROM � WHERE f_key = � zkey z not found)r$ �fetchr% �plch�json�loads�KeyError)r �key�recordr r r �__getitem__� s ��� zDBDict.__getitem__�setc C s@ | |= | j �d| j� d| j j� d| j j� d�|t�|�f� d S )Nz INSERT INTO z VALUES (z, z) )r$ �executer% r+ r, �dumps�r r/ �valuer r r �__setitem__� s ����zDBDict.__setitem__�delc C s( | j �d| j� d| j j� d�|f� d S )Nz DELETE FROM r( r) )r$ r3 r% r+ �r r/ r r r �__delitem__� s ���zDBDict.__delitem__c c s&