Wednesday, March 13, 2019

Working with Cisco Nexus 9K switches using PowerShell

In this article, I will explain briefly about how to work with Cisco NX-API CLI through PowerShell. Before getting into the steps and sample PowerShell code, lets first familiarize with NX-API Developer Sandbox. You can access the sandbox by entering the management IP of your Cisco switch in a web browser. Provide user name and password. Once successfully logged in, you will get a page as shown below. The developer sandbox will convert the normal CLI commands into JSON request and will also provide result/ response in JSON format.

NX-API Developer Sandbox

In the above screenshot, I am using "show hostname" command. The message format is set to JSON and command type is set to cli_show to get a response in JSON. Once done, hit POST. You can see the corresponding request and response in JSON format.

Now, let's try to do the same using PowerShell.

#Step1:

<# 
To fix the connection issues <The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.>
#> 
add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
        ServicePoint srvPoint, X509Certificate certificate,
        WebRequest request, int certificateProblem) {
        return true;
        }
    }
"@

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls11

#Step2:

$creds = Get-Credential

#Step3:

$request = @'
{
    "ins_api": {
          "version": "1.0",
          "type": "cli_show",
          "chunk": "0",
          "sid": "1",
          "input": "show hostname",
          "output_format": "json"
    }
}
'@

#Step4:

$result = Invoke-RestMethod -Uri "http://<IP of switch>/ins" -Method post -Credential $creds -ContentType "application/json" -Body $request


Output:


Hope it was useful. Cheers!

Reference:

Friday, February 15, 2019

Deleting inaccessible objects from vSAN cluster

Scenario:


Resolution:

  • Login to vSAN VCSA as root
  • rvc
  • Provide a username that has administrator privileges @localhost as shown below
  • Change directory to localhost
  • Now browse through and set the directory to the respective cluster (in my case cluster name is "Cluster-Rack7")
  • vsan.check_state -r <path to your cluster>
  • You can purge vswp objects using: vsan.purge_inaccessible_vswp_objects <path to cluster>
  • In this case its not a vswp object. So we have to find the owner node of the object and delete it forcefully from there.
  • vsan.cmmds_find -u <UUID of object> <path to cluster> to find owner of the object
  • SSH into the owner node and delete the inaccessible object file forcefully using /usr/lib/vmware/osfs/bin/objtool delete -u <UUID of inaccessible object> -f -v 10
  • Perform vSAN health check to verify status

Hope it was useful. Cheers!

References:

Friday, January 25, 2019

How to manually add multiple NICs to the vROps 7.x appliance

This article explains how to add multiple network interfaces to a vROps 7.0/ 7.5 appliance. Recently we had a scenario where the vROps appliance needs access to different networks which are isolated/ not routed with the primary network management interface of vROps. In my case the vROps instance needed access to 3 different networks.

Initially while installing the vROps there will be only one interface (eth0) and its the default interface for vROps appliance.  


For configuring additional interfaces follow the steps below:

  • Add a network card and connect to the respective port group by editing VM settings
  • Login to vROps with root creds
  • cd /etc/sysconfig/network
  • Create an entry for the new interface eth1 (as it will not be present!)
  • vi ifcfg-eth1
  • Provide all necessary IP details and save

  • Reboot the appliance
  • Verify details

  • Similarly, follow the above steps if you require more interfaces 
Note: I am not sure whether this is officially supported by vROps, but it works! Haven't found any VMware documentations related to this.

Wednesday, December 12, 2018

Inactive or missing VMware VMFS datastore

Today I came across a situation where one of the shared VMFS datastores in a 4 node ESXi 6.5 cluster was found missing/ inactive after a planned reboot. This post is about the steps I followed to resolve this issue/ re-mount the inactive shared datastore.

On a ESXi node, to list the datastores that are available to mount: esxcfg-volume –l
To mount the available datastore: esxcfg-volume –M <UUID>

Sample screenshot is given below:


Hope it was useful. Cheers!

Reference:
https://community.spiceworks.com/topic/2108624-missing-datastore-after-upgrade-from-esxi-6-0-to-6-5

Saturday, November 17, 2018

Real time VMware VM resource monitoring using PowerShell

This post is about monitoring resource usage of a list of virtual machines hosted on VMware ESXi clusters using PowerCLI. Output format is given below which gets refreshed automatically every few seconds.

Prerequisites:
  • VMware.PowerCLI module should be installed on the node from which you are running the script
  • You can verify using: Get-Module -Name VMware.PowerCLI -ListAvailable
  • If not installed, you can find the latest version from the PSGallery: Find-Module -Name VMware.PowerCLI
  • Install the module: Install-Module -Name VMware.PowerCLI
Note:
  • I am using PowerCLI Version 11.0.0.10380590

Latest version of the project and code available at: github.com/vineethac/vmware_vm_monitor

    Sample screenshot of output:


    Notes:

    VMware guidance: CPU Ready time and Co-Stop values per core greater than 5% and 3% respectively could  be a performance concern.

    Hope this will be useful for resource monitoring as well as right sizing of VMs. Cheers!

    References:

    Saturday, October 20, 2018

    Real time VMware datastore performance monitoring using PowerShell

    I had a scenario where we had to monitor the real time performance statistics of multiple shared VMFS datastores which are part of a multi-node VMware ESXi cluster. So this post is about the short script which uses VMware PowerCLI to get read/ write IOPS and latency details of these shared datastores across all nodes in the cluster. The output format is given below which gets refreshed automatically every few seconds.

    Prerequisites:
    • VMware.PowerCLI module should be installed on the node from which you are running the script
    • You can verify using: Get-Module -Name VMware.PowerCLI -ListAvailable
    • If not installed, you can find the latest version from the PSGallery: Find-Module -Name VMware.PowerCLI
    • Install the module: Install-Module -Name VMware.PowerCLI
    Note:
    • I am using PowerCLI Version 11.0.0.10380590


    Latest version of the project and code available at: github.com/vineethac/datastore_perfmon

    Sample screenshot of output:


    Hope it was useful. Cheers!

    Reference:

    Saturday, September 15, 2018

    Working with iDRAC9 Redfish API using PowerShell - Part 2

    In this article I will explain briefly about the JSON response from iDRAC and how you can navigate through the Redfish API tree structure to get all the required information. Now, lets have a look at the URIs. 

    Query the computer system collection:
    $result1 = Invoke-RestMethod -Uri "https://$($idrac_ip)/redfish/v1/Systems" -Credential $Credentials -Method Get -UseBasicParsing -ContentType 'application/json'

    Response: 

    You can see one member with URI /redfish/v1/Systems/System.Embedded.1

    Below is a sample screen shot of JSON output when you try to query the above listed member system. 


    You can get some of the basic information straight away from the above JSON response. And these are organized in hierarchy where you can drill down to each object and get the required details. Below diagram shows basic iDRAC Redfish API tree structure.


    Example: You can get details/ health status of  storage controller as shown below.

    Query:
    $result2 = Invoke-RestMethod -Uri "https://$($idrac_ip)/redfish/v1/Systems/System.Embedded.1/Storage /Controllers/NonRAID.Integrated.1-1" -Credential $Credentials -Method Get -UseBasicParsing -ContentType 'application/json'