Example #1
0
 def setUp(self):
     self.random_rpc = RpcLayer(host_url=u"amqp://127.0.0.1")
     self.adapter = VNFManagerAdapter()
     self.adapter.connect(url=u"amqp://127.0.0.1")
     self.file = open("testsrc/linux.vnfd", "r")
     self.json_dict = json.load(self.file)
     self.descriptors = list()
     for vnfc in self.json_dict["vnf"]["VNFC"]:
         self.descriptors.append({
             key: value
             for key, value in vnfc.items()
             if key in ["events", "auth", "name"]
         })
     print self.descriptors
Example #2
0
class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.random_rpc = RpcLayer(host_url=u"amqp://127.0.0.1")
        self.adapter = VNFManagerAdapter()
        self.adapter.connect(url=u"amqp://127.0.0.1")
        self.file = open("testsrc/linux.vnfd", "r")
        self.json_dict = json.load(self.file)
        self.descriptors = list()
        for vnfc in self.json_dict["vnf"]["VNFC"]:
            self.descriptors.append({
                key: value
                for key, value in vnfc.items()
                if key in ["events", "auth", "name"]
            })
        print self.descriptors

    def test_something(self):
        try:
            time.sleep(1)
            d = self.random_rpc.call("VNFManagerAdapter.create_vnf_manager",
                                     1337, self.descriptors)
            while not d.called:
                pass
            time.sleep(1)
            for vnc in self.descriptors:
                d = self.random_rpc.call("1337.new_vnfc_instance",
                                         ip_address=u"127.0.0.1",
                                         vnfc_id=vnc["name"])
            while not d.called:
                pass
            self.assertEqual(d.result,
                             "Hello, Is there anybody out there ???\n")
            try:
                i = raw_input()
            except KeyboardInterrupt:
                pass
        except:
            try:
                i = raw_input()
            except KeyboardInterrupt:
                pass

    def tearDown(self):
        print "Begin Down done"
        self.adapter.dispose()
        self.random_rpc.dispose()
        print "Tear Down done"
 def setUp(self):
     self.random_rpc = RpcLayer(host_url=u"amqp://127.0.0.1")
     self.adapter = VNFManagerAdapter()
     self.adapter.connect(url=u"amqp://127.0.0.1")
     self.file = open("testsrc/linux.vnfd","r")
     self.json_dict = json.load(self.file)
     self.descriptors = list()
     for vnfc in self.json_dict["vnf"]["VNFC"]:
         self.descriptors.append({key:value for key,value in vnfc.items() if key in ["events","auth","name"]})
     print self.descriptors
class MyTestCase(unittest.TestCase):

    def setUp(self):
        self.random_rpc = RpcLayer(host_url=u"amqp://127.0.0.1")
        self.adapter = VNFManagerAdapter()
        self.adapter.connect(url=u"amqp://127.0.0.1")
        self.file = open("testsrc/linux.vnfd","r")
        self.json_dict = json.load(self.file)
        self.descriptors = list()
        for vnfc in self.json_dict["vnf"]["VNFC"]:
            self.descriptors.append({key:value for key,value in vnfc.items() if key in ["events","auth","name"]})
        print self.descriptors

    def test_something(self):
        try:
            time.sleep(1)
            d = self.random_rpc.call("VNFManagerAdapter.create_vnf_manager", 1337, self.descriptors)
            while not d.called:
                pass
            time.sleep(1)
            for vnc in self.descriptors:
                d = self.random_rpc.call("1337.new_vnfc_instance", ip_address=u"127.0.0.1", vnfc_id=vnc["name"])
            while not d.called:
                pass
            self.assertEqual(d.result,"Hello, Is there anybody out there ???\n")
            try:
                i = raw_input()
            except KeyboardInterrupt:
                pass
        except:
            try:
                i = raw_input()
            except KeyboardInterrupt:
                pass



    def tearDown(self):
        print "Begin Down done"
        self.adapter.dispose()
        self.random_rpc.dispose()
        print "Tear Down done"
class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.random_rpc = RpcLayer(host_url=u"amqp://127.0.0.1")
        self.adapter = VNFManagerAdapter()
        self.adapter.connect(url=u"amqp://127.0.0.1")

    def test_something(self):
        time.sleep(1)

        d = self.random_rpc.call("storage.get_vnf", options=[], filters={})

        while not d.called:
            pass
        code, list = d.result

        if code == 200 and len(list) > 0:
            vnf_id = list[0]["uuid"]

            d = self.random_rpc.call("VNFManagerAdapter.create_vnf_manager",
                                     vnf_id)
            while not d.called:
                pass
            time.sleep(1)

            d = self.random_rpc.call("storage.get_vm",
                                     options=[],
                                     filters={"vnf_id": vnf_id})
            while not d.called:
                pass
            code, descriptors = d.result

            for vnc in descriptors:
                d = self.random_rpc.call(
                    "{0}.new_vnfc_instance".format(vnf_id), vnc["name"],
                    u"127.0.0.1", {
                        "username": "******",
                        "password": ""
                    })
                while not d.called:
                    pass
                self.assertEqual(d.result, [[u"Starting\n"]])

    def tearDown(self):
        print "Begin Down done"
        self.adapter.dispose()
        self.random_rpc.dispose()
        print "Tear Down done"
class MyTestCase(unittest.TestCase):

    def setUp(self):
        self.random_rpc = RpcLayer(host_url=u"amqp://127.0.0.1")
        self.adapter = VNFManagerAdapter()
        self.adapter.connect(url=u"amqp://127.0.0.1")


    def test_something(self):
            time.sleep(1)

            d = self.random_rpc.call("storage.get_vnf", options=[],filters={})

            while not d.called:
                pass
            code, list = d.result



            if code == 200 and len(list)>0:
                vnf_id = list[0]["uuid"]

                d = self.random_rpc.call("VNFManagerAdapter.create_vnf_manager", vnf_id)
                while not d.called:
                    pass
                time.sleep(1)

                d = self.random_rpc.call("storage.get_vm", options=[],filters={"vnf_id": vnf_id})
                while not d.called:
                    pass
                code, descriptors = d.result

                for vnc in descriptors:
                    d = self.random_rpc.call("{0}.new_vnfc_instance".format(vnf_id), vnc["name"], u"127.0.0.1",
                                             {"username" : "thgoette" , "password" : ""} )
                    while not d.called:
                        pass
                    self.assertEqual(d.result,[[u"Starting\n"]])


    def tearDown(self):
        print "Begin Down done"
        self.adapter.dispose()
        self.random_rpc.dispose()
        print "Tear Down done"
 def setUp(self):
     self.random_rpc = RpcLayer(host_url=u"amqp://127.0.0.1")
     self.adapter = VNFManagerAdapter()
     self.adapter.connect(url=u"amqp://127.0.0.1")
 def setUp(self):
     self.random_rpc = RpcLayer(host_url=u"amqp://127.0.0.1")
     self.adapter = VNFManagerAdapter()
     self.adapter.connect(url=u"amqp://127.0.0.1")
Example #9
0
 def __init__(self, url, component_registry, contract_registry, logger):
     self.logger = logger
     self.component_registry = component_registry
     self.contract_registry = contract_registry
     self._rpc = None
     self.rpc = RpcLayer(url, logger=logger)
Example #10
0
class BunnyConnector(object):
    def __init__(self, url, component_registry, contract_registry, logger):
        self.logger = logger
        self.component_registry = component_registry
        self.contract_registry = contract_registry
        self._rpc = None
        self.rpc = RpcLayer(url, logger=logger)

    def version(self):
        return {'version': __version__, 'date': version_date}

    def component_add(self, name, tenant):
        component = dict()
        component['name'] = name
        if not len(tenant):
            self.logger.exception('No component name specified')
            defer.returnValue({
                'result': False,
                'error': {
                    'message': 'No component name specified'
                }
            })
        self.logger.debug("Add component %s" % name)
        # Check tenant
        if not len(tenant):
            self.logger.exception(
                "Could not add component '%s', because no tenant missing" %
                name)
            defer.returnValue({
                'result': False,
                'error': {
                    'message': 'No tenant specified'
                }
            })

        # Get component version
        self.logger.debug("Get version of component %s" % name)
        try:
            component['version'] = (yield self.rpc.call(
                '%s.version' % component['name']))['version']
        except Exception as err:
            self.logger.exception("Could not get version of component '%s'" %
                                  name)
            defer.returnValue({
                'result': False,
                'error': {
                    'message': "Could not get version of component '%s'" % name
                }
            })

        # Get component functions
        self.logger.debug("Get functions of component %s" % name)
        try:
            component['functions'] = (yield self.rpc.call(
                '%s.functions' % component['name']))['functions']
        except Exception as err:
            self.logger.exception("Could not get functions of component '%s'" %
                                  name)
            defer.returnValue({
                'result': False,
                'error': {
                    'message':
                    "Could not get functions of component '%s'" % name
                }
            })
        # Get component contracts and add them if there are unknown ones
        self.logger.debug("Get contracts of component %s" % name)
        try:
            component['contracts'] = (yield self.rpc.call(
                '%s.contracts' % component['name']))['contracts']
        except Exception as err:
            self.logger.exception("Could not get contracts of component '%s'" %
                                  name)
            defer.returnValue({
                'result': False,
                'error': {
                    'message':
                    "Could not get contracts of component '%s'" % name
                }
            })

        self.logger.debug("Add component '%s' to the registry")
        # Add the component to the registry
        self.component_registry.add(component, tenant)
        defer.returnValue({'result': True})

    def component_remove(self, component_id):
        # Remove contracts that are only supported by this component
        self.component_registry.remove(component_id)

    def component_list(self):
        components = self.component_registry.get_list()
        result = []
        for component in components:
            result.append({'id': component.id, 'name': component.name})
        return {'result': result}

    def component_list_by_contract(self, contract_name):
        self.logger.debug("Retrieving functions for contract '%s'" %
                          contract_name)
        contract = self.contract_registry[contract_name]
        self.logger.debug('Contract name: %s' % contract.name)
        result = []
        if contract is not None:
            component_name = None
            component = None
            self.logger.debug('Contract functions: %r %d' %
                              (contract.functions, len(contract.functions)))
            for item in contract.functions:
                if component_name != item.component.name:
                    if component is not None:
                        result.append(component)
                    component_name = item.component.name
                    self.logger.debug('  Component name: %s' %
                                      item.component.name)
                    component = dict()
                    component['name'] = component_name
                    component['functions'] = []
                function = dict()
                function['name'] = item.name
                self.logger.debug('    Function name: %s' % item.name)
                component['functions'].append(function)
            if component is not None:
                result.append(component)

            # result = self.component_registry.get_functions_by_contract(contract)

        return {'result': result}

    def component_info(self, key):
        component = self.component_registry[key]

        result = {
            'id': component.id,
            'name': component.name,
            'functions': [],
        }
        for function in component.functions:
            result['functions'].append({'name': function.name})
        return {'result': result}

    def contract_list(self):
        contracts = self.contract_registry.get_list()
        result = []
        for contract in contracts:
            item = {'name': contract.name, 'input': [], 'output': []}
            for port in contract.input_ports:
                item['input'].append({
                    'name': port.name,
                    'type': port.data_type
                })
            for port in contract.output_ports:
                item['output'].append({
                    'name': port.name,
                    'type': port.data_type
                })
            result.append(item)
        return {'result': result}

    def call(self,
             function,
             component=None,
             callback=None,
             function_args=[],
             function_kwargs={},
             callback_args=[],
             callback_kwargs={}):
        rpc_name = function
        if component is not None:
            rpc_name = component + "." + rpc_name
        else:
            rpc_name = "*." + rpc_name

        d = self.rpc.call(rpc_name, *function_args, **function_kwargs)
        if callback is not None:
            d.addCallback(callback, *callback_args, **callback_kwargs)

    def __del__(self):
        self.dispose()

    def dispose(self):
        self.logger.debug('Closing rpc connection')
        if self.rpc is not None:
            self.deregister_rpc()
            self.rpc.dispose()
            self._rpc = None
Example #11
0
class BunnyConnector(object):
    def __init__(self, url, logger):
        self.logger = logger
        self._rpc = None
        self.rpc = RpcLayer(url, logger=logger)

    @property
    def rpc(self):
        return self._rpc

    @rpc.setter
    def rpc(self, value):
        if self._rpc is not None:
            self.deregister_rpc()
        self._rpc = value
        if self._rpc is not None:
            self.register_rpc()

    def deregister_rpc(self):
        # deregister endpoints here
        self.logger.debug('Deregistering endpoints...')
        self.rpc.deregister('decaf_oscar.version')
        self.rpc.deregister('decaf_oscar.functions')
        self.rpc.deregister('decaf_oscar.contracts')
        self.rpc.deregister('decaf_oscar.scenario_start')
        self.logger.debug('Endpoints deregistered')

    def register_rpc(self):
        # register endpoints here
        self.logger.debug('Registering endpoints...')
        self.rpc.register('decaf_oscar.version', self.version)
        self.rpc.register('decaf_oscar.functions', self.functions)
        self.rpc.register('decaf_oscar.contracts', self.contracts)
        self.rpc.register('decaf_oscar.scenario_start', self.scenario_start)
        self.logger.debug('Endpoints registered')

    @rpc.setter
    def rpc(self, value):
        if self._rpc is not None:
            self.deregister_rpc()
        self._rpc = value
        if self._rpc is not None:
            self.register_rpc()

    def version(self):
        return {'version': __version__,
                'date': version_date}

    def functions(self):
        """
        Gets a list of endpoints provided by this component. This function implements the core.functions contract and
        is required by the component manager.

        :return:
        """
        return {'functions': [
            {
                'name': 'version',
                'contract': 'core.version'
            },
            {
                'name': 'functions',
                'contract': 'core.functions'
            },
            {
                'name': 'contracts',
                'contract': 'core.contracts'
            },
            {
                'name': 'scenario_start',
                'contract': 'oscar.deployment.scenario_start'
            }
        ]}

    def contracts(self):
        """
        Gets a list of contracts provided by this component. This function implements the core.contracts contract and
        is required by the component manager.

        :return:
        """
        return {'contracts': [
            {
                'name': 'core.version',
                'input': [],
                'output': [
                    {
                        'name': 'version',
                        'type': 'Version'
                    },
                    {
                        'name': 'date',
                        'type': 'DateTime'
                    },
                ]
            },
            {
                'name': 'core.functions',
                'input': [],
                'output': [
                    {
                        'name': 'functions',
                        'type': 'FunctionList'
                    }
                ]
            },
            {
                'name': 'core.contracts',
                'input': [],
                'output': [
                    {
                        'name': 'contracts',
                        'type': 'ContractList'
                    }
                ]
            },
            {
                'name': 'oscar.deployment.scenario_start',
                'input': [
                    {
                        'name': 'scenario_id',
                        'type': 'UUID'
                    },
                    {
                        'name': 'scenario_instance_name',
                        'type': 'String'
                    },
                    {
                        'name': 'datacenter_id',
                        'type': 'UUID'
                    },
                    {
                        'name': 'startvms',
                        'type': 'Boolean'
                    }
                ],
                'output': [
                    {
                        'name': 'scenario_instance_id',
                        'type': 'UUID'
                    }
                ]
            }
        ]}

    @defer.inlineCallbacks
    def scenario_start(self, scenario_id, scenario_instance_name, datacenter_id, startvms):
        callees = []
        try:
            callees = (yield self.rpc.call('decaf_componentmanager.component_list_by_contract',
                                           contract_name="deployment.scenario_start"))
            self.logger.debug("Callees dump %r"%callees)
        except Exception as err:
            self.logger.exception("Could not resolve contract 'deployment.scenario_start'")
            defer.returnValue(
                {'scenario_instance_id': None, 'error': {'message': "Could not resolve contract 'deployment.scenario_start'"}})

        self.logger.debug("Has found callees: %r %r" % (isinstance(callees, list), len(callees) > 0))
        if isinstance(callees['result'], list) and len(callees['result'])>0:
            try:
                component = callees['result'][0]['name']
                function = callees['result'][0]['functions'][0]['name']
                self.logger.exception("Try to call '%s.%s'" % (component, function))
                result = (yield self.rpc.call('%s.%s'% (component, function), scenario_id, scenario_instance_name, datacenter_id, startvms))
                defer.returnValue(result)
            except Exception as err:
                self.logger.exception("Could not start scenario")
                defer.returnValue(
                    {'scenario_instance_id': None, 'error': {'message': "Could not start scenario"}})

    @defer.inlineCallbacks
    def call_contract(self, contract, callback=None, function_args=[], function_kwargs={}, callback_args=[],
                      callback_kwargs={}):
        callees = (yield self.rpc.call('decaf_componentmanager.component_list_by_contract', contract=contract))
        if isinstance(callees, list) and len(callees) > 0:
            self.call(callees[0]['functions'][0]['name'], callees[0]['name'], callback, function_args, function_kwargs,
                      callback_args, callback_kwargs)

    def call(self, function, component=None, callback=None, function_args=[], function_kwargs={}, callback_args=[],
             callback_kwargs={}):
        rpc_name = function
        if component is not None:
            rpc_name = component + "." + rpc_name
        else:
            rpc_name = "*." + rpc_name

        d = self.rpc.call(rpc_name, *function_args, **function_kwargs)
        if callback is not None:
            d.addCallback(callback, *callback_args, **callback_kwargs)

    def __del__(self):
        self.dispose()

    def dispose(self):
        self.logger.debug('Closing rpc connection')
        if self.rpc is not None:
            self.deregister_rpc()
            self.rpc.dispose()
            self._rpc = None
Example #12
0
 def __init__(self, url, logger):
     self.logger = logger
     self._rpc = None
     self.rpc = RpcLayer(url, logger=logger)
Example #13
0
class BunnyConnector(object):
    def __init__(self, url, logger):
        self.logger = logger
        self._rpc = None
        self.rpc = RpcLayer(url, logger=logger)

    @property
    def rpc(self):
        return self._rpc

    @rpc.setter
    def rpc(self, value):
        if self._rpc is not None:
            self.deregister_rpc()
        self._rpc = value
        if self._rpc is not None:
            self.register_rpc()

    def deregister_rpc(self):
        # deregister endpoints here
        self.logger.debug('Deregistering endpoints...')
        self.rpc.deregister('decaf_oscar.version')
        self.rpc.deregister('decaf_oscar.functions')
        self.rpc.deregister('decaf_oscar.contracts')
        self.rpc.deregister('decaf_oscar.scenario_start')
        self.logger.debug('Endpoints deregistered')

    def register_rpc(self):
        # register endpoints here
        self.logger.debug('Registering endpoints...')
        self.rpc.register('decaf_oscar.version', self.version)
        self.rpc.register('decaf_oscar.functions', self.functions)
        self.rpc.register('decaf_oscar.contracts', self.contracts)
        self.rpc.register('decaf_oscar.scenario_start', self.scenario_start)
        self.logger.debug('Endpoints registered')

    @rpc.setter
    def rpc(self, value):
        if self._rpc is not None:
            self.deregister_rpc()
        self._rpc = value
        if self._rpc is not None:
            self.register_rpc()

    def version(self):
        return {'version': __version__, 'date': version_date}

    def functions(self):
        """
        Gets a list of endpoints provided by this component. This function implements the core.functions contract and
        is required by the component manager.

        :return:
        """
        return {
            'functions': [{
                'name': 'version',
                'contract': 'core.version'
            }, {
                'name': 'functions',
                'contract': 'core.functions'
            }, {
                'name': 'contracts',
                'contract': 'core.contracts'
            }, {
                'name': 'scenario_start',
                'contract': 'oscar.deployment.scenario_start'
            }]
        }

    def contracts(self):
        """
        Gets a list of contracts provided by this component. This function implements the core.contracts contract and
        is required by the component manager.

        :return:
        """
        return {
            'contracts': [{
                'name':
                'core.version',
                'input': [],
                'output': [
                    {
                        'name': 'version',
                        'type': 'Version'
                    },
                    {
                        'name': 'date',
                        'type': 'DateTime'
                    },
                ]
            }, {
                'name':
                'core.functions',
                'input': [],
                'output': [{
                    'name': 'functions',
                    'type': 'FunctionList'
                }]
            }, {
                'name':
                'core.contracts',
                'input': [],
                'output': [{
                    'name': 'contracts',
                    'type': 'ContractList'
                }]
            }, {
                'name':
                'oscar.deployment.scenario_start',
                'input': [{
                    'name': 'scenario_id',
                    'type': 'UUID'
                }, {
                    'name': 'scenario_instance_name',
                    'type': 'String'
                }, {
                    'name': 'datacenter_id',
                    'type': 'UUID'
                }, {
                    'name': 'startvms',
                    'type': 'Boolean'
                }],
                'output': [{
                    'name': 'scenario_instance_id',
                    'type': 'UUID'
                }]
            }]
        }

    @defer.inlineCallbacks
    def scenario_start(self, scenario_id, scenario_instance_name,
                       datacenter_id, startvms):
        callees = []
        try:
            callees = (yield self.rpc.call(
                'decaf_componentmanager.component_list_by_contract',
                contract_name="deployment.scenario_start"))
            self.logger.debug("Callees dump %r" % callees)
        except Exception as err:
            self.logger.exception(
                "Could not resolve contract 'deployment.scenario_start'")
            defer.returnValue({
                'scenario_instance_id': None,
                'error': {
                    'message':
                    "Could not resolve contract 'deployment.scenario_start'"
                }
            })

        self.logger.debug("Has found callees: %r %r" %
                          (isinstance(callees, list), len(callees) > 0))
        if isinstance(callees['result'], list) and len(callees['result']) > 0:
            try:
                component = callees['result'][0]['name']
                function = callees['result'][0]['functions'][0]['name']
                self.logger.exception("Try to call '%s.%s'" %
                                      (component, function))
                result = (yield
                          self.rpc.call('%s.%s' % (component, function),
                                        scenario_id, scenario_instance_name,
                                        datacenter_id, startvms))
                defer.returnValue(result)
            except Exception as err:
                self.logger.exception("Could not start scenario")
                defer.returnValue({
                    'scenario_instance_id': None,
                    'error': {
                        'message': "Could not start scenario"
                    }
                })

    @defer.inlineCallbacks
    def call_contract(self,
                      contract,
                      callback=None,
                      function_args=[],
                      function_kwargs={},
                      callback_args=[],
                      callback_kwargs={}):
        callees = (yield self.rpc.call(
            'decaf_componentmanager.component_list_by_contract',
            contract=contract))
        if isinstance(callees, list) and len(callees) > 0:
            self.call(callees[0]['functions'][0]['name'], callees[0]['name'],
                      callback, function_args, function_kwargs, callback_args,
                      callback_kwargs)

    def call(self,
             function,
             component=None,
             callback=None,
             function_args=[],
             function_kwargs={},
             callback_args=[],
             callback_kwargs={}):
        rpc_name = function
        if component is not None:
            rpc_name = component + "." + rpc_name
        else:
            rpc_name = "*." + rpc_name

        d = self.rpc.call(rpc_name, *function_args, **function_kwargs)
        if callback is not None:
            d.addCallback(callback, *callback_args, **callback_kwargs)

    def __del__(self):
        self.dispose()

    def dispose(self):
        self.logger.debug('Closing rpc connection')
        if self.rpc is not None:
            self.deregister_rpc()
            self.rpc.dispose()
            self._rpc = None
Example #14
0
 def __init__(self, url, logger):
     self.logger = logger
     self._rpc = None
     self.rpc = RpcLayer(url, logger=logger)
Example #15
0
 def __init__(self, url, component_registry, contract_registry, logger):
     self.logger = logger
     self.component_registry = component_registry
     self.contract_registry = contract_registry
     self._rpc = None
     self.rpc = RpcLayer(url, logger=logger)
Example #16
0
class BunnyConnector(object):

    def __init__(self, url, component_registry, contract_registry, logger):
        self.logger = logger
        self.component_registry = component_registry
        self.contract_registry = contract_registry
        self._rpc = None
        self.rpc = RpcLayer(url, logger=logger)

    def version(self):
        return {'version': __version__,
                'date': version_date}


    def component_add(self, name, tenant):
        component = dict()
        component['name'] = name
        if not len(tenant):
            self.logger.exception('No component name specified')
            defer.returnValue({'result': False, 'error': {'message': 'No component name specified'}})
        self.logger.debug("Add component %s" % name)
        # Check tenant
        if not len(tenant):
            self.logger.exception("Could not add component '%s', because no tenant missing" % name)
            defer.returnValue({'result': False, 'error': {'message': 'No tenant specified'}})

        # Get component version
        self.logger.debug("Get version of component %s" % name)
        try:
            component['version'] = (yield self.rpc.call('%s.version' % component['name']))['version']
        except Exception as err:
            self.logger.exception("Could not get version of component '%s'" % name)
            defer.returnValue({'result': False, 'error': {'message': "Could not get version of component '%s'" % name}})

        # Get component functions
        self.logger.debug("Get functions of component %s" % name)
        try:
            component['functions'] = (yield self.rpc.call('%s.functions' % component['name']))['functions']
        except Exception as err:
            self.logger.exception("Could not get functions of component '%s'" % name)
            defer.returnValue(
                {'result': False, 'error': {'message': "Could not get functions of component '%s'" % name}})
        # Get component contracts and add them if there are unknown ones
        self.logger.debug("Get contracts of component %s" % name)
        try:
            component['contracts'] = (yield self.rpc.call('%s.contracts' % component['name']))['contracts']
        except Exception as err:
            self.logger.exception("Could not get contracts of component '%s'" % name)
            defer.returnValue(
                {'result': False, 'error': {'message': "Could not get contracts of component '%s'" % name}})

        self.logger.debug("Add component '%s' to the registry")
        # Add the component to the registry
        self.component_registry.add(component, tenant)
        defer.returnValue({'result': True})

    def component_remove(self, component_id):
        # Remove contracts that are only supported by this component
        self.component_registry.remove(component_id)

    def component_list(self):
        components = self.component_registry.get_list()
        result = []
        for component in components:
            result.append({'id': component.id,
                           'name': component.name})
        return {'result': result}

    def component_list_by_contract(self, contract_name):
        self.logger.debug("Retrieving functions for contract '%s'" % contract_name)
        contract = self.contract_registry[contract_name]
        self.logger.debug('Contract name: %s' % contract.name)
        result = []
        if contract is not None:
            component_name = None
            component = None
            self.logger.debug('Contract functions: %r %d' % (contract.functions, len(contract.functions)))
            for item in contract.functions:
                if component_name != item.component.name:
                    if component is not None:
                        result.append(component)
                    component_name = item.component.name
                    self.logger.debug('  Component name: %s' % item.component.name)
                    component = dict()
                    component['name'] = component_name
                    component['functions'] = []
                function = dict()
                function['name'] = item.name
                self.logger.debug('    Function name: %s' % item.name)
                component['functions'].append(function)
            if component is not None:
                result.append(component)

            # result = self.component_registry.get_functions_by_contract(contract)

        return {'result': result}

    def component_info(self, key):
        component = self.component_registry[key]

        result = {'id': component.id,
                  'name': component.name,
                  'functions': [],
                  }
        for function in component.functions:
            result['functions'].append({'name': function.name})
        return {'result': result}

    def contract_list(self):
        contracts = self.contract_registry.get_list()
        result = []
        for contract in contracts:
            item = {'name': contract.name, 'input': [], 'output': []}
            for port in contract.input_ports:
                item['input'].append({'name': port.name, 'type': port.data_type})
            for port in contract.output_ports:
                item['output'].append({'name': port.name, 'type': port.data_type})
            result.append(item)
        return {'result': result}

    def call(self, function, component=None, callback=None, function_args=[], function_kwargs={}, callback_args=[],
             callback_kwargs={}):
        rpc_name = function
        if component is not None:
            rpc_name = component + "." + rpc_name
        else:
            rpc_name = "*." + rpc_name

        d = self.rpc.call(rpc_name, *function_args, **function_kwargs)
        if callback is not None:
            d.addCallback(callback, *callback_args, **callback_kwargs)

    def __del__(self):
        self.dispose()

    def dispose(self):
        self.logger.debug('Closing rpc connection')
        if self.rpc is not None:
            self.deregister_rpc()
            self.rpc.dispose()
            self._rpc = None