VMware Cloud Community
carl1
Expert
Expert
Jump to solution

Adding an extent to a VMFS datastore

OK, I am stumped here. I need to destroy one VMFS datastore and add the released LUN to another datastore as an extent.

-


# Get SharedTMPLs disk reference<br /><br/>
$esxMoRef = $scHost | % {get-View $_.Id}<br/><br/>
$esxStorageSystem = $esxMoRef.configManager.StorageSystem<br/><br/>
$esxStorageSystemMoRef = get-View $esxStorageSystem<br/><br/>
$ds = get-Datastore -name 'SharedTMPLs' -VMhost $scHost | get-View<br/><br/>
$lun = $ds.info.vmfs.extent[0].DiskName<br/><br/>
$HostDiskPart = New-Object VMware.Vim.HostScsiDiskPartition<br/><br/>
$HostDiskPart.diskName = $lun<br/><br/>
$hostDiskPart.partition = 26<br/><br/>
<br/><br/>

## Destroy SharedTMPLs datastore
remove-Datastore -Datastore SharedTMPLs -VMHost $scHost -confirm:$false<br/><br/>
start-Sleep -s 10<br/><br/>
<br/><br/>

## Add SharedTMPLs disk space to SharedVMs
$ds = get-Datastore -name 'SharedVMs' -VMhost $scHost | get-View
$lunVM = $ds.info.vmfs.extent[0].DiskName<br /><br/>
$esxStorageSystemMoRef.attachVmfsExtent($lunVM, $HostDiskPart)<br/><br/>


-


I think this should work but Google could not find any examples of doing this. The error I get is

Exception calling "AttachVmfsExtent" with "2" argument(s): "A specified parameter was not correct."<br /><br/>
At line:1 char:40<br/><br/>
+ $esxStorageSystemMoRef.attachVmfsExtent &lt;&lt;&lt;&lt; ($lunVM, $HostDiskPart)<br/><br/>
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException<br/><br/>
+ FullyQualifiedErrorId : DotNetMethodException

</p></p>
<p><p>---------------------------------------------------------------------------------------------------------------- </p></p>
<p><p>The DotNetMethodException seems to be a bit of a catch all when things don't go well.  I tried a brand new powercli window (just to make 

sure the problem wasn't some clutter hanging around) but the same thing. Help Please!Thanks,

Carl L. <br /><br/>

</p>

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I came up with something similar.

Wouldn't have posted it since you gave your solution, but it shows how to get the correct Uuid.

For info, the script adds the LUN from DS4 to DS3 as an extent.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
11 Replies
aevrov
VMware Employee
VMware Employee
Jump to solution

Hi Carl,

Let's try to diagnose the problem. I need you to create an error report and attach it in a reply-post here so I can get some debugging-level information.

In order to create the error report you have to assign your script to a script-block variable and pass it as a parameter to the Get-ErroReport cmdlet:

$scriptBlock = {

  1. Your script here:

  1. Get SharedTMPLs disk reference

$esxMoRef = $scHost | % {get-View $_.Id}

... etc ...

$esxStorageSystemMoRef.attachVmfsExtent($lunVM, $HostDiskPart)

}

Get-ErrorReport -ProblemDescription "attachVmfsExtent returns an unexpected error" -ProblemScriptTimeoutSeconds 300 -Destination C:\ErrorReports -ProblemScript $scriptBlock -DontIncludeServerLogs

After executing the above script, you'll get a .zip file in the C:\ErrorReports folder. Please attach the file here so I can take a look at it.

Regards,

-Angel

0 Kudos
carl1
Expert
Expert
Jump to solution

Angel,

Thanks but get-errorReport returns a "CommandNotFound" exception.

Carl L.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That indicates that you are probably not running PowerCLI 4.1.

Can you check with

Get-PowerCLIVersion

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
carl1
Expert
Expert
Jump to solution

That is likely correct. It should be PowerCLI 4.0. The get-powerCliVersion also returns commandNotFoundException. I cannot upgrade to 4.1.

Carl L.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I never was able to get the attachVmfsExtent working, but I always thought it was because my lab uses iScsi storage.

With the ExtendVmfsDatastore method it works for me.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
carl1
Expert
Expert
Jump to solution

Ahh yes, but that is a 4.1 feature. I am stuck in 4.0 and that method is not there.

Carl L.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I don't think so. ExtendVmfsDatastore has been around since API 2.0.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
carl1
Expert
Expert
Jump to solution

Ahh, the downside of still learning. Did not invoke get-view correctly on the datastore. OK, I have this code now but still no joy. Do you have an example that I could work from. I think I am really close.

# Get SharedTMPLs disk reference
$esxMoRef = $scHost \| % {get-View $_.Id}
$esxStorageSystem = $esxMoRef.configManager.StorageSystem
$esxStorageSystemMoRef = get-View $esxStorageSystem
$ds = get-Datastore -name 'SharedTMPLs' -VMhost $scHost \| get-View
$SharedTMPLs = new-Object VMware.Vim.VmfsDatastoreExtendSpec
$SharedTMPLs.Extent = $ds.info.vmfs.extent

# Lun should be naa.60060160eb702600d845dba3a40adf11 on the Orange kit

# Destroy SharedTMPLs datastore
remove-Datastore -Datastore SharedTMPLs -VMHost $scHost -confirm:$false
start-Sleep -s 1

# Add SharedTMPLs disk space to SharedVMs
$sharedVMsDS = get-Datastore -name 'SharedVMs' -VMhost $scHost \| get-View
$dsView = get-view $scHostView.configManager.DatastoreSystem
$dsView.extendVmfsDatastore($sharedVMsDS, $SharedTMPLs)

I am getting the error

Cannot convert argument "0", with value: "SharedVMs", for "ExtendVmfsDatastore" to type "VMware.Vim.ManagedObjectReference":
 "Cannot convert the "SharedVMs" value of type "VMware.VimAutomation.Client20.DatastoreImpl" to type "VMware.Vim.ManagedObjectReference"."
At line:1 char:28
+ $dsView.extendVmfsDatastore &lt;&lt;&lt;&lt; ($sharedVMs, $SharedTMPLs)
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

Thanks!

Carl L. 

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Carl,

because the error message tells you that it needs a MoRef, I changed line 12 to get the MoRef of the datastore. I hope this will solve your problem.

# Get SharedTMPLs disk reference
$esxMoRef = $scHost | % {get-View $_.Id}
$esxStorageSystem = $esxMoRef.configManager.StorageSystem
$esxStorageSystemMoRef = get-View $esxStorageSystem
$ds = get-Datastore -name 'SharedTMPLs' -VMhost $scHost | get-View
$SharedTMPLs = new-Object VMware.Vim.VmfsDatastoreExtendSpec
$SharedTMPLs.Extent = $ds.info.vmfs.extent
# Lun should be naa.60060160eb702600d845dba3a40adf11 on the Orange kit
# Destroy SharedTMPLs datastore
remove-Datastore -Datastore SharedTMPLs -VMHost $scHost -confirm:$false start-Sleep -s 1
# Add SharedTMPLs disk space to SharedVMs
$sharedVMsDS = (get-Datastore -name 'SharedVMs' -VMhost $scHost).Id
$dsView = get-view $scHostView.configManager.DatastoreSystem
$dsView.extendVmfsDatastore($sharedVMsDS, $SharedTMPLs) 

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
carl1
Expert
Expert
Jump to solution

Well, that got me closer. I finally worked out the exact sequence. The code is attached for others to reference in their adventures. Thanks for all your help!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I came up with something similar.

Wouldn't have posted it since you gave your solution, but it shows how to get the correct Uuid.

For info, the script adds the LUN from DS4 to DS3 as an extent.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos