PowerCLI

 View Only
Expand all | Collapse all

Latency to be available to execute commands

  • 1.  Latency to be available to execute commands

    Posted Jul 29, 2013 03:08 PM

    Hi,

    I have setup a full powershell script in order to duplicate a master from 1 vCenter to another one.

    The way I am doing it is by snapmirroring (netapp storage) the volume where my Master is, then clone the lmast snapshot within the snapmirror and attach this clone a regular datastore to the 2nd vCenter.

    The issue I am facing is that in order to complete the storage attachment to my vCenter, I need to wait for something, but what ?, in order for the command to operate.

    Pratically, here is the script

    Connect-VIServer myvcenter
    $servers = Get-VMHost -location "MYCLUSTER"
    $server = Get-VMHost | WHERE {$_.Name -eq "myesxi.local.com"}
    Get-VMHostStorage -VMHost $server -RescanAllHba

    Get-Datastore -VMHost $server.Name -Refresh

    Then I enable SSH in order to pull the details for mapping the storage

    Start-VMHostService -HostService ($server | Get-VMHostService | Where { $_.key -eq "TSM-SSH"})
    $User = "root"
    $Pswd = "xxxxxxxxxx"
    $Computer = "myesxi.local.com"
    $plink = "c:\Scripts\plink.exe"
    $plinkoptions = " -ssh -pw $Pswd"

    $remoteCommand = "`"esxcfg-volume -l`""

    $command = $plink + " " + $plinkoptions + " " + $User + "@" + $computer + " " + $remoteCommand

    $Resultat = Invoke-Expression -command $command

    And this is where my 1st problem starts. I need to run that last command 6 or 7 time for it to give me the right result.

    Once this works I continue with this where I have the exact same issue

    $UUID = (($Resultat[0].Split(" "))[2].Split("/"))[0]

    $remoteCommand = "esxcfg-volume -M `"$UUID`""
    $command = $plink + " " + $plinkoptions + " " + $User + "@" + $computer + " " + $remoteCommand
    Invoke-Expression -command $command

    Stop-VMHostService -HostService ($server | Get-VMHostService | Where { $_.key -eq "TSM-SSH"}) -Confirm:$false

    Get-Datastore -VMHost $server.Name -Refresh

    It takes a very long time the Get-Datastore -Refresh to show my the last datastore attached to my ESXi ?

    Am I doing something wrong or the bad way ?

    Should I wait for some results from something in order to be able to run that script one shot ?

    Many thanks in advance for your lights :smileygrin:



  • 2.  RE: Latency to be available to execute commands

    Posted Jul 29, 2013 03:24 PM

    I suspect you need to be able to poll the NetApp to verify that the SnapMirror is finished.

    Perhaps you could ask in the NetApp forum for the NetApp PowerShell Toolkit.



  • 3.  RE: Latency to be available to execute commands

    Posted Jul 29, 2013 03:37 PM


    Sorry, this part of the script was not included into what I copied but I do wait for the replication at NetApp level to be completed.

    Import-Module DataOntap
    Connect-NaController mycontroler
    Invoke-NaSnapmirrorUpdate -Destination mycontroler:bkp_Modeles -Source a2b2:Modeles

    Do { Start-Sleep -S 30 }
    Until ((Get-NaSnapmirror -Location bkp_Modeles).Status -eq "idle")

    Then I continue with the cloning part of the volume and the publication of the lun to my esx.

    It looks like when I run $Resultat = Invoke-Expression -command $command, for some reason I need to run it several times until I get the result.

    Is this the proper way to attach a Datastore to an Esxi ?

    Or should I just proceed the way I do for the snapmirror and loop until I get something in $Resultat ?



  • 4.  RE: Latency to be available to execute commands

    Posted Jul 29, 2013 05:03 PM

    I see.

    Is there a specific reason why you use plink.exe to get the LUNs

    You could do that with the Get-EsxCli cmdlet as well.

    Something like this

    $esxcli = Get-EsxCli

    $esxcli.storage.core.device.list()



  • 5.  RE: Latency to be available to execute commands

    Posted Jul 29, 2013 08:23 PM

    Hi LucD,

    Thanks for your info.

    The only reason why I am doing it this way is because this is the only way I managed to do the link between my storage and my Esxis in Powershell and to get something close to something working ... or kind of !

    I will be happy to take a look at what your are suggesting (can't remember if I already tried it) and let you know.


    Manu thanks



  • 6.  RE: Latency to be available to execute commands

    Posted Jul 30, 2013 09:06 AM

    Since I was struggling for the proper syntax of the commands mentioned above, I googled a lot trying to get the powercli structure of the command as opposed to the all bunch of ssh you can find for esxcli and I found this :http://blogs.vmware.com/vsphere/2012/01/automating-datastore-storage-device-detachment-in-vsphere-5.html

    I started playing with it and my guess is it should help and simplify a lot the all mount/unmount process :smileyhappy:.

    Sorry I couldn't figure out the way to use powercli esxcli

    Thanks



  • 7.  RE: Latency to be available to execute commands

    Posted Aug 05, 2013 10:37 AM

    Hi Luck,

    I must be really thick, I haven't been able to put something together that would work.

    The other code I found doens't allow me get the newly attached lun to add it as a datastore (clone) and I haven't been able to convert the ssh commands I found in the document related to get-esxcli and more specically $esxcli.storage.core.device.list() to get somewhere.

    Would you have by any chance a sample scriptI could start from ?

    Many thanks for your help.



  • 8.  RE: Latency to be available to execute commands

    Posted Aug 05, 2013 10:43 AM

    Sorry, but I don't have any NetApp HW available.

    Did you raise the question on the NetApp PowerShell Toolkit forum ?



  • 9.  RE: Latency to be available to execute commands

    Posted Aug 05, 2013 11:25 AM

    The way I see it is "I'm fine from the storage point of view, my new lun (cloned from existing one) is online and made available to all my ESXis.

    Are you saying that this would be specific to NetApp ?

    I don't see the commands required to list the newly available VMFS storage to VMware being dependant on the storage vendor ? Or Am I missing something ?

    When I do the esxcfg-volume -l in SSH, this is VMware checking available storage, not NetApp right ?

    Why would this be different in Powershell with the command you sugested ?



  • 10.  RE: Latency to be available to execute commands

    Posted Aug 05, 2013 11:42 AM

    That is correct.

    So you do see the new LUN with a esxcfg-volume -l ?

    The following $esxcli commands show the steps to take when mounting a replica.

    Can you try these ?

    # List replica (same as esscfg-volume -l)
    $esxcli.storage.vmfs.snapshot.list()

    # Mount a replica
    # The $volumeLabel and $volumeUuid can be found in the output
    # of the previous
    $esxcli.storage.vmfs.snapshot.mount($nopersist,$volumeLabel,$volumeUuid)

    # Resignature a replica
    $esxcli.storage.vmfs.snapshot.resignature($volumeLabel,$volumeUuid)

    # Rescan on all connected ESXi nodes
    Get-VMHost MyEsx | Get-VMHostStorage -RescanAllHba -RescanVmfs


  • 11.  RE: Latency to be available to execute commands

    Posted Aug 05, 2013 12:25 PM

    Getting closer and closer (best 1 who knows than 10 searching :smileywink:), thank you.

    I can pull my lun but must be missing something.

    Beside the fact I am having a hard time breaking the result down to get the VolumeName and UUID, even if I run it manually, I am getting the following error :

    =====================================================================================

    PowerCLI C:\> $esxcli.storage.vmfs.snapshot.mount($nopersist,$volumeLabel,$volumeid)

    Message: A target snapshot cannot be specified by both volume label and uuid.;

    InnerText: A target snapshot cannot be specified by both volume label and uuid.EsxCLI.CLIFault.summary

    Au niveau de ligne : 1 Caractère : 36

    + $esxcli.storage.vmfs.snapshot.mount <<<< ($nopersist,$volumeLabel,$volumeid)

        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

        + FullyQualifiedErrorId : MethodInvocationException

    =====================================================================================

    Should I set $nopersist to $true or $false ?

    I set $volumeLabel and $volumeid manually. For some reasons I need to look into, the resulat of $esxcli.storage.vmfs.snapshot.list() doesn't accept split.

    Looking at the error message, I have tried with only $VolumeLabel or $volumeid, for the same result.

    Any idea of what I am doing wrong ?
    doesn't accept split



  • 12.  RE: Latency to be available to execute commands

    Posted Aug 05, 2013 12:40 PM

    It looks as if you have to specify or a VolumeLabel or a VolumeId, but not both.

    Try setting one of the parameters to $null.

    That's what I meant by "I don't have any NetApp HW", I can't test out the info I'm giving you :smileycry:

    The value of $nopersist depends on your requirements, if the mount shouldn't survive the next reboot, set $nopersist to $true.

    The list() method returns on object with a number of properties.

    Do a

    $esxcli.storage.vmfs.snapshot.list() | Get-Member

    to check what properties are there.



  • 13.  RE: Latency to be available to execute commands

    Posted Aug 05, 2013 01:04 PM

    We are almost there :smileyhappy:

    With the label  to $null and nopersist =$true, I datastore mounts like a charm :smileyhappy::smileyhappy::smileyhappy:

    While e are there, would you know by any chance the proper syntax for $esxcli.storage.filesystem.unmount ?

    I have tried with juste the UUid, and it doesn't like it.

    Also, the get-memeber doesn't help me much. I am ggoona have to dig this part to get the data.

    Many many thanks.



  • 14.  RE: Latency to be available to execute commands

    Posted Aug 05, 2013 01:11 PM

    The unmount states it wants these parameters

    $esxcli.storage.filesystem.unmount($nopersist,$volumelabel,$volumePath,$volumeUuid)

    I suspect you will have to provide the $volumePath as well.

    Strange that the Get-Member doesn't show the properties.

    What output do you get ?



  • 15.  RE: Latency to be available to execute commands

    Posted Aug 05, 2013 03:30 PM

    Thank you very much, I am gonna play with the unmount thing.

    My appologies for  get-member. I have an output, but what I meant was none of the properties available appeal to me.

    I have played with GetEnumerator, GetValue, ToString etc but no luck. Need to google a bit that part.

    PowerCLI C:\> get-member -InputObject $newlun


       TypeName: System.Object[]

    Name           MemberType    Definition
    ----           ----------    ----------
    Count          AliasProperty Count = Length
    Address        Method        System.Object&, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b7...
    Clone          Method        System.Object Clone()
    CopyTo         Method        System.Void CopyTo(array array, int index), System.Void CopyTo(array array, l...
    Equals         Method        bool Equals(System.Object obj)
    Get            Method        System.Object Get(int )
    GetEnumerator  Method        System.Collections.IEnumerator GetEnumerator()
    GetHashCode    Method        int GetHashCode()
    GetLength      Method        int GetLength(int dimension)
    GetLongLength  Method        long GetLongLength(int dimension)
    GetLowerBound  Method        int GetLowerBound(int dimension)
    GetType        Method        type GetType()
    GetUpperBound  Method        int GetUpperBound(int dimension)
    GetValue       Method        System.Object GetValue(Params int[] indices), System.Object GetValue(int inde...
    Initialize     Method        System.Void Initialize()
    Set            Method        System.Void Set(int , System.Object )
    SetValue       Method        System.Void SetValue(System.Object value, int index), System.Void SetValue(Sy...
    ToString       Method        string ToString()
    IsFixedSize    Property      System.Boolean IsFixedSize {get;}
    IsReadOnly     Property      System.Boolean IsReadOnly {get;}
    IsSynchronized Property      System.Boolean IsSynchronized {get;}
    Length         Property      System.Int32 Length {get;}
    LongLength     Property      System.Int64 LongLength {get;}
    Rank           Property      System.Int32 Rank {get;}
    SyncRoot       Property      System.Object SyncRoot {get;}


    PowerCLI C:\>



  • 16.  RE: Latency to be available to execute commands

    Posted Aug 05, 2013 04:28 PM

    It looks as if $newlun is an array, and we want the properties of the elements in the array.

    Try like this

    $newlun[0] | Get-Member



  • 17.  RE: Latency to be available to execute commands

    Posted Aug 06, 2013 03:32 PM

    Hi LucD,

    Thank you very much for your time and Input. Sorry, for my late reply, I got caught with something else today.

    I played with the variable yesterday night and the only way I managed to get something was basicaly exporting-csv and then importing again.

    This way, I had access directly to the data and proceeded this way.

    ======================

    $esxcli.storage.vmfs.snapshot.list() | Export-Csv c:\scripts\test.csv

    $newlun = Import-Csv C:\Scripts\test.csv

    $nopersist = $true

    $volumeLabel = $null

    $esxcli.storage.vmfs.snapshot.mount($nopersist,$volumeLabel,$newlun.VMFSUUID)

    ======================

    Looks uggly to me :smileyconfused: but it does the job.

    I remember playing with $newlun[0] but can't remember if I tried your suggested command.

    Shall give it a try and let you know

    Many many thanks.