orchard create vm: introduce --random-serial command-line argument (#248)
This commit is contained in:
parent
61d7d34ea4
commit
4794f2a5b6
|
|
@ -23,6 +23,7 @@ var username string
|
|||
var password string
|
||||
var resources map[string]string
|
||||
var labels map[string]string
|
||||
var randomSerial bool
|
||||
var restartPolicy string
|
||||
var startupScript string
|
||||
var hostDirsRaw []string
|
||||
|
|
@ -50,6 +51,8 @@ func newCreateVMCommand() *cobra.Command {
|
|||
"resources to request for this VM")
|
||||
command.PersistentFlags().StringToStringVar(&labels, "labels", map[string]string{},
|
||||
"labels required by this VM")
|
||||
command.PersistentFlags().BoolVar(&randomSerial, "random-serial", false,
|
||||
"generate a new random serial number if this is a macOS VM (no-op for Linux VMs)")
|
||||
command.PersistentFlags().StringVar(&restartPolicy, "restart-policy", string(v1.RestartPolicyNever),
|
||||
fmt.Sprintf("restart policy for this VM: specify %q to never restart or %q "+
|
||||
"to only restart when the VM fails", v1.RestartPolicyNever, v1.RestartPolicyOnFailure))
|
||||
|
|
@ -91,16 +94,17 @@ func runCreateVM(cmd *cobra.Command, args []string) error {
|
|||
Meta: v1.Meta{
|
||||
Name: name,
|
||||
},
|
||||
Image: image,
|
||||
CPU: cpu,
|
||||
Memory: memory,
|
||||
NetSoftnet: netSoftnet,
|
||||
NetBridged: netBridged,
|
||||
Headless: headless,
|
||||
Username: username,
|
||||
Password: password,
|
||||
Labels: labels,
|
||||
HostDirs: hostDirs,
|
||||
Image: image,
|
||||
CPU: cpu,
|
||||
Memory: memory,
|
||||
NetSoftnet: netSoftnet,
|
||||
NetBridged: netBridged,
|
||||
Headless: headless,
|
||||
Username: username,
|
||||
Password: password,
|
||||
RandomSerial: randomSerial,
|
||||
Labels: labels,
|
||||
HostDirs: hostDirs,
|
||||
}
|
||||
|
||||
// Convert resources
|
||||
|
|
|
|||
|
|
@ -95,15 +95,18 @@ func runGetVM(cmd *cobra.Command, args []string) error {
|
|||
table.AddRow("Restarted", restartedAtInfo)
|
||||
table.AddRow("Restart count", vm.RestartCount)
|
||||
|
||||
var resourcesInfo string
|
||||
if len(vm.Resources) != 0 {
|
||||
resourceDescriptions := lo.MapToSlice(vm.Resources, func(key string, value uint64) string {
|
||||
return fmt.Sprintf("%s: %d", key, value)
|
||||
})
|
||||
resourcesInfo = strings.Join(resourceDescriptions, "\n")
|
||||
}
|
||||
resourcesInfo := strings.Join(lo.MapToSlice(vm.Resources, func(key string, value uint64) string {
|
||||
return fmt.Sprintf("%s: %d", key, value)
|
||||
}), "\n")
|
||||
table.AddRow("Resources", nonEmptyOrNone(resourcesInfo))
|
||||
|
||||
labelsInfo := strings.Join(lo.MapToSlice(vm.Labels, func(key string, value string) string {
|
||||
return fmt.Sprintf("%s: %s", key, value)
|
||||
}), "\n")
|
||||
table.AddRow("Labels", nonEmptyOrNone(labelsInfo))
|
||||
|
||||
table.AddRow("Random serial", vm.RandomSerial)
|
||||
|
||||
var hostDirsInfo string
|
||||
if len(vm.HostDirs) != 0 {
|
||||
hostDirsDescriptions := lo.Map(vm.HostDirs, func(hostDir v1.HostDir, index int) string {
|
||||
|
|
|
|||
|
|
@ -222,6 +222,13 @@ func (vm *VM) cloneAndConfigure(ctx context.Context) error {
|
|||
}
|
||||
}
|
||||
|
||||
if vm.Resource.RandomSerial {
|
||||
_, _, err = tart.Tart(ctx, vm.logger, "set", "--random-serial", vm.id())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,10 @@ type VM struct {
|
|||
RestartedAt time.Time `json:"restarted_at,omitempty"`
|
||||
RestartCount uint64 `json:"restart_count,omitempty"`
|
||||
|
||||
// RandomSerial controls whether the worker will run the
|
||||
// "tart set --random-serial" when instantiating this VM.
|
||||
RandomSerial bool `json:"randomSerial,omitempty"`
|
||||
|
||||
// UID is a useful field for avoiding data races within a single Name.
|
||||
//
|
||||
// It is populated by the Controller when receiving a POST request.
|
||||
|
|
|
|||
Loading…
Reference in New Issue