class Controller(object):
    def __init__(self, conf):
        LOG.debug("[ServiceChain api] Creating Service Chain Manager controller with config:"
                                                "loadkulclouds.py %s", conf)
        self.conf = conf
        self.create_schema = ServiceChain_schema()
        self.name = 'ServiceChainMgr'

    @utils.verify_version
    def index(self, req, version):
        LOG.debug("[ServiceChain api] Show list of switches. Request: %s", req)
        result = core_api.index_servicech(self.conf, version)
        return result

    @utils.http_success_code(202)
    @utils.verify_version_argument
    def create(self, req, version, body):
        LOG.debug("[ServiceChain api] Got create request. Request: %s", req)
        #here we need to decide which device should be used
        params = self.create_schema.deserialize(body)
        LOG.debug("Headers: %s", req.headers)
        # We need to create LB object and return its id
        result = core_api.create_servicech(self.conf, version, params)
        return result

    @utils.http_success_code(204)
    @utils.verify_version
    def delete(self, req, version, dpid, name, ip):
        LOG.debug("[ServiceChain api] Got delete request. Request: %s", req)
        result = core_api.delete_servicech(self.conf, version, dpid, name, ip)
        return result

    @utils.verify_version
    def show(self, req, version, dpid, name, ip):
        LOG.debug("[ServiceChain api] Got info request. Request: %s", req)
        try:
            result = core_api.show_servicech(self.conf, version, dpid, name, ip)
        except Exception as e:
            raise webob.exc.HTTPBadRequest(content_type='application_json',body='There is no target switch')
        return result


    @utils.http_success_code(202)
    @utils.verify_version_argument
    def update(self, req, version, phone_num, body):
        LOG.debug("[ServiceChain api] Got update request. Request: %s", req)
        params = self.create_schema.deserialize(body)
        result = core_api.update_servicech(self.conf, version, phone_num, params)
        return result
    
    def get_servicechain_sync(self, req, version):
        LOG.debug("[ServiceChain api] Makdi synchronization request. Request: %s", req)
        result = core_api.sync_servicech(self.conf, version)
        return result    
 def __init__(self, conf):
     LOG.debug("[ServiceChain api] Creating Service Chain Manager controller with config:"
                                             "loadkulclouds.py %s", conf)
     self.conf = conf
     self.create_schema = ServiceChain_schema()
     self.name = 'ServiceChainMgr'