lib.py 7.91 KB
Newer Older
1
from .error import ServerSelectionError
2
from .query import (list_all_serverselections,
3 4 5 6 7 8
                   fetch_serverselection,
                   fetch_serverselection_dict,
                   fetch_all_user_serverselections,
                   fetch_default_user_serverselection,
                   fetch_all_user_servers,
                   insert_serverselection,
9
                   update_serverselection,
10 11 12 13 14
                   delete_serverselection,
                   add_server_to_serverselection,
                   remove_server_from_serverselection,
                   add_user_to_serverselection,
                   remove_user_from_serverselection,
15
                   remove_server_from_all_serverselections,
16 17 18
                   update_user_from_serverselection,
                   fetch_serverselection_user_role,
                   fetch_serverselection_user_server_role,
Matthieu Lamalle's avatar
Matthieu Lamalle committed
19 20
                   erase_serverselection,
                   set_list_server_serverselection
21 22 23 24
                   )

class ServerSelection():
    """Serverselection Manage API
25
    """
26 27 28 29 30

    def list_serverselections(self, cursor):
        """Fetch Serverselectionss from database

        :return: list of serverselection object
31
        """
32 33 34 35 36 37 38 39
        return  list_all_serverselections(cursor)

    def describe_serverselection(self, cursor, serverselectionid):
        """Get serverselection information asynchronously from database

        :param `int` serverselectionid: servserverselection identifier
        """
        return fetch_serverselection_dict(cursor, serverselectionid)
40

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
41
    def list_user_serverselections(self, cursor, username):
42 43
        """Get serverselections of a user

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
44
        :param str username: user name to be add to the serverselection
45
        """
Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
46
        return fetch_all_user_serverselections(cursor, username)
47

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
48
    def list_user_servers(self, cursor, username):
49 50
        """Get serverselections of a user

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
51
        :param str username: user name to be add to the serverselection
52
        """
Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
53
        return fetch_all_user_servers(cursor, username)
54

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
55
    def default_user_serverselection(self, cursor, username):
56 57
        """Get the default serverselection of a user

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
58
        :param str username: user name to be add to the serverselection
59
        """
Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
60
        return fetch_default_user_serverselection(cursor, username)
61

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
62
    def create_serverselection(self, cursor, serverselectionname, serverselectiondescription, username):
63 64 65 66
        """Creates a serverselection in database

        :param str serverselectionname: serverselection name
        :param str serverselectiondescription: servermodel identifier
Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
67 68
        :param str username: user name to be add to the serverselection
        :param str usernamerole: user role to be add to the serverselection
69 70 71
        :return: newly created serverselection identifier
        :rtype: int
        """
Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
72
        return insert_serverselection(cursor, serverselectionname, serverselectiondescription, username)
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

    def update_serverselection(self, cursor, serverselectionid, serverselectionname, serverselectiondescription, dynamique, requete):
        """Updates a serverselection in database

        :param int serverselectionid: serverselection identifier
        :param str serverselectionname: server name
        :param str serverselectiondescription: serverselection description
        :param bool dynamique : is serverselection dynamique
        :param str requete: request associated to the serverselection
        :return bool: True for update success, False either
        """
        return update_serverselection(cursor, serverselectionid, serverselectionname, serverselectiondescription, dynamique, requete)

    def delete_serverselection(self, cursor, serverselectionid):
        """Deletes a serverselection in database

        :param int serverselectionid: serverselection identifier
        :return bool: True for delete success, False either
        """
        return delete_serverselection(cursor, serverselectionid)

    def erase_serverselection(self, cursor):
        erase_serverselection(cursor)

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
97
    def add_server_to_selection(self, cursor, serverid, serverselectionid):
98 99
        """Add a server to a serverselection in database

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
100
        :param int serverid: server identifier
101
        :param int serverselectionid: serverselection identifier
102 103
        :return bool: True for addition success, False either
        """
Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
104
        return add_server_to_serverselection(cursor, serverid, serverselectionid)
105

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
106
    def remove_server_from_selection(self, cursor, serverid, serverselectionid):
107 108
        """Remove a server from a serverselection in database

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
109
        :param int serverid: server identifier
110
        :param int serverselectionid: serverselection identifier
111 112
        :return bool: True for addition success, False either
        """
Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
113
        return remove_server_from_serverselection(cursor, serverid, serverselectionid)
114 115 116 117 118 119 120 121 122 123

    def remove_server_from_all_selections(self, cursor, serverid):
        """Remove a server from a serverselection in database

        :param int serverid: server identifier
        :param int serverselectionid: serverselection identifier
        :return bool: True for addition success, False either
        """
        return remove_server_from_all_serverselections(cursor, serverid)

Matthieu Lamalle's avatar
Matthieu Lamalle committed
124 125 126 127 128 129 130 131 132
    def set_serverselection_server_list(self, cursor, serverselectionid, serveridlist):
        """Set the list of servers in a serverselection

        :param int serverselectionid: serverselection identifier
        :param string serveridlist: servers list
        :return bool: True for addition success, False either
        """
        return set_list_server_serverselection(cursor, serverselectionid, serveridlist)

133 134 135
    def add_user_to_serverselection(self, cursor, serverselectionid, username, role):
        """Add a user to a serverselection

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
136
        :param int serverid: server identifier
137
        :param str username: user name to be add to the serverseleciton
138
        :param str role: user role to be add to the serverseleciton
139 140 141
        :return bool: True for addition success, False either
        """
        return add_user_to_serverselection(cursor, serverselectionid, username, role)
142

143 144 145
    def remove_user_from_serverselection(self, cursor, serverselectionid, username):
        """Remove a user from a serverselection

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
146
        :param int serverid: server identifier
147 148
        :param int serverselectionid: serverselection identifier
        :param str username: user name to be add to the serverseleciton
149 150 151
        :return bool: True for addition success, False either
        """
        return remove_user_from_serverselection(cursor, serverselectionid, username)
152

153 154 155
    def update_user_to_serverselection(self, cursor, serverselectionid, username, role):
        """Update a user from a serverselection

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
156
        :param int serverid: server identifier
157
        :param str username: user name to be add to the serverseleciton
158
        :param str role: user role to be add to the serverseleciton
159 160 161
        :return bool: True for addition success, False either
        """
        return update_user_from_serverselection(cursor, serverselectionid, username, role)
162

163 164 165
    def get_serverselection_user_role(self, cursor, serverselectionid, username):
        """Update a user from a serverselection

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
166
        :param int serverid: server identifier
167
        :param str username: user name to be add to the serverseleciton
168
        :param str role: user role to be add to the serverseleciton
169 170 171
        :return bool: True for addition success, False either
        """
        return fetch_serverselection_user_role(cursor, username, serverselectionid)
172

173 174 175
    def get_serverselection_user_server_role(self, cursor, serverid, username):
        """Update a user from a serverselection

Matthieu Lamalle's avatar
Acl  
Matthieu Lamalle committed
176
        :param int serverid: server identifier
177
        :param str username: user name to be add to the serverseleciton
178
        :param str role: user role to be add to the serverseleciton
179 180 181
        :return bool: True for addition success, False either
        """
        return fetch_serverselection_user_server_role(cursor, username, serverid)