public NfsFileServerOverviewModel(NfsFileServer fileServer)
        {
            if (fileServer != null)
            {
                Name              = fileServer.Name;
                RepositoryType    = fileServer.RepositoryType;
                SubscriptionId    = fileServer.SubscriptionId;
                Username          = fileServer.Username;
                Password          = fileServer.Password;
                VmName            = fileServer.VmName;
                PublicIp          = fileServer.PublicIp;
                PrivateIp         = fileServer.PrivateIp;
                VmSize            = fileServer.VmSize;
                ProvisioningState = fileServer.ProvisioningState;
                ResourceGroupName = fileServer.ResourceGroupName;
                DeploymentName    = fileServer.DeploymentName;
                FileShares        = fileServer.FileShares;
                AllowedNetworks   = fileServer.AllowedNetworks;

                if (fileServer.Subnet != null)
                {
                    SubnetName       = fileServer.Subnet.Name;
                    SubnetVNetName   = fileServer.Subnet.VNetName;
                    SubnetResourceId = fileServer.Subnet.ResourceId;
                    SubnetPrefix     = fileServer.Subnet.AddressPrefix;
                    SubnetLocation   = fileServer.Subnet.Location;
                }
            }
        }
 private async Task <List <VirtualMachineStatus> > GetVirtualMachineStatus(NfsFileServer fileServer)
 {
     return(new List <VirtualMachineStatus>
     {
         await GetVirtualMachineStatus(
             fileServer.SubscriptionId,
             fileServer.ResourceGroupName,
             fileServer.VmName)
     });
 }
 public AddNfsFileServerModel(NfsFileServer fileServer)
 {
     RepositoryName       = fileServer.Name;
     RepositoryType       = fileServer.RepositoryType;
     NewResourceGroupName = fileServer.ResourceGroupName;
     SubscriptionId       = fileServer.SubscriptionId;
     Subnet          = fileServer.Subnet;
     AllowedNetworks = Subnet?.AddressPrefix;
     VmName          = fileServer.VmName;
     VmSize          = fileServer.VmSize;
     UserName        = fileServer.Username;
 }
 public NfsFileServerOverviewModel(NfsFileServer fileServer) : base(fileServer)
 {
     if (fileServer != null)
     {
         Username        = fileServer.Username;
         Password        = fileServer.Password;
         VmName          = fileServer.VmName;
         VmSize          = fileServer.VmSize;
         PublicIp        = fileServer.PublicIp;
         PrivateIp       = fileServer.PrivateIp;
         FileShares      = fileServer.FileShares;
         AllowedNetworks = fileServer.AllowedNetworks;
     }
 }
        private Dictionary <string, object> GetTemplateParameters(NfsFileServer repository)
        {
            var fileShare = repository.FileShares.FirstOrDefault();

            return(new Dictionary <string, object>
            {
                { "environmentTag", repository.EnvironmentName ?? "Global" },
                { "vmName", repository.VmName },
                { "adminUserName", repository.Username },
                { "adminPassword", repository.Password },
                { "vmSize", repository.VmSize },
                { "subnetResourceId", repository.Subnet.ResourceId },
                { "sharesToExport", fileShare?.Name ?? "" },
                { "subnetAddressPrefix", string.Join(",", repository.AllowedNetworks) },
            });
        }
        private async Task DeployFileServer(NfsFileServer repository, IManagementClientProvider managementClientProvider)
        {
            try
            {
                using (var client = await managementClientProvider.CreateResourceManagementClient(repository.SubscriptionId))
                {
                    await client.ResourceGroups.CreateOrUpdateAsync(repository.ResourceGroupName,
                                                                    new ResourceGroup { Location = repository.Subnet.Location });

                    var templateParams = GetTemplateParameters(repository);

                    var properties = new Deployment
                    {
                        Properties = new DeploymentProperties
                        {
                            Template   = await _templateProvider.GetTemplate("linux-file-server.json"),
                            Parameters = _templateProvider.GetParameters(templateParams),
                            Mode       = DeploymentMode.Incremental
                        }
                    };

                    // Start the ARM deployment
                    await client.Deployments.BeginCreateOrUpdateAsync(
                        repository.ResourceGroupName,
                        repository.DeploymentName,
                        properties);

                    // Queue a request for the background host to monitor the deployment
                    // and update the state and IP address when it's done.
                    await _deploymentQueue.Add(new ActiveDeployment
                    {
                        FileServerName = repository.Name,
                        StartTime      = DateTime.UtcNow,
                    });

                    repository.ProvisioningState = ProvisioningState.Running;
                    repository.InProgress        = false;

                    await UpdateRepository(repository);
                }
            }
            catch (CloudException ex)
            {
                _logger.LogError(ex, $"Failed to deploy NFS server: {ex.Message}.");
                throw;
            }
        }
Esempio n. 7
0
        public AddNfsFileServerModel(NfsFileServer fileServer)
        {
            RepositoryName       = fileServer.Name;
            RepositoryType       = fileServer.RepositoryType;
            NewResourceGroupName = fileServer.ResourceGroupName;
            SubscriptionId       = fileServer.SubscriptionId;

            if (fileServer.Subnet?.ResourceId != null)
            {
                SubnetResourceIdLocationAndAddressPrefix = fileServer.Subnet.ToString();
                AllowedNetworks = fileServer.Subnet.AddressPrefix;
            }

            VmName   = fileServer.VmName;
            VmSize   = fileServer.VmSize;
            UserName = fileServer.Username;
        }
        private async Task UpdateFileServerFromDeploymentAsync(
            DeploymentExtended deployment,
            NfsFileServer fileServer)
        {
            if (fileServer.Deployment.ProvisioningState == ProvisioningState.Succeeded)
            {
                var(privateIp, publicIp) = await GetIpAddressesAsync(fileServer);

                fileServer.PrivateIp = privateIp;
                fileServer.PublicIp  = publicIp;
            }

            if (fileServer.Deployment.ProvisioningState == ProvisioningState.Failed)
            {
                fileServer.State = StorageState.Failed;
            }
        }
        private async Task <(string privateIp, string publicIp)> GetIpAddressesAsync(NfsFileServer fileServer)
        {
            using (var computeClient = await _clientProvider.CreateComputeManagementClient(fileServer.SubscriptionId))
                using (var networkClient = await _clientProvider.CreateNetworkManagementClient(fileServer.SubscriptionId))
                {
                    var vm = await computeClient.VirtualMachines.GetAsync(fileServer.ResourceGroupName, fileServer.VmName);

                    var networkIfaceName = vm.NetworkProfile.NetworkInterfaces.First().Id.Split("/").Last();
                    var net = await networkClient.NetworkInterfaces.GetAsync(fileServer.ResourceGroupName, networkIfaceName);

                    var firstConfiguration = net.IpConfigurations.First();

                    var privateIp  = firstConfiguration.PrivateIPAddress;
                    var publicIpId = firstConfiguration.PublicIPAddress?.Id;
                    var publicIp   =
                        publicIpId != null
                        ? await networkClient.PublicIPAddresses.GetAsync(
                            fileServer.ResourceGroupName,
                            publicIpId.Split("/").Last())
                        : null;

                    return(privateIp, publicIp?.IpAddress);
                }
        }
 private async Task DeleteFileServerAsync(NfsFileServer fileServer)
 {
     await DeleteVirtualMachineAsync(fileServer.SubscriptionId, fileServer.ResourceGroupName, fileServer.VmName);
 }