| 503 | |
| 504 | |
| 505 | class ProfileManager(object): |
| 506 | |
| 507 | def __init__(self): |
| 508 | self.profiles = dict() |
| 509 | |
| 510 | def _profiles_without_explicit_lbps(self): |
| 511 | names = (profile_name for |
| 512 | profile_name, profile in self.profiles.items() |
| 513 | if not profile._load_balancing_policy_explicit) |
| 514 | return tuple( |
| 515 | 'EXEC_PROFILE_DEFAULT' if n is EXEC_PROFILE_DEFAULT else n |
| 516 | for n in names |
| 517 | ) |
| 518 | |
| 519 | def distance(self, host): |
| 520 | distances = set(p.load_balancing_policy.distance(host) for p in self.profiles.values()) |
| 521 | return HostDistance.LOCAL if HostDistance.LOCAL in distances else \ |
| 522 | HostDistance.REMOTE if HostDistance.REMOTE in distances else \ |
| 523 | HostDistance.IGNORED |
| 524 | |
| 525 | def populate(self, cluster, hosts): |
| 526 | for p in self.profiles.values(): |
| 527 | p.load_balancing_policy.populate(cluster, hosts) |
| 528 | |
| 529 | def check_supported(self): |
| 530 | for p in self.profiles.values(): |
| 531 | p.load_balancing_policy.check_supported() |
| 532 | |
| 533 | def on_up(self, host): |
| 534 | for p in self.profiles.values(): |
| 535 | p.load_balancing_policy.on_up(host) |
| 536 | |
| 537 | def on_down(self, host): |
| 538 | for p in self.profiles.values(): |
| 539 | p.load_balancing_policy.on_down(host) |
| 540 | |
| 541 | def on_add(self, host): |
| 542 | for p in self.profiles.values(): |
| 543 | p.load_balancing_policy.on_add(host) |
| 544 | |
| 545 | def on_remove(self, host): |
| 546 | for p in self.profiles.values(): |
| 547 | p.load_balancing_policy.on_remove(host) |
| 548 | |
| 549 | @property |
| 550 | def default(self): |
| 551 | """ |
| 552 | internal-only; no checks are done because this entry is populated on cluster init |
| 553 | """ |
| 554 | return self.profiles[EXEC_PROFILE_DEFAULT] |
| 555 | |
| 556 | |
| 557 | EXEC_PROFILE_DEFAULT = object() |
no outgoing calls
no test coverage detected