feat(cloud): add edge host enrollment
This commit is contained in:
@@ -8,10 +8,12 @@ from cloud.internal_api.models import AssignmentModel
|
||||
from device.manager import DeviceManager
|
||||
from driver.registry import build_driver_factory
|
||||
from host_agent.assignment import AssignmentExecutor
|
||||
from host_agent.client import HostAgentClient
|
||||
from host_agent.client import HostAgentClient, HostAgentEnrollmentClient
|
||||
from host_agent.config import HostAgentConfig, load_host_agent_config
|
||||
from host_agent.enrollment import resolve_host_identity
|
||||
from host_agent.execution import create_execution_factories
|
||||
from host_agent.heartbeat import HeartbeatSynchronizer
|
||||
from host_agent.identity import HostIdentityStore
|
||||
from host_agent.lease import ActiveAssignmentRunner
|
||||
from host_agent.processor import AssignmentProcessingResult, AssignmentProcessor
|
||||
from storage.device_config import DeviceConfigStore
|
||||
@@ -97,9 +99,29 @@ def create_application(
|
||||
config: HostAgentConfig | None = None,
|
||||
manager: DeviceManager | None = None,
|
||||
device_config_store: DeviceConfigStore | None = None,
|
||||
identity_store: HostIdentityStore | None = None,
|
||||
enrollment_client: HostAgentEnrollmentClient | None = None,
|
||||
) -> HostAgentApplication:
|
||||
resolved_config = config or load_host_agent_config()
|
||||
resolved_manager = manager or _configured_device_manager(device_config_store)
|
||||
startup_config = config or load_host_agent_config()
|
||||
config_store = device_config_store or DeviceConfigStore()
|
||||
owned_enrollment_client = enrollment_client is None
|
||||
bootstrap_client = enrollment_client or HostAgentEnrollmentClient(startup_config)
|
||||
try:
|
||||
resolved_config = resolve_host_identity(
|
||||
startup_config,
|
||||
identity_store=identity_store
|
||||
or HostIdentityStore(startup_config.identity_path),
|
||||
client=bootstrap_client,
|
||||
)
|
||||
bootstrap_client.config = resolved_config
|
||||
resolved_manager = manager or _configured_device_manager(
|
||||
config_store,
|
||||
config=resolved_config,
|
||||
enrollment_client=bootstrap_client,
|
||||
)
|
||||
finally:
|
||||
if owned_enrollment_client:
|
||||
bootstrap_client.close()
|
||||
client = HostAgentClient(resolved_config)
|
||||
heartbeat = HeartbeatSynchronizer(resolved_manager, client, resolved_config)
|
||||
executor = AssignmentExecutor(create_execution_factories(resolved_manager))
|
||||
@@ -112,13 +134,25 @@ def create_application(
|
||||
|
||||
|
||||
def _configured_device_manager(
|
||||
config_store: DeviceConfigStore | None,
|
||||
config_store: DeviceConfigStore,
|
||||
*,
|
||||
config: HostAgentConfig,
|
||||
enrollment_client: HostAgentEnrollmentClient,
|
||||
) -> DeviceManager:
|
||||
manager = DeviceManager()
|
||||
store = config_store or DeviceConfigStore()
|
||||
for device in store.list():
|
||||
for device in config_store.list():
|
||||
runtime_device_id = device["device_id"]
|
||||
if config.enrollment_managed:
|
||||
enrollment = enrollment_client.enroll_device(
|
||||
local_device_id=device["device_id"],
|
||||
driver_type=device["driver_type"],
|
||||
name=device["name"],
|
||||
capability_tags=[],
|
||||
)
|
||||
runtime_device_id = enrollment.device_id
|
||||
config_store.set_cloud_device_id(device["device_id"], runtime_device_id)
|
||||
manager.register_device(
|
||||
device["device_id"],
|
||||
runtime_device_id,
|
||||
build_driver_factory(
|
||||
device["driver_type"],
|
||||
device["connection_info"],
|
||||
|
||||
Reference in New Issue
Block a user