github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/acceptancetests/jujupy/controller.py (about) 1 # This file is part of JujuPy, a library for driving the Juju CLI. 2 # Copyright 2013-2019 Canonical Ltd. 3 # 4 # This program is free software: you can redistribute it and/or modify it 5 # under the terms of the Lesser GNU General Public License version 3, as 6 # published by the Free Software Foundation. 7 # 8 # This program is distributed in the hope that it will be useful, but WITHOUT 9 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, 10 # SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the Lesser GNU General Public License 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 import json 17 import yaml 18 19 __metaclass__ = type 20 21 22 class Controllers: 23 24 def __init__(self, info, text): 25 self.info = info 26 self.text = text 27 28 @classmethod 29 def from_text(cls, text): 30 try: 31 # Parsing as JSON is much faster than parsing as YAML, so try 32 # parsing as JSON first and fall back to YAML. 33 info = json.loads(text) 34 except ValueError: 35 info = yaml.safe_load(text) 36 return cls(info, text) 37 38 def get_controller(self, name): 39 """Controller returns the controller associated with the name provided 40 41 :param name: name associated with the controller 42 """ 43 return Controller(self.info[name]) 44 45 46 class Controller: 47 48 def __init__(self, info): 49 self.info = info 50 51 def get_details(self): 52 return ControllerDetails(self.info["details"]) 53 54 55 class ControllerDetails: 56 57 def __init__(self, info): 58 self.info = info 59 60 @property 61 def agent_version(self): 62 return self.info["agent-version"] 63 64 @property 65 def mongo_version(self): 66 return self.info["mongo-version"] 67 68 69 class ControllerConfig: 70 71 def __init__(self, cfg): 72 self.cfg = cfg 73 74 @classmethod 75 def from_text(cls, text): 76 try: 77 # Parsing as JSON is much faster than parsing as YAML, so try 78 # parsing as JSON first and fall back to YAML. 79 cfg = json.loads(text) 80 except ValueError: 81 cfg = yaml.safe_load(text) 82 return cls(cfg) 83 84 @property 85 def mongo_memory_profile(self): 86 if 'mongo-memory-profile' in self.cfg: 87 return self.cfg["mongo-memory-profile"] 88 return "low" 89 90 @property 91 def db_snap_channel(self): 92 if 'juju-db-snap-channel' in self.cfg: 93 return self.cfg["juju-db-snap-channel"] 94 return "4.4/stable"