<s> from django . core . urlresolvers import reverse <EOL> from django import shortcuts <EOL> from django import template <EOL> from django . template import defaultfilters as filters <EOL> from django . utils import http <EOL> from django . utils . http import urlencode <EOL> from django . utils . translation import pgettext_lazy <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils . translation import ungettext_lazy <EOL> from horizon import conf <EOL> from horizon import exceptions <EOL> from horizon import messages <EOL> from horizon import tables <EOL> from openstack_dashboard import api <EOL> from openstack_dashboard . dashboards . project . access_and_security . floating_ips import workflows <EOL> from openstack_dashboard import policy <EOL> class AddPoolLink ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , ) <EOL> icon = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> class AddVipLink ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> classes = ( "<STR_LIT>" , ) <EOL> icon = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def get_link_url ( self , pool ) : <EOL> base_url = reverse ( "<STR_LIT>" , <EOL> kwargs = { '<STR_LIT>' : pool . id } ) <EOL> return base_url <EOL> def allowed ( self , request , datum = None ) : <EOL> if datum and datum . vip_id : <EOL> return False <EOL> return True <EOL> class AddMemberLink ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , ) <EOL> icon = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> class AddMonitorLink ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , ) <EOL> icon = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> class DeleteVipLink ( policy . PolicyTargetMixin , tables . Action ) : <EOL> name = "<STR_LIT>" <EOL> preempt = True <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> action_type = "<STR_LIT>" <EOL> def allowed ( self , request , datum = None ) : <EOL> if datum and datum . vip_id : <EOL> self . help_text = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % datum . vip_id <EOL> return True <EOL> return False <EOL> def single ( self , table , request , obj_id ) : <EOL> try : <EOL> vip_id = api . lbaas . pool_get ( request , obj_id ) . vip_id <EOL> except Exception as e : <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) <EOL> % e ) <EOL> if vip_id is not None : <EOL> try : <EOL> api . lbaas . vip_delete ( request , vip_id ) <EOL> messages . success ( request , _ ( '<STR_LIT>' ) % vip_id ) <EOL> except Exception as e : <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) % e ) <EOL> class DeletePoolLink ( policy . PolicyTargetMixin , tables . DeleteAction ) : <EOL> name = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> @ staticmethod <EOL> def action_present ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> @ staticmethod <EOL> def action_past ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> def allowed ( self , request , datum = None ) : <EOL> if datum and datum . vip_id : <EOL> return False <EOL> return True <EOL> def delete ( self , request , obj_id ) : <EOL> try : <EOL> api . lbaas . pool_delete ( request , obj_id ) <EOL> except Exception as e : <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) % e ) <EOL> class DeleteMonitorLink ( policy . PolicyTargetMixin , <EOL> tables . DeleteAction ) : <EOL> name = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> @ staticmethod <EOL> def action_present ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> @ staticmethod <EOL> def action_past ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> def delete ( self , request , obj_id ) : <EOL> try : <EOL> api . lbaas . pool_health_monitor_delete ( request , obj_id ) <EOL> except Exception as e : <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) % e ) <EOL> class DeleteMemberLink ( policy . PolicyTargetMixin , tables . DeleteAction ) : <EOL> name = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> @ staticmethod <EOL> def action_present ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> @ staticmethod <EOL> def action_past ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> def delete ( self , request , obj_id ) : <EOL> try : <EOL> api . lbaas . member_delete ( request , obj_id ) <EOL> except Exception as e : <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) % e ) <EOL> class UpdatePoolLink ( policy . PolicyTargetMixin , tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> classes = ( "<STR_LIT>" , "<STR_LIT>" , ) <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def get_link_url ( self , pool ) : <EOL> base_url = reverse ( "<STR_LIT>" , <EOL> kwargs = { '<STR_LIT>' : pool . id } ) <EOL> return base_url <EOL> class UpdateVipLink ( policy . PolicyTargetMixin , tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> classes = ( "<STR_LIT>" , "<STR_LIT>" , ) <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def get_link_url ( self , pool ) : <EOL> base_url = reverse ( "<STR_LIT>" , <EOL> kwargs = { '<STR_LIT>' : pool . vip_id } ) <EOL> return base_url <EOL> def allowed ( self , request , datum = None ) : <EOL> if datum and not datum . vip_id : <EOL> return False <EOL> return True <EOL> class UpdateMemberLink ( policy . PolicyTargetMixin , tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> classes = ( "<STR_LIT>" , "<STR_LIT>" , ) <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def get_link_url ( self , member ) : <EOL> base_url = reverse ( "<STR_LIT>" , <EOL> kwargs = { '<STR_LIT>' : member . id } ) <EOL> return base_url <EOL> class UpdateMonitorLink ( policy . PolicyTargetMixin , tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> classes = ( "<STR_LIT>" , "<STR_LIT>" , ) <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def get_link_url ( self , monitor ) : <EOL> base_url = reverse ( "<STR_LIT>" , <EOL> kwargs = { '<STR_LIT>' : monitor . id } ) <EOL> return base_url <EOL> class AddPMAssociationLink ( policy . PolicyTargetMixin , <EOL> tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , ) <EOL> icon = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def allowed ( self , request , datum = None ) : <EOL> try : <EOL> tenant_id = request . user . tenant_id <EOL> monitors = api . lbaas . pool_health_monitor_list ( request , <EOL> tenant_id = tenant_id ) <EOL> for m in monitors : <EOL> if m . id not in datum [ '<STR_LIT>' ] : <EOL> return True <EOL> except Exception : <EOL> exceptions . handle ( request , <EOL> _ ( '<STR_LIT>' ) ) <EOL> return False <EOL> class DeletePMAssociationLink ( policy . PolicyTargetMixin , <EOL> tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , ) <EOL> icon = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> action_type = "<STR_LIT>" <EOL> def allowed ( self , request , datum = None ) : <EOL> if datum and not datum [ '<STR_LIT>' ] : <EOL> return False <EOL> return True <EOL> class AddVIPFloatingIP ( policy . PolicyTargetMixin , tables . LinkAction ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> classes = ( "<STR_LIT>" , ) <EOL> icon = "<STR_LIT>" <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> def allowed ( self , request , pool ) : <EOL> if not api . network . floating_ip_supported ( request ) : <EOL> return False <EOL> if api . network . floating_ip_simple_associate_supported ( request ) : <EOL> return False <EOL> if hasattr ( pool , "<STR_LIT>" ) and pool . vip : <EOL> vip = pool . vip <EOL> return not ( hasattr ( vip , "<STR_LIT>" ) and vip . fip ) <EOL> return False <EOL> def get_link_url ( self , datum ) : <EOL> base_url = reverse ( self . url ) <EOL> next_url = self . table . get_full_url ( ) <EOL> params = { <EOL> workflows . IPAssociationWorkflow . redirect_param_name : next_url } <EOL> if hasattr ( datum , "<STR_LIT>" ) and datum . vip : <EOL> vip = datum . vip <EOL> params [ '<STR_LIT>' ] = vip . port_id <EOL> params = urlencode ( params ) <EOL> return "<STR_LIT:?>" . join ( [ base_url , params ] ) <EOL> class RemoveVIPFloatingIP ( policy . PolicyTargetMixin , tables . Action ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> preempt = True <EOL> icon = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> classes = ( "<STR_LIT>" , ) <EOL> policy_rules = ( ( "<STR_LIT>" , "<STR_LIT>" ) , ) <EOL> action_type = "<STR_LIT>" <EOL> def allowed ( self , request , pool ) : <EOL> if not api . network . floating_ip_supported ( request ) : <EOL> return False <EOL> if not conf . HORIZON_CONFIG [ "<STR_LIT>" ] : <EOL> return False <EOL> if hasattr ( pool , "<STR_LIT>" ) and pool . vip : <EOL> vip = pool . vip <EOL> self . help_text = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % vip . name <EOL> return hasattr ( vip , "<STR_LIT>" ) and vip . fip <EOL> return False <EOL> def single ( self , table , request , pool_id ) : <EOL> try : <EOL> pool = api . lbaas . pool_get ( request , pool_id ) <EOL> fips = api . network . tenant_floating_ip_list ( request ) <EOL> vip_fips = [ fip for fip in fips <EOL> if fip . port_id == pool . vip . port_id ] <EOL> if not vip_fips : <EOL> messages . info ( request , _ ( "<STR_LIT>" ) ) <EOL> else : <EOL> api . network . floating_ip_disassociate ( request , <EOL> vip_fips [ <NUM_LIT:0> ] . id ) <EOL> messages . success ( request , <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % fip . ip ) <EOL> except Exception : <EOL> exceptions . handle ( request , <EOL> _ ( "<STR_LIT>" ) ) <EOL> return shortcuts . redirect ( request . get_full_path ( ) ) <EOL> class UpdatePoolsRow ( tables . Row ) : <EOL> ajax = True <EOL> def get_data ( self , request , pool_id ) : <EOL> pool = api . lbaas . pool_get ( request , pool_id ) <EOL> try : <EOL> vip = api . lbaas . vip_get ( request , pool . vip_id ) <EOL> pool . vip = vip <EOL> except Exception : <EOL> pass <EOL> try : <EOL> subnet = api . neutron . subnet_get ( request , pool . subnet_id ) <EOL> pool . subnet_name = subnet . cidr <EOL> except Exception : <EOL> pool . subnet_name = pool . subnet_id <EOL> return pool <EOL> STATUS_CHOICES = ( <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , True ) , <EOL> ( "<STR_LIT>" , False ) , <EOL> ) <EOL> STATUS_DISPLAY_CHOICES = ( <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) , <EOL> ) <EOL> ADMIN_STATE_DISPLAY_CHOICES = ( <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , u"<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , u"<STR_LIT>" ) ) , <EOL> ) <EOL> def get_vip_name ( pool ) : <EOL> if hasattr ( pool , "<STR_LIT>" ) and pool . vip : <EOL> template_name = '<STR_LIT>' <EOL> context = { "<STR_LIT>" : pool . vip , } <EOL> return template . loader . render_to_string ( template_name , context ) <EOL> else : <EOL> return None <EOL> def get_subnet ( pool ) : <EOL> if hasattr ( pool , "<STR_LIT>" ) and pool . subnet : <EOL> template_name = '<STR_LIT>' <EOL> context = { "<STR_LIT>" : pool . subnet } <EOL> return template . loader . render_to_string ( template_name , context ) <EOL> else : <EOL> return None <EOL> class PoolsTable ( tables . DataTable ) : <EOL> METHOD_DISPLAY_CHOICES = ( <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) , <EOL> ( "<STR_LIT>" , pgettext_lazy ( "<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) , <EOL> ) <EOL> name = tables . Column ( "<STR_LIT>" , <EOL> verbose_name = _ ( "<STR_LIT:Name>" ) , <EOL> link = "<STR_LIT>" ) <EOL> description = tables . Column ( '<STR_LIT:description>' , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> provider = tables . Column ( '<STR_LIT>' , verbose_name = _ ( "<STR_LIT>" ) , <EOL> filters = ( lambda v : filters . default ( v , _ ( '<STR_LIT>' ) ) , ) ) <EOL> subnet_name = tables . Column ( get_subnet , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> protocol = tables . Column ( '<STR_LIT>' , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> method = tables . Column ( '<STR_LIT>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> display_choices = METHOD_DISPLAY_CHOICES ) <EOL> status = tables . Column ( '<STR_LIT:status>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> status = True , <EOL> status_choices = STATUS_CHOICES , <EOL> display_choices = STATUS_DISPLAY_CHOICES ) <EOL> vip_name = tables . Column ( get_vip_name , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> admin_state = tables . Column ( "<STR_LIT>" , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> display_choices = ADMIN_STATE_DISPLAY_CHOICES ) <EOL> class Meta ( object ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> status_columns = [ "<STR_LIT:status>" ] <EOL> row_class = UpdatePoolsRow <EOL> table_actions = ( AddPoolLink , DeletePoolLink ) <EOL> row_actions = ( UpdatePoolLink , AddVipLink , UpdateVipLink , <EOL> DeleteVipLink , AddPMAssociationLink , <EOL> DeletePMAssociationLink , DeletePoolLink , <EOL> AddVIPFloatingIP , RemoveVIPFloatingIP ) <EOL> def get_pool_link ( member ) : <EOL> return reverse ( "<STR_LIT>" , <EOL> args = ( http . urlquote ( member . pool_id ) , ) ) <EOL> def get_member_link ( member ) : <EOL> return reverse ( "<STR_LIT>" , <EOL> args = ( http . urlquote ( member . id ) , ) ) <EOL> class UpdateMemberRow ( tables . Row ) : <EOL> ajax = True <EOL> def get_data ( self , request , member_id ) : <EOL> member = api . lbaas . member_get ( request , member_id ) <EOL> try : <EOL> pool = api . lbaas . pool_get ( request , member . pool_id ) <EOL> member . pool_name = pool . name <EOL> except Exception : <EOL> member . pool_name = member . pool_id <EOL> return member <EOL> class MembersTable ( tables . DataTable ) : <EOL> address = tables . Column ( '<STR_LIT:address>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> link = get_member_link , <EOL> attrs = { '<STR_LIT>' : "<STR_LIT>" } ) <EOL> protocol_port = tables . Column ( '<STR_LIT>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) ) <EOL> weight = tables . Column ( '<STR_LIT>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) ) <EOL> pool_name = tables . Column ( '<STR_LIT>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) , link = get_pool_link ) <EOL> status = tables . Column ( '<STR_LIT:status>' , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> status = True , <EOL> status_choices = STATUS_CHOICES , <EOL> display_choices = STATUS_DISPLAY_CHOICES ) <EOL> admin_state = tables . Column ( "<STR_LIT>" , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> display_choices = ADMIN_STATE_DISPLAY_CHOICES ) <EOL> class Meta ( object ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> status_columns = [ "<STR_LIT:status>" ] <EOL> row_class = UpdateMemberRow <EOL> table_actions = ( AddMemberLink , DeleteMemberLink ) <EOL> row_actions = ( UpdateMemberLink , DeleteMemberLink ) <EOL> def get_monitor_details ( monitor ) : <EOL> if monitor . type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return ( "<STR_LIT>" % <EOL> { '<STR_LIT>' : monitor . http_method , <EOL> '<STR_LIT>' : monitor . url_path , <EOL> '<STR_LIT>' : monitor . expected_codes } ) <EOL> else : <EOL> return _ ( "<STR_LIT:->" ) <EOL> class MonitorsTable ( tables . DataTable ) : <EOL> monitor_type = tables . Column ( <EOL> "<STR_LIT:type>" , verbose_name = _ ( "<STR_LIT>" ) , <EOL> link = "<STR_LIT>" ) <EOL> delay = tables . Column ( "<STR_LIT>" , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> timeout = tables . Column ( "<STR_LIT>" , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> max_retries = tables . Column ( "<STR_LIT>" , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> details = tables . Column ( get_monitor_details , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> admin_state = tables . Column ( "<STR_LIT>" , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> display_choices = ADMIN_STATE_DISPLAY_CHOICES ) <EOL> class Meta ( object ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> table_actions = ( AddMonitorLink , DeleteMonitorLink ) <EOL> row_actions = ( UpdateMonitorLink , DeleteMonitorLink ) </s>
