Yes it is possible I have attached a python script here which will display the details of a VPLEX context. I've tested it quite a few times and it does work. Below is the output from a run that displays the information for a cluster-witness:
Output:
Enter hostname or IP address> 10.250.X.X
Enter username> service
Enter password>
Type in the context to display data> cluster-witness
Have you tried printing the username and password to the console before you attempt to login? Maybe something is getting added or removed in the process of assigning the strings to username and password. You could also temporarily disable the inputs for username and password and put them in manually here:
the syntax is definitely correctly as I was able to connect to my github account with this method, not sure why I cannot get it past VPLEX authentication though.
Good news. I have other scripts as well but this is the first I wrote and it's been the foundation for the others. The biggest piece is iterating through the attributes, finding the appropriate names, determining the type of object the value is and then printing it out.
This loop looks for type virtual-volume and then finds the values for a few things I need for my documentation:
for ini in parsed_json["response"]["context"]:
if ini["type"] == 'virtual-volume':
for x in range(len(ini["attributes"])):
if ini["attributes"] ["name"] == 'name':
volName = ini["attributes"] ["value"]
if ini["attributes"] ["name"] == 'vpd-id':
vpdId = ini["attributes"] ["value"]
vpdId = re.sub('VPD83T3:', '', vpdId)
if ini["attributes"] ["name"] == 'capacity':
capBytes = ini["attributes"] ["value"]
if ini["attributes"] ["name"] == 'locality':
local = ini["attributes"] ["value"]
clusterid = ini["parent"]
if re.search("cluster", clusterid):
cid = clusterid[10:19]
if cid == 'cluster-1':
dc = 'PDC'
else:
dc = 'SDC'
strLine = volName + ',' + vpdId + ',' + capBytes + ',' + local + ',' + dc
Not sure if you've seen this, but in terms of sample scripts there's a zip file on every VPLEX management server in /opt/emc/VPlex/clientscripts.zip. This is a copy: https://community.emc.com/docs/DOC-64817 Gary
getting below error during passing of the arguments will you be able to help
xyz-vp01.ikea.com { "response": { "context": null, "message": "export storage-view find-unmapped-volumes", "exception": "export storage-view Evaluation of < > failed.\ncause: Command execution failed.\ncause: missing argument --cluster: Unable to find a\n reasonable default value for this option when\n this command is executed in the current context.\n", "custom-data": null } }
ThomDaleyPPI
1 Rookie
•
108 Posts
7885
1
Posted August 6th, 2018 05:00
Yes it is possible I have attached a python script here which will display the details of a VPLEX context. I've tested it quite a few times and it does work. Below is the output from a run that displays the information for a cluster-witness:
Output:
Enter hostname or IP address> 10.250.X.X
Enter username> service
Enter password>
Type in the context to display data> cluster-witness
admin-state enabled
name cluster-witness
private-ip-address 128.221.254.3
public-ip-address 10.250.X.X
components components-in-cluster-witness
Code:
#################################################################################################
# #
# This python script uses REST on VPLEX to grab config data. The user is prompted #
# for the context and the data is displayed on separate lines. #
# need to add a check for dict object type #
#################################################################################################
import json
import requests
import csv
import re
import getpass
import sys
requests.packages.urllib3.disable_warnings()
#Get user input
hostname = input("Enter hostname or IP address> ")
username = input("Enter username> ")
passwd = getpass.getpass("Enter password> ")
context = input("Type in the context to display data> ")
headers = {'content-type': 'application/json'}
url = 'https://' + hostname + '/vplex/' + context
response = requests.get(url, auth=(username,passwd), headers=headers, verify=False)
if response.status_code != 200:
sys.exit("JSON Request failed error code: " + str(response.status_code))
parsed_json = json.loads(response.text)
for ini in parsed_json["response"]["context"]:
clusterid = ini["parent"]
if re.search("cluster", clusterid):
cid = clusterid[10:19]
print('Cluster ID: ' + cid)
#print(response.text)
for x in range(len(ini["attributes"])):
#Test for value type. If it's a null, then skip it. If it's a list then iterate through it. If it's a string then print it.
if ini["attributes"] ["value"] == None:
continue
elif isinstance(ini["attributes"] ["value"], list):
#Iterate through the list
strList = ''
strName = ini["attributes"] ["name"]
for l in range(len(ini["attributes"] ["value"])):
strList = ini["attributes"] ["value"] + ',' + strList
prtName = strName + ' ' + strList
print(prtName)
else:
print(ini["attributes"] ["name"] + ' ' + ini["attributes"] ["value"])
for y in range(len(ini["children"])):
print(ini["children"] ["name"] + ' ' + ini["children"] ["type"])