1+ import os
2+ import shutil
13from typing import Union , List
2-
3- import openbrokerapi
44from openbrokerapi import api
55from openbrokerapi .api import ServiceBroker
66from openbrokerapi .catalog import ServicePlan
77from openbrokerapi .service_broker import *
88
9+ from .utils import get_instance_path , get_chart_path , get_plan_path , get_addon_path
10+ from .tasks import provision
911
1012class HelmServiceBroker (ServiceBroker ):
13+
1114 def catalog (self ) -> Union [Service , List [Service ]]:
12- return Service (
15+ return [ Service (
1316 id = 'server' ,
1417 name = 'server' ,
1518 description = 'service description' ,
@@ -27,16 +30,27 @@ def catalog(self) -> Union[Service, List[Service]]:
2730 )
2831 ],
2932 plan_updateable = True ,
30- )
33+ )]
3134
3235 def provision (self ,
3336 instance_id : str ,
3437 details : ProvisionDetails ,
3538 async_allowed : bool ,
3639 ** kwargs ) -> ProvisionedServiceSpec :
37- # Create service instance
38- # ...
39- return ProvisionedServiceSpec ()
40+ instance_path = get_instance_path (instance_id )
41+ if os .path .exists (instance_path ):
42+ return ProvisionedServiceSpec (
43+ state = ProvisionState .IDENTICAL_ALREADY_EXISTS
44+ )
45+ os .makedirs (instance_path , exist_ok = True )
46+ chart_path , plan_path = get_chart_path (instance_id ), get_plan_path (instance_id )
47+ addon_chart_path , addon_plan_path = get_addon_path (details .service_id , details .plan_id )
48+ shutil .copy (addon_chart_path , chart_path )
49+ shutil .copy (addon_plan_path , plan_path )
50+ if async_allowed :
51+ provision .delay (instance_id , details . async_allowed , ** kwargs )
52+ return ProvisionedServiceSpec (state = ProvisionState .IS_ASYNC )
53+ return provision (instance_id , details . async_allowed , ** kwargs )
4054
4155 def get_binding (self ,
4256 instance_id : str ,
0 commit comments