...
 
#!/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import time
import argparse
......@@ -12,6 +14,7 @@ import logging
import logging.handlers
import csv
import re
import warnings
# Create log-object
......@@ -37,6 +40,9 @@ def storwize_connect(storwize_user, storwize_password, storwize_ip, storwize_por
try:
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Work around py-cryptography deprecation warnings triggered by paramiko
with warnings.catch_warnings():
warnings.filterwarnings(action='ignore', module='paramiko')
ssh_client.connect(hostname=storwize_ip, username=storwize_user, password=storwize_password, port=22)
storwize_logger.info("Connection Established Successfully")
return ssh_client
......@@ -108,8 +114,9 @@ def advanced_info_of_resource(resource, needed_attributes, storwize_connection,
elif resource == 'lsenclosurepsu':
stdin, stdout, stderr = storwize_connection.exec_command('svcinfo {0} -psu {1} {2}'.format(resource, id_of_resource[1], id_of_resource[0]))
if len(stderr.read()) > 0:
storwize_logger.info("Error Occurs in advanced info of enclosure - {0}".format(stderr.read()))
stderr_content = stderr.read().rstrip('\n')
if len(stderr_content) > 0:
storwize_logger.info("Error Occurs in advanced info of enclosure - {0}".format(stderr_content))
storwize_logout(storwize_connection)
sys.exit("1100")
else:
......@@ -173,8 +180,9 @@ def discovering_resources(storwize_user, storwize_password, storwize_ip, storwiz
for resource in list_resources:
stdin, stdout, stderr = storwize_connection.exec_command('svcinfo {0} -delim :'.format(resource))
if len(stderr.read()) > 0: # Если случились ошибки, запиши их в лог и выйди из скрипта (If errors occur, than write them to log and correctyl end of ssh-session)
storwize_logger.info("Error Occurs in SSH Command - {0}".format(stderr.read()))
stderr_content = stderr.read().rstrip('\n')
if len(stderr_content) > 0: # Если случились ошибки, запиши их в лог и выйди из скрипта (If errors occur, than write them to log and correctyl end of ssh-session)
storwize_logger.info("Error Occurs in SSH Command - {0}".format(stderr_content))
storwize_logout(storwize_connection)
sys.exit("1100")
else:
......@@ -245,8 +253,9 @@ def get_status_resources(storwize_user, storwize_password, storwize_ip, storwize
for resource in list_resources:
stdin, stdout, stderr = storwize_connection.exec_command('svcinfo {0} -delim :'.format(resource))
if len(stderr.read()) > 0: # Если случились ошибки, запиши их в лог и выйди из скрипта (If errors occur, then write them to log-file and correctyly end of ssh-session)
storwize_logger.error("Error Occurs in SSH Command - {0}".format(stderr.read()))
stderr_content = stderr.read().rstrip('\n')
if len(stderr_content) > 0: # Если случились ошибки, запиши их в лог и выйди из скрипта (If errors occur, then write them to log-file and correctyly end of ssh-session)
storwize_logger.error("Error Occurs in SSH Command - {0}".format(stderr_content))
storwize_logout(storwize_connection)
sys.exit("1100")
else:
......@@ -347,11 +356,11 @@ def main():
if arguments.discovery:
storwize_logger.info("********************************* Starting Discovering *********************************")
result_discovery = discovering_resources(arguments.storwize_user, arguments.storwize_password, arguments.storwize_ip, arguments.storwize_port, arguments.storage_name, list_resources)
print result_discovery
print(result_discovery)
elif arguments.status:
storwize_logger.info("********************************* Starting Get Status *********************************")
result_status = get_status_resources(arguments.storwize_user, arguments.storwize_password, arguments.storwize_ip, arguments.storwize_port, arguments.storage_name, list_resources)
print result_status
print(result_status)
if __name__ == "__main__":
......