blob: d40d3b3d13dc23b5bc8ec62435e0818543275685 [file] [log] [blame]
Peter Pentchev469dfea2022-06-27 12:48:18 +03001#! /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
18from ops_openstack.plugins.classes import CinderStoragePluginCharm
Peter Pentcheva8266902022-07-29 05:55:35 +000019from ops_openstack.core import charm_class, get_charm_class
Peter Pentchev469dfea2022-06-27 12:48:18 +030020from ops.main import main
21
22
23class CinderCharmBase(CinderStoragePluginCharm):
24
Biser Milanov53644f62022-08-03 16:08:59 +030025 PACKAGES = ["cinder-common"]
26 MANDATORY_CONFIG = ["protocol"]
Peter Pentchev469dfea2022-06-27 12:48:18 +030027 # 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 Milanov53644f62022-08-03 16:08:59 +030036 backend_name = config.get("volume-backend-name", self.framework.model.app.name)
37 volume_driver = "cinder.volume.drivers.storpool.StorPoolDriver"
Peter Pentchev469dfea2022-06-27 12:48:18 +030038 options = [
Biser Milanov53644f62022-08-03 16:08:59 +030039 ("volume_driver", volume_driver),
40 ("volume_backend_name", backend_name),
Peter Pentchev469dfea2022-06-27 12:48:18 +030041 ]
42
Biser Milanov53644f62022-08-03 16:08:59 +030043 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 Pentchev469dfea2022-06-27 12:48:18 +030050
51 return options
52
53
54@charm_class
55class CinderStorPoolCharm(CinderCharmBase):
Biser Milanov53644f62022-08-03 16:08:59 +030056 release = "yoga"
Peter Pentchev469dfea2022-06-27 12:48:18 +030057
58
Biser Milanov53644f62022-08-03 16:08:59 +030059if __name__ == "__main__":
Peter Pentchev3a17d7d2022-07-27 13:11:57 +000060 # main(get_charm_class_for_release())
Peter Pentcheva8266902022-07-29 05:55:35 +000061 # main(CinderStorPoolCharm)
62 main(get_charm_class(release="yoga"))