예제 #1
0
    def obj_create(self, bundle, **kwargs):
        request = bundle.request

        self.is_valid(bundle)

        if bundle.errors:
            raise ImmediateHttpResponse(response=self.error_response(
                bundle.request, bundle.errors[self._meta.resource_name]))

        # Set up an errors dict in the bundle to allow us to carry
        # hydration errors through to validation.
        setattr(bundle, 'data_errors', defaultdict(list))

        bundle.data['content_type'] = ContentType.objects.get_for_model(
            KIND_TO_KLASS[bundle.data['kind']]).natural_key()

        # Should really only be doing one validation pass, but this works
        # OK for now.  It's better than raising a 404 or duplicating the
        # filesystem validation failure if it doesn't exist, anyhow.
        self.is_valid(bundle)

        targets, command = JobSchedulerClient.create_targets([bundle.data])

        if request.method == 'POST':
            raise custom_response(
                self, request, http.HttpAccepted, {
                    'command':
                    dehydrate_command(command),
                    'target':
                    self.full_dehydrate(self.build_bundle(obj=targets[0])).data
                })
예제 #2
0
    def obj_update(self, bundle, **kwargs):
        if "pk" in kwargs:
            return super(LNetConfigurationResource,
                         self).obj_update(bundle, **kwargs)

        lnet_configurations_data = bundle.data.get("objects", [bundle.data])

        lnet_configuration = []

        for lnet_configuration_data in lnet_configurations_data:
            lnet_configuration.append({
                "host_id":
                lnet_configuration_data["host"]["id"],
                "state":
                lnet_configuration_data["state"]
            })

        command_id = JobSchedulerClient.update_lnet_configuration(
            lnet_configuration)

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

        raise custom_response(self, bundle.request, http.HttpAccepted,
                              {"command": dehydrate_command(command)})
예제 #3
0
        def _update_corosync_configuration(self, corosync_configuration, request, **kwargs):
            network_interface_ids = [resolve(interwork_interface)[2]['pk'] for interwork_interface in corosync_configuration['network_interfaces']]

            return self.BulkActionResult(dehydrate_command(JobSchedulerClient.update_corosync_configuration(corosync_configuration_id=corosync_configuration['id'],
                                                                                                            mcast_port=corosync_configuration['mcast_port'],
                                                                                                            network_interface_ids=network_interface_ids)),
                                         None, None)
    def patch_list(self, request, **kwargs):
        """
        Specialization of patch_list to do bulk target creation in a single RPC to job_scheduler (and
        consequently in a single command).
        """
        deserialized = self.deserialize(request, request.raw_post_data, format=request.META.get('CONTENT_TYPE', 'application/json'))

        if "objects" not in deserialized:
            raise BadRequest("Invalid data sent.")

        if len(deserialized["objects"]) and 'put' not in self._meta.detail_allowed_methods:
            raise ImmediateHttpResponse(response=http.HttpMethodNotAllowed())

        # If any of the included targets is not a creation, then
        # skip to a normal PATCH instead of this special case one
        for target_data in deserialized['objects']:
            if 'id' in target_data or 'resource_uri' in target_data:
                super(TargetResource, self).patch_list(request, **kwargs)

        # Validate and prepare each target dict for consumption by job_scheduler
        for target_data in deserialized['objects']:
            data = self.alter_deserialized_detail_data(request, target_data)
            bundle = self.build_bundle(data=dict_strip_unicode_keys(data))
            bundle.request = request
            self.is_valid(bundle)

            target_data['content_type'] = ContentType.objects.get_for_model(KIND_TO_KLASS[target_data['kind']]).natural_key()

        targets, command = JobSchedulerClient.create_targets(deserialized['objects'])

        raise custom_response(self, request, http.HttpAccepted,
                              {'command': dehydrate_command(command),
                               'targets': [self.get_resource_uri(target) for target in targets]})
 def _pool_delete(self, request, obj_list):
     commands = []
     for obj in obj_list:
         command_id = JobSchedulerClient.delete_ostpool(obj.id)
         command = Command.objects.get(pk=command_id)
         commands.append(dehydrate_command(command))
     raise custom_response(self, request, http.HttpAccepted,
                           {"commands": commands})
    def obj_create(self, bundle, **kwargs):
        request = bundle.request

        ostpool_id, command_id = JobSchedulerClient.create_ostpool(bundle.data)
        command = Command.objects.get(pk=command_id)

        raise custom_response(self, request, http.HttpAccepted,
                              {"command": dehydrate_command(command)})
예제 #7
0
    def obj_create(self, bundle, **kwargs):
        command_id = JobSchedulerClient.configure_stratagem(bundle.data)

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

        raise custom_response(self, bundle.request, http.HttpAccepted,
                              {"command": dehydrate_command(command)})
    def obj_update(self, bundle, **kwargs):
        try:
            obj = self.obj_get(bundle, **kwargs)
        except ObjectDoesNotExist:
            raise NotFound(
                "A model instance matching the provided arguments could not be found."
            )

        command_id = JobSchedulerClient.update_ostpool(bundle.data)
        command = Command.objects.get(pk=command_id)

        raise custom_response(self, bundle.request, http.HttpAccepted,
                              {"command": dehydrate_command(command)})
예제 #9
0
    def obj_create(self, bundle, request=None, **kwargs):

        filesystem_id, command_id = JobSchedulerClient.create_filesystem(
            bundle.data)
        filesystem = ManagedFilesystem.objects.get(pk=filesystem_id)
        command = Command.objects.get(pk=command_id)
        fs_bundle = self.full_dehydrate(self.build_bundle(obj=filesystem))
        filesystem_data = self.alter_detail_data_to_serialize(
            request, fs_bundle).data

        raise custom_response(self, request, http.HttpAccepted, {
            'command': dehydrate_command(command),
            'filesystem': filesystem_data
        })
예제 #10
0
    def obj_create(self, bundle, **kwargs):
        (_, fs_id) = get_fs_id(bundle)

        mdts = list(
            ManagedMdt.objects.filter(
                filesystem_id=fs_id,
                active_mount_id__isnull=False).values_list("id", flat=True))

        command_id = JobSchedulerClient.run_stratagem(mdts, fs_id, bundle.data)

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

        raise custom_response(self, bundle.request, http.HttpAccepted,
                              {"command": dehydrate_command(command)})
        def _update_corosync_configuration(self, corosync_configuration, request, **kwargs):
            network_interface_ids = [
                resolve(interwork_interface)[2]["pk"]
                for interwork_interface in corosync_configuration["network_interfaces"]
            ]

            return self.BulkActionResult(
                dehydrate_command(
                    JobSchedulerClient.update_corosync_configuration(
                        corosync_configuration_id=corosync_configuration["id"],
                        mcast_port=corosync_configuration["mcast_port"],
                        network_interface_ids=network_interface_ids,
                    )
                ),
                None,
                None,
            )
예제 #12
0
    def _create_host(self, address, data, request):
        # Resolve a server profile URI to a record
        profile = ServerProfileResource().get_via_uri(data["server_profile"], request)

        host, command = JobSchedulerClient.create_host_ssh(server_profile=profile.name, **_host_params(data, address))

        #  TODO:  Could simplify this by adding a 'command' key to the
        #  bundle, then optionally handling dehydrating that
        #  in super.alter_detail_data_to_serialize.  That way could
        #  return from this method avoiding all this extra code, and
        #  providing a central handling for all things that migth have
        #  a command argument.  NB:  not tested, and not part of any ticket
        object = {
            "command": dehydrate_command(command),
            "host": self.alter_detail_data_to_serialize(None, self.full_dehydrate(self.build_bundle(obj=host))).data,
        }

        return self.BulkActionResult(object, None, None)
예제 #13
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)})
예제 #14
0
    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)})
예제 #15
0
 def _test_host_contact(self, data, request, **kwargs):
     return self.BulkActionResult(
         dehydrate_command(
             JobSchedulerClient.test_host_contact(
                 **_host_params(data))), None, None)