Fix for the network usecases

The below network commands are fixed
1. rmIP functionality not working
2. addVLAN functionality not working
3. network addIP has the -p option as optional.
   But without this input, the functionality does not work.

Tested by:
1.python openbmctool.py -U <user> -P <passwd> -H <host> network rmIP -a <ip> -I eth0
2.python openbmctool.py -U <user> -P <passwd> -H <host> network addVLAN -I eth0 -n <id>
3.Verified -p is now required for addIP command.

Signed-off-by: Sunitha Harish <sunithaharish04@gmail.com>
Change-Id: Ie328d04996b0fef048d73f03ba9e41d9d8779776
diff --git a/thalerj/openbmctool.py b/thalerj/openbmctool.py
index 4af8c1c..6351d35 100755
--- a/thalerj/openbmctool.py
+++ b/thalerj/openbmctool.py
@@ -3336,19 +3336,22 @@
         return "No object found for given address on given Interface"
 
     for obj in objDict['data']:
-        if args.address in objDict['data'][obj]['Address']:
-            url = "https://"+host+obj+"/action/delete"
-            try:
-                res = session.post(url, headers=jsonHeader, json=data,
-                                   verify=False, timeout=baseTimeout)
-            except(requests.exceptions.Timeout):
-                return(connectionErrHandler(args.json, "Timeout", None))
-            except(requests.exceptions.ConnectionError) as err:
-                return connectionErrHandler(args.json, "ConnectionError", err)
-            return res.text
-        else:
-            continue
-    return "No object found for given address on given Interface"
+        try:
+            if args.address in objDict['data'][obj]['Address']:
+                url = "https://"+host+obj+"/action/Delete"
+                try:
+                    res = session.post(url, headers=jsonHeader, json=data,
+                                       verify=False, timeout=baseTimeout)
+                except(requests.exceptions.Timeout):
+                    return(connectionErrHandler(args.json, "Timeout", None))
+                except(requests.exceptions.ConnectionError) as err:
+                    return connectionErrHandler(args.json, "ConnectionError", err)
+                return res.text
+            else:
+                continue
+        except KeyError:
+            return "No object found for address " + args.address + \
+                    " on Interface(" + args.Interface + ")"
 
 
 def addVLAN(host, args, session):
@@ -3364,8 +3367,7 @@
 
     url = "https://" + host+"/xyz/openbmc_project/network/action/VLAN"
 
-    data = {"data": [args.Interface,args.Identifier]}
-
+    data = {"data": [args.Interface,int(args.Identifier)]}
     try:
         res = session.post(url, headers=jsonHeader, json=data, verify=False,
                            timeout=baseTimeout)
@@ -3374,8 +3376,8 @@
     except(requests.exceptions.ConnectionError) as err:
         return connectionErrHandler(args.json, "ConnectionError", err)
     if res.status_code == 400:
-        return "The specified Interface" + "(" + args.Interface + ")" +\
-            " doesn't exist"
+        return "Adding VLAN to interface" + "(" + args.Interface + ")" +\
+            " failed"
 
     return res.text
 
@@ -4384,7 +4386,8 @@
                                   help="The gateway for given interface")
     parser_ip_config.add_argument("-l", "--prefixLength", required=True,
                                   help="The prefixLength of IP address")
-    parser_ip_config.add_argument("-p", "--type", choices=['ipv4', 'ipv6'],
+    parser_ip_config.add_argument("-p", "--type", required=True,
+                                  choices=['ipv4', 'ipv6'],
                                   help="The protocol type of the given"
                                   "IP address")
     parser_ip_config.add_argument("-I", "--Interface", required=True,