Beispiel #1
0
    detach: function(params) {
        if (!params.volume)
            throw new Error("Missing volume");

        var volume = params.volume,
            volumeState = new VolumeState({
                status_raw: "detaching"
            }),
            instanceUUID = volume.get("attach_data").instance_id,
            instance = stores.InstanceStore.getAll().findWhere({
                uuid: instanceUUID
            }),
            actionRequest = new InstanceVolumeActionRequest({
                instance: instance,
                volume: volume
            });

        volume.set({
            state: volumeState
        });
        Utils.dispatch(VolumeConstants.UPDATE_VOLUME, {
            volume: volume
        });

        actionRequest.save(null, {
            attrs: {
                action: "detach_volume",
                volume_id: volume.get("uuid")
            }
        }).done(function() {
            // todo: volume detach happens quickly once the cloud gets the request. The problem is that
            // at this moment, all that's happened is that the *request* to detach has been received. If
            // we tell the user the volume was detached, we're lying - it hasn't been.
            // NotificationController.success(
            //  "Volume Detached",
            //  "Volume was detached.  It is now available to attach to another instance or destroy."
            // );

            volume.set("state", volumeState);
            Utils.dispatch(VolumeConstants.UPDATE_VOLUME, {
                volume: volume
            });
            Utils.dispatch(VolumeConstants.POLL_VOLUME_WITH_DELAY, {
                volume: volume,
                delay: 30*1000,
            });
        }).fail(function(response) {
            Utils.displayError({
                title: "Volume could not be detached",
                response: response
            });
            Utils.dispatch(VolumeConstants.POLL_VOLUME, {
                volume: volume
            });
        });

    }
Beispiel #2
0
    attach: function(params) {
        if (!params.instance) throw new Error("Missing instance");
        if (!params.volume) throw new Error("Missing volume");

        var instance = params.instance,
            mountLocation = params.mountLocation,
            volume = params.volume,
            helpLink = params.helpLink;

        var volumeState = new VolumeState({
                status_raw: "attaching"
            }),
            actionRequest = new InstanceVolumeActionRequest({
                instance: instance,
                volume: volume
            });

        volume.set({
            state: volumeState
        });
        Utils.dispatch(VolumeConstants.UPDATE_VOLUME, {
            volume: volume
        });

        actionRequest
            .save(null, {
                attrs: {
                    action: "attach_volume",
                    volume_id: volume.get("uuid"),
                    mount_location: mountLocation
                }
            })
            .done(function() {
                // todo: volume attach happens quickly once the cloud gets the request. The problem is that
                // at this moment, all that's happened is that the *request* to attach has been received. If
                // we tell the user the volume was attached, we're lying - it hasn't been.
                // NotificationController.success("Volume Attached",
                //                                VolumeAttachNotifications.success(helpLink));

                Utils.dispatch(VolumeConstants.UPDATE_VOLUME, {
                    volume: volume
                });
                Utils.dispatch(VolumeConstants.POLL_VOLUME_WITH_DELAY, {
                    volume: volume,
                    delay: 30 * 1000
                });
                if (globals.BADGES_ENABLED) {
                    actions.BadgeActions.checkOrGrant(
                        Badges.ATTACH_VOLUME_BADGE
                    );
                }
            })
            .fail(function(response) {
                var title = "Error attaching volume",
                    message,
                    error;

                try {
                    error = response.responseJSON.errors[0];
                    if (error.code === 409) {
                        message = VolumeAttachNotifications.attachError(
                            volume,
                            instance,
                            helpLink
                        );
                        NotificationController.error(title, message);
                    } else {
                        NotificationController.error(
                            title,
                            error.code + ": " + error.message
                        );
                    }
                } catch (err) {
                    NotificationController.error(
                        title,
                        "If the problem persists, please contact support."
                    );
                }

                // poll the volume to get it's real status
                Utils.dispatch(VolumeConstants.POLL_VOLUME, {
                    volume: volume
                });
            });
    }