集群,来自 Python 的节点

Cluster, Node from Python

我有一个集群的 DNS 名称,该集群的服务节点很少 运行。 我首先编写了 powershell 脚本,它为我提供了提供服务 运行 的节点及其状态。脚本使用 Get-ClusterResource 命令 然后我写了 python 脚本来执行这个 powershell。 当我是 运行 powershell 脚本时,我正在获取节点及其状态。但是当我从 python 运行 powershell 脚本时,我得到的错误是:

Get-ClusterResource : The term 'Get-ClusterResource' is not recognized as the 
name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is 
correct and try again.

我尝试使用 import-module failovercluster 但没有成功。

请让我知道我错在哪里,如果不可能,那么我正在搜索 python 库来实现相同的目的。

我对集群的一些认识: - 我们不能 create PSSession 集群。

我是这样的运行 powershell脚本:

subprocess.check_output(["powershell.exe", '-ExecutionPolicy', 'Unrestricted', self.win_cluster_handling() + " -Cluster_Name " + self.cluster_name + " -ClusterNode_Action Stop-Cluster" + " -Service_Name " + self.service_name + " -Username " + self.username + " -Password " + self.password])

您的脚本中是否也包含 Import-module FailoverClusters

看看这个question

一个建议是更新到 PowerShell v3.0 或更高版本。

重新阅读您的描述,问题出现在您从 Python 调用的 Powershell 脚本中。在您的 Powershell 脚本中,您能否写一些行来确定该脚本是否 运行 具有与您通常 运行 Powershell 时相同的环境变量、PATH 等。

例如,如果您从 Powershell 运行: "Get-ChildItem Env:",它会为您提供环境变量列表。您可以在您的 powershell 脚本中包含相同的内容,并检查它们是否相同,或者您的脚本 运行 中是否缺少某些内容。