Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # -----------------------------------------------------------------------------
- # "THE BEER-WARE LICENSE" (Revision 42):
- # zmey20000@yahoo.com wrote this file. As long as you retain this notice you
- # can do whatever you want with this stuff. If we meet some day, and you think
- # this stuff is worth it, you can buy me a beer in return Mikhail Zakharov
- # -----------------------------------------------------------------------------
- # Hitachi Command Suite XML API usage example in Pyton.
- import base64
- import http.client
- import xml.etree.ElementTree as ET
- # ----------------------------------------------------------------------------
- hcs_server = 'hcs8.server.name'
- login = 'system'
- password = 'manager'
- command = 'StorageArray'
- option = 'all'
- # ----------------------------------------------------------------------------
- b64lp = base64.b64encode((login + ':' + password).encode('ascii'))
- body = """<?xml version="1.0" encoding="UTF-8"?>
- <HiCommandServerMessage>
- <APIInfo version="7.6" />
- <Request>
- <StorageManager>
- <Get target=""" + '"' + command + '" ' + """option=""" + '"' + option + '" ' + """>
- <StorageArray />
- </Get>
- </StorageManager>
- </Request>
- </HiCommandServerMessage>"""
- headers = {'Content-Type': 'text/xml',
- 'User-Agent': 'Deck Eight:One Step:0',
- 'Authorization': 'Basic ' + b64lp.decode('utf-8')}
- httpc = http.client.HTTPConnection(hcs_server, 2001, timeout=30)
- httpc.request('POST', '/service/ServerAdmin', body, headers)
- resp = httpc.getresponse()
- #print(resp.status, resp.reason)
- data = resp.read()
- data = data.decode('utf-8')
- root = ET.fromstring(data)
- for array in root.iter('StorageArray'):
- name = array.get('name')
- hardwareRevision = array.get('hardwareRevision')
- cacheInMB = array.get('cacheInMB')
- totalFreeSpaceInKB = array.get('totalFreeSpaceInKB')
- allocatedCapacityInKB = array.get('allocatedCapacityInKB')
- capacityInKB = array.get('capacityInKB')
- numberOfControllers = array.get('numberOfControllers')
- controllerVersion = array.get('controllerVersion')
- productName = array.get('productName')
- arrayType = array.get('arrayType')
- serialNumber = array.get('serialNumber')
- print(name, serialNumber, arrayType, productName, totalFreeSpaceInKB, allocatedCapacityInKB, capacityInKB, controllerVersion, numberOfControllers, cacheInMB, hardwareRevision)
- httpc.close()
Add Comment
Please, Sign In to add comment