예제 #1
0
	def set_state(self, message, state):

		# This Method creates a new state entry into the DB.
		# The entry is created if it has not been created before, otherwise it is updated.
		retrieve_state = DB().get_state(message['Arguments']['device_mac'])

		if len(retrieve_state) == 0:
			query = DB().get_policy(message['Arguments']['device_mac'])

			if len(query) is not 0:
				condition = 'defined'
			else:
				condition = 'undefined'

			state = {
        		'device': message['Arguments']['device_mac'],
        		'port': message['Arguments']['device_port'], 
        		'policy': condition,
        		'state': state
			}

			status = DB().get_status()
			status.append(state)
			DB().save_status(status)

		else:
			DB().update_status(message['Arguments']['device_mac'], 'state', 'online')
예제 #2
0
    def define_policy(self, policy):

        # This Method stores the policy defined by the user in the DB.
        policies = DB().get_policies()
        policies.append(policy)
        DB().save_policies(policies)
        DB().update_status(
            policy['device'], 'policy',
            'defined')  # The device state entry must be updated.
        self.set_policy(policy)
예제 #3
0
	def get_renema_app_id(self):

		# This method retrieves all the allocated Ids in order to know what should
		# be the next prefix to be allocated.
		# Then, the new Id is stored in the DB.
		renema_apps_ids = []
		renema_apps_ids = DB().get_renema_apps_ids()
		app_id = len(renema_apps_ids) + 1
		renema_id = prefix + str(app_id)
		renema_apps_ids.append(renema_id) 
		DB().save_renema_apps_ids(renema_apps_ids)
		return renema_id