Ejemplo n.º 1
0
        public async Task <Response <VirtualHub> > GetAsync(string resourceGroupName, string virtualHubName, CancellationToken cancellationToken = default)
        {
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (virtualHubName == null)
            {
                throw new ArgumentNullException(nameof(virtualHubName));
            }

            using var message = CreateGetRequest(resourceGroupName, virtualHubName);
            await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);

            switch (message.Response.Status)
            {
            case 200:
            {
                VirtualHub value = default;
                using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);

                if (document.RootElement.ValueKind == JsonValueKind.Null)
                {
                    value = null;
                }
                else
                {
                    value = VirtualHub.DeserializeVirtualHub(document.RootElement);
                }
                return(Response.FromValue(value, message.Response));
            }
Ejemplo n.º 2
0
        public void AddBgpConnectionsToPSVirtualHub(VirtualHub virtualHub,
                                                    CNM.PSVirtualHub virtualHubModel,
                                                    string resourceGroupName,
                                                    string routerName)
        {
            var bgpConnections    = this.NetworkClient.NetworkManagementClient.VirtualHubBgpConnections.List(resourceGroupName, routerName);
            var bgpConnectionList = ListNextLink <BgpConnection> .GetAllResourcesByPollingNextLink(bgpConnections, this.NetworkClient.NetworkManagementClient.VirtualHubBgpConnections.ListNext);

            foreach (var connection in bgpConnectionList)
            {
                virtualHubModel.BgpConnections.Add(NetworkResourceManagerProfile.Mapper.Map <CNM.PSBgpConnection>(connection));
            }
        }
Ejemplo n.º 3
0
        private PSSecurityPartnerProvider CreateSecurityPartnerProvider()
        {
            string virtualHubResourceGroupName = this.ResourceGroupName; // default to common RG
            var    resolvedVirtualHub          = new VirtualHub();

            /// Resolve and Set the Virtual HUb
            if (this.VirtualHubId != null) // When Id is provided
            {
                var resourceInfo = new ResourceIdentifier(VirtualHubId);
                virtualHubResourceGroupName = resourceInfo.ResourceGroupName;
                this.VirtualHubName         = resourceInfo.ResourceName;
            }
            else if (this.VirtualHub != null) // When Hub is provided
            {
                this.VirtualHubName         = this.VirtualHub.Name;
                virtualHubResourceGroupName = this.VirtualHub.ResourceGroupName;
            }

            if (!string.IsNullOrWhiteSpace(this.VirtualHubName))
            {
                resolvedVirtualHub = this.VirtualHubClient.Get(virtualHubResourceGroupName, this.VirtualHubName);
            }

            var securityPartnerProvider = new PSSecurityPartnerProvider()
            {
                Name = this.Name,
                ResourceGroupName = this.ResourceGroupName,
                Location          = this.Location,
                VirtualHub        = resolvedVirtualHub.Id == null? null: new SubResource()
                {
                    Id = resolvedVirtualHub?.Id
                },
                SecurityProviderName = this.SecurityProviderName
            };

            // Map to the sdk object
            var securityPartnerProviderModel = NetworkResourceManagerProfile.Mapper.Map <MNM.SecurityPartnerProvider>(securityPartnerProvider);

            securityPartnerProviderModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

            // Execute the Create Security Partner Provider call
            this.SecurityPartnerProviderClient.CreateOrUpdate(this.ResourceGroupName, this.Name, securityPartnerProviderModel);

            return(this.GetSecurityPartnerProvider(this.ResourceGroupName, this.Name));
        }
        public virtual VirtualHubsCreateOrUpdateOperation StartCreateOrUpdate(string resourceGroupName, string virtualHubName, VirtualHub virtualHubParameters, CancellationToken cancellationToken = default)
        {
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException(nameof(resourceGroupName));
            }
            if (virtualHubName == null)
            {
                throw new ArgumentNullException(nameof(virtualHubName));
            }
            if (virtualHubParameters == null)
            {
                throw new ArgumentNullException(nameof(virtualHubParameters));
            }

            using var scope = _clientDiagnostics.CreateScope("VirtualHubsClient.StartCreateOrUpdate");
            scope.Start();
            try
            {
                var originalResponse = RestClient.CreateOrUpdate(resourceGroupName, virtualHubName, virtualHubParameters, cancellationToken);
                return(new VirtualHubsCreateOrUpdateOperation(_clientDiagnostics, _pipeline, RestClient.CreateCreateOrUpdateRequest(resourceGroupName, virtualHubName, virtualHubParameters).Request, originalResponse));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
 /// <summary>
 /// Creates a VirtualHub resource if it doesn't exist else updates the existing
 /// VirtualHub.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The resource group name of the VirtualHub.
 /// </param>
 /// <param name='virtualHubName'>
 /// The name of the VirtualHub.
 /// </param>
 /// <param name='virtualHubParameters'>
 /// Parameters supplied to create or update VirtualHub.
 /// </param>
 public static VirtualHub CreateOrUpdate(this IVirtualHubsOperations operations, string resourceGroupName, string virtualHubName, VirtualHub virtualHubParameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, virtualHubName, virtualHubParameters).GetAwaiter().GetResult());
 }
 /// <summary>
 /// Creates a VirtualHub resource if it doesn't exist else updates the existing
 /// VirtualHub.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The resource group name of the VirtualHub.
 /// </param>
 /// <param name='virtualHubName'>
 /// The name of the VirtualHub.
 /// </param>
 /// <param name='virtualHubParameters'>
 /// Parameters supplied to create or update VirtualHub.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <VirtualHub> BeginCreateOrUpdateAsync(this IVirtualHubsOperations operations, string resourceGroupName, string virtualHubName, VirtualHub virtualHubParameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, virtualHubName, virtualHubParameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }