使用mongodb ops manager restapi执行切换

2024-05-14 11:04:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经编写了一个python脚本(和一个ansible剧本,因为无法使脚本工作,但那是另一个故事),其目的是在ops manager版本3.6管理的mongodb副本集中执行切换。我有两个站点,一个站点有3个服务器,另一个站点有2个服务器,这个脚本基本上是发送一个PUT请求来编辑副本集的自动化配置,并且根据给定的站点,将想要的服务器的优先级更改为2,同时将其他服务器的优先级保留为1,并添加仲裁器,然后在必要时删除它们。现在的目的只是更改put请求的优先级以尝试使其工作,put请求如下所示:

data = {"replicaSets": [
{
     "_id"_: "PP_ATLAS",
     "members": [
          {
               "_id": 2,
              "host": "*servername*",
              "priority": 2,
          },
          {
              "_id": 3,
              "host": "*servername*",
          },
          {
              "_id": 4,
              "host": "*servername*",
          }
     ]
   }
],
}
headers = {'Content-Type': 'application/json'}
js = requests.put(url, auth=HTTPDigestAuth (MMS_User, MMS_API), data=json.dumps(data), headers=headers, verify=False)

MMS\u User和MMS\u API是用于访问ops manager(也称为MMS)的标识令牌。你知道吗

当我尝试这样做时(脚本请求一个服务器名作为参数切换到),我收到:

{"detail":"Invalid automation config: Process *servername that was given as an argument* referenced in one or more deployment items but not found in configuration.","error":400,"errorCode":null,"parameters":null,"reason":"Bad Request"}
400

作为参数提供的服务器名是它所说的,而不是实际的引号“作为参数提供的服务器名”。你知道吗


Tags: 目的服务器脚本idhostdata参数put

热门问题