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
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
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()