コード例 #1
0
ファイル: openstack.go プロジェクト: yashodhank/lobster
func (this *OpenStack) ImageFetch(url string, format string) (string, error) {
	opts := image.CreateOpts{
		Name:            "lobster",
		ContainerFormat: "bare",
		DiskFormat:      format,
		CopyFrom:        url,
	}
	createResult := image.Create(this.ImageClient, opts)
	image, err := createResult.Extract()
	if err != nil {
		return "", err
	} else {
		return image.ID, nil
	}
}
コード例 #2
0
ファイル: openstack.go プロジェクト: LunaNode/cloug
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")
	}
}