<s> from __future__ import absolute_import <EOL> from collections import OrderedDict <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from horizon import messages <EOL> from openstack_dashboard . api import neutron <EOL> neutronclient = neutron . neutronclient <EOL> class Vip ( neutron . NeutronAPIDictWrapper ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , apiresource ) : <EOL> super ( Vip , self ) . __init__ ( apiresource ) <EOL> class Pool ( neutron . NeutronAPIDictWrapper ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , apiresource ) : <EOL> if '<STR_LIT>' not in apiresource : <EOL> apiresource [ '<STR_LIT>' ] = None <EOL> apiresource [ '<STR_LIT>' ] = '<STR_LIT>' if apiresource [ '<STR_LIT>' ] else '<STR_LIT>' <EOL> super ( Pool , self ) . __init__ ( apiresource ) <EOL> class Member ( neutron . NeutronAPIDictWrapper ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , apiresource ) : <EOL> apiresource [ '<STR_LIT>' ] = '<STR_LIT>' if apiresource [ '<STR_LIT>' ] else '<STR_LIT>' <EOL> super ( Member , self ) . __init__ ( apiresource ) <EOL> class PoolStats ( neutron . NeutronAPIDictWrapper ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , apiresource ) : <EOL> super ( PoolStats , self ) . __init__ ( apiresource ) <EOL> class PoolMonitor ( neutron . NeutronAPIDictWrapper ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , apiresource ) : <EOL> apiresource [ '<STR_LIT>' ] = '<STR_LIT>' if apiresource [ '<STR_LIT>' ] else '<STR_LIT>' <EOL> super ( PoolMonitor , self ) . __init__ ( apiresource ) <EOL> def vip_create ( request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> body = { '<STR_LIT>' : { '<STR_LIT:name>' : kwargs [ '<STR_LIT:name>' ] , <EOL> '<STR_LIT:description>' : kwargs [ '<STR_LIT:description>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] <EOL> } } <EOL> if kwargs . get ( '<STR_LIT>' ) : <EOL> body [ '<STR_LIT>' ] [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] <EOL> if kwargs . get ( '<STR_LIT:address>' ) : <EOL> body [ '<STR_LIT>' ] [ '<STR_LIT:address>' ] = kwargs [ '<STR_LIT:address>' ] <EOL> vip = neutronclient ( request ) . create_vip ( body ) . get ( '<STR_LIT>' ) <EOL> return Vip ( vip ) <EOL> def vip_list ( request , ** kwargs ) : <EOL> vips = neutronclient ( request ) . list_vips ( ** kwargs ) . get ( '<STR_LIT>' ) <EOL> return [ Vip ( v ) for v in vips ] <EOL> def vip_get ( request , vip_id ) : <EOL> return _vip_get ( request , vip_id , expand_resource = True ) <EOL> def _vip_get ( request , vip_id , expand_resource = False ) : <EOL> vip = neutronclient ( request ) . show_vip ( vip_id ) . get ( '<STR_LIT>' ) <EOL> if expand_resource : <EOL> vip [ '<STR_LIT>' ] = neutron . subnet_get ( request , vip [ '<STR_LIT>' ] ) <EOL> vip [ '<STR_LIT:port>' ] = neutron . port_get ( request , vip [ '<STR_LIT>' ] ) <EOL> vip [ '<STR_LIT>' ] = _pool_get ( request , vip [ '<STR_LIT>' ] ) <EOL> return Vip ( vip ) <EOL> def vip_update ( request , vip_id , ** kwargs ) : <EOL> vip = neutronclient ( request ) . update_vip ( vip_id , kwargs ) . get ( '<STR_LIT>' ) <EOL> return Vip ( vip ) <EOL> def vip_delete ( request , vip_id ) : <EOL> neutronclient ( request ) . delete_vip ( vip_id ) <EOL> def pool_create ( request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> body = { '<STR_LIT>' : { '<STR_LIT:name>' : kwargs [ '<STR_LIT:name>' ] , <EOL> '<STR_LIT:description>' : kwargs [ '<STR_LIT:description>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> } } <EOL> pool = neutronclient ( request ) . create_pool ( body ) . get ( '<STR_LIT>' ) <EOL> return Pool ( pool ) <EOL> def _get_vip ( request , pool , vip_dict ) : <EOL> if pool [ '<STR_LIT>' ] is not None : <EOL> try : <EOL> if vip_dict : <EOL> vip = vip_dict . get ( pool [ '<STR_LIT>' ] ) <EOL> else : <EOL> vip = _vip_get ( request , pool [ '<STR_LIT>' ] ) <EOL> except Exception : <EOL> messages . warning ( request , _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % { "<STR_LIT>" : pool [ "<STR_LIT:id>" ] } ) <EOL> vip = Vip ( { '<STR_LIT:id>' : pool [ '<STR_LIT>' ] , '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> return vip <EOL> else : <EOL> return None <EOL> def pool_list ( request , ** kwargs ) : <EOL> return _pool_list ( request , expand_subnet = True , expand_vip = True , ** kwargs ) <EOL> def _pool_list ( request , expand_subnet = False , expand_vip = False , ** kwargs ) : <EOL> pools = neutronclient ( request ) . list_pools ( ** kwargs ) . get ( '<STR_LIT>' ) <EOL> if expand_subnet : <EOL> subnets = neutron . subnet_list ( request ) <EOL> subnet_dict = OrderedDict ( ( s . id , s ) for s in subnets ) <EOL> for p in pools : <EOL> p [ '<STR_LIT>' ] = subnet_dict . get ( p [ '<STR_LIT>' ] ) <EOL> if expand_vip : <EOL> vips = vip_list ( request ) <EOL> vip_dict = OrderedDict ( ( v . id , v ) for v in vips ) <EOL> for p in pools : <EOL> p [ '<STR_LIT>' ] = _get_vip ( request , p , vip_dict ) <EOL> return [ Pool ( p ) for p in pools ] <EOL> def pool_get ( request , pool_id ) : <EOL> return _pool_get ( request , pool_id , expand_resource = True ) <EOL> def _pool_get ( request , pool_id , expand_resource = False ) : <EOL> try : <EOL> pool = neutronclient ( request ) . show_pool ( pool_id ) . get ( '<STR_LIT>' ) <EOL> except Exception : <EOL> messages . warning ( request , _ ( "<STR_LIT>" ) ) <EOL> return None <EOL> if expand_resource : <EOL> try : <EOL> pool [ '<STR_LIT>' ] = neutron . subnet_get ( request , pool [ '<STR_LIT>' ] ) <EOL> except Exception : <EOL> messages . warning ( request , _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % { "<STR_LIT>" : pool_id } ) <EOL> pool [ '<STR_LIT>' ] = _get_vip ( request , pool , vip_dict = None ) <EOL> if pool [ '<STR_LIT>' ] : <EOL> try : <EOL> pool [ '<STR_LIT>' ] = _member_list ( request , expand_pool = False , <EOL> pool_id = pool_id ) <EOL> except Exception : <EOL> messages . warning ( request , _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % { "<STR_LIT>" : pool_id } ) <EOL> if pool [ '<STR_LIT>' ] : <EOL> monitors = [ ] <EOL> for monitor_id in pool [ '<STR_LIT>' ] : <EOL> try : <EOL> monitors . append ( _pool_health_monitor_get ( request , <EOL> monitor_id , <EOL> False ) ) <EOL> except Exception : <EOL> messages . warning ( request , <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> % { "<STR_LIT>" : pool_id , <EOL> "<STR_LIT>" : monitor_id } ) <EOL> pool [ '<STR_LIT>' ] = monitors <EOL> return Pool ( pool ) <EOL> def pool_update ( request , pool_id , ** kwargs ) : <EOL> pool = neutronclient ( request ) . update_pool ( pool_id , kwargs ) . get ( '<STR_LIT>' ) <EOL> return Pool ( pool ) <EOL> def pool_delete ( request , pool ) : <EOL> neutronclient ( request ) . delete_pool ( pool ) <EOL> def pool_stats ( request , pool_id , ** kwargs ) : <EOL> stats = neutronclient ( request ) . retrieve_pool_stats ( pool_id , ** kwargs ) <EOL> return PoolStats ( stats ) <EOL> def pool_health_monitor_create ( request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> monitor_type = kwargs [ '<STR_LIT:type>' ] . upper ( ) <EOL> body = { '<STR_LIT>' : { '<STR_LIT:type>' : monitor_type , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] <EOL> } } <EOL> if monitor_type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> body [ '<STR_LIT>' ] [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] <EOL> body [ '<STR_LIT>' ] [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] <EOL> body [ '<STR_LIT>' ] [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] <EOL> mon = neutronclient ( request ) . create_health_monitor ( body ) . get ( <EOL> '<STR_LIT>' ) <EOL> return PoolMonitor ( mon ) <EOL> def pool_health_monitor_list ( request , ** kwargs ) : <EOL> monitors = neutronclient ( request ) . list_health_monitors ( <EOL> ** kwargs ) . get ( '<STR_LIT>' ) <EOL> return [ PoolMonitor ( m ) for m in monitors ] <EOL> def pool_health_monitor_get ( request , monitor_id ) : <EOL> return _pool_health_monitor_get ( request , monitor_id , expand_resource = True ) <EOL> def _pool_health_monitor_get ( request , monitor_id , expand_resource = False ) : <EOL> monitor = neutronclient ( request <EOL> ) . show_health_monitor ( monitor_id <EOL> ) . get ( '<STR_LIT>' ) <EOL> if expand_resource : <EOL> pool_ids = [ p [ '<STR_LIT>' ] for p in monitor [ '<STR_LIT>' ] ] <EOL> if pool_ids : <EOL> monitor [ '<STR_LIT>' ] = _pool_list ( request , id = pool_ids ) <EOL> return PoolMonitor ( monitor ) <EOL> def pool_health_monitor_update ( request , monitor_id , ** kwargs ) : <EOL> monitor = neutronclient ( request <EOL> ) . update_health_monitor ( monitor_id , kwargs <EOL> ) . get ( '<STR_LIT>' ) <EOL> return PoolMonitor ( monitor ) <EOL> def pool_health_monitor_delete ( request , mon_id ) : <EOL> neutronclient ( request ) . delete_health_monitor ( mon_id ) <EOL> def member_create ( request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> body = { '<STR_LIT>' : { '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT:address>' : kwargs [ '<STR_LIT:address>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : kwargs [ '<STR_LIT>' ] <EOL> } } <EOL> if kwargs . get ( '<STR_LIT>' ) : <EOL> body [ '<STR_LIT>' ] [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] <EOL> member = neutronclient ( request ) . create_member ( body ) . get ( '<STR_LIT>' ) <EOL> return Member ( member ) <EOL> def member_list ( request , ** kwargs ) : <EOL> return _member_list ( request , expand_pool = True , ** kwargs ) <EOL> def _member_list ( request , expand_pool , ** kwargs ) : <EOL> members = neutronclient ( request ) . list_members ( ** kwargs ) . get ( '<STR_LIT>' ) <EOL> if expand_pool : <EOL> pools = _pool_list ( request ) <EOL> pool_dict = OrderedDict ( ( p . id , p ) for p in pools ) <EOL> for m in members : <EOL> m [ '<STR_LIT>' ] = pool_dict . get ( m [ '<STR_LIT>' ] ) . name_or_id <EOL> return [ Member ( m ) for m in members ] <EOL> def member_get ( request , member_id ) : <EOL> return _member_get ( request , member_id , expand_pool = True ) <EOL> def _member_get ( request , member_id , expand_pool ) : <EOL> member = neutronclient ( request ) . show_member ( member_id ) . get ( '<STR_LIT>' ) <EOL> if expand_pool : <EOL> member [ '<STR_LIT>' ] = _pool_get ( request , member [ '<STR_LIT>' ] ) <EOL> return Member ( member ) <EOL> def member_update ( request , member_id , ** kwargs ) : <EOL> member = neutronclient ( request ) . update_member ( member_id , kwargs <EOL> ) . get ( '<STR_LIT>' ) <EOL> return Member ( member ) <EOL> def member_delete ( request , mem_id ) : <EOL> neutronclient ( request ) . delete_member ( mem_id ) <EOL> def pool_monitor_association_create ( request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> body = { '<STR_LIT>' : { '<STR_LIT:id>' : kwargs [ '<STR_LIT>' ] , } } <EOL> neutronclient ( request ) . associate_health_monitor ( <EOL> kwargs [ '<STR_LIT>' ] , body ) <EOL> def pool_monitor_association_delete ( request , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> neutronclient ( request ) . disassociate_health_monitor ( <EOL> kwargs [ '<STR_LIT>' ] , kwargs [ '<STR_LIT>' ] ) </s>
