First off, unless you include set-if-exists true as part of your API call, the API will not allow you to create an object if something with the same IP exists--you'll get an error like:
[Expert@mgmt:0]# mgmt_cli -r true add host name foobar ipv4-address 192.168.1.1
code: "err_validation_failed"
message: "Validation failed with 1 warning"
warnings:
- message: "Multiple objects have the same IP address 192.168.1.1"
The trick is figuring out what object has that IP.
Fortunately, there's an API call for that:
[Expert@mgmt:0]# mgmt_cli -r true show objects filter 192.168.1.1 ip-only true type host
from: 1
to: 1
total: 1
objects:
- uid: "846051cb-a16a-4c4b-acfc-664217fc8ee6"
name: "barfoo"
type: "host"
domain:
uid: "41e821a0-3720-11e3-aa6e-0800200c9fde"
name: "SMC User"
domain-type: "domain"
ipv4-address: "192.168.1.1"
Now, you can reference the object by UID and change the name/comment:
[Expert@mgmt:0]# mgmt_cli -r true set host uid 846051cb-a16a-4c4b-acfc-664217fc8ee6 new-name foobar \
comments "This is my comment"
---------------------------------------------
Time: [13:56:11] 3/6/2019
---------------------------------------------
"Publish operation" succeeded (100%)
How you script the above is up to you, but that's the gist of it.