protected override void ProcessRecord()
        {
            TrafficManagerEndpoint trafficManagerEndpoint = this.TrafficManagerClient.SetTrafficManagerEndpoint(this.TrafficManagerEndpoint);

            this.WriteVerbose(ProjectResources.Success);
            this.WriteObject(trafficManagerEndpoint);
        }
Esempio n. 2
0
        public bool EnableDisableTrafficManagerEndpoint(TrafficManagerEndpoint endpoint, bool shouldEnableEndpointStatus)
        {
            endpoint.EndpointStatus = shouldEnableEndpointStatus ? Constants.StatusEnabled : Constants.StatusDisabled;

            Endpoint sdkEndpoint = endpoint.ToSDKEndpoint();

            sdkEndpoint.Properties.EndpointLocation      = null;
            sdkEndpoint.Properties.EndpointMonitorStatus = null;
            sdkEndpoint.Properties.Priority         = null;
            sdkEndpoint.Properties.Weight           = null;
            sdkEndpoint.Properties.Target           = null;
            sdkEndpoint.Properties.TargetResourceId = null;

            var parameters = new EndpointUpdateParameters
            {
                Endpoint = sdkEndpoint
            };

            AzureOperationResponse response = this.TrafficManagerManagementClient.Endpoints.Update(
                endpoint.ResourceGroupName,
                endpoint.ProfileName,
                endpoint.Type,
                endpoint.Name,
                parameters);

            return(response.StatusCode.Equals(HttpStatusCode.Created));
        }
        public override void ExecuteCmdlet()
        {
            TrafficManagerEndpoint endpointToEnable = null;

            if (this.ParameterSetName == "Fields")
            {
                endpointToEnable = new TrafficManagerEndpoint
                {
                    Name              = this.Name,
                    Target            = this.Type,
                    ProfileName       = this.ProfileName,
                    ResourceGroupName = this.ResourceGroupName
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                endpointToEnable = this.TrafficManagerEndpoint;
            }

            bool enabled = this.TrafficManagerClient.EnableDisableTrafficManagerEndpoint(endpointToEnable, shouldEnableEndpointStatus: true);

            if (enabled)
            {
                this.WriteVerbose(ProjectResources.Success);
                this.WriteVerbose(string.Format(ProjectResources.Success_EnableEndpoint, endpointToEnable.Name, endpointToEnable.ProfileName, endpointToEnable.ResourceGroupName));
            }

            this.WriteObject(enabled);
        }
        public void SetTrafficManagerEndpointMissingLocationSucceeds()
        {
            // Setup
            ProfileWithDefinition original = GetProfileWithDefinition();

            cmdlet = new SetAzureTrafficManagerEndpoint
            {
                DomainName            = DomainName,
                TrafficManagerProfile = original,
                Weight         = Weight,
                Type           = EndpointType.Any.ToString(),
                Status         = EndpointStatus.Enabled.ToString(),
                CommandRuntime = mockCommandRuntime
            };

            // Assert the endpoint doesn't exist
            Assert.IsFalse(original.Endpoints.Any(e => e.DomainName == DomainName));

            // Action
            cmdlet.ExecuteCmdlet();

            // Assert
            var actual = mockCommandRuntime.OutputPipeline[0] as ProfileWithDefinition;

            // There is a new endpoint with the domain name in "actual"
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Endpoints.Any(e => e.DomainName == DomainName));
            TrafficManagerEndpoint newEndpoint = actual.Endpoints.First(e => e.DomainName == DomainName);

            Assert.AreEqual(EndpointType.Any, newEndpoint.Type);
            Assert.AreEqual(EndpointStatus.Enabled, newEndpoint.Status);

            Assert.AreEqual(Weight, newEndpoint.Weight);
            Assert.AreEqual(null, newEndpoint.Location);
        }
        public void AddTrafficManagerEndpointAlreadyExistsFails()
        {
            // Setup
            ProfileWithDefinition original = GetProfileWithDefinition();

            var existingEndpoint = new TrafficManagerEndpoint
            {
                DomainName = DomainName,
                Type       = EndpointType.Any,
                Status     = EndpointStatus.Enabled
            };

            original.Endpoints.Add(existingEndpoint);

            cmdlet = new AddAzureTrafficManagerEndpoint
            {
                DomainName            = DomainName,
                Type                  = AnyType,
                TrafficManagerProfile = original,
                CommandRuntime        = mockCommandRuntime
            };

            // Action + Assert
            Testing.AssertThrows <Exception>(() => cmdlet.ExecuteCmdlet());
        }
Esempio n. 6
0
        private static TrafficManagerEndpoint GetPowershellTrafficManagerEndpoint(string id, string resourceGroupName, string profileName, string endpointType, string endpointName, Endpoint sdkEndpoint)
        {
            return(new TrafficManagerEndpoint
            {
                Id = id,
                ResourceGroupName = resourceGroupName,
                ProfileName = profileName,
                Name = endpointName,
                Type = TrafficManagerEndpoint.ToShortEndpointType(endpointType),

                EndpointStatus = sdkEndpoint.EndpointStatus,
                EndpointMonitorStatus = sdkEndpoint.EndpointMonitorStatus,
                GeoMapping = sdkEndpoint.GeoMapping != null?sdkEndpoint.GeoMapping.ToList() : null,
                                 Location = sdkEndpoint.EndpointLocation,
                                 MinChildEndpoints = (uint?)sdkEndpoint.MinChildEndpoints,
                                 MinChildEndpointsIPv4 = (uint?)sdkEndpoint.MinChildEndpointsIPv4,
                                 MinChildEndpointsIPv6 = (uint?)sdkEndpoint.MinChildEndpointsIPv6,
                                 Priority = (uint?)sdkEndpoint.Priority,
                                 Target = sdkEndpoint.Target,
                                 TargetResourceId = sdkEndpoint.TargetResourceId,
                                 Weight = (uint?)sdkEndpoint.Weight,
                                 SubnetMapping = sdkEndpoint.Subnets?.Select(ipAddressRange =>
                                                                             TrafficManagerIpAddressRange.FromSDKSubnetMapping(ipAddressRange)).ToList(),
                                 CustomHeaders = sdkEndpoint.CustomHeaders?.Select(customHeader =>
                                                                                   TrafficManagerCustomHeader.FromSDKEndpointPropertiesCustomHeadersItem(customHeader)).ToList(),
            });
        }
Esempio n. 7
0
        public TrafficManagerEndpoint CreateTrafficManagerEndpoint(string resourceGroupName, string profileName, string endpointType, string endpointName, string targetResourceId, string target, string endpointStatus, uint?weight, uint?priority, string endpointLocation, uint?minChildEndpoints)
        {
            EndpointCreateOrUpdateResponse response = this.TrafficManagerManagementClient.Endpoints.CreateOrUpdate(
                resourceGroupName,
                profileName,
                endpointType,
                endpointName,
                new EndpointCreateOrUpdateParameters
            {
                Endpoint = new Endpoint
                {
                    Name       = endpointName,
                    Type       = TrafficManagerEndpoint.ToSDKEndpointType(endpointType),
                    Properties = new EndpointProperties
                    {
                        TargetResourceId  = targetResourceId,
                        Target            = target,
                        EndpointStatus    = endpointStatus,
                        Weight            = weight,
                        Priority          = priority,
                        EndpointLocation  = endpointLocation,
                        MinChildEndpoints = minChildEndpoints,
                    }
                }
            });

            return(TrafficManagerClient.GetPowershellTrafficManagerEndpoint(response.Endpoint.Id, resourceGroupName, profileName, endpointType, endpointName, response.Endpoint.Properties));
        }
Esempio n. 8
0
        public override void ExecuteCmdlet()
        {
            TrafficManagerEndpoint trafficManagerEndpoint = this.TrafficManagerClient.SetTrafficManagerEndpoint(this.TrafficManagerEndpoint);

            this.WriteVerbose(ProjectResources.Success);
            this.WriteObject(trafficManagerEndpoint);
        }
        public void AddTrafficManagerEndpointNoWeightNoLocationNoMinChildEndpoints()
        {
            // Setup
            ProfileWithDefinition original = GetProfileWithDefinition();

            cmdlet = new AddAzureTrafficManagerEndpoint
            {
                DomainName            = DomainName,
                Type                  = AnyType,
                TrafficManagerProfile = original,
                CommandRuntime        = mockCommandRuntime,
                Status                = "Enabled"
            };

            // Action
            cmdlet.ExecuteCmdlet();

            var actual = mockCommandRuntime.OutputPipeline[0] as ProfileWithDefinition;

            // Assert
            // All the properties stay the same except the endpoints
            AssertAllProfilePropertiesDontChangeExceptEndpoints(original, actual);

            // There is a new endpoint with the new domain name in "actual" but not in "original"
            Assert.IsTrue(actual.Endpoints.Any(e => e.DomainName == DomainName));
            TrafficManagerEndpoint endpoint = actual.Endpoints.First(e => e.DomainName == DomainName);

            Assert.AreEqual(null, endpoint.Weight);
            Assert.IsNull(endpoint.Location);
            Assert.AreEqual(null, endpoint.MinChildEndpoints);
        }
Esempio n. 10
0
        public override void ExecuteCmdlet()
        {
            var deleted = false;
            TrafficManagerEndpoint trafficManagerEndpointToDelete = null;

            if (this.ParameterSetName == "Fields")
            {
                trafficManagerEndpointToDelete = new TrafficManagerEndpoint
                {
                    Name              = this.Name,
                    ProfileName       = this.ProfileName,
                    ResourceGroupName = this.ResourceGroupName,
                    Type              = this.Type
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                trafficManagerEndpointToDelete = this.TrafficManagerEndpoint;
            }

            this.ConfirmAction(
                this.Force.IsPresent,
                string.Format(ProjectResources.Confirm_RemoveEndpoint, trafficManagerEndpointToDelete.Name, trafficManagerEndpointToDelete.ProfileName, trafficManagerEndpointToDelete.ResourceGroupName),
                ProjectResources.Progress_RemovingEndpoint,
                this.Name,
                () => { deleted = this.TrafficManagerClient.DeleteTrafficManagerEndpoint(trafficManagerEndpointToDelete); });

            if (deleted)
            {
                this.WriteVerbose(ProjectResources.Success);
                this.WriteVerbose(string.Format(ProjectResources.Success_RemoveEndpoint, trafficManagerEndpointToDelete.Name, trafficManagerEndpointToDelete.ProfileName, trafficManagerEndpointToDelete.ResourceGroupName));
            }

            this.WriteObject(deleted);
        }
Esempio n. 11
0
        protected override void ProcessRecord()
        {
            var disabled = false;
            TrafficManagerEndpoint endpointToDisable = null;

            if (this.ParameterSetName == "Fields")
            {
                endpointToDisable = new TrafficManagerEndpoint
                {
                    Name              = this.Name,
                    Type              = this.Type,
                    ProfileName       = this.ProfileName,
                    ResourceGroupName = this.ResourceGroupName
                };
            }
            else if (this.ParameterSetName == "Object")
            {
                endpointToDisable = this.TrafficManagerEndpoint;
            }

            this.ConfirmAction(
                this.Force.IsPresent,
                string.Format(ProjectResources.Confirm_DisableEndpoint, endpointToDisable.Name, endpointToDisable.ProfileName),
                ProjectResources.Progress_DisablingEndpoint,
                this.Name,
                () => { disabled = this.TrafficManagerClient.EnableDisableTrafficManagerEndpoint(endpointToDisable, shouldEnableEndpointStatus: false); });

            if (disabled)
            {
                this.WriteVerbose(ProjectResources.Success);
                this.WriteVerbose(string.Format(ProjectResources.Success_DisableEndpoint, endpointToDisable.Name, endpointToDisable.Name, endpointToDisable.ResourceGroupName));
            }

            this.WriteObject(disabled);
        }
        public void RemoveTrafficManagerEndpointNonExistingFails()
        {
            // Setup
            ProfileWithDefinition original = GetProfileWithDefinition();

            var existingEndpoint = new TrafficManagerEndpoint
            {
                DomainName = DomainName,
                Type       = EndpointType.Any,
                Status     = EndpointStatus.Enabled
            };

            original.Endpoints.Add(existingEndpoint);

            // Assert the endpoint exists
            Assert.IsTrue(original.Endpoints.Any(e => e.DomainName == DomainName));

            cmdlet = new RemoveAzureTrafficManagerEndpoint
            {
                DomainName            = DomainName,
                TrafficManagerProfile = original,
                CommandRuntime        = mockCommandRuntime
            };

            // Action + Assert
            Testing.AssertThrows <Exception>(() => cmdlet.ExecuteCmdlet());
        }
Esempio n. 13
0
        public bool DeleteTrafficManagerEndpoint(TrafficManagerEndpoint trafficManagerEndpoint)
        {
            AzureOperationResponse response = this.TrafficManagerManagementClient.Endpoints.Delete(
                trafficManagerEndpoint.ResourceGroupName,
                trafficManagerEndpoint.ProfileName,
                trafficManagerEndpoint.Type,
                trafficManagerEndpoint.Name);

            return(response.StatusCode.Equals(HttpStatusCode.OK));
        }
Esempio n. 14
0
        public bool DeleteTrafficManagerEndpoint(TrafficManagerEndpoint trafficManagerEndpoint)
        {
            // DeleteOperationResult response =
            HttpStatusCode code =
                this.DeleteTrafficManagerEndpoint(
                    trafficManagerEndpoint.ResourceGroupName,
                    trafficManagerEndpoint.ProfileName,
                    trafficManagerEndpoint.Type,
                    trafficManagerEndpoint.Name);

            return(code == HttpStatusCode.OK);
        }
        public void SetTrafficManagerEndpointSucceeds()
        {
            // Setup
            ProfileWithDefinition original = GetProfileWithDefinition();

            var existingEndpoint = new TrafficManagerEndpoint
            {
                DomainName        = DomainName,
                Type              = EndpointType.Any,
                Status            = EndpointStatus.Enabled,
                Weight            = 10,
                MinChildEndpoints = 2
            };

            original.Endpoints.Add(existingEndpoint);

            // Assert the endpoint exists
            Assert.IsTrue(original.Endpoints.Any(e => e.DomainName == DomainName));

            cmdlet = new SetAzureTrafficManagerEndpoint
            {
                DomainName            = DomainName,
                TrafficManagerProfile = original,
                Weight            = Weight,
                MinChildEndpoints = MinChildEndpoints,
                Location          = Location,
                CommandRuntime    = mockCommandRuntime
            };

            // Action
            cmdlet.ExecuteCmdlet();

            // Assert
            var actual = mockCommandRuntime.OutputPipeline[0] as ProfileWithDefinition;

            // All the properties stay the same except the endpoints
            AssertAllProfilePropertiesDontChangeExceptEndpoints(original, actual);

            // There is an endpoint with the domain name in "actual"
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Endpoints.Any(e => e.DomainName == DomainName));
            TrafficManagerEndpoint updatedEndpoint = actual.Endpoints.First(e => e.DomainName == DomainName);

            // Unchanged properties
            Assert.AreEqual(EndpointType.Any, updatedEndpoint.Type);
            Assert.AreEqual(EndpointStatus.Enabled, updatedEndpoint.Status);

            // Updated properties
            Assert.AreEqual(Weight, updatedEndpoint.Weight);
            Assert.AreEqual(Location, updatedEndpoint.Location);
            Assert.AreEqual(MinChildEndpoints, updatedEndpoint.MinChildEndpoints);
        }
        public override void ExecuteCmdlet()
        {
            ProfileWithDefinition profile = TrafficManagerProfile.GetInstance();

            if (!profile.Endpoints.Any(e => e.DomainName.Equals(DomainName, StringComparison.InvariantCultureIgnoreCase)))
            {
                throw new Exception(Resources.RemoveTrafficManagerEndpointMissing);
            }

            TrafficManagerEndpoint endpoint = profile.Endpoints.First(e => e.DomainName.Equals(DomainName, StringComparison.InvariantCultureIgnoreCase));

            profile.Endpoints.Remove(endpoint);

            WriteObject(profile);
        }
        public override void ExecuteCmdlet()
        {
            ProfileWithDefinition profile = TrafficManagerProfile.GetInstance();

            if (!profile.Endpoints.Any(e => e.DomainName == DomainName))
            {
                throw new Exception(Resources.RemoveTrafficManagerEndpointMissing);
            }

            TrafficManagerEndpoint endpoint = profile.Endpoints.First(e => e.DomainName == DomainName);

            profile.Endpoints.Remove(endpoint);

            WriteObject(profile);
        }
Esempio n. 18
0
        public bool EnableDisableTrafficManagerEndpoint(TrafficManagerEndpoint endpoint, bool shouldEnableEndpointStatus)
        {
            endpoint.EndpointStatus = shouldEnableEndpointStatus ? Constants.StatusEnabled : Constants.StatusDisabled;

            Endpoint sdkEndpoint = endpoint.ToSDKEndpointForPatch();

            sdkEndpoint.EndpointStatus = endpoint.EndpointStatus;

            Endpoint response = this.TrafficManagerManagementClient.Endpoints.Update(
                endpoint.ResourceGroupName,
                endpoint.ProfileName,
                endpoint.Type,
                endpoint.Name,
                sdkEndpoint);

            return(true);
        }
Esempio n. 19
0
        public override void ExecuteCmdlet()
        {
            ProfileWithDefinition profile = TrafficManagerProfile.GetInstance();

            TrafficManagerEndpoint endpoint = profile.Endpoints.FirstOrDefault(e => e.DomainName.Equals(DomainName, StringComparison.InvariantCultureIgnoreCase));

            if (endpoint == null)
            {
                if (String.IsNullOrEmpty(Type) ||
                    String.IsNullOrEmpty(Status) ||
                    String.IsNullOrEmpty(DomainName))
                {
                    throw new Exception(Resources.SetTrafficManagerEndpointNeedsParameters);
                }

                WriteVerboseWithTimestamp(Resources.SetInexistentTrafficManagerEndpointMessage, profile.Name, DomainName);
                endpoint                   = new TrafficManagerEndpoint();
                endpoint.DomainName        = DomainName;
                endpoint.Location          = Location;
                endpoint.Type              = (EndpointType)Enum.Parse(typeof(EndpointType), Type);
                endpoint.Weight            = Weight;
                endpoint.MinChildEndpoints = MinChildEndpoints;
                endpoint.Status            = (EndpointStatus)Enum.Parse(typeof(EndpointStatus), Status);

                // Add it because the endpoint didn't exist
                profile.Endpoints.Add(endpoint);
            }

            endpoint.Location = Location ?? endpoint.Location;

            endpoint.Type = !String.IsNullOrEmpty(Type)
                ? (EndpointType)Enum.Parse(typeof(EndpointType), Type)
                : endpoint.Type;

            endpoint.Weight            = Weight.HasValue ? Weight.Value : endpoint.Weight;
            endpoint.MinChildEndpoints = MinChildEndpoints.HasValue ? MinChildEndpoints.Value : endpoint.MinChildEndpoints;

            endpoint.Status = !String.IsNullOrEmpty(Status)
                ? (EndpointStatus)Enum.Parse(typeof(EndpointStatus), Status)
                : endpoint.Status;

            WriteObject(profile);
        }
Esempio n. 20
0
        public TrafficManagerEndpoint SetTrafficManagerEndpoint(TrafficManagerEndpoint endpoint)
        {
            Endpoint endpointToSet = endpoint.ToSDKEndpoint();

            Endpoint response = this.TrafficManagerManagementClient.Endpoints.CreateOrUpdate(
                endpoint.ResourceGroupName,
                endpoint.ProfileName,
                endpoint.Type,
                endpoint.Name,
                endpointToSet);

            return(TrafficManagerClient.GetPowershellTrafficManagerEndpoint(
                       endpoint.Id,
                       endpoint.ResourceGroupName,
                       endpoint.ProfileName,
                       endpoint.Type,
                       endpoint.Name,
                       response));
        }
Esempio n. 21
0
        public TrafficManagerEndpoint CreateTrafficManagerEndpoint(
            string resourceGroupName,
            string profileName,
            string endpointType,
            string endpointName,
            string targetResourceId,
            string target,
            string endpointStatus,
            uint?weight,
            uint?priority,
            string endpointLocation,
            uint?minChildEndpoints,
            uint?minChildEndpointsIPv4,
            uint?minChildEndpointsIPv6,
            IList <string> geoMapping,
            IList <TrafficManagerIpAddressRange> subnetMapping,
            IList <TrafficManagerCustomHeader> customHeaders
            )
        {
            Endpoint response = this.TrafficManagerManagementClient.Endpoints.CreateOrUpdate(
                resourceGroupName,
                profileName,
                endpointType,
                endpointName,
                new Endpoint(name: endpointName, type: TrafficManagerEndpoint.ToFullEndpointType(endpointType))
            {
                EndpointLocation      = endpointLocation,
                EndpointStatus        = endpointStatus,
                GeoMapping            = geoMapping,
                MinChildEndpoints     = minChildEndpoints,
                MinChildEndpointsIPv4 = minChildEndpointsIPv4,
                MinChildEndpointsIPv6 = minChildEndpointsIPv6,
                Priority         = priority,
                Target           = target,
                TargetResourceId = targetResourceId,
                Weight           = weight,
                Subnets          = subnetMapping?.Select(ipAddressRange => ipAddressRange.ToSDKSubnetMapping()).ToList(),
                CustomHeaders    = customHeaders?.Select(customHeader => customHeader.ToSDKEndpointPropertiesCustomHeadersItem()).ToList()
            });

            return(TrafficManagerClient.GetPowershellTrafficManagerEndpoint(response.Id, resourceGroupName, profileName, endpointType, endpointName, response));
        }
        public override void ExecuteCmdlet()
        {
            // We are not supporting etags yet, NewAzureTrafficManagerEndpoint should not overwrite any existing endpoint.
            // Since our create operation is implemented using PUT, it will overwrite by default.
            // Therefore, we need to check whether the Profile exists before we actually try to create it.
            try
            {
                this.TrafficManagerClient.GetTrafficManagerEndpoint(this.ResourceGroupName, this.ProfileName, this.Type, this.Name);

                throw new PSArgumentException(string.Format(ProjectResources.Error_CreateExistingEndpoint, this.Name, this.ProfileName, this.ResourceGroupName));
            }
            catch (CloudException exception)
            {
                if (exception.Response.StatusCode.Equals(HttpStatusCode.NotFound))
                {
                    TrafficManagerEndpoint trafficManagerEndpoint = this.TrafficManagerClient.CreateTrafficManagerEndpoint(
                        this.ResourceGroupName,
                        this.ProfileName,
                        this.Type,
                        this.Name,
                        this.TargetResourceId,
                        this.Target,
                        this.EndpointStatus,
                        this.Weight,
                        this.Priority,
                        this.EndpointLocation,
                        this.MinChildEndpoints,
                        this.MinChildEndpointsIPv4,
                        this.MinChildEndpointsIPv6,
                        this.GeoMapping,
                        this.SubnetMapping,
                        this.CustomHeader);

                    this.WriteVerbose(ProjectResources.Success);
                    this.WriteObject(trafficManagerEndpoint);
                }
                else
                {
                    throw;
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            TrafficManagerEndpoint endpoint = new TrafficManagerEndpoint();

            endpoint.DomainName = DomainName;
            endpoint.Location   = Location;
            endpoint.Status     = (EndpointStatus)Enum.Parse(typeof(EndpointStatus), Status);
            endpoint.Type       = (EndpointType)Enum.Parse(typeof(EndpointType), Type);
            endpoint.Weight     = Weight.HasValue ? Weight.Value : 1;
            ProfileWithDefinition profile = TrafficManagerProfile.GetInstance();

            if (profile.Endpoints.Any(e => e.DomainName == endpoint.DomainName))
            {
                throw new Exception(
                          string.Format(Resources.AddTrafficManagerEndpointFailed, profile.Name, endpoint.DomainName));
            }

            profile.Endpoints.Add(endpoint);
            WriteObject(TrafficManagerProfile);
        }
        public void SetTrafficManagerEndpointNotExisting()
        {
            // Setup
            ProfileWithDefinition  original         = GetProfileWithDefinition();
            TrafficManagerEndpoint expectedEndpoint = new TrafficManagerEndpoint()
            {
                DomainName        = DomainName,
                Type              = EndpointType.Any,
                Status            = EndpointStatus.Enabled,
                Weight            = Weight,
                MinChildEndpoints = MinChildEndpoints,
                Location          = Location
            };

            cmdlet = new SetAzureTrafficManagerEndpoint
            {
                DomainName            = DomainName,
                TrafficManagerProfile = original,
                Type              = EndpointType.Any.ToString(),
                Weight            = Weight,
                MinChildEndpoints = MinChildEndpoints,
                Location          = Location,
                Status            = EndpointStatus.Enabled.ToString(),
                CommandRuntime    = mockCommandRuntime
            };

            // Assert the endpoint doesn't exist
            Assert.IsFalse(original.Endpoints.Any(e => e.DomainName == DomainName));

            // Action
            cmdlet.ExecuteCmdlet();

            var actual = mockCommandRuntime.OutputPipeline[0] as ProfileWithDefinition;

            // There is a new endpoint with the domain name in "actual"
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Endpoints.Any(e => e.DomainName == DomainName));
            TrafficManagerEndpoint newEndpoint = actual.Endpoints.First(e => e.DomainName == DomainName);

            Assert.AreEqual(expectedEndpoint, newEndpoint);
        }
        public TrafficManagerEndpoint SetTrafficManagerEndpoint(TrafficManagerEndpoint endpoint)
        {
            var parameters = new EndpointCreateOrUpdateParameters
            {
                Endpoint = endpoint.ToSDKEndpoint()
            };

            EndpointCreateOrUpdateResponse response = this.TrafficManagerManagementClient.Endpoints.CreateOrUpdate(
                endpoint.ResourceGroupName,
                endpoint.ProfileName,
                endpoint.Type,
                endpoint.Name,
                parameters);

            return(TrafficManagerClient.GetPowershellTrafficManagerEndpoint(
                       endpoint.ResourceGroupName,
                       endpoint.ProfileName,
                       endpoint.Type,
                       endpoint.Name,
                       response.Endpoint.Properties));
        }
        private static TrafficManagerEndpoint GetPowershellTrafficManagerEndpoint(string id, string resourceGroupName, string profileName, string endpointType, string endpointName, Endpoint sdkEndpoint)
        {
            return(new TrafficManagerEndpoint
            {
                Id = id,
                ResourceGroupName = resourceGroupName,
                ProfileName = profileName,
                Name = endpointName,
                Type = TrafficManagerEndpoint.ToShortEndpointType(endpointType),

                EndpointStatus = sdkEndpoint.EndpointStatus,
                EndpointMonitorStatus = sdkEndpoint.EndpointMonitorStatus,
                GeoMapping = sdkEndpoint.GeoMapping != null?sdkEndpoint.GeoMapping.ToList() : null,
                                 Location = sdkEndpoint.EndpointLocation,
                                 MinChildEndpoints = (uint?)sdkEndpoint.MinChildEndpoints,
                                 Priority = (uint?)sdkEndpoint.Priority,
                                 Target = sdkEndpoint.Target,
                                 TargetResourceId = sdkEndpoint.TargetResourceId,
                                 Weight = (uint?)sdkEndpoint.Weight,
            });
        }
        public TrafficManagerEndpoint CreateTrafficManagerEndpoint(string resourceGroupName, string profileName, string endpointType, string endpointName, string targetResourceId, string target, string endpointStatus, uint?weight, uint?priority, string endpointLocation, uint?minChildEndpoints, IList <string> geoMapping)
        {
            Endpoint response = this.TrafficManagerManagementClient.Endpoints.CreateOrUpdate(
                resourceGroupName,
                profileName,
                endpointType,
                endpointName,
                new Endpoint(name: endpointName, type: TrafficManagerEndpoint.ToFullEndpointType(endpointType))
            {
                EndpointLocation  = endpointLocation,
                EndpointStatus    = endpointStatus,
                GeoMapping        = geoMapping,
                MinChildEndpoints = minChildEndpoints,
                Priority          = priority,
                Target            = target,
                TargetResourceId  = targetResourceId,
                Weight            = weight,
            });

            return(TrafficManagerClient.GetPowershellTrafficManagerEndpoint(response.Id, resourceGroupName, profileName, endpointType, endpointName, response));
        }
Esempio n. 28
0
        public override void ExecuteCmdlet()
        {
            TrafficManagerEndpoint endpoint = new TrafficManagerEndpoint();

            endpoint.DomainName        = DomainName;
            endpoint.Location          = Location;
            endpoint.Status            = (EndpointStatus)Enum.Parse(typeof(EndpointStatus), Status);
            endpoint.Type              = (EndpointType)Enum.Parse(typeof(EndpointType), Type);
            endpoint.Weight            = Weight;
            endpoint.MinChildEndpoints = MinChildEndpoints;
            ProfileWithDefinition profile = TrafficManagerProfile.GetInstance();

            if (profile.Endpoints.Any(e => e.DomainName.Equals(endpoint.DomainName, StringComparison.InvariantCultureIgnoreCase)))
            {
                throw new Exception(
                          string.Format(Resources.AddTrafficManagerEndpointFailed, profile.Name, endpoint.DomainName));
            }

            profile.Endpoints.Add(endpoint);
            WriteObject(TrafficManagerProfile);
        }
        public void RemoveTrafficManagerEndpointSucceeds()
        {
            // Setup
            ProfileWithDefinition original = GetProfileWithDefinition();

            var existingEndpoint = new TrafficManagerEndpoint
            {
                DomainName = DomainName,
                Type       = EndpointType.Any,
                Status     = EndpointStatus.Enabled
            };

            original.Endpoints.Add(existingEndpoint);

            // Assert the endpoint exists
            Assert.IsTrue(original.Endpoints.Any(e => e.DomainName == DomainName));

            cmdlet = new RemoveAzureTrafficManagerEndpoint
            {
                DomainName            = DomainName,
                TrafficManagerProfile = original,
                CommandRuntime        = mockCommandRuntime
            };

            // Action
            cmdlet.ExecuteCmdlet();

            // Assert
            var actual = mockCommandRuntime.OutputPipeline[0] as ProfileWithDefinition;

            // All the properties stay the same except the endpoints
            AssertAllProfilePropertiesDontChangeExceptEndpoints(original, actual);

            // There is a new endpoint with the new domain name in "actual"
            Assert.IsNotNull(actual);
            Assert.IsFalse(actual.Endpoints.Any(e => e.DomainName == DomainName));
        }
        protected override void ProcessRecord()
        {
            TrafficManagerEndpoint trafficManagerEndpoint = null;

            if (this.ParameterSetName == "Fields")
            {
                trafficManagerEndpoint = this.TrafficManagerClient.GetTrafficManagerEndpoint(
                    this.ResourceGroupName,
                    this.ProfileName,
                    this.Type,
                    this.Name);
            }
            else if (this.ParameterSetName == "Object")
            {
                trafficManagerEndpoint = this.TrafficManagerClient.GetTrafficManagerEndpoint(
                    this.TrafficManagerEndpoint.ResourceGroupName,
                    this.TrafficManagerEndpoint.ProfileName,
                    this.TrafficManagerEndpoint.Type,
                    this.TrafficManagerEndpoint.Name);
            }

            this.WriteVerbose(ProjectResources.Success);
            this.WriteObject(trafficManagerEndpoint);
        }
        public TrafficManagerEndpoint SetTrafficManagerEndpoint(TrafficManagerEndpoint endpoint)
        {
            var parameters = new EndpointCreateOrUpdateParameters
            {
                Endpoint = endpoint.ToSDKEndpoint()
            };

            EndpointCreateOrUpdateResponse response = this.TrafficManagerManagementClient.Endpoints.CreateOrUpdate(
                endpoint.ResourceGroupName,
                endpoint.ProfileName,
                endpoint.Type,
                endpoint.Name,
                parameters);

            return TrafficManagerClient.GetPowershellTrafficManagerEndpoint(
                endpoint.Id,
                endpoint.ResourceGroupName,
                endpoint.ProfileName,
                endpoint.Type,
                endpoint.Name,
                response.Endpoint.Properties);
        }
        public bool EnableDisableTrafficManagerEndpoint(TrafficManagerEndpoint endpoint, bool shouldEnableEndpointStatus)
        {
            endpoint.EndpointStatus = shouldEnableEndpointStatus ? Constants.StatusEnabled : Constants.StatusDisabled;

            Endpoint sdkEndpoint = endpoint.ToSDKEndpoint();
            sdkEndpoint.Properties.EndpointLocation = null;
            sdkEndpoint.Properties.EndpointMonitorStatus = null;
            sdkEndpoint.Properties.Priority = null;
            sdkEndpoint.Properties.Weight = null;
            sdkEndpoint.Properties.Target = null;
            sdkEndpoint.Properties.TargetResourceId = null;

            var parameters = new EndpointUpdateParameters
            {
                Endpoint = sdkEndpoint
            };

            AzureOperationResponse response = this.TrafficManagerManagementClient.Endpoints.Update(
                endpoint.ResourceGroupName,
                endpoint.ProfileName,
                endpoint.Type,
                endpoint.Name,
                parameters);

            return response.StatusCode.Equals(HttpStatusCode.Created);
        }
        public bool DeleteTrafficManagerEndpoint(TrafficManagerEndpoint trafficManagerEndpoint)
        {
            AzureOperationResponse response = this.TrafficManagerManagementClient.Endpoints.Delete(
                trafficManagerEndpoint.ResourceGroupName,
                trafficManagerEndpoint.ProfileName,
                trafficManagerEndpoint.Type,
                trafficManagerEndpoint.Name);

            return response.StatusCode.Equals(HttpStatusCode.OK);
        }