Passer au contenu principal
  • Passer des commandes rapidement et facilement
  • Afficher les commandes et suivre l’état de votre expédition
  • Profitez de récompenses et de remises réservées aux membres
  • Créez et accédez à une liste de vos produits
  • Gérer vos sites, vos produits et vos contacts au niveau des produits Dell EMC à l’aide de la rubrique Gestion des informations de l’entreprise.

Dell PowerVault ME4 Series Storage System CLI Guide

PDF

Using a script to access the CLI

Basic command-line semantics provide prompts for user input, and response time is indeterminate. Scripts need to use an “expect”-type mechanism to scan output for prompts. It is recommended and more efficient to use the HTTP interface to access the API.

Two login methods are supported:

  • HTTPS authentication using an SHA256 hash to return a session key that is sent for each request. The session key is valid has a 30-minute inactivity timeout. Use of SHA256 is now recommended instead of MD5, which is deprecated.

    To log in to the HTTPS API, the username and password must be joined with an underscore as a separator (username_password). The username and password is then sent through an SHA256 hash. The SHA256 hash is represented in lower case hexadecimal format. This string is appended to the login function for the API, https://IP-address/api/login/hash. For example:

    https://10.0.0.2/api/login/539e12f63b693a9970a97b885e857f8b
  • HTTPS basic authentication using the Authorization header. If this login method is used, the username and password must be joined with a ‘:’ (username:password) and then encoded in Base64. For example:

    Authorization: Basic base64-string

    Use the following URL for basic authentication:

    https://IP-address/api/login

For both methods, the response that is returned is in XML and the content contains an OBJECT element. Within the OBJECT element, a PROPERTY element with the name attribute of response contains the session key. These XML API elements are described in Table 1.

The following example shows how to construct a Perl script to communicate with the XML API using HTTPS:

NOTE:The API provides default self-signed certificates for an HTTPS connection. To validate the certificate, download it through a browser and then set the following environment variable to point to the certificate:
# export HTTPS_CA_FILE=path-to-certificate
# Include required libraries
 use LWP::UserAgent;
 use Digest::SHA qw(sha256_hex); 
 use XML::LibXML;

# Generate the login hash used to authenticate the user. The username 
# and password are hard coded here to illustrate the requirements for the string.
# The user name and password must be joined with an underscore.

my $auth_data = "username_password";
my $sha256_hash = sha256_hex( $auth_data );

# Create a user agent for sending https requests and generate a request object.

$user_agent = LWP::UserAgent->new( );
$url = 'https://IP-address/api/login/' . $sha256_hash;
$request = HTTP::Request->new( GET => $url );

# Send the request object to the system. The response will be returned.
$response = $user_agent->request($request);

# Once the script has logged in, the response returns back a session key.
# This code shows how to retrieve that session key.

my $parser = XML::LibXML->new();
my $document = $parser->parse_string( $response->content );

my $root = $document->getDocumentElement;
my @objects = $root->getElementsByTagName( 'OBJECT' );
my @properties = $objects[0]->getElementsByTagName( 'PROPERTY' ); 
my $sessionKey;
foreach my $property ( @properties ) {
my $name = $property->getAttribute( 'name' );

if( $name eq 'response' ) {
$sessionKey = $property->textContent;
}
}

The following example shows how to construct a Python script to communicate with the JSON API using HTTPS:

import sys 
import requests 
import json 
import hashlib

# NOTE: This is to suppress the insecure connection warning for certificate
# verification.
from requests.packages.urllib3.exceptions import InsecureRequestWarning 
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

url = "https://IP-address"
auth_string = hashlib.sha256('username_password').hexdigest()

# Login and obtain the session key. 
headers = {'datatype':'json'}
r = requests.get(url + '/api/login/' + auth_string, headers=headers, verify=False ) 
response = json.loads(r.content)
sessionKey = response['status'][0]['response']

# Obtain the health of the system
headers = {'sessionKey': sessionKey, 'datatype':'json'}
r = requests.get(url+'/api/show/system', headers=headers, verify=False) 
print r.content
response = json.loads(r.content)
print "Health = " + response['system'][0]['health']

The following code segment shows how to get the entire configuration information from the CLI and print the output using the ipa option for XML output:

NOTE:The output can be redirected to a file for archiving.
$url = 'https://IP-address/api/show/configuration';
$request = HTTP::Request->new(GET => $url );
$request->header('sessionKey' => $sessionKey );
$request->header('dataType' => 'ipa' );

$response = $user_agent->request( $request ); 
print $response->content;

Alternatively, the dataType in the request header can be set to json for JSON output, or to console for standard CLI text output. Do not use the console output should for parsing. However, the console output can be useful for tabular reports that are obtained directly from the CLI commands.


Évaluez ce contenu

Précis
Utile
Facile à comprendre
Avez-vous trouvé cet article utile ?
0/3000 characters
  Veuillez attribuer une note (1 à 5 étoiles).
  Veuillez attribuer une note (1 à 5 étoiles).
  Veuillez attribuer une note (1 à 5 étoiles).
  Veuillez indiquer si l’article a été utile ou non.
  Les commentaires ne doivent pas contenir les caractères spéciaux : <>()\