VMware {code} Community
rmilkowski
Contributor
Contributor
Jump to solution

PBM Policies and Replication/Consistency groups

Hi,

I have SPBMs with requirements for specific replication groups - so when a storage policy is assigned to a VM it utilize array based auto snaphotting. Example policy:

General
Name Pure - LOS - Workstations
Description
Rule-set 1: com.purestorage.storage.policy
Placement
Storage Type com.purestorage.storage.policy
Pure Storage FlashArray Yes
FlashArray Group losarray1
Replication > Custom
Provider com.purestorage.storage.replication
Local Snapshot Interval 1 Hours
Local Snapshot Retention 48 Hours
Consistency Group Name PG-Workstations

 

Notice the replication requirements for 48 hourly snapshots and the consistency group name: PG-Workstations.

When assigning such storage policy to a vm via vCenter gui it requires the replication/consistency group to be selected as well. Given that a specific name of the group is required by the above policy it will only present this single group. Which can be selected and then the policy gets assigned to the vm just fine. However, how do I do it programmatically in Python?

I think I should call placementSolver.PbmCheckRequirements() which should return PbmPlacementMatchingResources[] which then should return replicationGroup *ReplicationGroupId[] which then I should use in configspec and reconfigure VM. However the below code fails:

 

pbmRef = pbm.ServerObjectRef(key=vm._moId,
objectType=pbm.ServerObjectRef.ObjectType('virtualMachineAndDisks'))

pbmReq = pbm.placement.Requirement = []
pbmReqProf = pbm.placement.CapabilityProfileRequirement()
pbmReqProf.profileId = profile.profileId
pbmReq.append(pbmReqProf)

 

datacenter = self._get_datacenter(self.datacenter_name)
datastore = self._get_datastore(datacenter, self.datastore_name)
hub = pbm.placement.PlacementHub()
hub.hubType = 'Datastore'
hub.hubId = datastore

placement_results = placementSolver.PbmCheckRequirements(hubsToSearch=[hub], placementSubjectRef=pbmRef, placementSubjectRequirement=pbmReq)


it fails with:
...

File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/VmomiSupport.py", line 706, in <lambda>
self.f(*(self.args + (obj,) + args), **kwargs)
File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/VmomiSupport.py", line 512, in _InvokeMethod
return self._stub.InvokeMethod(self, info, args)
File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/SoapAdapter.py", line 1345, in InvokeMethod
req = self.SerializeRequest(mo, info, args)
File "/var/tmp/hdb-tool_venv/lib64/python3.7/site-packages/pyVmomi/SoapAdapter.py", line 914, in SerializeRequest
method=info.name)
pyVmomi.VmomiSupport.MethodNotFound: (vmodl.fault.MethodNotFound) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
msg = <unset>,
faultCause = <unset>,
faultMessage = (vmodl.LocalizableMessage) [],
receiver = 'pbm.placement.PlacementSolver:placementSolver',
method = 'CheckRequirements'
}

 

Why does it fail?

 

I tried to use the depricated API:

 

placement_results = placementSolver.PbmCheckCompatibility(hubsToSearch=[hub], profile=profile.profileId)

 

While this call executes it returns:

 

(pbm.placement.CompatibilityResult) [
(pbm.placement.CompatibilityResult) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
hub = (pbm.placement.PlacementHub) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
hubType = 'Datastore',
hubId = 'datastore-2433'
},
matchingResources = (pbm.placement.MatchingResources) [],
howMany = <unset>,
utilization = (pbm.placement.ResourceUtilization) [],
warning = (vmodl.MethodFault) [],
error = (vmodl.MethodFault) []
}
]

 

Notice that matchingResources is an empty list for some reason so can't get replication group id.

It's an depricated api anyway and PbmCheckRequirements(hubsToSearch() should work and return the matchingResources[] with the replication groups, bu as shown above it just fails completely.

 

I'm using pyvmomi 7.0.1 wiht vCenter 7.0.1 as well.

I'm not sure if this is possible to do via the vSphere Management SDK directly or just via pyvmomi.

 

Any ideas?

 

 

Reply
0 Kudos
1 Solution

Accepted Solutions
rmilkowski
Contributor
Contributor
Jump to solution

This was fixed by replacing version1 with version11 in the below code:

 

    def _pbm_connect(self):

        if self.pbmSI is not None:

            return

 

        self._pyvmomi_connect()

        VmomiSupport.GetRequestContext()["vcSessionCookie"] = self.si._stub.cookie.split('"')[1]

        hostname = self.si._stub.host.split(":")[0]

        pbmStub = SoapStubAdapter(

            host=hostname,

            version="pbm.version.version1",

            path="/pbm/sdk",

            poolSize=0,

            sslContext=ssl._create_unverified_context())

        pbmServiceInstance = pbm.ServiceInstance("ServiceInstance", pbmStub)

 

        self.pbmSI = pbmServiceInstance

 

View solution in original post

Reply
0 Kudos
1 Reply
rmilkowski
Contributor
Contributor
Jump to solution

This was fixed by replacing version1 with version11 in the below code:

 

    def _pbm_connect(self):

        if self.pbmSI is not None:

            return

 

        self._pyvmomi_connect()

        VmomiSupport.GetRequestContext()["vcSessionCookie"] = self.si._stub.cookie.split('"')[1]

        hostname = self.si._stub.host.split(":")[0]

        pbmStub = SoapStubAdapter(

            host=hostname,

            version="pbm.version.version1",

            path="/pbm/sdk",

            poolSize=0,

            sslContext=ssl._create_unverified_context())

        pbmServiceInstance = pbm.ServiceInstance("ServiceInstance", pbmStub)

 

        self.pbmSI = pbmServiceInstance

 

Reply
0 Kudos