def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update( value=dict(type='float', required=True) ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) set_cmd = "settraceprobability {0}".format(module.params['value']) get_cmd = "gettraceprobability" value = module.params['value'] n = NodeToolGetSetCommand(module, get_cmd, set_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.get_command() out = out.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err get_response = "Current trace probability: {0}".format(value) if get_response == out: if rc != 0: result['changed'] = False module.fail_json(name=get_cmd, msg="get command failed", **result) else: if module.check_mode: result['changed'] = True else: (rc, out, err) = n.set_command() out = out.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['changed'] = False module.fail_json(name=set_cmd, msg="set command failed", **result) else: result['changed'] = True module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update(keyspace=dict(type='str', required=True), table=dict(type='str', required=True), min=dict(type='int', required=True), max=dict(type='int', required=True)) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) keyspace = module.params['keyspace'] table = module.params['table'] min = module.params['min'] max = module.params['max'] set_cmd = "setcompactionthreshold {0} {1} {2} {3}".format( keyspace, table, min, max) get_cmd = "getcompactionthreshold {0} {1}".format(keyspace, table) n = NodeToolGetSetCommand(module, get_cmd, set_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.get_command() out = out.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err get_response = "Current compaction thresholds for {0}/{1}: \n min = {2}, max = {3}".format( keyspace, table, min, max) if get_response == out: if rc != 0: result['changed'] = False module.fail_json(name=get_cmd, msg="get command failed", **result) else: if module.check_mode: result['changed'] = True else: (rc, out, err) = n.set_command() out = out.strip() if module.debug: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['changed'] = False module.fail_json(name=set_cmd, msg="set command failed", **result) else: result['changed'] = True module.exit_json(**result)
def main(): argument_spec = cassandra_common_argument_spec() argument_spec.update( value=dict(type='int', required=True) ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) set_cmd = "setbatchlogreplaythrottle {0}".format(module.params['value']) get_cmd = "getbatchlogreplaythrottle" value = module.params['value'] n = NodeToolGetSetCommand(module, get_cmd, set_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.get_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err get_response = "Batchlog replay throttle: {0} KB/s".format(value) if get_response == out: if rc != 0: result['changed'] = False module.fail_json(name=get_cmd, msg="{0} command failed".format(get_cmd), **result) else: result['changed'] = False result['msg'] = "Batch log replay throttle is already {0} KB/s".format(value) else: if module.check_mode: result['changed'] = True result['msg'] = "Batch log replay throttle updated" else: (rc, out, err) = n.set_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['changed'] = False module.fail_json(name=set_cmd, msg="{0} command failed".format(set_cmd), **result) else: result['changed'] = True result['msg'] = "Batch log replay throttle updated" module.exit_json(**result)
def main(): cs_choices = [ "AntiEntropyStage", "CounterMutationStage", "GossipStage", "ImmediateStage", "InternalResponseStage", "MigrationStage", "MiscStage", "MutationStage", "ReadStage", "RequestResponseStage", "TracingStage", "ViewMutationStage" ] argument_spec = cassandra_common_argument_spec() argument_spec.update(concurrency_type=dict( type='str', choices=["default", "compactors", "viewbuilders"], default="default"), concurrency_stage=dict(type='str', choices=cs_choices), value=dict(type='int', required=True)) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[["concurrency_type", "default", ["concurrency_stage"]]]) concurrency_type = module.params['concurrency_type'] concurrency_stage = module.params['concurrency_stage'] value = module.params['value'] if concurrency_type != "default": get_cmd = "{0}{1}".format("getconcurrent", concurrency_type) set_cmd = "{0}{1} -- {2}".format("setconcurrent", concurrency_type, value) else: get_cmd = "{0} -- {1} ".format("getconcurrency", concurrency_stage) set_cmd = "{0} -- {1} {2}".format("setconcurrency", concurrency_stage, value) n = NodeToolGetSetCommand(module, get_cmd, set_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.get_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err # Matches the last int in the output try: current_value = out.split()[-1:][0] if current_value.isdigit(): current_value = int(current_value) else: raise IndexError except IndexError as ie: module.fail_json(msg="Failure parsing {0} output: {1}".format( get_cmd, str(ie)), **result) if current_value == value: if rc != 0: # should probably move this above result['changed'] = False module.fail_json(name=get_cmd, msg="get command failed", **result) result['msg'] = "Configured value is already {0}".format(value) else: if module.check_mode: result['changed'] = True if concurrency_type != "default": result['msg'] = "{0} updated to {1}".format( concurrency_type, value) else: result['msg'] = "{0}/{1} updated to {2}".format( concurrency_type, concurrency_stage, value) else: (rc, out, err) = n.set_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['changed'] = False module.fail_json(name=set_cmd, msg="set command failed", **result) else: result['changed'] = True if concurrency_type != "default": result['msg'] = "{0} updated to {1}".format( concurrency_type, value) else: result['msg'] = "{0}/{1} updated to {2}".format( concurrency_type, concurrency_stage, value) module.exit_json(**result)
def main(): timeout_type_choices = ['read', 'range', 'write', 'counterwrite', 'cascontention', 'truncate', 'internodeconnect', 'internodeuser', 'internodestreaminguser', 'misc'] argument_spec = cassandra_common_argument_spec() argument_spec.update( timeout=dict(type='int', required=True), timeout_type=dict(type='str', choices=timeout_type_choices, default='read') ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) timeout = module.params['timeout'] timeout_type = module.params['timeout_type'] set_cmd = "settimeout {0} {1}".format(timeout_type, timeout) get_cmd = "gettimeout {0}".format(timeout_type) n = NodeToolGetSetCommand(module, get_cmd, set_cmd) rc = None out = '' err = '' result = {} (rc, out, err) = n.get_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err get_response = "Current timeout for type {0}: {1} ms".format(timeout_type, timeout) if get_response == out: if rc != 0: module.fail_json(name=get_cmd, msg="get command failed", **result) result['changed'] = False result['msg'] = "{0} timeout unchanged".format(timeout_type) else: if module.check_mode: result['changed'] = True else: (rc, out, err) = n.set_command() out = out.strip() if module.params['debug']: if out: result['stdout'] = out if err: result['stderr'] = err if rc != 0: result['changed'] = False module.fail_json(name=set_cmd, msg="set command failed", **result) else: result['changed'] = True result['msg'] = "{0} timeout changed".format(timeout_type) module.exit_json(**result)