Ejemplo n.º 1
0
 def _getPoolId(self, listener_id):
     """
     获取所有负载均衡器池id
     :param listener_id:
     :return: pool_id
     """
     command = "neutron lbaas-listener-show " + listener_id + " -f json"
     command = self._neutronInsertAuth(command)
     tmp_pool_id = subprocess.check_output(command, shell=True)
     tmp_pool_id = StrTool.getStringWithLBRB(
         tmp_pool_id, '{"Field": "default_pool_id", "Value": "', '"}')
     pool_id = tmp_pool_id.strip()
     if not pool_id:
         return None
     return pool_id
Ejemplo n.º 2
0
 def _getMemberId(self, pool_id):
     """
     获取所有负载均衡器后端服务器id
     :param pool_id:
     :return: member_ids
     """
     command = "neutron lbaas-pool-show " + pool_id + " -f json"
     command = self._neutronInsertAuth(command)
     tmp_member_ids = subprocess.check_output(command, shell=True)
     tmp_member_ids = StrTool.getStringWithLBRB(
         tmp_member_ids, '{"Field": "members", "Value": "', '"}')
     member_ids = []
     if not tmp_member_ids.strip():
         return member_ids
     member_ids = tmp_member_ids.split('\\n')
     return member_ids
Ejemplo n.º 3
0
 def _getHealthmonitorId(self, pool_id):
     """
     获取所有负载均衡器健康检测器id
     :param pool_id:
     :return: healthmonitor_id
     """
     command = "neutron lbaas-pool-show " + pool_id + " -f json"
     command = self._neutronInsertAuth(command)
     tmp_healthmonitor_id = subprocess.check_output(command, shell=True)
     tmp_healthmonitor_id = StrTool.getStringWithLBRB(
         tmp_healthmonitor_id, '{"Field": "healthmonitor_id", "Value": "',
         '"}')
     healthmonitor_id = tmp_healthmonitor_id.strip()
     if not healthmonitor_id:
         return None
     return healthmonitor_id
Ejemplo n.º 4
0
 def _getListenerId(self, loadbalancer_id):
     """
     获取负载均衡器listenerid
     :param loadbalancer_id:
     :return: listener_id
     """
     command = "neutron lbaas-loadbalancer-show " + loadbalancer_id + " -f json"
     command = self._neutronInsertAuth(command)
     tmp_listener_id = subprocess.check_output(command, shell=True)
     tmp_listener_id = StrTool.getStringWithLBRB(
         tmp_listener_id,
         '{"Field": "listeners", "Value": "{\\\\"id\\\\": \\\\"', '\\\\"}')
     listener_id = tmp_listener_id.strip()
     if not listener_id:
         return None
     return listener_id
Ejemplo n.º 5
0
 def getIp(self):
     """
     获取存储地址
     :return:
     """
     commad = "openstack endpoint show -f json `openstack  endpoint list | grep swift_s3 | grep public | awk {'print $2'}`"
     commad = self._authTool.insertAdminAuth(commad)
     try:
         tmp_ip = subprocess.check_output(commad, shell=True)
         tmp_ip = ujson.dumps(tmp_ip)
         ip = StrTool.getStringWithLBRB(tmp_ip, 'url\\\\": \\\\"http://',
                                        '\\\\",', 'all')
         ip = ip[0].strip()
         if not ip:
             return None
         return ip
     except Exception:
         return None
Ejemplo n.º 6
0
 def createLoadbalancer(self, lb_name, floatingip_id, subnet_id,
                        connection_limit, protocol, protocol_port,
                        lb_algorithmt, delay_time, max_retries, timeout,
                        protocol_type, instance_ips_weight):
     """
     创建负载均衡器
     :param lb_name:
     :param floatingip_id:
     :param subnet_id:
     :param connection_limit: 最大连接数,可选5000,10000,20000
     :param protocol: 协议,可选HTTP、TCP
     :param protocol_port: 端口,范围1-65535
     :param lb_algorithmt: 负载均衡方式,可选ROUND_ROBIN,LEAST_CONNECTIONS,SOURCE_IP
     :param delay_time: 间隔时间,范围2-60
     :param max_retries: 尝试次数,范围1-10
     :param timeout: 超时时间,范围5-300
     :param protocol_type: 健康检查方式,可选PING、HTTP
     :param instance_ips_weight: 数组[[云主机ip,weight],[云主机ip,weight]],weight范围1-10
     :return: loadbalancer_id
     """
     command = "neutron lbaas-loadbalancer-create --name " + lb_name + " --floatingip_id " + floatingip_id + " -f json"
     command = self._neutronInsertAuth(command)
     loadbalancer_id = subprocess.check_output(command, shell=True)
     loadbalancer_id = StrTool.getStringWithLBRB(
         loadbalancer_id, '{"Field": "id", "Value": "', '"}')
     loadbalancer_id = loadbalancer_id.strip()
     if not loadbalancer_id:
         return None
     self._addInterfaceForLoadbalancer(loadbalancer_id, subnet_id)
     listener_id = self._addListenerForLoadbalancer(lb_name,
                                                    loadbalancer_id,
                                                    connection_limit,
                                                    protocol, protocol_port)
     pool_id = self._addPoolForLoadbalancer(lb_name, listener_id, protocol,
                                            lb_algorithmt)
     self._addHealthmonitorForLoadbalancer(delay_time, max_retries, timeout,
                                           protocol_type, pool_id)
     for instance_ip_weight in instance_ips_weight:
         self.addMemberForLoadbalancer(subnet_id, instance_ip_weight[0],
                                       protocol_port, instance_ip_weight[1],
                                       pool_id)
     return loadbalancer_id
Ejemplo n.º 7
0
 def _addPoolForLoadbalancer(self, pool_name, listener_id, protocol,
                             lb_algorithmt):
     """
     为负载均衡器创建pool
     :param pool_name:
     :param listener_id:
     :param protocol:
     :param lb_algorithmt:
     :return: pool_id
     """
     command = "neutron lbaas-pool-create --name " + pool_name + " --listener " + listener_id + " --protocol " + protocol\
               + " --lb-algorithm " + lb_algorithmt + " -f json"
     command = self._neutronInsertAuth(command)
     pool_id = subprocess.check_output(command, shell=True)
     pool_id = StrTool.getStringWithLBRB(pool_id,
                                         '{"Field": "id", "Value": "', '"}')
     pool_id = pool_id.strip()
     if not pool_id:
         return None
     return pool_id
Ejemplo n.º 8
0
 def _addListenerForLoadbalancer(self, listener_name, loadbalancer_id,
                                 connection_limit, protocol, protocol_port):
     """
     为负载均衡器创建监听器
     :param listener_name:
     :param loadbalancer_id:
     :param connection_limit:
     :param protocol:
     :param protocol_port:
     :return: listener_id
     """
     command = "neutron lbaas-listener-create --name " + listener_name + " --loadbalancer " + loadbalancer_id + " --connection_limit "\
               + connection_limit + " --protocol " + protocol + " --protocol-port " + protocol_port + " -f json"
     command = self._neutronInsertAuth(command)
     listener_id = subprocess.check_output(command, shell=True)
     listener_id = StrTool.getStringWithLBRB(listener_id,
                                             '{"Field": "id", "Value": "',
                                             '"}')
     listener_id = listener_id.strip()
     if not listener_id:
         return None
     return listener_id