Exemple #1
0
	def message (self,tokeniser):
		valid_messages = ['notification','open','keepalive','update','refresh','operational']
		valid_options = ['parsed','packets','consolidated']

		def printf (string):
			return (string[::-1].replace(',', ' and'[::-1], 1))[::-1]

		# location is set by our caller
		direction = self.location[-2]  # pylint: disable=E1101
		message = self.location[-1]    # pylint: disable=E1101
		actions = tokeniser()

		for (idx_line,idx_column,line,action) in actions:
			if action not in valid_options:
				raise RaisedProcess(Location(idx_line,idx_column,line),'invalid message option %s, valid options are "%s"' % (action,printf('", "'.join(valid_options))))

			messages = valid_messages if message == 'all' else [message]

			for m in messages:
				section = self.content.setdefault(direction,{}).setdefault(m,[])

				if action in section:
					raise RaisedProcess(Location(idx_line,idx_column,line),'duplicate action (%s) for message %s%s' % (
						action,
						m,
						" using the alis 'all'" if message == 'all' else ''
					))

				if 'consolidated' in section and len(section) > 0:
					raise RaisedProcess(Location(idx_line,idx_column,line),'consolidated can not be used with another keyword')

				section.append(action)
Exemple #2
0
    def _add(self, tokeniser, afi_name, safi_names):
        self._check_duplicate(tokeniser, RaisedFamily)
        known = self.content.setdefault(AFI(AFI.value(afi_name)), [])

        for (idx_line, idx_column, line, safi_name) in safi_names:
            if safi_name not in AFI.implemented_safi(afi_name):
                raise RaisedFamily(
                    Location(idx_line, idx_column, line),
                    'the family pair afi/safi %s/%s is unimplemented' %
                    (afi_name, safi_name))

            safi = SAFI(SAFI.value(safi_name))
            if safi in known:
                raise RaisedFamily(
                    Location(idx_line, idx_column, line),
                    'afi/safi pair already defined in this family')
            known.append(safi)
Exemple #3
0
	def content (self,producer):
		try:
			while True:
				self.idx_line,self.idx_column,self.line,token = producer()
				if token == '[':
					returned = []
					for token in self.iterate_list(producer):
						returned.append((self.idx_line,self.idx_column,self.line,token))
					return returned
				elif token[0] in ('"',"'"):
					return unescape(token[1:-1])
				else:
					return token
		except ValueError:
			raise Raised(Location(self.idx_line,self.idx_column,self.line),'Could not parse %s' % str(token))
		except StopIteration:
			return None