def main(): module = AnsibleModule( argument_spec=dict(alias_ip=dict(type='str', required=False), alias_ip_subnet=dict(type='str', required=False), ip_addr=dict(type='str', required=True), subnet_mask=dict(type='str', required=False), gateway=dict(type='str', required=False), hostname=dict(type='str', required=False), port=dict(type='str', required=False), dhcp_enable=dict(type='str', required=False), ctl_vlan_id=dict(type='str', required=False), ctl_vlan_pcp=dict(type='str', required=False), ctl_vlan_enable=dict(type='str', required=False)), supports_check_mode=True, ) try: url = f"http://{IPv4Address(module.params['ip_addr'])}/emsfp/node/v1/self/ipconfig/" except (AddressValueError, NetmaskValueError) as e: module.fail_json(changed=False, msg=e) payload_params = { 'hostname': module.params['hostname'], 'ctl_vlan_enable': module.params['ctl_vlan_enable'], 'ctl_vlan_id': module.params['ctl_vlan_id'], 'ctl_vlan_pcp': module.params['ctl_vlan_pcp'], 'dhcp_enable': module.params['dhcp_enable'], 'port': module.params['port'], } em = EMSFP(url, payload_params) configure_em_device(module, em)
def main(): arguments = dict(sdi_audio_configs_payload=dict(type='dict', required=True)) module = AnsibleModule( argument_spec=dict( ip_addr=dict(type='str', required=True), reference_clock_id=dict(type='str', required=True), domain_num=dict(type='str'), vlan_id=dict(type='str'), dscp=dict(type='str') ), supports_check_mode=True, ) payload_params = { "domain_num": module.params['domain_num'], "vlan_id": module.params['vlan_id'], "dscp": module.params['dscp'] } if not fullmatch(REF_CLOCK_ID, module.params['reference_clock_id']): error_msg = f"reference_clock_id \'{module.params['reference_clock_id']}\' est invalide selon le regex: {REF_CLOCK_ID}" module.fail_json(changed=False, msg=error_msg) url = f"http://{IPv4Address(module.params['ip_addr'])}/emsfp/node/v1/refclk/{module.params['reference_clock_id']}/" em = EMSFP(url, payload_params, PAYLOAD_TEMPLATE) module_inital_config = em.target_config configure_em_device(module, em)
def main(): module = AnsibleModule(argument_spec=dict(ip_addr=dict(type='str', required=True), port_id=dict(type='str', required=True), host_pinout=dict(type='str', required=True)), supports_check_mode=True) try: em_type = get_module_type(f"{IPv4Address(module.params['ip_addr'])}") except (AddressValueError, NetmaskValueError) as e: module.fail_json(changed=False, msg=e) payload_params = {'host_pinout': module.params['host_pinout']} if (em_type == 'Embox6' and int(module.params['port_id']) <= 6) or ( em_type == 'Embox3' and int(module.params['port_id']) <= 3): url = f"http://{module.params['ip_addr']}/emsfp/node/v1/port/{module.params['port_id']}" em = EMSFP(url, payload_params) configure_em_device(module, em, wait_for_device_reboot=25) else: module.fail_json( changed=False, msg=f"Port {module.params['port_id']} doesn't exists on {em_type}." )
def main(): # arguments = dict(sdi_audio_configs_payload=dict(type='dict', required=True)) module = AnsibleModule( argument_spec=dict( ip_addr=dict(type='str', required=True), sdi_channel_id=dict(type='str', required=True), ch0=dict(type='str'), ch1=dict(type='str'), ch2=dict(type='str'), ch3=dict(type='str'), ch4=dict(type='str'), ch5=dict(type='str'), ch6=dict(type='str'), ch7=dict(type='str'), ch8=dict(type='str'), ch9=dict(type='str'), ch10=dict(type='str'), ch11=dict(type='str'), ch12=dict(type='str'), ch13=dict(type='str'), ch14=dict(type='str'), ch15=dict(type='str') ), supports_check_mode=True ) if not fullmatch(SDI_CHANNEL_ID_REGEX, module.params['sdi_channel_id']): error_msg = f"sdi_channel_id \'{module.params['sdi_channel_id']}\' est invalide selon le regex: {SDI_CHANNEL_ID_REGEX}" module.fail_json(changed=False, msg=error_msg) try: url = f"http://{IPv4Address(module.params['ip_addr'])}/emsfp/node/v1/sdi_output/{module.params['sdi_channel_id']}/" except (AddressValueError, NetmaskValueError) as e: module.fail_json(changed=False, msg=e) payload_params = { 'sdi_aud_chans_cfg': { 'ch0': module.params['ch0'], 'ch1': module.params['ch1'], 'ch2': module.params['ch2'], 'ch3': module.params['ch3'], 'ch4': module.params['ch4'], 'ch5': module.params['ch5'], 'ch6': module.params['ch6'], 'ch7': module.params['ch7'], 'ch8': module.params['ch8'], 'ch9': module.params['ch9'], 'ch10': module.params['ch10'], 'ch11': module.params['ch11'], 'ch12': module.params['ch12'], 'ch13': module.params['ch13'], 'ch14': module.params['ch14'], 'ch15': module.params['ch15'] } } em = EMSFP(url, payload_params, PAYLOAD_TEMPLATE) module_inital_config = em.target_config configure_em_device(module, em)
def main(): module = AnsibleModule(argument_spec=dict( ip_addr=dict(type='str', required=True), e1_ip=dict(type='str', required=False), e1_subnet_mask=dict(type='str', required=False), e1_gateway=dict(type='str', required=False), e1_vlan=dict(type='int', required=False, default=0), e2_ip=dict(type='str', required=False), e2_subnet_mask=dict(type='str', required=False), e2_gateway=dict(type='str', required=False), e2_vlan=dict(type='int', required=False, default=0), ), supports_check_mode=True) try: url = f"http://{IPv4Address(module.params['ip_addr'])}/emsfp/node/v1/self/interfaces/" except (AddressValueError, NetmaskValueError) as e: module.fail_json(changed=False, msg=e) payload_params = { 'ip_addr': module.params['ip_addr'], 'e1': { 'static_ip': str( ip_interface( f"{module.params['e1_ip']}/{module.params['e1_subnet_mask']}" )), 'static_gateway': str(IPv4Address(module.params['e1_gateway'])), 'vlan': int(module.params['e1_vlan']) }, 'e2': { 'static_ip': str( ip_interface( f"{module.params['e2_ip']}/{module.params['e2_subnet_mask']}" )), 'static_gateway': str(IPv4Address(module.params['e2_gateway'])), 'vlan': int(module.params['e2_vlan']) } } em = EMSFP(url, payload_params, PAYLOAD_TEMPLATE) configure_em_device(module, em, wait_for_device_reboot=25)
def main(): module = AnsibleModule(argument_spec=dict(ip_addr=dict(type='str', required=True), operating_bit_rate=dict( type='str', required=False)), supports_check_mode=True) # module.exit_json(changed=False, msg=f"Payload: \n{module.params}") payload_params = { "configuration": { "operating_bit_rate": module.params['operating_bit_rate'] } } url = f"http://{IPv4Address(module.params['ip_addr'])}/emsfp/node/v1/sdi/" em = EMSFP(url, payload_params, PAYLOAD_TEMPLATE) module_inital_config = em.target_config configure_em_device(module, em)
def main(): arguments = dict(sdi_audio_configs_payload=dict(type='dict', required=True)) module = AnsibleModule( argument_spec=dict( ip_addr=dict(type='str', required=True), mode=dict(type='str', choice=["0", "1", "2"], required=True), manual_ctrl=dict(type='str', required=False) ), supports_check_mode=True, ) payload_params = { "mode": module.params['mode'], "manual_ctrl": module.params['manual_ctrl'] } url = f"http://{IPv4Address(module.params['ip_addr'])}/emsfp/node/v1/refclk/" em = EMSFP(url, module.params, PAYLOAD_TEMPLATE) module_inital_config = em.target_config configure_em_device(module, em)
def main(): module = AnsibleModule( argument_spec=dict( ip_addr=dict(type='str', required=True), reboot=dict(type='bool'), config_reset=dict(type='str', choices=["0", "flows", "application", "system"]) ), supports_check_mode=True, ) try: url = f"http://{IPv4Address(module.params['ip_addr'])}/emsfp/node/v1/self/system/" except (AddressValueError, NetmaskValueError) as e: module.fail_json(changed=False, msg=e) payload_params = { 'reboot': module.params['reboot'], 'config_reset': module.params['config_reset'] } em = EMSFP(url, module.params, PAYLOAD_TEMPLATE) configure_em_device(module, em, validate_changes=False)
def main(): module = AnsibleModule( argument_spec=dict( alias_ip=dict(type='str', required=False), alias_ip_subnet=dict(type='str', required=False), ip_addr=dict(type='str', required=True), subnet_mask=dict(type='str', required=False), gateway=dict(type='str', required=False), hostname=dict(type='str', required=False), port=dict(type='int', required=False), dhcp_enable=dict(type='bool', required=False), ctl_vlan_id=dict(type='int', required=False), ctl_vlan_pcp=dict(type='int', required=False), ctl_vlan_enable=dict(type='bool', required=False) ), supports_check_mode=True, ) url = f"http://{IPv4Address(mmodule.params['ip_addr'])}/emsfp/node/v1/self/ipconfig/" em = em.EMSFP(url, module.params, PAYLOAD_TEMPLATE) module_inital_config = em.get_module_config configure_em_device(module, em)
def main(): flow_log.info( "------------------- Appel du module flow -------------------") module = AnsibleModule( argument_spec=dict(Target=dict(type=str, required=False), ip_addr=dict(type=str, required=True), FlowType=dict(type=str, required=True), format_type=dict(type=str, required=False), sfp_type=dict(type=str, required=False), Flow=dict(type=str, required=True), label=dict(type=str, required=False), name=dict(type=str, required=False), src_ip_addr=dict(type=str, required=False), src_udp_port=dict(type=str, required=False), dst_ip_addr=dict(type=str, required=False), dst_udp_port=dict(type=str, required=False), vlan_tag=dict(type=str, required=False), pkt_filter_src_ip=dict(type=str, required=False), pkt_filter_src_udp=dict(type=str, required=False), pkt_filter_src_mac=dict(type=str, required=False), pkt_filter_dst_ip=dict(type=str, required=False), pkt_filter_dst_udp=dict(type=str, required=False), pkt_filter_dst_mac=dict(type=str, required=False), pkt_filter_vlan=dict(type=str, required=False), pkt_filter_ssrc=dict(type=str, required=False), rtp_pt=dict(type=str, required=False), dscp=dict(type=str, required=False), igmp_src_ip=dict(type=str, required=False), enable=dict(type=str, required=False), aud_chan_map=dict(type=str, required=False), audio_mapping_ch0=dict(type=str, required=False, default="none"), audio_mapping_ch1=dict(type=str, required=False, default="none"), audio_mapping_ch2=dict(type=str, required=False, default="none"), audio_mapping_ch3=dict(type=str, required=False, default="none"), audio_mapping_ch4=dict(type=str, required=False, default="none"), audio_mapping_ch5=dict(type=str, required=False, default="none"), audio_mapping_ch6=dict(type=str, required=False, default="none"), audio_mapping_ch7=dict(type=str, required=False, default="none"), audio_mapping_ch8=dict(type=str, required=False, default="none"), audio_mapping_ch9=dict(type=str, required=False, default="none"), audio_mapping_ch10=dict(type=str, required=False, default="none"), audio_mapping_ch11=dict(type=str, required=False, default="none"), audio_mapping_ch12=dict(type=str, required=False, default="none"), audio_mapping_ch13=dict(type=str, required=False, default="none"), audio_mapping_ch14=dict(type=str, required=False, default="none"), audio_mapping_ch15=dict(type=str, required=False, default="none"), aud_ptime_idx=dict(type=str, required=False), aud_chan_cnt=dict(type=str, required=False, default="none"), anc_flow_profile=dict(type=str, required=False), sender_type=dict(type=str, required=False)), supports_check_mode=True, ) if module.params['ip_addr'] != 'None': ip_addr = str(IPv4Address(module.params['ip_addr'])) elif module.params['Target'] != 'None': ip_addr = str(IPv4Address(module.params['Target'])) else: module.fail_json( changed=False, msg=f"Missing parameter: ip_addr or Target must be provided") #Clean IPs of unused 0 if module.params['src_ip_addr']: module.params['src_ip_addr'] = str( IPv4Address(module.params['src_ip_addr'])) if module.params['dst_ip_addr']: module.params['dst_ip_addr'] = str( IPv4Address(module.params['dst_ip_addr'])) #Generate dest multicast mac try: module.params['dst_mac'] = generate_dest_multicast_mac( module.params['dst_ip_addr']) except TypeError as e: module.fail_json(changed=False, msg=f"Error generating multicast mac: {e}", module_ip=ip_addr, module_flow_id=module.params['Flow']) try: url = f"http://{ip_addr}/emsfp/node/v1/flows/{module.params['Flow']}" except (AddressValueError, NetmaskValueError) as e: module.fail_json(changed=False, msg=f"{e}\n") payload_params = {} selected_payload_template = "None" try: # Get firmware version ef = EB22(ip_addr) module_type = get_flow_type(url) payload_params = get_flow_payload( module_type, module.params, float(ef.getActiveFirmawareVersion())) except Exception as e: exc_type, exc_value, exc_tb = exc_info() module.fail_json(changed=False, msg=f"Error during payload_param creation.\n" \ f"Device type: {module.params['sfp_type']}\n" \ f"Error: {e}\n" \ f"Traceback:{pprint(traceback.format_exception(exc_type, exc_value, exc_tb))}") try: em = EMSFP(url, payload_params) except Exception as e: exc_type, exc_value, exc_tb = exc_info() module.fail_json(changed=False, msg=f"Flow type: {module_type}\nSelected template: {selected_payload_template}\n" \ f"Error: {e}\n" \ f"Traceback:{pprint(traceback.format_exception(exc_type, exc_value, exc_tb))}") configure_em_device( module, em, message= f"Device type: {module_type}\nSelected template: {selected_payload_template}\nRoute: {url}\nPayload: {em.payload}\n" )
def main(): arguments = dict(sdi_audio_configs_payload=dict(type='dict', required=True)) module = AnsibleModule( argument_spec=dict( ip_addr=dict(type='str', required=True), module_type=dict(type='str', required=True), sdi_channel_id=dict(type='str', required=True), frame_sync=dict(type='str', required=False), offset_mode=dict(type='str', required=False), usec_offset=dict(type='str', required=False), v_offset=dict(type='str', required=False), h_offset=dict(type='str', required=False) ), supports_check_mode=True, ) channel_type = "" payload_params = {} if ( module.params['module_type'] in ['encap', 'enc', "st2110_10G_enc"]) or ( module.params['module_type'] in ['box3u_25G', 'Embox6_8'] and module.params['sdi_channel_id'][:2] in ['b0', 'b2', 'b4', 'b6']): channel_type = "sdi_input" payload_params = { 'line_offset': { 'frame_sync': module.params['frame_sync'], 'offset_mode': module.params['offset_mode'], 'usec_offset': module.params['usec_offset'], 'v_offset': module.params['v_offset'], 'h_offset': module.params['h_offset'] } } elif (module.params['module_type'] in ['decap', 'dec', "st2110_10G_dec"]): channel_type = "sdi_output" payload_params = { 'line_offset': { 'frame_sync': module.params['frame_sync'], 'offset_mode': module.params['offset_mode'], 'usec_offset': module.params['usec_offset'], 'v_offset': module.params['v_offset'], 'h_offset': module.params['h_offset'] } } elif module.params['module_type'] in ['box3u_25G', 'Embox6_8'] and module.params['sdi_channel_id'][:2] in ['b1', 'b3', 'b5', 'b7']: module.exit_json(changed=False, msg=f"No frame_sync parameter on box SDI Output.") else: error_msg = f"\'{module.params['module_type']}\' isn't a valid sfp module \'{module.params['sdi_channel_id'][:2]}\' doesn't match sdi channel id prefix." module.fail_json(changed=False, msg=error_msg) if not fullmatch(SDI_CHANNEL_ID, module.params['sdi_channel_id']): error_msg = f"sdi_channel_id \'{module.params['sdi_channel_id']}\' est invalide selon le regex: {SDI_CHANNEL_ID}" module.fail_json(changed=False, msg=error_msg) url = f"http://{IPv4Address(module.params['ip_addr'])}/emsfp/node/v1/{channel_type}/{module.params['sdi_channel_id']}/" try: response = get(url) if response.status_code == 400: if channel_type == 'sdi_input': module.fail_json( changed=False, msg=f"URL unreachable: {url}\nReason: Corresponding SDI input module innexistant or defective.\n" ) elif channel_type == 'sdi_output': module.fail_json( changed=False, msg=f"URL unreachable: {url}\nReason: Corresponding SDI output module innexistant or defective.\n" ) except RequestException as e: module.fail_json( changed=False, msg=f"URL unreachable: {url}\nReason: {e}\n" ) em = EMSFP(url, payload_params) configure_em_device(module, em)