--- /dev/null
+# Copyright 2021 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+backup:
+ description: "Do a mongodb backup"
from typing import NoReturn, Optional
from urllib.parse import urlparse
+from oci_image import OCIImageResource
from ops.framework import EventBase
from ops.main import main
from opslib.osm.charm import CharmedOsmBase
ModelValidator,
validator,
)
+import requests
logger = logging.getLogger(__name__)
self._publish_prometheus_info,
)
+ # Registering actions
+ self.framework.observe(
+ self.on.backup_action, # pylint: disable=E1101
+ self._on_backup_action,
+ )
+
def _publish_prometheus_info(self, event: EventBase) -> NoReturn:
self.prometheus.publish_info(self.app.name, PORT)
+ def _on_backup_action(self, event: EventBase) -> NoReturn:
+ url = f"http://{self.model.app.name}:{PORT}/api/v2/admin/tsdb/snapshot"
+ result = requests.post(url)
+
+ if result.status_code == 200:
+ event.set_results({"backup-name": result.json()["name"]})
+ else:
+ event.fail(f"status-code: {result.status_code}, result: {result.json()}")
+
def _build_files(self, config: ConfigModel):
files_builder = FilesV3Builder()
files_builder.add_file(
config = ConfigModel(**dict(self.config))
# Create Builder for the PodSpec
pod_spec_builder = PodSpecV3Builder()
+
+ # Build Backup Container
+ backup_image = OCIImageResource(self, "backup-image")
+ backup_image_info = backup_image.fetch()
+ backup_container_builder = ContainerV3Builder("prom-backup", backup_image_info)
+ backup_container = backup_container_builder.build()
+ # Add backup container to pod spec
+ pod_spec_builder.add_container(backup_container)
+
# Build Container
container_builder = ContainerV3Builder(self.app.name, image_info)
container_builder.add_port(name=self.app.name, port=PORT)