Skip to content

Commit

Permalink
storage: Change InstallSelected to be a map
Browse files Browse the repository at this point in the history
Change InstallSelected to be a map with the key being
the name of the TargetMedias from the model to support
installing across multiple disks.

Signed-off-by: Mark D Horn <[email protected]>
  • Loading branch information
mdhorn committed Sep 13, 2019
1 parent b07b16b commit 7098434
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 42 deletions.
1 change: 1 addition & 0 deletions clr-installer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func main() {
if md, err = model.LoadFile(cf, options); err != nil {
fatal(err)
}
md.ClearInstallSelected()

log.Info("Querying Clear Linux version")
if err := utils.ParseOSClearVersion(); err != nil {
Expand Down
11 changes: 10 additions & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,24 @@ func Install(rootDir string, model *model.SystemInstall, options args.Args) erro

// expand block device's name case we've detected image replacement cases
for _, tm := range expandMe {
oldName := tm.Name
tm.ExpandName(aliasMap)
newName := tm.Name
// Remap the InstallSelected
model.InstallSelected[newName] = model.InstallSelected[oldName]
delete(model.InstallSelected, oldName)
}

mountPoints := []*storage.BlockDevice{}

// prepare all the target block devices
for _, curr := range model.TargetMedias {
var wholeDisk bool
if val, ok := model.InstallSelected[curr.Name]; ok {
wholeDisk = val.WholeDisk
}
// based on the description given, write the partition table
if err = curr.WritePartitionTable(model.LegacyBios, model.InstallSelected.WholeDisk, nil); err != nil {
if err = curr.WritePartitionTable(model.LegacyBios, wholeDisk, nil); err != nil {
return err
}

Expand Down
4 changes: 3 additions & 1 deletion massinstall/massinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ func (mi *MassInstall) Run(md *model.SystemInstall, rootDir string, options args

// Need to ensure the partitioner knows we are running from
// the command line and will be using the whole disk
md.InstallSelected = storage.InstallTarget{WholeDisk: true}
for _, curr := range md.TargetMedias {
md.InstallSelected[curr.Name] = storage.InstallTarget{WholeDisk: true}
}

progress.Set(mi)

Expand Down
74 changes: 37 additions & 37 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,38 @@ var testAlias = []string{}
// SystemInstall represents the system install "configuration", the target
// medias, bundles to install and whatever state a install may require
type SystemInstall struct {
// Even though TargetMedias is an array, we currently only support
// it containing a single BlockDevice which matches/maps to the InstallTarget
// TODO: Change InstallSelected to be a map with the key being the
// device name for which it holds InstallTarget information when/if
// we add support for installing across multiple disks.
InstallSelected storage.InstallTarget `yaml:"-"`
TargetMedias []*storage.BlockDevice `yaml:"targetMedia"`
NetworkInterfaces []*network.Interface `yaml:"networkInterfaces,omitempty,flow"`
Keyboard *keyboard.Keymap `yaml:"keyboard,omitempty,flow"`
Language *language.Language `yaml:"language,omitempty,flow"`
Bundles []string `yaml:"bundles,omitempty,flow"`
UserBundles []string `yaml:"userBundles,omitempty,flow"`
HTTPSProxy string `yaml:"httpsProxy,omitempty,flow"`
Telemetry *telemetry.Telemetry `yaml:"telemetry,omitempty,flow"`
Timezone *timezone.TimeZone `yaml:"timezone,omitempty,flow"`
Users []*user.User `yaml:"users,omitempty,flow"`
KernelArguments *kernel.Arguments `yaml:"kernel-arguments,omitempty,flow"`
Kernel *kernel.Kernel `yaml:"kernel,omitempty,flow"`
PostReboot bool `yaml:"postReboot,omitempty,flow"`
SwupdMirror string `yaml:"swupdMirror,omitempty,flow"`
PostArchive bool `yaml:"postArchive,omitempty,flow"`
Hostname string `yaml:"hostname,omitempty,flow"`
AutoUpdate bool `yaml:"autoUpdate,omitempty,flow"`
TelemetryURL string `yaml:"telemetryURL,omitempty,flow"`
TelemetryTID string `yaml:"telemetryTID,omitempty,flow"`
TelemetryPolicy string `yaml:"telemetryPolicy,omitempty,flow"`
PreInstall []*InstallHook `yaml:"pre-install,omitempty,flow"`
PostInstall []*InstallHook `yaml:"post-install,omitempty,flow"`
Version uint `yaml:"version,omitempty,flow"`
StorageAlias []*StorageAlias `yaml:"block-devices,omitempty,flow"`
LegacyBios bool `yaml:"legacyBios,omitempty,flow"`
CopyNetwork bool `yaml:"copyNetwork,omitempty,flow"`
Environment map[string]string `yaml:"env,omitempty,flow"`
CryptPass string `yaml:"-"`
MakeISO bool `yaml:"iso,omitempty,flow"`
KeepImage bool `yaml:"keepImage,omitempty,flow"`
LockFile string `yaml:"-"`
InstallSelected map[string]storage.InstallTarget `yaml:"-"`
TargetMedias []*storage.BlockDevice `yaml:"targetMedia"`
NetworkInterfaces []*network.Interface `yaml:"networkInterfaces,omitempty,flow"`
Keyboard *keyboard.Keymap `yaml:"keyboard,omitempty,flow"`
Language *language.Language `yaml:"language,omitempty,flow"`
Bundles []string `yaml:"bundles,omitempty,flow"`
UserBundles []string `yaml:"userBundles,omitempty,flow"`
HTTPSProxy string `yaml:"httpsProxy,omitempty,flow"`
Telemetry *telemetry.Telemetry `yaml:"telemetry,omitempty,flow"`
Timezone *timezone.TimeZone `yaml:"timezone,omitempty,flow"`
Users []*user.User `yaml:"users,omitempty,flow"`
KernelArguments *kernel.Arguments `yaml:"kernel-arguments,omitempty,flow"`
Kernel *kernel.Kernel `yaml:"kernel,omitempty,flow"`
PostReboot bool `yaml:"postReboot,omitempty,flow"`
SwupdMirror string `yaml:"swupdMirror,omitempty,flow"`
PostArchive bool `yaml:"postArchive,omitempty,flow"`
Hostname string `yaml:"hostname,omitempty,flow"`
AutoUpdate bool `yaml:"autoUpdate,omitempty,flow"`
TelemetryURL string `yaml:"telemetryURL,omitempty,flow"`
TelemetryTID string `yaml:"telemetryTID,omitempty,flow"`
TelemetryPolicy string `yaml:"telemetryPolicy,omitempty,flow"`
PreInstall []*InstallHook `yaml:"pre-install,omitempty,flow"`
PostInstall []*InstallHook `yaml:"post-install,omitempty,flow"`
Version uint `yaml:"version,omitempty,flow"`
StorageAlias []*StorageAlias `yaml:"block-devices,omitempty,flow"`
LegacyBios bool `yaml:"legacyBios,omitempty,flow"`
CopyNetwork bool `yaml:"copyNetwork,omitempty,flow"`
Environment map[string]string `yaml:"env,omitempty,flow"`
CryptPass string `yaml:"-"`
MakeISO bool `yaml:"iso,omitempty,flow"`
KeepImage bool `yaml:"keepImage,omitempty,flow"`
LockFile string `yaml:"-"`
}

// SystemUsage is used to include additional information into the telemetry payload
Expand Down Expand Up @@ -112,6 +107,11 @@ type StorageAlias struct {
DeviceFile bool `yaml:"devicefile,omitempty,flow"`
}

// ClearInstallSelected clears the map of Installation Selected targets
func (si *SystemInstall) ClearInstallSelected() {
si.InstallSelected = map[string]storage.InstallTarget{}
}

// ClearExtraKernelArguments clears all of the of custom extra kernel arguments
func (si *SystemInstall) ClearExtraKernelArguments() {
if si.KernelArguments == nil {
Expand Down
4 changes: 1 addition & 3 deletions storage/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -1696,10 +1696,8 @@ func getPlannedPartitionChanges(media *BlockDevice) []string {

// GetPlannedMediaChanges returns an array of strings with all of
// disk and partition planned changes to advise the user before start
func GetPlannedMediaChanges(target InstallTarget, medias []*BlockDevice) []string {
func GetPlannedMediaChanges(targets map[string]InstallTarget, medias []*BlockDevice) []string {
results := []string{}
target.Name = medias[0].Name
targets := []InstallTarget{target}

if len(targets) != len(medias) {
log.Warning("The number of install targets (%d) != media devices (%d)",
Expand Down

0 comments on commit 7098434

Please sign in to comment.