예제 #1
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);
        }
예제 #2
0
        public PSExpressRouteConnection CreateOrUpdateExpressRouteConnection(string resourceGroupName, string expressRouteGatewayName, PSExpressRouteConnection expressRouteConnection, Hashtable tags)
        {
            var expressRouteConnectionModel = NetworkResourceManagerProfile.Mapper.Map <MNM.ExpressRouteConnection>(expressRouteConnection);

            this.ExpressRouteConnectionClient.CreateOrUpdate(resourceGroupName, expressRouteGatewayName, expressRouteConnection.Name, expressRouteConnectionModel);
            var connectionToReturn = this.GetExpressRouteConnection(resourceGroupName, expressRouteGatewayName, expressRouteConnection.Name);

            return(connectionToReturn);
        }