Example #1
0
    def _validate_and_clean_interface(
        self, param_name, param, result_params, ret
    ):
        """Validate and clean interface input."""
        value = param["value"]
        for i in value.split(","):
            if ":" in i:
                # Allow users to specify an Interface using the vendor and
                # product.
                vendor, product = i.split(":")
                interfaces = self._get_interfaces(
                    vendor=vendor, product=product
                )
                if len(interfaces) != 0:
                    for interface in interfaces:
                        clean_param = copy.deepcopy(result_params)
                        clean_param[param_name] = copy.deepcopy(param)
                        clean_param[param_name][
                            "value"
                        ] = self._interface_to_dict(interface)
                        ret.append(clean_param)
                    continue

            if is_mac(i):
                interfaces = self._get_interfaces(mac_address=i)
            else:
                interfaces = self._get_interfaces(
                    Q(name=i)
                    | Q(vendor=i)
                    | Q(product=i)
                    | Q(tags__overlap=[i])
                )
            if len(interfaces) == 0:
                set_form_error(
                    self,
                    param_name,
                    "Unknown interface for %s(%s)"
                    % (self._node.fqdn, self._node.system_id),
                )
                continue
            for interface in interfaces:
                clean_param = copy.deepcopy(result_params)
                clean_param[param_name] = copy.deepcopy(param)
                clean_param[param_name]["value"] = self._interface_to_dict(
                    interface
                )
                ret.append(clean_param)
Example #2
0
    def _validate_and_clean_interface(
            self, param_name, param, result_params, ret):
        """Validate and clean interface input."""
        value = param['value']
        for i in value.split(','):
            if ':' in i:
                # Allow users to specify an Interface using the vendor and
                # product.
                vendor, product = i.split(':')
                try:
                    interface = self._get_interfaces().get(
                        vendor=vendor, product=product)
                except ObjectDoesNotExist:
                    pass
                else:
                    clean_param = copy.deepcopy(result_params)
                    clean_param[param_name] = copy.deepcopy(param)
                    clean_param[param_name]['value'] = self._interface_to_dict(
                        interface)
                    ret.append(clean_param)
                    continue

            if is_mac(i):
                qs = self._get_interfaces().filter(mac_address=i)
            else:
                qs = self._get_interfaces().filter(
                    Q(name=i) | Q(vendor=i) | Q(product=i) |
                    Q(tags__overlap=[i]))
            if len(qs) == 0:
                set_form_error(
                    self, param_name, "Unknown interface for %s(%s)" % (
                        self._node.fqdn, self._node.system_id))
                continue
            for interface in qs:
                clean_param = copy.deepcopy(result_params)
                clean_param[param_name] = copy.deepcopy(param)
                clean_param[param_name]['value'] = self._interface_to_dict(
                    interface)
                ret.append(clean_param)
Example #3
0
 def test_false(self):
     self.assertFalse(is_mac(factory.make_name("bad")))
Example #4
0
 def test_true(self):
     self.assertTrue(is_mac(factory.make_MAC()))
Example #5
0
 def test__false(self):
     self.assertFalse(is_mac(factory.make_name('bad')))