01-31-2023 11:02 AM
Hello,
Can someone tell me how to add an IP Subnet to a network-object using RESTCONF? I have no issues with adding an IP, but I get a 400 error when trying to add a subnet.
I am using an HTTP client to make this call. The parameters as as follows:
URL:
https://X.X.X.X/restconf/data/Cisco-IOS-XE-native:native/object-group/Cisco-IOS-XE-object-group:network=blacklist_sources/obj-Mode-config-network-group/host
HTTP Method:
PATCH
Headers: Content-Type - application/yang-data+json
Authorization Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Body:
{"Cisco-IOS-XE-object-group:host":[{"ipv4-host":"1.2.3.0 255.255.255.0"}]}
This is the error message I receive.
{"errors":{"error":[{"error-message":"missing element: ipv4-host in /ios:native/ios:object-group/ios-og:network[ios-og:name='blacklist_sources']/ios-og:obj-Mode-config-network-group/ios-og:host","error-path":"/Cisco-IOS-XE-native:native/object-group/Cisco-IOS-XE-object-group:network=blacklist_sources/obj-Mode-config-network-group/host","error-tag":"malformed-message","error-type":"application"}]}}
Solved! Go to Solution.
01-31-2023 12:44 PM
Try this.
curl -k -v -X PATCH -u dafrey:xxxxxxx -H 'Content-Type: application/yang-data+json' \
https://192.168.0.20/restconf/data/Cisco-IOS-XE-native:native/object-group/Cisco-IOS-XE-object-group:network=blacklist_sources/obj-Mode-config-network-group/network_address \
--data '{"network_address": [{"ipv4_addr": "10.2.1.0", "ipv4_mask": "255.255.255.0" }]}'
01-31-2023 12:44 PM
Try this.
curl -k -v -X PATCH -u dafrey:xxxxxxx -H 'Content-Type: application/yang-data+json' \
https://192.168.0.20/restconf/data/Cisco-IOS-XE-native:native/object-group/Cisco-IOS-XE-object-group:network=blacklist_sources/obj-Mode-config-network-group/network_address \
--data '{"network_address": [{"ipv4_addr": "10.2.1.0", "ipv4_mask": "255.255.255.0" }]}'
01-31-2023 12:58 PM - edited 01-31-2023 12:59 PM
James,
Based on the below YANG model, you may want to try network_address since you're adding a subnet as opposed to ipv4-host. Request below:
curl -X 'PATCH' \
'https://<IP_ADDRESS>:443/restconf/data/Cisco-IOS-XE-native:native/object-group/Cisco-IOS-XE-object-group:network=,/obj-Mode-config-network-group/network_address' \
-H 'accept: application/yang-data+json' \
-H 'Content-Type: application/yang-data+json' \
-d '{
"network_address": [
{
"ipv4_addr": "1.2.3.0",
"ipv4_mask": "255.255.255.0"
}
]
}'
YANG model:
```
(yang-test-venv) atestini@ATESTINI-M-R61B 1791 % pyang -f tree Cisco-IOS-XE-object-group.yang
module: Cisco-IOS-XE-object-group
augment /ios:native/ios:object-group:
+--rw network* [name]
| +--rw name string
| +--rw obj-Mode-config-network-group
| +--rw network_address* [ipv4_addr ipv4_mask]
| | +--rw ipv4_addr inet:ipv4-address
| | +--rw ipv4_mask inet:ipv4-address
| +--rw description? string
| +--rw group-objects* [network-group]
| | +--rw network-group -> /ios:native/object-group/ios-og:network/name
| x--rw group-object? string
| +--rw host* [ipv4-host]
| | +--rw ipv4-host inet:host
| +--rw addr-ranges* [addr-range-start addr-range-end]
| | +--rw addr-range-start inet:ipv4-address
| | +--rw addr-range-end inet:ipv4-address
| x--rw range
| x--rw ip-addr-min? inet:ipv4-address
| x--rw ip-addr-max? inet:ipv4-address
<snip>
```
Hope that helps!
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide