2626import typing as tp
2727import uuid as sys_uuid
2828
29+ from gcl_sdk .clients .http import base as http_base
2930from oslo_config import cfg
3031from restalchemy .common import config_opts as ra_config_opts
3132from restalchemy .dm import filters as dm_filters
4546GCTL_CFG_DIR = f"/home/{ USER } /.exordos"
4647SPEC_PATH = "/mnt/cdrom/spec.json"
4748MANIFEST_PATH = "/mnt/cdrom/core.yaml"
49+ MANIFEST_COLLECTION = "/v1/em/manifests/"
4850ECOSYSTEM_REALM_MANIFEST_PATH = "/mnt/cdrom/ecosystem_realm.yaml"
4951MAIN_SUBNET_UUID = sys_uuid .UUID ("c910a7e1-61ae-4d56-bdd6-a59faa3cbda3" )
5052
6769 ),
6870 cfg .StrOpt (
6971 "core_endpoint" ,
70- default = "http://localhost:11010 " ,
72+ default = "http://localhost/api/core " ,
7173 help = "Core endpoint" ,
7274 ),
7375 cfg .StrOpt (
8385 default = None ,
8486 help = "Global salt for IAM" ,
8587 ),
86- cfg .StrOpt (
87- "client_secret" ,
88- default = "GenesisCoreSecret" ,
89- help = "Client secret for IAM" ,
90- ),
9188 cfg .StrOpt (
9289 "hs256_jwks_encryption_key" ,
9390 default = c .DEFAULT_HS256_JWKS_ENCRYPTION_KEY ,
@@ -227,7 +224,7 @@ def _apply_startup_db(spec: dict[str, tp.Any]) -> None:
227224 LOG .info ("Machine pool %s already exists, skipping" , pool .uuid )
228225
229226
230- def _ensure_gctl_config (spec : dict [str , tp .Any ]):
227+ def _ensure_exordos_config (spec : dict [str , tp .Any ]):
231228 """Ensure gctl configuration file exists."""
232229 if "admin_password" not in spec :
233230 raise RuntimeError ("No admin password found in spec" )
@@ -269,6 +266,7 @@ def _ensure_gctl_config(spec: dict[str, tp.Any]):
269266def _install_element_manifest (
270267 element_name : str ,
271268 manifest_path : str ,
269+ spec : dict [str , tp .Any ],
272270):
273271 """Idempotent element manifest installation."""
274272 element = em_models .Element .objects .get_one_or_none (
@@ -283,10 +281,34 @@ def _install_element_manifest(
283281 LOG .info ("No manifest file found at %s" , manifest_path )
284282 return
285283
286- os .system (
287- f"exordos --config { GCTL_CFG_DIR } /exordosctl.yaml ee install { manifest_path } "
284+ with open (manifest_path ) as f :
285+ manifest_data = yaml .safe_load (f )
286+
287+ auth = http_base .CoreIamAuthenticator (
288+ base_url = "http://localhost:11010" ,
289+ username = CONF .core_user ,
290+ password = spec ["admin_password" ],
291+ client_id = spec ["iam" ]["default_client_id" ],
292+ client_secret = spec ["iam" ]["default_client_secret" ],
293+ client_uuid = sys_uuid .UUID (spec ["iam" ]["default_client_uuid" ]),
294+ )
295+
296+ client = http_base .CollectionBaseClient (
297+ base_url = "http://localhost:11010" , auth = auth
288298 )
289299
300+ manifest_data = client .create (MANIFEST_COLLECTION , manifest_data )
301+ try :
302+ client .do_action (
303+ MANIFEST_COLLECTION , "install" , manifest_data ["uuid" ], invoke = True
304+ )
305+ except Exception :
306+ LOG .exception (
307+ "Failed to install manifest %s, deleting..." , manifest_data ["uuid" ]
308+ )
309+ client .delete (MANIFEST_COLLECTION , manifest_data ["uuid" ])
310+ raise
311+
290312
291313def _set_defaults_vs (spec : dict [str , tp .Any ]):
292314 """Set default values, profiles, etc."""
@@ -297,6 +319,8 @@ def _set_defaults_vs(spec: dict[str, tp.Any]):
297319 "func" : bootstrap_defaults .set_core_ip_var ,
298320 "args" : [spec ["stand" ]["bootstraps" ][0 ]["ports" ][0 ]["ip" ]],
299321 },
322+ {"func" : bootstrap_defaults .set_core_root_disk_size_var , "args" : [spec ]},
323+ {"func" : bootstrap_defaults .set_core_data_disk_size_var , "args" : [spec ]},
300324 {"func" : bootstrap_defaults .set_ecosystem_endpoint_var , "args" : [spec ]},
301325 {"func" : bootstrap_defaults .set_disable_telemetry_var , "args" : [spec ]},
302326 {"func" : bootstrap_defaults .set_realm_uuid_var , "args" : [spec ]},
@@ -307,6 +331,9 @@ def _set_defaults_vs(spec: dict[str, tp.Any]):
307331 "func" : bootstrap_defaults .set_hs256_jwks_encryption_key_var ,
308332 "args" : [CONF ["iam" ].hs256_jwks_encryption_key ],
309333 },
334+ {"func" : bootstrap_defaults .set_iam_default_client_uuid_var , "args" : [spec ]},
335+ {"func" : bootstrap_defaults .set_iam_default_client_id_var , "args" : [spec ]},
336+ {"func" : bootstrap_defaults .set_iam_default_client_secret_var , "args" : [spec ]},
310337 ]
311338
312339 # Perform all tasks to set default values until timeout
@@ -354,13 +381,16 @@ def main() -> None:
354381 LOG .info ("GC Bootstrap script" )
355382 bootstrap_defaults .apply_startup_db (spec )
356383 bootstrap_defaults .init_secrets (
357- spec , CONF ["iam" ].global_salt , CONF ["iam" ].client_secret
384+ spec ,
385+ CONF ["iam" ].global_salt ,
386+ spec ["iam" ]["default_client_id" ],
387+ spec ["iam" ]["default_client_secret" ],
358388 )
359389 bootstrap_defaults .add_core_set (spec )
360- _ensure_gctl_config (spec )
361- _install_element_manifest ("core" , CONF .manifest_path )
390+ _ensure_exordos_config (spec )
391+ _install_element_manifest ("core" , CONF .manifest_path , spec )
362392 _install_element_manifest (
363- "ecosystem_realm" , CONF .ecosystem_realm_manifest_path
393+ "ecosystem_realm" , CONF .ecosystem_realm_manifest_path , spec
364394 )
365395 _set_defaults_vs (spec )
366396 return
0 commit comments