On this page
dellemc.enterprise_sonic.sonic_api – Manages REST operations on devices running Enterprise SONiC
Note
This plugin is part of the dellemc.enterprise_sonic collection (version 1.1.0).
You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install dellemc.enterprise_sonic.
To use it in a playbook, specify: dellemc.enterprise_sonic.sonic_api.
New in version 1.0.0: of dellemc.enterprise_sonic
Synopsis
- Manages REST operations on devices running Enterprise SONiC Distribution by Dell Technologies. This module provides an implementation for working with SONiC REST operations in a deterministic way.
 
Note
This module has a corresponding action plugin.
Parameters
| Parameter | Choices/Defaults | Comments | 
|---|---|---|
| body
        
        raw
         | 
      
        
        The body of the HTTP request/response to the web service which contains the payload.
         | 
     |
| method
        
        string / required
         | 
      
       
  | 
      
        
        The HTTP method of the request or response. Must be a valid method accepted by the service that handles the request.
         | 
     
| status_code
        
        list / elements=integer / required
         | 
      
        
        A list of valid, numeric, HTTP status codes that signifies the success of a request.
         | 
     |
| url
        
        path / required
         | 
      
        
        The HTTP path of the request after 'restconf/'.
         | 
     
Notes
Note
- Tested against Enterprise SONiC Distribution by Dell Technologies.
 - Supports 
check_mode. 
Examples
- name: Checks that you can connect (GET) to a page and it returns a status 200
  dellemc.enterprise_sonic.sonic_api:
    url: data/openconfig-interfaces:interfaces/interface=Ethernet60
    method: "GET"
    status_code: 200
- name: Appends data to an existing interface using PATCH and verifies if it returns status 204
  dellemc.enterprise_sonic.sonic_api:
    url: data/openconfig-interfaces:interfaces/interface=Ethernet60/config/description
    method: "PATCH"
    body: {"openconfig-interfaces:description": "Eth-60"}
    status_code: 204
- name: Deletes an associated IP address using DELETE and verifies if it returns status 204
  dellemc.enterprise_sonic.sonic_api:
    url: >
      data/openconfig-interfaces:interfaces/interface=Ethernet64/subinterfaces/subinterface=0/
      openconfig-if-ip:ipv4/addresses/address=1.1.1.1/config/prefix-length
    method: "DELETE"
    status_code: 204
- name: Adds a VLAN network instance using PUT and verifies if it returns status 204
  dellemc.enterprise_sonic.sonic_api:
    url: data/openconfig-network-instance:network-instances/network-instance=Vlan100/
    method: "PUT"
    body: {"openconfig-network-instance:network-instance": [{"name": "Vlan100","config": {"name": "Vlan100"}}]}
    status_code: 204
- name: Adds a prefix-set to a routing policy using POST and verifies if it returns 201
  dellemc.enterprise_sonic.sonic_api:
        url: data/openconfig-routing-policy:routing-policy/defined-sets/prefix-sets/prefix-set=p1
        method: "POST"
        body: {"openconfig-routing-policy:config": {"name": "p1","mode": "IPV4" }}
        status_code: 201
  Return Values
Common return values are documented here, the following are the fields unique to this module:
| Key | Returned | Description | 
|---|---|---|
| msg
        
        string
         | 
      HTTP Error | 
        
        The HTTP error message from the request.
          | 
     
| response
        
        list / elements=string
         | 
      always | 
        
        The response at the network device end for the REST call which contains the status code.
         Sample:
        
       
        {'response': [204, {'': None}]}
         | 
     
Authors
- Abirami N (@abirami-n)
 
© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
 https://docs.ansible.com/ansible/latest/collections/dellemc/enterprise_sonic/sonic_api_module.html