def build_cmdref_objects(td): cmd_ref[td['type']]['ref'] = [] saved_ids = [] if want.get(td['name']): for playvals in want[td['name']]: valiate_input(playvals, td['name'], self._module) if playvals['id'] in saved_ids: continue saved_ids.append(playvals['id']) resource_key = td['cmd'].format(playvals['id']) # Only build the NxosCmdRef object for the td['name'] module parameters. self._module.params[ 'config'] = get_module_params_subsection( ALL_MP, td['type'], playvals['id']) cmd_ref[td['type']]['ref'].append( NxosCmdRef(self._module, td['obj'])) ref = cmd_ref[td['type']]['ref'][-1] ref.set_context([resource_key]) if td['type'] == 'TMS_SENSORGROUP' and get_setval_path( self._module): # Sensor group path setting can contain optional values. # Call get_setval_path helper function to process any # optional setval keys. ref._ref['path']['setval'] = get_setval_path( self._module) ref.get_existing(device_cache) ref.get_playvals() if td['type'] == 'TMS_DESTGROUP': normalize_data(ref)
def set_state(self, want, have): """ Select the appropriate function based on the state provided :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ state = self._module.params['state'] # The deleted case is very simple since we purge all telemetry config # and does not require any processing using NxosCmdRef objects. if state == 'deleted': return self._state_deleted(want, have) # Save off module params ALL_MP = self._module.params['config'] cmd_ref = {} cmd_ref['TMS_GLOBAL'] = {} cmd_ref['TMS_DESTGROUP'] = {} cmd_ref['TMS_SENSORGROUP'] = {} cmd_ref['TMS_SUBSCRIPTION'] = {} # Get Telemetry Global Data cmd_ref['TMS_GLOBAL']['ref'] = [] self._module.params['config'] = get_module_params_subsection( ALL_MP, 'TMS_GLOBAL') cmd_ref['TMS_GLOBAL']['ref'].append( NxosCmdRef(self._module, TMS_GLOBAL)) ref = cmd_ref['TMS_GLOBAL']['ref'][0] ref.set_context() ref.get_existing() ref.get_playvals() device_cache = ref.cache_existing # Get Telemetry Destination Group Data if want.get('destination_groups'): td = { 'name': 'destination_groups', 'type': 'TMS_DESTGROUP', 'obj': TMS_DESTGROUP, 'cmd': 'destination-group {0}' } cmd_ref[td['type']]['ref'] = [] saved_ids = [] for playvals in want[td['name']]: valiate_input(playvals, td['name'], self._module) if playvals['id'] in saved_ids: continue saved_ids.append(playvals['id']) resource_key = td['cmd'].format(playvals['id']) # Only build the NxosCmdRef object for the destination group module parameters. self._module.params['config'] = get_module_params_subsection( ALL_MP, td['type'], playvals['id']) cmd_ref[td['type']]['ref'].append( NxosCmdRef(self._module, td['obj'])) ref = cmd_ref[td['type']]['ref'][-1] ref.set_context([resource_key]) ref.get_existing(device_cache) ref.get_playvals() normalize_data(ref) # Get Telemetry Sensor Group Data if want.get('sensor_groups'): td = { 'name': 'sensor_groups', 'type': 'TMS_SENSORGROUP', 'obj': TMS_SENSORGROUP, 'cmd': 'sensor-group {0}' } cmd_ref[td['type']]['ref'] = [] saved_ids = [] for playvals in want[td['name']]: valiate_input(playvals, td['name'], self._module) if playvals['id'] in saved_ids: continue saved_ids.append(playvals['id']) resource_key = td['cmd'].format(playvals['id']) # Only build the NxosCmdRef object for the sensor group module parameters. self._module.params['config'] = get_module_params_subsection( ALL_MP, td['type'], playvals['id']) cmd_ref[td['type']]['ref'].append( NxosCmdRef(self._module, td['obj'])) ref = cmd_ref[td['type']]['ref'][-1] ref.set_context([resource_key]) if get_setval_path(self._module): # Sensor group path setting can contain optional values. # Call get_setval_path helper function to process any # optional setval keys. ref._ref['path']['setval'] = get_setval_path(self._module) ref.get_existing(device_cache) ref.get_playvals() # Get Telemetry Subscription Data if want.get('subscriptions'): td = { 'name': 'subscriptions', 'type': 'TMS_SUBSCRIPTION', 'obj': TMS_SUBSCRIPTION, 'cmd': 'subscription {0}' } cmd_ref[td['type']]['ref'] = [] saved_ids = [] for playvals in want[td['name']]: valiate_input(playvals, td['name'], self._module) if playvals['id'] in saved_ids: continue saved_ids.append(playvals['id']) resource_key = td['cmd'].format(playvals['id']) # Only build the NxosCmdRef object for the subscription module parameters. self._module.params['config'] = get_module_params_subsection( ALL_MP, td['type'], playvals['id']) cmd_ref[td['type']]['ref'].append( NxosCmdRef(self._module, td['obj'])) ref = cmd_ref[td['type']]['ref'][-1] ref.set_context([resource_key]) ref.get_existing(device_cache) ref.get_playvals() if state == 'overridden': if want == have: return [] commands = self._state_overridden(cmd_ref, want, have) elif state == 'merged': if want == have: return [] commands = self._state_merged(cmd_ref) elif state == 'replaced': if want == have: return [] commands = self._state_replaced(cmd_ref) return commands