et_client.py 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. # Copyright (c) 2023 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 Et Channel IPv6.
  16. """
  17. import copy
  18. import json
  19. import uuid
  20. from baidubce import bce_base_client
  21. from baidubce import compat
  22. from baidubce import utils
  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.utils import required
  28. from baidubce.services.et.model import ETStatus
  29. class EtClient(bce_base_client.BceBaseClient):
  30. """
  31. Et base sdk client
  32. """
  33. prefix = b'/v1'
  34. et = 'et'
  35. init = 'init'
  36. channel = 'channel'
  37. route = 'route'
  38. rule = 'rule'
  39. def __init__(self, config=None):
  40. """
  41. :type config: baidubce.BceClientConfiguration
  42. """
  43. bce_base_client.BceBaseClient.__init__(self, config)
  44. def _merge_config(self, config=None):
  45. """
  46. :param config:
  47. :type config: baidubce.BceClientConfiguration
  48. :return:
  49. """
  50. if config is None:
  51. return self.config
  52. else:
  53. new_config = copy.copy(self.config)
  54. new_config.merge_non_none_values(config)
  55. return new_config
  56. def _send_request(self, http_method, path,
  57. body=None, headers=None, params=None,
  58. config=None, body_parser=None):
  59. """
  60. :param http_method:
  61. :param path:
  62. :param body:
  63. :param headers:
  64. :param params:
  65. :param config:
  66. :param body_parser:
  67. :return:
  68. """
  69. config = self._merge_config(config)
  70. if body_parser is None:
  71. body_parser = handler.parse_json
  72. if headers is None:
  73. headers = {b'Accept': b'*/*', b'Content-Type':
  74. b'application/json;charset=utf-8'}
  75. return bce_http_client.send_request(
  76. config, bce_v1_signer.sign, [handler.parse_error, body_parser],
  77. http_method, path, body, headers, params)
  78. def create_et_dcphy(self, name, isp, intf_type, ap_type, ap_addr, user_name, user_phone, user_email,
  79. user_idc, client_token=None, description=None, config=None):
  80. """
  81. Create new ET
  82. :param name: the name of ET
  83. :type name: string
  84. :param description: description of ET
  85. :type description: string
  86. :param isp: the type of isp
  87. :type isp: string
  88. :param intf_type: the type of interface
  89. :type intf_type: string
  90. :param ap_type: the type of ap
  91. :type ap_type: string
  92. :param ap_addr: the type of ap Address
  93. :type ap_addr: string
  94. :param user_name: the name of user
  95. :type user_name: string
  96. :param user_phone: phone number of user
  97. :type user_phone: string
  98. :param user_email: email of user
  99. :type user_email: string
  100. :param user_idc: Idc of user
  101. :type user_idc: string
  102. :param client_token:
  103. If the clientToken is not specified by the user, a random String
  104. generated by default algorithm will be used.
  105. :type client_token: string
  106. :type config: baidubce.BceClientConfiguration
  107. :param config:
  108. :return: created ET ID
  109. """
  110. path = utils.append_uri(self.prefix, self.et, self.init)
  111. params = {}
  112. if client_token is None:
  113. params[b'clientToken'] = generate_client_token()
  114. else:
  115. params[b'clientToken'] = client_token
  116. body = {
  117. 'name': name,
  118. 'description': description,
  119. 'isp': isp,
  120. 'intfType': intf_type,
  121. 'apType': ap_type,
  122. 'apAddr': ap_addr,
  123. 'userName': user_name,
  124. 'userPhone': user_phone,
  125. 'userEmail': user_email,
  126. 'userIdc': user_idc,
  127. }
  128. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  129. def update_et_dcphy(self, et_id, name=None, description=None, user_name=None,
  130. user_phone=None, user_email=None, client_token=None, config=None):
  131. """
  132. Update existed Et
  133. :param et_id: ET ID
  134. :type et_id: string
  135. :param user_name: the name of user
  136. :type user_name: string
  137. :param user_phone: phone number of user
  138. :type user_phone: string
  139. :param user_email: email of user
  140. :type user_email: string
  141. :param user_idc: Idc of user
  142. :type user_idc: string
  143. :param description: description of ET
  144. :type description: string
  145. :param client_token:
  146. If the clientToken is not specified by the user, a random String
  147. generated by default algorithm will be used.
  148. :type client_token: string
  149. :param config:
  150. :type config: baidubce.BceClientConfiguration
  151. """
  152. path = utils.append_uri(self.prefix, self.et, et_id)
  153. params = {}
  154. if name is not None:
  155. params[b'name'] = name
  156. if description is not None:
  157. params[b'description'] = description
  158. if user_name is not None:
  159. params[b'userName'] = user_name
  160. if user_phone is not None:
  161. params[b'userPhone'] = user_phone
  162. if user_email is not None:
  163. params[b'userEmail'] = user_email
  164. if client_token is None:
  165. params[b'clientToken'] = generate_client_token()
  166. else:
  167. params[b'clientToken'] = client_token
  168. return self._send_request(http_methods.PUT, path, params=params, config=config)
  169. def list_et_dcphy(self, status=None, marker=None, max_keys=1000, config=None):
  170. """
  171. get a list of ETs owned by the authenticated user and specified
  172. conditions.
  173. :type status: string
  174. :param status: status of ET condition, if query by the status condition, must provides
  175. :type marker: string
  176. :param marker: The optional parameter marker specified in the original
  177. request to specify where in the results to begin listing.
  178. :type max_keys: int
  179. :param max_keys: The optional parameter to specifies the max number
  180. of list result to return. The default value is 1000.
  181. :type config: baidubce.BceClientConfiguration
  182. :param config:
  183. :return: list of ET model, for example:
  184. {
  185. "nextMarker": "dcphy-gq65bz9ip712",
  186. "marker": "dcphy-gq65bz9ie712",
  187. "maxKeys": 1,
  188. "isTruncated": true,
  189. "ets": [{
  190. "id": "dcphy-jy1sbnx32ez0",
  191. "name": "et_6",
  192. "description": "描述",
  193. "status": "established",
  194. "expireTime": "2019-01-30T08:50:00Z",
  195. "isp": "ISP_CTC",
  196. "intfType": "10G",
  197. "apType": "BAIDU",
  198. "apAddr": "BB",
  199. "userName": "张三",
  200. "userPhone": "133*****333",
  201. "userEmail": "1***@123.com",
  202. "userIdc": "北京|市辖区|东城区|2321"
  203. }]
  204. }
  205. """
  206. path = utils.append_uri(self.prefix, self.et)
  207. params = {}
  208. if status is not None and isinstance(status, ETStatus):
  209. params[b'status'] = status.value
  210. if marker is not None:
  211. params[b'marker'] = marker
  212. if max_keys is not None:
  213. params[b'maxKeys'] = max_keys
  214. return self._send_request(http_methods.GET, path, params=params,
  215. config=config)
  216. def list_et_dcphy_detail(self, et_id, config=None):
  217. """
  218. List specific ET detail
  219. :param et_id: ET ID
  220. :type et_id: string
  221. :param config:
  222. :type config: baidubce.BceClientConfiguration
  223. :return: list of ET model, for example:
  224. {
  225. "id": "dcphy-gq65bz9ip712",
  226. "name": "ZX051501-testET",
  227. "description": "",
  228. "status": "established",
  229. "expireTime": 1,
  230. "isp": "ISP_CUCC",
  231. "intfType": "10G",
  232. "apType": "SINGLE",
  233. "apAddr": "WHGG",
  234. "userName": "张三",
  235. "userPhone": "133*****333",
  236. "userEmail": "1***@123.com",
  237. "userIdc": "北京|市辖区|东城区|百度科技园K2"
  238. }
  239. """
  240. path = utils.append_uri(self.prefix, self.et, et_id)
  241. return self._send_request(http_methods.GET, path, config=config)
  242. def create_et_channel(self, et_id, local_ip, name, remote_ip, route_type, vlan_id,
  243. authorized_users=None, description=None, networks=None,
  244. bgp_asn=None, bgp_key=None, enable_ipv6=None, local_ipv6=None,
  245. remote_ipv6=None, ipv6_networks=None, client_token=None, config=None):
  246. """
  247. Create new et channel
  248. :param et_id: et id
  249. :type et_id: string
  250. :param local_ip: baidu IPv4 address of et channel
  251. :type local_ip: string
  252. :param name: et channel name
  253. :type name: string
  254. :param networks: et channel IPv4 routes
  255. :type networks: list<string>
  256. :param remote_ip: customer IPv4 address of et channel
  257. :type remote_ip: string
  258. :param description: description of channel
  259. :type description: string
  260. :param route_type: et channel route type
  261. :value "bgp" or "static"
  262. :type route_type: string
  263. :param vlan_id: et channel vlan id
  264. :value 0, 2-4009
  265. :type vlan_id: integer
  266. :param authorized_users: et channel authorized users
  267. :type authorized_users: list<string>
  268. :param enable_ipv6: et channel enable ipv6
  269. :value 0 or 1
  270. :type enable_ipv6: integer
  271. :param local_ipv6: baidu IPv6 address of et channel
  272. :type local_ipv6: string
  273. :param remote_ipv6: customer IPv6 address of et channel
  274. :type remote_ipv6: string
  275. :param ipv6_networks: et channel IPv6 routes
  276. :type ipv6_networks: list<string>
  277. :param bgp_asn: BGP ASN
  278. :type bgp_asn: string
  279. :param bgp_key: BGP KEY
  280. :type bgp_key: string
  281. :param client_token:
  282. If the clientToken is not specified by the user, a random String
  283. generated by default algorithm will be used.
  284. :type client_token: string
  285. :param config:
  286. :type config: baidubce.BceClientConfiguration
  287. :return:
  288. :rtype baidubce.bce_response.BceResponse
  289. """
  290. path = utils.append_uri(self.prefix, self.et, et_id, self.channel)
  291. params = {}
  292. if client_token is None:
  293. params[b'clientToken'] = generate_client_token()
  294. else:
  295. params[b'clientToken'] = client_token
  296. body = {
  297. 'etId': et_id,
  298. 'baiduAddress': local_ip,
  299. 'name': name,
  300. 'customerAddress': remote_ip,
  301. 'routeType': route_type,
  302. 'vlanId': vlan_id,
  303. }
  304. if networks is not None:
  305. body['networks'] = networks
  306. if authorized_users is not None:
  307. body['authorizedUsers'] = authorized_users
  308. if description is not None:
  309. body['description'] = compat.convert_to_string(description)
  310. if enable_ipv6 is not None:
  311. body['enableIpv6'] = enable_ipv6
  312. if local_ipv6 is not None:
  313. body['baiduIpv6Address'] = compat.convert_to_string(local_ipv6)
  314. if remote_ipv6 is not None:
  315. body['customerIpv6Address'] = compat.convert_to_string(remote_ipv6)
  316. if ipv6_networks is not None:
  317. body['ipv6Networks'] = ipv6_networks
  318. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  319. @required(et_id=(bytes, str))
  320. def get_et_channel(self, et_id, client_token=None, config=None):
  321. """
  322. Get et channel.
  323. :param et_id:
  324. et id
  325. :type et_id: string
  326. :param client_token:
  327. If the clientToken is not specified by the user, a random String
  328. generated by default algorithm will be used.
  329. :type client_token: string
  330. :param config:
  331. :type config: baidubce.BceClientConfiguration
  332. :return:
  333. :rtype baidubce.bce_response.BceResponse
  334. """
  335. path = utils.append_uri(self.prefix, self.et, et_id, self.channel)
  336. params = {}
  337. if client_token is None:
  338. params[b'clientToken'] = generate_client_token()
  339. else:
  340. params[b'clientToken'] = client_token
  341. return self._send_request(http_methods.GET, path, params=params, config=config)
  342. @required(et_id=(bytes, str), et_channel_id=(bytes, str), local_ip=(bytes, str), name=(bytes, str),
  343. networks=(list, tuple), remote_ip=(bytes, str), route_type=(bytes, str), vlan_id=int)
  344. def recommit_et_channel(self, et_id, et_channel_id, local_ip, name, networks, remote_ip, route_type, vlan_id,
  345. authorized_users=None, description=None, enable_ipv6=None, local_ipv6=None,
  346. remote_ipv6=None, ipv6_networks=None, client_token=None, config=None):
  347. """
  348. Recommit et channel.
  349. :param et_id:
  350. et id
  351. :type et_id: string
  352. :param et_channel_id:
  353. et channel id
  354. :type et_channel_id: string
  355. :param local_ip:
  356. baidu IPv4 address of et channel
  357. :type local_ip: string
  358. :param name:
  359. et channel name
  360. :type name: string
  361. :param networks:
  362. et channel IPv4 routes
  363. :type networks: list<string>
  364. :param remote_ip:
  365. customer IPv4 address of et channel
  366. :type remote_ip: string
  367. :param route_type:
  368. et channel route type
  369. :value "bgp" or "static"
  370. :type route_type: string
  371. :param vlan_id:
  372. et channel vlan id
  373. :value 0, 2-4009
  374. :type vlan_id: integer
  375. :param authorized_users:
  376. et channel authorized users
  377. :type authorized_users: list<string>
  378. :param description:
  379. et channel description
  380. :type description: string
  381. :param enable_ipv6:
  382. et channel enable ipv6
  383. :value 0 or 1
  384. :type enable_ipv6: integer
  385. :param local_ipv6:
  386. baidu IPv6 address of et channel
  387. :type local_ipv6: string
  388. :param remote_ipv6:
  389. customer IPv6 address of et channel
  390. :type remote_ipv6: string
  391. :param ipv6_networks:
  392. et channel IPv6 routes
  393. :type ipv6_networks: list<string>
  394. :param client_token:
  395. If the clientToken is not specified by the user, a random String
  396. generated by default algorithm will be used.
  397. :type client_token: string
  398. :param config:
  399. :type config: baidubce.BceClientConfiguration
  400. :return:
  401. :rtype baidubce.bce_response.BceResponse
  402. """
  403. path = utils.append_uri(self.prefix, self.et, et_id, self.channel,
  404. et_channel_id)
  405. params = {b'reCreate':None}
  406. if client_token is None:
  407. params[b'clientToken'] = generate_client_token()
  408. else:
  409. params[b'clientToken'] = client_token
  410. body = {
  411. 'baiduAddress': local_ip,
  412. 'name': name,
  413. 'networks': networks,
  414. 'customerAddress': remote_ip,
  415. 'routeType': route_type,
  416. 'vlanId': vlan_id,
  417. }
  418. if authorized_users is not None:
  419. body['authorizedUsers'] = authorized_users
  420. if description is not None:
  421. body['description'] = compat.convert_to_string(description)
  422. if enable_ipv6 is not None:
  423. body['enableIpv6'] = enable_ipv6
  424. if local_ipv6 is not None:
  425. body['baiduIpv6Address'] = compat.convert_to_string(local_ipv6)
  426. if remote_ipv6 is not None:
  427. body['customerIpv6Address'] = compat.convert_to_string(remote_ipv6)
  428. if ipv6_networks is not None:
  429. body['ipv6Networks'] = ipv6_networks
  430. return self._send_request(http_methods.PUT, path, params=params, body=json.dumps(body), config=config)
  431. @required(et_id=(bytes, str), et_channel_id=(bytes, str))
  432. def update_et_channel(self, et_id, et_channel_id, name=None, description=None, client_token=None, config=None):
  433. """
  434. update et channel.
  435. :param et_id:
  436. et id
  437. :type et_id: string
  438. :param et_channel_id:
  439. et channel id
  440. :type et_channel_id: string
  441. :param name:
  442. et channel name
  443. :type name: string
  444. :param description:
  445. et channel description
  446. :type description: string
  447. :param client_token:
  448. If the clientToken is not specified by the user, a random String
  449. generated by default algorithm will be used.
  450. :type client_token: string
  451. :param config:
  452. :type config: baidubce.BceClientConfiguration
  453. :return:
  454. :rtype baidubce.bce_response.BceResponse
  455. """
  456. path = utils.append_uri(self.prefix, self.et, et_id, self.channel,
  457. et_channel_id)
  458. params = {b'modifyAttribute': None}
  459. if client_token is None:
  460. params[b'clientToken'] = generate_client_token()
  461. else:
  462. params[b'clientToken'] = client_token
  463. body = {}
  464. if name is not None:
  465. body['name'] = compat.convert_to_string(name)
  466. if description is not None:
  467. body['description'] = compat.convert_to_string(description)
  468. return self._send_request(http_methods.PUT, path, params=params, body=json.dumps(body), config=config)
  469. @required(et_id=(bytes, str), et_channel_id=(bytes, str))
  470. def delete_et_channel(self, et_id, et_channel_id, client_token=None, config=None):
  471. """
  472. Delete et channel.
  473. :param et_id:
  474. et id
  475. :type et_id: string
  476. :param et_channel_id:
  477. et channel id
  478. :type et_channel_id: string
  479. :param client_token:
  480. If the clientToken is not specified by the user, a random String
  481. generated by default algorithm will be used.
  482. :type client_token: string
  483. :param config:
  484. :type config: baidubce.BceClientConfiguration
  485. :return:
  486. :rtype baidubce.bce_response.BceResponse
  487. """
  488. path = utils.append_uri(self.prefix, self.et, et_id, self.channel,
  489. et_channel_id)
  490. params = {}
  491. if client_token is None:
  492. params[b'clientToken'] = generate_client_token()
  493. else:
  494. params[b'clientToken'] = client_token
  495. return self._send_request(http_methods.DELETE, path, params=params, config=config)
  496. @required(et_id=(bytes, str), et_channel_id=(bytes, str),
  497. local_ipv6=(bytes, str), remote_ipv6=(bytes, str))
  498. def enable_et_channel_ipv6(self, et_id, et_channel_id, local_ipv6, remote_ipv6,
  499. ipv6_networks=None, client_token=None, config=None):
  500. """
  501. Enable IPv6 of the specific et channel.
  502. :param et_id:
  503. et id
  504. :type et_id: string
  505. :param et_channel_id:
  506. et channel id
  507. :type et_channel_id: string
  508. :param local_ipv6:
  509. baidu IPv6 address of et channel
  510. :type local_ipv6: string
  511. :param remote_ipv6:
  512. customer IPv6 address of et channel
  513. :type remote_ipv6: string
  514. :param ipv6_networks:
  515. et channel IPv6 routes
  516. :type ipv6_networks: list<string>
  517. :param client_token:
  518. If the clientToken is not specified by the user, a random String
  519. generated by default algorithm will be used.
  520. :type client_token: string
  521. :param config:
  522. :type config: baidubce.BceClientConfiguration
  523. :return:
  524. :rtype baidubce.bce_response.BceResponse
  525. """
  526. path = utils.append_uri(self.prefix, self.et, et_id, self.channel,
  527. et_channel_id)
  528. params = {b'enableIpv6': None}
  529. if client_token is None:
  530. params[b'clientToken'] = generate_client_token()
  531. else:
  532. params[b'clientToken'] = client_token
  533. body = {
  534. 'baiduIpv6Address': compat.convert_to_string(local_ipv6),
  535. 'customerIpv6Address': compat.convert_to_string(remote_ipv6),
  536. }
  537. if ipv6_networks is not None:
  538. body['ipv6Networks'] = ipv6_networks
  539. return self._send_request(http_methods.PUT, path, params=params, body=json.dumps(body), config=config)
  540. @required(et_id=(bytes, str), et_channel_id=(bytes, str))
  541. def disable_et_channel_ipv6(self, et_id, et_channel_id, client_token=None, config=None):
  542. """
  543. Disable IPv6 of the specific et channel.
  544. :param et_id:
  545. The id of et.
  546. :type et_id: string
  547. :param et_channel_id:
  548. The id of et channel.
  549. :type et_channel_id: string
  550. :param client_token:
  551. If the clientToken is not specified by the user, a random String
  552. generated by default algorithm will be used.
  553. :type client_token: string
  554. :param config:
  555. :type config: baidubce.BceClientConfiguration
  556. :return:
  557. :rtype baidubce.bce_response.BceResponse
  558. """
  559. path = utils.append_uri(self.prefix, self.et, et_id, self.channel,
  560. et_channel_id)
  561. params = {b'disableIpv6': None}
  562. if client_token is None:
  563. params[b'clientToken'] = generate_client_token()
  564. else:
  565. params[b'clientToken'] = client_token
  566. return self._send_request(http_methods.PUT, path, params=params, config=config)
  567. @required(et_id=(bytes, str), et_channel_id=(bytes, str))
  568. def create_et_channel_route_rule(self, et_id, et_channel_id, dest_address, nexthop_type,
  569. nexthop_id, description=None, ip_version=4,
  570. client_token=None, config=None):
  571. """
  572. Create a et channel route rule with the specified options.
  573. :param et_id:
  574. The id of et.
  575. :type et_id: string
  576. :param et_channel_id:
  577. The id of et channel.
  578. :type et_channel_id: string
  579. :param dest_address:
  580. Destination address of the route rule.
  581. :type dest_address: string
  582. :param nexthop_type
  583. The type of nexthop.
  584. Value can be "etGateway" or "etChannel", respectively dedicated gateway, dedicated channel type.
  585. :type nexthop_type: string
  586. :param nexthop_id:
  587. The id of nexthop instance.
  588. :type nexthop_id: string
  589. :param description:
  590. The description of the route rule.
  591. :type description: string
  592. :param ip_version:
  593. The ip version of the route rule.
  594. Value can be 4 or 6, default 4.
  595. :type ip_version: int
  596. :param client_token:
  597. An ASCII string whose length is less than 64.
  598. The request will be idempotent if clientToken is provided.
  599. If the clientToken is not specified by the user,
  600. a random String generated by default algorithm will be used.
  601. :type client_token: string
  602. :param config:
  603. :type config: baidubce.BceClientConfiguration
  604. :return:
  605. :rtype baidubce.bce_response.BceResponse
  606. """
  607. path = utils.append_uri(self.prefix, self.et, et_id, self.channel,
  608. et_channel_id, self.route, self.rule)
  609. params = {}
  610. if client_token is None:
  611. params[b'clientToken'] = generate_client_token()
  612. else:
  613. params[b'clientToken'] = client_token
  614. body = {
  615. 'ipVersion': ip_version,
  616. 'destAddress': compat.convert_to_string(dest_address),
  617. 'nexthopType': compat.convert_to_string(nexthop_type),
  618. 'nexthopId': compat.convert_to_string(nexthop_id),
  619. }
  620. if description is not None:
  621. body['description'] = compat.convert_to_string(description)
  622. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params,
  623. config=config)
  624. @required(et_id=(bytes, str), et_channel_id=(bytes, str),
  625. marker=(bytes, str), max_Keys=int, dest_address=(bytes, str))
  626. def list_et_channel_route_rules(self, et_id, et_channel_id, marker=None,
  627. max_Keys=None, dest_address=None, config=None):
  628. """
  629. Return a list of route rules specifying the et channel
  630. :param et_id:
  631. The id of et.
  632. :type et_id: string
  633. :param et_channel_id:
  634. The id of et channel.
  635. :type et_channel_id: string
  636. :param marker:
  637. The optional parameter marker specified in the original request to specify
  638. where in the results to begin listing.
  639. Together with the marker, specifies the list result which listing should begin.
  640. If the marker is not specified, the list result will listing from the first one.
  641. :type marker: string
  642. :param max_keys:
  643. The optional parameter to specifies the max number of list result to return.
  644. The default value is 1000.
  645. :type max_keys: int
  646. :param dest_address:
  647. Destination address of the route rule.
  648. :type dest_address: string
  649. :param config:
  650. :type config: baidubce.BceClientConfiguration
  651. :return:
  652. :rtype baidubce.bce_response.BceResponse
  653. """
  654. path = utils.append_uri(self.prefix, self.et, et_id, self.channel,
  655. et_channel_id, self.route, self.rule)
  656. params = {}
  657. if marker is not None:
  658. params[b'marker'] = marker
  659. if max_Keys is not None:
  660. params[b'maxKeys'] = max_Keys
  661. if dest_address is not None:
  662. params[b'destAddress'] = dest_address
  663. return self._send_request(http_methods.GET, path, params=params, config=config)
  664. @required(et_id=(bytes, str), et_channel=(bytes, str), et_channel_route_rule_id=(bytes, str))
  665. def update_et_channel_route_rule(self, et_id, et_channel_id, et_channel_route_rule_id,
  666. description, client_token=None, config=None):
  667. """
  668. Modify the special et channel route rule to new value.
  669. :param et_id:
  670. The id of et.
  671. :type et_id: string
  672. :param et_channel_id:
  673. The id of et channel.
  674. :type et_channel_id: string
  675. :param et_channel_route_rule_id:
  676. The id of et channel route rule.
  677. :type et_channel_route_rule_id: string
  678. :param description:
  679. The description of the route rule.
  680. :type description: string
  681. :param client_token:
  682. An ASCII string whose length is less than 64.
  683. The request will be idempotent if clientToken is provided.
  684. If the clientToken is not specified by the user,
  685. a random String generated by default algorithm will be used.
  686. :type client_token: string
  687. :param config:
  688. :type config: baidubce.BceClientConfiguration
  689. :return:
  690. :rtype baidubce.bce_response.BceResponse
  691. """
  692. path = utils.append_uri(self.prefix, self.et, et_id, self.channel, et_channel_id,
  693. self.route, self.rule, et_channel_route_rule_id)
  694. params = {}
  695. body = {
  696. 'description': compat.convert_to_string(description)
  697. }
  698. if client_token is None:
  699. params[b'clientToken'] = generate_client_token()
  700. else:
  701. params[b'clientToken'] = client_token
  702. return self._send_request(http_methods.PUT, path, json.dumps(body),
  703. params=params, config=config)
  704. @required(et_id=(bytes, str), et_channel_id=(bytes, str), et_channel_route_rule_id=(bytes, str))
  705. def delete_et_channel_route_rule(self, et_id, et_channel_id, et_channel_route_rule_id,
  706. client_token=None, config=None):
  707. """
  708. Delete the special et channel route rule to new value.
  709. :param et_id:
  710. The id of et.
  711. :type et_id: string
  712. :param et_channel_id:
  713. The id of et channel.
  714. :type et_channel_id: string
  715. :param et_channel_route_rule_id:
  716. The id of et channel route rule.
  717. :type et_channel_route_rule_id: string
  718. :param client_token:
  719. An ASCII string whose length is less than 64.
  720. The request will be idempotent if clientToken is provided.
  721. If the clientToken is not specified by the user, a random String generated by default algorithm will
  722. be used.
  723. :type client_token: string
  724. :param config:
  725. :type config: baidubce.BceClientConfiguration
  726. :return:
  727. :rtype baidubce.bce_response.BceResponse
  728. """
  729. path = utils.append_uri(self.prefix, self.et, et_id, self.channel, et_channel_id,
  730. self.route, self.rule, et_channel_route_rule_id)
  731. params = {}
  732. if client_token is None:
  733. params[b'clientToken'] = generate_client_token()
  734. else:
  735. params[b'clientToken'] = client_token
  736. return self._send_request(http_methods.DELETE, path, params=params, config=config)
  737. @required(et_id=(bytes, str), et_channel_id=(bytes, str), extra_channel_id=(bytes, str))
  738. def associate_et_channel(self, et_id, et_channel_id, extra_channel_id, client_token=None, config=None):
  739. """
  740. Associate et channel.
  741. :param et_id:
  742. et id
  743. :type et_id: string
  744. : param et_channel_id:
  745. et channel id
  746. :type et_channel_id: string
  747. :param extra_channel_id:
  748. extra channel id
  749. :type extra_channel_id: string
  750. :param client_token:
  751. If the clientToken is not specified by the user, a random String
  752. generated by default algorithm will be used.
  753. :type client_token: string
  754. :param config:
  755. :type config: baidubce.BceClientConfiguration
  756. :return:
  757. :rtype baidubce.bce_response.BceResponse
  758. """
  759. path = utils.append_uri(self.prefix, self.et, et_id, self.channel,
  760. et_channel_id)
  761. params = {b'associate': None}
  762. if client_token is None:
  763. params[b'clientToken'] = generate_client_token()
  764. else:
  765. params[b'clientToken'] = client_token
  766. body = {
  767. 'extraChannelId': compat.convert_to_string(extra_channel_id),
  768. }
  769. return self._send_request(http_methods.PUT, path, params=params, body=json.dumps(body), config=config)
  770. @required(et_id=(bytes, str), et_channel_id=(bytes, str), extra_channel_id=(bytes, str))
  771. def disassociate_et_channel(self, et_id, et_channel_id, extra_channel_id, client_token=None, config=None):
  772. """
  773. Disassociate et channel.
  774. :param et_id:
  775. et id
  776. :type et_id: string
  777. :param et_channel_id:
  778. et channel id
  779. :type et_channel_id: string
  780. :param extra_channel_id:
  781. extra channel id
  782. :type extra_channel_id: string
  783. :param client_token:
  784. If the clientToken is not specified by the user, a random String
  785. generated by default algorithm will be used.
  786. :type client_token: string
  787. :param config:
  788. :type config: baidubce.BceClientConfiguration
  789. :return:
  790. :rtype baidubce.bce_response.BceResponse
  791. """
  792. path = utils.append_uri(self.prefix, self.et, et_id, self.channel,
  793. et_channel_id)
  794. params = {b'disassociate': None}
  795. if client_token is None:
  796. params[b'clientToken'] = generate_client_token()
  797. else:
  798. params[b'clientToken'] = client_token
  799. body = {
  800. 'extraChannelId': compat.convert_to_string(extra_channel_id),
  801. }
  802. return self._send_request(http_methods.PUT, path, params=params, body=json.dumps(body), config=config)
  803. def generate_client_token_by_uuid():
  804. """
  805. The default method to generate the random string for client_token
  806. if the optional parameter client_token is not specified by the user.
  807. :return:
  808. :rtype string
  809. """
  810. return str(uuid.uuid4())
  811. generate_client_token = generate_client_token_by_uuid