コード例 #1
0
ファイル: validate.py プロジェクト: ddtsm/napalm
def _get_validation_file(validation_file):
    try:
        with open(validation_file, 'r') as stream:
            try:
                validation_source = yaml.load(stream)
            except yaml.YAMLError as exc:
                raise ValidationException(exc)
    except IOError:
        raise ValidationException("File {0} not found.".format(validation_file))
    return validation_source
コード例 #2
0
def _get_validation_file(validation_file: str) -> Dict[str, Dict]:
    try:
        with open(validation_file, "r") as stream:
            try:
                validation_source = yaml.safe_load(stream)
            except yaml.YAMLError as exc:
                raise ValidationException(exc)
    except IOError:
        raise ValidationException("File {0} not found.".format(validation_file))
    return validation_source
コード例 #3
0
ファイル: validate.py プロジェクト: ddtsm/napalm
def _mode(mode_string):
    mode = {'strict': False}

    for m in mode_string.split():
        if m not in mode.keys():
            raise ValidationException("mode '{}' not recognized".format(m))
        mode[m] = True
    return mode
コード例 #4
0
def _mode(mode_string: str) -> Dict[str, bool]:
    mode = {"strict": False}

    for m in mode_string.split():
        if m not in mode.keys():
            raise ValidationException("mode '{}' not recognized".format(m))
        mode[m] = True
    return mode
コード例 #5
0
ファイル: gaiaos.py プロジェクト: remingu/napalm-gaia
 def get_virtual_systems(self) -> dict:
     """
         | Get virtual systems information.   
         | Returns a dictionary with configured virtual systems.
         | The keys of the main dictionary represents virtual system ID.
         | The values represent the detail of the  virtual system,
         | represeted by the following keys.
         |   * type (str)
         |   * name (str)
         |   * policy (str)
         |   * sic (str)
         
         :return: dict
         
         example::
             {
               0:
                 {'
                   'type': 'VSX Gateway',
                   'name': 'dummy_vsx_gw',
                   'policy': 'dummy_policy'
                   'sic': 'Trust established'
                 }
             }
     """
     try:
         if self._check_vsx_state() is True:
             vs_regex = r'\|(.\d+)\|([A-z0-9-_]+\s.\w+)+(?:\s+\||\|)+([A-z0-9-_]+)+' \
                        r'(?:\s+\||\|)+([A-z0-9_-]+)+(?:\s+\||\|)+(.*)(?:\|)'
             command = 'cpstat -f stat vsx'
             output = self.device.send_command(command)
             vs = {}
             for match in re.finditer(vs_regex, output, re.M):
                 vs[match.group(1)] = {
                     'type': match.group(2),
                     'name': match.group(3),
                     'policy': match.group(4),
                     'sic': match.group(5)
                 }
             return vs
         else:
             raise ValidationException('VSX not enabled')
     except (socket.error, EOFError) as e:
         raise ConnectionClosedException(str(e))
コード例 #6
0
ファイル: gaiaos.py プロジェクト: remingu/napalm-gaia
 def _set_virtual_system(self, vsid: int) -> bool:
     """
         | Switch to VSX context. Raises RuntimeError if failed.
         
         :return: bool
     """
     try:
         if self._check_vsx_state() is True:
             if self._check_expert_mode() is True:
                 command = 'vsenv {}'.format(vsid)
             else:
                 command = 'set virtual-system {}'.format(vsid)
             vsid_regex = r'(?<=:){}'.format(vsid)
             expect_regex = r'(?<=:)\d+'
             output = self.device.send_command(command, expect_regex)
             if re.search(vsid_regex, output):
                 return True
             else:
                 raise CommandErrorException('cannot access virtual-system')
         else:
             raise ValidationException('VSX not enabled')
     except (socket.error, EOFError) as e:
         raise ConnectionClosedException(str(e))