Ejemplo n.º 1
0
class BunnyConnector(object):
    def __init__(self, url, logger):
        self.logger = logger
        self.logger.debug('Creating BunnyConnector...')
        self._rpc = None
        self.rpc = RpcLayer(url, logger=logger)
        self.logger.debug('Created BunnyConnector')

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

    @rpc.setter
    def rpc(self, value):
        self._rpc = value

    def call(self, name, function, args, kwargs):
        """
        Call a remote function.

        :param name: Name of the component, that provides the function.
        :param function: The name of the function.
        :param args: An array of arguments.
        :return: The response received from the RPC
        """
        self.logger.debug("Calling %s.%s" % (name, function))
        try:
            ret = self.rpc.callSync(600, '%s.%s' % (name, function), *args,
                                    **kwargs)
            return ret
        except RPCError as e:
            self.logger.error(
                "Could not call function '%s' on component '%s'. Error: %s" %
                (function, name, e.getMessage))
        except:
            e = sys.exc_info()[0]
            self.logger.error(
                "Could not call function '%s' on component '%s'. Error: %s" %
                (function, name, e))

    def __del__(self):
        if self.rpc is not None:
            self.rpc.dispose()
            self.rpc = None
Ejemplo n.º 2
0
class BunnyConnector(object):
    def __init__(self, url, logger):
        self.logger = logger
        self.logger.debug('Creating BunnyConnector...')
        self._rpc = None
        self.rpc = RpcLayer(url, logger=logger)
        self.logger.debug('Created BunnyConnector')

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

    @rpc.setter
    def rpc(self, value):
        self._rpc = value

    def call(self, name, function, args, kwargs):
        """
        Call a remote function.

        :param name: Name of the component, that provides the function.
        :param function: The name of the function.
        :param args: An array of arguments.
        :return: The response received from the RPC
        """
        self.logger.debug("Calling %s.%s" % (name, function))
        try:
            ret = self.rpc.callSync(600, '%s.%s' % (name, function), *args, **kwargs)
            return ret
        except RPCError as e:
            self.logger.error("Could not call function '%s' on component '%s'. Error: %s" % (function, name, e.getMessage))
        except:
            e = sys.exc_info()[0]
            self.logger.error("Could not call function '%s' on component '%s'. Error: %s" % (function, name, e))

    def __del__(self):
        if self.rpc is not None:
            self.rpc.dispose()
            self.rpc = None
Ejemplo n.º 3
0
class RPCTester(object):

    def __init__(self):
        self.rpc = RpcLayer(u'amqp://fg-cn-sandman1.cs.upb.de:5672', logger=None)

    def test_deploy(self, deploy_graph):
        result = self.rpc.callSync(60, "decaf_masta.deploy_scenario", deploy_graph)
        print(result)
        print(result["graph"]["nodes"][0]["metadata"]["keypair"]["private_key"].replace('\\n', '\n'))

    def test_extend(self, add_graph):
        result = self.rpc.callSync(60, "decaf_masta.extend_scenario", add_graph)
        print(result)

    def test_shrink(self, shrink_graph):
        result = self.rpc.callSync(60, "decaf_masta.shrink_scenario", shrink_graph)
        print(result)

    def test_destroy(self, scenario_instance_id):
        result = self.rpc.callSync(60, "decaf_masta.destroy_scenario", scenario_instance_id)
        print(result)

    def destroy_all_scenarios(self):
        result = self.rpc.callSync(60, "decaf_masta.destroy_all_scenarios")
        print(result)

    def delete_all_monitoring_alarms(self):
        result = self.rpc.callSync(60, "decaf_masta.delete_all_monitoring_alarms")
        print(result)

    def get_datacenter_ip_namespace(self, datacenter_id):
        result = self.rpc.callSync(60, "decaf_masta.get_datacenter_ip_namespace", datacenter_id)
        print(result)

    def create_flavor(self, flavor_data):
        result = self.rpc.callSync(60, "decaf_masta.create_flavor", flavor_data)
        print(result)

    def delete_flavor(self, flavor_id):
        result = self.rpc.callSync(60, "decaf_masta.delete_flavor", flavor_id)
        print(result)

    def create_image(self, image_data):
        result = self.rpc.callSync(60, "decaf_masta.create_image", image_data)
        print(result)

    def delete_image(self, image_id):
        result = self.rpc.callSync(60, "decaf_masta.delete_image", image_id)
        print(result)

    def create_keystone_credentials(self, credentials):
        result = self.rpc.callSync(60, "decaf_masta.create_keystone_credentials", credentials)
        print(result)

    def initialize_datacenter(self, datacenter_config):
        result = self.rpc.callSync(60, "decaf_masta.initialize_datacenter", datacenter_config)
        print(result)

    def action_vm_instance(self, vm_action):
        result = self.rpc.callSync(60, "decaf_masta.action_vm_instance", vm_action)
        print(result)

    def get_monitoring_data(self, monitoring_data):
        result = self.rpc.callSync(60, "decaf_masta.get_monitoring_data", monitoring_data)
        print(result)

    def create_monitoring_alarm(self, monitoring_alarm_request):
        result = self.rpc.callSync(60, "decaf_masta.create_monitoring_alarm", monitoring_alarm_request)
        return(result)

    def delete_monitoring_alarm(self, monitoring_alarm_id):
        result = self.rpc.callSync(60, "decaf_masta.delete_monitoring_alarm", monitoring_alarm_id)
        print(result)

    def vnf_manager_create_interface(self, interface_instance_id):
        result = self.rpc.callSync(60, "6c7aac08-4cb2-4655-9634-e87010e49a20.create_interface", iface_instance_id=interface_instance_id)
        print(result)

    def vnf_manager_delete_interface(self, interface_instance_id):
        result = self.rpc.callSync(60, "6c7aac08-4cb2-4655-9634-e87010e49a20.delete_interface", iface_instance_id=interface_instance_id)
        print(result)

    def new_successor(self, ip_address):
        result = self.rpc.callSync(60, "6c7aac08-4cb2-4655-9634-e87010e49a20.new_successor", ip_address=ip_address)
        print(result)

    def delete_successor(self, ip_address):
        result = self.rpc.callSync(60, "6c7aac08-4cb2-4655-9634-e87010e49a20.delete_successor", ip_address=ip_address)
        print(result)

    def scale_up(self, monitoring_alarm_event):
        result = self.rpc.callSync(60, "decaf_example_scaling.scale_up", monitoring_alarm_event=monitoring_alarm_event)
        print(result)

    def scale_down(self, monitoring_alarm_event):
        result = self.rpc.callSync(60, "decaf_example_scaling.scale_down", monitoring_alarm_event=monitoring_alarm_event)
        print(result)

    def end(self):
        self.rpc.dispose()
Ejemplo n.º 4
0
class BasicTest(unittest.TestCase):
    def setUp(self):
        def unnamed(x):
            print "Got Call"
            return x

        def mixed(x, foo='bar'):
            print "Got Call"
            return x, foo

        def named(foo='bar'):
            print "Got Call"
            return foo

        def add(x, y):
            print "Got Call"
            return x + y

        def multiply(x, y):
            print "Got Call"
            return x * y

        def timeout(*args):
            print "Got Call"
            time.sleep(300)
            return "I've been waiting a long time for this moment"

        @defer.inlineCallbacks
        def callbackCascade(x):
            print "Starting Cascade"
            plus5 = yield self.callee.call("add", x, 5)
            print "First result is: {0}".format(plus5)
            self.assertEqual(plus5, x + 5)
            times10 = yield self.callee.call("multiply", plus5, 10)
            print "Second result is: {0}".format(times10)
            self.assertEqual(times10, (x + 5) * 10)
            defer.returnValue(times10)

        import logging

        logger = logging.getLogger(__name__)

        self.caller = RpcLayer(logger=logger)
        self.callee = RpcLayer(logger=logger)

        open = list()
        open.extend([
            "unnamed", "named", "mixed", "add", "multiply", "plus5times10",
            "timeout"
        ])

        lock = threading.Lock()

        def waiter(name):
            print "Thread tries to get lock"
            lock.acquire()
            print name + " ready"
            open.remove(name)
            lock.release()

        #self.callee.register("unnamed",unnamed).addCallback(waiter)
        #self.callee.register("named", named).addCallback(waiter)
        #self.callee.register("mixed", mixed).addCallback(waiter)
        #self.callee.register("add", add).addCallback(waiter)
        #self.callee.register("multiply", multiply).addCallback(waiter)
        #self.callee.register("plus5times10", callbackCascade).addCallback(waiter)
        #self.callee.register("timeout", timeout).addCallback(waiter)

        self.callee.register("unnamed", function_pointer=unnamed)
        self.callee.register("named", function_pointer=named)
        self.callee.register("mixed", function_pointer=mixed)
        self.callee.register("add", function_pointer=add)
        self.callee.register("multiply", function_pointer=multiply)
        self.callee.register("plus5times10", function_pointer=callbackCascade)
        self.callee.register("timeout", function_pointer=timeout)

        time.sleep(2)

        OK = True

        while not OK:
            lock.acquire()
            OK = (len(open) == 0)
            lock.release()

        print "Set Up done"

    def tearDown(self):
        print "Begin Down done"
        self.callee.dispose()
        self.caller.dispose()
        print "Tear Down done"