async def connect_controller(self, controller_name=None, specified_facades=None): """Connect to a controller by name. If the name is empty, it connect to the current controller. """ if not controller_name: controller_name = self.jujudata.current_controller() if not controller_name: raise JujuConnectionError('No current controller') controller = self.jujudata.controllers()[controller_name] endpoints = controller['api-endpoints'] accounts = self.jujudata.accounts().get(controller_name, {}) proxy = proxy_from_config(controller.get('proxy-config', None)) await self.connect( endpoint=endpoints, uuid=None, username=accounts.get('user'), password=accounts.get('password'), cacert=controller.get('ca-cert'), bakery_client=self.bakery_client_for_controller(controller_name), specified_facades=specified_facades, proxy=proxy, ) self.controller_name = controller_name self.controller_uuid = controller["uuid"]
def test_proxy_from_config_missing_type(self): """ Test that a nil proxy type returns None """ self.assertIsNone(proxy_from_config({ "config": {}, }))
def test_proxy_from_config_kubernetes(self): """ Tests that a Kubernetes proxy is correctly created from config """ proxy = proxy_from_config({ "type": "kubernetes-port-forward", "config": { "api-host": "https://localhost:8456", "namespace": "controller-python-test", "remote-port": "1234", "service": "controller", "service-account-token": "==AA", "ca-cert": "==AA", }, }) self.assertIs(type(proxy), KubernetesProxy)
async def connect_model(self, model_name=None): """Connect to a model by name. If either controller or model parts of the name are empty, the current controller and/or model will be used. :param str model: <controller>:<model> """ try: controller_name, model_name = self.jujudata.parse_model(model_name) controller = self.jujudata.controllers().get(controller_name) except JujuError as e: raise JujuConnectionError(e.message) from e if controller is None: raise JujuConnectionError( 'Controller {} not found'.format(controller_name)) endpoints = controller['api-endpoints'] account = self.jujudata.accounts().get(controller_name, {}) models = self.jujudata.models().get(controller_name, {}).get('models', {}) if model_name not in models: raise JujuConnectionError('Model not found: {}'.format(model_name)) proxy = proxy_from_config(controller.get('proxy-config', None)) # TODO if there's no record for the required model name, connect # to the controller to find out the model's uuid, then connect # to that. This will let connect_model work with models that # haven't necessarily synced with the local juju data, # and also remove the need for base.CleanModel to # subclass JujuData. await self.connect( endpoint=endpoints, uuid=models[model_name]['uuid'], username=account.get('user'), password=account.get('password'), cacert=controller.get('ca-cert'), bakery_client=self.bakery_client_for_controller(controller_name), proxy=proxy, ) self.controller_name = controller_name self.model_name = controller_name + ':' + model_name
def test_proxy_from_config_non_arg(self): """ Tests that providing an empty proxy config results in a None proxy """ self.assertIsNone(proxy_from_config(None))