@@ -67,6 +67,13 @@ async def connect(self, **kwargs):
6767 for macaroon in kwargs .pop ('macaroons' ):
6868 jar .set_cookie (go_to_py_cookie (macaroon ))
6969 self ._connection = await Connection .connect (** kwargs )
70+ controller = self .jujudata .controllers ()[
71+ self .jujudata .current_controller ()
72+ ]
73+ self ._connection .endpoints = [
74+ (e , controller ["ca-cert" ])
75+ for e in controller ["api-endpoints" ]
76+ ]
7077
7178 async def disconnect (self ):
7279 """Shut down the watcher task and close websockets.
@@ -86,13 +93,11 @@ async def connect_controller(self, controller_name=None, specified_facades=None)
8693 raise JujuConnectionError ('No current controller' )
8794
8895 controller = self .jujudata .controllers ()[controller_name ]
89- # TODO change Connection so we can pass all the endpoints
90- # instead of just the first.
91- endpoint = controller ['api-endpoints' ][0 ]
96+ endpoints = controller ['api-endpoints' ]
9297 accounts = self .jujudata .accounts ().get (controller_name , {})
9398
9499 await self .connect (
95- endpoint = endpoint ,
100+ endpoint = endpoints ,
96101 uuid = None ,
97102 username = accounts .get ('user' ),
98103 password = accounts .get ('password' ),
@@ -119,9 +124,7 @@ async def connect_model(self, model_name=None):
119124 if controller is None :
120125 raise JujuConnectionError ('Controller {} not found' .format (
121126 controller_name ))
122- # TODO change Connection so we can pass all the endpoints
123- # instead of just the first one.
124- endpoint = controller ['api-endpoints' ][0 ]
127+ endpoints = controller ['api-endpoints' ]
125128 account = self .jujudata .accounts ().get (controller_name , {})
126129 models = self .jujudata .models ().get (controller_name , {}).get ('models' ,
127130 {})
@@ -135,7 +138,7 @@ async def connect_model(self, model_name=None):
135138 # and also remove the need for base.CleanModel to
136139 # subclass JujuData.
137140 await self .connect (
138- endpoint = endpoint ,
141+ endpoint = endpoints ,
139142 uuid = models [model_name ]['uuid' ],
140143 username = account .get ('user' ),
141144 password = account .get ('password' ),
0 commit comments