Spaces:
Running on Zero
Running on Zero
Create compute_provider_manager.py
Browse files- compute_provider_manager.py +115 -0
compute_provider_manager.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# =====================================================
|
| 2 |
+
# Apckeyl Framework
|
| 3 |
+
# Version 1.0
|
| 4 |
+
# compute_provider_manager.py
|
| 5 |
+
# =====================================================
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
Compute Provider Manager.
|
| 9 |
+
|
| 10 |
+
Version 1.0
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
from compute_provider_factory import (
|
| 14 |
+
ComputeProviderFactory,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
from compute_provider_selector import (
|
| 18 |
+
ComputeProviderSelector,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# =====================================================
|
| 23 |
+
# Manager
|
| 24 |
+
# =====================================================
|
| 25 |
+
|
| 26 |
+
class ComputeProviderManager:
|
| 27 |
+
|
| 28 |
+
def __init__(self, registry):
|
| 29 |
+
|
| 30 |
+
if registry is None:
|
| 31 |
+
|
| 32 |
+
raise ValueError(
|
| 33 |
+
"Registry is required"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
self.factory = (
|
| 37 |
+
ComputeProviderFactory(
|
| 38 |
+
registry
|
| 39 |
+
)
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
self.selector = (
|
| 43 |
+
ComputeProviderSelector(
|
| 44 |
+
registry
|
| 45 |
+
)
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# =================================================
|
| 50 |
+
# Register Provider
|
| 51 |
+
# =================================================
|
| 52 |
+
|
| 53 |
+
def register_provider(
|
| 54 |
+
self,
|
| 55 |
+
provider,
|
| 56 |
+
):
|
| 57 |
+
|
| 58 |
+
return (
|
| 59 |
+
self.factory.create_provider(
|
| 60 |
+
provider
|
| 61 |
+
)
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# =================================================
|
| 66 |
+
# Get Provider
|
| 67 |
+
# =================================================
|
| 68 |
+
|
| 69 |
+
def get_provider(
|
| 70 |
+
self,
|
| 71 |
+
provider_id: str,
|
| 72 |
+
):
|
| 73 |
+
|
| 74 |
+
return (
|
| 75 |
+
self.factory.get_provider(
|
| 76 |
+
provider_id
|
| 77 |
+
)
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# =================================================
|
| 82 |
+
# Select Provider
|
| 83 |
+
# =================================================
|
| 84 |
+
|
| 85 |
+
def select_provider(
|
| 86 |
+
self,
|
| 87 |
+
task_type: str,
|
| 88 |
+
):
|
| 89 |
+
|
| 90 |
+
return (
|
| 91 |
+
self.selector.select(
|
| 92 |
+
task_type
|
| 93 |
+
)
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
# =================================================
|
| 98 |
+
# Check Availability
|
| 99 |
+
# =================================================
|
| 100 |
+
|
| 101 |
+
def is_available(
|
| 102 |
+
self,
|
| 103 |
+
task_type: str,
|
| 104 |
+
) -> bool:
|
| 105 |
+
|
| 106 |
+
return (
|
| 107 |
+
self.selector.is_available(
|
| 108 |
+
task_type
|
| 109 |
+
)
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
# =====================================================
|
| 114 |
+
# End of File
|
| 115 |
+
# =====================================================
|