Example #1
0
  def _create_custom_user(self):
    user = get_validated_string_input(
      "Enter user account for ambari-server service ({0}):".format(self.user),
      self.user, None,
      "Invalid username.",
      False
    )
    if user in self.NR_SYSTEM_USERS:
      self.user = user
      return 0

    if get_silent():
      password = self.password
    else:
      password = get_validated_string_input("Enter password for user {0}:".format(user), "", None, "Password", True, False)

    from ambari_commons.os_windows import UserHelper

    uh = UserHelper(user)

    if uh.find_user():
      print_info_msg("User {0} already exists, make sure that you typed correct password for user, "
                     "skipping user creation".format(user))
    else:
      status, message = uh.create_user(password)
      if status == UserHelper.USER_EXISTS:
        print_info_msg("User {0} already exists, make sure that you typed correct password for user, "
                       "skipping user creation".format(user))

      elif status == UserHelper.ACTION_FAILED:  # fail
        print_warning_msg("Can't create user {0}. Failed with message {1}".format(user, message))
        return UserHelper.ACTION_FAILED

    self.password = password

    # setting SeServiceLogonRight and SeBatchLogonRight to user
    #This is unconditional
    status, message = uh.add_user_privilege('SeServiceLogonRight')
    if status == UserHelper.ACTION_FAILED:
      print_warning_msg("Can't add SeServiceLogonRight to user {0}. Failed with message {1}".format(user, message))
      return UserHelper.ACTION_FAILED

    status, message = uh.add_user_privilege('SeBatchLogonRight')
    if status == UserHelper.ACTION_FAILED:
      print_warning_msg("Can't add SeBatchLogonRight to user {0}. Failed with message {1}".format(user, message))
      return UserHelper.ACTION_FAILED

    print_info_msg("User configuration is done.")
    print_warning_msg("When using non SYSTEM user make sure that your user has read\write access to log directories and "
                      "all server directories. In case of integrated authentication for SQL Server make sure that your "
                      "user is properly configured to access the ambari database.")

    if user.find('\\') == -1:
      user = '******' + user

    self.user = user
    return 0
Example #2
0
    def _create_custom_user(self):
        user = get_validated_string_input(
            "Enter user account for ambari-server service ({0}):".format(
                self.NR_DEFAULT_USER), self.NR_DEFAULT_USER, None,
            "Invalid username.", False)
        if user == self.NR_DEFAULT_USER:
            return 0, user
        password = get_validated_string_input(
            "Enter password for user {0}:".format(user), "", None, "Password",
            True, False)

        from ambari_commons.os_windows import UserHelper

        uh = UserHelper()

        status, message = uh.create_user(user, password)
        if status == UserHelper.USER_EXISTS:
            print_info_msg(
                "User {0} already exists, make sure that you typed correct password for user, "
                "skipping user creation".format(user))

        elif status == UserHelper.ACTION_FAILED:  # fail
            print_warning_msg(
                "Can't create user {0}. Failed with message {1}".format(
                    user, message))
            return UserHelper.ACTION_FAILED, None

        # setting SeServiceLogonRight to user

        status, message = uh.add_user_privilege(user, 'SeServiceLogonRight')
        if status == UserHelper.ACTION_FAILED:
            print_warning_msg(
                "Can't add SeServiceLogonRight to user {0}. Failed with message {1}"
                .format(user, message))
            return UserHelper.ACTION_FAILED, None

        print_info_msg("User configuration is done.")
        print_warning_msg(
            "When using non SYSTEM user make sure that your user have read\write access to log directories and "
            "all server directories. In case of integrated authentication for SQL Server make sure that your "
            "user properly configured to use ambari and metric database.")
        #storing username and password in os.environ temporary to pass them to service
        os.environ[SERVICE_USERNAME_KEY] = user
        os.environ[SERVICE_PASSWORD_KEY] = password
        return 0, user