1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import random
23
25
27 self.repo = repo
28 self.failures = 0
29
31 """Returns a serverurl based on this failover method or None
32 if complete failure. If i is given it is a direct index
33 to pull a server URL from instead of using the failures
34 counter."""
35 return None
36
38 "Tells the failover method that the current server is failed."
39 self.failures = self.failures + 1
40
42 "Reset the failures counter to a given index."
43 self.failures = i
44
46 """Returns the current number of failures which is also the
47 index into the list this object represents. ger_serverurl()
48 should always be used to translate an index into a URL
49 as this object may change how indexs map. (See RoundRobin)"""
50
51 return self.failures
52
54 """Returns the how many URLs we've got to cycle through."""
55
56 return len(self.repo.urls)
57
58
59
61
62 """Chooses server based on the first success in the list."""
63
65 "Returns a serverurl based on this failover method or None if complete failure."
66
67 if i == None:
68 index = self.failures
69 else:
70 index = i
71
72 if index >= len(self.repo.urls):
73 return None
74
75 return self.repo.urls[index]
76
77
78
80
81 """Chooses server based on a round robin."""
82
87
89 "Returns a serverurl based on this failover method or None if complete failure."
90
91 if i == None:
92 index = self.failures
93 else:
94 index = i
95
96 if index >= len(self.repo.urls):
97 return None
98
99 rr = (index + self.offset) % len(self.repo.urls)
100 return self.repo.urls[rr]
101
102
103