func ConvertAs2_0_0(in Config) (types.Config, error) { out := types.Config{ Ignition: types.Ignition{ Version: types.IgnitionVersion{Major: 2, Minor: 0}, }, } for _, ref := range in.Ignition.Config.Append { newRef, err := convertConfigReference(ref) if err != nil { return types.Config{}, err } out.Ignition.Config.Append = append(out.Ignition.Config.Append, newRef) } if in.Ignition.Config.Replace != nil { newRef, err := convertConfigReference(*in.Ignition.Config.Replace) if err != nil { return types.Config{}, err } out.Ignition.Config.Replace = &newRef } for _, disk := range in.Storage.Disks { newDisk := types.Disk{ Device: types.Path(disk.Device), WipeTable: disk.WipeTable, } for _, partition := range disk.Partitions { size, err := convertPartitionDimension(partition.Size) if err != nil { return types.Config{}, err } start, err := convertPartitionDimension(partition.Start) if err != nil { return types.Config{}, err } newDisk.Partitions = append(newDisk.Partitions, types.Partition{ Label: types.PartitionLabel(partition.Label), Number: partition.Number, Size: size, Start: start, TypeGUID: types.PartitionTypeGUID(partition.TypeGUID), }) } out.Storage.Disks = append(out.Storage.Disks, newDisk) } for _, array := range in.Storage.Arrays { newArray := types.Raid{ Name: array.Name, Level: array.Level, Spares: array.Spares, } for _, device := range array.Devices { newArray.Devices = append(newArray.Devices, types.Path(device)) } out.Storage.Arrays = append(out.Storage.Arrays, newArray) } for _, filesystem := range in.Storage.Filesystems { newFilesystem := types.Filesystem{ Name: filesystem.Name, Path: func(p types.Path) *types.Path { if p == "" { return nil } return &p }(types.Path(filesystem.Path)), } if filesystem.Mount != nil { newFilesystem.Mount = &types.FilesystemMount{ Device: types.Path(filesystem.Mount.Device), Format: types.FilesystemFormat(filesystem.Mount.Format), } if filesystem.Mount.Create != nil { newFilesystem.Mount.Create = &types.FilesystemCreate{ Force: filesystem.Mount.Create.Force, Options: types.MkfsOptions(filesystem.Mount.Create.Options), } } } out.Storage.Filesystems = append(out.Storage.Filesystems, newFilesystem) } for _, file := range in.Storage.Files { newFile := types.File{ Filesystem: file.Filesystem, Path: types.Path(file.Path), Mode: types.FileMode(file.Mode), User: types.FileUser{Id: file.User.Id}, Group: types.FileGroup{Id: file.Group.Id}, } if file.Contents.Inline != "" { newFile.Contents = types.FileContents{ Source: types.Url{ Scheme: "data", Opaque: "," + dataurl.EscapeString(file.Contents.Inline), }, } } if file.Contents.Remote.Url != "" { source, err := url.Parse(file.Contents.Remote.Url) if err != nil { return types.Config{}, err } newFile.Contents = types.FileContents{Source: types.Url(*source)} } if newFile.Contents == (types.FileContents{}) { newFile.Contents = types.FileContents{ Source: types.Url{ Scheme: "data", Opaque: ",", }, } } newFile.Contents.Compression = types.Compression(file.Contents.Remote.Compression) newFile.Contents.Verification = convertVerification(file.Contents.Remote.Verification) out.Storage.Files = append(out.Storage.Files, newFile) } for _, unit := range in.Systemd.Units { newUnit := types.SystemdUnit{ Name: types.SystemdUnitName(unit.Name), Enable: unit.Enable, Mask: unit.Mask, Contents: unit.Contents, } for _, dropIn := range unit.DropIns { newUnit.DropIns = append(newUnit.DropIns, types.SystemdUnitDropIn{ Name: types.SystemdUnitDropInName(dropIn.Name), Contents: dropIn.Contents, }) } out.Systemd.Units = append(out.Systemd.Units, newUnit) } for _, unit := range in.Networkd.Units { out.Networkd.Units = append(out.Networkd.Units, types.NetworkdUnit{ Name: types.NetworkdUnitName(unit.Name), Contents: unit.Contents, }) } for _, user := range in.Passwd.Users { newUser := types.User{ Name: user.Name, PasswordHash: user.PasswordHash, SSHAuthorizedKeys: user.SSHAuthorizedKeys, } if user.Create != nil { newUser.Create = &types.UserCreate{ Uid: user.Create.Uid, GECOS: user.Create.GECOS, Homedir: user.Create.Homedir, NoCreateHome: user.Create.NoCreateHome, PrimaryGroup: user.Create.PrimaryGroup, Groups: user.Create.Groups, NoUserGroup: user.Create.NoUserGroup, System: user.Create.System, NoLogInit: user.Create.NoLogInit, Shell: user.Create.Shell, } } out.Passwd.Users = append(out.Passwd.Users, newUser) } for _, group := range in.Passwd.Groups { out.Passwd.Groups = append(out.Passwd.Groups, types.Group{ Name: group.Name, Gid: group.Gid, PasswordHash: group.PasswordHash, System: group.System, }) } if err := out.AssertValid(); err != nil { return types.Config{}, err } return out, nil }
func TranslateFromV1(old v1.Config) (types.Config, error) { config := types.Config{ Ignition: types.Ignition{ Version: types.IgnitionVersion{Major: 2}, }, } for _, oldDisk := range old.Storage.Disks { disk := types.Disk{ Device: types.Path(oldDisk.Device), WipeTable: oldDisk.WipeTable, } for _, oldPartition := range oldDisk.Partitions { disk.Partitions = append(disk.Partitions, types.Partition{ Label: types.PartitionLabel(oldPartition.Label), Number: oldPartition.Number, Size: types.PartitionDimension(oldPartition.Size), Start: types.PartitionDimension(oldPartition.Start), TypeGUID: types.PartitionTypeGUID(oldPartition.TypeGUID), }) } config.Storage.Disks = append(config.Storage.Disks, disk) } for _, oldArray := range old.Storage.Arrays { array := types.Raid{ Name: oldArray.Name, Level: oldArray.Level, Spares: oldArray.Spares, } for _, oldDevice := range oldArray.Devices { array.Devices = append(array.Devices, types.Path(oldDevice)) } config.Storage.Arrays = append(config.Storage.Arrays, array) } for i, oldFilesystem := range old.Storage.Filesystems { filesystem := types.Filesystem{ Name: fmt.Sprintf("_translate-filesystem-%d", i), Mount: &types.FilesystemMount{ Device: types.Path(oldFilesystem.Device), Format: types.FilesystemFormat(oldFilesystem.Format), }, } if oldFilesystem.Create != nil { filesystem.Mount.Create = &types.FilesystemCreate{ Force: oldFilesystem.Create.Force, Options: types.MkfsOptions(oldFilesystem.Create.Options), } } config.Storage.Filesystems = append(config.Storage.Filesystems, filesystem) for _, oldFile := range oldFilesystem.Files { file := types.File{ Filesystem: filesystem.Name, Path: types.Path(oldFile.Path), Contents: types.FileContents{ Source: types.Url{ Scheme: "data", Opaque: "," + dataurl.EscapeString(oldFile.Contents), }, }, Mode: types.FileMode(oldFile.Mode), User: types.FileUser{Id: oldFile.Uid}, Group: types.FileGroup{Id: oldFile.Gid}, } config.Storage.Files = append(config.Storage.Files, file) } } for _, oldUnit := range old.Systemd.Units { unit := types.SystemdUnit{ Name: types.SystemdUnitName(oldUnit.Name), Enable: oldUnit.Enable, Mask: oldUnit.Mask, Contents: oldUnit.Contents, } for _, oldDropIn := range oldUnit.DropIns { unit.DropIns = append(unit.DropIns, types.SystemdUnitDropIn{ Name: types.SystemdUnitDropInName(oldDropIn.Name), Contents: oldDropIn.Contents, }) } config.Systemd.Units = append(config.Systemd.Units, unit) } for _, oldUnit := range old.Networkd.Units { config.Networkd.Units = append(config.Networkd.Units, types.NetworkdUnit{ Name: types.NetworkdUnitName(oldUnit.Name), Contents: oldUnit.Contents, }) } for _, oldUser := range old.Passwd.Users { user := types.User{ Name: oldUser.Name, PasswordHash: oldUser.PasswordHash, SSHAuthorizedKeys: oldUser.SSHAuthorizedKeys, } if oldUser.Create != nil { user.Create = &types.UserCreate{ Uid: oldUser.Create.Uid, GECOS: oldUser.Create.GECOS, Homedir: oldUser.Create.Homedir, NoCreateHome: oldUser.Create.NoCreateHome, PrimaryGroup: oldUser.Create.PrimaryGroup, Groups: oldUser.Create.Groups, NoUserGroup: oldUser.Create.NoUserGroup, System: oldUser.Create.System, NoLogInit: oldUser.Create.NoLogInit, Shell: oldUser.Create.Shell, } } config.Passwd.Users = append(config.Passwd.Users, user) } for _, oldGroup := range old.Passwd.Groups { config.Passwd.Groups = append(config.Passwd.Groups, types.Group{ Name: oldGroup.Name, Gid: oldGroup.Gid, PasswordHash: oldGroup.PasswordHash, System: oldGroup.System, }) } return config, nil }