Skip to content

Commit

Permalink
cmd/incus/admin: Translate all strings
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Oct 5, 2023
1 parent a5eead2 commit 4d29f25
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 157 deletions.
50 changes: 25 additions & 25 deletions cmd/incus/admin_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,58 +51,58 @@ func (c *cmdAdminInit) Command() *cobra.Command {
init --dump
`
cmd.RunE = c.Run
cmd.Flags().BoolVar(&c.flagAuto, "auto", false, "Automatic (non-interactive) mode")
cmd.Flags().BoolVar(&c.flagMinimal, "minimal", false, "Minimal configuration (non-interactive)")
cmd.Flags().BoolVar(&c.flagPreseed, "preseed", false, "Pre-seed mode, expects YAML config from stdin")
cmd.Flags().BoolVar(&c.flagDump, "dump", false, "Dump YAML config to stdout")

cmd.Flags().StringVar(&c.flagNetworkAddress, "network-address", "", "Address to bind to (default: none)"+"``")
cmd.Flags().IntVar(&c.flagNetworkPort, "network-port", -1, fmt.Sprintf("Port to bind to (default: %d)"+"``", ports.HTTPSDefaultPort))
cmd.Flags().StringVar(&c.flagStorageBackend, "storage-backend", "", "Storage backend to use (btrfs, dir, lvm or zfs, default: dir)"+"``")
cmd.Flags().StringVar(&c.flagStorageDevice, "storage-create-device", "", "Setup device based storage using DEVICE"+"``")
cmd.Flags().IntVar(&c.flagStorageLoopSize, "storage-create-loop", -1, "Setup loop based storage with SIZE in GiB"+"``")
cmd.Flags().StringVar(&c.flagStoragePool, "storage-pool", "", "Storage pool to use or create"+"``")
cmd.Flags().BoolVar(&c.flagAuto, "auto", false, i18n.G("Automatic (non-interactive) mode"))
cmd.Flags().BoolVar(&c.flagMinimal, "minimal", false, i18n.G("Minimal configuration (non-interactive)"))
cmd.Flags().BoolVar(&c.flagPreseed, "preseed", false, i18n.G("Pre-seed mode, expects YAML config from stdin"))
cmd.Flags().BoolVar(&c.flagDump, "dump", false, i18n.G("Dump YAML config to stdout"))

cmd.Flags().StringVar(&c.flagNetworkAddress, "network-address", "", i18n.G("Address to bind to (default: none)")+"``")
cmd.Flags().IntVar(&c.flagNetworkPort, "network-port", -1, fmt.Sprintf(i18n.G("Port to bind to (default: %d)")+"``", ports.HTTPSDefaultPort))
cmd.Flags().StringVar(&c.flagStorageBackend, "storage-backend", "", i18n.G("Storage backend to use (btrfs, dir, lvm or zfs, default: dir)")+"``")
cmd.Flags().StringVar(&c.flagStorageDevice, "storage-create-device", "", i18n.G("Setup device based storage using DEVICE")+"``")
cmd.Flags().IntVar(&c.flagStorageLoopSize, "storage-create-loop", -1, i18n.G("Setup loop based storage with SIZE in GiB")+"``")
cmd.Flags().StringVar(&c.flagStoragePool, "storage-pool", "", i18n.G("Storage pool to use or create")+"``")

return cmd
}

func (c *cmdAdminInit) Run(cmd *cobra.Command, args []string) error {
// Quick checks.
if c.flagAuto && c.flagPreseed {
return fmt.Errorf("Can't use --auto and --preseed together")
return fmt.Errorf(i18n.G("Can't use --auto and --preseed together"))
}

if c.flagMinimal && c.flagPreseed {
return fmt.Errorf("Can't use --minimal and --preseed together")
return fmt.Errorf(i18n.G("Can't use --minimal and --preseed together"))
}

if c.flagMinimal && c.flagAuto {
return fmt.Errorf("Can't use --minimal and --auto together")
return fmt.Errorf(i18n.G("Can't use --minimal and --auto together"))
}

if !c.flagAuto && (c.flagNetworkAddress != "" || c.flagNetworkPort != -1 ||
c.flagStorageBackend != "" || c.flagStorageDevice != "" ||
c.flagStorageLoopSize != -1 || c.flagStoragePool != "") {
return fmt.Errorf("Configuration flags require --auto")
return fmt.Errorf(i18n.G("Configuration flags require --auto"))
}

if c.flagDump && (c.flagAuto || c.flagMinimal ||
c.flagPreseed || c.flagNetworkAddress != "" ||
c.flagNetworkPort != -1 || c.flagStorageBackend != "" ||
c.flagStorageDevice != "" || c.flagStorageLoopSize != -1 ||
c.flagStoragePool != "") {
return fmt.Errorf("Can't use --dump with other flags")
return fmt.Errorf(i18n.G("Can't use --dump with other flags"))
}

// Connect to the daemon
d, err := incus.ConnectIncusUnix("", nil)
if err != nil {
return fmt.Errorf("Failed to connect to local daemon: %w", err)
return fmt.Errorf(i18n.G("Failed to connect to local daemon: %w"), err)
}

server, _, err := d.GetServer()
if err != nil {
return fmt.Errorf("Failed to connect to get server info: %w", err)
return fmt.Errorf(i18n.G("Failed to connect to get server info: %w"), err)
}

// Dump mode
Expand Down Expand Up @@ -146,7 +146,7 @@ func (c *cmdAdminInit) Run(cmd *cobra.Command, args []string) error {
// If yes then read cluster certificate from file
if config.Cluster != nil && config.Cluster.ClusterCertificatePath != "" {
if !util.PathExists(config.Cluster.ClusterCertificatePath) {
return fmt.Errorf("Path %s doesn't exist", config.Cluster.ClusterCertificatePath)
return fmt.Errorf(i18n.G("Path %s doesn't exist"), config.Cluster.ClusterCertificatePath)
}

content, err := os.ReadFile(config.Cluster.ClusterCertificatePath)
Expand All @@ -161,7 +161,7 @@ func (c *cmdAdminInit) Run(cmd *cobra.Command, args []string) error {
if config.Cluster != nil && config.Cluster.ClusterToken != "" {
joinToken, err := internalUtil.JoinTokenDecode(config.Cluster.ClusterToken)
if err != nil {
return fmt.Errorf("Invalid cluster join token: %w", err)
return fmt.Errorf(i18n.G("Invalid cluster join token: %w"), err)
}

// Set server name from join token
Expand All @@ -176,13 +176,13 @@ func (c *cmdAdminInit) Run(cmd *cobra.Command, args []string) error {
// Cluster certificate
cert, err := localtls.GetRemoteCertificate(fmt.Sprintf("https://%s", config.Cluster.ClusterAddress), version.UserAgent)
if err != nil {
fmt.Printf("Error connecting to existing cluster member %q: %v\n", clusterAddress, err)
fmt.Printf(i18n.G("Error connecting to existing cluster member %q: %v")+"\n", clusterAddress, err)
continue
}

certDigest := localtls.CertFingerprint(cert)
if joinToken.Fingerprint != certDigest {
return fmt.Errorf("Certificate fingerprint mismatch between join token and cluster member %q", clusterAddress)
return fmt.Errorf(i18n.G("Certificate fingerprint mismatch between join token and cluster member %q"), clusterAddress)
}

config.Cluster.ClusterCertificate = string(pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}))
Expand All @@ -191,7 +191,7 @@ func (c *cmdAdminInit) Run(cmd *cobra.Command, args []string) error {
}

if config.Cluster.ClusterCertificate == "" {
return fmt.Errorf("Unable to connect to any of the cluster members specified in join token")
return fmt.Errorf(i18n.G("Unable to connect to any of the cluster members specified in join token"))
}
}

Expand All @@ -212,12 +212,12 @@ func (c *cmdAdminInit) Run(cmd *cobra.Command, args []string) error {

op, err := d.UpdateCluster(config.Cluster.ClusterPut, "")
if err != nil {
return fmt.Errorf("Failed to join cluster: %w", err)
return fmt.Errorf(i18n.G("Failed to join cluster: %w"), err)
}

err = op.Wait()
if err != nil {
return fmt.Errorf("Failed to join cluster: %w", err)
return fmt.Errorf(i18n.G("Failed to join cluster: %w"), err)
}

return nil
Expand Down
17 changes: 9 additions & 8 deletions cmd/incus/admin_init_auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"

"github.com/lxc/incus/client"
"github.com/lxc/incus/internal/i18n"
"github.com/lxc/incus/internal/linux"
"github.com/lxc/incus/internal/ports"
internalUtil "github.com/lxc/incus/internal/util"
Expand All @@ -18,36 +19,36 @@ import (
func (c *cmdAdminInit) RunAuto(cmd *cobra.Command, args []string, d incus.InstanceServer, server *api.Server) (*api.InitPreseed, error) {
// Quick checks.
if c.flagStorageBackend != "" && !util.ValueInSlice(c.flagStorageBackend, []string{"dir", "btrfs", "lvm", "zfs"}) {
return nil, fmt.Errorf("The requested backend '%s' isn't supported by init", c.flagStorageBackend)
return nil, fmt.Errorf(i18n.G("The requested backend '%s' isn't supported by init"), c.flagStorageBackend)
}

if c.flagStorageBackend != "" && !util.ValueInSlice(c.flagStorageBackend, linux.AvailableStorageDrivers(internalUtil.VarPath(), server.Environment.StorageSupportedDrivers, internalUtil.PoolTypeAny)) {
return nil, fmt.Errorf("The requested backend '%s' isn't available on your system (missing tools)", c.flagStorageBackend)
return nil, fmt.Errorf(i18n.G("The requested backend '%s' isn't available on your system (missing tools)"), c.flagStorageBackend)
}

if c.flagStorageBackend == "dir" || c.flagStorageBackend == "" {
if c.flagStorageLoopSize != -1 || c.flagStorageDevice != "" || c.flagStoragePool != "" {
return nil, fmt.Errorf("None of --storage-pool, --storage-create-device or --storage-create-loop may be used with the 'dir' backend")
return nil, fmt.Errorf(i18n.G("None of --storage-pool, --storage-create-device or --storage-create-loop may be used with the 'dir' backend"))
}
} else {
if c.flagStorageLoopSize != -1 && c.flagStorageDevice != "" {
return nil, fmt.Errorf("Only one of --storage-create-device or --storage-create-loop can be specified")
return nil, fmt.Errorf(i18n.G("Only one of --storage-create-device or --storage-create-loop can be specified"))
}
}

if c.flagNetworkAddress == "" {
if c.flagNetworkPort != -1 {
return nil, fmt.Errorf("--network-port can't be used without --network-address")
return nil, fmt.Errorf(i18n.G("--network-port can't be used without --network-address"))
}
}

storagePools, err := d.GetStoragePoolNames()
if err != nil {
return nil, fmt.Errorf("Failed to retrieve list of storage pools: %w", err)
return nil, fmt.Errorf(i18n.G("Failed to retrieve list of storage pools: %w"), err)
}

if len(storagePools) > 0 && (c.flagStorageBackend != "" || c.flagStorageDevice != "" || c.flagStorageLoopSize != -1 || c.flagStoragePool != "") {
return nil, fmt.Errorf("Storage has already been configured")
return nil, fmt.Errorf(i18n.G("Storage has already been configured"))
}

// Defaults
Expand Down Expand Up @@ -111,7 +112,7 @@ func (c *cmdAdminInit) RunAuto(cmd *cobra.Command, args []string, d incus.Instan
// Network configuration
networks, err := d.GetNetworks()
if err != nil {
return nil, fmt.Errorf("Failed to retrieve list of networks: %w", err)
return nil, fmt.Errorf(i18n.G("Failed to retrieve list of networks: %w"), err)
}

// Extract managed networks
Expand Down
13 changes: 7 additions & 6 deletions cmd/incus/admin_init_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
yaml "gopkg.in/yaml.v2"

"github.com/lxc/incus/client"
"github.com/lxc/incus/internal/i18n"
"github.com/lxc/incus/shared/api"
)

func (c *cmdAdminInit) RunDump(d incus.InstanceServer) error {
currentServer, _, err := d.GetServer()
if err != nil {
return fmt.Errorf("Failed to retrieve current server configuration: %w", err)
return fmt.Errorf(i18n.G("Failed to retrieve current server configuration: %w"), err)
}

var config api.InitLocalPreseed
Expand All @@ -24,7 +25,7 @@ func (c *cmdAdminInit) RunDump(d incus.InstanceServer) error {
// projects at this time.
networks, err := d.UseProject("default").GetNetworks()
if err != nil {
return fmt.Errorf("Failed to retrieve current server network configuration for project %q: %w", "default", err)
return fmt.Errorf(i18n.G("Failed to retrieve current server network configuration for project %q: %w"), "default", err)
}

for _, network := range networks {
Expand All @@ -45,7 +46,7 @@ func (c *cmdAdminInit) RunDump(d incus.InstanceServer) error {

storagePools, err := d.GetStoragePools()
if err != nil {
return fmt.Errorf("Failed to retrieve current server configuration: %w", err)
return fmt.Errorf(i18n.G("Failed to retrieve current server configuration: %w"), err)
}

for _, storagePool := range storagePools {
Expand All @@ -60,7 +61,7 @@ func (c *cmdAdminInit) RunDump(d incus.InstanceServer) error {

profiles, err := d.GetProfiles()
if err != nil {
return fmt.Errorf("Failed to retrieve current server configuration: %w", err)
return fmt.Errorf(i18n.G("Failed to retrieve current server configuration: %w"), err)
}

for _, profile := range profiles {
Expand All @@ -75,7 +76,7 @@ func (c *cmdAdminInit) RunDump(d incus.InstanceServer) error {

projects, err := d.GetProjects()
if err != nil {
return fmt.Errorf("Failed to retrieve current server configuration: %w", err)
return fmt.Errorf(i18n.G("Failed to retrieve current server configuration: %w"), err)
}

for _, project := range projects {
Expand All @@ -89,7 +90,7 @@ func (c *cmdAdminInit) RunDump(d incus.InstanceServer) error {

out, err := yaml.Marshal(config)
if err != nil {
return fmt.Errorf("Failed to retrieve current server configuration: %w", err)
return fmt.Errorf(i18n.G("Failed to retrieve current server configuration: %w"), err)
}

fmt.Printf("%s\n", out)
Expand Down
Loading

0 comments on commit 4d29f25

Please sign in to comment.