def main(self): violations = [] # build list of values from configured data value_builder = ValueBuilder(self._client, 'verify') for key, value in self._data.items(): value_builder.build('', key, value) for expected_value in value_builder.values: if expected_value.state == State.PRESENT: violations.append({ 'path': expected_value.path, 'expected-value': 'present', 'value': 'absent' }) elif expected_value.state == State.ABSENT: violations.append({ 'path': expected_value.path, 'expected-value': 'absent', 'value': 'present' }) elif expected_value.state == State.SET: try: value = self._client.get_value( expected_value.path)['value'] except NsoException as ex: if ex.error.get('type', '') == 'data.not_found': value = None else: raise # handle different types properly n_value = normalize_value(expected_value.value, value, expected_value.path) if n_value != expected_value.value: # if the value comparison fails, try mapping identityref value_type = value_builder.get_type(expected_value.path) if value_type is not None and 'identityref' in value_type: n_value, t_value = self.get_prefix_name(value) if expected_value.value != n_value: violations.append({ 'path': expected_value.path, 'expected-value': expected_value.value, 'value': n_value }) else: raise ModuleFailException( 'value state {0} not supported at {1}'.format( expected_value.state, expected_value.path)) return violations
def main(self): # build list of values from configured data value_builder = ValueBuilder(self._client) for key, value in self._data.items(): value_builder.build('', key, value) self._data_write(value_builder.values) # check sync AFTER configuration is written sync_values = self._sync_check(value_builder.values) self._sync_ensure(sync_values) return self._changes, self._diffs
def _sync_check(self, values): sync_values = [] for value in values: if value.state in (State.CHECK_SYNC, State.IN_SYNC): action = 'check-sync' elif value.state in (State.DEEP_CHECK_SYNC, State.DEEP_IN_SYNC): action = 'deep-check-sync' else: action = None if action is not None: action_path = '{0}/{1}'.format(value.path, action) action_params = {'outformat': 'cli'} resp = self._client.run_action(None, action_path, action_params) if len(resp) > 0: sync_values.append( ValueBuilder.Value(value.path, value.state, resp[0]['value'])) return sync_values