1
2 """
3 Resource management.
4
5 Handles authentication, privilege, resource accounting and notification
6 for individual users on the server.
7
8 Maps to a backend user database and resource database.
9 """
12 """
13 Resource management.
14
15 Resource management is based on domains. All jobs in the particular
16 domain have the same privileges. Note that domain is explicitly
17 separate from any concept of user so that we can separate privilege
18 from identity. In systems with full user accounting, each user id
19 may be a separate domain. In looser systems where users are not
20 explicitly identified, the domain may be something like the IP
21 address of the client.
22
23 By default all jobs compete for resources at an equal level with
24 no limits on the number of jobs that can be requested.
25 """
26 id = ""
27 """Unique id for the resource domain"""
28 priority = 0
29 """Priority for jobs in this domain"""
30 credit = -1
31 """Amount of credit remaining in this domain, or -1 if unlimited"""
32 cpu_requested = 0
33 """Number of CPU hours requested in this domain"""
34 cpu_used = 0
35 """Number of CPU hours used in this domain"""
36 last_credit = 0
37 """timestamp of last credit"""
38 @staticmethod
40 """
41 Fetch a resource domain from the database.
42 """
43 usage=databaselookup(id)
44 return usage
45 - def nice(self, points=1, cost=None):
46 """
47 Purchase or sell nice points.
48
49 Users who let some jobs run at lower priority are rewarded by having
50 other jobs run at higher priority. To avoid too much gaming of the
51 system, the cost of the jobs must be estimated, based on number of
52 cpu hours.
53
54 Raises ValueError if insufficient credit to raise the privilege.
55 """
56 if self.credit >= 0:
57 if points*cost<self.credit:
58 raise ValueError("Insufficient credit")
59 self.credit -= points*cost
60 databasestore(self)
62 """
63 Record the request.
64
65 Note that no request will be denied at this point. By always
66 allowing work to run we avoid under-utilizing the machine.
67 """
68
70 """
71 Information about the individual user.
72
73 This is mapped to a persistent store in the service database.
74 """
75 domain = ""
76 """
77 Domain to use for the user.
78 """
79 name = ""
80 """Screen name for the user. This is for convenience and need not
81 be unique. The real identiy is the user id and the associated
82 authentication key."""
83 key = ""
84 """Authentication key used to uniquely identify the user. This should
85 be the public key portion of a public-private pair, or the key hash
86 for secure remote password."""
87 password = ""
88 """Password for logging into the service without a public key."""
89