rds_client.py 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902
  1. # Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  4. # except in compliance with the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the
  9. # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  10. # either express or implied. See the License for the specific language governing permissions
  11. # and limitations under the License.
  12. """
  13. This module provides a client class for RDS.
  14. """
  15. from __future__ import unicode_literals
  16. import copy
  17. import json
  18. import logging
  19. import random
  20. import string
  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.services.rds import rds_model
  28. from baidubce.utils import aes128_encrypt_16char_key
  29. from baidubce.utils import required
  30. from baidubce import compat
  31. _logger = logging.getLogger(__name__)
  32. FETCH_MODE_SYNC = b"sync"
  33. FETCH_MODE_ASYNC = b"async"
  34. ENCRYPTION_ALGORITHM = "AES256"
  35. default_billing_to_purchase_created = rds_model.Billing('Postpaid')
  36. default_billing_to_purchase_reserved = rds_model.Billing()
  37. class RDSClient(bce_base_client.BceBaseClient):
  38. """
  39. Rds base sdk client
  40. """
  41. prefix = b'/v1'
  42. prefix_v2 = b'/v2'
  43. def __init__(self, config=None):
  44. bce_base_client.BceBaseClient.__init__(self, config)
  45. def _merge_config(self, config=None):
  46. if config is None:
  47. return self.config
  48. else:
  49. new_config = copy.copy(self.config)
  50. new_config.merge_non_none_values(config)
  51. return new_config
  52. # 1. instance manager
  53. def _send_request(self, http_method, path,
  54. body=None, headers=None, params=None,
  55. config=None, body_parser=None, prefix=None):
  56. config = self._merge_config(config)
  57. if body_parser is None:
  58. body_parser = handler.parse_json
  59. if prefix is None:
  60. prefix = RDSClient.prefix
  61. return bce_http_client.send_request(
  62. config, bce_v1_signer.sign, [handler.parse_error, body_parser],
  63. http_method, prefix + path, body, headers, params)
  64. @required(engine=(str), engine_version=(str), category=(str),
  65. cpuCount=int, memory_capacity=int, volume_capacity=int, disk_io_type=(str),
  66. purchase_count=int, zone_names=list, vpc_id=(str),
  67. subnets=list)
  68. def create_instance(self, engine, engine_version, category, cpu_count, memory_capacity, volume_capacity,
  69. disk_io_type, is_direct_pay=None, initial_data_reference=None, bgw_group_id=None,
  70. bgw_group_exclusive=None, character_set_name=None, lower_case_table_names=None,
  71. parameter_template_id=None, data=None, instance_name=None, vpc_id=None, subnets=None,
  72. tags=None, purchase_count=1, zone_names=None, auto_renew_time_unit='month',
  73. auto_renew_time=None, billing=None, config=None, client_token=None):
  74. """
  75. Create instance with specific config
  76. :param purchase_count:
  77. Instance count
  78. :type purchase_count: int
  79. :param instance_name:
  80. Instance name
  81. :type instance_name: string
  82. :param engine:
  83. database engine
  84. :type engine: string
  85. :param engine_version:
  86. database version
  87. :type engine_version: string or unicode
  88. :param category: Singleton or Standard
  89. :type category: string
  90. :param cpu_count: Number of CPUs
  91. :type cpu_count: int
  92. :param memory_capacity:
  93. memory size,unit:GB
  94. :type memory_capacity: int
  95. :param volume_capacity:
  96. disk size,unit:GB
  97. :type volume_capacity: int
  98. :param disk_io_type:
  99. normal_io; cloud_high; cloud_nor; cloud_enha
  100. :type disk_io_type: string
  101. :param zone_names:
  102. Subnet Name Collection
  103. :type zone_names: list
  104. :param vpc_id:
  105. the vpc short id
  106. :type vpc_id: string
  107. :param is_direct_pay:
  108. Whether to make direct payment, default to false.
  109. Variable configuration orders set to direct payment will
  110. be directly deducted without the need for payment logic
  111. :type is_direct_pay: bool
  112. :param initial_data_reference:
  113. :type initial_data_reference: rds_instance_model.InitialDataReference
  114. :param subnets:
  115. list of model.SubnetMap
  116. :type subnets: list
  117. :param tags:
  118. tag object of collection
  119. :type tags: list
  120. :param bgw_group_id:
  121. If bgwGroupExclusive is true,
  122. if a dedicated cluster ID is specified when creating an instance,
  123. BLB will be assigned to the specified dedicated cluster.
  124. If not passed, it will be assigned by default
  125. :type bgw_group_id: string
  126. :param bgw_group_exclusive:
  127. Load balancing cluster attributes,
  128. true indicates specifying a dedicated cluster,
  129. false indicates using a shared cluster
  130. :type bgw_group_exclusive: bool
  131. :param character_set_name:
  132. the Specify the instance character set,
  133. which includes options such as "utf8mb4",
  134. "latin1", "gbk", and "utf8". The default is "utf8"
  135. (currently only supports MySQL primary instances)
  136. :type character_set_name: string
  137. :param lower_case_table_names:
  138. Is the table name case sensitive. The default is 0,
  139. indicating case sensitivity and case sensitivity;
  140. Pass 1 to indicate case insensitivity
  141. :type lower_case_table_names: int
  142. :param parameter_template_id:
  143. parameter template id
  144. :type parameter_template_id: string
  145. :param auto_renew_time_unit:
  146. Renew monthly or yearly,value in ['month','year]
  147. :type auto_renew_time_unit: str
  148. :param auto_renew_time:
  149. If billing is Prepay, the automatic renewal time is 1-9
  150. when auto_renew_time_unit is 'month' and 1-3 when auto_renew_time_unit is 'year'
  151. :type auto_renew_time: int
  152. :param initial_data_reference:
  153. :type initial_data_reference: instance_model.InitialDataReference
  154. :param data:
  155. Parameter Object of lit
  156. :type data: list
  157. :param billing: default billing is Prepay 1 month
  158. :type billing: rds_instance_model.Billing
  159. :param config: None
  160. :type config: BceClientConfiguration
  161. :return: Object
  162. {
  163. "instance_ids": ["rds-sgrw14145"]
  164. }
  165. :rtype: baidubce.bce_response.BceResponse
  166. """
  167. if billing is None:
  168. billing = rds_model.Billing()
  169. if zone_names is None:
  170. zone_names = []
  171. if subnets is None:
  172. subnets = []
  173. if tags is None:
  174. tags = []
  175. if data is None:
  176. data = []
  177. body = {
  178. 'billing': billing.__dict__,
  179. 'purchaseCount': purchase_count,
  180. 'instanceName': instance_name,
  181. 'engine': engine,
  182. 'engineVersion': engine_version,
  183. 'category': category,
  184. 'cpuCount': cpu_count,
  185. 'memoryCapacity': memory_capacity,
  186. 'volumeCapacity': volume_capacity,
  187. 'diskIoType': disk_io_type,
  188. 'zoneNames': zone_names,
  189. 'vpcId': vpc_id,
  190. 'isDirectPay': is_direct_pay,
  191. 'subnets': subnets,
  192. 'tags': tags,
  193. 'bgwGroupId': bgw_group_id,
  194. 'bgwGroupExclusive': bgw_group_exclusive,
  195. 'characterSetName': character_set_name,
  196. 'lowerCaseTableNames': lower_case_table_names,
  197. 'parameterTemplateId': parameter_template_id,
  198. 'autoRenewTimeUnit': auto_renew_time_unit,
  199. 'autoRenewTime': auto_renew_time,
  200. 'initialDataReference': initial_data_reference,
  201. 'data': data
  202. }
  203. path = b'/instance'
  204. params = {}
  205. if client_token is None:
  206. params['clientToken'] = generate_client_token()
  207. else:
  208. params['clientToken'] = client_token
  209. headers = {b'Content-Type': b'application/json'}
  210. return self._send_request(http_methods.POST, path, json.dumps(body),
  211. headers=headers, params=params, config=config)
  212. @required(instance_name=(str), source_instance_id=(str), zone_names=list, vpc_id=(str),
  213. is_direct_pay=bool, subnets=list, tags=list, billing=rds_model.Billing)
  214. def create_read_instance(self, source_instance_id, cpu_count, memory_capacity, volume_capacity,
  215. instance_name=None, vpc_id=None, subnets=None, tags=None, zone_names=None,
  216. disk_io_type=None, is_direct_pay=None, billing=None,
  217. config=None):
  218. """
  219. Create instance with specific config
  220. :param source_instance_id:
  221. The Source instance count
  222. :type source_instance_id: string
  223. :param instance_name:
  224. The Instance name
  225. :type instance_name: string
  226. :param cpu_count: cpu core number
  227. :type cpu_count: int
  228. :param memory_capacity:
  229. The memory size ,unit:GB
  230. :type memory_capacity: int
  231. :param volume_capacity:
  232. The disk size,unit:GB
  233. :type volume_capacity: int
  234. :param disk_io_type:
  235. normal_io; cloud_high; cloud_nor; cloud_enha
  236. :type disk_io_type: string
  237. :param zone_names:
  238. zone name of arraylist
  239. :type zone_names: list
  240. :param vpc_id:
  241. VPC short ID
  242. :type vpc_id: string
  243. :param is_direct_pay:
  244. :type is_direct_pay: bool
  245. :param subnets:
  246. list of model.SubnetMap
  247. :type subnets: list
  248. :param tags:
  249. :type tags: list
  250. :param billing: default billing is Prepay 1 month
  251. :type billing: rds_instance_model.Billing
  252. :param config: None
  253. :type config: BceClientConfiguration
  254. :return: Object
  255. {
  256. "instance_ids": ["rds-sgrw14145"]
  257. }
  258. :rtype: baidubce.bce_response.BceResponse
  259. """
  260. if billing is None:
  261. billing = rds_model.Billing()
  262. if zone_names is None:
  263. zone_names = []
  264. if subnets is None:
  265. subnets = []
  266. if tags is None:
  267. tags = []
  268. data = {
  269. 'billing': billing.__dict__,
  270. 'sourceInstanceId': source_instance_id,
  271. 'instanceName': instance_name,
  272. 'cpuCount': cpu_count,
  273. 'memoryCapacity': memory_capacity,
  274. 'volumeCapacity': volume_capacity,
  275. 'zoneNames': zone_names,
  276. 'vpcId': vpc_id,
  277. 'diskIoType': disk_io_type,
  278. 'isDirectPay': is_direct_pay,
  279. 'subnets': subnets,
  280. 'tags': tags
  281. }
  282. path = b'/instance'
  283. headers = {b'Content-Type': b'application/json'}
  284. return self._send_request(http_methods.POST, path,
  285. params={"clientToken": uuid.uuid4(), "readReplica": ""},
  286. headers=headers,
  287. body=json.dumps(data, cls=rds_model.JsonWrapper, indent=4),
  288. config=config)
  289. @required(instance_name=(str), source_instance_id=(str), node_amount=int, zone_names=list,
  290. vpc_id=(str), is_direct_pay=bool, subnets=list, tags=list, billing=rds_model.Billing)
  291. def create_proxy_instance(self, source_instance_id, node_amount, instance_name=None,
  292. vpc_id=None, subnets=None, tags=None, zone_names=None,
  293. is_direct_pay=None, billing=None, config=None):
  294. """
  295. Create instance with specific config
  296. :param source_instance_id:
  297. Source instance count
  298. :type source_instance_id: string
  299. :param instance_name:
  300. Instance name
  301. :type instance_name: string
  302. :param node_amount:
  303. number of node
  304. :type node_amount: int
  305. :param zone_names:
  306. zone name of arraylist
  307. :type zone_names: list
  308. :param vpc_id:
  309. :type vpc_id: string
  310. :param is_direct_pay:
  311. Whether to make direct payment, default to false.
  312. Variable configuration orders set to direct payment will
  313. be directly deducted without the need for payment logic
  314. :type is_direct_pay: bool
  315. :param subnets: list of model.SubnetMap
  316. :type subnets: list
  317. :param tags:
  318. tag object of arraylist
  319. :type tags: list
  320. :param billing: default billing is Prepay 1 month
  321. :type billing: instance_model.Billing
  322. :param config: None
  323. :type config: BceClientConfiguration
  324. :return: Object
  325. {
  326. "instance_ids": ["rds-sgrw14145"]
  327. }
  328. :rtype: baidubce.bce_response.BceResponse
  329. """
  330. if billing is None:
  331. billing = rds_model.Billing()
  332. if zone_names is None:
  333. zone_names = []
  334. if subnets is None:
  335. subnets = []
  336. if tags is None:
  337. tags = []
  338. data = {
  339. 'billing': billing.__dict__,
  340. 'sourceInstanceId': source_instance_id,
  341. 'instanceName': instance_name,
  342. 'nodeAmount': node_amount,
  343. 'zoneNames': zone_names,
  344. 'vpcId': vpc_id,
  345. 'isDirectPay': is_direct_pay,
  346. 'subnets': subnets,
  347. 'tags': tags
  348. }
  349. headers = {b'Content-Type': b'application/json'}
  350. return self._send_request(http_methods.POST,
  351. b'/instance',
  352. params={"clientToken": uuid.uuid4(), "rdsproxy": ""}, headers=headers,
  353. body=json.dumps(data, cls=rds_model.JsonWrapper, indent=4),
  354. config=config)
  355. @required(instance_id=(str))
  356. def get_instance_detail(self, instance_id, config=None):
  357. """
  358. Get instance detail
  359. :param instance_id:
  360. The ID of instance
  361. :type instance_id: string or unicode
  362. :param config: None
  363. :type config: BceClientConfiguration
  364. :return:
  365. {
  366. "instanceId": "rds-mut9rhom8p3m",
  367. "instanceName": "mysql56",
  368. "memoryCapacity": 0.25,
  369. "volumeCapacity": 5,
  370. "nodeAmount": 2,
  371. "usedStorage": 0.5672,
  372. "engine": "mysql",
  373. "engineVersion": "5.6",
  374. "characterSetName": "utf8mb4",
  375. "instanceStatus": "Available",
  376. "publicAccessStatus": "Closed",
  377. "instanceCreateTime": "2016-04-26T06:46:30Z",
  378. "instanceExpireTime": "2016-05-26T06:46:11Z",
  379. "endpoint": {
  380. "address": "<address>",
  381. "port": 3306,
  382. "vnetIp": "<vnetIp>",
  383. "inetIp": "<inetIp>"
  384. },
  385. "instanceType": "Master",
  386. "zoneNames": ["cn-bj-a"],
  387. "vpcId": "v-kj3nc8fs",
  388. "backupPolicy": {
  389. "backupDays": "0,1,2,3,4,5,6",
  390. "backupTime": "17:00:00Z",
  391. "persistent": false,
  392. "expireInDays": 0,
  393. "freeSpace": 5
  394. },
  395. "topology": {
  396. "rdsproxy": [],
  397. "master": [
  398. "rds-mut9rhog"
  399. ],
  400. "readReplica": [
  401. "rds-m2s2du6j",
  402. "rds-m4bkxb0i"
  403. ]
  404. },
  405. "syncMode": "Async",
  406. "paymentTiming": "Prepaid"
  407. }
  408. """
  409. template = b'/instance/{instance_id}'
  410. # 注意:由于模板是bytes类型,你需要将变量也转换为bytes类型以匹配
  411. formatted_url = template.decode().format(instance_id=instance_id).encode()
  412. return self._send_request(http_methods.GET,
  413. formatted_url,
  414. params=None,
  415. body=None,
  416. config=config)
  417. def list_instances(self, marker=None, max_keys=1000, config=None):
  418. """
  419. Get instances in current region
  420. :param marker:
  421. To search for the instance id, fill in -1 from the first page
  422. :type marker: str
  423. :param max_keys:
  424. max count per page,deafult is 1000
  425. :type marker: int
  426. :param config:
  427. :return:
  428. """
  429. params = {}
  430. if marker is not None:
  431. params[b'marker'] = marker
  432. if max_keys is not None:
  433. params[b'maxKeys'] = max_keys
  434. return self._send_request(http_methods.GET,
  435. path=b'/instance',
  436. params=params,
  437. config=config)
  438. @required(instance_id=(str), cpu_count=int, memory_capacity=int, volume_capacity=int, node_amount=int,
  439. is_direct_pay=bool, is_enhanced=bool, effective_time=(str))
  440. def resize_instance(self, instance_id, cpu_count=None, memory_capacity=None, volume_capacity=None,
  441. node_amount=None, is_direct_pay=None, is_enhanced=None, effective_time=None,
  442. disk_io_type=None, force_hot_upgrade=None, master_azone=None, backup_azone=None,
  443. subnet_id=None, edge_subnet_id=None, config=None):
  444. """
  445. Create instance with specific config
  446. :param cpu_count:
  447. CPU cores number,Unit:Pieces
  448. :type cpu_count: int
  449. :param memory_capacity:
  450. memory size,Unit:GB
  451. :type memory_capacity: int
  452. :param volume_capacity:
  453. disk size,Unit:GB
  454. :type volume_capacity: int
  455. :param node_amount:
  456. number of nodes
  457. :type node_amount: int
  458. :param is_direct_pay:
  459. Whether to make direct payment, default to false.
  460. Variable configuration orders set to direct payment will
  461. be directly deducted without the need for payment logic
  462. :type is_direct_pay: bool
  463. :param effective_time:
  464. The operation execution method has two values: timewindow
  465. and immediate. Among them, timewindow represents execution
  466. within the time window, and immediate represents immediate
  467. execution. The default is immediate. The default time window
  468. for the instance is from 05:00 to 06:00. Please refer to the
  469. instance details for details
  470. :type effective_time: string
  471. :param disk_io_type:
  472. normal_io; cloud_high; cloud_nor; cloud_enha
  473. :type disk_io_type: string
  474. :param force_hot_upgrade:
  475. :type force_hot_upgrade: int
  476. :param master_azone:
  477. When changing the configuration, it is necessary to change
  478. the available area of the main database. This parameter
  479. needs to be passed a value, such as cn-bj-a.
  480. Do not transfer default to the current main database az
  481. :type master_azone: string
  482. :param subnet_id:
  483. Subnet ID, default to empty
  484. :type subnet_id: string
  485. :param backup_azone:
  486. When changing the configuration, it is necessary to change
  487. the available area of the backup database. This parameter
  488. needs to be passed a value, such as cn-bj-a. Do not transfer,
  489. default to retrieve the current backup database az
  490. :type backup_azone: string
  491. :param edge_subnet_id:
  492. Parameter Edge Subnet ID
  493. :type edge_subnet_id: string
  494. :param config: None
  495. :type config: BceClientConfiguration
  496. :return: Object
  497. {
  498. "instance_ids": ["rds-sgrw14145"]
  499. }
  500. :rtype: baidubce.bce_response.BceResponse
  501. """
  502. data = {
  503. 'cpuCount': cpu_count,
  504. 'memoryCapacity': memory_capacity,
  505. 'volumeCapacity': volume_capacity,
  506. 'nodeAmount': node_amount,
  507. 'isDirectPay': is_direct_pay,
  508. 'isEnhanced': is_enhanced,
  509. 'effectiveTime': effective_time,
  510. 'diskIoType': disk_io_type,
  511. 'forceHotUpgrade': force_hot_upgrade,
  512. 'masterAzone': master_azone,
  513. 'backupAzone': backup_azone,
  514. 'subnetId': subnet_id,
  515. 'edgeSubnetId': edge_subnet_id
  516. }
  517. path = b'/instance/{instance_id}'
  518. formatted_url = path.decode().format(instance_id=instance_id).encode()
  519. headers = {b'Content-Type': b'application/json'}
  520. return rds_model.CreateInstanceResponse(
  521. self._send_request(http_methods.PUT,
  522. path=formatted_url,
  523. body=json.dumps(data),
  524. headers=headers,
  525. params={"resize": ""},
  526. config=config))
  527. @required(instance_ids=(str))
  528. def delete_instance(self, instance_ids, config=None):
  529. """
  530. Delete instance
  531. :param instance_ids:
  532. The ID of instance
  533. :type instance_ids: string or unicode
  534. :param config:
  535. None
  536. :type config: BceClientConfiguration
  537. :return:
  538. """
  539. path = b'/instance'
  540. return self._send_request(http_method=http_methods.DELETE,
  541. path=path,
  542. params={"instanceIds": instance_ids},
  543. config=config)
  544. @required(instance_id=(str))
  545. def reboot_instance(self, instance_id, config=None):
  546. """
  547. Reboot instance
  548. :param instance_id:
  549. the ID of instance
  550. :type instance_id: string
  551. :param config:
  552. :type config: BceClientConfiguration
  553. :return:
  554. """
  555. template = b'/instance/{instance_id}'
  556. # 注意:由于模板是bytes类型,你需要将变量也转换为bytes类型以匹配
  557. formatted_url = template.decode().format(instance_id=instance_id).encode()
  558. headers = {b'Content-Type': b'application/json'}
  559. return self._send_request(http_method=http_methods.PUT,
  560. path=formatted_url,
  561. headers=headers,
  562. params={"reboot": ""},
  563. config=config)
  564. @required(instance_id=(str), instance_name=(str))
  565. def rename_instance(self, instance_id, instance_name, config=None):
  566. """
  567. Rename instance
  568. :param instance_id:
  569. the ID of instance
  570. :type instance_id: str
  571. :param instance_name:
  572. name
  573. :type instance_name: str
  574. :param config:
  575. :return:
  576. """
  577. data = {
  578. 'instanceName': instance_name
  579. }
  580. template = b'/instance/{instance_id}'
  581. # 注意:由于模板是bytes类型,你需要将变量也转换为bytes类型以匹配
  582. formatted_url = template.decode().format(instance_id=instance_id).encode()
  583. headers = {b'Content-Type': b'application/json'}
  584. return self._send_request(http_method=http_methods.PUT,
  585. path=formatted_url,
  586. params={"rename": ""},
  587. headers=headers,
  588. body=json.dumps(data),
  589. config=config)
  590. @required(instance_id=(str), sync_mode=(str))
  591. def modify_sync_mode_instance(self, instance_id, sync_mode, config=None):
  592. """
  593. ModifySyncMode instance
  594. :param instance_id:
  595. the ID of instance
  596. :type instance_id: str
  597. :param sync_mode:
  598. Async/Semi_sync
  599. :type sync_mode: str
  600. :param config:
  601. :return:
  602. """
  603. data = {
  604. 'syncMode': sync_mode
  605. }
  606. template = b'/instance/{instance_id}'
  607. # 注意:由于模板是bytes类型,你需要将变量也转换为bytes类型以匹配
  608. formatted_url = template.decode().format(instance_id=instance_id).encode()
  609. headers = {b'Content-Type': b'application/json'}
  610. return self._send_request(http_method=http_methods.PUT,
  611. path=formatted_url,
  612. params={"modifySyncMode": ""},
  613. headers=headers,
  614. body=json.dumps(data),
  615. config=config)
  616. @required(instance_id=(str), sync_mode=(str))
  617. def modify_endpoint_instance(self, instance_id, address, config=None):
  618. """
  619. ModifyEndpoint instance
  620. :param instance_id:
  621. the ID of instance
  622. :type instance_id: string
  623. :param address:
  624. Fill in the domain name
  625. :type address: string
  626. :param config:
  627. :type config: BceClientConfiguration
  628. :return:
  629. """
  630. data = {
  631. 'address': address
  632. }
  633. template = b'/instance/{instance_id}'
  634. # 注意:由于模板是bytes类型,你需要将变量也转换为bytes类型以匹配
  635. formatted_url = template.decode().format(instance_id=instance_id).encode()
  636. headers = {b'Content-Type': b'application/json'}
  637. return self._send_request(http_method=http_methods.PUT,
  638. path=formatted_url,
  639. params={"modifyEndpoint": ""},
  640. headers=headers,
  641. body=json.dumps(data),
  642. config=config)
  643. @required(instance_id=(str), public_access=bool)
  644. def modify_public_access_instance(self, instance_id, public_access, config=None):
  645. """
  646. ModifyPublicAccess instance
  647. :param instance_id:
  648. the ID of instance
  649. :type instance_id: string
  650. :param public_access:
  651. ture/false
  652. :type public_access: bool
  653. :param config:
  654. :type config: BceClientConfiguration
  655. :return:
  656. """
  657. data = {
  658. 'publicAccess': public_access
  659. }
  660. template = b'/instance/{instance_id}'
  661. # 注意:由于模板是bytes类型,你需要将变量也转换为bytes类型以匹配
  662. formatted_url = template.decode().format(instance_id=instance_id).encode()
  663. headers = {b'Content-Type': b'application/json'}
  664. return self._send_request(http_method=http_methods.PUT,
  665. path=formatted_url,
  666. params={"modifyPublicAccess": ""},
  667. headers=headers,
  668. body=json.dumps(data),
  669. config=config)
  670. @required(instance_ids=list, auto_renew_time_unit=(str), auto_renew_time=int)
  671. def auto_renew_instance(self, instance_ids=None, auto_renew_time_unit=None, auto_renew_time=None, config=None):
  672. """
  673. AutoRenew instance
  674. :param instance_ids:
  675. the ID of instance
  676. :type instance_ids: list
  677. :param auto_renew_time_unit:
  678. Renewal period, in months
  679. :type auto_renew_time_unit: str
  680. :param auto_renew_time:
  681. Renewal duration
  682. :type auto_renew_time: int
  683. :param config:
  684. :return:
  685. """
  686. if instance_ids is None:
  687. instance_ids = []
  688. data = {
  689. 'instanceIds': instance_ids,
  690. 'autoRenewTimeUnit': auto_renew_time_unit,
  691. 'autoRenewTime': auto_renew_time
  692. }
  693. headers = {b'Content-Type': b'application/json'}
  694. return self._send_request(http_method=http_methods.PUT,
  695. path=b'/instance',
  696. params={"autoRenew": ""},
  697. headers=headers,
  698. body=json.dumps(data),
  699. config=config)
  700. def zone(self, config=None):
  701. """
  702. Get zone list
  703. :param config:
  704. :type config: BceClientConfiguration
  705. :return:
  706. """
  707. return self._send_request(
  708. http_method=http_methods.GET,
  709. path=b'/zone',
  710. config=config)
  711. def subnet(self, vpc_id=None, zone_name=None, config=None):
  712. """
  713. get Subnet list
  714. :param config:
  715. :type config: BceClientConfiguration
  716. :return:
  717. """
  718. return self._send_request(http_method=http_methods.GET,
  719. path=b'/subnet',
  720. params={"vpcId": vpc_id, "zoneName": zone_name},
  721. config=config)
  722. def price_instance(self, duration, number, product_type, instance=None, config=None):
  723. """
  724. Gets the specified instance price
  725. :param duration:
  726. The purchase duration does not need to be set when the payment
  727. method is post-payment, but must be set when pre-payment.
  728. The default time unit is month.
  729. :type duration: int
  730. :param number:
  731. Number of purchases. The default value is 1.
  732. :type number: int
  733. :param product_type:
  734. prepay/postpay
  735. :type product_type: string
  736. :param instance: Inquiry parameter object
  737. :type instance: rds_instance_model.Instance
  738. :param config:
  739. :type config: BceClientConfiguration
  740. :return:
  741. """
  742. data = {
  743. 'instance': instance.__dict__,
  744. 'duration': duration,
  745. 'number': number,
  746. 'productType': product_type
  747. }
  748. headers = {b'Content-Type': b'application/json'}
  749. return self._send_request(http_methods.POST,
  750. path=b'/instance/price',
  751. headers=headers,
  752. body=json.dumps(data, cls=rds_model.JsonWrapper, indent=4),
  753. config=config)
  754. @required(order_id=(str))
  755. def order_status(self, order_id, config=None):
  756. """
  757. Get order status
  758. :param order_id:
  759. the ID of order
  760. :type order_id: string
  761. :param config:
  762. :type config: BceClientConfiguration
  763. :return:
  764. """
  765. template = b'/instance/order/{order_id}'
  766. # 注意:由于模板是bytes类型,你需要将变量也转换为bytes类型以匹配
  767. formatted_url = template.decode().format(order_id=order_id).encode()
  768. return self._send_request(http_method=http_methods.GET,
  769. path=formatted_url,
  770. config=config)
  771. @required(duration=int, instance_ids=list)
  772. def renew_instance(self, duration, instance_ids, config=None):
  773. """
  774. Used to renew existing prepaid instances.
  775. If the prepaid instance is in the recycle bin,
  776. it will be restored from the recycle bin after renewal.
  777. :param duration:
  778. Renewal period, unit is month
  779. :type duration: int
  780. :param instance_ids:
  781. An instance array of renewal instances
  782. :type instance_ids: list of string
  783. :param config:
  784. :return:
  785. """
  786. data = {
  787. "duration": duration,
  788. "instanceIds": instance_ids
  789. }
  790. headers = {b'Content-Type': b'application/json'}
  791. return self._send_request(http_method=http_methods.POST,
  792. path=b'/instance/renew',
  793. headers=headers,
  794. body=json.dumps(data),
  795. config=config)
  796. @required(instance_id=(str), maintain_start_time=(str), maintain_duration=int)
  797. def maintaintime_instance(self, instance_id, maintain_start_time, maintain_duration, config=None):
  798. """
  799. Update the time window of the instance.
  800. The default time window of the instance is 05:00 to 06:00
  801. :param instance_id:
  802. The ID of instance
  803. :type instance_id: string
  804. :param maintain_start_time:
  805. Start time of the instance maintenance time window,
  806. local time, for example, 17:00:00
  807. :type maintain_start_time: string
  808. :param maintain_duration:
  809. The duration of the instance maintenance time window,
  810. expressed in hours, for example,
  811. Each hour is a time range,The start time and duration cannot span one day
  812. :type maintain_duration: int
  813. :param config:
  814. :type config: BceClientConfiguration
  815. :return:
  816. """
  817. data = {
  818. "maintainDuration": maintain_duration,
  819. "maintainStartTime": maintain_start_time
  820. }
  821. template = b'/instance/{instance_id}/maintaintime'
  822. # 注意:由于模板是bytes类型,你需要将变量也转换为bytes类型以匹配
  823. formatted_url = template.decode().format(instance_id=instance_id).encode()
  824. headers={b'Content-Type': b'application/json'}
  825. return self._send_request(http_method=http_methods.PUT,
  826. path=formatted_url,
  827. headers=headers,
  828. body=json.dumps(data),
  829. config=config)
  830. # 2. database manager
  831. @required(instance_id=(str), data=(dict))
  832. def create_database(self, instance_id, data, config=None):
  833. """
  834. create a database on the specified instance
  835. :param instance_id:
  836. The specified instance ID
  837. :type instance_id: str
  838. :param data:
  839. This data is an AccountPrivilege array object
  840. :type data: list
  841. :param config: baidubce.BceClientConfiguration
  842. :type config: baidubce.BceClientConfiguration
  843. :return: void
  844. :@rtype: void
  845. """
  846. path = b'/instance/{instance_id}/databases'
  847. # 注意:由于模板是bytes类型,你需要将变量也转换为bytes类型以匹配
  848. formatted_url = path.decode().format(instance_id=instance_id).encode()
  849. headers = {b'Content-Type': b'application/json'}
  850. return self._send_request(http_method=http_methods.POST,
  851. path=formatted_url,
  852. headers=headers,
  853. body=json.dumps(data),
  854. config=config)
  855. @required(instance_id=(str))
  856. def query_database_list(self, instance_id, config=None):
  857. """
  858. query database information to return as a list
  859. :param instance_id:
  860. The instance id that needs to be queried
  861. :type instance_id: str
  862. :param config: config
  863. :type config: baidubce.BceClientConfiguration
  864. :return: json
  865. :type: string
  866. """
  867. path = b'/instance/{instance_id}/databases'
  868. # 注意:由于模板是bytes类型,你需要将变量也转换为bytes类型以匹配
  869. formatted_url = path.decode().format(instance_id=instance_id).encode()
  870. return self._send_request(http_method=http_methods.GET,
  871. path=formatted_url,
  872. config=config)
  873. @required(instance_id=(str), db_name=(str), remark=(str))
  874. def update_database_remark(self, instance_id, db_name=None, remark=None, config=None):
  875. """
  876. update the database remark on the specified instance
  877. :param instance_id:
  878. The specified instance ID
  879. :type instance_id: str
  880. :param db_name:
  881. The specified database name
  882. :type instance_id: str
  883. :param remark:
  884. need to update remark
  885. :type instance_id: str
  886. :param config: config
  887. :type config: baidubce.BceClientConfiguration
  888. :return: void
  889. """
  890. headers = {b'Content-Type': b'application/json'}
  891. data = {"remark": remark}
  892. path = b'/instance/{instance_id}/databases/{db_name}/remark'
  893. formatted_url = path.decode().format(instance_id=instance_id, db_name=db_name).encode()
  894. return self._send_request(http_method=http_methods.PUT,
  895. path=formatted_url,
  896. headers=headers,
  897. body=json.dumps(data),
  898. config=config)
  899. @required(instance_id=(str), db_port=(int))
  900. def update_database_port(self, instance_id, db_port=None, config=None):
  901. """
  902. Update the database port on the specified instance
  903. :param instance_id:
  904. The specified instance ID
  905. :type instance_id: str
  906. :param db_port:
  907. need to update port
  908. :type db_port: int
  909. :param config: config
  910. :type config: baidubce.BceClientConfiguration
  911. :return: void
  912. :rtype: void
  913. """
  914. data = {"entryPort": db_port}
  915. headers = {b'Content-Type': b'application/json'}
  916. path = b'/instance/{instance_id}/port'
  917. formatted_url = path.decode().format(instance_id=instance_id).encode()
  918. return self._send_request(http_method=http_methods.PUT,
  919. path=formatted_url,
  920. body=json.dumps(data),
  921. headers=headers,
  922. config=config)
  923. @required(instance_id=(str), db_name=(str))
  924. def delete_database(self, instance_id, db_name=None, config=None):
  925. """
  926. Delete the database on the specified instance
  927. :param instance_id:
  928. The specified instance ID
  929. :rtype: str
  930. :param db_name:
  931. need to update db_name
  932. :rtype: str
  933. :param config: config
  934. :type config: baidubce.BceClientConfiguration
  935. :return: void
  936. :rtype: void
  937. """
  938. path=b'/instance/{instance_id}/databases/{db_name}'
  939. # 注意:由于模板是bytes类型,你需要将变量也转换为bytes类型以匹配
  940. formatted_url = path.decode().format(instance_id=instance_id, db_name=db_name).encode()
  941. return self._send_request(http_method=http_methods.DELETE,
  942. path=formatted_url,
  943. config=config)
  944. # 3. backup manager
  945. @required(instance_id=(str), backup_id=(str))
  946. def backup_detail(self, instance_id, backup_id, config=None):
  947. """
  948. this is open api backup detail
  949. :param instance_id:
  950. The Specify the instance short id,for example: rds-rWLm6n4e
  951. :type instance_id: str
  952. :param backup_id:
  953. The Specify the backup id,for example: 1702325499881950802
  954. :param config: config
  955. :type config: baidubce.BceClientConfiguration
  956. :return:
  957. """
  958. path = b'/instance/{instanceId}/backup/{backupId}'
  959. formatted_url = path.decode().format(instanceId=instance_id, backupId=backup_id).encode()
  960. return self._send_request(http_method=http_methods.GET,
  961. path=formatted_url,
  962. body=None,
  963. config=config)
  964. @required(instance_id=(str))
  965. def backup_list(self, instance_id, marker=None, max_keys=None, config=None):
  966. """
  967. this is open api backup list
  968. :param instance_id:
  969. The Specify the instance short id,for example: rds-rWLm6n4e
  970. :type instance_id: str
  971. :param marker:
  972. The backup snapshot ID that needs to be searched,
  973. :type marker: str or None
  974. :param max_keys:
  975. Number of entries per page, default to 10
  976. :type max_keys: int
  977. :param config:config
  978. :type config: baidubce.BceClientConfiguration
  979. :return:
  980. :rtype rds_backup_policy_model.BackUpList
  981. """
  982. if marker is None:
  983. marker = '-1'
  984. if max_keys is None:
  985. max_keys = 1000
  986. params = {
  987. "marker": marker,
  988. "maxKeys": max_keys
  989. }
  990. path = b'/instance/{instanceId}/backup'
  991. formatted_url = path.decode().format(instanceId=instance_id).encode()
  992. return self._send_request(http_method=http_methods.GET,
  993. path=formatted_url,
  994. params=params,
  995. config=config)
  996. @required(instance_id=(str), backup_days=(str),
  997. backup_time=(str), persistent=(bool))
  998. def modify_backup_policy(self, instance_id, backup_days, backup_time, persistent, expire_in_days=None,
  999. config=None):
  1000. """
  1001. this is open api modify backup policy
  1002. :param instance_id:
  1003. The Specify the instance short id,for example: rds-rWLm6n4e
  1004. :type instance_id: str
  1005. :param backup_days:
  1006. Backup time day separated by a comma in English,
  1007. with Sunday as the first day, with a value of 0,
  1008. Example: "0,1,2,3,5,6"(mandatory)
  1009. :type backup_days: str
  1010. :param backup_time:
  1011. Backup start time, the time here is in UTC yyyy-mm-ddThh:mmZ format,
  1012. :type backup_time: str
  1013. :param persistent:
  1014. Is backup data persistence enabled,ture or false
  1015. :type persistent: bool
  1016. :param expire_in_days:
  1017. Persistence days, ranging from 1-730 days;
  1018. If not enabled, it is 0 or left blank
  1019. :type expire_in_days: int
  1020. :param config:config
  1021. :type config: baidubce.BceClientConfiguration
  1022. :return: void
  1023. """
  1024. path = b'/instance/{instanceId}'
  1025. formatted_url = path.decode().format(instanceId=instance_id).encode()
  1026. data = {
  1027. "backupDays": backup_days,
  1028. "backupTime": backup_time,
  1029. "persistent": persistent
  1030. }
  1031. if expire_in_days is not None:
  1032. data['expireInDays'] = int(expire_in_days)
  1033. headers = {b'Content-Type': b'application/json'}
  1034. return self._send_request(http_method=http_methods.PUT,
  1035. path=formatted_url,
  1036. headers = headers,
  1037. params={"modifyBackupPolicy": ""},
  1038. body=json.dumps(data),
  1039. config=config)
  1040. @required(instance_id=(str), effective_time=(str), data_backup_type=(str),
  1041. data_backup_objects=(list))
  1042. def full_backup(self, instance_id, effective_time=None, data_backup_type=None,
  1043. data_backup_objects=None, config=None):
  1044. """
  1045. Fully backup the database and data tables on the backup instance
  1046. :param instance_id:
  1047. The Specify the instance short id,for example: rds-rWLm6n4e
  1048. :type instance_id: str
  1049. :param effective_time:
  1050. Window field. The operation execution method has two values:
  1051. timewindow and immediate. Among them, timewindow represents
  1052. execution within the time window,and immediate represents
  1053. immediate execution.The default is immediate. The default
  1054. time window for the instance is from 05:00 to 06:00
  1055. :type effective_time: str
  1056. :param data_backup_type:
  1057. Backup type, supports physical/snapshot, with a value of snapshot.
  1058. If the disk type is SSD, snapshot backup is not supported
  1059. :type data_backup_type: str
  1060. :param data_backup_objects:
  1061. Tables/tables that require backup or restoring library/table objects
  1062. :type data_backup_objects: list
  1063. :param config:config
  1064. :type config: baidubce.BceClientConfiguration
  1065. :return:
  1066. """
  1067. data = {}
  1068. if effective_time is not None:
  1069. data['effectiveTime'] = effective_time
  1070. elif data_backup_type is not None:
  1071. data['dataBackupType'] = data_backup_type
  1072. elif data_backup_objects is not None:
  1073. data['dataBackupObjects'] = data_backup_objects
  1074. path = b'/instance/{instanceId}/backup'
  1075. formatted_url = path.decode().format(instanceId=instance_id).encode()
  1076. headers = {b'Content-Type': b'application/json'}
  1077. return self._send_request(http_method=http_methods.POST,
  1078. path=formatted_url,
  1079. headers=headers,
  1080. body=json.dumps(data),
  1081. config=config)
  1082. @required(instance_id=(str), snapsho_id=(str))
  1083. def delete_specified_backup(self, instance_id, snapshot_id, config=None):
  1084. """
  1085. delete specified backup sdk client
  1086. :param instance_id:
  1087. The Specify the instance short id,for example: rds-rWLm6n4e
  1088. :type instance_id: str
  1089. :param snapshot_id:
  1090. Delete the specified backup snapshot id, for example: 1701950306675099301
  1091. :type snapshot_id: str
  1092. :param config: config
  1093. :type config: baidubce.BceClientConfiguration
  1094. :return:
  1095. """
  1096. path = b'/instance/{instanceId}/backup/{snapshotId}'
  1097. formatted_url = path.decode().format(instanceId=instance_id, snapshotId=snapshot_id).encode()
  1098. return self._send_request(http_method=http_methods.DELETE,
  1099. path=formatted_url,
  1100. config=config)
  1101. @required(instance_id=(str), date_time=(str))
  1102. def binlog_list(self, instance_id, date_time, config=None):
  1103. """
  1104. Get the binlog list on the instance sdk client
  1105. :param instance_id:
  1106. The Specify the instance short id,for example: rds-rWLm6n4e
  1107. :type instance_id: str
  1108. :param date_time:
  1109. The time to obtain the binglog list, here is UTC time. Users need to
  1110. calculate the UTC time themselves and fill it in,The time to obtain
  1111. the binglog list, here is UTC time. Users need to calculate the UTC
  1112. time themselves and fill it in,The format is YYYY-MM-DDThh:mm:ss:z
  1113. :type date_time: str
  1114. :param config: config
  1115. :type config: baidubce.BceClientConfiguration
  1116. :return:
  1117. """
  1118. path = b'/instance/{instanceId}/binlogs/{datetime}'
  1119. formatted_url = path.decode().format(instanceId=instance_id, datetime=date_time).encode()
  1120. return self._send_request(http_method=http_methods.GET,
  1121. path=formatted_url,
  1122. config=config)
  1123. @required(instance_id=(str), binlog_id=(str),
  1124. download_valid_time_in_sec=(str))
  1125. def binlog_detail(self, instance_id, binlog_id, download_valid_time_in_sec, config=None):
  1126. """
  1127. obtain bean log details based on instance id
  1128. :param instance_id:
  1129. The Specify the instance short id,for example: rds-rWLm6n4e
  1130. :type binlog_id: str
  1131. :param download_valid_time_in_sec:
  1132. download effective time/S
  1133. :type download_valid_time_in_sec: int
  1134. :param config: config
  1135. :type config: baidubce.BceClientConfiguration
  1136. :return: BinlogDetail
  1137. :return: string
  1138. """
  1139. path = b'/instance/{instance_id}/binlogs/{binlog_id}/{downloadValidTimeInSec}'
  1140. formatted_url = path.decode().format(instance_id=instance_id, binlog_id=binlog_id,
  1141. downloadValidTimeInSec=download_valid_time_in_sec).encode()
  1142. return self._send_request(http_method=http_methods.GET,
  1143. path=formatted_url, config=config)
  1144. # 4. hot instance group manager
  1145. def force_change_instance(self, group_id, leader_id, force=None, max_behind=None, config=None):
  1146. """
  1147. Specify a hot active instance to forcibly switch to the main role
  1148. :param group_id:
  1149. The instance group id
  1150. to the primary role
  1151. :type group_id: str
  1152. :param leader_id:
  1153. The instance ID in the instance group that needs to switch
  1154. to the primary role
  1155. :type leader_id: str or None
  1156. :param force:
  1157. Used in fault state,0- Non fault (used in non fault state) 1-
  1158. Fault
  1159. :type force: int or None
  1160. :param max_behind:
  1161. Maximum allowable backup behind_Master value (0 indicates
  1162. that the data from the backup database and the faulty main
  1163. database must be completely consistent. It is recommended
  1164. that the business gradually increase from 0 until the
  1165. maximum tolerance value is reached.When force=0, this
  1166. parameter does not take effect)
  1167. :type force: int or None
  1168. :param config:config
  1169. :type config: baidubce.BceClientConfiguration or None
  1170. :return: json str
  1171. :type: josn
  1172. """
  1173. data = {
  1174. "leaderId": leader_id,
  1175. "force": force,
  1176. "maxBehind": max_behind
  1177. }
  1178. path = b'/instance/group/{groupId}/forceChange'
  1179. formatted_url = path.decode().format(groupId=group_id).encode()
  1180. headers = {b'Content-Type': b'application/json'}
  1181. return self._send_request(http_method=http_methods.PUT,
  1182. path=formatted_url,
  1183. body=json.dumps(data),
  1184. headers=headers,
  1185. config=config)
  1186. def group_batch_join(self, follower_ids, name, leader_id, config=None):
  1187. """
  1188. Interface Description
  1189. 1.This interface is used to batch add instances to the hot instance
  1190. group sdk client.
  1191. matters needing attention
  1192. 1.To join a hot instance group, the following prerequisites must be met
  1193. 2.The active instance group only supports MYSQL version 5.6/5.7
  1194. 3.The synchronization mode of the main instance must be asynchronous
  1195. synchronization
  1196. 4.The primary instance must have GTID enabled
  1197. 5.The location of the primary instance ID must be consistent with the
  1198. current requested location
  1199. 6.Batch added leader nodes cannot be within the current instance group
  1200. :param follower_ids:
  1201. slave instance short ID array
  1202. :type follower_ids: list
  1203. :param name:
  1204. Name of joining the instance group
  1205. :type name: str
  1206. :param leader_id:
  1207. Leader instance short ID
  1208. :type leader_id: str
  1209. :param config: config
  1210. :type config: baidubce.BceClientConfiguration
  1211. :return: void
  1212. :type: void
  1213. """
  1214. data = {
  1215. "followerIds": follower_ids,
  1216. "name": name,
  1217. "leaderId": leader_id
  1218. }
  1219. headers = {b'Content-Type': b'application/json'}
  1220. return self._send_request(http_method=http_methods.POST,
  1221. path=b'/instance/group/batchjoin',
  1222. headers=headers,
  1223. body=json.dumps(data),
  1224. config=config)
  1225. def create_group(self, name, leader_id, config=None):
  1226. """
  1227. Create a hot instance group
  1228. :param name:
  1229. Instance Group Name
  1230. :type name: str
  1231. :param leader_id:
  1232. Need to create an instance ID as a leader node
  1233. :type leader_id: str
  1234. :param config: config
  1235. :type config: baidubce.BceClientConfiguration
  1236. :return: void
  1237. :type: void
  1238. """
  1239. data = {
  1240. "name": name,
  1241. "leaderId": leader_id
  1242. }
  1243. headers = {b'Content-Type': b'application/json'}
  1244. return self._send_request(http_method=http_methods.POST,
  1245. path=b'/instance/group',
  1246. headers=headers,
  1247. body=json.dumps(data),
  1248. config=config)
  1249. def group_list(self, order=None, order_by=None, page_no=None, page_size=None, filter_map_str=None,
  1250. days_to_expiration=None, config=None):
  1251. """
  1252. Get a list of hot instance groups
  1253. :param order: asc/desc
  1254. :type order: str
  1255. :param order_by: sort field
  1256. :type order_by: str
  1257. :param page_no:
  1258. Current number of pages,
  1259. :type page_no: int
  1260. :param page_size:
  1261. Number of entries per page
  1262. :type page_size: int
  1263. :param filter_map_str:
  1264. Filtering that includes,three aspects: groupId, groupName, and instanceStatus
  1265. # filter_map_str = "{\"groupId\":\"rdcqzga9i4s\"}"
  1266. # filter_map_str = "{\"groupName\":\"acount-test\"}"
  1267. # filter_map_str = "{\"instanceStatus\":\"topoModifying\"}"
  1268. :param days_to_expiration:
  1269. Deadline, default to -1
  1270. :type days_to_expiration: int
  1271. :param config:
  1272. :type config: baidubce.BceClientConfiguration
  1273. :return:
  1274. """
  1275. params = {b"manner": b"page"}
  1276. if order is not None:
  1277. params[b"order"] = order
  1278. if order_by is not None:
  1279. params[b"orderBy"] = order_by
  1280. if page_no is not None:
  1281. params[b"pageNo"] = page_no
  1282. if page_size is not None:
  1283. params[b"pageSize"] = page_size
  1284. if filter_map_str is not None:
  1285. params[b"filterMapStr"] = filter_map_str
  1286. if days_to_expiration is not None:
  1287. params[b"daysToExpiration"] = days_to_expiration
  1288. return self._send_request(http_method=http_methods.GET,
  1289. path=b'/instance/group',
  1290. params=params, config=config)
  1291. def detail_group(self, group_id, config=None):
  1292. """
  1293. Query details of hot instance groups
  1294. :param group_id:
  1295. ID of the hot instance group
  1296. :type group_id: str
  1297. :param config:
  1298. :type config: baidubce.BceClientConfiguration
  1299. :return:json str
  1300. :GroupDetailResponse
  1301. """
  1302. path = b'/instance/group/{groupId}'
  1303. formatted_url = path.decode().format(groupId=group_id).encode()
  1304. return self._send_request(http_method=http_methods.GET,
  1305. path=formatted_url,
  1306. config=config)
  1307. def check_gtid_group(self, instance_id, config=None):
  1308. """
  1309. This interface is used for instance group pre-check (GTID check).
  1310. :param instance_id:
  1311. the Specifies the instance ID
  1312. :type instance_id: str
  1313. :param config:config
  1314. :type config: baidubce.BceClientConfiguration
  1315. :return result: true or false
  1316. :rtype result: rds_hot_active_instance_group_model.GroupCheckGtidResponse
  1317. """
  1318. data = {
  1319. "instanceId": instance_id
  1320. }
  1321. headers = {b'Content-Type': b'application/json'}
  1322. return self._send_request(http_method=http_methods.POST,
  1323. path=b'/instance/group/checkGtid',
  1324. headers=headers,
  1325. body=json.dumps(data),
  1326. config=config)
  1327. def check_ping_group(self, source_id, target_id, config=None):
  1328. """
  1329. This interface is used for instance group pre-check
  1330. (instance connectivity check). The region of the
  1331. current request must be the same as the region
  1332. where the sourceId resides.
  1333. :param source_id:
  1334. Source instance id
  1335. :type source_id: str
  1336. :param target_id:
  1337. Target instance id
  1338. :type source_id: str
  1339. :param config: config
  1340. :type config: baidubce.BceClientConfiguration
  1341. :return result: true or false
  1342. :rtype result: rds_hot_active_instance_group_model.GroupCheckPingResponse
  1343. """
  1344. data = {
  1345. "sourceId": source_id,
  1346. "targetId": target_id
  1347. }
  1348. headers = {b'Content-Type': b'application/json'}
  1349. return self._send_request(http_method=http_methods.POST,
  1350. path=b'/instance/group/checkPing',
  1351. headers=headers,
  1352. body=json.dumps(data),
  1353. config=config)
  1354. def check_data_group(self, instance_id, config=None):
  1355. """
  1356. this interface is used for instance group pre-check
  1357. (data check). The region of the incoming instance
  1358. instanceId must be the same as that of the current
  1359. request.
  1360. :param instance_id:
  1361. the Specifies the instance ID
  1362. :type instance_id: str
  1363. :param config: config
  1364. :type config: baidubce.BceClientConfiguration
  1365. :return result : true or false
  1366. :rtype result: rds_hot_active_instance_group_model.GroupCheckDataResponse
  1367. """
  1368. data = {
  1369. "instanceId": instance_id
  1370. }
  1371. headers = {b'Content-Type': b'application/json'}
  1372. return self._send_request(http_method=http_methods.POST,
  1373. path=b'/instance/group/checkData',
  1374. headers=headers,
  1375. body=json.dumps(data),
  1376. config=config)
  1377. def add_instance_to_group(self, group_id, follower_id, config=None):
  1378. """
  1379. adding an instance group refers to adding an existing
  1380. instance group. The instance to be added cannot be
  1381. an existing hot live instance group
  1382. :param group_id:
  1383. The Specify the ID of the created Heat instance group
  1384. :type group_id: str
  1385. :param follower_id:
  1386. The ID of the instance to be added
  1387. :type follower_id: str
  1388. :param config:config
  1389. :type config: baidubce.BceClientConfiguration
  1390. :return result:true or false
  1391. :rtype result :bool
  1392. """
  1393. data = {
  1394. "followerId": follower_id
  1395. }
  1396. path=b'/instance/group/{groupId}/instance'
  1397. formatted_url = path.decode().format(groupId=group_id).encode()
  1398. headers = {b'Content-Type': b'application/json'}
  1399. return self._send_request(http_method=http_methods.POST,
  1400. path=formatted_url,
  1401. body=json.dumps(data),
  1402. headers=headers,
  1403. config=config)
  1404. def modify_instances_group_name(self, group_id, group_name, config=None):
  1405. """
  1406. modify instances group name
  1407. :param group_id:
  1408. The Specifies the ID of the hot instance group
  1409. :type group_id: str
  1410. :param group_name:
  1411. Name of the Heat instance group that you want to modify
  1412. :type group_name: str
  1413. :param config: config
  1414. :type config: baidubce.BceClientConfiguration
  1415. :return:
  1416. """
  1417. data = {
  1418. "name": group_name
  1419. }
  1420. path = b'/instance/group/{groupId}/name'
  1421. formatted_url = path.decode().format(groupId=group_id).encode()
  1422. headers = {b'Content-Type': b'application/json'}
  1423. return self._send_request(http_method=http_methods.POST,
  1424. path=formatted_url,
  1425. body=json.dumps(data),
  1426. headers=headers,
  1427. config=config)
  1428. def delete_instances_group(self, group_id, config=None):
  1429. """
  1430. delete a specified instance group. Only one leader instance can be deleted
  1431. :param group_id:
  1432. id of the instance group to be deleted
  1433. :type group_id: str
  1434. :param config: config
  1435. :type config: baidubce.BceClientConfiguration
  1436. :return:
  1437. """
  1438. path=b'/instance/group/{groupId}'
  1439. formatted_url = path.decode().format(groupId=group_id).encode()
  1440. return self._send_request(http_method=http_methods.DELETE,
  1441. path=formatted_url,
  1442. config=config)
  1443. def master_role_change(self, group_id, leader_id, config=None):
  1444. """
  1445. To switch the instance of the instance group to the primary role
  1446. :param group_id:
  1447. The Specifies the ID of the hot instance group
  1448. : type group_id: str
  1449. :param leader_id:
  1450. Switch the instance of the master role
  1451. :type leader_id: str
  1452. :param config: config
  1453. :type config: baidubce.BceClientConfiguration
  1454. :return:
  1455. :rtype:
  1456. """
  1457. data = {
  1458. "leaderId": leader_id
  1459. }
  1460. path=b'/instance/group/{groupId}/instance'
  1461. formatted_url = path.decode().format(groupId=group_id).encode()
  1462. headers = {b'Content-Type': b'application/json'}
  1463. return self._send_request(http_method=http_methods.PUT,
  1464. path=formatted_url,
  1465. body=json.dumps(data),
  1466. headers=headers,
  1467. config=config)
  1468. def quit_instances_group(self, group_id, instance_id, config=None):
  1469. """
  1470. To exit the hot instance group, the region of the incoming
  1471. instance instanceId must be the same as that of the current
  1472. request
  1473. :param group_id:
  1474. id of the group from which you want to exit the
  1475. hot instance group
  1476. :type group_id: str
  1477. :param instance_id:
  1478. id of the hot instance group from which you want
  1479. to exit
  1480. :type instance_id: str
  1481. :param config: config
  1482. :type config: baidubce.BceClientConfiguration
  1483. :return:
  1484. :rtype:
  1485. """
  1486. path=b'/instance/group/{groupId}/instance/{instanceId}'
  1487. formatted_url = path.decode().format(groupId=group_id, instanceId=instance_id).encode()
  1488. return self._send_request(http_method=http_methods.DELETE,
  1489. path=formatted_url,
  1490. config=config)
  1491. def check_min_version(self, leader_id, follower_id, config=None):
  1492. """
  1493. pre-check the minor version of the instance added to the
  1494. hot live group
  1495. :param leader_id:
  1496. The specifies the id of the leader instance
  1497. :type leader_id: str
  1498. :param follower_id:
  1499. The specifies the follower instance id
  1500. :type follower_id: str
  1501. :param config:config
  1502. :type config: baidubce.BceClientConfiguration
  1503. :return result: true or false
  1504. :rtype result: bool
  1505. """
  1506. data = {
  1507. "leaderId": leader_id,
  1508. "followerId": follower_id
  1509. }
  1510. headers = {b'Content-Type': b'application/json'}
  1511. return self._send_request(http_method=http_methods.POST,
  1512. path=b'/instance/group/checkVersion',
  1513. headers=headers,
  1514. body=json.dumps(data),
  1515. config=config)
  1516. # 5. log manager
  1517. @required(instance_id=(str))
  1518. def slow_log_detail(self, instance_id, start_time=None, end_time=None, page_no=None, page_size=None,
  1519. db_name=None, host_ip=None, user_name=None, sql=None, config=None):
  1520. """
  1521. get slow log detail
  1522. :param instance_id:
  1523. id of the slow log instance
  1524. :type instance_id: str
  1525. :param start_time:
  1526. Slow log start time. The format is yyyy-mm-ddThh:mm:ssZ,
  1527. for example,2014-07-30T15:06:00Z.
  1528. :type start_time: str
  1529. :param end_time:
  1530. Slow log end time. The format is yyyy-mm-ddThh:mm:ssZ,
  1531. for example,2014-08-20T18:06:00Z.
  1532. :type end_time: str
  1533. :param page_no:
  1534. Current page count, not from the first page
  1535. :type page_no: int
  1536. :param page_size:
  1537. Number of items per page. 10 items per page is recommended
  1538. :type page_size: int
  1539. :param db_name: database name list
  1540. :type db_name: list
  1541. :param host_ip: ip address list(ipv4)
  1542. :type host_ip: list
  1543. :param user_name: username list
  1544. :type user_name: list
  1545. :param sql: sql statement
  1546. :type sql: str
  1547. :param config:
  1548. :return:
  1549. """
  1550. data = {}
  1551. if start_time is not None:
  1552. data['startTime'] = start_time
  1553. if end_time is not None:
  1554. data['endTime'] = end_time
  1555. if page_no is not None:
  1556. data['pageNo'] = page_no
  1557. if page_size is not None:
  1558. data['pageSize'] = page_size
  1559. if db_name is not None:
  1560. data['dbName'] = db_name
  1561. if host_ip is not None:
  1562. data['hostIp'] = host_ip
  1563. if user_name is not None:
  1564. data['userName'] = user_name
  1565. if sql is not None:
  1566. data['sql'] = sql
  1567. path=b'/instance/{instanceId}/slowlogs/details'
  1568. formatted_url = path.decode().format(instanceId=instance_id).encode()
  1569. headers = {b'Content-Type': b'application/json'}
  1570. return self._send_request(http_method=http_methods.POST,
  1571. path=formatted_url,
  1572. headers=headers,
  1573. body=json.dumps(data),
  1574. config=config)
  1575. @required(instance_id=(str))
  1576. def error_log_detail(self, instance_id, start_time=None, end_time=None, page_no=None, page_size=None,
  1577. key_word=None, config=None):
  1578. """
  1579. get error log detail
  1580. :param instance_id:
  1581. id of the slow log instance
  1582. :type instance_id: str
  1583. :param start_time:
  1584. Error log start time. The format is yyyy-mm-ddThh:mm:ssZ,
  1585. for example,2014-07-30T15:06:00Z.
  1586. :type start_time: str
  1587. :param end_time:
  1588. Error log end time. The format is yyyy-mm-ddThh:mm:ssZ,
  1589. for example,2014-07-30T15:06:00Z.
  1590. :type end_time: str
  1591. :param page_no:
  1592. Current page count, not from the first page
  1593. :type page_no: int
  1594. :param page_size:
  1595. Number of items per page. 10 items per page is recommended
  1596. :type page_size: int
  1597. :param key_word:
  1598. Search keywords
  1599. :type key_word: str
  1600. :param config:
  1601. :type config: baidubce.BceClientConfiguration
  1602. :return:
  1603. :rtype: baidubce.services.rds.model.ErrorLogDetail
  1604. """
  1605. data = {}
  1606. if start_time is not None:
  1607. data['startTime'] = start_time
  1608. if end_time is not None:
  1609. data['endTime'] = end_time
  1610. if page_no is not None:
  1611. data['pageNo'] = page_no
  1612. if page_size is not None:
  1613. data['pageSize'] = page_size
  1614. if key_word is not None:
  1615. data['keyWord'] = key_word
  1616. path=b'/instance/{instanceId}/errorlogs/details'
  1617. formatted_url = path.decode().format(instanceId=instance_id).encode()
  1618. headers = {b'Content-Type': b'application/json'}
  1619. return self._send_request(http_method=http_methods.POST,
  1620. path=formatted_url,
  1621. body=json.dumps(data),
  1622. headers=headers,
  1623. config=config)
  1624. @required(instance_id=(str), log_id=(str), download_valid_time_in_sec=(int))
  1625. def slow_log_download_detail(self, instance_id, log_id, download_valid_time_in_sec, config=None):
  1626. """
  1627. slow log download detail
  1628. :param instance_id:
  1629. The specify instance id
  1630. :type instance_id: str
  1631. :param log_id:
  1632. The slow log id
  1633. :param download_valid_time_in_sec: 1800
  1634. :type download_valid_time_in_sec: int
  1635. :param config:
  1636. :type config: baidubce.BceClientConfiguration
  1637. :return:
  1638. """
  1639. path = b'/instance/{instanceId}/slowlogs/download_url/{logId}/{downloadValidTimeInSec}'
  1640. formatted_url = path.decode().format(instanceId=instance_id, logId=log_id,
  1641. downloadValidTimeInSec=download_valid_time_in_sec).encode()
  1642. return self._send_request(http_method=http_methods.GET,
  1643. path=formatted_url,
  1644. config=config)
  1645. @required(instance_id=(str), log_id=(str), download_valid_time_in_sec=(str))
  1646. def error_log_download_detail(self, instance_id, log_id, download_valid_time_in_sec, config=None):
  1647. """
  1648. error log download detail
  1649. :param instance_id:
  1650. The specify instance id
  1651. :type instance_id: str
  1652. :param log_id:
  1653. The error log id
  1654. :type log_id: str
  1655. :param download_valid_time_in_sec: 1800
  1656. :type download_valid_time_in_sec: str
  1657. :param config:
  1658. :type config: baidubce.BceClientConfiguration
  1659. :return:
  1660. :type: baidubce.services.rds.model.DownLoadDetail
  1661. """
  1662. path=b'/instance/{instanceId}/errorlogs/download_url/{logId}/{downloadValidTimeInSec}'
  1663. formatted_url = path.decode().format(instanceId=instance_id, logId=log_id,
  1664. downloadValidTimeInSec=download_valid_time_in_sec).encode()
  1665. return self._send_request(http_method=http_methods.GET,
  1666. path=formatted_url,
  1667. config=config)
  1668. # 6.recycle manager
  1669. def recycler_list(self, marker=None, max_keys=None, config=None):
  1670. """
  1671. Get instances recycler list
  1672. :param marker: Find the instance id in the recycle bin list
  1673. :type marker: str or None
  1674. :param max_keys: the current number
  1675. :type max_keys: int or None
  1676. :param config:
  1677. :type config: baidubce.BceClientConfiguration
  1678. :return:
  1679. """
  1680. params = {}
  1681. if marker is not None:
  1682. params[b'marker'] = marker
  1683. if max_keys is not None:
  1684. params[b'maxKeys'] = max_keys
  1685. return self._send_request(http_methods.GET,
  1686. path=b'/instance/recycler/list',
  1687. params=params,
  1688. config=config)
  1689. @required(instance_ids=list)
  1690. def recycler_recover(self, instance_ids, config=None):
  1691. """
  1692. Get instances recycler recover
  1693. :param instance_ids:
  1694. List of instance ids in the recycle bin
  1695. :type instance_ids: list
  1696. :param config:
  1697. :type config: baidubce.BceClientConfiguration
  1698. :return:
  1699. """
  1700. data = {
  1701. 'instanceIds': instance_ids
  1702. }
  1703. headers={b'Content-Type': b'application/json'}
  1704. return self._send_request(http_method=http_methods.PUT,
  1705. path=b'/instance/recycler/recover',
  1706. body=json.dumps(data),
  1707. headers=headers,
  1708. config=config)
  1709. @required(instance_id=(str))
  1710. def delete_recycler(self, instance_id, config=None):
  1711. """
  1712. Delete the instance from the recycle bin
  1713. :param instance_id: the instance id in recycle bin
  1714. :type instance_id: str
  1715. :param config:
  1716. :type config: baidubce.BceClientConfiguration
  1717. :return:
  1718. """
  1719. path=b'/instance/recycler/{instanceId}'
  1720. formatted_url = path.decode().format(instanceId=instance_id).encode()
  1721. return self._send_request(http_method=http_methods.DELETE,
  1722. path=formatted_url,
  1723. config=config)
  1724. # 7.task manager
  1725. def task_instance(self, page_size=None, page_no=None, end_time=None, instance_id=None,
  1726. instance_name=None, task_id=None, task_type=None, task_status=None,
  1727. start_time=None, config=None):
  1728. """
  1729. task list
  1730. :param instance_id: the specified instance id
  1731. :type instance_id: string
  1732. :param page_size: the number of items per page
  1733. :type page_size: int or None
  1734. :param page_no: the current page no
  1735. :type page_no: int or None
  1736. :param end_time: the task executor end time
  1737. :type end_time: string or None
  1738. :param instance_name: the specified instance name
  1739. :type instance_name: string or None
  1740. :param task_id: the specified task id
  1741. :type task_id: string or None
  1742. :param task_type: Task type, value: resize/switch/reboot/changeAzone
  1743. :type task_type: string or None
  1744. :param task_status: Task status, value, created/running/success/failed/cancelled
  1745. :type task_status: string or None
  1746. :param start_time: Task executor start time
  1747. :type start_time: string or None
  1748. :param config:
  1749. :return:
  1750. """
  1751. data = {}
  1752. if page_no is not None:
  1753. data['pageNo'] = page_no
  1754. if page_size is not None:
  1755. data['pageSize'] = page_size
  1756. if end_time is not None:
  1757. data['endTime'] = end_time
  1758. if instance_id is not None:
  1759. data['instanceId'] = instance_id
  1760. if instance_name is not None:
  1761. data['instanceName'] = instance_name
  1762. if task_id is not None:
  1763. data['taskId'] = task_id
  1764. if task_type is not None:
  1765. data['taskType'] = task_type
  1766. if task_status is not None:
  1767. data['taskStatus'] = task_status
  1768. if start_time is not None:
  1769. data['startTime'] = start_time
  1770. headers = {b'Content-Type': b'application/json'}
  1771. return self._send_request(http_method=http_methods.POST,
  1772. path=b'/instance/task',
  1773. headers=headers,
  1774. body=json.dumps(data),
  1775. config=config)
  1776. # 8.param manager
  1777. @required(instance_id=str)
  1778. def parameter_list(self, instance_id, keyword=None, config=None):
  1779. """
  1780. Gets a list of parameters for the specified instance
  1781. :param instance_id:
  1782. the specified instance id
  1783. :type instance_id: str
  1784. :param keyword:
  1785. the keyword of parameter
  1786. :type keyword: str or None
  1787. :param config: config
  1788. :type config: baidubce.BceClientConfiguration
  1789. :return:
  1790. """
  1791. path=b'/instance/{instanceId}/parameter'
  1792. formatted_url = path.decode().format(instanceId=instance_id).encode()
  1793. return self._send_request(http_method=http_methods.GET,
  1794. path=formatted_url,
  1795. params={'keyword': keyword},
  1796. config=config)
  1797. @required(instance_id=(str), e_tag=(str), effective_time=(str), parameters=(list))
  1798. def modify_config_parameter(self, instance_id, e_tag, effective_time, parameters,
  1799. config=None):
  1800. """
  1801. Modifying config parameters for the specified instance
  1802. :param instance_id:
  1803. The specified instance id
  1804. :type instance_id: str
  1805. :param e_tag:
  1806. The new version, for example, v1,
  1807. is obtained from the details list
  1808. :type e_tag: str
  1809. :param effective_time:
  1810. Actual validity mode: immediate or
  1811. maintenance time (timewindow)
  1812. :type effective_time: str
  1813. :param parameters:
  1814. Parameter list to be modified
  1815. :type parameters: list
  1816. :param config: config
  1817. :type config: baidubce.BceClientConfiguration
  1818. :return:
  1819. """
  1820. headers = {b'Content-Type': b'application/json', b'x-bce-if-match': e_tag}
  1821. data = {
  1822. "effectiveTime": effective_time,
  1823. "parameters": parameters
  1824. }
  1825. path=b'/instance/{instanceId}/parameter'
  1826. formatted_url = path.decode().format(instanceId=instance_id).encode()
  1827. return self._send_request(http_method=http_methods.PUT,
  1828. path=formatted_url,
  1829. body=json.dumps(data),
  1830. headers=headers,
  1831. config=config)
  1832. @required(instance_id=(str))
  1833. def query_modify_parameter_history_List(self, instance_id, config=None):
  1834. """
  1835. query modify parameter history list
  1836. :param instance_id:
  1837. The specified instance id
  1838. :type instance_id: str
  1839. :param config: config
  1840. :type config: baidubce.BceClientConfiguration
  1841. :return:
  1842. """
  1843. path=b'/instance/{instanceId}/parameter/history'
  1844. formatted_url = path.decode().format(instanceId=instance_id).encode()
  1845. return self._send_request(http_method=http_methods.GET,
  1846. path=formatted_url,
  1847. config=config)
  1848. def query_parameter_template_list(self, page_no=None, page_size=None, template_type=None,
  1849. db_type=None, db_version=None, config=None):
  1850. """
  1851. query parameter template
  1852. :param page_no:
  1853. The current page number,default is 1
  1854. :type page_no: int
  1855. :param page_size:
  1856. The number of records per page,default is 10
  1857. :type page_no: int
  1858. :param template_type:
  1859. The template type can be user or system.
  1860. The default value is user. user: Returns
  1861. a list of custom parameters. system:
  1862. Returns the system parameter list.
  1863. :type template_type: string
  1864. :param db_type:
  1865. Tthe Database type
  1866. :type db_type: string
  1867. :param db_version:
  1868. The Database version
  1869. :type db_version: string
  1870. :param config:
  1871. :type config: baidubce.BceClientConfiguration
  1872. :return:
  1873. """
  1874. params = {}
  1875. if page_no is not None:
  1876. params['pageNo'] = page_no
  1877. if page_size is not None:
  1878. params['pageSize'] = page_size
  1879. if template_type is not None:
  1880. params['type'] = template_type
  1881. if db_type is not None:
  1882. params['dbType'] = db_type
  1883. if db_version is not None:
  1884. params['dbVersion'] = db_version
  1885. return self._send_request(http_method=http_methods.GET,
  1886. path=b'/instance/paraTemplate',
  1887. params=params,
  1888. config=config)
  1889. @required(template_id=(str))
  1890. def query_parameter_template_detail(self, template_id, config=None):
  1891. """
  1892. query parameter template detail
  1893. :param template_id:
  1894. The id of parameter template
  1895. :type template_id: str
  1896. :param config:
  1897. :type config: baidubce.BceClientConfiguration
  1898. :return:
  1899. """
  1900. path=b'/instance/paraTemplate/template/detail/{templateId}'
  1901. formatted_url = path.decode().format(templateId=template_id).encode()
  1902. return self._send_request(http_method=http_methods.GET,
  1903. path=formatted_url,
  1904. config=config)
  1905. @required(template_id=(str), name=(str), desc=(str))
  1906. def copy_parameter_template(self, template_id, name, desc, config=None):
  1907. """
  1908. copy parameter template
  1909. :param name:
  1910. The name of parameter template
  1911. :type name: str
  1912. :param desc:
  1913. The description of parameter template
  1914. :type desc: str
  1915. :param template_id:
  1916. The id of parameter template
  1917. :type template_id: str
  1918. :param config:
  1919. :type config: baidubce.BceClientConfiguration
  1920. :return:
  1921. """
  1922. data = {
  1923. 'name': name,
  1924. 'desc': desc,
  1925. "templateId": template_id
  1926. }
  1927. headers = {b'Content-Type': b'application/json'}
  1928. return self._send_request(http_method=http_methods.POST,
  1929. path=b'/instance/paraTemplate/duplicate/template',
  1930. headers=headers,
  1931. body=json.dumps(data),
  1932. config=config)
  1933. # security manager
  1934. @required(instance_id=(str))
  1935. def get_white_list(self, instance_id, config=None):
  1936. """
  1937. query whit list
  1938. :param instance_id: the specified instance id
  1939. :type instance_id: str
  1940. :param config:
  1941. :type config: baidubce.BceClientConfiguration
  1942. :return:
  1943. """
  1944. path=b'/instance/{instanceId}/securityIp'
  1945. formatted_url = path.decode().format(instanceId=instance_id).encode()
  1946. return self._send_request(http_method=http_methods.GET,
  1947. path=formatted_url,
  1948. config=config)
  1949. @required(instance_id=(str), security_ips=(list), e_tag=(str))
  1950. def update_white_list(self, instance_id, security_ips, e_tag, config=None):
  1951. """
  1952. update whit list
  1953. :param instance_id: the specified instance id
  1954. :type instance_id: str
  1955. :param security_ips:
  1956. Set the IP addresses of the whitelist, separated by commas (,)
  1957. for example: [ "xx.xx.xx.xx","xx.xx.xx.xx" ]
  1958. :type security_ips: list
  1959. :param e_tag:
  1960. The ETag value is obtained by querying the interface
  1961. :type e_tag: str
  1962. :param config:
  1963. :type config: baidubce.BceClientConfiguration
  1964. :return:
  1965. """
  1966. path=b'/instance/{instanceId}/securityIp'
  1967. formatted_url = path.decode().format(instanceId=instance_id).encode()
  1968. data = {"securityIps": security_ips}
  1969. headers = {b'Content-Type': b'application/json', b'x-bce-if-match': e_tag}
  1970. return self._send_request(http_method=http_methods.PUT,
  1971. path=formatted_url,
  1972. headers=headers,
  1973. body=json.dumps(data),
  1974. config=config)
  1975. @required(instance_id=(str))
  1976. def get_ssl_status(self, instance_id, config=None):
  1977. """
  1978. Enable and disable ssl
  1979. :param instance_id:
  1980. the specified instance id
  1981. :type instance_id: str
  1982. :param config:
  1983. :type config: baidubce.BceClientConfiguration
  1984. :return:
  1985. """
  1986. path=b'/instance/ssl/{instanceId}'
  1987. formatted_url = path.decode().format(instanceId=instance_id).encode()
  1988. return self._send_request(http_method=http_methods.GET,
  1989. path=formatted_url,
  1990. config=config)
  1991. def obtain_ssl_ca(self, config=None):
  1992. """
  1993. Obtaining a ca Certificate
  1994. :param config:
  1995. :type config: baidubce.BceClientConfiguration
  1996. :return:
  1997. """
  1998. return self._send_request(http_method=http_methods.GET,
  1999. path=b'/instance/ssl/static/ca',
  2000. config=config)
  2001. # read only manager
  2002. @required(instance_id=(str), vpc_id=(str), subnet_id=(str))
  2003. def create_readonly_group(self, instance_id, vpc_id, subnet_id, ro_group_name=None,
  2004. enable_delay_off=None, least_app_amount=None,
  2005. balance_reload=None, bgw_group_exclusive=None,
  2006. bgw_groupId=None, entry_port=None, vnet_ip=None,
  2007. delay_threshold=None, config=None):
  2008. """
  2009. create readonly group
  2010. :param instance_id:
  2011. the specified instance id
  2012. :type instance_id: str
  2013. :param vpc_id:
  2014. the specified vpc id
  2015. :type vpc_id: str
  2016. :param subnet_id:
  2017. the specified subnet id
  2018. :type subnet_id: str
  2019. :param ro_group_name:
  2020. the created ro group name
  2021. :type ro_group_name: str or None
  2022. :param enable_delay_off:
  2023. Whether to enable deferred culling.
  2024. The default value is off. When enabled,
  2025. read-only instances in a group that experience
  2026. latency and reach a threshold are removed from
  2027. the group if the minimum number of retained instances is met
  2028. :type enable_delay_off: bool(True/False) or None
  2029. :param least_app_amount:
  2030. Minimum number of reserved instances in a group.
  2031. The value is an integer ranging from 0 to 5. Default is 1
  2032. :type least_app_amount: int or None
  2033. :param balance_reload:
  2034. Whether to enable the reload balancing switch.
  2035. The default value is disabled. After this function
  2036. is enabled, old connections are disconnected when
  2037. the weight of read-only instances in a group is changed
  2038. :type balance_reload: bool(True/False)
  2039. :param bgw_group_exclusive:
  2040. The value is assigned to a shared cluster or a dedicated
  2041. cluster. The default value is false
  2042. :type bgw_group_exclusive: bool(True/False) or None
  2043. :param bgw_groupId:
  2044. Cluster ID, if passed, to which cluster to assign the blb;
  2045. If no dedicated cluster is transmitted, use the dedicated
  2046. cluster with the least default configuration.
  2047. If no dedicated cluster is transmitted, use the shared
  2048. cluster with the least default configuration.
  2049. :type bgw_groupId: str or None
  2050. :param entry_port:
  2051. Service port. The default value MySQL is 3306
  2052. :type entry_port: int or None
  2053. :param vnet_ip:
  2054. The IP address of the virtual network, for example 10.254.38.96
  2055. :type vnet_ip: str or None
  2056. :param delay_threshold:
  2057. The value is an integer greater than or equal to 0. Default is 10
  2058. :type delay_threshold: int or None
  2059. :param config:
  2060. :type config: baidubce.BceClientConfiguration or None
  2061. :return:
  2062. """
  2063. data = {"vpcId": vpc_id, "subnetId": subnet_id}
  2064. if ro_group_name is not None:
  2065. data["roGroupName"] = ro_group_name
  2066. if enable_delay_off is not None:
  2067. data["enableDelayOff"] = enable_delay_off
  2068. if bgw_groupId is not None:
  2069. data["bgwGroupId"] = bgw_groupId
  2070. if entry_port is not None:
  2071. data["entryPort"] = int(entry_port)
  2072. if vnet_ip is not None:
  2073. data["vnetIp"] = vnet_ip
  2074. if least_app_amount is None:
  2075. data["leastAppAmount"] = 1
  2076. else:
  2077. data["leastAppAmount"] = int(least_app_amount)
  2078. if bgw_group_exclusive is None:
  2079. data["bgwGroupExclusive"] = False
  2080. else:
  2081. data["bgwGroupExclusive"] = bgw_group_exclusive
  2082. if delay_threshold is None:
  2083. data["delayThreshold"] = 10
  2084. else:
  2085. data["delayThreshold"] = int(delay_threshold)
  2086. if balance_reload is None:
  2087. data["balanceReload"] = False
  2088. else:
  2089. data["balanceReload"] = bool(balance_reload)
  2090. path = b'/rds/{sourceAppId}/rogroup'
  2091. formatted_url = path.decode().format(sourceAppId=instance_id).encode()
  2092. headers = {b'Content-Type': b'application/json'}
  2093. return self._send_request(http_method=http_methods.POST,
  2094. path=formatted_url,
  2095. body=json.dumps(data),
  2096. headers=headers,
  2097. config=config)
  2098. @required(instance_id=(str), ro_group_id=(str))
  2099. def readonly_group_detail(self, instance_id, ro_group_id, config=None):
  2100. """
  2101. get readonly group detail
  2102. :param instance_id:
  2103. the specified instance id
  2104. :type instance_id: str
  2105. :param ro_group_id:
  2106. the specified ro group id
  2107. :type ro_group_id: str
  2108. :param config:
  2109. :type config: baidubce.BceClientConfiguration
  2110. :return:
  2111. """
  2112. path = b'/rds/{sourceAppId}/rogroup/detail/{roGroupId}'
  2113. formatted_url = path.decode().format(sourceAppId=instance_id, roGroupId=ro_group_id).encode()
  2114. return self._send_request(http_method=http_methods.GET,
  2115. path=formatted_url,
  2116. config=config)
  2117. @required(instance_id=(str))
  2118. def master_instance_associated_readonly_List(self, instance_id, config=None):
  2119. """
  2120. Displays the list of read-only groups associated
  2121. with the primary instance.
  2122. :param instance_id:
  2123. the specified instance id
  2124. :type instance_id: str
  2125. :param config:
  2126. :type config: baidubce.BceClientConfiguration
  2127. @return:
  2128. """
  2129. path = b'/rds/{sourceAppId}/rogroup/list'
  2130. formatted_url = path.decode().format(sourceAppId=instance_id).encode()
  2131. headers = {b'Content-Type': b'application/json'}
  2132. return self._send_request(http_method=http_methods.GET,
  2133. path=formatted_url,
  2134. config=config)
  2135. @required(instance_id=(str), ro_group_id=(str), read_replica_list=(list))
  2136. def join_readonly_group(self, instance_id, ro_group_id, read_replica_list, config=None):
  2137. """
  2138. You can add read-only instances to a read-only group
  2139. individually or add a maximum of four word read groups in a batch.
  2140. :param instance_id:
  2141. the specified source isntance id
  2142. :type instance_id: str
  2143. :param ro_group_id:
  2144. the specified ro group id
  2145. :type ro_group_id: str
  2146. :param read_replica_list:
  2147. the specified read replica list include more read app
  2148. :type read_replica_list: list
  2149. :param config:
  2150. :type config: baidubce.BceClientConfiguration
  2151. :return:
  2152. """
  2153. data = {"readReplicaList": read_replica_list}
  2154. path = b'/rds/{sourceAppId}/rogroup/{roGroupId}/join'
  2155. formatted_url = path.decode().format(sourceAppId=instance_id, roGroupId=ro_group_id).encode()
  2156. headers = {b'Content-Type': b'application/json'}
  2157. self._send_request(http_method=http_methods.PUT,
  2158. path=formatted_url,
  2159. headers=headers,
  2160. body=json.dumps(data),
  2161. config=config)
  2162. @required(instance_id=(str), ro_group_id=(str))
  2163. def readonly_group_load_balance(self, source_app_id, ro_group_id, config=None):
  2164. """
  2165. Load balancing is restarted for the read-only group
  2166. :param source_app_id:
  2167. The specified source isntance id
  2168. :type source_app_id: str
  2169. :param ro_group_id:
  2170. The specified ro group id
  2171. :type ro_group_id: str
  2172. :param config: config
  2173. :type config: baidubce.BceClientConfiguration
  2174. :return:
  2175. """
  2176. path = b'/rds/{sourceAppId}/rogroup/{roGroupId}/reload'
  2177. formatted_url = path.decode().format(sourceAppId=source_app_id, roGroupId=ro_group_id).encode()
  2178. headers = {b'Content-Type': b'application/json'}
  2179. self._send_request(http_method=http_methods.PUT,
  2180. path=formatted_url,
  2181. headers=headers,
  2182. config=config)
  2183. @required(source_app_id=(str), ro_group_id=(str))
  2184. def batch_modify_readonly_group_properties(self, source_app_id, ro_group_id, ro_group_name=None,
  2185. enable_delay_off=None, delay_threshold=None,
  2186. balance_reload=None, least_app_amount=None,
  2187. read_replica_list=None, config=None):
  2188. """
  2189. batch modify readonly group properties
  2190. :param source_app_id:
  2191. The specified source instance id
  2192. :type source_app_id: str
  2193. :param ro_group_id:
  2194. The specified ro group id
  2195. :type ro_group_id: str
  2196. :param ro_group_name:
  2197. Name of the read-only group that you want to change
  2198. :type ro_group_name: str or None
  2199. :param enable_delay_off:
  2200. Delay auto-delete switch of read-only groups,true / false
  2201. :type enable_delay_off: bool or None
  2202. :param delay_threshold:
  2203. Delay threshold. The value must be an integer greater than
  2204. or equal to 0, ranging from 1 to 2147483646
  2205. :type delay_threshold: int or None
  2206. :param balance_reload:
  2207. Re-load balancing switch of the read-only group, true / false
  2208. :type balance_reload: bool or None
  2209. :param least_app_amount:
  2210. Minimum number of reserved instances in a group.
  2211. The value is an integer ranging from 0 to 5. Default is 1
  2212. :type least_app_amount: int or None
  2213. :param read_replica_list:
  2214. List of read-only instances for which you want to change the
  2215. weight Recommended range: 1-100
  2216. :type read_replica_list: list or None
  2217. :param config:
  2218. :type config: baidubce.BceClientConfiguration
  2219. :return:
  2220. """
  2221. data = {}
  2222. if source_app_id is not None:
  2223. data["sourceAppId"] = source_app_id
  2224. if ro_group_id is not None:
  2225. data["roGroupId"] = ro_group_id
  2226. if ro_group_name is not None:
  2227. data["roGroupName"] = ro_group_name
  2228. if enable_delay_off is not None:
  2229. data["enableDelayOff"] = enable_delay_off
  2230. if delay_threshold is not None:
  2231. data["delayThreshold"] = int(delay_threshold)
  2232. if balance_reload is not None:
  2233. data["balanceReload"] = bool(balance_reload)
  2234. if least_app_amount is not None:
  2235. data["leastAppAmount"] = int(least_app_amount)
  2236. if read_replica_list is not None:
  2237. data["readReplicaList"] = read_replica_list
  2238. path = b'/rds/{sourceAppId}/rogroup/{roGroupId}/updateRoGroupProperty'
  2239. formatted_url = path.decode().format(sourceAppId=source_app_id, roGroupId=ro_group_id).encode()
  2240. headers = {b'Content-Type': b'application/json'}
  2241. self._send_request(http_method=http_methods.PUT,
  2242. path=formatted_url,
  2243. body=json.dumps(data),
  2244. headers=headers,
  2245. config=config)
  2246. @required(source_app_id=(str), ro_group_id=(str), publicly_accessible=(bool))
  2247. def update_publicly_accessible(self, source_app_id, ro_group_id, publicly_accessible, config=None):
  2248. """
  2249. Enable or disable a public network
  2250. :param source_app_id:
  2251. The specified source isntance id
  2252. :type source_app_id: str
  2253. :param ro_group_id:
  2254. The specified readonly group id
  2255. :type ro_group_id: str
  2256. :param publicly_accessible:
  2257. ture / false
  2258. :type publicly_accessible: bool
  2259. :param config:
  2260. :type config: baidubce.BceClientConfiguration
  2261. :return:
  2262. """
  2263. data = {"publiclyAccessible": publicly_accessible}
  2264. path = b'/rds/{sourceAppId}/rogroup/{roGroupId}/updatePubliclyAccessible'
  2265. formatted_url = path.decode().format(sourceAppId=source_app_id, roGroupId=ro_group_id).encode()
  2266. headers = {b'Content-Type': b'application/json'}
  2267. self._send_request(http_method=http_methods.PUT,
  2268. path=formatted_url,
  2269. body=json.dumps(data),
  2270. headers=headers,
  2271. config=config)
  2272. @required(source_app_id=(str), ro_group_id=(str))
  2273. def update_endpoint(self, source_app_id, ro_group_id, endpoint, ro_group_name=None,
  2274. least_app_amount=None, delay_threshold=None, config=None):
  2275. """
  2276. update endpoint information
  2277. :param source_app_id:
  2278. The specified source isntance id
  2279. :type source_app_id: str
  2280. :param ro_group_id:
  2281. The specified read-only group id
  2282. :type ro_group_id: str
  2283. :param endpoint:
  2284. The specified endpoint object
  2285. :type endpoint: baidubce.services.rds.request_param.Endpoint
  2286. :param ro_group_name:
  2287. The update readonly group name
  2288. :type ro_group_name: str or None
  2289. :param least_app_amount:
  2290. Change the minimum number of reserved instances in a group
  2291. update ranging from 0 to 5. Default is 1
  2292. :type least_app_amount: int or None
  2293. :param delay_threshold:
  2294. Enable or disable intra-group balance recovery
  2295. :type delay_threshold: int or None
  2296. :param config:
  2297. :type config: baidubce.BceClientConfiguration
  2298. :return:
  2299. """
  2300. data = {"endpoint": endpoint.to_json()}
  2301. if ro_group_name is not None:
  2302. data["roGroupName"] = ro_group_name
  2303. if least_app_amount is not None:
  2304. data["leastAppAmount"] = int(least_app_amount)
  2305. if delay_threshold is not None:
  2306. data["delayThreshold"] = int(delay_threshold)
  2307. path = b'/rds/{sourceAppId}/rogroup/{roGroupId}/updateEndpoint'
  2308. formatted_url = path.decode().format(sourceAppId=source_app_id, roGroupId=ro_group_id).encode()
  2309. headers = {b'Content-Type': b'application/json'}
  2310. self._send_request(http_method=http_methods.PUT,
  2311. path=formatted_url,
  2312. headers=headers,
  2313. body=json.dumps(data),
  2314. config=config)
  2315. @required(source_app_id=(str), ro_group_id=(str), read_replica_list=(list))
  2316. def level_readonly_group(self, source_app_id, ro_group_id, read_replica_list, config=None):
  2317. """
  2318. level readonly group
  2319. :param source_app_id:
  2320. The specified source instance id
  2321. :type source_app_id: str
  2322. :param ro_group_id:
  2323. The level read-only group id
  2324. :type ro_group_id: str
  2325. :param read_replica_list:
  2326. The level read-only group read-only instance list
  2327. :type read_replica_list: list
  2328. :param config: config
  2329. :type config: baidubce.BceClientConfiguration
  2330. :return:
  2331. """
  2332. data = {"readReplicaList": read_replica_list}
  2333. path = b'/rds/{sourceAppId}/rogroup/{roGroupId}/leave'
  2334. formatted_url = path.decode().format(sourceAppId=source_app_id, roGroupId=ro_group_id).encode()
  2335. headers = {b'Content-Type': b'application/json'}
  2336. self._send_request(http_method=http_methods.PUT,
  2337. path=formatted_url,
  2338. headers=headers,
  2339. body=json.dumps(data),
  2340. config=config)
  2341. @required(source_app_id=(str), ro_group_id=(str))
  2342. def delete_readonly_group(self, source_app_id, ro_group_id, config=None):
  2343. """
  2344. delete readonly group
  2345. :param source_app_id:
  2346. The specified source instance id
  2347. :type source_app_id: str
  2348. :param ro_group_id:
  2349. The specified read-only group id
  2350. :type ro_group_id: str
  2351. :param config:
  2352. :type config: baidubce.BceClientConfiguration
  2353. :return:
  2354. """
  2355. path = b'/rds/{sourceAppId}/rogroup/{roGroupId}'
  2356. formatted_url = path.decode().format(sourceAppId=source_app_id, roGroupId=ro_group_id).encode()
  2357. self._send_request(http_method=http_methods.DELETE,
  2358. path=formatted_url,
  2359. config=config)
  2360. def generate_client_token_by_uuid():
  2361. """
  2362. The default method to generate the random string for client_token
  2363. if the optional parameter client_token is not specified by the user.
  2364. :return:
  2365. :rtype string
  2366. """
  2367. return str(uuid.uuid4())
  2368. generate_client_token = generate_client_token_by_uuid