�
�Udac @` s, d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d
Z d d l
m Z d d l m
Z
d d
l m Z y. d d l Z d d l Z d d l Z e Z Wn e k
r� e Z n Xd � Z d � Z d d d d � Z d � Z d � Z d � Z d � Z e d k r(e � n d S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_bys)
---
module: opx_cps
version_added: "2.7"
author: "Senthil Kumar Ganesan (@skg-net)"
short_description: CPS operations on networking device running Openswitch (OPX)
description:
- Executes the given operation on the YANG object, using CPS API in the
networking device running OpenSwitch (OPX). It uses the YANG models
provided in https://github.com/open-switch/opx-base-model.
options:
module_name:
description:
- Yang path to be configured.
attr_type:
description:
- Attribute Yang type.
attr_data:
description:
- Attribute Yang path and their corresponding data.
operation:
description:
- Operation to be performed on the object.
default: create
choices: ['delete', 'create', 'set', 'action', 'get']
db:
description:
- Queries/Writes the specified yang path from/to the db.
type: bool
default: 'no'
qualifier:
description:
- A qualifier provides the type of object data to retrieve or act on.
default: target
choices: ['target', 'observed', 'proposed', 'realtime', 'registration', 'running', 'startup']
commit_event:
description:
- Attempts to force the auto-commit event to the specified yang object.
type: bool
default: 'no'
requirements:
- "cps"
- "cps_object"
- "cps_utils"
s�
- name: Create VLAN
opx_cps:
module_name: "dell-base-if-cmn/if/interfaces/interface"
attr_data: {
"base-if-vlan/if/interfaces/interface/id": 230,
"if/interfaces/interface/name": "br230",
"if/interfaces/interface/type": "ianaift:l2vlan"
}
operation: "create"
- name: Get VLAN
opx_cps:
module_name: "dell-base-if-cmn/if/interfaces/interface"
attr_data: {
"if/interfaces/interface/name": "br230",
}
operation: "get"
- name: Modify some attributes in VLAN
opx_cps:
module_name: "dell-base-if-cmn/if/interfaces/interface"
attr_data: {
"cps/key_data":
{ "if/interfaces/interface/name": "br230" },
"dell-if/if/interfaces/interface/untagged-ports": ["e101-008-0"],
}
operation: "set"
- name: Delete VLAN
opx_cps:
module_name: "dell-base-if-cmn/if/interfaces/interface"
attr_data: {
"if/interfaces/interface/name": "br230",
}
operation: "delete"
s�
response:
description: Output from the CPS transaction.
Output of CPS Get operation if CPS set/create/delete not done.
returned: when a CPS transaction is successfully performed.
type: list
sample:
[{
"data": {
"base-if-vlan/if/interfaces/interface/id": 230,
"cps/object-group/return-code": 0,
"dell-base-if-cmn/if/interfaces/interface/if-index": 46,
"if/interfaces/interface/name": "br230",
"if/interfaces/interface/type": "ianaift:l2vlan"
},
"key": "target/dell-base-if-cmn/if/interfaces/interface"
}]
cps_curr_config:
description: Returns the CPS Get output i.e. the running configuration
before CPS operation of set/delete is performed
returned: when CPS operations set, delete
type: dict
sample:
[{
"data": {
"base-if-vlan/if/interfaces/interface/id": 230,
"cps/key_data": {
"if/interfaces/interface/name": "br230"
},
"dell-base-if-cmn/if/interfaces/interface/if-index": 44,
"dell-if/if/interfaces/interface/learning-mode": 1,
"dell-if/if/interfaces/interface/mtu": 1532,
"dell-if/if/interfaces/interface/phys-address": "",
"dell-if/if/interfaces/interface/vlan-type": 1,
"if/interfaces/interface/enabled": 0,
"if/interfaces/interface/type": "ianaift:l2vlan"
},
"key": "target/dell-base-if-cmn/if/interfaces/interface"
}]
diff:
description: The actual configuration that will be pushed comparing
the running configuration and input attributes
returned: when CPS operations set, delete
type: dict
sample:
{
"cps/key_data": {
"if/interfaces/interface/name": "br230"
},
"dell-if/if/interfaces/interface/untagged-ports": [
"e101-007-0"
]
}
db:
description: Denotes if CPS DB transaction was performed
returned: when db is set to True in module options
type: bool
sample: True
commit_event:
description: Denotes if auto-commit event is set
returned: when commit_event is set to True in module options
type: bool
sample: True
( t
AnsibleModule( t iteritems( t dict_diffNc C` s� g } | r� xt | D]i } t | � } | r | d } i } | | d <t j | � d t j | d � | d <| j | � q q Wn | S( Nt keyt datat /i ( t convert_cps_raw_datat cpst
qual_from_keyt
name_from_keyt append( t raw_listt resp_listt raw_elemt processed_elementt raw_keyt individual_element( ( sG /usr/lib/python2.7/site-packages/ansible/modules/network/opx/opx_cps.pyt convert_cps_raw_list� s
c C` sD i } t j d | � } x% | d D] } | j | � | | <q# W| S( Nt objR ( t
cps_objectt CPSObjectt
get_attr_data( R t dR t attr( ( sG /usr/lib/python2.7/site-packages/ansible/modules/network/opx/opx_cps.pyR � s
c
C` s� t j d | d | � } | r1 | j d | � n | rj x0 t | � D] \ } } t j j | | � qD Wn x� t | � D]� \ } } | j d � }
t |
� } | d k r� | j |
| | d � qw t
| t � r)| j d � } t | � d k s| j d � r| j
| | � q9| j
| | � qw | j
| | � qw W| rlt j | j � d � | j d t � n | j d t � | r�t j | j � t � | j d
t � n | S( Nt modulet qualt opert ,i i i t {t dbs commit-event( R R t set_propertyR t cps_utilst cps_attr_types_mapt add_typet splitt lent add_embed_attrt
isinstancet strt
startswitht add_attrR t set_ownership_typet get_keyt Truet Falset set_auto_commit_event(
t module_namet qualifiert attr_typet attr_datat operationR% t commit_eventR R t valt embed_attrst embed_attrs_lent val_list( ( sG /usr/lib/python2.7/site-packages/ansible/modules/network/opx/opx_cps.pyt parse_cps_parameters� s2 !c C` sH t � } | j � } g } t j | g | � t | � } | | d <| S( Nt response( t dictt getR R ( R t RESULTR t lR ( ( sG /usr/lib/python2.7/site-packages/ansible/modules/network/opx/opx_cps.pyt cps_get� s
c C` s� t � } i | j d � d 6| j � d 6} t j | g � rb t | d g � | d <t | d <n d | j d � } t | � � | S( NR"