1
0
mirror of https://github.com/lxc/incus.git synced 2026-02-05 09:46:19 +01:00

cmd/incus-user: Remove LXD mentions

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
This commit is contained in:
Stéphane Graber
2023-08-29 23:27:58 -04:00
parent da931e33d4
commit 8b704f2355
4 changed files with 33 additions and 34 deletions

View File

@@ -17,14 +17,13 @@ func main() {
// daemon command (main)
daemonCmd := cmdDaemon{}
app := daemonCmd.Command()
app.Use = "lxd-user"
app.Short = "LXD user project daemon"
app.Use = "incus-user"
app.Short = "Incus user project daemon"
app.Long = `Description:
LXD user project daemon
Incus user project daemon
This daemon is used to allow users that aren't considered to be LXD
administrators access to a personal LXD project with suitable
restrictions.
This daemon is used to allow users that aren't considered to be Incus
administrators access to a personal project with suitable restrictions.
`
app.SilenceUsage = true
app.CompletionOptions = cobra.CompletionOptions{DisableDefaultCmd: true}

View File

@@ -23,7 +23,7 @@ type cmdDaemon struct{}
func (c *cmdDaemon) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = "lxd-user"
cmd.Use = "incus-user"
cmd.RunE = c.Run
return cmd
@@ -37,28 +37,28 @@ func (c *cmdDaemon) Run(cmd *cobra.Command, args []string) error {
log.SetLevel(log.InfoLevel)
log.SetOutput(os.Stdout)
// Connect to LXD.
log.Debug("Connecting to LXD")
// Connect.
log.Debug("Connecting to the daemon")
client, err := incus.ConnectIncusUnix("", nil)
if err != nil {
return fmt.Errorf("Unable to connect to LXD: %w", err)
return fmt.Errorf("Unable to connect to the daemon: %w", err)
}
// Validate LXD configuration.
ok, err := lxdIsConfigured(client)
// Validate the configuration.
ok, err := serverIsConfigured(client)
if err != nil {
return fmt.Errorf("Failed to check LXD configuration: %w", err)
return fmt.Errorf("Failed to check the configuration: %w", err)
}
if !ok {
log.Info("Performing initial LXD configuration")
err = lxdInitialConfiguration(client)
log.Info("Performing initial configuration")
err = serverInitialConfiguration(client)
if err != nil {
return fmt.Errorf("Failed to apply initial LXD configuration: %w", err)
return fmt.Errorf("Failed to apply initial configuration: %w", err)
}
}
// Disconnect from LXD.
// Disconnect.
client.Disconnect()
// Setup the unix socket.

View File

@@ -81,15 +81,15 @@ func proxyConnection(conn *net.UnixConn) {
// Check if the user was setup.
if !shared.PathExists(filepath.Join("users", fmt.Sprintf("%d", creds.Uid))) {
log.Infof("Setting up LXD for uid %d", creds.Uid)
err := lxdSetupUser(creds.Uid)
log.Infof("Setting up for uid %d", creds.Uid)
err := serverSetupUser(creds.Uid)
if err != nil {
log.Errorf("Failed to setup new user: %v", err)
return
}
}
// Connect to LXD.
// Connect to the daemon.
unixAddr, err := net.ResolveUnixAddr("unix", shared.VarPath("unix.socket"))
if err != nil {
log.Errorf("Unable to resolve the target server: %v", err)

View File

@@ -14,15 +14,15 @@ import (
"github.com/lxc/incus/shared/api"
)
func lxdIsConfigured(client incus.InstanceServer) (bool, error) {
func serverIsConfigured(client incus.InstanceServer) (bool, error) {
// Look for networks.
networks, err := client.GetNetworkNames()
if err != nil {
return false, fmt.Errorf("Failed to list networks: %w", err)
}
if !shared.StringInSlice("lxdbr0", networks) {
// Couldn't find lxdbr0.
if !shared.StringInSlice("incusbr0", networks) {
// Couldn't find incusbr0.
return false, nil
}
@@ -40,7 +40,7 @@ func lxdIsConfigured(client incus.InstanceServer) (bool, error) {
return true, nil
}
func lxdInitialConfiguration(client incus.InstanceServer) error {
func serverInitialConfiguration(client incus.InstanceServer) error {
// Load current server config.
info, _, err := client.GetServer()
if err != nil {
@@ -73,7 +73,7 @@ func lxdInitialConfiguration(client incus.InstanceServer) error {
// Check if zsys.
poolName, _ := shared.RunCommand("zpool", "get", "-H", "-o", "value", "name", "rpool")
if strings.TrimSpace(poolName) == "rpool" {
pool.Config["source"] = "rpool/lxd"
pool.Config["source"] = "rpool/incus"
}
} else {
// Fallback to dir backend.
@@ -109,11 +109,11 @@ func lxdInitialConfiguration(client incus.InstanceServer) error {
}
if !found {
// Create lxdbr0.
// Create incusbr0.
network := api.NetworksPost{}
network.Config = map[string]string{}
network.Type = "bridge"
network.Name = "lxdbr0"
network.Name = "incusbr0"
err := client.CreateNetwork(network)
if err != nil {
@@ -123,7 +123,7 @@ func lxdInitialConfiguration(client incus.InstanceServer) error {
// Add to default profile in default project.
profile.Devices["eth0"] = map[string]string{
"type": "nic",
"network": "lxdbr0",
"network": "incusbr0",
"name": "eth0",
}
}
@@ -137,9 +137,9 @@ func lxdInitialConfiguration(client incus.InstanceServer) error {
return nil
}
func lxdSetupUser(uid uint32) error {
func serverSetupUser(uid uint32) error {
projectName := fmt.Sprintf("user-%d", uid)
networkName := fmt.Sprintf("lxdbr-%d", uid)
networkName := fmt.Sprintf("incusbr-%d", uid)
userPath := filepath.Join("users", fmt.Sprintf("%d", uid))
// User account.
@@ -171,10 +171,10 @@ func lxdSetupUser(uid uint32) error {
return fmt.Errorf("Failed to generate user certificate: %w", err)
}
// Connect to LXD.
// Connect to the daemon.
client, err := incus.ConnectIncusUnix("", nil)
if err != nil {
return fmt.Errorf("Unable to connect to LXD: %w", err)
return fmt.Errorf("Unable to connect to the daemon: %w", err)
}
_, _, _ = client.GetServer()
@@ -225,7 +225,7 @@ func lxdSetupUser(uid uint32) error {
// Add the certificate to the trust store.
err = client.CreateCertificate(api.CertificatesPost{
CertificatePut: api.CertificatePut{
Name: fmt.Sprintf("lxd-user-%d", uid),
Name: fmt.Sprintf("incus-user-%d", uid),
Type: "client",
Restricted: true,
Projects: []string{projectName},
@@ -252,7 +252,7 @@ func lxdSetupUser(uid uint32) error {
// Setup default profile.
err = client.UseProject(projectName).UpdateProfile("default", api.ProfilePut{
Description: "Default LXD profile",
Description: "Default Incus profile",
Config: map[string]string{
"raw.idmap": fmt.Sprintf("uid %s %s\ngid %s %s", pw[2], pw[2], pw[3], pw[3]),
},