<s> from werkzeug . utils import cached_property <EOL> from base import db , Base <EOL> from cluster import Cluster <EOL> class Proxy ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> host = db . Column ( db . String ( <NUM_LIT:255> ) , nullable = False ) <EOL> port = db . Column ( db . Integer , nullable = False ) <EOL> eru_container_id = db . Column ( db . String ( <NUM_LIT:64> ) , index = True ) <EOL> cluster_id = db . Column ( db . ForeignKey ( Cluster . id ) , index = True ) <EOL> suppress_alert = db . Column ( db . Integer , nullable = False , default = <NUM_LIT:1> ) <EOL> __table_args__ = ( db . Index ( '<STR_LIT:address>' , '<STR_LIT:host>' , '<STR_LIT:port>' , unique = True ) , ) <EOL> @ cached_property <EOL> def eru_deployed ( self ) : <EOL> return self . eru_container_id is not None <EOL> @ cached_property <EOL> def eru_info ( self ) : <EOL> import eru_utils <EOL> if eru_utils . eru_client is None or not self . eru_deployed : <EOL> return None <EOL> return eru_utils . eru_client . get_container ( self . eru_container_id ) <EOL> @ cached_property <EOL> def cluster ( self ) : <EOL> return Cluster . query . get ( self . cluster_id ) <EOL> def get_by_host_port ( host , port ) : <EOL> return db . session . query ( Proxy ) . filter ( <EOL> Proxy . host == host , Proxy . port == port ) . first ( ) <EOL> def del_by_host_port ( host , port ) : <EOL> return db . session . query ( Proxy ) . filter ( <EOL> Proxy . host == host , Proxy . port == port ) . delete ( ) <EOL> def get_or_create ( host , port , cluster_id = None ) : <EOL> p = db . session . query ( Proxy ) . filter ( <EOL> Proxy . host == host , Proxy . port == port ) . first ( ) <EOL> if p is None : <EOL> p = Proxy ( host = host , port = port , cluster_id = cluster_id ) <EOL> db . session . add ( p ) <EOL> db . session . flush ( ) <EOL> return p <EOL> def create_eru_instance ( host , port , cluster_id , eru_container_id ) : <EOL> node = Proxy ( host = host , port = port , eru_container_id = eru_container_id , <EOL> cluster_id = cluster_id ) <EOL> db . session . add ( node ) <EOL> db . session . flush ( ) <EOL> return node <EOL> def delete_eru_instance ( eru_container_id ) : <EOL> db . session . query ( Proxy ) . filter ( <EOL> Proxy . eru_container_id == eru_container_id ) . delete ( ) <EOL> def get_eru_by_container_id ( eru_container_id ) : <EOL> return db . session . query ( Proxy ) . filter ( <EOL> Proxy . eru_container_id == eru_container_id ) . first ( ) <EOL> def list_all ( ) : <EOL> return db . session . query ( Proxy ) . all ( ) <EOL> def list_eru_proxies ( offset , limit ) : <EOL> return db . session . query ( Proxy ) . filter ( <EOL> Proxy . eru_container_id != None ) . order_by ( <EOL> Proxy . id . desc ( ) ) . offset ( offset ) . limit ( limit ) . all ( ) <EOL> def list_ip ( ) : <EOL> return db . session . query ( Proxy . host , Proxy . port ) . all ( ) </s>
