Пример #1
0
        public static PSResourceGroup ToPSResourceGroup(this ResourceGroup resourceGroup)
        {
            var result = new PSResourceGroup
            {
                ResourceGroupName = resourceGroup.Name,
                Location          = resourceGroup.Location,
                ProvisioningState = resourceGroup.Properties == null ? null : resourceGroup.Properties.ProvisioningState,
                Tags       = TagsConversionHelper.CreateTagHashtable(resourceGroup.Tags),
                ResourceId = resourceGroup.Id,
                ManagedBy  = resourceGroup.ManagedBy
            };

            return(result);
        }
Пример #2
0
        public override void Execute()
        {
            base.Execute();


            var vRouteTable = new PSRouteTable
            {
                DisableBgpRoutePropagation = this.DisableBgpRoutePropagation,
                Location = this.Location,
                Routes   = this.Route,
            };

            var vRouteTableModel = NetworkResourceManagerProfile.Mapper.Map <MNM.RouteTable>(vRouteTable);

            vRouteTableModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
            var present = true;

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

            ConfirmAction(
                Force.IsPresent,
                string.Format(Properties.Resources.OverwritingResource, Name),
                Properties.Resources.CreatingResourceMessage,
                Name,
                () =>
            {
                this.NetworkClient.NetworkManagementClient.RouteTables.CreateOrUpdate(this.ResourceGroupName, this.Name, vRouteTableModel);
                var getRouteTable = this.NetworkClient.NetworkManagementClient.RouteTables.Get(this.ResourceGroupName, this.Name);
                var psRouteTable  = NetworkResourceManagerProfile.Mapper.Map <PSRouteTable>(getRouteTable);
                psRouteTable.ResourceGroupName = this.ResourceGroupName;
                psRouteTable.Tag = TagsConversionHelper.CreateTagHashtable(getRouteTable.Tags);
                WriteObject(psRouteTable, true);
            },
                () => present);
        }
        /// <summary>
        /// Convert a Management.Sql.LegacySdk.Models.ManagedInstance to AzureSqlDatabaseManagedInstanceModel
        /// </summary>
        /// <param name="resourceGroupName">The resource group the managed instance is in</param>
        /// <param name="resp">The management client managed instance response to convert</param>
        /// <returns>The converted managed instance model</returns>
        private static AzureSqlManagedInstanceModel CreateManagedInstanceModelFromResponse(Management.Sql.Models.ManagedInstance resp)
        {
            AzureSqlManagedInstanceModel managedInstance = new AzureSqlManagedInstanceModel();

            // Extract the resource group name from the ID.
            // ID is in the form:
            // /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rgName/providers/Microsoft.Sql/managedInstances/managedInstanceName
            string[] segments = resp.Id.Split('/');
            managedInstance.ResourceGroupName = segments[4];

            managedInstance.ManagedInstanceName = resp.Name;
            managedInstance.Id = resp.Id;
            managedInstance.FullyQualifiedDomainName = resp.FullyQualifiedDomainName;
            managedInstance.AdministratorLogin       = resp.AdministratorLogin;
            managedInstance.Location = resp.Location;
            managedInstance.Tags     = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(resp.Tags), false);
            managedInstance.Identity = resp.Identity;
            managedInstance.FullyQualifiedDomainName = resp.FullyQualifiedDomainName;
            managedInstance.SubnetId                  = resp.SubnetId;
            managedInstance.LicenseType               = resp.LicenseType;
            managedInstance.VCores                    = resp.VCores;
            managedInstance.StorageSizeInGB           = resp.StorageSizeInGB;
            managedInstance.Collation                 = resp.Collation;
            managedInstance.PublicDataEndpointEnabled = resp.PublicDataEndpointEnabled;
            managedInstance.ProxyOverride             = resp.ProxyOverride;
            managedInstance.TimezoneId                = resp.TimezoneId;
            managedInstance.DnsZone                   = resp.DnsZone;
            managedInstance.InstancePoolName          = resp.InstancePoolId != null ?
                                                        new ResourceIdentifier(resp.InstancePoolId).ResourceName : null;
            managedInstance.MinimalTlsVersion          = resp.MinimalTlsVersion;
            managedInstance.BackupStorageRedundancy    = MapInternalBackupStorageRedundancyToExternal(resp.StorageAccountType);
            managedInstance.MaintenanceConfigurationId = resp.MaintenanceConfigurationId;

            Management.Internal.Resources.Models.Sku sku = new Management.Internal.Resources.Models.Sku();
            sku.Name   = resp.Sku.Name;
            sku.Tier   = resp.Sku.Tier;
            sku.Family = resp.Sku.Family;

            managedInstance.Sku            = sku;
            managedInstance.Administrators = resp.Administrators;

            if (managedInstance.Administrators != null && managedInstance.Administrators.AdministratorType == null)
            {
                managedInstance.Administrators.AdministratorType = "ActiveDirectory";
            }
            managedInstance.PrimaryUserAssignedIdentityId = resp.PrimaryUserAssignedIdentityId;
            managedInstance.KeyId = resp.KeyId;

            return(managedInstance);
        }
 public static PSAfdProfile ToPSAfdProfile(this SdkAfdProfile sdkAfdProfile)
 {
     return(new PSAfdProfile
     {
         Id = sdkAfdProfile.Id,
         Name = sdkAfdProfile.Name,
         Type = sdkAfdProfile.Type,
         ProvisioningState = sdkAfdProfile.ProvisioningState,
         Location = sdkAfdProfile.Location,
         Tags = TagsConversionHelper.CreateTagHashtable(sdkAfdProfile.Tags),
         ResourceState = sdkAfdProfile.ResourceState,
         Sku = sdkAfdProfile.Sku.Name
     });
 }
Пример #5
0
 public PSAttestation(AttestationProvider attestation)
 {
     Id       = attestation.Id;
     Location = attestation.Location;
     if (!attestation.Id.StartsWith("/providers/"))
     {
         ResourceGroupName = new ResourceIdentifier(attestation.Id).ResourceGroupName;
     }
     Name       = attestation.Name;
     Status     = attestation.Status;
     TrustModel = attestation.TrustModel;
     AttestUri  = attestation.AttestUri;
     Tags       = TagsConversionHelper.CreateTagHashtable(attestation.Tags);
 }
Пример #6
0
        public override void Execute()
        {
            base.Execute();

            if (string.Equals(this.ParameterSetName, VirtualRouterParameterSetNames.ByVirtualRouterResourceId, StringComparison.OrdinalIgnoreCase))
            {
                var resourceInfo = new ResourceIdentifier(ResourceId);
                ResourceGroupName = resourceInfo.ResourceGroupName;
                RouterName        = resourceInfo.ResourceName;
            }

            if (ShouldGetByName(ResourceGroupName, RouterName))
            {
                var vVirtualRouter      = this.NetworkClient.NetworkManagementClient.VirtualRouters.Get(ResourceGroupName, RouterName);
                var vVirtualRouterModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSVirtualRouter>(vVirtualRouter);
                vVirtualRouterModel.ResourceGroupName = this.ResourceGroupName;
                vVirtualRouterModel.Tag = TagsConversionHelper.CreateTagHashtable(vVirtualRouter.Tags);
                AddPeeringsToPSVirtualRouter(vVirtualRouter, vVirtualRouterModel, ResourceGroupName, RouterName);
                WriteObject(vVirtualRouterModel, true);
            }
            else
            {
                IPage <VirtualRouter> vVirtualRouterPage;
                if (ShouldListByResourceGroup(ResourceGroupName, RouterName))
                {
                    vVirtualRouterPage = this.NetworkClient.NetworkManagementClient.VirtualRouters.ListByResourceGroup(this.ResourceGroupName);
                }
                else
                {
                    vVirtualRouterPage = this.NetworkClient.NetworkManagementClient.VirtualRouters.List();
                }

                var vVirtualRouterList = ListNextLink <VirtualRouter> .GetAllResourcesByPollingNextLink(vVirtualRouterPage,
                                                                                                        this.NetworkClient.NetworkManagementClient.VirtualRouters.ListNext);

                List <PSVirtualRouter> psVirtualRouterList = new List <PSVirtualRouter>();
                foreach (var vVirtualRouter in vVirtualRouterList)
                {
                    RouterName = vVirtualRouter.Name;
                    var vVirtualRouterModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSVirtualRouter>(vVirtualRouter);
                    vVirtualRouterModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(vVirtualRouter.Id);
                    vVirtualRouterModel.Tag = TagsConversionHelper.CreateTagHashtable(vVirtualRouter.Tags);
                    AddPeeringsToPSVirtualRouter(vVirtualRouter, vVirtualRouterModel, ResourceGroupName, RouterName);

                    psVirtualRouterList.Add(vVirtualRouterModel);
                }
                WriteObject(psVirtualRouterList, true);
            }
        }
        /// <summary>
        /// Construct AzureSqlDatabaseModel from Management.Sql.Database object
        /// </summary>
        /// <param name="resourceGroup">Resource group</param>
        /// <param name="serverName">Server name</param>
        /// <param name="database">Database object</param>
        public AzureSqlDatabaseModel(string resourceGroup, string serverName, Management.Sql.Models.Database database)
        {
            ResourceGroupName = resourceGroup;
            ServerName        = serverName;
            CollationName     = database.Collation;
            CreationDate      = database.CreationDate.Value;
            MaxSizeBytes      = (long)database.MaxSizeBytes;
            DatabaseName      = database.Name;
            Status            = database.Status;
            Tags                = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(database.Tags), false);
            ElasticPoolName     = database.ElasticPoolName;
            Location            = database.Location;
            ResourceId          = database.Id;
            CreateMode          = database.CreateMode;
            EarliestRestoreDate = database.EarliestRestoreDate;

            CurrentServiceObjectiveName = database.CurrentServiceObjectiveName;

            DatabaseId = database.DatabaseId.Value;

            Edition = database.Edition;

            RequestedServiceObjectiveName = database.RequestedServiceObjectiveName;

            DatabaseReadScale readScale;

            if (Enum.TryParse <DatabaseReadScale>(database.ReadScale.ToString(), true, out readScale))
            {
                ReadScale = readScale;
            }

            ZoneRedundant = database.ZoneRedundant;

            Capacity = database.Sku == null ? (int?)null : database.Sku.Capacity;

            Family = database.Sku == null ? null : database.Sku.Family;

            SkuName = database.Sku == null ? null : database.Sku.Name;

            LicenseType = database.LicenseType;

            AutoPauseDelayInMinutes          = database.AutoPauseDelay;
            MinimumCapacity                  = database.MinCapacity;
            HighAvailabilityReplicaCount     = database.HighAvailabilityReplicaCount;
            CurrentBackupStorageRedundancy   = database.CurrentBackupStorageRedundancy;
            RequestedBackupStorageRedundancy = database.RequestedBackupStorageRedundancy;
            SecondaryType = database.SecondaryType;
            MaintenanceConfigurationId = database.MaintenanceConfigurationId;
        }
        public PSNetworkInterface ToPsNetworkInterface(NetworkInterface nic)
        {
            var psNic = Mapper.Map <PSNetworkInterface>(nic);

            psNic.Tag = TagsConversionHelper.CreateTagHashtable(nic.Tags);

            foreach (var ipconfig in psNic.IpConfigurations)
            {
                ipconfig.LoadBalancerBackendAddressPools       = ipconfig.LoadBalancerBackendAddressPools ?? new List <PSBackendAddressPool>();
                ipconfig.LoadBalancerInboundNatRules           = ipconfig.LoadBalancerInboundNatRules ?? new List <PSInboundNatRule>();
                ipconfig.ApplicationGatewayBackendAddressPools = ipconfig.ApplicationGatewayBackendAddressPools ?? new List <PSApplicationGatewayBackendAddressPool>();
            }

            return(psNic);
        }
Пример #9
0
 /// <summary>
 /// Construct AzureSqlServerfailoverGroupModel from Management.Sql.LegacySdk.Models.FailoverGroup object
 /// </summary>
 /// <param name="resourceGroupName">Resource group</param>
 /// <param name="serverName">Server name</param>
 /// <param name="advisorName">Advisor name</param>
 /// <param name="failoverGroup">Recommended Action object</param>
 public AzureSqlFailoverGroupModel(string resourceGroupName, string serverName, string failoverGroupName, Management.Sql.LegacySdk.Models.FailoverGroup failoverGroup)
 {
     ResourceGroupName = resourceGroupName;
     ServerName        = serverName;
     FailoverGroupName = failoverGroup.Name;
     Id       = failoverGroup.Id;
     Location = failoverGroup.Location;
     FailoverGroupReadOnlyEndpoint  = failoverGroup.Properties.ReadOnlyEndpoint;
     FailoverGroupReadWriteEndpoint = failoverGroup.Properties.ReadWriteEndpoint;
     PartnerServers   = failoverGroup.Properties.PartnerServers;
     Databases        = failoverGroup.Properties.Databases;
     ReplicationRole  = failoverGroup.Properties.ReplicationRole;
     ReplicationState = failoverGroup.Properties.ReplicationState;
     Tags             = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(failoverGroup.Tags), false);
 }
Пример #10
0
 public static PSAfdEndpoint ToPSAfdEndpoint(this SdkAfdEndpoint sdkAfdEndpoint)
 {
     return(new PSAfdEndpoint
     {
         Id = sdkAfdEndpoint.Id,
         Name = sdkAfdEndpoint.Name,
         Type = sdkAfdEndpoint.Type,
         ProvisioningState = sdkAfdEndpoint.ProvisioningState,
         Location = sdkAfdEndpoint.Location,
         Tags = TagsConversionHelper.CreateTagHashtable(sdkAfdEndpoint.Tags),
         HostName = sdkAfdEndpoint.HostName,
         OriginResponseTimeoutSeconds = sdkAfdEndpoint.OriginResponseTimeoutSeconds,
         EnabledState = sdkAfdEndpoint.EnabledState
     });
 }
        private static PSPrivateDnsZone ToPrivateDnsZone(PrivateZone zone)
        {
            PrivateDnsUtils.GetResourceGroupNameFromResourceId(zone.Id, out var resourceGroupName);

            return(new PSPrivateDnsZone()
            {
                Name = zone.Name,
                ResourceId = zone.Id,
                ResourceGroupName = resourceGroupName,
                Etag = zone.Etag,
                Tags = TagsConversionHelper.CreateTagHashtable(zone.Tags),
                NumberOfRecordSets = zone.NumberOfRecordSets,
                MaxNumberOfRecordSets = zone.MaxNumberOfRecordSets,
            });
        }
Пример #12
0
        public override void Execute()
        {
            base.Execute();


            var vDdosProtectionPlan = new PSDdosProtectionPlan
            {
                Location = this.Location,
            };

            var vDdosProtectionPlanModel = NetworkResourceManagerProfile.Mapper.Map <MNM.DdosProtectionPlan>(vDdosProtectionPlan);

            vDdosProtectionPlanModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
            var present = true;

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

            ConfirmAction(
                true,
                string.Format(Properties.Resources.OverwritingResource, Name),
                Properties.Resources.CreatingResourceMessage,
                Name,
                () =>
            {
                this.NetworkClient.NetworkManagementClient.DdosProtectionPlans.CreateOrUpdate(this.ResourceGroupName, this.Name, vDdosProtectionPlanModel);
                var getDdosProtectionPlan = this.NetworkClient.NetworkManagementClient.DdosProtectionPlans.Get(this.ResourceGroupName, this.Name);
                var psDdosProtectionPlan  = NetworkResourceManagerProfile.Mapper.Map <PSDdosProtectionPlan>(getDdosProtectionPlan);
                psDdosProtectionPlan.ResourceGroupName = this.ResourceGroupName;
                psDdosProtectionPlan.Tag = TagsConversionHelper.CreateTagHashtable(getDdosProtectionPlan.Tags);
                WriteObject(psDdosProtectionPlan, true);
            },
                () => present);
        }
Пример #13
0
        /// <summary>
        /// Construct AzureSqlDatabaseModel from Management.Sql.LegacySdk.Models.Database object
        /// </summary>
        /// <param name="resourceGroup">Resource group</param>
        /// <param name="serverName">Server name</param>
        /// <param name="database">Database object</param>
        public AzureSqlDatabaseModel(string resourceGroup, string serverName, Management.Sql.LegacySdk.Models.Database database)
        {
            Guid id = Guid.Empty;

            ResourceGroupName           = resourceGroup;
            ServerName                  = serverName;
            CollationName               = database.Properties.Collation;
            CreationDate                = database.Properties.CreationDate;
            CurrentServiceObjectiveName = database.Properties.ServiceObjective;
            MaxSizeBytes                = database.Properties.MaxSizeBytes;
            DatabaseName                = database.Name;
            Status              = database.Properties.Status;
            Tags                = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(database.Tags), false);
            ElasticPoolName     = database.Properties.ElasticPoolName;
            Location            = database.Location;
            ResourceId          = database.Id;
            CreateMode          = database.Properties.CreateMode;
            EarliestRestoreDate = database.Properties.EarliestRestoreDate;

            Guid.TryParse(database.Properties.CurrentServiceObjectiveId, out id);
            CurrentServiceObjectiveId = id;

            Guid.TryParse(database.Properties.DatabaseId, out id);
            DatabaseId = id;

            Edition = database.Properties.Edition;

            Guid.TryParse(database.Properties.RequestedServiceObjectiveId, out id);
            RequestedServiceObjectiveId = id;

            DatabaseReadScale readScale;

            if (Enum.TryParse <DatabaseReadScale>(database.Properties.ReadScale, true, out readScale))
            {
                ReadScale = readScale;
            }

            ZoneRedundant                    = false;
            AutoPauseDelayInMinutes          = null;
            MinimumCapacity                  = null;
            ReadReplicaCount                 = null;
            HighAvailabilityReplicaCount     = null;
            CurrentBackupStorageRedundancy   = null;
            RequestedBackupStorageRedundancy = null;
            SecondaryType                    = null;
            MaintenanceConfigurationId       = null;
            EnableLedger = false;
        }
        public override void Execute()
        {
            base.Execute();


            var vApplicationSecurityGroup = new PSApplicationSecurityGroup
            {
                Location = this.Location,
            };

            var vApplicationSecurityGroupModel = Mapper.Map <MNM.ApplicationSecurityGroup>(vApplicationSecurityGroup);

            vApplicationSecurityGroupModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
            var present = true;

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

            ConfirmAction(
                Force.IsPresent,
                string.Format(Properties.Resources.OverwritingResource, Name),
                Properties.Resources.CreatingResourceMessage,
                Name,
                () =>
            {
                this.NetworkClient.NetworkManagementClient.ApplicationSecurityGroups.CreateOrUpdate(this.ResourceGroupName, this.Name, vApplicationSecurityGroupModel);
                var getApplicationSecurityGroup = this.NetworkClient.NetworkManagementClient.ApplicationSecurityGroups.Get(this.ResourceGroupName, this.Name);
                var psApplicationSecurityGroup  = Mapper.Map <PSApplicationSecurityGroup>(getApplicationSecurityGroup);
                psApplicationSecurityGroup.ResourceGroupName = this.ResourceGroupName;
                psApplicationSecurityGroup.Tag = TagsConversionHelper.CreateTagHashtable(getApplicationSecurityGroup.Tags);
                WriteObject(psApplicationSecurityGroup, true);
            },
                () => present);
        }
Пример #15
0
 private static DnsZone ToDnsZone(Zone zone)
 {
     return(new DnsZone()
     {
         Name = zone.Name,
         ResourceGroupName = ExtractResourceGroupNameFromId(zone.Id),
         Etag = zone.Etag,
         Tags = TagsConversionHelper.CreateTagHashtable(zone.Tags),
         NameServers = zone.NameServers != null?zone.NameServers.ToList() : new List <string>(),
                           NumberOfRecordSets = zone.NumberOfRecordSets,
                           MaxNumberOfRecordSets = zone.MaxNumberOfRecordSets,
                           ZoneType = zone.ZoneType,
                           RegistrationVirtualNetworkIds = zone.RegistrationVirtualNetworks.ToVirtualNetworkIds().ToList(),
                           ResolutionVirtualNetworkIds = zone.ResolutionVirtualNetworks.ToVirtualNetworkIds().ToList(),
     });
 }
        public override void ExecuteCmdlet()
        {
            var currentAccount = DataLakeStoreClient.GetAccount(ResourceGroupName, Name);
            var location       = currentAccount.Location;

            if (string.IsNullOrEmpty(DefaultGroup))
            {
                DefaultGroup = currentAccount.DefaultGroup;
            }

            if (Tags == null)
            {
                Tags = TagsConversionHelper.CreateTagHashtable(currentAccount.Tags);
            }

            if (!TrustedIdProviderState.HasValue)
            {
                TrustedIdProviderState = currentAccount.TrustedIdProviderState;
            }

            if (!FirewallState.HasValue)
            {
                FirewallState = currentAccount.FirewallState;
            }

            if (AllowAzureIpState.HasValue && FirewallState.Value == Management.DataLake.Store.Models.FirewallState.Disabled)
            {
                WriteWarning(string.Format(Resources.FirewallDisabledWarning, Name));
            }

            if (!AllowAzureIpState.HasValue)
            {
                AllowAzureIpState = currentAccount.FirewallAllowAzureIps;
            }

            WriteObject(
                new PSDataLakeStoreAccount(
                    DataLakeStoreClient.UpdateAccount(
                        ResourceGroupName,
                        Name,
                        DefaultGroup,
                        TrustedIdProviderState.GetValueOrDefault(),
                        FirewallState.GetValueOrDefault(),
                        AllowAzureIpState.GetValueOrDefault(),
                        Tags,
                        tier: Tier)));
        }
        public override void ExecuteCmdlet()
        {
            string capacityName      = Name;
            string resourceGroupName = ResourceGroupName;

            if (!string.IsNullOrEmpty(ResourceId))
            {
                PowerBIUtils.GetResourceGroupNameAndCapacityName(ResourceId, out resourceGroupName, out capacityName);
            }
            else if (InputObject != null)
            {
                PowerBIUtils.GetResourceGroupNameAndCapacityName(InputObject.Id, out resourceGroupName, out capacityName);
            }

            if (string.IsNullOrEmpty(capacityName))
            {
                WriteExceptionError(new PSArgumentNullException("Name", "Name of capacity not specified"));
            }

            if (ShouldProcess(capacityName, Resources.UpdatingPowerBIEmbeddedCapacity))
            {
                PSPowerBIEmbeddedCapacity currentCapacity = null;
                if (!PowerBIClient.TestCapacity(resourceGroupName, capacityName, out currentCapacity))
                {
                    throw new InvalidOperationException(string.Format(Properties.Resources.CapacityDoesNotExist, capacityName));
                }

                var availableSkus = PowerBIClient.ListSkusForExisting(resourceGroupName, capacityName);
                if (Sku != null && !availableSkus.Value.Any(v => v.Sku.Name == Sku))
                {
                    throw new InvalidOperationException(string.Format(Resources.InvalidSku, Sku, String.Join(",", availableSkus.Value.Select(v => v.Sku.Name))));
                }

                var location = currentCapacity.Location;
                if (Tag == null && currentCapacity.Tag != null)
                {
                    Tag = TagsConversionHelper.CreateTagHashtable(currentCapacity.Tag);
                }

                PSPowerBIEmbeddedCapacity updateCapacity = PowerBIClient.CreateOrUpdateCapacity(resourceGroupName, capacityName, location, Sku, Tag, Administrator, currentCapacity);

                if (PassThru.IsPresent)
                {
                    WriteObject(updateCapacity);
                }
            }
        }
Пример #18
0
        public override void ExecuteCmdlet()
        {
            var currentAccount = DataLakeStoreClient.GetAccount(ResourceGroupName, Name);
            var location       = currentAccount.Location;

            if (string.IsNullOrEmpty(DefaultGroup))
            {
                DefaultGroup = currentAccount.Properties.DefaultGroup;
            }

            if (Tags == null)
            {
                Tags = TagsConversionHelper.CreateTagHashtable(currentAccount.Tags);
            }

            WriteObject(DataLakeStoreClient.CreateOrUpdateAccount(ResourceGroupName, Name, DefaultGroup, location, Tags));
        }
Пример #19
0
        public PSVault(KeyVaultManagement.Vault vault, PSResourceManagerModels.ActiveDirectory.ActiveDirectoryClient adClient)
        {
            var vaultTenantDisplayName = ModelExtensions.GetDisplayNameForTenant(vault.Properties.TenantId, adClient);

            VaultName         = vault.Name;
            Location          = vault.Location;
            ResourceId        = vault.Id;
            ResourceGroupName = (new PSResourceManagerModels.ResourceIdentifier(vault.Id)).ResourceGroupName;
            Tags                 = TagsConversionHelper.CreateTagHashtable(vault.Tags);
            Sku                  = vault.Properties.Sku.Name;
            TenantId             = vault.Properties.TenantId;
            TenantName           = vaultTenantDisplayName;
            VaultUri             = vault.Properties.VaultUri;
            EnabledForDeployment = vault.Properties.EnabledForDeployment;
            AccessPolicies       = vault.Properties.AccessPolicies.Select(s => new PSVaultAccessPolicy(s, adClient)).ToArray();
            OriginalVault        = vault;
        }
        /// <summary>
        /// Convert a Management.Sql.Models.VirtualCluster to AzureSqlVirtualClusterModel
        /// </summary>
        /// <param name="resp">The management client Virtual Cluster response to convert</param>
        /// <returns>The converted Virtual Cluster model</returns>
        private static AzureSqlVirtualClusterModel CreateVirtualClusterModelFromResponse(Management.Sql.Models.VirtualCluster resp)
        {
            AzureSqlVirtualClusterModel virtualCluster = new AzureSqlVirtualClusterModel();

            // Extract the resource group name from the ID.
            ResourceIdentifier resourceIdentifier = new ResourceIdentifier(resp.Id);

            virtualCluster.ResourceGroupName = resourceIdentifier.ResourceGroupName;

            virtualCluster.VirtualClusterName = resp.Name;
            virtualCluster.Id       = resp.Id;
            virtualCluster.Location = resp.Location;
            virtualCluster.Tags     = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(resp.Tags), false);
            virtualCluster.SubnetId = resp.SubnetId;

            return(virtualCluster);
        }
        public PSNetworkInterface GetNetworkInterface(string resourceGroupName, string name)
        {
            var getNetworkInterfaceResponse = this.NetworkInterfaceClient.Get(resourceGroupName, name);

            var networkInterface = Mapper.Map <PSNetworkInterface>(getNetworkInterfaceResponse.NetworkInterface);

            networkInterface.ResourceGroupName = resourceGroupName;
            networkInterface.Tag =
                TagsConversionHelper.CreateTagHashtable(getNetworkInterfaceResponse.NetworkInterface.Tags);

            if (networkInterface.IpConfigurations[0].PublicIpAddress == null)
            {
                networkInterface.IpConfigurations[0].PublicIpAddress = new PSResourceId();
            }

            return(networkInterface);
        }
Пример #22
0
        public override void Execute()
        {
            base.Execute();

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.Name = resourceIdentifier.ResourceName;
            }

            if (ShouldGetByName(ResourceGroupName, Name))
            {
                var vVirtualNetworkTap      = this.NetworkClient.NetworkManagementClient.VirtualNetworkTaps.Get(ResourceGroupName, Name);
                var vVirtualNetworkTapModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSVirtualNetworkTap>(vVirtualNetworkTap);
                vVirtualNetworkTapModel.ResourceGroupName = this.ResourceGroupName;
                vVirtualNetworkTapModel.Tag = TagsConversionHelper.CreateTagHashtable(vVirtualNetworkTap.Tags);
                WriteObject(vVirtualNetworkTapModel, true);
            }
            else
            {
                IPage <VirtualNetworkTap> vtapPage;
                if (ShouldListByResourceGroup(ResourceGroupName, Name))
                {
                    vtapPage = this.NetworkClient.NetworkManagementClient.VirtualNetworkTaps.ListByResourceGroup(this.ResourceGroupName);
                }
                else
                {
                    vtapPage = this.NetworkClient.NetworkManagementClient.VirtualNetworkTaps.ListAll();
                }

                // Get all resources by polling on next page link
                var vtapList = ListNextLink <VirtualNetworkTap> .GetAllResourcesByPollingNextLink(vtapPage, this.NetworkClient.NetworkManagementClient.VirtualNetworkTaps.ListByResourceGroupNext);

                var psVtaps = new List <PSVirtualNetworkTap>();
                foreach (var vtap in vtapList)
                {
                    var psVtap = this.ToPsVirtualNetworkTap(vtap);
                    psVtap.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(vtap.Id);
                    psVtaps.Add(psVtap);
                }

                WriteObject(TopLevelWildcardFilter(ResourceGroupName, Name, psVtaps), true);
            }
        }
Пример #23
0
        public override void Execute()
        {
            base.Execute();

            if (this.IsParameterBound(p => p.ResourceId))
            {
                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.Name = resourceIdentifier.ResourceName;
            }

            if (!string.IsNullOrEmpty(this.Name))
            {
                var vNetworkProfile      = this.NetworkClient.NetworkManagementClient.NetworkProfiles.Get(ResourceGroupName, Name, ExpandResource);
                var vNetworkProfileModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSNetworkProfile>(vNetworkProfile);
                vNetworkProfileModel.ResourceGroupName = this.ResourceGroupName;
                vNetworkProfileModel.Tag = TagsConversionHelper.CreateTagHashtable(vNetworkProfile.Tags);
                WriteObject(vNetworkProfileModel, true);
            }
            else
            {
                IPage <NetworkProfile> vNetworkProfilePage;
                if (!string.IsNullOrEmpty(this.ResourceGroupName))
                {
                    vNetworkProfilePage = this.NetworkClient.NetworkManagementClient.NetworkProfiles.List(this.ResourceGroupName);
                }
                else
                {
                    vNetworkProfilePage = this.NetworkClient.NetworkManagementClient.NetworkProfiles.ListAll();
                }

                var vNetworkProfileList = ListNextLink <NetworkProfile> .GetAllResourcesByPollingNextLink(vNetworkProfilePage,
                                                                                                          this.NetworkClient.NetworkManagementClient.NetworkProfiles.ListNext);

                List <PSNetworkProfile> psNetworkProfileList = new List <PSNetworkProfile>();
                foreach (var vNetworkProfile in vNetworkProfileList)
                {
                    var vNetworkProfileModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSNetworkProfile>(vNetworkProfile);
                    vNetworkProfileModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(vNetworkProfile.Id);
                    vNetworkProfileModel.Tag = TagsConversionHelper.CreateTagHashtable(vNetworkProfile.Tags);
                    psNetworkProfileList.Add(vNetworkProfileModel);
                }
                WriteObject(psNetworkProfileList, true);
            }
        }
        public override void Execute()
        {
            base.Execute();

            if (string.Equals(this.ParameterSetName, ResourceIdParameterSet, StringComparison.OrdinalIgnoreCase))
            {
                var resourceInfo = new ResourceIdentifier(ResourceId);
                ResourceGroupName = resourceInfo.ResourceGroupName;
                Name = resourceInfo.ResourceName;
            }

            if (ShouldGetByName(ResourceGroupName, Name))
            {
                var vExpressRoutePort      = this.NetworkClient.NetworkManagementClient.ExpressRoutePorts.Get(ResourceGroupName, Name);
                var vExpressRoutePortModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSExpressRoutePort>(vExpressRoutePort);
                vExpressRoutePortModel.ResourceGroupName = this.ResourceGroupName;
                vExpressRoutePortModel.Tag = TagsConversionHelper.CreateTagHashtable(vExpressRoutePort.Tags);
                WriteObject(vExpressRoutePortModel, true);
            }
            else
            {
                IPage <ExpressRoutePort> vExpressRoutePortPage;
                if (ShouldListByResourceGroup(ResourceGroupName, Name))
                {
                    vExpressRoutePortPage = this.NetworkClient.NetworkManagementClient.ExpressRoutePorts.ListByResourceGroup(this.ResourceGroupName);
                }
                else
                {
                    vExpressRoutePortPage = this.NetworkClient.NetworkManagementClient.ExpressRoutePorts.List();
                }

                var vExpressRoutePortList = ListNextLink <ExpressRoutePort> .GetAllResourcesByPollingNextLink(vExpressRoutePortPage,
                                                                                                              this.NetworkClient.NetworkManagementClient.ExpressRoutePorts.ListNext);

                List <PSExpressRoutePort> psExpressRoutePortList = new List <PSExpressRoutePort>();
                foreach (var vExpressRoutePort in vExpressRoutePortList)
                {
                    var vExpressRoutePortModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSExpressRoutePort>(vExpressRoutePort);
                    vExpressRoutePortModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(vExpressRoutePort.Id);
                    vExpressRoutePortModel.Tag = TagsConversionHelper.CreateTagHashtable(vExpressRoutePort.Tags);
                    psExpressRoutePortList.Add(vExpressRoutePortModel);
                }
                WriteObject(TopLevelWildcardFilter(ResourceGroupName, Name, psExpressRoutePortList), true);
            }
        }
Пример #25
0
        private static TrafficManagerProfile GetPowershellTrafficManagerProfile(string resourceGroupName, string profileName, Profile sdkProfile)
        {
            var profile = new TrafficManagerProfile
            {
                Id   = sdkProfile.Id,
                Tags = TagsConversionHelper.CreateTagHashtable(sdkProfile.Tags),
                Name = profileName,
                ResourceGroupName = resourceGroupName,
                ProfileStatus     = sdkProfile.ProfileStatus,
                RelativeDnsName   = sdkProfile.DnsConfig.RelativeName,
                Ttl = (uint)sdkProfile.DnsConfig.Ttl,
                TrafficRoutingMethod             = sdkProfile.TrafficRoutingMethod,
                MonitorProtocol                  = sdkProfile.MonitorConfig.Protocol,
                MonitorPort                      = (uint)sdkProfile.MonitorConfig.Port,
                MonitorPath                      = sdkProfile.MonitorConfig.Path,
                MonitorIntervalInSeconds         = (int?)sdkProfile.MonitorConfig.IntervalInSeconds,
                MonitorTimeoutInSeconds          = (int?)sdkProfile.MonitorConfig.TimeoutInSeconds,
                MonitorToleratedNumberOfFailures = (int?)sdkProfile.MonitorConfig.ToleratedNumberOfFailures,
                MaxReturn     = sdkProfile.MaxReturn,
                CustomHeaders = sdkProfile.MonitorConfig.CustomHeaders?.Select(
                    customHeader => TrafficManagerCustomHeader.FromSDKMonitorConfigCustomHeadersItem(customHeader)).ToList(),
                ExpectedStatusCodeRanges = sdkProfile.MonitorConfig.ExpectedStatusCodeRanges?.Select(
                    statusCodeRanges => TrafficManagerExpectedStatusCodeRange.FromSDKMonitorConfigStatusCodeRangesItem(statusCodeRanges))
                                           .Where(statusCodeRange => statusCodeRange != null).ToList(),
            };

            if (sdkProfile.Endpoints != null)
            {
                profile.Endpoints = new List <TrafficManagerEndpoint>();

                foreach (Endpoint endpoint in sdkProfile.Endpoints)
                {
                    profile.Endpoints.Add(
                        GetPowershellTrafficManagerEndpoint(
                            endpoint.Id,
                            resourceGroupName,
                            profileName,
                            endpoint.Type,
                            endpoint.Name,
                            endpoint));
                }
            }

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

            var present = true;

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

            if (!present)
            {
                throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound);
            }

            NormalizeChildIds(this.NetworkProfile);

            // Map to the sdk object
            var vNetworkProfileModel = NetworkResourceManagerProfile.Mapper.Map <MNM.NetworkProfile>(this.NetworkProfile);

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

            // Execute the PUT NetworkProfile call
            this.NetworkClient.NetworkManagementClient.NetworkProfiles.CreateOrUpdate(this.NetworkProfile.ResourceGroupName, this.NetworkProfile.Name, vNetworkProfileModel);

            var getNetworkProfile = this.NetworkClient.NetworkManagementClient.NetworkProfiles.Get(this.NetworkProfile.ResourceGroupName, this.NetworkProfile.Name);
            var psNetworkProfile  = NetworkResourceManagerProfile.Mapper.Map <PSNetworkProfile>(getNetworkProfile);

            psNetworkProfile.ResourceGroupName = this.NetworkProfile.ResourceGroupName;
            psNetworkProfile.Tag = TagsConversionHelper.CreateTagHashtable(getNetworkProfile.Tags);
            WriteObject(psNetworkProfile, true);
        }
        public override void Execute()
        {
            base.Execute();

            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.Name = resourceIdentifier.ResourceName;
            }

            if (ShouldGetByName(this.ResourceGroupName, this.Name))
            {
                var vNatGateway      = this.NetworkClient.NetworkManagementClient.NatGateways.Get(ResourceGroupName, Name);
                var vNatGatewayModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSNatGateway>(vNatGateway);
                vNatGatewayModel.ResourceGroupName = this.ResourceGroupName;
                vNatGatewayModel.Tag = TagsConversionHelper.CreateTagHashtable(vNatGateway.Tags);
                WriteObject(vNatGatewayModel, true);
            }
            else
            {
                IPage <NatGateway> vNatGatewayPage;
                if (ShouldListByResourceGroup(this.ResourceGroupName, this.Name))
                {
                    vNatGatewayPage = this.NetworkClient.NetworkManagementClient.NatGateways.List(this.ResourceGroupName);
                }
                else
                {
                    vNatGatewayPage = this.NetworkClient.NetworkManagementClient.NatGateways.ListAll();
                }

                var vNatGatewayList = ListNextLink <NatGateway> .GetAllResourcesByPollingNextLink(vNatGatewayPage,
                                                                                                  this.NetworkClient.NetworkManagementClient.NatGateways.ListNext);

                List <PSNatGateway> psNatGatewayList = new List <PSNatGateway>();
                foreach (var vNatGateway in vNatGatewayList)
                {
                    var vNatGatewayModel = NetworkResourceManagerProfile.Mapper.Map <CNM.PSNatGateway>(vNatGateway);
                    vNatGatewayModel.ResourceGroupName = NetworkBaseCmdlet.GetResourceGroup(vNatGateway.Id);
                    vNatGatewayModel.Tag = TagsConversionHelper.CreateTagHashtable(vNatGateway.Tags);
                    psNatGatewayList.Add(vNatGatewayModel);
                }
                WriteObject(TopLevelWildcardFilter(ResourceGroupName, Name, psNatGatewayList), true);
            }
        }
Пример #28
0
        /// <summary>
        /// Take an AccountResource and turn it into a BatchAccountContext
        /// </summary>
        /// <param name="resource">Resource info returned by RP</param>
        /// <returns>Void</returns>
        internal void ConvertAccountResourceToAccountContext(BatchAccount resource)
        {
            var accountEndpoint = resource.AccountEndpoint;

            if (Uri.CheckHostName(accountEndpoint) != UriHostNameType.Dns)
            {
                throw new ArgumentException(String.Format(Resources.InvalidEndpointType, accountEndpoint), "AccountEndpoint");
            }

            this.Id = resource.Id;
            this.AccountEndpoint = accountEndpoint;
            this.Location        = resource.Location;
            this.State           = resource.ProvisioningState.ToString();
            this.Tags            = TagsConversionHelper.CreateTagHashtable(resource.Tags);
            this.CoreQuota       = resource.CoreQuota;
            this.PoolQuota       = resource.PoolQuota;
            this.ActiveJobAndJobScheduleQuota = resource.ActiveJobAndJobScheduleQuota;

            if (resource.AutoStorage != null)
            {
                this.AutoStorageProperties = new AutoStorageProperties()
                {
                    StorageAccountId = resource.AutoStorage.StorageAccountId,
                    LastKeySync      = resource.AutoStorage.LastKeySync,
                };
            }

            // extract the host and strip off the account name for the TaskTenantUrl and AccountName
            var hostParts = accountEndpoint.Split('.');

            this.AccountName   = hostParts[0];
            this.TaskTenantUrl = Uri.UriSchemeHttps + Uri.SchemeDelimiter + accountEndpoint;

            // get remaining fields from Id which looks like:
            // /subscriptions/4a06fe24-c197-4353-adc1-058d1a51924e/resourceGroups/clwtest/providers/Microsoft.Batch/batchAccounts/clw
            var idParts = resource.Id.Split('/');

            if (idParts.Length < 5)
            {
                throw new ArgumentException(String.Format(Resources.InvalidResourceId, resource.Id), "Id");
            }

            this.Subscription      = idParts[2];
            this.ResourceGroupName = idParts[4];
        }
Пример #29
0
        /// <summary>
        /// Convert a Management.SqlVirtualMachine.Models.SqlVirtualMachineGroupModel to AzureSqlVirtualMachineGroupModel
        /// </summary>
        /// <param name="resourceGroupName">The resource group the sql virtual machine group is in</param>
        /// <param name="resp">The management client sql virtual machine group response to convert</param>
        /// <returns>The converted sql virtual machine group model</returns>
        private static AzureSqlVMGroupModel CreateSqlVirtualMachineGroupModelFromResponse(SqlVirtualMachineGroup resp)
        {
            // Extract the resource group name from the ID.
            string[] segments = resp.Id.Split('/');

            AzureSqlVMGroupModel model = new AzureSqlVMGroupModel(segments[4])
            {
                Name              = resp.Name,
                Location          = resp.Location,
                Sku               = resp.SqlImageSku,
                Offer             = resp.SqlImageOffer,
                WsfcDomainProfile = resp.WsfcDomainProfile,
                Tags              = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(resp.Tags), true),
                ResourceId        = resp.Id
            };

            return(model);
        }
        public PSVirtualNetwork GetVirtualNetwork(string resourceGroupName, string name, string expandResource = null)
        {
            var vnet = this.VirtualNetworkClient.Get(resourceGroupName, name, expandResource);

            var psVirtualNetwork = NetworkResourceManagerProfile.Mapper.Map <PSVirtualNetwork>(vnet);

            psVirtualNetwork.ResourceGroupName = resourceGroupName;

            psVirtualNetwork.Tag =
                TagsConversionHelper.CreateTagHashtable(vnet.Tags);

            if (psVirtualNetwork.DhcpOptions == null)
            {
                psVirtualNetwork.DhcpOptions = new PSDhcpOptions();
            }

            return(psVirtualNetwork);
        }