python脚本去配合RefreshScope动态刷新配置

python脚本去配合RefreshScope动态刷新配置

大家都知道哇,eureka注册中心的服务,一个服务可能对应了多个机子,就会有多个ip,虽然使用@refreshScope刷新不需要重启服务就能生效配置,但是如果有10多个机子也是很奔溃的哇。。。

在这里插入图片描述

像我这种偷懒选手,肯定是要找躺平的办法(✪ω✪)

@RefreshScope怎么实现刷新的就不多解释了,找到对应的服务地址加上/refresh就能实现刷新了

直接上代码!!

import requests
from bs4 import  BeautifulSoup

from urllib.parse import urlparse

URL = '你的eureka注册中心地址'
header = {'Accept': "application/json, text/plain, */*",'content-type': "application/x-www-form-urlencoded;charset=UTF-8"}
r = requests.get(url = URL, headers = header)

html = r.text
soup = BeautifulSoup(html, features="html.parser")
# MY-SERVICE
current = soup.find("td",text="*****-SERVICE")
# print('current:', current)
parent = current.find_parent()
# print('parent:', parent)
child = parent.findChild()
# print('child:', child)
next = current.find_next("td").find_next("td").find_next("td")
# print('next:', next)
find_all = next.find_all("a")
# print('find_all:', find_all)
# 遍历所有ip
for find in find_all:
    find_href_ = find['href']
    # print("find_href_:",find_href_)
    _url = urlparse((find_href_))
    refreshUrl =_url.scheme +'://'+ _url.hostname +':'+ str(_url.port)+'/refresh'
    print("refreshUrl:",refreshUrl)
    # 刷新多个服务
    responseValue = requests.post(url=refreshUrl, headers=header)
    # 获取响应内容
    print("显示响应内容:", responseValue.text)

不清楚大家的eureka展示是否一样,大致就是获取页面标签去搜索对应服务下所有的ip,然后酱酱酱子。
在这里插入图片描述

办法有很多,我这个蠢蠢的但是还能用!够够了。
今天很困,就说这么多吧
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值