Ejemplo n.º 1
0
        /// <summary>
        /// Create cache.
        /// </summary>
        /// <param name="name">Name of the cache.</param>
        /// <param name="sku">Name of the SKU.</param>
        /// <param name="cacheSize">Size of cache.</param>
        /// <param name="skipGet">Skip get cache before creating it.</param>
        /// <returns>Cache object.</returns>
        public Cache Create(string name, string sku, int cacheSize, bool skipGet = false)
        {
            Cache cache;

            if (!skipGet)
            {
                try
                {
                    cache = this.Get(name);
                }
                catch (CloudErrorException ex)
                {
                    if (ex.Body.Error.Code == "ResourceNotFound")
                    {
                        cache = null;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                cache = null;
            }

            if (cache == null)
            {
                var cacheSku = new CacheSku()
                {
                    Name = sku
                };
                var subnetUri       = $"/subscriptions/{this.subscriptionId}/resourcegroups/{this.resourceGroup.Name}/providers/Microsoft.Network/virtualNetworks/{this.virtualNetwork.Name}/subnets/{this.subNet.Name}";
                var cacheParameters = new Cache()
                {
                    CacheSizeGB = cacheSize, Location = this.resourceGroup.Location, Sku = cacheSku, Subnet = subnetUri
                };
                cache = this.StoragecacheManagementClient.Caches.CreateOrUpdate(this.resourceGroup.Name, name, cacheParameters);
            }

            return(cache);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Execution cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            try
            {
                var cacheExists = this.HpcCacheClient.Caches.Get(this.ResourceGroupName, this.Name);
                throw new CloudException(string.Format("Cache name {0} already exists", this.Name));
            }
            catch (CloudErrorException ex)
            {
                if (ex.Body.Error.Code != "ResourceNotFound")
                {
                    throw;
                }
            }

            Utility.ValidateResourceGroup(this.ResourceGroupName);
            var cacheSku = new CacheSku()
            {
                Name = this.Sku
            };
            var tag             = this.Tag.ToDictionaryTags();
            var cacheParameters = new Cache()
            {
                CacheSizeGB = this.CacheSize, Location = this.Location, Sku = cacheSku, Subnet = this.SubnetUri, Tags = tag
            };

            if (this.ShouldProcess(this.Name, string.Format(Resources.CreateCache, this.ResourceGroupName, this.Name)))
            {
                try
                {
                    var cache = this.HpcCacheClient.Caches.CreateOrUpdate(this.ResourceGroupName, this.Name, cacheParameters);
                    this.WriteObject(new PSHPCCache(cache), enumerateCollection: true);
                }
                catch (CloudErrorException ex)
                {
                    throw new CloudException(string.Format("Exception: {0}", ex.Body.Error.Message));
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create cache.
        /// </summary>
        /// <param name="name">Name of the cache.</param>
        /// <param name="sku">Name of the SKU.</param>
        /// <param name="cacheSize">Size of cache.</param>
        /// <param name="identity">Cache identity type.</param>
        /// <param name="keyVaultResourceId">Describes a resource Id to source Key vault.</param>
        /// <param name="encryptionKeyURL">The URL referencing a key encryption key in key vault.</param>
        /// <param name="skipGet">Skip get cache before creating it.</param>
        /// <returns>Cache object.</returns>
        public Cache Create(string name, string sku, int cacheSize, CacheIdentity identity, KeyVaultKeyReferenceSourceVault keyVaultResourceId = null, string encryptionKeyURL = null, bool skipGet = false)
        {
            Cache cache;
            CacheEncryptionSettings cacheEncryptionSettings;
            KeyVaultKeyReference    keyVaultKeyReference;

            if (!skipGet)
            {
                try
                {
                    cache = this.Get(name);
                }
                catch (CloudErrorException ex)
                {
                    if (ex.Body.Error.Code == "ResourceNotFound")
                    {
                        cache = null;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                cache = null;
            }

            if (cache == null)
            {
                var cacheSku = new CacheSku()
                {
                    Name = sku
                };
                var subnetUri = $"/subscriptions/{this.subscriptionId}/resourcegroups/{this.resourceGroup.Name}/providers/Microsoft.Network/virtualNetworks/{this.virtualNetwork.Name}/subnets/{this.subNet.Name}";
                if (encryptionKeyURL is null || keyVaultResourceId is null)
                {
                    keyVaultKeyReference = new KeyVaultKeyReference()
                    {
                    };
                    cacheEncryptionSettings = new CacheEncryptionSettings()
                    {
                    };
                }
                else
                {
                    keyVaultKeyReference = new KeyVaultKeyReference()
                    {
                        KeyUrl      = encryptionKeyURL,
                        SourceVault = keyVaultResourceId,
                    };
                    cacheEncryptionSettings = new CacheEncryptionSettings()
                    {
                        KeyEncryptionKey = keyVaultKeyReference,
                    };
                }


                var cacheParameters = new Cache()
                {
                    CacheSizeGB        = cacheSize,
                    Location           = this.resourceGroup.Location,
                    Sku                = cacheSku,
                    Subnet             = subnetUri,
                    Identity           = identity,
                    EncryptionSettings = cacheEncryptionSettings,
                };
                cache = this.StoragecacheManagementClient.Caches.CreateOrUpdate(this.resourceGroup.Name, name, cacheParameters);
            }