Example #1
0
File: volume.go Project: vmware/vic
// volumeCreate issues a CreateVolume request to the portlayer
func (v *Volume) volumeCreate(name, driverName string, volumeData, labels map[string]string) (*types.Volume, error) {
	defer trace.End(trace.Begin(""))
	result := &types.Volume{}

	client := PortLayerClient()
	if client == nil {
		return nil, fmt.Errorf("failed to get a portlayer client")
	}

	if name == "" {
		name = uuid.New().String()
	}

	// TODO: support having another driver besides vsphere.
	// assign the values of the model to be passed to the portlayer handler
	req, varErr := newVolumeCreateReq(name, driverName, volumeData, labels)
	if varErr != nil {
		return result, varErr
	}
	log.Infof("Finalized model for volume create request to portlayer: %#v", req)

	res, err := client.Storage.CreateVolume(storage.NewCreateVolumeParamsWithContext(ctx).WithVolumeRequest(req))
	if err != nil {
		return result, err
	}
	result = NewVolumeModel(res.Payload, labels)
	return result, nil
}
Example #2
0
func processAnonymousVolumes(h *string, volumes map[string]struct{}, client *client.PortLayer) ([]volumeFields, error) {
	var volumeFields []volumeFields

	for v := range volumes {
		fields, err := processVolumeParam(v)
		log.Infof("Processed Volume arguments : %#v", fields)
		if err != nil {
			return nil, err
		}
		//NOTE: This should be the guard for the case of an anonymous volume.
		//NOTE: we should not expect any driver args if the drive is anonymous.
		log.Infof("anonymous volume being created - Container Create - volume mount section ID: %s ", fields.ID)
		metadata := make(map[string]string)
		metadata["flags"] = fields.Flags
		volumeRequest := models.VolumeRequest{
			Capacity: -1,
			Driver:   "vsphere",
			Store:    "default",
			Name:     fields.ID,
			Metadata: metadata,
		}
		_, err = client.Storage.CreateVolume(storage.NewCreateVolumeParamsWithContext(ctx).WithVolumeRequest(&volumeRequest))
		if err != nil {
			return nil, err
		}
		volumeFields = append(volumeFields, fields)
	}
	return volumeFields, nil
}
Example #3
0
// VolumeCreate : docker personality implementation for VIC
func (v *Volume) VolumeCreate(name, driverName string, opts, labels map[string]string) (*types.Volume, error) {
	defer trace.End(trace.Begin("Volume.VolumeCreate"))
	result := &types.Volume{}

	client := PortLayerClient()
	if client == nil {
		return nil, derr.NewErrorWithStatusCode(fmt.Errorf("Failed to get a portlayer client"), http.StatusInternalServerError)
	}

	// TODO: support having another driver besides vsphere.
	// assign the values of the model to be passed to the portlayer handler
	model, varErr := translateInputsToPortlayerRequestModel(name, driverName, opts, labels)
	if varErr != nil {
		return result, derr.NewErrorWithStatusCode(fmt.Errorf("Bad Driver Arg: %s", varErr), http.StatusBadRequest)
	}

	if model.Name == "" {
		model.Name = uuid.New().String()
	}

	res, err := client.Storage.CreateVolume(storage.NewCreateVolumeParamsWithContext(ctx).WithVolumeRequest(model))
	if err != nil {
		switch err := err.(type) {

		case *storage.CreateVolumeInternalServerError:
			// FIXME: right now this does not return an error model...
			return result, derr.NewErrorWithStatusCode(fmt.Errorf("%s", err.Error()), http.StatusInternalServerError)

		case *storage.CreateVolumeDefault:
			return result, derr.NewErrorWithStatusCode(fmt.Errorf("%s", err.Payload.Message), http.StatusInternalServerError)

		default:
			return result, derr.NewErrorWithStatusCode(fmt.Errorf("%s", err), http.StatusInternalServerError)
		}
	}

	result = NewVolumeModel(res.Payload, labels)
	return result, nil
}