bcc_client.py 293 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911
  1. # -*- coding: utf-8 -*-
  2. # Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  5. # except in compliance with the License. You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software distributed under the
  10. # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  11. # either express or implied. See the License for the specific language governing permissions
  12. # and limitations under the License.
  13. """
  14. This module provides a client class for BCC.
  15. """
  16. from __future__ import unicode_literals
  17. import copy
  18. import json
  19. import logging
  20. import random
  21. import string
  22. import uuid
  23. from baidubce import bce_base_client
  24. from baidubce import compat
  25. from baidubce.auth import bce_v1_signer
  26. from baidubce.http import bce_http_client
  27. from baidubce.http import handler
  28. from baidubce.http import http_methods
  29. from baidubce.services.bcc import bcc_model
  30. from baidubce.utils import aes128_encrypt_16char_key
  31. from baidubce.utils import required
  32. _logger = logging.getLogger(__name__)
  33. FETCH_MODE_SYNC = b"sync"
  34. FETCH_MODE_ASYNC = b"async"
  35. ENCRYPTION_ALGORITHM = "AES256"
  36. default_billing_to_purchase_created = bcc_model.Billing('Postpaid')
  37. default_billing_to_purchase_reserved = bcc_model.Billing()
  38. class BccClient(bce_base_client.BceBaseClient):
  39. """
  40. Bcc base sdk client
  41. """
  42. prefix = b'/v2'
  43. prefix_v3 = b'/v3'
  44. def __init__(self, config=None):
  45. bce_base_client.BceBaseClient.__init__(self, config)
  46. def _merge_config(self, config=None):
  47. if config is None:
  48. return self.config
  49. else:
  50. new_config = copy.copy(self.config)
  51. new_config.merge_non_none_values(config)
  52. return new_config
  53. def _send_request(self, http_method, path,
  54. body=None, headers=None, params=None,
  55. config=None, body_parser=None, 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 = BccClient.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. def _send_action_request(self, http_method, path,
  65. body=None, headers=None, params=None,
  66. config=None, body_parser=None):
  67. config = self._merge_config(config)
  68. if body_parser is None:
  69. body_parser = handler.parse_json
  70. return bce_http_client.send_request(
  71. config, bce_v1_signer.sign, [handler.parse_error, body_parser],
  72. http_method, path, body, headers, params)
  73. @required(cpu_count=int,
  74. memory_capacity_in_gb=int,
  75. image_id=(bytes, str)) # ***Unicode***
  76. def create_instance(self, cpu_count, memory_capacity_in_gb, image_id, instance_type=None,
  77. billing=None, create_cds_list=None, root_disk_size_in_gb=0, root_disk_storage_type=None,
  78. ephemeral_disks=None, dedicate_host_id=None, auto_renew_time_unit=None, auto_renew_time=0,
  79. deploy_id=None, bid_model=None, bid_price=None, key_pair_id=None, cds_auto_renew=False,
  80. internet_charge_type=None, internal_ips=None, request_token=None, asp_id=None, tags=None,
  81. network_capacity_in_mbps=0, purchase_count=1, cardCount=1, name=None, admin_pass=None,
  82. zone_name=None, subnet_id=None, security_group_id=None, gpuCard=None, fpgaCard=None,
  83. spec=None, eip_name=None, hostname=None, auto_seq_suffix=False, is_open_hostname_domain=False,
  84. relation_tag=None, is_open_ipv6=None, enterprise_security_group_id=None,
  85. security_group_ids=None, enterprise_security_group_ids=None, ehc_cluster_id=None,
  86. kunlunCard=None, isomerismCard=None, file_systems=None, user_data=None, is_open_hosteye=False,
  87. deletion_protection=None, res_group_id=None,
  88. client_token=None, config=None, card_count=1, isomerism_card=None, is_keep_image_login=None):
  89. """
  90. Create a bcc Instance with the specified options.
  91. You must fill the field of clientToken,which is especially for keeping idempotent.
  92. This is an asynchronous interface,
  93. you can get the latest status by BccClient.get_instance.
  94. :param instance_type:
  95. The specified Specification to create the instance,
  96. See more detail on
  97. https://cloud.baidu.com/doc/BCC/API.html#InstanceType
  98. :type instance_type: string
  99. :param cpu_count:
  100. The parameter to specified the cpu core to create the instance.
  101. :type cpu_count: int
  102. :param memory_capacity_in_gb:
  103. The parameter to specified the capacity of memory in GB to create the instance.
  104. :type memory_capacity_in_gb: int
  105. :param image_id:
  106. The id of image, list all available image in BccClient.list_images.
  107. :type image_id: string
  108. :param billing:
  109. Billing information.
  110. :type billing: bcc_model.Billing
  111. :param create_cds_list:
  112. The optional list of volume detail info to create.
  113. :type create_cds_list: list<bcc_model.CreateCdsModel>
  114. :param network_capacity_in_mbps:
  115. The optional parameter to specify the bandwidth in Mbps for the new instance.
  116. It must among 0 and 200, default value is 0.
  117. If it's specified to 0, it will get the internal ip address only.
  118. :type network_capacity_in_mbps: int
  119. :param purchase_count:
  120. The number of instance to buy, the default value is 1.
  121. :type purchase_count: int
  122. :param name:
  123. The optional parameter to desc the instance that will be created.
  124. :type name: string
  125. :param admin_pass:
  126. The optional parameter to specify the password for the instance.
  127. If specify the adminPass,the adminPass must be a 8-16 characters String
  128. which must contains letters, numbers and symbols.
  129. The symbols only contains "!@#$%^*()".
  130. The adminPass will be encrypted in AES-128 algorithm
  131. with the substring of the former 16 characters of user SecretKey.
  132. If not specify the adminPass, it will be specified by an random string.
  133. See more detail on
  134. https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
  135. :type admin_pass: string
  136. :param zone_name:
  137. The optional parameter to specify the available zone for the instance.
  138. See more detail through list_zones method
  139. :type zone_name: string
  140. :param subnet_id:
  141. The optional parameter to specify the id of subnet from vpc, optional param
  142. default value is default subnet from default vpc
  143. :type subnet_id: string
  144. :param security_group_id:
  145. The optional parameter to specify the securityGroupId of the instance
  146. vpcId of the securityGroupId must be the same as the vpcId of subnetId
  147. See more detail through listSecurityGroups method
  148. :type security_group_id: string
  149. :param client_token:
  150. An ASCII string whose length is less than 64.
  151. The request will be idempotent if client token is provided.
  152. If the clientToken is not specified by the user,
  153. a random String generated by default algorithm will be used.
  154. See more detail at
  155. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  156. :type client_token: string
  157. :param fpgaCard:
  158. This parameter is obsolete. Use parameter isomerism_card instead.
  159. :type fpgaCard: string
  160. :param gpuCard:
  161. This parameter is obsolete. Use parameter isomerism_card instead.
  162. :type gpuCard: string
  163. :param cardCount:
  164. This parameter is obsolete. Use parameter card_count instead.
  165. :type cardCount: int
  166. :param card_count:
  167. The parameter to specify the card count for creating GPU/FPGA instance.
  168. :type card_count: int
  169. :param root_disk_size_in_gb:
  170. The parameter to specify the root disk size in GB.
  171. The root disk excludes the system disk, available is 40-500GB.
  172. :type root_disk_size_in_gb: int
  173. :param root_disk_storage_type:
  174. The parameter to specify the root disk storage type.
  175. Default use of HP1 cloud disk.
  176. :type root_disk_storage_type: string
  177. :param ephemeral_disks:
  178. The optional list of ephemeral volume detail info to create.
  179. :type ephemeral_disks: list<bcc_model.EphemeralDisk>
  180. :param dedicate_host_id:
  181. The parameter to specify the dedicate host id.
  182. :type dedicate_host_id: string
  183. :param auto_renew_time_unit:
  184. The parameter to specify the unit of the auto renew time.
  185. The auto renew time unit can be "month" or "year".
  186. The default value is "month".
  187. :type auto_renew_time_unit: string
  188. :param auto_renew_time:
  189. The parameter to specify the auto renew time, the default value is 0.
  190. :type auto_renew_time: int
  191. :param tags:
  192. The optional list of tag to be bonded.
  193. :type tags: list<bcc_model.TagModel>
  194. :param deploy_id:
  195. The parameter to specify the id of the deploymentSet.
  196. :type deploy_id: string
  197. :param bid_model:
  198. The parameter to specify the bidding model.
  199. The bidding model can be "market" or "custom".
  200. :type bid_model: string
  201. :param bid_price:
  202. The parameter to specify the bidding price.
  203. When the bid_model is "custom", it works.
  204. :type bid_price: string
  205. :param key_pair_id:
  206. The parameter to specify id of the keypair.
  207. :type key_pair_id: string
  208. :param asp_id:
  209. The parameter to specify id of the asp.
  210. :type asp_id: string
  211. :param request_token:
  212. The parameter to specify the request token which will make the request idempotent.
  213. :type request_token: string
  214. :param internet_charge_type:
  215. The parameter to specify the internet charge type.
  216. See more detail on
  217. https://cloud.baidu.com/doc/BCC/API.html#InternetChargeType
  218. :type internet_charge_type: string
  219. :param internal_ips:
  220. The parameter to specify the internal ips.
  221. :type internal_ips: list<string>
  222. :param cds_auto_renew
  223. The parameter to specify whether the cds is auto renew or not.
  224. The default value is false.
  225. :type cds_auto_renew: boolean
  226. :param spec:
  227. spec
  228. :type spec: string
  229. :param eip_name:
  230. eip name
  231. :type eip_name: string
  232. :param hostname:
  233. The optional parameter to specify the host name of the instance virtual machine.
  234. By default, hostname is not specified.
  235. If hostname is specified: hostname is used as the prefix of the name in batches.
  236. The backend will add a suffix, and the suffix generation method is: name{-serial number}.
  237. If name is not specified, it will be automatically generated using the following method:
  238. {instance-eight-digit random string-serial number}.
  239. Note: The random string is generated from the characters 0-9 and a-z;
  240. the serial number increases sequentially according to the magnitude of count.
  241. If count is 100, the serial number increases from 000~100, and if it is 10, it increases from 00~10.
  242. Only lowercase letters, numbers and - . special characters are supported.
  243. They must start with a letter. Special symbols cannot be used continuously.
  244. Special symbols are not supported at the beginning or end. The length is 2-64.
  245. :type hostname: string
  246. :param auto_seq_suffix:
  247. The parameter to specify whether name and hostname order suffixes are automatically generated
  248. :type auto_seq_suffix: boolean
  249. :param is_open_hostname_domain:
  250. The parameter to specify whether hostname domain is automatically generated
  251. :type is_open_hostname_domain: boolean
  252. :param relation_tag:
  253. The parameter to specify whether the instance related to existing tags
  254. :type relation_tag: boolean
  255. :param is_open_ipv6:
  256. is_open_ipv6
  257. :type is_open_ipv6: boolean
  258. :param enterprise_security_group_id:
  259. enterprise_security_group_id
  260. :type enterprise_security_group_id: string
  261. :param security_group_ids:
  262. security_group_ids
  263. :type security_group_ids: list<string>
  264. :param enterprise_security_group_ids:
  265. enterprise_security_group_ids
  266. :type enterprise_security_group_ids: list<string>
  267. :param ehc_cluster_id:
  268. The id of ehcCluster.
  269. :type ehc_cluster_id: string
  270. :param kunlunCard:
  271. This parameter is obsolete. Use parameter isomerism_card instead.
  272. :type kunlunCard: string
  273. :param isomerismCard:
  274. type of isomerismCard, including kunlunCard, fpgaCard, gpuCard
  275. :type isomerismCard: string
  276. :param isomerism_card:
  277. type of isomerismCard, including kunlunCard, fpgaCard, gpuCard.
  278. :type isomerism_card: string
  279. :param file_systems:
  280. This parameter is obsolete.
  281. :type file_systems:list<bcc_model.FileSystemModel>
  282. :param user_data:
  283. :type user_data: string
  284. :param is_open_hosteye:
  285. :type is_open_hosteye: boolean
  286. :param deletion_protection:
  287. :type deletion_protection: int
  288. :param res_group_id:
  289. The optional parameter to specify the resGroupId of the instance
  290. :type res_group_id: string
  291. :return:
  292. :rtype baidubce.bce_response.BceResponse
  293. """
  294. path = b'/instance'
  295. params = {}
  296. if client_token is None:
  297. params['clientToken'] = generate_client_token()
  298. else:
  299. params['clientToken'] = client_token
  300. if billing is None:
  301. billing = default_billing_to_purchase_created
  302. if card_count == 1 and cardCount > 1:
  303. card_count = cardCount
  304. if isomerism_card is None:
  305. isomerism_card = isomerismCard
  306. body = {
  307. 'cpuCount': cpu_count,
  308. 'memoryCapacityInGB': memory_capacity_in_gb,
  309. 'imageId': image_id,
  310. 'billing': billing.__dict__
  311. }
  312. if spec is not None:
  313. body['spec'] = spec
  314. if eip_name is not None:
  315. body['eipName'] = eip_name
  316. if hostname is not None:
  317. body['hostname'] = hostname
  318. if auto_seq_suffix is not None:
  319. body['autoSeqSuffix'] = auto_seq_suffix
  320. if is_open_hostname_domain is not None:
  321. body['isOpenHostnameDomain'] = is_open_hostname_domain
  322. if relation_tag is not None:
  323. body['relationTag'] = relation_tag
  324. if is_open_ipv6 is not None:
  325. body['isOpenIpv6'] = is_open_ipv6
  326. if file_systems is not None:
  327. file_system_list = [file_system.__dict__ for file_system in file_systems]
  328. body['fileSystems'] = file_system_list
  329. if user_data is not None:
  330. body['userData'] = user_data
  331. if is_open_hosteye is not None:
  332. body['isOpenHosteye'] = is_open_hosteye
  333. if deletion_protection is not None:
  334. body['deletionProtection'] = deletion_protection
  335. if instance_type is not None:
  336. body['instanceType'] = instance_type
  337. if root_disk_size_in_gb != 0:
  338. body['rootDiskSizeInGb'] = root_disk_size_in_gb
  339. if root_disk_storage_type is not None:
  340. body['rootDiskStorageType'] = root_disk_storage_type
  341. if create_cds_list is not None:
  342. body['createCdsList'] = [create_cds.__dict__ for create_cds in create_cds_list]
  343. if network_capacity_in_mbps != 0:
  344. body['networkCapacityInMbps'] = network_capacity_in_mbps
  345. if purchase_count > 0:
  346. body['purchaseCount'] = purchase_count
  347. if name is not None:
  348. body['name'] = name
  349. if admin_pass is not None:
  350. secret_access_key = self.config.credentials.secret_access_key
  351. cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
  352. body['adminPass'] = cipher_admin_pass
  353. if zone_name is not None:
  354. body['zoneName'] = zone_name
  355. if subnet_id is not None:
  356. body['subnetId'] = subnet_id
  357. if security_group_id is not None:
  358. body['securityGroupId'] = security_group_id
  359. if enterprise_security_group_id is not None:
  360. body['enterpriseSecurityGroupId'] = enterprise_security_group_id
  361. if security_group_ids is not None:
  362. body['securityGroupIds'] = security_group_ids
  363. if enterprise_security_group_ids is not None:
  364. body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
  365. if ehc_cluster_id is not None:
  366. body['ehcClusterId'] = ehc_cluster_id
  367. if gpuCard is not None:
  368. body['gpuCard'] = gpuCard
  369. body['cardCount'] = card_count if card_count > 1 else 1
  370. if fpgaCard is not None:
  371. body['fpgaCard'] = fpgaCard
  372. body['cardCount'] = card_count if card_count > 1 else 1
  373. if kunlunCard is not None:
  374. body['kunlunCard'] = kunlunCard
  375. body['cardCount'] = card_count if card_count > 1 else 1
  376. if isomerism_card is not None:
  377. body['isomerismCard'] = isomerism_card
  378. body['cardCount'] = card_count if card_count > 1 else 1
  379. if is_keep_image_login is not None:
  380. body['keepImageLogin'] = is_keep_image_login
  381. if auto_renew_time != 0:
  382. body['autoRenewTime'] = auto_renew_time
  383. if auto_renew_time_unit is None:
  384. body['autoRenewTimeUnit'] = "month"
  385. else:
  386. body['autoRenewTimeUnit'] = auto_renew_time_unit
  387. if ephemeral_disks is not None:
  388. body['ephemeralDisks'] = [ephemeral_disk.__dict__ for ephemeral_disk in ephemeral_disks]
  389. if dedicate_host_id is not None:
  390. body['dedicatedHostId'] = dedicate_host_id
  391. if deploy_id is not None:
  392. body['deployId'] = deploy_id
  393. if bid_model is not None:
  394. body['bidModel'] = bid_model
  395. if bid_price is not None:
  396. body['bidPrice'] = bid_price
  397. if key_pair_id is not None:
  398. body['keypairId'] = key_pair_id
  399. if internet_charge_type is not None:
  400. body['internetChargeType'] = internet_charge_type
  401. if asp_id is not None:
  402. body['aspId'] = asp_id
  403. if request_token is not None:
  404. body['requestToken'] = request_token
  405. if tags is not None:
  406. tag_list = [tag.__dict__ for tag in tags]
  407. body['tags'] = tag_list
  408. if internal_ips is not None:
  409. body['internalIps'] = internal_ips
  410. if res_group_id is not None:
  411. body['resGroupId'] = res_group_id
  412. body['cdsAutoRenew'] = cds_auto_renew
  413. return self._send_request(http_methods.POST, path, json.dumps(body),
  414. params=params, config=config)
  415. @required(cpu_count=int, memory_capacity_in_gb=int, dedicated_host_id=(bytes, str), # ***Unicode***
  416. image_id=(bytes, str)) # ***Unicode***
  417. def create_instance_from_dedicated_host_with_encrypted_password(self, cpu_count, memory_capacity_in_gb, image_id,
  418. dedicated_host_id, ephemeral_disks=None,
  419. purchase_count=1, name=None, admin_pass=None,
  420. subnet_id=None, security_group_id=None,
  421. client_token=None, config=None):
  422. """
  423. Create a Instance from dedicatedHost with the specified options.
  424. You must fill the field of clientToken,which is especially for keeping idempotent.
  425. This is an asynchronous interface,
  426. you can get the latest status by BccClient.get_instance.
  427. :param cpu_count:
  428. The specified number of cpu core to create the instance,
  429. is less than or equal to the remain of dedicated host.
  430. :type cpu_count: int
  431. :param memory_capacity_in_gb:
  432. The capacity of memory to create the instance,
  433. is less than or equal to the remain of dedicated host.
  434. :type memory_capacity_in_gb: int
  435. :param image_id:
  436. The id of image, list all available image in BccClient.list_images.
  437. :type image_id: string
  438. :param dedicated_host_id:
  439. The id of dedicated host, we can locate the instance in specified dedicated host.
  440. :type dedicated_host_id: string
  441. :param ephemeral_disks:
  442. The optional list of ephemeral volume detail info to create.
  443. :type ephemeral_disks: list<bcc_model.EphemeralDisk>
  444. :param purchase_count:
  445. The number of instance to buy, the default value is 1.
  446. :type purchase_count: int
  447. :param name:
  448. The optional parameter to desc the instance that will be created.
  449. :type name: string
  450. :param admin_pass:
  451. The optional parameter to specify the password for the instance.
  452. If specify the adminPass,the adminPass must be a 8-16 characters String
  453. which must contains letters, numbers and symbols.
  454. The symbols only contains "!@#$%^*()".
  455. The adminPass will be encrypted in AES-128 algorithm
  456. with the substring of the former 16 characters of user SecretKey.
  457. If not specify the adminPass, it will be specified by an random string.
  458. See more detail on
  459. https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
  460. :type admin_pass: string
  461. :param subnet_id:
  462. The optional parameter to specify the id of subnet from vpc, optional param
  463. default value is default subnet from default vpc
  464. :type subnet_id: string
  465. :param security_group_id:
  466. The optional parameter to specify the securityGroupId of the instance
  467. vpcId of the securityGroupId must be the same as the vpcId of subnetId
  468. See more detail through listSecurityGroups method
  469. :type security_group_id: string
  470. :param client_token:
  471. An ASCII string whose length is less than 64.
  472. The request will be idempotent if client token is provided.
  473. If the clientToken is not specified by the user,
  474. a random String generated by default algorithm will be used.
  475. See more detail at
  476. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  477. :type client_token: string
  478. :return:
  479. :rtype baidubce.bce_response.BceResponse
  480. """
  481. path = b'/instance'
  482. params = {}
  483. if client_token is None:
  484. params['clientToken'] = generate_client_token()
  485. else:
  486. params['clientToken'] = client_token
  487. body = {
  488. 'cpuCount': cpu_count,
  489. 'memoryCapacityInGB': memory_capacity_in_gb,
  490. 'imageId': image_id,
  491. 'dedicatedHostId': dedicated_host_id
  492. }
  493. if ephemeral_disks is not None:
  494. body['ephemeralDisks'] = ephemeral_disks
  495. if purchase_count > 0:
  496. body['purchaseCount'] = purchase_count
  497. if name is not None:
  498. body['name'] = name
  499. if subnet_id is not None:
  500. body['subnetId'] = subnet_id
  501. if security_group_id is not None:
  502. body['securityGroupId'] = security_group_id
  503. if admin_pass is not None:
  504. secret_access_key = self.config.credentials.secret_access_key
  505. cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
  506. body['adminPass'] = cipher_admin_pass
  507. return self._send_request(http_methods.POST, path, json.dumps(body), params=params,
  508. config=config)
  509. @required(cpu_count=int, memory_capacity_in_gb=int, dedicated_host_id=(bytes, str), # ***Unicode***
  510. image_id=(bytes, str)) # ***Unicode***
  511. def create_instance_from_dedicated_host(self, cpu_count, memory_capacity_in_gb, image_id,
  512. dedicated_host_id, ephemeral_disks=None,
  513. purchase_count=1, name=None, admin_pass=None,
  514. subnet_id=None, security_group_id=None,
  515. client_token=None, config=None):
  516. """
  517. Create a Instance from dedicatedHost with the specified options.
  518. You must fill the field of clientToken,which is especially for keeping idempotent.
  519. This is an asynchronous interface,
  520. you can get the latest status by BccClient.get_instance.
  521. :param cpu_count:
  522. The specified number of cpu core to create the instance,
  523. is less than or equal to the remain of dedicated host.
  524. :type cpu_count: int
  525. :param memory_capacity_in_gb:
  526. The capacity of memory to create the instance,
  527. is less than or equal to the remain of dedicated host.
  528. :type memory_capacity_in_gb: int
  529. :param image_id:
  530. The id of image, list all available image in BccClient.list_images.
  531. :type image_id: string
  532. :param dedicated_host_id:
  533. The id of dedicated host, we can locate the instance in specified dedicated host.
  534. :type dedicated_host_id: string
  535. :param ephemeral_disks:
  536. The optional list of ephemeral volume detail info to create.
  537. :type ephemeral_disks: list<bcc_model.EphemeralDisk>
  538. :param purchase_count:
  539. The number of instance to buy, the default value is 1.
  540. :type purchase_count: int
  541. :param name:
  542. The optional parameter to desc the instance that will be created.
  543. :type name: string
  544. :param admin_pass:
  545. The optional parameter to specify the password for the instance.
  546. If specify the adminPass,the adminPass must be a 8-16 characters String
  547. which must contains letters, numbers and symbols.
  548. The symbols only contains "!@#$%^*()".
  549. The adminPass will be encrypted in AES-128 algorithm
  550. with the substring of the former 16 characters of user SecretKey.
  551. If not specify the adminPass, it will be specified by an random string.
  552. See more detail on
  553. https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
  554. :type admin_pass: string
  555. :param subnet_id:
  556. The optional parameter to specify the id of subnet from vpc, optional param
  557. default value is default subnet from default vpc
  558. :type subnet_id: string
  559. :param security_group_id:
  560. The optional parameter to specify the securityGroupId of the instance
  561. vpcId of the securityGroupId must be the same as the vpcId of subnetId
  562. See more detail through listSecurityGroups method
  563. :type security_group_id: string
  564. :param client_token:
  565. An ASCII string whose length is less than 64.
  566. The request will be idempotent if client token is provided.
  567. If the clientToken is not specified by the user,
  568. a random String generated by default algorithm will be used.
  569. See more detail at
  570. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  571. :type client_token: string
  572. :return:
  573. :rtype baidubce.bce_response.BceResponse
  574. """
  575. path = b'/instance'
  576. params = {}
  577. if client_token is None:
  578. params['clientToken'] = generate_client_token()
  579. else:
  580. params['clientToken'] = client_token
  581. body = {
  582. 'cpuCount': cpu_count,
  583. 'memoryCapacityInGB': memory_capacity_in_gb,
  584. 'imageId': image_id,
  585. 'dedicatedHostId': dedicated_host_id
  586. }
  587. if ephemeral_disks is not None:
  588. body['ephemeralDisks'] = ephemeral_disks
  589. if purchase_count > 0:
  590. body['purchaseCount'] = purchase_count
  591. if name is not None:
  592. body['name'] = name
  593. if admin_pass is not None:
  594. body['adminPass'] = admin_pass
  595. if subnet_id is not None:
  596. body['subnetId'] = subnet_id
  597. if security_group_id is not None:
  598. body['securityGroupId'] = security_group_id
  599. return self._send_request(http_methods.POST, path, json.dumps(body), params=params,
  600. config=config)
  601. @required(cpu_count=int,
  602. memory_capacity_in_gb=int,
  603. image_id=(bytes, str)) # ***Unicode***
  604. def create_instance_of_bid(self, cpu_count, memory_capacity_in_gb, image_id, instance_type=None,
  605. billing=None, create_cds_list=None, root_disk_size_in_gb=0, root_disk_storage_type=None,
  606. ephemeral_disks=None, dedicate_host_id=None, auto_renew_time_unit=None,
  607. auto_renew_time=0,
  608. deploy_id=None, bid_model=None, bid_price=None, key_pair_id=None, cds_auto_renew=False,
  609. internet_charge_type=None, internal_ips=None, request_token=None, asp_id=None, tags=None,
  610. network_capacity_in_mbps=0, purchase_count=1, cardCount=1, name=None, admin_pass=None,
  611. zone_name=None, subnet_id=None, security_group_id=None, gpuCard=None, fpgaCard=None,
  612. client_token=None, config=None, spec=None, user_data=None,
  613. eip_name=None, hostname=None, auto_seq_suffix=False, is_open_hostname_domain=False,
  614. spec_id=None, relation_tag=False, is_open_ipv6=False, deletion_protection=None,
  615. enterprise_security_group_id=None, security_group_ids=None, res_group_id=None,
  616. enterprise_security_group_ids=None, isomerismCard=None, file_systems=None,
  617. card_count=1, isomerism_card=None, is_eip_auto_related_delete=False
  618. , is_keep_image_login=None):
  619. """
  620. Create a bcc Instance with the specified options.
  621. You must fill the field of clientToken,which is especially for keeping idempotent.
  622. This is an asynchronous interface,
  623. you can get the latest status by BccClient.get_instance.
  624. :param instance_type:
  625. The specified Specification to create the instance,
  626. See more detail on
  627. https://cloud.baidu.com/doc/BCC/API.html#InstanceType
  628. :type instance_type: string
  629. :param cpu_count:
  630. The parameter to specified the cpu core to create the instance.
  631. :type cpu_count: int
  632. :param memory_capacity_in_gb:
  633. The parameter to specified the capacity of memory in GB to create the instance.
  634. :type memory_capacity_in_gb: int
  635. :param image_id:
  636. The id of image, list all available image in BccClient.list_images.
  637. :type image_id: string
  638. :param billing:
  639. Billing information.
  640. :type billing: bcc_model.Billing
  641. :param create_cds_list:
  642. The optional list of volume detail info to create.
  643. :type create_cds_list: list<bcc_model.CreateCdsModel>
  644. :param network_capacity_in_mbps:
  645. The optional parameter to specify the bandwidth in Mbps for the new instance.
  646. It must among 0 and 200, default value is 0.
  647. If it's specified to 0, it will get the internal ip address only.
  648. :type network_capacity_in_mbps: int
  649. :param purchase_count:
  650. The number of instance to buy, the default value is 1.
  651. :type purchase_count: int
  652. :param name:
  653. The optional parameter to desc the instance that will be created.
  654. :type name: string
  655. :param admin_pass:
  656. The optional parameter to specify the password for the instance.
  657. If specify the adminPass,the adminPass must be a 8-16 characters String
  658. which must contains letters, numbers and symbols.
  659. The symbols only contains "!@#$%^*()".
  660. The adminPass will be encrypted in AES-128 algorithm
  661. with the substring of the former 16 characters of user SecretKey.
  662. If not specify the adminPass, it will be specified by an random string.
  663. See more detail on
  664. https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
  665. :type admin_pass: string
  666. :param zone_name:
  667. The optional parameter to specify the available zone for the instance.
  668. See more detail through list_zones method
  669. :type zone_name: string
  670. :param subnet_id:
  671. The optional parameter to specify the id of subnet from vpc, optional param
  672. default value is default subnet from default vpc
  673. :type subnet_id: string
  674. :param security_group_id:
  675. The optional parameter to specify the securityGroupId of the instance
  676. vpcId of the securityGroupId must be the same as the vpcId of subnetId
  677. See more detail through listSecurityGroups method
  678. :type security_group_id: string
  679. :param client_token:
  680. An ASCII string whose length is less than 64.
  681. The request will be idempotent if client token is provided.
  682. If the clientToken is not specified by the user,
  683. a random String generated by default algorithm will be used.
  684. See more detail at
  685. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  686. :type client_token: string
  687. :param fpgaCard:
  688. This parameter is obsolete. Use parameter isomerism_card instead.
  689. :type fpgaCard: string
  690. :param gpuCard:
  691. This parameter is obsolete. Use parameter isomerism_card instead.
  692. :type gpuCard: string
  693. :param cardCount:
  694. This parameter is obsolete. Use parameter card_count instead.
  695. :type cardCount: int
  696. :param card_count:
  697. The parameter to specify the card count for creating GPU/FPGA instance.
  698. :type card_count: int
  699. :param root_disk_size_in_gb:
  700. The parameter to specify the root disk size in GB.
  701. The root disk excludes the system disk, available is 40-500GB.
  702. :type root_disk_size_in_gb: int
  703. :param root_disk_storage_type:
  704. The parameter to specify the root disk storage type.
  705. Default use of HP1 cloud disk.
  706. :type root_disk_storage_type: string
  707. :param ephemeral_disks:
  708. The optional list of ephemeral volume detail info to create.
  709. :type ephemeral_disks: list<bcc_model.EphemeralDisk>
  710. :param dedicate_host_id:
  711. This parameter is obsolete.
  712. :type dedicate_host_id: string
  713. :param auto_renew_time_unit:
  714. This parameter is obsolete.
  715. :type auto_renew_time_unit: string
  716. :param auto_renew_time:
  717. This parameter is obsolete.
  718. :type auto_renew_time: string
  719. :param tags:
  720. The optional list of tag to be bonded.
  721. :type tags: list<bcc_model.TagModel>
  722. :param deploy_id:
  723. This parameter is obsolete.
  724. :type deploy_id: string
  725. :param bid_model:
  726. The parameter to specify the bidding model.
  727. The bidding model can be "market" or "custom".
  728. :type bid_model: string
  729. :param bid_price:
  730. The parameter to specify the bidding price.
  731. When the bid_model is "custom", it works.
  732. :type bid_price: string
  733. :param key_pair_id:
  734. The parameter to specify id of the keypair.
  735. :type key_pair_id: string
  736. :param asp_id:
  737. The parameter to specify id of the asp.
  738. :type asp_id: string
  739. :param request_token:
  740. The parameter to specify the request token which will make the request idempotent.
  741. :type request_token: string
  742. :param internet_charge_type:
  743. The parameter to specify the internet charge type.
  744. See more detail on
  745. https://cloud.baidu.com/doc/BCC/API.html#InternetChargeType
  746. :type internet_charge_type: string
  747. :param internal_ips:
  748. This parameter is obsolete.
  749. :type internal_ips: list<string>
  750. :param cds_auto_renew:
  751. This parameter is obsolete.
  752. :type cds_auto_renew: boolean
  753. :param spec:
  754. The parameter to specify Specification to create the instance.
  755. :type spec: string
  756. :param user_data:
  757. The parameter to specify instance custom data.
  758. :type user_data string
  759. :param hostname:
  760. The optional parameter to specify the host name of the instance virtual machine.
  761. By default, hostname is not specified.
  762. If hostname is specified: hostname is used as the prefix of the name in batches.
  763. The backend will add a suffix, and the suffix generation method is: name{-serial number}.
  764. If name is not specified, it will be automatically generated using the following method:
  765. {instance-eight-digit random string-serial number}.
  766. Note: The random string is generated from the characters 0-9 and a-z;
  767. the serial number increases sequentially according to the magnitude of count.
  768. If count is 100, the serial number increases from 000~100, and if it is 10, it increases from 00~10.
  769. Only lowercase letters, numbers and - . special characters are supported.
  770. They must start with a letter. Special symbols cannot be used continuously.
  771. Special symbols are not supported at the beginning or end. The length is 2-64.
  772. :type hostname: string
  773. :param auto_seq_suffix:
  774. The parameter to specify whether name and hostname order suffixes are automatically generated.
  775. :type auto_seq_suffix: boolean
  776. :param is_open_hostname_domain:
  777. The parameter to specify whether hostname domain is automatically generated
  778. :type is_open_hostname_domain: boolean
  779. :param spec_id:
  780. Identify of the spec.
  781. :type spec_id: string
  782. :param relation_tag:
  783. The parameter to specify whether the instance related to existing tags
  784. :type relation_tag: boolean
  785. :param is_open_ipv6:
  786. The parameter indicates whether the instance to be created is enabled for IPv6.
  787. It can only be enabled when both the image and subnet support IPv6.
  788. True indicates enabled, false indicates disabled,
  789. and no transmission indicates automatic adaptation of the image and subnet's IPv6 support
  790. :type is_open_ipv6: boolean
  791. :param deletion_protection:
  792. The status of instance deletion protection. 1:enable, 0:disable.
  793. :type deletion_protection: int
  794. :param eip_name:
  795. eip name
  796. :type eip_name: string
  797. :param isomerismCard:
  798. This parameter is obsolete. Use parameter isomerism_card instead.
  799. :type isomerismCard: string
  800. :param isomerism_card:
  801. The parameter to specify the card type for creating GPU/FPGA instance.
  802. :type isomerism_card: string
  803. :param enterprise_security_group_id:
  804. :type enterprise_security_group_id: string
  805. :param security_group_ids:
  806. security_group_ids
  807. :type security_group_ids: list<string>
  808. :param res_group_id:
  809. The optional parameter to specify the resGroupId of the instance
  810. :type res_group_id: string
  811. :param enterprise_security_group_ids:
  812. enterprise_security_group_ids
  813. :type enterprise_security_group_ids: list<string>
  814. :param file_systems:
  815. This parameter is obsolete.
  816. :type file_systems: list<bcc_model.FileSystemModel>
  817. :param is_eip_auto_related_delete:
  818. The parameter to specify whether to delete the relevant EIP after the bidding instance is automatically deleted.
  819. :type is_eip_auto_related_delete: boolean
  820. :return:
  821. :rtype baidubce.bce_response.BceResponse
  822. """
  823. path = b'/instance/bid'
  824. params = {}
  825. if client_token is None:
  826. params['clientToken'] = generate_client_token()
  827. else:
  828. params['clientToken'] = client_token
  829. if billing is None:
  830. billing = default_billing_to_purchase_created
  831. if card_count == 1 and cardCount > 1:
  832. card_count = cardCount
  833. if isomerism_card is None:
  834. isomerism_card = isomerismCard
  835. body = {
  836. 'cpuCount': cpu_count,
  837. 'memoryCapacityInGB': memory_capacity_in_gb,
  838. 'imageId': image_id,
  839. 'billing': billing.__dict__
  840. }
  841. if hostname is not None:
  842. body['hostname'] = hostname
  843. if auto_seq_suffix is not None:
  844. body['autoSeqSuffix'] = auto_seq_suffix
  845. if is_open_hostname_domain is not None:
  846. body['isOpenHostnameDomain'] = is_open_hostname_domain
  847. if spec_id is not None:
  848. body['specId'] = spec_id
  849. if relation_tag is not None:
  850. body['relationTag'] = relation_tag
  851. if is_open_ipv6 is not None:
  852. body['isOpenIpv6'] = is_open_ipv6
  853. if deletion_protection is not None:
  854. body['deletionProtection'] = deletion_protection
  855. if eip_name is not None:
  856. body['eipName'] = eip_name
  857. if enterprise_security_group_id is not None:
  858. body['enterpriseSecurityGroupId'] = enterprise_security_group_id
  859. if isomerism_card is not None:
  860. body['isomerismCard'] = isomerism_card
  861. if file_systems is not None:
  862. file_system_list = [file_system.__dict__ for file_system in file_systems]
  863. body['fileSystems'] = file_system_list
  864. if instance_type is not None:
  865. body['instanceType'] = instance_type
  866. if root_disk_size_in_gb != 0:
  867. body['rootDiskSizeInGb'] = root_disk_size_in_gb
  868. if root_disk_storage_type is not None:
  869. body['rootDiskStorageType'] = root_disk_storage_type
  870. if create_cds_list is not None:
  871. body['createCdsList'] = [create_cds.__dict__ for create_cds in create_cds_list]
  872. if network_capacity_in_mbps != 0:
  873. body['networkCapacityInMbps'] = network_capacity_in_mbps
  874. if purchase_count > 0:
  875. body['purchaseCount'] = purchase_count
  876. if name is not None:
  877. body['name'] = name
  878. if admin_pass is not None:
  879. secret_access_key = self.config.credentials.secret_access_key
  880. cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
  881. body['adminPass'] = cipher_admin_pass
  882. if zone_name is not None:
  883. body['zoneName'] = zone_name
  884. if subnet_id is not None:
  885. body['subnetId'] = subnet_id
  886. if security_group_id is not None:
  887. body['securityGroupId'] = security_group_id
  888. if security_group_ids is not None:
  889. body['securityGroupIds'] = security_group_ids
  890. if enterprise_security_group_ids is not None:
  891. body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
  892. if gpuCard is not None:
  893. body['gpuCard'] = gpuCard
  894. body['cardCount'] = card_count if card_count > 1 else 1
  895. if fpgaCard is not None:
  896. body['fpgaCard'] = fpgaCard
  897. body['cardCount'] = card_count if card_count > 1 else 1
  898. if auto_renew_time != 0:
  899. body['autoRenewTime'] = auto_renew_time
  900. if auto_renew_time_unit is None:
  901. body['autoRenewTimeUnit'] = "month"
  902. else:
  903. body['autoRenewTimeUnit'] = auto_renew_time_unit
  904. if ephemeral_disks is not None:
  905. body['ephemeralDisks'] = [ephemeral_disk.__dict__ for ephemeral_disk in ephemeral_disks]
  906. if dedicate_host_id is not None:
  907. body['dedicatedHostId'] = dedicate_host_id
  908. if deploy_id is not None:
  909. body['deployId'] = deploy_id
  910. if bid_model is not None:
  911. body['bidModel'] = bid_model
  912. if bid_price is not None:
  913. body['bidPrice'] = bid_price
  914. if key_pair_id is not None:
  915. body['keypairId'] = key_pair_id
  916. if internet_charge_type is not None:
  917. body['internetChargeType'] = internet_charge_type
  918. if asp_id is not None:
  919. body['aspId'] = asp_id
  920. if request_token is not None:
  921. body['requestToken'] = request_token
  922. if tags is not None:
  923. tag_list = [tag.__dict__ for tag in tags]
  924. body['tags'] = tag_list
  925. if internal_ips is not None:
  926. body['internalIps'] = internal_ips
  927. body['cdsAutoRenew'] = cds_auto_renew
  928. if spec is not None:
  929. body['spec'] = spec
  930. if user_data is not None:
  931. body['userData'] = user_data
  932. if res_group_id is not None:
  933. body['resGroupId'] = res_group_id
  934. if is_keep_image_login is not None:
  935. body['keepImageLogin'] = is_keep_image_login
  936. body['isEipAutoRelatedDelete'] = is_eip_auto_related_delete
  937. return self._send_request(http_methods.POST, path, json.dumps(body),
  938. params=params, config=config)
  939. def list_instances(self, marker=None, max_keys=None, internal_ip=None, dedicated_host_id=None,
  940. zone_name=None, instance_ids=None, instance_names=None, cds_ids=None, ehc_cluster_id=None,
  941. deployset_ids=None, security_group_ids=None, payment_timing=None, status=None, tags=None,
  942. vpc_id=None, private_ips=None, ipv6_addresses=None, auto_renew=None, fuzzy_instance_name=None,
  943. config=None):
  944. """
  945. Return a list of instances owned by the authenticated user.
  946. :param marker:
  947. The optional parameter marker specified in the original request to specify
  948. where in the results to begin listing.
  949. Together with the marker, specifies the list result which listing should begin.
  950. If the marker is not specified, the list result will listing from the first one.
  951. :type marker: string
  952. :param max_keys:
  953. The optional parameter to specifies the max number of list result to return.
  954. The default value is 1000.
  955. :type max_keys: int
  956. :param internal_ip:
  957. The identified internal ip of instance.
  958. :type internal_ip: string
  959. :param dedicated_host_id:
  960. get instance list filtered by id of dedicated host
  961. :type dedicated_host_id: string
  962. :param zone_name:
  963. get instance list filtered by name of available zone
  964. :type zone_name: string
  965. :param instance_ids:
  966. filter instance list with multiple instance ids join by ','
  967. :type instance_ids: string
  968. :param instance_names:
  969. filter instance list with multiple instance names join by ','
  970. :type instance_names: string
  971. :param cds_ids:
  972. filter instance list with multiple cds ids join by ','
  973. :type cds_ids: string
  974. :param ehc_cluster_id:
  975. get instance list filtered by id of ehc cluster
  976. :type ehc_cluster_id: string
  977. :param deployset_ids:
  978. filter instance list with multiple deployset ids join by ','
  979. :type deployset_ids: string
  980. :param security_group_ids:
  981. filter instance list with multiple securityGroup ids join by ','
  982. :type security_group_ids: string
  983. :param payment_timing:
  984. filter instance list with multiple type of paymentTiming join by ','
  985. :type payment_timing: string
  986. :param status:
  987. filter instance list with multiple instance status join by ','
  988. :type status: string
  989. :param tags:
  990. filter instance list with multiple tags join by ',', the format of tag can be :
  991. tagKey:tagValue or tagKey
  992. :type tags: string
  993. :param vpc_id:
  994. filter instance list with vpc id, the parameter should be used with private_ips
  995. :type vpc_id: string
  996. :param private_ips:
  997. filter instance list with multiple private ips join by ',', the parameter should be used with
  998. vpc_id
  999. :type private_ips: string
  1000. :param ipv6_addresses:
  1001. filter instance list with multiple ipv6 private ips join by ',', the parameter should be used with
  1002. vpc_id
  1003. :type ipv6_addresses: string
  1004. :param auto_renew:
  1005. :type auto_renew: boolean
  1006. :param fuzzy_instance_name:
  1007. filter instance list with fuzzy instance name
  1008. :type fuzzy_instance_name: string
  1009. :return:
  1010. :rtype baidubce.bce_response.BceResponse
  1011. """
  1012. path = b'/instance'
  1013. params = {}
  1014. if marker is not None:
  1015. params['marker'] = marker
  1016. if max_keys is not None:
  1017. params['maxKeys'] = max_keys
  1018. if internal_ip is not None:
  1019. params['internalIp'] = internal_ip
  1020. if dedicated_host_id is not None:
  1021. params['dedicatedHostId'] = dedicated_host_id
  1022. if zone_name is not None:
  1023. params['zoneName'] = zone_name
  1024. if instance_ids is not None:
  1025. params['instanceIds'] = instance_ids
  1026. if instance_names is not None:
  1027. params['instanceNames'] = instance_names
  1028. if cds_ids is not None:
  1029. params['cdsIds'] = cds_ids
  1030. if ehc_cluster_id is not None:
  1031. params['ehcClusterId'] = ehc_cluster_id
  1032. if deployset_ids is not None:
  1033. params['deploySetIds'] = deployset_ids
  1034. if security_group_ids is not None:
  1035. params['securityGroupIds'] = security_group_ids
  1036. if payment_timing is not None:
  1037. params['paymentTiming'] = payment_timing
  1038. if status is not None:
  1039. params['status'] = status
  1040. if tags is not None:
  1041. params['tags'] = tags
  1042. if vpc_id is not None:
  1043. params['vpcId'] = vpc_id
  1044. if private_ips is not None:
  1045. params['privateIps'] = private_ips
  1046. if ipv6_addresses is not None:
  1047. params['ipv6Addresses'] = ipv6_addresses
  1048. if auto_renew is not None:
  1049. params['autoRenew'] = auto_renew
  1050. if fuzzy_instance_name is not None:
  1051. params['fuzzyInstanceName'] = fuzzy_instance_name
  1052. return self._send_request(http_methods.GET, path, params=params, config=config)
  1053. @required(instance_id=(bytes, str)) # ***Unicode***
  1054. def get_instance(self, instance_id, contains_failed=False, config=None):
  1055. """
  1056. Get the detail information of specified instance.
  1057. :param instance_id:
  1058. The id of instance.
  1059. :type instance_id: string
  1060. :param contains_failed:
  1061. The optional parameters to get the failed message.If true, it means get the failed message.
  1062. :type contains_failed: boolean
  1063. :return:
  1064. :rtype baidubce.bce_response.BceResponse
  1065. """
  1066. instance_id = instance_id.encode(encoding='utf-8')
  1067. path = b'/instance/%s' % instance_id
  1068. params = {}
  1069. if contains_failed:
  1070. params['containsFailed'] = contains_failed
  1071. return self._send_request(http_methods.GET, path, params=params, config=config)
  1072. @required(instance_id=(bytes, str)) # ***Unicode***s
  1073. def start_instance(self, instance_id, config=None):
  1074. """
  1075. Starting the instance owned by the user.
  1076. You can start the instance only when the instance is Stopped,
  1077. otherwise, it's will get 409 errorCode.
  1078. This is an asynchronous interface,
  1079. you can get the latest status by BccClient.get_instance.
  1080. :param instance_id: id of instance proposed to start
  1081. :type instance_id: string
  1082. :return:
  1083. :rtype baidubce.bce_response.BceResponse
  1084. """
  1085. instance_id = compat.convert_to_bytes(instance_id)
  1086. path = b'/instance/%s' % instance_id
  1087. params = {
  1088. 'start': None
  1089. }
  1090. return self._send_request(http_methods.PUT, path, params=params, config=config)
  1091. @required(instance_id=(bytes, str)) # ***Unicode***
  1092. def stop_instance(self, instance_id, force_stop=False, stopWithNoCharge=False, config=None):
  1093. """
  1094. Stopping the instance owned by the user.
  1095. You can stop the instance only when the instance is Running,
  1096. otherwise, it's will get 409 errorCode.
  1097. This is an asynchronous interface,
  1098. you can get the latest status by BccClient.get_instance.
  1099. :param instance_id:
  1100. The id of instance.
  1101. :type instance_id: string
  1102. :param force_stop:
  1103. The optional parameter to stop the instance forcibly.If true,
  1104. it will stop the instance just like power off immediately
  1105. and it may result in losing important data which have not been written to disk.
  1106. :type force_stop: boolean
  1107. :return:
  1108. :rtype baidubce.bce_response.BceResponse
  1109. """
  1110. instance_id = compat.convert_to_bytes(instance_id)
  1111. path = b'/instance/%s' % instance_id
  1112. body = {
  1113. 'forceStop': force_stop,
  1114. 'stopWithNoCharge': stopWithNoCharge
  1115. }
  1116. params = {
  1117. 'stop': None
  1118. }
  1119. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1120. params=params, config=config)
  1121. @required(instance_id=(bytes, str)) # ***Unicode***
  1122. def reboot_instance(self, instance_id, force_stop=False, config=None):
  1123. """
  1124. Rebooting the instance owned by the user.
  1125. You can reboot the instance only when the instance is Running,
  1126. otherwise, it's will get 409 errorCode.
  1127. This is an asynchronous interface,
  1128. you can get the latest status by BccClient.get_instance.
  1129. :param instance_id:
  1130. The id of instance.
  1131. :type instance_id: string
  1132. :param force_stop:
  1133. The optional parameter to stop the instance forcibly.If true,
  1134. it will stop the instance just like power off immediately
  1135. and it may result in losing important data which have not been written to disk.
  1136. :type force_stop: boolean
  1137. :return:
  1138. :rtype baidubce.bce_response.BceResponse
  1139. """
  1140. instance_id = compat.convert_to_bytes(instance_id)
  1141. path = b'/instance/%s' % instance_id
  1142. body = {
  1143. 'forceStop': force_stop
  1144. }
  1145. params = {
  1146. 'reboot': None
  1147. }
  1148. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1149. params=params, config=config)
  1150. @required(instance_id=str)
  1151. def batch_add_ip(self, instance_id, private_ips=None, secondary_private_ip_address_count=None,
  1152. allocate_multi_ipv6_addr=None, config=None):
  1153. """
  1154. batch_add_ip
  1155. :param instance_id:
  1156. The id of instance.
  1157. :type instance_id: string
  1158. :param private_ips:
  1159. The IPV6/IPV4 address that needs to be added must exist with secondary_private_ip_address_count.
  1160. :type private_ips: list
  1161. :param secondary_private_ip_address_count:
  1162. The number of IPV6/IPV4 needs to be increased, and one with private_ips must exist.
  1163. :type secondary_private_ip_address_count: list
  1164. :param allocate_multi_ipv6_addr:
  1165. The parameter indicates whether to support multiple IPV6.
  1166. It must be true to create IPV6.
  1167. :type allocate_multi_ipv6_addr: bool
  1168. :return:
  1169. :rtype baidubce.bce_response.BceResponse
  1170. """
  1171. path = b'/instance/batchAddIp'
  1172. body = {
  1173. 'instanceId': instance_id,
  1174. }
  1175. if private_ips is not None:
  1176. body['privateIps'] = private_ips
  1177. if secondary_private_ip_address_count is not None:
  1178. body['secondaryPrivateIpAddressCount'] = secondary_private_ip_address_count
  1179. if allocate_multi_ipv6_addr is not None:
  1180. body['allocateMultiIpv6Addr'] = allocate_multi_ipv6_addr
  1181. params = {
  1182. }
  1183. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1184. params=params, config=config)
  1185. @required(instance_id=str, private_ips=list)
  1186. def batch_delete_ip(self, instance_id, private_ips, config=None):
  1187. """
  1188. :param instance_id:
  1189. :param private_ips:
  1190. :param config:
  1191. :return:
  1192. """
  1193. path = b'/instance/batchDelIp'
  1194. body = {
  1195. 'instanceId': instance_id,
  1196. 'privateIps': private_ips,
  1197. }
  1198. params = {
  1199. }
  1200. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1201. params=params, config=config)
  1202. @required(instance_id=(bytes, str), # ***Unicode***
  1203. admin_pass=(bytes, str)) # ***Unicode***
  1204. def modify_instance_password(self, instance_id, admin_pass, config=None):
  1205. """
  1206. Modifying the password of the instance.
  1207. You can change the instance password only when the instance is Running or Stopped ,
  1208. otherwise, it's will get 409 errorCode.
  1209. This is an asynchronous interface,
  1210. you can get the latest status by BccClient.get_instance.
  1211. :param instance_id:
  1212. The id of instance.
  1213. :type instance_id: string
  1214. :param admin_pass:
  1215. The new password to update.
  1216. The adminPass will be encrypted in AES-128 algorithm
  1217. with the substring of the former 16 characters of user SecretKey.
  1218. :type admin_pass: string
  1219. :return:
  1220. :rtype baidubce.bce_response.BceResponse
  1221. """
  1222. instance_id = compat.convert_to_bytes(instance_id)
  1223. secret_access_key = self.config.credentials.secret_access_key
  1224. cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
  1225. path = b'/instance/%s' % instance_id
  1226. body = {
  1227. 'adminPass': cipher_admin_pass
  1228. }
  1229. params = {
  1230. 'changePass': None
  1231. }
  1232. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1233. params=params, config=config)
  1234. @required(instance_id=(bytes, str), # ***Unicode***
  1235. name=(bytes, str)) # ***Unicode***
  1236. def modify_instance_attributes(self, instance_id, name=None, neteth_queuecount=None,
  1237. enable_jumbo_frame=None, config=None):
  1238. """
  1239. Modifying the special attribute to new value of the instance.
  1240. You can reboot the instance only when the instance is Running or Stopped ,
  1241. otherwise, it's will get 409 errorCode.
  1242. :param instance_id:
  1243. The id of instance.
  1244. :type instance_id: string
  1245. :param name:
  1246. The new value for instance's name.
  1247. :type name: string
  1248. :param neteth_queuecount:
  1249. The new value for instance's neteth_queuecount.
  1250. :type neteth_queuecount: string
  1251. :param enable_jumbo_frame:
  1252. The parameter indicates whether the instance is enabled for JumboFrame.
  1253. It can only be enabled when the flavor support JumboFrame.
  1254. True indicates enabled, false indicates disabled,
  1255. :type enable_jumbo_frame: bool
  1256. :return:
  1257. :rtype baidubce.bce_response.BceResponse
  1258. """
  1259. instance_id = compat.convert_to_bytes(instance_id)
  1260. path = b'/instance/%s' % instance_id
  1261. body = {
  1262. 'name': name,
  1263. 'netEthQueueCount': neteth_queuecount
  1264. }
  1265. if enable_jumbo_frame is not None:
  1266. body['enableJumboFrame'] = enable_jumbo_frame
  1267. params = {
  1268. 'modifyAttribute': None
  1269. }
  1270. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1271. params=params, config=config)
  1272. @required(instance_id=(bytes, str),
  1273. desc=(bytes, str))
  1274. def modify_instance_desc(self, instance_id, desc, config=None):
  1275. """
  1276. Modifying the description of the instance.
  1277. You can reboot the instance only when the instance is Running or Stopped ,
  1278. otherwise, it's will get 409 errorCode.
  1279. :param instance_id:
  1280. The id of instance.
  1281. :type instance_id: string
  1282. :param desc:
  1283. The new value for instance's description.
  1284. :type name: string
  1285. :return:
  1286. :rtype baidubce.bce_response.BceResponse
  1287. """
  1288. instance_id = compat.convert_to_bytes(instance_id)
  1289. path = b'/instance/%s' % instance_id
  1290. body = {
  1291. 'desc': desc
  1292. }
  1293. params = {
  1294. 'modifyDesc': None
  1295. }
  1296. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1297. params=params, config=config)
  1298. @required(instance_id=(bytes, str), # ***Unicode***
  1299. image_id=(bytes, str)) # ***Unicode***
  1300. def rebuild_instance(self, instance_id, image_id, admin_pass=None, key_pair_id=None, is_keep_image_login=None,
  1301. config=None, user_data=None, clean_last_user_data=None, is_open_hostEye=None,
  1302. sys_root_size=None, is_preserve_data=None, raid_id=None, data_partition_type=None,
  1303. root_partition_type=None):
  1304. """
  1305. Rebuilding the instance owned by the user.
  1306. After rebuilding the instance,
  1307. all of snapshots created from original instance system disk will be deleted,
  1308. all of customized images will be saved for using in the future.
  1309. This is an asynchronous interface,
  1310. you can get the latest status by BccClient.get_instance.
  1311. :param instance_id:
  1312. The id of instance.
  1313. :type instance_id: string
  1314. :param image_id:
  1315. The id of the image which is used to rebuild the instance.
  1316. :type image_id: string
  1317. :param admin_pass:
  1318. The admin password to login the instance.
  1319. The admin password will be encrypted in AES-128 algorithm
  1320. with the substring of the former 16 characters of user SecretKey.
  1321. See more detail on
  1322. https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
  1323. :type admin_pass: string
  1324. :param key_pair_id:
  1325. key_pair_id or admin_pass is required for rebuild instance.
  1326. :type key_pair_id: string
  1327. :param user_data:
  1328. User data to pass to the instance at launch time.
  1329. :type user_data: string
  1330. :param clean_last_user_data:
  1331. Indicates whether to clean the user data after the instance has been rebuilded.
  1332. Default value is False.
  1333. :type clean_user_data: boolean
  1334. :param is_open_hostEye:
  1335. Indicates whether to open host eye.
  1336. :type is_open_hostEye: boolean
  1337. :param sys_root_size:
  1338. System partition size (unit: GB).
  1339. :type sys_root_size: int
  1340. :param is_preserve_data:
  1341. Indicates whether to preserve data during the instance rebuilding process.
  1342. Default value is False.
  1343. :type is_preserve_data: boolean
  1344. :param raid_id:
  1345. RAID ID.
  1346. :type raid_id: string
  1347. :param data_partition_type:
  1348. Data partition type.
  1349. :type data_partition_type: string
  1350. :param root_partition_type:
  1351. Root partition type.
  1352. :type root_partition_type: string
  1353. :return:
  1354. :rtype baidubce.bce_response.BceResponse
  1355. """
  1356. instance_id = compat.convert_to_bytes(instance_id)
  1357. path = b'/instance/%s' % instance_id
  1358. body = {
  1359. 'imageId': image_id,
  1360. }
  1361. if key_pair_id is not None:
  1362. body['keypairId'] = key_pair_id
  1363. if is_keep_image_login is not None:
  1364. body['keepImageLogin'] = is_keep_image_login
  1365. if admin_pass is not None:
  1366. secret_access_key = self.config.credentials.secret_access_key
  1367. cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
  1368. body['adminPass'] = cipher_admin_pass
  1369. if user_data is not None:
  1370. body['userData'] = user_data
  1371. if clean_last_user_data is not None:
  1372. body['cleanLastUserData'] = clean_last_user_data
  1373. if is_open_hostEye is not None:
  1374. body['isOpenHostEye'] = is_open_hostEye
  1375. if sys_root_size is not None:
  1376. body['sysRootSize'] = sys_root_size
  1377. if is_preserve_data is not None:
  1378. body['isPreserveData'] = is_preserve_data
  1379. if raid_id is not None:
  1380. body['raidId'] = raid_id
  1381. if data_partition_type is not None:
  1382. body['dataPartitionType'] = data_partition_type
  1383. if root_partition_type is not None:
  1384. body['rootPartitionType'] = root_partition_type
  1385. params = {
  1386. 'rebuild': None
  1387. }
  1388. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1389. params=params, config=config)
  1390. @required(instance_id=(bytes, str)) # ***Unicode***
  1391. def release_instance(self, instance_id, config=None):
  1392. """
  1393. Releasing the instance owned by the user.
  1394. Only the Postpaid instance or Prepaid which is expired can be released.
  1395. After releasing the instance,
  1396. all of the data will be deleted.
  1397. all of volumes attached will be auto detached, but the volume snapshots will be saved.
  1398. all of snapshots created from original instance system disk will be deleted,
  1399. all of customized images created from original instance system disk will be reserved.
  1400. :param instance_id:
  1401. The id of instance.
  1402. :type instance_id: string
  1403. :return:
  1404. :rtype baidubce.bce_response.BceResponse
  1405. """
  1406. instance_id = compat.convert_to_bytes(instance_id)
  1407. path = b'/instance/%s' % instance_id
  1408. return self._send_request(http_methods.DELETE, path, config=config)
  1409. @required(instance_id=(bytes, str), # ***Unicode***
  1410. cpu_count=int,
  1411. memory_capacity_in_gb=int)
  1412. def resize_instance(self, instance_id, cpu_count, memory_capacity_in_gb,
  1413. live_resize=None, gpu_card_count=None, ephemeral_disk_in_gb=None,
  1414. enable_jumbo_frame=None,
  1415. client_token=None, config=None):
  1416. """
  1417. Resizing the instance owned by the user.
  1418. The Prepaid instance can not be downgrade.
  1419. Only the Running/Stopped instance can be resized, otherwise, it's will get 409 errorCode.
  1420. After resizing the instance,it will be reboot once.
  1421. This is an asynchronous interface,
  1422. you can get the latest status by BccClient.get_instance.
  1423. :param instance_id:
  1424. The id of instance.
  1425. :type instance_id: string
  1426. :param cpu_count:
  1427. The parameter of specified the cpu core to resize the instance.
  1428. :type cpu_count: int
  1429. :param memory_capacity_in_gb:
  1430. The parameter of specified the capacity of memory in GB to resize the instance.
  1431. :type memory_capacity_in_gb: int
  1432. :param enable_jumbo_frame:
  1433. The parameter of specified the instance enable/disable jumbo frame.
  1434. True means enable jumbo frame, false means disable jumbo frame.
  1435. enable_jumbo_frame default None which means:
  1436. When you change to the spec which doesn't support jumbo frame, the jumbo frame will be disabled.
  1437. When the original instance don't support jumbo frame and you change to the spec which support jumbo frame,
  1438. the jumbo frame will be disabled.
  1439. When the original spec of the instance support jumbo frame , then you change to the spec which support jumbo
  1440. frame, if the original instance enable jumbo frame, the jumbo frame will be enabled, if the original instance
  1441. disable jumbo frame, the jumbo frame will be disabled.
  1442. :type enable_jumbo_frame: bool
  1443. :param client_token:
  1444. An ASCII string whose length is less than 64.
  1445. The request will be idempotent if client token is provided.
  1446. If the clientToken is not specified by the user,
  1447. a random String generated by default algorithm will be used.
  1448. See more detail at
  1449. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  1450. :type client_token: string
  1451. :param live_resize:
  1452. :type live_resize: boolean
  1453. :param gpu_card_count:
  1454. :type gpu_card_count: int
  1455. :param ephemeral_disk_in_gb:
  1456. :type ephemeral_disk_in_gb: int
  1457. :return:
  1458. :rtype baidubce.bce_response.BceResponse
  1459. """
  1460. instance_id = compat.convert_to_bytes(instance_id)
  1461. path = b'/instance/%s' % instance_id
  1462. body = {
  1463. 'cpuCount': cpu_count,
  1464. 'memoryCapacityInGB': memory_capacity_in_gb
  1465. }
  1466. if live_resize is not None:
  1467. body['liveResize'] = live_resize
  1468. if gpu_card_count is not None:
  1469. body['gpuCardCount'] = gpu_card_count
  1470. if ephemeral_disk_in_gb is not None:
  1471. body['ephemeralDiskInGb'] = ephemeral_disk_in_gb
  1472. if enable_jumbo_frame is not None:
  1473. body['enableJumboFrame'] = enable_jumbo_frame
  1474. params = None
  1475. if client_token is None:
  1476. params = {
  1477. 'resize': None,
  1478. 'clientToken': generate_client_token()
  1479. }
  1480. else:
  1481. params = {
  1482. 'resize': None,
  1483. 'clientToken': client_token
  1484. }
  1485. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1486. params=params, config=config)
  1487. @required(instance_id=(bytes, str), # ***Unicode***
  1488. security_group_id=(bytes, str)) # ***Unicode***
  1489. def bind_instance_to_security_group(self, instance_id, security_group_id, config=None):
  1490. """
  1491. Binding the instance to specified securitygroup.
  1492. :param instance_id:
  1493. The id of the instance.
  1494. :type instance_id: string
  1495. :param securitygroup_id:
  1496. The id of the securitygroup.
  1497. :type securitygroup_id: string
  1498. :return:
  1499. :rtype baidubce.bce_response.BceResponse
  1500. """
  1501. instance_id = compat.convert_to_bytes(instance_id)
  1502. path = b'/instance/%s' % instance_id
  1503. body = {
  1504. 'securityGroupId': security_group_id
  1505. }
  1506. params = {
  1507. 'bind': None
  1508. }
  1509. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1510. params=params, config=config)
  1511. @required(instance_id=(bytes, str), # ***Unicode***
  1512. security_group_id=(bytes, str)) # ***Unicode***
  1513. def unbind_instance_from_security_group(self, instance_id, security_group_id, config=None):
  1514. """
  1515. Unbinding the instance from securitygroup.
  1516. :param instance_id:
  1517. The id of the instance.
  1518. :type instance_id: string
  1519. :param securitygroup_id:
  1520. The id of the securitygroup.
  1521. :type securitygroup_id: string
  1522. :return:
  1523. :rtype baidubce.bce_response.BceResponse
  1524. """
  1525. instance_id = compat.convert_to_bytes(instance_id)
  1526. path = b'/instance/%s' % instance_id
  1527. body = {
  1528. 'securityGroupId': security_group_id
  1529. }
  1530. params = {
  1531. 'unbind': None
  1532. }
  1533. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1534. params=params, config=config)
  1535. @required(reserved_instance_ids=list,
  1536. tags=list)
  1537. def bind_reserved_instance_to_tags(self, reserved_instance_ids, tags, config=None):
  1538. """
  1539. :param reserved_instance_ids:
  1540. :param tags:
  1541. :param config:
  1542. :return:
  1543. """
  1544. path = b'/bcc/reserved/tag'
  1545. tag_list = [tag.__dict__ for tag in tags]
  1546. body = {
  1547. 'changeTags': tag_list,
  1548. 'reservedInstanceIds': reserved_instance_ids
  1549. }
  1550. params = {
  1551. 'bind': None
  1552. }
  1553. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1554. params=params, config=config)
  1555. @required(reserved_instance_ids=list,
  1556. tags=list)
  1557. def unbind_reserved_instance_from_tags(self, reserved_instance_ids, tags, config=None):
  1558. """
  1559. :param reserved_instance_ids:
  1560. :param tags:
  1561. :param config:
  1562. :return:
  1563. """
  1564. path = b'/bcc/reserved/tag'
  1565. tag_list = [tag.__dict__ for tag in tags]
  1566. body = {
  1567. 'changeTags': tag_list,
  1568. 'reservedInstanceIds': reserved_instance_ids
  1569. }
  1570. params = {
  1571. 'unbind': None
  1572. }
  1573. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1574. params=params, config=config)
  1575. def bind_tags_batch_by_resource_type(self, resource_type, resource_ids, tags, is_relation_tag, config=None):
  1576. """
  1577. :param resource_type:
  1578. :param resource_ids:
  1579. :param tags:
  1580. :param is_relation_tag:
  1581. :param config:
  1582. :return:
  1583. """
  1584. path = b'/bcc/tag'
  1585. tag_list = [tag.__dict__ for tag in tags]
  1586. body = {
  1587. 'resourceType': resource_type,
  1588. 'resourceIds': resource_ids,
  1589. 'tags': tag_list,
  1590. 'isRelationTag': is_relation_tag
  1591. }
  1592. params = {
  1593. 'action': 'AttachTags'
  1594. }
  1595. return self._send_request(http_methods.POST, path, json.dumps(body),
  1596. params=params, config=config, prefix=self.prefix_v3)
  1597. def unbind_tags_batch_by_resource_type(self, resource_type, resource_ids, tags, is_relation_tag, config=None):
  1598. """
  1599. :param resource_type:
  1600. :param resource_ids:
  1601. :param tags:
  1602. :param is_relation_tag:
  1603. :param config:
  1604. :return:
  1605. """
  1606. path = b'/bcc/tag'
  1607. tag_list = [tag.__dict__ for tag in tags]
  1608. body = {
  1609. 'resourceType': resource_type,
  1610. 'resourceIds': resource_ids,
  1611. 'tags': tag_list,
  1612. 'isRelationTag': is_relation_tag
  1613. }
  1614. params = {
  1615. 'action': 'DetachTags'
  1616. }
  1617. return self._send_request(http_methods.POST, path, json.dumps(body),
  1618. params=params, config=config, prefix=self.prefix_v3)
  1619. @required(instance_id=(bytes, str),
  1620. tags=list)
  1621. def bind_instance_to_tags(self, instance_id, tags, config=None):
  1622. """
  1623. :param instance_id:
  1624. :param tags:
  1625. :param config:
  1626. :return:
  1627. """
  1628. instance_id = compat.convert_to_bytes(instance_id)
  1629. path = b'/instance/%s/tag' % instance_id
  1630. tag_list = [tag.__dict__ for tag in tags]
  1631. body = {
  1632. 'changeTags': tag_list
  1633. }
  1634. params = {
  1635. 'bind': None
  1636. }
  1637. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1638. params=params, config=config)
  1639. @required(instance_id=(bytes, str),
  1640. tags=list)
  1641. def unbind_instance_from_tags(self, instance_id, tags, config=None):
  1642. """
  1643. :param instance_id:
  1644. :param tags:
  1645. :param config:
  1646. :return:
  1647. """
  1648. instance_id = compat.convert_to_bytes(instance_id)
  1649. path = b'/instance/%s/tag' % instance_id
  1650. tag_list = [tag.__dict__ for tag in tags]
  1651. body = {
  1652. 'changeTags': tag_list
  1653. }
  1654. params = {
  1655. 'unbind': None
  1656. }
  1657. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1658. params=params, config=config)
  1659. @required(instance_id=(bytes, str)) # ***Unicode***
  1660. def get_instance_vnc(self, instance_id, config=None):
  1661. """
  1662. Getting the vnc url to access the instance.
  1663. The vnc url can be used once.
  1664. :param instance_id:
  1665. The id of the instance.
  1666. :type instance_id: string
  1667. :return:
  1668. :rtype baidubce.bce_response.BceResponse
  1669. """
  1670. instance_id = compat.convert_to_bytes(instance_id)
  1671. path = b'/instance/%s/vnc' % instance_id
  1672. return self._send_request(http_methods.GET, path, config=config)
  1673. @required(instance_id=(bytes, str)) # ***Unicode***
  1674. def purchase_reserved_instance(self,
  1675. instance_id,
  1676. billing=None,
  1677. related_renew_flag=None,
  1678. client_token=None,
  1679. config=None,
  1680. cds_custom_period=None):
  1681. """
  1682. PurchaseReserved the instance with fixed duration.
  1683. You can not purchaseReserved the instance which is resizing.
  1684. This is an asynchronous interface,
  1685. you can get the latest status by BccClient.get_instance.
  1686. :param instance_id:
  1687. The id of the instance.
  1688. :type instance_id: string
  1689. :param billing:
  1690. Billing information.
  1691. :type billing: bcc_model.Billing
  1692. :param related_renew_flag:
  1693. Detailed information see: https://cloud.baidu.com/doc/BCC/s/6jwvyo0q2#relatedrenewflag
  1694. :type related_renew_flag: string
  1695. :param cds_custom_period:
  1696. Custom renew period for CDS.
  1697. :type cds_custom_period: list
  1698. :param client_token:
  1699. An ASCII string whose length is less than 64.
  1700. The request will be idempotent if client token is provided.
  1701. If the clientToken is not specified by the user,
  1702. a random String generated by default algorithm will be used.
  1703. See more detail at
  1704. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  1705. :type client_token: string
  1706. :return:
  1707. :rtype baidubce.bce_response.BceResponse
  1708. """
  1709. instance_id = compat.convert_to_bytes(instance_id)
  1710. path = b'/instance/%s' % instance_id
  1711. if billing is None:
  1712. billing = default_billing_to_purchase_reserved
  1713. cds_custom_period_list = []
  1714. if cds_custom_period is not None:
  1715. cds_custom_period_list = [custom_period.__dict__ for custom_period in cds_custom_period]
  1716. body = {
  1717. 'billing': billing.__dict__,
  1718. "cdsCustomPeriod": cds_custom_period_list
  1719. }
  1720. params = None
  1721. if client_token is None:
  1722. params = {
  1723. 'purchaseReserved': None,
  1724. 'clientToken': generate_client_token()
  1725. }
  1726. else:
  1727. params = {
  1728. 'purchaseReserved': None,
  1729. 'clientToken': client_token
  1730. }
  1731. if related_renew_flag is not None:
  1732. params['relatedRenewFlag'] = related_renew_flag
  1733. return self._send_request(http_methods.PUT, path, json.dumps(body),
  1734. params=params, config=config)
  1735. def list_instance_specs(self, config=None):
  1736. """
  1737. The interface will be deprecated in the future,
  1738. we suggest to use triad (instanceType, cpuCount, memoryCapacityInGB) to specified the instance configuration.
  1739. Listing all of specification for instance resource to buy.
  1740. See more detail on
  1741. https://bce.baidu.com/doc/BCC/API.html#.E5.AE.9E.E4.BE.8B.E5.A5.97.E9.A4.90.E8.A7.84.E6.A0.BC
  1742. :return:
  1743. :rtype baidubce.bce_response.BceResponse
  1744. """
  1745. path = b'/instance/spec'
  1746. return self._send_request(http_methods.GET, path, config=config)
  1747. @required(cds_size_in_gb=int)
  1748. def create_volume_with_cds_size(self, cds_size_in_gb, billing=None, purchase_count=1,
  1749. storage_type='hp1', zone_name=None,
  1750. instance_id=None, encrypt_key=None, name=None,
  1751. description=None, renew_time_unit=None, renew_time=None,
  1752. cluster_id=None, relation_tag=False,
  1753. tags=None, auto_snapshot_policy=None,
  1754. client_token=None, config=None, charge_type=None):
  1755. """
  1756. Create a volume with the specified options.
  1757. You can use this method to create a new empty volume by specified options
  1758. or you can create a new volume from customized volume snapshot but not system disk snapshot.
  1759. By using the cdsSizeInGB parameter you can create a newly empty volume.
  1760. By using snapshotId parameter to create a volume form specific snapshot.
  1761. :param cds_size_in_gb:
  1762. The size of volume to create in GB.
  1763. By specifying the snapshotId,
  1764. it will create volume from the specified snapshot and the parameter cdsSizeInGB will be ignored.
  1765. :type cds_size_in_gb: int
  1766. :param billing:
  1767. Billing information.Deprecated
  1768. :type billing: bcc_model.Billing
  1769. :param purchase_count:
  1770. The optional parameter to specify how many volumes to buy, default value is 1.
  1771. The maximum to create for one time is 5.
  1772. :type purchase_count: int
  1773. :param storage_type:
  1774. The storage type of volume, see more detail in
  1775. https://bce.baidu.com/doc/BCC/API.html#StorageType
  1776. :type storage_type: menu{'hp1', 'std1'}
  1777. :param zone_name:
  1778. The optional parameter to specify the available zone for the volume.
  1779. See more detail through list_zones method
  1780. :type zone_name: string
  1781. :param client_token:
  1782. An ASCII string whose length is less than 64.
  1783. The request will be idempotent if client token is provided.
  1784. If the clientToken is not specified by the user,
  1785. a random String generated by default algorithm will be used.
  1786. See more detail at
  1787. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  1788. :type client_token: string
  1789. :param instance_id:
  1790. :type instance_id: string
  1791. :param encrypt_key:
  1792. :type encrypt_key: string
  1793. :param name:
  1794. :type name: string
  1795. :param description:
  1796. :type description: string
  1797. :param renew_time_unit:
  1798. :type renew_time_unit: string
  1799. :param renew_time:
  1800. :type renew_time: int
  1801. :param cluster_id:
  1802. cds cluster id
  1803. :type cluster_id: string
  1804. :param relation_tag:
  1805. :type relation_tag: boolean
  1806. :param tags:
  1807. The optional list of tag to be bonded.
  1808. :type tags: list<bcc_model.TagModel>
  1809. :param auto_snapshot_policy:
  1810. The optional auto snapshot policy to be bonded.
  1811. :type auto_snapshot_policy: bcc_model.AutoSnapshotPolicyModel
  1812. :param charge_type:
  1813. The optional parameter to specify the payment for the volume.
  1814. The billing type and payment method, including Prepaid and Postpaid,
  1815. need to be specified only when the instanceId is not empty and the corresponding instance type is prepaid.
  1816. If instanceId is empty:
  1817. create a post payment type CDS;
  1818. If the instanceId is not empty:
  1819. If the instance is prepaid, a chargeType needs to be specified;
  1820. If the instance is post paid, create a post paid CDS
  1821. :type charge_type: menu{'Prepaid', 'Postpaid'}
  1822. :return:
  1823. :rtype baidubce.bce_response.BceResponse
  1824. """
  1825. path = b'/volume'
  1826. params = {}
  1827. if client_token is None:
  1828. params['clientToken'] = generate_client_token()
  1829. else:
  1830. params['clientToken'] = client_token
  1831. if billing is None:
  1832. billing = default_billing_to_purchase_created
  1833. body = {
  1834. 'cdsSizeInGB': cds_size_in_gb,
  1835. 'billing': billing.__dict__
  1836. }
  1837. if purchase_count is not None:
  1838. body['purchaseCount'] = purchase_count
  1839. if storage_type is not None:
  1840. body['storageType'] = storage_type
  1841. if zone_name is not None:
  1842. body['zoneName'] = zone_name
  1843. if renew_time_unit is not None:
  1844. body['renewTimeUnit'] = renew_time_unit
  1845. if renew_time is not None:
  1846. body['renewTime'] = renew_time
  1847. if cluster_id is not None:
  1848. body['clusterId'] = cluster_id
  1849. if relation_tag is not None:
  1850. body['relationTag'] = relation_tag
  1851. if tags is not None:
  1852. tag_list = [tag.__dict__ for tag in tags]
  1853. body['tags'] = tag_list
  1854. if auto_snapshot_policy is not None:
  1855. body['autoSnapshotPolicy'] = auto_snapshot_policy.__dict__
  1856. if name is not None:
  1857. body['name'] = name
  1858. if description is not None:
  1859. body['description'] = description
  1860. if encrypt_key is not None:
  1861. body['encryptKey'] = encrypt_key
  1862. if instance_id is not None:
  1863. body['instanceId'] = instance_id
  1864. if charge_type is not None:
  1865. body['chargeType'] = charge_type
  1866. return self._send_request(http_methods.POST, path, json.dumps(body),
  1867. params=params, config=config)
  1868. @required(snapshot_id=(bytes, str)) # ***Unicode***
  1869. def create_volume_with_snapshot_id(self, snapshot_id, billing=None, purchase_count=1,
  1870. storage_type='hp1', zone_name=None, client_token=None,
  1871. instance_id=None, encrypt_key=None, name=None,
  1872. description=None, renew_time_unit=None, renew_time=None,
  1873. cluster_id=None, relation_tag=False,
  1874. tags=None, auto_snapshot_policy=None,
  1875. config=None, charge_type=None):
  1876. """
  1877. Create a volume with the specified options.
  1878. You can use this method to create a new empty volume by specified options
  1879. or you can create a new volume from customized volume snapshot but not system disk snapshot.
  1880. By using the cdsSizeInGB parameter you can create a newly empty volume.
  1881. By using snapshotId parameter to create a volume form specific snapshot.
  1882. :param snapshot_id:xx
  1883. The id of snapshot.
  1884. By specifying the snapshotId,
  1885. it will create volume from the specified snapshot and the parameter cdsSizeInGB will be ignored.
  1886. :type snapshot_id: string
  1887. :param billing:
  1888. Billing information.Deprecated
  1889. :type billing: bcc_model.Billing
  1890. :param purchase_count:
  1891. The optional parameter to specify how many volumes to buy, default value is 1.
  1892. The maximum to create for one time is 5.
  1893. :type purchase_count: int
  1894. :param storage_type:
  1895. The storage type of volume, see more detail in
  1896. https://bce.baidu.com/doc/BCC/API.html#StorageType
  1897. :type storage_type: menu{'hp1', 'std1'}
  1898. :param zone_name:
  1899. The optional parameter to specify the available zone for the volume.
  1900. See more detail through list_zones method
  1901. :type zone_name: string
  1902. :param instance_id:
  1903. :type instance_id: string
  1904. :param encrypt_key:
  1905. :type encrypt_key: string
  1906. :param name:
  1907. :type name: string
  1908. :param description:
  1909. :type description: string
  1910. :param renew_time_unit:
  1911. :type renew_time_unit: string
  1912. :param renew_time:
  1913. :type renew_time: int
  1914. :param cluster_id:
  1915. cds cluster id
  1916. :type cluster_id: string
  1917. :param relation_tag:
  1918. :type relation_tag: boolean
  1919. :param tags:
  1920. The optional list of tag to be bonded.
  1921. :type tags: list<bcc_model.TagModel>
  1922. :param auto_snapshot_policy:
  1923. The optional auto snapshot policy to be bonded.
  1924. :type auto_snapshot_policy: bcc_model.AutoSnapshotPolicyModel
  1925. :param client_token:
  1926. An ASCII string whose length is less than 64.
  1927. The request will be idempotent if client token is provided.
  1928. If the clientToken is not specified by the user,
  1929. a random String generated by default algorithm will be used.
  1930. See more detail at
  1931. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  1932. :type client_token: string
  1933. :param charge_type:
  1934. The optional parameter to specify the payment for the volume.
  1935. The billing type and payment method, including Prepaid and Postpaid,
  1936. need to be specified only when the instanceId is not empty and the corresponding instance type is prepaid.
  1937. If instanceId is empty:
  1938. create a post payment type CDS;
  1939. If the instanceId is not empty:
  1940. If the instance is prepaid, a chargeType needs to be specified;
  1941. If the instance is post paid, create a post paid CDS
  1942. :type charge_type: menu{'Prepaid', 'Postpaid'}
  1943. :return:
  1944. :rtype baidubce.bce_response.BceResponse
  1945. """
  1946. path = b'/volume'
  1947. params = {}
  1948. if client_token is None:
  1949. params['clientToken'] = generate_client_token()
  1950. else:
  1951. params['clientToken'] = client_token
  1952. if billing is None:
  1953. billing = default_billing_to_purchase_created
  1954. body = {
  1955. 'snapshotId': snapshot_id,
  1956. 'billing': billing.__dict__
  1957. }
  1958. if purchase_count is not None:
  1959. body['purchaseCount'] = purchase_count
  1960. if storage_type is not None:
  1961. body['storageType'] = storage_type
  1962. if zone_name is not None:
  1963. body['zoneName'] = zone_name
  1964. if renew_time_unit is not None:
  1965. body['renewTimeUnit'] = renew_time_unit
  1966. if renew_time is not None:
  1967. body['renewTime'] = renew_time
  1968. if cluster_id is not None:
  1969. body['clusterId'] = cluster_id
  1970. if relation_tag is not None:
  1971. body['relationTag'] = relation_tag
  1972. if tags is not None:
  1973. tag_list = [tag.__dict__ for tag in tags]
  1974. body['tags'] = tag_list
  1975. if auto_snapshot_policy is not None:
  1976. body['autoSnapshotPolicy'] = auto_snapshot_policy.__dict__
  1977. if name is not None:
  1978. body['name'] = name
  1979. if description is not None:
  1980. body['description'] = description
  1981. if encrypt_key is not None:
  1982. body['encryptKey'] = encrypt_key
  1983. if instance_id is not None:
  1984. body['instanceId'] = instance_id
  1985. if charge_type is not None:
  1986. body['chargeType'] = charge_type
  1987. return self._send_request(http_methods.POST, path, json.dumps(body),
  1988. params=params, config=config)
  1989. def list_volumes(self, instance_id=None, zone_name=None, marker=None, max_keys=None,
  1990. cluster_id=None,
  1991. volume_ids=None,
  1992. config=None):
  1993. """
  1994. Listing volumes owned by the authenticated user.
  1995. :param instance_id:
  1996. The id of instance. The optional parameter to list the volume.
  1997. If it's specified,only the volumes attached to the specified instance will be listed.
  1998. :type instance_id: string
  1999. :param zone_name:
  2000. The name of available zone. The optional parameter to list volumes
  2001. :type zone_name: string
  2002. :param marker:
  2003. The optional parameter marker specified in the original request to specify
  2004. where in the results to begin listing.
  2005. Together with the marker, specifies the list result which listing should begin.
  2006. If the marker is not specified, the list result will listing from the first one.
  2007. :type marker: string
  2008. :param max_keys:
  2009. The optional parameter to specifies the max number of list result to return.
  2010. The default value is 1000.
  2011. :type max_keys: int
  2012. :param cluster_id:
  2013. :type cluster_id: string
  2014. :param volume_ids:
  2015. :type volume_ids: string
  2016. :return:
  2017. :rtype baidubce.bce_response.BceResponse
  2018. """
  2019. path = b'/volume'
  2020. params = {}
  2021. if instance_id is not None:
  2022. params['instanceId'] = instance_id
  2023. if zone_name is not None:
  2024. params['zoneName'] = zone_name
  2025. if marker is not None:
  2026. params['marker'] = marker
  2027. if max_keys is not None:
  2028. params['maxKeys'] = max_keys
  2029. if cluster_id is not None:
  2030. params['clusterId'] = cluster_id
  2031. if volume_ids is not None:
  2032. params['volumeIds'] = volume_ids
  2033. return self._send_request(http_methods.GET, path, params=params, config=config)
  2034. @required(volume_id=(bytes, str)) # ***Unicode***
  2035. def get_volume(self, volume_id, config=None):
  2036. """
  2037. Get the detail information of specified volume.
  2038. :param volume_id:
  2039. The id of the volume.
  2040. :type volume_id: string
  2041. :return:
  2042. :rtype baidubce.bce_response.BceResponse
  2043. """
  2044. volume_id = compat.convert_to_bytes(volume_id)
  2045. path = b'/volume/%s' % volume_id
  2046. return self._send_request(http_methods.GET, path, config=config)
  2047. @required(volume_id=(bytes, str), # ***Unicode***
  2048. instance_id=(bytes, str)) # ***Unicode***
  2049. def attach_volume(self, volume_id, instance_id, config=None):
  2050. """
  2051. Attaching the specified volume to a specified instance.
  2052. You can attach the specified volume to a specified instance only
  2053. when the volume is Available and the instance is Running or Stopped,
  2054. otherwise, it's will get 409 errorCode.
  2055. :param volume_id:
  2056. The id of the volume which will be attached to specified instance.
  2057. :type volume_id: string
  2058. :param instance_id:
  2059. The id of the instance which will be attached with a volume.
  2060. :type instance_id: string
  2061. :return:
  2062. :rtype baidubce.bce_response.BceResponse
  2063. """
  2064. volume_id = compat.convert_to_bytes(volume_id)
  2065. path = b'/volume/%s' % volume_id
  2066. body = {
  2067. 'instanceId': instance_id
  2068. }
  2069. params = {
  2070. 'attach': None
  2071. }
  2072. return self._send_request(http_methods.PUT, path, json.dumps(body),
  2073. params=params, config=config)
  2074. @required(volume_id=(bytes, str), # ***Unicode***
  2075. instance_id=(bytes, str)) # ***Unicode***
  2076. def detach_volume(self, volume_id, instance_id, config=None):
  2077. """
  2078. Detaching the specified volume from a specified instance.
  2079. You can detach the specified volume from a specified instance only
  2080. when the instance is Running or Stopped ,
  2081. otherwise, it's will get 409 errorCode.
  2082. :param volume_id:
  2083. The id of the volume which will be attached to specified instance.
  2084. :type volume_id: string
  2085. :param instance_id:
  2086. The id of the instance which will be attached with a volume.
  2087. :type instance_id: string
  2088. :return:
  2089. :rtype baidubce.bce_response.BceResponse
  2090. """
  2091. volume_id = compat.convert_to_bytes(volume_id)
  2092. path = b'/volume/%s' % volume_id
  2093. body = {
  2094. 'instanceId': instance_id
  2095. }
  2096. params = {
  2097. 'detach': None
  2098. }
  2099. return self._send_request(http_methods.PUT, path, json.dumps(body),
  2100. params=params, config=config)
  2101. def describe_regions(self, region, config=None):
  2102. """
  2103. List all region's endpoint information with the specific parameters.
  2104. Use global endpoint bcc.baidubce.com to get BCC,CDS,ReservedInstance's endpoint.
  2105. :param region:
  2106. The id of region.
  2107. :type region: string
  2108. :return:
  2109. :rtype baidubce.bce_response.BceResponse
  2110. """
  2111. path = b'/region/describeRegions'
  2112. body = {
  2113. 'region': region
  2114. }
  2115. params = {}
  2116. return self._send_request(http_methods.POST, path, json.dumps(body),
  2117. params=params, config=config)
  2118. @required(volume_id=(bytes, str)) # ***Unicode***
  2119. def release_volume(self, volume_id, config=None):
  2120. """
  2121. Releasing the specified volume owned by the user.
  2122. You can release the specified volume only
  2123. when the instance is among state of Available/Expired/Error,
  2124. otherwise, it's will get 409 errorCode.
  2125. :param volume_id:
  2126. The id of the volume which will be released.
  2127. :type volume_id: string
  2128. :return:
  2129. :rtype baidubce.bce_response.BceResponse
  2130. """
  2131. volume_id = compat.convert_to_bytes(volume_id)
  2132. path = b'/volume/%s' % volume_id
  2133. return self._send_request(http_methods.DELETE, path, config=config)
  2134. @required(volume_id=(bytes, str), # ***Unicode***
  2135. new_cds_size=int)
  2136. def resize_volume(self, volume_id, new_cds_size, new_volume_type,
  2137. client_token=None, config=None):
  2138. """
  2139. Resizing the specified volume with newly size.
  2140. You can resize the specified volume only when the volume is Available,
  2141. otherwise, it's will get 409 errorCode.
  2142. The prepaid volume can not be downgrade.
  2143. This is an asynchronous interface,
  2144. you can get the latest status by BccClient.get_volume.
  2145. :param volume_id:
  2146. The id of volume which you want to resize.
  2147. :type volume_id: string
  2148. :param new_cds_size:
  2149. The new volume size you want to resize in GB.
  2150. :type new_cds_size: int
  2151. :param new_volume_type:
  2152. detail information see: https://cloud.baidu.com/doc/BCC/s/6jwvyo0q2#storagetype
  2153. :type new_volume_type: string
  2154. :param client_token:
  2155. An ASCII string whose length is less than 64.
  2156. The request will be idempotent if client token is provided.
  2157. If the clientToken is not specified by the user,
  2158. a random String generated by default algorithm will be used.
  2159. See more detail at
  2160. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  2161. :type client_token: string
  2162. :return:
  2163. :rtype baidubce.bce_response.BceResponse
  2164. """
  2165. volume_id = compat.convert_to_bytes(volume_id)
  2166. path = b'/volume/%s' % volume_id
  2167. body = {
  2168. 'newCdsSizeInGB': new_cds_size
  2169. }
  2170. if new_volume_type is not None:
  2171. body['newVolumeType'] = new_volume_type
  2172. params = None
  2173. if client_token is None:
  2174. params = {
  2175. 'resize': None,
  2176. 'clientToken': generate_client_token()
  2177. }
  2178. else:
  2179. params = {
  2180. 'resize': None,
  2181. 'clientToken': client_token
  2182. }
  2183. return self._send_request(http_methods.PUT, path, json.dumps(body),
  2184. params=params, config=config)
  2185. @required(volume_id=(bytes, str), # ***Unicode***
  2186. snapshot_id=(bytes, str)) # ***Unicode***
  2187. def rollback_volume(self, volume_id, snapshot_id, config=None):
  2188. """
  2189. Rollback the volume with the specified volume snapshot.
  2190. You can rollback the specified volume only when the volume is Available,
  2191. otherwise, it's will get 409 errorCode.
  2192. The snapshot used to rollback must be created by the volume,
  2193. otherwise,it's will get 404 errorCode.
  2194. If rolling back the system volume,the instance must be Running or Stopped,
  2195. otherwise, it's will get 409 errorCode.After rolling back the
  2196. volume,all the system disk data will erase.
  2197. :param volume_id:
  2198. The id of volume which will be rollback.
  2199. :type volume_id: string
  2200. :param snapshot_id:
  2201. The id of snapshot which will be used to rollback the volume.
  2202. :type snapshot_id: string
  2203. :return:
  2204. :rtype baidubce.bce_response.BceResponse
  2205. """
  2206. volume_id = compat.convert_to_bytes(volume_id)
  2207. path = b'/volume/%s' % volume_id
  2208. body = {
  2209. 'snapshotId': snapshot_id
  2210. }
  2211. params = {
  2212. 'rollback': None,
  2213. }
  2214. return self._send_request(http_methods.PUT, path, json.dumps(body),
  2215. params=params, config=config)
  2216. @required(volume_id=(bytes, str)) # ***Unicode***
  2217. def purchase_reserved_volume(self,
  2218. volume_id,
  2219. billing=None,
  2220. client_token=None,
  2221. config=None,
  2222. instance_id=None):
  2223. """
  2224. PurchaseReserved the instance with fixed duration.
  2225. You can not purchaseReserved the instance which is resizing.
  2226. This is an asynchronous interface,
  2227. you can get the latest status by BccClient.get_volume.
  2228. :param volume_id:
  2229. The id of volume which will be renew.
  2230. :type volume_id: string
  2231. :param billing:
  2232. Billing information.
  2233. :type billing: bcc_model.Billing
  2234. :param instance_id:
  2235. The id of instance to align renew duarion.
  2236. :param client_token:
  2237. An ASCII string whose length is less than 64.
  2238. The request will be idempotent if client token is provided.
  2239. If the clientToken is not specified by the user,
  2240. a random String generated by default algorithm will be used.
  2241. See more detail at
  2242. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  2243. :type client_token: string
  2244. :return:
  2245. :rtype baidubce.bce_response.BceResponse
  2246. """
  2247. volume_id = compat.convert_to_bytes(volume_id)
  2248. path = b'/volume/%s' % volume_id
  2249. if billing is None:
  2250. billing = default_billing_to_purchase_reserved
  2251. body = {
  2252. 'billing': billing.__dict__,
  2253. 'instanceId': instance_id
  2254. }
  2255. params = None
  2256. if client_token is None:
  2257. params = {
  2258. 'purchaseReserved': None,
  2259. 'clientToken': generate_client_token()
  2260. }
  2261. else:
  2262. params = {
  2263. 'purchaseReserved': None,
  2264. 'clientToken': client_token
  2265. }
  2266. return self._send_request(http_methods.PUT, path, json.dumps(body),
  2267. params=params, config=config)
  2268. @required(volume_id=(bytes, str),
  2269. cds_name=(bytes, str),
  2270. desc=(bytes, str))
  2271. def modify_volume_Attribute(self,
  2272. volume_id,
  2273. cds_name,
  2274. desc,
  2275. config=None):
  2276. """
  2277. :param volume_id:
  2278. :type volume_id: string
  2279. :param cds_name:
  2280. :type cds_name:string
  2281. :param desc:
  2282. :type desc: string
  2283. :return:
  2284. """
  2285. volume_id = compat.convert_to_bytes(volume_id)
  2286. path = b'/volume/%s' % volume_id
  2287. body = {
  2288. 'cdsName': cds_name
  2289. }
  2290. if desc is not None:
  2291. body['desc'] = desc
  2292. params = {
  2293. 'modify': None
  2294. }
  2295. return self._send_request(http_methods.PUT, path, json.dumps(body),
  2296. params=params, config=config)
  2297. @required(volume_id=(bytes, str))
  2298. def modify_volume_charge_type(self,
  2299. volume_id,
  2300. billing=None,
  2301. effective_type=None,
  2302. config=None):
  2303. """
  2304. :param volume_id: volume id
  2305. :type volume_id: string
  2306. :param billing: payment information
  2307. :type billing: bcc_model.Billing
  2308. :param effective_type: Optional parameters:
  2309. AtOnce (switch to pay-as-you-go immediately),
  2310. AfterExpiration (switch to pay-as-you-go after expiration).
  2311. Defaults to AfterExpiration if not provided.
  2312. :param config:
  2313. :return:
  2314. :rtype baidubce.bce_response.BceResponse
  2315. """
  2316. volume_id = compat.convert_to_bytes(volume_id)
  2317. path = b'/volume/%s' % volume_id
  2318. if billing is None:
  2319. billing = default_billing_to_purchase_reserved
  2320. body = {
  2321. 'effectiveType': effective_type,
  2322. 'billing': billing.__dict__
  2323. }
  2324. params = {
  2325. 'modifyChargeType': None
  2326. }
  2327. return self._send_request(http_methods.PUT, path, json.dumps(body),
  2328. params=params, config=config)
  2329. @required(image_name=(bytes, str), # ***Unicode***
  2330. instance_id=(bytes, str)) # ***Unicode***
  2331. def create_image_from_instance_id(self,
  2332. image_name,
  2333. instance_id,
  2334. encrypt_key=None,
  2335. relate_cds=False,
  2336. client_token=None,
  2337. config=None,
  2338. detection=None):
  2339. """
  2340. Creating a customized image which can be used for creating instance.
  2341. You can create an image from an instance with this method.
  2342. While creating an image from an instance, the instance must be Running or Stopped,
  2343. otherwise, it's will get 409 errorCode.
  2344. This is an asynchronous interface,
  2345. you can get the latest status by BccClient.get_image.
  2346. :param image_name:
  2347. The name for the image that will be created.
  2348. The name length from 1 to 65,only contains letters,digital and underline.
  2349. :type image_name: string
  2350. :param instance_id:
  2351. The optional parameter specify the id of the instance which will be used to create the new image.
  2352. When instanceId and snapshotId are specified ,only instanceId will be used.
  2353. :type instance_id: string
  2354. :param encrypt_key:
  2355. :type encrypt_key: string
  2356. :param relate_cds:
  2357. :type relate_cds: boolean
  2358. :param client_token:
  2359. An ASCII string whose length is less than 64.
  2360. The request will be idempotent if client token is provided.
  2361. If the clientToken is not specified by the user,
  2362. a random String generated by default algorithm will be used.
  2363. See more detail at
  2364. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  2365. :type client_token: string
  2366. :return:
  2367. :rtype baidubce.bce_response.BceResponse
  2368. """
  2369. path = b'/image'
  2370. params = None
  2371. if client_token is None:
  2372. params = {
  2373. 'clientToken': generate_client_token()
  2374. }
  2375. else:
  2376. params = {
  2377. 'clientToken': client_token
  2378. }
  2379. body = {
  2380. 'imageName': image_name,
  2381. 'instanceId': instance_id
  2382. }
  2383. if encrypt_key is not None:
  2384. body['encryptKey'] = encrypt_key
  2385. if relate_cds is not None:
  2386. body['relateCds'] = relate_cds
  2387. if detection:
  2388. body['detection'] = detection
  2389. return self._send_request(http_methods.POST, path, json.dumps(body),
  2390. params=params, config=config)
  2391. @required(image_name=(bytes, str), # ***Unicode***
  2392. snapshot_id=(bytes, str)) # ***Unicode***
  2393. def create_image_from_snapshot_id(self,
  2394. image_name,
  2395. snapshot_id,
  2396. encrypt_key=None,
  2397. client_token=None,
  2398. config=None,
  2399. detection=None):
  2400. """
  2401. Creating a customized image which can be used for creating instance.
  2402. You can create an image from an snapshot with tihs method.
  2403. You can create the image only from system snapshot.
  2404. While creating an image from a system snapshot,the snapshot must be Available,
  2405. otherwise, it's will get 409 errorCode.
  2406. This is an asynchronous interface,
  2407. you can get the latest status by BccClient.get_image.
  2408. :param image_name:
  2409. The name for the image that will be created.
  2410. The name length from 1 to 65,only contains letters,digital and underline.
  2411. :type image_name: string
  2412. :param snapshot_id:
  2413. The optional parameter specify the id of the snapshot which will be used to create the new image.
  2414. When instanceId and snapshotId are specified ,only instanceId will be used.
  2415. :type snapshot_id: string
  2416. :param encrypt_key:
  2417. :type encrypt_key: string
  2418. :param client_token:
  2419. An ASCII string whose length is less than 64.
  2420. The request will be idempotent if client token is provided.
  2421. If the clientToken is not specified by the user,
  2422. a random String generated by default algorithm will be used.
  2423. See more detail at
  2424. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  2425. :type client_token: string
  2426. :return:
  2427. :rtype baidubce.bce_response.BceResponse
  2428. """
  2429. path = b'/image'
  2430. params = {}
  2431. if client_token is None:
  2432. params['clientToken'] = generate_client_token()
  2433. else:
  2434. params['clientToken'] = client_token
  2435. body = {
  2436. 'imageName': image_name,
  2437. 'snapshotId': snapshot_id
  2438. }
  2439. if encrypt_key is not None:
  2440. body['encryptKey'] = encrypt_key
  2441. if detection:
  2442. body['detection'] = detection
  2443. return self._send_request(http_methods.POST, path, json.dumps(body),
  2444. params=params, config=config)
  2445. def list_images(self, image_type='All', marker=None, max_keys=None, image_name=None,
  2446. config=None):
  2447. """
  2448. Listing images owned by the authenticated user.
  2449. :param image_type:
  2450. The optional parameter to filter image to list.
  2451. See more detail at
  2452. https://bce.baidu.com/doc/BCC/API.html#ImageType"
  2453. :type image_type: menu{'All', System', 'Custom', 'Integration'}
  2454. :param marker:
  2455. The optional parameter marker specified in the original request to specify
  2456. where in the results to begin listing.
  2457. Together with the marker, specifies the list result which listing should begin.
  2458. If the marker is not specified, the list result will listing from the first one.
  2459. :type marker: string
  2460. :param max_keys:
  2461. The optional parameter to specifies the max number of list result to return.
  2462. The default value is 1000.
  2463. :type max_keys: int
  2464. :param image_name:
  2465. The optional parameter to query specified custom image by image name.
  2466. :type image_name: string
  2467. :return:
  2468. :rtype baidubce.bce_response.BceResponse
  2469. """
  2470. path = b'/image'
  2471. params = {
  2472. 'imageType': image_type
  2473. }
  2474. if marker is not None:
  2475. params['marker'] = marker
  2476. if max_keys is not None:
  2477. params['maxKeys'] = max_keys
  2478. if image_name is not None:
  2479. params['imageName'] = image_name
  2480. return self._send_request(http_methods.GET, path, params=params, config=config)
  2481. @required(image_id=(bytes, str)) # ***Unicode***
  2482. def get_image(self, image_id, config=None):
  2483. """
  2484. Get the detail information of specified image.
  2485. :param image_id:
  2486. The id of image.
  2487. :type image_id: string
  2488. :return:
  2489. :rtype baidubce.bce_response.BceResponse
  2490. """
  2491. image_id = compat.convert_to_bytes(image_id)
  2492. path = b'/image/%s' % image_id
  2493. return self._send_request(http_methods.GET, path, config=config)
  2494. @required(image_id=(bytes, str)) # ***Unicode***
  2495. def delete_image(self, image_id, config=None):
  2496. """
  2497. Deleting the specified image.
  2498. Only the customized image can be deleted,
  2499. otherwise, it's will get 403 errorCode.
  2500. :param image_id:
  2501. The id of image.
  2502. :type image_id: string
  2503. :return:
  2504. :rtype baidubce.bce_response.BceResponse
  2505. """
  2506. image_id = compat.convert_to_bytes(image_id)
  2507. path = b'/image/%s' % image_id
  2508. return self._send_request(http_methods.DELETE, path, config=config)
  2509. @required(image_id=(bytes, str),
  2510. name=(bytes, str),
  2511. destRegions=list)
  2512. def remote_copy_image(self,
  2513. image_id,
  2514. name,
  2515. destRegions,
  2516. config=None):
  2517. """
  2518. :param image_id:
  2519. :param name:
  2520. :param destRegions:
  2521. :param config:
  2522. :return:
  2523. """
  2524. image_id = compat.convert_to_bytes(image_id)
  2525. path = b'/image/%s' % image_id
  2526. body = {
  2527. 'name': name,
  2528. 'destRegion': destRegions
  2529. }
  2530. params = {
  2531. 'remoteCopy': None
  2532. }
  2533. return self._send_request(http_methods.POST, path, json.dumps(body),
  2534. params=params, config=config)
  2535. @required(image_id=(bytes, str))
  2536. def cancle_remote_copy_image(self,
  2537. image_id,
  2538. config=None):
  2539. """
  2540. :param image_id:
  2541. :param config:
  2542. :return:
  2543. """
  2544. image_id = compat.convert_to_bytes(image_id)
  2545. path = b'/image/%s' % image_id
  2546. params = {
  2547. 'cancelRemoteCopy': None
  2548. }
  2549. return self._send_request(http_methods.POST, path, params=params, config=config)
  2550. @required(image_id=(bytes, str))
  2551. def share_image(self,
  2552. image_id,
  2553. account=None,
  2554. account_id=None,
  2555. ucaccount=None,
  2556. config=None):
  2557. """
  2558. :param image_id: image id
  2559. :type image_id: string
  2560. :param account: share image to target account
  2561. :type account: string
  2562. :param account_id: share image to target account_id
  2563. :type account_id: string
  2564. :param ucaccount: share image to target ucaccount
  2565. :type ucaccount: string
  2566. :param config:
  2567. :return:
  2568. :rtype baidubce.bce_response.BceResponse
  2569. """
  2570. image_id = compat.convert_to_bytes(image_id)
  2571. path = b'/image/%s' % image_id
  2572. body = {}
  2573. if account is not None:
  2574. body['account'] = account
  2575. if account_id is not None:
  2576. body['accountId'] = account_id
  2577. if ucaccount is not None:
  2578. body['ucAccount'] = ucaccount
  2579. params = {
  2580. 'share': None
  2581. }
  2582. return self._send_request(http_methods.POST, path, json.dumps(body),
  2583. params=params, config=config)
  2584. @required(image_id=(bytes, str))
  2585. def unshare_image(self,
  2586. image_id,
  2587. account=None,
  2588. account_id=None,
  2589. ucaccount=None,
  2590. config=None):
  2591. """
  2592. :param image_id: image id
  2593. :type image_id: string
  2594. :param account: unshare image with target account
  2595. :type account: string
  2596. :param account_id: unshare image with target account_id
  2597. :type account_id: string
  2598. :param ucaccount: unshare image with target ucaccount
  2599. :type ucaccount: string
  2600. :param config:
  2601. :return:
  2602. :rtype baidubce.bce_response.BceResponse
  2603. """
  2604. image_id = compat.convert_to_bytes(image_id)
  2605. path = b'/image/%s' % image_id
  2606. body = {}
  2607. if account is not None:
  2608. body['account'] = account
  2609. if account_id is not None:
  2610. body['accountId'] = account_id
  2611. if ucaccount is not None:
  2612. body['ucAccount'] = ucaccount
  2613. params = {
  2614. 'unshare': None
  2615. }
  2616. return self._send_request(http_methods.POST, path, json.dumps(body),
  2617. params=params, config=config)
  2618. @required(image_id=(bytes, str))
  2619. def list_shared_user(self,
  2620. image_id,
  2621. config=None):
  2622. """
  2623. :param image_id:
  2624. :param config:
  2625. :return:
  2626. """
  2627. image_id = compat.convert_to_bytes(image_id)
  2628. path = b'/image/%s/sharedUsers' % image_id
  2629. return self._send_request(http_methods.GET, path, config=config)
  2630. @required(instance_ids=list)
  2631. def list_os(self,
  2632. instance_ids=None,
  2633. config=None):
  2634. """
  2635. :param instance_ids:
  2636. :param config:
  2637. :return:
  2638. """
  2639. path = b'/image/os'
  2640. instance_id_list = instance_ids
  2641. body = {
  2642. 'instanceIds': instance_id_list
  2643. }
  2644. return self._send_request(http_methods.POST, path, json.dumps(body), config=config)
  2645. @required(volume_id=(bytes, str), # ***Unicode***
  2646. snapshot_name=(bytes, str)) # ***Unicode***
  2647. def create_snapshot(self,
  2648. volume_id,
  2649. snapshot_name,
  2650. desc=None,
  2651. tags=None,
  2652. client_token=None,
  2653. config=None):
  2654. """
  2655. Creating snapshot from specified volume.
  2656. You can create snapshot from system volume and CDS volume.
  2657. While creating snapshot from system volume,the instance must be Running or Stopped,
  2658. otherwise, it's will get 409 errorCode.
  2659. While creating snapshot from CDS volume, the volume must be InUs or Available,
  2660. otherwise, it's will get 409 errorCode.
  2661. This is an asynchronous interface,
  2662. you can get the latest status by BccClient.get_snapshot.
  2663. :param volume_id:
  2664. The id which specify where the snapshot will be created from.
  2665. If you want to create an snapshot from a customized volume, a id of the volume will be set.
  2666. If you want to create an snapshot from a system volume, a id of the instance will be set.
  2667. :type volume_id: string
  2668. :param snapshot_name:
  2669. The name for the snapshot that will be created.
  2670. The name length from 1 to 65,only contains letters,digital and underline.
  2671. :type snapshot_name: string
  2672. :param desc:
  2673. The optional parameter to describe the information of the new snapshot.
  2674. :type desc: string
  2675. :param tags:
  2676. The optional list of tag to be bonded.
  2677. :type tags: list<bcc_model.TagModel>
  2678. :param client_token:
  2679. An ASCII string whose length is less than 64.
  2680. The request will be idempotent if client token is provided.
  2681. If the clientToken is not specified by the user,
  2682. a random String generated by default algorithm will be used.
  2683. See more detail at
  2684. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  2685. :type client_token: string
  2686. :return:
  2687. :rtype baidubce.bce_response.BceResponse
  2688. """
  2689. path = b'/snapshot'
  2690. params = None
  2691. if client_token is None:
  2692. params = {
  2693. 'clientToken': generate_client_token()
  2694. }
  2695. else:
  2696. params = {
  2697. 'clientToken': client_token
  2698. }
  2699. body = {
  2700. 'volumeId': volume_id,
  2701. 'snapshotName': snapshot_name
  2702. }
  2703. if desc is not None:
  2704. body['desc'] = desc
  2705. if tags is not None:
  2706. tag_list = [tag.__dict__ for tag in tags]
  2707. body['tags'] = tag_list
  2708. return self._send_request(http_methods.POST, path, json.dumps(body),
  2709. params=params, config=config)
  2710. def list_snapshots(self, marker=None, max_keys=None, volume_id=None, config=None):
  2711. """
  2712. List snapshots
  2713. :param marker:
  2714. The optional parameter marker specified in the original request to specify
  2715. where in the results to begin listing.
  2716. Together with the marker, specifies the list result which listing should begin.
  2717. If the marker is not specified, the list result will listing from the first one.
  2718. :type params: string
  2719. :param max_keys:
  2720. The optional parameter to specifies the max number of list result to return.
  2721. The default value is 1000.
  2722. :type params: int
  2723. :param volume_id:
  2724. The id of the volume.
  2725. :type volume_id: string
  2726. :return:
  2727. :rtype baidubce.bce_response.BceResponse
  2728. """
  2729. path = b'/snapshot'
  2730. params = None
  2731. if marker is not None or max_keys is not None or volume_id is not None:
  2732. params = {}
  2733. if marker is not None:
  2734. params['marker'] = marker
  2735. if max_keys is not None:
  2736. params['maxKeys'] = max_keys
  2737. if volume_id is not None:
  2738. params['volumeId'] = volume_id
  2739. return self._send_request(http_methods.GET, path, params=params, config=config)
  2740. @required(snapshot_id=(bytes, str)) # ***Unicode***
  2741. def get_snapshot(self, snapshot_id, config=None):
  2742. """
  2743. Get the detail information of specified snapshot.
  2744. :param snapshot_id:
  2745. The id of snapshot.
  2746. :type snapshot_id: string
  2747. :return:
  2748. :rtype baidubce.bce_response.BceResponse
  2749. """
  2750. snapshot_id = compat.convert_to_bytes(snapshot_id)
  2751. path = b'/snapshot/%s' % snapshot_id
  2752. return self._send_request(http_methods.GET, path, config=config)
  2753. @required(snapshot_id=(bytes, str)) # ***Unicode***
  2754. def delete_snapshot(self, snapshot_id, config=None):
  2755. """
  2756. Deleting the specified snapshot.
  2757. Only when the snapshot is CreatedFailed or Available,the specified snapshot can be deleted.
  2758. otherwise, it's will get 403 errorCode.
  2759. :param snapshot_id:
  2760. The id of snapshot.
  2761. :type snapshot_id: string
  2762. :return:
  2763. :rtype baidubce.bce_response.BceResponse
  2764. """
  2765. snapshot_id = compat.convert_to_bytes(snapshot_id)
  2766. path = b'/snapshot/%s' % snapshot_id
  2767. return self._send_request(http_methods.DELETE, path, config=config)
  2768. @required(name=(bytes, str), # ***Unicode***
  2769. rules=list)
  2770. def create_security_group(self,
  2771. name,
  2772. rules,
  2773. vpc_id=None,
  2774. desc=None,
  2775. client_token=None,
  2776. tags=None,
  2777. config=None):
  2778. """
  2779. Creating a newly SecurityGroup with specified rules.
  2780. :param name:
  2781. The name of SecurityGroup that will be created.
  2782. :type name: string
  2783. :param rules:
  2784. The list of rules which define how the SecurityGroup works.
  2785. :type rules: list<bcc_model.SecurityGroupRuleModel>
  2786. :param vpc_id:
  2787. The optional parameter to specify the id of VPC to SecurityGroup
  2788. :type vpc_id: string
  2789. :param desc:
  2790. The optional parameter to describe the SecurityGroup that will be created.
  2791. :type desc: string
  2792. :param tags:
  2793. The optional list of tag to be bonded.
  2794. :type tags: list<bcc_model.TagModel>
  2795. :param client_token:
  2796. An ASCII string whose length is less than 64.
  2797. The request will be idempotent if client token is provided.
  2798. If the clientToken is not specified by the user,
  2799. a random String generated by default algorithm will be used.
  2800. See more detail at
  2801. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  2802. :type client_token: string
  2803. :return:
  2804. :rtype baidubce.bce_response.BceResponse
  2805. """
  2806. path = b'/securityGroup'
  2807. params = None
  2808. if client_token is None:
  2809. params = {
  2810. 'clientToken': generate_client_token()
  2811. }
  2812. else:
  2813. params = {
  2814. 'clientToken': client_token
  2815. }
  2816. rule_list = [rule.__dict__ for rule in rules]
  2817. body = {
  2818. 'name': name,
  2819. 'rules': rule_list
  2820. }
  2821. if vpc_id is not None:
  2822. body['vpcId'] = vpc_id
  2823. if desc is not None:
  2824. body['desc'] = desc
  2825. if tags is not None:
  2826. tag_list = [tag.__dict__ for tag in tags]
  2827. body['tags'] = tag_list
  2828. return self._send_request(http_methods.POST, path, json.dumps(body),
  2829. params=params, config=config)
  2830. def list_security_groups(self, instance_id=None, vpc_id=None, security_group_ids=None, marker=None, max_keys=None,
  2831. config=None):
  2832. """
  2833. Listing SecurityGroup owned by the authenticated user.
  2834. :param instance_id:
  2835. The id of instance. The optional parameter to list the SecurityGroup.
  2836. If it's specified,only the SecurityGroup related to the specified instance will be listed
  2837. :type instance_id: string
  2838. :param vpc_id:
  2839. filter by vpcId, optional parameter
  2840. :type vpc_id: string
  2841. :param security_group_ids:
  2842. filter by securityGroupIds, optional parameter
  2843. :type security_group_ids: string
  2844. :param marker:
  2845. The optional parameter marker specified in the original request to specify
  2846. where in the results to begin listing.
  2847. Together with the marker, specifies the list result which listing should begin.
  2848. If the marker is not specified, the list result will listing from the first one.
  2849. :type marker: string
  2850. :param max_keys:
  2851. The optional parameter to specifies the max number of list result to return.
  2852. The default value is 1000.
  2853. :type max_keys: int
  2854. :return:
  2855. :rtype baidubce.bce_response.BceResponse
  2856. """
  2857. path = b'/securityGroup'
  2858. params = {}
  2859. if instance_id is not None:
  2860. params['instanceId'] = instance_id
  2861. if vpc_id is not None:
  2862. params['vpcId'] = vpc_id
  2863. if security_group_ids is not None:
  2864. params['securityGroupIds'] = security_group_ids
  2865. if marker is not None:
  2866. params['marker'] = marker
  2867. if max_keys is not None:
  2868. params['maxKeys'] = max_keys
  2869. return self._send_request(http_methods.GET, path,
  2870. params=params, config=config)
  2871. @required(security_group_id=(bytes, str)) # ***Unicode***
  2872. def delete_security_group(self, security_group_id, config=None):
  2873. """
  2874. Deleting the specified SecurityGroup.
  2875. :param security_group_id:
  2876. The id of SecurityGroup that will be deleted.
  2877. :type security_group_id: string
  2878. :return:
  2879. :rtype baidubce.bce_response.BceResponse
  2880. """
  2881. security_group_id = compat.convert_to_bytes(security_group_id)
  2882. path = b'/securityGroup/%s' % security_group_id
  2883. return self._send_request(http_methods.DELETE, path, config=config)
  2884. @required(security_group_id=(bytes, str), # ***Unicode***
  2885. rule=bcc_model.SecurityGroupRuleModel)
  2886. def authorize_security_group_rule(self, security_group_id, rule, client_token=None,
  2887. config=None):
  2888. """
  2889. authorize a security group rule to the specified security group
  2890. :param security_group_id:
  2891. The id of SecurityGroup that will be authorized.
  2892. :type security_group_id: string
  2893. :param rule:
  2894. security group rule detail.
  2895. Through protocol/portRange/direction/sourceIp/sourceGroupId, we can confirmed only one rule.
  2896. :type rule: bcc_model.SecurityGroupRuleModel
  2897. :param client_token:
  2898. An ASCII string whose length is less than 64.
  2899. The request will be idempotent if client token is provided.
  2900. If the clientToken is not specified by the user,
  2901. a random String generated by default algorithm will be used.
  2902. See more detail at
  2903. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  2904. :type client_token: string
  2905. :return:
  2906. :rtype baidubce.bce_response.BceResponse
  2907. """
  2908. security_group_id = compat.convert_to_bytes(security_group_id)
  2909. path = b'/securityGroup/%s' % security_group_id
  2910. params = {'authorizeRule': ''}
  2911. if client_token is None:
  2912. params['clientToken'] = generate_client_token()
  2913. else:
  2914. params['clientToken'] = client_token
  2915. body = {
  2916. 'rule': rule.__dict__
  2917. }
  2918. return self._send_request(http_methods.PUT, path, json.dumps(body),
  2919. params=params, config=config)
  2920. @required(security_group_id=(bytes, str), # ***Unicode***
  2921. rule=bcc_model.SecurityGroupRuleModel)
  2922. def revoke_security_group_rule(self, security_group_id, rule, client_token=None, config=None):
  2923. """
  2924. revoke a security group rule from the specified security group
  2925. :param security_group_id:
  2926. The id of SecurityGroup that will be revoked.
  2927. :type security_group_id: string
  2928. :param rule:
  2929. security group rule detail.
  2930. Through protocol/portRange/direction/sourceIp/sourceGroupId, we can confirmed only one rule.
  2931. :type rule: bcc_model.SecurityGroupRuleModel
  2932. :param client_token:
  2933. An ASCII string whose length is less than 64.
  2934. The request will be idempotent if client token is provided.
  2935. If the clientToken is not specified by the user,
  2936. a random String generated by default algorithm will be used.
  2937. See more detail at
  2938. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  2939. :type client_token: string
  2940. :return:
  2941. :rtype baidubce.bce_response.BceResponse
  2942. """
  2943. security_group_id = compat.convert_to_bytes(security_group_id)
  2944. path = b'/securityGroup/%s' % security_group_id
  2945. params = {'revokeRule': ''}
  2946. if client_token is None:
  2947. params['clientToken'] = generate_client_token()
  2948. else:
  2949. params['clientToken'] = client_token
  2950. body = {
  2951. 'rule': rule.__dict__
  2952. }
  2953. return self._send_request(http_methods.PUT, path, json.dumps(body),
  2954. params=params, config=config)
  2955. def update_security_group_rule(self, security_group_rule_id,
  2956. remark=None,
  2957. direction=None,
  2958. protocol=None,
  2959. portrange=None,
  2960. source_ip=None,
  2961. sourcegroup_id=None,
  2962. dest_ip=None,
  2963. destgroup_id=None,
  2964. config=None):
  2965. """
  2966. uodate a security group rule from the specified security group
  2967. :param security_group_rule_id:
  2968. security group rule id.
  2969. :param: remark:
  2970. The remark for the rule.
  2971. :param: portrange:
  2972. The port range to specify the port which the rule will work on.
  2973. Available range is rang [0, 65535], the fault value is "" for all port.
  2974. :param: protocol:
  2975. The parameter specify which protocol will the rule work on, the fault value is "" for all protocol.
  2976. Available protocol are tcp, udp and icmp.
  2977. :param: source_ip:
  2978. The source ip range with CIDR formats. The default value 0.0.0.0/0 (allow all ip address),
  2979. other supported formats such as {ip_addr}/12 or {ip_addr}. Only supports IPV4.
  2980. Only works for direction = "ingress".
  2981. :param: sourcegroup_id:
  2982. The source security group id. Cannot coexist with sourceIP.
  2983. :param: dest_ip:
  2984. The destination ip range with CIDR formats. The default value 0.0.0.0/0 (allow all ip address),
  2985. other supported formats such as {ip_addr}/12 or {ip_addr}. Only supports IPV4.
  2986. Only works for direction = "egress".
  2987. :param: destgroup_id:
  2988. The destination security group id. Cannot coexist with destIP.
  2989. :param: priority:
  2990. The parameter specify the priority of the rule(range 1-1000).
  2991. :param config:
  2992. :type config: baidubce.BceClientConfiguration
  2993. :return:
  2994. :rtype baidubce.bce_response.BceResponse
  2995. """
  2996. path = b'/securityGroup/rule/update'
  2997. body = {
  2998. 'securityGroupRuleId': security_group_rule_id,
  2999. 'remark': remark,
  3000. 'direction': direction,
  3001. 'protocol': protocol,
  3002. 'portRange': portrange,
  3003. 'sourceIp': source_ip,
  3004. 'sourceGroupId': sourcegroup_id,
  3005. 'destIp': dest_ip,
  3006. 'destGroupId': destgroup_id
  3007. }
  3008. return self._send_request(http_methods.PUT, path, json.dumps(body),
  3009. params=None, config=config)
  3010. @required(security_group_rule_id=(bytes, str)) # ***Unicode***
  3011. def delete_security_group_rule(self, security_group_rule_id, config=None):
  3012. """
  3013. delete a security group rule from the specified security group
  3014. :param security_group_rule_id:
  3015. The id of SecurityGroupRule that will be deleted.
  3016. :type security_group_id: string
  3017. :param config:
  3018. :type config: baidubce.BceClientConfiguration
  3019. :return:
  3020. :rtype baidubce.bce_response.BceResponse
  3021. """
  3022. security_group_rule_id = compat.convert_to_bytes(security_group_rule_id)
  3023. path = b'/securityGroup/rule/%s' % security_group_rule_id
  3024. return self._send_request(http_methods.DELETE, path, params=None, config=config)
  3025. @required(security_group_id=(bytes, str)) # ***Unicode***
  3026. def get_security_group_detail(self, security_group_id, config=None):
  3027. """
  3028. get a security group detail from the specified security group
  3029. :param security_group_id:
  3030. The id of security_group that will be deleted.
  3031. :type security_group_id: string
  3032. :param config:
  3033. :type config: baidubce.BceClientConfiguration
  3034. :return:
  3035. :rtype baidubce.bce_response.BceResponse
  3036. """
  3037. security_group_id = compat.convert_to_bytes(security_group_id)
  3038. path = b'/securityGroup/%s' % security_group_id
  3039. return self._send_request(http_methods.GET, path, params=None, config=config)
  3040. def list_zones(self, config=None):
  3041. """
  3042. Get zone detail list within current region
  3043. :param config:
  3044. :return:
  3045. """
  3046. path = b'/zone'
  3047. return self._send_request(http_methods.GET, path, config=config)
  3048. @required(asp_name=(bytes, str),
  3049. time_points=list,
  3050. repeat_week_days=list,
  3051. retention_days=(bytes, str))
  3052. def create_asp(self,
  3053. asp_name=None,
  3054. time_points=None,
  3055. repeat_week_days=None,
  3056. retention_days=None,
  3057. client_token=None,
  3058. config=None):
  3059. """
  3060. :param asp_name:
  3061. :param time_points:
  3062. :param repeat_week_days:
  3063. :param retention_days:
  3064. :param client_token:
  3065. :param config:
  3066. :return:
  3067. """
  3068. path = b'/asp'
  3069. params = None
  3070. if client_token is None:
  3071. params = {
  3072. 'clientToken': generate_client_token()
  3073. }
  3074. else:
  3075. params = {
  3076. 'clientToken': client_token
  3077. }
  3078. body = {
  3079. 'name': asp_name,
  3080. 'timePoints': time_points,
  3081. 'repeatWeekdays': repeat_week_days,
  3082. 'retentionDays': retention_days
  3083. }
  3084. return self._send_request(http_methods.POST, path, json.dumps(body),
  3085. params=params, config=config)
  3086. @required(asp_id=(bytes, str),
  3087. volume_ids=list)
  3088. def attach_asp(self,
  3089. asp_id=None,
  3090. volume_ids=None,
  3091. config=None):
  3092. """
  3093. :param asp_id:
  3094. :param volume_ids:
  3095. :param config:
  3096. :return:
  3097. """
  3098. asp_id = compat.convert_to_bytes(asp_id)
  3099. path = b'/asp/%s' % asp_id
  3100. body = {
  3101. 'volumeIds': volume_ids
  3102. }
  3103. params = {
  3104. 'attach': None
  3105. }
  3106. return self._send_request(http_methods.PUT, path, json.dumps(body),
  3107. params=params, config=config)
  3108. @required(asp_id=(bytes, str),
  3109. volume_ids=list)
  3110. def detach_asp(self,
  3111. asp_id=None,
  3112. volume_ids=None,
  3113. config=None):
  3114. """
  3115. :param asp_id:
  3116. :param volume_ids:
  3117. :param config:
  3118. :return:
  3119. """
  3120. asp_id = compat.convert_to_bytes(asp_id)
  3121. path = b'/asp/%s' % asp_id
  3122. body = {
  3123. 'volumeIds': volume_ids
  3124. }
  3125. params = {
  3126. 'detach': None
  3127. }
  3128. return self._send_request(http_methods.PUT, path, json.dumps(body),
  3129. params=params, config=config)
  3130. @required(asp_id=(bytes, str))
  3131. def delete_asp(self,
  3132. asp_id=None,
  3133. config=None):
  3134. """
  3135. :param asp_id:
  3136. :param config:
  3137. :return:
  3138. """
  3139. asp_id = compat.convert_to_bytes(asp_id)
  3140. path = b'/asp/%s' % asp_id
  3141. return self._send_request(http_methods.DELETE, path, config=config)
  3142. def list_asps(self, marker=None, max_keys=None, asp_name=None, volume_name=None, config=None):
  3143. """
  3144. :param marker:
  3145. :param max_keys:
  3146. :param asp_name:
  3147. :param volume_name:
  3148. :param config:
  3149. :return:
  3150. """
  3151. path = b'/asp'
  3152. params = None
  3153. if marker is not None or max_keys is not None or asp_name is not None or volume_name is not None:
  3154. params = {}
  3155. if marker is not None:
  3156. params['marker'] = marker
  3157. if max_keys is not None:
  3158. params['maxKeys'] = max_keys
  3159. if asp_name is not None:
  3160. params['aspName'] = asp_name
  3161. if volume_name is not None:
  3162. params['volumeName'] = volume_name
  3163. return self._send_request(http_methods.GET, path, params=params, config=config)
  3164. @required(asp_id=(bytes, str))
  3165. def get_asp(self, asp_id=None, config=None):
  3166. """
  3167. :param asp_id:
  3168. :param config:
  3169. :return:
  3170. """
  3171. asp_id = compat.convert_to_bytes(asp_id)
  3172. path = b'/asp/%s' % asp_id
  3173. return self._send_request(http_methods.GET, path, config=config)
  3174. @required(keypair_name=(bytes, str))
  3175. def create_keypair(self,
  3176. keypair_name=None,
  3177. keypair_desc=None,
  3178. config=None):
  3179. """
  3180. :param keypair_name:
  3181. :param keypair_desc:
  3182. :param config:
  3183. :return:
  3184. """
  3185. path = b'/keypair'
  3186. body = {
  3187. 'name': keypair_name,
  3188. 'description': keypair_desc
  3189. }
  3190. params = {
  3191. 'create': None
  3192. }
  3193. return self._send_request(http_methods.POST, path, json.dumps(body),
  3194. params=params, config=config)
  3195. @required(keypair_name=(bytes, str),
  3196. public_key=(bytes, str))
  3197. def import_keypair(self,
  3198. keypair_name=None,
  3199. keypair_desc=None,
  3200. public_key=None,
  3201. config=None):
  3202. """
  3203. :param keypair_name:
  3204. :param keypair_desc:
  3205. :param public_key:
  3206. :param config:
  3207. :return:
  3208. """
  3209. path = b'/keypair'
  3210. body = {
  3211. 'name': keypair_name,
  3212. 'publicKey': public_key
  3213. }
  3214. if keypair_desc is not None:
  3215. body['description'] = keypair_desc
  3216. params = {
  3217. 'import': None
  3218. }
  3219. return self._send_request(http_methods.PUT, path, json.dumps(body),
  3220. params=params, config=config)
  3221. def list_keypairs(self, marker=None, max_keys=None, name=None, config=None):
  3222. """
  3223. :param marker:
  3224. :param max_keys:
  3225. :param config:
  3226. :return:
  3227. """
  3228. path = b'/keypair'
  3229. params = None
  3230. if marker is not None or max_keys is not None or name is not None:
  3231. params = {}
  3232. if marker is not None:
  3233. params['marker'] = marker
  3234. if max_keys is not None:
  3235. params['maxKeys'] = max_keys
  3236. if name is not None:
  3237. params['name'] = name
  3238. return self._send_request(http_methods.GET, path, params=params, config=config)
  3239. @required(keypair_id=(bytes, str))
  3240. def get_keypair(self, keypair_id=None, config=None):
  3241. """
  3242. :param keypair_id:
  3243. :param config:
  3244. :return:
  3245. """
  3246. keypair_id = compat.convert_to_bytes(keypair_id)
  3247. path = b'/keypair/%s' % keypair_id
  3248. return self._send_request(http_methods.GET, path, config=config)
  3249. @required(keypair_id=(bytes, str),
  3250. instance_ids=list)
  3251. def attach_keypair(self,
  3252. keypair_id=None,
  3253. instance_ids=None,
  3254. config=None):
  3255. """
  3256. :param keypair_id:
  3257. :param instance_ids:
  3258. :param config:
  3259. :return:
  3260. """
  3261. keypair_id = compat.convert_to_bytes(keypair_id)
  3262. path = b'/keypair/%s' % keypair_id
  3263. body = {
  3264. 'instanceIds': instance_ids
  3265. }
  3266. params = {
  3267. 'attach': None
  3268. }
  3269. return self._send_request(http_methods.PUT, path, json.dumps(body),
  3270. params=params, config=config)
  3271. @required(keypair_id=(bytes, str),
  3272. instance_id=list)
  3273. def detach_keypair(self,
  3274. keypair_id=None,
  3275. instance_ids=None,
  3276. config=None):
  3277. """
  3278. :param keypair_id:
  3279. :param instance_ids:
  3280. :param config:
  3281. :return:
  3282. """
  3283. keypair_id = compat.convert_to_bytes(keypair_id)
  3284. path = b'/keypair/%s' % keypair_id
  3285. body = {
  3286. 'instanceIds': instance_ids
  3287. }
  3288. params = {
  3289. 'detach': None
  3290. }
  3291. return self._send_request(http_methods.PUT, path, json.dumps(body),
  3292. params=params, config=config)
  3293. @required(keypair_id=(bytes, str))
  3294. def delete_keypair(self,
  3295. keypair_id=None,
  3296. config=None):
  3297. """
  3298. :param keypair_id:
  3299. :param config:
  3300. :return:
  3301. """
  3302. keypair_id = compat.convert_to_bytes(keypair_id)
  3303. path = b'/keypair/%s' % keypair_id
  3304. return self._send_request(http_methods.DELETE, path, config=config)
  3305. @required(keypair_id=(bytes, str),
  3306. keypair_name=(bytes, str))
  3307. def rename_keypair(self,
  3308. keypair_id=None,
  3309. keypair_name=None,
  3310. config=None):
  3311. """
  3312. :param keypair_id:
  3313. :param keypair_name:
  3314. :param config:
  3315. :return:
  3316. """
  3317. keypair_id = compat.convert_to_bytes(keypair_id)
  3318. path = b'/keypair/%s' % keypair_id
  3319. body = {
  3320. 'name': keypair_name
  3321. }
  3322. params = {
  3323. 'rename': None
  3324. }
  3325. return self._send_request(http_methods.PUT, path, json.dumps(body),
  3326. params=params, config=config)
  3327. @required(keypair_id=(bytes, str),
  3328. keypair_desc=(bytes, str))
  3329. def update_keypair_desc(self,
  3330. keypair_id=None,
  3331. keypair_desc=None,
  3332. config=None):
  3333. """
  3334. :param keypair_id:
  3335. :param keypair_desc:
  3336. :param config:
  3337. :return:
  3338. """
  3339. keypair_id = compat.convert_to_bytes(keypair_id)
  3340. path = b'/keypair/%s' % keypair_id
  3341. body = {
  3342. 'description': keypair_desc
  3343. }
  3344. params = {
  3345. 'updateDesc': None
  3346. }
  3347. return self._send_request(http_methods.PUT, path, json.dumps(body),
  3348. params=params, config=config)
  3349. @required(cluster_size_in_gb=int)
  3350. def create_volume_cluster(self, cluster_size_in_gb, purchase_count=1, storage_type='hp1', cluster_name=None,
  3351. paymentTiming='Prepaid', reservation_length=6, reservation_time_unit='month',
  3352. renew_time_unit=None, renew_time=None, zone_name=None, uuid_flag=None,
  3353. client_token=None, config=None):
  3354. """
  3355. create_volume_cluster.
  3356. """
  3357. path = b'/volume/cluster'
  3358. params = {}
  3359. if uuid_flag is not None:
  3360. params['uuidFlag'] = uuid_flag
  3361. if client_token is None:
  3362. params['clientToken'] = generate_client_token()
  3363. else:
  3364. params['clientToken'] = client_token
  3365. billing = bcc_model.Billing(paymentTiming=paymentTiming, reservationLength=reservation_length,
  3366. reservationTimeUnit=reservation_time_unit)
  3367. body = {
  3368. 'clusterSizeInGB': cluster_size_in_gb,
  3369. 'storageType': storage_type,
  3370. 'purchaseCount': purchase_count,
  3371. 'billing': billing.__dict__
  3372. }
  3373. if zone_name is not None:
  3374. body['zoneName'] = zone_name
  3375. if cluster_name is not None:
  3376. body['clusterName'] = cluster_name
  3377. if renew_time_unit is not None:
  3378. body['renewTimeUnit'] = renew_time_unit
  3379. if renew_time is not None:
  3380. body['renewTime'] = renew_time
  3381. return self._send_request(http_methods.POST, path, json.dumps(body), params=params, config=config)
  3382. def list_volume_cluster(self, cluster_name=None, zone_name=None, marker=None, max_keys=None,
  3383. config=None):
  3384. """
  3385. list_volume_cluster.
  3386. """
  3387. path = b'/volume/cluster'
  3388. params = {}
  3389. if cluster_name is not None:
  3390. params['clusterName'] = cluster_name
  3391. if zone_name is not None:
  3392. params['zoneName'] = zone_name
  3393. if marker is not None:
  3394. params['marker'] = marker
  3395. if max_keys is not None:
  3396. params['maxKeys'] = max_keys
  3397. return self._send_request(http_methods.GET, path, params=params, config=config)
  3398. @required(cluster_id=(bytes, str)) # ***Unicode***
  3399. def get_volume_cluster(self, cluster_id, config=None):
  3400. """
  3401. Get cluster detail
  3402. """
  3403. cluster_id = compat.convert_to_bytes(cluster_id)
  3404. path = b'/volume/cluster/%s' % cluster_id
  3405. return self._send_request(http_methods.GET, path, config=config)
  3406. @required(cluster_id=(bytes, str), # ***Unicode***
  3407. new_cluster_size=int)
  3408. def resize_volume_cluster(self, cluster_id, new_cluster_size, client_token=None, config=None):
  3409. """
  3410. resize_volume_cluster
  3411. """
  3412. cluster_id = compat.convert_to_bytes(cluster_id)
  3413. path = b'/volume/cluster/%s' % cluster_id
  3414. body = {
  3415. 'newClusterSizeInGB': new_cluster_size
  3416. }
  3417. params = None
  3418. if client_token is None:
  3419. params = {
  3420. 'resize': None,
  3421. 'clientToken': generate_client_token()
  3422. }
  3423. else:
  3424. params = {
  3425. 'resize': None,
  3426. 'clientToken': client_token
  3427. }
  3428. return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
  3429. @required(cluster_id=(bytes, str)) # ***Unicode***
  3430. def renew_volume_cluster(self, cluster_id, reservation_length=6, reservation_time_unit='month',
  3431. client_token=None, config=None):
  3432. """
  3433. renew_volume_cluster
  3434. """
  3435. cluster_id = compat.convert_to_bytes(cluster_id)
  3436. path = b'/volume/cluster/%s' % cluster_id
  3437. billing = bcc_model.Billing(reservationLength=reservation_length,
  3438. reservationTimeUnit=reservation_time_unit)
  3439. body = {
  3440. 'billing': billing.__dict__
  3441. }
  3442. params = None
  3443. if client_token is None:
  3444. params = {
  3445. 'purchaseReserved': None,
  3446. 'clientToken': generate_client_token()
  3447. }
  3448. else:
  3449. params = {
  3450. 'purchaseReserved': None,
  3451. 'clientToken': client_token
  3452. }
  3453. return self._send_request(http_methods.PUT, path, json.dumps(body),
  3454. params=params, config=config)
  3455. @required(cluster_id=(bytes, str)) # ***Unicode***
  3456. def autoRenew_volume_cluster(self, cluster_id, renew_time=6, renew_time_unit='month',
  3457. client_token=None, config=None):
  3458. """
  3459. autoRenew_volume_cluster
  3460. """
  3461. cluster_id = compat.convert_to_bytes(cluster_id)
  3462. path = b'/volume/cluster/autoRenew'
  3463. body = {
  3464. 'clusterId': cluster_id,
  3465. 'renewTimeUnit': renew_time_unit,
  3466. 'renewTime': renew_time,
  3467. }
  3468. params = None
  3469. if client_token is None:
  3470. params = {
  3471. 'clientToken': generate_client_token()
  3472. }
  3473. else:
  3474. params = {
  3475. 'clientToken': client_token
  3476. }
  3477. return self._send_request(http_methods.POST, path, json.dumps(body),
  3478. params=params, config=config)
  3479. @required(cluster_id=(bytes, str)) # ***Unicode***
  3480. def cancel_autoRenew_volume_cluster(self, cluster_id, client_token=None, config=None):
  3481. """
  3482. cancel_autoRenew_volume_cluster
  3483. """
  3484. cluster_id = compat.convert_to_bytes(cluster_id)
  3485. path = b'/volume/cluster/cancelAutoRenew'
  3486. body = {
  3487. 'clusterId': cluster_id
  3488. }
  3489. params = None
  3490. if client_token is None:
  3491. params = {
  3492. 'clientToken': generate_client_token()
  3493. }
  3494. else:
  3495. params = {
  3496. 'clientToken': client_token
  3497. }
  3498. return self._send_request(http_methods.POST, path, json.dumps(body),
  3499. params=params, config=config)
  3500. def list_recycled_instances(self, marker=None, max_keys=None, instance_id=None, name=None, payment_timing=None,
  3501. recycle_begin=None, recycle_end=None, config=None):
  3502. """
  3503. Lists recycled instances.
  3504. :param marker:
  3505. The optional parameter marker specified in the original request to specify
  3506. where in the results to begin listing.
  3507. Together with the marker, specifies the list result which listing should begin.
  3508. If the marker is not specified, the list result will listing from the first one.
  3509. :type marker: string
  3510. :param max_keys:
  3511. The optional parameter to specifies the max number of list result to return.
  3512. The default value is 1000.
  3513. :type max_keys: int
  3514. :param instance_id:
  3515. The identified of instance to specifies one instance.
  3516. :type instance_id: string
  3517. :param name:
  3518. The name of instance to specifies one instance.
  3519. :type name: string
  3520. :param payment_timing:
  3521. The payment timing of instance order values: [prepay/postpay].
  3522. :type payment_timing: string
  3523. :param recycle_begin:
  3524. The begintime of the recycled instances date range. FORMAT: yyyy-MM-dd'T'HH:mm:ss'Z'
  3525. :type recycle_begin: string
  3526. :param recycle_end:
  3527. The endtime of the recycled instances date range. FORMAT: yyyy-MM-dd'T'HH:mm:ss'Z'
  3528. :type recycle_end: string
  3529. :return:
  3530. :rtype baidubce.bce_response.BceResponse
  3531. """
  3532. path = b'/recycle/instance'
  3533. body = {}
  3534. if marker is not None:
  3535. body['marker'] = marker
  3536. if max_keys is not None:
  3537. body['maxKeys'] = max_keys
  3538. if instance_id is not None:
  3539. body['instanceId'] = instance_id
  3540. if name is not None:
  3541. body['name'] = name
  3542. if payment_timing is not None:
  3543. body['paymentTiming'] = payment_timing
  3544. if recycle_begin is not None:
  3545. body['recycleBegin'] = recycle_begin
  3546. if recycle_end is not None:
  3547. body['recycleEnd'] = recycle_end
  3548. return self._send_request(http_methods.POST, path, body=json.dumps(body), config=config)
  3549. @required(spec=str, image_id=(bytes, str)) # ***Unicode***
  3550. def create_instance_by_spec(self, spec, image_id, root_disk_size_in_gb=0, root_disk_storage_type=None,
  3551. ephemeral_disks=None, create_cds_list=None, network_capacity_in_mbps=0, eip_name=None,
  3552. internet_charge_type=None, purchase_count=1, name=None, hostname=None,
  3553. auto_seq_suffix=None, is_open_hostname_domain=None, admin_pass=None, billing=None,
  3554. zone_name=None, subnet_id=None, security_group_id=None,
  3555. enterprise_security_group_id=None, security_group_ids=None,
  3556. enterprise_security_group_ids=None, relation_tag=None, ehc_cluster_id=None,
  3557. is_open_ipv6=None, tags=None, key_pair_id=None, auto_renew_time_unit=None,
  3558. auto_renew_time=0, cds_auto_renew=None, asp_id=None, bid_model=None, bid_price=None,
  3559. dedicate_host_id=None, deploy_id=None, deploy_id_list=None, enable_jumbo_frame=None,
  3560. cpu_thread_config=None, numa_config=None, eni_ids=None, client_token=None, config=None,
  3561. user_data=None, spec_id=None, deletion_protection=None, is_open_hosteye=None,
  3562. hosteye_type=None, res_group_id=None, enable_ht=None, data_partition_type=None,
  3563. root_partition_type=None, file_systems=None, disable_root_disk_serial=None,
  3564. internal_ips=None, network_purchase_type=None, is_keep_image_login=None,
  3565. reserved_instance=None):
  3566. """
  3567. Create a bcc Instance with the specified options.
  3568. You must fill the field of clientToken,which is especially for keeping idempotent.
  3569. This is an asynchronous interface,
  3570. you can get the latest status by BccClient.get_instance.
  3571. :param spec:
  3572. The specification of the BBC package.
  3573. :type spec: string
  3574. :param image_id:
  3575. The id of image, list all available image in BccClient.list_images.
  3576. :type image_id: string
  3577. :param billing:
  3578. Billing information.
  3579. :type billing: bcc_model.Billing
  3580. :param create_cds_list:
  3581. The optional list of volume detail info to create.
  3582. :type create_cds_list: list<bcc_model.CreateCdsModel>
  3583. :param network_capacity_in_mbps:
  3584. The optional parameter to specify the bandwidth in Mbps for the new instance.
  3585. It must among 0 and 200, default value is 0.
  3586. If it's specified to 0, it will get the internal ip address only.
  3587. :type network_capacity_in_mbps: int
  3588. :param eip_name:
  3589. eip name
  3590. :type eip_name: string
  3591. :param purchase_count:
  3592. The number of instance to buy, the default value is 1.
  3593. :type purchase_count: int
  3594. :param name:
  3595. The optional parameter to desc the instance that will be created.
  3596. :type name: string
  3597. :param hostname:
  3598. The optional parameter to specify the host name of the instance virtual machine.
  3599. By default, hostname is not specified.
  3600. If hostname is specified: hostname is used as the prefix of the name in batches.
  3601. The backend will add a suffix, and the suffix generation method is: name{-serial number}.
  3602. If name is not specified, it will be automatically generated using the following method:
  3603. {instance-eight-digit random string-serial number}.
  3604. Note: The random string is generated from the characters 0-9 and a-z;
  3605. the serial number increases sequentially according to the magnitude of count.
  3606. If count is 100, the serial number increases from 000~100, and if it is 10, it increases from 00~10.
  3607. Only lowercase letters, numbers and - . special characters are supported.
  3608. They must start with a letter. Special symbols cannot be used continuously.
  3609. Special symbols are not supported at the beginning or end. The length is 2-64.
  3610. :type hostname: string
  3611. :param auto_seq_suffix:
  3612. The parameter to specify whether name and hostname order suffixes are automatically generated.
  3613. :type auto_seq_suffix: boolean
  3614. :param is_open_hostname_domain:
  3615. The parameter to specify whether hostname domain is automatically generated
  3616. :type is_open_hostname_domain: boolean
  3617. :param admin_pass:
  3618. The optional parameter to specify the password for the instance.
  3619. If specify the adminPass,the adminPass must be a 8-16 characters String
  3620. which must contains letters, numbers and symbols.
  3621. The symbols only contains "!@#$%^*()".
  3622. The adminPass will be encrypted in AES-128 algorithm
  3623. with the substring of the former 16 characters of user SecretKey.
  3624. If not specify the adminPass, it will be specified by an random string.
  3625. See more detail on
  3626. https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
  3627. :type admin_pass: string
  3628. :param zone_name:
  3629. The optional parameter to specify the available zone for the instance.
  3630. See more detail through list_zones method
  3631. :type zone_name: string
  3632. :param subnet_id:
  3633. The optional parameter to specify the id of subnet from vpc, optional param
  3634. default value is default subnet from default vpc
  3635. :type subnet_id: string
  3636. :param security_group_id:
  3637. The optional parameter to specify the securityGroupId of the instance
  3638. vpcId of the securityGroupId must be the same as the vpcId of subnetId
  3639. See more detail through listSecurityGroups method
  3640. :type security_group_id: string
  3641. :param enterprise_security_group_id:
  3642. enterprise_security_group_id
  3643. :type enterprise_security_group_id: string
  3644. :param security_group_ids:
  3645. security_group_ids
  3646. :type security_group_ids: list<string>
  3647. :param enterprise_security_group_ids:
  3648. enterprise_security_group_ids
  3649. :type enterprise_security_group_ids: list<string>
  3650. :param relation_tag:
  3651. The parameter to specify whether the instance related to existing tags
  3652. :type relation_tag: boolean
  3653. :param ehc_cluster_id:
  3654. The id of ehcCluster.
  3655. :type ehc_cluster_id: string
  3656. :param is_open_ipv6:
  3657. The parameter indicates whether the instance to be created is enabled for IPv6.
  3658. It can only be enabled when both the image and subnet support IPv6.
  3659. True indicates enabled, false indicates disabled,
  3660. and no transmission indicates automatic adaptation of the image and subnet's IPv6 support
  3661. :type is_open_ipv6: boolean
  3662. :param deploy_id_list:
  3663. This parameter is the list of deployment set IDs where the specified instance is located.
  3664. :type deploy_id_list: list<string>
  3665. :param client_token:
  3666. An ASCII string whose length is less than 64.
  3667. The request will be idempotent if client token is provided.
  3668. If the clientToken is not specified by the user,
  3669. a random String generated by default algorithm will be used.
  3670. See more detail at
  3671. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  3672. :type client_token: string
  3673. :param root_disk_size_in_gb:
  3674. The parameter to specify the root disk size in GB.
  3675. The root disk excludes the system disk, available is 40-500GB.
  3676. :type root_disk_size_in_gb: int
  3677. :param root_disk_storage_type:
  3678. The parameter to specify the root disk storage type.
  3679. Default use of HP1 cloud disk.
  3680. :type root_disk_storage_type: string
  3681. :param ephemeral_disks:
  3682. The optional list of ephemeral volume detail info to create.
  3683. :type ephemeral_disks: list<bcc_model.EphemeralDisk>
  3684. :param dedicate_host_id
  3685. The parameter to specify the dedicate host id.
  3686. :type dedicate_host_id: string
  3687. :param auto_renew_time_unit
  3688. The parameter to specify the unit of the auto renew time.
  3689. The auto renew time unit can be "month" or "year".
  3690. The default value is "month".
  3691. :type auto_renew_time_unit: string
  3692. :param auto_renew_time
  3693. The parameter to specify the auto renew time, the default value is 0.
  3694. :type auto_renew_time: int
  3695. :param tags
  3696. The optional list of tag to be bonded.
  3697. :type tags: list<bcc_model.TagModel>
  3698. :param deploy_id
  3699. The parameter to specify the id of the deploymentSet.
  3700. :type deploy_id: string
  3701. :param bid_model
  3702. The parameter to specify the bidding model.
  3703. The bidding model can be "market" or "custom".
  3704. :type bid_model: string
  3705. :param bid_price
  3706. The parameter to specify the bidding price.
  3707. When the bid_model is "custom", it works.
  3708. :type bid_price: string
  3709. :param key_pair_id
  3710. The parameter to specify id of the keypair.
  3711. :type key_pair_id: string
  3712. :param asp_id
  3713. The parameter to specify id of the asp.
  3714. :type asp_id: string
  3715. :param internet_charge_type
  3716. The parameter to specify the internet charge type.
  3717. See more detail on
  3718. https://cloud.baidu.com/doc/BCC/API.html#InternetChargeType
  3719. :type internet_charge_type: string
  3720. :param cds_auto_renew
  3721. The parameter to specify whether the cds is auto renew or not.
  3722. The default value is false.
  3723. :type cds_auto_renew: boolean
  3724. :param enable_jumbo_frame:
  3725. The parameter indicates whether the instance is enabled for JumboFrame.
  3726. It can only be enabled when the flavor support JumboFrame.
  3727. True indicates enabled, false indicates disabled,
  3728. :type enable_jumbo_frame: bool
  3729. :param cpu_thread_config:
  3730. Manage hyper - threading, which is the same on both Intel and AMD platforms.
  3731. :type cpu_thread_config: string
  3732. :param numa_config:
  3733. Manage NPS on AMD platforms. Manage NUMA on Intel platforms.
  3734. :type numa_config: string
  3735. :param eni_ids:
  3736. The optional list of eni short ids to attach.
  3737. The number of eniIds must be an integer multiple of the number of instances.
  3738. The enis must in the same vpc and available zone with instance.
  3739. :type eni_ids: list<string>
  3740. :param user_data:
  3741. :type user_data: string
  3742. :param is_open_hosteye:
  3743. :type is_open_hosteye: boolean
  3744. :param hosteye_type:
  3745. :type hosteye_type: string
  3746. :param res_group_id:
  3747. The optional parameter to specify the resGroupId of the instance
  3748. :type res_group_id: string
  3749. :param enable_ht:
  3750. Whether to enable HT (used by EBC). Default: true
  3751. :type enable_ht: bool
  3752. :param data_partition_type:
  3753. Data disk file system format.Available values: xfs, ext4.
  3754. :type data_partition_type: bool
  3755. :param root_partition_type:
  3756. System disk file system format.Available values: xfs, ext4.
  3757. :type root_partition_type: bool
  3758. :param deletion_protection:
  3759. :type deletion_protection: int
  3760. :param spec_id:
  3761. Identify of the spec.
  3762. :param file_systems:
  3763. This parameter is obsolete.
  3764. :type file_systems:list<bcc_model.FileSystemModel>
  3765. :param disable_root_disk_serial:
  3766. Whether to hide the system disk SN during instance creation. Default: false
  3767. :type disable_root_disk_serial: bool
  3768. :param internal_ips:
  3769. The parameter to specify the internal ips.
  3770. :type internal_ips: list<string>
  3771. :param network_purchase_type:
  3772. EIP line type, including Standard BGP (BGP) and Enhanced BGP (BGP_S).The default value is Standard BGP.
  3773. :type network_purchase_type: string
  3774. :return:
  3775. :rtype baidubce.bce_response.BceResponse
  3776. """
  3777. path = b'/instanceBySpec'
  3778. params = {}
  3779. if client_token is None:
  3780. params['clientToken'] = generate_client_token()
  3781. else:
  3782. params['clientToken'] = client_token
  3783. if billing is None:
  3784. billing = default_billing_to_purchase_created
  3785. body = {
  3786. 'spec': spec,
  3787. 'imageId': image_id,
  3788. 'billing': billing.__dict__
  3789. }
  3790. if root_disk_size_in_gb != 0:
  3791. body['rootDiskSizeInGb'] = root_disk_size_in_gb
  3792. if root_disk_storage_type is not None:
  3793. body['rootDiskStorageType'] = root_disk_storage_type
  3794. if create_cds_list is not None:
  3795. body['createCdsList'] = [create_cds.__dict__ for create_cds in create_cds_list]
  3796. if network_capacity_in_mbps != 0:
  3797. body['networkCapacityInMbps'] = network_capacity_in_mbps
  3798. if eip_name is not None:
  3799. body['eipName'] = eip_name
  3800. if purchase_count > 0:
  3801. body['purchaseCount'] = purchase_count
  3802. if name is not None:
  3803. body['name'] = name
  3804. if hostname is not None:
  3805. body['hostname'] = hostname
  3806. if auto_seq_suffix is not None:
  3807. body['autoSeqSuffix'] = auto_seq_suffix
  3808. if is_open_hostname_domain is not None:
  3809. body['isOpenHostnameDomain'] = is_open_hostname_domain
  3810. if admin_pass is not None:
  3811. secret_access_key = self.config.credentials.secret_access_key
  3812. cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
  3813. body['adminPass'] = cipher_admin_pass
  3814. if zone_name is not None:
  3815. body['zoneName'] = zone_name
  3816. if subnet_id is not None:
  3817. body['subnetId'] = subnet_id
  3818. if security_group_id is not None:
  3819. body['securityGroupId'] = security_group_id
  3820. if enterprise_security_group_id is not None:
  3821. body['enterpriseSecurityGroupId'] = enterprise_security_group_id
  3822. if security_group_ids is not None:
  3823. body['securityGroupIds'] = security_group_ids
  3824. if enterprise_security_group_ids is not None:
  3825. body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
  3826. if auto_renew_time != 0:
  3827. body['autoRenewTime'] = auto_renew_time
  3828. if auto_renew_time_unit is None:
  3829. body['autoRenewTimeUnit'] = "month"
  3830. else:
  3831. body['autoRenewTimeUnit'] = auto_renew_time_unit
  3832. if ephemeral_disks is not None:
  3833. body['ephemeralDisks'] = [ephemeral_disk.__dict__ for ephemeral_disk in ephemeral_disks]
  3834. if dedicate_host_id is not None:
  3835. body['dedicatedHostId'] = dedicate_host_id
  3836. if deploy_id is not None:
  3837. body['deployId'] = deploy_id
  3838. if deploy_id_list is not None:
  3839. body['deployIdList'] = deploy_id_list
  3840. if bid_model is not None:
  3841. body['bidModel'] = bid_model
  3842. if bid_price is not None:
  3843. body['bidPrice'] = bid_price
  3844. if key_pair_id is not None:
  3845. body['keypairId'] = key_pair_id
  3846. if internet_charge_type is not None:
  3847. body['internetChargeType'] = internet_charge_type
  3848. if asp_id is not None:
  3849. body['aspId'] = asp_id
  3850. if relation_tag is not None:
  3851. body['relationTag'] = relation_tag
  3852. if ehc_cluster_id is not None:
  3853. body['ehcClusterId'] = ehc_cluster_id
  3854. if is_open_ipv6 is not None:
  3855. body['isOpenIpv6'] = is_open_ipv6
  3856. if tags is not None:
  3857. tag_list = [tag.__dict__ for tag in tags]
  3858. body['tags'] = tag_list
  3859. if enable_jumbo_frame is not None:
  3860. body['enableJumboFrame'] = enable_jumbo_frame
  3861. if cpu_thread_config is not None:
  3862. body['cpuThreadConfig'] = cpu_thread_config
  3863. if numa_config is not None:
  3864. body['numaConfig'] = numa_config
  3865. if eni_ids is not None:
  3866. body['eniIds'] = eni_ids
  3867. body['cdsAutoRenew'] = cds_auto_renew
  3868. if user_data is not None:
  3869. body['userData'] = user_data
  3870. if spec_id is not None:
  3871. body['specId'] = spec_id
  3872. if is_open_hosteye is not None:
  3873. body['isOpenHosteye'] = is_open_hosteye
  3874. if deletion_protection is not None:
  3875. body['deletionProtection'] = deletion_protection
  3876. if hosteye_type is not None:
  3877. body['hosteyeType'] = hosteye_type
  3878. if res_group_id is not None:
  3879. body['resGroupId'] = res_group_id
  3880. if enable_ht is not None:
  3881. body['enableHt'] = enable_ht
  3882. if data_partition_type is not None:
  3883. body['dataPartitionType'] = data_partition_type
  3884. if root_partition_type is not None:
  3885. body['rootPartitionType'] = root_partition_type
  3886. if file_systems is not None:
  3887. file_system_list = [file_system.__dict__ for file_system in file_systems]
  3888. body['fileSystems'] = file_system_list
  3889. if disable_root_disk_serial is not None:
  3890. body['disableRootDiskSerial'] = disable_root_disk_serial
  3891. if internal_ips is not None:
  3892. body['internalIps'] = internal_ips
  3893. if network_purchase_type is not None:
  3894. body['networkPurchaseType'] = network_purchase_type
  3895. if is_keep_image_login is not None:
  3896. body['keepImageLogin'] = is_keep_image_login
  3897. if reserved_instance is not None:
  3898. body['reservedInstance'] = reserved_instance
  3899. return self._send_request(http_methods.POST, path, json.dumps(body),
  3900. params=params, config=config)
  3901. @required(instance_id=(bytes, str))
  3902. def auto_release_instance(self, instance_id, release_time=None, client_token=None, config=None):
  3903. """
  3904. set instance auto release.
  3905. :param instance_id:
  3906. The id of instance.
  3907. :type instance_id: string
  3908. :param release_time:
  3909. The new value for instance's name.
  3910. :type release_time: string in format yyyy-MM-dd'T'HH:mm:ss'Z'.
  3911. :param client_token:
  3912. An ASCII string whose length is less than 64.
  3913. The request will be idempotent if client token is provided.
  3914. If the clientToken is not specified by the user,
  3915. a random String generated by default algorithm will be used.
  3916. See more detail at
  3917. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  3918. :type client_token: string
  3919. :return:
  3920. :rtype baidubce.bce_response.BceResponse
  3921. """
  3922. params = {
  3923. 'autorelease': None,
  3924. }
  3925. if client_token is None:
  3926. params['clientToken'] = generate_client_token()
  3927. else:
  3928. params['clientToken'] = client_token
  3929. instance_id = compat.convert_to_bytes(instance_id)
  3930. # instance_id = instance_id.encode(encoding='utf-8')
  3931. path = b'/instance/%s' % instance_id
  3932. body = {
  3933. 'releaseTime': release_time
  3934. }
  3935. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  3936. @required(instance_id=(bytes, str)) # ***Unicode***
  3937. def release_instance_with_related_resources(self, instance_id, related_release_flag=None,
  3938. delete_cds_snapshot_flag=None, delete_related_enis_flag=None,
  3939. bcc_recycle_flag=None, cds_attribute_active=None,
  3940. client_token=None, config=None):
  3941. """
  3942. Releasing the instance owned by the user.
  3943. Only the Postpaid instance or Prepaid which is expired can be released.
  3944. After releasing the instance,
  3945. all of the data will be deleted.
  3946. all of volumes attached will be auto detached, but the volume snapshots will be saved.
  3947. all of snapshots created from original instance system disk will be deleted,
  3948. all of customized images created from original instance system disk will be reserved.
  3949. :param instance_id:
  3950. The id of instance.
  3951. :type instance_id: string
  3952. :param related_release_flag:
  3953. Release or not related resources.
  3954. :type related_release_flag: bool
  3955. :param delete_cds_snapshot_flag:
  3956. Delete or not cds snapshot.
  3957. :type delete_cds_snapshot_flag: bool
  3958. :param delete_related_enis_flag:
  3959. Delete or not related enis.
  3960. :type delete_related_enis_flag: bool
  3961. :param bcc_recycle_flag:
  3962. Recycle or not bcc instance.
  3963. :type bcc_recycle_flag: bool
  3964. :return:
  3965. :rtype baidubce.bce_response.BceResponse
  3966. """
  3967. params = {}
  3968. if client_token is None:
  3969. params['clientToken'] = generate_client_token()
  3970. else:
  3971. params['clientToken'] = client_token
  3972. instance_id = compat.convert_to_bytes(instance_id)
  3973. path = b'/instance/%s' % instance_id
  3974. body = {}
  3975. if related_release_flag is not None:
  3976. body['relatedReleaseFlag'] = related_release_flag
  3977. if delete_cds_snapshot_flag is not None:
  3978. body['deleteCdsSnapshotFlag'] = delete_cds_snapshot_flag
  3979. if delete_related_enis_flag is not None:
  3980. body['deleteRelatedEnisFlag'] = delete_related_enis_flag
  3981. if bcc_recycle_flag is not None:
  3982. body['bccRecycleFlag'] = bcc_recycle_flag
  3983. if bcc_recycle_flag is not None:
  3984. body['cdsAttributeActive'] = cds_attribute_active
  3985. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  3986. @required(instance_id=(bytes, str)) # ***Unicode***
  3987. def release_prepaid_instance_with_related_resources(self, instance_id, related_release_flag=None,
  3988. delete_cds_snapshot_flag=None, delete_related_enis_flag=None,
  3989. client_token=None, config=None):
  3990. """
  3991. Releasing the instance owned by the user.
  3992. Only the Prepaid instance and the instance has not expired can be released.
  3993. After releasing the instance,
  3994. all of the data will be deleted.
  3995. all of volumes attached will be auto detached, but the volume snapshots will be saved.
  3996. all of snapshots created from original instance system disk will be deleted,
  3997. all of customized images created from original instance system disk will be reserved.
  3998. :param instance_id:
  3999. The id of instance.
  4000. :type instance_id: string
  4001. :param related_release_flag:
  4002. Release or not related resources.
  4003. :type related_release_flag: bool
  4004. :param delete_cds_snapshot_flag:
  4005. Delete or not cds snapshot.
  4006. :type delete_cds_snapshot_flag: bool
  4007. :param delete_related_enis_flag:
  4008. Delete or not related enis.
  4009. :type delete_related_enis_flag: bool
  4010. :return:
  4011. :rtype baidubce.bce_response.BceResponse
  4012. """
  4013. params = {}
  4014. if client_token is None:
  4015. params['clientToken'] = generate_client_token()
  4016. else:
  4017. params['clientToken'] = client_token
  4018. path = b'/instance/delete'
  4019. body = {}
  4020. body['instanceId'] = instance_id
  4021. if related_release_flag is not None:
  4022. body['relatedReleaseFlag'] = related_release_flag
  4023. if delete_cds_snapshot_flag is not None:
  4024. body['deleteCdsSnapshotFlag'] = delete_cds_snapshot_flag
  4025. if delete_related_enis_flag is not None:
  4026. body['deleteRelatedEnisFlag'] = delete_related_enis_flag
  4027. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  4028. @required(instance_id=(bytes, str)) # ***Unicode***
  4029. def get_instance_with_deploy_set(self, instance_id, contains_failed=None, config=None):
  4030. """
  4031. Get the detail information of specified instance.
  4032. :param instance_id:
  4033. The id of instance.
  4034. :type instance_id: string
  4035. :param contains_failed:
  4036. The optional parameters to get the failed message.If true, it means get the failed message.
  4037. :type contains_failed: boolean
  4038. :return:
  4039. :rtype baidubce.bce_response.BceResponse
  4040. """
  4041. instance_id = instance_id.encode(encoding='utf-8')
  4042. path = b'/instance/%s' % instance_id
  4043. params = {
  4044. 'isDeploySet': True
  4045. }
  4046. if contains_failed:
  4047. params['containsFailed'] = contains_failed
  4048. return self._send_request(http_methods.GET, path, params=params, config=config)
  4049. @required(instance_id=(bytes, str)) # ***Unicode***
  4050. def get_instance_with_deploy_set_and_failed(self, instance_id, contains_failed=None, config=None):
  4051. """
  4052. Get the detail information of specified instance.
  4053. :param instance_id:
  4054. The id of instance.
  4055. :type instance_id: string
  4056. :param contains_failed:
  4057. The optional parameters to get the failed message.If true, it means get the failed message.
  4058. :type contains_failed: boolean
  4059. :return:
  4060. :rtype baidubce.bce_response.BceResponse
  4061. """
  4062. instance_id = instance_id.encode(encoding='utf-8')
  4063. path = b'/instance/%s' % instance_id
  4064. params = {
  4065. 'containsFailed': None
  4066. }
  4067. if contains_failed:
  4068. params['containsFailed'] = contains_failed
  4069. return self._send_request(http_methods.GET, path, params=params, config=config)
  4070. @required(instance_id=(bytes, str), hostname=str) # ***Unicode***
  4071. def modify_instance_hostname(self, instance_id, hostname, reboot=None, is_open_hostname_domain=None,
  4072. client_token=None, config=None):
  4073. """
  4074. modify instance hostname
  4075. :param instance_id:
  4076. The id of instance.
  4077. :type instance_id: string
  4078. :param hostname:
  4079. new hostname
  4080. :type hostname: string, FORMAT ^([a-z]+)((\.|-)?[a-z0-9]+)*$
  4081. :param reboot:
  4082. Auto reboot the instance after hostname changed.
  4083. :type reboot: bool
  4084. :param is_open_hostname_domain:
  4085. Set hostname domain opening
  4086. :type is_open_hostname_domain: bool
  4087. :return:
  4088. :rtype baidubce.bce_response.BceResponse
  4089. """
  4090. params = {
  4091. "changeHostname": None
  4092. }
  4093. if client_token is None:
  4094. params['clientToken'] = generate_client_token()
  4095. else:
  4096. params['clientToken'] = client_token
  4097. instance_id = compat.convert_to_bytes(instance_id)
  4098. path = b'/instance/%s' % instance_id
  4099. body = {
  4100. "hostname": hostname
  4101. }
  4102. if reboot is not None:
  4103. body['reboot'] = reboot
  4104. if is_open_hostname_domain is not None:
  4105. body['isOpenHostnameDomain'] = is_open_hostname_domain
  4106. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  4107. @required(instance_id_list=(list)) # ***Unicode***
  4108. def recovery_instances(self, instance_id_list, client_token=None, config=None):
  4109. """
  4110. Recovery multi instances
  4111. :param instance_id_list:
  4112. The id list of instances to recovery.
  4113. :type instance_id_list: list of string
  4114. :return:
  4115. :rtype baidubce.bce_response.BceResponse
  4116. """
  4117. params = {}
  4118. if client_token is None:
  4119. params['clientToken'] = generate_client_token()
  4120. else:
  4121. params['clientToken'] = client_token
  4122. path = b'/instance/recovery'
  4123. list_of_item = []
  4124. for instance_id in instance_id_list:
  4125. list_of_item.append({'instanceId': instance_id})
  4126. body = {
  4127. "instanceIds": list_of_item
  4128. }
  4129. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  4130. @required(instance_ids=(list))
  4131. def batch_refund_resources(self, instance_ids, related_release_flag=None,
  4132. delete_cds_snapshot_flag=None, delete_related_enis_flag=None,
  4133. client_token=None, config=None):
  4134. """
  4135. Releasing the instance owned by the user.
  4136. Only the Prepaid instance and the instance has not expired can be released.
  4137. After releasing the instance, all of the data will be deleted.
  4138. :param instance_ids:
  4139. The id list of instances.
  4140. :type instance_ids: list of string
  4141. :param related_release_flag:
  4142. Release or not related resources.
  4143. :type related_release_flag: bool
  4144. :param delete_cds_snapshot_flag:
  4145. Delete or not cds snapshot.
  4146. :type delete_cds_snapshot_flag: bool
  4147. :param delete_related_enis_flag:
  4148. Delete or not related enis.
  4149. :type delete_related_enis_flag: bool
  4150. :return:
  4151. :rtype baidubce.bce_response.BceResponse
  4152. """
  4153. params = {}
  4154. if client_token is None:
  4155. params['clientToken'] = generate_client_token()
  4156. else:
  4157. params['clientToken'] = client_token
  4158. path = b'/instance/batchRefundResource'
  4159. body = {
  4160. "instanceIds": instance_ids
  4161. }
  4162. if related_release_flag is not None:
  4163. body['relatedReleaseFlag'] = related_release_flag
  4164. if delete_cds_snapshot_flag is not None:
  4165. body['deleteCdsSnapshotFlag'] = delete_cds_snapshot_flag
  4166. if delete_related_enis_flag is not None:
  4167. body['deleteRelatedEnisFlag'] = delete_related_enis_flag
  4168. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  4169. @required(instance_type=str, cpu_count=int, memory_cap_in_gb=int) # ***Unicode***
  4170. def get_bid_instance_price(self, instance_type, cpu_count, memory_cap_in_gb,
  4171. root_disk_size_in_gb=None, root_disk_storage_type=None, create_cds_list=None,
  4172. purchase_count=1, name=None, admin_pass=None, key_pair_id=None, asp_id=None,
  4173. image_id=None, bid_model=None, bid_price=None, network_cap_in_mbps=None,
  4174. relation_tag=None, tags=None, security_group_id=None, subnet_id=None,
  4175. zone_name=None, internet_charge_type=None, client_token=None, config=None):
  4176. """
  4177. Query bid instance price in market.
  4178. :param instance_type:
  4179. The specified Specification to create the instance,
  4180. See more detail on
  4181. https://cloud.baidu.com/doc/BCC/API.html#InstanceType
  4182. :type instance_type: string
  4183. :param cpu_count:
  4184. The parameter to specified the cpu core to create the instance.
  4185. :type cpu_count: int
  4186. :param memory_cap_in_gb:
  4187. The parameter to specified the capacity of memory in GB to create the instance.
  4188. :type memory_cap_in_gb: int
  4189. :param image_id:
  4190. The id of image, list all available image in BccClient.list_images.
  4191. :type image_id: string
  4192. :param create_cds_list:
  4193. The optional list of volume detail info to create.
  4194. :type create_cds_list: list<bcc_model.CreateCdsModel>
  4195. :param network_cap_in_mbps:
  4196. The optional parameter to specify the bandwidth in Mbps for the new instance.
  4197. It must among 0 and 200, default value is 0.
  4198. If it's specified to 0, it will get the internal ip address only.
  4199. :type network_cap_in_mbps: int
  4200. :param purchase_count:
  4201. The number of instance to buy, the default value is 1.
  4202. :type purchase_count: int
  4203. :param name:
  4204. The optional parameter to desc the instance that will be created.
  4205. :type name: string
  4206. :param admin_pass:
  4207. The optional parameter to specify the password for the instance.
  4208. If specify the adminPass,the adminPass must be a 8-16 characters String
  4209. which must contains letters, numbers and symbols.
  4210. The symbols only contains "!@#$%^*()".
  4211. The adminPass will be encrypted in AES-128 algorithm
  4212. with the substring of the former 16 characters of user SecretKey.
  4213. If not specify the adminPass, it will be specified by an random string.
  4214. See more detail on
  4215. https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
  4216. :type admin_pass: string
  4217. :param zone_name:
  4218. The optional parameter to specify the available zone for the instance.
  4219. See more detail through list_zones method
  4220. :type zone_name: string
  4221. :param subnet_id:
  4222. The optional parameter to specify the id of subnet from vpc, optional param
  4223. default value is default subnet from default vpc
  4224. :type subnet_id: string
  4225. :param security_group_id:
  4226. The optional parameter to specify the securityGroupId of the instance
  4227. vpcId of the securityGroupId must be the same as the vpcId of subnetId
  4228. See more detail through listSecurityGroups method
  4229. :type security_group_id: string
  4230. :param client_token:
  4231. An ASCII string whose length is less than 64.
  4232. The request will be idempotent if client token is provided.
  4233. If the clientToken is not specified by the user,
  4234. a random String generated by default algorithm will be used.
  4235. See more detail at
  4236. https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
  4237. :type client_token: string
  4238. :param root_disk_size_in_gb:
  4239. The parameter to specify the root disk size in GB.
  4240. The root disk excludes the system disk, available is 40-500GB.
  4241. :type root_disk_size_in_gb: int
  4242. :param root_disk_storage_type:
  4243. The parameter to specify the root disk storage type.
  4244. Default use of HP1 cloud disk.
  4245. :type root_disk_storage_type: string
  4246. :param relation_tag
  4247. Set whether the tags specified by the instance to ne queried needs
  4248. to be associated with an existing tag key.
  4249. The default value is false, this param is optional.
  4250. :type relation_tag: bool
  4251. :param tags
  4252. The optional list of tag to be bonded.
  4253. :type tags: list<bcc_model.TagModel>
  4254. :param bid_model
  4255. The parameter to specify the bidding model.
  4256. The bidding model can be "market" or "custom".
  4257. :type bid_model: string
  4258. :param bid_price
  4259. The parameter to specify the bidding price.
  4260. When the bid_model is "custom", it works.
  4261. :type bid_price: string
  4262. :param key_pair_id
  4263. The parameter to specify id of the keypair.
  4264. :type key_pair_id: string
  4265. :param asp_id
  4266. The parameter to specify id of the asp.
  4267. :type asp_id: string
  4268. :param internet_charge_type
  4269. The parameter to specify the internet charge type.
  4270. See more detail on
  4271. https://cloud.baidu.com/doc/BCC/API.html#InternetChargeType
  4272. :type internet_charge_type: string
  4273. :return:
  4274. :rtype baidubce.bce_response.BceResponse
  4275. """
  4276. path = b'/instance/bidPrice'
  4277. params = {}
  4278. if client_token is None:
  4279. params['clientToken'] = generate_client_token()
  4280. else:
  4281. params['clientToken'] = client_token
  4282. body = {
  4283. 'cpuCount': cpu_count,
  4284. 'memoryCapacityInGB': memory_cap_in_gb,
  4285. 'instanceType': instance_type
  4286. }
  4287. if image_id is not None:
  4288. body['imageId'] = image_id
  4289. if root_disk_size_in_gb != 0:
  4290. body['rootDiskSizeInGb'] = root_disk_size_in_gb
  4291. if root_disk_storage_type is not None:
  4292. body['rootDiskStorageType'] = root_disk_storage_type
  4293. if create_cds_list is not None:
  4294. body['createCdsList'] = [create_cds.__dict__ for create_cds in create_cds_list]
  4295. if purchase_count > 0:
  4296. body['purchaseCount'] = purchase_count
  4297. if name is not None:
  4298. body['name'] = name
  4299. if admin_pass is not None:
  4300. secret_access_key = self.config.credentials.secret_access_key
  4301. cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
  4302. body['adminPass'] = cipher_admin_pass
  4303. if zone_name is not None:
  4304. body['zoneName'] = zone_name
  4305. if subnet_id is not None:
  4306. body['subnetId'] = subnet_id
  4307. if security_group_id is not None:
  4308. body['securityGroupId'] = security_group_id
  4309. if bid_model is not None:
  4310. body['bidModel'] = bid_model
  4311. if bid_price is not None:
  4312. body['bidPrice'] = bid_price
  4313. if key_pair_id is not None:
  4314. body['keypairId'] = key_pair_id
  4315. if internet_charge_type is not None:
  4316. body['internetChargeType'] = internet_charge_type
  4317. if asp_id is not None:
  4318. body['aspId'] = asp_id
  4319. if relation_tag is not None:
  4320. body['relationTag'] = relation_tag
  4321. if tags is not None:
  4322. tag_list = [tag.__dict__ for tag in tags]
  4323. body['tags'] = tag_list
  4324. if network_cap_in_mbps is not None:
  4325. body['networkCapacityInMbps'] = network_cap_in_mbps
  4326. return self._send_request(http_methods.POST, path, json.dumps(body), params=params, config=config)
  4327. def list_bid_flavor(self, client_token=None, config=None):
  4328. """
  4329. Get all bid flavors.
  4330. :return:
  4331. :rtype baidubce.bce_response.BceResponse
  4332. """
  4333. params = {}
  4334. if client_token is None:
  4335. params['clientToken'] = generate_client_token()
  4336. else:
  4337. params['clientToken'] = client_token
  4338. path = b'/instance/bidFlavor'
  4339. return self._send_request(http_methods.POST, path, params=params, config=config)
  4340. @required(instance_id=(bytes, str), deletion_protection=int)
  4341. def modify_deletion_protection(self, instance_id, deletion_protection, client_token=None, config=None):
  4342. """
  4343. Set instance deleion protection.
  4344. :param instance_id
  4345. The id of instance.
  4346. :type instance_id: string
  4347. :param deletion_protection
  4348. The status of instance deletion protection. 1:enable, 0:disable.
  4349. :type deletion_protection: int
  4350. :return:
  4351. :rtype baidubce.bce_response.BceResponse
  4352. """
  4353. params = {}
  4354. if client_token is None:
  4355. params['clientToken'] = generate_client_token()
  4356. else:
  4357. params['clientToken'] = client_token
  4358. instance_id = instance_id.encode(encoding='utf-8')
  4359. path = b'/instance/%s/deletionProtection' % instance_id
  4360. body = {
  4361. "deletionProtection": deletion_protection
  4362. }
  4363. return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
  4364. @required(instance_id=(bytes, str), is_eip_auto_related_delete=bool)
  4365. def modify_related_delete_policy(self, instance_id, is_eip_auto_related_delete, client_token=None, config=None):
  4366. """
  4367. Set bid instance eip_auto_related_delete.
  4368. :param instance_id
  4369. The id of instance.
  4370. :type instance_id: string
  4371. :param is_eip_auto_related_delete
  4372. Enables the deletion of the related EIP of bid instance when the instance is being deleted.
  4373. :type is_eip_auto_related_delete: bool
  4374. :return:
  4375. :rtype baidubce.bce_response.BceResponse
  4376. """
  4377. params = {}
  4378. if client_token is None:
  4379. params['clientToken'] = generate_client_token()
  4380. else:
  4381. params['clientToken'] = client_token
  4382. instance_id = instance_id.encode(encoding='utf-8')
  4383. path = b'/instance/%s/modifyRelatedDeletePolicy' % instance_id
  4384. body = {
  4385. "isEipAutoRelatedDelete": is_eip_auto_related_delete
  4386. }
  4387. return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
  4388. @required(volume_id=(bytes, str)) # ***Unicode***
  4389. def release_volume_new(self, volume_id, auto_snapshot=None, manual_snapshot=None,
  4390. recycle=None, client_token=None, config=None):
  4391. """
  4392. Releasing the specified volume owned by the user.
  4393. You can release the specified volume only
  4394. when the instance is among state of Available/Expired/Error,
  4395. otherwise, it's will get 409 errorCode.
  4396. :param volume_id:
  4397. The id of the volume which will be released.
  4398. :type volume_id: string
  4399. :param auto_snapshot:
  4400. Snapshot volume automatically. value: 'on'/'off'. Default value: 'off'.
  4401. :type auto_snapshot: string
  4402. :param manual_snapshot:
  4403. Snapshot volume manually. value: 'on'/'off'. Default value: 'off'.
  4404. :type manual_snapshot: string
  4405. :param recycle:
  4406. where recycle volume or not, value: 'on'/'off'. Default value: 'on'.
  4407. :type recycle: string
  4408. :return:
  4409. :rtype baidubce.bce_response.BceResponse
  4410. """
  4411. params = {}
  4412. if client_token is None:
  4413. params['clientToken'] = generate_client_token()
  4414. else:
  4415. params['clientToken'] = client_token
  4416. volume_id = volume_id.encode(encoding='utf-8')
  4417. path = b'/volume/%s' % volume_id
  4418. body = {}
  4419. if auto_snapshot is not None:
  4420. body['autoSnapshot'] = auto_snapshot
  4421. if manual_snapshot is not None:
  4422. body['manualSnapshot'] = manual_snapshot
  4423. if recycle is not None:
  4424. body['recycle'] = recycle
  4425. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  4426. @required(volume_id=str, renew_time=int, renew_time_unit=str) # ***Unicode***
  4427. def auto_renew_cds_volume(self, volume_id, renew_time, renew_time_unit, client_token=None, config=None):
  4428. """
  4429. set auto_renew_cds_volume
  4430. :param volume_id:
  4431. The id of the volume which will be renewed.
  4432. :type volume_id: string
  4433. :param renew_time:
  4434. Auto renew start time.
  4435. Value:
  4436. - month: 1 ~ 9
  4437. - year: 1 ~ 3
  4438. :type renew_time: string
  4439. :param renew_time_unit:
  4440. Choose automatic monthly or annual renewals. value: 'month'/'year'
  4441. :type renew_time_unit: string
  4442. :return:
  4443. :rtype baidubce.bce_response.BceResponse
  4444. """
  4445. params = {}
  4446. if client_token is None:
  4447. params['clientToken'] = generate_client_token()
  4448. else:
  4449. params['clientToken'] = client_token
  4450. path = b'/volume/autoRenew'
  4451. body = {
  4452. 'volumeId': volume_id,
  4453. 'renewTime': renew_time,
  4454. 'renewTimeUnit': renew_time_unit
  4455. }
  4456. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  4457. @required(volume_id=str) # ***Unicode***
  4458. def cancel_auto_renew_cds_volume(self, volume_id, client_token=None, config=None):
  4459. """
  4460. cancel_auto_renew_volume_cluster
  4461. :param volume_id:
  4462. The id of the volume which will be renewed.
  4463. :type volume_id: string
  4464. :return:
  4465. :rtype baidubce.bce_response.BceResponse
  4466. """
  4467. path = b'/volume/cancelAutoRenew'
  4468. body = {
  4469. 'volumeId': volume_id
  4470. }
  4471. params = {}
  4472. if client_token is None:
  4473. params['clientToken'] = generate_client_token()
  4474. else:
  4475. params['clientToken'] = client_token
  4476. return self._send_request(http_methods.POST, path, json.dumps(body),
  4477. params=params, config=config)
  4478. @required(zone_name=str) # ***Unicode***
  4479. def get_available_disk_info(self, zone_name, client_token=None, config=None):
  4480. """
  4481. get_available_disk_info
  4482. :param zone_name:
  4483. The name of available zone for volume to use.
  4484. :type zone_name: string
  4485. :return:
  4486. :rtype baidubce.bce_response.BceResponse
  4487. """
  4488. path = b'/volume/disk'
  4489. params = {
  4490. 'zoneName': zone_name
  4491. }
  4492. if client_token is None:
  4493. params['clientToken'] = generate_client_token()
  4494. else:
  4495. params['clientToken'] = client_token
  4496. return self._send_request(http_methods.GET, path, params=params, config=config)
  4497. @required(volume_id=str) # ***Unicode***
  4498. def tag_volume(self, volume_id, relation_tag=None, tags=None, client_token=None, config=None):
  4499. """
  4500. bind tags to volume
  4501. :param volume_id:
  4502. The id of the volume which will be renewed.
  4503. :type volume_id: string
  4504. :param tags
  4505. The optional list of tag to be bonded.
  4506. :type tags: list<bcc_model.TagModel>
  4507. :return:
  4508. :rtype baidubce.bce_response.BceResponse
  4509. """
  4510. params = {
  4511. 'bind': None
  4512. }
  4513. if client_token is None:
  4514. params['clientToken'] = generate_client_token()
  4515. else:
  4516. params['clientToken'] = client_token
  4517. volume_id = volume_id.encode(encoding='utf-8')
  4518. path = b'/volume/%s/tag' % volume_id
  4519. body = {}
  4520. if relation_tag is not None:
  4521. body['relationTag'] = relation_tag
  4522. if tags is not None:
  4523. tag_list = [tag.__dict__ for tag in tags]
  4524. body['changeTags'] = tag_list
  4525. return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
  4526. @required(volume_id=str) # ***Unicode***
  4527. def untag_volume(self, volume_id, relation_tag=None, tags=None, client_token=None, config=None):
  4528. """
  4529. unbind tags to volume
  4530. :param volume_id:
  4531. The id of the volume which will be renewed.
  4532. :type volume_id: string
  4533. :param tags
  4534. The optional list of tag to be bonded.
  4535. :type tags: list<bcc_model.TagModel>
  4536. :return:
  4537. :rtype baidubce.bce_response.BceResponse
  4538. """
  4539. params = {
  4540. 'unbind': None
  4541. }
  4542. if client_token is None:
  4543. params['clientToken'] = generate_client_token()
  4544. else:
  4545. params['clientToken'] = client_token
  4546. volume_id = volume_id.encode(encoding='utf-8')
  4547. path = b'/volume/%s/tag' % volume_id
  4548. body = {}
  4549. if relation_tag is not None:
  4550. body['relationTag'] = relation_tag
  4551. if tags is not None:
  4552. tag_list = [tag.__dict__ for tag in tags]
  4553. body['changeTags'] = tag_list
  4554. return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
  4555. @required(volume_id=str) # ***Unicode***
  4556. def list_snapshot_chain(self, volume_id, order=None, order_by=None,
  4557. page_no=None, page_size=None, client_token=None, config=None):
  4558. """
  4559. list_snapshot_chain
  4560. :param volume_id:
  4561. The id of the volume which will be renewed.
  4562. :type volume_id: string
  4563. :param order
  4564. The response list order. Value: asc/desc
  4565. :type order: string
  4566. :param order_by
  4567. The response list order. Value: chainId(default)/chainSize/volumeSize
  4568. :type order_by: string
  4569. :param page_no
  4570. page number. default value = 1
  4571. :type page_no: int
  4572. :param page_size
  4573. page size. default value = 1000
  4574. :type page_size: int
  4575. :return:
  4576. :rtype baidubce.bce_response.BceResponse
  4577. """
  4578. path = b'/snapshot/chain'
  4579. params = {
  4580. 'volumeId': volume_id
  4581. }
  4582. if client_token is None:
  4583. params['clientToken'] = generate_client_token()
  4584. else:
  4585. params['clientToken'] = client_token
  4586. if order is not None:
  4587. params['order'] = order
  4588. if order_by is not None:
  4589. params['orderBy'] = order_by
  4590. if page_no is not None:
  4591. params['pageNo'] = page_no
  4592. if page_size is not None:
  4593. params['pageSize'] = page_size
  4594. return self._send_request(http_methods.GET, path, params=params, config=config)
  4595. @required(chain_id=str) # ***Unicode***
  4596. def tag_snapshot_chain(self, chain_id, tags=None, client_token=None, config=None):
  4597. """
  4598. bind tags to snapshot chain
  4599. :param chain_id:
  4600. The id of the volume which will be renewed.
  4601. :type chain_id: string
  4602. :param tags
  4603. The optional list of tag to be bonded.
  4604. :type tags: list<bcc_model.TagModel>
  4605. :return:
  4606. :rtype baidubce.bce_response.BceResponse
  4607. """
  4608. params = {
  4609. 'bind': None
  4610. }
  4611. if client_token is None:
  4612. params['clientToken'] = generate_client_token()
  4613. else:
  4614. params['clientToken'] = client_token
  4615. chain_id = chain_id.encode(encoding='utf-8')
  4616. path = b'/snapshot/chain/%s/tag' % chain_id
  4617. body = {}
  4618. if tags is not None:
  4619. tag_list = [tag.__dict__ for tag in tags]
  4620. body['changeTags'] = tag_list
  4621. return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
  4622. @required(chain_id=str) # ***Unicode***
  4623. def untag_snapshot_chain(self, chain_id, tags=None, client_token=None, config=None):
  4624. """
  4625. unbind tags to snapshot chain
  4626. :param chain_id:
  4627. The id of the volume which will be renewed.
  4628. :type chain_id: string
  4629. :param tags
  4630. The optional list of tag to be bonded.
  4631. :type tags: list<bcc_model.TagModel>
  4632. :return:
  4633. :rtype baidubce.bce_response.BceResponse
  4634. """
  4635. params = {
  4636. 'unbind': None
  4637. }
  4638. if client_token is None:
  4639. params['clientToken'] = generate_client_token()
  4640. else:
  4641. params['clientToken'] = client_token
  4642. chain_id = chain_id.encode(encoding='utf-8')
  4643. path = b'/snapshot/chain/%s/tag' % chain_id
  4644. body = {}
  4645. if tags is not None:
  4646. tag_list = [tag.__dict__ for tag in tags]
  4647. body['changeTags'] = tag_list
  4648. return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
  4649. def update_asp(self, name=None, asp_id=None, time_points=None, repeat_week_days=None, retention_days=None,
  4650. client_token=None, config=None):
  4651. """
  4652. update asp
  4653. Attention: Param name and asp_id can not both be none.
  4654. :param name:
  4655. The name of the asp.
  4656. :type name: string
  4657. :param asp_id:
  4658. Identify of asp.
  4659. :type asp_id: string
  4660. :param time_points:
  4661. Daily triggering time(hour of day, 0 ~ 23) of snapshot policy. e.g. [0, 6, 12, 18].
  4662. :type time_points: list
  4663. :param repeat_week_days:
  4664. Weekly triggering time(day of week, 0 ~ 6, 0 means Sunday) of snapshot policy. e.g. [1, 3]
  4665. :type repeat_week_days: list
  4666. :param retention_days:
  4667. Retention days of snapshot.
  4668. :type retention_days: int
  4669. :return:
  4670. :rtype baidubce.bce_response.BceResponse
  4671. """
  4672. path = b'/asp/update'
  4673. params = {}
  4674. if client_token is None:
  4675. params['clientToken'] = generate_client_token()
  4676. else:
  4677. params['clientToken'] = client_token
  4678. body = {}
  4679. if name is not None:
  4680. body['name'] = name
  4681. if asp_id is not None:
  4682. body['aspId'] = asp_id
  4683. if time_points is not None:
  4684. body['timePoints'] = time_points
  4685. if repeat_week_days is not None:
  4686. body['repeatWeekdays'] = repeat_week_days
  4687. if retention_days is not None:
  4688. body['retentionDays'] = retention_days
  4689. return self._send_request(http_methods.PUT, path, json.dumps(body),
  4690. params=params, config=config)
  4691. def get_price_by_spec(self, spec_id=None, spec=None, payment_timing=None, zone_name=None, purchase_num=None,
  4692. purchase_length=None, client_token=None, config=None):
  4693. """
  4694. Get price of instance flover by spec.
  4695. Attention: Param spec_id and spec can not both be none.
  4696. :param spec_id:
  4697. Identify of the spec.
  4698. :type spec_id: string
  4699. :param spec:
  4700. The name of spec.
  4701. :type spec: string
  4702. :param payment_timing:
  4703. Payment timing of instance, prepay or postpay.
  4704. :type payment_timing: string
  4705. :param zone_name:
  4706. Name of available zone.
  4707. :type zone_name: string
  4708. :param purchase_num:
  4709. Number of purchase.
  4710. :type purchase_num: int
  4711. :param purchase_length:
  4712. Reservation time.
  4713. :type purchase_length: int
  4714. :return:
  4715. :rtype baidubce.bce_response.BceResponse
  4716. """
  4717. path = b'/instance/price'
  4718. params = {}
  4719. if client_token is None:
  4720. params['clientToken'] = generate_client_token()
  4721. else:
  4722. params['clientToken'] = client_token
  4723. body = {}
  4724. if spec_id is not None:
  4725. body['specId'] = spec_id
  4726. if spec is not None:
  4727. body['spec'] = spec
  4728. if payment_timing is not None:
  4729. body['paymentTiming'] = payment_timing
  4730. if zone_name is not None:
  4731. body['zoneName'] = zone_name
  4732. if purchase_num is not None:
  4733. body['purchaseCount'] = purchase_num
  4734. if purchase_length is not None:
  4735. body['purchaseLength'] = purchase_length
  4736. return self._send_request(http_methods.POST, path, json.dumps(body),
  4737. params=params, config=config)
  4738. def list_type_zones(self, spec_id=None, spec=None, product_type=None, instance_type=None,
  4739. client_token=None, config=None):
  4740. """
  4741. list the logicalZone from the bcc package specification.
  4742. :param spec_id:
  4743. Identify of the spec.
  4744. :type spec_id: string
  4745. :param spec:
  4746. The name of spec.
  4747. :type spec: string
  4748. :param product_type:
  4749. Payment timing of instance, prepay or postpay.
  4750. :type product_type: string
  4751. :param instance_type:
  4752. The specified Specification to create the instance,
  4753. See more detail on
  4754. https://cloud.baidu.com/doc/BCC/API.html#InstanceType
  4755. :type instance_type: string
  4756. :return:
  4757. :rtype baidubce.bce_response.BceResponse
  4758. """
  4759. path = b'/instance/flavorZones'
  4760. params = {}
  4761. if client_token is None:
  4762. params['clientToken'] = generate_client_token()
  4763. else:
  4764. params['clientToken'] = client_token
  4765. if spec_id is not None:
  4766. params['specId'] = spec_id
  4767. if spec is not None:
  4768. params['spec'] = spec
  4769. if product_type is not None:
  4770. params['productType'] = product_type
  4771. if instance_type is not None:
  4772. params['instanceType'] = instance_type
  4773. return self._send_request(http_methods.GET, path, prefix=b"/v1", params=params, config=config)
  4774. def instance_change_subnet(self, instance_id, subnet_id=None,
  4775. internal_ip=None, reboot=None,
  4776. security_group_ids=None, enterprise_security_group_ids=None,
  4777. client_token=None, config=None):
  4778. """
  4779. Change instance subnet by id.
  4780. :param instance_id:
  4781. Identify of the instance.
  4782. :type instance_id: string
  4783. :param subnet_id:
  4784. New subnet id.
  4785. :type subnet_id: string
  4786. :param internal_ip:
  4787. Ip address of internal network.
  4788. :type internal_ip: string
  4789. :param reboot:
  4790. Reboot instance or not. Default value is False.
  4791. :type reboot: bool
  4792. :param security_group_ids:
  4793. :type security_group_ids: list<string>
  4794. :param enterprise_security_group_ids:
  4795. :type enterprise_security_group_ids: list<string>
  4796. :return:
  4797. :rtype baidubce.bce_response.BceResponse
  4798. """
  4799. path = b'/subnet/changeSubnet'
  4800. params = {}
  4801. if client_token is None:
  4802. params['clientToken'] = generate_client_token()
  4803. else:
  4804. params['clientToken'] = client_token
  4805. body = {}
  4806. if instance_id is not None:
  4807. body['instanceId'] = instance_id
  4808. if subnet_id is not None:
  4809. body['subnetId'] = subnet_id
  4810. if internal_ip is not None:
  4811. body['internalIp'] = internal_ip
  4812. if reboot is not None:
  4813. body['reboot'] = reboot
  4814. if security_group_ids is not None:
  4815. body['securityGroupIds'] = security_group_ids
  4816. if enterprise_security_group_ids is not None:
  4817. body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
  4818. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  4819. def instance_change_vpc(self, instance_id, subnet_id=None,
  4820. internal_ip=None, reboot=None, security_group_ids=None, enterprise_security_group_ids=None,
  4821. client_token=None, config=None):
  4822. """
  4823. Change instance vpc by id.
  4824. :param instance_id:
  4825. Identify of the instance.
  4826. :type instance_id: string
  4827. :param subnet_id:
  4828. New subnet id.
  4829. :type subnet_id: string
  4830. :param internal_ip:
  4831. Ip address of internal network.
  4832. :type internal_ip: string
  4833. :param reboot:
  4834. Reboot instance or not. Default value is False.
  4835. :type reboot: bool
  4836. :return:
  4837. :rtype baidubce.bce_response.BceResponse
  4838. """
  4839. path = b'/vpc/changeVpc'
  4840. params = {}
  4841. if client_token is None:
  4842. params['clientToken'] = generate_client_token()
  4843. else:
  4844. params['clientToken'] = client_token
  4845. body = {}
  4846. if instance_id is not None:
  4847. body['instanceId'] = instance_id
  4848. if subnet_id is not None:
  4849. body['subnetId'] = subnet_id
  4850. if internal_ip is not None:
  4851. body['internalIp'] = internal_ip
  4852. if reboot is not None:
  4853. body['reboot'] = reboot
  4854. if security_group_ids is not None:
  4855. body['securityGroupIds'] = security_group_ids
  4856. if enterprise_security_group_ids is not None:
  4857. body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
  4858. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  4859. @required(chain_id=str) # ***Unicode***
  4860. def list_instance_enis(self, instance_id, client_token=None, config=None):
  4861. """
  4862. Change instance vpc by id.
  4863. :param instance_id:
  4864. Identify of the instance.
  4865. :type instance_id: string
  4866. :return:
  4867. :rtype baidubce.bce_response.BceResponse
  4868. """
  4869. instance_id = instance_id.encode(encoding='utf-8')
  4870. path = b'/eni/%s' % instance_id
  4871. params = {}
  4872. if client_token is None:
  4873. params['clientToken'] = generate_client_token()
  4874. else:
  4875. params['clientToken'] = client_token
  4876. return self._send_request(http_methods.GET, path, params=params, config=config)
  4877. def list_flavor_spec(self, zone_name=None, client_token=None, config=None):
  4878. """
  4879. Change instance vpc by id.
  4880. :param zone_name:
  4881. Available zone name
  4882. :type zone_name: string
  4883. :return:
  4884. :rtype baidubce.bce_response.BceResponse
  4885. """
  4886. path = b'/instance/flavorSpec'
  4887. params = {}
  4888. if client_token is None:
  4889. params['clientToken'] = generate_client_token()
  4890. else:
  4891. params['clientToken'] = client_token
  4892. if zone_name is not None:
  4893. params['zoneName'] = zone_name
  4894. return self._send_request(http_methods.GET, path, params=params, config=config)
  4895. def resize_instance_by_spec(self, instance_id, spec, enable_jumbo_frame=None, client_token=None, config=None):
  4896. """
  4897. Resize instance by spec.
  4898. :param instance_id:
  4899. Identify of the instance.
  4900. :type instance_id: string
  4901. :param spec:
  4902. The name of spec.
  4903. :type spec: string
  4904. :param enable_jumbo_frame:
  4905. The parameter of specified the instance enable/disable jumbo frame.
  4906. True means enable jumbo frame, false means disable jumbo frame.
  4907. enable_jumbo_frame default None which means:
  4908. When you change to the spec which doesn't support jumbo frame, the jumbo frame will be disabled.
  4909. When the original instance don't support jumbo frame and you change to the spec which support jumbo frame,
  4910. the jumbo frame will be disabled.
  4911. When the original spec of the instance support jumbo frame , then you change to the spec which support jumbo
  4912. frame, if the original instance enable jumbo frame, the jumbo frame will be enabled, if the original instance
  4913. disable jumbo frame, the jumbo frame will be disabled.
  4914. :type enable_jumbo_frame: bool
  4915. :return:
  4916. :rtype baidubce.bce_response.BceResponse
  4917. """
  4918. instance_id = instance_id.encode(encoding='utf-8')
  4919. path = b'/instanceBySpec/%s' % instance_id
  4920. params = {
  4921. "resize": None
  4922. }
  4923. if client_token is None:
  4924. params['clientToken'] = generate_client_token()
  4925. else:
  4926. params['clientToken'] = client_token
  4927. body = {
  4928. "spec": spec
  4929. }
  4930. if enable_jumbo_frame is not None:
  4931. body['enableJumboFrame'] = enable_jumbo_frame
  4932. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  4933. def batch_rebuild_instances(self, image_id, admin_pass, instance_ids, keypair_id=None, is_keep_image_login=None,
  4934. client_token=None, config=None, user_data=None, use_last_user_data=None,
  4935. is_open_hostEye=None, sys_root_size=None, is_preserve_data=None, raid_id=None,
  4936. data_partition_type=None, root_partition_type=None):
  4937. """
  4938. Batch rebuild instances.
  4939. :param image_id:
  4940. Image id for rebuild.
  4941. :type image_id: string
  4942. :param admin_pass:
  4943. The password of admin.
  4944. :type admin_pass: string
  4945. :param instance_ids:
  4946. Identify list of instances need to rebuild.
  4947. :type instance_ids: list of string
  4948. :param keypair_id:
  4949. Set the id of the keypair to be bound. (optional param)
  4950. :type keypair_id: string
  4951. :param user_data:
  4952. UserData of the instance.
  4953. :param use_last_user_data:
  4954. Use last user data.
  4955. :param is_open_hostEye:
  4956. Is open host eye.
  4957. :param sys_root_size:
  4958. System disk size.
  4959. :param is_preserve_data:
  4960. Preserve data.
  4961. :param raid_id:
  4962. Raid id.
  4963. :param data_partition_type:
  4964. Data partition type.
  4965. :param root_partition_type:
  4966. Root partition type.
  4967. :return:
  4968. :rtype baidubce.bce_response.BceResponse
  4969. """
  4970. path = b'/instance/rebuild'
  4971. params = {}
  4972. if client_token is None:
  4973. params['clientToken'] = generate_client_token()
  4974. else:
  4975. params['clientToken'] = client_token
  4976. body = {
  4977. "imageId": image_id,
  4978. "instanceIds": instance_ids
  4979. }
  4980. if admin_pass is not None:
  4981. secret_access_key = self.config.credentials.secret_access_key
  4982. cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
  4983. body['adminPass'] = cipher_admin_pass
  4984. if keypair_id is not None:
  4985. body['keypairId'] = keypair_id
  4986. if is_keep_image_login is not None:
  4987. body['keepImageLogin'] = is_keep_image_login
  4988. if user_data is not None:
  4989. body['userData'] = user_data
  4990. if use_last_user_data is not None:
  4991. body['useLastUserData'] = use_last_user_data
  4992. if is_open_hostEye is not None:
  4993. body['isOpenHostEye'] = is_open_hostEye
  4994. if sys_root_size is not None:
  4995. body['sysRootSize'] = sys_root_size
  4996. if is_preserve_data is not None:
  4997. body['isPreserveData'] = is_preserve_data
  4998. if raid_id is not None:
  4999. body['raidId'] = raid_id
  5000. if data_partition_type is not None:
  5001. body['dataPartitionType'] = data_partition_type
  5002. if root_partition_type is not None:
  5003. body['rootPartitionType'] = root_partition_type
  5004. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  5005. def change_to_prepaid(self, instance_id, duration, relation_cds, auto_renew, auto_renew_period=None,
  5006. client_token=None, config=None):
  5007. """
  5008. Change instance pay timing to prepaid.
  5009. :param instance_id:
  5010. Identify of the instance to change
  5011. :type instance_id: string
  5012. :param duration:
  5013. Set the duration time of prepayment, unit:month.
  5014. :type duration: int
  5015. :param relation_cds:
  5016. Set whether to chagne the associated data disk. True - change; False - no change. Default is False.
  5017. :type relation_cds: bool
  5018. :param auto_renew:
  5019. Whether to enable automatic renewal, defaults to False.
  5020. :type auto_renew: bool
  5021. :param auto_renew_period:
  5022. Duration of each automatic renewal(Unit: months).
  5023. Value range: 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 24, 36. If not specified, the default is 1.
  5024. This parameter is effective only when auto_renew is set to true.
  5025. :type auto_renew_period: int
  5026. :return:
  5027. :rtype baidubce.bce_response.BceResponse
  5028. """
  5029. instance_id = instance_id.encode(encoding='utf-8')
  5030. path = b'/instance/%s' % instance_id
  5031. params = {
  5032. 'toPrepay': None
  5033. }
  5034. if client_token is None:
  5035. params['clientToken'] = generate_client_token()
  5036. else:
  5037. params['clientToken'] = client_token
  5038. body = {
  5039. "duration": duration
  5040. }
  5041. if auto_renew is not None:
  5042. body['autoRenew'] = auto_renew
  5043. body['autoRenewPeriod'] = auto_renew_period
  5044. if relation_cds is not None:
  5045. body['relationCds'] = relation_cds
  5046. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5047. def list_instance_no_charge(self, marker=None, max_keys=None, internal_ip=None, keypair_id=None,
  5048. zone_name=None, client_token=None, config=None):
  5049. """
  5050. Return a list of no charge instances owned by the authenticated user.
  5051. :param marker:
  5052. The optional parameter marker specified in the original request to specify
  5053. where in the results to begin listing.
  5054. Together with the marker, specifies the list result which listing should begin.
  5055. If the marker is not specified, the list result will listing from the first one.
  5056. :type marker: string
  5057. :param max_keys:
  5058. The optional parameter to specifies the max number of list result to return.
  5059. The default value is 1000.
  5060. :type max_keys: int
  5061. :param internal_ip:
  5062. The identified internal ip of instance.
  5063. :type internal_ip: string
  5064. :param keypair_id:
  5065. get instance list filtered by keypair
  5066. :type keypair_id: string
  5067. :param zone_name:
  5068. get instance list filtered by name of available zone
  5069. :type zone_name: string
  5070. :return:
  5071. :rtype baidubce.bce_response.BceResponse
  5072. """
  5073. path = b'/instance/noCharge'
  5074. params = {}
  5075. if client_token is None:
  5076. params['clientToken'] = generate_client_token()
  5077. else:
  5078. params['clientToken'] = client_token
  5079. if marker is not None:
  5080. params['marker'] = marker
  5081. if max_keys is not None:
  5082. params['maxKeys'] = max_keys
  5083. if internal_ip is not None:
  5084. params['internalIp'] = internal_ip
  5085. if keypair_id is not None:
  5086. params['keypairId'] = keypair_id
  5087. if zone_name is not None:
  5088. params['zoneName'] = zone_name
  5089. return self._send_request(http_methods.GET, path, params=params, config=config)
  5090. def cancel_bid_order(self, order_id, client_token=None, config=None):
  5091. """
  5092. Cancel a bid order
  5093. :param order_id:
  5094. Identify of the order to cancel
  5095. :type order_id: string
  5096. :return:
  5097. :rtype baidubce.bce_response.BceResponse
  5098. """
  5099. path = b'/instance/cancelBidOrder'
  5100. params = {}
  5101. if client_token is None:
  5102. params['clientToken'] = generate_client_token()
  5103. else:
  5104. params['clientToken'] = client_token
  5105. body = {
  5106. "orderId": order_id
  5107. }
  5108. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5109. def batch_create_auto_renew_rules(self, instance_id, renew_time_unit="month", renew_time=1,
  5110. renew_cds=None, renew_eip=None, client_token=None, config=None):
  5111. """
  5112. create auto renew rules for instance
  5113. :param instance_id:
  5114. Identify of the instance to auto renew
  5115. :type instance_id: string
  5116. :param renew_time_unit:
  5117. Time unit for renew, values: 'month'/'year', default value: month
  5118. :type renew_time_unit: string
  5119. :param renew_time:
  5120. renew time of year, values: 1/2/3, default value: 1
  5121. :type renew_time: int
  5122. :param renew_cds:
  5123. renew cds, values: True/False, default value: True
  5124. :param renew_eip:
  5125. renew eip, values: True/False, default value: True
  5126. :return:
  5127. :rtype baidubce.bce_response.BceResponse
  5128. """
  5129. path = b'/instance/batchCreateAutoRenewRules'
  5130. params = {}
  5131. if client_token is None:
  5132. params['clientToken'] = generate_client_token()
  5133. else:
  5134. params['clientToken'] = client_token
  5135. body = {
  5136. "instanceId": instance_id,
  5137. "renewTimeUnit": renew_time_unit,
  5138. "renewTime": renew_time
  5139. }
  5140. if renew_cds is not None:
  5141. body["renewCds"] = renew_cds
  5142. if renew_eip is not None:
  5143. body["renewEip"] = renew_eip
  5144. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5145. def batch_delete_auto_renew_rules(self, instance_id, renew_cds=None, renew_eip=None,
  5146. client_token=None, config=None):
  5147. """
  5148. delete auto renew rules for instance
  5149. :param instance_id:
  5150. Identify of the instance to auto renew
  5151. :type instance_id: string
  5152. :param renew_cds:
  5153. renew cds, values: True/False, default value: True
  5154. :param renew_eip:
  5155. renew eip, values: True/False, default value: True
  5156. :return:
  5157. :rtype baidubce.bce_response.BceResponse
  5158. """
  5159. path = b'/instance/batchDeleteAutoRenewRules'
  5160. params = {}
  5161. if client_token is None:
  5162. params['clientToken'] = generate_client_token()
  5163. else:
  5164. params['clientToken'] = client_token
  5165. body = {
  5166. "instanceId": instance_id
  5167. }
  5168. if renew_cds is not None:
  5169. body["renewCds"] = renew_cds
  5170. if renew_eip is not None:
  5171. body["renewEip"] = renew_eip
  5172. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5173. def delete_recycled_instance(self, instance_id, client_token=None, config=None):
  5174. """
  5175. delete auto renew rules for instance
  5176. :param instance_id:
  5177. Identify of the instance to delete
  5178. :type instance_id: string
  5179. :return:
  5180. :rtype baidubce.bce_response.BceResponse
  5181. """
  5182. instance_id = instance_id.encode(encoding='utf-8')
  5183. path = b'/recycle/instance/%s' % instance_id
  5184. params = {}
  5185. if client_token is None:
  5186. params['clientToken'] = generate_client_token()
  5187. else:
  5188. params['clientToken'] = client_token
  5189. body = {}
  5190. return self._send_request(http_methods.DELETE, path, body=json.dumps(body), params=params, config=config)
  5191. def list_instance_by_instance_ids(self, instance_ids, marker=None, max_keys=None, client_token=None, config=None):
  5192. """
  5193. list instances by id list
  5194. :param instance_ids:
  5195. Identify of the instances to return info
  5196. :type instance_ids: list of string
  5197. :param marker:
  5198. The optional parameter marker specified in the original request to specify
  5199. where in the results to begin listing.
  5200. Together with the marker, specifies the list result which listing should begin.
  5201. If the marker is not specified, the list result will listing from the first one.
  5202. :type marker: string
  5203. :param max_keys:
  5204. The optional parameter to specifies the max number of list result to return.
  5205. The default value is 1000.
  5206. :type max_keys: int
  5207. :return:
  5208. :rtype baidubce.bce_response.BceResponse
  5209. """
  5210. path = b'/instance/listByInstanceId'
  5211. params = {}
  5212. if client_token is None:
  5213. params['clientToken'] = generate_client_token()
  5214. else:
  5215. params['clientToken'] = client_token
  5216. if marker is not None:
  5217. params['marker'] = marker
  5218. if max_keys is not None:
  5219. params['maxKeys'] = max_keys
  5220. body = {
  5221. "instanceIds": instance_ids
  5222. }
  5223. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5224. def get_instance_delete_progress(self, instance_ids, client_token=None, config=None):
  5225. """
  5226. get instances delete progress
  5227. :param instance_ids:
  5228. Identify of the instances to return info
  5229. :type instance_ids: list of string
  5230. :return:
  5231. :rtype baidubce.bce_response.BceResponse
  5232. """
  5233. path = b'/instance/deleteProgress'
  5234. params = {}
  5235. if client_token is None:
  5236. params['clientToken'] = generate_client_token()
  5237. else:
  5238. params['clientToken'] = client_token
  5239. body = {
  5240. "instanceIds": instance_ids
  5241. }
  5242. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5243. def batch_delete_instance_with_related_resource(self, instance_ids, related_release_flag=None,
  5244. delete_cds_snapshot_flag=None, delete_related_enis_flag=None,
  5245. bcc_recycle_flag=None, cds_attribute_active=None,
  5246. client_token=None, config=None):
  5247. """
  5248. batch delete instance with related resource
  5249. :param instance_ids:
  5250. Identify of the instances to return info
  5251. :type instance_ids: list of string
  5252. :param related_release_flag:
  5253. Release or not related resources.
  5254. :type related_release_flag: bool
  5255. :param delete_cds_snapshot_flag:
  5256. Delete or not cds snapshot.
  5257. :type delete_cds_snapshot_flag: bool
  5258. :param delete_related_enis_flag:
  5259. Delete or not related enis.
  5260. :type delete_related_enis_flag: bool
  5261. :param bcc_recycle_flag:
  5262. Recycle or not bcc instance.
  5263. :type bcc_recycle_flag: bool
  5264. :return:
  5265. :rtype baidubce.bce_response.BceResponse
  5266. """
  5267. path = b'/instance/batchDelete'
  5268. params = {}
  5269. if client_token is None:
  5270. params['clientToken'] = generate_client_token()
  5271. else:
  5272. params['clientToken'] = client_token
  5273. body = {
  5274. "instanceIds": instance_ids
  5275. }
  5276. if related_release_flag is not None:
  5277. body['relatedReleaseFlag'] = related_release_flag
  5278. if delete_cds_snapshot_flag is not None:
  5279. body['deleteCdsSnapshotFlag'] = delete_cds_snapshot_flag
  5280. if delete_related_enis_flag is not None:
  5281. body['deleteRelatedEnisFlag'] = delete_related_enis_flag
  5282. if bcc_recycle_flag is not None:
  5283. body['bccRecycleFlag'] = bcc_recycle_flag
  5284. if bcc_recycle_flag is not None:
  5285. body['cdsAttributeActive'] = cds_attribute_active
  5286. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5287. def batch_start_instance(self, instance_ids, client_token=None, config=None):
  5288. """
  5289. batch start instance
  5290. :param instance_ids:
  5291. Identify of the instances to return info
  5292. :type instance_ids: list of string
  5293. :return:
  5294. :rtype baidubce.bce_response.BceResponse
  5295. """
  5296. path = b'/instance/batchAction'
  5297. params = {
  5298. 'start': None
  5299. }
  5300. if client_token is None:
  5301. params['clientToken'] = generate_client_token()
  5302. else:
  5303. params['clientToken'] = client_token
  5304. body = {
  5305. "instanceIds": instance_ids
  5306. }
  5307. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  5308. def batch_stop_instance(self, instance_ids, force_stop=None, stop_with_no_charge=None,
  5309. client_token=None, config=None):
  5310. """
  5311. batch stop instance
  5312. :param instance_ids:
  5313. Identify of the instances to return info
  5314. :type instance_ids: list of string
  5315. :param force_stop:
  5316. force stop instance
  5317. :type force_stop: bool
  5318. :param stop_with_no_charge:
  5319. stop instance and stop billing
  5320. :type stop_with_no_charge: bool
  5321. :return:
  5322. :rtype baidubce.bce_response.BceResponse
  5323. """
  5324. path = b'/instance/batchAction'
  5325. params = {
  5326. 'stop': None
  5327. }
  5328. if client_token is None:
  5329. params['clientToken'] = generate_client_token()
  5330. else:
  5331. params['clientToken'] = client_token
  5332. body = {
  5333. "instanceIds": instance_ids
  5334. }
  5335. if force_stop is not None:
  5336. body['forceStop'] = force_stop
  5337. if stop_with_no_charge is not None:
  5338. body['stopWithNoCharge'] = stop_with_no_charge
  5339. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  5340. def list_id_mappings(self, ids, id_type, object_type, client_token=None, config=None):
  5341. """
  5342. get short-long id mapping by short/long id list
  5343. :param ids:
  5344. short id list
  5345. :type ids: list of string
  5346. :param id_type:
  5347. id type
  5348. :type id_type: string. value: short|long
  5349. :param object_type:
  5350. object type
  5351. :type object_type: value: bcc
  5352. :return:
  5353. :rtype baidubce.bce_response.BceResponse
  5354. """
  5355. path = b'/instance/id/mapping'
  5356. params = {}
  5357. if client_token is None:
  5358. params['clientToken'] = generate_client_token()
  5359. else:
  5360. params['clientToken'] = client_token
  5361. body = {
  5362. "instanceIds": ids,
  5363. "idType": id_type,
  5364. "objectType": object_type
  5365. }
  5366. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5367. def batch_resize_instance(self, instance_ids, spec, subnet_id=None, logical_zone=None, internal_ip_v4=None,
  5368. enable_jumbo_frame=None, client_token=None, config=None):
  5369. """
  5370. batch resize instance
  5371. :param instance_ids:
  5372. Identify of the instances to return info
  5373. :type instance_ids: list of string
  5374. :param spec:
  5375. spec
  5376. :type spec: string
  5377. :param subnet_id:
  5378. subnet id
  5379. :type subnet_id: string
  5380. :param logical_zone:
  5381. logical zone name
  5382. :type logical_zone: string
  5383. :param internal_ip_v4:
  5384. internal ip for ipv4
  5385. :type internal_ip_v4: string
  5386. :param enable_jumbo_frame:
  5387. The parameter of specified the instance enable/disable jumbo frame.
  5388. True means enable jumbo frame, false means disable jumbo frame.
  5389. enable_jumbo_frame default None which means:
  5390. When you change to the spec which doesn't support jumbo frame, the jumbo frame will be disabled.
  5391. When the original instance don't support jumbo frame and you change to the spec which support jumbo frame,
  5392. the jumbo frame will be disabled.
  5393. When the original spec of the instance support jumbo frame , then you change to the spec which support jumbo
  5394. frame, if the original instance enable jumbo frame, the jumbo frame will be enabled, if the original instance
  5395. disable jumbo frame, the jumbo frame will be disabled.
  5396. :type enable_jumbo_frame: bool
  5397. :return:
  5398. :rtype baidubce.bce_response.BceResponse
  5399. """
  5400. path = b'/instanceBatchBySpec'
  5401. params = {
  5402. 'resize': None
  5403. }
  5404. if client_token is None:
  5405. params['clientToken'] = generate_client_token()
  5406. else:
  5407. params['clientToken'] = client_token
  5408. body = {
  5409. "instanceIdList": instance_ids,
  5410. "spec": spec
  5411. }
  5412. if subnet_id is not None:
  5413. body['subnetId'] = subnet_id
  5414. if logical_zone is not None:
  5415. body['logicalZone'] = logical_zone
  5416. if internal_ip_v4 is not None:
  5417. body['internalIpV4'] = internal_ip_v4
  5418. if enable_jumbo_frame is not None:
  5419. body['enableJumboFrame'] = enable_jumbo_frame
  5420. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  5421. def list_available_resize_specs(self, instance_ids, spec=None, spec_id=None, logical_zone=None,
  5422. client_token=None, config=None):
  5423. """
  5424. list available specs of resize instance in specified zone
  5425. :param instance_ids:
  5426. Identify of the instances to return info
  5427. :type instance_ids: list of string
  5428. :param spec:
  5429. spec
  5430. :type spec: string
  5431. :param spec_id:
  5432. spec id
  5433. :type spec_id: string
  5434. :param logical_zone:
  5435. logical zone name
  5436. :type logical_zone: string
  5437. :return:
  5438. :rtype baidubce.bce_response.BceResponse
  5439. """
  5440. path = b'/instance'
  5441. params = {
  5442. 'resizeList': None
  5443. }
  5444. if client_token is None:
  5445. params['clientToken'] = generate_client_token()
  5446. else:
  5447. params['clientToken'] = client_token
  5448. body = {
  5449. "instanceIdList": instance_ids,
  5450. "spec": spec
  5451. }
  5452. if spec_id is not None:
  5453. body['specId'] = spec_id
  5454. if logical_zone is not None:
  5455. body['zone'] = logical_zone
  5456. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5457. def batch_change_instance_to_prepay(self, change_pay_timing_req_list, client_token=None, config=None):
  5458. """
  5459. batch change instance to prepay
  5460. :param change_pay_timing_req_list:
  5461. batch change req list
  5462. :type change_pay_timing_req_list: list of PayTimingChangeReqModel
  5463. :return:
  5464. :rtype baidubce.bce_response.BceResponse
  5465. """
  5466. path = b'/instance/batch/charging'
  5467. params = {
  5468. 'toPrepay': None
  5469. }
  5470. if client_token is None:
  5471. params['clientToken'] = generate_client_token()
  5472. else:
  5473. params['clientToken'] = client_token
  5474. body = {
  5475. "config": [change_pay_timing_req.__dict__ for change_pay_timing_req in change_pay_timing_req_list]
  5476. }
  5477. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5478. def batch_change_instance_to_postpay(self, change_pay_timing_req_list, client_token=None, config=None):
  5479. """
  5480. batch change instance to postpay
  5481. :param change_pay_timing_req_list:
  5482. batch change req list
  5483. :type change_pay_timing_req_list: list of PayTimingChangeReqModel
  5484. :return:
  5485. :rtype baidubce.bce_response.BceResponse
  5486. """
  5487. path = b'/instance/batch/charging'
  5488. params = {
  5489. 'toPostpay': None
  5490. }
  5491. if client_token is None:
  5492. params['clientToken'] = generate_client_token()
  5493. else:
  5494. params['clientToken'] = client_token
  5495. body = {
  5496. "config": [change_pay_timing_req.__dict__ for change_pay_timing_req in change_pay_timing_req_list]
  5497. }
  5498. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5499. def list_instance_roles(self, client_token=None, config=None):
  5500. """
  5501. list instance role
  5502. :return:
  5503. :rtype baidubce.bce_response.BceResponse
  5504. """
  5505. path = b'/instance/role/list'
  5506. params = {}
  5507. if client_token is None:
  5508. params['clientToken'] = generate_client_token()
  5509. else:
  5510. params['clientToken'] = client_token
  5511. return self._send_request(http_methods.GET, path, params=params, config=config)
  5512. def bind_instance_role(self, instance_ids, role_name, client_token=None, config=None):
  5513. """
  5514. bind_instance_role
  5515. :param instance_ids:
  5516. instance id list
  5517. :type instance_ids: list of string
  5518. :param role_name:
  5519. name of role
  5520. :type role_name: string
  5521. :return:
  5522. :rtype baidubce.bce_response.BceResponse
  5523. """
  5524. path = b'/instance/role'
  5525. params = {
  5526. 'bind': None
  5527. }
  5528. instances = []
  5529. for instance_id in instance_ids:
  5530. instances.append({'instanceId': instance_id})
  5531. if client_token is None:
  5532. params['clientToken'] = generate_client_token()
  5533. else:
  5534. params['clientToken'] = client_token
  5535. body = {
  5536. "instances": instances,
  5537. "roleName": role_name
  5538. }
  5539. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5540. def unbind_instance_role(self, instance_ids, role_name, client_token=None, config=None):
  5541. """
  5542. unbind_instance_role
  5543. :param instance_ids:
  5544. instance id list
  5545. :type instance_ids: list of string
  5546. :param role_name:
  5547. name of role
  5548. :type role_name: string
  5549. :return:
  5550. :rtype baidubce.bce_response.BceResponse
  5551. """
  5552. path = b'/instance/role'
  5553. params = {
  5554. 'unbind': None
  5555. }
  5556. instances = []
  5557. for instance_id in instance_ids:
  5558. instances.append({'instanceId': instance_id})
  5559. if client_token is None:
  5560. params['clientToken'] = generate_client_token()
  5561. else:
  5562. params['clientToken'] = client_token
  5563. body = {
  5564. "instances": instances,
  5565. "roleName": role_name
  5566. }
  5567. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5568. def add_ipv6(self, instance_id, ipv6_address, reboot=False, client_token=None, config=None):
  5569. """
  5570. add_ipv6
  5571. :param instance_id:
  5572. instance id
  5573. :type instance_id: list of string
  5574. :param ipv6_address:
  5575. ipv6 address to bind instance
  5576. :type ipv6_address: list of string
  5577. :param reboot:
  5578. reboot the instance
  5579. :type reboot: list of string
  5580. :return:
  5581. :rtype baidubce.bce_response.BceResponse
  5582. """
  5583. path = b'/instance/addIpv6'
  5584. params = {}
  5585. if client_token is None:
  5586. params['clientToken'] = generate_client_token()
  5587. else:
  5588. params['clientToken'] = client_token
  5589. body = {
  5590. "instanceId": instance_id,
  5591. "ipv6Address": ipv6_address,
  5592. "reboot": reboot
  5593. }
  5594. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5595. def delete_ipv6(self, instance_id, reboot=False, client_token=None, config=None):
  5596. """
  5597. delete_ipv6
  5598. :param instance_id:
  5599. instance id
  5600. :type instance_id: list of string
  5601. :param reboot:
  5602. reboot the instance
  5603. :type reboot: list of string
  5604. :return:
  5605. :rtype baidubce.bce_response.BceResponse
  5606. """
  5607. path = b'/instance/delIpv6'
  5608. params = {}
  5609. if client_token is None:
  5610. params['clientToken'] = generate_client_token()
  5611. else:
  5612. params['clientToken'] = client_token
  5613. body = {
  5614. "instanceId": instance_id,
  5615. "reboot": reboot
  5616. }
  5617. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5618. def bind_image_to_tags(self, image_id, tags, client_token=None, config=None):
  5619. """
  5620. bind_image_to_tags
  5621. :param image_id:
  5622. image id
  5623. :type image_id: list of string
  5624. :param tags
  5625. The optional list of tag to be bonded.
  5626. :type tags: list<bcc_model.TagModel>
  5627. :return:
  5628. :rtype baidubce.bce_response.BceResponse
  5629. """
  5630. image_id = image_id.encode(encoding='utf-8')
  5631. path = b'/image/%s/tag' % image_id
  5632. params = {
  5633. 'bind': None
  5634. }
  5635. if client_token is None:
  5636. params['clientToken'] = generate_client_token()
  5637. else:
  5638. params['clientToken'] = client_token
  5639. tag_list = [tag.__dict__ for tag in tags]
  5640. body = {
  5641. 'changeTags': tag_list
  5642. }
  5643. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  5644. def unbind_image_to_tags(self, image_id, tags, client_token=None, config=None):
  5645. """
  5646. unbind_image_to_tags
  5647. :param image_id:
  5648. image id
  5649. :type image_id: list of string
  5650. :param tags
  5651. The optional list of tag to be bonded.
  5652. :type tags: list<bcc_model.TagModel>
  5653. :return:
  5654. :rtype baidubce.bce_response.BceResponse
  5655. """
  5656. image_id = image_id.encode(encoding='utf-8')
  5657. path = b'/image/%s/tag' % image_id
  5658. params = {
  5659. 'unbind': None
  5660. }
  5661. if client_token is None:
  5662. params['clientToken'] = generate_client_token()
  5663. else:
  5664. params['clientToken'] = client_token
  5665. tag_list = [tag.__dict__ for tag in tags]
  5666. body = {
  5667. 'changeTags': tag_list
  5668. }
  5669. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  5670. def import_custom_image(self, os_name, os_arch, os_type, os_version, name, bos_url, client_token=None, config=None,
  5671. detection=None, generation_type=None):
  5672. """
  5673. import_custom_image
  5674. :param os_name:
  5675. name of os
  5676. :type os_name: string
  5677. :param os_arch:
  5678. archicture of os
  5679. :type os_arch: string
  5680. :param os_type:
  5681. type of os
  5682. :type os_type: string
  5683. :param os_version:
  5684. version of os
  5685. :type os_version: string
  5686. :param name:
  5687. name of os
  5688. :type name: string
  5689. :param bos_url:
  5690. boot script of os
  5691. :type bos_url: string
  5692. :return:
  5693. :rtype baidubce.bce_response.BceResponse
  5694. """
  5695. path = b'/image/import'
  5696. params = {}
  5697. if client_token is None:
  5698. params['clientToken'] = generate_client_token()
  5699. else:
  5700. params['clientToken'] = client_token
  5701. body = {
  5702. 'osName': os_name,
  5703. 'osArch': os_arch,
  5704. 'osType': os_type,
  5705. 'osVersion': os_version,
  5706. 'name': name,
  5707. 'bosUrl': bos_url
  5708. }
  5709. if detection:
  5710. body['detection'] = detection
  5711. if generation_type is not None:
  5712. body['generationType'] = generation_type
  5713. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5714. def create_remote_copy_snapshot(self, snapshot_id, dest_region_infos, client_token=None, config=None):
  5715. """
  5716. create_remote_copy_snapshot
  5717. :param snapshot_id:
  5718. identify of snapshot
  5719. :type snapshot_id: string
  5720. :param dest_region_infos:
  5721. information of destination region
  5722. :type dest_region_infos: list of bcc_model.DestRegionInfoModel
  5723. :return:
  5724. :rtype baidubce.bce_response.BceResponse
  5725. """
  5726. snapshot_id = snapshot_id.encode(encoding='utf-8')
  5727. path = b'/snapshot/remote_copy/%s' % snapshot_id
  5728. params = {}
  5729. if client_token is None:
  5730. params['clientToken'] = generate_client_token()
  5731. else:
  5732. params['clientToken'] = client_token
  5733. body = {
  5734. "destRegionInfos": [dest_region_info.__dict__ for dest_region_info in dest_region_infos]
  5735. }
  5736. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  5737. def create_deploy_set(self, name=None, strategy=None, desc=None, concurrency=None, client_token=None, config=None):
  5738. """
  5739. create_deploy_set
  5740. :param name:
  5741. name of deploy set
  5742. :type name: string
  5743. :param strategy:
  5744. deploy strategy HOST_HA | RACK_HA | TOR_HA
  5745. :type strategy: string
  5746. :param desc:
  5747. description of deploy set
  5748. :type desc: string
  5749. :param concurrency:
  5750. mark how many instances can created in one location
  5751. location means host for HOST_HA, rack for RACK_HA, tor for TOR_HA
  5752. :type concurrency: int
  5753. :return:
  5754. :rtype baidubce.bce_response.BceResponse
  5755. """
  5756. path = b'/instance/deployset/create'
  5757. params = {}
  5758. if client_token is None:
  5759. params['clientToken'] = generate_client_token()
  5760. else:
  5761. params['clientToken'] = client_token
  5762. body = {}
  5763. if name is not None:
  5764. body['name'] = name
  5765. if strategy is not None:
  5766. body['strategy'] = strategy
  5767. if desc is not None:
  5768. body['desc'] = desc
  5769. if concurrency is not None:
  5770. body['concurrency'] = concurrency
  5771. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5772. def list_deploy_sets(self, client_token=None, config=None, deployment_set_ids=None):
  5773. """
  5774. list_deploy_sets
  5775. :param deployment_set_ids:
  5776. :type deployment_set_ids: string
  5777. :return:
  5778. :rtype baidubce.bce_response.BceResponse
  5779. """
  5780. path = b'/instance/deployset/list'
  5781. params = {}
  5782. if client_token is None:
  5783. params['clientToken'] = generate_client_token()
  5784. else:
  5785. params['clientToken'] = client_token
  5786. if deployment_set_ids is not None:
  5787. params['deploymentSetIds'] = deployment_set_ids
  5788. return self._send_request(http_methods.GET, path, params=params, config=config)
  5789. def delete_deploy_set(self, deploy_set_id, client_token=None, config=None):
  5790. """
  5791. delete_deploy_set
  5792. :param deploy_set_id:
  5793. identify of deployset
  5794. :type deploy_set_id: string
  5795. :return:
  5796. :rtype baidubce.bce_response.BceResponse
  5797. """
  5798. deploy_set_id = deploy_set_id.encode(encoding='utf-8')
  5799. path = b'/instance/deployset/%s' % deploy_set_id
  5800. params = {}
  5801. if client_token is None:
  5802. params['clientToken'] = generate_client_token()
  5803. else:
  5804. params['clientToken'] = client_token
  5805. return self._send_request(http_methods.DELETE, path, params=params, config=config)
  5806. def modify_deploy_set(self, deploy_set_id, name=None, desc=None, client_token=None, config=None):
  5807. """
  5808. modify_deploy_set
  5809. :param deploy_set_id:
  5810. identify of deployset
  5811. :type deploy_set_id: string
  5812. :param name:
  5813. name of deploy set
  5814. :type name: string
  5815. :param desc:
  5816. description of deploy set
  5817. :type desc: string
  5818. :return:
  5819. :rtype baidubce.bce_response.BceResponse
  5820. """
  5821. deploy_set_id = deploy_set_id.encode(encoding='utf-8')
  5822. path = b'/instance/deployset/%s' % deploy_set_id
  5823. params = {
  5824. 'modifyAttribute': None
  5825. }
  5826. if client_token is None:
  5827. params['clientToken'] = generate_client_token()
  5828. else:
  5829. params['clientToken'] = client_token
  5830. body = {}
  5831. if name is not None:
  5832. body['name'] = name
  5833. if desc is not None:
  5834. body['desc'] = desc
  5835. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  5836. def get_deploy_set(self, deploy_set_id, client_token=None, config=None):
  5837. """
  5838. get_deploy_set
  5839. :param deploy_set_id:
  5840. identify of deployset
  5841. :type deploy_set_id: string
  5842. :return:
  5843. :rtype baidubce.bce_response.BceResponse
  5844. """
  5845. deploy_set_id = deploy_set_id.encode(encoding='utf-8')
  5846. path = b'/deployset/%s' % deploy_set_id
  5847. params = {}
  5848. if client_token is None:
  5849. params['clientToken'] = generate_client_token()
  5850. else:
  5851. params['clientToken'] = client_token
  5852. return self._send_request(http_methods.GET, path, params=params, config=config)
  5853. def update_instance_deploy(self, instance_id, deployset_id_list, force=None,
  5854. client_token=None, config=None):
  5855. """
  5856. update instance deploy relation
  5857. :param instance_id:
  5858. identify of instance
  5859. :type instance_id: string
  5860. :param deployset_id_list:
  5861. identify list of deployset
  5862. :type deployset_id_list: string
  5863. :return:
  5864. :rtype baidubce.bce_response.BceResponse
  5865. """
  5866. path = b'/instance/deployset/updateRelation'
  5867. params = {}
  5868. if client_token is None:
  5869. params['clientToken'] = generate_client_token()
  5870. else:
  5871. params['clientToken'] = client_token
  5872. body = {
  5873. 'instanceId': instance_id,
  5874. 'deploysetIdList': deployset_id_list
  5875. }
  5876. if force is not None:
  5877. body['force'] = force
  5878. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5879. def del_instance_deploy(self, instance_id_list, deploy_set_id, client_token=None, config=None):
  5880. """
  5881. delete instance deploy relation
  5882. :param instance_id_list:
  5883. identify list of instance
  5884. :type instance_id_list: string
  5885. :param deploy_set_id:
  5886. identify of deployset
  5887. :type deploy_set_id: string
  5888. :return:
  5889. :rtype baidubce.bce_response.BceResponse
  5890. """
  5891. path = b'/instance/deployset/delRelation'
  5892. params = {}
  5893. if client_token is None:
  5894. params['clientToken'] = generate_client_token()
  5895. else:
  5896. params['clientToken'] = client_token
  5897. body = {
  5898. 'instanceIdList': instance_id_list,
  5899. 'deployId': deploy_set_id
  5900. }
  5901. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5902. def create_ehc_cluster(self, name, zone_name, description=None, client_token=None, config=None):
  5903. """
  5904. create ehc cluster
  5905. :param name:
  5906. The name of the EHC cluster. This parameter is required.
  5907. :type name: string
  5908. :param zone_name:
  5909. The availability zone name where the EHC cluster will be created.
  5910. :type zone_name: string
  5911. :param description:
  5912. Optional. A brief description of the EHC cluster. Default is an empty string.
  5913. :type description: string
  5914. :return:
  5915. :rtype baidubce.bce_response.BceResponse
  5916. """
  5917. path = b'/instance/ehc/cluster/create'
  5918. params = {}
  5919. if client_token is None:
  5920. params['clientToken'] = generate_client_token()
  5921. else:
  5922. params['clientToken'] = client_token
  5923. body = {
  5924. 'name': name,
  5925. 'zoneName': zone_name
  5926. }
  5927. if description is not None:
  5928. body['description'] = description
  5929. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5930. def modify_ehc_cluster(self, ehc_cluster_id, name=None, description=None, client_token=None, config=None):
  5931. """
  5932. Modifies the name and description of an EHC cluster.
  5933. :param ehc_cluster_id:
  5934. The ID of the EHC cluster to be modified. This parameter is required.
  5935. :type ehc_cluster_id: string
  5936. :param name:
  5937. Optional. The new name for the EHC cluster. If not specified, the name will not be changed.
  5938. :type name: string
  5939. :param description:
  5940. Optional. The new description for the EHC cluster. If not specified, the description will not be changed.
  5941. :type description: string
  5942. :return:
  5943. :rtype baidubce.bce_response.BceResponse
  5944. """
  5945. path = b'/instance/ehc/cluster/modify'
  5946. params = {}
  5947. if client_token is None:
  5948. params['clientToken'] = generate_client_token()
  5949. else:
  5950. params['clientToken'] = client_token
  5951. body = {
  5952. 'ehcClusterId': ehc_cluster_id
  5953. }
  5954. if name is not None:
  5955. body['name'] = name
  5956. if description is not None:
  5957. body['description'] = description
  5958. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5959. def get_ehc_cluster_list(self, ehc_cluster_id_list=None, name_list=None, zone_name=None, config=None):
  5960. """
  5961. get ehc cluster list
  5962. :param ehc_cluster_id_list:
  5963. Optional. List of EHC cluster IDs to filter the results. If not specified, retrieves all clusters.
  5964. :type ehc_cluster_id_list: list<string>
  5965. :param name_list:
  5966. Optional. List of EHC cluster names to filter the results. If not specified, retrieves all clusters.
  5967. :type name_list: list<string>
  5968. :param zone_name:
  5969. Optional. The name of the availability zone to filter the results.
  5970. :type zone_name: string
  5971. :return:
  5972. :rtype baidubce.bce_response.BceResponse
  5973. """
  5974. path = b'/instance/ehc/cluster/list'
  5975. params = {}
  5976. body = {}
  5977. if ehc_cluster_id_list is not None:
  5978. body['ehcClusterIdList'] = ehc_cluster_id_list
  5979. if name_list is not None:
  5980. body['nameList'] = name_list
  5981. if zone_name is not None:
  5982. body['zoneName'] = zone_name
  5983. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  5984. def delete_ehc_cluster(self, ehc_cluster_id_list, client_token=None, config=None):
  5985. """
  5986. Modifies the name and description of an EHC cluster.
  5987. :param ehc_cluster_id_list:
  5988. A list of IDs of the EHC clusters to be deleted. This parameter is required.
  5989. :type ehc_cluster_id_list: string
  5990. :return:
  5991. :rtype baidubce.bce_response.BceResponse
  5992. """
  5993. path = b'/instance/ehc/cluster/delete'
  5994. params = {}
  5995. if client_token is None:
  5996. params['clientToken'] = generate_client_token()
  5997. else:
  5998. params['clientToken'] = client_token
  5999. body = {
  6000. 'ehcClusterIdList': ehc_cluster_id_list
  6001. }
  6002. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  6003. def get_available_images_by_spec(self, marker=None, max_keys=None, spec=None, os_name=None, config=None):
  6004. """
  6005. :param marker:
  6006. The optional parameter marker specified in the original request to specify
  6007. where in the results to begin listing.
  6008. Together with the marker, specifies the list result which listing should begin.
  6009. If the marker is not specified, the list result will listing from the first one.
  6010. :type marker: string
  6011. :param max_keys:
  6012. The optional parameter to specifies the max number of list result to return.
  6013. The default value is 100.
  6014. :type max_keys: int
  6015. :param os_name:
  6016. The optional parameter to query specified public image by os name.
  6017. :type os_name: string
  6018. :param spec:
  6019. The required parameter to query specified public image by spec.
  6020. :type spec: string
  6021. :return:
  6022. :rtype baidubce.bce_response.BceResponse
  6023. """
  6024. path = b'/image/getAvailableImageBySpec'
  6025. params = {}
  6026. if marker is not None:
  6027. params['marker'] = marker
  6028. if max_keys is not None:
  6029. params['maxKeys'] = max_keys
  6030. if spec is not None:
  6031. params['spec'] = spec
  6032. if os_name is not None:
  6033. params['osName'] = os_name
  6034. return self._send_request(http_methods.GET, path, params=params, config=config)
  6035. def create_reserved_instances(self, reserved_instance_name=None, scope=None, zone_name=None, spec=None,
  6036. offering_type=None, instance_count=None, reserved_instance_count=None,
  6037. reserved_instance_time=None, reserved_instance_time_unit=None,
  6038. auto_renew_time_unit=None, auto_renew_time=None, auto_renew=None,
  6039. effective_time=None, ehc_cluster_id=None, ticket_id=None,
  6040. tags=None, client_token=None, config=None):
  6041. """
  6042. Create reserved instances.
  6043. :param reserved_instance_name:
  6044. The name of the reserved instance.
  6045. :type reserved_instance_name: string
  6046. :param scope:
  6047. The scope.
  6048. :type scope: string
  6049. :param zone_name:
  6050. The name of the availability zone.
  6051. :type zone_name: string
  6052. :param spec:
  6053. The instance specification.
  6054. :type spec: string
  6055. :param offering_type:
  6056. The offering type.
  6057. :type offering_type: string
  6058. :param instance_count:
  6059. The number of instances.
  6060. :type instance_count: int
  6061. :param reserved_instance_count:
  6062. The number of reserved instances.
  6063. :type reserved_instance_count: int
  6064. :param reserved_instance_time:
  6065. The duration of the reserved instance.
  6066. :type reserved_instance_time: int
  6067. :param reserved_instance_time_unit:
  6068. The time unit of the reserved instance.
  6069. :type reserved_instance_time_unit: string
  6070. :param auto_renew_time_unit:
  6071. The time unit for automatic renewal.
  6072. :type auto_renew_time_unit: string
  6073. :param auto_renew_time:
  6074. The duration for automatic renewal.
  6075. :type auto_renew_time: int
  6076. :param auto_renew:
  6077. Whether to enable automatic renewal, defaults to False.
  6078. :type auto_renew: bool
  6079. :param effective_time:
  6080. The effective time.
  6081. It is immediately effective by default.
  6082. :type effective_time: string
  6083. :param ehc_cluster_id:
  6084. The EHC cluster ID.
  6085. :type ehc_cluster_id: string
  6086. :param ticket_id:
  6087. The ticket ID.
  6088. :type ticket_id: string
  6089. :param tags:
  6090. The optional list of tag to be bonded.
  6091. :type tags: list<bcc_model.TagModel>
  6092. :return:
  6093. :rtype: baidubce.bce_response.BceResponse
  6094. """
  6095. path = b'/instance/reserved/create' # 请替换为实际的请求路径
  6096. params = {}
  6097. if client_token is not None:
  6098. params['clientToken'] = client_token
  6099. body = {}
  6100. if reserved_instance_name is not None:
  6101. body['reservedInstanceName'] = reserved_instance_name
  6102. if scope is not None:
  6103. body['scope'] = scope
  6104. if zone_name is not None:
  6105. body['zoneName'] = zone_name
  6106. if spec is not None:
  6107. body['spec'] = spec
  6108. if offering_type is not None:
  6109. body['offeringType'] = offering_type
  6110. if instance_count is not None:
  6111. body['instanceCount'] = instance_count
  6112. if reserved_instance_count is not None:
  6113. body['reservedInstanceCount'] = reserved_instance_count
  6114. if reserved_instance_time is not None:
  6115. body['reservedInstanceTime'] = reserved_instance_time
  6116. if reserved_instance_time_unit is not None:
  6117. body['reservedInstanceTimeUnit'] = reserved_instance_time_unit
  6118. if auto_renew_time_unit is not None:
  6119. body['autoRenewTimeUnit'] = auto_renew_time_unit
  6120. if auto_renew_time is not None:
  6121. body['autoRenewTime'] = auto_renew_time
  6122. if auto_renew is not False:
  6123. body['autoRenew'] = str(auto_renew).lower()
  6124. if effective_time is not None:
  6125. body['effectiveTime'] = effective_time
  6126. if ehc_cluster_id is not None:
  6127. body['ehcClusterId'] = ehc_cluster_id
  6128. if ticket_id is not None:
  6129. body['ticketId'] = ticket_id
  6130. if tags is not None:
  6131. tag_list = [tag.__dict__ for tag in tags]
  6132. body['tags'] = tag_list
  6133. return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
  6134. def modify_reserved_instances(self, reserved_instances=None, client_token=None, config=None):
  6135. """
  6136. Modify the information of reserved instances.
  6137. :param reserved_instances:
  6138. A list of dictionaries containing the information of reserved instances to be updated.
  6139. :type reserved_instances: list<bcc_model.ModifyReservedInstanceModel>
  6140. :return:
  6141. :rtype: baidubce.bce_response.BceResponse
  6142. """
  6143. path = b'/instance/reserved/modify'
  6144. params = {}
  6145. if client_token is not None:
  6146. params['clientToken'] = client_token
  6147. body = {}
  6148. if reserved_instances is not None:
  6149. reserved_instances_list = [reserved_instance.__dict__ for reserved_instance in reserved_instances]
  6150. body['reservedInstances'] = reserved_instances_list
  6151. return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
  6152. def get_instance_user_data(self, instance_id, client_token=None, config=None):
  6153. """
  6154. get_instance_user_data
  6155. """
  6156. path = b'/instance/attribute/getUserdata'
  6157. params = {}
  6158. if client_token is None:
  6159. params['clientToken'] = generate_client_token()
  6160. else:
  6161. params['clientToken'] = client_token
  6162. body = {
  6163. "instanceId": instance_id
  6164. }
  6165. return self._send_request(http_methods.POST, path, json.dumps(body),
  6166. params=params, config=config)
  6167. def enter_rescue_mode(self, instance_id, force_stop, password, client_token=None, config=None):
  6168. """
  6169. 进入救援模式。
  6170. :param enter_rescue_mode_req:
  6171. :desc
  6172. :type enter_rescue_mode_req: json
  6173. :return:
  6174. :rtype baidubce.bce_response.BceResponse
  6175. """
  6176. path = b'/instance/rescue/mode/enter'
  6177. params = {}
  6178. if client_token is None:
  6179. params['clientToken'] = generate_client_token()
  6180. else:
  6181. params['clientToken'] = client_token
  6182. body = {
  6183. 'instanceId': instance_id,
  6184. 'forceStop': force_stop,
  6185. 'password': password
  6186. }
  6187. return self._send_request(http_methods.PUT, path, json.dumps(body),
  6188. params=params, config=config)
  6189. def exit_rescue_mode(self, instance_id, client_token=None, config=None):
  6190. """
  6191. 退出救援模式。
  6192. :param exit_rescue_mode_req:
  6193. :desc
  6194. :type exit_rescue_mode_req: json
  6195. :return:
  6196. :rtype baidubce.bce_response.BceResponse
  6197. """
  6198. path = b'/instance/rescue/mode/exit'
  6199. params = {}
  6200. if client_token is None:
  6201. params['clientToken'] = generate_client_token()
  6202. else:
  6203. params['clientToken'] = client_token
  6204. body = {
  6205. 'instanceId': instance_id
  6206. }
  6207. return self._send_request(http_methods.PUT, path, json.dumps(body),
  6208. params=params, config=config)
  6209. def bind_sg(self, instance_ids, security_group_ids, security_group_type, client_token=None, config=None):
  6210. """
  6211. 绑定安全组。
  6212. :param bind_sg:
  6213. :desc
  6214. :type bind_sg: json
  6215. :return:
  6216. :rtype baidubce.bce_response.BceResponse
  6217. """
  6218. path = b'/securitygroup/bind'
  6219. params = {}
  6220. if client_token is None:
  6221. params['clientToken'] = generate_client_token()
  6222. else:
  6223. params['clientToken'] = client_token
  6224. body = {
  6225. 'instanceIds': instance_ids,
  6226. 'securityGroupIds': security_group_ids,
  6227. 'securityGroupType': security_group_type
  6228. }
  6229. return self._send_request(http_methods.PUT, path, json.dumps(body),
  6230. params=params, config=config)
  6231. def replace_sg(self, instance_ids, security_group_ids, security_group_type, client_token=None, config=None):
  6232. """
  6233. 替换安全组。
  6234. :param replace_sg:
  6235. :desc
  6236. :type replace_sg: json
  6237. :return:
  6238. :rtype baidubce.bce_response.BceResponse
  6239. """
  6240. path = b'/securitygroup/replace'
  6241. params = {}
  6242. if client_token is None:
  6243. params['clientToken'] = generate_client_token()
  6244. else:
  6245. params['clientToken'] = client_token
  6246. body = {
  6247. 'instanceIds': instance_ids,
  6248. 'securityGroupIds': security_group_ids,
  6249. 'securityGroupType': security_group_type
  6250. }
  6251. return self._send_request(http_methods.PUT, path, json.dumps(body),
  6252. params=params, config=config)
  6253. def unbind_sg(self, instance_ids, security_group_ids, security_group_type, client_token=None, config=None):
  6254. """
  6255. 解绑安全组。
  6256. :param unbind_sg:
  6257. :desc
  6258. :type unbind_sg: json
  6259. :return:
  6260. :rtype baidubce.bce_response.BceResponse
  6261. """
  6262. path = b'/securitygroup/unbind'
  6263. params = {}
  6264. if client_token is None:
  6265. params['clientToken'] = generate_client_token()
  6266. else:
  6267. params['clientToken'] = client_token
  6268. body = {
  6269. 'instanceIds': instance_ids,
  6270. 'securityGroupIds': security_group_ids,
  6271. 'securityGroupType': security_group_type
  6272. }
  6273. return self._send_request(http_methods.PUT, path, json.dumps(body),
  6274. params=params, config=config)
  6275. def authorize_server_event(self, authorize_maintenance_operation, server_event_id=None, instance_id=None,
  6276. execute_time=None, config=None, client_token=None):
  6277. """
  6278. authorize_server_event
  6279. :param authorize_maintenance_operation:
  6280. Authorized operation and maintenance operations
  6281. :type authorize_maintenance_operation: string
  6282. :param server_event_id:
  6283. event Id.
  6284. :type marker: string
  6285. :param instance_id:
  6286. Instance Id, server Event ID, instance ID must select one of the request options
  6287. :type max_keys: string
  6288. :param execute_time:
  6289. Authorized execution time,
  6290. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6291. :type execute_time: string
  6292. :return:
  6293. :rtype baidubce.bce_response.BceResponse
  6294. """
  6295. path = b'/'
  6296. params = {}
  6297. if client_token is None:
  6298. params['clientToken'] = generate_client_token()
  6299. else:
  6300. params['clientToken'] = client_token
  6301. params['action'] = 'AuthorizeServerEvent'
  6302. body = {
  6303. 'serverEventId': server_event_id,
  6304. 'instanceId': instance_id,
  6305. 'authorizeMaintenanceOperation': authorize_maintenance_operation,
  6306. 'executeTime': execute_time
  6307. }
  6308. return self._send_action_request(http_methods.POST, path, json.dumps(body),
  6309. params=params, config=config)
  6310. def create_authorize_rule(self, server_event_category, authorize_maintenance_operations, rule_name,
  6311. enable_rule=None, effective_scope=None, tags=None, config=None, client_token=None):
  6312. """
  6313. create_authorize_rule
  6314. :param server_event_category:
  6315. Server Event Category
  6316. :type server_event_category: string
  6317. :param authorize_maintenance_operations:
  6318. Authorized operation and maintenance operations
  6319. :type authorize_maintenance_operations: list
  6320. :param rule_name:
  6321. Rule Name
  6322. :type rule_name: string
  6323. :param enable_rule:
  6324. Whether to enable the rule
  6325. :type enable_rule: int
  6326. :param effective_scope:
  6327. Effective scope
  6328. :type effective_scope: String
  6329. :param tags:
  6330. Tag information
  6331. :type tags: list
  6332. :return:
  6333. :rtype baidubce.bce_response.BceResponse
  6334. """
  6335. path = b'/'
  6336. params = {}
  6337. if client_token is None:
  6338. params['clientToken'] = generate_client_token()
  6339. else:
  6340. params['clientToken'] = client_token
  6341. params['action'] = 'CreateAuthorizeRule'
  6342. body = {
  6343. 'enableRule': enable_rule,
  6344. 'serverEventCategory': server_event_category,
  6345. 'authorizeMaintenanceOperations': authorize_maintenance_operations,
  6346. 'tags': tags,
  6347. 'effectiveScope': effective_scope,
  6348. 'ruleName': rule_name
  6349. }
  6350. return self._send_action_request(http_methods.POST, path, json.dumps(body),
  6351. params=params, config=config)
  6352. def modify_authorize_rule(self, rule_id, authorize_maintenance_operations=None, rule_name=None,
  6353. enable_rule=None, effective_scope=None, tags=None, config=None, client_token=None):
  6354. """
  6355. modify_authorize_rule
  6356. :param rule_id:
  6357. rule_id to be modified
  6358. :type rule_id: string
  6359. :param authorize_maintenance_operations:
  6360. Authorized operation and maintenance operations
  6361. :type authorize_maintenance_operations: list
  6362. :param rule_name:
  6363. Rule Name
  6364. :type rule_name: string
  6365. :param enable_rule:
  6366. Whether to enable the rule
  6367. :type enable_rule: int
  6368. :param effective_scope:
  6369. Effective scope
  6370. :type effective_scope: String
  6371. :param tags:
  6372. Tag information
  6373. :type tags: list
  6374. :return:
  6375. :rtype baidubce.bce_response.BceResponse
  6376. """
  6377. path = b'/'
  6378. params = {}
  6379. if client_token is None:
  6380. params['clientToken'] = generate_client_token()
  6381. else:
  6382. params['clientToken'] = client_token
  6383. params['action'] = 'ModifyInstUserOpAuthorizeRuleAttribute'
  6384. body = {
  6385. 'enableRule': enable_rule,
  6386. 'authorizeMaintenanceOperations': authorize_maintenance_operations,
  6387. 'tags': tags,
  6388. 'effectiveScope': effective_scope,
  6389. 'ruleName': rule_name,
  6390. "ruleId": rule_id
  6391. }
  6392. return self._send_action_request(http_methods.POST, path, json.dumps(body),
  6393. params=params, config=config)
  6394. def delete_authorize_rule(self, rule_id, config=None, client_token=None):
  6395. """
  6396. delete_authorize_rule
  6397. :param rule_id:
  6398. rule_id to be deleted
  6399. :type rule_id: string
  6400. :return:
  6401. :rtype baidubce.bce_response.BceResponse
  6402. """
  6403. path = b'/'
  6404. params = {}
  6405. if client_token is None:
  6406. params['clientToken'] = generate_client_token()
  6407. else:
  6408. params['clientToken'] = client_token
  6409. params['action'] = 'DeleteInstUserOpAuthorizeRule'
  6410. body = {
  6411. 'ruleId': rule_id
  6412. }
  6413. return self._send_action_request(http_methods.POST, path, json.dumps(body),
  6414. params=params, config=config)
  6415. def describe_authorize_rules(self, max_keys, marker=None, rule_ids=None, rule_names=None, config=None):
  6416. """
  6417. describe_authorize_rules
  6418. :param max_keys:
  6419. The optional parameter to specifies the max number of list result to return.
  6420. The default value is 10.
  6421. :type max_keys: int
  6422. :param marker:
  6423. The optional parameter marker specified in the original request to specify
  6424. where in the results to begin listing.
  6425. Together with the marker, specifies the list result which listing should begin.
  6426. If the marker is not specified, the list result will listing from the first one.
  6427. :type marker: string
  6428. :param rule_ids:
  6429. filter rule list with multiple rule ids
  6430. :type rule_ids: string
  6431. :param rule_names:
  6432. filter rule list with multiple rule names
  6433. :type rule_names: list
  6434. :return:
  6435. :rtype baidubce.bce_response.BceResponse
  6436. """
  6437. path = b'/'
  6438. params = {}
  6439. params['action'] = 'DescribeAuthorizeRules'
  6440. body = {
  6441. "marker": marker,
  6442. "maxKeys": max_keys,
  6443. "ruleIds": rule_ids,
  6444. "ruleNames": rule_names
  6445. }
  6446. return self._send_action_request(http_methods.POST, path, json.dumps(body),
  6447. params=params, config=config)
  6448. def describe_planned_events(self, max_keys, marker=None, server_event_ids=None, instance_ids=None,
  6449. product_category=None, server_event_type=None, server_event_log_time_filter=None,
  6450. period_start_time=None, period_end_time=None, server_event_status=None, config=None):
  6451. """
  6452. describe_planned_events
  6453. :param max_keys:
  6454. The optional parameter to specifies the max number of list result to return.
  6455. The default value is 10.
  6456. :type max_keys: int
  6457. :param marker:
  6458. The optional parameter marker specified in the original request to specify
  6459. where in the results to begin listing.
  6460. Together with the marker, specifies the list result which listing should begin.
  6461. If the marker is not specified, the list result will listing from the first one.
  6462. :type marker: string
  6463. :param server_event_ids:
  6464. filter planned event list with multiple server event ids
  6465. :type server_event_ids: list of string
  6466. :param instance_ids:
  6467. filter planned event list with multiple instance ids
  6468. :type instance_ids: list of string
  6469. :param product_category:
  6470. filter planned event list with product_category
  6471. :type product_category: string
  6472. :param server_event_type:
  6473. filter planned event list with server_event_type
  6474. :type server_event_type: string
  6475. :param server_event_log_time_filter:
  6476. filter planned event list with server_event_log_time_filter,
  6477. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6478. :type server_event_log_time_filter: string
  6479. :param period_start_time:
  6480. filter planned event list with period_start_time,
  6481. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6482. :type period_start_time: string
  6483. :param period_end_time:
  6484. filter planned event list with period_end_time,
  6485. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6486. :type period_end_time: string
  6487. :param server_event_status:
  6488. filter planned event list with server_event_status
  6489. :type server_event_status: string
  6490. :return:
  6491. :rtype baidubce.bce_response.BceResponse
  6492. """
  6493. path = b'/'
  6494. params = {}
  6495. params['action'] = 'DescribePlannedEvents'
  6496. body = {
  6497. "marker": marker,
  6498. "maxKeys": max_keys,
  6499. "serverEventIds": server_event_ids,
  6500. "instanceIds": instance_ids,
  6501. "productCategory": product_category,
  6502. "serverEventType": server_event_type,
  6503. "serverEventLogTimeFilter": server_event_log_time_filter,
  6504. "periodStartTime": period_start_time,
  6505. "periodEndTime": period_end_time,
  6506. "serverEventStatus": server_event_status
  6507. }
  6508. return self._send_action_request(http_methods.POST, path, json.dumps(body),
  6509. params=params, config=config)
  6510. def describe_planned_recored_events(self, max_keys, marker=None, server_event_ids=None, instance_ids=None,
  6511. product_category=None, server_event_type=None,
  6512. server_event_log_time_filter=None, period_start_time=None,
  6513. period_end_time=None, config=None):
  6514. """
  6515. describe_planned_recored_events
  6516. :param max_keys:
  6517. The optional parameter to specifies the max number of list result to return.
  6518. The default value is 10.
  6519. :type max_keys: int
  6520. :param marker:
  6521. The optional parameter marker specified in the original request to specify
  6522. where in the results to begin listing.
  6523. Together with the marker, specifies the list result which listing should begin.
  6524. If the marker is not specified, the list result will listing from the first one.
  6525. :type marker: string
  6526. :param server_event_ids:
  6527. filter planned event list with multiple server event ids
  6528. :type server_event_ids: list of string
  6529. :param instance_ids:
  6530. filter planned event list with multiple instance ids
  6531. :type instance_ids: list of string
  6532. :param product_category:
  6533. filter planned event list with product_category
  6534. :type product_category: string
  6535. :param server_event_type:
  6536. filter planned event list with server_event_type
  6537. :type server_event_type: string
  6538. :param server_event_log_time_filter:
  6539. filter planned event list with server_event_log_time_filter,
  6540. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6541. :type server_event_log_time_filter: string
  6542. :param period_start_time:
  6543. filter planned event list with period_start_time,
  6544. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6545. :type period_start_time: string
  6546. :param period_end_time:
  6547. filter planned event list with period_end_time,
  6548. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6549. :type period_end_time: string
  6550. :return:
  6551. :rtype baidubce.bce_response.BceResponse
  6552. """
  6553. path = b'/'
  6554. params = {}
  6555. params['action'] = 'DescribePlannedEventRecords'
  6556. body = {
  6557. "marker": marker,
  6558. "maxKeys": max_keys,
  6559. "serverEventIds": server_event_ids,
  6560. "instanceIds": instance_ids,
  6561. "productCategory": product_category,
  6562. "serverEventType": server_event_type,
  6563. "serverEventLogTimeFilter": server_event_log_time_filter,
  6564. "periodStartTime": period_start_time,
  6565. "periodEndTime": period_end_time
  6566. }
  6567. return self._send_action_request(http_methods.POST, path, json.dumps(body),
  6568. params=params, config=config)
  6569. def describe_unplanned_events(self, max_keys, marker=None, server_event_ids=None, instance_ids=None,
  6570. product_category=None, server_event_type=None, server_event_log_time_filter=None,
  6571. period_start_time=None, period_end_time=None, server_event_status=None, config=None):
  6572. """
  6573. describe_unplanned_events
  6574. :param max_keys:
  6575. The optional parameter to specifies the max number of list result to return.
  6576. The default value is 10.
  6577. :type max_keys: int
  6578. :param marker:
  6579. The optional parameter marker specified in the original request to specify
  6580. where in the results to begin listing.
  6581. Together with the marker, specifies the list result which listing should begin.
  6582. If the marker is not specified, the list result will listing from the first one.
  6583. :type marker: string
  6584. :param server_event_ids:
  6585. filter unplanned event list with multiple server event ids
  6586. :type server_event_ids: list of string
  6587. :param instance_ids:
  6588. filter unplanned event list with multiple instance ids
  6589. :type instance_ids: list of string
  6590. :param product_category:
  6591. filter unplanned event list with product_category
  6592. :type product_category: string
  6593. :param server_event_type:
  6594. filter unplanned event list with server_event_type
  6595. :type server_event_type: string
  6596. :param server_event_log_time_filter:
  6597. filter unplanned event list with server_event_log_time_filter,
  6598. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6599. :type server_event_log_time_filter: string
  6600. :param period_start_time:
  6601. filter unplanned event list with period_start_time,
  6602. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6603. :type period_start_time: string
  6604. :param period_end_time:
  6605. filter unplanned event list with period_end_time,
  6606. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6607. :type period_end_time: string
  6608. :param server_event_status:
  6609. filter unplanned event list with server_event_status
  6610. :type server_event_status: string
  6611. :return:
  6612. :rtype baidubce.bce_response.BceResponse
  6613. """
  6614. path = b'/'
  6615. params = {}
  6616. params['action'] = 'DescribeUnplannedEvents'
  6617. body = {
  6618. "marker": marker,
  6619. "maxKeys": max_keys,
  6620. "serverEventIds": server_event_ids,
  6621. "instanceIds": instance_ids,
  6622. "productCategory": product_category,
  6623. "serverEventType": server_event_type,
  6624. "serverEventLogTimeFilter": server_event_log_time_filter,
  6625. "periodStartTime": period_start_time,
  6626. "periodEndTime": period_end_time,
  6627. "serverEventStatus": server_event_status
  6628. }
  6629. return self._send_action_request(http_methods.POST, path, json.dumps(body),
  6630. params=params, config=config)
  6631. def describe_unplanned_recored_events(self, max_keys, marker=None, server_event_ids=None, instance_ids=None,
  6632. product_category=None, server_event_type=None,
  6633. server_event_log_time_filter=None, period_start_time=None,
  6634. period_end_time=None, config=None):
  6635. """
  6636. describe_unplanned_recored_events
  6637. :param max_keys:
  6638. The optional parameter to specifies the max number of list result to return.
  6639. The default value is 10.
  6640. :type max_keys: int
  6641. :param marker:
  6642. The optional parameter marker specified in the original request to specify
  6643. where in the results to begin listing.
  6644. Together with the marker, specifies the list result which listing should begin.
  6645. If the marker is not specified, the list result will listing from the first one.
  6646. :type marker: string
  6647. :param server_event_ids:
  6648. filter unplanned event list with multiple server event ids
  6649. :type server_event_ids: list of string
  6650. :param instance_ids:
  6651. filter unplanned event list with multiple instance ids
  6652. :type instance_ids: list of string
  6653. :param product_category:
  6654. filter unplanned event list with product_category
  6655. :type product_category: string
  6656. :param server_event_type:
  6657. filter unplanned event list with server_event_type
  6658. :type server_event_type: string
  6659. :param server_event_log_time_filter:
  6660. filter unplanned event list with server_event_log_time_filter,
  6661. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6662. :type server_event_log_time_filter: string
  6663. :param period_start_time:
  6664. filter unplanned event list with period_start_time,
  6665. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6666. :type period_start_time: string
  6667. :param period_end_time:
  6668. filter unplanned event list with period_end_time,
  6669. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6670. :type period_end_time: string
  6671. :return:
  6672. :rtype baidubce.bce_response.BceResponse
  6673. """
  6674. path = b'/'
  6675. params = {}
  6676. params['action'] = 'DescribeUnplannedEventRecords'
  6677. body = {
  6678. "marker": marker,
  6679. "maxKeys": max_keys,
  6680. "serverEventIds": server_event_ids,
  6681. "instanceIds": instance_ids,
  6682. "productCategory": product_category,
  6683. "serverEventType": server_event_type,
  6684. "serverEventLogTimeFilter": server_event_log_time_filter,
  6685. "periodStartTime": period_start_time,
  6686. "periodEndTime": period_end_time
  6687. }
  6688. return self._send_action_request(http_methods.POST, path, json.dumps(body),
  6689. params=params, config=config)
  6690. def check_unplanned_event(self, server_event_id, check_result, issue_effect=None, issue_description=None,
  6691. authorize_maintenance_operation=None, config=None, client_token=None):
  6692. """
  6693. check_unplanned_event
  6694. :param server_event_id:
  6695. server_event_id to be check
  6696. :type server_event_id: string
  6697. :param check_result:
  6698. Whether unplanned events have passed the acceptance, supporting parameters Pass and Reject
  6699. :type check_result: string
  6700. :param issue_effect:
  6701. Fault effect must be passed when the fault acceptance is rejected
  6702. :type issue_effect: string
  6703. :param issue_description:
  6704. Fault description must be passed when the fault acceptance is rejected
  6705. :type issue_description: string
  6706. :param authorize_maintenance_operation:
  6707. Authorized operation and maintenance
  6708. :type authorize_maintenance_operation: string
  6709. :return:
  6710. :rtype baidubce.bce_response.BceResponse
  6711. """
  6712. path = b'/'
  6713. params = {}
  6714. if client_token is None:
  6715. params['clientToken'] = generate_client_token()
  6716. else:
  6717. params['clientToken'] = client_token
  6718. params['action'] = 'CheckUnplannedEvent'
  6719. body = {
  6720. "serverEventId": server_event_id,
  6721. "checkResult": check_result,
  6722. "issueEffect": issue_effect,
  6723. "issueDescription": issue_description,
  6724. "authorizeMaintenanceOperation": authorize_maintenance_operation
  6725. }
  6726. return self._send_action_request(http_methods.POST, path, json.dumps(body),
  6727. params=params, config=config)
  6728. def get_task(self, task_ids, max_keys=100, config=None):
  6729. """
  6730. get_task
  6731. :param task_ids:
  6732. task_ids to be used to query the task
  6733. :type task_ids: list of string
  6734. :param max_keys:
  6735. The optional parameter to specifies the max number of list result to return.
  6736. The default value is 100.
  6737. :type max_keys: int
  6738. :return:
  6739. :rtype baidubce.bce_response.BceResponse
  6740. """
  6741. path = b'/task/detail'
  6742. params = {}
  6743. body = {
  6744. "taskIds": task_ids,
  6745. "maxKeys": max_keys
  6746. }
  6747. return self._send_request(http_methods.POST, path, json.dumps(body),
  6748. params=params, config=config)
  6749. def list_task(self, max_keys=10, task_ids=None, task_action=None, task_status=None, resource_ids=None,
  6750. start_time=None, end_time=None, config=None):
  6751. """
  6752. list_task
  6753. :param task_ids:
  6754. task_ids to be used to query the task
  6755. :param task_action:
  6756. task_action to be used to query the task
  6757. :param task_status:
  6758. task_status to be used to query the task
  6759. :param start_time:
  6760. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6761. :param end_time:
  6762. The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
  6763. :param max_keys:
  6764. The optional parameter to specifies the max number of list result to return.
  6765. The default value is 10.
  6766. :param config:
  6767. :return:
  6768. """
  6769. path = b'/task/list'
  6770. params = {}
  6771. body = {
  6772. "taskIds": task_ids,
  6773. "taskAction": task_action,
  6774. "taskStatus": task_status,
  6775. "startTime": start_time,
  6776. "endTime": end_time,
  6777. "resourceIds": resource_ids,
  6778. "maxKeys": max_keys,
  6779. }
  6780. return self._send_request(http_methods.POST, path, json.dumps(body),
  6781. params=params, config=config)
  6782. def generate_client_token_by_uuid():
  6783. """
  6784. The default method to generate the random string for client_token
  6785. if the optional parameter client_token is not specified by the user.
  6786. :return:
  6787. :rtype string
  6788. """
  6789. return str(uuid.uuid4())
  6790. def generate_client_token_by_random():
  6791. """
  6792. The alternative method to generate the random string for client_token
  6793. if the optional parameter client_token is not specified by the user.
  6794. :return:
  6795. :rtype string
  6796. """
  6797. client_token = ''.join(random.sample(string.ascii_letters + string.digits, 36))
  6798. return client_token
  6799. def get_cds_price(self, purchase_length, payment_timing, storage_type, cds_size_in_gb, purchase_count, zone_name,
  6800. encrypt_key=None, client_token=None, config=None):
  6801. """
  6802. get_deploy_set
  6803. """
  6804. path = b'/volume/getPrice'
  6805. params = {}
  6806. if client_token is None:
  6807. params['clientToken'] = generate_client_token()
  6808. else:
  6809. params['clientToken'] = client_token
  6810. body = {
  6811. 'purchaseLength': purchase_length,
  6812. 'paymentTiming': payment_timing,
  6813. 'storageType': storage_type,
  6814. 'cdsSizeInGB': cds_size_in_gb,
  6815. 'purchaseCount': purchase_count,
  6816. 'zoneName': zone_name
  6817. }
  6818. if encrypt_key is not None:
  6819. body['encryptKey'] = encrypt_key
  6820. return self._send_request(http_methods.POST, path, json.dumps(body),
  6821. params=params, config=config)
  6822. generate_client_token = generate_client_token_by_uuid