Add additional repo options

- Some repos are built without components that MAAS
  assumes are there. This allows the configuration to
  describe that so MAAS can be updated to disregard
  those components

Change-Id: I4eafe9fb8278b944bcb993f10379966a01e94bf6
This commit is contained in:
Scott Hussey 2018-07-13 09:19:53 -05:00
parent 69a6f80031
commit 4423ee985e
4 changed files with 43 additions and 3 deletions

View File

@ -622,6 +622,9 @@ class CreateNetworkTemplate(BaseMaasAction):
class ConfigureNodeProvisioner(BaseMaasAction): class ConfigureNodeProvisioner(BaseMaasAction):
"""Action for configuring site-wide node provisioner options.""" """Action for configuring site-wide node provisioner options."""
# These repo names cannot be deleted out of MAAS
# and maintain functionality
DEFAULT_REPOS = ['main_archive', 'ports_archive']
def start(self): def start(self):
self.task.set_status(hd_fields.TaskStatus.Running) self.task.set_status(hd_fields.TaskStatus.Running)
@ -689,6 +692,16 @@ class ConfigureNodeProvisioner(BaseMaasAction):
self.task.add_status_msg( self.task.add_status_msg(
msg=msg, error=True, ctx='NA', ctx_type='NA') msg=msg, error=True, ctx='NA', ctx_type='NA')
self.task.failure() self.task.failure()
if repo_list.remove_unlisted:
defined_repos = [x.get_id() for x in repo_list]
to_delete = [r
for r
in current_repos
if r.name not in defined_repos]
for r in to_delete:
if r.name not in self.DEFAULT_REPOS:
r.delete()
current_repos.refresh()
else: else:
msg = ("No repositories to add, no work to do.") msg = ("No repositories to add, no work to do.")
self.logger.debug(msg) self.logger.debug(msg)
@ -714,7 +727,12 @@ class ConfigureNodeProvisioner(BaseMaasAction):
if repo_obj.distributions: if repo_obj.distributions:
model_fields['distributions'] = ','.join(repo_obj.distributions) model_fields['distributions'] = ','.join(repo_obj.distributions)
if repo_obj.components: if repo_obj.components:
if repo_obj.get_id() in ConfigureNodeProvisioner.DEFAULT_REPOS:
model_fields['disabled_components'] = ','.join(repo_obj.get_disabled_components())
else:
model_fields['components'] = ','.join(repo_obj.components) model_fields['components'] = ','.join(repo_obj.components)
if repo_obj.get_disabled_subrepos():
model_fields['disabled_pockets'] = ','.join(repo_obj.get_disabled_subrepos())
if repo_obj.arches: if repo_obj.arches:
model_fields['arches'] = ','.join(repo_obj.arches) model_fields['arches'] = ','.join(repo_obj.arches)

View File

@ -21,11 +21,11 @@ class Repository(model_base.ResourceBase):
resource_url = 'package-repositories/{resource_id}/' resource_url = 'package-repositories/{resource_id}/'
fields = [ fields = [
'resource_id', 'name', 'url', 'distributions', 'components', 'arches', 'resource_id', 'name', 'url', 'distributions', 'components', 'arches',
'key', 'enabled' 'key', 'enabled', 'disabled_components', 'disabled_pockets'
] ]
json_fields = [ json_fields = [
'name', 'url', 'distributions', 'components', 'arches', 'key', 'name', 'url', 'distributions', 'components', 'arches', 'key',
'enabled' 'enabled', 'disabled_components', 'disabled_pockets'
] ]
def __init__(self, api_client, **kwargs): def __init__(self, api_client, **kwargs):

View File

@ -101,11 +101,20 @@ class Repository(base.DrydockObject):
'repo_type': ovo_fields.StringField(), 'repo_type': ovo_fields.StringField(),
'gpgkey': ovo_fields.StringField(nullable=True), 'gpgkey': ovo_fields.StringField(nullable=True),
'distributions': ovo_fields.ListOfStringsField(nullable=True), 'distributions': ovo_fields.ListOfStringsField(nullable=True),
'subrepos': ovo_fields.ListOfStringsField(nullable=True),
'components': ovo_fields.ListOfStringsField(nullable=True), 'components': ovo_fields.ListOfStringsField(nullable=True),
'arches': ovo_fields.ListOfStringsField(default=['amd64']), 'arches': ovo_fields.ListOfStringsField(default=['amd64']),
'options': ovo_fields.DictOfStringsField(nullable=True) 'options': ovo_fields.DictOfStringsField(nullable=True)
} }
STANDARD_COMPONENTS = {
'apt': {'main', 'restricted', 'universe', 'multiverse'},
}
STANDARD_SUBREPOS = {
'apt': {'security', 'updates', 'backports'},
}
def __init__(self, **kwargs): def __init__(self, **kwargs):
super(Repository, self).__init__(**kwargs) super(Repository, self).__init__(**kwargs)
@ -113,6 +122,15 @@ class Repository(base.DrydockObject):
def get_id(self): def get_id(self):
return self.name return self.name
def get_disabled_components(self):
enabled = set(self.components or [])
std = self.STANDARD_COMPONENTS.get(self.repo_type, ())
return std - enabled
def get_disabled_subrepos(self):
enabled = set(self.subrepos or [])
std = self.STANDARD_SUBREPOS.get(self.repo_type, ())
return std - enabled
@base.DrydockObjectRegistry.register @base.DrydockObjectRegistry.register
class RepositoryList(base.DrydockObjectListBase, base.DrydockObject): class RepositoryList(base.DrydockObjectListBase, base.DrydockObject):

View File

@ -46,6 +46,10 @@ data:
type: 'array' type: 'array'
items: items:
type: 'string' type: 'string'
subrepos:
type: 'array'
items:
type: 'string'
components: components:
type: 'array' type: 'array'
items: items: