XYZ network: Verify & delete IP address via REST

This change includes:
    1. Threshold prefix length.
    2. Lowest prefix length.
    3. Get list of all IP addresses via REST.
    4. Delete IP address and its object.
    5. Handles network loss after modifying IP.

This resolves openbmc/openbmc-test-automation#850

Change-Id: Ic426fc661466cd429c348280d08bdda8dac472d3
Signed-off-by: Prashanth Katti <prkatti1@in.ibm.com>
diff --git a/lib/bmc_network_utils.robot b/lib/bmc_network_utils.robot
index ffb066e..79cd24f 100644
--- a/lib/bmc_network_utils.robot
+++ b/lib/bmc_network_utils.robot
@@ -115,3 +115,56 @@
     ${output}=  Execute Command on BMC  hostnamectl | grep hostname
 
     [Return]  ${output}
+
+Get List Of IP Address Via REST
+    [Documentation]  Get list of IP address via REST.
+    [Arguments]  @{ip_uri_list}
+
+    # Description of argument(s):
+    # ip_uri_list  List of IP objects.
+    # Example:
+    #   "data": [
+    #     "/xyz/openbmc_project/network/eth0/ipv4/e9767624",
+    #     "/xyz/openbmc_project/network/eth0/ipv4/31f4ce8b"
+    #   ],
+
+    ${ip_list}=  Create List
+
+    : FOR  ${ip_uri}  IN  @{ip_uri_list}
+    \  ${ip_addr}=  Read Attribute  ${ip_uri}  Address
+    \  Append To List  ${ip_list}  ${ip_addr}
+
+    [Return]  @{ip_list}
+
+Delete IP And Object
+    [Documentation]  Delete IP and object.
+    [Arguments]  ${ip_addr}  @{ip_uri_list}
+
+    # Description of argument(s):
+    # ip_addr      IP address to be deleted.
+    # ip_uri_list  List of IP object URIs.
+
+    # Find IP object having this IP address.
+
+    : FOR  ${ip_uri}  IN  @{ip_uri_list}
+    \  ${ip_addr1}=  Read Attribute  ${ip_uri}  Address
+    \  Run Keyword If  '${ip_addr}' == '${ip_addr1}'  Exit For Loop
+
+    # If the given IP address is not configured, return.
+    # Otherwise, delete the IP and object.
+
+    Run Keyword And Return If  '${ip_addr}' != '${ip_addr1}'
+    ...  Pass Execution  IP address to be deleted is not configured.
+
+    Run Keyword And Ignore Error  OpenBMC Delete Request  ${ip_uri}
+
+    # After any modification on network interface, BMC restarts network
+    # module, wait until it is reachable.
+
+    Wait For Host To Ping  ${OPENBMC_HOST}  0.3  1
+
+    # Verify whether deleted IP address is removed from BMC system.
+
+    ${ip_data}=  Get BMC IP Info
+    Should Not Contain Match  ${ip_info}  ${ip_addr}*
+    ...  msg=IP address not deleted.