Peter Pentchev | 469dfea | 2022-06-27 12:48:18 +0300 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
| 2 | |
| 3 | # Copyright 2021 Canonical Ltd |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | |
| 18 | from ops_openstack.plugins.classes import CinderStoragePluginCharm |
Peter Pentchev | a826690 | 2022-07-29 05:55:35 +0000 | [diff] [blame] | 19 | from ops_openstack.core import charm_class, get_charm_class |
Peter Pentchev | 469dfea | 2022-06-27 12:48:18 +0300 | [diff] [blame] | 20 | from ops.main import main |
| 21 | |
| 22 | |
| 23 | class CinderCharmBase(CinderStoragePluginCharm): |
| 24 | |
Biser Milanov | 53644f6 | 2022-08-03 16:08:59 +0300 | [diff] [blame^] | 25 | PACKAGES = ["cinder-common"] |
| 26 | MANDATORY_CONFIG = ["protocol"] |
Peter Pentchev | 469dfea | 2022-06-27 12:48:18 +0300 | [diff] [blame] | 27 | # Overriden from the parent. May be set depending on the charm's properties |
| 28 | stateless = True |
| 29 | active_active = True |
| 30 | |
| 31 | def __init__(self, *args, **kwargs): |
| 32 | super().__init__(*args, **kwargs) |
| 33 | |
| 34 | def cinder_configuration(self, config): |
| 35 | # Return the configuration to be set by the principal. |
Biser Milanov | 53644f6 | 2022-08-03 16:08:59 +0300 | [diff] [blame^] | 36 | backend_name = config.get("volume-backend-name", self.framework.model.app.name) |
| 37 | volume_driver = "cinder.volume.drivers.storpool.StorPoolDriver" |
Peter Pentchev | 469dfea | 2022-06-27 12:48:18 +0300 | [diff] [blame] | 38 | options = [ |
Biser Milanov | 53644f6 | 2022-08-03 16:08:59 +0300 | [diff] [blame^] | 39 | ("volume_driver", volume_driver), |
| 40 | ("volume_backend_name", backend_name), |
Peter Pentchev | 469dfea | 2022-06-27 12:48:18 +0300 | [diff] [blame] | 41 | ] |
| 42 | |
Biser Milanov | 53644f6 | 2022-08-03 16:08:59 +0300 | [diff] [blame^] | 43 | if config.get("use-multipath"): |
| 44 | options.extend( |
| 45 | [ |
| 46 | ("use_multipath_for_image_xfer", True), |
| 47 | ("enforce_multipath_for_image_xfer", True), |
| 48 | ] |
| 49 | ) |
Peter Pentchev | 469dfea | 2022-06-27 12:48:18 +0300 | [diff] [blame] | 50 | |
| 51 | return options |
| 52 | |
| 53 | |
| 54 | @charm_class |
| 55 | class CinderStorPoolCharm(CinderCharmBase): |
Biser Milanov | 53644f6 | 2022-08-03 16:08:59 +0300 | [diff] [blame^] | 56 | release = "yoga" |
Peter Pentchev | 469dfea | 2022-06-27 12:48:18 +0300 | [diff] [blame] | 57 | |
| 58 | |
Biser Milanov | 53644f6 | 2022-08-03 16:08:59 +0300 | [diff] [blame^] | 59 | if __name__ == "__main__": |
Peter Pentchev | 3a17d7d | 2022-07-27 13:11:57 +0000 | [diff] [blame] | 60 | # main(get_charm_class_for_release()) |
Peter Pentchev | a826690 | 2022-07-29 05:55:35 +0000 | [diff] [blame] | 61 | # main(CinderStorPoolCharm) |
| 62 | main(get_charm_class(release="yoga")) |