| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911 |
- # -*- coding: utf-8 -*-
- # Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
- #
- # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
- # except in compliance with the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software distributed under the
- # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- # either express or implied. See the License for the specific language governing permissions
- # and limitations under the License.
- """
- This module provides a client class for BCC.
- """
- from __future__ import unicode_literals
- import copy
- import json
- import logging
- import random
- import string
- import uuid
- from baidubce import bce_base_client
- from baidubce import compat
- from baidubce.auth import bce_v1_signer
- from baidubce.http import bce_http_client
- from baidubce.http import handler
- from baidubce.http import http_methods
- from baidubce.services.bcc import bcc_model
- from baidubce.utils import aes128_encrypt_16char_key
- from baidubce.utils import required
- _logger = logging.getLogger(__name__)
- FETCH_MODE_SYNC = b"sync"
- FETCH_MODE_ASYNC = b"async"
- ENCRYPTION_ALGORITHM = "AES256"
- default_billing_to_purchase_created = bcc_model.Billing('Postpaid')
- default_billing_to_purchase_reserved = bcc_model.Billing()
- class BccClient(bce_base_client.BceBaseClient):
- """
- Bcc base sdk client
- """
- prefix = b'/v2'
- prefix_v3 = b'/v3'
- def __init__(self, config=None):
- bce_base_client.BceBaseClient.__init__(self, config)
- def _merge_config(self, config=None):
- if config is None:
- return self.config
- else:
- new_config = copy.copy(self.config)
- new_config.merge_non_none_values(config)
- return new_config
- def _send_request(self, http_method, path,
- body=None, headers=None, params=None,
- config=None, body_parser=None, prefix=None):
- config = self._merge_config(config)
- if body_parser is None:
- body_parser = handler.parse_json
- if prefix is None:
- prefix = BccClient.prefix
- return bce_http_client.send_request(
- config, bce_v1_signer.sign, [handler.parse_error, body_parser],
- http_method, prefix + path, body, headers, params)
- def _send_action_request(self, http_method, path,
- body=None, headers=None, params=None,
- config=None, body_parser=None):
- config = self._merge_config(config)
- if body_parser is None:
- body_parser = handler.parse_json
- return bce_http_client.send_request(
- config, bce_v1_signer.sign, [handler.parse_error, body_parser],
- http_method, path, body, headers, params)
- @required(cpu_count=int,
- memory_capacity_in_gb=int,
- image_id=(bytes, str)) # ***Unicode***
- def create_instance(self, cpu_count, memory_capacity_in_gb, image_id, instance_type=None,
- billing=None, create_cds_list=None, root_disk_size_in_gb=0, root_disk_storage_type=None,
- ephemeral_disks=None, dedicate_host_id=None, auto_renew_time_unit=None, auto_renew_time=0,
- deploy_id=None, bid_model=None, bid_price=None, key_pair_id=None, cds_auto_renew=False,
- internet_charge_type=None, internal_ips=None, request_token=None, asp_id=None, tags=None,
- network_capacity_in_mbps=0, purchase_count=1, cardCount=1, name=None, admin_pass=None,
- zone_name=None, subnet_id=None, security_group_id=None, gpuCard=None, fpgaCard=None,
- spec=None, eip_name=None, hostname=None, auto_seq_suffix=False, is_open_hostname_domain=False,
- relation_tag=None, is_open_ipv6=None, enterprise_security_group_id=None,
- security_group_ids=None, enterprise_security_group_ids=None, ehc_cluster_id=None,
- kunlunCard=None, isomerismCard=None, file_systems=None, user_data=None, is_open_hosteye=False,
- deletion_protection=None, res_group_id=None,
- client_token=None, config=None, card_count=1, isomerism_card=None, is_keep_image_login=None):
- """
- Create a bcc Instance with the specified options.
- You must fill the field of clientToken,which is especially for keeping idempotent.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param instance_type:
- The specified Specification to create the instance,
- See more detail on
- https://cloud.baidu.com/doc/BCC/API.html#InstanceType
- :type instance_type: string
- :param cpu_count:
- The parameter to specified the cpu core to create the instance.
- :type cpu_count: int
- :param memory_capacity_in_gb:
- The parameter to specified the capacity of memory in GB to create the instance.
- :type memory_capacity_in_gb: int
- :param image_id:
- The id of image, list all available image in BccClient.list_images.
- :type image_id: string
- :param billing:
- Billing information.
- :type billing: bcc_model.Billing
- :param create_cds_list:
- The optional list of volume detail info to create.
- :type create_cds_list: list<bcc_model.CreateCdsModel>
- :param network_capacity_in_mbps:
- The optional parameter to specify the bandwidth in Mbps for the new instance.
- It must among 0 and 200, default value is 0.
- If it's specified to 0, it will get the internal ip address only.
- :type network_capacity_in_mbps: int
- :param purchase_count:
- The number of instance to buy, the default value is 1.
- :type purchase_count: int
- :param name:
- The optional parameter to desc the instance that will be created.
- :type name: string
- :param admin_pass:
- The optional parameter to specify the password for the instance.
- If specify the adminPass,the adminPass must be a 8-16 characters String
- which must contains letters, numbers and symbols.
- The symbols only contains "!@#$%^*()".
- The adminPass will be encrypted in AES-128 algorithm
- with the substring of the former 16 characters of user SecretKey.
- If not specify the adminPass, it will be specified by an random string.
- See more detail on
- https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
- :type admin_pass: string
- :param zone_name:
- The optional parameter to specify the available zone for the instance.
- See more detail through list_zones method
- :type zone_name: string
- :param subnet_id:
- The optional parameter to specify the id of subnet from vpc, optional param
- default value is default subnet from default vpc
- :type subnet_id: string
- :param security_group_id:
- The optional parameter to specify the securityGroupId of the instance
- vpcId of the securityGroupId must be the same as the vpcId of subnetId
- See more detail through listSecurityGroups method
- :type security_group_id: string
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :param fpgaCard:
- This parameter is obsolete. Use parameter isomerism_card instead.
- :type fpgaCard: string
- :param gpuCard:
- This parameter is obsolete. Use parameter isomerism_card instead.
- :type gpuCard: string
- :param cardCount:
- This parameter is obsolete. Use parameter card_count instead.
- :type cardCount: int
- :param card_count:
- The parameter to specify the card count for creating GPU/FPGA instance.
- :type card_count: int
- :param root_disk_size_in_gb:
- The parameter to specify the root disk size in GB.
- The root disk excludes the system disk, available is 40-500GB.
- :type root_disk_size_in_gb: int
- :param root_disk_storage_type:
- The parameter to specify the root disk storage type.
- Default use of HP1 cloud disk.
- :type root_disk_storage_type: string
- :param ephemeral_disks:
- The optional list of ephemeral volume detail info to create.
- :type ephemeral_disks: list<bcc_model.EphemeralDisk>
- :param dedicate_host_id:
- The parameter to specify the dedicate host id.
- :type dedicate_host_id: string
- :param auto_renew_time_unit:
- The parameter to specify the unit of the auto renew time.
- The auto renew time unit can be "month" or "year".
- The default value is "month".
- :type auto_renew_time_unit: string
- :param auto_renew_time:
- The parameter to specify the auto renew time, the default value is 0.
- :type auto_renew_time: int
- :param tags:
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :param deploy_id:
- The parameter to specify the id of the deploymentSet.
- :type deploy_id: string
- :param bid_model:
- The parameter to specify the bidding model.
- The bidding model can be "market" or "custom".
- :type bid_model: string
- :param bid_price:
- The parameter to specify the bidding price.
- When the bid_model is "custom", it works.
- :type bid_price: string
- :param key_pair_id:
- The parameter to specify id of the keypair.
- :type key_pair_id: string
- :param asp_id:
- The parameter to specify id of the asp.
- :type asp_id: string
- :param request_token:
- The parameter to specify the request token which will make the request idempotent.
- :type request_token: string
- :param internet_charge_type:
- The parameter to specify the internet charge type.
- See more detail on
- https://cloud.baidu.com/doc/BCC/API.html#InternetChargeType
- :type internet_charge_type: string
- :param internal_ips:
- The parameter to specify the internal ips.
- :type internal_ips: list<string>
- :param cds_auto_renew
- The parameter to specify whether the cds is auto renew or not.
- The default value is false.
- :type cds_auto_renew: boolean
- :param spec:
- spec
- :type spec: string
- :param eip_name:
- eip name
- :type eip_name: string
- :param hostname:
- The optional parameter to specify the host name of the instance virtual machine.
- By default, hostname is not specified.
- If hostname is specified: hostname is used as the prefix of the name in batches.
- The backend will add a suffix, and the suffix generation method is: name{-serial number}.
- If name is not specified, it will be automatically generated using the following method:
- {instance-eight-digit random string-serial number}.
- Note: The random string is generated from the characters 0-9 and a-z;
- the serial number increases sequentially according to the magnitude of count.
- If count is 100, the serial number increases from 000~100, and if it is 10, it increases from 00~10.
- Only lowercase letters, numbers and - . special characters are supported.
- They must start with a letter. Special symbols cannot be used continuously.
- Special symbols are not supported at the beginning or end. The length is 2-64.
- :type hostname: string
- :param auto_seq_suffix:
- The parameter to specify whether name and hostname order suffixes are automatically generated
- :type auto_seq_suffix: boolean
- :param is_open_hostname_domain:
- The parameter to specify whether hostname domain is automatically generated
- :type is_open_hostname_domain: boolean
- :param relation_tag:
- The parameter to specify whether the instance related to existing tags
- :type relation_tag: boolean
- :param is_open_ipv6:
- is_open_ipv6
- :type is_open_ipv6: boolean
- :param enterprise_security_group_id:
- enterprise_security_group_id
- :type enterprise_security_group_id: string
- :param security_group_ids:
- security_group_ids
- :type security_group_ids: list<string>
- :param enterprise_security_group_ids:
- enterprise_security_group_ids
- :type enterprise_security_group_ids: list<string>
- :param ehc_cluster_id:
- The id of ehcCluster.
- :type ehc_cluster_id: string
- :param kunlunCard:
- This parameter is obsolete. Use parameter isomerism_card instead.
- :type kunlunCard: string
- :param isomerismCard:
- type of isomerismCard, including kunlunCard, fpgaCard, gpuCard
- :type isomerismCard: string
- :param isomerism_card:
- type of isomerismCard, including kunlunCard, fpgaCard, gpuCard.
- :type isomerism_card: string
- :param file_systems:
- This parameter is obsolete.
- :type file_systems:list<bcc_model.FileSystemModel>
- :param user_data:
- :type user_data: string
- :param is_open_hosteye:
- :type is_open_hosteye: boolean
- :param deletion_protection:
- :type deletion_protection: int
- :param res_group_id:
- The optional parameter to specify the resGroupId of the instance
- :type res_group_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- if billing is None:
- billing = default_billing_to_purchase_created
- if card_count == 1 and cardCount > 1:
- card_count = cardCount
- if isomerism_card is None:
- isomerism_card = isomerismCard
- body = {
- 'cpuCount': cpu_count,
- 'memoryCapacityInGB': memory_capacity_in_gb,
- 'imageId': image_id,
- 'billing': billing.__dict__
- }
- if spec is not None:
- body['spec'] = spec
- if eip_name is not None:
- body['eipName'] = eip_name
- if hostname is not None:
- body['hostname'] = hostname
- if auto_seq_suffix is not None:
- body['autoSeqSuffix'] = auto_seq_suffix
- if is_open_hostname_domain is not None:
- body['isOpenHostnameDomain'] = is_open_hostname_domain
- if relation_tag is not None:
- body['relationTag'] = relation_tag
- if is_open_ipv6 is not None:
- body['isOpenIpv6'] = is_open_ipv6
- if file_systems is not None:
- file_system_list = [file_system.__dict__ for file_system in file_systems]
- body['fileSystems'] = file_system_list
- if user_data is not None:
- body['userData'] = user_data
- if is_open_hosteye is not None:
- body['isOpenHosteye'] = is_open_hosteye
- if deletion_protection is not None:
- body['deletionProtection'] = deletion_protection
- if instance_type is not None:
- body['instanceType'] = instance_type
- if root_disk_size_in_gb != 0:
- body['rootDiskSizeInGb'] = root_disk_size_in_gb
- if root_disk_storage_type is not None:
- body['rootDiskStorageType'] = root_disk_storage_type
- if create_cds_list is not None:
- body['createCdsList'] = [create_cds.__dict__ for create_cds in create_cds_list]
- if network_capacity_in_mbps != 0:
- body['networkCapacityInMbps'] = network_capacity_in_mbps
- if purchase_count > 0:
- body['purchaseCount'] = purchase_count
- if name is not None:
- body['name'] = name
- if admin_pass is not None:
- secret_access_key = self.config.credentials.secret_access_key
- cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
- body['adminPass'] = cipher_admin_pass
- if zone_name is not None:
- body['zoneName'] = zone_name
- if subnet_id is not None:
- body['subnetId'] = subnet_id
- if security_group_id is not None:
- body['securityGroupId'] = security_group_id
- if enterprise_security_group_id is not None:
- body['enterpriseSecurityGroupId'] = enterprise_security_group_id
- if security_group_ids is not None:
- body['securityGroupIds'] = security_group_ids
- if enterprise_security_group_ids is not None:
- body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
- if ehc_cluster_id is not None:
- body['ehcClusterId'] = ehc_cluster_id
- if gpuCard is not None:
- body['gpuCard'] = gpuCard
- body['cardCount'] = card_count if card_count > 1 else 1
- if fpgaCard is not None:
- body['fpgaCard'] = fpgaCard
- body['cardCount'] = card_count if card_count > 1 else 1
- if kunlunCard is not None:
- body['kunlunCard'] = kunlunCard
- body['cardCount'] = card_count if card_count > 1 else 1
- if isomerism_card is not None:
- body['isomerismCard'] = isomerism_card
- body['cardCount'] = card_count if card_count > 1 else 1
- if is_keep_image_login is not None:
- body['keepImageLogin'] = is_keep_image_login
- if auto_renew_time != 0:
- body['autoRenewTime'] = auto_renew_time
- if auto_renew_time_unit is None:
- body['autoRenewTimeUnit'] = "month"
- else:
- body['autoRenewTimeUnit'] = auto_renew_time_unit
- if ephemeral_disks is not None:
- body['ephemeralDisks'] = [ephemeral_disk.__dict__ for ephemeral_disk in ephemeral_disks]
- if dedicate_host_id is not None:
- body['dedicatedHostId'] = dedicate_host_id
- if deploy_id is not None:
- body['deployId'] = deploy_id
- if bid_model is not None:
- body['bidModel'] = bid_model
- if bid_price is not None:
- body['bidPrice'] = bid_price
- if key_pair_id is not None:
- body['keypairId'] = key_pair_id
- if internet_charge_type is not None:
- body['internetChargeType'] = internet_charge_type
- if asp_id is not None:
- body['aspId'] = asp_id
- if request_token is not None:
- body['requestToken'] = request_token
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['tags'] = tag_list
- if internal_ips is not None:
- body['internalIps'] = internal_ips
- if res_group_id is not None:
- body['resGroupId'] = res_group_id
- body['cdsAutoRenew'] = cds_auto_renew
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(cpu_count=int, memory_capacity_in_gb=int, dedicated_host_id=(bytes, str), # ***Unicode***
- image_id=(bytes, str)) # ***Unicode***
- def create_instance_from_dedicated_host_with_encrypted_password(self, cpu_count, memory_capacity_in_gb, image_id,
- dedicated_host_id, ephemeral_disks=None,
- purchase_count=1, name=None, admin_pass=None,
- subnet_id=None, security_group_id=None,
- client_token=None, config=None):
- """
- Create a Instance from dedicatedHost with the specified options.
- You must fill the field of clientToken,which is especially for keeping idempotent.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param cpu_count:
- The specified number of cpu core to create the instance,
- is less than or equal to the remain of dedicated host.
- :type cpu_count: int
- :param memory_capacity_in_gb:
- The capacity of memory to create the instance,
- is less than or equal to the remain of dedicated host.
- :type memory_capacity_in_gb: int
- :param image_id:
- The id of image, list all available image in BccClient.list_images.
- :type image_id: string
- :param dedicated_host_id:
- The id of dedicated host, we can locate the instance in specified dedicated host.
- :type dedicated_host_id: string
- :param ephemeral_disks:
- The optional list of ephemeral volume detail info to create.
- :type ephemeral_disks: list<bcc_model.EphemeralDisk>
- :param purchase_count:
- The number of instance to buy, the default value is 1.
- :type purchase_count: int
- :param name:
- The optional parameter to desc the instance that will be created.
- :type name: string
- :param admin_pass:
- The optional parameter to specify the password for the instance.
- If specify the adminPass,the adminPass must be a 8-16 characters String
- which must contains letters, numbers and symbols.
- The symbols only contains "!@#$%^*()".
- The adminPass will be encrypted in AES-128 algorithm
- with the substring of the former 16 characters of user SecretKey.
- If not specify the adminPass, it will be specified by an random string.
- See more detail on
- https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
- :type admin_pass: string
- :param subnet_id:
- The optional parameter to specify the id of subnet from vpc, optional param
- default value is default subnet from default vpc
- :type subnet_id: string
- :param security_group_id:
- The optional parameter to specify the securityGroupId of the instance
- vpcId of the securityGroupId must be the same as the vpcId of subnetId
- See more detail through listSecurityGroups method
- :type security_group_id: string
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'cpuCount': cpu_count,
- 'memoryCapacityInGB': memory_capacity_in_gb,
- 'imageId': image_id,
- 'dedicatedHostId': dedicated_host_id
- }
- if ephemeral_disks is not None:
- body['ephemeralDisks'] = ephemeral_disks
- if purchase_count > 0:
- body['purchaseCount'] = purchase_count
- if name is not None:
- body['name'] = name
- if subnet_id is not None:
- body['subnetId'] = subnet_id
- if security_group_id is not None:
- body['securityGroupId'] = security_group_id
- if admin_pass is not None:
- secret_access_key = self.config.credentials.secret_access_key
- cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
- body['adminPass'] = cipher_admin_pass
- return self._send_request(http_methods.POST, path, json.dumps(body), params=params,
- config=config)
- @required(cpu_count=int, memory_capacity_in_gb=int, dedicated_host_id=(bytes, str), # ***Unicode***
- image_id=(bytes, str)) # ***Unicode***
- def create_instance_from_dedicated_host(self, cpu_count, memory_capacity_in_gb, image_id,
- dedicated_host_id, ephemeral_disks=None,
- purchase_count=1, name=None, admin_pass=None,
- subnet_id=None, security_group_id=None,
- client_token=None, config=None):
- """
- Create a Instance from dedicatedHost with the specified options.
- You must fill the field of clientToken,which is especially for keeping idempotent.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param cpu_count:
- The specified number of cpu core to create the instance,
- is less than or equal to the remain of dedicated host.
- :type cpu_count: int
- :param memory_capacity_in_gb:
- The capacity of memory to create the instance,
- is less than or equal to the remain of dedicated host.
- :type memory_capacity_in_gb: int
- :param image_id:
- The id of image, list all available image in BccClient.list_images.
- :type image_id: string
- :param dedicated_host_id:
- The id of dedicated host, we can locate the instance in specified dedicated host.
- :type dedicated_host_id: string
- :param ephemeral_disks:
- The optional list of ephemeral volume detail info to create.
- :type ephemeral_disks: list<bcc_model.EphemeralDisk>
- :param purchase_count:
- The number of instance to buy, the default value is 1.
- :type purchase_count: int
- :param name:
- The optional parameter to desc the instance that will be created.
- :type name: string
- :param admin_pass:
- The optional parameter to specify the password for the instance.
- If specify the adminPass,the adminPass must be a 8-16 characters String
- which must contains letters, numbers and symbols.
- The symbols only contains "!@#$%^*()".
- The adminPass will be encrypted in AES-128 algorithm
- with the substring of the former 16 characters of user SecretKey.
- If not specify the adminPass, it will be specified by an random string.
- See more detail on
- https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
- :type admin_pass: string
- :param subnet_id:
- The optional parameter to specify the id of subnet from vpc, optional param
- default value is default subnet from default vpc
- :type subnet_id: string
- :param security_group_id:
- The optional parameter to specify the securityGroupId of the instance
- vpcId of the securityGroupId must be the same as the vpcId of subnetId
- See more detail through listSecurityGroups method
- :type security_group_id: string
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'cpuCount': cpu_count,
- 'memoryCapacityInGB': memory_capacity_in_gb,
- 'imageId': image_id,
- 'dedicatedHostId': dedicated_host_id
- }
- if ephemeral_disks is not None:
- body['ephemeralDisks'] = ephemeral_disks
- if purchase_count > 0:
- body['purchaseCount'] = purchase_count
- if name is not None:
- body['name'] = name
- if admin_pass is not None:
- body['adminPass'] = admin_pass
- if subnet_id is not None:
- body['subnetId'] = subnet_id
- if security_group_id is not None:
- body['securityGroupId'] = security_group_id
- return self._send_request(http_methods.POST, path, json.dumps(body), params=params,
- config=config)
- @required(cpu_count=int,
- memory_capacity_in_gb=int,
- image_id=(bytes, str)) # ***Unicode***
- def create_instance_of_bid(self, cpu_count, memory_capacity_in_gb, image_id, instance_type=None,
- billing=None, create_cds_list=None, root_disk_size_in_gb=0, root_disk_storage_type=None,
- ephemeral_disks=None, dedicate_host_id=None, auto_renew_time_unit=None,
- auto_renew_time=0,
- deploy_id=None, bid_model=None, bid_price=None, key_pair_id=None, cds_auto_renew=False,
- internet_charge_type=None, internal_ips=None, request_token=None, asp_id=None, tags=None,
- network_capacity_in_mbps=0, purchase_count=1, cardCount=1, name=None, admin_pass=None,
- zone_name=None, subnet_id=None, security_group_id=None, gpuCard=None, fpgaCard=None,
- client_token=None, config=None, spec=None, user_data=None,
- eip_name=None, hostname=None, auto_seq_suffix=False, is_open_hostname_domain=False,
- spec_id=None, relation_tag=False, is_open_ipv6=False, deletion_protection=None,
- enterprise_security_group_id=None, security_group_ids=None, res_group_id=None,
- enterprise_security_group_ids=None, isomerismCard=None, file_systems=None,
- card_count=1, isomerism_card=None, is_eip_auto_related_delete=False
- , is_keep_image_login=None):
- """
- Create a bcc Instance with the specified options.
- You must fill the field of clientToken,which is especially for keeping idempotent.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param instance_type:
- The specified Specification to create the instance,
- See more detail on
- https://cloud.baidu.com/doc/BCC/API.html#InstanceType
- :type instance_type: string
- :param cpu_count:
- The parameter to specified the cpu core to create the instance.
- :type cpu_count: int
- :param memory_capacity_in_gb:
- The parameter to specified the capacity of memory in GB to create the instance.
- :type memory_capacity_in_gb: int
- :param image_id:
- The id of image, list all available image in BccClient.list_images.
- :type image_id: string
- :param billing:
- Billing information.
- :type billing: bcc_model.Billing
- :param create_cds_list:
- The optional list of volume detail info to create.
- :type create_cds_list: list<bcc_model.CreateCdsModel>
- :param network_capacity_in_mbps:
- The optional parameter to specify the bandwidth in Mbps for the new instance.
- It must among 0 and 200, default value is 0.
- If it's specified to 0, it will get the internal ip address only.
- :type network_capacity_in_mbps: int
- :param purchase_count:
- The number of instance to buy, the default value is 1.
- :type purchase_count: int
- :param name:
- The optional parameter to desc the instance that will be created.
- :type name: string
- :param admin_pass:
- The optional parameter to specify the password for the instance.
- If specify the adminPass,the adminPass must be a 8-16 characters String
- which must contains letters, numbers and symbols.
- The symbols only contains "!@#$%^*()".
- The adminPass will be encrypted in AES-128 algorithm
- with the substring of the former 16 characters of user SecretKey.
- If not specify the adminPass, it will be specified by an random string.
- See more detail on
- https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
- :type admin_pass: string
- :param zone_name:
- The optional parameter to specify the available zone for the instance.
- See more detail through list_zones method
- :type zone_name: string
- :param subnet_id:
- The optional parameter to specify the id of subnet from vpc, optional param
- default value is default subnet from default vpc
- :type subnet_id: string
- :param security_group_id:
- The optional parameter to specify the securityGroupId of the instance
- vpcId of the securityGroupId must be the same as the vpcId of subnetId
- See more detail through listSecurityGroups method
- :type security_group_id: string
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :param fpgaCard:
- This parameter is obsolete. Use parameter isomerism_card instead.
- :type fpgaCard: string
- :param gpuCard:
- This parameter is obsolete. Use parameter isomerism_card instead.
- :type gpuCard: string
- :param cardCount:
- This parameter is obsolete. Use parameter card_count instead.
- :type cardCount: int
- :param card_count:
- The parameter to specify the card count for creating GPU/FPGA instance.
- :type card_count: int
- :param root_disk_size_in_gb:
- The parameter to specify the root disk size in GB.
- The root disk excludes the system disk, available is 40-500GB.
- :type root_disk_size_in_gb: int
- :param root_disk_storage_type:
- The parameter to specify the root disk storage type.
- Default use of HP1 cloud disk.
- :type root_disk_storage_type: string
- :param ephemeral_disks:
- The optional list of ephemeral volume detail info to create.
- :type ephemeral_disks: list<bcc_model.EphemeralDisk>
- :param dedicate_host_id:
- This parameter is obsolete.
- :type dedicate_host_id: string
- :param auto_renew_time_unit:
- This parameter is obsolete.
- :type auto_renew_time_unit: string
- :param auto_renew_time:
- This parameter is obsolete.
- :type auto_renew_time: string
- :param tags:
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :param deploy_id:
- This parameter is obsolete.
- :type deploy_id: string
- :param bid_model:
- The parameter to specify the bidding model.
- The bidding model can be "market" or "custom".
- :type bid_model: string
- :param bid_price:
- The parameter to specify the bidding price.
- When the bid_model is "custom", it works.
- :type bid_price: string
- :param key_pair_id:
- The parameter to specify id of the keypair.
- :type key_pair_id: string
- :param asp_id:
- The parameter to specify id of the asp.
- :type asp_id: string
- :param request_token:
- The parameter to specify the request token which will make the request idempotent.
- :type request_token: string
- :param internet_charge_type:
- The parameter to specify the internet charge type.
- See more detail on
- https://cloud.baidu.com/doc/BCC/API.html#InternetChargeType
- :type internet_charge_type: string
- :param internal_ips:
- This parameter is obsolete.
- :type internal_ips: list<string>
- :param cds_auto_renew:
- This parameter is obsolete.
- :type cds_auto_renew: boolean
- :param spec:
- The parameter to specify Specification to create the instance.
- :type spec: string
- :param user_data:
- The parameter to specify instance custom data.
- :type user_data string
- :param hostname:
- The optional parameter to specify the host name of the instance virtual machine.
- By default, hostname is not specified.
- If hostname is specified: hostname is used as the prefix of the name in batches.
- The backend will add a suffix, and the suffix generation method is: name{-serial number}.
- If name is not specified, it will be automatically generated using the following method:
- {instance-eight-digit random string-serial number}.
- Note: The random string is generated from the characters 0-9 and a-z;
- the serial number increases sequentially according to the magnitude of count.
- If count is 100, the serial number increases from 000~100, and if it is 10, it increases from 00~10.
- Only lowercase letters, numbers and - . special characters are supported.
- They must start with a letter. Special symbols cannot be used continuously.
- Special symbols are not supported at the beginning or end. The length is 2-64.
- :type hostname: string
- :param auto_seq_suffix:
- The parameter to specify whether name and hostname order suffixes are automatically generated.
- :type auto_seq_suffix: boolean
- :param is_open_hostname_domain:
- The parameter to specify whether hostname domain is automatically generated
- :type is_open_hostname_domain: boolean
- :param spec_id:
- Identify of the spec.
- :type spec_id: string
- :param relation_tag:
- The parameter to specify whether the instance related to existing tags
- :type relation_tag: boolean
- :param is_open_ipv6:
- The parameter indicates whether the instance to be created is enabled for IPv6.
- It can only be enabled when both the image and subnet support IPv6.
- True indicates enabled, false indicates disabled,
- and no transmission indicates automatic adaptation of the image and subnet's IPv6 support
- :type is_open_ipv6: boolean
- :param deletion_protection:
- The status of instance deletion protection. 1:enable, 0:disable.
- :type deletion_protection: int
- :param eip_name:
- eip name
- :type eip_name: string
- :param isomerismCard:
- This parameter is obsolete. Use parameter isomerism_card instead.
- :type isomerismCard: string
- :param isomerism_card:
- The parameter to specify the card type for creating GPU/FPGA instance.
- :type isomerism_card: string
- :param enterprise_security_group_id:
- :type enterprise_security_group_id: string
- :param security_group_ids:
- security_group_ids
- :type security_group_ids: list<string>
- :param res_group_id:
- The optional parameter to specify the resGroupId of the instance
- :type res_group_id: string
- :param enterprise_security_group_ids:
- enterprise_security_group_ids
- :type enterprise_security_group_ids: list<string>
- :param file_systems:
- This parameter is obsolete.
- :type file_systems: list<bcc_model.FileSystemModel>
- :param is_eip_auto_related_delete:
- The parameter to specify whether to delete the relevant EIP after the bidding instance is automatically deleted.
- :type is_eip_auto_related_delete: boolean
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/bid'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- if billing is None:
- billing = default_billing_to_purchase_created
- if card_count == 1 and cardCount > 1:
- card_count = cardCount
- if isomerism_card is None:
- isomerism_card = isomerismCard
- body = {
- 'cpuCount': cpu_count,
- 'memoryCapacityInGB': memory_capacity_in_gb,
- 'imageId': image_id,
- 'billing': billing.__dict__
- }
- if hostname is not None:
- body['hostname'] = hostname
- if auto_seq_suffix is not None:
- body['autoSeqSuffix'] = auto_seq_suffix
- if is_open_hostname_domain is not None:
- body['isOpenHostnameDomain'] = is_open_hostname_domain
- if spec_id is not None:
- body['specId'] = spec_id
- if relation_tag is not None:
- body['relationTag'] = relation_tag
- if is_open_ipv6 is not None:
- body['isOpenIpv6'] = is_open_ipv6
- if deletion_protection is not None:
- body['deletionProtection'] = deletion_protection
- if eip_name is not None:
- body['eipName'] = eip_name
- if enterprise_security_group_id is not None:
- body['enterpriseSecurityGroupId'] = enterprise_security_group_id
- if isomerism_card is not None:
- body['isomerismCard'] = isomerism_card
- if file_systems is not None:
- file_system_list = [file_system.__dict__ for file_system in file_systems]
- body['fileSystems'] = file_system_list
- if instance_type is not None:
- body['instanceType'] = instance_type
- if root_disk_size_in_gb != 0:
- body['rootDiskSizeInGb'] = root_disk_size_in_gb
- if root_disk_storage_type is not None:
- body['rootDiskStorageType'] = root_disk_storage_type
- if create_cds_list is not None:
- body['createCdsList'] = [create_cds.__dict__ for create_cds in create_cds_list]
- if network_capacity_in_mbps != 0:
- body['networkCapacityInMbps'] = network_capacity_in_mbps
- if purchase_count > 0:
- body['purchaseCount'] = purchase_count
- if name is not None:
- body['name'] = name
- if admin_pass is not None:
- secret_access_key = self.config.credentials.secret_access_key
- cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
- body['adminPass'] = cipher_admin_pass
- if zone_name is not None:
- body['zoneName'] = zone_name
- if subnet_id is not None:
- body['subnetId'] = subnet_id
- if security_group_id is not None:
- body['securityGroupId'] = security_group_id
- if security_group_ids is not None:
- body['securityGroupIds'] = security_group_ids
- if enterprise_security_group_ids is not None:
- body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
- if gpuCard is not None:
- body['gpuCard'] = gpuCard
- body['cardCount'] = card_count if card_count > 1 else 1
- if fpgaCard is not None:
- body['fpgaCard'] = fpgaCard
- body['cardCount'] = card_count if card_count > 1 else 1
- if auto_renew_time != 0:
- body['autoRenewTime'] = auto_renew_time
- if auto_renew_time_unit is None:
- body['autoRenewTimeUnit'] = "month"
- else:
- body['autoRenewTimeUnit'] = auto_renew_time_unit
- if ephemeral_disks is not None:
- body['ephemeralDisks'] = [ephemeral_disk.__dict__ for ephemeral_disk in ephemeral_disks]
- if dedicate_host_id is not None:
- body['dedicatedHostId'] = dedicate_host_id
- if deploy_id is not None:
- body['deployId'] = deploy_id
- if bid_model is not None:
- body['bidModel'] = bid_model
- if bid_price is not None:
- body['bidPrice'] = bid_price
- if key_pair_id is not None:
- body['keypairId'] = key_pair_id
- if internet_charge_type is not None:
- body['internetChargeType'] = internet_charge_type
- if asp_id is not None:
- body['aspId'] = asp_id
- if request_token is not None:
- body['requestToken'] = request_token
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['tags'] = tag_list
- if internal_ips is not None:
- body['internalIps'] = internal_ips
- body['cdsAutoRenew'] = cds_auto_renew
- if spec is not None:
- body['spec'] = spec
- if user_data is not None:
- body['userData'] = user_data
- if res_group_id is not None:
- body['resGroupId'] = res_group_id
- if is_keep_image_login is not None:
- body['keepImageLogin'] = is_keep_image_login
- body['isEipAutoRelatedDelete'] = is_eip_auto_related_delete
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def list_instances(self, marker=None, max_keys=None, internal_ip=None, dedicated_host_id=None,
- zone_name=None, instance_ids=None, instance_names=None, cds_ids=None, ehc_cluster_id=None,
- deployset_ids=None, security_group_ids=None, payment_timing=None, status=None, tags=None,
- vpc_id=None, private_ips=None, ipv6_addresses=None, auto_renew=None, fuzzy_instance_name=None,
- config=None):
- """
- Return a list of instances owned by the authenticated user.
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 1000.
- :type max_keys: int
- :param internal_ip:
- The identified internal ip of instance.
- :type internal_ip: string
- :param dedicated_host_id:
- get instance list filtered by id of dedicated host
- :type dedicated_host_id: string
- :param zone_name:
- get instance list filtered by name of available zone
- :type zone_name: string
- :param instance_ids:
- filter instance list with multiple instance ids join by ','
- :type instance_ids: string
- :param instance_names:
- filter instance list with multiple instance names join by ','
- :type instance_names: string
- :param cds_ids:
- filter instance list with multiple cds ids join by ','
- :type cds_ids: string
- :param ehc_cluster_id:
- get instance list filtered by id of ehc cluster
- :type ehc_cluster_id: string
- :param deployset_ids:
- filter instance list with multiple deployset ids join by ','
- :type deployset_ids: string
- :param security_group_ids:
- filter instance list with multiple securityGroup ids join by ','
- :type security_group_ids: string
- :param payment_timing:
- filter instance list with multiple type of paymentTiming join by ','
- :type payment_timing: string
- :param status:
- filter instance list with multiple instance status join by ','
- :type status: string
- :param tags:
- filter instance list with multiple tags join by ',', the format of tag can be :
- tagKey:tagValue or tagKey
- :type tags: string
- :param vpc_id:
- filter instance list with vpc id, the parameter should be used with private_ips
- :type vpc_id: string
- :param private_ips:
- filter instance list with multiple private ips join by ',', the parameter should be used with
- vpc_id
- :type private_ips: string
- :param ipv6_addresses:
- filter instance list with multiple ipv6 private ips join by ',', the parameter should be used with
- vpc_id
- :type ipv6_addresses: string
- :param auto_renew:
- :type auto_renew: boolean
- :param fuzzy_instance_name:
- filter instance list with fuzzy instance name
- :type fuzzy_instance_name: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance'
- params = {}
- if marker is not None:
- params['marker'] = marker
- if max_keys is not None:
- params['maxKeys'] = max_keys
- if internal_ip is not None:
- params['internalIp'] = internal_ip
- if dedicated_host_id is not None:
- params['dedicatedHostId'] = dedicated_host_id
- if zone_name is not None:
- params['zoneName'] = zone_name
- if instance_ids is not None:
- params['instanceIds'] = instance_ids
- if instance_names is not None:
- params['instanceNames'] = instance_names
- if cds_ids is not None:
- params['cdsIds'] = cds_ids
- if ehc_cluster_id is not None:
- params['ehcClusterId'] = ehc_cluster_id
- if deployset_ids is not None:
- params['deploySetIds'] = deployset_ids
- if security_group_ids is not None:
- params['securityGroupIds'] = security_group_ids
- if payment_timing is not None:
- params['paymentTiming'] = payment_timing
- if status is not None:
- params['status'] = status
- if tags is not None:
- params['tags'] = tags
- if vpc_id is not None:
- params['vpcId'] = vpc_id
- if private_ips is not None:
- params['privateIps'] = private_ips
- if ipv6_addresses is not None:
- params['ipv6Addresses'] = ipv6_addresses
- if auto_renew is not None:
- params['autoRenew'] = auto_renew
- if fuzzy_instance_name is not None:
- params['fuzzyInstanceName'] = fuzzy_instance_name
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(instance_id=(bytes, str)) # ***Unicode***
- def get_instance(self, instance_id, contains_failed=False, config=None):
- """
- Get the detail information of specified instance.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param contains_failed:
- The optional parameters to get the failed message.If true, it means get the failed message.
- :type contains_failed: boolean
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = instance_id.encode(encoding='utf-8')
- path = b'/instance/%s' % instance_id
- params = {}
- if contains_failed:
- params['containsFailed'] = contains_failed
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(instance_id=(bytes, str)) # ***Unicode***s
- def start_instance(self, instance_id, config=None):
- """
- Starting the instance owned by the user.
- You can start the instance only when the instance is Stopped,
- otherwise, it's will get 409 errorCode.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param instance_id: id of instance proposed to start
- :type instance_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- params = {
- 'start': None
- }
- return self._send_request(http_methods.PUT, path, params=params, config=config)
- @required(instance_id=(bytes, str)) # ***Unicode***
- def stop_instance(self, instance_id, force_stop=False, stopWithNoCharge=False, config=None):
- """
- Stopping the instance owned by the user.
- You can stop the instance only when the instance is Running,
- otherwise, it's will get 409 errorCode.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param force_stop:
- The optional parameter to stop the instance forcibly.If true,
- it will stop the instance just like power off immediately
- and it may result in losing important data which have not been written to disk.
- :type force_stop: boolean
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- body = {
- 'forceStop': force_stop,
- 'stopWithNoCharge': stopWithNoCharge
- }
- params = {
- 'stop': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=(bytes, str)) # ***Unicode***
- def reboot_instance(self, instance_id, force_stop=False, config=None):
- """
- Rebooting the instance owned by the user.
- You can reboot the instance only when the instance is Running,
- otherwise, it's will get 409 errorCode.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param force_stop:
- The optional parameter to stop the instance forcibly.If true,
- it will stop the instance just like power off immediately
- and it may result in losing important data which have not been written to disk.
- :type force_stop: boolean
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- body = {
- 'forceStop': force_stop
- }
- params = {
- 'reboot': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=str)
- def batch_add_ip(self, instance_id, private_ips=None, secondary_private_ip_address_count=None,
- allocate_multi_ipv6_addr=None, config=None):
- """
- batch_add_ip
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param private_ips:
- The IPV6/IPV4 address that needs to be added must exist with secondary_private_ip_address_count.
- :type private_ips: list
- :param secondary_private_ip_address_count:
- The number of IPV6/IPV4 needs to be increased, and one with private_ips must exist.
- :type secondary_private_ip_address_count: list
- :param allocate_multi_ipv6_addr:
- The parameter indicates whether to support multiple IPV6.
- It must be true to create IPV6.
- :type allocate_multi_ipv6_addr: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/batchAddIp'
- body = {
- 'instanceId': instance_id,
- }
- if private_ips is not None:
- body['privateIps'] = private_ips
- if secondary_private_ip_address_count is not None:
- body['secondaryPrivateIpAddressCount'] = secondary_private_ip_address_count
- if allocate_multi_ipv6_addr is not None:
- body['allocateMultiIpv6Addr'] = allocate_multi_ipv6_addr
- params = {
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=str, private_ips=list)
- def batch_delete_ip(self, instance_id, private_ips, config=None):
- """
- :param instance_id:
- :param private_ips:
- :param config:
- :return:
- """
- path = b'/instance/batchDelIp'
- body = {
- 'instanceId': instance_id,
- 'privateIps': private_ips,
- }
- params = {
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=(bytes, str), # ***Unicode***
- admin_pass=(bytes, str)) # ***Unicode***
- def modify_instance_password(self, instance_id, admin_pass, config=None):
- """
- Modifying the password of the instance.
- You can change the instance password only when the instance is Running or Stopped ,
- otherwise, it's will get 409 errorCode.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param admin_pass:
- The new password to update.
- The adminPass will be encrypted in AES-128 algorithm
- with the substring of the former 16 characters of user SecretKey.
- :type admin_pass: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- secret_access_key = self.config.credentials.secret_access_key
- cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
- path = b'/instance/%s' % instance_id
- body = {
- 'adminPass': cipher_admin_pass
- }
- params = {
- 'changePass': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=(bytes, str), # ***Unicode***
- name=(bytes, str)) # ***Unicode***
- def modify_instance_attributes(self, instance_id, name=None, neteth_queuecount=None,
- enable_jumbo_frame=None, config=None):
- """
- Modifying the special attribute to new value of the instance.
- You can reboot the instance only when the instance is Running or Stopped ,
- otherwise, it's will get 409 errorCode.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param name:
- The new value for instance's name.
- :type name: string
- :param neteth_queuecount:
- The new value for instance's neteth_queuecount.
- :type neteth_queuecount: string
- :param enable_jumbo_frame:
- The parameter indicates whether the instance is enabled for JumboFrame.
- It can only be enabled when the flavor support JumboFrame.
- True indicates enabled, false indicates disabled,
- :type enable_jumbo_frame: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- body = {
- 'name': name,
- 'netEthQueueCount': neteth_queuecount
- }
- if enable_jumbo_frame is not None:
- body['enableJumboFrame'] = enable_jumbo_frame
- params = {
- 'modifyAttribute': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=(bytes, str),
- desc=(bytes, str))
- def modify_instance_desc(self, instance_id, desc, config=None):
- """
- Modifying the description of the instance.
- You can reboot the instance only when the instance is Running or Stopped ,
- otherwise, it's will get 409 errorCode.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param desc:
- The new value for instance's description.
- :type name: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- body = {
- 'desc': desc
- }
- params = {
- 'modifyDesc': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=(bytes, str), # ***Unicode***
- image_id=(bytes, str)) # ***Unicode***
- def rebuild_instance(self, instance_id, image_id, admin_pass=None, key_pair_id=None, is_keep_image_login=None,
- config=None, user_data=None, clean_last_user_data=None, is_open_hostEye=None,
- sys_root_size=None, is_preserve_data=None, raid_id=None, data_partition_type=None,
- root_partition_type=None):
- """
- Rebuilding the instance owned by the user.
- After rebuilding the instance,
- all of snapshots created from original instance system disk will be deleted,
- all of customized images will be saved for using in the future.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param image_id:
- The id of the image which is used to rebuild the instance.
- :type image_id: string
- :param admin_pass:
- The admin password to login the instance.
- The admin password will be encrypted in AES-128 algorithm
- with the substring of the former 16 characters of user SecretKey.
- See more detail on
- https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
- :type admin_pass: string
- :param key_pair_id:
- key_pair_id or admin_pass is required for rebuild instance.
- :type key_pair_id: string
- :param user_data:
- User data to pass to the instance at launch time.
- :type user_data: string
- :param clean_last_user_data:
- Indicates whether to clean the user data after the instance has been rebuilded.
- Default value is False.
- :type clean_user_data: boolean
- :param is_open_hostEye:
- Indicates whether to open host eye.
- :type is_open_hostEye: boolean
- :param sys_root_size:
- System partition size (unit: GB).
- :type sys_root_size: int
- :param is_preserve_data:
- Indicates whether to preserve data during the instance rebuilding process.
- Default value is False.
- :type is_preserve_data: boolean
- :param raid_id:
- RAID ID.
- :type raid_id: string
- :param data_partition_type:
- Data partition type.
- :type data_partition_type: string
- :param root_partition_type:
- Root partition type.
- :type root_partition_type: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- body = {
- 'imageId': image_id,
- }
- if key_pair_id is not None:
- body['keypairId'] = key_pair_id
- if is_keep_image_login is not None:
- body['keepImageLogin'] = is_keep_image_login
- if admin_pass is not None:
- secret_access_key = self.config.credentials.secret_access_key
- cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
- body['adminPass'] = cipher_admin_pass
- if user_data is not None:
- body['userData'] = user_data
- if clean_last_user_data is not None:
- body['cleanLastUserData'] = clean_last_user_data
- if is_open_hostEye is not None:
- body['isOpenHostEye'] = is_open_hostEye
- if sys_root_size is not None:
- body['sysRootSize'] = sys_root_size
- if is_preserve_data is not None:
- body['isPreserveData'] = is_preserve_data
- if raid_id is not None:
- body['raidId'] = raid_id
- if data_partition_type is not None:
- body['dataPartitionType'] = data_partition_type
- if root_partition_type is not None:
- body['rootPartitionType'] = root_partition_type
- params = {
- 'rebuild': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=(bytes, str)) # ***Unicode***
- def release_instance(self, instance_id, config=None):
- """
- Releasing the instance owned by the user.
- Only the Postpaid instance or Prepaid which is expired can be released.
- After releasing the instance,
- all of the data will be deleted.
- all of volumes attached will be auto detached, but the volume snapshots will be saved.
- all of snapshots created from original instance system disk will be deleted,
- all of customized images created from original instance system disk will be reserved.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- return self._send_request(http_methods.DELETE, path, config=config)
- @required(instance_id=(bytes, str), # ***Unicode***
- cpu_count=int,
- memory_capacity_in_gb=int)
- def resize_instance(self, instance_id, cpu_count, memory_capacity_in_gb,
- live_resize=None, gpu_card_count=None, ephemeral_disk_in_gb=None,
- enable_jumbo_frame=None,
- client_token=None, config=None):
- """
- Resizing the instance owned by the user.
- The Prepaid instance can not be downgrade.
- Only the Running/Stopped instance can be resized, otherwise, it's will get 409 errorCode.
- After resizing the instance,it will be reboot once.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param cpu_count:
- The parameter of specified the cpu core to resize the instance.
- :type cpu_count: int
- :param memory_capacity_in_gb:
- The parameter of specified the capacity of memory in GB to resize the instance.
- :type memory_capacity_in_gb: int
- :param enable_jumbo_frame:
- The parameter of specified the instance enable/disable jumbo frame.
- True means enable jumbo frame, false means disable jumbo frame.
- enable_jumbo_frame default None which means:
- When you change to the spec which doesn't support jumbo frame, the jumbo frame will be disabled.
- When the original instance don't support jumbo frame and you change to the spec which support jumbo frame,
- the jumbo frame will be disabled.
- When the original spec of the instance support jumbo frame , then you change to the spec which support jumbo
- frame, if the original instance enable jumbo frame, the jumbo frame will be enabled, if the original instance
- disable jumbo frame, the jumbo frame will be disabled.
- :type enable_jumbo_frame: bool
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :param live_resize:
- :type live_resize: boolean
- :param gpu_card_count:
- :type gpu_card_count: int
- :param ephemeral_disk_in_gb:
- :type ephemeral_disk_in_gb: int
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- body = {
- 'cpuCount': cpu_count,
- 'memoryCapacityInGB': memory_capacity_in_gb
- }
- if live_resize is not None:
- body['liveResize'] = live_resize
- if gpu_card_count is not None:
- body['gpuCardCount'] = gpu_card_count
- if ephemeral_disk_in_gb is not None:
- body['ephemeralDiskInGb'] = ephemeral_disk_in_gb
- if enable_jumbo_frame is not None:
- body['enableJumboFrame'] = enable_jumbo_frame
- params = None
- if client_token is None:
- params = {
- 'resize': None,
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'resize': None,
- 'clientToken': client_token
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=(bytes, str), # ***Unicode***
- security_group_id=(bytes, str)) # ***Unicode***
- def bind_instance_to_security_group(self, instance_id, security_group_id, config=None):
- """
- Binding the instance to specified securitygroup.
- :param instance_id:
- The id of the instance.
- :type instance_id: string
- :param securitygroup_id:
- The id of the securitygroup.
- :type securitygroup_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- body = {
- 'securityGroupId': security_group_id
- }
- params = {
- 'bind': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=(bytes, str), # ***Unicode***
- security_group_id=(bytes, str)) # ***Unicode***
- def unbind_instance_from_security_group(self, instance_id, security_group_id, config=None):
- """
- Unbinding the instance from securitygroup.
- :param instance_id:
- The id of the instance.
- :type instance_id: string
- :param securitygroup_id:
- The id of the securitygroup.
- :type securitygroup_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- body = {
- 'securityGroupId': security_group_id
- }
- params = {
- 'unbind': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(reserved_instance_ids=list,
- tags=list)
- def bind_reserved_instance_to_tags(self, reserved_instance_ids, tags, config=None):
- """
- :param reserved_instance_ids:
- :param tags:
- :param config:
- :return:
- """
- path = b'/bcc/reserved/tag'
- tag_list = [tag.__dict__ for tag in tags]
- body = {
- 'changeTags': tag_list,
- 'reservedInstanceIds': reserved_instance_ids
- }
- params = {
- 'bind': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(reserved_instance_ids=list,
- tags=list)
- def unbind_reserved_instance_from_tags(self, reserved_instance_ids, tags, config=None):
- """
- :param reserved_instance_ids:
- :param tags:
- :param config:
- :return:
- """
- path = b'/bcc/reserved/tag'
- tag_list = [tag.__dict__ for tag in tags]
- body = {
- 'changeTags': tag_list,
- 'reservedInstanceIds': reserved_instance_ids
- }
- params = {
- 'unbind': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- def bind_tags_batch_by_resource_type(self, resource_type, resource_ids, tags, is_relation_tag, config=None):
- """
- :param resource_type:
- :param resource_ids:
- :param tags:
- :param is_relation_tag:
- :param config:
- :return:
- """
- path = b'/bcc/tag'
- tag_list = [tag.__dict__ for tag in tags]
- body = {
- 'resourceType': resource_type,
- 'resourceIds': resource_ids,
- 'tags': tag_list,
- 'isRelationTag': is_relation_tag
- }
- params = {
- 'action': 'AttachTags'
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config, prefix=self.prefix_v3)
- def unbind_tags_batch_by_resource_type(self, resource_type, resource_ids, tags, is_relation_tag, config=None):
- """
- :param resource_type:
- :param resource_ids:
- :param tags:
- :param is_relation_tag:
- :param config:
- :return:
- """
- path = b'/bcc/tag'
- tag_list = [tag.__dict__ for tag in tags]
- body = {
- 'resourceType': resource_type,
- 'resourceIds': resource_ids,
- 'tags': tag_list,
- 'isRelationTag': is_relation_tag
- }
- params = {
- 'action': 'DetachTags'
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config, prefix=self.prefix_v3)
- @required(instance_id=(bytes, str),
- tags=list)
- def bind_instance_to_tags(self, instance_id, tags, config=None):
- """
- :param instance_id:
- :param tags:
- :param config:
- :return:
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s/tag' % instance_id
- tag_list = [tag.__dict__ for tag in tags]
- body = {
- 'changeTags': tag_list
- }
- params = {
- 'bind': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=(bytes, str),
- tags=list)
- def unbind_instance_from_tags(self, instance_id, tags, config=None):
- """
- :param instance_id:
- :param tags:
- :param config:
- :return:
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s/tag' % instance_id
- tag_list = [tag.__dict__ for tag in tags]
- body = {
- 'changeTags': tag_list
- }
- params = {
- 'unbind': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=(bytes, str)) # ***Unicode***
- def get_instance_vnc(self, instance_id, config=None):
- """
- Getting the vnc url to access the instance.
- The vnc url can be used once.
- :param instance_id:
- The id of the instance.
- :type instance_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s/vnc' % instance_id
- return self._send_request(http_methods.GET, path, config=config)
- @required(instance_id=(bytes, str)) # ***Unicode***
- def purchase_reserved_instance(self,
- instance_id,
- billing=None,
- related_renew_flag=None,
- client_token=None,
- config=None,
- cds_custom_period=None):
- """
- PurchaseReserved the instance with fixed duration.
- You can not purchaseReserved the instance which is resizing.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param instance_id:
- The id of the instance.
- :type instance_id: string
- :param billing:
- Billing information.
- :type billing: bcc_model.Billing
- :param related_renew_flag:
- Detailed information see: https://cloud.baidu.com/doc/BCC/s/6jwvyo0q2#relatedrenewflag
- :type related_renew_flag: string
- :param cds_custom_period:
- Custom renew period for CDS.
- :type cds_custom_period: list
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- if billing is None:
- billing = default_billing_to_purchase_reserved
- cds_custom_period_list = []
- if cds_custom_period is not None:
- cds_custom_period_list = [custom_period.__dict__ for custom_period in cds_custom_period]
- body = {
- 'billing': billing.__dict__,
- "cdsCustomPeriod": cds_custom_period_list
- }
- params = None
- if client_token is None:
- params = {
- 'purchaseReserved': None,
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'purchaseReserved': None,
- 'clientToken': client_token
- }
- if related_renew_flag is not None:
- params['relatedRenewFlag'] = related_renew_flag
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- def list_instance_specs(self, config=None):
- """
- The interface will be deprecated in the future,
- we suggest to use triad (instanceType, cpuCount, memoryCapacityInGB) to specified the instance configuration.
- Listing all of specification for instance resource to buy.
- See more detail on
- 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
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/spec'
- return self._send_request(http_methods.GET, path, config=config)
- @required(cds_size_in_gb=int)
- def create_volume_with_cds_size(self, cds_size_in_gb, billing=None, purchase_count=1,
- storage_type='hp1', zone_name=None,
- instance_id=None, encrypt_key=None, name=None,
- description=None, renew_time_unit=None, renew_time=None,
- cluster_id=None, relation_tag=False,
- tags=None, auto_snapshot_policy=None,
- client_token=None, config=None, charge_type=None):
- """
- Create a volume with the specified options.
- You can use this method to create a new empty volume by specified options
- or you can create a new volume from customized volume snapshot but not system disk snapshot.
- By using the cdsSizeInGB parameter you can create a newly empty volume.
- By using snapshotId parameter to create a volume form specific snapshot.
- :param cds_size_in_gb:
- The size of volume to create in GB.
- By specifying the snapshotId,
- it will create volume from the specified snapshot and the parameter cdsSizeInGB will be ignored.
- :type cds_size_in_gb: int
- :param billing:
- Billing information.Deprecated
- :type billing: bcc_model.Billing
- :param purchase_count:
- The optional parameter to specify how many volumes to buy, default value is 1.
- The maximum to create for one time is 5.
- :type purchase_count: int
- :param storage_type:
- The storage type of volume, see more detail in
- https://bce.baidu.com/doc/BCC/API.html#StorageType
- :type storage_type: menu{'hp1', 'std1'}
- :param zone_name:
- The optional parameter to specify the available zone for the volume.
- See more detail through list_zones method
- :type zone_name: string
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :param instance_id:
- :type instance_id: string
- :param encrypt_key:
- :type encrypt_key: string
- :param name:
- :type name: string
- :param description:
- :type description: string
- :param renew_time_unit:
- :type renew_time_unit: string
- :param renew_time:
- :type renew_time: int
- :param cluster_id:
- cds cluster id
- :type cluster_id: string
- :param relation_tag:
- :type relation_tag: boolean
- :param tags:
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :param auto_snapshot_policy:
- The optional auto snapshot policy to be bonded.
- :type auto_snapshot_policy: bcc_model.AutoSnapshotPolicyModel
- :param charge_type:
- The optional parameter to specify the payment for the volume.
- The billing type and payment method, including Prepaid and Postpaid,
- need to be specified only when the instanceId is not empty and the corresponding instance type is prepaid.
- If instanceId is empty:
- create a post payment type CDS;
- If the instanceId is not empty:
- If the instance is prepaid, a chargeType needs to be specified;
- If the instance is post paid, create a post paid CDS
- :type charge_type: menu{'Prepaid', 'Postpaid'}
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/volume'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- if billing is None:
- billing = default_billing_to_purchase_created
- body = {
- 'cdsSizeInGB': cds_size_in_gb,
- 'billing': billing.__dict__
- }
- if purchase_count is not None:
- body['purchaseCount'] = purchase_count
- if storage_type is not None:
- body['storageType'] = storage_type
- if zone_name is not None:
- body['zoneName'] = zone_name
- if renew_time_unit is not None:
- body['renewTimeUnit'] = renew_time_unit
- if renew_time is not None:
- body['renewTime'] = renew_time
- if cluster_id is not None:
- body['clusterId'] = cluster_id
- if relation_tag is not None:
- body['relationTag'] = relation_tag
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['tags'] = tag_list
- if auto_snapshot_policy is not None:
- body['autoSnapshotPolicy'] = auto_snapshot_policy.__dict__
- if name is not None:
- body['name'] = name
- if description is not None:
- body['description'] = description
- if encrypt_key is not None:
- body['encryptKey'] = encrypt_key
- if instance_id is not None:
- body['instanceId'] = instance_id
- if charge_type is not None:
- body['chargeType'] = charge_type
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(snapshot_id=(bytes, str)) # ***Unicode***
- def create_volume_with_snapshot_id(self, snapshot_id, billing=None, purchase_count=1,
- storage_type='hp1', zone_name=None, client_token=None,
- instance_id=None, encrypt_key=None, name=None,
- description=None, renew_time_unit=None, renew_time=None,
- cluster_id=None, relation_tag=False,
- tags=None, auto_snapshot_policy=None,
- config=None, charge_type=None):
- """
- Create a volume with the specified options.
- You can use this method to create a new empty volume by specified options
- or you can create a new volume from customized volume snapshot but not system disk snapshot.
- By using the cdsSizeInGB parameter you can create a newly empty volume.
- By using snapshotId parameter to create a volume form specific snapshot.
- :param snapshot_id:xx
- The id of snapshot.
- By specifying the snapshotId,
- it will create volume from the specified snapshot and the parameter cdsSizeInGB will be ignored.
- :type snapshot_id: string
- :param billing:
- Billing information.Deprecated
- :type billing: bcc_model.Billing
- :param purchase_count:
- The optional parameter to specify how many volumes to buy, default value is 1.
- The maximum to create for one time is 5.
- :type purchase_count: int
- :param storage_type:
- The storage type of volume, see more detail in
- https://bce.baidu.com/doc/BCC/API.html#StorageType
- :type storage_type: menu{'hp1', 'std1'}
- :param zone_name:
- The optional parameter to specify the available zone for the volume.
- See more detail through list_zones method
- :type zone_name: string
- :param instance_id:
- :type instance_id: string
- :param encrypt_key:
- :type encrypt_key: string
- :param name:
- :type name: string
- :param description:
- :type description: string
- :param renew_time_unit:
- :type renew_time_unit: string
- :param renew_time:
- :type renew_time: int
- :param cluster_id:
- cds cluster id
- :type cluster_id: string
- :param relation_tag:
- :type relation_tag: boolean
- :param tags:
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :param auto_snapshot_policy:
- The optional auto snapshot policy to be bonded.
- :type auto_snapshot_policy: bcc_model.AutoSnapshotPolicyModel
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :param charge_type:
- The optional parameter to specify the payment for the volume.
- The billing type and payment method, including Prepaid and Postpaid,
- need to be specified only when the instanceId is not empty and the corresponding instance type is prepaid.
- If instanceId is empty:
- create a post payment type CDS;
- If the instanceId is not empty:
- If the instance is prepaid, a chargeType needs to be specified;
- If the instance is post paid, create a post paid CDS
- :type charge_type: menu{'Prepaid', 'Postpaid'}
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/volume'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- if billing is None:
- billing = default_billing_to_purchase_created
- body = {
- 'snapshotId': snapshot_id,
- 'billing': billing.__dict__
- }
- if purchase_count is not None:
- body['purchaseCount'] = purchase_count
- if storage_type is not None:
- body['storageType'] = storage_type
- if zone_name is not None:
- body['zoneName'] = zone_name
- if renew_time_unit is not None:
- body['renewTimeUnit'] = renew_time_unit
- if renew_time is not None:
- body['renewTime'] = renew_time
- if cluster_id is not None:
- body['clusterId'] = cluster_id
- if relation_tag is not None:
- body['relationTag'] = relation_tag
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['tags'] = tag_list
- if auto_snapshot_policy is not None:
- body['autoSnapshotPolicy'] = auto_snapshot_policy.__dict__
- if name is not None:
- body['name'] = name
- if description is not None:
- body['description'] = description
- if encrypt_key is not None:
- body['encryptKey'] = encrypt_key
- if instance_id is not None:
- body['instanceId'] = instance_id
- if charge_type is not None:
- body['chargeType'] = charge_type
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def list_volumes(self, instance_id=None, zone_name=None, marker=None, max_keys=None,
- cluster_id=None,
- volume_ids=None,
- config=None):
- """
- Listing volumes owned by the authenticated user.
- :param instance_id:
- The id of instance. The optional parameter to list the volume.
- If it's specified,only the volumes attached to the specified instance will be listed.
- :type instance_id: string
- :param zone_name:
- The name of available zone. The optional parameter to list volumes
- :type zone_name: string
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 1000.
- :type max_keys: int
- :param cluster_id:
- :type cluster_id: string
- :param volume_ids:
- :type volume_ids: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/volume'
- params = {}
- if instance_id is not None:
- params['instanceId'] = instance_id
- if zone_name is not None:
- params['zoneName'] = zone_name
- if marker is not None:
- params['marker'] = marker
- if max_keys is not None:
- params['maxKeys'] = max_keys
- if cluster_id is not None:
- params['clusterId'] = cluster_id
- if volume_ids is not None:
- params['volumeIds'] = volume_ids
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(volume_id=(bytes, str)) # ***Unicode***
- def get_volume(self, volume_id, config=None):
- """
- Get the detail information of specified volume.
- :param volume_id:
- The id of the volume.
- :type volume_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- volume_id = compat.convert_to_bytes(volume_id)
- path = b'/volume/%s' % volume_id
- return self._send_request(http_methods.GET, path, config=config)
- @required(volume_id=(bytes, str), # ***Unicode***
- instance_id=(bytes, str)) # ***Unicode***
- def attach_volume(self, volume_id, instance_id, config=None):
- """
- Attaching the specified volume to a specified instance.
- You can attach the specified volume to a specified instance only
- when the volume is Available and the instance is Running or Stopped,
- otherwise, it's will get 409 errorCode.
- :param volume_id:
- The id of the volume which will be attached to specified instance.
- :type volume_id: string
- :param instance_id:
- The id of the instance which will be attached with a volume.
- :type instance_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- volume_id = compat.convert_to_bytes(volume_id)
- path = b'/volume/%s' % volume_id
- body = {
- 'instanceId': instance_id
- }
- params = {
- 'attach': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(volume_id=(bytes, str), # ***Unicode***
- instance_id=(bytes, str)) # ***Unicode***
- def detach_volume(self, volume_id, instance_id, config=None):
- """
- Detaching the specified volume from a specified instance.
- You can detach the specified volume from a specified instance only
- when the instance is Running or Stopped ,
- otherwise, it's will get 409 errorCode.
- :param volume_id:
- The id of the volume which will be attached to specified instance.
- :type volume_id: string
- :param instance_id:
- The id of the instance which will be attached with a volume.
- :type instance_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- volume_id = compat.convert_to_bytes(volume_id)
- path = b'/volume/%s' % volume_id
- body = {
- 'instanceId': instance_id
- }
- params = {
- 'detach': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- def describe_regions(self, region, config=None):
- """
- List all region's endpoint information with the specific parameters.
- Use global endpoint bcc.baidubce.com to get BCC,CDS,ReservedInstance's endpoint.
- :param region:
- The id of region.
- :type region: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/region/describeRegions'
- body = {
- 'region': region
- }
- params = {}
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(volume_id=(bytes, str)) # ***Unicode***
- def release_volume(self, volume_id, config=None):
- """
- Releasing the specified volume owned by the user.
- You can release the specified volume only
- when the instance is among state of Available/Expired/Error,
- otherwise, it's will get 409 errorCode.
- :param volume_id:
- The id of the volume which will be released.
- :type volume_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- volume_id = compat.convert_to_bytes(volume_id)
- path = b'/volume/%s' % volume_id
- return self._send_request(http_methods.DELETE, path, config=config)
- @required(volume_id=(bytes, str), # ***Unicode***
- new_cds_size=int)
- def resize_volume(self, volume_id, new_cds_size, new_volume_type,
- client_token=None, config=None):
- """
- Resizing the specified volume with newly size.
- You can resize the specified volume only when the volume is Available,
- otherwise, it's will get 409 errorCode.
- The prepaid volume can not be downgrade.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_volume.
- :param volume_id:
- The id of volume which you want to resize.
- :type volume_id: string
- :param new_cds_size:
- The new volume size you want to resize in GB.
- :type new_cds_size: int
- :param new_volume_type:
- detail information see: https://cloud.baidu.com/doc/BCC/s/6jwvyo0q2#storagetype
- :type new_volume_type: string
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- volume_id = compat.convert_to_bytes(volume_id)
- path = b'/volume/%s' % volume_id
- body = {
- 'newCdsSizeInGB': new_cds_size
- }
- if new_volume_type is not None:
- body['newVolumeType'] = new_volume_type
- params = None
- if client_token is None:
- params = {
- 'resize': None,
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'resize': None,
- 'clientToken': client_token
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(volume_id=(bytes, str), # ***Unicode***
- snapshot_id=(bytes, str)) # ***Unicode***
- def rollback_volume(self, volume_id, snapshot_id, config=None):
- """
- Rollback the volume with the specified volume snapshot.
- You can rollback the specified volume only when the volume is Available,
- otherwise, it's will get 409 errorCode.
- The snapshot used to rollback must be created by the volume,
- otherwise,it's will get 404 errorCode.
- If rolling back the system volume,the instance must be Running or Stopped,
- otherwise, it's will get 409 errorCode.After rolling back the
- volume,all the system disk data will erase.
- :param volume_id:
- The id of volume which will be rollback.
- :type volume_id: string
- :param snapshot_id:
- The id of snapshot which will be used to rollback the volume.
- :type snapshot_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- volume_id = compat.convert_to_bytes(volume_id)
- path = b'/volume/%s' % volume_id
- body = {
- 'snapshotId': snapshot_id
- }
- params = {
- 'rollback': None,
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(volume_id=(bytes, str)) # ***Unicode***
- def purchase_reserved_volume(self,
- volume_id,
- billing=None,
- client_token=None,
- config=None,
- instance_id=None):
- """
- PurchaseReserved the instance with fixed duration.
- You can not purchaseReserved the instance which is resizing.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_volume.
- :param volume_id:
- The id of volume which will be renew.
- :type volume_id: string
- :param billing:
- Billing information.
- :type billing: bcc_model.Billing
- :param instance_id:
- The id of instance to align renew duarion.
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- volume_id = compat.convert_to_bytes(volume_id)
- path = b'/volume/%s' % volume_id
- if billing is None:
- billing = default_billing_to_purchase_reserved
- body = {
- 'billing': billing.__dict__,
- 'instanceId': instance_id
- }
- params = None
- if client_token is None:
- params = {
- 'purchaseReserved': None,
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'purchaseReserved': None,
- 'clientToken': client_token
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(volume_id=(bytes, str),
- cds_name=(bytes, str),
- desc=(bytes, str))
- def modify_volume_Attribute(self,
- volume_id,
- cds_name,
- desc,
- config=None):
- """
- :param volume_id:
- :type volume_id: string
- :param cds_name:
- :type cds_name:string
- :param desc:
- :type desc: string
- :return:
- """
- volume_id = compat.convert_to_bytes(volume_id)
- path = b'/volume/%s' % volume_id
- body = {
- 'cdsName': cds_name
- }
- if desc is not None:
- body['desc'] = desc
- params = {
- 'modify': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(volume_id=(bytes, str))
- def modify_volume_charge_type(self,
- volume_id,
- billing=None,
- effective_type=None,
- config=None):
- """
- :param volume_id: volume id
- :type volume_id: string
- :param billing: payment information
- :type billing: bcc_model.Billing
- :param effective_type: Optional parameters:
- AtOnce (switch to pay-as-you-go immediately),
- AfterExpiration (switch to pay-as-you-go after expiration).
- Defaults to AfterExpiration if not provided.
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- volume_id = compat.convert_to_bytes(volume_id)
- path = b'/volume/%s' % volume_id
- if billing is None:
- billing = default_billing_to_purchase_reserved
- body = {
- 'effectiveType': effective_type,
- 'billing': billing.__dict__
- }
- params = {
- 'modifyChargeType': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(image_name=(bytes, str), # ***Unicode***
- instance_id=(bytes, str)) # ***Unicode***
- def create_image_from_instance_id(self,
- image_name,
- instance_id,
- encrypt_key=None,
- relate_cds=False,
- client_token=None,
- config=None,
- detection=None):
- """
- Creating a customized image which can be used for creating instance.
- You can create an image from an instance with this method.
- While creating an image from an instance, the instance must be Running or Stopped,
- otherwise, it's will get 409 errorCode.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_image.
- :param image_name:
- The name for the image that will be created.
- The name length from 1 to 65,only contains letters,digital and underline.
- :type image_name: string
- :param instance_id:
- The optional parameter specify the id of the instance which will be used to create the new image.
- When instanceId and snapshotId are specified ,only instanceId will be used.
- :type instance_id: string
- :param encrypt_key:
- :type encrypt_key: string
- :param relate_cds:
- :type relate_cds: boolean
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/image'
- params = None
- if client_token is None:
- params = {
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'clientToken': client_token
- }
- body = {
- 'imageName': image_name,
- 'instanceId': instance_id
- }
- if encrypt_key is not None:
- body['encryptKey'] = encrypt_key
- if relate_cds is not None:
- body['relateCds'] = relate_cds
- if detection:
- body['detection'] = detection
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(image_name=(bytes, str), # ***Unicode***
- snapshot_id=(bytes, str)) # ***Unicode***
- def create_image_from_snapshot_id(self,
- image_name,
- snapshot_id,
- encrypt_key=None,
- client_token=None,
- config=None,
- detection=None):
- """
- Creating a customized image which can be used for creating instance.
- You can create an image from an snapshot with tihs method.
- You can create the image only from system snapshot.
- While creating an image from a system snapshot,the snapshot must be Available,
- otherwise, it's will get 409 errorCode.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_image.
- :param image_name:
- The name for the image that will be created.
- The name length from 1 to 65,only contains letters,digital and underline.
- :type image_name: string
- :param snapshot_id:
- The optional parameter specify the id of the snapshot which will be used to create the new image.
- When instanceId and snapshotId are specified ,only instanceId will be used.
- :type snapshot_id: string
- :param encrypt_key:
- :type encrypt_key: string
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/image'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'imageName': image_name,
- 'snapshotId': snapshot_id
- }
- if encrypt_key is not None:
- body['encryptKey'] = encrypt_key
- if detection:
- body['detection'] = detection
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def list_images(self, image_type='All', marker=None, max_keys=None, image_name=None,
- config=None):
- """
- Listing images owned by the authenticated user.
- :param image_type:
- The optional parameter to filter image to list.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#ImageType"
- :type image_type: menu{'All', System', 'Custom', 'Integration'}
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 1000.
- :type max_keys: int
- :param image_name:
- The optional parameter to query specified custom image by image name.
- :type image_name: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/image'
- params = {
- 'imageType': image_type
- }
- if marker is not None:
- params['marker'] = marker
- if max_keys is not None:
- params['maxKeys'] = max_keys
- if image_name is not None:
- params['imageName'] = image_name
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(image_id=(bytes, str)) # ***Unicode***
- def get_image(self, image_id, config=None):
- """
- Get the detail information of specified image.
- :param image_id:
- The id of image.
- :type image_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- image_id = compat.convert_to_bytes(image_id)
- path = b'/image/%s' % image_id
- return self._send_request(http_methods.GET, path, config=config)
- @required(image_id=(bytes, str)) # ***Unicode***
- def delete_image(self, image_id, config=None):
- """
- Deleting the specified image.
- Only the customized image can be deleted,
- otherwise, it's will get 403 errorCode.
- :param image_id:
- The id of image.
- :type image_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- image_id = compat.convert_to_bytes(image_id)
- path = b'/image/%s' % image_id
- return self._send_request(http_methods.DELETE, path, config=config)
- @required(image_id=(bytes, str),
- name=(bytes, str),
- destRegions=list)
- def remote_copy_image(self,
- image_id,
- name,
- destRegions,
- config=None):
- """
- :param image_id:
- :param name:
- :param destRegions:
- :param config:
- :return:
- """
- image_id = compat.convert_to_bytes(image_id)
- path = b'/image/%s' % image_id
- body = {
- 'name': name,
- 'destRegion': destRegions
- }
- params = {
- 'remoteCopy': None
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(image_id=(bytes, str))
- def cancle_remote_copy_image(self,
- image_id,
- config=None):
- """
- :param image_id:
- :param config:
- :return:
- """
- image_id = compat.convert_to_bytes(image_id)
- path = b'/image/%s' % image_id
- params = {
- 'cancelRemoteCopy': None
- }
- return self._send_request(http_methods.POST, path, params=params, config=config)
- @required(image_id=(bytes, str))
- def share_image(self,
- image_id,
- account=None,
- account_id=None,
- ucaccount=None,
- config=None):
- """
- :param image_id: image id
- :type image_id: string
- :param account: share image to target account
- :type account: string
- :param account_id: share image to target account_id
- :type account_id: string
- :param ucaccount: share image to target ucaccount
- :type ucaccount: string
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- image_id = compat.convert_to_bytes(image_id)
- path = b'/image/%s' % image_id
- body = {}
- if account is not None:
- body['account'] = account
- if account_id is not None:
- body['accountId'] = account_id
- if ucaccount is not None:
- body['ucAccount'] = ucaccount
- params = {
- 'share': None
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(image_id=(bytes, str))
- def unshare_image(self,
- image_id,
- account=None,
- account_id=None,
- ucaccount=None,
- config=None):
- """
- :param image_id: image id
- :type image_id: string
- :param account: unshare image with target account
- :type account: string
- :param account_id: unshare image with target account_id
- :type account_id: string
- :param ucaccount: unshare image with target ucaccount
- :type ucaccount: string
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- image_id = compat.convert_to_bytes(image_id)
- path = b'/image/%s' % image_id
- body = {}
- if account is not None:
- body['account'] = account
- if account_id is not None:
- body['accountId'] = account_id
- if ucaccount is not None:
- body['ucAccount'] = ucaccount
- params = {
- 'unshare': None
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(image_id=(bytes, str))
- def list_shared_user(self,
- image_id,
- config=None):
- """
- :param image_id:
- :param config:
- :return:
- """
- image_id = compat.convert_to_bytes(image_id)
- path = b'/image/%s/sharedUsers' % image_id
- return self._send_request(http_methods.GET, path, config=config)
- @required(instance_ids=list)
- def list_os(self,
- instance_ids=None,
- config=None):
- """
- :param instance_ids:
- :param config:
- :return:
- """
- path = b'/image/os'
- instance_id_list = instance_ids
- body = {
- 'instanceIds': instance_id_list
- }
- return self._send_request(http_methods.POST, path, json.dumps(body), config=config)
- @required(volume_id=(bytes, str), # ***Unicode***
- snapshot_name=(bytes, str)) # ***Unicode***
- def create_snapshot(self,
- volume_id,
- snapshot_name,
- desc=None,
- tags=None,
- client_token=None,
- config=None):
- """
- Creating snapshot from specified volume.
- You can create snapshot from system volume and CDS volume.
- While creating snapshot from system volume,the instance must be Running or Stopped,
- otherwise, it's will get 409 errorCode.
- While creating snapshot from CDS volume, the volume must be InUs or Available,
- otherwise, it's will get 409 errorCode.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_snapshot.
- :param volume_id:
- The id which specify where the snapshot will be created from.
- If you want to create an snapshot from a customized volume, a id of the volume will be set.
- If you want to create an snapshot from a system volume, a id of the instance will be set.
- :type volume_id: string
- :param snapshot_name:
- The name for the snapshot that will be created.
- The name length from 1 to 65,only contains letters,digital and underline.
- :type snapshot_name: string
- :param desc:
- The optional parameter to describe the information of the new snapshot.
- :type desc: string
- :param tags:
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/snapshot'
- params = None
- if client_token is None:
- params = {
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'clientToken': client_token
- }
- body = {
- 'volumeId': volume_id,
- 'snapshotName': snapshot_name
- }
- if desc is not None:
- body['desc'] = desc
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['tags'] = tag_list
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def list_snapshots(self, marker=None, max_keys=None, volume_id=None, config=None):
- """
- List snapshots
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type params: string
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 1000.
- :type params: int
- :param volume_id:
- The id of the volume.
- :type volume_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/snapshot'
- params = None
- if marker is not None or max_keys is not None or volume_id is not None:
- params = {}
- if marker is not None:
- params['marker'] = marker
- if max_keys is not None:
- params['maxKeys'] = max_keys
- if volume_id is not None:
- params['volumeId'] = volume_id
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(snapshot_id=(bytes, str)) # ***Unicode***
- def get_snapshot(self, snapshot_id, config=None):
- """
- Get the detail information of specified snapshot.
- :param snapshot_id:
- The id of snapshot.
- :type snapshot_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- snapshot_id = compat.convert_to_bytes(snapshot_id)
- path = b'/snapshot/%s' % snapshot_id
- return self._send_request(http_methods.GET, path, config=config)
- @required(snapshot_id=(bytes, str)) # ***Unicode***
- def delete_snapshot(self, snapshot_id, config=None):
- """
- Deleting the specified snapshot.
- Only when the snapshot is CreatedFailed or Available,the specified snapshot can be deleted.
- otherwise, it's will get 403 errorCode.
- :param snapshot_id:
- The id of snapshot.
- :type snapshot_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- snapshot_id = compat.convert_to_bytes(snapshot_id)
- path = b'/snapshot/%s' % snapshot_id
- return self._send_request(http_methods.DELETE, path, config=config)
- @required(name=(bytes, str), # ***Unicode***
- rules=list)
- def create_security_group(self,
- name,
- rules,
- vpc_id=None,
- desc=None,
- client_token=None,
- tags=None,
- config=None):
- """
- Creating a newly SecurityGroup with specified rules.
- :param name:
- The name of SecurityGroup that will be created.
- :type name: string
- :param rules:
- The list of rules which define how the SecurityGroup works.
- :type rules: list<bcc_model.SecurityGroupRuleModel>
- :param vpc_id:
- The optional parameter to specify the id of VPC to SecurityGroup
- :type vpc_id: string
- :param desc:
- The optional parameter to describe the SecurityGroup that will be created.
- :type desc: string
- :param tags:
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/securityGroup'
- params = None
- if client_token is None:
- params = {
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'clientToken': client_token
- }
- rule_list = [rule.__dict__ for rule in rules]
- body = {
- 'name': name,
- 'rules': rule_list
- }
- if vpc_id is not None:
- body['vpcId'] = vpc_id
- if desc is not None:
- body['desc'] = desc
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['tags'] = tag_list
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def list_security_groups(self, instance_id=None, vpc_id=None, security_group_ids=None, marker=None, max_keys=None,
- config=None):
- """
- Listing SecurityGroup owned by the authenticated user.
- :param instance_id:
- The id of instance. The optional parameter to list the SecurityGroup.
- If it's specified,only the SecurityGroup related to the specified instance will be listed
- :type instance_id: string
- :param vpc_id:
- filter by vpcId, optional parameter
- :type vpc_id: string
- :param security_group_ids:
- filter by securityGroupIds, optional parameter
- :type security_group_ids: string
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 1000.
- :type max_keys: int
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/securityGroup'
- params = {}
- if instance_id is not None:
- params['instanceId'] = instance_id
- if vpc_id is not None:
- params['vpcId'] = vpc_id
- if security_group_ids is not None:
- params['securityGroupIds'] = security_group_ids
- if marker is not None:
- params['marker'] = marker
- if max_keys is not None:
- params['maxKeys'] = max_keys
- return self._send_request(http_methods.GET, path,
- params=params, config=config)
- @required(security_group_id=(bytes, str)) # ***Unicode***
- def delete_security_group(self, security_group_id, config=None):
- """
- Deleting the specified SecurityGroup.
- :param security_group_id:
- The id of SecurityGroup that will be deleted.
- :type security_group_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- security_group_id = compat.convert_to_bytes(security_group_id)
- path = b'/securityGroup/%s' % security_group_id
- return self._send_request(http_methods.DELETE, path, config=config)
- @required(security_group_id=(bytes, str), # ***Unicode***
- rule=bcc_model.SecurityGroupRuleModel)
- def authorize_security_group_rule(self, security_group_id, rule, client_token=None,
- config=None):
- """
- authorize a security group rule to the specified security group
- :param security_group_id:
- The id of SecurityGroup that will be authorized.
- :type security_group_id: string
- :param rule:
- security group rule detail.
- Through protocol/portRange/direction/sourceIp/sourceGroupId, we can confirmed only one rule.
- :type rule: bcc_model.SecurityGroupRuleModel
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- security_group_id = compat.convert_to_bytes(security_group_id)
- path = b'/securityGroup/%s' % security_group_id
- params = {'authorizeRule': ''}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'rule': rule.__dict__
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(security_group_id=(bytes, str), # ***Unicode***
- rule=bcc_model.SecurityGroupRuleModel)
- def revoke_security_group_rule(self, security_group_id, rule, client_token=None, config=None):
- """
- revoke a security group rule from the specified security group
- :param security_group_id:
- The id of SecurityGroup that will be revoked.
- :type security_group_id: string
- :param rule:
- security group rule detail.
- Through protocol/portRange/direction/sourceIp/sourceGroupId, we can confirmed only one rule.
- :type rule: bcc_model.SecurityGroupRuleModel
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- security_group_id = compat.convert_to_bytes(security_group_id)
- path = b'/securityGroup/%s' % security_group_id
- params = {'revokeRule': ''}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'rule': rule.__dict__
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- def update_security_group_rule(self, security_group_rule_id,
- remark=None,
- direction=None,
- protocol=None,
- portrange=None,
- source_ip=None,
- sourcegroup_id=None,
- dest_ip=None,
- destgroup_id=None,
- config=None):
- """
- uodate a security group rule from the specified security group
- :param security_group_rule_id:
- security group rule id.
- :param: remark:
- The remark for the rule.
- :param: portrange:
- The port range to specify the port which the rule will work on.
- Available range is rang [0, 65535], the fault value is "" for all port.
- :param: protocol:
- The parameter specify which protocol will the rule work on, the fault value is "" for all protocol.
- Available protocol are tcp, udp and icmp.
- :param: source_ip:
- The source ip range with CIDR formats. The default value 0.0.0.0/0 (allow all ip address),
- other supported formats such as {ip_addr}/12 or {ip_addr}. Only supports IPV4.
- Only works for direction = "ingress".
- :param: sourcegroup_id:
- The source security group id. Cannot coexist with sourceIP.
- :param: dest_ip:
- The destination ip range with CIDR formats. The default value 0.0.0.0/0 (allow all ip address),
- other supported formats such as {ip_addr}/12 or {ip_addr}. Only supports IPV4.
- Only works for direction = "egress".
- :param: destgroup_id:
- The destination security group id. Cannot coexist with destIP.
- :param: priority:
- The parameter specify the priority of the rule(range 1-1000).
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/securityGroup/rule/update'
- body = {
- 'securityGroupRuleId': security_group_rule_id,
- 'remark': remark,
- 'direction': direction,
- 'protocol': protocol,
- 'portRange': portrange,
- 'sourceIp': source_ip,
- 'sourceGroupId': sourcegroup_id,
- 'destIp': dest_ip,
- 'destGroupId': destgroup_id
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=None, config=config)
- @required(security_group_rule_id=(bytes, str)) # ***Unicode***
- def delete_security_group_rule(self, security_group_rule_id, config=None):
- """
- delete a security group rule from the specified security group
- :param security_group_rule_id:
- The id of SecurityGroupRule that will be deleted.
- :type security_group_id: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- security_group_rule_id = compat.convert_to_bytes(security_group_rule_id)
- path = b'/securityGroup/rule/%s' % security_group_rule_id
- return self._send_request(http_methods.DELETE, path, params=None, config=config)
- @required(security_group_id=(bytes, str)) # ***Unicode***
- def get_security_group_detail(self, security_group_id, config=None):
- """
- get a security group detail from the specified security group
- :param security_group_id:
- The id of security_group that will be deleted.
- :type security_group_id: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- security_group_id = compat.convert_to_bytes(security_group_id)
- path = b'/securityGroup/%s' % security_group_id
- return self._send_request(http_methods.GET, path, params=None, config=config)
- def list_zones(self, config=None):
- """
- Get zone detail list within current region
- :param config:
- :return:
- """
- path = b'/zone'
- return self._send_request(http_methods.GET, path, config=config)
- @required(asp_name=(bytes, str),
- time_points=list,
- repeat_week_days=list,
- retention_days=(bytes, str))
- def create_asp(self,
- asp_name=None,
- time_points=None,
- repeat_week_days=None,
- retention_days=None,
- client_token=None,
- config=None):
- """
- :param asp_name:
- :param time_points:
- :param repeat_week_days:
- :param retention_days:
- :param client_token:
- :param config:
- :return:
- """
- path = b'/asp'
- params = None
- if client_token is None:
- params = {
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'clientToken': client_token
- }
- body = {
- 'name': asp_name,
- 'timePoints': time_points,
- 'repeatWeekdays': repeat_week_days,
- 'retentionDays': retention_days
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(asp_id=(bytes, str),
- volume_ids=list)
- def attach_asp(self,
- asp_id=None,
- volume_ids=None,
- config=None):
- """
- :param asp_id:
- :param volume_ids:
- :param config:
- :return:
- """
- asp_id = compat.convert_to_bytes(asp_id)
- path = b'/asp/%s' % asp_id
- body = {
- 'volumeIds': volume_ids
- }
- params = {
- 'attach': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(asp_id=(bytes, str),
- volume_ids=list)
- def detach_asp(self,
- asp_id=None,
- volume_ids=None,
- config=None):
- """
- :param asp_id:
- :param volume_ids:
- :param config:
- :return:
- """
- asp_id = compat.convert_to_bytes(asp_id)
- path = b'/asp/%s' % asp_id
- body = {
- 'volumeIds': volume_ids
- }
- params = {
- 'detach': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(asp_id=(bytes, str))
- def delete_asp(self,
- asp_id=None,
- config=None):
- """
- :param asp_id:
- :param config:
- :return:
- """
- asp_id = compat.convert_to_bytes(asp_id)
- path = b'/asp/%s' % asp_id
- return self._send_request(http_methods.DELETE, path, config=config)
- def list_asps(self, marker=None, max_keys=None, asp_name=None, volume_name=None, config=None):
- """
- :param marker:
- :param max_keys:
- :param asp_name:
- :param volume_name:
- :param config:
- :return:
- """
- path = b'/asp'
- params = None
- if marker is not None or max_keys is not None or asp_name is not None or volume_name is not None:
- params = {}
- if marker is not None:
- params['marker'] = marker
- if max_keys is not None:
- params['maxKeys'] = max_keys
- if asp_name is not None:
- params['aspName'] = asp_name
- if volume_name is not None:
- params['volumeName'] = volume_name
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(asp_id=(bytes, str))
- def get_asp(self, asp_id=None, config=None):
- """
- :param asp_id:
- :param config:
- :return:
- """
- asp_id = compat.convert_to_bytes(asp_id)
- path = b'/asp/%s' % asp_id
- return self._send_request(http_methods.GET, path, config=config)
- @required(keypair_name=(bytes, str))
- def create_keypair(self,
- keypair_name=None,
- keypair_desc=None,
- config=None):
- """
- :param keypair_name:
- :param keypair_desc:
- :param config:
- :return:
- """
- path = b'/keypair'
- body = {
- 'name': keypair_name,
- 'description': keypair_desc
- }
- params = {
- 'create': None
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(keypair_name=(bytes, str),
- public_key=(bytes, str))
- def import_keypair(self,
- keypair_name=None,
- keypair_desc=None,
- public_key=None,
- config=None):
- """
- :param keypair_name:
- :param keypair_desc:
- :param public_key:
- :param config:
- :return:
- """
- path = b'/keypair'
- body = {
- 'name': keypair_name,
- 'publicKey': public_key
- }
- if keypair_desc is not None:
- body['description'] = keypair_desc
- params = {
- 'import': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- def list_keypairs(self, marker=None, max_keys=None, name=None, config=None):
- """
- :param marker:
- :param max_keys:
- :param config:
- :return:
- """
- path = b'/keypair'
- params = None
- if marker is not None or max_keys is not None or name is not None:
- params = {}
- if marker is not None:
- params['marker'] = marker
- if max_keys is not None:
- params['maxKeys'] = max_keys
- if name is not None:
- params['name'] = name
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(keypair_id=(bytes, str))
- def get_keypair(self, keypair_id=None, config=None):
- """
- :param keypair_id:
- :param config:
- :return:
- """
- keypair_id = compat.convert_to_bytes(keypair_id)
- path = b'/keypair/%s' % keypair_id
- return self._send_request(http_methods.GET, path, config=config)
- @required(keypair_id=(bytes, str),
- instance_ids=list)
- def attach_keypair(self,
- keypair_id=None,
- instance_ids=None,
- config=None):
- """
- :param keypair_id:
- :param instance_ids:
- :param config:
- :return:
- """
- keypair_id = compat.convert_to_bytes(keypair_id)
- path = b'/keypair/%s' % keypair_id
- body = {
- 'instanceIds': instance_ids
- }
- params = {
- 'attach': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(keypair_id=(bytes, str),
- instance_id=list)
- def detach_keypair(self,
- keypair_id=None,
- instance_ids=None,
- config=None):
- """
- :param keypair_id:
- :param instance_ids:
- :param config:
- :return:
- """
- keypair_id = compat.convert_to_bytes(keypair_id)
- path = b'/keypair/%s' % keypair_id
- body = {
- 'instanceIds': instance_ids
- }
- params = {
- 'detach': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(keypair_id=(bytes, str))
- def delete_keypair(self,
- keypair_id=None,
- config=None):
- """
- :param keypair_id:
- :param config:
- :return:
- """
- keypair_id = compat.convert_to_bytes(keypair_id)
- path = b'/keypair/%s' % keypair_id
- return self._send_request(http_methods.DELETE, path, config=config)
- @required(keypair_id=(bytes, str),
- keypair_name=(bytes, str))
- def rename_keypair(self,
- keypair_id=None,
- keypair_name=None,
- config=None):
- """
- :param keypair_id:
- :param keypair_name:
- :param config:
- :return:
- """
- keypair_id = compat.convert_to_bytes(keypair_id)
- path = b'/keypair/%s' % keypair_id
- body = {
- 'name': keypair_name
- }
- params = {
- 'rename': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(keypair_id=(bytes, str),
- keypair_desc=(bytes, str))
- def update_keypair_desc(self,
- keypair_id=None,
- keypair_desc=None,
- config=None):
- """
- :param keypair_id:
- :param keypair_desc:
- :param config:
- :return:
- """
- keypair_id = compat.convert_to_bytes(keypair_id)
- path = b'/keypair/%s' % keypair_id
- body = {
- 'description': keypair_desc
- }
- params = {
- 'updateDesc': None
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(cluster_size_in_gb=int)
- def create_volume_cluster(self, cluster_size_in_gb, purchase_count=1, storage_type='hp1', cluster_name=None,
- paymentTiming='Prepaid', reservation_length=6, reservation_time_unit='month',
- renew_time_unit=None, renew_time=None, zone_name=None, uuid_flag=None,
- client_token=None, config=None):
- """
- create_volume_cluster.
- """
- path = b'/volume/cluster'
- params = {}
- if uuid_flag is not None:
- params['uuidFlag'] = uuid_flag
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- billing = bcc_model.Billing(paymentTiming=paymentTiming, reservationLength=reservation_length,
- reservationTimeUnit=reservation_time_unit)
- body = {
- 'clusterSizeInGB': cluster_size_in_gb,
- 'storageType': storage_type,
- 'purchaseCount': purchase_count,
- 'billing': billing.__dict__
- }
- if zone_name is not None:
- body['zoneName'] = zone_name
- if cluster_name is not None:
- body['clusterName'] = cluster_name
- if renew_time_unit is not None:
- body['renewTimeUnit'] = renew_time_unit
- if renew_time is not None:
- body['renewTime'] = renew_time
- return self._send_request(http_methods.POST, path, json.dumps(body), params=params, config=config)
- def list_volume_cluster(self, cluster_name=None, zone_name=None, marker=None, max_keys=None,
- config=None):
- """
- list_volume_cluster.
- """
- path = b'/volume/cluster'
- params = {}
- if cluster_name is not None:
- params['clusterName'] = cluster_name
- if zone_name is not None:
- params['zoneName'] = zone_name
- if marker is not None:
- params['marker'] = marker
- if max_keys is not None:
- params['maxKeys'] = max_keys
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(cluster_id=(bytes, str)) # ***Unicode***
- def get_volume_cluster(self, cluster_id, config=None):
- """
- Get cluster detail
- """
- cluster_id = compat.convert_to_bytes(cluster_id)
- path = b'/volume/cluster/%s' % cluster_id
- return self._send_request(http_methods.GET, path, config=config)
- @required(cluster_id=(bytes, str), # ***Unicode***
- new_cluster_size=int)
- def resize_volume_cluster(self, cluster_id, new_cluster_size, client_token=None, config=None):
- """
- resize_volume_cluster
- """
- cluster_id = compat.convert_to_bytes(cluster_id)
- path = b'/volume/cluster/%s' % cluster_id
- body = {
- 'newClusterSizeInGB': new_cluster_size
- }
- params = None
- if client_token is None:
- params = {
- 'resize': None,
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'resize': None,
- 'clientToken': client_token
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
- @required(cluster_id=(bytes, str)) # ***Unicode***
- def renew_volume_cluster(self, cluster_id, reservation_length=6, reservation_time_unit='month',
- client_token=None, config=None):
- """
- renew_volume_cluster
- """
- cluster_id = compat.convert_to_bytes(cluster_id)
- path = b'/volume/cluster/%s' % cluster_id
- billing = bcc_model.Billing(reservationLength=reservation_length,
- reservationTimeUnit=reservation_time_unit)
- body = {
- 'billing': billing.__dict__
- }
- params = None
- if client_token is None:
- params = {
- 'purchaseReserved': None,
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'purchaseReserved': None,
- 'clientToken': client_token
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- @required(cluster_id=(bytes, str)) # ***Unicode***
- def autoRenew_volume_cluster(self, cluster_id, renew_time=6, renew_time_unit='month',
- client_token=None, config=None):
- """
- autoRenew_volume_cluster
- """
- cluster_id = compat.convert_to_bytes(cluster_id)
- path = b'/volume/cluster/autoRenew'
- body = {
- 'clusterId': cluster_id,
- 'renewTimeUnit': renew_time_unit,
- 'renewTime': renew_time,
- }
- params = None
- if client_token is None:
- params = {
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'clientToken': client_token
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(cluster_id=(bytes, str)) # ***Unicode***
- def cancel_autoRenew_volume_cluster(self, cluster_id, client_token=None, config=None):
- """
- cancel_autoRenew_volume_cluster
- """
- cluster_id = compat.convert_to_bytes(cluster_id)
- path = b'/volume/cluster/cancelAutoRenew'
- body = {
- 'clusterId': cluster_id
- }
- params = None
- if client_token is None:
- params = {
- 'clientToken': generate_client_token()
- }
- else:
- params = {
- 'clientToken': client_token
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def list_recycled_instances(self, marker=None, max_keys=None, instance_id=None, name=None, payment_timing=None,
- recycle_begin=None, recycle_end=None, config=None):
- """
- Lists recycled instances.
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 1000.
- :type max_keys: int
- :param instance_id:
- The identified of instance to specifies one instance.
- :type instance_id: string
- :param name:
- The name of instance to specifies one instance.
- :type name: string
- :param payment_timing:
- The payment timing of instance order values: [prepay/postpay].
- :type payment_timing: string
- :param recycle_begin:
- The begintime of the recycled instances date range. FORMAT: yyyy-MM-dd'T'HH:mm:ss'Z'
- :type recycle_begin: string
- :param recycle_end:
- The endtime of the recycled instances date range. FORMAT: yyyy-MM-dd'T'HH:mm:ss'Z'
- :type recycle_end: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/recycle/instance'
- body = {}
- if marker is not None:
- body['marker'] = marker
- if max_keys is not None:
- body['maxKeys'] = max_keys
- if instance_id is not None:
- body['instanceId'] = instance_id
- if name is not None:
- body['name'] = name
- if payment_timing is not None:
- body['paymentTiming'] = payment_timing
- if recycle_begin is not None:
- body['recycleBegin'] = recycle_begin
- if recycle_end is not None:
- body['recycleEnd'] = recycle_end
- return self._send_request(http_methods.POST, path, body=json.dumps(body), config=config)
- @required(spec=str, image_id=(bytes, str)) # ***Unicode***
- def create_instance_by_spec(self, spec, image_id, root_disk_size_in_gb=0, root_disk_storage_type=None,
- ephemeral_disks=None, create_cds_list=None, network_capacity_in_mbps=0, eip_name=None,
- internet_charge_type=None, purchase_count=1, name=None, hostname=None,
- auto_seq_suffix=None, is_open_hostname_domain=None, admin_pass=None, billing=None,
- zone_name=None, subnet_id=None, security_group_id=None,
- enterprise_security_group_id=None, security_group_ids=None,
- enterprise_security_group_ids=None, relation_tag=None, ehc_cluster_id=None,
- is_open_ipv6=None, tags=None, key_pair_id=None, auto_renew_time_unit=None,
- auto_renew_time=0, cds_auto_renew=None, asp_id=None, bid_model=None, bid_price=None,
- dedicate_host_id=None, deploy_id=None, deploy_id_list=None, enable_jumbo_frame=None,
- cpu_thread_config=None, numa_config=None, eni_ids=None, client_token=None, config=None,
- user_data=None, spec_id=None, deletion_protection=None, is_open_hosteye=None,
- hosteye_type=None, res_group_id=None, enable_ht=None, data_partition_type=None,
- root_partition_type=None, file_systems=None, disable_root_disk_serial=None,
- internal_ips=None, network_purchase_type=None, is_keep_image_login=None,
- reserved_instance=None):
- """
- Create a bcc Instance with the specified options.
- You must fill the field of clientToken,which is especially for keeping idempotent.
- This is an asynchronous interface,
- you can get the latest status by BccClient.get_instance.
- :param spec:
- The specification of the BBC package.
- :type spec: string
- :param image_id:
- The id of image, list all available image in BccClient.list_images.
- :type image_id: string
- :param billing:
- Billing information.
- :type billing: bcc_model.Billing
- :param create_cds_list:
- The optional list of volume detail info to create.
- :type create_cds_list: list<bcc_model.CreateCdsModel>
- :param network_capacity_in_mbps:
- The optional parameter to specify the bandwidth in Mbps for the new instance.
- It must among 0 and 200, default value is 0.
- If it's specified to 0, it will get the internal ip address only.
- :type network_capacity_in_mbps: int
- :param eip_name:
- eip name
- :type eip_name: string
- :param purchase_count:
- The number of instance to buy, the default value is 1.
- :type purchase_count: int
- :param name:
- The optional parameter to desc the instance that will be created.
- :type name: string
- :param hostname:
- The optional parameter to specify the host name of the instance virtual machine.
- By default, hostname is not specified.
- If hostname is specified: hostname is used as the prefix of the name in batches.
- The backend will add a suffix, and the suffix generation method is: name{-serial number}.
- If name is not specified, it will be automatically generated using the following method:
- {instance-eight-digit random string-serial number}.
- Note: The random string is generated from the characters 0-9 and a-z;
- the serial number increases sequentially according to the magnitude of count.
- If count is 100, the serial number increases from 000~100, and if it is 10, it increases from 00~10.
- Only lowercase letters, numbers and - . special characters are supported.
- They must start with a letter. Special symbols cannot be used continuously.
- Special symbols are not supported at the beginning or end. The length is 2-64.
- :type hostname: string
- :param auto_seq_suffix:
- The parameter to specify whether name and hostname order suffixes are automatically generated.
- :type auto_seq_suffix: boolean
- :param is_open_hostname_domain:
- The parameter to specify whether hostname domain is automatically generated
- :type is_open_hostname_domain: boolean
- :param admin_pass:
- The optional parameter to specify the password for the instance.
- If specify the adminPass,the adminPass must be a 8-16 characters String
- which must contains letters, numbers and symbols.
- The symbols only contains "!@#$%^*()".
- The adminPass will be encrypted in AES-128 algorithm
- with the substring of the former 16 characters of user SecretKey.
- If not specify the adminPass, it will be specified by an random string.
- See more detail on
- https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
- :type admin_pass: string
- :param zone_name:
- The optional parameter to specify the available zone for the instance.
- See more detail through list_zones method
- :type zone_name: string
- :param subnet_id:
- The optional parameter to specify the id of subnet from vpc, optional param
- default value is default subnet from default vpc
- :type subnet_id: string
- :param security_group_id:
- The optional parameter to specify the securityGroupId of the instance
- vpcId of the securityGroupId must be the same as the vpcId of subnetId
- See more detail through listSecurityGroups method
- :type security_group_id: string
- :param enterprise_security_group_id:
- enterprise_security_group_id
- :type enterprise_security_group_id: string
- :param security_group_ids:
- security_group_ids
- :type security_group_ids: list<string>
- :param enterprise_security_group_ids:
- enterprise_security_group_ids
- :type enterprise_security_group_ids: list<string>
- :param relation_tag:
- The parameter to specify whether the instance related to existing tags
- :type relation_tag: boolean
- :param ehc_cluster_id:
- The id of ehcCluster.
- :type ehc_cluster_id: string
- :param is_open_ipv6:
- The parameter indicates whether the instance to be created is enabled for IPv6.
- It can only be enabled when both the image and subnet support IPv6.
- True indicates enabled, false indicates disabled,
- and no transmission indicates automatic adaptation of the image and subnet's IPv6 support
- :type is_open_ipv6: boolean
- :param deploy_id_list:
- This parameter is the list of deployment set IDs where the specified instance is located.
- :type deploy_id_list: list<string>
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :param root_disk_size_in_gb:
- The parameter to specify the root disk size in GB.
- The root disk excludes the system disk, available is 40-500GB.
- :type root_disk_size_in_gb: int
- :param root_disk_storage_type:
- The parameter to specify the root disk storage type.
- Default use of HP1 cloud disk.
- :type root_disk_storage_type: string
- :param ephemeral_disks:
- The optional list of ephemeral volume detail info to create.
- :type ephemeral_disks: list<bcc_model.EphemeralDisk>
- :param dedicate_host_id
- The parameter to specify the dedicate host id.
- :type dedicate_host_id: string
- :param auto_renew_time_unit
- The parameter to specify the unit of the auto renew time.
- The auto renew time unit can be "month" or "year".
- The default value is "month".
- :type auto_renew_time_unit: string
- :param auto_renew_time
- The parameter to specify the auto renew time, the default value is 0.
- :type auto_renew_time: int
- :param tags
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :param deploy_id
- The parameter to specify the id of the deploymentSet.
- :type deploy_id: string
- :param bid_model
- The parameter to specify the bidding model.
- The bidding model can be "market" or "custom".
- :type bid_model: string
- :param bid_price
- The parameter to specify the bidding price.
- When the bid_model is "custom", it works.
- :type bid_price: string
- :param key_pair_id
- The parameter to specify id of the keypair.
- :type key_pair_id: string
- :param asp_id
- The parameter to specify id of the asp.
- :type asp_id: string
- :param internet_charge_type
- The parameter to specify the internet charge type.
- See more detail on
- https://cloud.baidu.com/doc/BCC/API.html#InternetChargeType
- :type internet_charge_type: string
- :param cds_auto_renew
- The parameter to specify whether the cds is auto renew or not.
- The default value is false.
- :type cds_auto_renew: boolean
- :param enable_jumbo_frame:
- The parameter indicates whether the instance is enabled for JumboFrame.
- It can only be enabled when the flavor support JumboFrame.
- True indicates enabled, false indicates disabled,
- :type enable_jumbo_frame: bool
- :param cpu_thread_config:
- Manage hyper - threading, which is the same on both Intel and AMD platforms.
- :type cpu_thread_config: string
- :param numa_config:
- Manage NPS on AMD platforms. Manage NUMA on Intel platforms.
- :type numa_config: string
- :param eni_ids:
- The optional list of eni short ids to attach.
- The number of eniIds must be an integer multiple of the number of instances.
- The enis must in the same vpc and available zone with instance.
- :type eni_ids: list<string>
- :param user_data:
- :type user_data: string
- :param is_open_hosteye:
- :type is_open_hosteye: boolean
- :param hosteye_type:
- :type hosteye_type: string
- :param res_group_id:
- The optional parameter to specify the resGroupId of the instance
- :type res_group_id: string
- :param enable_ht:
- Whether to enable HT (used by EBC). Default: true
- :type enable_ht: bool
- :param data_partition_type:
- Data disk file system format.Available values: xfs, ext4.
- :type data_partition_type: bool
- :param root_partition_type:
- System disk file system format.Available values: xfs, ext4.
- :type root_partition_type: bool
- :param deletion_protection:
- :type deletion_protection: int
- :param spec_id:
- Identify of the spec.
- :param file_systems:
- This parameter is obsolete.
- :type file_systems:list<bcc_model.FileSystemModel>
- :param disable_root_disk_serial:
- Whether to hide the system disk SN during instance creation. Default: false
- :type disable_root_disk_serial: bool
- :param internal_ips:
- The parameter to specify the internal ips.
- :type internal_ips: list<string>
- :param network_purchase_type:
- EIP line type, including Standard BGP (BGP) and Enhanced BGP (BGP_S).The default value is Standard BGP.
- :type network_purchase_type: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instanceBySpec'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- if billing is None:
- billing = default_billing_to_purchase_created
- body = {
- 'spec': spec,
- 'imageId': image_id,
- 'billing': billing.__dict__
- }
- if root_disk_size_in_gb != 0:
- body['rootDiskSizeInGb'] = root_disk_size_in_gb
- if root_disk_storage_type is not None:
- body['rootDiskStorageType'] = root_disk_storage_type
- if create_cds_list is not None:
- body['createCdsList'] = [create_cds.__dict__ for create_cds in create_cds_list]
- if network_capacity_in_mbps != 0:
- body['networkCapacityInMbps'] = network_capacity_in_mbps
- if eip_name is not None:
- body['eipName'] = eip_name
- if purchase_count > 0:
- body['purchaseCount'] = purchase_count
- if name is not None:
- body['name'] = name
- if hostname is not None:
- body['hostname'] = hostname
- if auto_seq_suffix is not None:
- body['autoSeqSuffix'] = auto_seq_suffix
- if is_open_hostname_domain is not None:
- body['isOpenHostnameDomain'] = is_open_hostname_domain
- if admin_pass is not None:
- secret_access_key = self.config.credentials.secret_access_key
- cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
- body['adminPass'] = cipher_admin_pass
- if zone_name is not None:
- body['zoneName'] = zone_name
- if subnet_id is not None:
- body['subnetId'] = subnet_id
- if security_group_id is not None:
- body['securityGroupId'] = security_group_id
- if enterprise_security_group_id is not None:
- body['enterpriseSecurityGroupId'] = enterprise_security_group_id
- if security_group_ids is not None:
- body['securityGroupIds'] = security_group_ids
- if enterprise_security_group_ids is not None:
- body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
- if auto_renew_time != 0:
- body['autoRenewTime'] = auto_renew_time
- if auto_renew_time_unit is None:
- body['autoRenewTimeUnit'] = "month"
- else:
- body['autoRenewTimeUnit'] = auto_renew_time_unit
- if ephemeral_disks is not None:
- body['ephemeralDisks'] = [ephemeral_disk.__dict__ for ephemeral_disk in ephemeral_disks]
- if dedicate_host_id is not None:
- body['dedicatedHostId'] = dedicate_host_id
- if deploy_id is not None:
- body['deployId'] = deploy_id
- if deploy_id_list is not None:
- body['deployIdList'] = deploy_id_list
- if bid_model is not None:
- body['bidModel'] = bid_model
- if bid_price is not None:
- body['bidPrice'] = bid_price
- if key_pair_id is not None:
- body['keypairId'] = key_pair_id
- if internet_charge_type is not None:
- body['internetChargeType'] = internet_charge_type
- if asp_id is not None:
- body['aspId'] = asp_id
- if relation_tag is not None:
- body['relationTag'] = relation_tag
- if ehc_cluster_id is not None:
- body['ehcClusterId'] = ehc_cluster_id
- if is_open_ipv6 is not None:
- body['isOpenIpv6'] = is_open_ipv6
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['tags'] = tag_list
- if enable_jumbo_frame is not None:
- body['enableJumboFrame'] = enable_jumbo_frame
- if cpu_thread_config is not None:
- body['cpuThreadConfig'] = cpu_thread_config
- if numa_config is not None:
- body['numaConfig'] = numa_config
- if eni_ids is not None:
- body['eniIds'] = eni_ids
- body['cdsAutoRenew'] = cds_auto_renew
- if user_data is not None:
- body['userData'] = user_data
- if spec_id is not None:
- body['specId'] = spec_id
- if is_open_hosteye is not None:
- body['isOpenHosteye'] = is_open_hosteye
- if deletion_protection is not None:
- body['deletionProtection'] = deletion_protection
- if hosteye_type is not None:
- body['hosteyeType'] = hosteye_type
- if res_group_id is not None:
- body['resGroupId'] = res_group_id
- if enable_ht is not None:
- body['enableHt'] = enable_ht
- if data_partition_type is not None:
- body['dataPartitionType'] = data_partition_type
- if root_partition_type is not None:
- body['rootPartitionType'] = root_partition_type
- if file_systems is not None:
- file_system_list = [file_system.__dict__ for file_system in file_systems]
- body['fileSystems'] = file_system_list
- if disable_root_disk_serial is not None:
- body['disableRootDiskSerial'] = disable_root_disk_serial
- if internal_ips is not None:
- body['internalIps'] = internal_ips
- if network_purchase_type is not None:
- body['networkPurchaseType'] = network_purchase_type
- if is_keep_image_login is not None:
- body['keepImageLogin'] = is_keep_image_login
- if reserved_instance is not None:
- body['reservedInstance'] = reserved_instance
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(instance_id=(bytes, str))
- def auto_release_instance(self, instance_id, release_time=None, client_token=None, config=None):
- """
- set instance auto release.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param release_time:
- The new value for instance's name.
- :type release_time: string in format yyyy-MM-dd'T'HH:mm:ss'Z'.
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {
- 'autorelease': None,
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- instance_id = compat.convert_to_bytes(instance_id)
- # instance_id = instance_id.encode(encoding='utf-8')
- path = b'/instance/%s' % instance_id
- body = {
- 'releaseTime': release_time
- }
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- @required(instance_id=(bytes, str)) # ***Unicode***
- def release_instance_with_related_resources(self, instance_id, related_release_flag=None,
- delete_cds_snapshot_flag=None, delete_related_enis_flag=None,
- bcc_recycle_flag=None, cds_attribute_active=None,
- client_token=None, config=None):
- """
- Releasing the instance owned by the user.
- Only the Postpaid instance or Prepaid which is expired can be released.
- After releasing the instance,
- all of the data will be deleted.
- all of volumes attached will be auto detached, but the volume snapshots will be saved.
- all of snapshots created from original instance system disk will be deleted,
- all of customized images created from original instance system disk will be reserved.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param related_release_flag:
- Release or not related resources.
- :type related_release_flag: bool
- :param delete_cds_snapshot_flag:
- Delete or not cds snapshot.
- :type delete_cds_snapshot_flag: bool
- :param delete_related_enis_flag:
- Delete or not related enis.
- :type delete_related_enis_flag: bool
- :param bcc_recycle_flag:
- Recycle or not bcc instance.
- :type bcc_recycle_flag: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- body = {}
- if related_release_flag is not None:
- body['relatedReleaseFlag'] = related_release_flag
- if delete_cds_snapshot_flag is not None:
- body['deleteCdsSnapshotFlag'] = delete_cds_snapshot_flag
- if delete_related_enis_flag is not None:
- body['deleteRelatedEnisFlag'] = delete_related_enis_flag
- if bcc_recycle_flag is not None:
- body['bccRecycleFlag'] = bcc_recycle_flag
- if bcc_recycle_flag is not None:
- body['cdsAttributeActive'] = cds_attribute_active
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- @required(instance_id=(bytes, str)) # ***Unicode***
- def release_prepaid_instance_with_related_resources(self, instance_id, related_release_flag=None,
- delete_cds_snapshot_flag=None, delete_related_enis_flag=None,
- client_token=None, config=None):
- """
- Releasing the instance owned by the user.
- Only the Prepaid instance and the instance has not expired can be released.
- After releasing the instance,
- all of the data will be deleted.
- all of volumes attached will be auto detached, but the volume snapshots will be saved.
- all of snapshots created from original instance system disk will be deleted,
- all of customized images created from original instance system disk will be reserved.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param related_release_flag:
- Release or not related resources.
- :type related_release_flag: bool
- :param delete_cds_snapshot_flag:
- Delete or not cds snapshot.
- :type delete_cds_snapshot_flag: bool
- :param delete_related_enis_flag:
- Delete or not related enis.
- :type delete_related_enis_flag: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- path = b'/instance/delete'
- body = {}
- body['instanceId'] = instance_id
- if related_release_flag is not None:
- body['relatedReleaseFlag'] = related_release_flag
- if delete_cds_snapshot_flag is not None:
- body['deleteCdsSnapshotFlag'] = delete_cds_snapshot_flag
- if delete_related_enis_flag is not None:
- body['deleteRelatedEnisFlag'] = delete_related_enis_flag
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- @required(instance_id=(bytes, str)) # ***Unicode***
- def get_instance_with_deploy_set(self, instance_id, contains_failed=None, config=None):
- """
- Get the detail information of specified instance.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param contains_failed:
- The optional parameters to get the failed message.If true, it means get the failed message.
- :type contains_failed: boolean
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = instance_id.encode(encoding='utf-8')
- path = b'/instance/%s' % instance_id
- params = {
- 'isDeploySet': True
- }
- if contains_failed:
- params['containsFailed'] = contains_failed
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(instance_id=(bytes, str)) # ***Unicode***
- def get_instance_with_deploy_set_and_failed(self, instance_id, contains_failed=None, config=None):
- """
- Get the detail information of specified instance.
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param contains_failed:
- The optional parameters to get the failed message.If true, it means get the failed message.
- :type contains_failed: boolean
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = instance_id.encode(encoding='utf-8')
- path = b'/instance/%s' % instance_id
- params = {
- 'containsFailed': None
- }
- if contains_failed:
- params['containsFailed'] = contains_failed
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(instance_id=(bytes, str), hostname=str) # ***Unicode***
- def modify_instance_hostname(self, instance_id, hostname, reboot=None, is_open_hostname_domain=None,
- client_token=None, config=None):
- """
- modify instance hostname
- :param instance_id:
- The id of instance.
- :type instance_id: string
- :param hostname:
- new hostname
- :type hostname: string, FORMAT ^([a-z]+)((\.|-)?[a-z0-9]+)*$
- :param reboot:
- Auto reboot the instance after hostname changed.
- :type reboot: bool
- :param is_open_hostname_domain:
- Set hostname domain opening
- :type is_open_hostname_domain: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {
- "changeHostname": None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- instance_id = compat.convert_to_bytes(instance_id)
- path = b'/instance/%s' % instance_id
- body = {
- "hostname": hostname
- }
- if reboot is not None:
- body['reboot'] = reboot
- if is_open_hostname_domain is not None:
- body['isOpenHostnameDomain'] = is_open_hostname_domain
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- @required(instance_id_list=(list)) # ***Unicode***
- def recovery_instances(self, instance_id_list, client_token=None, config=None):
- """
- Recovery multi instances
- :param instance_id_list:
- The id list of instances to recovery.
- :type instance_id_list: list of string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- path = b'/instance/recovery'
- list_of_item = []
- for instance_id in instance_id_list:
- list_of_item.append({'instanceId': instance_id})
- body = {
- "instanceIds": list_of_item
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- @required(instance_ids=(list))
- def batch_refund_resources(self, instance_ids, related_release_flag=None,
- delete_cds_snapshot_flag=None, delete_related_enis_flag=None,
- client_token=None, config=None):
- """
- Releasing the instance owned by the user.
- Only the Prepaid instance and the instance has not expired can be released.
- After releasing the instance, all of the data will be deleted.
- :param instance_ids:
- The id list of instances.
- :type instance_ids: list of string
- :param related_release_flag:
- Release or not related resources.
- :type related_release_flag: bool
- :param delete_cds_snapshot_flag:
- Delete or not cds snapshot.
- :type delete_cds_snapshot_flag: bool
- :param delete_related_enis_flag:
- Delete or not related enis.
- :type delete_related_enis_flag: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- path = b'/instance/batchRefundResource'
- body = {
- "instanceIds": instance_ids
- }
- if related_release_flag is not None:
- body['relatedReleaseFlag'] = related_release_flag
- if delete_cds_snapshot_flag is not None:
- body['deleteCdsSnapshotFlag'] = delete_cds_snapshot_flag
- if delete_related_enis_flag is not None:
- body['deleteRelatedEnisFlag'] = delete_related_enis_flag
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- @required(instance_type=str, cpu_count=int, memory_cap_in_gb=int) # ***Unicode***
- def get_bid_instance_price(self, instance_type, cpu_count, memory_cap_in_gb,
- root_disk_size_in_gb=None, root_disk_storage_type=None, create_cds_list=None,
- purchase_count=1, name=None, admin_pass=None, key_pair_id=None, asp_id=None,
- image_id=None, bid_model=None, bid_price=None, network_cap_in_mbps=None,
- relation_tag=None, tags=None, security_group_id=None, subnet_id=None,
- zone_name=None, internet_charge_type=None, client_token=None, config=None):
- """
- Query bid instance price in market.
- :param instance_type:
- The specified Specification to create the instance,
- See more detail on
- https://cloud.baidu.com/doc/BCC/API.html#InstanceType
- :type instance_type: string
- :param cpu_count:
- The parameter to specified the cpu core to create the instance.
- :type cpu_count: int
- :param memory_cap_in_gb:
- The parameter to specified the capacity of memory in GB to create the instance.
- :type memory_cap_in_gb: int
- :param image_id:
- The id of image, list all available image in BccClient.list_images.
- :type image_id: string
- :param create_cds_list:
- The optional list of volume detail info to create.
- :type create_cds_list: list<bcc_model.CreateCdsModel>
- :param network_cap_in_mbps:
- The optional parameter to specify the bandwidth in Mbps for the new instance.
- It must among 0 and 200, default value is 0.
- If it's specified to 0, it will get the internal ip address only.
- :type network_cap_in_mbps: int
- :param purchase_count:
- The number of instance to buy, the default value is 1.
- :type purchase_count: int
- :param name:
- The optional parameter to desc the instance that will be created.
- :type name: string
- :param admin_pass:
- The optional parameter to specify the password for the instance.
- If specify the adminPass,the adminPass must be a 8-16 characters String
- which must contains letters, numbers and symbols.
- The symbols only contains "!@#$%^*()".
- The adminPass will be encrypted in AES-128 algorithm
- with the substring of the former 16 characters of user SecretKey.
- If not specify the adminPass, it will be specified by an random string.
- See more detail on
- https://bce.baidu.com/doc/BCC/API.html#.7A.E6.31.D8.94.C1.A1.C2.1A.8D.92.ED.7F.60.7D.AF
- :type admin_pass: string
- :param zone_name:
- The optional parameter to specify the available zone for the instance.
- See more detail through list_zones method
- :type zone_name: string
- :param subnet_id:
- The optional parameter to specify the id of subnet from vpc, optional param
- default value is default subnet from default vpc
- :type subnet_id: string
- :param security_group_id:
- The optional parameter to specify the securityGroupId of the instance
- vpcId of the securityGroupId must be the same as the vpcId of subnetId
- See more detail through listSecurityGroups method
- :type security_group_id: string
- :param client_token:
- An ASCII string whose length is less than 64.
- The request will be idempotent if client token is provided.
- If the clientToken is not specified by the user,
- a random String generated by default algorithm will be used.
- See more detail at
- https://bce.baidu.com/doc/BCC/API.html#.E5.B9.82.E7.AD.89.E6.80.A7
- :type client_token: string
- :param root_disk_size_in_gb:
- The parameter to specify the root disk size in GB.
- The root disk excludes the system disk, available is 40-500GB.
- :type root_disk_size_in_gb: int
- :param root_disk_storage_type:
- The parameter to specify the root disk storage type.
- Default use of HP1 cloud disk.
- :type root_disk_storage_type: string
- :param relation_tag
- Set whether the tags specified by the instance to ne queried needs
- to be associated with an existing tag key.
- The default value is false, this param is optional.
- :type relation_tag: bool
- :param tags
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :param bid_model
- The parameter to specify the bidding model.
- The bidding model can be "market" or "custom".
- :type bid_model: string
- :param bid_price
- The parameter to specify the bidding price.
- When the bid_model is "custom", it works.
- :type bid_price: string
- :param key_pair_id
- The parameter to specify id of the keypair.
- :type key_pair_id: string
- :param asp_id
- The parameter to specify id of the asp.
- :type asp_id: string
- :param internet_charge_type
- The parameter to specify the internet charge type.
- See more detail on
- https://cloud.baidu.com/doc/BCC/API.html#InternetChargeType
- :type internet_charge_type: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/bidPrice'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'cpuCount': cpu_count,
- 'memoryCapacityInGB': memory_cap_in_gb,
- 'instanceType': instance_type
- }
- if image_id is not None:
- body['imageId'] = image_id
- if root_disk_size_in_gb != 0:
- body['rootDiskSizeInGb'] = root_disk_size_in_gb
- if root_disk_storage_type is not None:
- body['rootDiskStorageType'] = root_disk_storage_type
- if create_cds_list is not None:
- body['createCdsList'] = [create_cds.__dict__ for create_cds in create_cds_list]
- if purchase_count > 0:
- body['purchaseCount'] = purchase_count
- if name is not None:
- body['name'] = name
- if admin_pass is not None:
- secret_access_key = self.config.credentials.secret_access_key
- cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
- body['adminPass'] = cipher_admin_pass
- if zone_name is not None:
- body['zoneName'] = zone_name
- if subnet_id is not None:
- body['subnetId'] = subnet_id
- if security_group_id is not None:
- body['securityGroupId'] = security_group_id
- if bid_model is not None:
- body['bidModel'] = bid_model
- if bid_price is not None:
- body['bidPrice'] = bid_price
- if key_pair_id is not None:
- body['keypairId'] = key_pair_id
- if internet_charge_type is not None:
- body['internetChargeType'] = internet_charge_type
- if asp_id is not None:
- body['aspId'] = asp_id
- if relation_tag is not None:
- body['relationTag'] = relation_tag
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['tags'] = tag_list
- if network_cap_in_mbps is not None:
- body['networkCapacityInMbps'] = network_cap_in_mbps
- return self._send_request(http_methods.POST, path, json.dumps(body), params=params, config=config)
- def list_bid_flavor(self, client_token=None, config=None):
- """
- Get all bid flavors.
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- path = b'/instance/bidFlavor'
- return self._send_request(http_methods.POST, path, params=params, config=config)
- @required(instance_id=(bytes, str), deletion_protection=int)
- def modify_deletion_protection(self, instance_id, deletion_protection, client_token=None, config=None):
- """
- Set instance deleion protection.
- :param instance_id
- The id of instance.
- :type instance_id: string
- :param deletion_protection
- The status of instance deletion protection. 1:enable, 0:disable.
- :type deletion_protection: int
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- instance_id = instance_id.encode(encoding='utf-8')
- path = b'/instance/%s/deletionProtection' % instance_id
- body = {
- "deletionProtection": deletion_protection
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
- @required(instance_id=(bytes, str), is_eip_auto_related_delete=bool)
- def modify_related_delete_policy(self, instance_id, is_eip_auto_related_delete, client_token=None, config=None):
- """
- Set bid instance eip_auto_related_delete.
- :param instance_id
- The id of instance.
- :type instance_id: string
- :param is_eip_auto_related_delete
- Enables the deletion of the related EIP of bid instance when the instance is being deleted.
- :type is_eip_auto_related_delete: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- instance_id = instance_id.encode(encoding='utf-8')
- path = b'/instance/%s/modifyRelatedDeletePolicy' % instance_id
- body = {
- "isEipAutoRelatedDelete": is_eip_auto_related_delete
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
- @required(volume_id=(bytes, str)) # ***Unicode***
- def release_volume_new(self, volume_id, auto_snapshot=None, manual_snapshot=None,
- recycle=None, client_token=None, config=None):
- """
- Releasing the specified volume owned by the user.
- You can release the specified volume only
- when the instance is among state of Available/Expired/Error,
- otherwise, it's will get 409 errorCode.
- :param volume_id:
- The id of the volume which will be released.
- :type volume_id: string
- :param auto_snapshot:
- Snapshot volume automatically. value: 'on'/'off'. Default value: 'off'.
- :type auto_snapshot: string
- :param manual_snapshot:
- Snapshot volume manually. value: 'on'/'off'. Default value: 'off'.
- :type manual_snapshot: string
- :param recycle:
- where recycle volume or not, value: 'on'/'off'. Default value: 'on'.
- :type recycle: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- volume_id = volume_id.encode(encoding='utf-8')
- path = b'/volume/%s' % volume_id
- body = {}
- if auto_snapshot is not None:
- body['autoSnapshot'] = auto_snapshot
- if manual_snapshot is not None:
- body['manualSnapshot'] = manual_snapshot
- if recycle is not None:
- body['recycle'] = recycle
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- @required(volume_id=str, renew_time=int, renew_time_unit=str) # ***Unicode***
- def auto_renew_cds_volume(self, volume_id, renew_time, renew_time_unit, client_token=None, config=None):
- """
- set auto_renew_cds_volume
- :param volume_id:
- The id of the volume which will be renewed.
- :type volume_id: string
- :param renew_time:
- Auto renew start time.
- Value:
- - month: 1 ~ 9
- - year: 1 ~ 3
- :type renew_time: string
- :param renew_time_unit:
- Choose automatic monthly or annual renewals. value: 'month'/'year'
- :type renew_time_unit: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- path = b'/volume/autoRenew'
- body = {
- 'volumeId': volume_id,
- 'renewTime': renew_time,
- 'renewTimeUnit': renew_time_unit
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- @required(volume_id=str) # ***Unicode***
- def cancel_auto_renew_cds_volume(self, volume_id, client_token=None, config=None):
- """
- cancel_auto_renew_volume_cluster
- :param volume_id:
- The id of the volume which will be renewed.
- :type volume_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/volume/cancelAutoRenew'
- body = {
- 'volumeId': volume_id
- }
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- @required(zone_name=str) # ***Unicode***
- def get_available_disk_info(self, zone_name, client_token=None, config=None):
- """
- get_available_disk_info
- :param zone_name:
- The name of available zone for volume to use.
- :type zone_name: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/volume/disk'
- params = {
- 'zoneName': zone_name
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(volume_id=str) # ***Unicode***
- def tag_volume(self, volume_id, relation_tag=None, tags=None, client_token=None, config=None):
- """
- bind tags to volume
- :param volume_id:
- The id of the volume which will be renewed.
- :type volume_id: string
- :param tags
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {
- 'bind': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- volume_id = volume_id.encode(encoding='utf-8')
- path = b'/volume/%s/tag' % volume_id
- body = {}
- if relation_tag is not None:
- body['relationTag'] = relation_tag
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['changeTags'] = tag_list
- return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
- @required(volume_id=str) # ***Unicode***
- def untag_volume(self, volume_id, relation_tag=None, tags=None, client_token=None, config=None):
- """
- unbind tags to volume
- :param volume_id:
- The id of the volume which will be renewed.
- :type volume_id: string
- :param tags
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {
- 'unbind': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- volume_id = volume_id.encode(encoding='utf-8')
- path = b'/volume/%s/tag' % volume_id
- body = {}
- if relation_tag is not None:
- body['relationTag'] = relation_tag
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['changeTags'] = tag_list
- return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
- @required(volume_id=str) # ***Unicode***
- def list_snapshot_chain(self, volume_id, order=None, order_by=None,
- page_no=None, page_size=None, client_token=None, config=None):
- """
- list_snapshot_chain
- :param volume_id:
- The id of the volume which will be renewed.
- :type volume_id: string
- :param order
- The response list order. Value: asc/desc
- :type order: string
- :param order_by
- The response list order. Value: chainId(default)/chainSize/volumeSize
- :type order_by: string
- :param page_no
- page number. default value = 1
- :type page_no: int
- :param page_size
- page size. default value = 1000
- :type page_size: int
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/snapshot/chain'
- params = {
- 'volumeId': volume_id
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- if order is not None:
- params['order'] = order
- if order_by is not None:
- params['orderBy'] = order_by
- if page_no is not None:
- params['pageNo'] = page_no
- if page_size is not None:
- params['pageSize'] = page_size
- return self._send_request(http_methods.GET, path, params=params, config=config)
- @required(chain_id=str) # ***Unicode***
- def tag_snapshot_chain(self, chain_id, tags=None, client_token=None, config=None):
- """
- bind tags to snapshot chain
- :param chain_id:
- The id of the volume which will be renewed.
- :type chain_id: string
- :param tags
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {
- 'bind': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- chain_id = chain_id.encode(encoding='utf-8')
- path = b'/snapshot/chain/%s/tag' % chain_id
- body = {}
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['changeTags'] = tag_list
- return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
- @required(chain_id=str) # ***Unicode***
- def untag_snapshot_chain(self, chain_id, tags=None, client_token=None, config=None):
- """
- unbind tags to snapshot chain
- :param chain_id:
- The id of the volume which will be renewed.
- :type chain_id: string
- :param tags
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- params = {
- 'unbind': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- chain_id = chain_id.encode(encoding='utf-8')
- path = b'/snapshot/chain/%s/tag' % chain_id
- body = {}
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['changeTags'] = tag_list
- return self._send_request(http_methods.PUT, path, json.dumps(body), params=params, config=config)
- def update_asp(self, name=None, asp_id=None, time_points=None, repeat_week_days=None, retention_days=None,
- client_token=None, config=None):
- """
- update asp
- Attention: Param name and asp_id can not both be none.
- :param name:
- The name of the asp.
- :type name: string
- :param asp_id:
- Identify of asp.
- :type asp_id: string
- :param time_points:
- Daily triggering time(hour of day, 0 ~ 23) of snapshot policy. e.g. [0, 6, 12, 18].
- :type time_points: list
- :param repeat_week_days:
- Weekly triggering time(day of week, 0 ~ 6, 0 means Sunday) of snapshot policy. e.g. [1, 3]
- :type repeat_week_days: list
- :param retention_days:
- Retention days of snapshot.
- :type retention_days: int
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/asp/update'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {}
- if name is not None:
- body['name'] = name
- if asp_id is not None:
- body['aspId'] = asp_id
- if time_points is not None:
- body['timePoints'] = time_points
- if repeat_week_days is not None:
- body['repeatWeekdays'] = repeat_week_days
- if retention_days is not None:
- body['retentionDays'] = retention_days
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- def get_price_by_spec(self, spec_id=None, spec=None, payment_timing=None, zone_name=None, purchase_num=None,
- purchase_length=None, client_token=None, config=None):
- """
- Get price of instance flover by spec.
- Attention: Param spec_id and spec can not both be none.
- :param spec_id:
- Identify of the spec.
- :type spec_id: string
- :param spec:
- The name of spec.
- :type spec: string
- :param payment_timing:
- Payment timing of instance, prepay or postpay.
- :type payment_timing: string
- :param zone_name:
- Name of available zone.
- :type zone_name: string
- :param purchase_num:
- Number of purchase.
- :type purchase_num: int
- :param purchase_length:
- Reservation time.
- :type purchase_length: int
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/price'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {}
- if spec_id is not None:
- body['specId'] = spec_id
- if spec is not None:
- body['spec'] = spec
- if payment_timing is not None:
- body['paymentTiming'] = payment_timing
- if zone_name is not None:
- body['zoneName'] = zone_name
- if purchase_num is not None:
- body['purchaseCount'] = purchase_num
- if purchase_length is not None:
- body['purchaseLength'] = purchase_length
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def list_type_zones(self, spec_id=None, spec=None, product_type=None, instance_type=None,
- client_token=None, config=None):
- """
- list the logicalZone from the bcc package specification.
- :param spec_id:
- Identify of the spec.
- :type spec_id: string
- :param spec:
- The name of spec.
- :type spec: string
- :param product_type:
- Payment timing of instance, prepay or postpay.
- :type product_type: string
- :param instance_type:
- The specified Specification to create the instance,
- See more detail on
- https://cloud.baidu.com/doc/BCC/API.html#InstanceType
- :type instance_type: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/flavorZones'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- if spec_id is not None:
- params['specId'] = spec_id
- if spec is not None:
- params['spec'] = spec
- if product_type is not None:
- params['productType'] = product_type
- if instance_type is not None:
- params['instanceType'] = instance_type
- return self._send_request(http_methods.GET, path, prefix=b"/v1", params=params, config=config)
- def instance_change_subnet(self, instance_id, subnet_id=None,
- internal_ip=None, reboot=None,
- security_group_ids=None, enterprise_security_group_ids=None,
- client_token=None, config=None):
- """
- Change instance subnet by id.
- :param instance_id:
- Identify of the instance.
- :type instance_id: string
- :param subnet_id:
- New subnet id.
- :type subnet_id: string
- :param internal_ip:
- Ip address of internal network.
- :type internal_ip: string
- :param reboot:
- Reboot instance or not. Default value is False.
- :type reboot: bool
- :param security_group_ids:
- :type security_group_ids: list<string>
- :param enterprise_security_group_ids:
- :type enterprise_security_group_ids: list<string>
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/subnet/changeSubnet'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {}
- if instance_id is not None:
- body['instanceId'] = instance_id
- if subnet_id is not None:
- body['subnetId'] = subnet_id
- if internal_ip is not None:
- body['internalIp'] = internal_ip
- if reboot is not None:
- body['reboot'] = reboot
- if security_group_ids is not None:
- body['securityGroupIds'] = security_group_ids
- if enterprise_security_group_ids is not None:
- body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- def instance_change_vpc(self, instance_id, subnet_id=None,
- internal_ip=None, reboot=None, security_group_ids=None, enterprise_security_group_ids=None,
- client_token=None, config=None):
- """
- Change instance vpc by id.
- :param instance_id:
- Identify of the instance.
- :type instance_id: string
- :param subnet_id:
- New subnet id.
- :type subnet_id: string
- :param internal_ip:
- Ip address of internal network.
- :type internal_ip: string
- :param reboot:
- Reboot instance or not. Default value is False.
- :type reboot: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/vpc/changeVpc'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {}
- if instance_id is not None:
- body['instanceId'] = instance_id
- if subnet_id is not None:
- body['subnetId'] = subnet_id
- if internal_ip is not None:
- body['internalIp'] = internal_ip
- if reboot is not None:
- body['reboot'] = reboot
- if security_group_ids is not None:
- body['securityGroupIds'] = security_group_ids
- if enterprise_security_group_ids is not None:
- body['enterpriseSecurityGroupIds'] = enterprise_security_group_ids
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- @required(chain_id=str) # ***Unicode***
- def list_instance_enis(self, instance_id, client_token=None, config=None):
- """
- Change instance vpc by id.
- :param instance_id:
- Identify of the instance.
- :type instance_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = instance_id.encode(encoding='utf-8')
- path = b'/eni/%s' % instance_id
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- return self._send_request(http_methods.GET, path, params=params, config=config)
- def list_flavor_spec(self, zone_name=None, client_token=None, config=None):
- """
- Change instance vpc by id.
- :param zone_name:
- Available zone name
- :type zone_name: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/flavorSpec'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- if zone_name is not None:
- params['zoneName'] = zone_name
- return self._send_request(http_methods.GET, path, params=params, config=config)
- def resize_instance_by_spec(self, instance_id, spec, enable_jumbo_frame=None, client_token=None, config=None):
- """
- Resize instance by spec.
- :param instance_id:
- Identify of the instance.
- :type instance_id: string
- :param spec:
- The name of spec.
- :type spec: string
- :param enable_jumbo_frame:
- The parameter of specified the instance enable/disable jumbo frame.
- True means enable jumbo frame, false means disable jumbo frame.
- enable_jumbo_frame default None which means:
- When you change to the spec which doesn't support jumbo frame, the jumbo frame will be disabled.
- When the original instance don't support jumbo frame and you change to the spec which support jumbo frame,
- the jumbo frame will be disabled.
- When the original spec of the instance support jumbo frame , then you change to the spec which support jumbo
- frame, if the original instance enable jumbo frame, the jumbo frame will be enabled, if the original instance
- disable jumbo frame, the jumbo frame will be disabled.
- :type enable_jumbo_frame: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = instance_id.encode(encoding='utf-8')
- path = b'/instanceBySpec/%s' % instance_id
- params = {
- "resize": None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "spec": spec
- }
- if enable_jumbo_frame is not None:
- body['enableJumboFrame'] = enable_jumbo_frame
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- def batch_rebuild_instances(self, image_id, admin_pass, instance_ids, keypair_id=None, is_keep_image_login=None,
- client_token=None, config=None, user_data=None, use_last_user_data=None,
- is_open_hostEye=None, sys_root_size=None, is_preserve_data=None, raid_id=None,
- data_partition_type=None, root_partition_type=None):
- """
- Batch rebuild instances.
- :param image_id:
- Image id for rebuild.
- :type image_id: string
- :param admin_pass:
- The password of admin.
- :type admin_pass: string
- :param instance_ids:
- Identify list of instances need to rebuild.
- :type instance_ids: list of string
- :param keypair_id:
- Set the id of the keypair to be bound. (optional param)
- :type keypair_id: string
- :param user_data:
- UserData of the instance.
- :param use_last_user_data:
- Use last user data.
- :param is_open_hostEye:
- Is open host eye.
- :param sys_root_size:
- System disk size.
- :param is_preserve_data:
- Preserve data.
- :param raid_id:
- Raid id.
- :param data_partition_type:
- Data partition type.
- :param root_partition_type:
- Root partition type.
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/rebuild'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "imageId": image_id,
- "instanceIds": instance_ids
- }
- if admin_pass is not None:
- secret_access_key = self.config.credentials.secret_access_key
- cipher_admin_pass = aes128_encrypt_16char_key(admin_pass, secret_access_key)
- body['adminPass'] = cipher_admin_pass
- if keypair_id is not None:
- body['keypairId'] = keypair_id
- if is_keep_image_login is not None:
- body['keepImageLogin'] = is_keep_image_login
- if user_data is not None:
- body['userData'] = user_data
- if use_last_user_data is not None:
- body['useLastUserData'] = use_last_user_data
- if is_open_hostEye is not None:
- body['isOpenHostEye'] = is_open_hostEye
- if sys_root_size is not None:
- body['sysRootSize'] = sys_root_size
- if is_preserve_data is not None:
- body['isPreserveData'] = is_preserve_data
- if raid_id is not None:
- body['raidId'] = raid_id
- if data_partition_type is not None:
- body['dataPartitionType'] = data_partition_type
- if root_partition_type is not None:
- body['rootPartitionType'] = root_partition_type
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- def change_to_prepaid(self, instance_id, duration, relation_cds, auto_renew, auto_renew_period=None,
- client_token=None, config=None):
- """
- Change instance pay timing to prepaid.
- :param instance_id:
- Identify of the instance to change
- :type instance_id: string
- :param duration:
- Set the duration time of prepayment, unit:month.
- :type duration: int
- :param relation_cds:
- Set whether to chagne the associated data disk. True - change; False - no change. Default is False.
- :type relation_cds: bool
- :param auto_renew:
- Whether to enable automatic renewal, defaults to False.
- :type auto_renew: bool
- :param auto_renew_period:
- Duration of each automatic renewal(Unit: months).
- Value range: 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 24, 36. If not specified, the default is 1.
- This parameter is effective only when auto_renew is set to true.
- :type auto_renew_period: int
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = instance_id.encode(encoding='utf-8')
- path = b'/instance/%s' % instance_id
- params = {
- 'toPrepay': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "duration": duration
- }
- if auto_renew is not None:
- body['autoRenew'] = auto_renew
- body['autoRenewPeriod'] = auto_renew_period
- if relation_cds is not None:
- body['relationCds'] = relation_cds
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def list_instance_no_charge(self, marker=None, max_keys=None, internal_ip=None, keypair_id=None,
- zone_name=None, client_token=None, config=None):
- """
- Return a list of no charge instances owned by the authenticated user.
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 1000.
- :type max_keys: int
- :param internal_ip:
- The identified internal ip of instance.
- :type internal_ip: string
- :param keypair_id:
- get instance list filtered by keypair
- :type keypair_id: string
- :param zone_name:
- get instance list filtered by name of available zone
- :type zone_name: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/noCharge'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- if marker is not None:
- params['marker'] = marker
- if max_keys is not None:
- params['maxKeys'] = max_keys
- if internal_ip is not None:
- params['internalIp'] = internal_ip
- if keypair_id is not None:
- params['keypairId'] = keypair_id
- if zone_name is not None:
- params['zoneName'] = zone_name
- return self._send_request(http_methods.GET, path, params=params, config=config)
- def cancel_bid_order(self, order_id, client_token=None, config=None):
- """
- Cancel a bid order
- :param order_id:
- Identify of the order to cancel
- :type order_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/cancelBidOrder'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "orderId": order_id
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def batch_create_auto_renew_rules(self, instance_id, renew_time_unit="month", renew_time=1,
- renew_cds=None, renew_eip=None, client_token=None, config=None):
- """
- create auto renew rules for instance
- :param instance_id:
- Identify of the instance to auto renew
- :type instance_id: string
- :param renew_time_unit:
- Time unit for renew, values: 'month'/'year', default value: month
- :type renew_time_unit: string
- :param renew_time:
- renew time of year, values: 1/2/3, default value: 1
- :type renew_time: int
- :param renew_cds:
- renew cds, values: True/False, default value: True
- :param renew_eip:
- renew eip, values: True/False, default value: True
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/batchCreateAutoRenewRules'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceId": instance_id,
- "renewTimeUnit": renew_time_unit,
- "renewTime": renew_time
- }
- if renew_cds is not None:
- body["renewCds"] = renew_cds
- if renew_eip is not None:
- body["renewEip"] = renew_eip
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def batch_delete_auto_renew_rules(self, instance_id, renew_cds=None, renew_eip=None,
- client_token=None, config=None):
- """
- delete auto renew rules for instance
- :param instance_id:
- Identify of the instance to auto renew
- :type instance_id: string
- :param renew_cds:
- renew cds, values: True/False, default value: True
- :param renew_eip:
- renew eip, values: True/False, default value: True
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/batchDeleteAutoRenewRules'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceId": instance_id
- }
- if renew_cds is not None:
- body["renewCds"] = renew_cds
- if renew_eip is not None:
- body["renewEip"] = renew_eip
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def delete_recycled_instance(self, instance_id, client_token=None, config=None):
- """
- delete auto renew rules for instance
- :param instance_id:
- Identify of the instance to delete
- :type instance_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- instance_id = instance_id.encode(encoding='utf-8')
- path = b'/recycle/instance/%s' % instance_id
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {}
- return self._send_request(http_methods.DELETE, path, body=json.dumps(body), params=params, config=config)
- def list_instance_by_instance_ids(self, instance_ids, marker=None, max_keys=None, client_token=None, config=None):
- """
- list instances by id list
- :param instance_ids:
- Identify of the instances to return info
- :type instance_ids: list of string
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 1000.
- :type max_keys: int
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/listByInstanceId'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- if marker is not None:
- params['marker'] = marker
- if max_keys is not None:
- params['maxKeys'] = max_keys
- body = {
- "instanceIds": instance_ids
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def get_instance_delete_progress(self, instance_ids, client_token=None, config=None):
- """
- get instances delete progress
- :param instance_ids:
- Identify of the instances to return info
- :type instance_ids: list of string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/deleteProgress'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceIds": instance_ids
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def batch_delete_instance_with_related_resource(self, instance_ids, related_release_flag=None,
- delete_cds_snapshot_flag=None, delete_related_enis_flag=None,
- bcc_recycle_flag=None, cds_attribute_active=None,
- client_token=None, config=None):
- """
- batch delete instance with related resource
- :param instance_ids:
- Identify of the instances to return info
- :type instance_ids: list of string
- :param related_release_flag:
- Release or not related resources.
- :type related_release_flag: bool
- :param delete_cds_snapshot_flag:
- Delete or not cds snapshot.
- :type delete_cds_snapshot_flag: bool
- :param delete_related_enis_flag:
- Delete or not related enis.
- :type delete_related_enis_flag: bool
- :param bcc_recycle_flag:
- Recycle or not bcc instance.
- :type bcc_recycle_flag: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/batchDelete'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceIds": instance_ids
- }
- if related_release_flag is not None:
- body['relatedReleaseFlag'] = related_release_flag
- if delete_cds_snapshot_flag is not None:
- body['deleteCdsSnapshotFlag'] = delete_cds_snapshot_flag
- if delete_related_enis_flag is not None:
- body['deleteRelatedEnisFlag'] = delete_related_enis_flag
- if bcc_recycle_flag is not None:
- body['bccRecycleFlag'] = bcc_recycle_flag
- if bcc_recycle_flag is not None:
- body['cdsAttributeActive'] = cds_attribute_active
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def batch_start_instance(self, instance_ids, client_token=None, config=None):
- """
- batch start instance
- :param instance_ids:
- Identify of the instances to return info
- :type instance_ids: list of string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/batchAction'
- params = {
- 'start': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceIds": instance_ids
- }
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- def batch_stop_instance(self, instance_ids, force_stop=None, stop_with_no_charge=None,
- client_token=None, config=None):
- """
- batch stop instance
- :param instance_ids:
- Identify of the instances to return info
- :type instance_ids: list of string
- :param force_stop:
- force stop instance
- :type force_stop: bool
- :param stop_with_no_charge:
- stop instance and stop billing
- :type stop_with_no_charge: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/batchAction'
- params = {
- 'stop': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceIds": instance_ids
- }
- if force_stop is not None:
- body['forceStop'] = force_stop
- if stop_with_no_charge is not None:
- body['stopWithNoCharge'] = stop_with_no_charge
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- def list_id_mappings(self, ids, id_type, object_type, client_token=None, config=None):
- """
- get short-long id mapping by short/long id list
- :param ids:
- short id list
- :type ids: list of string
- :param id_type:
- id type
- :type id_type: string. value: short|long
- :param object_type:
- object type
- :type object_type: value: bcc
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/id/mapping'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceIds": ids,
- "idType": id_type,
- "objectType": object_type
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def batch_resize_instance(self, instance_ids, spec, subnet_id=None, logical_zone=None, internal_ip_v4=None,
- enable_jumbo_frame=None, client_token=None, config=None):
- """
- batch resize instance
- :param instance_ids:
- Identify of the instances to return info
- :type instance_ids: list of string
- :param spec:
- spec
- :type spec: string
- :param subnet_id:
- subnet id
- :type subnet_id: string
- :param logical_zone:
- logical zone name
- :type logical_zone: string
- :param internal_ip_v4:
- internal ip for ipv4
- :type internal_ip_v4: string
- :param enable_jumbo_frame:
- The parameter of specified the instance enable/disable jumbo frame.
- True means enable jumbo frame, false means disable jumbo frame.
- enable_jumbo_frame default None which means:
- When you change to the spec which doesn't support jumbo frame, the jumbo frame will be disabled.
- When the original instance don't support jumbo frame and you change to the spec which support jumbo frame,
- the jumbo frame will be disabled.
- When the original spec of the instance support jumbo frame , then you change to the spec which support jumbo
- frame, if the original instance enable jumbo frame, the jumbo frame will be enabled, if the original instance
- disable jumbo frame, the jumbo frame will be disabled.
- :type enable_jumbo_frame: bool
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instanceBatchBySpec'
- params = {
- 'resize': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceIdList": instance_ids,
- "spec": spec
- }
- if subnet_id is not None:
- body['subnetId'] = subnet_id
- if logical_zone is not None:
- body['logicalZone'] = logical_zone
- if internal_ip_v4 is not None:
- body['internalIpV4'] = internal_ip_v4
- if enable_jumbo_frame is not None:
- body['enableJumboFrame'] = enable_jumbo_frame
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- def list_available_resize_specs(self, instance_ids, spec=None, spec_id=None, logical_zone=None,
- client_token=None, config=None):
- """
- list available specs of resize instance in specified zone
- :param instance_ids:
- Identify of the instances to return info
- :type instance_ids: list of string
- :param spec:
- spec
- :type spec: string
- :param spec_id:
- spec id
- :type spec_id: string
- :param logical_zone:
- logical zone name
- :type logical_zone: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance'
- params = {
- 'resizeList': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceIdList": instance_ids,
- "spec": spec
- }
- if spec_id is not None:
- body['specId'] = spec_id
- if logical_zone is not None:
- body['zone'] = logical_zone
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def batch_change_instance_to_prepay(self, change_pay_timing_req_list, client_token=None, config=None):
- """
- batch change instance to prepay
- :param change_pay_timing_req_list:
- batch change req list
- :type change_pay_timing_req_list: list of PayTimingChangeReqModel
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/batch/charging'
- params = {
- 'toPrepay': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "config": [change_pay_timing_req.__dict__ for change_pay_timing_req in change_pay_timing_req_list]
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def batch_change_instance_to_postpay(self, change_pay_timing_req_list, client_token=None, config=None):
- """
- batch change instance to postpay
- :param change_pay_timing_req_list:
- batch change req list
- :type change_pay_timing_req_list: list of PayTimingChangeReqModel
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/batch/charging'
- params = {
- 'toPostpay': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "config": [change_pay_timing_req.__dict__ for change_pay_timing_req in change_pay_timing_req_list]
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def list_instance_roles(self, client_token=None, config=None):
- """
- list instance role
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/role/list'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- return self._send_request(http_methods.GET, path, params=params, config=config)
- def bind_instance_role(self, instance_ids, role_name, client_token=None, config=None):
- """
- bind_instance_role
- :param instance_ids:
- instance id list
- :type instance_ids: list of string
- :param role_name:
- name of role
- :type role_name: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/role'
- params = {
- 'bind': None
- }
- instances = []
- for instance_id in instance_ids:
- instances.append({'instanceId': instance_id})
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instances": instances,
- "roleName": role_name
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def unbind_instance_role(self, instance_ids, role_name, client_token=None, config=None):
- """
- unbind_instance_role
- :param instance_ids:
- instance id list
- :type instance_ids: list of string
- :param role_name:
- name of role
- :type role_name: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/role'
- params = {
- 'unbind': None
- }
- instances = []
- for instance_id in instance_ids:
- instances.append({'instanceId': instance_id})
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instances": instances,
- "roleName": role_name
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def add_ipv6(self, instance_id, ipv6_address, reboot=False, client_token=None, config=None):
- """
- add_ipv6
- :param instance_id:
- instance id
- :type instance_id: list of string
- :param ipv6_address:
- ipv6 address to bind instance
- :type ipv6_address: list of string
- :param reboot:
- reboot the instance
- :type reboot: list of string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/addIpv6'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceId": instance_id,
- "ipv6Address": ipv6_address,
- "reboot": reboot
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def delete_ipv6(self, instance_id, reboot=False, client_token=None, config=None):
- """
- delete_ipv6
- :param instance_id:
- instance id
- :type instance_id: list of string
- :param reboot:
- reboot the instance
- :type reboot: list of string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/delIpv6'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceId": instance_id,
- "reboot": reboot
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def bind_image_to_tags(self, image_id, tags, client_token=None, config=None):
- """
- bind_image_to_tags
- :param image_id:
- image id
- :type image_id: list of string
- :param tags
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- image_id = image_id.encode(encoding='utf-8')
- path = b'/image/%s/tag' % image_id
- params = {
- 'bind': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- tag_list = [tag.__dict__ for tag in tags]
- body = {
- 'changeTags': tag_list
- }
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- def unbind_image_to_tags(self, image_id, tags, client_token=None, config=None):
- """
- unbind_image_to_tags
- :param image_id:
- image id
- :type image_id: list of string
- :param tags
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- image_id = image_id.encode(encoding='utf-8')
- path = b'/image/%s/tag' % image_id
- params = {
- 'unbind': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- tag_list = [tag.__dict__ for tag in tags]
- body = {
- 'changeTags': tag_list
- }
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- def import_custom_image(self, os_name, os_arch, os_type, os_version, name, bos_url, client_token=None, config=None,
- detection=None, generation_type=None):
- """
- import_custom_image
- :param os_name:
- name of os
- :type os_name: string
- :param os_arch:
- archicture of os
- :type os_arch: string
- :param os_type:
- type of os
- :type os_type: string
- :param os_version:
- version of os
- :type os_version: string
- :param name:
- name of os
- :type name: string
- :param bos_url:
- boot script of os
- :type bos_url: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/image/import'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'osName': os_name,
- 'osArch': os_arch,
- 'osType': os_type,
- 'osVersion': os_version,
- 'name': name,
- 'bosUrl': bos_url
- }
- if detection:
- body['detection'] = detection
- if generation_type is not None:
- body['generationType'] = generation_type
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def create_remote_copy_snapshot(self, snapshot_id, dest_region_infos, client_token=None, config=None):
- """
- create_remote_copy_snapshot
- :param snapshot_id:
- identify of snapshot
- :type snapshot_id: string
- :param dest_region_infos:
- information of destination region
- :type dest_region_infos: list of bcc_model.DestRegionInfoModel
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- snapshot_id = snapshot_id.encode(encoding='utf-8')
- path = b'/snapshot/remote_copy/%s' % snapshot_id
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "destRegionInfos": [dest_region_info.__dict__ for dest_region_info in dest_region_infos]
- }
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- def create_deploy_set(self, name=None, strategy=None, desc=None, concurrency=None, client_token=None, config=None):
- """
- create_deploy_set
- :param name:
- name of deploy set
- :type name: string
- :param strategy:
- deploy strategy HOST_HA | RACK_HA | TOR_HA
- :type strategy: string
- :param desc:
- description of deploy set
- :type desc: string
- :param concurrency:
- mark how many instances can created in one location
- location means host for HOST_HA, rack for RACK_HA, tor for TOR_HA
- :type concurrency: int
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/deployset/create'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {}
- if name is not None:
- body['name'] = name
- if strategy is not None:
- body['strategy'] = strategy
- if desc is not None:
- body['desc'] = desc
- if concurrency is not None:
- body['concurrency'] = concurrency
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def list_deploy_sets(self, client_token=None, config=None, deployment_set_ids=None):
- """
- list_deploy_sets
- :param deployment_set_ids:
- :type deployment_set_ids: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/deployset/list'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- if deployment_set_ids is not None:
- params['deploymentSetIds'] = deployment_set_ids
- return self._send_request(http_methods.GET, path, params=params, config=config)
- def delete_deploy_set(self, deploy_set_id, client_token=None, config=None):
- """
- delete_deploy_set
- :param deploy_set_id:
- identify of deployset
- :type deploy_set_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- deploy_set_id = deploy_set_id.encode(encoding='utf-8')
- path = b'/instance/deployset/%s' % deploy_set_id
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- return self._send_request(http_methods.DELETE, path, params=params, config=config)
- def modify_deploy_set(self, deploy_set_id, name=None, desc=None, client_token=None, config=None):
- """
- modify_deploy_set
- :param deploy_set_id:
- identify of deployset
- :type deploy_set_id: string
- :param name:
- name of deploy set
- :type name: string
- :param desc:
- description of deploy set
- :type desc: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- deploy_set_id = deploy_set_id.encode(encoding='utf-8')
- path = b'/instance/deployset/%s' % deploy_set_id
- params = {
- 'modifyAttribute': None
- }
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {}
- if name is not None:
- body['name'] = name
- if desc is not None:
- body['desc'] = desc
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- def get_deploy_set(self, deploy_set_id, client_token=None, config=None):
- """
- get_deploy_set
- :param deploy_set_id:
- identify of deployset
- :type deploy_set_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- deploy_set_id = deploy_set_id.encode(encoding='utf-8')
- path = b'/deployset/%s' % deploy_set_id
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- return self._send_request(http_methods.GET, path, params=params, config=config)
- def update_instance_deploy(self, instance_id, deployset_id_list, force=None,
- client_token=None, config=None):
- """
- update instance deploy relation
- :param instance_id:
- identify of instance
- :type instance_id: string
- :param deployset_id_list:
- identify list of deployset
- :type deployset_id_list: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/deployset/updateRelation'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'instanceId': instance_id,
- 'deploysetIdList': deployset_id_list
- }
- if force is not None:
- body['force'] = force
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def del_instance_deploy(self, instance_id_list, deploy_set_id, client_token=None, config=None):
- """
- delete instance deploy relation
- :param instance_id_list:
- identify list of instance
- :type instance_id_list: string
- :param deploy_set_id:
- identify of deployset
- :type deploy_set_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/deployset/delRelation'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'instanceIdList': instance_id_list,
- 'deployId': deploy_set_id
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def create_ehc_cluster(self, name, zone_name, description=None, client_token=None, config=None):
- """
- create ehc cluster
- :param name:
- The name of the EHC cluster. This parameter is required.
- :type name: string
- :param zone_name:
- The availability zone name where the EHC cluster will be created.
- :type zone_name: string
- :param description:
- Optional. A brief description of the EHC cluster. Default is an empty string.
- :type description: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/ehc/cluster/create'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'name': name,
- 'zoneName': zone_name
- }
- if description is not None:
- body['description'] = description
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def modify_ehc_cluster(self, ehc_cluster_id, name=None, description=None, client_token=None, config=None):
- """
- Modifies the name and description of an EHC cluster.
- :param ehc_cluster_id:
- The ID of the EHC cluster to be modified. This parameter is required.
- :type ehc_cluster_id: string
- :param name:
- Optional. The new name for the EHC cluster. If not specified, the name will not be changed.
- :type name: string
- :param description:
- Optional. The new description for the EHC cluster. If not specified, the description will not be changed.
- :type description: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/ehc/cluster/modify'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'ehcClusterId': ehc_cluster_id
- }
- if name is not None:
- body['name'] = name
- if description is not None:
- body['description'] = description
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def get_ehc_cluster_list(self, ehc_cluster_id_list=None, name_list=None, zone_name=None, config=None):
- """
- get ehc cluster list
- :param ehc_cluster_id_list:
- Optional. List of EHC cluster IDs to filter the results. If not specified, retrieves all clusters.
- :type ehc_cluster_id_list: list<string>
- :param name_list:
- Optional. List of EHC cluster names to filter the results. If not specified, retrieves all clusters.
- :type name_list: list<string>
- :param zone_name:
- Optional. The name of the availability zone to filter the results.
- :type zone_name: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/ehc/cluster/list'
- params = {}
- body = {}
- if ehc_cluster_id_list is not None:
- body['ehcClusterIdList'] = ehc_cluster_id_list
- if name_list is not None:
- body['nameList'] = name_list
- if zone_name is not None:
- body['zoneName'] = zone_name
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def delete_ehc_cluster(self, ehc_cluster_id_list, client_token=None, config=None):
- """
- Modifies the name and description of an EHC cluster.
- :param ehc_cluster_id_list:
- A list of IDs of the EHC clusters to be deleted. This parameter is required.
- :type ehc_cluster_id_list: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/ehc/cluster/delete'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'ehcClusterIdList': ehc_cluster_id_list
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def get_available_images_by_spec(self, marker=None, max_keys=None, spec=None, os_name=None, config=None):
- """
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 100.
- :type max_keys: int
- :param os_name:
- The optional parameter to query specified public image by os name.
- :type os_name: string
- :param spec:
- The required parameter to query specified public image by spec.
- :type spec: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/image/getAvailableImageBySpec'
- params = {}
- if marker is not None:
- params['marker'] = marker
- if max_keys is not None:
- params['maxKeys'] = max_keys
- if spec is not None:
- params['spec'] = spec
- if os_name is not None:
- params['osName'] = os_name
- return self._send_request(http_methods.GET, path, params=params, config=config)
- def create_reserved_instances(self, reserved_instance_name=None, scope=None, zone_name=None, spec=None,
- offering_type=None, instance_count=None, reserved_instance_count=None,
- reserved_instance_time=None, reserved_instance_time_unit=None,
- auto_renew_time_unit=None, auto_renew_time=None, auto_renew=None,
- effective_time=None, ehc_cluster_id=None, ticket_id=None,
- tags=None, client_token=None, config=None):
- """
- Create reserved instances.
- :param reserved_instance_name:
- The name of the reserved instance.
- :type reserved_instance_name: string
- :param scope:
- The scope.
- :type scope: string
- :param zone_name:
- The name of the availability zone.
- :type zone_name: string
- :param spec:
- The instance specification.
- :type spec: string
- :param offering_type:
- The offering type.
- :type offering_type: string
- :param instance_count:
- The number of instances.
- :type instance_count: int
- :param reserved_instance_count:
- The number of reserved instances.
- :type reserved_instance_count: int
- :param reserved_instance_time:
- The duration of the reserved instance.
- :type reserved_instance_time: int
- :param reserved_instance_time_unit:
- The time unit of the reserved instance.
- :type reserved_instance_time_unit: string
- :param auto_renew_time_unit:
- The time unit for automatic renewal.
- :type auto_renew_time_unit: string
- :param auto_renew_time:
- The duration for automatic renewal.
- :type auto_renew_time: int
- :param auto_renew:
- Whether to enable automatic renewal, defaults to False.
- :type auto_renew: bool
- :param effective_time:
- The effective time.
- It is immediately effective by default.
- :type effective_time: string
- :param ehc_cluster_id:
- The EHC cluster ID.
- :type ehc_cluster_id: string
- :param ticket_id:
- The ticket ID.
- :type ticket_id: string
- :param tags:
- The optional list of tag to be bonded.
- :type tags: list<bcc_model.TagModel>
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- path = b'/instance/reserved/create' # 请替换为实际的请求路径
- params = {}
- if client_token is not None:
- params['clientToken'] = client_token
- body = {}
- if reserved_instance_name is not None:
- body['reservedInstanceName'] = reserved_instance_name
- if scope is not None:
- body['scope'] = scope
- if zone_name is not None:
- body['zoneName'] = zone_name
- if spec is not None:
- body['spec'] = spec
- if offering_type is not None:
- body['offeringType'] = offering_type
- if instance_count is not None:
- body['instanceCount'] = instance_count
- if reserved_instance_count is not None:
- body['reservedInstanceCount'] = reserved_instance_count
- if reserved_instance_time is not None:
- body['reservedInstanceTime'] = reserved_instance_time
- if reserved_instance_time_unit is not None:
- body['reservedInstanceTimeUnit'] = reserved_instance_time_unit
- if auto_renew_time_unit is not None:
- body['autoRenewTimeUnit'] = auto_renew_time_unit
- if auto_renew_time is not None:
- body['autoRenewTime'] = auto_renew_time
- if auto_renew is not False:
- body['autoRenew'] = str(auto_renew).lower()
- if effective_time is not None:
- body['effectiveTime'] = effective_time
- if ehc_cluster_id is not None:
- body['ehcClusterId'] = ehc_cluster_id
- if ticket_id is not None:
- body['ticketId'] = ticket_id
- if tags is not None:
- tag_list = [tag.__dict__ for tag in tags]
- body['tags'] = tag_list
- return self._send_request(http_methods.POST, path, body=json.dumps(body), params=params, config=config)
- def modify_reserved_instances(self, reserved_instances=None, client_token=None, config=None):
- """
- Modify the information of reserved instances.
- :param reserved_instances:
- A list of dictionaries containing the information of reserved instances to be updated.
- :type reserved_instances: list<bcc_model.ModifyReservedInstanceModel>
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- path = b'/instance/reserved/modify'
- params = {}
- if client_token is not None:
- params['clientToken'] = client_token
- body = {}
- if reserved_instances is not None:
- reserved_instances_list = [reserved_instance.__dict__ for reserved_instance in reserved_instances]
- body['reservedInstances'] = reserved_instances_list
- return self._send_request(http_methods.PUT, path, body=json.dumps(body), params=params, config=config)
- def get_instance_user_data(self, instance_id, client_token=None, config=None):
- """
- get_instance_user_data
- """
- path = b'/instance/attribute/getUserdata'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- "instanceId": instance_id
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def enter_rescue_mode(self, instance_id, force_stop, password, client_token=None, config=None):
- """
- 进入救援模式。
- :param enter_rescue_mode_req:
- :desc
- :type enter_rescue_mode_req: json
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/rescue/mode/enter'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'instanceId': instance_id,
- 'forceStop': force_stop,
- 'password': password
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- def exit_rescue_mode(self, instance_id, client_token=None, config=None):
- """
- 退出救援模式。
- :param exit_rescue_mode_req:
- :desc
- :type exit_rescue_mode_req: json
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/instance/rescue/mode/exit'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'instanceId': instance_id
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- def bind_sg(self, instance_ids, security_group_ids, security_group_type, client_token=None, config=None):
- """
- 绑定安全组。
- :param bind_sg:
- :desc
- :type bind_sg: json
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/securitygroup/bind'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'instanceIds': instance_ids,
- 'securityGroupIds': security_group_ids,
- 'securityGroupType': security_group_type
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- def replace_sg(self, instance_ids, security_group_ids, security_group_type, client_token=None, config=None):
- """
- 替换安全组。
- :param replace_sg:
- :desc
- :type replace_sg: json
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/securitygroup/replace'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'instanceIds': instance_ids,
- 'securityGroupIds': security_group_ids,
- 'securityGroupType': security_group_type
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- def unbind_sg(self, instance_ids, security_group_ids, security_group_type, client_token=None, config=None):
- """
- 解绑安全组。
- :param unbind_sg:
- :desc
- :type unbind_sg: json
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/securitygroup/unbind'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'instanceIds': instance_ids,
- 'securityGroupIds': security_group_ids,
- 'securityGroupType': security_group_type
- }
- return self._send_request(http_methods.PUT, path, json.dumps(body),
- params=params, config=config)
- def authorize_server_event(self, authorize_maintenance_operation, server_event_id=None, instance_id=None,
- execute_time=None, config=None, client_token=None):
- """
- authorize_server_event
- :param authorize_maintenance_operation:
- Authorized operation and maintenance operations
- :type authorize_maintenance_operation: string
- :param server_event_id:
- event Id.
- :type marker: string
- :param instance_id:
- Instance Id, server Event ID, instance ID must select one of the request options
- :type max_keys: string
- :param execute_time:
- Authorized execution time,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type execute_time: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- params['action'] = 'AuthorizeServerEvent'
- body = {
- 'serverEventId': server_event_id,
- 'instanceId': instance_id,
- 'authorizeMaintenanceOperation': authorize_maintenance_operation,
- 'executeTime': execute_time
- }
- return self._send_action_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def create_authorize_rule(self, server_event_category, authorize_maintenance_operations, rule_name,
- enable_rule=None, effective_scope=None, tags=None, config=None, client_token=None):
- """
- create_authorize_rule
- :param server_event_category:
- Server Event Category
- :type server_event_category: string
- :param authorize_maintenance_operations:
- Authorized operation and maintenance operations
- :type authorize_maintenance_operations: list
- :param rule_name:
- Rule Name
- :type rule_name: string
- :param enable_rule:
- Whether to enable the rule
- :type enable_rule: int
- :param effective_scope:
- Effective scope
- :type effective_scope: String
- :param tags:
- Tag information
- :type tags: list
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- params['action'] = 'CreateAuthorizeRule'
- body = {
- 'enableRule': enable_rule,
- 'serverEventCategory': server_event_category,
- 'authorizeMaintenanceOperations': authorize_maintenance_operations,
- 'tags': tags,
- 'effectiveScope': effective_scope,
- 'ruleName': rule_name
- }
- return self._send_action_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def modify_authorize_rule(self, rule_id, authorize_maintenance_operations=None, rule_name=None,
- enable_rule=None, effective_scope=None, tags=None, config=None, client_token=None):
- """
- modify_authorize_rule
- :param rule_id:
- rule_id to be modified
- :type rule_id: string
- :param authorize_maintenance_operations:
- Authorized operation and maintenance operations
- :type authorize_maintenance_operations: list
- :param rule_name:
- Rule Name
- :type rule_name: string
- :param enable_rule:
- Whether to enable the rule
- :type enable_rule: int
- :param effective_scope:
- Effective scope
- :type effective_scope: String
- :param tags:
- Tag information
- :type tags: list
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- params['action'] = 'ModifyInstUserOpAuthorizeRuleAttribute'
- body = {
- 'enableRule': enable_rule,
- 'authorizeMaintenanceOperations': authorize_maintenance_operations,
- 'tags': tags,
- 'effectiveScope': effective_scope,
- 'ruleName': rule_name,
- "ruleId": rule_id
- }
- return self._send_action_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def delete_authorize_rule(self, rule_id, config=None, client_token=None):
- """
- delete_authorize_rule
- :param rule_id:
- rule_id to be deleted
- :type rule_id: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- params['action'] = 'DeleteInstUserOpAuthorizeRule'
- body = {
- 'ruleId': rule_id
- }
- return self._send_action_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def describe_authorize_rules(self, max_keys, marker=None, rule_ids=None, rule_names=None, config=None):
- """
- describe_authorize_rules
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 10.
- :type max_keys: int
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param rule_ids:
- filter rule list with multiple rule ids
- :type rule_ids: string
- :param rule_names:
- filter rule list with multiple rule names
- :type rule_names: list
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/'
- params = {}
- params['action'] = 'DescribeAuthorizeRules'
- body = {
- "marker": marker,
- "maxKeys": max_keys,
- "ruleIds": rule_ids,
- "ruleNames": rule_names
- }
- return self._send_action_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def describe_planned_events(self, max_keys, marker=None, server_event_ids=None, instance_ids=None,
- product_category=None, server_event_type=None, server_event_log_time_filter=None,
- period_start_time=None, period_end_time=None, server_event_status=None, config=None):
- """
- describe_planned_events
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 10.
- :type max_keys: int
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param server_event_ids:
- filter planned event list with multiple server event ids
- :type server_event_ids: list of string
- :param instance_ids:
- filter planned event list with multiple instance ids
- :type instance_ids: list of string
- :param product_category:
- filter planned event list with product_category
- :type product_category: string
- :param server_event_type:
- filter planned event list with server_event_type
- :type server_event_type: string
- :param server_event_log_time_filter:
- filter planned event list with server_event_log_time_filter,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type server_event_log_time_filter: string
- :param period_start_time:
- filter planned event list with period_start_time,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type period_start_time: string
- :param period_end_time:
- filter planned event list with period_end_time,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type period_end_time: string
- :param server_event_status:
- filter planned event list with server_event_status
- :type server_event_status: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/'
- params = {}
- params['action'] = 'DescribePlannedEvents'
- body = {
- "marker": marker,
- "maxKeys": max_keys,
- "serverEventIds": server_event_ids,
- "instanceIds": instance_ids,
- "productCategory": product_category,
- "serverEventType": server_event_type,
- "serverEventLogTimeFilter": server_event_log_time_filter,
- "periodStartTime": period_start_time,
- "periodEndTime": period_end_time,
- "serverEventStatus": server_event_status
- }
- return self._send_action_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def describe_planned_recored_events(self, max_keys, marker=None, server_event_ids=None, instance_ids=None,
- product_category=None, server_event_type=None,
- server_event_log_time_filter=None, period_start_time=None,
- period_end_time=None, config=None):
- """
- describe_planned_recored_events
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 10.
- :type max_keys: int
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param server_event_ids:
- filter planned event list with multiple server event ids
- :type server_event_ids: list of string
- :param instance_ids:
- filter planned event list with multiple instance ids
- :type instance_ids: list of string
- :param product_category:
- filter planned event list with product_category
- :type product_category: string
- :param server_event_type:
- filter planned event list with server_event_type
- :type server_event_type: string
- :param server_event_log_time_filter:
- filter planned event list with server_event_log_time_filter,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type server_event_log_time_filter: string
- :param period_start_time:
- filter planned event list with period_start_time,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type period_start_time: string
- :param period_end_time:
- filter planned event list with period_end_time,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type period_end_time: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/'
- params = {}
- params['action'] = 'DescribePlannedEventRecords'
- body = {
- "marker": marker,
- "maxKeys": max_keys,
- "serverEventIds": server_event_ids,
- "instanceIds": instance_ids,
- "productCategory": product_category,
- "serverEventType": server_event_type,
- "serverEventLogTimeFilter": server_event_log_time_filter,
- "periodStartTime": period_start_time,
- "periodEndTime": period_end_time
- }
- return self._send_action_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def describe_unplanned_events(self, max_keys, marker=None, server_event_ids=None, instance_ids=None,
- product_category=None, server_event_type=None, server_event_log_time_filter=None,
- period_start_time=None, period_end_time=None, server_event_status=None, config=None):
- """
- describe_unplanned_events
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 10.
- :type max_keys: int
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param server_event_ids:
- filter unplanned event list with multiple server event ids
- :type server_event_ids: list of string
- :param instance_ids:
- filter unplanned event list with multiple instance ids
- :type instance_ids: list of string
- :param product_category:
- filter unplanned event list with product_category
- :type product_category: string
- :param server_event_type:
- filter unplanned event list with server_event_type
- :type server_event_type: string
- :param server_event_log_time_filter:
- filter unplanned event list with server_event_log_time_filter,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type server_event_log_time_filter: string
- :param period_start_time:
- filter unplanned event list with period_start_time,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type period_start_time: string
- :param period_end_time:
- filter unplanned event list with period_end_time,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type period_end_time: string
- :param server_event_status:
- filter unplanned event list with server_event_status
- :type server_event_status: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/'
- params = {}
- params['action'] = 'DescribeUnplannedEvents'
- body = {
- "marker": marker,
- "maxKeys": max_keys,
- "serverEventIds": server_event_ids,
- "instanceIds": instance_ids,
- "productCategory": product_category,
- "serverEventType": server_event_type,
- "serverEventLogTimeFilter": server_event_log_time_filter,
- "periodStartTime": period_start_time,
- "periodEndTime": period_end_time,
- "serverEventStatus": server_event_status
- }
- return self._send_action_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def describe_unplanned_recored_events(self, max_keys, marker=None, server_event_ids=None, instance_ids=None,
- product_category=None, server_event_type=None,
- server_event_log_time_filter=None, period_start_time=None,
- period_end_time=None, config=None):
- """
- describe_unplanned_recored_events
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 10.
- :type max_keys: int
- :param marker:
- The optional parameter marker specified in the original request to specify
- where in the results to begin listing.
- Together with the marker, specifies the list result which listing should begin.
- If the marker is not specified, the list result will listing from the first one.
- :type marker: string
- :param server_event_ids:
- filter unplanned event list with multiple server event ids
- :type server_event_ids: list of string
- :param instance_ids:
- filter unplanned event list with multiple instance ids
- :type instance_ids: list of string
- :param product_category:
- filter unplanned event list with product_category
- :type product_category: string
- :param server_event_type:
- filter unplanned event list with server_event_type
- :type server_event_type: string
- :param server_event_log_time_filter:
- filter unplanned event list with server_event_log_time_filter,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type server_event_log_time_filter: string
- :param period_start_time:
- filter unplanned event list with period_start_time,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type period_start_time: string
- :param period_end_time:
- filter unplanned event list with period_end_time,
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :type period_end_time: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/'
- params = {}
- params['action'] = 'DescribeUnplannedEventRecords'
- body = {
- "marker": marker,
- "maxKeys": max_keys,
- "serverEventIds": server_event_ids,
- "instanceIds": instance_ids,
- "productCategory": product_category,
- "serverEventType": server_event_type,
- "serverEventLogTimeFilter": server_event_log_time_filter,
- "periodStartTime": period_start_time,
- "periodEndTime": period_end_time
- }
- return self._send_action_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def check_unplanned_event(self, server_event_id, check_result, issue_effect=None, issue_description=None,
- authorize_maintenance_operation=None, config=None, client_token=None):
- """
- check_unplanned_event
- :param server_event_id:
- server_event_id to be check
- :type server_event_id: string
- :param check_result:
- Whether unplanned events have passed the acceptance, supporting parameters Pass and Reject
- :type check_result: string
- :param issue_effect:
- Fault effect must be passed when the fault acceptance is rejected
- :type issue_effect: string
- :param issue_description:
- Fault description must be passed when the fault acceptance is rejected
- :type issue_description: string
- :param authorize_maintenance_operation:
- Authorized operation and maintenance
- :type authorize_maintenance_operation: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- params['action'] = 'CheckUnplannedEvent'
- body = {
- "serverEventId": server_event_id,
- "checkResult": check_result,
- "issueEffect": issue_effect,
- "issueDescription": issue_description,
- "authorizeMaintenanceOperation": authorize_maintenance_operation
- }
- return self._send_action_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def get_task(self, task_ids, max_keys=100, config=None):
- """
- get_task
- :param task_ids:
- task_ids to be used to query the task
- :type task_ids: list of string
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 100.
- :type max_keys: int
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/task/detail'
- params = {}
- body = {
- "taskIds": task_ids,
- "maxKeys": max_keys
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def list_task(self, max_keys=10, task_ids=None, task_action=None, task_status=None, resource_ids=None,
- start_time=None, end_time=None, config=None):
- """
- list_task
- :param task_ids:
- task_ids to be used to query the task
- :param task_action:
- task_action to be used to query the task
- :param task_status:
- task_status to be used to query the task
- :param start_time:
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :param end_time:
- The format is yyyy-MM-dd'T'HH: mm: ss'Z ', if it is empty, query the operation log of the day
- :param max_keys:
- The optional parameter to specifies the max number of list result to return.
- The default value is 10.
- :param config:
- :return:
- """
- path = b'/task/list'
- params = {}
- body = {
- "taskIds": task_ids,
- "taskAction": task_action,
- "taskStatus": task_status,
- "startTime": start_time,
- "endTime": end_time,
- "resourceIds": resource_ids,
- "maxKeys": max_keys,
- }
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- def generate_client_token_by_uuid():
- """
- The default method to generate the random string for client_token
- if the optional parameter client_token is not specified by the user.
- :return:
- :rtype string
- """
- return str(uuid.uuid4())
- def generate_client_token_by_random():
- """
- The alternative method to generate the random string for client_token
- if the optional parameter client_token is not specified by the user.
- :return:
- :rtype string
- """
- client_token = ''.join(random.sample(string.ascii_letters + string.digits, 36))
- return client_token
- def get_cds_price(self, purchase_length, payment_timing, storage_type, cds_size_in_gb, purchase_count, zone_name,
- encrypt_key=None, client_token=None, config=None):
- """
- get_deploy_set
- """
- path = b'/volume/getPrice'
- params = {}
- if client_token is None:
- params['clientToken'] = generate_client_token()
- else:
- params['clientToken'] = client_token
- body = {
- 'purchaseLength': purchase_length,
- 'paymentTiming': payment_timing,
- 'storageType': storage_type,
- 'cdsSizeInGB': cds_size_in_gb,
- 'purchaseCount': purchase_count,
- 'zoneName': zone_name
- }
- if encrypt_key is not None:
- body['encryptKey'] = encrypt_key
- return self._send_request(http_methods.POST, path, json.dumps(body),
- params=params, config=config)
- generate_client_token = generate_client_token_by_uuid
|