public string Resolve(CloudResource source, SandboxResourceLight destination, string destMember, ResolutionContext context)
        {
            if (source != null)
            {
                var shouldHaveRetryLink = false;

                var baseStatusOnThisOperation = ResourceStatusUtil.DecideWhatOperationToBaseStatusOn(source);

                if (baseStatusOnThisOperation == null)
                {
                    shouldHaveRetryLink = true;
                }
                else if (CloudResourceOperationUtil.HasValidStateForRetry(baseStatusOnThisOperation))
                {
                    shouldHaveRetryLink = true;
                }

                if (shouldHaveRetryLink)
                {
                    return(AzureResourceUtil.CreateResourceRetryLink(source.Id));
                }
            }

            return(null);
        }
Пример #2
0
        public static string CreateResourceCostLink(IConfiguration config, Sandbox sandbox)
        {
            var resourceGroupEntry = CloudResourceUtil.GetSandboxResourceGroupEntry(sandbox.Resources);

            if (resourceGroupEntry == null)
            {
                return(null);
            }

            var resourceGroupId = resourceGroupEntry.ResourceId;

            if (String.IsNullOrWhiteSpace(resourceGroupId))
            {
                return(null);
            }

            var domain = ConfigUtil.GetConfigValueAndThrowIfEmpty(config, ConfigConstants.AZ_DOMAIN);

            if (resourceGroupId == AzureResourceNameUtil.AZURE_RESOURCE_INITIAL_ID_OR_NAME)
            {
                return(null);
            }

            return(AzureResourceUtil.CreateResourceCostLink(domain, resourceGroupId));
        }
        async Task <IVirtualMachine> CreateInternalAsync(Region region, string resourceGroupName, string vmName, string primaryNetworkName, string subnetName, string userName, string password, string vmSize, string osName, string osCategory, IDictionary <string, string> tags, string diagStorageAccountName, CancellationToken cancellationToken = default)
        {
            IVirtualMachine vm;

            // Get diagnostic storage account reference for boot diagnostics
            var diagStorage = _azure.StorageAccounts.GetByResourceGroup(resourceGroupName, diagStorageAccountName);

            AzureResourceUtil.ThrowIfResourceIsNull(diagStorage, AzureResourceType.StorageAccount, diagStorageAccountName, "Create VM failed");

            var network = await _azure.Networks.GetByResourceGroupAsync(resourceGroupName, primaryNetworkName);

            AzureResourceUtil.ThrowIfResourceIsNull(network, AzureResourceType.VirtualNetwork, primaryNetworkName, "Create VM failed");

            var publicIpName = AzureResourceNameUtil.VirtualMachinePublicIp(vmName);

            var pip = await _azure.PublicIPAddresses.Define(publicIpName)
                      .WithRegion(region)
                      .WithExistingResourceGroup(resourceGroupName)
                      .WithStaticIP()
                      .WithSku(PublicIPSkuType.Standard)
                      .WithTags(tags)
                      .CreateAsync(cancellationToken);

            var vmCreatable = _azure.VirtualMachines.Define(vmName)
                              .WithRegion(region)
                              .WithExistingResourceGroup(resourceGroupName)
                              .WithExistingPrimaryNetwork(network)
                              .WithSubnet(subnetName)
                              .WithPrimaryPrivateIPAddressDynamic()
                              .WithExistingPrimaryPublicIPAddress(pip);


            IWithCreate vmWithOS;

            if (osCategory.ToLower().Equals("windows"))
            {
                vmWithOS = CreateWindowsVm(vmCreatable, osName, userName, password);
            }
            else if (osCategory.ToLower().Equals("linux"))
            {
                vmWithOS = CreateLinuxVm(vmCreatable, osName, userName, password);
            }
            else
            {
                throw new ArgumentException($"Argument 'osCategory' needs to be either 'windows' or 'linux'. Current value: {osCategory}");
            }

            var vmWithSize = vmWithOS.WithSize(vmSize);

            vm = await vmWithSize
                 .WithBootDiagnostics(diagStorage)
                 .WithTags(tags)
                 .CreateAsync(cancellationToken);

            return(vm);
        }
Пример #4
0
        public string Resolve(CloudResource source, DatasetResourceLightDto destination, string destMember, ResolutionContext context)
        {
            var baseStatusOnThisOperation = ResourceStatusUtil.DecideWhatOperationToBaseStatusOn(source);

            if (baseStatusOnThisOperation != null)
            {
                if (source.ResourceType == AzureResourceType.StorageAccount &&
                    source.Purpose == CloudResourcePurpose.StudySpecificDatasetStorageAccount &&
                    baseStatusOnThisOperation.Status == CloudResourceOperationState.FAILED &&
                    baseStatusOnThisOperation.TryCount >= baseStatusOnThisOperation.MaxTryCount)
                {
                    return(AzureResourceUtil.CreateResourceRetryLink(source.Id));
                }
            }

            return(null);
        }
        public string Resolve(Dataset source, DatasetDto destination, string destMember, ResolutionContext context)
        {
            string storageAccountIdToUse = null;

            if (source.StudySpecific)
            {
                var storageAccountResource = DatasetUtils.GetStudySpecificStorageAccountResourceEntry(source);

                if (storageAccountResource != null)
                {
                    storageAccountIdToUse = storageAccountResource.ResourceId;
                }
            }
            else
            {
                storageAccountIdToUse = source.StorageAccountId;
            }

            return(AzureResourceUtil.CreateResourceLink(_config, storageAccountIdToUse));
        }
Пример #6
0
 public static string CreateResourceLink(IConfiguration config, CloudResource resource)
 {
     return(AzureResourceUtil.CreateResourceLink(config, resource.ResourceId));
 }
 public string Resolve(CloudResource source, IHasStorageAccountLink destination, string destMember, ResolutionContext context)
 {
     return(AzureResourceUtil.CreateResourceLink(_config, source.ResourceId));
 }