mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
@ -38,7 +38,6 @@ func init() {
|
|||||||
})
|
})
|
||||||
flags := initCmd.Flags()
|
flags := initCmd.Flags()
|
||||||
cfg := registry.PodmanConfig()
|
cfg := registry.PodmanConfig()
|
||||||
|
|
||||||
cpusFlagName := "cpus"
|
cpusFlagName := "cpus"
|
||||||
flags.Uint64Var(
|
flags.Uint64Var(
|
||||||
&initOpts.CPUS,
|
&initOpts.CPUS,
|
||||||
@ -69,6 +68,13 @@ func init() {
|
|||||||
"now", false,
|
"now", false,
|
||||||
"Start machine now",
|
"Start machine now",
|
||||||
)
|
)
|
||||||
|
timezoneFlagName := "timezone"
|
||||||
|
defaultTz := cfg.TZ()
|
||||||
|
if len(defaultTz) < 1 {
|
||||||
|
defaultTz = "local"
|
||||||
|
}
|
||||||
|
flags.StringVar(&initOpts.TimeZone, timezoneFlagName, defaultTz, "Set timezone")
|
||||||
|
_ = initCmd.RegisterFlagCompletionFunc(timezoneFlagName, completion.AutocompleteDefault)
|
||||||
|
|
||||||
ImagePathFlagName := "image-path"
|
ImagePathFlagName := "image-path"
|
||||||
flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.Machine.Image, "Path to qcow image")
|
flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.Machine.Image, "Path to qcow image")
|
||||||
|
@ -55,6 +55,12 @@ Memory (in MB).
|
|||||||
|
|
||||||
Start the virtual machine immediately after it has been initialized.
|
Start the virtual machine immediately after it has been initialized.
|
||||||
|
|
||||||
|
#### **--timezone**
|
||||||
|
|
||||||
|
Set the timezone for the machine and containers. Valid values are `local` or
|
||||||
|
a `timezone` such as `America/Chicago`. A value of `local`, which is the default,
|
||||||
|
means to use the timezone of the machine host.
|
||||||
|
|
||||||
#### **--help**
|
#### **--help**
|
||||||
|
|
||||||
Print usage statement.
|
Print usage statement.
|
||||||
|
@ -21,6 +21,7 @@ type InitOptions struct {
|
|||||||
IsDefault bool
|
IsDefault bool
|
||||||
Memory uint64
|
Memory uint64
|
||||||
Name string
|
Name string
|
||||||
|
TimeZone string
|
||||||
URI url.URL
|
URI url.URL
|
||||||
Username string
|
Username string
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -44,6 +45,7 @@ func getNodeGrp(grpName string) NodeGroup {
|
|||||||
type DynamicIgnition struct {
|
type DynamicIgnition struct {
|
||||||
Name string
|
Name string
|
||||||
Key string
|
Key string
|
||||||
|
TimeZone string
|
||||||
VMName string
|
VMName string
|
||||||
WritePath string
|
WritePath string
|
||||||
}
|
}
|
||||||
@ -76,6 +78,37 @@ func NewIgnitionFile(ign DynamicIgnition) error {
|
|||||||
Links: getLinks(ign.Name),
|
Links: getLinks(ign.Name),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add or set the time zone for the machine
|
||||||
|
if len(ign.TimeZone) > 0 {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
tz string
|
||||||
|
)
|
||||||
|
// local means the same as the host
|
||||||
|
// lookup where it is pointing to on the host
|
||||||
|
if ign.TimeZone == "local" {
|
||||||
|
tz, err = getLocalTimeZone()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tz = ign.TimeZone
|
||||||
|
}
|
||||||
|
tzLink := Link{
|
||||||
|
Node: Node{
|
||||||
|
Group: getNodeGrp("root"),
|
||||||
|
Path: "/etc/localtime",
|
||||||
|
Overwrite: boolToPtr(false),
|
||||||
|
User: getNodeUsr("root"),
|
||||||
|
},
|
||||||
|
LinkEmbedded1: LinkEmbedded1{
|
||||||
|
Hard: boolToPtr(false),
|
||||||
|
Target: filepath.Join("/usr/share/zoneinfo", tz),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
ignStorage.Links = append(ignStorage.Links, tzLink)
|
||||||
|
}
|
||||||
|
|
||||||
// ready is a unit file that sets up the virtual serial device
|
// ready is a unit file that sets up the virtual serial device
|
||||||
// where when the VM is done configuring, it will send an ack
|
// where when the VM is done configuring, it will send an ack
|
||||||
// so a listening host knows it can being interacting with it
|
// so a listening host knows it can being interacting with it
|
||||||
|
16
pkg/machine/ignition_darwin.go
Normal file
16
pkg/machine/ignition_darwin.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//+build darwin
|
||||||
|
|
||||||
|
package machine
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getLocalTimeZone() (string, error) {
|
||||||
|
tzPath, err := os.Readlink("/etc/localtime")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return strings.TrimPrefix(tzPath, "/var/db/timezone/zoneinfo"), nil
|
||||||
|
}
|
15
pkg/machine/ignition_linux.go
Normal file
15
pkg/machine/ignition_linux.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package machine
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getLocalTimeZone() (string, error) {
|
||||||
|
output, err := exec.Command("timedatectl", "show", "--property=Timezone").Output()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
// Remove prepended field and the newline
|
||||||
|
return strings.TrimPrefix(strings.TrimSuffix(string(output), "\n"), "Timezone="), nil
|
||||||
|
}
|
@ -145,6 +145,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) error {
|
|||||||
// Get image as usual
|
// Get image as usual
|
||||||
v.ImageStream = opts.ImagePath
|
v.ImageStream = opts.ImagePath
|
||||||
dd, err := machine.NewFcosDownloader(vmtype, v.Name, opts.ImagePath)
|
dd, err := machine.NewFcosDownloader(vmtype, v.Name, opts.ImagePath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -235,6 +236,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) error {
|
|||||||
Name: opts.Username,
|
Name: opts.Username,
|
||||||
Key: key,
|
Key: key,
|
||||||
VMName: v.Name,
|
VMName: v.Name,
|
||||||
|
TimeZone: opts.TimeZone,
|
||||||
WritePath: v.IgnitionFilePath,
|
WritePath: v.IgnitionFilePath,
|
||||||
}
|
}
|
||||||
return machine.NewIgnitionFile(ign)
|
return machine.NewIgnitionFile(ign)
|
||||||
|
Reference in New Issue
Block a user