LB-createLB整理架构图-loadbalancer-openstack F版
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                LB-createLB整理架构图-loadbalancer-openstack F版
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                2019獨角獸企業(yè)重金招聘Python工程師標準>>>
感謝朋友支持本博客,歡迎共同探討交流,由于能力和時間有限,錯誤之處在所難免,歡迎指正!
 如有轉(zhuǎn)載,請保留源作者博客信息。
如需交流,歡迎大家博客留言。
1、第1層 根據(jù): mapper.resource("loadbalancer", "loadbalancers", member={'details': 'GET'}, controller=lb_resource, collection={'detail': 'GET'})self._list()對應底層的index()函數(shù) self._create()對應底層的create()函數(shù) self._delete()對應底層的delete()函數(shù) self._get()對應底層的show()函數(shù)
由上圖對應關(guān)系我們可以知道create()函數(shù)的webservice發(fā)布為: return self._create("/loadbalancers", body, "loadbalancer") 接著就自動調(diào)用balancer里面的: @utils.http_success_code(202) def create(self, req, body): LOG.debug("Got create request. Request: %s", req) #here we need to decide which device should be used params = body.copy()#將參數(shù)復制 LOG.debug("Headers: %s", req.headers) # We need to create LB object and return its id tenant_id = req.headers.get('X-Tenant-Id', "") params['tenant_id'] = tenant_id#參數(shù)列表中獲取tenant_id lb_id = core_api.create_lb(self.conf, params) #跟進到1.1層 return {'loadbalancer': {'id': lb_id}}#返回一個包含lb_id的字典列表
2、第1.1層、
def create_lb(conf, params): nodes = params.pop('nodes', [])#獲取nodes參數(shù)列表,其詳細內(nèi)容,參考下面注解 probes = params.pop('healthMonitor', [])#獲取監(jiān)測檢查的參數(shù)列表,其詳細內(nèi)容,參考下面注解 vips = params.pop('virtualIps', [])#獲取虛擬VIP參數(shù)列表,其詳細內(nèi)容,參考下面注解 values = db_api.loadbalancer_pack_extra(params)#解析參數(shù)為一個字典列表 lb_ref = db_api.loadbalancer_create(conf, values)#更新loadbalancer的數(shù)據(jù)庫,返回值為models.LoadBalancer()數(shù)據(jù)庫表。 跟進到下一層1.1.1 device = scheduler.schedule_loadbalancer(conf, lb_ref)#根據(jù)當前l(fā)b數(shù)據(jù),修改底層配置device文件,進行調(diào)度。 跟進到下一層1.1.2 device_driver = drivers.get_device_driver(conf, device['id'])#獲取device驅(qū)動, 跟進到下一層1.1.3 lb = db_api.unpack_extra(lb_ref)#將lb_ref轉(zhuǎn)變?yōu)橐粋€字典 lb['device_id'] = device['id'] lb_ref = db_api.loadbalancer_pack_extra(lb)#加入device_id選項之后再次封裝 try: with device_driver.request_context() as ctx:#此處ctx的作用???(相關(guān)驅(qū)動配置???) commands.create_loadbalancer(ctx, lb_ref, nodes, probes, vips)#創(chuàng)建loadbalancer, 跟進到下一層1.1.4
except (exception.Error, exception.Invalid): lb_ref.status = lb_status.ERROR lb_ref.deployed = 'False' else: lb_ref.status = lb_status.ACTIVE lb_ref.deployed = 'True' db_api.loadbalancer_update(conf, lb['id'], lb_ref) return lb_ref['id']
注解: nodes里面包括虛擬機的地址,以及端口和負載均衡調(diào)度的權(quán)重參數(shù)等。
healthMonitor里面包括???
VIP用來連接外部和內(nèi)部實例IP直接通訊的中間層IP。這樣當我們機器出現(xiàn)故障時,我們的VIP還能正常工作接受外部服務和請求。
3、第1.1.1層
更新models.LoadBalancer()數(shù)據(jù)庫表值,返回整個LoadBalancer()表格數(shù)據(jù)
4、第1.1.2層 def schedule_loadbalancer(conf, lb_ref): conf.register_opts(bind_opts)#綁定特定配置文件,以便于修改為特定配置文件 device_filters = [utils.import_class(foo) for foo in conf.device_filters] all_devices = db_api.device_get_all(conf)#獲取所有 models.Device數(shù)據(jù)庫表?, 跟進到下一層1.1.2.1 if not all_devices:#如果沒有設備則報設備找不到異常 raise exp.DeviceNotFound cost_functions = [] for fullname in conf.device_cost_functions: conf_name = 'device_cost_%s_weight' % fullname.rpartition('.')[-1] try: weight = getattr(conf, conf_name)#獲取權(quán)重 except cfg.NoSuchOptError: conf.register_opt(cfg.FloatOpt(conf_name, default=1.)) weight = getattr(conf, conf_name) cost_functions.append((utils.import_class(fullname), weight)) filtered_devices = [dev for dev in all_devices if all(filt(conf, lb_ref, dev) for filt in device_filters)] if not filtered_devices: raise exp.NoValidDevice costed = [] for dev in filtered_devices: w = 0. for cost_func, weight in cost_functions: w += weight * cost_func(conf, lb_ref, dev) costed.append((w, dev)) costed.sort() return costed[0][1]
5、第1.1.2.1層
獲取models.Device數(shù)據(jù)庫表里面的所有數(shù)據(jù)
6、第1.1.3層
7、第1.1.4層
def create_loadbalancer(ctx, balancer, nodes, probes, vips): ? ? lb = db_api.unpack_extra(balancer)#解封裝為字典 ? ? sf = db_api.serverfarm_create(ctx.conf, {'lb_id': lb['id']})#創(chuàng)建serverfarm(更新models.ServerFarm()數(shù)據(jù)庫表),跟進下一層1.1.4.1 ? ? if?'algorithm'?in lb:#如果lb參數(shù)中有’algorithm‘則獲取type屬性字典 ? ? ? ? predictor_params = {'sf_id': sf['id'], 'type': lb['algorithm']} ? ? else: ? ? ? ? predictor_params = {'sf_id': sf['id']} ? ? db_api.predictor_create(ctx.conf, predictor_params)#更新數(shù)據(jù)到預報器models.Predictor()數(shù)據(jù)庫表中 ? ? create_server_farm(ctx, sf)#創(chuàng)建serverfarm(更新models.ServerFarm()數(shù)據(jù)庫表),跟進下一層1.1.4.2 ? ? for node in?nodes:#如果參數(shù)中有node則更新server數(shù)據(jù)庫 ? ? ? ? node_values = db_api.server_pack_extra(node) ? ? ? ? node_values['sf_id'] = sf['id']#加入sf_id重新封裝 ? ? ? ? rs_ref = db_api.server_create(ctx.conf, node_values)#更新models.Server()數(shù)據(jù)庫數(shù)據(jù) ? ? ? ? create_rserver(ctx, rs_ref)#創(chuàng)建rserver,更新models.Server()數(shù)據(jù)庫數(shù)據(jù) ? ? ? ? add_rserver_to_server_farm(ctx, sf, rs_ref)#跟進到下一層1.1.4.3
? ? for probe in?probes:#如果參數(shù)中有probe(探測器)則更新probe數(shù)據(jù)庫 ? ? ? ? probe_values = db_api.probe_pack_extra(probe) ? ? ? ? probe_values['lb_id'] = lb['id'] ? ? ? ? probe_values['sf_id'] = sf['id'] ? ? ? ? probe_ref = db_api.probe_create(ctx.conf, probe_values)#更新probe數(shù)據(jù)庫 ? ? ? ? create_probe(ctx, ?probe_ref)# 代碼pass:??? ? ? ? ? add_probe_to_server_farm(ctx, sf, probe_ref)
? ? for vip in?vips:#如果參數(shù)中有vip則更新virturalIps數(shù)據(jù)庫 ? ? ? ? vip_values = db_api.virtualserver_pack_extra(vip) ? ? ? ? vip_values['lb_id'] = lb['id'] ? ? ? ? vip_values['sf_id'] = sf['id'] ? ? ? ? vip_ref = db_api.virtualserver_create(ctx.conf, vip_values) ? ? ? ? create_vip(ctx, vip_ref, sf)##跟進到下一層1.1.4.4
8、第1.1.4.1層
更新models.ServerFarm()數(shù)據(jù)庫表
9、第1.1.4.2層 @with_rollback def create_server_farm(ctx, sf): try: pr = db_api.predictor_get_all_by_sf_id(ctx.conf, sf['id'])#通過sf_id過濾獲取models.Predictor數(shù)據(jù) ctx.device.create_server_farm(sf, pr) ? ?#???? db_api.serverfarm_update(ctx.conf, sf['id'], {'deployed': True})#更新 serverfarm數(shù)據(jù)庫表 yield except Exception: delete_server_farm(ctx, sf)#出現(xiàn)異常則刪除剛剛建立好的數(shù)據(jù)庫數(shù)據(jù) raise
10、1.1.4.3層 @with_rollback def add_rserver_to_server_farm(ctx, server_farm, rserver): try: if (rserver.get('parent_id') and rserver['parent_id'] != ""): #Nasty hack. We need to think how todo this more elegant rserver['name'] = rserver['parent_id'] ctx.device.add_real_server_to_server_farm(server_farm, rserver)#根據(jù)特定的device(以HAproxy為例), 跟進到下一層1.1.4.3.1層 yield except Exception: ctx.device.delete_real_server_from_server_farm(server_farm, rserver) raise
11、第1.1.4.3.1層 def add_real_server_to_server_farm(self, serverfarm, rserver): haproxy_serverfarm = HaproxyBackend() haproxy_serverfarm.name = serverfarm['id'] haproxy_rserver = HaproxyRserver() haproxy_rserver.name = rserver['id'] haproxy_rserver.weight = rserver.get('weight') or 1 haproxy_rserver.address = rserver['address'] haproxy_rserver.port = rserver.get('port') or 0 haproxy_rserver.maxconn = rserver['extra'].get('maxCon') or 10000 #Modify remote config file, check and restart remote haproxy logger.debug('[HAPROXY] Creating rserver %s in the ' 'backend block %s' % (haproxy_rserver.name, haproxy_serverfarm.name))
config_file = self._get_config()#??? config_file.add_rserver_to_backend_block(haproxy_serverfarm, haproxy_rserver)#???
12、第 ?1.1.4.4?層 def create_virtual_ip(self, virtualserver, serverfarm): if not bool(virtualserver['id']): logger.error('[HAPROXY] Virtualserver name is empty') return 'VIRTUALSERVER NAME ERROR' haproxy_virtualserver = HaproxyFronted() haproxy_virtualserver.name = virtualserver['id'] haproxy_virtualserver.bind_address = virtualserver['address'] haproxy_virtualserver.bind_port = virtualserver.get('port') or 0 haproxy_serverfarm = HaproxyBackend() haproxy_serverfarm.name = serverfarm['id'] logger.debug('[HAPROXY] create VIP %s' % haproxy_serverfarm.name) #Add new IP address remote_interface = RemoteInterface(self.device_ref, haproxy_virtualserver) remote_interface.add_ip() #Modify remote config file, check and restart remote haproxy config_file = self._get_config() config_file.add_frontend(haproxy_virtualserver, haproxy_serverfarm)
轉(zhuǎn)載于:https://my.oschina.net/tantexian/blog/626571
總結(jié)
以上是生活随笔為你收集整理的LB-createLB整理架构图-loadbalancer-openstack F版的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: UFT开发实例:QTP调用OutLook
 - 下一篇: zabbix server监控项报警提示