예제 #1
0
    def is_valid(self, bundle, request=None, **kwargs):
        errors = defaultdict(list)

        if request.method != "POST":
            return errors

        for nids_data in bundle.data.get("objects", [bundle.data]):
            if "lnd_network" not in nids_data:
                errors["lnd_network"] = [
                    "Field lnd_network not present in data"
                ]

            if not errors:
                self.validate_object(
                    nids_data,
                    errors,
                    {
                        "lnd_network":
                        self.Expectation(True),
                        "network_interface":
                        self.Expectation(True),
                        "lnd_type":
                        self.Expectation(int(nids_data["lnd_network"] != -1)),
                        "resource_uri":
                        self.Expectation(False),
                        "lnet_configuration":
                        self.Expectation(False),
                    },
                )

            if not errors:
                self.validate_resources(
                    [
                        self.URIInfo(nids_data.get("lnet_configuration", None),
                                     LNetConfigurationResource),
                        self.URIInfo(nids_data["network_interface"],
                                     NetworkInterfaceResource),
                    ],
                    errors,
                    request,
                )

            if not errors:
                # Check the lnd_type passed is valid for the network_interface
                if ("lnd_type" in nids_data) and (
                        nids_data["lnd_type"]
                        not in NetworkInterfaceResource().get_via_uri(
                            nids_data["network_interface"],
                            request).lnd_types):
                    errors["lnd_type"].append(
                        "lnd_type %s not valid for interface %s" % (
                            nids_data["lnd_type"],
                            NetworkInterfaceResource().get_via_uri(
                                nids_data["network_interface"], request),
                        ))

        return errors
예제 #2
0
    def obj_create(self, bundle, request=None, **kwargs):
        if 'objects' in bundle.data:
            nids_data = bundle.data['objects']
        else:
            nids_data = [bundle.data]

        for nid_data in nids_data:
            nid_data['network_interface'] = NetworkInterfaceResource(
            ).get_via_uri(nid_data['network_interface']).id

        command_id = JobSchedulerClient.update_nids(nids_data)

        try:
            command = Command.objects.get(pk=command_id)
        except ObjectDoesNotExist:
            command = None

        raise custom_response(self, request, http.HttpAccepted,
                              {'command': dehydrate_command(command)})
    def obj_create(self, bundle, **kwargs):
        request = bundle.request

        if "objects" in bundle.data:
            nids_data = bundle.data["objects"]
        else:
            nids_data = [bundle.data]

        for nid_data in nids_data:
            nid_data["network_interface"] = (
                NetworkInterfaceResource().get_via_uri(nid_data["network_interface"], bundle.request).id
            )

        command_id = JobSchedulerClient.update_nids(nids_data)

        try:
            command = Command.objects.get(pk=command_id)
        except ObjectDoesNotExist:
            command = None

        raise custom_response(self, request, http.HttpAccepted, {"command": dehydrate_command(command)})