public override void Execute()
        {
            base.Execute();

            var present = true;

            try
            {
                this.NetworkClient.NetworkManagementClient.VirtualHubBgpConnection.Get(this.ResourceGroupName, this.RouteServerName, this.PeerName);
            }
            catch (Exception ex)
            {
                if (ex is Microsoft.Azure.Management.Network.Models.ErrorException || ex is Rest.Azure.CloudException)
                {
                    // Resource is not present
                    present = false;
                }
                else
                {
                    throw;
                }
            }

            if (present)
            {
                throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.PeerName, this.ResourceGroupName, this.RouteServerName));
            }

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                PeerName,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.PeerName));
                PSRouteServerPeer peer = new PSRouteServerPeer
                {
                    PeerAsn = this.PeerAsn,
                    PeerIp  = this.PeerIp,
                    Name    = this.PeerName
                };
                string ipConfigName = "ipconfig1";

                var bgpConnectionModel = NetworkResourceManagerProfile.Mapper.Map <MNM.BgpConnection>(peer);

                this.NetworkClient.NetworkManagementClient.VirtualHubBgpConnection.CreateOrUpdate(this.ResourceGroupName, this.RouteServerName, this.PeerName, bgpConnectionModel);
                var virtualHub      = this.NetworkClient.NetworkManagementClient.VirtualHubs.Get(this.ResourceGroupName, this.RouteServerName);
                var virtualHubModel = NetworkResourceManagerProfile.Mapper.Map <PSVirtualHub>(virtualHub);
                virtualHubModel.ResourceGroupName = this.ResourceGroupName;
                virtualHubModel.Tag = TagsConversionHelper.CreateTagHashtable(virtualHub.Tags);
                AddBgpConnectionsToPSVirtualHub(virtualHubModel, ResourceGroupName, this.RouteServerName);
                AddIpConfigurtaionToPSVirtualHub(virtualHubModel, this.ResourceGroupName, this.RouteServerName, ipConfigName);

                var routeServerModel = new PSRouteServer(virtualHubModel);
                routeServerModel.Tag = TagsConversionHelper.CreateTagHashtable(virtualHub.Tags);

                WriteObject(routeServerModel, true);
            });
        }
        public override void Execute()
        {
            if (ParameterSetName.Equals(RouteServerPeerParameterSetNames.ByRouteServerPeerInputObject, StringComparison.OrdinalIgnoreCase))
            {
                PeerName = InputObject.Name;
                PeerAsn  = InputObject.PeerAsn;
                PeerIp   = InputObject.PeerIp;
            }
            else if (ParameterSetName.Equals(RouteServerPeerParameterSetNames.ByRouteServerPeerResourceId, StringComparison.OrdinalIgnoreCase))
            {
                var parsedResourceId = new ResourceIdentifier(ResourceId);
                PeerName = parsedResourceId.ResourceName;
            }

            base.Execute();

            var           present = true;
            BgpConnection existingBgpConnection = null;

            try
            {
                existingBgpConnection = this.NetworkClient.NetworkManagementClient.VirtualHubBgpConnection.Get(this.ResourceGroupName, this.RouteServerName, this.PeerName);
            }
            catch (Microsoft.Rest.Azure.CloudException exception)
            {
                if (exception.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    // Resource is not present
                    present = false;
                }
                else
                {
                    throw;
                }
            }

            if (!present)
            {
                throw new PSArgumentException(string.Format(Properties.Resources.ResourceNotFound, this.PeerName, this.ResourceGroupName, this.RouteServerName));
            }

            if (ParameterSetName.Equals(RouteServerPeerParameterSetNames.ByRouteServerPeerResourceId, StringComparison.OrdinalIgnoreCase))
            {
                var parsedResourceId = new ResourceIdentifier(ResourceId);
                PeerAsn = (uint)existingBgpConnection.PeerAsn;
                PeerIp  = existingBgpConnection.PeerIp;
            }

            ConfirmAction(
                Properties.Resources.SettingResourceMessage,
                PeerName,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.UpdatingLongRunningOperationMessage, this.ResourceGroupName, this.PeerName));
                PSRouteServerPeer peer = new PSRouteServerPeer
                {
                    Name    = this.PeerName,
                    PeerAsn = this.PeerAsn,
                    PeerIp  = this.PeerIp
                };

                var bgpConnectionModel = NetworkResourceManagerProfile.Mapper.Map <MNM.BgpConnection>(peer);

                this.NetworkClient.NetworkManagementClient.VirtualHubBgpConnection.CreateOrUpdate(this.ResourceGroupName, this.RouteServerName, this.PeerName, bgpConnectionModel);
                var virtualHub      = this.NetworkClient.NetworkManagementClient.VirtualHubs.Get(this.ResourceGroupName, this.RouteServerName);
                var virtualHubModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSVirtualHub>(virtualHub);
                virtualHubModel.ResourceGroupName = this.ResourceGroupName;
                virtualHubModel.Tag = TagsConversionHelper.CreateTagHashtable(virtualHub.Tags);
                AddBgpConnectionsToPSVirtualHub(virtualHubModel, ResourceGroupName, this.RouteServerName);
                AddIpConfigurtaionToPSVirtualHub(virtualHubModel, this.ResourceGroupName, this.RouteServerName);

                var routeServerModel = new PSRouteServer(virtualHubModel);
                routeServerModel.Tag = TagsConversionHelper.CreateTagHashtable(virtualHub.Tags);

                WriteObject(routeServerModel, true);
            });
        }