def main(): module = AnsibleModule( argument_spec=dict( ip_addr=dict(type='str', required=True), inventory=dict(type='str', required=True), hostname=dict(type='str', required=True), device_type=dict(type='dict', required=True), ), supports_check_mode=True, ) module_ip = module.params['ip_addr'] em = EB22(module_ip) try: serial_number = em.getSerialNumber() except Exception as e: module.exit_json( changed=False, msg= f"Error while trying to obtain serial number.\n Exception message: {e}", serial_number="Failed to connect") module.exit_json(changed=False, msg=f"Serial Number: {serial_number}", serial_number=serial_number)
def main(): module = AnsibleModule( argument_spec=dict( module_ip=dict(type=str, required=True), module_firmware_slot=dict(default=0, type=str), module_firmware_filepath=dict(default=0, type=str) ), supports_check_mode=True, ) module_ip = module.params['module_ip'] module_firmware_slot = module.params['module_firmware_slot'] module_firmware_filepath = module.params['module_firmware_filepath'] # Checking if slot ID is in declared range. if module_firmware_slot not in ['0', '1', '2', '3']: module.fail_json(changed=False, msg="Slot must be in this range : 0,1,2 and 3.") # Initiating the upload firmware object. em = EB22(module_ip) # Checking if the selected slot is cleared and can be used to upload firmware. module_slot_config = em.getLoads()[module_firmware_slot] if bool(module_slot_config['empty']) == False: if bool(module_slot_config['Active']) == True: if module.check_mode: module.fail_json(changed=False, msg="CHECK_MODE_ACTIVATED : The call to upload a firmware to this slot on the module : " + module_ip + \ " in REAL mode would result in an error. The selected slot " + module_firmware_slot + " is currently used and set as Active and a firmware can't be upload.") module.fail_json(changed=False, msg="Error : " + module_ip + " The selected slot " + module_firmware_slot + " is currently used and set as Active and a firmware can't be upload.") elif bool(module_slot_config['Default']) == True: if module.check_mode: module.fail_json(changed=False, msg="CHECK_MODE_ACTIVATED : The call to upload a firmware to this slot on the module : " + module_ip + \ " in REAL mode would result in an error. The selected slot " + module_firmware_slot + " is currently used and set as Default and a firmware can't be upload.") module.fail_json(changed=False, msg="Error : " + module_ip + " The selected slot " + module_firmware_slot + " is currently used and set as Default and a firmware can't be upload.") else: if module.check_mode: module.fail_json(changed=True, msg="CHECK_MODE_ACTIVATED : The call to upload a firmware to this slot on the module : " + module_ip + \ " in REAL mode would result in an error. The selected slot " + module_firmware_slot + " is currently used and a firmware can't be upload.") module.fail_json(changed=False, msg="Error : " + module_ip + " The selected slot " + module_firmware_slot + " is currently used and a firmware can't be upload.") else: if module.check_mode: module.exit_json(changed=True, msg="CHECK_MODE_ACTIVATED : The call to upload a firmware to this slot on the module : " + module_ip + \ " in REAL mode would be executed. The selected slot " + module_firmware_slot + " is empty.") # Upload firmware to selected slot. response = em.uploadFirmware(module_firmware_slot, module_firmware_filepath) # Evaluate how to exit this module. if response[0] == False: module.fail_json(changed=False, msg=response[1]) else: module.exit_json(changed=True, msg=response[1])
def main(): module = AnsibleModule( argument_spec=dict(module_ip=dict(type=str, required=True)), supports_check_mode=True, ) module_ip = module.params['module_ip'] #Initiating the upload firmware object. em = EB22(module_ip) # Get module original configurations. ModuleConfigs = em.getLoads() module.exit_json(changed=False, msg=str(ModuleConfigs))
def main(): module = AnsibleModule( argument_spec=dict( ip_addr=dict(type='str', required=True), inventory=dict(type='str', required=True), hostname=dict(type='str', required=True), device_type=dict(type='dict', required=True), ), supports_check_mode=True, ) module_ip = module.params['ip_addr'] em = EB22(module_ip) try: firmware_version = float(em.getActiveFirmawareVersion()) except Exception as e: exc_type, exc_value, exc_tb = exc_info() module.exit_json( changed=False, msg= f"Error while trying to obtain version.\n Exception message: {e}", version="Failed to connect") else: hostname = module.params['hostname'] device_type = get_device_type(hostname, module.params['device_type']) if (device_type != None): with open(module.params['inventory'], 'r') as inventory_file: inventory = yaml.full_load(inventory_file) inventory['all']['children']['emsfp']['children'][device_type][ 'hosts'][hostname]['firmware'] = firmware_version with open(module.params['inventory'], 'w') as f: documents = yaml.dump(inventory, f) module.exit_json(changed=False, msg=f"Firmware version: {firmware_version}", version=firmware_version)
def main(): module = AnsibleModule( argument_spec=dict(module_ip=dict(type=str, required=True), module_firmware_slot=dict(default=0, type=str)), supports_check_mode=True, ) module_ip = module.params['module_ip'] module_firmware_slot = module.params['module_firmware_slot'] # Checking if slot ID is in declared range. if module_firmware_slot not in ['0', '1', '2', '3']: module.fail_json(changed=False, msg="Slot must be in this range : 0,1,2 and 3.") # Initiating the upload firmware object. em = EB22(module_ip) # Checking if slot can be cleared base on it's current configuration. module_slot_config = em.getLoads()[module_firmware_slot] if bool(module_slot_config['empty']) == True: if module.check_mode: module.exit_json( changed=False, msg= "CHECK_MODE_ACTIVATED :The call to clear this slot on the module : " + module_ip + " in REAL mode would be skipped. The selected slot " + module_firmware_slot + " is allready empty.") module.exit_json(changed=False, msg="Skipping module : " + module_ip + " The selected slot " + module_firmware_slot + " is allready empty.") else: if bool(module_slot_config['Active']) == True: if module.check_mode: module.exit_json( changed=False, msg= "CHECK_MODE_ACTIVATED : The call to clear this slot on the module : " + module_ip + " in REAL mode would be skipped. The selected slot " + module_firmware_slot + " is currently used and set as Active and can't be cleared." ) module.fail_json( changed=False, msg="Error clearing slot for module " + module_ip + ": The selected slot " + module_firmware_slot + " is currently set to Active and can't be cleared.") elif bool(module_slot_config['Default']) == True: if module.check_mode: module.exit_json( changed=False, msg= "CHECK_MODE_ACTIVATED : The call to clear this slot on the module : " + module_ip + " in REAL mode would be skipped. The selected slot " + module_firmware_slot + " is currently used and set as Default and can't be cleared." ) module.fail_json( changed=False, msg="Error clearing slot for module" + module_ip + ": The selected slot " + module_firmware_slot + " is currently set to Default and can't be cleared.") else: if module.check_mode: module.exit_json( changed=True, msg= "CHECK_MODE_ACTIVATED : The call to clear this slot on the module : " + module_ip + " in REAL mode would be executed. The selected slot " + module_firmware_slot + " is currently used but not set as Active or Default.") # Clearing selected slot. response = em.clearSlot(module_firmware_slot) # Evaluate how to exit this module. if response[0] == False: module.fail_json(changed=False, msg=response[1]) else: module.exit_json(changed=True, msg=response[1])
def main(): module = AnsibleModule( argument_spec=dict(module_ip=dict(type=str, required=True), module_firmware_slot=dict(default=0, type=str)), supports_check_mode=True, ) module_ip = module.params['module_ip'] module_firmware_slot = module.params['module_firmware_slot'] # Checking if slot ID is in declared range. if module_firmware_slot not in ['0', '1', '2', '3']: module.fail_json(changed=False, msg="Slot must be in this range : 0,1,2 and 3.") # Initiating the upload firmware object. em = EB22(module_ip) # Logic to check if the selected slot can be set as Default. module_slot_config = em.getLoads()[module_firmware_slot] if bool(module_slot_config['empty']) == True: if module.check_mode: module.exit_json( changed=False, msg= "CHECK_MODE_ACTIVATED : The call to set this slot as Default on the module : " + module_ip + " in REAL mode would be skipped. The selected slot " + module_firmware_slot + " is curently empty.") else: module.exit_json(changed=False, msg="Skipping module : " + module_ip + " The selected slot " + module_firmware_slot + " is curently empty.") if bool(module_slot_config['Default']) == True: if module.check_mode: module.exit_json( changed=False, msg= "CHECK_MODE_ACTIVATED : The call to set this slot as Default on the module : " + module_ip + " in REAL mode would be skipped. The selected slot " + module_firmware_slot + " is allready set as Default.") module.exit_json(changed=False, msg="Skipping module : " + module_ip + " The selected slot " + module_firmware_slot + " is allready set as Default.") else: if module.check_mode: module.exit_json( changed=True, msg= "CHECK_MODE_ACTIVATED : The call to set this slot as Default on the module : " + module_ip + " in REAL mode would executed.") # Setting the selected slot as Default. response = em.setDefaultSlot(module_firmware_slot) # Evaluate how to exit this module. if response[0] == False: module.fail_json(changed=False, msg=response[1]) else: module.exit_json(changed=True, msg=response[1])
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" )