Ejemplo n.º 1
0
func (os *OpenStack) CreateImage(imageTemplate *compute.Image) (*compute.Image, error) {
	if imageTemplate.SourceInstance != "" {
		opts := servers.CreateImageOpts{
			Name: imageTemplate.Name,
		}
		imageID, err := servers.CreateImage(os.ComputeClient, imageTemplate.SourceInstance, opts).ExtractImageID()
		if err != nil {
			return nil, err
		} else {
			return &compute.Image{
				ID:             imageID,
				Name:           imageTemplate.Name,
				SourceInstance: imageTemplate.SourceInstance,
			}, nil
		}
	} else if imageTemplate.SourceURL != "" {
		if imageTemplate.Format == "" {
			return nil, errors.New("missing image format (e.g. iso, qcow2, raw)")
		}
		opts := image.CreateOpts{
			Name:            imageTemplate.Name,
			ContainerFormat: "bare",
			DiskFormat:      imageTemplate.Format,
			CopyFrom:        imageTemplate.SourceURL,
		}
		createResult := image.Create(os.ImageClient, opts)
		apiImage, err := createResult.Extract()
		if err != nil {
			return nil, err
		} else {
			return &compute.Image{
				ID:     apiImage.ID,
				Name:   apiImage.Name,
				Format: apiImage.DiskFormat,
			}, nil
		}
	} else {
		return nil, errors.New("neither source instance nor source URL is set")
	}
}
Ejemplo n.º 2
0
func (this *OpenStack) VmSnapshot(vm *lobster.VirtualMachine) (string, error) {
	opts := servers.CreateImageOpts{
		Name: utils.Uid(16),
	}
	return servers.CreateImage(this.ComputeClient, vm.Identification, opts).ExtractImageID()
}