RemoveReplicationRelationshipEx( string name, UInt16 relationshipType) { if (relationshipType > 1) { throw new ArgumentException("Replication relationship should be either 0 or 1"); } ManagementScope scope = new ManagementScope(@"root\virtualization\v2"); // // Retrieve the Msvm_ComputerSystem. // using (ManagementObject vm = WmiUtilities.GetVirtualMachine(name, scope)) { string vmPath = vm.Path.Path; // // Retrieve the specified Msvm_ReplicationRelationship object. // using (ManagementObject replicationRelationship = ReplicaUtilities.GetReplicationRelationshipObject(vm, relationshipType)) { if (replicationRelationship == null) { throw new ManagementException(string.Format(CultureInfo.CurrentCulture, "No Msvm_ReplicationRelationship object with relationship type {0} could be found", relationshipType)); } string replicationRelationshipEmbedded = replicationRelationship.GetText(TextFormat.WmiDtd20); using (ManagementObject replicationService = ReplicaUtilities.GetVirtualMachineReplicationService(scope)) { using (ManagementBaseObject inParams = replicationService.GetMethodParameters("RemoveReplicationRelationshipEx")) { inParams["ComputerSystem"] = vmPath; inParams["ReplicationRelationship"] = replicationRelationshipEmbedded; using (ManagementBaseObject outParams = replicationService.InvokeMethod("RemoveReplicationRelationshipEx", inParams, null)) { WmiUtilities.ValidateOutput(outParams, scope); } } } } Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0} replication is successfully removed for virtual machine \"{1}\"", relationshipType == 0 ? "Primary" : "Extended", name)); } }
RequestReplicationStateChangeEx( string name, UInt16 requestedState, UInt16 relationshipType) { if (relationshipType > 1) { throw new ArgumentException("Replication relationship should be either 0 or 1"); } ManagementScope scope = new ManagementScope(@"root\virtualization\v2"); // // Retrieve the Msvm_ComputerSystem. // using (ManagementObject vm = WmiUtilities.GetVirtualMachine(name, scope)) { // // Retrieve the specified Msvm_ReplicationRelationship object. // using (ManagementObject replicationRelationship = ReplicaUtilities.GetReplicationRelationshipObject(vm, relationshipType)) { if (replicationRelationship == null) { throw new ManagementException(string.Format(CultureInfo.CurrentCulture, "No Msvm_ReplicationRelationship object with relationship type {0} could be found", relationshipType)); } string replicationRelationshipEmbedded = replicationRelationship.GetText(TextFormat.WmiDtd20); using (ManagementBaseObject inParams = vm.GetMethodParameters("RequestReplicationStateChangeEx")) { inParams["RequestedState"] = requestedState; inParams["ReplicationRelationship"] = replicationRelationshipEmbedded; using (ManagementBaseObject outParams = vm.InvokeMethod("RequestReplicationStateChangeEx", inParams, null)) { WmiUtilities.ValidateOutput(outParams, scope); } ReplicaUtilities.ReplicationState state = (ReplicaUtilities.ReplicationState)requestedState; Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0} replication state for virtual machine \"{1}\" is changed to \"{2}\"", relationshipType == 0 ? "Primary" : "Extended", name, state.ToString())); } } } }
GetReplicationRelationshipInfo( string name, UInt16 relationshipType) { if (relationshipType > 1) { throw new ArgumentException("Replication relationship should be either 0 or 1"); } ManagementScope scope = new ManagementScope(@"root\virtualization\v2"); // // Retrieve the Msvm_ComputerSystem. // using (ManagementObject vm = WmiUtilities.GetVirtualMachine(name, scope)) { // // Retrieve the specified Msvm_ReplicationRelationship object. // using (ManagementObject replicationRelationship = ReplicaUtilities.GetReplicationRelationshipObject(vm, relationshipType)) { if (replicationRelationship == null) { throw new ManagementException(string.Format(CultureInfo.CurrentCulture, "No Msvm_ReplicationRelationship object with relationship type {0} could be found", relationshipType)); } // // Print the information present in the replication relationship object. // ReplicaUtilities.PrintReplicationRelationshipObject(replicationRelationship); } } }