vmware / dscr-for-vmware

The Repository contains Microsoft PowerShell Desired State Configuration (DSC) Resources for managing VC and ESXi settings.
Other
140 stars 41 forks source link

Add/Modify DSC Resource to have the capability to mount the NFS Datastore #283

Closed jatinpurohit92 closed 3 years ago

jatinpurohit92 commented 4 years ago

The Current DSCResource NfsDatastore, Creates a NFS datastore but does not allow the same datastore to mount on other ESXi hosts. Request is to modify this DSC Resource so that-

  1. Multiple VMHosts can be passed as a parameter
  2. Create a datastore on first VMhost and mount the same on other VMHosts.
mikedonleyuoy commented 4 years ago

The cause of the failure is down to this test in GetDatastore action in VMware.vSphereDSC.psm1

if ($null -ne $datastoreInvCenter) {
    throw ($this.CouldNotCreateDatastoreWithTheSpecifiedNameMessage -f $this.Name, $this.VMHost.Name, $this.Connection.Name)
}

Whilst the test for an existing datastore of the same name is valid non-NFS datastores, it's not relevant for NFS.

SimeonGerginov commented 3 years ago

The bug was fixed with PR #297, so the name validation for NFS Datastores is no longer applicable and everything should work as expected with the latest version of the module.

jeremysbrain commented 3 years ago

The NfsDatastore module does not appear to allow the addition of multiple hosts to a Nfs Datastore. The "VMHostName" accepts a single value, and subsequent executions create a new datastore mapped to the additional hosts instead of mapping the host to the existing datastore.

Specs:

get-module VMware.vSphereDSC -list | fl

Name              : VMware.vSphereDSC
Description       : This PowerShell module contains DSC Resources for vSphere.
ModuleType        : Script
Version           : 2.2.0.84

Sample code:

        $NfsDatastoreResource = @()
        foreach ($ESXiHost in $Node.ESXiHosts) {
        $NfsDatastoreResource += "[NfsDatastore]Nfs_$ESXiHost"
            NfsDatastore "Nfs_$ESXiHost" {
                Server = $Server
                Credential = $Credential
                VMHostName = $ESXiHost
                Name = 'Nfs'
                Path = '/nfs'
                NfsHost = 'nfs.demo.local'
                FileSystemVersion = '3'
                Ensure = 'Present'
                DependsOn = $ESXiHostResource #"[vCenterVMHost]ESXiHost_$ESXiHost"
            }
        }

Result:

Get-Datastore

Name                               FreeSpaceGB      CapacityGB
----                               -----------      ----------
Nfs (1)                                191.621         195.858
Nfs                                    195.117         195.858

Expected Result (from configuring from vCenter GUI):

Get-Datastore

Name                               FreeSpaceGB      CapacityGB
----                               -----------      ----------
Nfs                                    195.117         195.858