def delete_irods_account(request): if request.method == 'POST': user = request.user try: exec_cmd = "{0} {1}".format(settings.HS_USER_ZONE_PROXY_USER_DELETE_USER_CMD, user.username) output = run_ssh_command(host=settings.HS_USER_ZONE_HOST, uname=settings.HS_USER_ZONE_PROXY_USER, pwd=settings.HS_USER_ZONE_PROXY_USER_PWD, exec_cmd=exec_cmd) if output: if 'ERROR:' in output.upper(): # there is an error from icommand run, report the error return HttpResponse( dumps({"error": 'iRODS server failed to delete this iRODS account {0}. Check the server log for details.'.format(user.username)}), content_type = "application/json" ) user_profile = UserProfile.objects.filter(user=user).first() user_profile.create_irods_user_account = False user_profile.save() return HttpResponse( dumps({"success": "iRODS account {0} is deleted successfully".format(user.username)}), content_type = "application/json" ) except Exception as ex: return HttpResponse( dumps({"error": ex.message}), content_type = "application/json" )
def delete_irods_account(request): if request.method == 'POST': user = request.user try: exec_cmd = "{0} {1}".format( settings.HS_USER_ZONE_PROXY_USER_DELETE_USER_CMD, user.username) output = run_ssh_command(host=settings.HS_USER_ZONE_HOST, uname=settings.HS_USER_ZONE_PROXY_USER, pwd=settings.HS_USER_ZONE_PROXY_USER_PWD, exec_cmd=exec_cmd) if output: if 'ERROR:' in output.upper(): # there is an error from icommand run, report the error return HttpResponse(dumps({ "error": 'iRODS server failed to delete this iRODS account {0}. Check the server log for details.' .format(user.username) }), content_type="application/json") user_profile = UserProfile.objects.filter(user=user).first() user_profile.create_irods_user_account = False user_profile.save() return HttpResponse(dumps({ "success": "iRODS account {0} is deleted successfully".format( user.username) }), content_type="application/json") except Exception as ex: return HttpResponse(dumps({"error": ex.message}), content_type="application/json")
def create_irods_account(request): if request.method == 'POST': try: user = request.user pwd = str(request.POST.get('password')) exec_cmd = "{0} {1} {2}".format( settings.LINUX_ADMIN_USER_CREATE_USER_IN_USER_ZONE_CMD, user.username, pwd) output = run_ssh_command( host=settings.HS_USER_ZONE_HOST, uname=settings.LINUX_ADMIN_USER_FOR_HS_USER_ZONE, pwd=settings.LINUX_ADMIN_USER_PWD_FOR_HS_USER_ZONE, exec_cmd=exec_cmd) for out_str in output: if 'bash:' in out_str or ('ERROR:' in out_str.upper() and \ not 'CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME' in out_str.upper()): # there is an error from icommand run which is not about the fact # that the user already exists, report the error return JsonResponse( { "error": 'iRODS server failed to create this iRODS account {0}. ' 'Check the server log for details.'.format( user.username) }, status=status.HTTP_500_INTERNAL_SERVER_ERROR) user_profile = UserProfile.objects.filter(user=user).first() user_profile.create_irods_user_account = True user_profile.save() return JsonResponse( { "success": "iRODS account {0} is created successfully".format( user.username) }, status=status.HTTP_200_OK) except Exception as ex: return JsonResponse( { "error": str(ex) + ' - iRODS server failed to create this iRODS account.' }, status=status.HTTP_500_INTERNAL_SERVER_ERROR) else: return JsonResponse({"error": "Not POST request"}, status=status.HTTP_400_BAD_REQUEST)
def create_irods_account(request): if request.method == 'POST': try: user = request.user pwd = str(request.POST.get('password')) exec_cmd = "{0} {1} {2}".format( settings.LINUX_ADMIN_USER_CREATE_USER_IN_USER_ZONE_CMD, user.username, pwd) output = run_ssh_command( host=settings.HS_USER_ZONE_HOST, uname=settings.LINUX_ADMIN_USER_FOR_HS_USER_ZONE, pwd=settings.LINUX_ADMIN_USER_PWD_FOR_HS_USER_ZONE, exec_cmd=exec_cmd) if output: if 'ERROR:' in output.upper() and \ not 'CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME' in output.upper(): # there is an error from icommand run which is not about the fact # that the user already exists, report the error return HttpResponse(dumps({ "error": 'iRODS server failed to create this iRODS account {0}. ' 'Check the server log for details.'.format( user.username) }), content_type="application/json") user_profile = UserProfile.objects.filter(user=user).first() user_profile.create_irods_user_account = True user_profile.save() return HttpResponse(dumps({ "success": "iRODS account {0} is created successfully".format( user.username) }), content_type="application/json") except Exception as ex: return HttpResponse(dumps({ "error": ex.message + ' - iRODS server failed to create this ' 'iRODS account.' }), content_type="application/json") else: return HttpResponse(dumps({"error": "Not POST request"}), content_type="application/json")
def create_irods_user_in_user_zone(self): """Create corresponding irods account in user zone.""" try: exec_cmd = "{0} {1} {2}".format(settings.HS_USER_ZONE_PROXY_USER_CREATE_USER_CMD, self.user.username, self.user.username) output = run_ssh_command(host=settings.HS_USER_ZONE_HOST, uname=settings.HS_USER_ZONE_PROXY_USER, pwd=settings.HS_USER_ZONE_PROXY_USER_PWD, exec_cmd=exec_cmd) if output: if 'ERROR:' in output.upper(): # irods account failed to create self.assertRaises(SessionException(-1, output, output)) user_profile = UserProfile.objects.filter(user=self.user).first() user_profile.create_irods_user_account = True user_profile.save() except Exception as ex: self.assertRaises(SessionException(-1, ex.message, ex.message))
def delete_irods_user_in_user_zone(self): """Delete irods test user in user zone.""" try: exec_cmd = "{0} {1}".format(settings.HS_USER_ZONE_PROXY_USER_DELETE_USER_CMD, self.user.username) output = run_ssh_command(host=settings.HS_USER_ZONE_HOST, uname=settings.HS_USER_ZONE_PROXY_USER, pwd=settings.HS_USER_ZONE_PROXY_USER_PWD, exec_cmd=exec_cmd) if output: if 'ERROR:' in output.upper(): # there is an error from icommand run, report the error self.assertRaises(SessionException(-1, output, output)) user_profile = UserProfile.objects.filter(user=self.user).first() user_profile.create_irods_user_account = False user_profile.save() except Exception as ex: # there is an error from icommand run, report the error self.assertRaises(SessionException(-1, ex.message, ex.message))
def create_irods_account(request): if request.method == 'POST': try: user = request.user pwd = str(request.POST.get('password')) exec_cmd = "{0} {1} {2}".format(settings.HS_USER_ZONE_PROXY_USER_CREATE_USER_CMD, user.username, pwd) output = run_ssh_command(host=settings.HS_USER_ZONE_HOST, uname=settings.HS_USER_ZONE_PROXY_USER, pwd=settings.HS_USER_ZONE_PROXY_USER_PWD, exec_cmd=exec_cmd) if output: if 'ERROR:' in output.upper() and \ not 'CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME' in output.upper(): # there is an error from icommand run which is not about the fact # that the user already exists, report the error return HttpResponse( dumps({"error": 'iRODS server failed to create this iRODS account {0}. ' 'Check the server log for details.'.format(user.username)}), content_type = "application/json" ) user_profile = UserProfile.objects.filter(user=user).first() user_profile.create_irods_user_account = True user_profile.save() return HttpResponse( dumps({"success": "iRODS account {0} is created successfully".format( user.username)}), content_type = "application/json" ) except Exception as ex: return HttpResponse( dumps({"error": ex.message + ' - iRODS server failed to create this ' 'iRODS account.'}), content_type = "application/json" ) else: return HttpResponse( dumps({"error": "Not POST request"}), content_type="application/json" )
def create_irods_user_in_user_zone(self): """Create corresponding irods account in user zone.""" try: exec_cmd = "{0} {1} {2}".format( settings.LINUX_ADMIN_USER_CREATE_USER_IN_USER_ZONE_CMD, self.user.username, self.user.username) output = run_ssh_command( host=settings.HS_USER_ZONE_HOST, uname=settings.LINUX_ADMIN_USER_FOR_HS_USER_ZONE, pwd=settings.LINUX_ADMIN_USER_PWD_FOR_HS_USER_ZONE, exec_cmd=exec_cmd) for out_str in output: if 'ERROR:' in out_str.upper(): # irods account failed to create self.assertRaises(SessionException(-1, out_str, out_str)) user_profile = UserProfile.objects.filter(user=self.user).first() user_profile.create_irods_user_account = True user_profile.save() except Exception as ex: self.assertRaises(SessionException(-1, str(ex), str(ex)))
def delete_irods_account(request): if request.method == 'POST': user = request.user try: exec_cmd = "{0} {1}".format( settings.LINUX_ADMIN_USER_DELETE_USER_IN_USER_ZONE_CMD, user.username) output = run_ssh_command( host=settings.HS_USER_ZONE_HOST, uname=settings.LINUX_ADMIN_USER_FOR_HS_USER_ZONE, pwd=settings.LINUX_ADMIN_USER_PWD_FOR_HS_USER_ZONE, exec_cmd=exec_cmd) for out_str in output: if 'ERROR:' in out_str.upper(): # there is an error from icommand run, report the error return JsonResponse( { "error": 'iRODS server failed to delete this iRODS account {0}. ' 'Check the server log for details.'.format( user.username) }, status=status.HTTP_500_INTERNAL_SERVER_ERROR) user_profile = UserProfile.objects.filter(user=user).first() user_profile.create_irods_user_account = False user_profile.save() return JsonResponse( { "success": "iRODS account {0} is deleted successfully".format( user.username) }, status=status.HTTP_200_OK) except Exception as ex: return JsonResponse({"error": str(ex)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)