def create_load_balancer_listener()

in footmark/slb/connection.py [0:0]


    def create_load_balancer_listener(self, load_balancer_id,\
                                            protocol,\
                                            listener_port,\
                                            backend_server_port,\
                                            bandwidth=None,\
                                            sticky_session='',\
                                            health_check='',\
                                            scheduler='',\
                                            sticky_session_type='',\
                                            cookie_timeout=None,\
                                            cookie='',\
                                            health_check_domain='',\
                                            health_check_uri='',\
                                            health_check_connect_port=None,\
                                            healthy_threshold=None,\
                                            unhealthy_threshold=None,\
                                            health_check_timeout=None,\
                                            health_check_interval=None,\
                                            health_check_http_code='',\
                                            vserver_group_id='',\
                                            gzip='',\
                                            server_certificate_id='',\
                                            master_slave_server_group_id='',\
                                            persistence_timeout=None,\
                                            health_check_connect_timeout=None,\
                                            xforwarded_for = 'on',\
                                            ca_certificate_id=''):
        """
        Create HTTP Listener; create Listeners based on the HTTP protocol for the Server Load Balancer instance,
        including policies and health check configurations based on the HTTP protocol
        :type load_balancer_id: string
        :param load_balancer_id: load balance id
        :type listener_port: int
        :param listener_port: Server Load Balancer instance frontend port. Value: 1-65535
        :type backend_server_port: int
        :param backend_server_port: Server Load Balancer instance backend port. Value: 1-65535
        :type bandwidth: int
        :param bandwidth: Listener bandwidth. Value: -1 / 1-1000 Mbps
        :type sticky_session: string
        :param sticky_session: Whether to open the Gzip compression
        :type protocol: string
        :param protocol: type of listener to create
        :type health_check: string
        :param health_check: Whether to enable health check
        :type health_check: string
        :param health_check: Whether to enable health check
        :type: scheduler: string
        :param: scheduler: Scheduling algorithm. Value: wrr / wlc / rr Default value: wrr
        :type: sticky_session_type: string
        :param: sticky_session_type: Mode for handling the cookie.
        :type: cookie_timeout: int
        :param: cookie_timeout: Cookie timeout.
        :type: cookie: string
        :param: cookie: The cookie configured on the server
        :type: health_check_domain: string
        :param: health_check_domain: Domain name used for health check.
        :type: health_check_uri: string
        :param: health_check_uri: URI used for health check
        :type: health_check_connect_port: int
        :param: health_check_connect_port: Port used for health check.
        :type: healthy_threshold: int
        :param: healthy_threshold: Threshold determining the result of the health check is success.
        :type: unhealthy_threshold: int
        :param: unhealthy_threshold: Threshold determining the result of the health check is fail. 
        :type: health_check_timeout: int
        :param: health_check_timeout: Maximum timeout of each health check response. 
        :type: health_check_http_code: string
        :param: health_check_http_code: Regular health check HTTP status code. Multiple codes are segmented by ",".
        :type: health_check_interval: int
        :param: health_check_interval: Time interval of health checks.
        :type: vserver_group_id: string
        :param: vserver_group_id: Virtual server group ID.
        :type: gzip: string
        :param: gzip: whether open Gzip compression
        :type: server_certificate_id: string
        :param: server_certificate_id: Server certificate ID.
        :type: master_slave_server_group_id: string
        :param: master_slave_server_group_id: Master standby server group ID
        :type: persistence_timeout: string
        :param: persistence_timeout: Timeout time for connection persistence.
        :type: health_check_connect_timeout: int
        :param: health_check_connect_timeout: Health check connection timeout.
        :type: xforwarded_for: int
        :param: xforwarded_for: Whether open access to the actual IP of visitors through X-Forwarded-For
        :type: ca_certificate_id: string
        :param: ca_certificate_id: CA certificate ID
        :return: returns request status
        """

        params = {}
        results = []
        changed = False
        listener_type_dic = dict(http="CreateLoadBalancerHTTPListener",\
                                 https= "CreateLoadBalancerHTTPSListener",\
                                 tcp="CreateLoadBalancerTCPListener",\
                                 udp="CreateLoadBalancerUDPListener")
        key = listener_type_dic.get(protocol, '')

        self.build_list_params(params, load_balancer_id, 'LoadBalancerId')
        self.build_list_params(params, listener_port, 'ListenerPort')
        self.build_list_params(params, backend_server_port, 'BackendServerPort')
        if bandwidth:
            self.build_list_params(params, bandwidth, 'Bandwidth')
        if sticky_session:
            self.build_list_params(params, sticky_session, 'StickySession')
        if health_check:
            self.build_list_params(params, health_check, 'HealthCheck')
        if scheduler:
            self.build_list_params(params, scheduler, 'Scheduler')
        if gzip:
            self.build_list_params(params, gzip, 'Gzip')
        if server_certificate_id:
            self.build_list_params(params, server_certificate_id, 'ServerCertificateId')
        if xforwarded_for:
            self.build_list_params(params, 'on', 'XForwardedFor')
        if sticky_session_type:
            self.build_list_params(params, sticky_session_type, 'StickySessionType')
        if cookie_timeout:
            self.build_list_params(params, cookie_timeout, 'CookieTimeout')
        if cookie:
            self.build_list_params(params, cookie, 'Cookie')
        if health_check_domain:
            self.build_list_params(params, health_check_domain, 'HealthCheckDomain')
        if health_check_uri:
            self.build_list_params(params, health_check_uri, 'HealthCheckURI')
        if health_check_connect_port:
            self.build_list_params(params, health_check_connect_port, 'HealthCheckConnectPort')
        if healthy_threshold:
            self.build_list_params(params, healthy_threshold, 'HealthyThreshold')
        if unhealthy_threshold:
            self.build_list_params(params, unhealthy_threshold, 'UnhealthyThreshold')
        if health_check_timeout:
            self.build_list_params(params, health_check_timeout, 'HealthCheckTimeout')
        if health_check_interval:
            self.build_list_params(params, health_check_interval, 'HealthCheckInterval')
        if health_check_http_code:
            self.build_list_params(params, health_check_http_code, 'HealthCheckHttpCode')
        if vserver_group_id:
            self.build_list_params(params, vserver_group_id, 'VServerGroupId')
        if master_slave_server_group_id:
            self.build_list_params(params, master_slave_server_group_id, 'MasterSlaveServerGroupId')
        if persistence_timeout:
            self.build_list_params(params, persistence_timeout, 'PersistenceTimeout')
        if health_check_connect_timeout:
            self.build_list_params(params, health_check_connect_timeout, 'HealthCheckConnectTimeout')
        if ca_certificate_id:
            self.build_list_params(params, ca_certificate_id, 'CACertificateId')

        if self.get_status(key, params):
            return self.start_load_balancer_listener(load_balancer_id, listener_port)
        return False