22import shutil
33from typing import Union , List
44from openbrokerapi import api
5- from openbrokerapi .api import ServiceBroker
6- from openbrokerapi .catalog import ServicePlan
5+ from openbrokerapi .api import ServiceBroker , ErrInstanceAlreadyExists , ErrAsyncRequired
76from openbrokerapi .service_broker import *
87
98from .meta import InstanceMeta
@@ -28,18 +27,17 @@ def provision(self,
2827 ** kwargs ) -> ProvisionedServiceSpec :
2928 instance_path = get_instance_path (instance_id )
3029 if os .path .exists (instance_path ):
31- return ProvisionedServiceSpec (
32- state = ProvisionState . IDENTICAL_ALREADY_EXISTS
33- )
30+ raise ErrInstanceAlreadyExists ( "Instance %s already exists" % instance_id )
31+ if not async_allowed :
32+ raise ErrAsyncRequired ( )
3433 os .makedirs (instance_path , exist_ok = True )
3534 chart_path , plan_path = get_chart_path (instance_id ), get_plan_path (instance_id )
3635 addon_chart_path , addon_plan_path = get_addon_path (details .service_id , details .plan_id )
3736 shutil .copy (addon_chart_path , chart_path )
3837 shutil .copy (addon_plan_path , plan_path )
39- if async_allowed :
40- provision .delay (instance_id , details , async_allowed , ** kwargs )
41- return ProvisionedServiceSpec (state = ProvisionState .IS_ASYNC )
42- return provision (instance_id , details , async_allowed , ** kwargs )
38+ provision .delay (instance_id , details , async_allowed , ** kwargs )
39+ return ProvisionedServiceSpec (state = ProvisionState .IS_ASYNC )
40+
4341
4442 def get_binding (self ,
4543 instance_id : str ,
@@ -59,17 +57,16 @@ def bind(self,
5957 if not (InstanceMeta .load (instance_id ) and
6058 InstanceMeta .load (instance_id )['last_operation' ]['state' ] == 'Ready' ):
6159 return Binding (state = "status error: this instance is not ready" )
62-
60+ if not async_allowed :
61+ raise ErrAsyncRequired ()
6362 instance_path = get_instance_path (instance_id )
6463 if os .path .exists (f'{ instance_path } /bind.yaml' ):
6564 return Binding (state = BindState .IDENTICAL_ALREADY_EXISTS )
6665 chart_path , plan_path = get_chart_path (instance_id ), get_plan_path (instance_id )
6766 addon_name = get_addon_name (details .service_id )
6867 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 )
68+ bind .delay (instance_id , binding_id , details , async_allowed , ** kwargs )
69+ return Binding (state = BindState .IS_ASYNC )
7370
7471 def unbind (self ,
7572 instance_id : str ,
0 commit comments