openbmctool: Add option to delete firmware version

Add an option to delete an existing firmware version. This is
useful is the user would want to delete a version prior to
updating or just to remove it completely from their system.

Tested: Verified that the "firmware delete <id>" option
deleted the version from the bmc and was not displayed anymore in the
"firmware list" output.

Change-Id: I649b6e50d6b787b36e522daa14b4fcbd6ae2f4c9
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/thalerj/openbmctool.py b/thalerj/openbmctool.py
index 20b9c2f..4dc7462 100755
--- a/thalerj/openbmctool.py
+++ b/thalerj/openbmctool.py
@@ -2084,6 +2084,32 @@
     return displayFWInvenory(firmwareInfoDict, args)
 
 
+def deleteFWVersion(host, args, session):
+    """
+         deletes a firmware version on the BMC
+
+         @param host: string, the hostname or IP address of the BMC
+         @param args: contains additional arguments used by the fwflash sub command
+         @param session: the active session to use
+         @param fwID: the unique ID of the fw version to delete
+    """
+    fwID = args.versionID
+
+    print("Deleting version: "+fwID)
+    url="https://"+host+"/xyz/openbmc_project/software/"+ fwID + "/action/Delete"
+    httpHeader = {'Content-Type':'application/json'}
+    data = "{\"data\": [] }"
+
+    try:
+        res = session.post(url, headers=httpHeader, data=data, verify=False, timeout=30)
+    except(requests.exceptions.Timeout):
+        return(connectionErrHandler(args.json, "Timeout", None))
+    if res.status_code == 200:
+        return ('The firmware version has been deleted')
+    else:
+        return ('Unable to delete the specified firmware version')
+
+
 def restLogging(host, args, session):
     """
          Called by the logging function. Turns REST API logging on/off.
@@ -3379,6 +3405,10 @@
     fwprint.add_argument('-v', '--verbose', action='store_true', help='Verbose output')
     fwprint.set_defaults(func=firmwareList)
 
+    fwDelete = fwflash_subproc.add_parser('delete', help="Delete an existing firmware version")
+    fwDelete.add_argument('versionID', help="The version ID to delete from the firmware list. Ex: 63c95399")
+    fwDelete.set_defaults(func=deleteFWVersion)
+
     #logging
     parser_logging = subparsers.add_parser("logging", help="logging controls")
     logging_sub = parser_logging.add_subparsers(title='subcommands', description='valid subcommands',help="sub-command help", dest='command')
@@ -3729,7 +3759,7 @@
          main function for running the command line utility as a sub application
     """
     global toolVersion
-    toolVersion = "1.10"
+    toolVersion = "1.11"
     parser = createCommandParser()
     args = parser.parse_args(argv)