Esempio n. 1
0
 def get_from_config_store(self, config_path):
     """Query the agent's config store for the data at the key 'config_path'."""
     resolved_path = check_for_config_link(config_path)
     entry = self.vip.rpc.call(CONFIGURATION_STORE, 'manage_get', self.core.identity, resolved_path, raw=True).get()
     if type(entry) == str:
         entry = json.loads(utils.strip_comments(entry))
     return entry
Esempio n. 2
0
    def parse_config(self, agent, device_type, config_dict, reg_config_str):
        if reg_config_str is None:
            return

        config_str = (utils.strip_comments(reg_config_str).lstrip()).rstrip()

        import re
        # remove whitespace after delimiter,  but not within delimited value:
        config_str = re.sub(r',[\s]+', ',', config_str)

        # remove trailing whitespace within delimited value:
        config_str = re.sub(r'[\s]+,', ',', config_str)

        # remove trailing whitespace at end of line:
        # re.MULTILINE - When specified, '^' matches the beginning of the string andbeginning of each line (immediately following each newline)
        # and '$' matches end of the string and end of each line (immediately preceding each newline).
        config_str = re.sub(r'[\s]+$', '', config_str, flags=re.MULTILINE)

        _log.debug('Configuring {} Driver with {} and config_str {}'.format(
            device_type, config_dict, config_str))

        f = StringIO(config_str)
        regDict = DictReader(f)

        agent.ConfigureAgent(self, config_dict, regDict)
Esempio n. 3
0
    def setup_device(self):
        #First call to setup_device won't have anything to unsubscribe to.
        #         try:
        #             self.vip.pubsub.unsubscribe('pubsub', None, None)
        #         except KeyError:
        #             pass

        config_str = self.get_config(self.config_name)
        self.config = config = jsonapi.loads(utils.strip_comments(config_str))
        driver_config = config["driver_config"]
        driver_type = config["driver_type"]
        registry_config = self.get_config(config["registry_config"])
        self.heart_beat_point = config.get("heart_beat_point")
        self.publish_depth_first_all = config.get("publish_depth_first_all",
                                                  True)
        self.publish_breadth_first_all = config.get(
            "publish_breadth_first_all", True)
        self.publish_depth_first = config.get("publish_depth_first", True)
        self.publish_breadth_first = config.get("publish_breadth_first", True)
        self.interface = self.get_interface(driver_type, driver_config,
                                            registry_config)
        self.meta_data = {}

        for point in self.interface.get_register_names():
            register = self.interface.get_register_by_name(point)
            if register.register_type == 'bit':
                ts_type = 'boolean'
            else:
                if register.python_type is int:
                    ts_type = 'integer'
                elif register.python_type is float:
                    ts_type = 'float'
                elif register.python_type is str:
                    ts_type = 'string'

            self.meta_data[point] = {
                'units': register.get_units(),
                'type': ts_type,
                'tz': config['timezone']
            }

        self.base_topic = DEVICES_VALUE(campus=config.get('campus', ''),
                                        building=config.get('building', ''),
                                        unit=config.get('unit', ''),
                                        path=config.get('path', ''),
                                        point=None)

        self.device_name = DEVICES_PATH(base='',
                                        node='',
                                        campus=config.get('campus', ''),
                                        building=config.get('building', ''),
                                        unit=config.get('unit', ''),
                                        path=config.get('path', ''),
                                        point='')

        self.parent.device_startup_callback(self.device_name, self)
Esempio n. 4
0
def add_definitions_to_config_store(test_agent):
    """Add PointDefinitions and FunctionDefinitions to the mesaagent's config store."""
    with open(POINT_DEFINITIONS_PATH, 'r') as f:
        points_json = json.loads(strip_comments(f.read()))
    test_agent.vip.rpc.call('config.store', 'manage_store', MESA_AGENT_ID,
                            'mesa_points.config', points_json, config_type='raw')
    with open(FUNCTION_DEFINITIONS_PATH, 'r') as f:
        functions_json = yaml.load(f.read())
    test_agent.vip.rpc.call('config.store', 'manage_store', MESA_AGENT_ID,
                            'mesa_functions.config', functions_json, config_type='raw')
Esempio n. 5
0
    def parse_config(self, agent, config_dict, reg_config_str):
        if reg_config_str is None:
            return

        config_str = utils.strip_comments(reg_config_str).lstrip()
        _log.debug('Configure with {} and config_str {}'.format(config_dict, config_str))
         
        f = StringIO(config_str)
        regDict = DictReader(f)
        
        self.agent.ConfigureAgent(self, config_dict, regDict )
Esempio n. 6
0
    def parse_config(self, agent, device_type, config_dict, reg_config_str):
        if reg_config_str is None:
            return

        config_str = (utils.strip_comments(reg_config_str).lstrip()).rstrip()
        _log.debug('Configuring {} Driver with {} and config_str {}'.format(
            device_type, config_dict, config_str))

        f = StringIO(config_str)
        regDict = DictReader(f)

        agent.ConfigureAgent(self, config_dict, regDict)
Esempio n. 7
0
 def _read_auth_file(self):
     auth_path = os.path.join(self.volttron_home, 'auth.json')
     try:
         with open(auth_path, 'r') as fd:
             data = strip_comments(FileObject(fd, close=False).read())
             if data:
                 auth = jsonapi.loads(data)
             else:
                 auth = {}
     except IOError:
         auth = {}
     if 'allow' not in auth:
         auth['allow'] = []
     return auth, auth_path
Esempio n. 8
0
 def _read_auth_file(self):
     auth_path = os.path.join(self.volttron_home, 'auth.json')
     try:
         with open(auth_path, 'r') as fd:
             data = strip_comments(FileObject(fd, close=False).read())
             if data:
                 auth = jsonapi.loads(data)
             else:
                 auth = {}
     except IOError:
         auth = {}
     if 'allow' not in auth:
         auth['allow'] = []
     return auth, auth_path
Esempio n. 9
0
    def setup_device(self):
        #First call to setup_device won't have anything to unsubscribe to.
#         try:
#             self.vip.pubsub.unsubscribe('pubsub', None, None)
#         except KeyError:
#             pass
        
        config_str = self.get_config(self.config_name)
        self.config = config = jsonapi.loads(utils.strip_comments(config_str))  
        driver_config = config["driver_config"] 
        driver_type = config["driver_type"] 
        registry_config = self.get_config(config["registry_config"]) 
        
        self.heart_beat_point = config.get("heart_beat_point") 
                           
        self.interface = self.get_interface(driver_type, driver_config, registry_config)
        self.meta_data = {}
        
        for point in self.interface.get_register_names():
            register = self.interface.get_register_by_name(point)
            if register.register_type == 'bit':
                ts_type = 'boolean'
            else:
                if register.python_type is int:
                    ts_type = 'integer'
                elif register.python_type is float:
                    ts_type = 'float'
                elif register.python_type is str:
                    ts_type = 'string'
            
            self.meta_data[point] = {'units': register.get_units(),
                                     'type': ts_type,
                                     'tz': config['timezone']}
            
        self.base_topic = DEVICES_VALUE(campus=config.get('campus', ''), 
                                        building=config.get('building', ''), 
                                        unit=config.get('unit', ''),
                                        path=config.get('path', ''),
                                        point=None)
        
        self.device_name = DEVICES_PATH(base='',
                                   node='',
                                   campus=config.get('campus', ''), 
                                   building=config.get('building', ''), 
                                   unit=config.get('unit', ''),
                                   path=config.get('path', ''),
                                   point='')
        
        self.parent.device_startup_callback(self.device_name, self)
Esempio n. 10
0
	def parse_config(self, agent, device_type, config_dict, reg_config_str):
		if reg_config_str is None:
			return

		config_str = (utils.strip_comments(reg_config_str).lstrip()).rstrip()

		import re
		# remove whitespace after delimiter,  but not within delimited value:
		config_str = re.sub(r',[\s]+', ',', config_str)

		# remove trailing whitespace within delimited value:
		config_str = re.sub(r'[\s]+,', ',', config_str)

		# remove trailing whitespace at end of line:
		# re.MULTILINE - When specified, '^' matches the beginning of the string andbeginning of each line (immediately following each newline)
		# and '$' matches end of the string and end of each line (immediately preceding each newline).
		config_str = re.sub(r'[\s]+$', '', config_str, flags=re.MULTILINE)

		_log.debug('Configuring {} Driver with {} and config_str {}'.format(device_type, config_dict, config_str))

		f = StringIO(config_str)
		regDict = DictReader(f)

		agent.ConfigureAgent(self, config_dict, regDict )