Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PowerFlex Manager API

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

PowerFlex Manager API

(PowerFlex REST API Introduction)


Mar 2023

1
Table Of Contents

Use cases
Create an NVMe host
Add volume to a resource group
Get compliance report

2
PowerFlex Manager API
Use cases

This section provides examples for the PowerFlex block API.

Create an NVMe host


Add a volume to a resource group
Get deployment compliance report (PowerFlex Manager 3.x)

Create an NVMe host

This use case demonstrates how to create an NVMe host in PowerFlex Manager.

The following data is required for our JSON payload:

Name of host
The host nqn identifier
The maximum number of paths
The maximum number of target ports

#Import modules

import requests

import json

from pfauth import authenticate

import urllib3

def createHost(pfxm, accessToken, hostName, hostNqn, maxPaths,


maxTargetPorts):

url = f'https://{pfxm}/api/types/Host/instances'

payload = json.dumps({

"name": f"{hostName}",

"nqn": f"{hostNqn}",

"maxNumPaths": f"{maxPaths}",

"maxNumSysPorts": f"{maxTargetPorts}"

3
PowerFlex Manager API
})

headers = {

'Content-Type': 'application/json',

'Accept': 'application/json',

'Authorization': f'Bearer {accessToken}'

response = requests.post(url, headers=headers, data=payload, verify=False)

return response.content

#Prompt user for PowerFlex Manager username and password.

username = input('Enter PowerFlex Manager username:')

password = getpass.getpass('Enter password:')

#Pass variables to the authenticate() function.

accessToken = authenticate(username, password)

#PFxM host

pfxm = 'pfmp.powerflex.lab'

#Variables for JSON payload

hostName = 'host1'

hostNqn = 'nqn.2014-08.org.nvmexpress:uuid:4c1c111-0031-4710-8036-
b8c04f425a32'

maxPaths = '4'

maxTargetPorts = '10'

#Call createHost function

response = createHost(hostName, hostNqn, maxPaths, maxTargetPorts)

Add volume to a resource group

4
PowerFlex Manager API
This use case demonstrates the steps required to add a volume to a storage-only
resource group.

#Import modules

import requests

import json

from pfauth import authenticate

import urllib3

#Expand resource group by adding volume

def addVolume(pfxm, accessToken, deploymentID, volName, volSize, spID,


volType):

url = f'https

://{pfxm}/Api/V1/Deployment/{deploymentID}/addvolumes'

payload = json.dumps({

"volumeRequests": [{

"numAutoGenerateVolumes": 0,

"volumeActionType": "NEW",

"volume": {

"name":f'{volName}',

"compressionMethod": "false",

"sizeInKb": f'{volSize}',

"storagePoolId": f'{spID}',

"volumeType": f'{volType}'}

}]

})

5
PowerFlex Manager API
headers = {

'Content-Type': 'application/json',

'Accept': 'application/json',

'Authorization': f'Bearer {accessToken}'

response = requests.post(url, headers=headers, data=payload, verify=False)

return response

#PFxM host

pfxm = 'pfmp.powerflex.lab'

#PowerFlex Manager username and password.

username = 'admin'

password = 'Password'

#Pass variables to the authenticate() function.

accessToken = authenticate(username, password)

#Target Deployment/Resource Group

deploymentID = '8aaa3a1c82c8df1a0182cc226f6b79d3'

#Variables for JSON payload

volName = 'restvol001'

volSize = '16777216'

spID = 'c5d4313100000000'

volType = 'thin'

#Call the addVolume function and pass required variables.

returnCode = addVolume(deploymentID,volName,volSize,spID,volType)

print (f'{returnCode}')

6
PowerFlex Manager API
Get compliance report

This use case prints the compliance report for a specified deployment. This example
uses PowerFlex Manager 3.x, which uses three custom headers for authentication.

Custom headers

X-dell.auth-key
X-dell-auth-signature
X-dell-auth-timestamp

Authentication process:

1. Call POST /Api/V1/Authenticate.


2. Concatenate the five values returned from the authentication call.
3. Compute a Base64 encoded SHA-256 HMAC digest of the concatenated request
string using the apiSecret obtained from the POST to /Api/V1/Authenticate call.
a. Compute the SHA-256 HMAC digest
b. Encode the HMAC digest using Base64
4. Set the three custom headers

import datetime

import hmac

import hashlib

import requests

import base64

import time

import sys

import getpass

# PFxM credentials

Usr = "admin"

Pwd = "password123"

Domain = "VXLOCAL"

7
PowerFlex Manager API
# PFxM IP address

srv: str = "172.128.30.30"

loginUri = "https://{}/Api/V1/Authenticate".format(Srv)

# print("loginUri is: {}".format(loginUri))

hdr = {'content-type': 'application/json',

'Accept': 'application/json'}

Conn = requests.Session()

Conn.headers = hdr

Conn.verify = False

authCred = {

"username": Usr,

"domain": Domain,

"password": Pwd

# for item in authCred.items():

# print(item)

rAuth = Conn.post(loginUri, json=authCred)

# print(rAuth.text)

AuthJson = rAuth.json()

# for item in AuthJson:

# print(item)

fmApiKey = str.format(AuthJson.get('apiKey'))

fmApiKeyEnc = fmApiKey.encode()

print("the api key is : {}".format(fmApiKey))

8
PowerFlex Manager API
# print(type(fmApiKey))

# print("the api keyenc is : {}".format(fmApiKeyEnc))

fmApiSecret = str.format(AuthJson.get('apiSecret'))

fmApiSecretEnc = fmApiSecret.encode()

print("the api secret is : {}".format(fmApiSecret))

# print(type(fmApiSecret))

# print("the api secret enc is : {}".format(fmApiSecretEnc))

timerightnow = str(int(datetime.datetime.now().timestamp()))

print("the time is : {}".format(timerightnow))

# print(type(timerightnow))

# uAgent = "PostmanRuntime/7.28.2"

uAgent = "My User Agent 1.0"

print("user agent is : {}".format(uAgent))

deployURI =
"https://{}/Api/V1/Deployment/2c9e649e78d6b7c00178e2a59ff63f9a/firmware/compli
ancereport".format(Srv)

print("the uri is : {}".format(deployURI))

deployURIpath =
"/Api/V1/Deployment/2c9e649e78d6b7c00178e2a59ff63f9a/firmware/compliancerep
ort"

print("the uri path is : {}".format(deployURIpath))

reqString = fmApiKey + ":" + "GET" + ":" + deployURIpath + ":" + uAgent + ":" +


timerightnow

reqStringEnc = reqString.encode()

print("reqString is : {}".format(reqString))

# print(type(reqString))

9
PowerFlex Manager API
reqHeadHash = hmac.digest(fmApiSecretEnc, reqStringEnc, hashlib.sha256)

# print(type(reqHeadHash))

# print("the digest is : {}".format(reqHeadHash))

reqHeadHashb64 = base64.b64encode(reqHeadHash)

print("the base 64 encoded value is : {}".format(reqHeadHashb64))

reqHeaderNow = {

'content-type': 'application/json',

'Accept': 'application/json',

'User-Agent': uAgent,

'x-dell-auth-key': fmApiKey,

'x-dell-auth-signature': reqHeadHashb64,

'x-dell-auth-timestamp': timerightnow

Conn.headers = reqHeaderNow

rDeployments = Conn.get(deployURI)

print("status is : {}".format(rDeployments.status_code))

print(rDeployments.text)

10
PowerFlex Manager API

You might also like