@@ -139,23 +139,38 @@ def get_bucket_hosts(self, ak, bucket, home_dir, force=False):
139
139
if not force and len (bucket_hosts ) > 0 :
140
140
return bucket_hosts
141
141
142
- hosts = compat .json .loads (self .bucket_hosts (ak , bucket ))
142
+ hosts = compat .json .loads (self .bucket_hosts (ak , bucket )).get ('hosts' , [])
143
+
144
+ if type (hosts ) is not list or len (hosts ) == 0 :
145
+ raise KeyError ("Please check your BUCKET_NAME! Server hosts not correct! The hosts is %s" % hosts )
146
+
147
+ region = hosts [0 ]
148
+
143
149
default_ttl = 24 * 3600 # 1 day
144
- hosts ['ttl' ] = hosts ['ttl' ] if 'ttl' in hosts else default_ttl
145
-
146
- try :
147
- scheme_hosts = hosts [self .scheme ]
148
- except KeyError :
149
- raise KeyError (
150
- "Please check your BUCKET_NAME! The UpHosts is %s" %
151
- hosts )
150
+ region ['ttl' ] = region .get ('ttl' , default_ttl )
151
+
152
152
bucket_hosts = {
153
- 'upHosts' : scheme_hosts ['up' ],
154
- 'ioHosts' : scheme_hosts ['io' ],
155
- 'rsHosts' : scheme_hosts ['rs' ],
156
- 'rsfHosts' : scheme_hosts ['rsf' ],
157
- 'apiHosts' : scheme_hosts ['api' ],
158
- 'deadline' : int (time .time ()) + hosts ['ttl' ]
153
+ 'upHosts' : [
154
+ '{0}://{1}' .format (self .scheme , domain )
155
+ for domain in region .get ('up' , {}).get ('domains' , [])
156
+ ],
157
+ 'ioHosts' : [
158
+ '{0}://{1}' .format (self .scheme , domain )
159
+ for domain in region .get ('io' , {}).get ('domains' , [])
160
+ ],
161
+ 'rsHosts' : [
162
+ '{0}://{1}' .format (self .scheme , domain )
163
+ for domain in region .get ('rs' , {}).get ('domains' , [])
164
+ ],
165
+ 'rsfHosts' : [
166
+ '{0}://{1}' .format (self .scheme , domain )
167
+ for domain in region .get ('rsf' , {}).get ('domains' , [])
168
+ ],
169
+ 'apiHosts' : [
170
+ '{0}://{1}' .format (self .scheme , domain )
171
+ for domain in region .get ('api' , {}).get ('domains' , [])
172
+ ],
173
+ 'deadline' : int (time .time ()) + region ['ttl' ]
159
174
}
160
175
home_dir = ""
161
176
self .set_bucket_hosts_to_cache (key , bucket_hosts , home_dir )
@@ -208,7 +223,7 @@ def bucket_hosts(self, ak, bucket):
208
223
uc_host = UC_HOST
209
224
if is_customized_default ('default_uc_host' ):
210
225
uc_host = get_default ('default_uc_host' )
211
- url = "{0}/v1 /query?ak={1}&bucket={2}" .format (uc_host , ak , bucket )
226
+ url = "{0}/v4 /query?ak={1}&bucket={2}" .format (uc_host , ak , bucket )
212
227
ret = requests .get (url )
213
228
data = compat .json .dumps (ret .json (), separators = (',' , ':' ))
214
229
return data
0 commit comments