diff --git a/manifests/candidate.yml b/manifests/candidate.yml index 97e488f5..85c37787 100644 --- a/manifests/candidate.yml +++ b/manifests/candidate.yml @@ -40,6 +40,8 @@ software: channel: 2024.1/candidate config: snap-channel: 2024.1/candidate + openstack-images-sync-k8s: + channel: 2024.1/candidate ovn-central-k8s: channel: 24.03/candidate ovn-relay-k8s: diff --git a/manifests/edge.yml b/manifests/edge.yml index be001109..f8006ff7 100644 --- a/manifests/edge.yml +++ b/manifests/edge.yml @@ -40,6 +40,8 @@ software: channel: 2024.1/edge config: snap-channel: 2024.1/edge + openstack-images-sync-k8s: + channel: 2024.1/edge ovn-central-k8s: channel: 24.03/edge ovn-relay-k8s: diff --git a/sunbeam-python/sunbeam/plugins/images_sync/__init__.py b/sunbeam-python/sunbeam/plugins/images_sync/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sunbeam-python/sunbeam/plugins/images_sync/plugin.py b/sunbeam-python/sunbeam/plugins/images_sync/plugin.py new file mode 100644 index 00000000..c06771e4 --- /dev/null +++ b/sunbeam-python/sunbeam/plugins/images_sync/plugin.py @@ -0,0 +1,105 @@ +# Copyright (c) 2024 Canonical Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import logging + +import click +from packaging.version import Version +from rich.console import Console + +from sunbeam.jobs.deployment import Deployment +from sunbeam.plugins.interface.v1.openstack import ( + ApplicationChannelData, + OpenStackControlPlanePlugin, + TerraformPlanLocation, +) +from sunbeam.versions import OPENSTACK_CHANNEL + +LOG = logging.getLogger(__name__) +console = Console() + + +class ImagesSyncPlugin(OpenStackControlPlanePlugin): + version = Version("0.0.1") + + def __init__(self, deployment: Deployment) -> None: + super().__init__( + "images-sync", + deployment, + tf_plan_location=TerraformPlanLocation.SUNBEAM_TERRAFORM_REPO, + ) + + def manifest_defaults(self) -> dict: + """Manifest plugin part in dict format.""" + return { + "charms": { + "openstack-images-sync-k8s": {"channel": OPENSTACK_CHANNEL}, + } + } + + def manifest_attributes_tfvar_map(self) -> dict: + """Manifest attributes terraformvars map.""" + return { + self.tfplan: { + "charms": { + "openstack-images-sync-k8s": { + "channel": "images-sync-channel", + "revision": "images-sync-revision", + "config": "images-sync-config", + } + } + } + } + + def set_application_names(self) -> list: + """Application names handled by the terraform plan.""" + return ["images-sync"] + + def set_tfvars_on_enable(self) -> dict: + """Set terraform variables to enable the application.""" + return { + "enable-images-sync": True, + } + + def set_tfvars_on_disable(self) -> dict: + """Set terraform variables to disable the application.""" + return {"enable-images-sync": False} + + def set_tfvars_on_resize(self) -> dict: + """Set terraform variables to resize the application.""" + return {} + + @click.command() + def enable_plugin(self) -> None: + """Enable images-sync service.""" + super().enable_plugin() + + @click.command() + def disable_plugin(self) -> None: + """Disable images-sync service.""" + super().disable_plugin() + + @property + def k8s_application_data(self): + return { + "images-sync": ApplicationChannelData( + channel=OPENSTACK_CHANNEL, + tfvars_channel_var=None, + ), + } + + @property + def tfvars_channel_var(self): + return "images-sync-channel" diff --git a/sunbeam-python/sunbeam/plugins/plugins.yaml b/sunbeam-python/sunbeam/plugins/plugins.yaml index 157abf33..3cc97ea6 100644 --- a/sunbeam-python/sunbeam/plugins/plugins.yaml +++ b/sunbeam-python/sunbeam/plugins/plugins.yaml @@ -79,3 +79,9 @@ sunbeam-plugins: path: sunbeam.plugins.validation.plugin.ValidationPlugin supported_architectures: - amd64 + - name: "images-sync" + version: "0.0.1" + description: "Plugin for syncing images from a simplestreams source" + path: sunbeam.plugins.images_sync.plugin.ImagesSyncPlugin + supported_architectures: + - amd64