openbmctool : change password support for OP940

The exisitng setPassword command is extended to support the
redfish interface for the OP940

Tested by:
Changing the password on a redfish supported system and non-redfish system.
python openbmctool.py -U root -P <current passwd> -H $BMC_IP set_password -p <new password>

Signed-off-by: Sunitha Harish <sunithaharish04@gmail.com>
Change-Id: Ic8dba6437607590feb26894b585b4d0d56413149
diff --git a/thalerj/openbmctool.py b/thalerj/openbmctool.py
index 4077ebe..021cef4 100755
--- a/thalerj/openbmctool.py
+++ b/thalerj/openbmctool.py
@@ -3714,10 +3714,17 @@
                 will be provided in json format for programmatic consumption
          @return: Session object
     """
-    url = "https://" + host + "/xyz/openbmc_project/user/" + args.user + \
-        "/action/SetPassword"
     try:
-        res = session.post(url, headers=jsonHeader,
+        if(isRedfishSupport):
+            url = "https://" + host + "/redfish/v1/AccountService/Accounts/"+ \
+                  args.user
+            data = {"Password":args.password}
+            res = session.patch(url, headers=jsonHeader, json=data,
+                                verify=False, timeout=baseTimeout)
+        else:
+            url = "https://" + host + "/xyz/openbmc_project/user/" + args.user + \
+                "/action/SetPassword"
+            res = session.post(url, headers=jsonHeader,
                            json={"data": [args.password]}, verify=False,
                            timeout=baseTimeout)
     except(requests.exceptions.Timeout):
@@ -3726,8 +3733,7 @@
         return connectionErrHandler(args.json, "ConnectionError", err)
     except(requests.exceptions.RequestException) as err:
         return connectionErrHandler(args.json, "RequestException", err)
-    return res.text
-
+    return res.status_code
 
 def getThermalZones(host, args, session):
     """
@@ -4467,6 +4473,7 @@
     """
     global toolVersion
     toolVersion = "1.15"
+    global isRedfishSupport
     parser = createCommandParser()
     args = parser.parse_args(argv)
 
@@ -4504,7 +4511,7 @@
                     print(mysess)
                     sys.exit(1)
             logintimeStop = int(round(time.time()*1000))
-
+            isRedfishSupport = redfishSupportPresent(args.host,mysess)
             commandTimeStart = int(round(time.time()*1000))
             output = args.func(args.host, args, mysess)
             commandTimeStop = int(round(time.time()*1000))