<s> from neutron_lib import exceptions as n_exc <EOL> from oslo_config import cfg <EOL> from oslo_log import log <EOL> import sqlalchemy as sa <EOL> from sqlalchemy import sql <EOL> from neutron . _i18n import _ , _LE <EOL> from neutron . db import model_base <EOL> from neutron . plugins . common import constants as p_const <EOL> from neutron . plugins . ml2 . drivers import type_tunnel <EOL> LOG = log . getLogger ( __name__ ) <EOL> gre_opts = [ <EOL> cfg . ListOpt ( '<STR_LIT>' , <EOL> default = [ ] , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> ] <EOL> cfg . CONF . register_opts ( gre_opts , "<STR_LIT>" ) <EOL> class GreAllocation ( model_base . BASEV2 ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> gre_id = sa . Column ( sa . Integer , nullable = False , primary_key = True , <EOL> autoincrement = False ) <EOL> allocated = sa . Column ( sa . Boolean , nullable = False , default = False , <EOL> server_default = sql . false ( ) , index = True ) <EOL> class GreEndpoints ( model_base . BASEV2 ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> __table_args__ = ( <EOL> sa . UniqueConstraint ( '<STR_LIT:host>' , <EOL> name = '<STR_LIT>' ) , <EOL> model_base . BASEV2 . __table_args__ <EOL> ) <EOL> ip_address = sa . Column ( sa . String ( <NUM_LIT:64> ) , primary_key = True ) <EOL> host = sa . Column ( sa . String ( <NUM_LIT:255> ) , nullable = True ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . ip_address <EOL> class GreTypeDriver ( type_tunnel . EndpointTunnelTypeDriver ) : <EOL> def __init__ ( self ) : <EOL> super ( GreTypeDriver , self ) . __init__ ( <EOL> GreAllocation , GreEndpoints ) <EOL> def get_type ( self ) : <EOL> return p_const . TYPE_GRE <EOL> def initialize ( self ) : <EOL> try : <EOL> self . _initialize ( cfg . CONF . ml2_type_gre . tunnel_id_ranges ) <EOL> except n_exc . NetworkTunnelRangeError : <EOL> LOG . exception ( _LE ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> raise SystemExit ( ) <EOL> def get_endpoints ( self ) : <EOL> """<STR_LIT>""" <EOL> gre_endpoints = self . _get_endpoints ( ) <EOL> return [ { '<STR_LIT>' : gre_endpoint . ip_address , <EOL> '<STR_LIT:host>' : gre_endpoint . host } <EOL> for gre_endpoint in gre_endpoints ] <EOL> def add_endpoint ( self , ip , host ) : <EOL> return self . _add_endpoint ( ip , host ) <EOL> def get_mtu ( self , physical_network = None ) : <EOL> mtu = super ( GreTypeDriver , self ) . get_mtu ( physical_network ) <EOL> return mtu - p_const . GRE_ENCAP_OVERHEAD if mtu else <NUM_LIT:0> </s>
