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
9+ from .meta import InstanceMeta
10+ from .utils import get_instance_path , get_chart_path , get_plan_path , \
11+ get_addon_path , get_addon_name
12+ from .tasks import provision , bind
1113from helmbroker .loader import read_addons_file
1214
1315
@@ -17,26 +19,7 @@ def catalog(self) -> Union[Service, List[Service]]:
1719 services = read_addons_file ()
1820 return [Service (
1921 ** addons
20- ) for _ ,addons in services .items ()]
21- # return Service(
22- # id='server',
23- # name='server',
24- # description='service description',
25- # bindable=True,
26- # plans=[
27- # ServicePlan(
28- # id='server-1:1-1',
29- # name='1-1',
30- # description='plan description',
31- # ),
32- # ServicePlan(
33- # id='server-2:2-2',
34- # name='2-2',
35- # description='plan description',
36- # )
37- # ],
38- # plan_updateable=True,
39- # )
22+ ) for _ , addons in services .items ()]
4023
4124 def provision (self ,
4225 instance_id : str ,
@@ -54,9 +37,9 @@ def provision(self,
5437 shutil .copy (addon_chart_path , chart_path )
5538 shutil .copy (addon_plan_path , plan_path )
5639 if async_allowed :
57- provision .delay (instance_id , details . async_allowed , ** kwargs )
40+ provision .delay (instance_id , details , async_allowed , ** kwargs )
5841 return ProvisionedServiceSpec (state = ProvisionState .IS_ASYNC )
59- return provision (instance_id , details . async_allowed , ** kwargs )
42+ return provision (instance_id , details , async_allowed , ** kwargs )
6043
6144 def get_binding (self ,
6245 instance_id : str ,
@@ -72,7 +55,21 @@ def bind(self,
7255 async_allowed : bool ,
7356 ** kwargs
7457 ) -> Binding :
75- return Binding (credentials = {"url" : "postgres://1.1.1.1" , "passwd" : "123" })
58+
59+ if not (InstanceMeta .load (instance_id ) and
60+ InstanceMeta .load (instance_id )['last_operation' ]['state' ] == 'Ready' ):
61+ return Binding (state = "status error: this instance is not ready" )
62+
63+ instance_path = get_instance_path (instance_id )
64+ if os .path .exists (f'{ instance_path } /bind.yaml' ):
65+ return Binding (state = BindState .IDENTICAL_ALREADY_EXISTS )
66+ chart_path , plan_path = get_chart_path (instance_id ), get_plan_path (instance_id )
67+ addon_name = get_addon_name (details .service_id )
68+ shutil .copy (f'{ plan_path } /bind.yaml' , f'{ chart_path } /{ addon_name } /templates' )
69+ if async_allowed :
70+ bind .delay (instance_id , binding_id , details , async_allowed , ** kwargs )
71+ return Binding (state = BindState .IS_ASYNC )
72+ return bind (instance_id , binding_id , details , async_allowed , ** kwargs )
7673
7774 def unbind (self ,
7875 instance_id : str ,
0 commit comments