+ @classmethod
+ async def connect_current_controller(cls):
+ """Connect to the currently active controller.
+
+ """
+ jujudata = JujuData()
+ controller_name = jujudata.current_controller()
+
+ return await cls.connect_controller(controller_name)
+
+ @classmethod
+ async def connect_controller(cls, controller_name):
+ """Connect to a controller by name.
+
+ """
+ jujudata = JujuData()
+ controller = jujudata.controllers()[controller_name]
+ endpoint = controller['api-endpoints'][0]
+ cacert = controller.get('ca-cert')
+ accounts = jujudata.accounts()[controller_name]
+ username = accounts['user']
+ password = accounts.get('password')
+ macaroons = get_macaroons() if not password else None
+
+ return await cls.connect(
+ endpoint, None, username, password, cacert, macaroons)
+