blb_client.py 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609
  1. # Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing,
  10. # software distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions
  13. # and limitations under the License.
  14. """
  15. This module provides a client class for BLB.
  16. """
  17. import copy
  18. import json
  19. import logging
  20. import uuid
  21. import sys
  22. from baidubce import bce_base_client
  23. from baidubce.auth import bce_v1_signer
  24. from baidubce.http import bce_http_client
  25. from baidubce.http import handler
  26. from baidubce.http import http_methods
  27. from baidubce import utils
  28. from baidubce.utils import required
  29. from baidubce import compat
  30. if sys.version < '3':
  31. reload(sys)
  32. sys.setdefaultencoding('utf-8')
  33. _logger = logging.getLogger(__name__)
  34. class BlbClient(bce_base_client.BceBaseClient):
  35. """
  36. BLB base sdk client
  37. """
  38. version = b'/v1'
  39. def __init__(self, config=None):
  40. bce_base_client.BceBaseClient.__init__(self, config)
  41. def _merge_config(self, config=None):
  42. """
  43. :param config:
  44. :type config: baidubce.BceClientConfiguration
  45. :return:
  46. """
  47. if config is None:
  48. return self.config
  49. else:
  50. new_config = copy.copy(self.config)
  51. new_config.merge_non_none_values(config)
  52. return new_config
  53. def _send_request(self, http_method, path,
  54. body=None, headers=None, params=None,
  55. config=None, body_parser=None):
  56. config = self._merge_config(config)
  57. if body_parser is None:
  58. body_parser = handler.parse_json
  59. if headers is None:
  60. headers = {b'Accept': b'*/*',
  61. b'Content-Type': b'application/json;charset=utf-8'}
  62. return bce_http_client.send_request(
  63. config, bce_v1_signer.sign, [handler.parse_error, body_parser],
  64. http_method, path, body, headers, params)
  65. @required(vpc_id=(bytes, str),
  66. subnet_id=(bytes, str))
  67. def create_loadbalancer(self, vpc_id, subnet_id, name=None,
  68. desc=None, client_token=None, config=None):
  69. """
  70. Create a LoadBalancer with the specified options.
  71. :param name:
  72. the name of LoadBalancer to create
  73. :type name: string
  74. :param desc:
  75. The description of LoadBalancer
  76. :type desc: string
  77. :param vpc_id:
  78. id of vpc which the LoadBalancer belong to
  79. :type vpc_id: string
  80. :param subnet_id:
  81. id of subnet which the LoadBalancer belong to
  82. :type subnet_id: string
  83. :param client_token:
  84. If the clientToken is not specified by the user, a random String
  85. generated by default algorithm will be used.
  86. :type client_token: string
  87. :param config:
  88. :type config: baidubce.BceClientConfiguration
  89. :return:
  90. :rtype baidubce.bce_response.BceResponse
  91. """
  92. path = utils.append_uri(self.version, 'blb')
  93. params = {}
  94. if client_token is None:
  95. params[b'clientToken'] = generate_client_token()
  96. else:
  97. params[b'clientToken'] = client_token
  98. body = {}
  99. if name is not None:
  100. body['name'] = compat.convert_to_string(name)
  101. if desc is not None:
  102. body['desc'] = compat.convert_to_string(desc)
  103. body['vpcId'] = compat.convert_to_string(vpc_id)
  104. body['subnetId'] = compat.convert_to_string(subnet_id)
  105. return self._send_request(http_methods.POST, path,
  106. body=json.dumps(body), params=params,
  107. config=config)
  108. def describe_loadbalancers(self, address=None, name=None, blb_id=None,
  109. bcc_id=None, marker=None, max_keys=None,
  110. config=None):
  111. """
  112. Return a list of LoadBalancers
  113. :param address:
  114. Intranet service address in dotted decimal notation
  115. :type address: string
  116. :param name:
  117. name of LoadBalancer to describe
  118. :type name: string
  119. :param blb_id:
  120. id of LoadBalancer to describe
  121. :type blb_id: string
  122. :param bcc_id:
  123. bcc which bind the LoadBalancers
  124. :type bcc_id: string
  125. :param marker:
  126. The optional parameter marker specified in the original
  127. request to specify where in the results to begin listing.
  128. Together with the marker, specifies the list result
  129. which listing should begin.
  130. If the marker is not specified, the list result will
  131. listing from the first one.
  132. :type marker: string
  133. :param max_keys
  134. The optional parameter to specifies the max number of list
  135. result to return.
  136. The default value is 1000.
  137. :type max_keys: int
  138. :param config:
  139. :type config: baidubce.BceClientConfiguration
  140. :return:
  141. :rtype baidubce.bce_response.BceResponse
  142. """
  143. path = utils.append_uri(self.version, 'blb')
  144. params = {}
  145. if address is not None:
  146. params[b'address'] = address
  147. if name is not None:
  148. params[b'name'] = name
  149. if blb_id is not None:
  150. params[b'blbId'] = blb_id
  151. if bcc_id is not None:
  152. params[b'bccId'] = bcc_id
  153. if marker is not None:
  154. params[b'marker'] = marker
  155. if max_keys is not None:
  156. params[b'maxKeys'] = max_keys
  157. return self._send_request(http_methods.GET, path,
  158. params=params, config=config)
  159. @required(blb_id=(bytes, str))
  160. def describe_loadbalancer_detail(self, blb_id, config=None):
  161. """
  162. Return detail imformation of specific LoadBalancer
  163. :param blb_id:
  164. id of LoadBalancer to describe
  165. :type blb_id: string
  166. :param config:
  167. :type config: baidubce.BceClientConfiguration
  168. :return:
  169. :rtype baidubce.bce_response.BceResponse
  170. """
  171. path = utils.append_uri(self.version, 'blb', blb_id)
  172. return self._send_request(http_methods.GET, path,
  173. config=config)
  174. @required(blbId=(bytes, str))
  175. def update_loadbalancer(self, blb_id, name=None, desc=None,
  176. client_token=None, config=None):
  177. """
  178. Modify the special attribute to new value of the LoadBalancer
  179. owned by the user.
  180. :param name:
  181. name of LoadBalancer to describe
  182. :type name: string
  183. :param blb_id:
  184. id of LoadBalancer to describe
  185. :type blb_id: string
  186. :param desc:
  187. The description of LoadBalancer
  188. :type desc: string
  189. :param client_token:
  190. If the clientToken is not specified by the user,
  191. a random String generated by default algorithm
  192. will be used.
  193. :type client_token: string
  194. :param config:
  195. :type config: baidubce.BceClientConfiguration
  196. :return:
  197. :rtype baidubce.bce_response.BceResponse
  198. """
  199. path = utils.append_uri(self.version, 'blb', blb_id)
  200. params = {}
  201. if client_token is None:
  202. params[b'clientToken'] = generate_client_token()
  203. else:
  204. params[b'clientToken'] = client_token
  205. body = {}
  206. if name is not None:
  207. body['name'] = compat.convert_to_string(name)
  208. if desc is not None:
  209. body['desc'] = compat.convert_to_string(desc)
  210. return self._send_request(http_methods.PUT, path, json.dumps(body),
  211. params=params, config=config)
  212. @required(blb_id=(bytes, str))
  213. def delete_loadbalancer(self, blb_id, client_token=None, config=None):
  214. """
  215. delete the LoadBalancer owned by the user.
  216. :param blb_id:
  217. id of LoadBalancer to describe
  218. :type blb_id: string
  219. :param client_token:
  220. If the clientToken is not specified by the user,
  221. a random String generated by default algorithm
  222. will be used.
  223. :type client_token: string
  224. :param config:
  225. :type config: baidubce.BceClientConfiguration
  226. :return:
  227. :rtype baidubce.bce_response.BceResponse
  228. """
  229. path = utils.append_uri(self.version, 'blb', blb_id)
  230. params = {}
  231. if client_token is None:
  232. params[b'clientToken'] = generate_client_token()
  233. else:
  234. params[b'clientToken'] = client_token
  235. return self._send_request(http_methods.DELETE, path,
  236. params=params, config=config)
  237. @required(blb_id=(bytes, str))
  238. def update_loadbalancer_acl(self, blb_id, client_token=None, support_acl=None, config=None):
  239. """
  240. update the specified LoadBalancer to support the acl feature.
  241. :param blb_id:
  242. id of LoadBalancer to describe
  243. :type blb_id: string
  244. :param client_token:
  245. If the clientToken is not specified by the user,
  246. a random String generated by default algorithm
  247. will be used.
  248. :type client_token: string
  249. :param support_acl:
  250. parameters to support LoadBalancer acl, default is true.
  251. :type support_acl: Boolean
  252. :param config:
  253. :type config: baidubce.BceClientConfiguration
  254. :return:
  255. :rtype baidubce.bce_response.BceResponse
  256. """
  257. path = utils.append_uri(self.version, 'blb/acl', blb_id)
  258. params = {}
  259. if client_token is None:
  260. params[b'clientToken'] = generate_client_token()
  261. else:
  262. params[b'clientToken'] = client_token
  263. body = {}
  264. if support_acl is not None:
  265. body['supportAcl'] = support_acl
  266. else:
  267. body['supportAcl'] = True
  268. return self._send_request(http_methods.PUT, path, json.dumps(body),
  269. params=params, config=config)
  270. @required(vpc_id=(bytes, str),
  271. subnet_id=(bytes, str))
  272. def create_ipv6_loadbalancer(self, vpc_id, subnet_id, name=None,
  273. desc=None, client_token=None, config=None):
  274. """
  275. Create a LoadBalancer with the specified options.
  276. :param name:
  277. the name of LoadBalancer to create
  278. :type name: string
  279. :param desc:
  280. The description of LoadBalancer
  281. :type desc: string
  282. :param vpc_id:
  283. id of vpc which the LoadBalancer belong to
  284. :type vpc_id: string
  285. :param subnet_id:
  286. id of subnet which the LoadBalancer belong to
  287. :type subnet_id: string
  288. :param client_token:
  289. If the clientToken is not specified by the user, a random String
  290. generated by default algorithm will be used.
  291. :type client_token: string
  292. :param config:
  293. :type config: baidubce.BceClientConfiguration
  294. :return:
  295. :rtype baidubce.bce_response.BceResponse
  296. """
  297. path = utils.append_uri(self.version, 'blb')
  298. params = {}
  299. if client_token is None:
  300. params[b'clientToken'] = generate_client_token()
  301. else:
  302. params[b'clientToken'] = client_token
  303. body = {}
  304. if name is not None:
  305. body['name'] = compat.convert_to_string(name)
  306. if desc is not None:
  307. body['desc'] = compat.convert_to_string(desc)
  308. body['vpcId'] = compat.convert_to_string(vpc_id)
  309. body['subnetId'] = compat.convert_to_string(subnet_id)
  310. body['type'] = compat.convert_to_string('ipv6')
  311. return self._send_request(http_methods.POST, path,
  312. body=json.dumps(body), params=params,
  313. config=config)
  314. def describe_ipv6_loadbalancers(self, address=None, name=None, blb_id=None,
  315. bcc_id=None, marker=None, max_keys=None,
  316. config=None):
  317. """
  318. Return a list of LoadBalancers
  319. :param address:
  320. Intranet service address in dotted decimal notation
  321. :type address: string
  322. :param name:
  323. name of LoadBalancer to describe
  324. :type name: string
  325. :param blb_id:
  326. id of LoadBalancer to describe
  327. :type blb_id: string
  328. :param bcc_id:
  329. bcc which bind the LoadBalancers
  330. :type bcc_id: string
  331. :param marker:
  332. The optional parameter marker specified in the original
  333. request to specify where in the results to begin listing.
  334. Together with the marker, specifies the list result
  335. which listing should begin.
  336. If the marker is not specified, the list result will
  337. listing from the first one.
  338. :type marker: string
  339. :param max_keys
  340. The optional parameter to specifies the max number of list
  341. result to return.
  342. The default value is 1000.
  343. :type max_keys: int
  344. :param config:
  345. :type config: baidubce.BceClientConfiguration
  346. :return:
  347. :rtype baidubce.bce_response.BceResponse
  348. """
  349. path = utils.append_uri(self.version, 'blb')
  350. params = {}
  351. if address is not None:
  352. params[b'address'] = address
  353. if name is not None:
  354. params[b'name'] = name
  355. if blb_id is not None:
  356. params[b'blbId'] = blb_id
  357. if bcc_id is not None:
  358. params[b'bccId'] = bcc_id
  359. if marker is not None:
  360. params[b'marker'] = marker
  361. if max_keys is not None:
  362. params[b'maxKeys'] = max_keys
  363. params[b'type'] = compat.convert_to_string('ipv6')
  364. return self._send_request(http_methods.GET, path,
  365. params=params, config=config)
  366. @required(blb_id=(bytes, str),
  367. listener_port=int,
  368. backend_port=int,
  369. scheduler=(bytes, str))
  370. def create_tcp_listener(self, blb_id, listener_port,
  371. backend_port, scheduler,
  372. health_check_timeout_in_second=None,
  373. health_check_interval=None,
  374. unhealthy_threshold=None,
  375. healthy_threshold=None,
  376. client_token=None, config=None):
  377. """
  378. Create a tcp listener rule with the specified options.
  379. :param blb_id:
  380. the id of blb which the listener work on
  381. :type blb_id: string
  382. :param listener_port:
  383. port to be linstened owned by listener
  384. :value 1-65535
  385. :type listener_port: int
  386. :param backend_port:
  387. port to be listened owned by Backend server
  388. :value 1-65535
  389. :type backend_port: int
  390. :param scheduler
  391. balancing algorithm
  392. :value 'RoundRobin' or 'LeastConnection' or 'Hash'
  393. :type scheduler: string
  394. :param health_check_timeout_in_second
  395. Health check timeout
  396. :value 1-60, default: 3, unit: seconds
  397. :type health_check_timeout_in_second: string
  398. :param health_check_interval
  399. Health check interval
  400. :value 1-10, default: 3, unit: seconds
  401. :type health_check_interval: string
  402. :param unhealthy_threshold
  403. Unhealthy threshold,
  404. how many consecutive health check failures,
  405. shielding the backend server
  406. :value 2-5, default: 3
  407. :type unhealthy_threshold: string
  408. :param healthy_threshold
  409. Health threshold,
  410. how many consecutive health checks are successful,
  411. then re-use the back-end server
  412. :value 2-5, default: 3
  413. :type healthy_threshold: string
  414. :param client_token:
  415. If the clientToken is not specified by the user, a random String
  416. generated by default algorithm will be used.
  417. :type client_token: string
  418. :param config:
  419. :type config: baidubce.BceClientConfiguration
  420. :return:
  421. :rtype baidubce.bce_response.BceResponse
  422. """
  423. path = utils.append_uri(self.version, 'blb', blb_id, 'TCPlistener')
  424. params = {}
  425. if client_token is None:
  426. params[b'clientToken'] = generate_client_token()
  427. else:
  428. params[b'clientToken'] = client_token
  429. body = {
  430. 'listenerPort': listener_port,
  431. 'backendPort': backend_port,
  432. 'scheduler': compat.convert_to_string(scheduler)
  433. }
  434. if health_check_timeout_in_second is not None:
  435. body['healthCheckTimeoutInSecond'] = \
  436. health_check_timeout_in_second
  437. if health_check_interval is not None:
  438. body['healthCheckInterval'] = health_check_interval
  439. if unhealthy_threshold is not None:
  440. body['unhealthyThreshold'] = unhealthy_threshold
  441. if healthy_threshold is not None:
  442. body['healthyThreshold'] = healthy_threshold
  443. return self._send_request(http_methods.POST, path,
  444. body=json.dumps(body), params=params,
  445. config=config)
  446. @required(blb_id=(bytes, str),
  447. listener_port=int,
  448. backend_port=int,
  449. scheduler=(bytes, str),
  450. health_check_string=(bytes, str))
  451. def create_udp_listener(self, blb_id, listener_port, backend_port,
  452. scheduler, health_check_string,
  453. health_check_type=None,
  454. health_check_port=None,
  455. health_check_timeout_in_second=None,
  456. health_check_interval=None,
  457. unhealthy_threshold=None,
  458. healthy_threshold=None,
  459. client_token=None, config=None):
  460. """
  461. Create a udp listener rule with the specified options.
  462. :param blb_id:
  463. the id of blb which the listener work on
  464. :type blb_id: string
  465. :param listener_port:
  466. port to be linstened owned by listener
  467. :value 1-65535
  468. :type listener_port: int
  469. :param backend_port:
  470. port to be listened owned by Backend server
  471. :value 1-65535
  472. :type backend_port: int
  473. :param scheduler
  474. balancing algorithm
  475. :value 'RoundRobin' or 'LeastConnection' or 'Hash'
  476. :type scheduler: string
  477. :param health_check_string
  478. The request string sent by the health,
  479. the backend server needs to respond after receiving it.
  480. :type health_check_string: string
  481. :param health_check_type
  482. Health check protocol
  483. :value 'UDP' or 'ICMP'
  484. :type health_check_type: string
  485. :param health_check_port
  486. Health check port, the default is the same as backend_port.
  487. :type health_check_port: int
  488. :param health_check_timeout_in_second
  489. Health check timeout
  490. :value 1-60, default: 3, unit: seconds
  491. :type health_check_timeout_in_second: string
  492. :param health_check_interval
  493. Health check interval
  494. :value 1-10, default: 3, unit: seconds
  495. :type health_check_interval: string
  496. :param unhealthy_threshold
  497. Unhealthy threshold,
  498. how many consecutive health check failures,
  499. shielding the backend server
  500. :value 2-5, default: 3
  501. :type unhealthy_threshold: string
  502. :param healthy_threshold
  503. Health threshold,
  504. how many consecutive health checks are successful,
  505. then re-use the back-end server
  506. :value 2-5, default: 3
  507. :type healthy_threshold: string
  508. :param client_token:
  509. If the clientToken is not specified by the user, a random String
  510. generated by default algorithm will be used.
  511. :type client_token: string
  512. :param config:
  513. :type config: baidubce.BceClientConfiguration
  514. :return:
  515. :rtype baidubce.bce_response.BceResponse
  516. """
  517. path = utils.append_uri(self.version, 'blb', blb_id, 'UDPlistener')
  518. params = {}
  519. if client_token is None:
  520. params[b'clientToken'] = generate_client_token()
  521. else:
  522. params[b'clientToken'] = client_token
  523. body = {
  524. 'listenerPort': listener_port,
  525. 'backendPort': backend_port,
  526. 'scheduler': compat.convert_to_string(scheduler),
  527. 'healthCheckString': compat.convert_to_string(health_check_string)
  528. }
  529. if health_check_type is not None:
  530. body['healthCheckType'] = health_check_type
  531. if health_check_port is not None:
  532. body['healthCheckPort'] = health_check_port
  533. if health_check_timeout_in_second is not None:
  534. body['healthCheckTimeoutInSecond'] = \
  535. health_check_timeout_in_second
  536. if health_check_interval is not None:
  537. body['healthCheckInterval'] = health_check_interval
  538. if unhealthy_threshold is not None:
  539. body['unhealthyThreshold'] = unhealthy_threshold
  540. if healthy_threshold is not None:
  541. body['healthyThreshold'] = healthy_threshold
  542. return self._send_request(http_methods.POST, path,
  543. body=json.dumps(body), params=params,
  544. config=config)
  545. @required(blb_id=(bytes, str), listener_port=int,
  546. backend_port=int, scheduler=(bytes, str))
  547. def create_http_listener(self, blb_id, listener_port,
  548. backend_port, scheduler,
  549. keep_session=None, keep_session_type=None,
  550. keep_session_duration=None,
  551. keep_session_cookie_name=None,
  552. x_forward_for=None,
  553. health_check_type=None, health_check_port=None,
  554. health_check_uri=None,
  555. health_check_timeout_in_second=None,
  556. health_check_interval=None,
  557. unhealthy_threshold=None,
  558. healthy_threshold=None,
  559. health_check_normal_status=None,
  560. server_timeout=None, redirect_port=None,
  561. client_token=None, config=None):
  562. """
  563. Create a http listener rule with the specified options.
  564. :param blb_id:
  565. the id of blb which the listener work on
  566. :type blb_id: string
  567. :param listener_port:
  568. port to be linstened owned by listener
  569. :value 1-65535
  570. :type listener_port: int
  571. :param backend_port:
  572. port to be listened owned by Backend server
  573. :value 1-65535
  574. :type backend_port: int
  575. :param scheduler:
  576. balancing algorithm
  577. :value 'RoundRobin' or 'LeastConnection'
  578. :type scheduler: string
  579. :param keep_session:
  580. Whether to enable the session hold function,
  581. that is,the request sent by the same client will
  582. reach the same backend server
  583. :value true or false default:false
  584. :type keep_session: bool
  585. :param keep_session_type:
  586. The cookie handling method maintained by the session,
  587. valid only if the session is held open
  588. :value 'insert' or 'rewrite' default:insert
  589. :type keep_session_type: string
  590. :param keep_session_duration:
  591. The time the cookie is kept in session (in seconds),
  592. valid only if the session is held open
  593. :value 1-15552000 default:3600
  594. :type keep_session_duration: int
  595. :param keep_session_cookie_name:
  596. The session keeps the name of the cookie that needs to be
  597. overridden if and only if session persistence is enabled
  598. and keep_session_type="rewrite"
  599. :type keep_session_cookie_name: int
  600. :param x_forward_for:
  601. Whether to enable the real IP address of the client,
  602. the backend server can obtain the real address of the client
  603. through the X-Forwarded-For HTTP header.
  604. :value true or false, default: False
  605. :type x_forward_for: bool
  606. :param health_check_type:
  607. Health check protocol
  608. :value 'HTTP' or 'TCP'
  609. :type health_check_type: string
  610. :param health_check_port:
  611. Health check port, the default is the same as backend_port
  612. :type health_check_port: int
  613. :param health_check_uri:
  614. Health check URI, default '/'.
  615. Effective when the health check protocol is "HTTP"
  616. :type health_check_uri: string
  617. :param health_check_timeout_in_second:
  618. Health check timeout (unit: second)
  619. :value 1-60, default: 3
  620. :type health_check_timeout_in_second: int
  621. :param health_check_interval:
  622. Health check interval (unit: second)
  623. :value 1-10, default: 3
  624. :type health_check_interval: int
  625. :param unhealthy_threshold:
  626. The unhealthy threshold, that is,
  627. how many consecutive health check failures,
  628. shields the backend server.
  629. :value 2-5, default: 3
  630. :type unhealthy_threshold: int
  631. :param healthy_threshold:
  632. Health threshold, that is,
  633. how many consecutive health checks are successful,
  634. then re-use the back-end server
  635. value: 2-5, default: 3
  636. :type health_threshold: int
  637. :param health_check_normal_status:
  638. The HTTP status code when the health check is normal supports
  639. a combination of five types of status codes,
  640. such as "http_1xx|http_2xx",
  641. Effective when the health check protocol is "HTTP"
  642. :value default:http_2xx|http_3xx
  643. :type health_check_normal_status:string
  644. :param server_timeout:
  645. Backend server maximum timeout (unit: second)
  646. :value 1-3600, default: 30
  647. :type server_timeout:int
  648. :param redirect_port:
  649. Forward the request received by this listener to the
  650. HTTPS listener, which is specified by the HTTPS listener.
  651. :type redirect_port:int
  652. :param client_token:
  653. If the clientToken is not specified by the user,
  654. a random String generated by default algorithm will be used.
  655. :type client_token: string
  656. :param config:
  657. :type config: baidubce.BceClientConfiguration
  658. :return:
  659. :rtype baidubce.bce_response.BceResponse
  660. """
  661. path = utils.append_uri(self.version, 'blb', blb_id, 'HTTPlistener')
  662. params = {}
  663. if client_token is None:
  664. params[b'clientToken'] = generate_client_token()
  665. else:
  666. params[b'clientToken'] = client_token
  667. body = {
  668. 'listenerPort': listener_port,
  669. 'backendPort': backend_port,
  670. 'scheduler': compat.convert_to_string(scheduler)}
  671. if keep_session is not None:
  672. body['keepSession'] = keep_session
  673. if keep_session_type is not None:
  674. body['keepSessionType'] = keep_session_type
  675. if keep_session_duration is not None:
  676. body['keepSessionDuration'] = keep_session_duration
  677. if keep_session_cookie_name is not None:
  678. body['keepSessionCookieName'] = keep_session_cookie_name
  679. if x_forward_for is not None:
  680. body['xForwardFor'] = x_forward_for
  681. if health_check_type is not None:
  682. body['healthCheckType'] = \
  683. compat.convert_to_string(health_check_type)
  684. if health_check_port is not None:
  685. body['healthCheckPort'] = health_check_port
  686. if health_check_uri is not None:
  687. body['healthCheckURI'] = \
  688. compat.convert_to_string(health_check_uri)
  689. if health_check_timeout_in_second is not None:
  690. body['healthCheckTimeoutInSecond'] = \
  691. health_check_timeout_in_second
  692. if health_check_interval is not None:
  693. body['healthCheckInterval'] = health_check_interval
  694. if unhealthy_threshold is not None:
  695. body['unhealthyThreshold'] = unhealthy_threshold
  696. if healthy_threshold is not None:
  697. body['healthyThreshold'] = healthy_threshold
  698. if health_check_normal_status is not None:
  699. body['healthCheckNormalStatus'] = \
  700. compat.convert_to_string(health_check_normal_status)
  701. if server_timeout is not None:
  702. body['serverTimeout'] = server_timeout
  703. if redirect_port is not None:
  704. body['redirectPort'] = redirect_port
  705. return self._send_request(http_methods.POST, path,
  706. body=json.dumps(body), params=params,
  707. config=config)
  708. @required(blb_id=(bytes, str), listener_port=int,
  709. backend_port=int, scheduler=(bytes, str), cert_ids=list)
  710. def create_https_listener(self, blb_id, listener_port, backend_port,
  711. scheduler, cert_ids, keep_session=None,
  712. keep_session_type=None,
  713. keep_session_duration=None,
  714. keep_session_cookie_name=None,
  715. x_forward_for=None, health_check_type=None,
  716. health_check_port=None, health_check_uri=None,
  717. health_check_timeout_in_second=None,
  718. health_check_interval=None,
  719. unhealth_threshold=None, health_threshold=None,
  720. health_check_normal_status=None,
  721. server_timeout=None, ie6_compatible=None,
  722. encryption_type=None, encryption_protocols=None,
  723. dual_auth=None, client_certIds=None,
  724. additional_cert_domains=None,
  725. client_token=None, config=None):
  726. """
  727. Create a https listener rule with the specified options
  728. :param blb_id:
  729. The id of blb which the listener work on
  730. :type blb_id: string
  731. :param listener_port:
  732. port to be linstened owned by listener
  733. :value 1-65535
  734. :type listener_port: int
  735. :param backend_port:
  736. Port to be listened owned by Backend server
  737. :value 1-65535
  738. :type backend_port: int
  739. :param scheduler:
  740. balancing algorithm
  741. :value 'RoundRobin' or 'LeastConnection'
  742. :type scheduler: string
  743. :param cert_ids:
  744. The certificate to be loaded by the listener.
  745. :type cert_ids: List<String>
  746. :param keep_session:
  747. Whether to enable the session hold function,
  748. that is, the request sent by the same client will reach the
  749. same backend server
  750. :value true or false, default: false
  751. :type keep_session: bool
  752. :param keep_session_type:
  753. The cookie handling method maintained by the session,
  754. valid only if the session is held open
  755. :value 'insert' or 'rewrite', default:insert
  756. :type keep_session_type: string
  757. :param keep_session_duration:
  758. The time the cookie is kept in session (in seconds),
  759. valid only if the session is held open
  760. :value 1-15552000, default:3600
  761. :type keep_session_duration: int
  762. :param keep_session_cookie_name:
  763. The session keeps the name of the cookie that needs
  764. to be overridden if and only if session persistence
  765. is enabled and keep_session_type="rewrite"
  766. :type keep_session_cookie_name: int
  767. :param x_forward_for:
  768. Whether to enable the real IP address of the client,
  769. the backend server can obtain the real address of the client
  770. through the X-Forwarded-For HTTP header.
  771. :value true or false, default: flase
  772. :type x_forward_for: bool
  773. :param health_check_type:
  774. Health check protocol
  775. :value 'HTTP' or 'TCP'
  776. :type health_check_type: string
  777. :param health_check_port:
  778. Health check port, the default is the same as backend_port
  779. :type health_check_port: int
  780. :param health_check_uri:
  781. Health check URI, default '/'.
  782. Effective when the health check protocol is "HTTP"
  783. :type health_check_uri: string
  784. :param health_check_timeout_in_second:
  785. Health check timeout (unit: second)
  786. :value 1-60, default:3
  787. :type health_check_timeout_in_second: int
  788. :param health_check_interval:
  789. Health check interval (unit: second)
  790. :value 1-10, default: 3
  791. :type health_check_interval: int
  792. :param unhealth_threshold:
  793. The unhealthy threshold, that is, how many consecutive health
  794. check failures, shields the backend server.
  795. :value 2-5, default: 3
  796. :type unhealth_threshold: int
  797. :param health_threshold:
  798. Health threshold, that is, how many consecutive health checks
  799. are successful, then re-use the back-end server
  800. :value:2-5, default: 3
  801. :type health_threshold: int
  802. :param health_check_normal_status:
  803. The HTTP status code when the health check is normal
  804. supports a combination of five types of status codes,
  805. such as "http_1xx|http_2xx", Effective when the health check
  806. protocol is "HTTP"
  807. :value default: http_2xx|http_3xx
  808. :type health_check_normal_status: string
  809. :param server_timeout:
  810. Backend server maximum timeout (unit: second)
  811. :value 1-3600, default: 30
  812. :type server_timeout: int
  813. :param ie6_compatible:
  814. compatible with IE6 HTTPS request
  815. (the protocol format is earlier SSL3.0, the security is poor)
  816. :value true or false, default: true
  817. :type ie6_compatible: bool
  818. :param encryption_type:
  819. Encryption options, support three types:
  820. compatibleIE or incompatibleIE or userDefind,
  821. corresponding to:
  822. IE-compatible encryption or disabled unsecure encryption
  823. or custom encryption,
  824. when encryptionType is valid and legitimate,
  825. ie6Compatible field transfer value will not take effect
  826. type: encryption_type:string
  827. :param encryption_protocols:
  828. When the encryptionType value is userDefind,
  829. the list of protocol types is a string list composed of four protocols:
  830. "sslv3", "tlsv10", "tlsv11", "tlsv12".
  831. type: encryption_protocols:list
  832. :param dual_auth:
  833. Whether to Open Two-way Authentication,
  834. default:false
  835. :type dual_auth: boolean
  836. :param client_certIds:
  837. When dualAuth is true, the loaded client certificate chain
  838. :type client_certIds: list
  839. :param additional_cert_domains:
  840. Additional domain name,each element is an object that contains two attributes, namely "certId" and "host"
  841. :type additional_cert_domains: list
  842. :param client_token:
  843. If the clientToken is not specified by the user,
  844. a random String generated by default algorithm will be used.
  845. :type client_token: string
  846. :param config:
  847. :type config: baidubce.BceClientConfiguration
  848. :return
  849. :rtype baidubce.bce_response.BceResponse
  850. """
  851. path = utils.append_uri(self.version, 'blb', blb_id, 'HTTPSlistener')
  852. params = {}
  853. if client_token is None:
  854. params[b'clientToken'] = generate_client_token()
  855. else:
  856. params[b'clientToken'] = client_token
  857. body = {
  858. 'listenerPort': listener_port, 'backendPort': backend_port,
  859. 'scheduler': compat.convert_to_string(scheduler),
  860. 'certIds': cert_ids}
  861. if keep_session is not None:
  862. body['keepSession'] = keep_session
  863. if keep_session_type is not None:
  864. body['keepSessionType'] = \
  865. compat.convert_to_string(keep_session_type)
  866. if keep_session_duration is not None:
  867. body['keepSessionDuration'] = keep_session_duration
  868. if keep_session_cookie_name is not None:
  869. body['keepSessionCookieName'] = keep_session_cookie_name
  870. if x_forward_for is not None:
  871. body['xForwardFor'] = x_forward_for
  872. if health_check_type is not None:
  873. body['healthCheckType'] = \
  874. compat.convert_to_string(health_check_type)
  875. if health_check_port is not None:
  876. body['healthCheckPort'] = health_check_port
  877. if health_check_uri is not None:
  878. body['healthCheckURI'] = \
  879. compat.convert_to_string(health_check_uri)
  880. if health_check_timeout_in_second is not None:
  881. body['healthCheckTimeoutInSecond'] = \
  882. health_check_timeout_in_second
  883. if health_check_interval is not None:
  884. body['healthCheckInterval'] = health_check_interval
  885. if unhealth_threshold is not None:
  886. body['unhealthyThreshold'] = unhealth_threshold
  887. if health_threshold is not None:
  888. body['healthyThreshold'] = health_threshold
  889. if health_check_normal_status is not None:
  890. body['healthCheckNormalStatus'] = \
  891. compat.convert_to_string(health_check_normal_status)
  892. if server_timeout is not None:
  893. body['serverTimeout'] = server_timeout
  894. if ie6_compatible is not None:
  895. body['ie6Compatible'] = ie6_compatible
  896. if encryption_type is not None:
  897. body['encryptionType'] = \
  898. compat.convert_to_string(encryption_type)
  899. if encryption_protocols is not None:
  900. body['encryptionProtocols'] = encryption_protocols
  901. if dual_auth is not None:
  902. body['dualAuth'] = dual_auth
  903. if client_certIds is not None:
  904. body['clientCertIds'] = client_certIds
  905. if additional_cert_domains is not None:
  906. body['additionalCertDomains'] = additional_cert_domains
  907. return self._send_request(http_methods.POST, path,
  908. body=json.dumps(body),
  909. params=params, config=config)
  910. @required(blb_id=(bytes, str), listener_port=int,
  911. backend_port=int, scheduler=(bytes, str), cert_ids=list)
  912. def create_ssl_listener(self, blb_id, listener_port, backend_port,
  913. scheduler, cert_ids,
  914. health_check_timeout_in_second=None,
  915. health_check_interval=None,
  916. unhealth_threshold=None, health_threshold=None,
  917. ie6_compatible=None, encryption_type=None,
  918. encryption_protocols=None,
  919. dual_auth=None, client_certIds=None,
  920. client_token=None, config=None):
  921. """
  922. Create a ssl listener rule with thSe specified options.
  923. :param blb_id:
  924. The id of blb which the listener work on
  925. :type blb_id: string
  926. :param listener_port:
  927. port to be linstened owned by listener
  928. :value 1-65535
  929. :type listener_port: int
  930. :param backend_port:
  931. Port to be listened owned by Backend server
  932. :value 1-65535
  933. :type backend_port: int
  934. :param scheduler:
  935. balancing algorithm
  936. :value 'RoundRobin' or 'LeastConnection'
  937. :type scheduler: string
  938. :param cert_ids:
  939. The SSL certificate to be loaded by the listener.
  940. Currently HTTPS listeners can only bind one SSL certificate.
  941. :type cert_ids: List<String>
  942. :param health_check_timeout_in_second:
  943. Health check timeout (unit: second)
  944. :value 1-60, default:3
  945. :type health_check_timeout_in_second: int
  946. :param health_check_interval:
  947. Health check interval (unit: second)
  948. :value 1-10, default: 3
  949. :type health_check_interval: int
  950. :param unhealth_threshold:
  951. The unhealthy threshold, that is, how many consecutive health
  952. check failures, shields the backend server.
  953. :value 2-5, default: 3
  954. :type unhealth_threshold: int
  955. :param health_threshold:
  956. Health threshold, that is, how many consecutive health checks
  957. are successful, then re-use the back-end server
  958. :value:2-5, default: 3
  959. :type health_threshold: int
  960. :param ie6_compatible:
  961. compatible with IE6 HTTPS request
  962. (the protocol format is earlier SSL3.0, the security is poor)
  963. :value true or false, default: true
  964. :type ie6_compatible: bool
  965. :param encryption_type:
  966. Encryption options, support three types:
  967. compatibleIE or incompatibleIE or userDefind,
  968. corresponding to:
  969. IE-compatible encryption or disabled unsecure encryption
  970. or custom encryption,
  971. when encryptionType is valid and legitimate,
  972. ie6Compatible field transfer value will not take effect
  973. type: encryption_type:string
  974. :param encryption_protocols:
  975. When the encryptionType value is userDefind,
  976. the list of protocol types is a string list composed of four protocols:
  977. "sslv3", "tlsv10", "tlsv11", "tlsv12".
  978. type: encryption_protocols:list
  979. :param dual_auth:
  980. Whether to Open Two-way Authentication,
  981. default:false
  982. :type dual_auth: boolean
  983. :param client_certIds:
  984. When dualAuth is true, the loaded client certificate chain
  985. :type client_certIds: list
  986. :param client_token:
  987. If the clientToken is not specified by the user,
  988. a random String generated by default algorithm will be used.
  989. :type client_token: string
  990. :param config:
  991. :type config: baidubce.BceClientConfiguration
  992. :return
  993. :rtype baidubce.bce_response.BceResponse
  994. """
  995. path = utils.append_uri(self.version, 'blb', blb_id, 'SSLlistener')
  996. params = {}
  997. if client_token is None:
  998. params[b'clientToken'] = generate_client_token()
  999. else:
  1000. params[b'clientToken'] = client_token
  1001. body = {
  1002. 'listenerPort': listener_port, 'backendPort': backend_port,
  1003. 'scheduler': compat.convert_to_string(scheduler),
  1004. 'certIds': cert_ids}
  1005. if health_check_timeout_in_second is not None:
  1006. body['healthCheckTimeoutInSecond'] = \
  1007. health_check_timeout_in_second
  1008. if health_check_interval is not None:
  1009. body['healthCheckInterval'] = health_check_interval
  1010. if unhealth_threshold is not None:
  1011. body['unhealthyThreshold'] = unhealth_threshold
  1012. if health_threshold is not None:
  1013. body['healthyThreshold'] = health_threshold
  1014. if ie6_compatible is not None:
  1015. body['ie6Compatible'] = ie6_compatible
  1016. if encryption_type is not None:
  1017. body['encryptionType'] = \
  1018. compat.convert_to_string(encryption_type)
  1019. if encryption_protocols is not None:
  1020. body['encryptionProtocols'] = encryption_protocols
  1021. if dual_auth is not None:
  1022. body['dualAuth'] = dual_auth
  1023. if client_certIds is not None:
  1024. body['clientCertIds'] = client_certIds
  1025. # for test,if not,return internal server error
  1026. # body['healthCheckType'] = "TCP"
  1027. return self._send_request(http_methods.POST, path,
  1028. body=json.dumps(body),
  1029. params=params, config=config)
  1030. @required(blb_id=(bytes, str))
  1031. def describe_tcp_listener(self, blb_id, listener_port=None,
  1032. marker=None, max_keys=None, config=None):
  1033. """
  1034. get tcp listeners identified by blbID
  1035. :param blb_id
  1036. the id of blb which the listener work on
  1037. :type blb_id:string
  1038. :param listener_port
  1039. The listener port to query
  1040. :type listener_port:int
  1041. :param marker
  1042. The optional parameter marker specified in the
  1043. original request to specify
  1044. where in the results to begin listing.
  1045. Together with the marker, specifies the list result
  1046. which listing should begin.
  1047. If the marker is not specified, the list result will
  1048. listing from the first one.
  1049. :type marker: string
  1050. :param max_keys
  1051. The optional parameter to specifies the max number of
  1052. list result to return.
  1053. The default value is 1000.
  1054. :type max_keys: int
  1055. :param config:
  1056. :type config: baidubce.BceClientConfiguration
  1057. :return:
  1058. :rtype baidubce.bce_response.BceResponse
  1059. """
  1060. path = utils.append_uri(self.version, 'blb', blb_id, 'TCPlistener')
  1061. params = {}
  1062. if listener_port is not None:
  1063. params[b'listenerPort'] = listener_port
  1064. if marker is not None:
  1065. params[b'marker'] = marker
  1066. if max_keys is not None:
  1067. params[b'maxKeys'] = max_keys
  1068. return self._send_request(http_methods.GET, path,
  1069. params=params, config=config)
  1070. @required(blb_id=(bytes, str))
  1071. def describe_udp_listener(self, blb_id, listener_port=None, marker=None,
  1072. max_keys=None, config=None):
  1073. """
  1074. get udp listeners identified by blbID
  1075. :param blb_id
  1076. the id of blb which the listener work on
  1077. :type blb_id:string
  1078. :param listener_port
  1079. The listener port to query
  1080. :type listener_port:int
  1081. :param marker
  1082. The optional parameter marker specified in the original
  1083. request to specify where in the results to begin listing.
  1084. Together with the marker, specifies the list result which
  1085. listing should begin.
  1086. If the marker is not specified, the list result will
  1087. listing from the first one.
  1088. :type marker: string
  1089. :param max_keys
  1090. The optional parameter to specifies the max number of
  1091. list result to return.
  1092. The default value is 1000.
  1093. :type max_keys: int
  1094. :param config:
  1095. :type config: baidubce.BceClientConfiguration
  1096. :return:
  1097. :rtype baidubce.bce_response.BceResponse
  1098. """
  1099. path = utils.append_uri(self.version, 'blb', blb_id, 'UDPlistener')
  1100. params = {}
  1101. if listener_port is not None:
  1102. params[b'listenerPort'] = listener_port
  1103. if marker is not None:
  1104. params[b'marker'] = marker
  1105. if max_keys is not None:
  1106. params[b'maxKeys'] = max_keys
  1107. return self._send_request(http_methods.GET, path,
  1108. params=params, config=config)
  1109. @required(blb_id=(bytes, str))
  1110. def describe_http_listener(self, blb_id, listener_port=None,
  1111. marker=None, max_keys=None, config=None):
  1112. """
  1113. get http listeners identified by blbID
  1114. :param blb_id
  1115. the id of blb which the listener work on
  1116. :type blb_id:string
  1117. :param listener_port
  1118. The listener port to query
  1119. :type listener_port:int
  1120. :param marker
  1121. The optional parameter marker specified in the original
  1122. request to specify where in the results to begin listing.
  1123. Together with the marker, specifies the list result which
  1124. listing should begin.
  1125. If the marker is not specified, the list result will listing
  1126. from the first one.
  1127. :type marker: string
  1128. :param max_keys
  1129. The optional parameter to specifies the max number of list
  1130. result to return.
  1131. The default value is 1000.
  1132. :type max_keys: int
  1133. :param config:
  1134. :type config: baidubce.BceClientConfiguration
  1135. :return:
  1136. :rtype baidubce.bce_response.BceResponse
  1137. """
  1138. path = utils.append_uri(self.version, 'blb', blb_id, 'HTTPlistener')
  1139. params = {}
  1140. if listener_port is not None:
  1141. params[b'listenerPort'] = listener_port
  1142. if marker is not None:
  1143. params[b'marker'] = marker
  1144. if max_keys is not None:
  1145. params[b'maxKeys'] = max_keys
  1146. return self._send_request(http_methods.GET, path,
  1147. params=params, config=config)
  1148. @required(blb_id=(bytes, str))
  1149. def describe_https_listener(self, blb_id, listener_port=None,
  1150. marker=None, max_keys=None, config=None):
  1151. """
  1152. get https listeners identified by blbID
  1153. :param blb_id
  1154. the id of blb which the listener work on
  1155. :type blb_id:string
  1156. :param listener_port
  1157. The listener port to query
  1158. :type listener_port:int
  1159. :param marker
  1160. The optional parameter marker specified in the original
  1161. request to specify where in the results to begin listing.
  1162. Together with the marker, specifies the list result which
  1163. listing should begin.
  1164. If the marker is not specified, the list result will listing
  1165. from the first one.
  1166. :type marker: string
  1167. :param max_keys
  1168. The optional parameter to specifies the max number of list
  1169. result to return.
  1170. The default value is 1000.
  1171. :type max_keys: int
  1172. :param config:
  1173. :type config: baidubce.BceClientConfiguration
  1174. :return:
  1175. :rtype baidubce.bce_response.BceResponse
  1176. """
  1177. path = utils.append_uri(self.version, 'blb', blb_id, 'HTTPSlistener')
  1178. params = {}
  1179. if listener_port is not None:
  1180. params[b'listenerPort'] = listener_port
  1181. if marker is not None:
  1182. params[b'marker'] = marker
  1183. if max_keys is not None:
  1184. params[b'maxKeys'] = max_keys
  1185. return self._send_request(http_methods.GET, path,
  1186. params=params, config=config)
  1187. @required(blb_id=(bytes, str))
  1188. def describe_ssl_listener(self, blb_id, listener_port=None,
  1189. marker=None, max_keys=None, config=None):
  1190. """
  1191. get ssl listeners identified by blbID
  1192. :param blb_id
  1193. the id of blb which the listener work on
  1194. :type blb_id:string
  1195. :param listener_port
  1196. The listener port to query
  1197. :type listener_port:int
  1198. :param marker
  1199. The optional parameter marker specified in the original
  1200. request to specify where in the results to begin listing.
  1201. Together with the marker, specifies the list result which
  1202. listing should begin.
  1203. If the marker is not specified, the list result will listing
  1204. from the first one.
  1205. :type marker: string
  1206. :param max_keys
  1207. The optional parameter to specifies the max number of list
  1208. result to return.
  1209. The default value is 1000.
  1210. :type max_keys: int
  1211. :param config:
  1212. :type config: baidubce.BceClientConfiguration
  1213. :return:
  1214. :rtype baidubce.bce_response.BceResponse
  1215. """
  1216. path = utils.append_uri(self.version, 'blb', blb_id, 'SSLlistener')
  1217. params = {}
  1218. if listener_port is not None:
  1219. params[b'listenerPort'] = listener_port
  1220. if marker is not None:
  1221. params[b'marker'] = marker
  1222. if max_keys is not None:
  1223. params[b'maxKeys'] = max_keys
  1224. return self._send_request(http_methods.GET, path,
  1225. params=params, config=config)
  1226. @required(blb_id=(bytes, str))
  1227. def describe_all_listeners(self, blb_id, listener_port=None,
  1228. marker=None, max_keys=None, config=None):
  1229. """
  1230. get all listeners identified by blbID
  1231. :param blb_id
  1232. the id of blb which the listener work on
  1233. :type blb_id:string
  1234. :param listener_port
  1235. The listener port to query
  1236. :type listener_port:int
  1237. :param marker
  1238. The optional parameter marker specified in the original
  1239. request to specify where in the results to begin listing.
  1240. Together with the marker, specifies the list result which
  1241. listing should begin.
  1242. If the marker is not specified, the list result will listing
  1243. from the first one.
  1244. :type marker: string
  1245. :param max_keys
  1246. The optional parameter to specifies the max number of list
  1247. result to return.
  1248. The default value is 1000.
  1249. :type max_keys: int
  1250. :param config:
  1251. :type config: baidubce.BceClientConfiguration
  1252. :return:
  1253. :rtype baidubce.bce_response.BceResponse
  1254. """
  1255. path = utils.append_uri(self.version, 'blb', blb_id, 'listener')
  1256. params = {}
  1257. if listener_port is not None:
  1258. params[b'listenerPort'] = listener_port
  1259. if marker is not None:
  1260. params[b'marker'] = marker
  1261. if max_keys is not None:
  1262. params[b'maxKeys'] = max_keys
  1263. return self._send_request(http_methods.GET, path,
  1264. params=params, config=config)
  1265. @required(blb_id=(bytes, str),
  1266. listener_port=int)
  1267. def update_tcp_listener(self, blb_id, listener_port,
  1268. backend_port=None, scheduler=None,
  1269. health_check_timeout_in_second=None,
  1270. health_check_interval=None,
  1271. unhealth_threshold=None,
  1272. health_threshold=None,
  1273. config=None):
  1274. """
  1275. update a tcp listener rule with the specified options.
  1276. :param blb_id:
  1277. the id of blb which the listener work on
  1278. :type blb_id:string
  1279. :param listener_port:
  1280. port to be linstened owned by listener
  1281. :value 1-65535
  1282. :type listener_port:int
  1283. :param backend_port:
  1284. port to be listened owned by Backend server
  1285. :value 1-65535
  1286. :type backend_port:int
  1287. :param scheduler
  1288. balancing algorithm
  1289. :value 'RoundRobin'or'LeastConnection'or'Hash'
  1290. :type scheduler:string
  1291. :param health_check_timeout_in_second
  1292. Health check timeout
  1293. :value 1-60 default:3 unit:seconds
  1294. :type health_check_timeout_in_second:string
  1295. :param health_check_interval
  1296. Health check interval
  1297. :value 1-10 default:3 unit:seconds
  1298. :type health_check_interval:string
  1299. :param unhealth_threshold
  1300. Unhealthy threshold,
  1301. how many consecutive health check failures,
  1302. shielding the backend server
  1303. :value 2-5 default:3
  1304. :type unhealth_threshold:string
  1305. :param health_threshold
  1306. Health threshold,
  1307. how many consecutive health checks are successful,
  1308. then re-use the back-end server
  1309. :value 2-5 default:3
  1310. :type health_threshold:string
  1311. :param config:
  1312. :type config: baidubce.BceClientConfiguration
  1313. :return:
  1314. :rtype baidubce.bce_response.BceResponse
  1315. """
  1316. path = utils.append_uri(self.version, 'blb', blb_id, 'TCPlistener')
  1317. params = {}
  1318. params[b'listenerPort'] = listener_port
  1319. body = {}
  1320. if backend_port is not None:
  1321. body['backendPort'] = backend_port
  1322. if scheduler is not None:
  1323. body['scheduler'] = compat.convert_to_string(scheduler)
  1324. if health_check_timeout_in_second is not None:
  1325. body['healthCheckTimeoutInSecond'] = \
  1326. health_check_timeout_in_second
  1327. if health_check_interval is not None:
  1328. body['healthCheckInterval'] = health_check_interval
  1329. if unhealth_threshold is not None:
  1330. body['unhealthyThreshold'] = unhealth_threshold
  1331. if health_threshold is not None:
  1332. body['healthyThreshold'] = health_threshold
  1333. return self._send_request(http_methods.PUT, path,
  1334. body=json.dumps(body), params=params,
  1335. config=config)
  1336. @required(blb_id=(bytes, str),
  1337. listener_port=int,
  1338. backend_port=int)
  1339. def update_udp_listener(self, blb_id, listener_port, backend_port=None,
  1340. scheduler=None,
  1341. health_check_type=None,
  1342. health_check_port=None,
  1343. health_check_string=None,
  1344. health_check_timeout_in_second=None,
  1345. health_check_interval=None,
  1346. unhealth_threshold=None,
  1347. health_threshold=None,
  1348. config=None):
  1349. """
  1350. update a udp listener rule with the specified options.
  1351. :param blb_id:
  1352. the id of blb which the listener work on
  1353. :type blb_id:string
  1354. :param listener_port:
  1355. port to be linstened owned by listener
  1356. :value 1-65535
  1357. :type listener_port:int
  1358. :param backend_port:
  1359. port to be listened owned by Backend server
  1360. :value 1-65535
  1361. :type backend_port:int
  1362. :param scheduler
  1363. balancing algorithm
  1364. :value 'RoundRobin'or'LeastConnection'or'Hash'
  1365. :type scheduler:string
  1366. :param health_check_type
  1367. Health check protocol
  1368. :value 'UDP' or 'ICMP'
  1369. :type health_check_type:string
  1370. :param health_check_port
  1371. Health check port, the default is the same as backend_port.
  1372. This field can only be updated if health_check_type is UDP.
  1373. :type health_check_port:int
  1374. :param health_check_string
  1375. The request string sent by the health,
  1376. the backend server needs to respond after receiving it,
  1377. and supports standard escaping
  1378. :type health_check_string:string
  1379. :param health_check_timeout_in_second
  1380. Health check timeout
  1381. :value 1-60 default:3 unit:seconds
  1382. :type health_check_timeout_in_second:string
  1383. :param health_check_interval
  1384. Health check interval
  1385. :value 1-10 default:3 unit:seconds
  1386. :type health_check_interval:string
  1387. :param unhealth_threshold
  1388. Unhealthy threshold,
  1389. how many consecutive health check failures,
  1390. shielding the backend server
  1391. :value 2-5 default:3
  1392. :type unhealth_threshold:string
  1393. :param health_threshold
  1394. Health threshold,
  1395. how many consecutive health checks are successful,
  1396. then re-use the back-end server
  1397. :value 2-5 default:3
  1398. :type health_threshold:string
  1399. :param config:
  1400. :type config: baidubce.BceClientConfiguration
  1401. :return:
  1402. :rtype baidubce.bce_response.BceResponse
  1403. """
  1404. path = utils.append_uri(self.version, 'blb', blb_id, 'UDPlistener')
  1405. params = {}
  1406. params[b'listenerPort'] = listener_port
  1407. body = {}
  1408. if backend_port is not None:
  1409. body['backendPort'] = backend_port
  1410. if scheduler is not None:
  1411. body['scheduler'] = compat.convert_to_string(scheduler)
  1412. if health_check_type is not None:
  1413. body['healthCheckType'] = \
  1414. compat.convert_to_string(health_check_type)
  1415. if health_check_port is not None:
  1416. body['healthCheckPort'] = health_check_port
  1417. if health_check_string is not None:
  1418. body['healthCheckString'] = \
  1419. compat.convert_to_string(health_check_string)
  1420. if health_check_timeout_in_second is not None:
  1421. body['healthCheckTimeoutInSecond'] = \
  1422. health_check_timeout_in_second
  1423. if health_check_interval is not None:
  1424. body['healthCheckInterval'] = health_check_interval
  1425. if unhealth_threshold is not None:
  1426. body['unhealthyThreshold'] = unhealth_threshold
  1427. if health_threshold is not None:
  1428. body['healthyThreshold'] = health_threshold
  1429. return self._send_request(http_methods.PUT, path,
  1430. body=json.dumps(body),
  1431. params=params, config=config)
  1432. @required(blb_id=(bytes, str),
  1433. listener_port=int)
  1434. def update_http_listener(self, blb_id, listener_port, backend_port=None,
  1435. scheduler=None, keep_session=None,
  1436. keep_session_type=None,
  1437. keep_session_duration=None,
  1438. keep_session_cookie_name=None,
  1439. x_forward_for=None,
  1440. health_check_type=None, health_check_port=None,
  1441. health_check_uri=None,
  1442. health_check_timeout_in_second=None,
  1443. health_check_interval=None,
  1444. unhealth_threshold=None, health_threshold=None,
  1445. health_check_normal_status=None,
  1446. server_timeout=None,
  1447. redirect_port=None, config=None):
  1448. """
  1449. update a http listener rule with the specified options.
  1450. :param blb_id:
  1451. The id of blb which the listener work on
  1452. :type blb_id: string
  1453. :param listener_port:
  1454. Port to be linstened owned by listener
  1455. :value 1-65535
  1456. :type listener_port: int
  1457. :param backend_port:
  1458. port to be listened owned by Backend server
  1459. :value 1-65535
  1460. :type backend_port: int
  1461. :param scheduler:
  1462. Balancing algorithm
  1463. :value 'RoundRobin' or 'LeastConnection' or 'Hash'
  1464. :type scheduler: string
  1465. :param keep_session:
  1466. Whether to enable the session hold function, that is,
  1467. the request sent by the same client will reach the
  1468. same backend server
  1469. :value true or false, default:false
  1470. :type keep_session: bool
  1471. :param keep_session_type:
  1472. The cookie handling method maintained by the session,
  1473. valid only if the session is held open
  1474. :value 'insert' or 'rewrite', default:insert
  1475. :type keep_session_type: string
  1476. :param keep_session_duration:
  1477. The time the cookie is kept in session (in seconds),
  1478. valid only if the session is held open
  1479. :value 1-15552000, default:3600
  1480. :type keep_session_duration: int
  1481. :param keep_session_cookie_name:
  1482. The session keeps the name of the cookie that needs
  1483. to be overridden,if and only if session persistence is
  1484. enabled and keep_session_type="rewrite"
  1485. :type keep_session_cookie_name: int
  1486. :param x_forward_for:
  1487. Whether to enable the real IP address of the client,
  1488. the backend server can obtain the real address of the
  1489. client through the X-Forwarded-For HTTP header.
  1490. :value true or false, default: flase
  1491. :type x_forward_for: bool
  1492. :param health_check_type:
  1493. Health check protocol
  1494. :value 'HTTP' or 'TCP'
  1495. :type health_check_type: string
  1496. :param health_check_port:
  1497. Health check port, the default is the same as backend_port
  1498. :type health_check_port: int
  1499. :param health_check_uri:
  1500. Health check URI, default '/'.
  1501. Effective when the health check protocol is "HTTP"
  1502. :type health_check_uri: string
  1503. :param health_check_timeout_in_second:
  1504. Health check timeout (unit: second)
  1505. :value 1-60, default: 3
  1506. :type health_check_timeout_in_second: int
  1507. :param health_check_interval:
  1508. Health check interval (unit: second)
  1509. :value 1-10, default: 3
  1510. :type health_check_interval: int
  1511. :param unhealth_threshold:
  1512. The unhealthy threshold, that is, how many consecutive health
  1513. check failures, shields the backend server.
  1514. :value 2-5, default: 3
  1515. :type unhealth_threshold: int
  1516. :param health_threshold:
  1517. Health threshold, that is, how many consecutive health checks
  1518. are successful, then re-use the back-end server
  1519. :value:2-5, default: 3
  1520. :type health_threshold: int
  1521. :param health_check_normal_status:
  1522. The HTTP status code when the health check is normal supports
  1523. a combination of five types of status codes,
  1524. such as "http_1xx|http_2xx", Effective when the health check
  1525. protocol is "HTTP"
  1526. :value default: http_2xx|http_3xx
  1527. :type health_check_normal_status: string
  1528. :param server_timeout:
  1529. Backend server maximum timeout (unit: second)
  1530. :value 1-3600, default: 30
  1531. :type server_timeout: int
  1532. :param redirect_port:
  1533. Forward the request received by this listener to the HTTPS
  1534. listener, which is specified by the HTTPS listener.
  1535. :type redirect_port: int
  1536. :param config:
  1537. :type config: baidubce.BceClientConfiguration
  1538. :return:
  1539. :rtype baidubce.bce_response.BceResponse
  1540. """
  1541. path = utils.append_uri(self.version, 'blb', blb_id, 'HTTPlistener')
  1542. params = {}
  1543. params[b'listenerPort'] = listener_port
  1544. body = {}
  1545. if backend_port is not None:
  1546. body['backendPort'] = backend_port
  1547. if scheduler is not None:
  1548. body['scheduler'] = compat.convert_to_string(scheduler)
  1549. if keep_session is not None:
  1550. body['keepSession'] = keep_session
  1551. if keep_session_type is not None:
  1552. body['keepSessionType'] = \
  1553. compat.convert_to_string(keep_session_type)
  1554. if keep_session_duration is not None:
  1555. body['keepSessionDuration'] = keep_session_duration
  1556. if keep_session_cookie_name is not None:
  1557. body['keepSessionCookieName'] = keep_session_cookie_name
  1558. if x_forward_for is not None:
  1559. body['xForwardFor'] = x_forward_for
  1560. if health_check_type is not None:
  1561. body['healthCheckType'] = \
  1562. compat.convert_to_string(health_check_type)
  1563. if health_check_port is not None:
  1564. body['healthCheckPort'] = health_check_port
  1565. if health_check_uri is not None:
  1566. body['healthCheckURI'] = \
  1567. compat.convert_to_string(health_check_uri)
  1568. if health_check_timeout_in_second is not None:
  1569. body['healthCheckTimeoutInSecond'] = \
  1570. health_check_timeout_in_second
  1571. if health_check_interval is not None:
  1572. body['healthCheckInterval'] = health_check_interval
  1573. if unhealth_threshold is not None:
  1574. body['unhealthyThreshold'] = unhealth_threshold
  1575. if health_threshold is not None:
  1576. body['healthyThreshold'] = health_threshold
  1577. if health_check_normal_status is not None:
  1578. body['healthCheckNormalStatus'] = \
  1579. compat.convert_to_string(health_check_normal_status)
  1580. if server_timeout is not None:
  1581. body['serverTimeout'] = server_timeout
  1582. if redirect_port is not None:
  1583. body['redirectPort'] = redirect_port
  1584. return self._send_request(http_methods.PUT, path,
  1585. body=json.dumps(body),
  1586. params=params, config=config)
  1587. @required(blb_id=(bytes, str), listener_port=int)
  1588. def update_https_listener(self, blb_id, listener_port,
  1589. backend_port=None,
  1590. scheduler=None, keep_session=None,
  1591. keep_session_type=None,
  1592. keep_session_duration=None,
  1593. keep_session_cookie_name=None,
  1594. x_forward_for=None, health_check_type=None,
  1595. health_check_port=None, health_check_uri=None,
  1596. health_check_timeout_in_second=None,
  1597. health_check_interval=None,
  1598. unhealth_threshold=None, health_threshold=None,
  1599. health_check_normal_status=None,
  1600. server_timeout=None,
  1601. cert_ids=None, additional_cert_domains=None,
  1602. ie6_compatible=None, config=None):
  1603. """
  1604. update a https listener rule with the specified options.
  1605. :param blb_id:
  1606. The id of blb which the listener work on
  1607. :type blb_id: string
  1608. :param listener_port:
  1609. Port to be linstened owned by listener
  1610. :value 1-65535
  1611. :type listener_port: int
  1612. :param backend_port:
  1613. Port to be listened owned by Backend server
  1614. :value 1-65535
  1615. :type backend_port: int
  1616. :param scheduler:
  1617. Balancing algorithm
  1618. :value 'RoundRobin' or 'LeastConnection' or 'Hash'
  1619. :type scheduler: string
  1620. :param keep_session:
  1621. Whether to enable the session hold function, that is, the request
  1622. sent by the same client will reach the same backend server
  1623. :value true or false, default: false
  1624. :type keep_session: bool
  1625. :param keep_session_type:
  1626. The cookie handling method maintained by the session,
  1627. valid only if the session is held open
  1628. :value 'insert' or 'rewrite', default: insert
  1629. :type keep_session_type: string
  1630. :param keep_session_duration:
  1631. The time the cookie is kept in session (in seconds),
  1632. valid only if the session is held open
  1633. :value 1-15552000, default:3600
  1634. :type keep_session_duration: int
  1635. :param keep_session_cookie_name:
  1636. The session keeps the name of the cookie that needs to be
  1637. overridden,if and only if session persistence is enabled and
  1638. keep_session_type="rewrite"
  1639. :type keep_session_cookie_name: int
  1640. :param x_forward_for:
  1641. Whether to enable the real IP address of the client,
  1642. the backend server can obtain the real address of the client
  1643. through the X-Forwarded-For HTTP header.
  1644. :value true or false, default: False
  1645. :type x_forward_for: bool
  1646. :param health_check_type:
  1647. Health check protocol
  1648. :value 'HTTP' or 'TCP'
  1649. :type health_check_type: string
  1650. :param health_check_port:
  1651. Health check port, the default is the same as backend_port
  1652. :type health_check_port: int
  1653. :param health_check_uri:
  1654. Health check URI, default '/'.
  1655. Effective when the health check protocol is "HTTP"
  1656. :type health_check_uri: string
  1657. :param health_check_timeout_in_second:
  1658. Health check timeout (unit: second)
  1659. :value 1-60, default: 3
  1660. :type health_check_timeout_in_second: int
  1661. :param health_check_interval:
  1662. Health check interval (unit: second)
  1663. :value 1-10, default: 3
  1664. :type health_check_interval: int
  1665. :param unhealth_threshold:
  1666. The unhealthy threshold, that is, how many consecutive health
  1667. check failures, shields the backend server.
  1668. :value 2-5, default: 3
  1669. :type unhealth_threshold: int
  1670. :param health_threshold:
  1671. Health threshold, that is, how many consecutive health checks
  1672. are successful, then re-use the back-end server
  1673. :value:2-5, default: 3
  1674. :type health_threshold: int
  1675. :param health_check_normal_status:
  1676. The HTTP status code when the health check is normal supports
  1677. a combination of five types of status codes,
  1678. such as "http_1xx|http_2xx", Effective when the health check
  1679. protocol is "HTTP"
  1680. :value default: http_2xx|http_3xx
  1681. :type health_check_normal_status: string
  1682. :param server_timeout:
  1683. Backend server maximum timeout (unit: second)
  1684. :value 1-3600, default: 30
  1685. :type server_timeout: int
  1686. :param cert_ids:
  1687. The SSL certificate to be loaded by the listener.
  1688. Currently HTTPS listeners can only bind one SSL certificate.
  1689. :type cert_ids:List<String>
  1690. :param: additional_cert_domains:
  1691. Additional domain name,each element is an object that contains two attributes, namely "cert_id" and "host"
  1692. :type additional_cert_domains: list
  1693. :param ie6_compatible:
  1694. Is it compatible with IE6 HTTPS request
  1695. (the protocol format is earlier SSL3.0, the security is poor)
  1696. :value true or false, default: true
  1697. :type ie6_compatible: bool
  1698. :param config:
  1699. :type config: baidubce.BceClientConfiguration
  1700. :return:
  1701. :rtype baidubce.bce_response.BceResponse
  1702. """
  1703. path = utils.append_uri(self.version, 'blb', blb_id, 'HTTPSlistener')
  1704. params = {}
  1705. params[b'listenerPort'] = listener_port
  1706. body = {}
  1707. if backend_port is not None:
  1708. body['backendPort'] = backend_port
  1709. if scheduler is not None:
  1710. body['scheduler'] = compat.convert_to_string(scheduler)
  1711. if keep_session is not None:
  1712. body['keepSession'] = keep_session
  1713. if keep_session_type is not None:
  1714. body['keepSessionType'] = \
  1715. compat.convert_to_string(keep_session_type)
  1716. if keep_session_duration is not None:
  1717. body['keepSessionDuration'] = keep_session_duration
  1718. if keep_session_cookie_name is not None:
  1719. body['keepSessionCookieName'] = keep_session_cookie_name
  1720. if x_forward_for is not None:
  1721. body['xForwardFor'] = x_forward_for
  1722. if health_check_type is not None:
  1723. body['healthCheckType'] = \
  1724. compat.convert_to_string(health_check_type)
  1725. if health_check_port is not None:
  1726. body['healthCheckPort'] = health_check_port
  1727. if health_check_uri is not None:
  1728. body['healthCheckURI'] = \
  1729. compat.convert_to_string(health_check_uri)
  1730. if health_check_timeout_in_second is not None:
  1731. body['healthCheckTimeoutInSecond'] = \
  1732. health_check_timeout_in_second
  1733. if health_check_interval is not None:
  1734. body['healthCheckInterval'] = health_check_interval
  1735. if unhealth_threshold is not None:
  1736. body['unhealthyThreshold'] = unhealth_threshold
  1737. if health_threshold is not None:
  1738. body['healthyThreshold'] = health_threshold
  1739. if health_check_normal_status is not None:
  1740. body['healthCheckNormalStatus'] = \
  1741. compat.convert_to_string(health_check_normal_status)
  1742. if server_timeout is not None:
  1743. body['serverTimeout'] = server_timeout
  1744. if cert_ids is not None:
  1745. body['certIds'] = cert_ids
  1746. if additional_cert_domains is not None:
  1747. body['additionalCertDomains'] = additional_cert_domains
  1748. if ie6_compatible is not None:
  1749. body['ie6Compatible'] = ie6_compatible
  1750. return self._send_request(http_methods.PUT, path,
  1751. body=json.dumps(body), params=params,
  1752. config=config)
  1753. @required(blb_id=(bytes, str), listener_port=int)
  1754. def update_ssl_listener(self, blb_id, listener_port,
  1755. backend_port=None, scheduler=None,
  1756. health_check_timeout_in_second=None,
  1757. health_check_interval=None,
  1758. unhealth_threshold=None,
  1759. health_threshold=None, cert_ids=None,
  1760. ie6_compatible=None,
  1761. encryption_type=None,
  1762. encryption_protocols=None,
  1763. dual_auth=None, client_certIds=None,
  1764. config=None):
  1765. """
  1766. update a ssl listener rule with the specified options.
  1767. :param blb_id:
  1768. The id of blb which the listener work on
  1769. :type blb_id: string
  1770. :param listener_port:
  1771. port to be linstened owned by listener
  1772. :value 1-65535
  1773. :type listener_port: int
  1774. :param backend_port:
  1775. Port to be listened owned by Backend server
  1776. :value 1-65535
  1777. :type backend_port: int
  1778. :param scheduler:
  1779. balancing algorithm
  1780. :value 'RoundRobin' or 'LeastConnection'
  1781. :type scheduler: string
  1782. :param health_check_timeout_in_second:
  1783. Health check timeout (unit: second)
  1784. :value 1-60, default:3
  1785. :type health_check_timeout_in_second: int
  1786. :param health_check_interval:
  1787. Health check interval (unit: second)
  1788. :value 1-10, default: 3
  1789. :type health_check_interval: int
  1790. :param unhealth_threshold:
  1791. The unhealthy threshold, that is, how many consecutive health
  1792. check failures, shields the backend server.
  1793. :value 2-5, default: 3
  1794. :type unhealth_threshold: int
  1795. :param health_threshold:
  1796. Health threshold, that is, how many consecutive health checks
  1797. are successful, then re-use the back-end server
  1798. :value:2-5, default: 3
  1799. :type health_threshold: int
  1800. :param cert_ids:
  1801. The SSL certificate to be loaded by the listener.
  1802. Currently HTTPS listeners can only bind one SSL certificate.
  1803. :type cert_ids: List<String>
  1804. :param ie6_compatible:
  1805. compatible with IE6 HTTPS request
  1806. (the protocol format is earlier SSL3.0, the security is poor)
  1807. :value true or false, default: true
  1808. :type ie6_compatible: bool
  1809. :param encryption_type:
  1810. Encryption options, support three types:
  1811. compatibleIE or incompatibleIE or userDefind,
  1812. corresponding to:
  1813. IE-compatible encryption or disabled unsecure encryption or
  1814. custom encryption,
  1815. when encryptionType is valid and legitimate,
  1816. ie6Compatible field transfer value will not take effect
  1817. type: encryption_type:string
  1818. :param encryption_protocols:
  1819. When the encryptionType value is userDefind,
  1820. the list of protocol types is a string list composed of four protocols:
  1821. "sslv3", "tlsv10", "tlsv11", "tlsv12".
  1822. type: encryption_protocols:list
  1823. :param dual_auth:
  1824. Whether to Open Two-way Authentication,
  1825. default:false
  1826. :type dual_auth: boolean
  1827. :param client_certIds:
  1828. When dualAuth is true, the loaded client certificate chain
  1829. :type client_certIds: list
  1830. :param config:
  1831. :type config: baidubce.BceClientConfiguration
  1832. :return
  1833. :rtype baidubce.bce_response.BceResponse
  1834. """
  1835. path = utils.append_uri(self.version, 'blb', blb_id, 'SSLlistener')
  1836. params = {}
  1837. params[b'listenerPort'] = listener_port
  1838. body = {}
  1839. if backend_port is not None:
  1840. body['backendPort'] = backend_port
  1841. if scheduler is not None:
  1842. body['scheduler'] = compat.convert_to_string(scheduler)
  1843. if health_check_timeout_in_second is not None:
  1844. body['healthCheckTimeoutInSecond'] = \
  1845. health_check_timeout_in_second
  1846. if health_check_interval is not None:
  1847. body['healthCheckInterval'] = health_check_interval
  1848. if unhealth_threshold is not None:
  1849. body['unhealthyThreshold'] = unhealth_threshold
  1850. if health_threshold is not None:
  1851. body['healthyThreshold'] = health_threshold
  1852. if cert_ids is not None:
  1853. body['certIds'] = cert_ids
  1854. if ie6_compatible is not None:
  1855. body['ie6Compatible'] = ie6_compatible
  1856. if encryption_type is not None:
  1857. body['encryptionType'] = \
  1858. compat.convert_to_string(encryption_type)
  1859. if encryption_protocols is not None:
  1860. body['encryptionProtocols'] = encryption_protocols
  1861. if dual_auth is not None:
  1862. body['dualAuth'] = dual_auth
  1863. if client_certIds is not None:
  1864. body['clientCertIds'] = client_certIds
  1865. return self._send_request(http_methods.PUT, path,
  1866. body=json.dumps(body),
  1867. params=params, config=config)
  1868. @required(blb_id=(bytes, str),
  1869. portList=list)
  1870. def delete_listeners(self, blb_id, portList, client_token=None, config=None):
  1871. """
  1872. Release the listener under the specified LoadBalancer,
  1873. the listener is specified by listening to the port.
  1874. :param blb_id:
  1875. id of LoadBalancer
  1876. :type blb_id:string
  1877. :param portList:
  1878. The ports of listeners to be released
  1879. :type portList:list<int>
  1880. :param client_token:
  1881. If the clientToken is not specified by the user, a random String
  1882. generated by default algorithm will be used.
  1883. :type client_token: string
  1884. :param config:
  1885. :type config: baidubce.BceClientConfiguration
  1886. :return:
  1887. :rtype baidubce.bce_response.BceResponse
  1888. """
  1889. path = utils.append_uri(self.version, 'blb', blb_id, 'listener')
  1890. params = {}
  1891. params[b'batchdelete'] = None
  1892. if client_token is None:
  1893. params[b'clientToken'] = generate_client_token()
  1894. else:
  1895. params[b'clientToken'] = client_token
  1896. body = {}
  1897. body['portList'] = portList
  1898. return self._send_request(http_methods.PUT, path,
  1899. body=json.dumps(body), params=params,
  1900. config=config)
  1901. """
  1902. BackendServer API
  1903. """
  1904. @required(blb_id=(bytes, str),
  1905. backend_server_list=list)
  1906. def add_backend_servers(self, blb_id, backend_server_list,
  1907. client_token=None, config=None):
  1908. """
  1909. Add a backend server for the specified LoadBalancer,
  1910. support batch add
  1911. :param blb_id:
  1912. id of LoadBalancer
  1913. :type blb_id:string
  1914. :param backend_server_list
  1915. List of backend servers to be added
  1916. :type backend_server_list:List<BackendServerModel>
  1917. BackendServerModel{:param:instanceId
  1918. id of Backend server
  1919. :type instanceId:string
  1920. :param weight
  1921. Backend server weight, value range [0, 100],
  1922. weight 0 means not to forward traffic to
  1923. the backend server
  1924. :type weight:int
  1925. }
  1926. :param client_token:
  1927. If the clientToken is not specified by the user, a random String
  1928. generated by default algorithm will be used.
  1929. :type client_token: string
  1930. :param config:
  1931. :type config: baidubce.BceClientConfiguration
  1932. :return:
  1933. :rtype baidubce.bce_response.BceResponse
  1934. """
  1935. path = utils.append_uri(self.version, 'blb', blb_id, 'backendserver')
  1936. params = {}
  1937. if client_token is None:
  1938. params[b'clientToken'] = generate_client_token()
  1939. else:
  1940. params[b'clientToken'] = client_token
  1941. body = {}
  1942. body['backendServerList'] = backend_server_list
  1943. return self._send_request(http_methods.POST, path,
  1944. body=json.dumps(body), params=params,
  1945. config=config)
  1946. @required(blb_id=(bytes, str),
  1947. listener_port=int)
  1948. def describe_health_status(self, blb_id, listener_port,
  1949. marker=None, max_keys=None, config=None):
  1950. """
  1951. Query the information about the backend server under the specified
  1952. LoadBalancer identified by listenPort
  1953. :param blb_id:
  1954. id of LoadBalancer
  1955. :type blb_id: string
  1956. :param listener_port:
  1957. port to be linstened owned by listener
  1958. :value 1-65535
  1959. :type listener_port: int
  1960. :param marker:
  1961. The optional parameter marker specified in the original request
  1962. to specify where in the results to begin listing.
  1963. Together with the marker, specifies the list result which listing
  1964. should begin. If the marker is not specified, the list result will
  1965. listing from the first one.
  1966. :type marker: string
  1967. :param max_keys:
  1968. The optional parameter to specifies the max number of list
  1969. result to return.
  1970. The default value is 1000.
  1971. :type max_keys: int
  1972. :param config:
  1973. :type config: baidubce.BceClientConfiguration
  1974. :return:
  1975. :rtype baidubce.bce_response.BceResponse
  1976. """
  1977. path = utils.append_uri(self.version, 'blb', blb_id, 'backendserver')
  1978. params = {}
  1979. params[b'listenerPort'] = listener_port
  1980. if marker is not None:
  1981. params[b'marker'] = marker
  1982. if max_keys is not None:
  1983. params[b'maxKeys'] = max_keys
  1984. return self._send_request(http_methods.GET, path, params=params,
  1985. config=config)
  1986. @required(blb_id=(bytes, str))
  1987. def describe_backend_servers(self, blb_id, marker=None,
  1988. max_keys=None, config=None):
  1989. """
  1990. Query the list of backend servers under the specified LoadBalancer
  1991. :param blb_id:
  1992. Id of LoadBalancer
  1993. :type blb_id:string
  1994. :param marker:
  1995. The optional parameter marker specified in the original
  1996. request to specify where in the results to begin listing.
  1997. Together with the marker, specifies the list result which
  1998. listing should begin. If the marker is not specified,
  1999. the list result will listing from the first one.
  2000. :type marker: string
  2001. :param max_keys:
  2002. The optional parameter to specifies the max number of
  2003. list result to return.
  2004. The default value is 1000.
  2005. :type max_keys: int
  2006. :param config:
  2007. :type config: baidubce.BceClientConfiguration
  2008. :return:
  2009. :rtype baidubce.bce_response.BceResponse
  2010. """
  2011. path = utils.append_uri(self.version, 'blb', blb_id, 'backendserver')
  2012. params = {}
  2013. if marker is not None:
  2014. params[b'marker'] = marker
  2015. if max_keys is not None:
  2016. params[b'maxKeys'] = max_keys
  2017. return self._send_request(http_methods.GET, path, params=params,
  2018. config=config)
  2019. @required(blb_id=(bytes, str),
  2020. backend_server_list=list)
  2021. def update_backend_servers(self, blb_id, backend_server_list,
  2022. client_token=None, config=None):
  2023. """
  2024. update the information about the backend server under
  2025. the specified LoadBalancer
  2026. :param blb_id:
  2027. id of LoadBalancer
  2028. :type blb_id:string
  2029. :param backend_server_list:
  2030. List of backend servers to be updated
  2031. :type backend_server_list:List<BackendServerModel>
  2032. BackendServerModel{:param:instanceId
  2033. id of Backend server
  2034. :type instanceId:string
  2035. :param weight
  2036. Backend server weight, value range [0, 100],
  2037. weight 0 means not to forward traffic to
  2038. the backend server
  2039. :type weight:int
  2040. }
  2041. :param client_token:
  2042. If the clientToken is not specified by the user, a random String
  2043. generated by default algorithm will be used.
  2044. :type client_token: string
  2045. :param config:
  2046. :type config: baidubce.BceClientConfiguration
  2047. :return:
  2048. :rtype baidubce.bce_response.BceResponse
  2049. """
  2050. path = utils.append_uri(self.version, 'blb', blb_id, 'backendserver')
  2051. params = {}
  2052. params[b'update'] = None
  2053. if client_token is None:
  2054. params[b'clientToken'] = generate_client_token()
  2055. else:
  2056. params[b'clientToken'] = client_token
  2057. body = {}
  2058. body['backendServerList'] = backend_server_list
  2059. return self._send_request(http_methods.PUT, path,
  2060. body=json.dumps(body), params=params,
  2061. config=config)
  2062. @required(blb_id=(bytes, str),
  2063. backend_server_list=list)
  2064. def remove_backend_servers(self, blb_id, backend_server_list,
  2065. client_token=None, config=None):
  2066. """
  2067. Release the backend server under the specified LoadBalancer,
  2068. which is specified by its backend server
  2069. :param blb_id:
  2070. id of LoadBalancer
  2071. :type blb_id:string
  2072. :param backend_server_list:
  2073. List of backend servers to be removed
  2074. :type backend_server_list:List<string>
  2075. :param client_token:
  2076. If the clientToken is not specified by the user,
  2077. a random String generated by default algorithm will be used.
  2078. :type client_token: string
  2079. :param config:
  2080. :type config: baidubce.BceClientConfiguration
  2081. :return:
  2082. :rtype baidubce.bce_response.BceResponse
  2083. """
  2084. path = utils.append_uri(self.version, 'blb', blb_id, 'backendserver')
  2085. params = {}
  2086. if client_token is None:
  2087. params[b'clientToken'] = generate_client_token()
  2088. else:
  2089. params[b'clientToken'] = client_token
  2090. body = {}
  2091. body['backendServerList'] = backend_server_list
  2092. return self._send_request(http_methods.PUT, path,
  2093. body=json.dumps(body), params=params,
  2094. config=config)
  2095. @required(blb_id=(bytes, str),
  2096. securitygroupids=list)
  2097. def bind_security_groups(self, blb_id, securitygroupids,
  2098. client_token=None, config=None):
  2099. """
  2100. bind the blb security groups (normal/ipv6 LoadBalancer)
  2101. :param blb_id:
  2102. id of LoadBalancer
  2103. :type blb_id:string
  2104. :param securitygroupids:
  2105. List of security group ids to be bind
  2106. :type securitygroupids:List<string>
  2107. :param client_token:
  2108. If the clientToken is not specified by the user,
  2109. a random String generated by default algorithm will be used.
  2110. :type client_token: string
  2111. :param config:
  2112. :type config: baidubce.BceClientConfiguration
  2113. :return:
  2114. :rtype baidubce.bce_response.BceResponse
  2115. """
  2116. path = utils.append_uri(self.version, 'blb', blb_id, 'securitygroup')
  2117. params = {}
  2118. params[b'bind'] = None
  2119. if client_token is None:
  2120. params[b'clientToken'] = generate_client_token()
  2121. else:
  2122. params[b'clientToken'] = client_token
  2123. body = {}
  2124. body['securityGroupIds'] = securitygroupids
  2125. return self._send_request(http_methods.PUT, path,
  2126. body=json.dumps(body), params=params,
  2127. config=config)
  2128. @required(blb_id=(bytes, str),
  2129. securitygroupids=list)
  2130. def unbind_security_groups(self, blb_id, securitygroupids,
  2131. client_token=None, config=None):
  2132. """
  2133. unbind the blb security groups (normal/ipv6 LoadBalancer)
  2134. :param blb_id:
  2135. id of LoadBalancer
  2136. :type blb_id:string
  2137. :param securitygroupids:
  2138. List of security group ids to be bind
  2139. :type securitygroupids:List<string>
  2140. :param client_token:
  2141. If the clientToken is not specified by the user,
  2142. a random String generated by default algorithm will be used.
  2143. :type client_token: string
  2144. :param config:
  2145. :type config: baidubce.BceClientConfiguration
  2146. :return:
  2147. :rtype baidubce.bce_response.BceResponse
  2148. """
  2149. path = utils.append_uri(self.version, 'blb', blb_id, 'securitygroup')
  2150. params = {}
  2151. params[b'unbind'] = None
  2152. if client_token is None:
  2153. params[b'clientToken'] = generate_client_token()
  2154. else:
  2155. params[b'clientToken'] = client_token
  2156. body = {}
  2157. body['securityGroupIds'] = securitygroupids
  2158. return self._send_request(http_methods.PUT, path,
  2159. body=json.dumps(body), params=params,
  2160. config=config)
  2161. @required(blb_id=(bytes, str))
  2162. def describe_security_groups(self, blb_id,
  2163. client_token=None, config=None):
  2164. """
  2165. describe the blb security groups (normal/ipv6 LoadBalancer)
  2166. :param blb_id:
  2167. id of LoadBalancer
  2168. :type blb_id:string
  2169. :param client_token:
  2170. If the clientToken is not specified by the user,
  2171. a random String generated by default algorithm will be used.
  2172. :type client_token: string
  2173. :param config:
  2174. :type config: baidubce.BceClientConfiguration
  2175. :return:
  2176. :rtype baidubce.bce_response.BceResponse
  2177. """
  2178. path = utils.append_uri(self.version, 'blb', blb_id, 'securitygroup')
  2179. params = {}
  2180. if client_token is None:
  2181. params[b'clientToken'] = generate_client_token()
  2182. else:
  2183. params[b'clientToken'] = client_token
  2184. return self._send_request(http_methods.GET, path, params=params,
  2185. config=config)
  2186. @required(blb_id=(bytes, str),
  2187. enterprisesecuritygroupids=list)
  2188. def bind_enterprise_security_groups(self, blb_id, enterprisesecuritygroupids,
  2189. client_token=None, config=None):
  2190. """
  2191. bind the blb enterprise security groups (normal/ipv6 LoadBalancer)
  2192. :param blb_id:
  2193. id of LoadBalancer
  2194. :type blb_id:string
  2195. :param enterprisesecuritygroupids:
  2196. List of enterprise security group ids to be bind
  2197. :type enterprisesecuritygroupids:List<string>
  2198. :param client_token:
  2199. If the clientToken is not specified by the user,
  2200. a random String generated by default algorithm will be used.
  2201. :type client_token: string
  2202. :param config:
  2203. :type config: baidubce.BceClientConfiguration
  2204. :return:
  2205. :rtype baidubce.bce_response.BceResponse
  2206. """
  2207. path = utils.append_uri(self.version, 'blb', blb_id, 'enterprise', 'securitygroup')
  2208. params = {}
  2209. params[b'bind'] = None
  2210. if client_token is None:
  2211. params[b'clientToken'] = generate_client_token()
  2212. else:
  2213. params[b'clientToken'] = client_token
  2214. body = {}
  2215. body['enterpriseSecurityGroupIds'] = enterprisesecuritygroupids
  2216. return self._send_request(http_methods.PUT, path,
  2217. body=json.dumps(body), params=params,
  2218. config=config)
  2219. @required(blb_id=(bytes, str),
  2220. enterprisesecuritygroupids=list)
  2221. def unbind_enterprise_security_groups(self, blb_id, enterprisesecuritygroupids,
  2222. client_token=None, config=None):
  2223. """
  2224. unbind the blb enterprise security groups (normal/ipv6 LoadBalancer)
  2225. :param blb_id:
  2226. id of LoadBalancer
  2227. :type blb_id:string
  2228. :param enterprisesecuritygroupids:
  2229. List of enterprise security group ids to be unbind
  2230. :type enterprisesecuritygroupids:List<string>
  2231. :param client_token:
  2232. If the clientToken is not specified by the user,
  2233. a random String generated by default algorithm will be used.
  2234. :type client_token: string
  2235. :param config:
  2236. :type config: baidubce.BceClientConfiguration
  2237. :return:
  2238. :rtype baidubce.bce_response.BceResponse
  2239. """
  2240. path = utils.append_uri(self.version, 'blb', blb_id, 'enterprise', 'securitygroup')
  2241. params = {}
  2242. params[b'unbind'] = None
  2243. if client_token is None:
  2244. params[b'clientToken'] = generate_client_token()
  2245. else:
  2246. params[b'clientToken'] = client_token
  2247. body = {}
  2248. body['enterpriseSecurityGroupIds'] = enterprisesecuritygroupids
  2249. return self._send_request(http_methods.PUT, path,
  2250. body=json.dumps(body), params=params,
  2251. config=config)
  2252. @required(blb_id=(bytes, str))
  2253. def describe_enterprise_security_groups(self, blb_id,
  2254. client_token=None, config=None):
  2255. """
  2256. describe the blb enterprise security groups (normal/ipv6 LoadBalancer)
  2257. :param blb_id:
  2258. id of LoadBalancer
  2259. :type blb_id:string
  2260. :param client_token:
  2261. If the clientToken is not specified by the user,
  2262. a random String generated by default algorithm will be used.
  2263. :type client_token: string
  2264. :param config:
  2265. :type config: baidubce.BceClientConfiguration
  2266. :return:
  2267. :rtype baidubce.bce_response.BceResponse
  2268. """
  2269. path = utils.append_uri(self.version, 'blb', blb_id, 'enterprise', 'securitygroup')
  2270. params = {}
  2271. if client_token is None:
  2272. params[b'clientToken'] = generate_client_token()
  2273. else:
  2274. params[b'clientToken'] = client_token
  2275. return self._send_request(http_methods.GET, path, params=params,
  2276. config=config)
  2277. def generate_client_token_by_uuid():
  2278. """
  2279. The default method to generate the random string for client_token
  2280. if the optional parameter client_token is not specified by the user.
  2281. :return:
  2282. :rtype string
  2283. """
  2284. return str(uuid.uuid4())
  2285. generate_client_token = generate_client_token_by_uuid