Пример #1
0
 def _ensure_numeric_vlan_valid(self, allocation_range):
     if not represents_int(self.vlan_resource_model.vlan_id):
         raise ValueError("VLAN Id attribute value is not numeric")
     numeric_vlan = int(self.vlan_resource_model.vlan_id)
     if numeric_vlan < allocation_range.start or numeric_vlan > allocation_range.end:
         raise ValueError("VLAN Id is outside of the allocated range {0}"
                          .format(self.vlan_resource_model.allocation_ranges))
Пример #2
0
    def parse_vlan_id(vlan_type, vlan_id):
        if not vlan_type or not vlan_id:
            raise ValueError('vlan_id is empty')

        if vlan_type == 'Access':
            if represents_int(vlan_id):
                return int(vlan_id)
            raise KeyError('Access supports only int vlan id')
        elif vlan_type == 'Trunk':
            if not vlan_id:
                raise Exception(
                    'VLAN should be a number or range in format 1-100')
            vlan_parts = str(vlan_id).split("-")
            if len(vlan_parts) > 2:
                raise Exception(
                    'VLAN should be a number or range in format 1-100')
            if len(vlan_parts) == 1:
                return [
                    vim.NumericRange(start=int(vlan_parts[0]),
                                     end=int(vlan_parts[0]))
                ]
            if len(vlan_parts) == 2:
                start_port = int(vlan_parts[0])
                end_port = int(vlan_parts[1])
                return [vim.NumericRange(start=start_port, end=end_port)]
        raise KeyError('vlan type: {0} is not supported'.format(vlan_type))
Пример #3
0
 def _ensure_numeric_vlan_valid(self, allocation_range):
     if not represents_int(self.vlan_resource_model.vlan_id):
         raise ValueError("VLAN Id attribute value is not numeric")
     numeric_vlan = int(self.vlan_resource_model.vlan_id)
     if numeric_vlan < allocation_range.start or numeric_vlan > allocation_range.end:
         raise ValueError(
             "VLAN Id is outside of the allocated range {0}".format(
                 self.vlan_resource_model.allocation_ranges))
Пример #4
0
    def parse_vlan_id(vlan_type, vlan_id):
        if not vlan_type or not vlan_id:
            raise ValueError('vlan_id is empty')

        if vlan_type == 'Access':
            if represents_int(vlan_id):
                return int(vlan_id)
            raise KeyError('Access supports only int vlan id')
        elif vlan_type == 'Trunk':
            if not vlan_id:
                raise Exception('VLAN should be a number or range in format 1-100')
            vlan_parts = str(vlan_id).split("-")
            if len(vlan_parts) > 2:
                raise Exception('VLAN should be a number or range in format 1-100')
            if len(vlan_parts) == 1:
                return [vim.NumericRange(start=int(vlan_parts[0]), end=int(vlan_parts[0]))]
            if len(vlan_parts) == 2:
                start_port = int(vlan_parts[0])
                end_port = int(vlan_parts[1])
                return [vim.NumericRange(start=start_port, end=end_port)]
        raise KeyError('vlan type: {0} is not supported'.format(vlan_type))