22import shutil
33from typing import Union , List
44from openbrokerapi import api
5- from openbrokerapi .api import ServiceBroker , ErrInstanceAlreadyExists , ErrAsyncRequired
5+ from openbrokerapi .api import ServiceBroker , ErrInstanceAlreadyExists , ErrAsyncRequired , ErrInstanceDoesNotExist
66from openbrokerapi .service_broker import *
77
8- from .meta import InstanceMeta
8+ from .meta import InstanceMeta , load_instance_meta
99from .utils import get_instance_path , get_chart_path , get_plan_path , \
1010 get_addon_path , get_addon_name
11- from .tasks import provision , bind
11+ from .tasks import provision , bind , deprovision
1212from helmbroker .loader import read_addons_file
1313
1414
@@ -35,7 +35,7 @@ def provision(self,
3535 addon_chart_path , addon_plan_path = get_addon_path (details .service_id , details .plan_id )
3636 shutil .copy (addon_chart_path , chart_path )
3737 shutil .copy (addon_plan_path , plan_path )
38- provision .delay (instance_id , details , async_allowed , ** kwargs )
38+ provision .delay (instance_id , details )
3939 return ProvisionedServiceSpec (state = ProvisionState .IS_ASYNC )
4040
4141
@@ -91,23 +91,23 @@ def deprovision(self,
9191 details : DeprovisionDetails ,
9292 async_allowed : bool ,
9393 ** kwargs ) -> DeprovisionServiceSpec :
94- # Delete service instance
95- # ...
94+ instance_path = get_instance_path (instance_id )
95+ if not os .path .exists (instance_path ):
96+ raise ErrInstanceDoesNotExist ("Instance %s not exists" % instance_id )
97+ if not async_allowed :
98+ raise ErrAsyncRequired ()
9699
97- return DeprovisionServiceSpec (is_async = False )
100+ deprovision .delay (instance_id , details )
101+ return DeprovisionServiceSpec (state = ProvisionState .IS_ASYNC )
98102
99103
100104 def last_operation (self ,
101105 instance_id : str ,
102106 operation_data : Optional [str ],
103107 ** kwargs
104108 ) -> LastOperation :
105- """
106- Further readings `CF Broker API#LastOperation <https://docs.cloudfoundry.org/services/api.html#polling>`_
107-
108- :param instance_id: Instance id provided by the platform
109- :param operation_data: Operation data received from async operation
110- :param kwargs: May contain additional information, improves compatibility with upstream versions
111- :rtype: LastOperation
112- """
113- raise NotImplementedError ()
109+ data = load_instance_meta ()
110+ return LastOperation (
111+ data ["last_operation" ]["state" ],
112+ data ["last_operation" ]["description" ]
113+ )
0 commit comments