Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Issue - nanovms#559

Able to create instance on Openstack.

* accepting volume size via config. I have kept default size to 1GB.

* Adding proper keys to be used while assigning values.
  • Loading branch information
chaitanya-baraskar authored Oct 9, 2020
1 parent 4bbf227 commit 467413f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
27 changes: 14 additions & 13 deletions lepton/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ type ProviderConfig struct {

// RunConfig provides runtime details
type RunConfig struct {
Imagename string // FIXME: fullpath? of image
BaseName string // FIXME: basename of image only
Ports []int
GdbPort int
CPUs int // number of cpus
Verbose bool
Memory string
Bridged bool
TapName string
Accel bool
UDP bool // enable UDP
OnPrem bool // true if in a multi-instance/tenant on-prem env
Mounts []string
Imagename string // FIXME: fullpath? of image
BaseName string // FIXME: basename of image only
Ports []int
GdbPort int
CPUs int // number of cpus
Verbose bool
Memory string
Bridged bool
TapName string
Accel bool
UDP bool // enable UDP
OnPrem bool // true if in a multi-instance/tenant on-prem env
Mounts []string
VolumeSizeInGb int //This option is only for openstack.
}

// RuntimeConfig constructs runtime config
Expand Down
49 changes: 41 additions & 8 deletions lepton/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lepton
import (
"errors"
"fmt"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume"
"os"
"strings"

Expand Down Expand Up @@ -306,24 +307,56 @@ func (o *OpenStack) CreateInstance(ctx *Context) error {
fmt.Println(err)
}

fmt.Printf("deploying flavorID %s", flavorID)
fmt.Printf("\nDeploying flavorID %s", flavorID)

server, err := servers.Create(client, servers.CreateOpts{
var createOpts servers.CreateOptsBuilder
createOpts = &servers.CreateOpts{
Name: imageName,
FlavorRef: flavorID,
ImageRef: imageID,
}).Extract()
if err != nil {
fmt.Println(err)
FlavorRef: flavorID,
AdminPass: "TODO",
}

fmt.Printf("%+v", server)
var volumeSize int
if ctx.config.RunConfig.VolumeSizeInGb == 0 {
volumeSize = 1
} else {
volumeSize = ctx.config.RunConfig.VolumeSizeInGb
}

fmt.Println("un-implemented")
createOpts = o.addBootFromVolumeParams(createOpts, imageID, volumeSize)
server, err := servers.Create(client, createOpts).Extract()

if err != nil {
exitWithError(err.Error())
}

fmt.Printf("\n Instance Created Successfully. ID ---> %s \n", server.ID)
return nil
}

func (o *OpenStack) addBootFromVolumeParams(
createOpts servers.CreateOptsBuilder,
imageID string,
rootDiskSizeGb int,
) *bootfromvolume.CreateOptsExt {
blockDevice := bootfromvolume.BlockDevice{
BootIndex: 0,
DeleteOnTermination: true,
DestinationType: "volume",
SourceType: bootfromvolume.SourceType("image"),
UUID: imageID,
}
if rootDiskSizeGb > 0 {
blockDevice.VolumeSize = rootDiskSizeGb
}

return &bootfromvolume.CreateOptsExt{
CreateOptsBuilder: createOpts,
BlockDevice: []bootfromvolume.BlockDevice{blockDevice},
}
}

// GetInstances return all instances on OpenStack
// TODO
func (o *OpenStack) GetInstances(ctx *Context) ([]CloudInstance, error) {
Expand Down

0 comments on commit 467413f

Please sign in to comment.