Skip to content

Commit

Permalink
Merge pull request #1 from aakittel/aakittel
Browse files Browse the repository at this point in the history
	modified:   __main__.py
  • Loading branch information
aakittel committed Feb 3, 2023
2 parents 80fc03c + 164c01e commit 28fcebf
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 22 deletions.
12 changes: 11 additions & 1 deletion __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from mnode import AssetMgmt, Settings, about
from package import upload_element_image, list_packages
from program_data import ProgramData
from system import SysInfo
from storage import Clusters
from storage_healthcheck import StorageHealthcheck
from storage_bundle import StorageBundle
from support_bundle import SupportBundle
Expand Down Expand Up @@ -69,6 +69,7 @@ def get_args():
computehealthcheck: Run a compute healthcheck
elementupgrade: Element upgrade options
listassets: One liner list of all assets
listpackages: One liner list of all packages
storagebundle: Gather storage support bundle
elementupload: Upload Element upgrade image '''))

Expand Down Expand Up @@ -333,6 +334,7 @@ def check_mnode_ip(ip):
ElemUpgrade.find_upgrade(repo)
ElemUpgrade.upgrade_action(repo)
if repo.UPGRADE_OPTION == 's':
Clusters.get_upgrade_log(repo)
ElemUpgrade.discovery(repo)
ElemUpgrade.select_version(repo)
ElemUpgrade.start_upgrade(repo)
Expand Down Expand Up @@ -366,3 +368,11 @@ def check_mnode_ip(ip):
logmsg.info('\nAvailable packages;')
for package in new_packages:
logmsg.info('name: {:<20} version: {:<20} id:{}'.format(package['name'],package['version'],package['id']))

#============================================================
# One liner list of packages
elif args.action == 'listpackages':
logmsg.info("\nNetApp HCI release notes: https://docs.netapp.com/us-en/hci/docs/rn_relatedrn.html")
current_packages = list_packages(repo)
for package in current_packages:
logmsg.info("\n{:<20}{}\n\t{}\n\t{}\n\t{}".format(package["name"],package["version"],package['CIFSUrl'],package['HTTPSUrl'],package['NFSUrl']))
47 changes: 36 additions & 11 deletions element_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from get_token import get_token
from log_setup import Logging
from mnode import AssetMgmt

from package import list_packages
from storage import Clusters
# =====================================================================
#
# NetApp / SolidFire
Expand All @@ -18,6 +19,7 @@
logmsg = Logging.logmsg()

class ElemUpgrade():

#============================================================
# Choose upgrade option
#============================================================
Expand All @@ -44,19 +46,20 @@ def discovery(repo):
targetcluster = ""
logmsg.info("\nList of available clusters.")
for cluster in repo.CURRENT_ASSET_JSON[0]["storage"]:
cluster_data = Clusters.get_cluster_by_id(cluster["id"], repo)
if(cluster["host_name"]):
clusterlist[(cluster["host_name"])] = cluster["id"]
logmsg.info("+ {}".format(cluster["host_name"]))
logmsg.info("+ {:<15}{:<15}".format(cluster["host_name"], cluster_data['cluster']['GetClusterVersionInfo']['clusterVersion']))
targetcluster = cluster["host_name"]
repo.STORAGE_ELEMENT_UPGRADE_TARGET = clusterlist[(cluster["host_name"])]
else:
clusterlist[(cluster["ip"])] = cluster["id"]
logmsg.info("+ {}".format(cluster["ip"]))
logmsg.info("+ {:<15}{:<15}".format(cluster["ip"], cluster_data['cluster']['GetClusterVersionInfo']['clusterVersion']))
targetcluster = str(cluster["ip"])
repo.STORAGE_ELEMENT_UPGRADE_TARGET = clusterlist[(cluster["ip"])]
if len(clusterlist) > 1:
while userinput not in clusterlist:
userinput = input("Enter the target cluster from the list: ")
userinput = input("\nEnter the target cluster from the list: ")
targetcluster = userinput
repo.STORAGE_ELEMENT_UPGRADE_TARGET = clusterlist[userinput]
logmsg.info("Upgrade target cluster = {}".format(targetcluster))
Expand All @@ -65,10 +68,16 @@ def discovery(repo):
# Select Element version
#============================================================
def select_version(repo):
logmsg.info("\nAvailable upgrade packages")
availablepackages = list_packages(repo)
if availablepackages[0]['name']:
for package in availablepackages:
logmsg.info("+ {:<15}{:<15}".format(package['name'],package['version']))

userinput = "none"
targetpkg = ""
pkglist = {}
logmsg.info("\nElement upgrade version selection")
logmsg.info("\nLooking for a valid upgrade image...")
get_token(repo)
url = ("{}/storage/1/clusters/{}/valid-packages".format(repo.URL,repo.STORAGE_ELEMENT_UPGRADE_TARGET))
try:
Expand All @@ -79,7 +88,7 @@ def select_version(repo):
if response.text.find("solidfire"):
packages = json.loads(response.text)
if not packages:
logmsg.info("No packages found. Check internet connectivity or upload an image with the -a elementupload option")
logmsg.info("\nNo valid upgrade packages found.\n\tThe selected cluster is at or above available upgrade packages.\n\tUpload a package with the -a elementupload option")
exit(0)
for package in packages:
pkglist[(package["filename"])] = package["packageId"]
Expand Down Expand Up @@ -134,6 +143,14 @@ def start_upgrade(repo):
logmsg.info("Upgrade ID: {}".format(repo.UPGRADE_ID))
logmsg.info("Upgrade task ID: {}".format(repo.UPGRADE_TASK_ID))
logmsg.info("Waiting 10 seconds to pass initializing state")
repo.STORAGE_UPGRADE_LOG = ("/var/log/ElementUpgrade-{}.log".format(repo.STORAGE_ELEMENT_UPGRADE_TARGET))
logmsg.info("Writing upgrade details to {}".format(repo.STORAGE_UPGRADE_LOG))
try:
with open(repo.STORAGE_UPGRADE_LOG, 'a') as outfile:
outfile.write(response.text)
outfile.close()
except FileNotFoundError:
logmsg.info("Could not open {}".format(repo.STORAGE_UPGRADE_LOG))
sleep(10)
else:
logmsg.info("Failed return {} See /var/log/mnode-support-util.log for details".format(response.status_code))
Expand Down Expand Up @@ -199,9 +216,7 @@ def check_upgrade(repo):
while percent_complete != 100:
try:
get_token(repo)
#logmsg.debug("Sending {}".format(url))
response = requests.get(url, headers=repo.HEADER_READ, data = payload, verify=False)
#logmsg.debug(response.text)
if response.status_code == 200:
response_json = json.loads(response.text)
if not response_json["status"]["message"] and not response_json['state']:
Expand All @@ -213,11 +228,21 @@ def check_upgrade(repo):
logmsg.info(response_json['status']['message'])
exit(1)
if repo.UPGRADE_STATUS_MESSAGE not in response_json["status"]["message"]:
try:
with open(repo.STORAGE_UPGRADE_LOG, 'a') as outfile:
outfile.write(response.text)
outfile.close()
except FileNotFoundError:
logmsg.info("Could not open {}".format(repo.STORAGE_UPGRADE_LOG))
repo.UPGRADE_STATUS_MESSAGE = response_json["status"]["message"]
logmsg.info("\nUpgrade status: {}".format(response_json["status"]["message"]))
if response_json["state"]: logmsg.info("Upgrade state: {}".format(response_json["state"]))
if response_json["status"]["percent"]: logmsg.info("Upgrade Percentage: {}".format(str(response_json["status"]["percent"])))
if response_json["status"]["step"]: logmsg.info("Upgrade step: {}".format(response_json["status"]["step"]))
if response_json["state"]:
logmsg.info("Upgrade state: {}".format(response_json["state"]))
if response_json["status"]["percent"]:
logmsg.info("Upgrade Percentage: {}".format(str(response_json["status"]["percent"])))
percent_complete = response_json["status"]["percent"]
if response_json["status"]["step"]:
logmsg.info("Upgrade step: {}".format(response_json["status"]["step"]))
if response_json["status"]["availableActions"]:
for action in response_json["status"]["availableActions"]:
logmsg.info("Available action: {}".format(action))
Expand Down
3 changes: 1 addition & 2 deletions get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ def get_token(repo):
logmsg.info("DID NOT RECEIVE VALID TOKEN. An exception occured. See /var/log/mnode-support-util.log for details")
logmsg.debug(exception)
logmsg.debug(response.text)
exit(1)

exit(1)
Binary file modified mnode-support-util
Binary file not shown.
6 changes: 2 additions & 4 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ def list_packages(repo):
logmsg.debug(response.text)
if response.status_code == 200:
packages = (json.loads(response.text))
return packages
else:
logmsg.debug(response.text)
logmsg.info("Failed return {} See /var/log/mnode-support-util.log for details".format(response.status_code))
logmsg.debug(response.text)
exit(1)
packages = "Failed to retrieve package list. See /var/log/mnode-support-util.log for details"
except requests.exceptions.RequestException as exception:
logmsg.info("An exception occured. See /var/log/mnode-support-util.log for details")
logmsg.debug(exception)
logmsg.debug(response.text)
return packages

def delete_package(repo):
get_token(repo)
Expand Down
3 changes: 2 additions & 1 deletion program_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ProgramData():
# Define the used variables
def __init__(self, args):
self.UTIL_VERSION = "2.4"
self.UTIL_VERSION = "2.5"
self.PAYLOAD = {}
self.UPDATEFILE = args.updatefile
# token
Expand Down Expand Up @@ -81,5 +81,6 @@ def __init__(self, args):
# Element upgrades
self.STORAGE_ELEMENT_UPGRADE_TARGET = "none"
self.STORAGE_ELEMENT_UPGRADE_PACKAGE = "none"
self.STORAGE_UPGRADE_LOG = "none"
self.UPGRADE_TASK_ID = "none"

60 changes: 60 additions & 0 deletions storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,66 @@
# =====================================================================

class Clusters():
# =====================================================================
# Get storage info for a single asset
# =====================================================================
def get_cluster_by_id(cluster_id, repo):
try:
get_token(repo)
url = ("{}/storage/1/{}/info".format(repo.URL,cluster_id))
logmsg.debug("Sending GET {}".format(url))
response = requests.get(url, headers=repo.HEADER_READ, data={}, verify=False)
logmsg.debug(response.text)
if response.status_code == 200:
cluster_info = json.loads(response.text)
else:
cluster_info = "Unable to fetch cluster data"
except requests.exceptions.RequestException as exception:
logmsg.info("An exception occured. See /var/log/mnode-support-util.log for details")
logmsg.debug(exception)
return cluster_info

# =====================================================================
# Get the last upgrade log
# =====================================================================
def get_upgrade_log(repo):
logmsg.info("\nChecking for previous upgrade log")
try:
get_token(repo)
url = ("{}/storage/1/upgrades?includeCompleted=true".format(repo.URL))
logmsg.debug("Sending GET {}".format(url))
response = requests.get(url, headers=repo.HEADER_READ, data={}, verify=False)
logmsg.debug(response.text)
if response.status_code == 200:
upgrade = json.loads(response.text)
repo.UPGRADE_ID = upgrade[0]['upgradeId']
repo.STORAGE_ELEMENT_UPGRADE_TARGET = upgrade[0]['storageId']
repo.STORAGE_UPGRADE_LOG = ("/var/log/ElementUpgrade-{}.log".format(repo.STORAGE_ELEMENT_UPGRADE_TARGET))
try:
url = ("{}/storage/1/upgrades/{}/log".format(repo.URL,repo.UPGRADE_ID))
logmsg.debug("Sending GET {}".format(url))
response = requests.get(url, headers=repo.HEADER_READ, data={}, verify=False)
logmsg.debug(response.text)
if response.status_code == 200:
try:
with open(repo.STORAGE_UPGRADE_LOG, 'w') as outfile:
outfile.write(response.text)
logmsg.info("Previous upgrade log saved to {}".format(repo.STORAGE_UPGRADE_LOG))
outfile.close()
except FileNotFoundError:
logmsg.info("Could not open {}".format(outfile))
except requests.exceptions.RequestException as exception:
logmsg.info("An exception occured. See /var/log/mnode-support-util.log for details")
logmsg.debug(exception)
else:
logmsg.info("No previous upgrade found")
except requests.exceptions.RequestException as exception:
logmsg.info("An exception occured. See /var/log/mnode-support-util.log for details")
logmsg.debug(exception)

# =====================================================================
# Get storage info for support bundle
# =====================================================================
def get_storage_info(repo):
get_token(repo)
filename = ("{}support-storage-info.json".format(repo.SUPPORT_DIR))
Expand Down
3 changes: 2 additions & 1 deletion support_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, args, repo):
filename = ("{}support-auth-configuration".format(repo.SUPPORT_DIR))
try:
with open(filename, 'w') as outfile:
logmsg.info("Get auth configuration...")
logmsg.info("Get auth configuration")
Clusters.check_auth_config(repo)
outfile.write("Auth client configuration")
outfile.write(json.dumps(repo.AUTH_CONFIG))
Expand Down Expand Up @@ -150,6 +150,7 @@ def __init__(self, args, repo):
outfile.close()
except FileNotFoundError:
logmsg.info("Could not open {}".format(filename))
Clusters.get_upgrade_log(repo)

logmsg.info("Get storage cluster(s) details (This may take a while)...")
Clusters.get_storage_info(repo)
Expand Down
4 changes: 2 additions & 2 deletions system.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ def local_files(repo):
def create_tar():
#============================================================
# NOT needed when intigrated with HCC or :442 log collection
logmsg.info("Creating support tar bundle")
logmsg.info("Creating support tar bundle. Please wait....")
date_time = datetime.now()
time_stamp = date_time.strftime("%d-%b-%Y-%H.%M.%S")
tar_file = ("/tmp/mnode-support-bundle-%s.tar" % time_stamp)
try:
bundle = tarfile.open(tar_file, "w:gz")
for root, dirs, files in os.walk("/var/log"):
for file in files:
logmsg.info("Adding {} to bundle.".format(file))
#logmsg.info("Adding {} to bundle.".format(file)) <<<----- TOO CHATTY
bundle.add(os.path.join(root, file))
logmsg.info("\nDone. Bundle name: {}".format(tar_file))
bundle.close()
Expand Down

0 comments on commit 28fcebf

Please sign in to comment.