Merge pull request #1153 from ogayot/ua-with-autoinstall

Add support for ubuntu-advantage with autoinstall
This commit is contained in:
Dan Bungert 2022-01-07 15:27:41 -07:00 committed by GitHub
commit 3d10a71d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 0 deletions

View File

@ -260,6 +260,18 @@
}
]
},
"ubuntu-advantage": {
"type": "object",
"properties": {
"token": {
"type": "string",
"minLength": 24,
"maxLength": 30,
"pattern": "^C[1-9A-HJ-NP-Za-km-z]+$",
"description": "A valid token starts with a C and is followed by 23 to 29 Base58 characters.\nSee https://pkg.go.dev/github.com/btcsuite/btcutil/base58#CheckEncode"
}
}
},
"proxy": {
"type": [
"string",

View File

@ -42,6 +42,9 @@ snaps:
channel: 3.2/stable
updates: all
timezone: Pacific/Guam
ubuntu-advantage:
# Token that passes the basic format checking but is invalid (i.e. contains more than 16 bytes of random data)
token: C1NWcZTHLteJXGVMM6YhvHDpGrhyy7
storage:
config:
- {type: disk, ptable: gpt, path: /dev/vdb, wipe: superblock, preserve: false, grub_device: true, id: disk-1}

View File

@ -173,6 +173,7 @@ python3 scripts/check-yaml-fields.py .subiquity/var/log/installer/subiquity-curt
python3 scripts/check-yaml-fields.py <(python3 scripts/check-yaml-fields.py .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg datasource.None.userdata_raw) \
locale='"en_GB.UTF-8"' \
timezone='"Pacific/Guam"' \
ubuntu_advantage.token='"C1NWcZTHLteJXGVMM6YhvHDpGrhyy7"' \
'snap.commands=[snap install --channel=3.2/stable etcd]'
grep -q 'finish: subiquity/Install/install/postinstall/install_package1: SUCCESS: installing package1' \
.subiquity/subiquity-server-debug.log

View File

@ -22,6 +22,10 @@ from subiquity.server.controller import SubiquityController
log = logging.getLogger("subiquity.server.controllers.ubuntu_advantage")
TOKEN_DESC = """\
A valid token starts with a C and is followed by 23 to 29 Base58 characters.
See https://pkg.go.dev/github.com/btcsuite/btcutil/base58#CheckEncode"""
class UbuntuAdvantageController(SubiquityController):
""" Represent the server-side Ubuntu Advantage controller. """
@ -29,6 +33,33 @@ class UbuntuAdvantageController(SubiquityController):
endpoint = API.ubuntu_advantage
model_name = "ubuntu_advantage"
autoinstall_key = "ubuntu-advantage"
autoinstall_schema = {
"type": "object",
"properties": {
"token": {
"type": "string",
"minLength": 24,
"maxLength": 30,
"pattern": "^C[1-9A-HJ-NP-Za-km-z]+$",
"description": TOKEN_DESC,
},
},
}
def load_autoinstall_data(self, data: dict) -> None:
""" Load autoinstall data and update the model. """
if data is None:
return
self.model.token = data.get("token", "")
def make_autoinstall(self) -> dict:
""" Return a dictionary that can be used as an autoinstall snippet for
Ubuntu Advantage.
"""
return {
"token": self.model.token
}
def serialize(self) -> str:
""" Save the current state of the model so it can be loaded later.