def hostname_set(): """Changes the machine’s hostname Expects a JSON data structure in the request body that contains the new hostname as string. Example: { 'hostname': 'grandpilot' } Returns: A JSON string with two keys: success, error. success: true if successful. error: null if successful, str otherwise. Example of success: { 'success': true, 'error': null } Example of error: { 'success': false, 'error': 'Invalid hostname.' } """ try: new_hostname = request_parsers.hostname.parse_hostname(flask.request) hostname.change(new_hostname) return json_response.success() except request_parsers.errors.Error as e: return json_response.error('Invalid input: %s' % str(e)), 200 except hostname.Error as e: return json_response.error('Operation failed: %s' % str(e)), 200
def hostname_set(): """Changes the machine’s hostname Expects a JSON data structure in the request body that contains the new hostname as string. Example: { 'hostname': 'grandpilot' } Returns: Empty response on success, error object otherwise. """ try: new_hostname = request_parsers.hostname.parse_hostname(flask.request) hostname.change(new_hostname) return json_response.success2() except request_parsers.errors.Error as e: return json_response.error2(e), 400 except hostname.Error as e: return json_response.error2(e), 500