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

Add service list and service add #260

Closed
wants to merge 8 commits into from
83 changes: 57 additions & 26 deletions cmd/microcloud/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,38 @@ func (c *CmdControl) askDisks(sh *service.Handler, systems map[string]InitSystem
systems[peer] = system
}

wantsDisks := true
if !autoSetup && foundDisks {
wantsDisks, err = c.asker.AskBool("Would you like to set up local storage? (yes/no) [default=yes]: ", "yes")
if err != nil {
return err
}
lxd := sh.Services[types.LXD].(*service.LXDService)
client, err := lxd.Client(context.Background(), "")
if err != nil {
return err
}

if !foundDisks {
wantsDisks = false
storagePools, err := client.GetStoragePoolNames()
if err != nil {
return err
}

lxd := sh.Services[types.LXD].(*service.LXDService)
if wantsDisks {
c.askRetry("Retry selecting disks?", autoSetup, func() error {
return askLocalPool(systems, autoSetup, wipeAllDisks, *lxd)
})
wantsDisks := true
if !shared.ValueInSlice[string](lxd.DefaultZFSStoragePool().Name, storagePools) {
if !autoSetup && foundDisks {
wantsDisks, err = c.asker.AskBool("Would you like to set up local storage? (yes/no) [default=yes]: ", "yes")
if err != nil {
return err
}
}

if !foundDisks {
wantsDisks = false
}

if wantsDisks {
c.askRetry("Retry selecting disks?", autoSetup, func() error {
return askLocalPool(systems, autoSetup, wipeAllDisks, *lxd)
})
}
}

if sh.Services[types.MicroCeph] != nil {
if sh.Services[types.MicroCeph] != nil && !shared.ValueInSlice[string](lxd.DefaultCephStoragePool().Name, storagePools) {
availableDisks := map[string][]api.ResourcesStorageDisk{}
for peer, system := range systems {
if len(system.AvailableDisks) > 0 {
Expand Down Expand Up @@ -628,20 +640,38 @@ func (c *CmdControl) askRemotePool(systems map[string]InitSystem, autoSetup bool
func (c *CmdControl) askNetwork(sh *service.Handler, systems map[string]InitSystem, microCloudInternalSubnet *net.IPNet, autoSetup bool) error {
_, bootstrap := systems[sh.Name]
lxd := sh.Services[types.LXD].(*service.LXDService)
for peer, system := range systems {
if bootstrap {
system.TargetNetworks = []api.NetworksPost{lxd.DefaultPendingFanNetwork()}
if peer == sh.Name {
network, err := lxd.DefaultFanNetwork()
if err != nil {
return err
}

system.Networks = []api.NetworksPost{network}
lxdClient, err := lxd.Client(context.Background(), "")
if err != nil {
return err
}

networkNames, err := lxdClient.GetNetworkNames()
if err != nil {
return err
}

networkExists := make(map[string]bool, len(networkNames))
for _, net := range networkNames {
networkExists[net] = true
}

if !networkExists[lxd.DefaultPendingFanNetwork().Name] {
for peer, system := range systems {
if bootstrap {
system.TargetNetworks = []api.NetworksPost{lxd.DefaultPendingFanNetwork()}
if peer == sh.Name {
network, err := lxd.DefaultFanNetwork()
if err != nil {
return err
}

system.Networks = []api.NetworksPost{network}
}
}
}

systems[peer] = system
systems[peer] = system
}
}

// Automatic setup gets a basic fan setup.
Expand All @@ -650,7 +680,8 @@ func (c *CmdControl) askNetwork(sh *service.Handler, systems map[string]InitSyst
}

// Environments without OVN get a basic fan setup.
if sh.Services[types.MicroOVN] == nil {
uplink, ovn := lxd.DefaultOVNNetwork("", "", "", "")
if sh.Services[types.MicroOVN] == nil || networkExists[uplink.Name] || networkExists[ovn.Name] {
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/microcloud/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ EOF`)
var cmdAdd = cmdAdd{common: &commonCmd}
app.AddCommand(cmdAdd.Command())

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

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

Expand Down
30 changes: 26 additions & 4 deletions cmd/microcloud/main_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,12 +933,34 @@ func setupCluster(s *service.Handler, systems map[string]InitSystem) 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
for k, v := range existingProfile.Config {
_, ok := profile.Config[k]
if !ok {
profile.Config[k] = v
}
}

for k, v := range existingProfile.Devices {
_, ok := profile.Devices[k]
if !ok {
profile.Devices[k] = v
}
}

err = lxdClient.UpdateProfile(profile.Name, profile.ProfilePut, "")
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the cluster was set up initially with only local storage I'm guessing that when adding ceph afterwards this will overwrite the root disk device in the default profile to be Ceph instead?

I think this might be a bit confusing to users so I'm not sure about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I think we should either ask a question here, or only update the default profile if there is not already a corresponding entry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I guess asking a question makes sense since it's highly likely there will already be root disk and nic devices in the default profile.

}
}

Expand Down
Loading
Loading