mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-19 16:36:52 +02:00
Resources support (#63)
* Resources support * Ability to provide VM and worker resources via the CLI * orchard dev: always listen on :6120 * orchard dev: support --resources * REST API: provide resource defaults when creating VM * OpenAPI: document "resources" field * orchard dev: serve Swagger API documentation on /v1/ * Integration guide
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
package create
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/cirruslabs/orchard/pkg/client"
|
||||
v1 "github.com/cirruslabs/orchard/pkg/resource/v1"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var ErrVMFailed = errors.New("failed to create VM")
|
||||
|
||||
var image string
|
||||
var cpu uint64
|
||||
var memory uint64
|
||||
var softnet bool
|
||||
var headless bool
|
||||
var stringToStringResources map[string]string
|
||||
|
||||
func newCreateVMCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
@@ -25,6 +30,8 @@ func newCreateVMCommand() *cobra.Command {
|
||||
command.PersistentFlags().Uint64Var(&memory, "memory", 8*1024, "megabytes of memory to use")
|
||||
command.PersistentFlags().BoolVar(&softnet, "softnet", false, "whether to use Softnet network isolation")
|
||||
command.PersistentFlags().BoolVar(&headless, "headless", true, "whether to run without graphics")
|
||||
command.PersistentFlags().StringToStringVar(&stringToStringResources, "resources", map[string]string{},
|
||||
"resources to request for this VM")
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -32,6 +39,12 @@ func newCreateVMCommand() *cobra.Command {
|
||||
func runCreateVM(cmd *cobra.Command, args []string) error {
|
||||
name := args[0]
|
||||
|
||||
// Convert resources
|
||||
resources, err := v1.NewResourcesFromStringToString(stringToStringResources)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrVMFailed, err)
|
||||
}
|
||||
|
||||
client, err := client.New()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -41,10 +54,11 @@ func runCreateVM(cmd *cobra.Command, args []string) error {
|
||||
Meta: v1.Meta{
|
||||
Name: name,
|
||||
},
|
||||
Image: image,
|
||||
CPU: cpu,
|
||||
Memory: memory,
|
||||
Softnet: softnet,
|
||||
Headless: headless,
|
||||
Image: image,
|
||||
CPU: cpu,
|
||||
Memory: memory,
|
||||
Softnet: softnet,
|
||||
Headless: headless,
|
||||
Resources: resources,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user