<commit_before>"""
Low-level implementation for methods
dealing with a bosserver.
uses BosServer and Bnode objects
"""
import types
import afs
from afs.lla.BaseLLA import BaseLLA, exec_wrapper
import BosServerLLAParse as PM
from afs.model import BosServer
from BosServerLLAError import BosServerLLAError


class BosServerLLA(BaseLLA) :
    """
    Direct Access Object for a Process (BNode)
    """

    def __init__(self) :
        BaseLLA.__init__(self)
        return

    #
    # public interface to deal with a full bos_server object
    #

    def push_bos_server(self, bos_server, _cfg=None) :
        """
        pushes configuration of bos_server to AFS-cell
        do not change bnodes
        """
        result_list = []
        # restart times
        result_list.append(self.set_general_restart_time(bos_server, \
            ))
        result_list.append(self.set_newbinary_restart_time(bos_server, \
            ))
        # userlist
        superusers=self.get_userlist(bos_server).superusers
        to_be_removed = []
        to_be_added = []
        for su in superusers :
            if not su in bos_server.superusers :
                to_be_removed.append(su)
        if len(to_be_removed) > 0 :
            self.remove_user(bos_server,to_be_removed)
        for su in bos_server.superusers :
            if not su in superusers :
                to_be_added.append(su)
        if len(to_be_added) > 0 :
            self.add_user(bos_server,to_be_added)
            
        return  

    def get_bos_server(self, bos_server, _cfg = None) :
        """
        get a full bos_server object from server.
        filled attributes depends on authorization. 
        """
        dns_info = afs.LOOKUP_UTIL[_cfg.cell].get_dns_info(bos_server.servernames[0])
        bos_server.servernames = dns_info["names"]
        bos_server.ipaddrs = dns_info["ipaddrs"]
        bos_server = self.get_bnodes(bos_server)
        bos_server = self.get_restart_times(bos_server)
        bos_server = self.get_db_servers(bos_server)
        return bos_server

    @exec_wrapper    
    def get_bnodes(self, bos_server, _cfg = None) :
        """
        get list of BNode Objects from a server.
        """ 
        command_list = [_cfg.binaries["bos"], "status", "-server", \
            "%s"  % bos_server.servernames[0] ,"-long", "-cell" , "%s" % _cfg.cell]
        return command_list, PM.get_bnodes

    #
    # methods to deal with specific attributes of a bos_server object
    #

    @exec_wrapper    
    def get_restart_times(self, bos_server, _cfg = None):
        """
        get attributes restart times from bosserver into given object
        """
        command_list = [_cfg.binaries["bos"], "getrestart", "-server", \
            "%s"  % bos_server.servernames[0], "-cell" , "%s" % _cfg.cell]
        return command_list, PM.get_restart_times

    @exec_wrapper    
    def set_general_restart_time(self, bos_server, _cfg = None) :
        """
        pushes general restart time onto bosserver as given in the object.
        """
        command_list = [_cfg.binaries["bos"], "setrestart", "-server", "%s"  % \
            bos_server.servernames[0], "-time",  "%s" % \
            bos_server.general_restart_time,  "-general", "-cell" , "%s" % _cfg.cell ]
        return command_list, PM.set_restart_time

    @exec_wrapper    
    def set_newbinary_restart_time(self, bos_server, _cfg = None) :
        """
        pushes restart time for new binaries on bosserver as given in the object.
        """
        command_list = [_cfg.binaries["bos"], "setrestart", "-server", "%s"  % \
            bos_server.servernames[0], "-time",  "%s" % \
            bos_server.general_restart_time,  "-newbinary", "-cell" , "%s" % _cfg.cell ]
        return command_list, PM.set_restart_time

    @exec_wrapper    
    def add_user(self, bos_server, userlist, _cfg = None) :
        """
        adds userlist to bosserver*s superuserlist
        should only be called by push_bos_server
        """
        if type(userlist) != types.ListType :
              raise BosServerLLAError("userlist must be a list of strings")
        usernames = " ".join(userlist)
        command_list = [_cfg.binaries["bos"], "adduser", "-server", "%s"  % \
            bos_server.servernames[0],  "-user",  "%s" % usernames, "-cell" , "%s" % _cfg.cell ]
        return command_list, PM.add_user
    
    @exec_wrapper    
    def remove_user(self, bos_server, userlist, _cfg = None) :
        """
        removes userlist to bosserver*s superuserlist
        should only be called by push_bos_server
        """<commit_msg>BosServerLLA: remove helper method for setting all<commit_after>"""
Low-level implementation for methods
dealing with a bosserver.
uses BosServer and Bnode objects
"""
import types
import afs
from afs.lla.BaseLLA import BaseLLA, exec_wrapper
import BosServerLLAParse as PM
from afs.model import BosServer
from BosServerLLAError import BosServerLLAError


class BosServerLLA(BaseLLA) :
    """
    Direct Access Object for a Process (BNode)
    """

    def __init__(self) :
        BaseLLA.__init__(self)
        return

    def get_bos_server(self, bos_server, _cfg = None) :
        """
        get a full bos_server object from server.
        filled attributes depends on authorization. 
        """
        dns_info = afs.LOOKUP_UTIL[_cfg.cell].get_dns_info(bos_server.servernames[0])
        bos_server.servernames = dns_info["names"]
        bos_server.ipaddrs = dns_info["ipaddrs"]
        bos_server = self.get_bnodes(bos_server)
        bos_server = self.get_restart_times(bos_server)
        bos_server = self.get_db_servers(bos_server)
        return bos_server

    @exec_wrapper    
    def get_bnodes(self, bos_server, _cfg = None) :
        """
        get list of BNode Objects from a server.
        """ 
        command_list = [_cfg.binaries["bos"], "status", "-server", \
            "%s"  % bos_server.servernames[0] ,"-long", "-cell" , "%s" % _cfg.cell]
        return command_list, PM.get_bnodes

    #
    # methods to deal with specific attributes of a bos_server object
    #

    @exec_wrapper    
    def get_restart_times(self, bos_server, _cfg = None):
        """
        get attributes restart times from bosserver into given object
        """
        command_list = [_cfg.binaries["bos"], "getrestart", "-server", \
            "%s"  % bos_server.servernames[0], "-cell" , "%s" % _cfg.cell]
        return command_list, PM.get_restart_times

    @exec_wrapper    
    def set_general_restart_time(self, bos_server, _cfg = None) :
        """
        sets general restart time onto bosserver as given in the object.
        """
        command_list = [_cfg.binaries["bos"], "setrestart", "-server", "%s"  % \
            bos_server.servernames[0], "-time",  "%s" % \
            bos_server.general_restart_time,  "-general", "-cell" , "%s" % _cfg.cell ]
        return command_list, PM.set_restart_time

    @exec_wrapper    
    def set_newbinary_restart_time(self, bos_server, _cfg = None) :
        """
        sets restart time for new binaries on bosserver as given in the object.
        """
        command_list = [_cfg.binaries["bos"], "setrestart", "-server", "%s"  % \
            bos_server.servernames[0], "-time",  "%s" % \
            bos_server.general_restart_time,  "-newbinary", "-cell" , "%s" % _cfg.cell ]
        return command_list, PM.set_restart_time

    @exec_wrapper    
    def add_user(self, bos_server, userlist, _cfg = None) :
        """
        adds userlist to bosserver*s superuserlist
        """
        if type(userlist) != types.ListType :
              raise BosServerLLAError("userlist must be a list of strings")
        usernames = " ".join(userlist)
        command_list = [_cfg.binaries["bos"], "adduser", "-server", "%s"  % \
            bos_server.servernames[0],  "-user",  "%s" % usernames, "-cell" , "%s" % _cfg.cell ]
        return command_list, PM.add_user
    
    @exec_wrapper    
    def remove_user(self, bos_server, userlist, _cfg = None) :
        """
        removes userlist to bosserver*s superuserlist
        """
{'fraction_non_alphanumeric': 0.10994828859886728, 'fraction_numerical': 0.0017237133710908644, 'mean_word_length': 2.4245362563237776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2450424', 'n_tokens_mistral': 2584, 'n_tokens_neox': 2531, 'n_words': 605}