eni_client.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. # -*- coding: utf-8 -*-
  2. # Copyright (c) 2023 Baidu.com, Inc. All Rights Reserved
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. # use this file except in compliance with the License. You may obtain a copy
  6. # of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions
  14. # and limitations under the License.
  15. """
  16. This module provides a client class for ENI.
  17. """
  18. import copy
  19. import json
  20. import logging
  21. import uuid
  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. _logger = logging.getLogger(__name__)
  31. class EniClient(bce_base_client.BceBaseClient):
  32. """
  33. ENI base sdk client
  34. """
  35. prefix = b'/v1'
  36. def __init__(self, config=None):
  37. bce_base_client.BceBaseClient.__init__(self, config)
  38. def _merge_config(self, config=None):
  39. """
  40. :param config:
  41. :type config: baidubce.BceClientConfiguration
  42. :return:
  43. """
  44. if config is None:
  45. return self.config
  46. else:
  47. new_config = copy.copy(self.config)
  48. new_config.merge_non_none_values(config)
  49. return new_config
  50. def _send_request(self, http_method, path,
  51. body=None, headers=None, params=None,
  52. config=None, body_parser=None):
  53. config = self._merge_config(config)
  54. if body_parser is None:
  55. body_parser = handler.parse_json
  56. if headers is None:
  57. headers = {b'Accept': b'*/*', b'Content-Type': b'application/json;charset=utf-8'}
  58. return bce_http_client.send_request(
  59. config, bce_v1_signer.sign, [handler.parse_error, body_parser],
  60. http_method, EniClient.prefix + path, body, headers, params)
  61. @required(name=(bytes, str), subnet_id=(bytes, str), security_group_ids=list,
  62. enterprise_security_group_ids=list, eni_ip_address_list=list, eni_ipv6_address_list=list)
  63. def create_eni(self, name, subnet_id, security_group_ids=None, enterprise_security_group_ids=None,
  64. eni_ip_address_list=None, eni_ipv6_address_list=None, description=None,
  65. network_interface_traffic_mode=None,
  66. client_token=None, config=None):
  67. """
  68. :param name:
  69. The name of eni to be created.
  70. :type name: string
  71. :param subnet_id:
  72. The parameter to specify the id of subnet from vpc
  73. :type subnet_id: string
  74. :param security_group_ids:
  75. security_group_ids
  76. :type security_group_ids: list<string>
  77. :param enterprise_security_group_ids:
  78. enterprise_security_group_ids
  79. :type enterprise_security_group_ids: list<string>
  80. :param eni_ip_address_list:
  81. The parameter to specify the ipv4 address list of eni
  82. :type eni_ip_address_list: eni_model.EniIPSet
  83. :param eni_ipv6_address_list:
  84. The parameter to specify the ipv6 address list of eni
  85. :type eni_ip_address_list: eni_model.EniIPSet
  86. :param description:
  87. The description of the eni.
  88. :type description: string
  89. :param network_interface_traffic_mode:
  90. The traffic mode of the eni.
  91. :type network_interface_traffic_mode: string
  92. :param client_token:
  93. An ASCII string whose length is less than 64.
  94. The request will be idempotent if clientToken is provided.
  95. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  96. :type client_token: string
  97. :param config:
  98. :type config: baidubce.BceClientConfiguration
  99. :return:
  100. :rtype baidubce.bce_response.BceResponse
  101. """
  102. path = b'/eni'
  103. params = {}
  104. if client_token is None:
  105. params[b'clientToken'] = generate_client_token()
  106. else:
  107. params[b'clientToken'] = client_token
  108. body = {
  109. 'name': compat.convert_to_string(name),
  110. 'subnetId': compat.convert_to_string(subnet_id),
  111. }
  112. if security_group_ids is not None:
  113. body['securityGroupIds'] = security_group_ids
  114. if enterprise_security_group_ids is not None:
  115. body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
  116. if eni_ip_address_list is not None:
  117. pri_ip_set = []
  118. for ip_set in eni_ip_address_list:
  119. pri_ip_set.append({"publicIpAddress":ip_set.public_ip, "primary":ip_set.primary,
  120. "privateIpAddress":ip_set.private_ip})
  121. body['privateIpSet'] = pri_ip_set
  122. if eni_ipv6_address_list is not None:
  123. pri_ipv6_set = []
  124. for ip_set in eni_ipv6_address_list:
  125. pri_ipv6_set.append({"publicIpAddress":ip_set.public_ip, "primary":ip_set.primary,
  126. "privateIpAddress":ip_set.private_ip})
  127. body['ipv6PrivateIpSet'] = pri_ipv6_set
  128. if description is not None:
  129. body['description'] = compat.convert_to_string(description)
  130. if network_interface_traffic_mode is not None:
  131. body['networkInterfaceTrafficMode'] = compat.convert_to_string(network_interface_traffic_mode)
  132. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params,
  133. config=config)
  134. @required(eni_id=(bytes, str))
  135. def delete_eni(self, eni_id, client_token=None, config=None):
  136. """
  137. release the eni(delete operation)
  138. if the eni has been bound, must unbind before releasing.
  139. :type eni_id: string
  140. :param eni_id: eni to be released
  141. :type client_token: string
  142. :param client_token: if the clientToken is not specified by the user,
  143. a random String generated by default algorithm will be used.
  144. :type config: baidubce.BceClientConfiguration
  145. :param config:
  146. :return: BceResponse
  147. """
  148. path = b'/eni/%s' % compat.convert_to_bytes(eni_id)
  149. if client_token is None:
  150. client_token = generate_client_token()
  151. params = {
  152. b'clientToken': client_token
  153. }
  154. return self._send_request(http_methods.DELETE, path, params=params,
  155. config=config)
  156. @required(eni_id=(bytes, str), name=(bytes, str))
  157. def update_eni(self, eni_id, name=None, description=None, client_token=None, config=None):
  158. """
  159. :param eni_id: eni to be updated
  160. :type eni_id: string
  161. :param name: eni name to be updated
  162. :type name: string
  163. :param description:
  164. The description of the eni.
  165. :type description: string
  166. :param client_token:
  167. An ASCII string whose length is less than 64.
  168. The request will be idempotent if clientToken is provided.
  169. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  170. :type client_token: string
  171. :type config: baidubce.BceClientConfiguration
  172. :param config:
  173. :return: BceResponse
  174. """
  175. path = b'/eni/%s' % compat.convert_to_bytes(eni_id)
  176. if client_token is None:
  177. client_token = generate_client_token()
  178. params = {
  179. b'modifyAttribute': None,
  180. b'clientToken': client_token
  181. }
  182. body = {}
  183. if name is not None:
  184. body['name'] = compat.convert_to_string(name)
  185. if description is not None:
  186. body['description'] = compat.convert_to_string(description)
  187. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params,
  188. config=config)
  189. @required(vpc_id=(bytes, str), instance_id=(bytes, str), name=(bytes, str), private_ip_address_list=list,
  190. marker=(bytes, str), max_keys=int)
  191. def list_eni(self, vpc_id, instance_id=None, name=None, private_ip_address_list=None,
  192. marker=None, max_keys=None, client_token=None, config=None):
  193. """
  194. :param vpc_id: The parameter to specify the vpc id
  195. :type vpc_id: string
  196. :param instance_id: The parameter to specify the id of instance
  197. :type instance_id: string
  198. :param name: eni name to be updated
  199. :type name: string
  200. :param private_ip_address_list: The parameter to specify the private ip address list
  201. :type private_ip_address_list: list
  202. :param marker:
  203. The optional parameter marker specified in the original request to specify
  204. where in the results to begin listing.
  205. Together with the marker, specify the list result which listing should begin.
  206. If the marker is not specified, the list result will listing from the first one.
  207. :type marker: string
  208. :param max_keys:
  209. The optional parameter to specify the max number of list result to return.
  210. The default value is 1000.
  211. :type max_keys: int
  212. :param client_token:
  213. An ASCII string whose length is less than 64.
  214. The request will be idempotent if clientToken is provided.
  215. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  216. :type client_token: string
  217. :type config: baidubce.BceClientConfiguration
  218. :param config:
  219. :return: BceResponse
  220. """
  221. path = b'/eni'
  222. params = {}
  223. params[b'vpcId'] = compat.convert_to_string(vpc_id)
  224. if instance_id is not None:
  225. params[b'instanceId'] = compat.convert_to_string(instance_id)
  226. if name is not None:
  227. params[b'name'] = compat.convert_to_string(name)
  228. if private_ip_address_list is not None:
  229. params[b'privateIpAddress'] = (",").join(private_ip_address_list)
  230. if marker is not None:
  231. params[b'marker'] = compat.convert_to_string(marker)
  232. if max_keys is None:
  233. params[b'maxKeys'] = 1000
  234. else:
  235. params[b'maxKeys'] = max_keys
  236. if client_token is None:
  237. params[b'clientToken'] = generate_client_token()
  238. else:
  239. params[b'clientToken'] = client_token
  240. return self._send_request(http_methods.GET, path, params=params,
  241. config=config)
  242. @required(eni_id=(bytes, str), is_ipv6=bool, private_ip_address=(bytes, str))
  243. def add_private_ip(self, eni_id, private_ip_address, is_ipv6=None, client_token=None, config=None):
  244. """
  245. :param eni_id: The parameter to specify the id of eni
  246. :type eni_id: string
  247. :param is_ipv6: The parameter to specify the ipv6 flag
  248. :type is_ipv6: bool
  249. :param private_ip_address:
  250. The parameter to specify the private ip address.
  251. if is_ipv6 is True, the private ip address must be a valid ipv6 address.
  252. :type private_ip_address: string
  253. :param client_token:
  254. An ASCII string whose length is less than 64.
  255. The request will be idempotent if clientToken is provided.
  256. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  257. :type client_token: string
  258. :type config: baidubce.BceClientConfiguration
  259. :param config:
  260. :return: BceResponse
  261. """
  262. path = b'/eni/%s/privateIp' % compat.convert_to_bytes(eni_id)
  263. if client_token is None:
  264. client_token = generate_client_token()
  265. params = {
  266. b'clientToken': client_token
  267. }
  268. body = {}
  269. body['privateIpAddress'] = compat.convert_to_string(private_ip_address)
  270. if is_ipv6 is not None:
  271. body['isIpv6'] = is_ipv6
  272. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params,
  273. config=config)
  274. @required(eni_id=(bytes, str), private_ip_address=(bytes, str))
  275. def delete_private_ip(self, eni_id, private_ip_address, client_token=None, config=None):
  276. """
  277. :param eni_id: The parameter to specify the id of eni
  278. :type eni_id: string
  279. :param private_ip_address:
  280. The parameter to specify the private ip address.
  281. :type private_ip_address: string
  282. :param client_token:
  283. An ASCII string whose length is less than 64.
  284. The request will be idempotent if clientToken is provided.
  285. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  286. :type client_token: string
  287. :type config: baidubce.BceClientConfiguration
  288. :param config:
  289. :return: BceResponse
  290. """
  291. path = b'/eni/%s/privateIp/%s' % (compat.convert_to_bytes(eni_id),
  292. utils.normalize_string(private_ip_address))
  293. if client_token is None:
  294. client_token = generate_client_token()
  295. params = {
  296. b'clientToken': client_token
  297. }
  298. return self._send_request(http_methods.DELETE, path, params=params,
  299. config=config)
  300. @required(eni_id=(bytes, str))
  301. def get_eni_details(self, eni_id, client_token=None, config=None):
  302. """
  303. :param eni_id: The parameter to specify the id of eni
  304. :type eni_id: string
  305. :param client_token:
  306. An ASCII string whose length is less than 64.
  307. The request will be idempotent if clientToken is provided.
  308. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  309. :type client_token: string
  310. :type config: baidubce.BceClientConfiguration
  311. :param config:
  312. :return: BceResponse
  313. """
  314. path = b'/eni/%s' % compat.convert_to_bytes(eni_id)
  315. if client_token is None:
  316. client_token = generate_client_token()
  317. params = {
  318. b'clientToken': client_token
  319. }
  320. return self._send_request(http_methods.GET, path, params=params,
  321. config=config)
  322. @required(eni_id=(bytes, str), instance_id=(bytes, str))
  323. def attach_eni_instance(self, eni_id, instance_id, client_token=None, config=None):
  324. """
  325. :param eni_id: The parameter to specify the id of eni
  326. :type eni_id: string
  327. :param instance_id: The parameter to specify the id of instance
  328. :type instance_id: string
  329. :param client_token:
  330. An ASCII string whose length is less than 64.
  331. The request will be idempotent if clientToken is provided.
  332. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  333. :type client_token: string
  334. :type config: baidubce.BceClientConfiguration
  335. :param config:
  336. :return: BceResponse
  337. """
  338. path = b'/eni/%s' % compat.convert_to_bytes(eni_id)
  339. if client_token is None:
  340. client_token = generate_client_token()
  341. params = {
  342. b'attach': None,
  343. b'clientToken': client_token
  344. }
  345. body = {}
  346. if instance_id is not None:
  347. body['instanceId'] = compat.convert_to_string(instance_id)
  348. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params,
  349. config=config)
  350. @required(eni_id=(bytes, str), instance_id=(bytes, str))
  351. def detach_eni_instance(self, eni_id, instance_id, client_token=None, config=None):
  352. """
  353. :param eni_id: The parameter to specify the id of eni
  354. :type eni_id: string
  355. :param instance_id: The parameter to specify the id of instance
  356. :type instance_id: string
  357. :param client_token:
  358. An ASCII string whose length is less than 64.
  359. The request will be idempotent if clientToken is provided.
  360. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  361. :type client_token: string
  362. :type config: baidubce.BceClientConfiguration
  363. :param config:
  364. :return: BceResponse
  365. """
  366. path = b'/eni/%s' % compat.convert_to_bytes(eni_id)
  367. if client_token is None:
  368. client_token = generate_client_token()
  369. params = {
  370. b'detach': None,
  371. b'clientToken': client_token
  372. }
  373. body = {}
  374. if instance_id is not None:
  375. body['instanceId'] = compat.convert_to_string(instance_id)
  376. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params,
  377. config=config)
  378. @required(eni_id=(bytes, str), security_group_ids=list)
  379. def update_eni_security_group(self, eni_id, security_group_ids, client_token=None, config=None):
  380. """
  381. :param eni_id: The parameter to specify the id of eni
  382. :type eni_id: string
  383. :param security_group_ids: security group ids
  384. :type security_group_ids: list
  385. :param client_token:
  386. An ASCII string whose length is less than 64.
  387. The request will be idempotent if clientToken is provided.
  388. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  389. :type client_token: string
  390. :type config: baidubce.BceClientConfiguration
  391. :param config:
  392. :return: BceResponse
  393. """
  394. path = b'/eni/%s' % compat.convert_to_bytes(eni_id)
  395. if client_token is None:
  396. client_token = generate_client_token()
  397. params = {
  398. b'bindSg': None,
  399. b'clientToken': client_token
  400. }
  401. body = {}
  402. body['securityGroupIds'] = security_group_ids
  403. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params,
  404. config=config)
  405. @required(eni_id=(bytes, str), security_group_ids=list)
  406. def update_eni_enterprise_security_group(self, eni_id, enterprise_security_group_ids,
  407. client_token=None, config=None):
  408. """
  409. :param eni_id: The parameter to specify the id of eni
  410. :type eni_id: string
  411. :param enterprise_security_group_ids: enterprise security group ids
  412. :type enterprise_security_group_ids: list
  413. :param client_token:
  414. An ASCII string whose length is less than 64.
  415. The request will be idempotent if clientToken is provided.
  416. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  417. :type client_token: string
  418. :type config: baidubce.BceClientConfiguration
  419. :param config:
  420. :return: BceResponse
  421. """
  422. path = b'/eni/%s' % compat.convert_to_bytes(eni_id)
  423. if client_token is None:
  424. client_token = generate_client_token()
  425. params = {
  426. b'bindEsg': None,
  427. b'clientToken': client_token
  428. }
  429. body = {}
  430. body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
  431. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params,
  432. config=config)
  433. @required(eni_id=(bytes, str), is_ipv6=bool, private_ip_address_list=list, private_ip_address_count=int)
  434. def batch_add_private_ip(self, eni_id, is_ipv6=None, private_ip_address_list=None,
  435. private_ip_address_count=None, client_token=None, config=None):
  436. """
  437. :param eni_id: The parameter to specify the id of eni
  438. :type eni_id: string
  439. :param is_ipv6: The parameter to specify the ipv6 flag
  440. :type is_ipv6: bool
  441. :param private_ip_address_list:
  442. The parameter to specify the private ip address list.
  443. if is_ipv6 is True, the private ip address must be a valid ipv6 address.
  444. :type private_ip_address_list: list
  445. :param client_token:
  446. An ASCII string whose length is less than 64.
  447. The request will be idempotent if clientToken is provided.
  448. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  449. :type client_token: string
  450. :type config: baidubce.BceClientConfiguration
  451. :param config:
  452. :return: BceResponse
  453. """
  454. path = b'/eni/%s/privateIp/batchAdd' % compat.convert_to_bytes(eni_id)
  455. if client_token is None:
  456. client_token = generate_client_token()
  457. params = {
  458. b'clientToken': client_token
  459. }
  460. body = {}
  461. if private_ip_address_list is not None:
  462. body['privateIpAddresses'] = private_ip_address_list
  463. if is_ipv6 is not None:
  464. body['isIpv6'] = is_ipv6
  465. if private_ip_address_count is not None:
  466. body['privateIpAddressCount'] = private_ip_address_count
  467. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params,
  468. config=config)
  469. @required(eni_id=(bytes, str), private_ip_address_list=list)
  470. def batch_delete_private_ip(self, eni_id, private_ip_address_list, client_token=None, config=None):
  471. """
  472. :param eni_id: The parameter to specify the id of eni
  473. :type eni_id: string
  474. :param private_ip_address_list:
  475. The parameter to specify the private ip address list.
  476. if is_ipv6 is True, the private ip address must be a valid ipv6 address.
  477. :type private_ip_address_list: list
  478. :param client_token:
  479. An ASCII string whose length is less than 64.
  480. The request will be idempotent if clientToken is provided.
  481. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  482. :type client_token: string
  483. :type config: baidubce.BceClientConfiguration
  484. :param config:
  485. :return: BceResponse
  486. """
  487. path = b'/eni/%s/privateIp/batchDel' % compat.convert_to_bytes(eni_id)
  488. if client_token is None:
  489. client_token = generate_client_token()
  490. params = {
  491. b'clientToken': client_token
  492. }
  493. body = {}
  494. body['privateIpAddresses'] = private_ip_address_list
  495. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params,
  496. config=config)
  497. @required(eni_id=(bytes, str))
  498. def get_eni_status(self, eni_id, client_token=None, config=None):
  499. """
  500. :param eni_id: The parameter to specify the id of eni
  501. :type eni_id: string
  502. :param client_token:
  503. An ASCII string whose length is less than 64.
  504. The request will be idempotent if clientToken is provided.
  505. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  506. :type client_token: string
  507. :type config: baidubce.BceClientConfiguration
  508. :param config:
  509. :return: BceResponse
  510. """
  511. path = b'/eni/%s/status' % compat.convert_to_bytes(eni_id)
  512. if client_token is None:
  513. client_token = generate_client_token()
  514. params = {
  515. b'clientToken': client_token
  516. }
  517. return self._send_request(http_methods.GET, path, params=params,
  518. config=config)
  519. @required(eni_id=(bytes, str), private_ip_address=(bytes, str), public_ip_address=(bytes, str))
  520. def bind_eni_public_ip(self, eni_id, privat_ip_address, public_ip_address, client_token=None, config=None):
  521. """
  522. :param eni_id: The parameter to specify the id of eni
  523. :type eni_id: string
  524. :param private_ip_address:
  525. The parameter to specify the private ip address.
  526. :type private_ip_address: string
  527. :param public_ip_address:
  528. The parameter to specify the public ip address.
  529. :type public_ip_address: string
  530. :param client_token:
  531. An ASCII string whose length is less than 64.
  532. The request will be idempotent if clientToken is provided.
  533. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  534. :type client_token: string
  535. :type config: baidubce.BceClientConfiguration
  536. :param config:
  537. :return: BceResponse
  538. """
  539. path = b'/eni/%s' % compat.convert_to_bytes(eni_id)
  540. if client_token is None:
  541. client_token = generate_client_token()
  542. params = {
  543. b'bind': None,
  544. b'clientToken': client_token
  545. }
  546. body = {}
  547. body['privateIpAddress'] = compat.convert_to_string(privat_ip_address)
  548. body['publicIpAddress'] = compat.convert_to_string(public_ip_address)
  549. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params,
  550. config=config)
  551. @required(eni_id=(bytes, str), private_ip_address=(bytes, str), public_ip_address=(bytes, str))
  552. def unbind_eni_public_ip(self, eni_id, public_ip_address, client_token=None, config=None):
  553. """
  554. :param eni_id: The parameter to specify the id of eni
  555. :type eni_id: string
  556. :param public_ip_address:
  557. The parameter to specify the public ip address.
  558. :type public_ip_address: string
  559. :param client_token:
  560. An ASCII string whose length is less than 64.
  561. The request will be idempotent if clientToken is provided.
  562. If the clientToken is not specified by the user, a random String generated by default algorithm will be used.
  563. :type client_token: string
  564. :type config: baidubce.BceClientConfiguration
  565. :param config:
  566. :return: BceResponse
  567. """
  568. path = b'/eni/%s' % compat.convert_to_bytes(eni_id)
  569. if client_token is None:
  570. client_token = generate_client_token()
  571. params = {
  572. b'unBind': None,
  573. b'clientToken': client_token
  574. }
  575. body = {}
  576. body['publicIpAddress'] = compat.convert_to_string(public_ip_address)
  577. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params,
  578. config=config)
  579. def generate_client_token_by_uuid():
  580. """
  581. The default method to generate the random string for client_token
  582. if the optional parameter client_token is not specified by the user.
  583. :return:
  584. :rtype string
  585. """
  586. return str(uuid.uuid4())
  587. generate_client_token = generate_client_token_by_uuid