public override void Execute()
        {
            if (ParameterSetName.Equals(CortexParameterSetNames.ByExpressRouteConnectionName, StringComparison.OrdinalIgnoreCase))
            {
                this.ResourceGroupName       = this.ResourceGroupName;
                this.ExpressRouteGatewayName = this.ExpressRouteGatewayName;
                this.Name = this.Name;
            }
            else if (ParameterSetName.Equals(CortexParameterSetNames.ByExpressRouteConnectionObject, StringComparison.OrdinalIgnoreCase))
            {
                this.ResourceId = this.InputObject.Id;

                this.SetResourceNames();
            }
            else if (ParameterSetName.Equals(CortexParameterSetNames.ByExpressRouteConnectionResourceId, StringComparison.OrdinalIgnoreCase))
            {
                this.SetResourceNames();
            }

            //// Get the expressRoutegateway object - this will throw not found if the object is not found
            PSExpressRouteGateway parentGateway = this.GetExpressRouteGateway(this.ResourceGroupName, this.ExpressRouteGatewayName);

            if (parentGateway == null ||
                parentGateway.ExpressRouteConnections == null ||
                !parentGateway.ExpressRouteConnections.Any(connection => connection.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase)))
            {
                throw new PSArgumentException(Properties.Resources.ExpressRouteConnectionNotFound, this.Name);
            }

            // TODO: drop this hack after ER Gateways backend updated with all the functionality exposed
            if (parentGateway.AutoScaleConfiguration.Bounds.Max < parentGateway.AutoScaleConfiguration.Bounds.Min)
            {
                parentGateway.AutoScaleConfiguration.Bounds.Max = parentGateway.AutoScaleConfiguration.Bounds.Min;
            }

            if (parentGateway.ExpressRouteConnections.Any())
            {
                var expressRouteConnectionToRemove = parentGateway.ExpressRouteConnections.FirstOrDefault(connection => connection.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase));
                if (expressRouteConnectionToRemove != null)
                {
                    base.Execute();

                    ConfirmAction(
                        Force.IsPresent,
                        string.Format(Properties.Resources.RemovingResource, this.Name),
                        Properties.Resources.RemoveResourceMessage,
                        this.Name,
                        () =>
                    {
                        parentGateway.ExpressRouteConnections.Remove(expressRouteConnectionToRemove);
                        this.CreateOrUpdateExpressRouteGateway(this.ResourceGroupName, this.ExpressRouteGatewayName, parentGateway, parentGateway.Tag);
                    });
                }
            }

            if (PassThru)
            {
                WriteObject(true);
            }
        }
예제 #2
0
        public override void Execute()
        {
            base.Execute();

            if (this.IsExpressRouteGatewayPresent(this.ResourceGroupName, this.Name))
            {
                throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName));
            }

            var expressRouteGateway = new PSExpressRouteGateway();

            expressRouteGateway.Name = this.Name;
            expressRouteGateway.ResourceGroupName = this.ResourceGroupName;
            expressRouteGateway.VirtualHub        = null;

            //// Resolve and Set the virtual hub
            if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase))
            {
                this.VirtualHubName = this.VirtualHub.Name;
            }
            else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubResourceId, StringComparison.OrdinalIgnoreCase))
            {
                var parsedResourceId = new ResourceIdentifier(this.VirtualHubId);
                this.VirtualHubName = parsedResourceId.ResourceName;
            }

            //// At this point, we should have the virtual hub name resolved. Fail this operation if it is not.
            if (string.IsNullOrWhiteSpace(this.VirtualHubName))
            {
                throw new PSArgumentException(Properties.Resources.VirtualHubRequiredForExpressRouteGateway);
            }

            var resolvedVirtualHub = new VirtualHubBaseCmdlet().GetVirtualHub(this.ResourceGroupName, this.VirtualHubName);

            expressRouteGateway.Location   = resolvedVirtualHub.Location;
            expressRouteGateway.VirtualHub = new PSVirtualHubId()
            {
                Id = resolvedVirtualHub.Id
            };

            if (this.MaxScaleUnits > 0 && this.MinScaleUnits > this.MaxScaleUnits)
            {
                throw new PSArgumentException(string.Format(Properties.Resources.InvalidAutoScaleConfiguration, this.MinScaleUnits, this.MaxScaleUnits));
            }

            expressRouteGateway.AutoScaleConfiguration            = new PSExpressRouteGatewayAutoscaleConfiguration();
            expressRouteGateway.AutoScaleConfiguration.Bounds     = new PSExpressRouteGatewayPropertiesAutoScaleConfigurationBounds();
            expressRouteGateway.AutoScaleConfiguration.Bounds.Min = Convert.ToInt32(this.MinScaleUnits);
            expressRouteGateway.AutoScaleConfiguration.Bounds.Max = (this.MaxScaleUnits > 0) ? Convert.ToInt32(this.MaxScaleUnits) : Convert.ToInt32(this.MinScaleUnits);

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                this.Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                WriteObject(this.CreateOrUpdateExpressRouteGateway(this.ResourceGroupName, this.Name, expressRouteGateway, this.Tag));
            });
        }
        public PSExpressRouteGateway CreateOrUpdateExpressRouteGateway(string resourceGroupName, string expressRouteGatewayName, PSExpressRouteGateway expressRouteGateway, Hashtable tags)
        {
            var expressRouteGatewayModel = NetworkResourceManagerProfile.Mapper.Map <MNM.ExpressRouteGateway>(expressRouteGateway);

            expressRouteGatewayModel.Tags = TagsConversionHelper.CreateTagDictionary(tags, validate: true);

            this.ExpressRouteGatewayClient.CreateOrUpdate(resourceGroupName, expressRouteGatewayName, expressRouteGatewayModel);
            PSExpressRouteGateway gatewayToReturn = this.GetExpressRouteGateway(resourceGroupName, expressRouteGatewayName);

            return(gatewayToReturn);
        }
예제 #4
0
        public override void Execute()
        {
            PSExpressRouteGateway existingExpressRouteGateway = null;

            if (ParameterSetName.Equals(CortexParameterSetNames.ByExpressRouteGatewayObject))
            {
                existingExpressRouteGateway = this.InputObject;
                this.ResourceGroupName      = this.InputObject.ResourceGroupName;
                this.Name = this.InputObject.Name;
            }
            else
            {
                if (ParameterSetName.Equals(CortexParameterSetNames.ByExpressRouteGatewayResourceId))
                {
                    var parsedResourceId = new ResourceIdentifier(ResourceId);
                    Name = parsedResourceId.ResourceName;
                    ResourceGroupName = parsedResourceId.ResourceGroupName;
                }

                existingExpressRouteGateway = this.GetExpressRouteGateway(this.ResourceGroupName, this.Name);
            }

            if (existingExpressRouteGateway == null)
            {
                throw new PSArgumentException(Properties.Resources.ExpressRouteGatewayNotFound);
            }

            if (this.MinScaleUnits > 0 || this.MaxScaleUnits > 0)
            {
                if (this.MinScaleUnits > this.MaxScaleUnits)
                {
                    throw new PSArgumentException(string.Format(Properties.Resources.InvalidAutoScaleConfiguration, this.MinScaleUnits, this.MaxScaleUnits));
                }

                existingExpressRouteGateway.AutoScaleConfiguration.Bounds.Min = Convert.ToInt32(this.MinScaleUnits);
                existingExpressRouteGateway.AutoScaleConfiguration.Bounds.Max = Convert.ToInt32(this.MaxScaleUnits);
            }

            ConfirmAction(
                Properties.Resources.SettingResourceMessage,
                this.Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.UpdatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                WriteObject(this.CreateOrUpdateExpressRouteGateway(this.ResourceGroupName, this.Name, existingExpressRouteGateway, this.Tag));
            });
        }
        public List <PSExpressRouteGateway> ListExpressRouteGateways(string resourceGroupName)
        {
            var expressRouteGateways = string.IsNullOrWhiteSpace(resourceGroupName) ?
                                       this.ExpressRouteGatewayClient.ListBySubscription() :                  //// List by sub id
                                       this.ExpressRouteGatewayClient.ListByResourceGroup(resourceGroupName); //// List by RG name

            List <PSExpressRouteGateway> gatewaysToReturn = new List <PSExpressRouteGateway>();

            if (expressRouteGateways != null)
            {
                foreach (MNM.ExpressRouteGateway gateway in expressRouteGateways.Value)
                {
                    PSExpressRouteGateway gatewayToReturn = ToPsExpressRouteGateway(gateway);
                    gatewayToReturn.ResourceGroupName = resourceGroupName;
                    gatewaysToReturn.Add(gatewayToReturn);
                }
            }

            return(gatewaysToReturn);
        }
        public List <PSExpressRouteGateway> ListExpressRouteGateways(string resourceGroupName)
        {
            var expressRouteGateways = ShouldListBySubscription(resourceGroupName, null) ?
                                       this.ExpressRouteGatewayClient.ListBySubscription() :                  //// List by sub id
                                       this.ExpressRouteGatewayClient.ListByResourceGroup(resourceGroupName); //// List by RG name

            List <PSExpressRouteGateway> gatewaysToReturn = new List <PSExpressRouteGateway>();

            if (expressRouteGateways != null)
            {
                foreach (MNM.ExpressRouteGateway gateway in expressRouteGateways.Value)
                {
                    PSExpressRouteGateway gatewayToReturn = ToPsExpressRouteGateway(gateway);
                    gatewayToReturn.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(gateway.Id);
                    gatewaysToReturn.Add(gatewayToReturn);
                }
            }

            return(gatewaysToReturn);
        }
예제 #7
0
        private PSExpressRouteConnection CreateExpressRouteConnection()
        {
            base.Execute();
            PSExpressRouteGateway expressRouteGateway = null;

            //// Resolve the ExpressRouteGateway
            if (ParameterSetName.Contains(CortexParameterSetNames.ByExpressRouteGatewayObject))
            {
                this.ResourceGroupName       = this.ExpressRouteGatewayObject.ResourceGroupName;
                this.ExpressRouteGatewayName = this.ExpressRouteGatewayObject.Name;
            }
            else if (ParameterSetName.Contains(CortexParameterSetNames.ByExpressRouteGatewayResourceId))
            {
                var parsedResourceId = new ResourceIdentifier(this.ParentResourceId);
                this.ResourceGroupName       = parsedResourceId.ResourceGroupName;
                this.ExpressRouteGatewayName = parsedResourceId.ResourceName;
            }

            if (string.IsNullOrWhiteSpace(this.ResourceGroupName) || string.IsNullOrWhiteSpace(this.ExpressRouteGatewayName))
            {
                throw new PSArgumentException(Properties.Resources.ExpressRouteGatewayRequiredToCreateExpressRouteConnection);
            }

            if (this.IsExpressRouteConnectionPresent(this.ResourceGroupName, this.ExpressRouteGatewayName, this.Name))
            {
                throw new PSArgumentException(string.Format(Properties.Resources.ChildResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName, this.ExpressRouteGatewayName));
            }

            //// At this point, we should have the resource name and the resource group for the parent ExpressRouteGateway resolved.
            //// This will throw not found exception if the ExpressRouteGateway does not exist
            expressRouteGateway = this.GetExpressRouteGateway(this.ResourceGroupName, this.ExpressRouteGatewayName);
            if (expressRouteGateway == null)
            {
                throw new PSArgumentException(Properties.Resources.ParentExpressRouteGatewayNotFound);
            }

            var peeringResourceId = new PSExpressRouteCircuitPeeringId()
            {
                Id = this.ExpressRouteCircuitPeeringId
            };

            PSExpressRouteConnection expressRouteConnection = new PSExpressRouteConnection
            {
                Name = this.Name,
                ExpressRouteCircuitPeering = peeringResourceId,
                EnableInternetSecurity     = this.EnableInternetSecurity.IsPresent
            };

            if (this.RoutingConfiguration != null)
            {
                if (this.RoutingConfiguration.VnetRoutes != null && this.RoutingConfiguration.VnetRoutes.StaticRoutes != null && this.RoutingConfiguration.VnetRoutes.StaticRoutes.Any())
                {
                    throw new PSArgumentException(Properties.Resources.StaticRoutesNotSupportedForThisRoutingConfiguration);
                }

                expressRouteConnection.RoutingConfiguration = RoutingConfiguration;
            }

            // Set the auth key, if specified
            if (!string.IsNullOrWhiteSpace(this.AuthorizationKey))
            {
                expressRouteConnection.AuthorizationKey = this.AuthorizationKey;
            }

            // Set routing weight, if specified
            if (this.RoutingWeight > 0)
            {
                expressRouteConnection.RoutingWeight = this.RoutingWeight;
            }

            WriteVerbose(string.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));

            PSExpressRouteConnection connectionToReturn = null;

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                this.Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                this.CreateOrUpdateExpressRouteConnection(this.ResourceGroupName, this.ExpressRouteGatewayName, expressRouteConnection, expressRouteGateway.Tag);

                var createdOrUpdatedExpressRouteGateway = this.GetExpressRouteGateway(this.ResourceGroupName, this.ExpressRouteGatewayName);
                connectionToReturn = createdOrUpdatedExpressRouteGateway.ExpressRouteConnections.FirstOrDefault(connection => connection.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase));
            });

            return(connectionToReturn);
        }
        public override void Execute()
        {
            base.Execute();

            if (ParameterSetName.Equals(CortexParameterSetNames.ByExpressRouteConnectionName, StringComparison.OrdinalIgnoreCase))
            {
                this.ResourceGroupName       = this.ResourceGroupName;
                this.ExpressRouteGatewayName = this.ExpressRouteGatewayName;
                this.Name = this.Name;
            }
            else if (ParameterSetName.Equals(CortexParameterSetNames.ByExpressRouteConnectionObject, StringComparison.OrdinalIgnoreCase))
            {
                this.ResourceId = this.InputObject.Id;

                this.SetResourceNames();
            }
            else if (ParameterSetName.Equals(CortexParameterSetNames.ByExpressRouteConnectionResourceId, StringComparison.OrdinalIgnoreCase))
            {
                this.SetResourceNames();
            }

            //// Get the expressRoutegateway object - this will throw not found if the object is not found
            PSExpressRouteGateway expressRouteGateway = this.GetExpressRouteGateway(this.ResourceGroupName, this.ExpressRouteGatewayName);

            if (expressRouteGateway == null ||
                expressRouteGateway.ExpressRouteConnections == null ||
                !expressRouteGateway.ExpressRouteConnections.Any(connection => connection.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase)))
            {
                throw new PSArgumentException(Properties.Resources.ExpressRouteConnectionNotFound);
            }

            var expressRouteConnectionToModify = expressRouteGateway.ExpressRouteConnections.FirstOrDefault(connection => connection.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase));

            if (ParameterSetName.Equals(CortexParameterSetNames.ByExpressRouteConnectionObject, StringComparison.OrdinalIgnoreCase))
            {
                expressRouteConnectionToModify = this.InputObject;
            }

            // Set the auth key, if specified
            if (!string.IsNullOrWhiteSpace(this.AuthorizationKey))
            {
                expressRouteConnectionToModify.AuthorizationKey = this.AuthorizationKey;
            }

            // Set routing weight, if specified
            if (this.RoutingWeight > 0)
            {
                expressRouteConnectionToModify.RoutingWeight = this.RoutingWeight;
            }

            // TODO: drop this hack after ER Gateways backend updated with all the functionality exposed
            if (expressRouteGateway.AutoScaleConfiguration.Bounds.Max < expressRouteGateway.AutoScaleConfiguration.Bounds.Min)
            {
                expressRouteGateway.AutoScaleConfiguration.Bounds.Max = expressRouteGateway.AutoScaleConfiguration.Bounds.Min;
            }

            WriteVerbose(string.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                this.Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                this.CreateOrUpdateExpressRouteConnection(this.ResourceGroupName, this.ExpressRouteGatewayName, expressRouteConnectionToModify, expressRouteGateway.Tag);
            });
        }