PowerShell

API v310.64 Documentation Available

Greetings,

The v310.64 API documentation is now available on Tintri’s GitHub site. So what’s new:

  • Four new systemProperty APIs which allows customization of the following system properties:
    • used percent alert low threshold
    • used percent aler high threshold
    • reserves used percent alert threshold
    • use percent disable snapshots threshold
    • use percent disable replication threshold
  • more Datastore statistics
    • snapshot space saving factor
    • space savings factor including snapshot savings

For more explanations on system properties, go to the systemProperites Data Transfer Object (DTO) documentation; and for more information on the new snaphot factors, go to the DatastoreStat DTO documentation.

Currently the PowerShell Toolkit and the Python SDK do not support the system property APIs except in raw API form.  See SysPropertyManger.ps1 for an example. However, the new information in the Datastore DTO is available to the Python SDK and the PowerShell Toolkit.

Happy coding,

– Rick –

Advertisements

Upgrade VMstores in Parallel

Greetings,

I just added some PowerShell code that upgrades VMstores in parallel to our GitHub site.  A JSON configuration file is used to configure the VMstores.  For example:

[
    {
        "VmstoreDnsName": "vmstore1",
        "Username": "username",
        "Password": "password",
        "UpgradePathToFile": "C:\Users\TestUser\upgrade_file.rpm"
    },
    {
        "VmstoreDnsName": "vmstore2",
        "Username": "username",
        "Password": "password",
        "UpgradePathToFile": "C:\Users\TestUser\upgrade_file.rpm"
    }
]

The only required attribute is the VmstoreDnsName. All the other attributes are optional and can be from the command line.  Here is a JSON configuration with only the VMstore names:

[
    {
        "VmstoreDnsName": "vmstore1"
    },
    {
        "VmstoreDnsName": "vmstore2"
    }
]

The following code can uses the above file.

Import-Module -Name .\VmstoreUpgrade.psm1
Import-Module -Name .\Parallel-Upgrade.psm1

# Set the user, VMstore configuration file, and upgrade file.
$user = "admin"
$vmstore_list_file = ".\vmstore_upgrade_list.json"
$upgradeFile = "C:\tmp\txos-4.3.1.5-8520.45801.20652.x86_64.rpm"

# Do the parallel upgrade.
Write-Host "Parallel updating VMstores with $upgradeFile"

# Get credentials that will work for all VMstores.
$cred = Get-Credential -Username $Username -Message "Enter valid password for all servers"
$pass = $cred.GetNetworkCredential().Password

# Start the parallel upgrade using a JSON file containing the VMstores, and
# the same username and password for all VMstores. 
Parallel-Upgrade -Verbose -UserName $user -UseSameUserName -Password $pass -UseSamePassword -UpgradeFile $upgradeFile -UseSameUpgradeFile -UseJsonFile $vmstore_list_file

Write-Host "Done Updating"
Write-Host ""

The above code gets a credential that is valid for all VMstores in the configuration file. Then the command line specifies the user name, password, and two options, -UseSameUserName, and -UseSamePassword.

Parallel-Upgrade logs to a dated log file: YYYY-MM-dd-HH-mm-ss_parallel_upgrade.log. The Verbose option will produce extra verbiage to follow along in the process and assist in debugging problems.  Unfortunately, you have to read the Parallel-Upgrade.psm1 module for help.

Until next time,

– Rick –

Invoke-RestMethod Exception Handling with Tintri APIs

Greetings,

Recently, I’ve been working in PowerShell.  Tintri has a great PowerShell Toolkit, but unfortunately some APIs cannot be invoked via the Toolkit.  So to invoke APIs that are not in the Toolkit, you can use Microsoft’s Invoke-RestMethod.  In this blog, I’m only going to discuss exception handling.

Try {
    $resp = Invoke-RestMethod -Uri $url -Method Delete -WebSession $session -ContentType $JSON_CONTENT
}
Catch {
    # Obtain some information
    $expMessage = $_.Exception.Message
    $failedItem = $_.Exception.Source
    $line = $_.InvocationInfo.ScriptLineNumber

    # Check if there is a response.
    if ($_.Exception.Response -eq $null) {
        Write-Host "At $($line):`r`n$expMessage" -ForeGroundColor Red
    }
    else {
        # Get the response body with more error detail.
        $respStream = $_.Exception.Response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($respStream)
        $respBody = $reader.ReadToEnd() | ConvertFrom-Json
        $errorCode = $respBody.code
        $errorMessage = $respBody.message
        $causeDetails = $respBody.causeDetails
       Write-Host "At line $($line):`r`n$expMessage`r`n$($errorCode): $errorMessage`n`r $causeDetails" -ForegroundColor Red
    } 
}

Take the example code above where we invoking a GET API.  The variable $session is the session ID and $url is of course the API URL.

If there is an Invoke-RestMethod() error, the exception is thrown and the Catch block is executed.  When a Tintri API error occurs Invoke-RestMethod does not return any data, and there is more information in the API response.  See the Error Handling section in the API documentation where the error response is documented:

{"typeId":"com.tintri.api.rest.v310.dto.domain.beans.TintriError",
 "code":"ERR-API-8001",
 "message":"Failed to find requested resource of type VirtualMachine with id: 'xxxxddd'",
 "causeDetails":"",
 "title":"Resource not found"
}

So how do you get that error information in the response?  Fortunately Chris Wahl shared some great information on his blog.  As you can see, the first three bold lines in the second part of  the Catch block is directly from Chris.  The italicized part is what I added for Tintri errors.

The code now checks Exception.response; therefore, this Catch block can now handle both non-Tintri and Tintri errors.  I changed Write-Error to Write-Host with a red foreground color for simpler output.

The response stream returns a string.  To get the error code and the error message, the split function would need to be used twice within a loop; or just call ConvertFrom-JSON which which gives us a nice dictionary to easily pluck out errorCode, errorMessage, and causeDetails.

Until next time,

– Rick –

 

Private Cloud Automation

I want to point out a set of 4 postings by Matthew Geddes, a Hyper-V architect, on Automation and Private Cloud.

  1. Part 1: sets the stage: a number of production SQL Server instances where some nightly reporting jobs are run. These reporting jobs are quite heavyweight and impact other users during their large processing window. What we want to do is to have the reporting jobs run on non-production VMs with that day’s production data.
  2. Part 2: shows how how to use syncVM from Tintri’s PowerShell Toolkit.  Matt breaks down usage of the PowerShell cmdlet, Sync-TintriVDisk; and then shows how to integrate it into a small script.
  3. Part 3: adds more code to the small script and wraps it into a function so that it can be used for multiple reports.
  4. Part 4: adds more automation with by showing how to parameterize the reports.  Matt summarizes and gives you some homework.

I like the way Matt goes through presents the use case, and then goes through the code step by step.

Until next time,

– Rick –

Changing QoS during Veeam Backups

Tintri’s QoS is a great tool to limit storage bandwidth per VM, but what happens when a backup occurs?  Well, QoS will also limit your backup storage IOPS. If this is an issue in your environment, you might consider clearing the QoS during backup.

As an example of clearing QoS when a backup occurs,  a PowerShell script is now available that interacts with Veeam Backup and Replication.  The script, Veeam_Backup_Tintri_QoS.ps1 is available on GitHub.  The file, README.md has the information needed to run the script.

Basically the script polls the Veeam backup server every 10 seconds. When a Veeam backup job has started, the script finds the associated storage.  If the storage is on a VMstore and QoS is set, then the QoS is cleared.  After the job is done, the script restores the QoS settings.  A TGC server is required since the script connects only to a TGC.

Below is a diagram of Veeam_Backup_Tintri_QoS.ps1 (Backup Script) running in the Veeam backup server.

.veeam_tgc_diagram

However the backup script could be in a separate VM.

This script could possibly be used as a template for other backup vendors.  Results may very.  Veeam made it straight-forward with a PowerShell plug-in.

Until next time,

– Rick –

tintri_veeam_logos_small

PowerShell VM CSV Report

Greetings,

A customer via a colleague, Satinder Sharma, wanted to have a CSV output from Get-TintriVM. Their attempt was:

Get-TintriVM  | Export-Csv WS_inventory.csv

This does nothing.  After some experimentation and assistance from Dhruv Vermula, we have this:

Get-TintriVM | Select-Object {$_.vmware.name}, {$_.Uuid.UuId} | Export-csv vm2.csv

This works, but the columns are “$_.vmware.name” and “$_Uuid.Uuid”, which is not very friendly.  So I created created a small script, VmCsvReport, that is similar to a blog post “Obtain a VM CSV Report“.  This script creates nice columns; for example, “VM Name” instead of “$_.vmware.name” and creates a CSV file.

The script uses @{Expression} to create alias columns.

 $ex = @{Expression={$_.vmware.name};label="VM Name"},
       @{Expression={$_.stat.sortedstats.LatencyTotalMs};label="Total Latency"},
       @{Expression={$_.stat.sortedstats.LatencyNetworkMs};label="Network Latency"},
       @{Expression={$_.stat.sortedstats.LatencyStorageMs};label="Storage Latency"},
       @{Expression={$_.stat.sortedstats.LatencyDiskMs};label="Disk Latency"}

The output of Get-TintriVM is piped into Select-Object using the aliases in $ex.  Then $results is piped to the Export-Csv cmdlet to create a CSV file.  This could be done in one line, but I broke it up so that I could easily examine the output in debug.

$result = Get-TintriVM -TintriServer $conn | Select-Object $ex
$result | Export-Csv $csv_file

The specified VM information is in the CSV file which Excel can read quite easily.

Unfortunately, the columns are hard-coded in the script, because the PowerShell Toolkit does not have a cmdlet that maps the CSV download API.  I couldn’t suss-out a way to have configurable columns similar “Obtain a VM CSV Report“. If you know a way, please let me know.

Until next time,

– Rick –

PowerShell 2.5 Toolkit Released

Greetings,

It has been a while since I have posted. While I’ve been on vacation and catching-up, my colleague was working on a new Tintri Automation Toolkit for PowerShell 2.5. Today it went up on Tintri’s support site for your downloading pleasure. If you haven’t visited the support site in a while, you’ll notice that it has changed. Once on the support download page, find “Tintri Automation Toolkit 2.5” and click on it. An information frame will appear on the right. Click on “Download MSI” to download the new toolkit.

The major features are:
• Upgrade VMstore(s) given the RPM file
• Configure appliance settings (Data IPs, DNS, Autosupport, Alerts)
• Configure Hypervisor Managers on a VMstore
• Set Service Group QoS
• Support for SyncVM File-Level-Restore
• Manage VMstores on a TGC
• Set quota on SMB shares
• Support for PowerCLI 6

A more information is on my Tintri blog. For me, the top 3 features are: Tintri command search, setting QoS in TGC Service Groups, and updating VMstores from a downloaded RPM file.

Let me know if you have questions, or have coded new scripts you want posted on our GitHub site.

Cheers,

– Rick –

PowerShell Automation Toolkit 2.0

Greetings,

Just a quick note to inform you that the PowerShell Automation Toolkit version 2.0 is now in Tech Preview.  Tech Preview means that the toolkit is available for download and we want your feedback.  In brief, the PowerShell Toolkit 2.0 includes these features:

  1. TGC Service Groups
  2. Setting QoS policies per VM
  3. Hyper-V VM Cloning
  4. High Frequency Snapshots
  5. Deleting Snapshot Schedules
  6. SSO authentication with VMstore
  7. SyncVM

When the new GitHub code examples are available, I’ll let you know.

Regards,

– Rick –

Tintri Automation Toolkit 1.5 Released

The Tintri Automation Toolkit version 1.5 is now released.  The Automation Toolkit allows you to manage Tintri VMstore and TGC using PowerShell.  It can be obtained from Tintri Support download page under the “Download” tab, and you need a login.

The Automation Toolkit QuickStart Overview Guide can be downloaded from Tintri Support download page under the “User Guides” tab.  Scroll down to “3/2/2015 entry: “Tintri Automation Toolkit Quick Start Overview Guide”.  The guide lists all the PowerShell cmdlets, discusses how to get help and authentication, and has code samples.  See my previous PowerShell post for pictures on how to download.

The 1.5 version highlights are:

  • Hyper-V VM management
  • Delete Snapshot
  • SMB Share management
  • Support v310 Tintri API servers (as well as v300)
  • View datastore level statistics from TGC 1.1
  • On-line help improvements

Just like VMware VMs can be piped to Tintri cmdlets, so can Hyper-V VMs be piped to Tintri cmdlets.  This is what it means to be virtually aware storage.

Tintri Automation Toolkit examples are now being posted on GitHub.  Check-out the following examples that demonstrate the new features:

Over time, more PowerShell examples will be added, so check periodically.

Enjoy the new features,

– Rick –

Tintri Releases PowerShell Automation Toolkit

Greetings,

Tintri has released a PowerShell Automation Toolkit.  The toolkit works with Tintri OS 3.0.  To download it, go to Tintri’s support site, http://support.tintri.com.  You will have to log in and be a Tintri user.

Tintri download page

Tintri download page

Click on ‘Downloads in the green rectangle, and then click on ‘Download’ in the ‘Tintri Automation Toolkit 1.0″ box as noted by the purple rectangle.

A Quick Start Guide is provided.  Click on the ‘User Guides’ tab.

Tintri User Guides

Tintri User Guides

Click on the ‘Tintri Automation Toolkit Quick Start Overview Guide’.  It is PDF, and has download information, and a little more information about the PowerShell Toolkit.  A code example is in the guide.  There are more PowerShell code examples under the ‘Utilities’ tab.

Tintri Utilities Page

Tintri Utilities Page

Click on the ‘Automation Toolkit PowerShell Examples. In the zip file, you will find 13 examples ranging from cloning, replication,  snapshots, and VM monitoring.  There is an HTTP index for your convenience.  These simple examples are there to get you going and give you a feel for the Toolkit.  These examples would need to be modified to suit your environment and are for reference purposes only.

Tintri’s PowerShell cmdlets integrate with VMware’s PowerCLI to provide end-to-end VM-level automation; for example, the output of VMware PowerCLI Get-VM command can be piped to the Get-TintriVM cmdlet. This is demonstrated in the Workflow_VMMonitoring script.

Finally, check-out Luc Deken’s excellent 2-part series on Tintri’s PowerShell Toolkit at http://www.lucd.info/2014/08/14/tintri-automation-toolkit-basics-part-1/ and http://www.lucd.info/2014/08/14/tintri-automation-toolkit-basics-part-2/.

Enjoy,

– Rick –