powercli site recovery manager: determine which protection group an unprotected VM will be in. SRM uses array based replication

huangapple go评论46阅读模式
英文:

powercli site recovery manager: determine which protection group an unprotected VM will be in. SRM uses array based replication

问题

我使用自动化来部署虚拟机到不同的vCenter集群。然后,我配置SRM网络映射,创建一个网络映射,将虚拟机所在的集群与用于灾难恢复的集群之间建立起联系,在这两个集群的保护组中。

SRM是为基于阵列的复制而设置的,只要将虚拟机放置在正确的集群中进行复制存储,它就会出现在SRM中的保护组下。如果网络映射已经设置好,那么SRM或者通过我的SRM配置脚本将自动保护虚拟机。

我目前已经将主要集群、灾难恢复集群和保护组硬编码进了脚本,但我想要确定虚拟机所在的保护组以及为保护组设置的两个集群的名称,这样就可以自动检测任何集群配置的更改,而不需要手动更改SRM配置脚本。

我已经查阅了SRM API文档,但尚未找到解决方法。

英文:

I use automation to deply VM's to various vcenter clusters.
I then confgiure SRM network mapping to create a network map between the cluster that the VM is in and the cluster which is used for DR purposes, in the protection group for those two clusters.

SRM is set up for array based replication, so as long as the VM is placed on replicated storage in the right cluster it will appear in SRM under the protection group, if a network mapping is in place then the VM will be auto protected by SRM or via my SRM config script.

I currently have the primary cluster, DR cluster and protection group hard coded, but would like to determine the protection group a VM is in and the name of the two clusters which the protection group is set up for, that way any changes to cluster configuration is automatically picked up and doesn't require manual changes to the SRM config script.

I've looked in the SRM API docs but it's not something I have worked out yet!

答案1

得分: 0

我已解决了这个问题:

$credential = Get-Credential
$server_name = "test-server"

Connect-VIServer -Server $primaryDC -Credential $credential
$srmConnection = Connect-SrmServer -Credential $credential -RemoteCredential $credential
Connect-VIServer -Server $secondaryDC -Credential $credential

$srmApi = $srmConnection.ExtensionData
$protectionGroups = $srmApi.Protection.ListProtectionGroups()

foreach ($protectionGroup in $protectionGroups){
    $associatedVms = $protectionGroup.ListProtectedDatastores() | Get-VIObjectByVIView | Get-VM | Where-Object {($_.name -eq $server_name) -and ($_.ExtensionData.Config.ManagedBy.ExtensionKey -ne 'com.vmware.vcDr' )}
    foreach ($vm in $associatedVms) {

        if ($vm.Name -eq $server_name) {
            $protection_group_name = $protectionGroup.GetInfo().Name
            $primary_cluster = get-vm -name $server_name | get-cluster
            $primary_cluster_res_group = $primary_cluster.ExtensionData.ResourcePool
            $srm_resource_groups = $srmApi.inventoryMapping.getResourcePoolMappings()

            foreach ($resource_group in $srm_resource_groups){
                if ($resource_group.PrimaryObject -eq $primary_cluster_res_group){
                    $secondary_res_group = $resource_group.SecondaryObject
                }
            }
        }
    }
}

$secondary_cluster = Get-Cluster | Where-Object {$_.ExtensionData.ResourcePool -eq $secondary_res_group}

Write-Host "VM: $vm - Protection Group: $protection_group_name - Primary cluster: $primary_cluster - Secondary cluster: $secondary_cluster - Primary ResGrp: $primary_cluster_res_group - Secondary ResGrp: $secondary_res_group"

请注意,代码部分已经被保留,只翻译了注释和字符串。

英文:

I have solved the issue:

$credential = Get-Credential 
$server_name = "test-server" 
  
Connect-VIServer -Server $primaryDC -Credential $credential 
$srmConnection = Connect-SrmServer -Credential $credential -RemoteCredential $credential 
Connect-VIServer -Server $secondaryDC -Credential $credential 
 
$srmApi = $srmConnection.ExtensionData 
$protectionGroups = $srmApi.Protection.ListProtectionGroups() 
        
foreach ($protectionGroup in $protectionGroups){ 
      $associatedVms = $protectionGroup.ListProtectedDatastores() | Get-VIObjectByVIView | Get-VM | Where-Object {($_.name -eq $server_name) -and($_.ExtensionData.Config.ManagedBy.ExtensionKey -ne 'com.vmware.vcDr' )} 
      foreach ($vm in $associatedVms) { 

          if ($vm.Name -eq $server_name) { 
            $protection_group_name = $protectionGroup.GetInfo().Name 
            $primary_cluster = get-vm -name $server_name | get-cluster 
            $primary_cluster_res_group = $primary_cluster.ExtensionData.ResourcePool 
            $srm_resource_groups = $srmApi.inventoryMapping.getResourcePoolMappings() 

            foreach ($resource_group in $srm_resource_groups){ 
              if ($resource_group.PrimaryObject -eq $primary_cluster_res_group){ 
                $secondary_res_group = $resource_group.SecondaryObject 
              }             
            } 
          } 
       } 
    } 
  
$secondary_cluster = Get-Cluster | Where-Object {$_.ExtensionData.ResourcePool -eq $secondary_res_group} 

Write-Host "VM: $vm  -  Protection Group: $protection_group_name  -  Primary cluster: $primary_cluster  -  Secondary cluster: $secondary_cluster  -  Primary ResGrp: $primary_cluster_res_group  -  Secondary ResGrp: $secondary_res_group" 

huangapple
  • 本文由 发表于 2023年2月8日 17:55:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75384037.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定