Example #1
0
        internal static void DeleteFailoverRelationship(DhcpServerFailoverRelationship relationship)
        {
            // refresh relationship instance
            relationship = (DhcpServerFailoverRelationship)relationship.Server.FailoverRelationships.GetRelationship(relationship.Name);

            if (relationship.scopeAddresses.Count > 0)
            {
                throw new InvalidOperationException("This failover relationship contains configured scopes. Deconfigure the scopes before deleting the relationship.");
            }

            var result = Api.DhcpV4FailoverDeleteRelationship(relationship.Server.Address, relationship.Name);

            if (result != DhcpErrors.SUCCESS)
            {
                throw new DhcpServerException(nameof(Api.DhcpV4FailoverDeleteScopeFromRelationship), result, "Failed to delete relationship");
            }

            var partnerServer = relationship.ConnectToPartner();

            result = Api.DhcpV4FailoverDeleteRelationship(partnerServer.Address, relationship.Name);
            if (result != DhcpErrors.SUCCESS)
            {
                throw new DhcpServerException(nameof(Api.DhcpV4FailoverDeleteScopeFromRelationship), result, "Failed to delete relationship on partner server");
            }
        }
Example #2
0
        internal static void ReplicateScopeRelationship(DhcpServerFailoverRelationship relationship, DhcpServerScope sourceScope)
        {
            var partner          = relationship.ConnectToPartner();
            var destinationScope = partner.Scopes.GetScope(sourceScope.Address);

            sourceScope.ReplicateTo((DhcpServerScope)destinationScope);
        }
Example #3
0
        private static void ReplicateRelationship(DhcpServerFailoverRelationship relationship)
        {
            var scopes  = relationship.Scopes.ToList();
            var partner = relationship.ConnectToPartner();

            foreach (var sourceScope in scopes)
            {
                var destinationScope = partner.Scopes.GetScope(sourceScope.Address);

                ((DhcpServerScope)sourceScope).ReplicateTo((DhcpServerScope)destinationScope);
            }
        }
Example #4
0
        internal static void AddScopeToFailoverRelationship(DhcpServerFailoverRelationship relationship, DhcpServerScope scope)
        {
            var partnerServer = (DhcpServer)relationship.ConnectToPartner();

            // create/replicate
            var partnerScope = CreateOrReplicatePartnerScope(partnerServer, scope);

            // determine relationship primary/secondary servers
            DhcpServer primaryServer;
            DhcpServer secondaryServer;

            if (relationship.ServerType == DhcpServerFailoverServerType.PrimaryServer)
            {
                primaryServer   = relationship.Server;
                secondaryServer = partnerServer;
            }
            else
            {
                primaryServer   = partnerServer;
                secondaryServer = relationship.Server;
            }

            using (var relationshipNative = new DHCP_FAILOVER_RELATIONSHIP_Managed(relationshipName: relationship.Name,
                                                                                   scopes: new DHCP_IP_ARRAY_Managed(scope.Address.ToNativeAsNetwork())))
            {
                // update relationship on primary server
                var result = Api.DhcpV4FailoverAddScopeToRelationship(primaryServer.Address, in relationshipNative);
                if (result != DhcpErrors.SUCCESS)
                {
                    throw new DhcpServerException(nameof(Api.DhcpV4FailoverAddScopeToRelationship), result, "Failed to add scope to failover relationship on primary server");
                }

                // update relationship on secondary server
                result = Api.DhcpV4FailoverAddScopeToRelationship(secondaryServer.Address, in relationshipNative);
                if (result != DhcpErrors.SUCCESS)
                {
                    throw new DhcpServerException(nameof(Api.DhcpV4FailoverAddScopeToRelationship), result, "Failed to add scope to failover relationship on secondary server");
                }
            }

            // update local cache
            relationship.scopeAddresses.Add(scope.Address);

            // activate scope on partner (if the scope is active on primary)
            if (scope.State == DhcpServerScopeState.Enabled || scope.State == DhcpServerScopeState.EnabledSwitched)
            {
                partnerScope = (DhcpServerScope)partnerServer.Scopes.GetScope(partnerScope.Address);
                partnerScope.Activate();
            }
        }