22import shutil
33from typing import Union , List
44from openbrokerapi import api
5- from openbrokerapi .api import ServiceBroker , ErrInstanceAlreadyExists , ErrAsyncRequired , ErrInstanceDoesNotExist
5+ from openbrokerapi .api import ServiceBroker
6+ from openbrokerapi .errors import ErrInstanceAlreadyExists , ErrAsyncRequired , \
7+ ErrBindingAlreadyExists , ErrBadRequest , ErrInstanceDoesNotExist
68from openbrokerapi .service_broker import *
79
8- from .meta import InstanceMeta , load_instance_meta
10+ from .meta import load_instance_meta
911from .utils import get_instance_path , get_chart_path , get_plan_path , \
1012 get_addon_path , get_addon_name
1113from .tasks import provision , bind , deprovision
@@ -37,7 +39,7 @@ def provision(self,
3739 shutil .copy (addon_plan_path , plan_path )
3840 provision .delay (instance_id , details )
3941 return ProvisionedServiceSpec (state = ProvisionState .IS_ASYNC )
40-
42+
4143
4244 def get_binding (self ,
4345 instance_id : str ,
@@ -53,16 +55,16 @@ def bind(self,
5355 async_allowed : bool ,
5456 ** kwargs
5557 ) -> Binding :
56-
57- if not (InstanceMeta . load ( instance_id ) and
58- InstanceMeta . load ( instance_id ) ['last_operation' ]['state' ] == 'Ready' ):
59- return Binding ( state = "status error: this instance is not ready" )
58+ instance_meta = load_instance_meta ( instance_id )
59+ if not (instance_meta and
60+ instance_meta ['last_operation' ]['state' ] == 'Ready' ):
61+ raise ErrBadRequest ( msg = "This instance %s is not ready" % instance_id )
6062 if not async_allowed :
6163 raise ErrAsyncRequired ()
6264 instance_path = get_instance_path (instance_id )
6365 if os .path .exists (f'{ instance_path } /bind.yaml' ):
64- return Binding ( state = BindState . IDENTICAL_ALREADY_EXISTS )
65- chart_path , plan_path = get_chart_path (instance_id ), get_plan_path (instance_id )
66+ raise ErrBindingAlreadyExists ( )
67+ chart_path , plan_path = get_chart_path (instance_id ), get_plan_path (instance_id )
6668 addon_name = get_addon_name (details .service_id )
6769 shutil .copy (f'{ plan_path } /bind.yaml' , f'{ chart_path } /{ addon_name } /templates' )
6870 bind .delay (instance_id , binding_id , details , async_allowed , ** kwargs )
@@ -100,7 +102,6 @@ def deprovision(self,
100102 deprovision .delay (instance_id , details )
101103 return DeprovisionServiceSpec (state = ProvisionState .IS_ASYNC )
102104
103-
104105 def last_operation (self ,
105106 instance_id : str ,
106107 operation_data : Optional [str ],
@@ -111,3 +112,22 @@ def last_operation(self,
111112 data ["last_operation" ]["state" ],
112113 data ["last_operation" ]["description" ]
113114 )
115+
116+
117+ def last_binding_operation (self ,
118+ instance_id : str ,
119+ binding_id : str ,
120+ operation_data : Optional [str ],
121+ ** kwargs
122+ ) -> LastOperation :
123+ """
124+ Further readings `CF Broker API#LastOperationForBindings <https://github.com/openservicebrokerapi/servicebroker/blob/v2.14/spec.md#polling-last-operation-for-service-bindings>`_
125+ Must be implemented if `Provision`, `Update`, or `Deprovision` are async.
126+
127+ :param instance_id: Instance id provided by the platform
128+ :param binding_id: Binding id provided by the platform
129+ :param operation_data: Operation data received from async operation
130+ :param kwargs: May contain additional information, improves compatibility with upstream versions
131+ :rtype: LastOperation
132+ """
133+ raise NotImplementedError ()
0 commit comments