-
Notifications
You must be signed in to change notification settings - Fork 36
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
[WIP] start machine now accepts a base datastructure #100
Open
jack-w-shaw
wants to merge
1
commit into
juju:v2
Choose a base branch
from
jack-w-shaw:JUJU-4138_deplyo_with_base
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2023 Canonical Ltd. | ||
// Licensed under the LGPLv3, see LICENCE file for details. | ||
|
||
package gomaasapi | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/juju/errors" | ||
"github.com/juju/version/v2" | ||
) | ||
|
||
var VersionDeploySupportsBases = version.Number{Major: 3, Minor: 3, Patch: 5} | ||
|
||
type OSType string | ||
|
||
var ( | ||
Custom OSType = "custom" | ||
Ubuntu OSType = "ubuntu" | ||
Centos OSType = "centos" | ||
) | ||
|
||
type Base struct { | ||
OS OSType | ||
Version string | ||
} | ||
|
||
func (b Base) String() string { | ||
if b.OS != "" && b.Version != "" { | ||
return fmt.Sprintf("%s/%s", b.OS, b.Version) | ||
} | ||
if b.Version != "" { | ||
return b.Version | ||
} | ||
return "" | ||
} | ||
|
||
func (b Base) toSeries() (string, error) { | ||
if b.OS == "" { | ||
return b.Version, nil | ||
} | ||
switch b.OS { | ||
case Custom: | ||
return b.String(), nil | ||
case Ubuntu: | ||
if series, ok := ubuntuMap[b.Version]; ok { | ||
return series, nil | ||
} | ||
return "", errors.NotValidf("base %s cannot be converted into a series", b) | ||
case Centos: | ||
if series, ok := centosMap[b.Version]; ok { | ||
return series, nil | ||
} | ||
return "", errors.NotValidf("base %s cannot be converted into a series", b) | ||
default: | ||
return "", errors.NotValidf("base %s OS", b) | ||
} | ||
|
||
} | ||
|
||
const ( | ||
centos7 = "centos7" | ||
centos8 = "centos8" | ||
centos9 = "centos9" | ||
) | ||
|
||
var ubuntuMap = map[string]string{ | ||
"20.04": "ubuntu/focal", | ||
"20.10": "ubuntu/groovy", | ||
"21.04": "ubuntu/hirsute", | ||
"21.10": "ubuntu/impish", | ||
"22.04": "ubuntu/jammy", | ||
"22.10": "ubuntu/kinetic", | ||
"23.04": "ubuntu/lunar", | ||
} | ||
|
||
var centosMap = map[string]string{ | ||
"7": "centos/centos7", | ||
"8": "centos/centos8", | ||
"9": "centos/centos9", | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite the right approach.
So we don't want to hardcode the versions here. That's for juju to request and for MAAS to say are valid or not. What I was looking for is just a
Base
type that you can validate up front. Either from a stringParseBase
which will return a validBase
orNewBase
which takes the concrete types. Both of which should validate the consistency of a base.For example, you can't set OS without a Version.
What we don't want is to have that lazily. If
toSeries
was calledValidate
(minus the concrete version checking), then that would be ideal.