Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service add and service list #355

Merged
merged 8 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/microcloud/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *cmdAdd) Run(cmd *cobra.Command, args []string) error {
}

// Ask to reuse existing clusters.
err = cfg.askClustered(s)
err = cfg.askClustered(s, services)
if err != nil {
return err
}
Expand Down
9 changes: 2 additions & 7 deletions cmd/microcloud/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,13 +1230,8 @@ func (c *initConfig) askCephNetwork(sh *service.Handler) error {
// If a service is already initialized on some systems, we will offer to add the remaining systems, or skip that service.
// In auto setup, we will expect no initialized services so that we can be opinionated about how we configure the cluster without user input.
// This works by deleting the record for the service from the `service.Handler`, thus ignoring it for the remainder of the setup.
func (c *initConfig) askClustered(s *service.Handler) error {
expectedServices := make(map[types.ServiceType]struct{}, len(s.Services))
for k := range s.Services {
expectedServices[k] = struct{}{}
}

for serviceType := range expectedServices {
func (c *initConfig) askClustered(s *service.Handler, expectedServices []types.ServiceType) error {
for _, serviceType := range expectedServices {
for name, info := range c.state {
_, newSystem := c.systems[name]
if !newSystem {
Expand Down
3 changes: 3 additions & 0 deletions cmd/microcloud/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ EOF`)
var cmdRemove = cmdRemove{common: &commonCmd}
app.AddCommand(cmdRemove.Command())

var cmdService = cmdServices{common: &commonCmd}
app.AddCommand(cmdService.Command())

var cmdPeers = cmdClusterMembers{common: &commonCmd}
app.AddCommand(cmdPeers.Command())

Expand Down
55 changes: 50 additions & 5 deletions cmd/microcloud/main_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (c *initConfig) RunInteractive(cmd *cobra.Command, args []string) error {
}

// Ask to reuse existing clusters.
err = c.askClustered(s)
err = c.askClustered(s, services)
if err != nil {
return err
}
Expand Down Expand Up @@ -952,12 +952,57 @@ func (c *initConfig) setupCluster(s *service.Handler) error {

if !shared.ValueInSlice(profile.Name, profiles) {
err = lxdClient.CreateProfile(profile)
if err != nil {
return err
}
} else {
err = lxdClient.UpdateProfile(profile.Name, profile.ProfilePut, "")
}
// Ensure any pre-existing devices and config are carried over to the new profile, unless we are managing them.
existingProfile, _, err := lxdClient.GetProfile("default")
if err != nil {
return err
}

if err != nil {
return err
askConflictingConfig := []string{}
askConflictingDevices := []string{}
for k, v := range profile.Config {
_, ok := existingProfile.Config[k]
if !ok {
masnax marked this conversation as resolved.
Show resolved Hide resolved
existingProfile.Config[k] = v
} else {
askConflictingConfig = append(askConflictingConfig, k)
}
}

for k, v := range profile.Devices {
_, ok := existingProfile.Devices[k]
masnax marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
existingProfile.Devices[k] = v
} else {
askConflictingDevices = append(askConflictingDevices, k)
}
}

if !c.autoSetup && len(askConflictingConfig) > 0 || len(askConflictingDevices) > 0 {
replace, err := c.asker.AskBool("Replace existing default profile configuration? (yes/no) [default=no]: ", "no")
if err != nil {
return err
}

if replace {
for _, key := range askConflictingConfig {
existingProfile.Config[key] = profile.Config[key]
}

for _, key := range askConflictingDevices {
existingProfile.Devices[key] = profile.Devices[key]
}
}
}

err = lxdClient.UpdateProfile(profile.Name, existingProfile.Writable(), "")
if err != nil {
return err
}
}
}

Expand Down
Loading
Loading