azure-block_store.res 549 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643
  1. cloudbridge.test.test_block_store_service.CloudBlockStoreServiceTestCase
  2. Test output
  3. .E.E..
  4. ======================================================================
  5. ERROR: test_crud_snapshot (cloudbridge.test.test_block_store_service.CloudBlockStoreServiceTestCase)
  6. ----------------------------------------------------------------------
  7. Traceback (most recent call last):
  8. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 45, in wrap_exception
  9. return next_handler.invoke(event_args, *args, **kwargs)
  10. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 110, in invoke
  11. result = self.callback(*args, **kwargs)
  12. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/line_profiler.py", line 115, in wrapper
  13. result = func(*args, **kwds)
  14. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py", line 537, in create
  15. params)
  16. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py", line 527, in create_snapshot
  17. params
  18. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/azure/mgmt/compute/v2018_04_01/operations/snapshots_operations.py", line 127, in create_or_update
  19. **operation_config
  20. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/azure/mgmt/compute/v2018_04_01/operations/snapshots_operations.py", line 79, in _create_or_update_initial
  21. raise exp
  22. msrestazure.azure_exceptions.CloudError: Azure Error: NotFound
  23. Message: Resource cb-crudsnap-af95c9-a9af68 is not found.
  24. The above exception was the direct cause of the following exception:
  25. Traceback (most recent call last):
  26. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 41, in wrapper
  27. func(self, *args, **kwargs)
  28. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/test_block_store_service.py", line 179, in test_crud_snapshot
  29. "cb-snap", create_snap, cleanup_snap)
  30. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/standard_interface_tests.py", line 339, in check_crud
  31. obj = create_func(label)
  32. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/test_block_store_service.py", line 164, in create_snap
  33. description=label)
  34. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py", line 445, in create_snapshot
  35. description)
  36. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/middleware.py", line 74, in wrapper
  37. return dispatcher.dispatch(self, event, *args, **kwargs)
  38. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 218, in dispatch
  39. return handlers[0].invoke(event_args, *args, **kwargs)
  40. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 78, in invoke
  41. result = self.callback(event_args, *args, **kwargs)
  42. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 55, in wrap_exception
  43. six.raise_from(cb_ex, e)
  44. File "<string>", line 3, in raise_from
  45. cloudbridge.cloud.interfaces.exceptions.CloudBridgeBaseException: CloudBridgeBaseException: Azure Error: NotFound
  46. Message: Resource cb-crudsnap-af95c9-a9af68 is not found. from exception type: <class 'msrestazure.azure_exceptions.CloudError'>
  47. ======================================================================
  48. ERROR: test_snapshot_properties (cloudbridge.test.test_block_store_service.CloudBlockStoreServiceTestCase)
  49. ----------------------------------------------------------------------
  50. Traceback (most recent call last):
  51. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 45, in wrap_exception
  52. return next_handler.invoke(event_args, *args, **kwargs)
  53. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 110, in invoke
  54. result = self.callback(*args, **kwargs)
  55. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/line_profiler.py", line 115, in wrapper
  56. result = func(*args, **kwds)
  57. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py", line 537, in create
  58. params)
  59. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/azure_client.py", line 527, in create_snapshot
  60. params
  61. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/azure/mgmt/compute/v2018_04_01/operations/snapshots_operations.py", line 127, in create_or_update
  62. **operation_config
  63. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/azure/mgmt/compute/v2018_04_01/operations/snapshots_operations.py", line 79, in _create_or_update_initial
  64. raise exp
  65. msrestazure.azure_exceptions.CloudError: Azure Error: NotFound
  66. Message: Resource cb-snapprop-29bbfa-a87924 is not found.
  67. The above exception was the direct cause of the following exception:
  68. Traceback (most recent call last):
  69. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 41, in wrapper
  70. func(self, *args, **kwargs)
  71. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/test_block_store_service.py", line 202, in test_snapshot_properties
  72. description=snap_label)
  73. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py", line 445, in create_snapshot
  74. description)
  75. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/middleware.py", line 74, in wrapper
  76. return dispatcher.dispatch(self, event, *args, **kwargs)
  77. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 218, in dispatch
  78. return handlers[0].invoke(event_args, *args, **kwargs)
  79. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 78, in invoke
  80. result = self.callback(event_args, *args, **kwargs)
  81. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 55, in wrap_exception
  82. six.raise_from(cb_ex, e)
  83. File "<string>", line 3, in raise_from
  84. cloudbridge.cloud.interfaces.exceptions.CloudBridgeBaseException: CloudBridgeBaseException: Azure Error: NotFound
  85. Message: Resource cb-snapprop-29bbfa-a87924 is not found. from exception type: <class 'msrestazure.azure_exceptions.CloudError'>
  86. ----------------------------------------------------------------------
  87. Ran 6 tests in 1006.019s
  88. FAILED (errors=2)
  89. Wrote profile results to run_single.py.lprof
  90. Timer unit: 1e-06 s
  91. Total time: 0 s
  92. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  93. Function: find at line 81
  94. Line # Hits Time Per Hit % Time Line Contents
  95. ==============================================================
  96. 81 @dispatch(event="provider.security.vm_firewalls.find",
  97. 82 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  98. 83 @profile
  99. 84 def find(self, **kwargs):
  100. 85 obj_list = self
  101. 86 filters = ['label']
  102. 87 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  103. 88
  104. 89 # All kwargs should have been popped at this time.
  105. 90 if len(kwargs) > 0:
  106. 91 raise InvalidParamException(
  107. 92 "Unrecognised parameters for search: %s. Supported "
  108. 93 "attributes: %s" % (kwargs, ", ".join(filters)))
  109. 94
  110. 95 return ClientPagedResultList(self.provider,
  111. 96 matches if matches else [])
  112. Total time: 0 s
  113. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  114. Function: get at line 111
  115. Line # Hits Time Per Hit % Time Line Contents
  116. ==============================================================
  117. 111 @dispatch(event="provider.security.vm_firewall_rules.get",
  118. 112 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  119. 113 @profile
  120. 114 def get(self, firewall, rule_id):
  121. 115 matches = [rule for rule in firewall.rules if rule.id == rule_id]
  122. 116 if matches:
  123. 117 return matches[0]
  124. 118 else:
  125. 119 return None
  126. Total time: 0 s
  127. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  128. Function: find at line 121
  129. Line # Hits Time Per Hit % Time Line Contents
  130. ==============================================================
  131. 121 @dispatch(event="provider.security.vm_firewall_rules.find",
  132. 122 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  133. 123 @profile
  134. 124 def find(self, firewall, **kwargs):
  135. 125 obj_list = firewall.rules
  136. 126 filters = ['name', 'direction', 'protocol', 'from_port', 'to_port',
  137. 127 'cidr', 'src_dest_fw', 'src_dest_fw_id']
  138. 128 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  139. 129 return ClientPagedResultList(self._provider, list(matches))
  140. Total time: 0 s
  141. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  142. Function: find at line 163
  143. Line # Hits Time Per Hit % Time Line Contents
  144. ==============================================================
  145. 163 @dispatch(event="provider.storage.buckets.find",
  146. 164 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  147. 165 @profile
  148. 166 def find(self, **kwargs):
  149. 167 obj_list = self
  150. 168 filters = ['name']
  151. 169 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  152. 170
  153. 171 # All kwargs should have been popped at this time.
  154. 172 if len(kwargs) > 0:
  155. 173 raise InvalidParamException(
  156. 174 "Unrecognised parameters for search: %s. Supported "
  157. 175 "attributes: %s" % (kwargs, ", ".join(filters)))
  158. 176
  159. 177 return ClientPagedResultList(self.provider,
  160. 178 matches if matches else [])
  161. Total time: 0 s
  162. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  163. Function: get at line 218
  164. Line # Hits Time Per Hit % Time Line Contents
  165. ==============================================================
  166. 218 @dispatch(event="provider.compute.vm_types.get",
  167. 219 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  168. 220 @profile
  169. 221 def get(self, vm_type_id):
  170. 222 vm_type = (t for t in self if t.id == vm_type_id)
  171. 223 return next(vm_type, None)
  172. Total time: 0 s
  173. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  174. Function: find at line 225
  175. Line # Hits Time Per Hit % Time Line Contents
  176. ==============================================================
  177. 225 @dispatch(event="provider.compute.vm_types.find",
  178. 226 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  179. 227 @profile
  180. 228 def find(self, **kwargs):
  181. 229 obj_list = self
  182. 230 filters = ['name']
  183. 231 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  184. 232 return ClientPagedResultList(self._provider, list(matches))
  185. Total time: 0 s
  186. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  187. Function: find at line 242
  188. Line # Hits Time Per Hit % Time Line Contents
  189. ==============================================================
  190. 242 @dispatch(event="provider.compute.regions.find",
  191. 243 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  192. 244 @profile
  193. 245 def find(self, **kwargs):
  194. 246 obj_list = self
  195. 247 filters = ['name']
  196. 248 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  197. 249 return ClientPagedResultList(self._provider, list(matches))
  198. Total time: 0 s
  199. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  200. Function: get_or_create_default at line 270
  201. Line # Hits Time Per Hit % Time Line Contents
  202. ==============================================================
  203. 270 @profile
  204. 271 def get_or_create_default(self):
  205. 272 networks = self.provider.networking.networks.find(
  206. 273 label=BaseNetwork.CB_DEFAULT_NETWORK_LABEL)
  207. 274
  208. 275 if networks:
  209. 276 return networks[0]
  210. 277 else:
  211. 278 log.info("Creating a CloudBridge-default network labeled %s",
  212. 279 BaseNetwork.CB_DEFAULT_NETWORK_LABEL)
  213. 280 return self.provider.networking.networks.create(
  214. 281 BaseNetwork.CB_DEFAULT_NETWORK_LABEL, '10.0.0.0/16')
  215. Total time: 0 s
  216. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  217. Function: find at line 283
  218. Line # Hits Time Per Hit % Time Line Contents
  219. ==============================================================
  220. 283 @dispatch(event="provider.networking.networks.find",
  221. 284 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  222. 285 @profile
  223. 286 def find(self, **kwargs):
  224. 287 obj_list = self
  225. 288 filters = ['label']
  226. 289 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  227. 290
  228. 291 # All kwargs should have been popped at this time.
  229. 292 if len(kwargs) > 0:
  230. 293 raise TypeError("Unrecognised parameters for search: %s."
  231. 294 " Supported attributes: %s" % (kwargs,
  232. 295 ", ".join(filters)))
  233. 296
  234. 297 return ClientPagedResultList(self.provider,
  235. 298 matches if matches else [])
  236. Total time: 0 s
  237. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  238. Function: find at line 308
  239. Line # Hits Time Per Hit % Time Line Contents
  240. ==============================================================
  241. 308 @dispatch(event="provider.networking.subnets.find",
  242. 309 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  243. 310 @profile
  244. 311 def find(self, network=None, **kwargs):
  245. 312 if not network:
  246. 313 obj_list = self
  247. 314 else:
  248. 315 obj_list = network.subnets
  249. 316 filters = ['label']
  250. 317 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  251. 318 return ClientPagedResultList(self._provider, list(matches))
  252. Total time: 3.50781 s
  253. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  254. Function: get_or_create_default at line 320
  255. Line # Hits Time Per Hit % Time Line Contents
  256. ==============================================================
  257. 320 @profile
  258. 321 def get_or_create_default(self, zone):
  259. 322 # Look for a CB-default subnet
  260. 323 2 3507803.0 1753901.5 100.0 matches = self.find(label=BaseSubnet.CB_DEFAULT_SUBNET_LABEL)
  261. 324 2 2.0 1.0 0.0 if matches:
  262. 325 2 3.0 1.5 0.0 return matches[0]
  263. 326
  264. 327 # No provider-default Subnet exists, try to create it (net + subnets)
  265. 328 network = self.provider.networking.networks.get_or_create_default()
  266. 329 subnet = self.create(BaseSubnet.CB_DEFAULT_SUBNET_LABEL, network,
  267. 330 BaseSubnet.CB_DEFAULT_SUBNET_IPV4RANGE, zone)
  268. 331 return subnet
  269. Total time: 0 s
  270. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  271. Function: get_or_create_default at line 341
  272. Line # Hits Time Per Hit % Time Line Contents
  273. ==============================================================
  274. 341 @profile
  275. 342 def get_or_create_default(self, network):
  276. 343 net_id = network.id if isinstance(network, Network) else network
  277. 344 routers = self.provider.networking.routers.find(
  278. 345 label=BaseRouter.CB_DEFAULT_ROUTER_LABEL)
  279. 346 for router in routers:
  280. 347 if router.network_id == net_id:
  281. 348 return router
  282. 349 else:
  283. 350 return self.provider.networking.routers.create(
  284. 351 network=net_id, label=BaseRouter.CB_DEFAULT_ROUTER_LABEL)
  285. Total time: 0 s
  286. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  287. Function: find at line 375
  288. Line # Hits Time Per Hit % Time Line Contents
  289. ==============================================================
  290. 375 @dispatch(event="provider.networking.floating_ips.find",
  291. 376 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  292. 377 @profile
  293. 378 def find(self, gateway, **kwargs):
  294. 379 obj_list = gateway.floating_ips
  295. 380 filters = ['name', 'public_ip']
  296. 381 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  297. 382 return ClientPagedResultList(self._provider, list(matches))
  298. Total time: 0 s
  299. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  300. Function: label at line 88
  301. Line # Hits Time Per Hit % Time Line Contents
  302. ==============================================================
  303. 88 @label.setter
  304. 89 # pylint:disable=arguments-differ
  305. 90 @profile
  306. 91 def label(self, value):
  307. 92 self.assert_valid_resource_label(value)
  308. 93 self._ec2_image.create_tags(Tags=[{'Key': 'Name',
  309. 94 'Value': value or ""}])
  310. Total time: 0 s
  311. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  312. Function: refresh at line 134
  313. Line # Hits Time Per Hit % Time Line Contents
  314. ==============================================================
  315. 134 @profile
  316. 135 def refresh(self):
  317. 136 self._ec2_image.reload()
  318. Total time: 0 s
  319. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  320. Function: label at line 254
  321. Line # Hits Time Per Hit % Time Line Contents
  322. ==============================================================
  323. 254 @label.setter
  324. 255 # pylint:disable=arguments-differ
  325. 256 @profile
  326. 257 def label(self, value):
  327. 258 self.assert_valid_resource_label(value)
  328. 259 self._ec2_instance.create_tags(Tags=[{'Key': 'Name',
  329. 260 'Value': value or ""}])
  330. Total time: 0 s
  331. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  332. Function: refresh at line 376
  333. Line # Hits Time Per Hit % Time Line Contents
  334. ==============================================================
  335. 376 @profile
  336. 377 def refresh(self):
  337. 378 try:
  338. 379 self._ec2_instance.reload()
  339. 380 self._unknown_state = False
  340. 381 except ClientError:
  341. 382 # The instance no longer exists and cannot be refreshed.
  342. 383 # set the state to unknown
  343. 384 self._unknown_state = True
  344. Total time: 0 s
  345. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  346. Function: label at line 426
  347. Line # Hits Time Per Hit % Time Line Contents
  348. ==============================================================
  349. 426 @label.setter
  350. 427 # pylint:disable=arguments-differ
  351. 428 @profile
  352. 429 def label(self, value):
  353. 430 self.assert_valid_resource_label(value)
  354. 431 self._volume.create_tags(Tags=[{'Key': 'Name', 'Value': value or ""}])
  355. Total time: 0 s
  356. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  357. Function: description at line 437
  358. Line # Hits Time Per Hit % Time Line Contents
  359. ==============================================================
  360. 437 @description.setter
  361. 438 @profile
  362. 439 def description(self, value):
  363. 440 self._volume.create_tags(Tags=[{'Key': 'Description',
  364. 441 'Value': value or ""}])
  365. Total time: 0 s
  366. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  367. Function: refresh at line 509
  368. Line # Hits Time Per Hit % Time Line Contents
  369. ==============================================================
  370. 509 @profile
  371. 510 def refresh(self):
  372. 511 try:
  373. 512 self._volume.reload()
  374. 513 self._unknown_state = False
  375. 514 except ClientError:
  376. 515 # The volume no longer exists and cannot be refreshed.
  377. 516 # set the status to unknown
  378. 517 self._unknown_state = True
  379. Total time: 0 s
  380. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  381. Function: label at line 552
  382. Line # Hits Time Per Hit % Time Line Contents
  383. ==============================================================
  384. 552 @label.setter
  385. 553 # pylint:disable=arguments-differ
  386. 554 @profile
  387. 555 def label(self, value):
  388. 556 self.assert_valid_resource_label(value)
  389. 557 self._snapshot.create_tags(Tags=[{'Key': 'Name',
  390. 558 'Value': value or ""}])
  391. Total time: 0 s
  392. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  393. Function: description at line 564
  394. Line # Hits Time Per Hit % Time Line Contents
  395. ==============================================================
  396. 564 @description.setter
  397. 565 @profile
  398. 566 def description(self, value):
  399. 567 self._snapshot.create_tags(Tags=[{
  400. 568 'Key': 'Description', 'Value': value or ""}])
  401. Total time: 0 s
  402. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  403. Function: refresh at line 593
  404. Line # Hits Time Per Hit % Time Line Contents
  405. ==============================================================
  406. 593 @profile
  407. 594 def refresh(self):
  408. 595 try:
  409. 596 self._snapshot.reload()
  410. 597 self._unknown_state = False
  411. 598 except ClientError:
  412. 599 # The snapshot no longer exists and cannot be refreshed.
  413. 600 # set the status to unknown
  414. 601 self._unknown_state = True
  415. Total time: 0 s
  416. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  417. Function: label at line 640
  418. Line # Hits Time Per Hit % Time Line Contents
  419. ==============================================================
  420. 640 @label.setter
  421. 641 # pylint:disable=arguments-differ
  422. 642 @profile
  423. 643 def label(self, value):
  424. 644 self.assert_valid_resource_label(value)
  425. 645 self._vm_firewall.create_tags(Tags=[{'Key': 'Name',
  426. 646 'Value': value or ""}])
  427. Total time: 0 s
  428. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  429. Function: description at line 655
  430. Line # Hits Time Per Hit % Time Line Contents
  431. ==============================================================
  432. 655 @description.setter
  433. 656 # pylint:disable=arguments-differ
  434. 657 @profile
  435. 658 def description(self, value):
  436. 659 self._vm_firewall.create_tags(Tags=[{'Key': 'Description',
  437. 660 'Value': value or ""}])
  438. Total time: 0 s
  439. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  440. Function: refresh at line 670
  441. Line # Hits Time Per Hit % Time Line Contents
  442. ==============================================================
  443. 670 @profile
  444. 671 def refresh(self):
  445. 672 self._vm_firewall.reload()
  446. Total time: 0 s
  447. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  448. Function: refresh at line 814
  449. Line # Hits Time Per Hit % Time Line Contents
  450. ==============================================================
  451. 814 @profile
  452. 815 def refresh(self):
  453. 816 self._obj.load()
  454. Total time: 0 s
  455. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  456. Function: label at line 896
  457. Line # Hits Time Per Hit % Time Line Contents
  458. ==============================================================
  459. 896 @label.setter
  460. 897 # pylint:disable=arguments-differ
  461. 898 @profile
  462. 899 def label(self, value):
  463. 900 self.assert_valid_resource_label(value)
  464. 901 self._vpc.create_tags(Tags=[{'Key': 'Name', 'Value': value or ""}])
  465. Total time: 0 s
  466. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  467. Function: refresh at line 930
  468. Line # Hits Time Per Hit % Time Line Contents
  469. ==============================================================
  470. 930 @profile
  471. 931 def refresh(self):
  472. 932 try:
  473. 933 self._vpc.reload()
  474. 934 self._unknown_state = False
  475. 935 except ClientError:
  476. 936 # The network no longer exists and cannot be refreshed.
  477. 937 # set the status to unknown
  478. 938 self._unknown_state = True
  479. Total time: 0 s
  480. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  481. Function: label at line 975
  482. Line # Hits Time Per Hit % Time Line Contents
  483. ==============================================================
  484. 975 @label.setter
  485. 976 # pylint:disable=arguments-differ
  486. 977 @profile
  487. 978 def label(self, value):
  488. 979 self.assert_valid_resource_label(value)
  489. 980 self._subnet.create_tags(Tags=[{'Key': 'Name', 'Value': value or ""}])
  490. Total time: 0 s
  491. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  492. Function: refresh at line 1006
  493. Line # Hits Time Per Hit % Time Line Contents
  494. ==============================================================
  495. 1006 @profile
  496. 1007 def refresh(self):
  497. 1008 try:
  498. 1009 self._subnet.reload()
  499. 1010 self._unknown_state = False
  500. 1011 except ClientError:
  501. 1012 # subnet no longer exists
  502. 1013 self._unknown_state = True
  503. Total time: 0 s
  504. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  505. Function: refresh at line 1038
  506. Line # Hits Time Per Hit % Time Line Contents
  507. ==============================================================
  508. 1038 @profile
  509. 1039 def refresh(self):
  510. 1040 self._ip.reload()
  511. Total time: 0 s
  512. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  513. Function: label at line 1061
  514. Line # Hits Time Per Hit % Time Line Contents
  515. ==============================================================
  516. 1061 @label.setter
  517. 1062 # pylint:disable=arguments-differ
  518. 1063 @profile
  519. 1064 def label(self, value):
  520. 1065 self.assert_valid_resource_label(value)
  521. 1066 self._route_table.create_tags(Tags=[{'Key': 'Name',
  522. 1067 'Value': value or ""}])
  523. Total time: 0 s
  524. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  525. Function: refresh at line 1069
  526. Line # Hits Time Per Hit % Time Line Contents
  527. ==============================================================
  528. 1069 @profile
  529. 1070 def refresh(self):
  530. 1071 try:
  531. 1072 self._route_table.reload()
  532. 1073 except ClientError:
  533. 1074 self._route_table.associations = None
  534. Total time: 0 s
  535. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  536. Function: refresh at line 1135
  537. Line # Hits Time Per Hit % Time Line Contents
  538. ==============================================================
  539. 1135 @profile
  540. 1136 def refresh(self):
  541. 1137 try:
  542. 1138 self._gateway.reload()
  543. 1139 except ClientError:
  544. 1140 self._gateway.state = GatewayState.UNKNOWN
  545. Total time: 0 s
  546. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  547. Function: get at line 106
  548. Line # Hits Time Per Hit % Time Line Contents
  549. ==============================================================
  550. 106 @dispatch(event="provider.security.key_pairs.get",
  551. 107 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  552. 108 @profile
  553. 109 def get(self, key_pair_id):
  554. 110 log.debug("Getting Key Pair Service %s", key_pair_id)
  555. 111 return self.svc.get(key_pair_id)
  556. Total time: 0 s
  557. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  558. Function: list at line 113
  559. Line # Hits Time Per Hit % Time Line Contents
  560. ==============================================================
  561. 113 @dispatch(event="provider.security.key_pairs.list",
  562. 114 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  563. 115 @profile
  564. 116 def list(self, limit=None, marker=None):
  565. 117 return self.svc.list(limit=limit, marker=marker)
  566. Total time: 0 s
  567. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  568. Function: find at line 119
  569. Line # Hits Time Per Hit % Time Line Contents
  570. ==============================================================
  571. 119 @dispatch(event="provider.security.key_pairs.find",
  572. 120 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  573. 121 @profile
  574. 122 def find(self, **kwargs):
  575. 123 name = kwargs.pop('name', None)
  576. 124
  577. 125 # All kwargs should have been popped at this time.
  578. 126 if len(kwargs) > 0:
  579. 127 raise InvalidParamException(
  580. 128 "Unrecognised parameters for search: %s. Supported "
  581. 129 "attributes: %s" % (kwargs, 'name'))
  582. 130
  583. 131 log.debug("Searching for Key Pair %s", name)
  584. 132 return self.svc.find(filter_name='key-name', filter_value=name)
  585. Total time: 0 s
  586. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  587. Function: create at line 134
  588. Line # Hits Time Per Hit % Time Line Contents
  589. ==============================================================
  590. 134 @dispatch(event="provider.security.key_pairs.create",
  591. 135 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  592. 136 @profile
  593. 137 def create(self, name, public_key_material=None):
  594. 138 AWSKeyPair.assert_valid_resource_name(name)
  595. 139 private_key = None
  596. 140 if not public_key_material:
  597. 141 public_key_material, private_key = cb_helpers.generate_key_pair()
  598. 142 try:
  599. 143 kp = self.svc.create('import_key_pair', KeyName=name,
  600. 144 PublicKeyMaterial=public_key_material)
  601. 145 kp.material = private_key
  602. 146 return kp
  603. 147 except ClientError as e:
  604. 148 if e.response['Error']['Code'] == 'InvalidKeyPair.Duplicate':
  605. 149 raise DuplicateResourceException(
  606. 150 'Keypair already exists with name {0}'.format(name))
  607. 151 else:
  608. 152 raise e
  609. Total time: 0 s
  610. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  611. Function: delete at line 154
  612. Line # Hits Time Per Hit % Time Line Contents
  613. ==============================================================
  614. 154 @dispatch(event="provider.security.key_pairs.delete",
  615. 155 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  616. 156 @profile
  617. 157 def delete(self, key_pair):
  618. 158 key_pair = (key_pair if isinstance(key_pair, AWSKeyPair) else
  619. 159 self.get(key_pair))
  620. 160 if key_pair:
  621. 161 # pylint:disable=protected-access
  622. 162 key_pair._key_pair.delete()
  623. Total time: 0 s
  624. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  625. Function: get at line 173
  626. Line # Hits Time Per Hit % Time Line Contents
  627. ==============================================================
  628. 173 @dispatch(event="provider.security.vm_firewalls.get",
  629. 174 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  630. 175 @profile
  631. 176 def get(self, vm_firewall_id):
  632. 177 log.debug("Getting Firewall Service with the id: %s", vm_firewall_id)
  633. 178 return self.svc.get(vm_firewall_id)
  634. Total time: 0 s
  635. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  636. Function: list at line 180
  637. Line # Hits Time Per Hit % Time Line Contents
  638. ==============================================================
  639. 180 @dispatch(event="provider.security.vm_firewalls.list",
  640. 181 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  641. 182 @profile
  642. 183 def list(self, limit=None, marker=None):
  643. 184 return self.svc.list(limit=limit, marker=marker)
  644. Total time: 0 s
  645. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  646. Function: create at line 186
  647. Line # Hits Time Per Hit % Time Line Contents
  648. ==============================================================
  649. 186 @cb_helpers.deprecated_alias(network_id='network')
  650. 187 @dispatch(event="provider.security.vm_firewalls.create",
  651. 188 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  652. 189 @profile
  653. 190 def create(self, label, network, description=None):
  654. 191 AWSVMFirewall.assert_valid_resource_label(label)
  655. 192 name = AWSVMFirewall._generate_name_from_label(label, 'cb-fw')
  656. 193 network_id = network.id if isinstance(network, Network) else network
  657. 194 obj = self.svc.create('create_security_group', GroupName=name,
  658. 195 Description=name,
  659. 196 VpcId=network_id)
  660. 197 obj.label = label
  661. 198 obj.description = description
  662. 199 return obj
  663. Total time: 0 s
  664. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  665. Function: find at line 201
  666. Line # Hits Time Per Hit % Time Line Contents
  667. ==============================================================
  668. 201 @dispatch(event="provider.security.vm_firewalls.find",
  669. 202 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  670. 203 @profile
  671. 204 def find(self, **kwargs):
  672. 205 # Filter by name or label
  673. 206 label = kwargs.pop('label', None)
  674. 207 log.debug("Searching for Firewall Service %s", label)
  675. 208 # All kwargs should have been popped at this time.
  676. 209 if len(kwargs) > 0:
  677. 210 raise InvalidParamException(
  678. 211 "Unrecognised parameters for search: %s. Supported "
  679. 212 "attributes: %s" % (kwargs, 'label'))
  680. 213 return self.svc.find(filter_name='tag:Name',
  681. 214 filter_value=label)
  682. Total time: 0 s
  683. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  684. Function: delete at line 216
  685. Line # Hits Time Per Hit % Time Line Contents
  686. ==============================================================
  687. 216 @dispatch(event="provider.security.vm_firewalls.delete",
  688. 217 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  689. 218 @profile
  690. 219 def delete(self, vm_firewall):
  691. 220 firewall = (vm_firewall if isinstance(vm_firewall, AWSVMFirewall)
  692. 221 else self.get(vm_firewall))
  693. 222 if firewall:
  694. 223 # pylint:disable=protected-access
  695. 224 firewall._vm_firewall.delete()
  696. Total time: 0 s
  697. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  698. Function: list at line 232
  699. Line # Hits Time Per Hit % Time Line Contents
  700. ==============================================================
  701. 232 @dispatch(event="provider.security.vm_firewall_rules.list",
  702. 233 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  703. 234 @profile
  704. 235 def list(self, firewall, limit=None, marker=None):
  705. 236 # pylint:disable=protected-access
  706. 237 rules = [AWSVMFirewallRule(firewall,
  707. 238 TrafficDirection.INBOUND, r)
  708. 239 for r in firewall._vm_firewall.ip_permissions]
  709. 240 # pylint:disable=protected-access
  710. 241 rules = rules + [
  711. 242 AWSVMFirewallRule(
  712. 243 firewall, TrafficDirection.OUTBOUND, r)
  713. 244 for r in firewall._vm_firewall.ip_permissions_egress]
  714. 245 return ClientPagedResultList(self.provider, rules,
  715. 246 limit=limit, marker=marker)
  716. Total time: 0 s
  717. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  718. Function: create at line 248
  719. Line # Hits Time Per Hit % Time Line Contents
  720. ==============================================================
  721. 248 @dispatch(event="provider.security.vm_firewall_rules.create",
  722. 249 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  723. 250 @profile
  724. 251 def create(self, firewall, direction, protocol=None, from_port=None,
  725. 252 to_port=None, cidr=None, src_dest_fw=None):
  726. 253 src_dest_fw_id = (
  727. 254 src_dest_fw.id if isinstance(src_dest_fw, AWSVMFirewall)
  728. 255 else src_dest_fw)
  729. 256
  730. 257 # pylint:disable=protected-access
  731. 258 ip_perm_entry = AWSVMFirewallRule._construct_ip_perms(
  732. 259 protocol, from_port, to_port, cidr, src_dest_fw_id)
  733. 260 # Filter out empty values to please Boto
  734. 261 ip_perms = [trim_empty_params(ip_perm_entry)]
  735. 262
  736. 263 try:
  737. 264 if direction == TrafficDirection.INBOUND:
  738. 265 # pylint:disable=protected-access
  739. 266 firewall._vm_firewall.authorize_ingress(
  740. 267 IpPermissions=ip_perms)
  741. 268 elif direction == TrafficDirection.OUTBOUND:
  742. 269 # pylint:disable=protected-access
  743. 270 firewall._vm_firewall.authorize_egress(
  744. 271 IpPermissions=ip_perms)
  745. 272 else:
  746. 273 raise InvalidValueException("direction", direction)
  747. 274 firewall.refresh()
  748. 275 return AWSVMFirewallRule(firewall, direction, ip_perm_entry)
  749. 276 except ClientError as ec2e:
  750. 277 if ec2e.response['Error']['Code'] == "InvalidPermission.Duplicate":
  751. 278 return AWSVMFirewallRule(
  752. 279 firewall, direction, ip_perm_entry)
  753. 280 else:
  754. 281 raise ec2e
  755. Total time: 0 s
  756. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  757. Function: delete at line 283
  758. Line # Hits Time Per Hit % Time Line Contents
  759. ==============================================================
  760. 283 @dispatch(event="provider.security.vm_firewall_rules.delete",
  761. 284 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  762. 285 @profile
  763. 286 def delete(self, firewall, rule):
  764. 287 # pylint:disable=protected-access
  765. 288 ip_perm_entry = rule._construct_ip_perms(
  766. 289 rule.protocol, rule.from_port, rule.to_port,
  767. 290 rule.cidr, rule.src_dest_fw_id)
  768. 291
  769. 292 # Filter out empty values to please Boto
  770. 293 ip_perms = [trim_empty_params(ip_perm_entry)]
  771. 294
  772. 295 # pylint:disable=protected-access
  773. 296 if rule.direction == TrafficDirection.INBOUND:
  774. 297 firewall._vm_firewall.revoke_ingress(
  775. 298 IpPermissions=ip_perms)
  776. 299 else:
  777. 300 # pylint:disable=protected-access
  778. 301 firewall._vm_firewall.revoke_egress(
  779. 302 IpPermissions=ip_perms)
  780. 303 firewall.refresh()
  781. Total time: 0 s
  782. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  783. Function: get at line 342
  784. Line # Hits Time Per Hit % Time Line Contents
  785. ==============================================================
  786. 342 @dispatch(event="provider.storage.volumes.get",
  787. 343 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  788. 344 @profile
  789. 345 def get(self, volume_id):
  790. 346 return self.svc.get(volume_id)
  791. Total time: 0 s
  792. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  793. Function: find at line 348
  794. Line # Hits Time Per Hit % Time Line Contents
  795. ==============================================================
  796. 348 @dispatch(event="provider.storage.volumes.find",
  797. 349 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  798. 350 @profile
  799. 351 def find(self, **kwargs):
  800. 352 label = kwargs.pop('label', None)
  801. 353
  802. 354 # All kwargs should have been popped at this time.
  803. 355 if len(kwargs) > 0:
  804. 356 raise InvalidParamException(
  805. 357 "Unrecognised parameters for search: %s. Supported "
  806. 358 "attributes: %s" % (kwargs, 'label'))
  807. 359
  808. 360 log.debug("Searching for AWS Volume Service %s", label)
  809. 361 return self.svc.find(filter_name='tag:Name', filter_value=label)
  810. Total time: 0 s
  811. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  812. Function: list at line 363
  813. Line # Hits Time Per Hit % Time Line Contents
  814. ==============================================================
  815. 363 @dispatch(event="provider.storage.volumes.list",
  816. 364 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  817. 365 @profile
  818. 366 def list(self, limit=None, marker=None):
  819. 367 return self.svc.list(limit=limit, marker=marker)
  820. Total time: 0 s
  821. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  822. Function: create at line 369
  823. Line # Hits Time Per Hit % Time Line Contents
  824. ==============================================================
  825. 369 @dispatch(event="provider.storage.volumes.create",
  826. 370 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  827. 371 @profile
  828. 372 def create(self, label, size, zone, snapshot=None, description=None):
  829. 373 AWSVolume.assert_valid_resource_label(label)
  830. 374 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  831. 375 snapshot_id = snapshot.id if isinstance(
  832. 376 snapshot, AWSSnapshot) and snapshot else snapshot
  833. 377
  834. 378 cb_vol = self.svc.create('create_volume', Size=size,
  835. 379 AvailabilityZone=zone_id,
  836. 380 SnapshotId=snapshot_id)
  837. 381 # Wait until ready to tag instance
  838. 382 cb_vol.wait_till_ready()
  839. 383 cb_vol.label = label
  840. 384 if description:
  841. 385 cb_vol.description = description
  842. 386 return cb_vol
  843. Total time: 0 s
  844. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  845. Function: delete at line 388
  846. Line # Hits Time Per Hit % Time Line Contents
  847. ==============================================================
  848. 388 @dispatch(event="provider.storage.volumes.delete",
  849. 389 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  850. 390 @profile
  851. 391 def delete(self, vol):
  852. 392 volume = vol if isinstance(vol, AWSVolume) else self.get(vol)
  853. 393 if volume:
  854. 394 # pylint:disable=protected-access
  855. 395 volume._volume.delete()
  856. Total time: 0 s
  857. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  858. Function: get at line 406
  859. Line # Hits Time Per Hit % Time Line Contents
  860. ==============================================================
  861. 406 @dispatch(event="provider.storage.snapshots.get",
  862. 407 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  863. 408 @profile
  864. 409 def get(self, snapshot_id):
  865. 410 return self.svc.get(snapshot_id)
  866. Total time: 0 s
  867. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  868. Function: find at line 412
  869. Line # Hits Time Per Hit % Time Line Contents
  870. ==============================================================
  871. 412 @dispatch(event="provider.storage.snapshots.find",
  872. 413 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  873. 414 @profile
  874. 415 def find(self, **kwargs):
  875. 416 # Filter by description or label
  876. 417 label = kwargs.get('label', None)
  877. 418
  878. 419 obj_list = []
  879. 420 if label:
  880. 421 log.debug("Searching for AWS Snapshot with label %s", label)
  881. 422 obj_list.extend(self.svc.find(filter_name='tag:Name',
  882. 423 filter_value=label,
  883. 424 OwnerIds=['self']))
  884. 425 else:
  885. 426 obj_list = list(self)
  886. 427 filters = ['label']
  887. 428 return cb_helpers.generic_find(filters, kwargs, obj_list)
  888. Total time: 0 s
  889. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  890. Function: list at line 430
  891. Line # Hits Time Per Hit % Time Line Contents
  892. ==============================================================
  893. 430 @dispatch(event="provider.storage.snapshots.list",
  894. 431 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  895. 432 @profile
  896. 433 def list(self, limit=None, marker=None):
  897. 434 return self.svc.list(limit=limit, marker=marker,
  898. 435 OwnerIds=['self'])
  899. Total time: 0 s
  900. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  901. Function: create at line 437
  902. Line # Hits Time Per Hit % Time Line Contents
  903. ==============================================================
  904. 437 @dispatch(event="provider.storage.snapshots.create",
  905. 438 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  906. 439 @profile
  907. 440 def create(self, label, volume, description=None):
  908. 441 AWSSnapshot.assert_valid_resource_label(label)
  909. 442 volume_id = volume.id if isinstance(volume, AWSVolume) else volume
  910. 443
  911. 444 cb_snap = self.svc.create('create_snapshot', VolumeId=volume_id)
  912. 445 # Wait until ready to tag instance
  913. 446 cb_snap.wait_till_ready()
  914. 447 cb_snap.label = label
  915. 448 if cb_snap.description:
  916. 449 cb_snap.description = description
  917. 450 return cb_snap
  918. Total time: 0 s
  919. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  920. Function: delete at line 452
  921. Line # Hits Time Per Hit % Time Line Contents
  922. ==============================================================
  923. 452 @dispatch(event="provider.storage.snapshots.delete",
  924. 453 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  925. 454 @profile
  926. 455 def delete(self, snapshot):
  927. 456 snapshot = (snapshot if isinstance(snapshot, AWSSnapshot) else
  928. 457 self.get(snapshot))
  929. 458 if snapshot:
  930. 459 # pylint:disable=protected-access
  931. 460 snapshot._snapshot.delete()
  932. Total time: 0 s
  933. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  934. Function: get at line 471
  935. Line # Hits Time Per Hit % Time Line Contents
  936. ==============================================================
  937. 471 @dispatch(event="provider.storage.buckets.get",
  938. 472 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  939. 473 @profile
  940. 474 def get(self, bucket_id):
  941. 475 """
  942. 476 Returns a bucket given its ID. Returns ``None`` if the bucket
  943. 477 does not exist.
  944. 478 """
  945. 479 try:
  946. 480 # Make a call to make sure the bucket exists. There's an edge case
  947. 481 # where a 403 response can occur when the bucket exists but the
  948. 482 # user simply does not have permissions to access it. See below.
  949. 483 self.provider.s3_conn.meta.client.head_bucket(Bucket=bucket_id)
  950. 484 return AWSBucket(self.provider,
  951. 485 self.provider.s3_conn.Bucket(bucket_id))
  952. 486 except ClientError as e:
  953. 487 # If 403, it means the bucket exists, but the user does not have
  954. 488 # permissions to access the bucket. However, limited operations
  955. 489 # may be permitted (with a session token for example), so return a
  956. 490 # Bucket instance to allow further operations.
  957. 491 # http://stackoverflow.com/questions/32331456/using-boto-upload-file-to-s3-
  958. 492 # sub-folder-when-i-have-no-permissions-on-listing-fo
  959. 493 if e.response['Error']['Code'] == "403":
  960. 494 log.warning("AWS Bucket %s already exists but user doesn't "
  961. 495 "have enough permissions to access the bucket",
  962. 496 bucket_id)
  963. 497 return AWSBucket(self.provider,
  964. 498 self.provider.s3_conn.Bucket(bucket_id))
  965. 499 # For all other responses, it's assumed that the bucket does not exist.
  966. 500 return None
  967. Total time: 0 s
  968. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  969. Function: list at line 502
  970. Line # Hits Time Per Hit % Time Line Contents
  971. ==============================================================
  972. 502 @dispatch(event="provider.storage.buckets.list",
  973. 503 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  974. 504 @profile
  975. 505 def list(self, limit=None, marker=None):
  976. 506 return self.svc.list(limit=limit, marker=marker)
  977. Total time: 0 s
  978. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  979. Function: create at line 508
  980. Line # Hits Time Per Hit % Time Line Contents
  981. ==============================================================
  982. 508 @dispatch(event="provider.storage.buckets.create",
  983. 509 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  984. 510 @profile
  985. 511 def create(self, name, location=None):
  986. 512 AWSBucket.assert_valid_resource_name(name)
  987. 513 location = location or self.provider.region_name
  988. 514 # Due to an API issue in S3, specifying us-east-1 as a
  989. 515 # LocationConstraint results in an InvalidLocationConstraint.
  990. 516 # Therefore, it must be special-cased and omitted altogether.
  991. 517 # See: https://github.com/boto/boto3/issues/125
  992. 518 # In addition, us-east-1 also behaves differently when it comes
  993. 519 # to raising duplicate resource exceptions, so perform a manual
  994. 520 # check
  995. 521 if location == 'us-east-1':
  996. 522 try:
  997. 523 # check whether bucket already exists
  998. 524 self.provider.s3_conn.meta.client.head_bucket(Bucket=name)
  999. 525 except ClientError as e:
  1000. 526 if e.response['Error']['Code'] == "404":
  1001. 527 # bucket doesn't exist, go ahead and create it
  1002. 528 return self.svc.create('create_bucket', Bucket=name)
  1003. 529 raise DuplicateResourceException(
  1004. 530 'Bucket already exists with name {0}'.format(name))
  1005. 531 else:
  1006. 532 try:
  1007. 533 return self.svc.create('create_bucket', Bucket=name,
  1008. 534 CreateBucketConfiguration={
  1009. 535 'LocationConstraint': location
  1010. 536 })
  1011. 537 except ClientError as e:
  1012. 538 if e.response['Error']['Code'] == "BucketAlreadyOwnedByYou":
  1013. 539 raise DuplicateResourceException(
  1014. 540 'Bucket already exists with name {0}'.format(name))
  1015. 541 else:
  1016. 542 raise
  1017. Total time: 0 s
  1018. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1019. Function: delete at line 544
  1020. Line # Hits Time Per Hit % Time Line Contents
  1021. ==============================================================
  1022. 544 @dispatch(event="provider.storage.buckets.delete",
  1023. 545 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  1024. 546 @profile
  1025. 547 def delete(self, bucket):
  1026. 548 b = bucket if isinstance(bucket, AWSBucket) else self.get(bucket)
  1027. 549 if b:
  1028. 550 # pylint:disable=protected-access
  1029. 551 b._bucket.delete()
  1030. Total time: 0 s
  1031. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1032. Function: get at line 559
  1033. Line # Hits Time Per Hit % Time Line Contents
  1034. ==============================================================
  1035. 559 @profile
  1036. 560 def get(self, bucket, object_id):
  1037. 561 try:
  1038. 562 # pylint:disable=protected-access
  1039. 563 obj = bucket._bucket.Object(object_id)
  1040. 564 # load() throws an error if object does not exist
  1041. 565 obj.load()
  1042. 566 return AWSBucketObject(self.provider, obj)
  1043. 567 except ClientError:
  1044. 568 return None
  1045. Total time: 0 s
  1046. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1047. Function: list at line 570
  1048. Line # Hits Time Per Hit % Time Line Contents
  1049. ==============================================================
  1050. 570 @profile
  1051. 571 def list(self, bucket, limit=None, marker=None, prefix=None):
  1052. 572 if prefix:
  1053. 573 # pylint:disable=protected-access
  1054. 574 boto_objs = bucket._bucket.objects.filter(Prefix=prefix)
  1055. 575 else:
  1056. 576 # pylint:disable=protected-access
  1057. 577 boto_objs = bucket._bucket.objects.all()
  1058. 578 objects = [AWSBucketObject(self.provider, obj) for obj in boto_objs]
  1059. 579 return ClientPagedResultList(self.provider, objects,
  1060. 580 limit=limit, marker=marker)
  1061. Total time: 0 s
  1062. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1063. Function: find at line 582
  1064. Line # Hits Time Per Hit % Time Line Contents
  1065. ==============================================================
  1066. 582 @profile
  1067. 583 def find(self, bucket, **kwargs):
  1068. 584 # pylint:disable=protected-access
  1069. 585 obj_list = [AWSBucketObject(self.provider, o)
  1070. 586 for o in bucket._bucket.objects.all()]
  1071. 587 filters = ['name']
  1072. 588 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  1073. 589 return ClientPagedResultList(self.provider, list(matches),
  1074. 590 limit=None, marker=None)
  1075. Total time: 0 s
  1076. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1077. Function: create at line 592
  1078. Line # Hits Time Per Hit % Time Line Contents
  1079. ==============================================================
  1080. 592 @profile
  1081. 593 def create(self, bucket, name):
  1082. 594 # pylint:disable=protected-access
  1083. 595 obj = bucket._bucket.Object(name)
  1084. 596 return AWSBucketObject(self.provider, obj)
  1085. Total time: 0 s
  1086. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1087. Function: get at line 633
  1088. Line # Hits Time Per Hit % Time Line Contents
  1089. ==============================================================
  1090. 633 @profile
  1091. 634 def get(self, image_id):
  1092. 635 log.debug("Getting AWS Image Service with the id: %s", image_id)
  1093. 636 return self.svc.get(image_id)
  1094. Total time: 0 s
  1095. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1096. Function: find at line 638
  1097. Line # Hits Time Per Hit % Time Line Contents
  1098. ==============================================================
  1099. 638 @profile
  1100. 639 def find(self, **kwargs):
  1101. 640 # Filter by name or label
  1102. 641 label = kwargs.pop('label', None)
  1103. 642 # Popped here, not used in the generic find
  1104. 643 owner = kwargs.pop('owners', None)
  1105. 644
  1106. 645 # All kwargs should have been popped at this time.
  1107. 646 if len(kwargs) > 0:
  1108. 647 raise InvalidParamException(
  1109. 648 "Unrecognised parameters for search: %s. Supported "
  1110. 649 "attributes: %s" % (kwargs, 'label'))
  1111. 650
  1112. 651 extra_args = {}
  1113. 652 if owner:
  1114. 653 extra_args.update(Owners=owner)
  1115. 654
  1116. 655 # The original list is made by combining both searches by "tag:Name"
  1117. 656 # and "AMI name" to allow for searches of public images
  1118. 657 if label:
  1119. 658 log.debug("Searching for AWS Image Service %s", label)
  1120. 659 obj_list = []
  1121. 660 obj_list.extend(self.svc.find(filter_name='name',
  1122. 661 filter_value=label, **extra_args))
  1123. 662 obj_list.extend(self.svc.find(filter_name='tag:Name',
  1124. 663 filter_value=label, **extra_args))
  1125. 664 return obj_list
  1126. 665 else:
  1127. 666 return []
  1128. Total time: 0 s
  1129. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1130. Function: list at line 668
  1131. Line # Hits Time Per Hit % Time Line Contents
  1132. ==============================================================
  1133. 668 @profile
  1134. 669 def list(self, filter_by_owner=True, limit=None, marker=None):
  1135. 670 return self.svc.list(Owners=['self'] if filter_by_owner else
  1136. 671 ['amazon', 'self'],
  1137. 672 limit=limit, marker=marker)
  1138. Total time: 0 s
  1139. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1140. Function: create_launch_config at line 765
  1141. Line # Hits Time Per Hit % Time Line Contents
  1142. ==============================================================
  1143. 765 @profile
  1144. 766 def create_launch_config(self):
  1145. 767 return AWSLaunchConfig(self.provider)
  1146. Total time: 0 s
  1147. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1148. Function: create at line 769
  1149. Line # Hits Time Per Hit % Time Line Contents
  1150. ==============================================================
  1151. 769 @dispatch(event="provider.compute.instances.create",
  1152. 770 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  1153. 771 @profile
  1154. 772 def create(self, label, image, vm_type, subnet, zone,
  1155. 773 key_pair=None, vm_firewalls=None, user_data=None,
  1156. 774 launch_config=None, **kwargs):
  1157. 775 AWSInstance.assert_valid_resource_label(label)
  1158. 776 image_id = image.id if isinstance(image, MachineImage) else image
  1159. 777 vm_size = vm_type.id if \
  1160. 778 isinstance(vm_type, VMType) else vm_type
  1161. 779 subnet = (self.provider.networking.subnets.get(subnet)
  1162. 780 if isinstance(subnet, str) else subnet)
  1163. 781 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  1164. 782 key_pair_name = key_pair.name if isinstance(
  1165. 783 key_pair,
  1166. 784 KeyPair) else key_pair
  1167. 785 if launch_config:
  1168. 786 bdm = self._process_block_device_mappings(launch_config)
  1169. 787 else:
  1170. 788 bdm = None
  1171. 789
  1172. 790 subnet_id, zone_id, vm_firewall_ids = \
  1173. 791 self._resolve_launch_options(subnet, zone_id, vm_firewalls)
  1174. 792
  1175. 793 placement = {'AvailabilityZone': zone_id} if zone_id else None
  1176. 794 inst = self.svc.create('create_instances',
  1177. 795 ImageId=image_id,
  1178. 796 MinCount=1,
  1179. 797 MaxCount=1,
  1180. 798 KeyName=key_pair_name,
  1181. 799 SecurityGroupIds=vm_firewall_ids or None,
  1182. 800 UserData=str(user_data) or None,
  1183. 801 InstanceType=vm_size,
  1184. 802 Placement=placement,
  1185. 803 BlockDeviceMappings=bdm,
  1186. 804 SubnetId=subnet_id
  1187. 805 )
  1188. 806 if inst and len(inst) == 1:
  1189. 807 # Wait until the resource exists
  1190. 808 # pylint:disable=protected-access
  1191. 809 inst[0]._wait_till_exists()
  1192. 810 # Tag the instance w/ the name
  1193. 811 inst[0].label = label
  1194. 812 return inst[0]
  1195. 813 raise ValueError(
  1196. 814 'Expected a single object response, got a list: %s' % inst)
  1197. Total time: 0 s
  1198. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1199. Function: get at line 816
  1200. Line # Hits Time Per Hit % Time Line Contents
  1201. ==============================================================
  1202. 816 @dispatch(event="provider.compute.instances.get",
  1203. 817 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  1204. 818 @profile
  1205. 819 def get(self, instance_id):
  1206. 820 return self.svc.get(instance_id)
  1207. Total time: 0 s
  1208. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1209. Function: find at line 822
  1210. Line # Hits Time Per Hit % Time Line Contents
  1211. ==============================================================
  1212. 822 @dispatch(event="provider.compute.instances.find",
  1213. 823 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  1214. 824 @profile
  1215. 825 def find(self, **kwargs):
  1216. 826 label = kwargs.pop('label', None)
  1217. 827
  1218. 828 # All kwargs should have been popped at this time.
  1219. 829 if len(kwargs) > 0:
  1220. 830 raise InvalidParamException(
  1221. 831 "Unrecognised parameters for search: %s. Supported "
  1222. 832 "attributes: %s" % (kwargs, 'label'))
  1223. 833
  1224. 834 return self.svc.find(filter_name='tag:Name', filter_value=label)
  1225. Total time: 0 s
  1226. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1227. Function: list at line 836
  1228. Line # Hits Time Per Hit % Time Line Contents
  1229. ==============================================================
  1230. 836 @dispatch(event="provider.compute.instances.list",
  1231. 837 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  1232. 838 @profile
  1233. 839 def list(self, limit=None, marker=None):
  1234. 840 return self.svc.list(limit=limit, marker=marker)
  1235. Total time: 0 s
  1236. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1237. Function: delete at line 842
  1238. Line # Hits Time Per Hit % Time Line Contents
  1239. ==============================================================
  1240. 842 @dispatch(event="provider.compute.instances.delete",
  1241. 843 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  1242. 844 @profile
  1243. 845 def delete(self, instance):
  1244. 846 aws_inst = (instance if isinstance(instance, AWSInstance) else
  1245. 847 self.get(instance))
  1246. 848 if aws_inst:
  1247. 849 # pylint:disable=protected-access
  1248. 850 aws_inst._ec2_instance.terminate()
  1249. Total time: 0 s
  1250. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1251. Function: list at line 881
  1252. Line # Hits Time Per Hit % Time Line Contents
  1253. ==============================================================
  1254. 881 @dispatch(event="provider.compute.vm_types.list",
  1255. 882 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  1256. 883 @profile
  1257. 884 def list(self, limit=None, marker=None):
  1258. 885 vm_types = [AWSVMType(self.provider, vm_type)
  1259. 886 for vm_type in self.instance_data]
  1260. 887 return ClientPagedResultList(self.provider, vm_types,
  1261. 888 limit=limit, marker=marker)
  1262. Total time: 0 s
  1263. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1264. Function: get at line 896
  1265. Line # Hits Time Per Hit % Time Line Contents
  1266. ==============================================================
  1267. 896 @dispatch(event="provider.compute.regions.get",
  1268. 897 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  1269. 898 @profile
  1270. 899 def get(self, region_id):
  1271. 900 log.debug("Getting AWS Region Service with the id: %s",
  1272. 901 region_id)
  1273. 902 region = [r for r in self if r.id == region_id]
  1274. 903 if region:
  1275. 904 return region[0]
  1276. 905 else:
  1277. 906 return None
  1278. Total time: 0 s
  1279. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1280. Function: list at line 908
  1281. Line # Hits Time Per Hit % Time Line Contents
  1282. ==============================================================
  1283. 908 @dispatch(event="provider.compute.regions.list",
  1284. 909 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  1285. 910 @profile
  1286. 911 def list(self, limit=None, marker=None):
  1287. 912 regions = [
  1288. 913 AWSRegion(self.provider, region) for region in
  1289. 914 self.provider.ec2_conn.meta.client.describe_regions()
  1290. 915 .get('Regions', [])]
  1291. 916 return ClientPagedResultList(self.provider, regions,
  1292. 917 limit=limit, marker=marker)
  1293. Total time: 0 s
  1294. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1295. Function: get at line 963
  1296. Line # Hits Time Per Hit % Time Line Contents
  1297. ==============================================================
  1298. 963 @dispatch(event="provider.networking.networks.get",
  1299. 964 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  1300. 965 @profile
  1301. 966 def get(self, network_id):
  1302. 967 return self.svc.get(network_id)
  1303. Total time: 0 s
  1304. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1305. Function: list at line 969
  1306. Line # Hits Time Per Hit % Time Line Contents
  1307. ==============================================================
  1308. 969 @dispatch(event="provider.networking.networks.list",
  1309. 970 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  1310. 971 @profile
  1311. 972 def list(self, limit=None, marker=None):
  1312. 973 return self.svc.list(limit=limit, marker=marker)
  1313. Total time: 0 s
  1314. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1315. Function: find at line 975
  1316. Line # Hits Time Per Hit % Time Line Contents
  1317. ==============================================================
  1318. 975 @dispatch(event="provider.networking.networks.find",
  1319. 976 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  1320. 977 @profile
  1321. 978 def find(self, **kwargs):
  1322. 979 label = kwargs.pop('label', None)
  1323. 980
  1324. 981 # All kwargs should have been popped at this time.
  1325. 982 if len(kwargs) > 0:
  1326. 983 raise InvalidParamException(
  1327. 984 "Unrecognised parameters for search: %s. Supported "
  1328. 985 "attributes: %s" % (kwargs, 'label'))
  1329. 986
  1330. 987 log.debug("Searching for AWS Network Service %s", label)
  1331. 988 return self.svc.find(filter_name='tag:Name', filter_value=label)
  1332. Total time: 0 s
  1333. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1334. Function: create at line 990
  1335. Line # Hits Time Per Hit % Time Line Contents
  1336. ==============================================================
  1337. 990 @dispatch(event="provider.networking.networks.create",
  1338. 991 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  1339. 992 @profile
  1340. 993 def create(self, label, cidr_block):
  1341. 994 AWSNetwork.assert_valid_resource_label(label)
  1342. 995
  1343. 996 cb_net = self.svc.create('create_vpc', CidrBlock=cidr_block)
  1344. 997 # Wait until ready to tag instance
  1345. 998 cb_net.wait_till_ready()
  1346. 999 if label:
  1347. 1000 cb_net.label = label
  1348. 1001 return cb_net
  1349. Total time: 0 s
  1350. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1351. Function: delete at line 1003
  1352. Line # Hits Time Per Hit % Time Line Contents
  1353. ==============================================================
  1354. 1003 @dispatch(event="provider.networking.networks.delete",
  1355. 1004 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  1356. 1005 @profile
  1357. 1006 def delete(self, network):
  1358. 1007 network = (network if isinstance(network, AWSNetwork)
  1359. 1008 else self.get(network))
  1360. 1009 if network:
  1361. 1010 # pylint:disable=protected-access
  1362. 1011 network._vpc.delete()
  1363. Total time: 0 s
  1364. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1365. Function: get_or_create_default at line 1013
  1366. Line # Hits Time Per Hit % Time Line Contents
  1367. ==============================================================
  1368. 1013 @profile
  1369. 1014 def get_or_create_default(self):
  1370. 1015 # # Look for provided default network
  1371. 1016 # for net in self.provider.networking.networks:
  1372. 1017 # pylint:disable=protected-access
  1373. 1018 # if net._vpc.is_default:
  1374. 1019 # return net
  1375. 1020
  1376. 1021 # No provider-default, try CB-default instead
  1377. 1022 default_nets = self.provider.networking.networks.find(
  1378. 1023 label=AWSNetwork.CB_DEFAULT_NETWORK_LABEL)
  1379. 1024 if default_nets:
  1380. 1025 return default_nets[0]
  1381. 1026
  1382. 1027 else:
  1383. 1028 log.info("Creating a CloudBridge-default network labeled %s",
  1384. 1029 AWSNetwork.CB_DEFAULT_NETWORK_LABEL)
  1385. 1030 return self.provider.networking.networks.create(
  1386. 1031 label=AWSNetwork.CB_DEFAULT_NETWORK_LABEL,
  1387. 1032 cidr_block=AWSNetwork.CB_DEFAULT_IPV4RANGE)
  1388. Total time: 0 s
  1389. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1390. Function: get at line 1043
  1391. Line # Hits Time Per Hit % Time Line Contents
  1392. ==============================================================
  1393. 1043 @dispatch(event="provider.networking.subnets.get",
  1394. 1044 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  1395. 1045 @profile
  1396. 1046 def get(self, subnet_id):
  1397. 1047 return self.svc.get(subnet_id)
  1398. Total time: 0 s
  1399. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1400. Function: list at line 1049
  1401. Line # Hits Time Per Hit % Time Line Contents
  1402. ==============================================================
  1403. 1049 @dispatch(event="provider.networking.subnets.list",
  1404. 1050 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  1405. 1051 @profile
  1406. 1052 def list(self, network=None, limit=None, marker=None):
  1407. 1053 network_id = network.id if isinstance(network, AWSNetwork) else network
  1408. 1054 if network_id:
  1409. 1055 return self.svc.find(
  1410. 1056 filter_name='vpc-id', filter_value=network_id,
  1411. 1057 limit=limit, marker=marker)
  1412. 1058 else:
  1413. 1059 return self.svc.list(limit=limit, marker=marker)
  1414. Total time: 0 s
  1415. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1416. Function: find at line 1061
  1417. Line # Hits Time Per Hit % Time Line Contents
  1418. ==============================================================
  1419. 1061 @dispatch(event="provider.networking.subnets.find",
  1420. 1062 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  1421. 1063 @profile
  1422. 1064 def find(self, network=None, **kwargs):
  1423. 1065 label = kwargs.pop('label', None)
  1424. 1066
  1425. 1067 # All kwargs should have been popped at this time.
  1426. 1068 if len(kwargs) > 0:
  1427. 1069 raise InvalidParamException(
  1428. 1070 "Unrecognised parameters for search: %s. Supported "
  1429. 1071 "attributes: %s" % (kwargs, 'label'))
  1430. 1072
  1431. 1073 log.debug("Searching for AWS Subnet Service %s", label)
  1432. 1074 return self.svc.find(filter_name='tag:Name', filter_value=label)
  1433. Total time: 0 s
  1434. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1435. Function: create at line 1076
  1436. Line # Hits Time Per Hit % Time Line Contents
  1437. ==============================================================
  1438. 1076 @dispatch(event="provider.networking.subnets.create",
  1439. 1077 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  1440. 1078 @profile
  1441. 1079 def create(self, label, network, cidr_block, zone):
  1442. 1080 AWSSubnet.assert_valid_resource_label(label)
  1443. 1081 zone_name = zone.name if isinstance(
  1444. 1082 zone, AWSPlacementZone) else zone
  1445. 1083
  1446. 1084 network_id = network.id if isinstance(network, AWSNetwork) else network
  1447. 1085
  1448. 1086 subnet = self.svc.create('create_subnet',
  1449. 1087 VpcId=network_id,
  1450. 1088 CidrBlock=cidr_block,
  1451. 1089 AvailabilityZone=zone_name)
  1452. 1090 if label:
  1453. 1091 subnet.label = label
  1454. 1092 return subnet
  1455. Total time: 0 s
  1456. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1457. Function: delete at line 1094
  1458. Line # Hits Time Per Hit % Time Line Contents
  1459. ==============================================================
  1460. 1094 @dispatch(event="provider.networking.subnets.delete",
  1461. 1095 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  1462. 1096 @profile
  1463. 1097 def delete(self, subnet):
  1464. 1098 sn = subnet if isinstance(subnet, AWSSubnet) else self.get(subnet)
  1465. 1099 if sn:
  1466. 1100 # pylint:disable=protected-access
  1467. 1101 sn._subnet.delete()
  1468. Total time: 0 s
  1469. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1470. Function: get_or_create_default at line 1103
  1471. Line # Hits Time Per Hit % Time Line Contents
  1472. ==============================================================
  1473. 1103 @profile
  1474. 1104 def get_or_create_default(self, zone):
  1475. 1105 zone_name = zone.name if isinstance(zone, AWSPlacementZone) else zone
  1476. 1106
  1477. 1107 # # Look for provider default subnet in current zone
  1478. 1108 # if zone_name:
  1479. 1109 # snl = self.svc.find('availabilityZone', zone_name)
  1480. 1110 #
  1481. 1111 # else:
  1482. 1112 # snl = self.svc.list()
  1483. 1113 # # Find first available default subnet by sorted order
  1484. 1114 # # of availability zone. Prefer zone us-east-1a over 1e,
  1485. 1115 # # because newer zones tend to have less compatibility
  1486. 1116 # # with different instance types (e.g. c5.large not available
  1487. 1117 # # on us-east-1e as of 14 Dec. 2017).
  1488. 1118 # # pylint:disable=protected-access
  1489. 1119 # snl.sort(key=lambda sn: sn._subnet.availability_zone)
  1490. 1120 #
  1491. 1121 # for sn in snl:
  1492. 1122 # # pylint:disable=protected-access
  1493. 1123 # if sn._subnet.default_for_az:
  1494. 1124 # return sn
  1495. 1125
  1496. 1126 # If no provider-default subnet has been found, look for
  1497. 1127 # cloudbridge-default by label. We suffix labels by availability zone,
  1498. 1128 # thus we add the wildcard for the regular expression to find the
  1499. 1129 # subnet
  1500. 1130 snl = self.find(label=AWSSubnet.CB_DEFAULT_SUBNET_LABEL + "*")
  1501. 1131
  1502. 1132 if snl:
  1503. 1133 # pylint:disable=protected-access
  1504. 1134 snl.sort(key=lambda sn: sn._subnet.availability_zone)
  1505. 1135 if not zone_name:
  1506. 1136 return snl[0]
  1507. 1137 for subnet in snl:
  1508. 1138 if subnet.zone.name == zone_name:
  1509. 1139 return subnet
  1510. 1140
  1511. 1141 # No default Subnet exists, try to create a CloudBridge-specific
  1512. 1142 # subnet. This involves creating the network, subnets, internet
  1513. 1143 # gateway, and connecting it all together so that the network has
  1514. 1144 # Internet connectivity.
  1515. 1145
  1516. 1146 # Check if a default net already exists and get it or create on
  1517. 1147 default_net = self.provider.networking.networks.get_or_create_default()
  1518. 1148
  1519. 1149 # Get/create an internet gateway for the default network and a
  1520. 1150 # corresponding router if it does not already exist.
  1521. 1151 # NOTE: Comment this out because the docs instruct users to setup
  1522. 1152 # network connectivity manually. There's a bit of discrepancy here
  1523. 1153 # though because the provider-default network will have Internet
  1524. 1154 # connectivity (unlike the CloudBridge-default network with this
  1525. 1155 # being commented) and is hence left in the codebase.
  1526. 1156 # default_gtw = default_net.gateways.get_or_create()
  1527. 1157 # router_label = "{0}-router".format(
  1528. 1158 # AWSNetwork.CB_DEFAULT_NETWORK_LABEL)
  1529. 1159 # default_routers = self.provider.networking.routers.find(
  1530. 1160 # label=router_label)
  1531. 1161 # if len(default_routers) == 0:
  1532. 1162 # default_router = self.provider.networking.routers.create(
  1533. 1163 # router_label, default_net)
  1534. 1164 # default_router.attach_gateway(default_gtw)
  1535. 1165 # else:
  1536. 1166 # default_router = default_routers[0]
  1537. 1167
  1538. 1168 # Create a subnet in each of the region's zones
  1539. 1169 region = self.provider.compute.regions.get(self.provider.region_name)
  1540. 1170 default_sn = None
  1541. 1171
  1542. 1172 # Determine how many subnets we'll need for the default network and the
  1543. 1173 # number of available zones. We need to derive a non-overlapping
  1544. 1174 # network size for each subnet within the parent net so figure those
  1545. 1175 # subnets here. `<net>.subnets` method will do this but we need to give
  1546. 1176 # it a prefix. Determining that prefix depends on the size of the
  1547. 1177 # network and should be incorporate the number of zones. So iterate
  1548. 1178 # over potential number of subnets until enough can be created to
  1549. 1179 # accommodate the number of available zones. That is where the fixed
  1550. 1180 # number comes from in the for loop as that many iterations will yield
  1551. 1181 # more potential subnets than any region has zones.
  1552. 1182 ip_net = ipaddress.ip_network(AWSNetwork.CB_DEFAULT_IPV4RANGE)
  1553. 1183 for x in range(5):
  1554. 1184 if len(region.zones) <= len(list(ip_net.subnets(
  1555. 1185 prefixlen_diff=x))):
  1556. 1186 prefixlen_diff = x
  1557. 1187 break
  1558. 1188 subnets = list(ip_net.subnets(prefixlen_diff=prefixlen_diff))
  1559. 1189
  1560. 1190 for i, z in reversed(list(enumerate(region.zones))):
  1561. 1191 sn_label = "{0}-{1}".format(AWSSubnet.CB_DEFAULT_SUBNET_LABEL,
  1562. 1192 z.id[-1])
  1563. 1193 log.info("Creating a default CloudBridge subnet %s: %s" %
  1564. 1194 (sn_label, str(subnets[i])))
  1565. 1195 sn = self.create(sn_label, default_net, str(subnets[i]), z)
  1566. 1196 # Create a route table entry between the SN and the inet gateway
  1567. 1197 # See note above about why this is commented
  1568. 1198 # default_router.attach_subnet(sn)
  1569. 1199 if zone and zone_name == z.name:
  1570. 1200 default_sn = sn
  1571. 1201 # No specific zone was supplied; return the last created subnet
  1572. 1202 # The list was originally reversed to have the last subnet be in zone a
  1573. 1203 if not default_sn:
  1574. 1204 default_sn = sn
  1575. 1205 return default_sn
  1576. Total time: 0 s
  1577. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1578. Function: get at line 1217
  1579. Line # Hits Time Per Hit % Time Line Contents
  1580. ==============================================================
  1581. 1217 @dispatch(event="provider.networking.routers.get",
  1582. 1218 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  1583. 1219 @profile
  1584. 1220 def get(self, router_id):
  1585. 1221 return self.svc.get(router_id)
  1586. Total time: 0 s
  1587. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1588. Function: find at line 1223
  1589. Line # Hits Time Per Hit % Time Line Contents
  1590. ==============================================================
  1591. 1223 @dispatch(event="provider.networking.routers.find",
  1592. 1224 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  1593. 1225 @profile
  1594. 1226 def find(self, **kwargs):
  1595. 1227 label = kwargs.pop('label', None)
  1596. 1228
  1597. 1229 # All kwargs should have been popped at this time.
  1598. 1230 if len(kwargs) > 0:
  1599. 1231 raise InvalidParamException(
  1600. 1232 "Unrecognised parameters for search: %s. Supported "
  1601. 1233 "attributes: %s" % (kwargs, 'label'))
  1602. 1234
  1603. 1235 log.debug("Searching for AWS Router Service %s", label)
  1604. 1236 return self.svc.find(filter_name='tag:Name', filter_value=label)
  1605. Total time: 0 s
  1606. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1607. Function: list at line 1238
  1608. Line # Hits Time Per Hit % Time Line Contents
  1609. ==============================================================
  1610. 1238 @dispatch(event="provider.networking.routers.list",
  1611. 1239 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  1612. 1240 @profile
  1613. 1241 def list(self, limit=None, marker=None):
  1614. 1242 return self.svc.list(limit=limit, marker=marker)
  1615. Total time: 0 s
  1616. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1617. Function: create at line 1244
  1618. Line # Hits Time Per Hit % Time Line Contents
  1619. ==============================================================
  1620. 1244 @dispatch(event="provider.networking.routers.create",
  1621. 1245 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  1622. 1246 @profile
  1623. 1247 def create(self, label, network):
  1624. 1248 network_id = network.id if isinstance(network, AWSNetwork) else network
  1625. 1249
  1626. 1250 cb_router = self.svc.create('create_route_table', VpcId=network_id)
  1627. 1251 if label:
  1628. 1252 cb_router.label = label
  1629. 1253 return cb_router
  1630. Total time: 0 s
  1631. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1632. Function: delete at line 1255
  1633. Line # Hits Time Per Hit % Time Line Contents
  1634. ==============================================================
  1635. 1255 @dispatch(event="provider.networking.routers.delete",
  1636. 1256 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  1637. 1257 @profile
  1638. 1258 def delete(self, router):
  1639. 1259 r = router if isinstance(router, AWSRouter) else self.get(router)
  1640. 1260 if r:
  1641. 1261 # pylint:disable=protected-access
  1642. 1262 r._route_table.delete()
  1643. Total time: 0 s
  1644. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1645. Function: get_or_create at line 1273
  1646. Line # Hits Time Per Hit % Time Line Contents
  1647. ==============================================================
  1648. 1273 @dispatch(event="provider.networking.gateways.get_or_create",
  1649. 1274 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  1650. 1275 @profile
  1651. 1276 def get_or_create(self, network):
  1652. 1277 network_id = network.id if isinstance(
  1653. 1278 network, AWSNetwork) else network
  1654. 1279 # Don't filter by label because it may conflict with at least the
  1655. 1280 # default VPC that most accounts have but that network is typically
  1656. 1281 # without a name.
  1657. 1282 gtw = self.svc.find(filter_name='attachment.vpc-id',
  1658. 1283 filter_value=network_id)
  1659. 1284 if gtw:
  1660. 1285 return gtw[0] # There can be only one gtw attached to a VPC
  1661. 1286 # Gateway does not exist so create one and attach to the supplied net
  1662. 1287 cb_gateway = self.svc.create('create_internet_gateway')
  1663. 1288 cb_gateway._gateway.create_tags(
  1664. 1289 Tags=[{'Key': 'Name',
  1665. 1290 'Value': AWSInternetGateway.CB_DEFAULT_INET_GATEWAY_NAME
  1666. 1291 }])
  1667. 1292 cb_gateway._gateway.attach_to_vpc(VpcId=network_id)
  1668. 1293 return cb_gateway
  1669. Total time: 0 s
  1670. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1671. Function: delete at line 1295
  1672. Line # Hits Time Per Hit % Time Line Contents
  1673. ==============================================================
  1674. 1295 @dispatch(event="provider.networking.gateways.delete",
  1675. 1296 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  1676. 1297 @profile
  1677. 1298 def delete(self, network, gateway):
  1678. 1299 gw = (gateway if isinstance(gateway, AWSInternetGateway)
  1679. 1300 else self.svc.get(gateway))
  1680. 1301 try:
  1681. 1302 if gw.network_id:
  1682. 1303 # pylint:disable=protected-access
  1683. 1304 gw._gateway.detach_from_vpc(VpcId=gw.network_id)
  1684. 1305 except ClientError as e:
  1685. 1306 log.warn("Error deleting gateway {0}: {1}".format(self.id, e))
  1686. 1307 # pylint:disable=protected-access
  1687. 1308 gw._gateway.delete()
  1688. Total time: 0 s
  1689. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1690. Function: list at line 1310
  1691. Line # Hits Time Per Hit % Time Line Contents
  1692. ==============================================================
  1693. 1310 @dispatch(event="provider.networking.gateways.list",
  1694. 1311 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  1695. 1312 @profile
  1696. 1313 def list(self, network, limit=None, marker=None):
  1697. 1314 log.debug("Listing current AWS internet gateways for net %s.",
  1698. 1315 network.id)
  1699. 1316 fltr = [{'Name': 'attachment.vpc-id', 'Values': [network.id]}]
  1700. 1317 return self.svc.list(limit=None, marker=None, Filters=fltr)
  1701. Total time: 0 s
  1702. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1703. Function: get at line 1328
  1704. Line # Hits Time Per Hit % Time Line Contents
  1705. ==============================================================
  1706. 1328 @dispatch(event="provider.networking.floating_ips.get",
  1707. 1329 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  1708. 1330 @profile
  1709. 1331 def get(self, gateway, fip_id):
  1710. 1332 log.debug("Getting AWS Floating IP Service with the id: %s", fip_id)
  1711. 1333 return self.svc.get(fip_id)
  1712. Total time: 0 s
  1713. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1714. Function: list at line 1335
  1715. Line # Hits Time Per Hit % Time Line Contents
  1716. ==============================================================
  1717. 1335 @dispatch(event="provider.networking.floating_ips.list",
  1718. 1336 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  1719. 1337 @profile
  1720. 1338 def list(self, gateway, limit=None, marker=None):
  1721. 1339 return self.svc.list(limit, marker)
  1722. Total time: 0 s
  1723. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1724. Function: create at line 1341
  1725. Line # Hits Time Per Hit % Time Line Contents
  1726. ==============================================================
  1727. 1341 @dispatch(event="provider.networking.floating_ips.create",
  1728. 1342 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  1729. 1343 @profile
  1730. 1344 def create(self, gateway):
  1731. 1345 log.debug("Creating a floating IP under gateway %s", gateway)
  1732. 1346 ip = self.provider.ec2_conn.meta.client.allocate_address(
  1733. 1347 Domain='vpc')
  1734. 1348 return AWSFloatingIP(
  1735. 1349 self.provider,
  1736. 1350 self.provider.ec2_conn.VpcAddress(ip.get('AllocationId')))
  1737. Total time: 0 s
  1738. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1739. Function: delete at line 1352
  1740. Line # Hits Time Per Hit % Time Line Contents
  1741. ==============================================================
  1742. 1352 @dispatch(event="provider.networking.floating_ips.delete",
  1743. 1353 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  1744. 1354 @profile
  1745. 1355 def delete(self, gateway, fip):
  1746. 1356 if isinstance(fip, AWSFloatingIP):
  1747. 1357 # pylint:disable=protected-access
  1748. 1358 aws_fip = fip._ip
  1749. 1359 else:
  1750. 1360 aws_fip = self.svc.get_raw(fip)
  1751. 1361 aws_fip.release()
  1752. Total time: 0 s
  1753. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1754. Function: label at line 81
  1755. Line # Hits Time Per Hit % Time Line Contents
  1756. ==============================================================
  1757. 81 @label.setter
  1758. 82 @profile
  1759. 83 def label(self, value):
  1760. 84 self.assert_valid_resource_label(value)
  1761. 85 self._vm_firewall.tags.update(Label=value or "")
  1762. 86 self._provider.azure_client.update_vm_firewall_tags(
  1763. 87 self.id, self._vm_firewall.tags)
  1764. Total time: 0 s
  1765. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1766. Function: description at line 93
  1767. Line # Hits Time Per Hit % Time Line Contents
  1768. ==============================================================
  1769. 93 @description.setter
  1770. 94 @profile
  1771. 95 def description(self, value):
  1772. 96 self._vm_firewall.tags.update(Description=value or "")
  1773. 97 self._provider.azure_client.\
  1774. 98 update_vm_firewall_tags(self.id,
  1775. 99 self._vm_firewall.tags)
  1776. Total time: 0 s
  1777. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1778. Function: refresh at line 105
  1779. Line # Hits Time Per Hit % Time Line Contents
  1780. ==============================================================
  1781. 105 @profile
  1782. 106 def refresh(self):
  1783. 107 """
  1784. 108 Refreshes the security group with tags if required.
  1785. 109 """
  1786. 110 try:
  1787. 111 self._vm_firewall = self._provider.azure_client. \
  1788. 112 get_vm_firewall(self.id)
  1789. 113 if not self._vm_firewall.tags:
  1790. 114 self._vm_firewall.tags = {}
  1791. 115 except (CloudError, ValueError) as cloud_error:
  1792. 116 log.exception(cloud_error.message)
  1793. Total time: 0 s
  1794. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1795. Function: refresh at line 265
  1796. Line # Hits Time Per Hit % Time Line Contents
  1797. ==============================================================
  1798. 265 @profile
  1799. 266 def refresh(self):
  1800. 267 self._key = self._provider.azure_client.get_blob(
  1801. 268 self._container.id, self._key.id)
  1802. Total time: 2.28898 s
  1803. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1804. Function: label at line 354
  1805. Line # Hits Time Per Hit % Time Line Contents
  1806. ==============================================================
  1807. 354 @label.setter
  1808. 355 # pylint:disable=arguments-differ
  1809. 356 @profile
  1810. 357 def label(self, value):
  1811. 358 """
  1812. 359 Set the volume label.
  1813. 360 """
  1814. 361 12 162.0 13.5 0.0 self.assert_valid_resource_label(value)
  1815. 362 4 13.0 3.2 0.0 self._volume.tags.update(Label=value or "")
  1816. 363 4 46.0 11.5 0.0 self._provider.azure_client. \
  1817. 364 4 6.0 1.5 0.0 update_disk_tags(self.id,
  1818. 365 4 2288758.0 572189.5 100.0 self._volume.tags)
  1819. Total time: 0 s
  1820. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1821. Function: description at line 371
  1822. Line # Hits Time Per Hit % Time Line Contents
  1823. ==============================================================
  1824. 371 @description.setter
  1825. 372 @profile
  1826. 373 def description(self, value):
  1827. 374 self._volume.tags.update(Description=value or "")
  1828. 375 self._provider.azure_client. \
  1829. 376 update_disk_tags(self.id,
  1830. 377 self._volume.tags)
  1831. Total time: 19.3186 s
  1832. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1833. Function: refresh at line 452
  1834. Line # Hits Time Per Hit % Time Line Contents
  1835. ==============================================================
  1836. 452 @profile
  1837. 453 def refresh(self):
  1838. 454 """
  1839. 455 Refreshes the state of this volume by re-querying the cloud provider
  1840. 456 for its latest state.
  1841. 457 """
  1842. 458 35 144.0 4.1 0.0 try:
  1843. 459 35 487.0 13.9 0.0 self._volume = self._provider.azure_client. \
  1844. 460 35 19317560.0 551930.3 100.0 get_disk(self.id)
  1845. 461 33 176.0 5.3 0.0 self._update_state()
  1846. 462 2 6.0 3.0 0.0 except (CloudError, ValueError) as cloud_error:
  1847. 463 2 249.0 124.5 0.0 log.exception(cloud_error.message)
  1848. 464 # The volume no longer exists and cannot be refreshed.
  1849. 465 # set the state to unknown
  1850. 466 2 4.0 2.0 0.0 self._state = 'unknown'
  1851. Total time: 0 s
  1852. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1853. Function: label at line 509
  1854. Line # Hits Time Per Hit % Time Line Contents
  1855. ==============================================================
  1856. 509 @label.setter
  1857. 510 # pylint:disable=arguments-differ
  1858. 511 @profile
  1859. 512 def label(self, value):
  1860. 513 """
  1861. 514 Set the snapshot label.
  1862. 515 """
  1863. 516 self.assert_valid_resource_label(value)
  1864. 517 self._snapshot.tags.update(Label=value or "")
  1865. 518 self._provider.azure_client. \
  1866. 519 update_snapshot_tags(self.id,
  1867. 520 self._snapshot.tags)
  1868. Total time: 0 s
  1869. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1870. Function: description at line 526
  1871. Line # Hits Time Per Hit % Time Line Contents
  1872. ==============================================================
  1873. 526 @description.setter
  1874. 527 @profile
  1875. 528 def description(self, value):
  1876. 529 self._snapshot.tags.update(Description=value or "")
  1877. 530 self._provider.azure_client. \
  1878. 531 update_snapshot_tags(self.id,
  1879. 532 self._snapshot.tags)
  1880. Total time: 0 s
  1881. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1882. Function: refresh at line 551
  1883. Line # Hits Time Per Hit % Time Line Contents
  1884. ==============================================================
  1885. 551 @profile
  1886. 552 def refresh(self):
  1887. 553 """
  1888. 554 Refreshes the state of this snapshot by re-querying the cloud provider
  1889. 555 for its latest state.
  1890. 556 """
  1891. 557 try:
  1892. 558 self._snapshot = self._provider.azure_client. \
  1893. 559 get_snapshot(self.id)
  1894. 560 self._state = self._snapshot.provisioning_state
  1895. 561 except (CloudError, ValueError) as cloud_error:
  1896. 562 log.exception(cloud_error.message)
  1897. 563 # The snapshot no longer exists and cannot be refreshed.
  1898. 564 # set the state to unknown
  1899. 565 self._state = 'unknown'
  1900. Total time: 0 s
  1901. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1902. Function: label at line 629
  1903. Line # Hits Time Per Hit % Time Line Contents
  1904. ==============================================================
  1905. 629 @label.setter
  1906. 630 @profile
  1907. 631 def label(self, value):
  1908. 632 """
  1909. 633 Set the image label when it is a private image.
  1910. 634 """
  1911. 635 if not self.is_gallery_image:
  1912. 636 self.assert_valid_resource_label(value)
  1913. 637 self._image.tags.update(Label=value or "")
  1914. 638 self._provider.azure_client. \
  1915. 639 update_image_tags(self.id, self._image.tags)
  1916. Total time: 0 s
  1917. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1918. Function: description at line 655
  1919. Line # Hits Time Per Hit % Time Line Contents
  1920. ==============================================================
  1921. 655 @description.setter
  1922. 656 @profile
  1923. 657 def description(self, value):
  1924. 658 """
  1925. 659 Set the image description.
  1926. 660 """
  1927. 661 if not self.is_gallery_image:
  1928. 662 self._image.tags.update(Description=value or "")
  1929. 663 self._provider.azure_client. \
  1930. 664 update_image_tags(self.id, self._image.tags)
  1931. Total time: 0 s
  1932. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1933. Function: refresh at line 705
  1934. Line # Hits Time Per Hit % Time Line Contents
  1935. ==============================================================
  1936. 705 @profile
  1937. 706 def refresh(self):
  1938. 707 """
  1939. 708 Refreshes the state of this instance by re-querying the cloud provider
  1940. 709 for its latest state.
  1941. 710 """
  1942. 711 if not self.is_gallery_image:
  1943. 712 try:
  1944. 713 self._image = self._provider.azure_client.get_image(self.id)
  1945. 714 self._state = self._image.provisioning_state
  1946. 715 except CloudError as cloud_error:
  1947. 716 log.exception(cloud_error.message)
  1948. 717 # image no longer exists
  1949. 718 self._state = "unknown"
  1950. Total time: 0 s
  1951. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1952. Function: label at line 757
  1953. Line # Hits Time Per Hit % Time Line Contents
  1954. ==============================================================
  1955. 757 @label.setter
  1956. 758 # pylint:disable=arguments-differ
  1957. 759 @profile
  1958. 760 def label(self, value):
  1959. 761 """
  1960. 762 Set the network label.
  1961. 763 """
  1962. 764 self.assert_valid_resource_label(value)
  1963. 765 self._network.tags.update(Label=value or "")
  1964. 766 self._provider.azure_client. \
  1965. 767 update_network_tags(self.id, self._network)
  1966. Total time: 0 s
  1967. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1968. Function: refresh at line 782
  1969. Line # Hits Time Per Hit % Time Line Contents
  1970. ==============================================================
  1971. 782 @profile
  1972. 783 def refresh(self):
  1973. 784 """
  1974. 785 Refreshes the state of this network by re-querying the cloud provider
  1975. 786 for its latest state.
  1976. 787 """
  1977. 788 try:
  1978. 789 self._network = self._provider.azure_client.\
  1979. 790 get_network(self.id)
  1980. 791 self._state = self._network.provisioning_state
  1981. 792 except (CloudError, ValueError) as cloud_error:
  1982. 793 log.exception(cloud_error.message)
  1983. 794 # The network no longer exists and cannot be refreshed.
  1984. 795 # set the state to unknown
  1985. 796 self._state = 'unknown'
  1986. Total time: 0 s
  1987. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1988. Function: refresh at line 852
  1989. Line # Hits Time Per Hit % Time Line Contents
  1990. ==============================================================
  1991. 852 @profile
  1992. 853 def refresh(self):
  1993. 854 # Gateway is not needed as it doesn't exist in Azure, so just
  1994. 855 # getting the Floating IP again from the client
  1995. 856 # pylint:disable=protected-access
  1996. 857 fip = self._provider.networking._floating_ips.get(None, self.id)
  1997. 858 # pylint:disable=protected-access
  1998. 859 self._ip = fip._ip
  1999. Total time: 0 s
  2000. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2001. Function: label at line 957
  2002. Line # Hits Time Per Hit % Time Line Contents
  2003. ==============================================================
  2004. 957 @label.setter
  2005. 958 # pylint:disable=arguments-differ
  2006. 959 @profile
  2007. 960 def label(self, value):
  2008. 961 self.assert_valid_resource_label(value)
  2009. 962 network = self.network
  2010. 963 # pylint:disable=protected-access
  2011. 964 az_network = network._network
  2012. 965 kwargs = {self.tag_name: value or ""}
  2013. 966 az_network.tags.update(**kwargs)
  2014. 967 self._provider.azure_client.update_network_tags(
  2015. 968 az_network.id, az_network)
  2016. Total time: 0 s
  2017. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2018. Function: refresh at line 999
  2019. Line # Hits Time Per Hit % Time Line Contents
  2020. ==============================================================
  2021. 999 @profile
  2022. 1000 def refresh(self):
  2023. 1001 """
  2024. 1002 Refreshes the state of this network by re-querying the cloud provider
  2025. 1003 for its latest state.
  2026. 1004 """
  2027. 1005 try:
  2028. 1006 self._subnet = self._provider.azure_client. \
  2029. 1007 get_subnet(self.id)
  2030. 1008 self._state = self._subnet.provisioning_state
  2031. 1009 except (CloudError, ValueError) as cloud_error:
  2032. 1010 log.exception(cloud_error.message)
  2033. 1011 # The subnet no longer exists and cannot be refreshed.
  2034. 1012 # set the state to unknown
  2035. 1013 self._state = 'unknown'
  2036. Total time: 0 s
  2037. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2038. Function: label at line 1086
  2039. Line # Hits Time Per Hit % Time Line Contents
  2040. ==============================================================
  2041. 1086 @label.setter
  2042. 1087 # pylint:disable=arguments-differ
  2043. 1088 @profile
  2044. 1089 def label(self, value):
  2045. 1090 """
  2046. 1091 Set the instance label.
  2047. 1092 """
  2048. 1093 self.assert_valid_resource_label(value)
  2049. 1094 self._vm.tags.update(Label=value or "")
  2050. 1095 self._provider.azure_client. \
  2051. 1096 update_vm_tags(self.id, self._vm)
  2052. Total time: 1.24565 s
  2053. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2054. Function: refresh at line 1340
  2055. Line # Hits Time Per Hit % Time Line Contents
  2056. ==============================================================
  2057. 1340 @profile
  2058. 1341 def refresh(self):
  2059. 1342 """
  2060. 1343 Refreshes the state of this instance by re-querying the cloud provider
  2061. 1344 for its latest state.
  2062. 1345 """
  2063. 1346 4 10.0 2.5 0.0 try:
  2064. 1347 4 1245282.0 311320.5 100.0 self._vm = self._provider.azure_client.get_vm(self.id)
  2065. 1348 2 4.0 2.0 0.0 if not self._vm.tags:
  2066. 1349 self._vm.tags = {}
  2067. 1350 2 13.0 6.5 0.0 self._update_state()
  2068. 1351 2 6.0 3.0 0.0 except (CloudError, ValueError) as cloud_error:
  2069. 1352 2 328.0 164.0 0.0 log.exception(cloud_error.message)
  2070. 1353 # The volume no longer exists and cannot be refreshed.
  2071. 1354 # set the state to unknown
  2072. 1355 2 4.0 2.0 0.0 self._state = 'unknown'
  2073. Total time: 0 s
  2074. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2075. Function: label at line 1461
  2076. Line # Hits Time Per Hit % Time Line Contents
  2077. ==============================================================
  2078. 1461 @label.setter
  2079. 1462 # pylint:disable=arguments-differ
  2080. 1463 @profile
  2081. 1464 def label(self, value):
  2082. 1465 """
  2083. 1466 Set the router label.
  2084. 1467 """
  2085. 1468 self.assert_valid_resource_label(value)
  2086. 1469 self._route_table.tags.update(Label=value or "")
  2087. 1470 self._provider.azure_client. \
  2088. 1471 update_route_table_tags(self._route_table.name,
  2089. 1472 self._route_table)
  2090. Total time: 0 s
  2091. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2092. Function: refresh at line 1474
  2093. Line # Hits Time Per Hit % Time Line Contents
  2094. ==============================================================
  2095. 1474 @profile
  2096. 1475 def refresh(self):
  2097. 1476 self._route_table = self._provider.azure_client. \
  2098. 1477 get_route_table(self._route_table.name)
  2099. Total time: 0 s
  2100. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2101. Function: refresh at line 1533
  2102. Line # Hits Time Per Hit % Time Line Contents
  2103. ==============================================================
  2104. 1533 @profile
  2105. 1534 def refresh(self):
  2106. 1535 pass
  2107. Total time: 0 s
  2108. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2109. Function: get at line 93
  2110. Line # Hits Time Per Hit % Time Line Contents
  2111. ==============================================================
  2112. 93 @dispatch(event="provider.security.vm_firewalls.get",
  2113. 94 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  2114. 95 @profile
  2115. 96 def get(self, vm_firewall_id):
  2116. 97 try:
  2117. 98 fws = self.provider.azure_client.get_vm_firewall(vm_firewall_id)
  2118. 99 return AzureVMFirewall(self.provider, fws)
  2119. 100 except (CloudError, InvalidValueException) as cloud_error:
  2120. 101 # Azure raises the cloud error if the resource not available
  2121. 102 log.exception(cloud_error)
  2122. 103 return None
  2123. Total time: 0 s
  2124. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2125. Function: list at line 105
  2126. Line # Hits Time Per Hit % Time Line Contents
  2127. ==============================================================
  2128. 105 @dispatch(event="provider.security.vm_firewalls.list",
  2129. 106 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  2130. 107 @profile
  2131. 108 def list(self, limit=None, marker=None):
  2132. 109 fws = [AzureVMFirewall(self.provider, fw)
  2133. 110 for fw in self.provider.azure_client.list_vm_firewall()]
  2134. 111 return ClientPagedResultList(self.provider, fws, limit, marker)
  2135. Total time: 0 s
  2136. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2137. Function: create at line 113
  2138. Line # Hits Time Per Hit % Time Line Contents
  2139. ==============================================================
  2140. 113 @cb_helpers.deprecated_alias(network_id='network')
  2141. 114 @dispatch(event="provider.security.vm_firewalls.create",
  2142. 115 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  2143. 116 @profile
  2144. 117 def create(self, label, network, description=None):
  2145. 118 AzureVMFirewall.assert_valid_resource_label(label)
  2146. 119 name = AzureVMFirewall._generate_name_from_label(label, "cb-fw")
  2147. 120 net = network.id if isinstance(network, Network) else network
  2148. 121 parameters = {"location": self.provider.region_name,
  2149. 122 "tags": {'Label': label,
  2150. 123 'network_id': net}}
  2151. 124
  2152. 125 if description:
  2153. 126 parameters['tags'].update(Description=description)
  2154. 127
  2155. 128 fw = self.provider.azure_client.create_vm_firewall(name,
  2156. 129 parameters)
  2157. 130
  2158. 131 # Add default rules to negate azure default rules.
  2159. 132 # See: https://github.com/CloudVE/cloudbridge/issues/106
  2160. 133 # pylint:disable=protected-access
  2161. 134 for rule in fw.default_security_rules:
  2162. 135 rule_name = "cb-override-" + rule.name
  2163. 136 # Transpose rules to priority 4001 onwards, because
  2164. 137 # only 0-4096 are allowed for custom rules
  2165. 138 rule.priority = rule.priority - 61440
  2166. 139 rule.access = "Deny"
  2167. 140 self.provider.azure_client.create_vm_firewall_rule(
  2168. 141 fw.id, rule_name, rule)
  2169. 142
  2170. 143 # Add a new custom rule allowing all outbound traffic to the internet
  2171. 144 parameters = {"priority": 3000,
  2172. 145 "protocol": "*",
  2173. 146 "source_port_range": "*",
  2174. 147 "source_address_prefix": "*",
  2175. 148 "destination_port_range": "*",
  2176. 149 "destination_address_prefix": "Internet",
  2177. 150 "access": "Allow",
  2178. 151 "direction": "Outbound"}
  2179. 152 result = self.provider.azure_client.create_vm_firewall_rule(
  2180. 153 fw.id, "cb-default-internet-outbound", parameters)
  2181. 154 fw.security_rules.append(result)
  2182. 155
  2183. 156 cb_fw = AzureVMFirewall(self.provider, fw)
  2184. 157 return cb_fw
  2185. Total time: 0 s
  2186. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2187. Function: delete at line 159
  2188. Line # Hits Time Per Hit % Time Line Contents
  2189. ==============================================================
  2190. 159 @dispatch(event="provider.security.vm_firewalls.delete",
  2191. 160 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  2192. 161 @profile
  2193. 162 def delete(self, vm_firewall):
  2194. 163 fw_id = (vm_firewall.id if isinstance(vm_firewall, AzureVMFirewall)
  2195. 164 else vm_firewall)
  2196. 165 self.provider.azure_client.delete_vm_firewall(fw_id)
  2197. Total time: 0 s
  2198. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2199. Function: list at line 173
  2200. Line # Hits Time Per Hit % Time Line Contents
  2201. ==============================================================
  2202. 173 @dispatch(event="provider.security.vm_firewall_rules.list",
  2203. 174 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  2204. 175 @profile
  2205. 176 def list(self, firewall, limit=None, marker=None):
  2206. 177 # Filter out firewall rules with priority < 3500 because values
  2207. 178 # between 3500 and 4096 are assumed to be owned by cloudbridge
  2208. 179 # default rules.
  2209. 180 # pylint:disable=protected-access
  2210. 181 rules = [AzureVMFirewallRule(firewall, rule) for rule
  2211. 182 in firewall._vm_firewall.security_rules
  2212. 183 if rule.priority < 3500]
  2213. 184 return ClientPagedResultList(self.provider, rules,
  2214. 185 limit=limit, marker=marker)
  2215. Total time: 0 s
  2216. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2217. Function: create at line 187
  2218. Line # Hits Time Per Hit % Time Line Contents
  2219. ==============================================================
  2220. 187 @dispatch(event="provider.security.vm_firewall_rules.create",
  2221. 188 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  2222. 189 @profile
  2223. 190 def create(self, firewall, direction, protocol=None, from_port=None,
  2224. 191 to_port=None, cidr=None, src_dest_fw=None):
  2225. 192 if protocol and from_port and to_port:
  2226. 193 return self._create_rule(firewall, direction, protocol, from_port,
  2227. 194 to_port, cidr)
  2228. 195 elif src_dest_fw:
  2229. 196 result = None
  2230. 197 fw = (self.provider.security.vm_firewalls.get(src_dest_fw)
  2231. 198 if isinstance(src_dest_fw, str) else src_dest_fw)
  2232. 199 for rule in fw.rules:
  2233. 200 result = self._create_rule(
  2234. 201 rule.direction, rule.protocol, rule.from_port,
  2235. 202 rule.to_port, rule.cidr)
  2236. 203 return result
  2237. 204 else:
  2238. 205 return None
  2239. Total time: 0 s
  2240. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2241. Function: delete at line 238
  2242. Line # Hits Time Per Hit % Time Line Contents
  2243. ==============================================================
  2244. 238 @dispatch(event="provider.security.vm_firewall_rules.delete",
  2245. 239 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  2246. 240 @profile
  2247. 241 def delete(self, firewall, rule):
  2248. 242 rule_id = rule.id if isinstance(rule, AzureVMFirewallRule) else rule
  2249. 243 fw_name = firewall.name
  2250. 244 self.provider.azure_client. \
  2251. 245 delete_vm_firewall_rule(rule_id, fw_name)
  2252. 246 for i, o in enumerate(firewall._vm_firewall.security_rules):
  2253. 247 if o.id == rule_id:
  2254. 248 # pylint:disable=protected-access
  2255. 249 del firewall._vm_firewall.security_rules[i]
  2256. 250 break
  2257. Total time: 22.2458 s
  2258. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2259. Function: get at line 259
  2260. Line # Hits Time Per Hit % Time Line Contents
  2261. ==============================================================
  2262. 259 @dispatch(event="provider.security.key_pairs.get",
  2263. 260 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  2264. 261 @profile
  2265. 262 def get(self, key_pair_id):
  2266. 263 4 5.0 1.2 0.0 try:
  2267. 264 4 30.0 7.5 0.0 key_pair = self.provider.azure_client.\
  2268. 265 4 22245719.0 5561429.8 100.0 get_public_key(key_pair_id)
  2269. 266
  2270. 267 4 7.0 1.8 0.0 if key_pair:
  2271. 268 2 42.0 21.0 0.0 return AzureKeyPair(self.provider, key_pair)
  2272. 269 2 0.0 0.0 0.0 return None
  2273. 270 except AzureException as error:
  2274. 271 log.debug("KeyPair %s was not found.", key_pair_id)
  2275. 272 log.debug(error)
  2276. 273 return None
  2277. Total time: 0 s
  2278. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2279. Function: list at line 275
  2280. Line # Hits Time Per Hit % Time Line Contents
  2281. ==============================================================
  2282. 275 @dispatch(event="provider.security.key_pairs.list",
  2283. 276 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  2284. 277 @profile
  2285. 278 def list(self, limit=None, marker=None):
  2286. 279 key_pairs, resume_marker = self.provider.azure_client.list_public_keys(
  2287. 280 AzureKeyPairService.PARTITION_KEY, marker=marker,
  2288. 281 limit=limit or self.provider.config.default_result_limit)
  2289. 282 results = [AzureKeyPair(self.provider, key_pair)
  2290. 283 for key_pair in key_pairs]
  2291. 284 return ServerPagedResultList(is_truncated=resume_marker,
  2292. 285 marker=resume_marker,
  2293. 286 supports_total=False,
  2294. 287 data=results)
  2295. Total time: 0 s
  2296. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2297. Function: find at line 289
  2298. Line # Hits Time Per Hit % Time Line Contents
  2299. ==============================================================
  2300. 289 @dispatch(event="provider.security.key_pairs.find",
  2301. 290 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  2302. 291 @profile
  2303. 292 def find(self, **kwargs):
  2304. 293 obj_list = self
  2305. 294 filters = ['name']
  2306. 295 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2307. 296
  2308. 297 # All kwargs should have been popped at this time.
  2309. 298 if len(kwargs) > 0:
  2310. 299 raise InvalidParamException(
  2311. 300 "Unrecognised parameters for search: %s. Supported "
  2312. 301 "attributes: %s" % (kwargs, ", ".join(filters)))
  2313. 302
  2314. 303 return ClientPagedResultList(self.provider,
  2315. 304 matches if matches else [])
  2316. Total time: 22.6894 s
  2317. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2318. Function: create at line 306
  2319. Line # Hits Time Per Hit % Time Line Contents
  2320. ==============================================================
  2321. 306 @dispatch(event="provider.security.key_pairs.create",
  2322. 307 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  2323. 308 @profile
  2324. 309 def create(self, name, public_key_material=None):
  2325. 310 2 26.0 13.0 0.0 AzureKeyPair.assert_valid_resource_name(name)
  2326. 311 2 22008812.0 11004406.0 97.0 key_pair = self.get(name)
  2327. 312
  2328. 313 2 1.0 0.5 0.0 if key_pair:
  2329. 314 raise DuplicateResourceException(
  2330. 315 'Keypair already exists with name {0}'.format(name))
  2331. 316
  2332. 317 2 2.0 1.0 0.0 private_key = None
  2333. 318 2 2.0 1.0 0.0 if not public_key_material:
  2334. 319 2 170174.0 85087.0 0.8 public_key_material, private_key = cb_helpers.generate_key_pair()
  2335. 320
  2336. 321 entity = {
  2337. 322 2 9.0 4.5 0.0 'PartitionKey': AzureKeyPairService.PARTITION_KEY,
  2338. 323 2 69.0 34.5 0.0 'RowKey': str(uuid.uuid4()),
  2339. 324 2 1.0 0.5 0.0 'Name': name,
  2340. 325 2 4.0 2.0 0.0 'Key': public_key_material
  2341. 326 }
  2342. 327
  2343. 328 2 253106.0 126553.0 1.1 self.provider.azure_client.create_public_key(entity)
  2344. 329 2 257143.0 128571.5 1.1 key_pair = self.get(name)
  2345. 330 2 5.0 2.5 0.0 key_pair.material = private_key
  2346. 331 2 1.0 0.5 0.0 return key_pair
  2347. Total time: 0.346711 s
  2348. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2349. Function: delete at line 333
  2350. Line # Hits Time Per Hit % Time Line Contents
  2351. ==============================================================
  2352. 333 @dispatch(event="provider.security.key_pairs.delete",
  2353. 334 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  2354. 335 @profile
  2355. 336 def delete(self, key_pair):
  2356. 337 2 4.0 2.0 0.0 key_pair = (key_pair if isinstance(key_pair, AzureKeyPair) else
  2357. 338 self.get(key_pair))
  2358. 339 2 3.0 1.5 0.0 if key_pair:
  2359. 340 # pylint:disable=protected-access
  2360. 341 2 346704.0 173352.0 100.0 self.provider.azure_client.delete_public_key(key_pair._key_pair)
  2361. Total time: 0.514181 s
  2362. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2363. Function: get at line 375
  2364. Line # Hits Time Per Hit % Time Line Contents
  2365. ==============================================================
  2366. 375 @dispatch(event="provider.storage.volumes.get",
  2367. 376 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  2368. 377 @profile
  2369. 378 def get(self, volume_id):
  2370. 379 2 1.0 0.5 0.0 try:
  2371. 380 2 514031.0 257015.5 100.0 volume = self.provider.azure_client.get_disk(volume_id)
  2372. 381 1 18.0 18.0 0.0 return AzureVolume(self.provider, volume)
  2373. 382 1 3.0 3.0 0.0 except (CloudError, InvalidValueException) as cloud_error:
  2374. 383 # Azure raises the cloud error if the resource not available
  2375. 384 1 127.0 127.0 0.0 log.exception(cloud_error)
  2376. 385 1 1.0 1.0 0.0 return None
  2377. Total time: 0.346307 s
  2378. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2379. Function: find at line 387
  2380. Line # Hits Time Per Hit % Time Line Contents
  2381. ==============================================================
  2382. 387 @dispatch(event="provider.storage.volumes.find",
  2383. 388 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  2384. 389 @profile
  2385. 390 def find(self, **kwargs):
  2386. 391 3 2.0 0.7 0.0 obj_list = self
  2387. 392 3 2.0 0.7 0.0 filters = ['label']
  2388. 393 3 346247.0 115415.7 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2389. 394
  2390. 395 # All kwargs should have been popped at this time.
  2391. 396 2 3.0 1.5 0.0 if len(kwargs) > 0:
  2392. 397 raise InvalidParamException(
  2393. 398 "Unrecognised parameters for search: %s. Supported "
  2394. 399 "attributes: %s" % (kwargs, ", ".join(filters)))
  2395. 400
  2396. 401 2 4.0 2.0 0.0 return ClientPagedResultList(self.provider,
  2397. 402 2 49.0 24.5 0.0 matches if matches else [])
  2398. Total time: 1.02974 s
  2399. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2400. Function: list at line 404
  2401. Line # Hits Time Per Hit % Time Line Contents
  2402. ==============================================================
  2403. 404 @dispatch(event="provider.storage.volumes.list",
  2404. 405 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  2405. 406 @profile
  2406. 407 def list(self, limit=None, marker=None):
  2407. 408 6 2733.0 455.5 0.3 azure_vols = self.provider.azure_client.list_disks()
  2408. 409 6 1026775.0 171129.2 99.7 cb_vols = [AzureVolume(self.provider, vol) for vol in azure_vols]
  2409. 410 6 20.0 3.3 0.0 return ClientPagedResultList(self.provider, cb_vols,
  2410. 411 6 216.0 36.0 0.0 limit=limit, marker=marker)
  2411. Total time: 161.33 s
  2412. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2413. Function: create at line 413
  2414. Line # Hits Time Per Hit % Time Line Contents
  2415. ==============================================================
  2416. 413 @dispatch(event="provider.storage.volumes.create",
  2417. 414 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  2418. 415 @profile
  2419. 416 def create(self, label, size, zone, snapshot=None, description=None):
  2420. 417 15 173.0 11.5 0.0 AzureVolume.assert_valid_resource_label(label)
  2421. 418 5 240.0 48.0 0.0 disk_name = AzureVolume._generate_name_from_label(label, "cb-vol")
  2422. 419 5 6.0 1.2 0.0 tags = {'Label': label}
  2423. 420
  2424. 421 5 7.0 1.4 0.0 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  2425. 422 snapshot = (self.provider.storage.snapshots.get(snapshot)
  2426. 423 5 4.0 0.8 0.0 if snapshot and isinstance(snapshot, str) else snapshot)
  2427. 424
  2428. 425 5 4.0 0.8 0.0 if description:
  2429. 426 1 2.0 2.0 0.0 tags.update(Description=description)
  2430. 427
  2431. 428 5 2.0 0.4 0.0 if snapshot:
  2432. 429 params = {
  2433. 430 'location':
  2434. 431 zone_id or self.provider.azure_client.region_name,
  2435. 432 'creation_data': {
  2436. 433 'create_option': DiskCreateOption.copy,
  2437. 434 'source_uri': snapshot.resource_id
  2438. 435 },
  2439. 436 'tags': tags
  2440. 437 }
  2441. 438
  2442. 439 disk = self.provider.azure_client.create_snapshot_disk(disk_name,
  2443. 440 params)
  2444. 441
  2445. 442 else:
  2446. 443 params = {
  2447. 444 'location':
  2448. 445 5 5.0 1.0 0.0 zone_id or self.provider.region_name,
  2449. 446 5 5.0 1.0 0.0 'disk_size_gb': size,
  2450. 447 'creation_data': {
  2451. 448 5 14.0 2.8 0.0 'create_option': DiskCreateOption.empty
  2452. 449 },
  2453. 450 5 7.0 1.4 0.0 'tags': tags
  2454. 451 }
  2455. 452
  2456. 453 5 1059871.0 211974.2 0.7 disk = self.provider.azure_client.create_empty_disk(disk_name,
  2457. 454 5 156255105.0 31251021.0 96.9 params)
  2458. 455
  2459. 456 5 4014558.0 802911.6 2.5 azure_vol = self.provider.azure_client.get_disk(disk.id)
  2460. 457 5 123.0 24.6 0.0 cb_vol = AzureVolume(self.provider, azure_vol)
  2461. 458
  2462. 459 5 6.0 1.2 0.0 return cb_vol
  2463. Total time: 156.372 s
  2464. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2465. Function: delete at line 461
  2466. Line # Hits Time Per Hit % Time Line Contents
  2467. ==============================================================
  2468. 461 @dispatch(event="provider.storage.volumes.delete",
  2469. 462 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  2470. 463 @profile
  2471. 464 def delete(self, volume_id):
  2472. 465 5 21.0 4.2 0.0 vol_id = (volume_id.id if isinstance(volume_id, AzureVolume)
  2473. 466 else volume_id)
  2474. 467 5 156372385.0 31274477.0 100.0 self.provider.azure_client.delete_disk(vol_id)
  2475. Total time: 0 s
  2476. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2477. Function: get at line 474
  2478. Line # Hits Time Per Hit % Time Line Contents
  2479. ==============================================================
  2480. 474 @dispatch(event="provider.storage.snapshots.get",
  2481. 475 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  2482. 476 @profile
  2483. 477 def get(self, snapshot_id):
  2484. 478 try:
  2485. 479 snapshot = self.provider.azure_client.get_snapshot(snapshot_id)
  2486. 480 return AzureSnapshot(self.provider, snapshot)
  2487. 481 except (CloudError, InvalidValueException) as cloud_error:
  2488. 482 # Azure raises the cloud error if the resource not available
  2489. 483 log.exception(cloud_error)
  2490. 484 return None
  2491. Total time: 0 s
  2492. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2493. Function: find at line 486
  2494. Line # Hits Time Per Hit % Time Line Contents
  2495. ==============================================================
  2496. 486 @dispatch(event="provider.storage.snapshots.find",
  2497. 487 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  2498. 488 @profile
  2499. 489 def find(self, **kwargs):
  2500. 490 obj_list = self
  2501. 491 filters = ['label']
  2502. 492 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2503. 493
  2504. 494 # All kwargs should have been popped at this time.
  2505. 495 if len(kwargs) > 0:
  2506. 496 raise InvalidParamException(
  2507. 497 "Unrecognised parameters for search: %s. Supported "
  2508. 498 "attributes: %s" % (kwargs, ", ".join(filters)))
  2509. 499
  2510. 500 return ClientPagedResultList(self.provider,
  2511. 501 matches if matches else [])
  2512. Total time: 0 s
  2513. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2514. Function: list at line 503
  2515. Line # Hits Time Per Hit % Time Line Contents
  2516. ==============================================================
  2517. 503 @dispatch(event="provider.storage.snapshots.list",
  2518. 504 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  2519. 505 @profile
  2520. 506 def list(self, limit=None, marker=None):
  2521. 507 snaps = [AzureSnapshot(self.provider, obj)
  2522. 508 for obj in
  2523. 509 self.provider.azure_client.list_snapshots()]
  2524. 510 return ClientPagedResultList(self.provider, snaps, limit, marker)
  2525. Total time: 1.55794 s
  2526. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2527. Function: create at line 512
  2528. Line # Hits Time Per Hit % Time Line Contents
  2529. ==============================================================
  2530. 512 @dispatch(event="provider.storage.snapshots.create",
  2531. 513 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  2532. 514 @profile
  2533. 515 def create(self, label, volume, description=None):
  2534. 516 12 207.0 17.2 0.0 AzureSnapshot.assert_valid_resource_label(label)
  2535. 517 2 4.0 2.0 0.0 snapshot_name = AzureSnapshot._generate_name_from_label(label,
  2536. 518 2 90.0 45.0 0.0 "cb-snap")
  2537. 519 2 4.0 2.0 0.0 tags = {'Label': label}
  2538. 520 2 1.0 0.5 0.0 if description:
  2539. 521 2 4.0 2.0 0.0 tags.update(Description=description)
  2540. 522
  2541. 523 volume = (self.provider.storage.volumes.get(volume)
  2542. 524 2 5.0 2.5 0.0 if isinstance(volume, str) else volume)
  2543. 525
  2544. 526 params = {
  2545. 527 2 17.0 8.5 0.0 'location': self.provider.azure_client.region_name,
  2546. 528 'creation_data': {
  2547. 529 2 6.0 3.0 0.0 'create_option': DiskCreateOption.copy,
  2548. 530 2 6.0 3.0 0.0 'source_uri': volume.resource_id
  2549. 531 },
  2550. 532 2 4.0 2.0 0.0 'disk_size_gb': volume.size,
  2551. 533 2 2.0 1.0 0.0 'tags': tags
  2552. 534 }
  2553. 535
  2554. 536 2 5.0 2.5 0.0 azure_snap = self.provider.azure_client.create_snapshot(snapshot_name,
  2555. 537 2 1557587.0 778793.5 100.0 params)
  2556. 538 return AzureSnapshot(self.provider, azure_snap)
  2557. Total time: 0 s
  2558. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2559. Function: delete at line 540
  2560. Line # Hits Time Per Hit % Time Line Contents
  2561. ==============================================================
  2562. 540 @dispatch(event="provider.storage.snapshots.delete",
  2563. 541 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  2564. 542 @profile
  2565. 543 def delete(self, snapshot_id):
  2566. 544 snap_id = (snapshot_id.id if isinstance(snapshot_id, AzureSnapshot)
  2567. 545 else snapshot_id)
  2568. 546 self.provider.azure_client.delete_snapshot(snap_id)
  2569. Total time: 0 s
  2570. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2571. Function: get at line 553
  2572. Line # Hits Time Per Hit % Time Line Contents
  2573. ==============================================================
  2574. 553 @dispatch(event="provider.storage.buckets.get",
  2575. 554 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  2576. 555 @profile
  2577. 556 def get(self, bucket_id):
  2578. 557 """
  2579. 558 Returns a bucket given its ID. Returns ``None`` if the bucket
  2580. 559 does not exist.
  2581. 560 """
  2582. 561 try:
  2583. 562 bucket = self.provider.azure_client.get_container(bucket_id)
  2584. 563 return AzureBucket(self.provider, bucket)
  2585. 564 except AzureException as error:
  2586. 565 log.exception(error)
  2587. 566 return None
  2588. Total time: 0 s
  2589. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2590. Function: list at line 568
  2591. Line # Hits Time Per Hit % Time Line Contents
  2592. ==============================================================
  2593. 568 @dispatch(event="provider.storage.buckets.list",
  2594. 569 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  2595. 570 @profile
  2596. 571 def list(self, limit=None, marker=None):
  2597. 572 buckets = [AzureBucket(self.provider, bucket)
  2598. 573 for bucket
  2599. 574 in self.provider.azure_client.list_containers()[0]]
  2600. 575 return ClientPagedResultList(self.provider, buckets,
  2601. 576 limit=limit, marker=marker)
  2602. Total time: 0 s
  2603. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2604. Function: create at line 578
  2605. Line # Hits Time Per Hit % Time Line Contents
  2606. ==============================================================
  2607. 578 @dispatch(event="provider.storage.buckets.create",
  2608. 579 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  2609. 580 @profile
  2610. 581 def create(self, name, location=None):
  2611. 582 """
  2612. 583 Create a new bucket.
  2613. 584 """
  2614. 585 AzureBucket.assert_valid_resource_name(name)
  2615. 586 bucket = self.provider.azure_client.create_container(name)
  2616. 587 return AzureBucket(self.provider, bucket)
  2617. Total time: 0 s
  2618. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2619. Function: delete at line 589
  2620. Line # Hits Time Per Hit % Time Line Contents
  2621. ==============================================================
  2622. 589 @dispatch(event="provider.storage.buckets.delete",
  2623. 590 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  2624. 591 @profile
  2625. 592 def delete(self, bucket):
  2626. 593 """
  2627. 594 Delete this bucket.
  2628. 595 """
  2629. 596 b_id = bucket.id if isinstance(bucket, AzureBucket) else bucket
  2630. 597 self.provider.azure_client.delete_container(b_id)
  2631. Total time: 0 s
  2632. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2633. Function: get at line 604
  2634. Line # Hits Time Per Hit % Time Line Contents
  2635. ==============================================================
  2636. 604 @profile
  2637. 605 def get(self, bucket, object_id):
  2638. 606 """
  2639. 607 Retrieve a given object from this bucket.
  2640. 608 """
  2641. 609 try:
  2642. 610 obj = self.provider.azure_client.get_blob(bucket.name,
  2643. 611 object_id)
  2644. 612 return AzureBucketObject(self.provider, bucket, obj)
  2645. 613 except AzureException as azureEx:
  2646. 614 log.exception(azureEx)
  2647. 615 return None
  2648. Total time: 0 s
  2649. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2650. Function: list at line 617
  2651. Line # Hits Time Per Hit % Time Line Contents
  2652. ==============================================================
  2653. 617 @profile
  2654. 618 def list(self, bucket, limit=None, marker=None, prefix=None):
  2655. 619 """
  2656. 620 List all objects within this bucket.
  2657. 621
  2658. 622 :rtype: BucketObject
  2659. 623 :return: List of all available BucketObjects within this bucket.
  2660. 624 """
  2661. 625 objects = [AzureBucketObject(self.provider, bucket, obj)
  2662. 626 for obj in
  2663. 627 self.provider.azure_client.list_blobs(
  2664. 628 bucket.name, prefix=prefix)]
  2665. 629 return ClientPagedResultList(self.provider, objects,
  2666. 630 limit=limit, marker=marker)
  2667. Total time: 0 s
  2668. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2669. Function: find at line 632
  2670. Line # Hits Time Per Hit % Time Line Contents
  2671. ==============================================================
  2672. 632 @profile
  2673. 633 def find(self, bucket, **kwargs):
  2674. 634 obj_list = [AzureBucketObject(self.provider, bucket, obj)
  2675. 635 for obj in
  2676. 636 self.provider.azure_client.list_blobs(bucket.name)]
  2677. 637 filters = ['name']
  2678. 638 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2679. 639 return ClientPagedResultList(self.provider, list(matches))
  2680. Total time: 0 s
  2681. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2682. Function: create at line 641
  2683. Line # Hits Time Per Hit % Time Line Contents
  2684. ==============================================================
  2685. 641 @profile
  2686. 642 def create(self, bucket, name):
  2687. 643 self.provider.azure_client.create_blob_from_text(
  2688. 644 bucket.name, name, '')
  2689. 645 return self.get(bucket, name)
  2690. Total time: 0.000192 s
  2691. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2692. Function: get at line 677
  2693. Line # Hits Time Per Hit % Time Line Contents
  2694. ==============================================================
  2695. 677 @profile
  2696. 678 def get(self, image_id):
  2697. 679 """
  2698. 680 Returns an Image given its id
  2699. 681 """
  2700. 682 2 1.0 0.5 0.5 try:
  2701. 683 2 157.0 78.5 81.8 image = self.provider.azure_client.get_image(image_id)
  2702. 684 2 34.0 17.0 17.7 return AzureMachineImage(self.provider, image)
  2703. 685 except (CloudError, InvalidValueException) as cloud_error:
  2704. 686 # Azure raises the cloud error if the resource not available
  2705. 687 log.exception(cloud_error)
  2706. 688 return None
  2707. Total time: 0 s
  2708. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2709. Function: find at line 690
  2710. Line # Hits Time Per Hit % Time Line Contents
  2711. ==============================================================
  2712. 690 @profile
  2713. 691 def find(self, **kwargs):
  2714. 692 obj_list = self
  2715. 693 filters = ['label']
  2716. 694 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2717. 695
  2718. 696 # All kwargs should have been popped at this time.
  2719. 697 if len(kwargs) > 0:
  2720. 698 raise InvalidParamException(
  2721. 699 "Unrecognised parameters for search: %s. Supported "
  2722. 700 "attributes: %s" % (kwargs, ", ".join(filters)))
  2723. 701
  2724. 702 return ClientPagedResultList(self.provider,
  2725. 703 matches if matches else [])
  2726. Total time: 0 s
  2727. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2728. Function: list at line 705
  2729. Line # Hits Time Per Hit % Time Line Contents
  2730. ==============================================================
  2731. 705 @profile
  2732. 706 def list(self, filter_by_owner=True, limit=None, marker=None):
  2733. 707 """
  2734. 708 List all images.
  2735. 709 """
  2736. 710 azure_images = self.provider.azure_client.list_images()
  2737. 711 azure_gallery_refs = self.provider.azure_client.list_gallery_refs() \
  2738. 712 if not filter_by_owner else []
  2739. 713 cb_images = [AzureMachineImage(self.provider, img)
  2740. 714 for img in azure_images + azure_gallery_refs]
  2741. 715 return ClientPagedResultList(self.provider, cb_images,
  2742. 716 limit=limit, marker=marker)
  2743. Total time: 0 s
  2744. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2745. Function: create_launch_config at line 859
  2746. Line # Hits Time Per Hit % Time Line Contents
  2747. ==============================================================
  2748. 859 @profile
  2749. 860 def create_launch_config(self):
  2750. 861 return AzureLaunchConfig(self.provider)
  2751. Total time: 326.251 s
  2752. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2753. Function: create at line 863
  2754. Line # Hits Time Per Hit % Time Line Contents
  2755. ==============================================================
  2756. 863 @dispatch(event="provider.compute.instances.create",
  2757. 864 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  2758. 865 @profile
  2759. 866 def create(self, label, image, vm_type, subnet, zone,
  2760. 867 key_pair=None, vm_firewalls=None, user_data=None,
  2761. 868 launch_config=None, **kwargs):
  2762. 869 2 30.0 15.0 0.0 AzureInstance.assert_valid_resource_label(label)
  2763. 870 2 5.0 2.5 0.0 instance_name = AzureInstance._generate_name_from_label(label,
  2764. 871 2 98.0 49.0 0.0 "cb-ins")
  2765. 872
  2766. 873 2 5.0 2.5 0.0 image = (image if isinstance(image, AzureMachineImage) else
  2767. 874 2 229.0 114.5 0.0 self.provider.compute.images.get(image))
  2768. 875 2 3.0 1.5 0.0 if not isinstance(image, AzureMachineImage):
  2769. 876 raise Exception("Provided image %s is not a valid azure image"
  2770. 877 % image)
  2771. 878
  2772. 879 instance_size = vm_type.id if \
  2773. 880 2 6.0 3.0 0.0 isinstance(vm_type, VMType) else vm_type
  2774. 881
  2775. 882 2 4.0 2.0 0.0 if not subnet:
  2776. 883 # Azure has only a single zone per region; use the current one
  2777. 884 zone = self.provider.compute.regions.get(
  2778. 885 self.provider.region_name).zones[0]
  2779. 886 subnet = self.provider.networking.subnets.get_or_create_default(
  2780. 887 zone)
  2781. 888 else:
  2782. 889 subnet = (self.provider.networking.subnets.get(subnet)
  2783. 890 2 6.0 3.0 0.0 if isinstance(subnet, str) else subnet)
  2784. 891
  2785. 892 2 4.0 2.0 0.0 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  2786. 893
  2787. 894 subnet_id, zone_id, vm_firewall_id = \
  2788. 895 2 6.0 3.0 0.0 self._resolve_launch_options(instance_name,
  2789. 896 2 986587.0 493293.5 0.3 subnet, zone_id, vm_firewalls)
  2790. 897
  2791. 898 2 5.0 2.5 0.0 storage_profile = self._create_storage_profile(image, launch_config,
  2792. 899 2 834.0 417.0 0.0 instance_name, zone_id)
  2793. 900
  2794. 901 nic_params = {
  2795. 902 2 9.0 4.5 0.0 'location': self.provider.region_name,
  2796. 903 'ip_configurations': [{
  2797. 904 2 4.0 2.0 0.0 'name': instance_name + '_ip_config',
  2798. 905 2 3.0 1.5 0.0 'private_ip_allocation_method': 'Dynamic',
  2799. 906 'subnet': {
  2800. 907 2 4.0 2.0 0.0 'id': subnet_id
  2801. 908 }
  2802. 909 }]
  2803. 910 }
  2804. 911
  2805. 912 2 4.0 2.0 0.0 if vm_firewall_id:
  2806. 913 nic_params['network_security_group'] = {
  2807. 914 'id': vm_firewall_id
  2808. 915 }
  2809. 916 2 15.0 7.5 0.0 nic_info = self.provider.azure_client.create_nic(
  2810. 917 2 4.0 2.0 0.0 instance_name + '_nic',
  2811. 918 2 63209196.0 31604598.0 19.4 nic_params
  2812. 919 )
  2813. 920 # #! indicates shell script
  2814. 921 ud = '#cloud-config\n' + user_data \
  2815. 922 2 6.0 3.0 0.0 if user_data and not user_data.startswith('#!')\
  2816. 923 and not user_data.startswith('#cloud-config') else user_data
  2817. 924
  2818. 925 # Key_pair is mandatory in azure and it should not be None.
  2819. 926 2 4.0 2.0 0.0 temp_key_pair = None
  2820. 927 2 2.0 1.0 0.0 if key_pair:
  2821. 928 key_pair = (key_pair if isinstance(key_pair, AzureKeyPair)
  2822. 929 else self.provider.security.key_pairs.get(key_pair))
  2823. 930 else:
  2824. 931 # Create a temporary keypair if none is provided to keep Azure
  2825. 932 # happy, but the private key will be discarded, so it'll be all
  2826. 933 # but useless. However, this will allow an instance to be launched
  2827. 934 # without specifying a keypair, so users may still be able to login
  2828. 935 # if they have a preinstalled keypair/password baked into the image
  2829. 936 2 4.0 2.0 0.0 temp_kp_name = "".join(["cb-default-kp-",
  2830. 937 2 8.0 4.0 0.0 str(uuid.uuid5(uuid.NAMESPACE_OID,
  2831. 938 2 136.0 68.0 0.0 instance_name))[-6:]])
  2832. 939 2 36.0 18.0 0.0 key_pair = self.provider.security.key_pairs.create(
  2833. 940 2 22710659.0 11355329.5 7.0 name=temp_kp_name)
  2834. 941 2 4.0 2.0 0.0 temp_key_pair = key_pair
  2835. 942
  2836. 943 params = {
  2837. 944 2 4.0 2.0 0.0 'location': zone_id or self.provider.region_name,
  2838. 945 'os_profile': {
  2839. 946 2 9.0 4.5 0.0 'admin_username': self.provider.vm_default_user_name,
  2840. 947 2 3.0 1.5 0.0 'computer_name': instance_name,
  2841. 948 'linux_configuration': {
  2842. 949 2 4.0 2.0 0.0 "disable_password_authentication": True,
  2843. 950 "ssh": {
  2844. 951 2 2.0 1.0 0.0 "public_keys": [{
  2845. 952 "path":
  2846. 953 2 4.0 2.0 0.0 "/home/{}/.ssh/authorized_keys".format(
  2847. 954 2 7.0 3.5 0.0 self.provider.vm_default_user_name),
  2848. 955 2 19.0 9.5 0.0 "key_data": key_pair._key_pair.Key
  2849. 956 }]
  2850. 957 }
  2851. 958 }
  2852. 959 },
  2853. 960 'hardware_profile': {
  2854. 961 2 5.0 2.5 0.0 'vm_size': instance_size
  2855. 962 },
  2856. 963 'network_profile': {
  2857. 964 2 4.0 2.0 0.0 'network_interfaces': [{
  2858. 965 2 8.0 4.0 0.0 'id': nic_info.id
  2859. 966 }]
  2860. 967 },
  2861. 968 2 4.0 2.0 0.0 'storage_profile': storage_profile,
  2862. 969 2 4.0 2.0 0.0 'tags': {'Label': label}
  2863. 970 }
  2864. 971
  2865. 972 2 7.0 3.5 0.0 for disk_def in storage_profile.get('data_disks', []):
  2866. 973 params['tags'] = dict(disk_def.get('tags', {}), **params['tags'])
  2867. 974
  2868. 975 2 4.0 2.0 0.0 if user_data:
  2869. 976 custom_data = base64.b64encode(bytes(ud, 'utf-8'))
  2870. 977 params['os_profile']['custom_data'] = str(custom_data, 'utf-8')
  2871. 978
  2872. 979 2 3.0 1.5 0.0 if not temp_key_pair:
  2873. 980 params['tags'].update(Key_Pair=key_pair.id)
  2874. 981
  2875. 982 2 4.0 2.0 0.0 try:
  2876. 983 2 238277139.0 119138569.5 73.0 vm = self.provider.azure_client.create_vm(instance_name, params)
  2877. 984 except Exception as e:
  2878. 985 # If VM creation fails, attempt to clean up intermediary resources
  2879. 986 self.provider.azure_client.delete_nic(nic_info.id)
  2880. 987 for disk_def in storage_profile.get('data_disks', []):
  2881. 988 if disk_def.get('tags', {}).get('delete_on_terminate'):
  2882. 989 disk_id = disk_def.get('managed_disk', {}).get('id')
  2883. 990 if disk_id:
  2884. 991 vol = self.provider.storage.volumes.get(disk_id)
  2885. 992 vol.delete()
  2886. 993 raise e
  2887. 994 finally:
  2888. 995 2 8.0 4.0 0.0 if temp_key_pair:
  2889. 996 2 368600.0 184300.0 0.1 temp_key_pair.delete()
  2890. 997 2 697523.0 348761.5 0.2 return AzureInstance(self.provider, vm)
  2891. Total time: 0 s
  2892. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2893. Function: list at line 999
  2894. Line # Hits Time Per Hit % Time Line Contents
  2895. ==============================================================
  2896. 999 @dispatch(event="provider.compute.instances.list",
  2897. 1000 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  2898. 1001 @profile
  2899. 1002 def list(self, limit=None, marker=None):
  2900. 1003 """
  2901. 1004 List all instances.
  2902. 1005 """
  2903. 1006 instances = [AzureInstance(self.provider, inst)
  2904. 1007 for inst in self.provider.azure_client.list_vm()]
  2905. 1008 return ClientPagedResultList(self.provider, instances,
  2906. 1009 limit=limit, marker=marker)
  2907. Total time: 0 s
  2908. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2909. Function: get at line 1011
  2910. Line # Hits Time Per Hit % Time Line Contents
  2911. ==============================================================
  2912. 1011 @dispatch(event="provider.compute.instances.get",
  2913. 1012 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  2914. 1013 @profile
  2915. 1014 def get(self, instance_id):
  2916. 1015 """
  2917. 1016 Returns an instance given its id. Returns None
  2918. 1017 if the object does not exist.
  2919. 1018 """
  2920. 1019 try:
  2921. 1020 vm = self.provider.azure_client.get_vm(instance_id)
  2922. 1021 return AzureInstance(self.provider, vm)
  2923. 1022 except (CloudError, InvalidValueException) as cloud_error:
  2924. 1023 # Azure raises the cloud error if the resource not available
  2925. 1024 log.exception(cloud_error)
  2926. 1025 return None
  2927. Total time: 0 s
  2928. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2929. Function: find at line 1027
  2930. Line # Hits Time Per Hit % Time Line Contents
  2931. ==============================================================
  2932. 1027 @dispatch(event="provider.compute.instances.find",
  2933. 1028 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  2934. 1029 @profile
  2935. 1030 def find(self, **kwargs):
  2936. 1031 obj_list = self
  2937. 1032 filters = ['label']
  2938. 1033 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2939. 1034
  2940. 1035 # All kwargs should have been popped at this time.
  2941. 1036 if len(kwargs) > 0:
  2942. 1037 raise InvalidParamException(
  2943. 1038 "Unrecognised parameters for search: %s. Supported "
  2944. 1039 "attributes: %s" % (kwargs, ", ".join(filters)))
  2945. 1040
  2946. 1041 return ClientPagedResultList(self.provider,
  2947. 1042 matches if matches else [])
  2948. Total time: 292.517 s
  2949. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2950. Function: delete at line 1044
  2951. Line # Hits Time Per Hit % Time Line Contents
  2952. ==============================================================
  2953. 1044 @dispatch(event="provider.compute.instances.delete",
  2954. 1045 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  2955. 1046 @profile
  2956. 1047 def delete(self, instance):
  2957. 1048 """
  2958. 1049 Permanently terminate this instance.
  2959. 1050 After deleting the VM. we are deleting the network interface
  2960. 1051 associated to the instance, and also removing OS disk and data disks
  2961. 1052 where tag with name 'delete_on_terminate' has value True.
  2962. 1053 """
  2963. 1054 2 5.0 2.5 0.0 ins = (instance if isinstance(instance, AzureInstance) else
  2964. 1055 self.get(instance))
  2965. 1056 2 2.0 1.0 0.0 if not instance:
  2966. 1057 return
  2967. 1058
  2968. 1059 # Remove IPs first to avoid a network interface conflict
  2969. 1060 # pylint:disable=protected-access
  2970. 1061 2 732860.0 366430.0 0.3 for public_ip_id in ins._public_ip_ids:
  2971. 1062 ins.remove_floating_ip(public_ip_id)
  2972. 1063 2 154126743.0 77063371.5 52.7 self.provider.azure_client.deallocate_vm(ins.id)
  2973. 1064 2 52998383.0 26499191.5 18.1 self.provider.azure_client.delete_vm(ins.id)
  2974. 1065 # pylint:disable=protected-access
  2975. 1066 4 28.0 7.0 0.0 for nic_id in ins._nic_ids:
  2976. 1067 2 22835045.0 11417522.5 7.8 self.provider.azure_client.delete_nic(nic_id)
  2977. 1068 # pylint:disable=protected-access
  2978. 1069 2 7.0 3.5 0.0 for data_disk in ins._vm.storage_profile.data_disks:
  2979. 1070 if data_disk.managed_disk:
  2980. 1071 # pylint:disable=protected-access
  2981. 1072 if ins._vm.tags.get('delete_on_terminate',
  2982. 1073 'False') == 'True':
  2983. 1074 self.provider.azure_client. \
  2984. 1075 delete_disk(data_disk.managed_disk.id)
  2985. 1076 # pylint:disable=protected-access
  2986. 1077 2 4.0 2.0 0.0 if ins._vm.storage_profile.os_disk.managed_disk:
  2987. 1078 2 17.0 8.5 0.0 self.provider.azure_client. \
  2988. 1079 2 61823804.0 30911902.0 21.1 delete_disk(ins._vm.storage_profile.os_disk.managed_disk.id)
  2989. Total time: 0 s
  2990. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2991. Function: list at line 1095
  2992. Line # Hits Time Per Hit % Time Line Contents
  2993. ==============================================================
  2994. 1095 @dispatch(event="provider.compute.vm_types.list",
  2995. 1096 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  2996. 1097 @profile
  2997. 1098 def list(self, limit=None, marker=None):
  2998. 1099 vm_types = [AzureVMType(self.provider, vm_type)
  2999. 1100 for vm_type in self.instance_data]
  3000. 1101 return ClientPagedResultList(self.provider, vm_types,
  3001. 1102 limit=limit, marker=marker)
  3002. Total time: 0.406326 s
  3003. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3004. Function: get at line 1109
  3005. Line # Hits Time Per Hit % Time Line Contents
  3006. ==============================================================
  3007. 1109 @dispatch(event="provider.compute.regions.get",
  3008. 1110 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  3009. 1111 @profile
  3010. 1112 def get(self, region_id):
  3011. 1113 2 3.0 1.5 0.0 region = None
  3012. 1114 6 406215.0 67702.5 100.0 for azureRegion in self.provider.azure_client.list_locations():
  3013. 1115 6 7.0 1.2 0.0 if azureRegion.name == region_id:
  3014. 1116 2 37.0 18.5 0.0 region = AzureRegion(self.provider, azureRegion)
  3015. 1117 2 62.0 31.0 0.0 break
  3016. 1118 2 2.0 1.0 0.0 return region
  3017. Total time: 0 s
  3018. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3019. Function: list at line 1120
  3020. Line # Hits Time Per Hit % Time Line Contents
  3021. ==============================================================
  3022. 1120 @dispatch(event="provider.compute.regions.list",
  3023. 1121 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  3024. 1122 @profile
  3025. 1123 def list(self, limit=None, marker=None):
  3026. 1124 regions = [AzureRegion(self.provider, region)
  3027. 1125 for region in self.provider.azure_client.list_locations()]
  3028. 1126 return ClientPagedResultList(self.provider, regions,
  3029. 1127 limit=limit, marker=marker)
  3030. Total time: 1.69307 s
  3031. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3032. Function: get at line 1168
  3033. Line # Hits Time Per Hit % Time Line Contents
  3034. ==============================================================
  3035. 1168 @dispatch(event="provider.networking.networks.get",
  3036. 1169 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  3037. 1170 @profile
  3038. 1171 def get(self, network_id):
  3039. 1172 6 6.0 1.0 0.0 try:
  3040. 1173 6 1692916.0 282152.7 100.0 network = self.provider.azure_client.get_network(network_id)
  3041. 1174 6 148.0 24.7 0.0 return AzureNetwork(self.provider, network)
  3042. 1175 except (CloudError, InvalidValueException) as cloud_error:
  3043. 1176 # Azure raises the cloud error if the resource not available
  3044. 1177 log.exception(cloud_error)
  3045. 1178 return None
  3046. Total time: 1.44535 s
  3047. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3048. Function: list at line 1180
  3049. Line # Hits Time Per Hit % Time Line Contents
  3050. ==============================================================
  3051. 1180 @dispatch(event="provider.networking.networks.list",
  3052. 1181 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  3053. 1182 @profile
  3054. 1183 def list(self, limit=None, marker=None):
  3055. 1184 2 3.0 1.5 0.0 networks = [AzureNetwork(self.provider, network)
  3056. 1185 2 1445222.0 722611.0 100.0 for network in self.provider.azure_client.list_networks()]
  3057. 1186 2 11.0 5.5 0.0 return ClientPagedResultList(self.provider, networks,
  3058. 1187 2 110.0 55.0 0.0 limit=limit, marker=marker)
  3059. Total time: 0 s
  3060. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3061. Function: create at line 1189
  3062. Line # Hits Time Per Hit % Time Line Contents
  3063. ==============================================================
  3064. 1189 @dispatch(event="provider.networking.networks.create",
  3065. 1190 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  3066. 1191 @profile
  3067. 1192 def create(self, label, cidr_block):
  3068. 1193 AzureNetwork.assert_valid_resource_label(label)
  3069. 1194 params = {
  3070. 1195 'location': self.provider.azure_client.region_name,
  3071. 1196 'address_space': {
  3072. 1197 'address_prefixes': [cidr_block]
  3073. 1198 },
  3074. 1199 'tags': {'Label': label}
  3075. 1200 }
  3076. 1201
  3077. 1202 network_name = AzureNetwork._generate_name_from_label(label, 'cb-net')
  3078. 1203
  3079. 1204 az_network = self.provider.azure_client.create_network(network_name,
  3080. 1205 params)
  3081. 1206 cb_network = AzureNetwork(self.provider, az_network)
  3082. 1207 return cb_network
  3083. Total time: 0 s
  3084. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3085. Function: delete at line 1209
  3086. Line # Hits Time Per Hit % Time Line Contents
  3087. ==============================================================
  3088. 1209 @dispatch(event="provider.networking.networks.delete",
  3089. 1210 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  3090. 1211 @profile
  3091. 1212 def delete(self, network):
  3092. 1213 net_id = network.id if isinstance(network, AzureNetwork) else network
  3093. 1214 if net_id:
  3094. 1215 self.provider.azure_client.delete_network(net_id)
  3095. Total time: 0 s
  3096. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3097. Function: get at line 1245
  3098. Line # Hits Time Per Hit % Time Line Contents
  3099. ==============================================================
  3100. 1245 @dispatch(event="provider.networking.subnets.get",
  3101. 1246 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  3102. 1247 @profile
  3103. 1248 def get(self, subnet_id):
  3104. 1249 """
  3105. 1250 Azure does not provide an api to get the subnet directly by id.
  3106. 1251 It also requires the network id.
  3107. 1252 To make it consistent across the providers the following code
  3108. 1253 gets the specific code from the subnet list.
  3109. 1254 """
  3110. 1255 try:
  3111. 1256 azure_subnet = self.provider.azure_client.get_subnet(subnet_id)
  3112. 1257 return AzureSubnet(self.provider,
  3113. 1258 azure_subnet) if azure_subnet else None
  3114. 1259 except (CloudError, InvalidValueException) as cloud_error:
  3115. 1260 # Azure raises the cloud error if the resource not available
  3116. 1261 log.exception(cloud_error)
  3117. 1262 return None
  3118. Total time: 0 s
  3119. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3120. Function: list at line 1264
  3121. Line # Hits Time Per Hit % Time Line Contents
  3122. ==============================================================
  3123. 1264 @dispatch(event="provider.networking.subnets.list",
  3124. 1265 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  3125. 1266 @profile
  3126. 1267 def list(self, network=None, limit=None, marker=None):
  3127. 1268 return ClientPagedResultList(self.provider,
  3128. 1269 self._list_subnets(network),
  3129. 1270 limit=limit, marker=marker)
  3130. Total time: 3.43614 s
  3131. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3132. Function: find at line 1272
  3133. Line # Hits Time Per Hit % Time Line Contents
  3134. ==============================================================
  3135. 1272 @dispatch(event="provider.networking.subnets.find",
  3136. 1273 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  3137. 1274 @profile
  3138. 1275 def find(self, network=None, **kwargs):
  3139. 1276 2 2276552.0 1138276.0 66.3 obj_list = self._list_subnets(network)
  3140. 1277 2 7.0 3.5 0.0 filters = ['label']
  3141. 1278 2 1159514.0 579757.0 33.7 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  3142. 1279
  3143. 1280 2 5.0 2.5 0.0 return ClientPagedResultList(self.provider,
  3144. 1281 2 64.0 32.0 0.0 matches if matches else [])
  3145. Total time: 0 s
  3146. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3147. Function: create at line 1283
  3148. Line # Hits Time Per Hit % Time Line Contents
  3149. ==============================================================
  3150. 1283 @dispatch(event="provider.networking.subnets.create",
  3151. 1284 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  3152. 1285 @profile
  3153. 1286 def create(self, label, network, cidr_block, zone):
  3154. 1287 AzureSubnet.assert_valid_resource_label(label)
  3155. 1288 # Although Subnet doesn't support tags in Azure, we use the parent
  3156. 1289 # Network's tags to track its subnets' labels
  3157. 1290 subnet_name = AzureSubnet._generate_name_from_label(label, "cb-sn")
  3158. 1291
  3159. 1292 network_id = network.id \
  3160. 1293 if isinstance(network, Network) else network
  3161. 1294
  3162. 1295 subnet_info = self.provider.azure_client\
  3163. 1296 .create_subnet(
  3164. 1297 network_id,
  3165. 1298 subnet_name,
  3166. 1299 {
  3167. 1300 'address_prefix': cidr_block
  3168. 1301 }
  3169. 1302 )
  3170. 1303
  3171. 1304 subnet = AzureSubnet(self.provider, subnet_info)
  3172. 1305 subnet.label = label
  3173. 1306 return subnet
  3174. Total time: 0 s
  3175. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3176. Function: delete at line 1308
  3177. Line # Hits Time Per Hit % Time Line Contents
  3178. ==============================================================
  3179. 1308 @dispatch(event="provider.networking.subnets.delete",
  3180. 1309 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  3181. 1310 @profile
  3182. 1311 def delete(self, subnet):
  3183. 1312 sn = subnet if isinstance(subnet, AzureSubnet) else self.get(subnet)
  3184. 1313 if sn:
  3185. 1314 self.provider.azure_client.delete_subnet(sn.id)
  3186. 1315 # Although Subnet doesn't support labels, we use the parent
  3187. 1316 # Network's tags to track the subnet's labels, thus that
  3188. 1317 # network-level tag must be deleted with the subnet
  3189. 1318 net_id = sn.network_id
  3190. 1319 az_network = self.provider.azure_client.get_network(net_id)
  3191. 1320 az_network.tags.pop(sn.tag_name)
  3192. 1321 self.provider.azure_client.update_network_tags(
  3193. 1322 az_network.id, az_network)
  3194. Total time: 0 s
  3195. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3196. Function: get at line 1329
  3197. Line # Hits Time Per Hit % Time Line Contents
  3198. ==============================================================
  3199. 1329 @dispatch(event="provider.networking.routers.get",
  3200. 1330 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  3201. 1331 @profile
  3202. 1332 def get(self, router_id):
  3203. 1333 try:
  3204. 1334 route = self.provider.azure_client.get_route_table(router_id)
  3205. 1335 return AzureRouter(self.provider, route)
  3206. 1336 except (CloudError, InvalidValueException) as cloud_error:
  3207. 1337 # Azure raises the cloud error if the resource not available
  3208. 1338 log.exception(cloud_error)
  3209. 1339 return None
  3210. Total time: 0 s
  3211. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3212. Function: find at line 1341
  3213. Line # Hits Time Per Hit % Time Line Contents
  3214. ==============================================================
  3215. 1341 @dispatch(event="provider.networking.routers.find",
  3216. 1342 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  3217. 1343 @profile
  3218. 1344 def find(self, **kwargs):
  3219. 1345 obj_list = self
  3220. 1346 filters = ['label']
  3221. 1347 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  3222. 1348
  3223. 1349 # All kwargs should have been popped at this time.
  3224. 1350 if len(kwargs) > 0:
  3225. 1351 raise InvalidParamException(
  3226. 1352 "Unrecognised parameters for search: %s. Supported "
  3227. 1353 "attributes: %s" % (kwargs, ", ".join(filters)))
  3228. 1354
  3229. 1355 return ClientPagedResultList(self.provider,
  3230. 1356 matches if matches else [])
  3231. Total time: 0 s
  3232. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3233. Function: list at line 1358
  3234. Line # Hits Time Per Hit % Time Line Contents
  3235. ==============================================================
  3236. 1358 @dispatch(event="provider.networking.routers.list",
  3237. 1359 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  3238. 1360 @profile
  3239. 1361 def list(self, limit=None, marker=None):
  3240. 1362 routes = [AzureRouter(self.provider, route)
  3241. 1363 for route in
  3242. 1364 self.provider.azure_client.list_route_tables()]
  3243. 1365 return ClientPagedResultList(self.provider,
  3244. 1366 routes,
  3245. 1367 limit=limit, marker=marker)
  3246. Total time: 0 s
  3247. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3248. Function: create at line 1369
  3249. Line # Hits Time Per Hit % Time Line Contents
  3250. ==============================================================
  3251. 1369 @dispatch(event="provider.networking.routers.create",
  3252. 1370 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  3253. 1371 @profile
  3254. 1372 def create(self, label, network):
  3255. 1373 router_name = AzureRouter._generate_name_from_label(label, "cb-router")
  3256. 1374
  3257. 1375 parameters = {"location": self.provider.region_name,
  3258. 1376 "tags": {'Label': label}}
  3259. 1377
  3260. 1378 route = self.provider.azure_client. \
  3261. 1379 create_route_table(router_name, parameters)
  3262. 1380 return AzureRouter(self.provider, route)
  3263. Total time: 0 s
  3264. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3265. Function: delete at line 1382
  3266. Line # Hits Time Per Hit % Time Line Contents
  3267. ==============================================================
  3268. 1382 @dispatch(event="provider.networking.routers.delete",
  3269. 1383 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  3270. 1384 @profile
  3271. 1385 def delete(self, router):
  3272. 1386 r = router if isinstance(router, AzureRouter) else self.get(router)
  3273. 1387 if r:
  3274. 1388 self.provider.azure_client.delete_route_table(r.name)
  3275. Total time: 0 s
  3276. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3277. Function: get_or_create at line 1403
  3278. Line # Hits Time Per Hit % Time Line Contents
  3279. ==============================================================
  3280. 1403 @dispatch(event="provider.networking.gateways.get_or_create",
  3281. 1404 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  3282. 1405 @profile
  3283. 1406 def get_or_create(self, network):
  3284. 1407 return self._gateway_singleton(network)
  3285. Total time: 0 s
  3286. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3287. Function: list at line 1409
  3288. Line # Hits Time Per Hit % Time Line Contents
  3289. ==============================================================
  3290. 1409 @dispatch(event="provider.networking.gateways.list",
  3291. 1410 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  3292. 1411 @profile
  3293. 1412 def list(self, network, limit=None, marker=None):
  3294. 1413 gws = [self._gateway_singleton(network)]
  3295. 1414 return ClientPagedResultList(self.provider,
  3296. 1415 gws,
  3297. 1416 limit=limit, marker=marker)
  3298. Total time: 0 s
  3299. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3300. Function: delete at line 1418
  3301. Line # Hits Time Per Hit % Time Line Contents
  3302. ==============================================================
  3303. 1418 @dispatch(event="provider.networking.gateways.delete",
  3304. 1419 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  3305. 1420 @profile
  3306. 1421 def delete(self, network, gateway):
  3307. 1422 pass
  3308. Total time: 0 s
  3309. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3310. Function: get at line 1430
  3311. Line # Hits Time Per Hit % Time Line Contents
  3312. ==============================================================
  3313. 1430 @dispatch(event="provider.networking.floating_ips.get",
  3314. 1431 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  3315. 1432 @profile
  3316. 1433 def get(self, gateway, fip_id):
  3317. 1434 try:
  3318. 1435 az_ip = self.provider.azure_client.get_floating_ip(fip_id)
  3319. 1436 except (CloudError, InvalidValueException) as cloud_error:
  3320. 1437 # Azure raises the cloud error if the resource not available
  3321. 1438 log.exception(cloud_error)
  3322. 1439 return None
  3323. 1440 return AzureFloatingIP(self.provider, az_ip)
  3324. Total time: 0 s
  3325. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3326. Function: list at line 1442
  3327. Line # Hits Time Per Hit % Time Line Contents
  3328. ==============================================================
  3329. 1442 @dispatch(event="provider.networking.floating_ips.list",
  3330. 1443 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  3331. 1444 @profile
  3332. 1445 def list(self, gateway, limit=None, marker=None):
  3333. 1446 floating_ips = [AzureFloatingIP(self.provider, floating_ip)
  3334. 1447 for floating_ip in self.provider.azure_client.
  3335. 1448 list_floating_ips()]
  3336. 1449 return ClientPagedResultList(self.provider, floating_ips,
  3337. 1450 limit=limit, marker=marker)
  3338. Total time: 0 s
  3339. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3340. Function: create at line 1452
  3341. Line # Hits Time Per Hit % Time Line Contents
  3342. ==============================================================
  3343. 1452 @dispatch(event="provider.networking.floating_ips.create",
  3344. 1453 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  3345. 1454 @profile
  3346. 1455 def create(self, gateway):
  3347. 1456 public_ip_parameters = {
  3348. 1457 'location': self.provider.azure_client.region_name,
  3349. 1458 'public_ip_allocation_method': 'Static'
  3350. 1459 }
  3351. 1460
  3352. 1461 public_ip_name = AzureFloatingIP._generate_name_from_label(
  3353. 1462 None, 'cb-fip-')
  3354. 1463
  3355. 1464 floating_ip = self.provider.azure_client.\
  3356. 1465 create_floating_ip(public_ip_name, public_ip_parameters)
  3357. 1466 return AzureFloatingIP(self.provider, floating_ip)
  3358. Total time: 0 s
  3359. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3360. Function: delete at line 1468
  3361. Line # Hits Time Per Hit % Time Line Contents
  3362. ==============================================================
  3363. 1468 @dispatch(event="provider.networking.floating_ips.delete",
  3364. 1469 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  3365. 1470 @profile
  3366. 1471 def delete(self, gateway, fip):
  3367. 1472 fip_id = fip.id if isinstance(fip, AzureFloatingIP) else fip
  3368. 1473 self.provider.azure_client.delete_floating_ip(fip_id)
  3369. Total time: 0 s
  3370. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3371. Function: label at line 482
  3372. Line # Hits Time Per Hit % Time Line Contents
  3373. ==============================================================
  3374. 482 @label.setter
  3375. 483 @profile
  3376. 484 def label(self, value):
  3377. 485 self.assert_valid_resource_label(value)
  3378. 486 tag_name = "_".join(["firewall", self.name, "label"])
  3379. 487 helpers.modify_or_add_metadata_item(self._provider, tag_name, value)
  3380. Total time: 0 s
  3381. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3382. Function: description at line 508
  3383. Line # Hits Time Per Hit % Time Line Contents
  3384. ==============================================================
  3385. 508 @description.setter
  3386. 509 @profile
  3387. 510 def description(self, value):
  3388. 511 # Change the description on all rules
  3389. 512 for fw in self._delegate.iter_firewalls(self._vm_firewall,
  3390. 513 self._network.name):
  3391. 514 fw['description'] = value or ''
  3392. 515 response = (self._provider
  3393. 516 .gcp_compute
  3394. 517 .firewalls()
  3395. 518 .update(project=self._provider.project_name,
  3396. 519 firewall=fw['name'],
  3397. 520 body=fw)
  3398. 521 .execute())
  3399. 522 self._provider.wait_for_operation(response)
  3400. 523 # Set back to None so that the next time the user gets it, it updates
  3401. 524 # but don't force update here to avoid more overhead
  3402. 525 self._description = None
  3403. Total time: 0 s
  3404. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3405. Function: refresh at line 542
  3406. Line # Hits Time Per Hit % Time Line Contents
  3407. ==============================================================
  3408. 542 @profile
  3409. 543 def refresh(self):
  3410. 544 fw = self._provider.security.vm_firewalls.get(self.id)
  3411. 545 # restore all internal state
  3412. 546 if fw:
  3413. 547 # pylint:disable=protected-access
  3414. 548 self._delegate = fw._delegate
  3415. 549 # pylint:disable=protected-access
  3416. 550 self._description = fw._description
  3417. 551 # pylint:disable=protected-access
  3418. 552 self._network = fw._network
  3419. 553 # pylint:disable=protected-access
  3420. 554 self._rule_container = fw._rule_container
  3421. Total time: 0 s
  3422. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3423. Function: label at line 713
  3424. Line # Hits Time Per Hit % Time Line Contents
  3425. ==============================================================
  3426. 713 @label.setter
  3427. 714 # pylint:disable=arguments-differ
  3428. 715 @profile
  3429. 716 def label(self, value):
  3430. 717 req = (self._provider
  3431. 718 .gcp_compute
  3432. 719 .images()
  3433. 720 .setLabels(project=self._provider.project_name,
  3434. 721 resource=self.name,
  3435. 722 body={}))
  3436. 723
  3437. 724 helpers.change_label(self, 'cblabel', value, '_gcp_image', req)
  3438. Total time: 0 s
  3439. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3440. Function: refresh at line 761
  3441. Line # Hits Time Per Hit % Time Line Contents
  3442. ==============================================================
  3443. 761 @profile
  3444. 762 def refresh(self):
  3445. 763 """
  3446. 764 Refreshes the state of this instance by re-querying the cloud provider
  3447. 765 for its latest state.
  3448. 766 """
  3449. 767 image = self._provider.compute.images.get(self.id)
  3450. 768 if image:
  3451. 769 # pylint:disable=protected-access
  3452. 770 self._gcp_image = image._gcp_image
  3453. 771 else:
  3454. 772 # image no longer exists
  3455. 773 self._gcp_image['status'] = MachineImageState.UNKNOWN
  3456. Total time: 0 s
  3457. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3458. Function: label at line 822
  3459. Line # Hits Time Per Hit % Time Line Contents
  3460. ==============================================================
  3461. 822 @label.setter
  3462. 823 # pylint:disable=arguments-differ
  3463. 824 @profile
  3464. 825 def label(self, value):
  3465. 826 req = (self._provider
  3466. 827 .gcp_compute
  3467. 828 .instances()
  3468. 829 .setLabels(project=self._provider.project_name,
  3469. 830 zone=self.zone_name,
  3470. 831 instance=self.name,
  3471. 832 body={}))
  3472. 833
  3473. 834 helpers.change_label(self, 'cblabel', value, '_gcp_instance', req)
  3474. Total time: 0 s
  3475. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3476. Function: refresh at line 1237
  3477. Line # Hits Time Per Hit % Time Line Contents
  3478. ==============================================================
  3479. 1237 @profile
  3480. 1238 def refresh(self):
  3481. 1239 """
  3482. 1240 Refreshes the state of this instance by re-querying the cloud provider
  3483. 1241 for its latest state.
  3484. 1242 """
  3485. 1243 inst = self._provider.compute.instances.get(self.id)
  3486. 1244 if inst:
  3487. 1245 # pylint:disable=protected-access
  3488. 1246 self._gcp_instance = inst._gcp_instance
  3489. 1247 else:
  3490. 1248 # instance no longer exists
  3491. 1249 self._gcp_instance['status'] = InstanceState.UNKNOWN
  3492. Total time: 0 s
  3493. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3494. Function: label at line 1305
  3495. Line # Hits Time Per Hit % Time Line Contents
  3496. ==============================================================
  3497. 1305 @label.setter
  3498. 1306 @profile
  3499. 1307 def label(self, value):
  3500. 1308 self.assert_valid_resource_label(value)
  3501. 1309 tag_name = "_".join(["network", self.name, "label"])
  3502. 1310 helpers.modify_or_add_metadata_item(self._provider, tag_name, value)
  3503. Total time: 0 s
  3504. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3505. Function: refresh at line 1340
  3506. Line # Hits Time Per Hit % Time Line Contents
  3507. ==============================================================
  3508. 1340 @profile
  3509. 1341 def refresh(self):
  3510. 1342 net = self._provider.networking.networks.get(self.id)
  3511. 1343 if net:
  3512. 1344 # pylint:disable=protected-access
  3513. 1345 self._network = net._network
  3514. 1346 else:
  3515. 1347 # network no longer exists
  3516. 1348 self._network['status'] = NetworkState.UNKNOWN
  3517. Total time: 0 s
  3518. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3519. Function: refresh at line 1390
  3520. Line # Hits Time Per Hit % Time Line Contents
  3521. ==============================================================
  3522. 1390 @profile
  3523. 1391 def refresh(self):
  3524. 1392 # pylint:disable=protected-access
  3525. 1393 fip = self._provider.networking._floating_ips.get(None, self.id)
  3526. 1394 # pylint:disable=protected-access
  3527. 1395 self._ip = fip._ip
  3528. 1396 self._process_ip_users()
  3529. Total time: 0 s
  3530. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3531. Function: label at line 1445
  3532. Line # Hits Time Per Hit % Time Line Contents
  3533. ==============================================================
  3534. 1445 @label.setter
  3535. 1446 @profile
  3536. 1447 def label(self, value):
  3537. 1448 self.assert_valid_resource_label(value)
  3538. 1449 tag_name = "_".join(["router", self.name, "label"])
  3539. 1450 helpers.modify_or_add_metadata_item(self._provider, tag_name, value)
  3540. Total time: 0 s
  3541. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3542. Function: refresh at line 1457
  3543. Line # Hits Time Per Hit % Time Line Contents
  3544. ==============================================================
  3545. 1457 @profile
  3546. 1458 def refresh(self):
  3547. 1459 router = self._provider.networking.routers.get(self.id)
  3548. 1460 if router:
  3549. 1461 # pylint:disable=protected-access
  3550. 1462 self._router = router._router
  3551. 1463 else:
  3552. 1464 # router no longer exists
  3553. 1465 self._router['status'] = RouterState.UNKNOWN
  3554. Total time: 0 s
  3555. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3556. Function: refresh at line 1523
  3557. Line # Hits Time Per Hit % Time Line Contents
  3558. ==============================================================
  3559. 1523 @profile
  3560. 1524 def refresh(self):
  3561. 1525 pass
  3562. Total time: 0 s
  3563. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3564. Function: label at line 1565
  3565. Line # Hits Time Per Hit % Time Line Contents
  3566. ==============================================================
  3567. 1565 @label.setter
  3568. 1566 @profile
  3569. 1567 def label(self, value):
  3570. 1568 self.assert_valid_resource_label(value)
  3571. 1569 tag_name = "_".join(["subnet", self.name, "label"])
  3572. 1570 helpers.modify_or_add_metadata_item(self._provider, tag_name, value)
  3573. Total time: 0 s
  3574. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3575. Function: refresh at line 1603
  3576. Line # Hits Time Per Hit % Time Line Contents
  3577. ==============================================================
  3578. 1603 @profile
  3579. 1604 def refresh(self):
  3580. 1605 subnet = self._provider.networking.subnets.get(self.id)
  3581. 1606 if subnet:
  3582. 1607 # pylint:disable=protected-access
  3583. 1608 self._subnet = subnet._subnet
  3584. 1609 else:
  3585. 1610 # subnet no longer exists
  3586. 1611 self._subnet['status'] = SubnetState.UNKNOWN
  3587. Total time: 0 s
  3588. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3589. Function: label at line 1643
  3590. Line # Hits Time Per Hit % Time Line Contents
  3591. ==============================================================
  3592. 1643 @label.setter
  3593. 1644 @profile
  3594. 1645 def label(self, value):
  3595. 1646 req = (self._provider
  3596. 1647 .gcp_compute
  3597. 1648 .disks()
  3598. 1649 .setLabels(project=self._provider.project_name,
  3599. 1650 zone=self.zone_name,
  3600. 1651 resource=self.name,
  3601. 1652 body={}))
  3602. 1653
  3603. 1654 helpers.change_label(self, 'cblabel', value, '_volume', req)
  3604. Total time: 0 s
  3605. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3606. Function: description at line 1663
  3607. Line # Hits Time Per Hit % Time Line Contents
  3608. ==============================================================
  3609. 1663 @description.setter
  3610. 1664 @profile
  3611. 1665 def description(self, value):
  3612. 1666 req = (self._provider
  3613. 1667 .gcp_compute
  3614. 1668 .disks()
  3615. 1669 .setLabels(project=self._provider.project_name,
  3616. 1670 zone=self.zone_name,
  3617. 1671 resource=self.name,
  3618. 1672 body={}))
  3619. 1673
  3620. 1674 helpers.change_label(self, 'description', value, '_volume', req)
  3621. Total time: 0 s
  3622. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3623. Function: refresh at line 1789
  3624. Line # Hits Time Per Hit % Time Line Contents
  3625. ==============================================================
  3626. 1789 @profile
  3627. 1790 def refresh(self):
  3628. 1791 """
  3629. 1792 Refreshes the state of this volume by re-querying the cloud provider
  3630. 1793 for its latest state.
  3631. 1794 """
  3632. 1795 vol = self._provider.storage.volumes.get(self.id)
  3633. 1796 if vol:
  3634. 1797 # pylint:disable=protected-access
  3635. 1798 self._volume = vol._volume
  3636. 1799 else:
  3637. 1800 # volume no longer exists
  3638. 1801 self._volume['status'] = VolumeState.UNKNOWN
  3639. Total time: 0 s
  3640. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3641. Function: label at line 1831
  3642. Line # Hits Time Per Hit % Time Line Contents
  3643. ==============================================================
  3644. 1831 @label.setter
  3645. 1832 # pylint:disable=arguments-differ
  3646. 1833 @profile
  3647. 1834 def label(self, value):
  3648. 1835 req = (self._provider
  3649. 1836 .gcp_compute
  3650. 1837 .snapshots()
  3651. 1838 .setLabels(project=self._provider.project_name,
  3652. 1839 resource=self.name,
  3653. 1840 body={}))
  3654. 1841
  3655. 1842 helpers.change_label(self, 'cblabel', value, '_snapshot', req)
  3656. Total time: 0 s
  3657. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3658. Function: description at line 1851
  3659. Line # Hits Time Per Hit % Time Line Contents
  3660. ==============================================================
  3661. 1851 @description.setter
  3662. 1852 @profile
  3663. 1853 def description(self, value):
  3664. 1854 req = (self._provider
  3665. 1855 .gcp_compute
  3666. 1856 .snapshots()
  3667. 1857 .setLabels(project=self._provider.project_name,
  3668. 1858 resource=self.name,
  3669. 1859 body={}))
  3670. 1860
  3671. 1861 helpers.change_label(self, 'description', value, '_snapshot', req)
  3672. Total time: 0 s
  3673. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3674. Function: refresh at line 1880
  3675. Line # Hits Time Per Hit % Time Line Contents
  3676. ==============================================================
  3677. 1880 @profile
  3678. 1881 def refresh(self):
  3679. 1882 """
  3680. 1883 Refreshes the state of this snapshot by re-querying the cloud provider
  3681. 1884 for its latest state.
  3682. 1885 """
  3683. 1886 snap = self._provider.storage.snapshots.get(self.id)
  3684. 1887 if snap:
  3685. 1888 # pylint:disable=protected-access
  3686. 1889 self._snapshot = snap._snapshot
  3687. 1890 else:
  3688. 1891 # snapshot no longer exists
  3689. 1892 self._snapshot['status'] = SnapshotState.UNKNOWN
  3690. Total time: 0 s
  3691. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3692. Function: refresh at line 2018
  3693. Line # Hits Time Per Hit % Time Line Contents
  3694. ==============================================================
  3695. 2018 @profile
  3696. 2019 def refresh(self):
  3697. 2020 # pylint:disable=protected-access
  3698. 2021 self._obj = self.bucket.objects.get(self.id)._obj
  3699. Total time: 0 s
  3700. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3701. Function: get at line 91
  3702. Line # Hits Time Per Hit % Time Line Contents
  3703. ==============================================================
  3704. 91 @dispatch(event="provider.security.key_pairs.get",
  3705. 92 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  3706. 93 @profile
  3707. 94 def get(self, key_pair_id):
  3708. 95 """
  3709. 96 Returns a KeyPair given its ID.
  3710. 97 """
  3711. 98 for kp in self:
  3712. 99 if kp.id == key_pair_id:
  3713. 100 return kp
  3714. 101 else:
  3715. 102 return None
  3716. Total time: 0 s
  3717. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3718. Function: list at line 104
  3719. Line # Hits Time Per Hit % Time Line Contents
  3720. ==============================================================
  3721. 104 @dispatch(event="provider.security.key_pairs.list",
  3722. 105 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  3723. 106 @profile
  3724. 107 def list(self, limit=None, marker=None):
  3725. 108 key_pairs = []
  3726. 109 for item in helpers.find_matching_metadata_items(
  3727. 110 self.provider, GCPKeyPair.KP_TAG_REGEX):
  3728. 111 metadata_value = json.loads(item['value'])
  3729. 112 kp_info = GCPKeyPair.GCPKeyInfo(**metadata_value)
  3730. 113 key_pairs.append(GCPKeyPair(self.provider, kp_info))
  3731. 114 return ClientPagedResultList(self.provider, key_pairs,
  3732. 115 limit=limit, marker=marker)
  3733. Total time: 0 s
  3734. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3735. Function: find at line 117
  3736. Line # Hits Time Per Hit % Time Line Contents
  3737. ==============================================================
  3738. 117 @dispatch(event="provider.security.key_pairs.find",
  3739. 118 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  3740. 119 @profile
  3741. 120 def find(self, **kwargs):
  3742. 121 """
  3743. 122 Searches for a key pair by a given list of attributes.
  3744. 123 """
  3745. 124 obj_list = self
  3746. 125 filters = ['id', 'name']
  3747. 126 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  3748. 127
  3749. 128 # All kwargs should have been popped at this time.
  3750. 129 if len(kwargs) > 0:
  3751. 130 raise InvalidParamException(
  3752. 131 "Unrecognised parameters for search: %s. Supported "
  3753. 132 "attributes: %s" % (kwargs, ", ".join(filters)))
  3754. 133
  3755. 134 return ClientPagedResultList(self.provider,
  3756. 135 matches if matches else [])
  3757. Total time: 0 s
  3758. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3759. Function: create at line 137
  3760. Line # Hits Time Per Hit % Time Line Contents
  3761. ==============================================================
  3762. 137 @dispatch(event="provider.security.key_pairs.create",
  3763. 138 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  3764. 139 @profile
  3765. 140 def create(self, name, public_key_material=None):
  3766. 141 GCPKeyPair.assert_valid_resource_name(name)
  3767. 142 private_key = None
  3768. 143 if not public_key_material:
  3769. 144 public_key_material, private_key = cb_helpers.generate_key_pair()
  3770. 145 # TODO: Add support for other formats not assume ssh-rsa
  3771. 146 elif "ssh-rsa" not in public_key_material:
  3772. 147 public_key_material = "ssh-rsa {}".format(public_key_material)
  3773. 148 kp_info = GCPKeyPair.GCPKeyInfo(name, public_key_material)
  3774. 149 metadata_value = json.dumps(kp_info._asdict())
  3775. 150 try:
  3776. 151 helpers.add_metadata_item(self.provider,
  3777. 152 GCPKeyPair.KP_TAG_PREFIX + name,
  3778. 153 metadata_value)
  3779. 154 return GCPKeyPair(self.provider, kp_info, private_key)
  3780. 155 except googleapiclient.errors.HttpError as err:
  3781. 156 if err.resp.get('content-type', '').startswith('application/json'):
  3782. 157 message = (json.loads(err.content).get('error', {})
  3783. 158 .get('errors', [{}])[0].get('message'))
  3784. 159 if "duplicate keys" in message:
  3785. 160 raise DuplicateResourceException(
  3786. 161 'A KeyPair with name {0} already exists'.format(name))
  3787. 162 raise
  3788. Total time: 0 s
  3789. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3790. Function: delete at line 164
  3791. Line # Hits Time Per Hit % Time Line Contents
  3792. ==============================================================
  3793. 164 @dispatch(event="provider.security.key_pairs.delete",
  3794. 165 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  3795. 166 @profile
  3796. 167 def delete(self, key_pair):
  3797. 168 key_pair = (key_pair if isinstance(key_pair, GCPKeyPair) else
  3798. 169 self.get(key_pair))
  3799. 170 if key_pair:
  3800. 171 helpers.remove_metadata_item(
  3801. 172 self.provider, GCPKeyPair.KP_TAG_PREFIX + key_pair.name)
  3802. Total time: 0 s
  3803. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3804. Function: get at line 181
  3805. Line # Hits Time Per Hit % Time Line Contents
  3806. ==============================================================
  3807. 181 @dispatch(event="provider.security.vm_firewalls.get",
  3808. 182 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  3809. 183 @profile
  3810. 184 def get(self, vm_firewall_id):
  3811. 185 tag, network_name = \
  3812. 186 self._delegate.get_tag_network_from_id(vm_firewall_id)
  3813. 187 if tag is None:
  3814. 188 return None
  3815. 189 network = self.provider.networking.networks.get(network_name)
  3816. 190 return GCPVMFirewall(self._delegate, tag, network)
  3817. Total time: 0 s
  3818. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3819. Function: list at line 192
  3820. Line # Hits Time Per Hit % Time Line Contents
  3821. ==============================================================
  3822. 192 @dispatch(event="provider.security.vm_firewalls.list",
  3823. 193 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  3824. 194 @profile
  3825. 195 def list(self, limit=None, marker=None):
  3826. 196 vm_firewalls = []
  3827. 197 for tag, network_name in self._delegate.tag_networks:
  3828. 198 network = self.provider.networking.networks.get(
  3829. 199 network_name)
  3830. 200 vm_firewall = GCPVMFirewall(self._delegate, tag, network)
  3831. 201 vm_firewalls.append(vm_firewall)
  3832. 202 return ClientPagedResultList(self.provider, vm_firewalls,
  3833. 203 limit=limit, marker=marker)
  3834. Total time: 0 s
  3835. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3836. Function: create at line 205
  3837. Line # Hits Time Per Hit % Time Line Contents
  3838. ==============================================================
  3839. 205 @dispatch(event="provider.security.vm_firewalls.create",
  3840. 206 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  3841. 207 @profile
  3842. 208 def create(self, label, network, description=None):
  3843. 209 GCPVMFirewall.assert_valid_resource_label(label)
  3844. 210 network = (network if isinstance(network, GCPNetwork)
  3845. 211 else self.provider.networking.networks.get(network))
  3846. 212 fw = GCPVMFirewall(self._delegate, label, network, description)
  3847. 213 fw.label = label
  3848. 214 # This rule exists implicitly. Add it explicitly so that the firewall
  3849. 215 # is not empty and the rule is shown by list/get/find methods.
  3850. 216 # pylint:disable=protected-access
  3851. 217 self.provider.security._vm_firewall_rules.create_with_priority(
  3852. 218 fw, direction=TrafficDirection.OUTBOUND, protocol='tcp',
  3853. 219 priority=65534, cidr='0.0.0.0/0')
  3854. 220 return fw
  3855. Total time: 0 s
  3856. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3857. Function: delete at line 222
  3858. Line # Hits Time Per Hit % Time Line Contents
  3859. ==============================================================
  3860. 222 @dispatch(event="provider.security.vm_firewalls.delete",
  3861. 223 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  3862. 224 @profile
  3863. 225 def delete(self, vm_firewall):
  3864. 226 fw_id = (vm_firewall.id if isinstance(vm_firewall, GCPVMFirewall)
  3865. 227 else vm_firewall)
  3866. 228 return self._delegate.delete_tag_network_with_id(fw_id)
  3867. Total time: 0 s
  3868. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3869. Function: find_by_network_and_tags at line 230
  3870. Line # Hits Time Per Hit % Time Line Contents
  3871. ==============================================================
  3872. 230 @profile
  3873. 231 def find_by_network_and_tags(self, network_name, tags):
  3874. 232 """
  3875. 233 Finds non-empty VM firewalls by network name and VM firewall names
  3876. 234 (tags). If no matching VM firewall is found, an empty list is returned.
  3877. 235 """
  3878. 236 vm_firewalls = []
  3879. 237 for tag, net_name in self._delegate.tag_networks:
  3880. 238 if network_name != net_name:
  3881. 239 continue
  3882. 240 if tag not in tags:
  3883. 241 continue
  3884. 242 network = self.provider.networking.networks.get(net_name)
  3885. 243 vm_firewalls.append(
  3886. 244 GCPVMFirewall(self._delegate, tag, network))
  3887. 245 return vm_firewalls
  3888. Total time: 0 s
  3889. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3890. Function: list at line 254
  3891. Line # Hits Time Per Hit % Time Line Contents
  3892. ==============================================================
  3893. 254 @dispatch(event="provider.security.vm_firewall_rules.list",
  3894. 255 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  3895. 256 @profile
  3896. 257 def list(self, firewall, limit=None, marker=None):
  3897. 258 rules = []
  3898. 259 for fw in firewall.delegate.iter_firewalls(
  3899. 260 firewall.name, firewall.network.name):
  3900. 261 rule = GCPVMFirewallRule(firewall, fw['id'])
  3901. 262 if rule.is_dummy_rule():
  3902. 263 self._dummy_rule = rule
  3903. 264 else:
  3904. 265 rules.append(rule)
  3905. 266 return ClientPagedResultList(self.provider, rules,
  3906. 267 limit=limit, marker=marker)
  3907. Total time: 0 s
  3908. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3909. Function: create_with_priority at line 284
  3910. Line # Hits Time Per Hit % Time Line Contents
  3911. ==============================================================
  3912. 284 @profile
  3913. 285 def create_with_priority(self, firewall, direction, protocol, priority,
  3914. 286 from_port=None, to_port=None, cidr=None,
  3915. 287 src_dest_fw=None):
  3916. 288 port = GCPVMFirewallRuleService.to_port_range(from_port, to_port)
  3917. 289 src_dest_tag = None
  3918. 290 src_dest_fw_id = None
  3919. 291 if src_dest_fw:
  3920. 292 src_dest_tag = src_dest_fw.name
  3921. 293 src_dest_fw_id = src_dest_fw.id
  3922. 294 if not firewall.delegate.add_firewall(
  3923. 295 firewall.name, direction, protocol, priority, port, cidr,
  3924. 296 src_dest_tag, firewall.description,
  3925. 297 firewall.network.name):
  3926. 298 return None
  3927. 299 rules = self.find(firewall, direction=direction, protocol=protocol,
  3928. 300 from_port=from_port, to_port=to_port, cidr=cidr,
  3929. 301 src_dest_fw_id=src_dest_fw_id)
  3930. 302 if len(rules) < 1:
  3931. 303 return None
  3932. 304 return rules[0]
  3933. Total time: 0 s
  3934. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3935. Function: create at line 306
  3936. Line # Hits Time Per Hit % Time Line Contents
  3937. ==============================================================
  3938. 306 @dispatch(event="provider.security.vm_firewall_rules.create",
  3939. 307 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  3940. 308 @profile
  3941. 309 def create(self, firewall, direction, protocol, from_port=None,
  3942. 310 to_port=None, cidr=None, src_dest_fw=None):
  3943. 311 return self.create_with_priority(firewall, direction, protocol,
  3944. 312 1000, from_port, to_port, cidr,
  3945. 313 src_dest_fw)
  3946. Total time: 0 s
  3947. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3948. Function: delete at line 315
  3949. Line # Hits Time Per Hit % Time Line Contents
  3950. ==============================================================
  3951. 315 @dispatch(event="provider.security.vm_firewall_rules.delete",
  3952. 316 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  3953. 317 @profile
  3954. 318 def delete(self, firewall, rule):
  3955. 319 rule = (rule if isinstance(rule, GCPVMFirewallRule)
  3956. 320 else self.get(firewall, rule))
  3957. 321 if rule.is_dummy_rule():
  3958. 322 return True
  3959. 323 firewall.delegate.delete_firewall_id(rule._rule)
  3960. Total time: 0 s
  3961. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3962. Function: get at line 341
  3963. Line # Hits Time Per Hit % Time Line Contents
  3964. ==============================================================
  3965. 341 @dispatch(event="provider.compute.vm_types.get",
  3966. 342 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  3967. 343 @profile
  3968. 344 def get(self, vm_type_id):
  3969. 345 vm_type = self.provider.get_resource('machineTypes', vm_type_id)
  3970. 346 return GCPVMType(self.provider, vm_type) if vm_type else None
  3971. Total time: 0 s
  3972. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3973. Function: find at line 348
  3974. Line # Hits Time Per Hit % Time Line Contents
  3975. ==============================================================
  3976. 348 @dispatch(event="provider.compute.vm_types.find",
  3977. 349 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  3978. 350 @profile
  3979. 351 def find(self, **kwargs):
  3980. 352 matched_inst_types = []
  3981. 353 for inst_type in self.instance_data:
  3982. 354 is_match = True
  3983. 355 for key, value in kwargs.items():
  3984. 356 if key not in inst_type:
  3985. 357 raise InvalidParamException(
  3986. 358 "Unrecognised parameters for search: %s." % key)
  3987. 359 if inst_type.get(key) != value:
  3988. 360 is_match = False
  3989. 361 break
  3990. 362 if is_match:
  3991. 363 matched_inst_types.append(
  3992. 364 GCPVMType(self.provider, inst_type))
  3993. 365 return matched_inst_types
  3994. Total time: 0 s
  3995. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3996. Function: list at line 367
  3997. Line # Hits Time Per Hit % Time Line Contents
  3998. ==============================================================
  3999. 367 @dispatch(event="provider.compute.vm_types.list",
  4000. 368 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  4001. 369 @profile
  4002. 370 def list(self, limit=None, marker=None):
  4003. 371 inst_types = [GCPVMType(self.provider, inst_type)
  4004. 372 for inst_type in self.instance_data]
  4005. 373 return ClientPagedResultList(self.provider, inst_types,
  4006. 374 limit=limit, marker=marker)
  4007. Total time: 0 s
  4008. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4009. Function: get at line 382
  4010. Line # Hits Time Per Hit % Time Line Contents
  4011. ==============================================================
  4012. 382 @dispatch(event="provider.compute.regions.get",
  4013. 383 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  4014. 384 @profile
  4015. 385 def get(self, region_id):
  4016. 386 region = self.provider.get_resource('regions', region_id,
  4017. 387 region=region_id)
  4018. 388 return GCPRegion(self.provider, region) if region else None
  4019. Total time: 0 s
  4020. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4021. Function: list at line 390
  4022. Line # Hits Time Per Hit % Time Line Contents
  4023. ==============================================================
  4024. 390 @dispatch(event="provider.compute.regions.list",
  4025. 391 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  4026. 392 @profile
  4027. 393 def list(self, limit=None, marker=None):
  4028. 394 max_result = limit if limit is not None and limit < 500 else 500
  4029. 395 regions_response = (self.provider
  4030. 396 .gcp_compute
  4031. 397 .regions()
  4032. 398 .list(project=self.provider.project_name,
  4033. 399 maxResults=max_result,
  4034. 400 pageToken=marker)
  4035. 401 .execute())
  4036. 402 regions = [GCPRegion(self.provider, region)
  4037. 403 for region in regions_response['items']]
  4038. 404 if len(regions) > max_result:
  4039. 405 log.warning('Expected at most %d results; got %d',
  4040. 406 max_result, len(regions))
  4041. 407 return ServerPagedResultList('nextPageToken' in regions_response,
  4042. 408 regions_response.get('nextPageToken'),
  4043. 409 False, data=regions)
  4044. Total time: 0 s
  4045. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4046. Function: get at line 435
  4047. Line # Hits Time Per Hit % Time Line Contents
  4048. ==============================================================
  4049. 435 @profile
  4050. 436 def get(self, image_id):
  4051. 437 """
  4052. 438 Returns an Image given its id
  4053. 439 """
  4054. 440 image = self.provider.get_resource('images', image_id)
  4055. 441 if image:
  4056. 442 return GCPMachineImage(self.provider, image)
  4057. 443 self._retrieve_public_images()
  4058. 444 for public_image in self._public_images:
  4059. 445 if public_image.id == image_id or public_image.name == image_id:
  4060. 446 return public_image
  4061. 447 return None
  4062. Total time: 0 s
  4063. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4064. Function: find at line 449
  4065. Line # Hits Time Per Hit % Time Line Contents
  4066. ==============================================================
  4067. 449 @profile
  4068. 450 def find(self, limit=None, marker=None, **kwargs):
  4069. 451 """
  4070. 452 Searches for an image by a given list of attributes
  4071. 453 """
  4072. 454 label = kwargs.pop('label', None)
  4073. 455
  4074. 456 # All kwargs should have been popped at this time.
  4075. 457 if len(kwargs) > 0:
  4076. 458 raise InvalidParamException(
  4077. 459 "Unrecognised parameters for search: %s. Supported "
  4078. 460 "attributes: %s" % (kwargs, 'label'))
  4079. 461
  4080. 462 # Retrieve all available images by setting limit to sys.maxsize
  4081. 463 images = [image for image in self if image.label == label]
  4082. 464 return ClientPagedResultList(self.provider, images,
  4083. 465 limit=limit, marker=marker)
  4084. Total time: 0 s
  4085. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4086. Function: list at line 467
  4087. Line # Hits Time Per Hit % Time Line Contents
  4088. ==============================================================
  4089. 467 @profile
  4090. 468 def list(self, limit=None, marker=None):
  4091. 469 """
  4092. 470 List all images.
  4093. 471 """
  4094. 472 self._retrieve_public_images()
  4095. 473 images = []
  4096. 474 if (self.provider.project_name not in
  4097. 475 GCPImageService._PUBLIC_IMAGE_PROJECTS):
  4098. 476 for image in helpers.iter_all(
  4099. 477 self.provider.gcp_compute.images(),
  4100. 478 project=self.provider.project_name):
  4101. 479 images.append(GCPMachineImage(self.provider, image))
  4102. 480 images.extend(self._public_images)
  4103. 481 return ClientPagedResultList(self.provider, images,
  4104. 482 limit=limit, marker=marker)
  4105. Total time: 0 s
  4106. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4107. Function: create at line 490
  4108. Line # Hits Time Per Hit % Time Line Contents
  4109. ==============================================================
  4110. 490 @dispatch(event="provider.compute.instances.create",
  4111. 491 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  4112. 492 @profile
  4113. 493 def create(self, label, image, vm_type, subnet, zone=None,
  4114. 494 key_pair=None, vm_firewalls=None, user_data=None,
  4115. 495 launch_config=None, **kwargs):
  4116. 496 """
  4117. 497 Creates a new virtual machine instance.
  4118. 498 """
  4119. 499 GCPInstance.assert_valid_resource_name(label)
  4120. 500 zone_name = self.provider.default_zone
  4121. 501 if zone:
  4122. 502 if not isinstance(zone, GCPPlacementZone):
  4123. 503 zone = GCPPlacementZone(
  4124. 504 self.provider,
  4125. 505 self.provider.get_resource('zones', zone))
  4126. 506 zone_name = zone.name
  4127. 507 if not isinstance(vm_type, GCPVMType):
  4128. 508 vm_type = self.provider.compute.vm_types.get(vm_type)
  4129. 509
  4130. 510 network_interface = {'accessConfigs': [{'type': 'ONE_TO_ONE_NAT',
  4131. 511 'name': 'External NAT'}]}
  4132. 512 if subnet:
  4133. 513 network_interface['subnetwork'] = subnet.id
  4134. 514 else:
  4135. 515 network_interface['network'] = 'global/networks/default'
  4136. 516
  4137. 517 num_roots = 0
  4138. 518 disks = []
  4139. 519 boot_disk = None
  4140. 520 if isinstance(launch_config, GCPLaunchConfig):
  4141. 521 for disk in launch_config.block_devices:
  4142. 522 if not disk.source:
  4143. 523 volume_name = 'disk-{0}'.format(uuid.uuid4())
  4144. 524 volume_size = disk.size if disk.size else 1
  4145. 525 volume = self.provider.storage.volumes.create(
  4146. 526 volume_name, volume_size, zone)
  4147. 527 volume.wait_till_ready()
  4148. 528 source_field = 'source'
  4149. 529 source_value = volume.id
  4150. 530 elif isinstance(disk.source, GCPMachineImage):
  4151. 531 source_field = 'initializeParams'
  4152. 532 # Explicitly set diskName; otherwise, instance label will
  4153. 533 # be used by default which may collide with existing disks.
  4154. 534 source_value = {
  4155. 535 'sourceImage': disk.source.id,
  4156. 536 'diskName': 'image-disk-{0}'.format(uuid.uuid4()),
  4157. 537 'diskSizeGb': disk.size if disk.size else 20}
  4158. 538 elif isinstance(disk.source, GCPVolume):
  4159. 539 source_field = 'source'
  4160. 540 source_value = disk.source.id
  4161. 541 elif isinstance(disk.source, GCPSnapshot):
  4162. 542 volume = disk.source.create_volume(zone, size=disk.size)
  4163. 543 volume.wait_till_ready()
  4164. 544 source_field = 'source'
  4165. 545 source_value = volume.id
  4166. 546 else:
  4167. 547 log.warning('Unknown disk source')
  4168. 548 continue
  4169. 549 autoDelete = True
  4170. 550 if disk.delete_on_terminate is not None:
  4171. 551 autoDelete = disk.delete_on_terminate
  4172. 552 num_roots += 1 if disk.is_root else 0
  4173. 553 if disk.is_root and not boot_disk:
  4174. 554 boot_disk = {'boot': True,
  4175. 555 'autoDelete': autoDelete,
  4176. 556 source_field: source_value}
  4177. 557 else:
  4178. 558 disks.append({'boot': False,
  4179. 559 'autoDelete': autoDelete,
  4180. 560 source_field: source_value})
  4181. 561
  4182. 562 if num_roots > 1:
  4183. 563 log.warning('The launch config contains %d boot disks. Will '
  4184. 564 'use the first one', num_roots)
  4185. 565 if image:
  4186. 566 if boot_disk:
  4187. 567 log.warning('A boot image is given while the launch config '
  4188. 568 'contains a boot disk, too. The launch config '
  4189. 569 'will be used.')
  4190. 570 else:
  4191. 571 if not isinstance(image, GCPMachineImage):
  4192. 572 image = self.provider.compute.images.get(image)
  4193. 573 # Explicitly set diskName; otherwise, instance name will be
  4194. 574 # used by default which may conflict with existing disks.
  4195. 575 boot_disk = {
  4196. 576 'boot': True,
  4197. 577 'autoDelete': True,
  4198. 578 'initializeParams': {
  4199. 579 'sourceImage': image.id,
  4200. 580 'diskName': 'image-disk-{0}'.format(uuid.uuid4())}}
  4201. 581
  4202. 582 if not boot_disk:
  4203. 583 log.warning('No boot disk is given for instance %s.', label)
  4204. 584 return None
  4205. 585 # The boot disk must be the first disk attached to the instance.
  4206. 586 disks.insert(0, boot_disk)
  4207. 587
  4208. 588 config = {
  4209. 589 'name': GCPInstance._generate_name_from_label(label, 'cb-inst'),
  4210. 590 'machineType': vm_type.resource_url,
  4211. 591 'disks': disks,
  4212. 592 'networkInterfaces': [network_interface]
  4213. 593 }
  4214. 594
  4215. 595 if vm_firewalls and isinstance(vm_firewalls, list):
  4216. 596 vm_firewall_names = []
  4217. 597 if isinstance(vm_firewalls[0], VMFirewall):
  4218. 598 vm_firewall_names = [f.name for f in vm_firewalls]
  4219. 599 elif isinstance(vm_firewalls[0], str):
  4220. 600 vm_firewall_names = vm_firewalls
  4221. 601 if len(vm_firewall_names) > 0:
  4222. 602 config['tags'] = {}
  4223. 603 config['tags']['items'] = vm_firewall_names
  4224. 604
  4225. 605 if user_data:
  4226. 606 entry = {'key': 'user-data', 'value': user_data}
  4227. 607 config['metadata'] = {'items': [entry]}
  4228. 608
  4229. 609 if key_pair:
  4230. 610 if not isinstance(key_pair, GCPKeyPair):
  4231. 611 key_pair = self._provider.security.key_pairs.get(key_pair)
  4232. 612 if key_pair:
  4233. 613 kp = key_pair._key_pair
  4234. 614 kp_entry = {
  4235. 615 "key": "ssh-keys",
  4236. 616 # Format is not removed from public key portion
  4237. 617 "value": "{}:{} {}".format(
  4238. 618 self.provider.vm_default_user_name,
  4239. 619 kp.public_key,
  4240. 620 kp.name)
  4241. 621 }
  4242. 622 meta = config.get('metadata', {})
  4243. 623 if meta:
  4244. 624 items = meta.get('items', [])
  4245. 625 items.append(kp_entry)
  4246. 626 else:
  4247. 627 config['metadata'] = {'items': [kp_entry]}
  4248. 628
  4249. 629 config['labels'] = {'cblabel': label}
  4250. 630
  4251. 631 operation = (self.provider
  4252. 632 .gcp_compute.instances()
  4253. 633 .insert(project=self.provider.project_name,
  4254. 634 zone=zone_name,
  4255. 635 body=config)
  4256. 636 .execute())
  4257. 637 instance_id = operation.get('targetLink')
  4258. 638 self.provider.wait_for_operation(operation, zone=zone_name)
  4259. 639 cb_inst = self.get(instance_id)
  4260. 640 return cb_inst
  4261. Total time: 0 s
  4262. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4263. Function: get at line 642
  4264. Line # Hits Time Per Hit % Time Line Contents
  4265. ==============================================================
  4266. 642 @dispatch(event="provider.compute.instances.get",
  4267. 643 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  4268. 644 @profile
  4269. 645 def get(self, instance_id):
  4270. 646 """
  4271. 647 Returns an instance given its name. Returns None
  4272. 648 if the object does not exist.
  4273. 649
  4274. 650 A GCP instance is uniquely identified by its selfLink, which is used
  4275. 651 as its id.
  4276. 652 """
  4277. 653 instance = self.provider.get_resource('instances', instance_id)
  4278. 654 return GCPInstance(self.provider, instance) if instance else None
  4279. Total time: 0 s
  4280. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4281. Function: find at line 656
  4282. Line # Hits Time Per Hit % Time Line Contents
  4283. ==============================================================
  4284. 656 @dispatch(event="provider.compute.instances.find",
  4285. 657 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  4286. 658 @profile
  4287. 659 def find(self, limit=None, marker=None, **kwargs):
  4288. 660 """
  4289. 661 Searches for instances by instance label.
  4290. 662 :return: a list of Instance objects
  4291. 663 """
  4292. 664 label = kwargs.pop('label', None)
  4293. 665
  4294. 666 # All kwargs should have been popped at this time.
  4295. 667 if len(kwargs) > 0:
  4296. 668 raise InvalidParamException(
  4297. 669 "Unrecognised parameters for search: %s. Supported "
  4298. 670 "attributes: %s" % (kwargs, 'label'))
  4299. 671
  4300. 672 instances = [instance for instance in self.list()
  4301. 673 if instance.label == label]
  4302. 674 return ClientPagedResultList(self.provider, instances,
  4303. 675 limit=limit, marker=marker)
  4304. Total time: 0 s
  4305. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4306. Function: list at line 677
  4307. Line # Hits Time Per Hit % Time Line Contents
  4308. ==============================================================
  4309. 677 @dispatch(event="provider.compute.instances.list",
  4310. 678 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  4311. 679 @profile
  4312. 680 def list(self, limit=None, marker=None):
  4313. 681 """
  4314. 682 List all instances.
  4315. 683 """
  4316. 684 # For GCP API, Acceptable values are 0 to 500, inclusive.
  4317. 685 # (Default: 500).
  4318. 686 max_result = limit if limit is not None and limit < 500 else 500
  4319. 687 response = (self.provider
  4320. 688 .gcp_compute
  4321. 689 .instances()
  4322. 690 .list(project=self.provider.project_name,
  4323. 691 zone=self.provider.default_zone,
  4324. 692 maxResults=max_result,
  4325. 693 pageToken=marker)
  4326. 694 .execute())
  4327. 695 instances = [GCPInstance(self.provider, inst)
  4328. 696 for inst in response.get('items', [])]
  4329. 697 if len(instances) > max_result:
  4330. 698 log.warning('Expected at most %d results; got %d',
  4331. 699 max_result, len(instances))
  4332. 700 return ServerPagedResultList('nextPageToken' in response,
  4333. 701 response.get('nextPageToken'),
  4334. 702 False, data=instances)
  4335. Total time: 0 s
  4336. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4337. Function: delete at line 704
  4338. Line # Hits Time Per Hit % Time Line Contents
  4339. ==============================================================
  4340. 704 @dispatch(event="provider.compute.instances.delete",
  4341. 705 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  4342. 706 @profile
  4343. 707 def delete(self, instance):
  4344. 708 instance = (instance if isinstance(instance, GCPInstance) else
  4345. 709 self.get(instance))
  4346. 710 if instance:
  4347. 711 (self._provider
  4348. 712 .gcp_compute
  4349. 713 .instances()
  4350. 714 .delete(project=self.provider.project_name,
  4351. 715 zone=instance.zone_name,
  4352. 716 instance=instance.name)
  4353. 717 .execute())
  4354. Total time: 0 s
  4355. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4356. Function: create_launch_config at line 719
  4357. Line # Hits Time Per Hit % Time Line Contents
  4358. ==============================================================
  4359. 719 @profile
  4360. 720 def create_launch_config(self):
  4361. 721 return GCPLaunchConfig(self.provider)
  4362. Total time: 0 s
  4363. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4364. Function: get at line 786
  4365. Line # Hits Time Per Hit % Time Line Contents
  4366. ==============================================================
  4367. 786 @dispatch(event="provider.networking.networks.get",
  4368. 787 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  4369. 788 @profile
  4370. 789 def get(self, network_id):
  4371. 790 network = self.provider.get_resource('networks', network_id)
  4372. 791 return GCPNetwork(self.provider, network) if network else None
  4373. Total time: 0 s
  4374. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4375. Function: find at line 793
  4376. Line # Hits Time Per Hit % Time Line Contents
  4377. ==============================================================
  4378. 793 @dispatch(event="provider.networking.networks.find",
  4379. 794 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  4380. 795 @profile
  4381. 796 def find(self, limit=None, marker=None, **kwargs):
  4382. 797 """
  4383. 798 GCP networks are global. There is at most one network with a given
  4384. 799 name.
  4385. 800 """
  4386. 801 obj_list = self
  4387. 802 filters = ['name', 'label']
  4388. 803 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  4389. 804 return ClientPagedResultList(self._provider, list(matches),
  4390. 805 limit=limit, marker=marker)
  4391. Total time: 0 s
  4392. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4393. Function: list at line 807
  4394. Line # Hits Time Per Hit % Time Line Contents
  4395. ==============================================================
  4396. 807 @dispatch(event="provider.networking.networks.list",
  4397. 808 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  4398. 809 @profile
  4399. 810 def list(self, limit=None, marker=None, filter=None):
  4400. 811 # TODO: Decide whether we keep filter in 'list'
  4401. 812 networks = []
  4402. 813 response = (self.provider
  4403. 814 .gcp_compute
  4404. 815 .networks()
  4405. 816 .list(project=self.provider.project_name,
  4406. 817 filter=filter)
  4407. 818 .execute())
  4408. 819 for network in response.get('items', []):
  4409. 820 networks.append(GCPNetwork(self.provider, network))
  4410. 821 return ClientPagedResultList(self.provider, networks,
  4411. 822 limit=limit, marker=marker)
  4412. Total time: 0 s
  4413. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4414. Function: create at line 824
  4415. Line # Hits Time Per Hit % Time Line Contents
  4416. ==============================================================
  4417. 824 @dispatch(event="provider.networking.networks.create",
  4418. 825 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  4419. 826 @profile
  4420. 827 def create(self, label, cidr_block):
  4421. 828 """
  4422. 829 Creates an auto mode VPC network with default subnets. It is possible
  4423. 830 to add additional subnets later.
  4424. 831 """
  4425. 832 GCPNetwork.assert_valid_resource_label(label)
  4426. 833 name = GCPNetwork._generate_name_from_label(label, 'cbnet')
  4427. 834 body = {'name': name}
  4428. 835 # This results in a custom mode network
  4429. 836 body['autoCreateSubnetworks'] = False
  4430. 837 response = (self.provider
  4431. 838 .gcp_compute
  4432. 839 .networks()
  4433. 840 .insert(project=self.provider.project_name,
  4434. 841 body=body)
  4435. 842 .execute())
  4436. 843 self.provider.wait_for_operation(response)
  4437. 844 cb_net = self.get(name)
  4438. 845 cb_net.label = label
  4439. 846 return cb_net
  4440. Total time: 0 s
  4441. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4442. Function: get_or_create_default at line 848
  4443. Line # Hits Time Per Hit % Time Line Contents
  4444. ==============================================================
  4445. 848 @profile
  4446. 849 def get_or_create_default(self):
  4447. 850 default_nets = self.provider.networking.networks.find(
  4448. 851 label=GCPNetwork.CB_DEFAULT_NETWORK_LABEL)
  4449. 852 if default_nets:
  4450. 853 return default_nets[0]
  4451. 854 else:
  4452. 855 log.info("Creating a CloudBridge-default network labeled %s",
  4453. 856 GCPNetwork.CB_DEFAULT_NETWORK_LABEL)
  4454. 857 return self.create(
  4455. 858 label=GCPNetwork.CB_DEFAULT_NETWORK_LABEL,
  4456. 859 cidr_block=GCPNetwork.CB_DEFAULT_IPV4RANGE)
  4457. Total time: 0 s
  4458. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4459. Function: delete at line 861
  4460. Line # Hits Time Per Hit % Time Line Contents
  4461. ==============================================================
  4462. 861 @dispatch(event="provider.networking.networks.delete",
  4463. 862 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  4464. 863 @profile
  4465. 864 def delete(self, network):
  4466. 865 # Accepts network object
  4467. 866 if isinstance(network, GCPNetwork):
  4468. 867 name = network.name
  4469. 868 # Accepts both name and ID
  4470. 869 elif 'googleapis' in network:
  4471. 870 name = network.split('/')[-1]
  4472. 871 else:
  4473. 872 name = network
  4474. 873 response = (self.provider
  4475. 874 .gcp_compute
  4476. 875 .networks()
  4477. 876 .delete(project=self.provider.project_name,
  4478. 877 network=name)
  4479. 878 .execute())
  4480. 879 self.provider.wait_for_operation(response)
  4481. 880 # Remove label
  4482. 881 tag_name = "_".join(["network", name, "label"])
  4483. 882 if not helpers.remove_metadata_item(self.provider, tag_name):
  4484. 883 log.warning('No label was found associated with this network '
  4485. 884 '"{}" when deleted.'.format(network))
  4486. 885 return True
  4487. Total time: 0 s
  4488. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4489. Function: get at line 893
  4490. Line # Hits Time Per Hit % Time Line Contents
  4491. ==============================================================
  4492. 893 @dispatch(event="provider.networking.routers.get",
  4493. 894 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  4494. 895 @profile
  4495. 896 def get(self, router_id):
  4496. 897 router = self.provider.get_resource(
  4497. 898 'routers', router_id, region=self.provider.region_name)
  4498. 899 return GCPRouter(self.provider, router) if router else None
  4499. Total time: 0 s
  4500. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4501. Function: find at line 901
  4502. Line # Hits Time Per Hit % Time Line Contents
  4503. ==============================================================
  4504. 901 @dispatch(event="provider.networking.routers.find",
  4505. 902 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  4506. 903 @profile
  4507. 904 def find(self, limit=None, marker=None, **kwargs):
  4508. 905 obj_list = self
  4509. 906 filters = ['name', 'label']
  4510. 907 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  4511. 908 return ClientPagedResultList(self._provider, list(matches),
  4512. 909 limit=limit, marker=marker)
  4513. Total time: 0 s
  4514. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4515. Function: list at line 911
  4516. Line # Hits Time Per Hit % Time Line Contents
  4517. ==============================================================
  4518. 911 @dispatch(event="provider.networking.routers.list",
  4519. 912 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  4520. 913 @profile
  4521. 914 def list(self, limit=None, marker=None):
  4522. 915 region = self.provider.region_name
  4523. 916 max_result = limit if limit is not None and limit < 500 else 500
  4524. 917 response = (self.provider
  4525. 918 .gcp_compute
  4526. 919 .routers()
  4527. 920 .list(project=self.provider.project_name,
  4528. 921 region=region,
  4529. 922 maxResults=max_result,
  4530. 923 pageToken=marker)
  4531. 924 .execute())
  4532. 925 routers = []
  4533. 926 for router in response.get('items', []):
  4534. 927 routers.append(GCPRouter(self.provider, router))
  4535. 928 if len(routers) > max_result:
  4536. 929 log.warning('Expected at most %d results; go %d',
  4537. 930 max_result, len(routers))
  4538. 931 return ServerPagedResultList('nextPageToken' in response,
  4539. 932 response.get('nextPageToken'),
  4540. 933 False, data=routers)
  4541. Total time: 0 s
  4542. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4543. Function: create at line 935
  4544. Line # Hits Time Per Hit % Time Line Contents
  4545. ==============================================================
  4546. 935 @dispatch(event="provider.networking.routers.create",
  4547. 936 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  4548. 937 @profile
  4549. 938 def create(self, label, network):
  4550. 939 log.debug("Creating GCP Router Service with params "
  4551. 940 "[label: %s network: %s]", label, network)
  4552. 941 GCPRouter.assert_valid_resource_label(label)
  4553. 942 name = GCPRouter._generate_name_from_label(label, 'cb-router')
  4554. 943
  4555. 944 if not isinstance(network, GCPNetwork):
  4556. 945 network = self.provider.networking.networks.get(network)
  4557. 946 network_url = network.resource_url
  4558. 947 region_name = self.provider.region_name
  4559. 948 response = (self.provider
  4560. 949 .gcp_compute
  4561. 950 .routers()
  4562. 951 .insert(project=self.provider.project_name,
  4563. 952 region=region_name,
  4564. 953 body={'name': name,
  4565. 954 'network': network_url})
  4566. 955 .execute())
  4567. 956 self.provider.wait_for_operation(response, region=region_name)
  4568. 957 cb_router = self.get(name)
  4569. 958 cb_router.label = label
  4570. 959 return cb_router
  4571. Total time: 0 s
  4572. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4573. Function: delete at line 961
  4574. Line # Hits Time Per Hit % Time Line Contents
  4575. ==============================================================
  4576. 961 @dispatch(event="provider.networking.routers.delete",
  4577. 962 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  4578. 963 @profile
  4579. 964 def delete(self, router):
  4580. 965 r = router if isinstance(router, GCPRouter) else self.get(router)
  4581. 966 if r:
  4582. 967 (self.provider
  4583. 968 .gcp_compute
  4584. 969 .routers()
  4585. 970 .delete(project=self.provider.project_name,
  4586. 971 region=r.region_name,
  4587. 972 router=r.name)
  4588. 973 .execute())
  4589. 974 # Remove label
  4590. 975 tag_name = "_".join(["router", r.name, "label"])
  4591. 976 if not helpers.remove_metadata_item(self.provider, tag_name):
  4592. 977 log.warning('No label was found associated with this router '
  4593. 978 '"{}" when deleted.'.format(r.name))
  4594. Total time: 0 s
  4595. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4596. Function: get at line 996
  4597. Line # Hits Time Per Hit % Time Line Contents
  4598. ==============================================================
  4599. 996 @dispatch(event="provider.networking.subnets.get",
  4600. 997 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  4601. 998 @profile
  4602. 999 def get(self, subnet_id):
  4603. 1000 subnet = self.provider.get_resource('subnetworks', subnet_id)
  4604. 1001 return GCPSubnet(self.provider, subnet) if subnet else None
  4605. Total time: 0 s
  4606. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4607. Function: list at line 1003
  4608. Line # Hits Time Per Hit % Time Line Contents
  4609. ==============================================================
  4610. 1003 @dispatch(event="provider.networking.subnets.list",
  4611. 1004 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  4612. 1005 @profile
  4613. 1006 def list(self, network=None, zone=None, limit=None, marker=None):
  4614. 1007 """
  4615. 1008 If the zone is not given, we list all subnets in the default region.
  4616. 1009 """
  4617. 1010 filter = None
  4618. 1011 if network is not None:
  4619. 1012 network = (network if isinstance(network, GCPNetwork)
  4620. 1013 else self.provider.networking.networks.get(network))
  4621. 1014 filter = 'network eq %s' % network.resource_url
  4622. 1015 if zone:
  4623. 1016 region_name = self._zone_to_region(zone)
  4624. 1017 else:
  4625. 1018 region_name = self.provider.region_name
  4626. 1019 subnets = []
  4627. 1020 response = (self.provider
  4628. 1021 .gcp_compute
  4629. 1022 .subnetworks()
  4630. 1023 .list(project=self.provider.project_name,
  4631. 1024 region=region_name,
  4632. 1025 filter=filter)
  4633. 1026 .execute())
  4634. 1027 for subnet in response.get('items', []):
  4635. 1028 subnets.append(GCPSubnet(self.provider, subnet))
  4636. 1029 return ClientPagedResultList(self.provider, subnets,
  4637. 1030 limit=limit, marker=marker)
  4638. Total time: 0 s
  4639. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4640. Function: create at line 1032
  4641. Line # Hits Time Per Hit % Time Line Contents
  4642. ==============================================================
  4643. 1032 @dispatch(event="provider.networking.subnets.create",
  4644. 1033 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  4645. 1034 @profile
  4646. 1035 def create(self, label, network, cidr_block, zone):
  4647. 1036 """
  4648. 1037 GCP subnets are regional. The region is inferred from the zone;
  4649. 1038 otherwise, the default region, as set in the
  4650. 1039 provider, is used.
  4651. 1040
  4652. 1041 If a subnet with overlapping IP range exists already, we return that
  4653. 1042 instead of creating a new subnet. In this case, other parameters, i.e.
  4654. 1043 the name and the zone, are ignored.
  4655. 1044 """
  4656. 1045 GCPSubnet.assert_valid_resource_label(label)
  4657. 1046 name = GCPSubnet._generate_name_from_label(label, 'cbsubnet')
  4658. 1047 region_name = self._zone_to_region(zone)
  4659. 1048 # for subnet in self.iter(network=network):
  4660. 1049 # if BaseNetwork.cidr_blocks_overlap(subnet.cidr_block, cidr_block):
  4661. 1050 # if subnet.region_name != region_name:
  4662. 1051 # log.error('Failed to create subnetwork in region %s: '
  4663. 1052 # 'the given IP range %s overlaps with a '
  4664. 1053 # 'subnetwork in a different region %s',
  4665. 1054 # region_name, cidr_block, subnet.region_name)
  4666. 1055 # return None
  4667. 1056 # return subnet
  4668. 1057 # if subnet.label == label and subnet.region_name == region_name:
  4669. 1058 # return subnet
  4670. 1059
  4671. 1060 body = {'ipCidrRange': cidr_block,
  4672. 1061 'name': name,
  4673. 1062 'network': network.resource_url,
  4674. 1063 'region': region_name
  4675. 1064 }
  4676. 1065 response = (self.provider
  4677. 1066 .gcp_compute
  4678. 1067 .subnetworks()
  4679. 1068 .insert(project=self.provider.project_name,
  4680. 1069 region=region_name,
  4681. 1070 body=body)
  4682. 1071 .execute())
  4683. 1072 self.provider.wait_for_operation(response, region=region_name)
  4684. 1073 cb_subnet = self.get(name)
  4685. 1074 cb_subnet.label = label
  4686. 1075 return cb_subnet
  4687. Total time: 0 s
  4688. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4689. Function: delete at line 1077
  4690. Line # Hits Time Per Hit % Time Line Contents
  4691. ==============================================================
  4692. 1077 @dispatch(event="provider.networking.subnets.delete",
  4693. 1078 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  4694. 1079 @profile
  4695. 1080 def delete(self, subnet):
  4696. 1081 sn = subnet if isinstance(subnet, GCPSubnet) else self.get(subnet)
  4697. 1082 if not sn:
  4698. 1083 return
  4699. 1084 response = (self.provider
  4700. 1085 .gcp_compute
  4701. 1086 .subnetworks()
  4702. 1087 .delete(project=self.provider.project_name,
  4703. 1088 region=sn.region_name,
  4704. 1089 subnetwork=sn.name)
  4705. 1090 .execute())
  4706. 1091 self.provider.wait_for_operation(response, region=sn.region_name)
  4707. 1092 # Remove label
  4708. 1093 tag_name = "_".join(["subnet", sn.name, "label"])
  4709. 1094 if not helpers.remove_metadata_item(self._provider, tag_name):
  4710. 1095 log.warning('No label was found associated with this subnet '
  4711. 1096 '"{}" when deleted.'.format(sn.name))
  4712. Total time: 0 s
  4713. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4714. Function: get_or_create_default at line 1098
  4715. Line # Hits Time Per Hit % Time Line Contents
  4716. ==============================================================
  4717. 1098 @profile
  4718. 1099 def get_or_create_default(self, zone):
  4719. 1100 """
  4720. 1101 Return an existing or create a new subnet for the supplied zone.
  4721. 1102
  4722. 1103 In GCP, subnets are a regional resource so a single subnet can services
  4723. 1104 an entire region. The supplied zone parameter is used to derive the
  4724. 1105 parent region under which the default subnet then exists.
  4725. 1106 """
  4726. 1107 # In case the supplied zone param is `None`, resort to the default one
  4727. 1108 region = self._zone_to_region(zone or self.provider.default_zone,
  4728. 1109 return_name_only=False)
  4729. 1110 # Check if a default subnet already exists for the given region/zone
  4730. 1111 for sn in self.find(label=GCPSubnet.CB_DEFAULT_SUBNET_LABEL):
  4731. 1112 if sn.region == region.id:
  4732. 1113 return sn
  4733. 1114 # No default subnet in the supplied zone. Look for a default network,
  4734. 1115 # then create a subnet whose address space does not overlap with any
  4735. 1116 # other existing subnets. If there are existing subnets, this process
  4736. 1117 # largely assumes the subnet address spaces are contiguous when it
  4737. 1118 # does the calculations (e.g., 10.0.0.0/24, 10.0.1.0/24).
  4738. 1119 cidr_block = GCPSubnet.CB_DEFAULT_SUBNET_IPV4RANGE
  4739. 1120 net = self.provider.networking.networks.get_or_create_default()
  4740. 1121 if net.subnets:
  4741. 1122 max_sn = net.subnets[0]
  4742. 1123 # Find the maximum address subnet address space within the network
  4743. 1124 for esn in net.subnets:
  4744. 1125 if (ipaddress.ip_network(esn.cidr_block) >
  4745. 1126 ipaddress.ip_network(max_sn.cidr_block)):
  4746. 1127 max_sn = esn
  4747. 1128 max_sn_ipa = ipaddress.ip_network(max_sn.cidr_block)
  4748. 1129 # Find the next available subnet after the max one, based on the
  4749. 1130 # max subnet size
  4750. 1131 next_sn_address = (
  4751. 1132 next(max_sn_ipa.hosts()) + max_sn_ipa.num_addresses - 1)
  4752. 1133 cidr_block = "{}/{}".format(next_sn_address, max_sn_ipa.prefixlen)
  4753. 1134 sn = self.provider.networking.subnets.create(
  4754. 1135 label=GCPSubnet.CB_DEFAULT_SUBNET_LABEL,
  4755. 1136 cidr_block=cidr_block, network=net, zone=zone)
  4756. 1137 router = self.provider.networking.routers.get_or_create_default(net)
  4757. 1138 router.attach_subnet(sn)
  4758. 1139 gateway = net.gateways.get_or_create()
  4759. 1140 router.attach_gateway(gateway)
  4760. 1141 return sn
  4761. Total time: 0 s
  4762. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4763. Function: get at line 1196
  4764. Line # Hits Time Per Hit % Time Line Contents
  4765. ==============================================================
  4766. 1196 @dispatch(event="provider.storage.volumes.get",
  4767. 1197 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  4768. 1198 @profile
  4769. 1199 def get(self, volume_id):
  4770. 1200 vol = self.provider.get_resource('disks', volume_id)
  4771. 1201 return GCPVolume(self.provider, vol) if vol else None
  4772. Total time: 0 s
  4773. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4774. Function: find at line 1203
  4775. Line # Hits Time Per Hit % Time Line Contents
  4776. ==============================================================
  4777. 1203 @dispatch(event="provider.storage.volumes.find",
  4778. 1204 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  4779. 1205 @profile
  4780. 1206 def find(self, limit=None, marker=None, **kwargs):
  4781. 1207 """
  4782. 1208 Searches for a volume by a given list of attributes.
  4783. 1209 """
  4784. 1210 label = kwargs.pop('label', None)
  4785. 1211
  4786. 1212 # All kwargs should have been popped at this time.
  4787. 1213 if len(kwargs) > 0:
  4788. 1214 raise InvalidParamException(
  4789. 1215 "Unrecognised parameters for search: %s. Supported "
  4790. 1216 "attributes: %s" % (kwargs, 'label'))
  4791. 1217
  4792. 1218 filtr = 'labels.cblabel eq ' + label
  4793. 1219 max_result = limit if limit is not None and limit < 500 else 500
  4794. 1220 response = (self.provider
  4795. 1221 .gcp_compute
  4796. 1222 .disks()
  4797. 1223 .list(project=self.provider.project_name,
  4798. 1224 zone=self.provider.default_zone,
  4799. 1225 filter=filtr,
  4800. 1226 maxResults=max_result,
  4801. 1227 pageToken=marker)
  4802. 1228 .execute())
  4803. 1229 gcp_vols = [GCPVolume(self.provider, vol)
  4804. 1230 for vol in response.get('items', [])]
  4805. 1231 if len(gcp_vols) > max_result:
  4806. 1232 log.warning('Expected at most %d results; got %d',
  4807. 1233 max_result, len(gcp_vols))
  4808. 1234 return ServerPagedResultList('nextPageToken' in response,
  4809. 1235 response.get('nextPageToken'),
  4810. 1236 False, data=gcp_vols)
  4811. Total time: 0 s
  4812. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4813. Function: list at line 1238
  4814. Line # Hits Time Per Hit % Time Line Contents
  4815. ==============================================================
  4816. 1238 @dispatch(event="provider.storage.volumes.list",
  4817. 1239 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  4818. 1240 @profile
  4819. 1241 def list(self, limit=None, marker=None):
  4820. 1242 """
  4821. 1243 List all volumes.
  4822. 1244
  4823. 1245 limit: The maximum number of volumes to return. The returned
  4824. 1246 ResultList's is_truncated property can be used to determine
  4825. 1247 whether more records are available.
  4826. 1248 """
  4827. 1249 # For GCP API, Acceptable values are 0 to 500, inclusive.
  4828. 1250 # (Default: 500).
  4829. 1251 max_result = limit if limit is not None and limit < 500 else 500
  4830. 1252 response = (self.provider
  4831. 1253 .gcp_compute
  4832. 1254 .disks()
  4833. 1255 .list(project=self.provider.project_name,
  4834. 1256 zone=self.provider.default_zone,
  4835. 1257 maxResults=max_result,
  4836. 1258 pageToken=marker)
  4837. 1259 .execute())
  4838. 1260 gcp_vols = [GCPVolume(self.provider, vol)
  4839. 1261 for vol in response.get('items', [])]
  4840. 1262 if len(gcp_vols) > max_result:
  4841. 1263 log.warning('Expected at most %d results; got %d',
  4842. 1264 max_result, len(gcp_vols))
  4843. 1265 return ServerPagedResultList('nextPageToken' in response,
  4844. 1266 response.get('nextPageToken'),
  4845. 1267 False, data=gcp_vols)
  4846. Total time: 0 s
  4847. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4848. Function: create at line 1269
  4849. Line # Hits Time Per Hit % Time Line Contents
  4850. ==============================================================
  4851. 1269 @dispatch(event="provider.storage.volumes.create",
  4852. 1270 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  4853. 1271 @profile
  4854. 1272 def create(self, label, size, zone, snapshot=None, description=None):
  4855. 1273 GCPVolume.assert_valid_resource_label(label)
  4856. 1274 name = GCPVolume._generate_name_from_label(label, 'cb-vol')
  4857. 1275 if not isinstance(zone, GCPPlacementZone):
  4858. 1276 zone = GCPPlacementZone(
  4859. 1277 self.provider,
  4860. 1278 self.provider.get_resource('zones', zone))
  4861. 1279 zone_name = zone.name
  4862. 1280 snapshot_id = snapshot.id if isinstance(
  4863. 1281 snapshot, GCPSnapshot) and snapshot else snapshot
  4864. 1282 labels = {'cblabel': label}
  4865. 1283 if description:
  4866. 1284 labels['description'] = description
  4867. 1285 disk_body = {
  4868. 1286 'name': name,
  4869. 1287 'sizeGb': size,
  4870. 1288 'type': 'zones/{0}/diskTypes/{1}'.format(zone_name, 'pd-standard'),
  4871. 1289 'sourceSnapshot': snapshot_id,
  4872. 1290 'labels': labels
  4873. 1291 }
  4874. 1292 operation = (self.provider
  4875. 1293 .gcp_compute
  4876. 1294 .disks()
  4877. 1295 .insert(
  4878. 1296 project=self._provider.project_name,
  4879. 1297 zone=zone_name,
  4880. 1298 body=disk_body)
  4881. 1299 .execute())
  4882. 1300 cb_vol = self.get(operation.get('targetLink'))
  4883. 1301 return cb_vol
  4884. Total time: 0 s
  4885. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4886. Function: delete at line 1303
  4887. Line # Hits Time Per Hit % Time Line Contents
  4888. ==============================================================
  4889. 1303 @dispatch(event="provider.storage.volumes.delete",
  4890. 1304 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  4891. 1305 @profile
  4892. 1306 def delete(self, volume):
  4893. 1307 volume = volume if isinstance(volume, GCPVolume) else self.get(volume)
  4894. 1308 if volume:
  4895. 1309 (self._provider.gcp_compute
  4896. 1310 .disks()
  4897. 1311 .delete(project=self.provider.project_name,
  4898. 1312 zone=volume.zone_name,
  4899. 1313 disk=volume.name)
  4900. 1314 .execute())
  4901. Total time: 0 s
  4902. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4903. Function: get at line 1322
  4904. Line # Hits Time Per Hit % Time Line Contents
  4905. ==============================================================
  4906. 1322 @dispatch(event="provider.storage.snapshots.get",
  4907. 1323 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  4908. 1324 @profile
  4909. 1325 def get(self, snapshot_id):
  4910. 1326 snapshot = self.provider.get_resource('snapshots', snapshot_id)
  4911. 1327 return GCPSnapshot(self.provider, snapshot) if snapshot else None
  4912. Total time: 0 s
  4913. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4914. Function: find at line 1329
  4915. Line # Hits Time Per Hit % Time Line Contents
  4916. ==============================================================
  4917. 1329 @dispatch(event="provider.storage.snapshots.find",
  4918. 1330 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  4919. 1331 @profile
  4920. 1332 def find(self, limit=None, marker=None, **kwargs):
  4921. 1333 label = kwargs.pop('label', None)
  4922. 1334
  4923. 1335 # All kwargs should have been popped at this time.
  4924. 1336 if len(kwargs) > 0:
  4925. 1337 raise InvalidParamException(
  4926. 1338 "Unrecognised parameters for search: %s. Supported "
  4927. 1339 "attributes: %s" % (kwargs, 'label'))
  4928. 1340
  4929. 1341 filtr = 'labels.cblabel eq ' + label
  4930. 1342 max_result = limit if limit is not None and limit < 500 else 500
  4931. 1343 response = (self.provider
  4932. 1344 .gcp_compute
  4933. 1345 .snapshots()
  4934. 1346 .list(project=self.provider.project_name,
  4935. 1347 filter=filtr,
  4936. 1348 maxResults=max_result,
  4937. 1349 pageToken=marker)
  4938. 1350 .execute())
  4939. 1351 snapshots = [GCPSnapshot(self.provider, snapshot)
  4940. 1352 for snapshot in response.get('items', [])]
  4941. 1353 if len(snapshots) > max_result:
  4942. 1354 log.warning('Expected at most %d results; got %d',
  4943. 1355 max_result, len(snapshots))
  4944. 1356 return ServerPagedResultList('nextPageToken' in response,
  4945. 1357 response.get('nextPageToken'),
  4946. 1358 False, data=snapshots)
  4947. Total time: 0 s
  4948. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4949. Function: list at line 1360
  4950. Line # Hits Time Per Hit % Time Line Contents
  4951. ==============================================================
  4952. 1360 @dispatch(event="provider.storage.snapshots.list",
  4953. 1361 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  4954. 1362 @profile
  4955. 1363 def list(self, limit=None, marker=None):
  4956. 1364 max_result = limit if limit is not None and limit < 500 else 500
  4957. 1365 response = (self.provider
  4958. 1366 .gcp_compute
  4959. 1367 .snapshots()
  4960. 1368 .list(project=self.provider.project_name,
  4961. 1369 maxResults=max_result,
  4962. 1370 pageToken=marker)
  4963. 1371 .execute())
  4964. 1372 snapshots = [GCPSnapshot(self.provider, snapshot)
  4965. 1373 for snapshot in response.get('items', [])]
  4966. 1374 if len(snapshots) > max_result:
  4967. 1375 log.warning('Expected at most %d results; got %d',
  4968. 1376 max_result, len(snapshots))
  4969. 1377 return ServerPagedResultList('nextPageToken' in response,
  4970. 1378 response.get('nextPageToken'),
  4971. 1379 False, data=snapshots)
  4972. Total time: 0 s
  4973. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4974. Function: create at line 1381
  4975. Line # Hits Time Per Hit % Time Line Contents
  4976. ==============================================================
  4977. 1381 @dispatch(event="provider.storage.snapshots.create",
  4978. 1382 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  4979. 1383 @profile
  4980. 1384 def create(self, label, volume, description=None):
  4981. 1385 GCPSnapshot.assert_valid_resource_label(label)
  4982. 1386 name = GCPSnapshot._generate_name_from_label(label, 'cbsnap')
  4983. 1387 volume_name = volume.name if isinstance(volume, GCPVolume) else volume
  4984. 1388 labels = {'cblabel': label}
  4985. 1389 if description:
  4986. 1390 labels['description'] = description
  4987. 1391 snapshot_body = {
  4988. 1392 "name": name,
  4989. 1393 "labels": labels
  4990. 1394 }
  4991. 1395 operation = (self.provider
  4992. 1396 .gcp_compute
  4993. 1397 .disks()
  4994. 1398 .createSnapshot(
  4995. 1399 project=self.provider.project_name,
  4996. 1400 zone=self.provider.default_zone,
  4997. 1401 disk=volume_name, body=snapshot_body)
  4998. 1402 .execute())
  4999. 1403 if 'zone' not in operation:
  5000. 1404 return None
  5001. 1405 self.provider.wait_for_operation(operation,
  5002. 1406 zone=self.provider.default_zone)
  5003. 1407 cb_snap = self.get(name)
  5004. 1408 return cb_snap
  5005. Total time: 0 s
  5006. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5007. Function: delete at line 1410
  5008. Line # Hits Time Per Hit % Time Line Contents
  5009. ==============================================================
  5010. 1410 @dispatch(event="provider.storage.snapshots.delete",
  5011. 1411 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  5012. 1412 @profile
  5013. 1413 def delete(self, snapshot):
  5014. 1414 snapshot = (snapshot if isinstance(snapshot, GCPSnapshot)
  5015. 1415 else self.get(snapshot))
  5016. 1416 if snapshot:
  5017. 1417 (self.provider
  5018. 1418 .gcp_compute
  5019. 1419 .snapshots()
  5020. 1420 .delete(project=self.provider.project_name,
  5021. 1421 snapshot=snapshot.name)
  5022. 1422 .execute())
  5023. Total time: 0 s
  5024. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5025. Function: get at line 1430
  5026. Line # Hits Time Per Hit % Time Line Contents
  5027. ==============================================================
  5028. 1430 @dispatch(event="provider.storage.buckets.get",
  5029. 1431 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  5030. 1432 @profile
  5031. 1433 def get(self, bucket_id):
  5032. 1434 """
  5033. 1435 Returns a bucket given its ID. Returns ``None`` if the bucket
  5034. 1436 does not exist or if the user does not have permission to access the
  5035. 1437 bucket.
  5036. 1438 """
  5037. 1439 bucket = self.provider.get_resource('buckets', bucket_id)
  5038. 1440 return GCPBucket(self.provider, bucket) if bucket else None
  5039. Total time: 0 s
  5040. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5041. Function: find at line 1442
  5042. Line # Hits Time Per Hit % Time Line Contents
  5043. ==============================================================
  5044. 1442 @dispatch(event="provider.storage.buckets.find",
  5045. 1443 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  5046. 1444 @profile
  5047. 1445 def find(self, limit=None, marker=None, **kwargs):
  5048. 1446 name = kwargs.pop('name', None)
  5049. 1447
  5050. 1448 # All kwargs should have been popped at this time.
  5051. 1449 if len(kwargs) > 0:
  5052. 1450 raise InvalidParamException(
  5053. 1451 "Unrecognised parameters for search: %s. Supported "
  5054. 1452 "attributes: %s" % (kwargs, 'name'))
  5055. 1453
  5056. 1454 buckets = [bucket for bucket in self if name in bucket.name]
  5057. 1455 return ClientPagedResultList(self.provider, buckets, limit=limit,
  5058. 1456 marker=marker)
  5059. Total time: 0 s
  5060. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5061. Function: list at line 1458
  5062. Line # Hits Time Per Hit % Time Line Contents
  5063. ==============================================================
  5064. 1458 @dispatch(event="provider.storage.buckets.list",
  5065. 1459 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  5066. 1460 @profile
  5067. 1461 def list(self, limit=None, marker=None):
  5068. 1462 """
  5069. 1463 List all containers.
  5070. 1464 """
  5071. 1465 max_result = limit if limit is not None and limit < 500 else 500
  5072. 1466 response = (self.provider
  5073. 1467 .gcp_storage
  5074. 1468 .buckets()
  5075. 1469 .list(project=self.provider.project_name,
  5076. 1470 maxResults=max_result,
  5077. 1471 pageToken=marker)
  5078. 1472 .execute())
  5079. 1473 buckets = []
  5080. 1474 for bucket in response.get('items', []):
  5081. 1475 buckets.append(GCPBucket(self.provider, bucket))
  5082. 1476 if len(buckets) > max_result:
  5083. 1477 log.warning('Expected at most %d results; got %d',
  5084. 1478 max_result, len(buckets))
  5085. 1479 return ServerPagedResultList('nextPageToken' in response,
  5086. 1480 response.get('nextPageToken'),
  5087. 1481 False, data=buckets)
  5088. Total time: 0 s
  5089. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5090. Function: create at line 1483
  5091. Line # Hits Time Per Hit % Time Line Contents
  5092. ==============================================================
  5093. 1483 @dispatch(event="provider.storage.buckets.create",
  5094. 1484 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  5095. 1485 @profile
  5096. 1486 def create(self, name, location=None):
  5097. 1487 GCPBucket.assert_valid_resource_name(name)
  5098. 1488 body = {'name': name}
  5099. 1489 if location:
  5100. 1490 body['location'] = location
  5101. 1491 try:
  5102. 1492 response = (self.provider
  5103. 1493 .gcp_storage
  5104. 1494 .buckets()
  5105. 1495 .insert(project=self.provider.project_name,
  5106. 1496 body=body)
  5107. 1497 .execute())
  5108. 1498 # GCP has a rate limit of 1 operation per 2 seconds for bucket
  5109. 1499 # creation/deletion: https://cloud.google.com/storage/quotas.
  5110. 1500 # Throttle here to avoid future failures.
  5111. 1501 time.sleep(2)
  5112. 1502 return GCPBucket(self.provider, response)
  5113. 1503 except googleapiclient.errors.HttpError as http_error:
  5114. 1504 # 409 = conflict
  5115. 1505 if http_error.resp.status in [409]:
  5116. 1506 raise DuplicateResourceException(
  5117. 1507 'Bucket already exists with name {0}'.format(name))
  5118. 1508 else:
  5119. 1509 raise
  5120. Total time: 0 s
  5121. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5122. Function: delete at line 1511
  5123. Line # Hits Time Per Hit % Time Line Contents
  5124. ==============================================================
  5125. 1511 @dispatch(event="provider.storage.buckets.delete",
  5126. 1512 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  5127. 1513 @profile
  5128. 1514 def delete(self, bucket):
  5129. 1515 """
  5130. 1516 Delete this bucket.
  5131. 1517 """
  5132. 1518 b = bucket if isinstance(bucket, GCPBucket) else self.get(bucket)
  5133. 1519 if b:
  5134. 1520 (self.provider
  5135. 1521 .gcp_storage
  5136. 1522 .buckets()
  5137. 1523 .delete(bucket=b.name)
  5138. 1524 .execute())
  5139. 1525 # GCP has a rate limit of 1 operation per 2 seconds for bucket
  5140. 1526 # creation/deletion: https://cloud.google.com/storage/quotas.
  5141. 1527 # Throttle here to avoid future failures.
  5142. 1528 time.sleep(2)
  5143. Total time: 0 s
  5144. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5145. Function: get at line 1536
  5146. Line # Hits Time Per Hit % Time Line Contents
  5147. ==============================================================
  5148. 1536 @profile
  5149. 1537 def get(self, bucket, name):
  5150. 1538 """
  5151. 1539 Retrieve a given object from this bucket.
  5152. 1540 """
  5153. 1541 obj = self.provider.get_resource('objects', name,
  5154. 1542 bucket=bucket.name)
  5155. 1543 return GCPBucketObject(self.provider, bucket, obj) if obj else None
  5156. Total time: 0 s
  5157. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5158. Function: list at line 1545
  5159. Line # Hits Time Per Hit % Time Line Contents
  5160. ==============================================================
  5161. 1545 @profile
  5162. 1546 def list(self, bucket, limit=None, marker=None, prefix=None):
  5163. 1547 """
  5164. 1548 List all objects within this bucket.
  5165. 1549 """
  5166. 1550 max_result = limit if limit is not None and limit < 500 else 500
  5167. 1551 response = (self.provider
  5168. 1552 .gcp_storage
  5169. 1553 .objects()
  5170. 1554 .list(bucket=bucket.name,
  5171. 1555 prefix=prefix if prefix else '',
  5172. 1556 maxResults=max_result,
  5173. 1557 pageToken=marker)
  5174. 1558 .execute())
  5175. 1559 objects = []
  5176. 1560 for obj in response.get('items', []):
  5177. 1561 objects.append(GCPBucketObject(self.provider, bucket, obj))
  5178. 1562 if len(objects) > max_result:
  5179. 1563 log.warning('Expected at most %d results; got %d',
  5180. 1564 max_result, len(objects))
  5181. 1565 return ServerPagedResultList('nextPageToken' in response,
  5182. 1566 response.get('nextPageToken'),
  5183. 1567 False, data=objects)
  5184. Total time: 0 s
  5185. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5186. Function: find at line 1569
  5187. Line # Hits Time Per Hit % Time Line Contents
  5188. ==============================================================
  5189. 1569 @profile
  5190. 1570 def find(self, bucket, limit=None, marker=None, **kwargs):
  5191. 1571 filters = ['name']
  5192. 1572 matches = cb_helpers.generic_find(filters, kwargs, bucket.objects)
  5193. 1573 return ClientPagedResultList(self._provider, list(matches),
  5194. 1574 limit=limit, marker=marker)
  5195. Total time: 0 s
  5196. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5197. Function: create at line 1586
  5198. Line # Hits Time Per Hit % Time Line Contents
  5199. ==============================================================
  5200. 1586 @profile
  5201. 1587 def create(self, bucket, name):
  5202. 1588 response = self._create_object_with_media_body(
  5203. 1589 bucket,
  5204. 1590 name,
  5205. 1591 googleapiclient.http.MediaIoBaseUpload(
  5206. 1592 io.BytesIO(b''), mimetype='plain/text'))
  5207. 1593 return GCPBucketObject(self._provider,
  5208. 1594 bucket,
  5209. 1595 response) if response else None
  5210. Total time: 0 s
  5211. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5212. Function: get_or_create at line 1610
  5213. Line # Hits Time Per Hit % Time Line Contents
  5214. ==============================================================
  5215. 1610 @dispatch(event="provider.networking.gateways.get_or_create",
  5216. 1611 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  5217. 1612 @profile
  5218. 1613 def get_or_create(self, network):
  5219. 1614 return self._default_internet_gateway
  5220. Total time: 0 s
  5221. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5222. Function: delete at line 1616
  5223. Line # Hits Time Per Hit % Time Line Contents
  5224. ==============================================================
  5225. 1616 @dispatch(event="provider.networking.gateways.delete",
  5226. 1617 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  5227. 1618 @profile
  5228. 1619 def delete(self, network, gateway):
  5229. 1620 pass
  5230. Total time: 0 s
  5231. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5232. Function: list at line 1622
  5233. Line # Hits Time Per Hit % Time Line Contents
  5234. ==============================================================
  5235. 1622 @dispatch(event="provider.networking.gateways.list",
  5236. 1623 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  5237. 1624 @profile
  5238. 1625 def list(self, network, limit=None, marker=None):
  5239. 1626 gws = [self._default_internet_gateway]
  5240. 1627 return ClientPagedResultList(self._provider,
  5241. 1628 gws,
  5242. 1629 limit=limit, marker=marker)
  5243. Total time: 0 s
  5244. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5245. Function: get at line 1637
  5246. Line # Hits Time Per Hit % Time Line Contents
  5247. ==============================================================
  5248. 1637 @dispatch(event="provider.networking.floating_ips.get",
  5249. 1638 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  5250. 1639 @profile
  5251. 1640 def get(self, gateway, floating_ip_id):
  5252. 1641 fip = self.provider.get_resource('addresses', floating_ip_id)
  5253. 1642 return (GCPFloatingIP(self.provider, fip)
  5254. 1643 if fip else None)
  5255. Total time: 0 s
  5256. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5257. Function: list at line 1645
  5258. Line # Hits Time Per Hit % Time Line Contents
  5259. ==============================================================
  5260. 1645 @dispatch(event="provider.networking.floating_ips.list",
  5261. 1646 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  5262. 1647 @profile
  5263. 1648 def list(self, gateway, limit=None, marker=None):
  5264. 1649 max_result = limit if limit is not None and limit < 500 else 500
  5265. 1650 response = (self.provider
  5266. 1651 .gcp_compute
  5267. 1652 .addresses()
  5268. 1653 .list(project=self.provider.project_name,
  5269. 1654 region=self.provider.region_name,
  5270. 1655 maxResults=max_result,
  5271. 1656 pageToken=marker)
  5272. 1657 .execute())
  5273. 1658 ips = [GCPFloatingIP(self.provider, ip)
  5274. 1659 for ip in response.get('items', [])]
  5275. 1660 if len(ips) > max_result:
  5276. 1661 log.warning('Expected at most %d results; got %d',
  5277. 1662 max_result, len(ips))
  5278. 1663 return ServerPagedResultList('nextPageToken' in response,
  5279. 1664 response.get('nextPageToken'),
  5280. 1665 False, data=ips)
  5281. Total time: 0 s
  5282. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5283. Function: create at line 1667
  5284. Line # Hits Time Per Hit % Time Line Contents
  5285. ==============================================================
  5286. 1667 @dispatch(event="provider.networking.floating_ips.create",
  5287. 1668 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  5288. 1669 @profile
  5289. 1670 def create(self, gateway):
  5290. 1671 region_name = self.provider.region_name
  5291. 1672 ip_name = 'ip-{0}'.format(uuid.uuid4())
  5292. 1673 response = (self.provider
  5293. 1674 .gcp_compute
  5294. 1675 .addresses()
  5295. 1676 .insert(project=self.provider.project_name,
  5296. 1677 region=region_name,
  5297. 1678 body={'name': ip_name})
  5298. 1679 .execute())
  5299. 1680 self.provider.wait_for_operation(response, region=region_name)
  5300. 1681 return self.get(gateway, ip_name)
  5301. Total time: 0 s
  5302. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5303. Function: delete at line 1683
  5304. Line # Hits Time Per Hit % Time Line Contents
  5305. ==============================================================
  5306. 1683 @dispatch(event="provider.networking.floating_ips.delete",
  5307. 1684 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  5308. 1685 @profile
  5309. 1686 def delete(self, gateway, fip):
  5310. 1687 fip = (fip if isinstance(fip, GCPFloatingIP)
  5311. 1688 else self.get(gateway, fip))
  5312. 1689 project_name = self.provider.project_name
  5313. 1690 # First, delete the forwarding rule, if there is any.
  5314. 1691 # pylint:disable=protected-access
  5315. 1692 if fip._rule:
  5316. 1693 response = (self.provider
  5317. 1694 .gcp_compute
  5318. 1695 .forwardingRules()
  5319. 1696 .delete(project=project_name,
  5320. 1697 region=fip.region_name,
  5321. 1698 forwardingRule=fip._rule['name'])
  5322. 1699 .execute())
  5323. 1700 self.provider.wait_for_operation(response,
  5324. 1701 region=fip.region_name)
  5325. 1702
  5326. 1703 # Release the address.
  5327. 1704 response = (self.provider
  5328. 1705 .gcp_compute
  5329. 1706 .addresses()
  5330. 1707 .delete(project=project_name,
  5331. 1708 region=fip.region_name,
  5332. 1709 address=fip._ip['name'])
  5333. 1710 .execute())
  5334. 1711 self.provider.wait_for_operation(response,
  5335. 1712 region=fip.region_name)
  5336. Total time: 0 s
  5337. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5338. Function: label at line 108
  5339. Line # Hits Time Per Hit % Time Line Contents
  5340. ==============================================================
  5341. 108 @label.setter
  5342. 109 # pylint:disable=arguments-differ
  5343. 110 @profile
  5344. 111 def label(self, value):
  5345. 112 """
  5346. 113 Set the image label.
  5347. 114 """
  5348. 115 self.assert_valid_resource_label(value)
  5349. 116 self._provider.os_conn.image.update_image(
  5350. 117 self._os_image, name=value or "")
  5351. Total time: 0 s
  5352. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5353. Function: refresh at line 148
  5354. Line # Hits Time Per Hit % Time Line Contents
  5355. ==============================================================
  5356. 148 @profile
  5357. 149 def refresh(self):
  5358. 150 """
  5359. 151 Refreshes the state of this instance by re-querying the cloud provider
  5360. 152 for its latest state.
  5361. 153 """
  5362. 154 log.debug("Refreshing OpenStack Machine Image")
  5363. 155 image = self._provider.compute.images.get(self.id)
  5364. 156 if image:
  5365. 157 # pylint:disable=protected-access
  5366. 158 self._os_image = image._os_image
  5367. 159 else:
  5368. 160 # The image no longer exists and cannot be refreshed.
  5369. 161 # set the status to unknown
  5370. 162 self._os_image.status = 'unknown'
  5371. Total time: 0 s
  5372. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5373. Function: label at line 312
  5374. Line # Hits Time Per Hit % Time Line Contents
  5375. ==============================================================
  5376. 312 @label.setter
  5377. 313 # pylint:disable=arguments-differ
  5378. 314 @profile
  5379. 315 def label(self, value):
  5380. 316 """
  5381. 317 Set the instance label.
  5382. 318 """
  5383. 319 self.assert_valid_resource_label(value)
  5384. 320
  5385. 321 self._os_instance.name = value
  5386. 322 self._os_instance.update(name=value or "cb-inst")
  5387. Total time: 0 s
  5388. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5389. Function: refresh at line 493
  5390. Line # Hits Time Per Hit % Time Line Contents
  5391. ==============================================================
  5392. 493 @profile
  5393. 494 def refresh(self):
  5394. 495 """
  5395. 496 Refreshes the state of this instance by re-querying the cloud provider
  5396. 497 for its latest state.
  5397. 498 """
  5398. 499 instance = self._provider.compute.instances.get(
  5399. 500 self.id)
  5400. 501 if instance:
  5401. 502 # pylint:disable=protected-access
  5402. 503 self._os_instance = instance._os_instance
  5403. 504 else:
  5404. 505 # The instance no longer exists and cannot be refreshed.
  5405. 506 # set the status to unknown
  5406. 507 self._os_instance.status = 'unknown'
  5407. Total time: 0 s
  5408. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5409. Function: label at line 582
  5410. Line # Hits Time Per Hit % Time Line Contents
  5411. ==============================================================
  5412. 582 @label.setter
  5413. 583 # pylint:disable=arguments-differ
  5414. 584 @profile
  5415. 585 def label(self, value):
  5416. 586 """
  5417. 587 Set the volume label.
  5418. 588 """
  5419. 589 self.assert_valid_resource_label(value)
  5420. 590 self._volume.name = value
  5421. 591 self._volume.update(name=value or "")
  5422. Total time: 0 s
  5423. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5424. Function: description at line 597
  5425. Line # Hits Time Per Hit % Time Line Contents
  5426. ==============================================================
  5427. 597 @description.setter
  5428. 598 @profile
  5429. 599 def description(self, value):
  5430. 600 self._volume.description = value
  5431. 601 self._volume.update(description=value)
  5432. Total time: 0 s
  5433. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5434. Function: refresh at line 662
  5435. Line # Hits Time Per Hit % Time Line Contents
  5436. ==============================================================
  5437. 662 @profile
  5438. 663 def refresh(self):
  5439. 664 """
  5440. 665 Refreshes the state of this volume by re-querying the cloud provider
  5441. 666 for its latest state.
  5442. 667 """
  5443. 668 vol = self._provider.storage.volumes.get(
  5444. 669 self.id)
  5445. 670 if vol:
  5446. 671 # pylint:disable=protected-access
  5447. 672 self._volume = vol._volume # pylint:disable=protected-access
  5448. 673 else:
  5449. 674 # The volume no longer exists and cannot be refreshed.
  5450. 675 # set the status to unknown
  5451. 676 self._volume.status = 'unknown'
  5452. Total time: 0 s
  5453. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5454. Function: label at line 710
  5455. Line # Hits Time Per Hit % Time Line Contents
  5456. ==============================================================
  5457. 710 @label.setter
  5458. 711 # pylint:disable=arguments-differ
  5459. 712 @profile
  5460. 713 def label(self, value):
  5461. 714 """
  5462. 715 Set the snapshot label.
  5463. 716 """
  5464. 717 self.assert_valid_resource_label(value)
  5465. 718 self._snapshot.name = value
  5466. 719 self._snapshot.update(name=value or "")
  5467. Total time: 0 s
  5468. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5469. Function: description at line 725
  5470. Line # Hits Time Per Hit % Time Line Contents
  5471. ==============================================================
  5472. 725 @description.setter
  5473. 726 @profile
  5474. 727 def description(self, value):
  5475. 728 self._snapshot.description = value
  5476. 729 self._snapshot.update(description=value)
  5477. Total time: 0 s
  5478. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5479. Function: refresh at line 748
  5480. Line # Hits Time Per Hit % Time Line Contents
  5481. ==============================================================
  5482. 748 @profile
  5483. 749 def refresh(self):
  5484. 750 """
  5485. 751 Refreshes the state of this snapshot by re-querying the cloud provider
  5486. 752 for its latest state.
  5487. 753 """
  5488. 754 snap = self._provider.storage.snapshots.get(
  5489. 755 self.id)
  5490. 756 if snap:
  5491. 757 # pylint:disable=protected-access
  5492. 758 self._snapshot = snap._snapshot
  5493. 759 else:
  5494. 760 # The snapshot no longer exists and cannot be refreshed.
  5495. 761 # set the status to unknown
  5496. 762 self._snapshot.status = 'unknown'
  5497. Total time: 0 s
  5498. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5499. Function: label at line 811
  5500. Line # Hits Time Per Hit % Time Line Contents
  5501. ==============================================================
  5502. 811 @label.setter
  5503. 812 @profile
  5504. 813 def label(self, value):
  5505. 814 """
  5506. 815 Set the network label.
  5507. 816 """
  5508. 817 self.assert_valid_resource_label(value)
  5509. 818 self._provider.neutron.update_network(
  5510. 819 self.id, {'network': {'name': value or ""}})
  5511. 820 self.refresh()
  5512. Total time: 0 s
  5513. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5514. Function: refresh at line 842
  5515. Line # Hits Time Per Hit % Time Line Contents
  5516. ==============================================================
  5517. 842 @profile
  5518. 843 def refresh(self):
  5519. 844 """Refresh the state of this network by re-querying the provider."""
  5520. 845 network = self._provider.networking.networks.get(self.id)
  5521. 846 if network:
  5522. 847 # pylint:disable=protected-access
  5523. 848 self._network = network._network
  5524. 849 else:
  5525. 850 # Network no longer exists
  5526. 851 self._network = {}
  5527. Total time: 0 s
  5528. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5529. Function: label at line 877
  5530. Line # Hits Time Per Hit % Time Line Contents
  5531. ==============================================================
  5532. 877 @label.setter
  5533. 878 @profile
  5534. 879 def label(self, value): # pylint:disable=arguments-differ
  5535. 880 """
  5536. 881 Set the subnet label.
  5537. 882 """
  5538. 883 self.assert_valid_resource_label(value)
  5539. 884 self._provider.neutron.update_subnet(
  5540. 885 self.id, {'subnet': {'name': value or ""}})
  5541. 886 self._subnet['name'] = value
  5542. Total time: 0 s
  5543. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5544. Function: refresh at line 910
  5545. Line # Hits Time Per Hit % Time Line Contents
  5546. ==============================================================
  5547. 910 @profile
  5548. 911 def refresh(self):
  5549. 912 subnet = self._provider.networking.subnets.get(self.id)
  5550. 913 if subnet:
  5551. 914 # pylint:disable=protected-access
  5552. 915 self._subnet = subnet._subnet
  5553. 916 self._state = SubnetState.AVAILABLE
  5554. 917 else:
  5555. 918 # subnet no longer exists
  5556. 919 self._state = SubnetState.UNKNOWN
  5557. Total time: 0 s
  5558. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5559. Function: refresh at line 944
  5560. Line # Hits Time Per Hit % Time Line Contents
  5561. ==============================================================
  5562. 944 @profile
  5563. 945 def refresh(self):
  5564. 946 net = self._provider.networking.networks.get(
  5565. 947 self._ip.floating_network_id)
  5566. 948 gw = net.gateways.get_or_create()
  5567. 949 fip = gw.floating_ips.get(self.id)
  5568. 950 # pylint:disable=protected-access
  5569. 951 self._ip = fip._ip
  5570. Total time: 0 s
  5571. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5572. Function: label at line 976
  5573. Line # Hits Time Per Hit % Time Line Contents
  5574. ==============================================================
  5575. 976 @label.setter
  5576. 977 @profile
  5577. 978 def label(self, value): # pylint:disable=arguments-differ
  5578. 979 """
  5579. 980 Set the router label.
  5580. 981 """
  5581. 982 self.assert_valid_resource_label(value)
  5582. 983 self._router = self._provider.os_conn.update_router(self.id, value)
  5583. Total time: 0 s
  5584. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5585. Function: refresh at line 985
  5586. Line # Hits Time Per Hit % Time Line Contents
  5587. ==============================================================
  5588. 985 @profile
  5589. 986 def refresh(self):
  5590. 987 self._router = self._provider.os_conn.get_router(self.id)
  5591. Total time: 0 s
  5592. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5593. Function: refresh at line 1070
  5594. Line # Hits Time Per Hit % Time Line Contents
  5595. ==============================================================
  5596. 1070 @profile
  5597. 1071 def refresh(self):
  5598. 1072 """Refresh the state of this network by re-querying the provider."""
  5599. 1073 network = self._provider.networking.networks.get(self.id)
  5600. 1074 if network:
  5601. 1075 # pylint:disable=protected-access
  5602. 1076 self._gateway_net = network._network
  5603. 1077 else:
  5604. 1078 # subnet no longer exists
  5605. 1079 self._gateway_net.state = NetworkState.UNKNOWN
  5606. Total time: 0 s
  5607. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5608. Function: description at line 1137
  5609. Line # Hits Time Per Hit % Time Line Contents
  5610. ==============================================================
  5611. 1137 @description.setter
  5612. 1138 @profile
  5613. 1139 def description(self, value):
  5614. 1140 if not value:
  5615. 1141 value = ""
  5616. 1142 value += " [{}{}]".format(self._network_id_tag,
  5617. 1143 self.network_id)
  5618. 1144 self._provider.os_conn.network.update_security_group(
  5619. 1145 self.id, description=value)
  5620. 1146 self.refresh()
  5621. Total time: 0 s
  5622. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5623. Function: label at line 1159
  5624. Line # Hits Time Per Hit % Time Line Contents
  5625. ==============================================================
  5626. 1159 @label.setter
  5627. 1160 # pylint:disable=arguments-differ
  5628. 1161 @profile
  5629. 1162 def label(self, value):
  5630. 1163 self.assert_valid_resource_label(value)
  5631. 1164 self._provider.os_conn.network.update_security_group(
  5632. 1165 self.id, name=value or "")
  5633. 1166 self.refresh()
  5634. Total time: 0 s
  5635. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5636. Function: refresh at line 1172
  5637. Line # Hits Time Per Hit % Time Line Contents
  5638. ==============================================================
  5639. 1172 @profile
  5640. 1173 def refresh(self):
  5641. 1174 self._vm_firewall = self._provider.os_conn.network.get_security_group(
  5642. 1175 self.id)
  5643. Total time: 0 s
  5644. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5645. Function: refresh at line 1345
  5646. Line # Hits Time Per Hit % Time Line Contents
  5647. ==============================================================
  5648. 1345 @profile
  5649. 1346 def refresh(self):
  5650. 1347 self._obj = self.cbcontainer.objects.get(self.id)._obj
  5651. Total time: 0 s
  5652. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5653. Function: get_or_create_ec2_credentials at line 101
  5654. Line # Hits Time Per Hit % Time Line Contents
  5655. ==============================================================
  5656. 101 @profile
  5657. 102 def get_or_create_ec2_credentials(self):
  5658. 103 """
  5659. 104 A provider specific method than returns the ec2 credentials for the
  5660. 105 current user, or creates a new pair if one doesn't exist.
  5661. 106 """
  5662. 107 keystone = self.provider.keystone
  5663. 108 if hasattr(keystone, 'ec2'):
  5664. 109 user_id = keystone.session.get_user_id()
  5665. 110 user_creds = [cred for cred in keystone.ec2.list(user_id) if
  5666. 111 cred.tenant_id == keystone.session.get_project_id()]
  5667. 112 if user_creds:
  5668. 113 return user_creds[0]
  5669. 114 else:
  5670. 115 return keystone.ec2.create(
  5671. 116 user_id, keystone.session.get_project_id())
  5672. 117
  5673. 118 return None
  5674. Total time: 0 s
  5675. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5676. Function: get_ec2_endpoints at line 120
  5677. Line # Hits Time Per Hit % Time Line Contents
  5678. ==============================================================
  5679. 120 @profile
  5680. 121 def get_ec2_endpoints(self):
  5681. 122 """
  5682. 123 A provider specific method than returns the ec2 endpoints if
  5683. 124 available.
  5684. 125 """
  5685. 126 keystone = self.provider.keystone
  5686. 127 ec2_url = keystone.session.get_endpoint(service_type='ec2')
  5687. 128 s3_url = keystone.session.get_endpoint(service_type='s3')
  5688. 129
  5689. 130 return {'ec2_endpoint': ec2_url,
  5690. 131 's3_endpoint': s3_url}
  5691. Total time: 0 s
  5692. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5693. Function: get at line 139
  5694. Line # Hits Time Per Hit % Time Line Contents
  5695. ==============================================================
  5696. 139 @dispatch(event="provider.security.key_pairs.get",
  5697. 140 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  5698. 141 @profile
  5699. 142 def get(self, key_pair_id):
  5700. 143 """
  5701. 144 Returns a KeyPair given its id.
  5702. 145 """
  5703. 146 log.debug("Returning KeyPair with the id %s", key_pair_id)
  5704. 147 try:
  5705. 148 return OpenStackKeyPair(
  5706. 149 self.provider, self.provider.nova.keypairs.get(key_pair_id))
  5707. 150 except NovaNotFound:
  5708. 151 log.debug("KeyPair %s was not found.", key_pair_id)
  5709. 152 return None
  5710. Total time: 0 s
  5711. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5712. Function: list at line 154
  5713. Line # Hits Time Per Hit % Time Line Contents
  5714. ==============================================================
  5715. 154 @dispatch(event="provider.security.key_pairs.list",
  5716. 155 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  5717. 156 @profile
  5718. 157 def list(self, limit=None, marker=None):
  5719. 158 """
  5720. 159 List all key pairs associated with this account.
  5721. 160
  5722. 161 :rtype: ``list`` of :class:`.KeyPair`
  5723. 162 :return: list of KeyPair objects
  5724. 163 """
  5725. 164 keypairs = self.provider.nova.keypairs.list()
  5726. 165 results = [OpenStackKeyPair(self.provider, kp)
  5727. 166 for kp in keypairs]
  5728. 167 log.debug("Listing all key pairs associated with OpenStack "
  5729. 168 "Account: %s", results)
  5730. 169 return ClientPagedResultList(self.provider, results,
  5731. 170 limit=limit, marker=marker)
  5732. Total time: 0 s
  5733. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5734. Function: find at line 172
  5735. Line # Hits Time Per Hit % Time Line Contents
  5736. ==============================================================
  5737. 172 @dispatch(event="provider.security.key_pairs.find",
  5738. 173 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  5739. 174 @profile
  5740. 175 def find(self, **kwargs):
  5741. 176 name = kwargs.pop('name', None)
  5742. 177
  5743. 178 # All kwargs should have been popped at this time.
  5744. 179 if len(kwargs) > 0:
  5745. 180 raise InvalidParamException(
  5746. 181 "Unrecognised parameters for search: %s. Supported "
  5747. 182 "attributes: %s" % (kwargs, 'name'))
  5748. 183
  5749. 184 keypairs = self.provider.nova.keypairs.findall(name=name)
  5750. 185 results = [OpenStackKeyPair(self.provider, kp)
  5751. 186 for kp in keypairs]
  5752. 187 log.debug("Searching for %s in: %s", name, keypairs)
  5753. 188 return ClientPagedResultList(self.provider, results)
  5754. Total time: 0 s
  5755. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5756. Function: create at line 190
  5757. Line # Hits Time Per Hit % Time Line Contents
  5758. ==============================================================
  5759. 190 @dispatch(event="provider.security.key_pairs.create",
  5760. 191 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  5761. 192 @profile
  5762. 193 def create(self, name, public_key_material=None):
  5763. 194 OpenStackKeyPair.assert_valid_resource_name(name)
  5764. 195 existing_kp = self.find(name=name)
  5765. 196 if existing_kp:
  5766. 197 raise DuplicateResourceException(
  5767. 198 'Keypair already exists with name {0}'.format(name))
  5768. 199
  5769. 200 private_key = None
  5770. 201 if not public_key_material:
  5771. 202 public_key_material, private_key = cb_helpers.generate_key_pair()
  5772. 203
  5773. 204 kp = self.provider.nova.keypairs.create(name,
  5774. 205 public_key=public_key_material)
  5775. 206 cb_kp = OpenStackKeyPair(self.provider, kp)
  5776. 207 cb_kp.material = private_key
  5777. 208 return cb_kp
  5778. Total time: 0 s
  5779. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5780. Function: delete at line 210
  5781. Line # Hits Time Per Hit % Time Line Contents
  5782. ==============================================================
  5783. 210 @dispatch(event="provider.security.key_pairs.delete",
  5784. 211 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  5785. 212 @profile
  5786. 213 def delete(self, key_pair):
  5787. 214 keypair = (key_pair if isinstance(key_pair, OpenStackKeyPair)
  5788. 215 else self.get(key_pair))
  5789. 216 if keypair:
  5790. 217 # pylint:disable=protected-access
  5791. 218 keypair._key_pair.delete()
  5792. Total time: 0 s
  5793. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5794. Function: get at line 226
  5795. Line # Hits Time Per Hit % Time Line Contents
  5796. ==============================================================
  5797. 226 @dispatch(event="provider.security.vm_firewalls.get",
  5798. 227 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  5799. 228 @profile
  5800. 229 def get(self, vm_firewall_id):
  5801. 230 try:
  5802. 231 return OpenStackVMFirewall(
  5803. 232 self.provider,
  5804. 233 self.provider.os_conn.network
  5805. 234 .get_security_group(vm_firewall_id))
  5806. 235 except (ResourceNotFound, NotFoundException):
  5807. 236 log.debug("Firewall %s not found.", vm_firewall_id)
  5808. 237 return None
  5809. Total time: 0 s
  5810. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5811. Function: list at line 239
  5812. Line # Hits Time Per Hit % Time Line Contents
  5813. ==============================================================
  5814. 239 @dispatch(event="provider.security.vm_firewalls.list",
  5815. 240 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  5816. 241 @profile
  5817. 242 def list(self, limit=None, marker=None):
  5818. 243 firewalls = [
  5819. 244 OpenStackVMFirewall(self.provider, fw)
  5820. 245 for fw in self.provider.os_conn.network.security_groups()]
  5821. 246
  5822. 247 return ClientPagedResultList(self.provider, firewalls,
  5823. 248 limit=limit, marker=marker)
  5824. Total time: 0 s
  5825. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5826. Function: create at line 250
  5827. Line # Hits Time Per Hit % Time Line Contents
  5828. ==============================================================
  5829. 250 @cb_helpers.deprecated_alias(network_id='network')
  5830. 251 @dispatch(event="provider.security.vm_firewalls.create",
  5831. 252 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  5832. 253 @profile
  5833. 254 def create(self, label, network, description=None):
  5834. 255 OpenStackVMFirewall.assert_valid_resource_label(label)
  5835. 256 net_id = network.id if isinstance(network, Network) else network
  5836. 257 # We generally simulate a network being associated with a firewall
  5837. 258 # by storing the supplied value in the firewall description field that
  5838. 259 # is not modifiable after creation; however, because of some networking
  5839. 260 # specificity in Nectar, we must also allow an empty network id value.
  5840. 261 if not net_id:
  5841. 262 net_id = ""
  5842. 263 if not description:
  5843. 264 description = ""
  5844. 265 description += " [{}{}]".format(OpenStackVMFirewall._network_id_tag,
  5845. 266 net_id)
  5846. 267 sg = self.provider.os_conn.network.create_security_group(
  5847. 268 name=label, description=description)
  5848. 269 if sg:
  5849. 270 return OpenStackVMFirewall(self.provider, sg)
  5850. 271 return None
  5851. Total time: 0 s
  5852. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5853. Function: delete at line 273
  5854. Line # Hits Time Per Hit % Time Line Contents
  5855. ==============================================================
  5856. 273 @dispatch(event="provider.security.vm_firewalls.delete",
  5857. 274 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  5858. 275 @profile
  5859. 276 def delete(self, vm_firewall):
  5860. 277 fw = (vm_firewall if isinstance(vm_firewall, OpenStackVMFirewall)
  5861. 278 else self.get(vm_firewall))
  5862. 279 if fw:
  5863. 280 # pylint:disable=protected-access
  5864. 281 fw._vm_firewall.delete(self.provider.os_conn.session)
  5865. Total time: 0 s
  5866. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5867. Function: list at line 289
  5868. Line # Hits Time Per Hit % Time Line Contents
  5869. ==============================================================
  5870. 289 @dispatch(event="provider.security.vm_firewall_rules.list",
  5871. 290 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  5872. 291 @profile
  5873. 292 def list(self, firewall, limit=None, marker=None):
  5874. 293 # pylint:disable=protected-access
  5875. 294 rules = [OpenStackVMFirewallRule(firewall, r)
  5876. 295 for r in firewall._vm_firewall.security_group_rules]
  5877. 296 return ClientPagedResultList(self.provider, rules,
  5878. 297 limit=limit, marker=marker)
  5879. Total time: 0 s
  5880. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5881. Function: create at line 299
  5882. Line # Hits Time Per Hit % Time Line Contents
  5883. ==============================================================
  5884. 299 @dispatch(event="provider.security.vm_firewall_rules.create",
  5885. 300 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  5886. 301 @profile
  5887. 302 def create(self, firewall, direction, protocol=None, from_port=None,
  5888. 303 to_port=None, cidr=None, src_dest_fw=None):
  5889. 304 src_dest_fw_id = (src_dest_fw.id if isinstance(src_dest_fw,
  5890. 305 OpenStackVMFirewall)
  5891. 306 else src_dest_fw)
  5892. 307
  5893. 308 try:
  5894. 309 if direction == TrafficDirection.INBOUND:
  5895. 310 os_direction = 'ingress'
  5896. 311 elif direction == TrafficDirection.OUTBOUND:
  5897. 312 os_direction = 'egress'
  5898. 313 else:
  5899. 314 raise InvalidValueException("direction", direction)
  5900. 315 # pylint:disable=protected-access
  5901. 316 rule = self.provider.os_conn.network.create_security_group_rule(
  5902. 317 security_group_id=firewall.id,
  5903. 318 direction=os_direction,
  5904. 319 port_range_max=to_port,
  5905. 320 port_range_min=from_port,
  5906. 321 protocol=protocol,
  5907. 322 remote_ip_prefix=cidr,
  5908. 323 remote_group_id=src_dest_fw_id)
  5909. 324 firewall.refresh()
  5910. 325 return OpenStackVMFirewallRule(firewall, rule.to_dict())
  5911. 326 except HttpException as e:
  5912. 327 firewall.refresh()
  5913. 328 # 409=Conflict, raised for duplicate rule
  5914. 329 if e.status_code == 409:
  5915. 330 existing = self.find(firewall, direction=direction,
  5916. 331 protocol=protocol, from_port=from_port,
  5917. 332 to_port=to_port, cidr=cidr,
  5918. 333 src_dest_fw_id=src_dest_fw_id)
  5919. 334 return existing[0]
  5920. 335 else:
  5921. 336 raise e
  5922. Total time: 0 s
  5923. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5924. Function: delete at line 338
  5925. Line # Hits Time Per Hit % Time Line Contents
  5926. ==============================================================
  5927. 338 @dispatch(event="provider.security.vm_firewall_rules.delete",
  5928. 339 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  5929. 340 @profile
  5930. 341 def delete(self, firewall, rule):
  5931. 342 rule_id = (rule.id if isinstance(rule, OpenStackVMFirewallRule)
  5932. 343 else rule)
  5933. 344 self.provider.os_conn.network.delete_security_group_rule(rule_id)
  5934. 345 firewall.refresh()
  5935. Total time: 0 s
  5936. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5937. Function: get at line 381
  5938. Line # Hits Time Per Hit % Time Line Contents
  5939. ==============================================================
  5940. 381 @dispatch(event="provider.storage.volumes.get",
  5941. 382 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  5942. 383 @profile
  5943. 384 def get(self, volume_id):
  5944. 385 try:
  5945. 386 return OpenStackVolume(
  5946. 387 self.provider, self.provider.cinder.volumes.get(volume_id))
  5947. 388 except CinderNotFound:
  5948. 389 log.debug("Volume %s was not found.", volume_id)
  5949. 390 return None
  5950. Total time: 0 s
  5951. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5952. Function: find at line 392
  5953. Line # Hits Time Per Hit % Time Line Contents
  5954. ==============================================================
  5955. 392 @dispatch(event="provider.storage.volumes.find",
  5956. 393 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  5957. 394 @profile
  5958. 395 def find(self, **kwargs):
  5959. 396 label = kwargs.pop('label', None)
  5960. 397
  5961. 398 # All kwargs should have been popped at this time.
  5962. 399 if len(kwargs) > 0:
  5963. 400 raise InvalidParamException(
  5964. 401 "Unrecognised parameters for search: %s. Supported "
  5965. 402 "attributes: %s" % (kwargs, 'label'))
  5966. 403
  5967. 404 log.debug("Searching for an OpenStack Volume with the label %s", label)
  5968. 405 search_opts = {'name': label}
  5969. 406 cb_vols = [
  5970. 407 OpenStackVolume(self.provider, vol)
  5971. 408 for vol in self.provider.cinder.volumes.list(
  5972. 409 search_opts=search_opts,
  5973. 410 limit=oshelpers.os_result_limit(self.provider),
  5974. 411 marker=None)]
  5975. 412
  5976. 413 return oshelpers.to_server_paged_list(self.provider, cb_vols)
  5977. Total time: 0 s
  5978. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5979. Function: list at line 415
  5980. Line # Hits Time Per Hit % Time Line Contents
  5981. ==============================================================
  5982. 415 @dispatch(event="provider.storage.volumes.list",
  5983. 416 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  5984. 417 @profile
  5985. 418 def list(self, limit=None, marker=None):
  5986. 419 cb_vols = [
  5987. 420 OpenStackVolume(self.provider, vol)
  5988. 421 for vol in self.provider.cinder.volumes.list(
  5989. 422 limit=oshelpers.os_result_limit(self.provider, limit),
  5990. 423 marker=marker)]
  5991. 424
  5992. 425 return oshelpers.to_server_paged_list(self.provider, cb_vols, limit)
  5993. Total time: 0 s
  5994. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5995. Function: create at line 427
  5996. Line # Hits Time Per Hit % Time Line Contents
  5997. ==============================================================
  5998. 427 @dispatch(event="provider.storage.volumes.create",
  5999. 428 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  6000. 429 @profile
  6001. 430 def create(self, label, size, zone, snapshot=None, description=None):
  6002. 431 OpenStackVolume.assert_valid_resource_label(label)
  6003. 432 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  6004. 433 snapshot_id = snapshot.id if isinstance(
  6005. 434 snapshot, OpenStackSnapshot) and snapshot else snapshot
  6006. 435
  6007. 436 os_vol = self.provider.cinder.volumes.create(
  6008. 437 size, name=label, description=description,
  6009. 438 availability_zone=zone_id, snapshot_id=snapshot_id)
  6010. 439 return OpenStackVolume(self.provider, os_vol)
  6011. Total time: 0 s
  6012. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6013. Function: delete at line 441
  6014. Line # Hits Time Per Hit % Time Line Contents
  6015. ==============================================================
  6016. 441 @dispatch(event="provider.storage.volumes.delete",
  6017. 442 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  6018. 443 @profile
  6019. 444 def delete(self, volume):
  6020. 445 volume = (volume if isinstance(volume, OpenStackVolume)
  6021. 446 else self.get(volume))
  6022. 447 if volume:
  6023. 448 # pylint:disable=protected-access
  6024. 449 volume._volume.delete()
  6025. Total time: 0 s
  6026. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6027. Function: get at line 457
  6028. Line # Hits Time Per Hit % Time Line Contents
  6029. ==============================================================
  6030. 457 @dispatch(event="provider.storage.snapshots.get",
  6031. 458 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  6032. 459 @profile
  6033. 460 def get(self, snapshot_id):
  6034. 461 try:
  6035. 462 return OpenStackSnapshot(
  6036. 463 self.provider,
  6037. 464 self.provider.cinder.volume_snapshots.get(snapshot_id))
  6038. 465 except CinderNotFound:
  6039. 466 log.debug("Snapshot %s was not found.", snapshot_id)
  6040. 467 return None
  6041. Total time: 0 s
  6042. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6043. Function: find at line 469
  6044. Line # Hits Time Per Hit % Time Line Contents
  6045. ==============================================================
  6046. 469 @dispatch(event="provider.storage.snapshots.find",
  6047. 470 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  6048. 471 @profile
  6049. 472 def find(self, **kwargs):
  6050. 473 label = kwargs.pop('label', None)
  6051. 474
  6052. 475 # All kwargs should have been popped at this time.
  6053. 476 if len(kwargs) > 0:
  6054. 477 raise InvalidParamException(
  6055. 478 "Unrecognised parameters for search: %s. Supported "
  6056. 479 "attributes: %s" % (kwargs, 'label'))
  6057. 480
  6058. 481 search_opts = {'name': label, # TODO: Cinder is ignoring name
  6059. 482 'limit': oshelpers.os_result_limit(self.provider),
  6060. 483 'marker': None}
  6061. 484 log.debug("Searching for an OpenStack snapshot with the following "
  6062. 485 "params: %s", search_opts)
  6063. 486 cb_snaps = [
  6064. 487 OpenStackSnapshot(self.provider, snap) for
  6065. 488 snap in self.provider.cinder.volume_snapshots.list(search_opts)
  6066. 489 if snap.name == label]
  6067. 490
  6068. 491 return oshelpers.to_server_paged_list(self.provider, cb_snaps)
  6069. Total time: 0 s
  6070. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6071. Function: list at line 493
  6072. Line # Hits Time Per Hit % Time Line Contents
  6073. ==============================================================
  6074. 493 @dispatch(event="provider.storage.snapshots.list",
  6075. 494 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  6076. 495 @profile
  6077. 496 def list(self, limit=None, marker=None):
  6078. 497 cb_snaps = [
  6079. 498 OpenStackSnapshot(self.provider, snap) for
  6080. 499 snap in self.provider.cinder.volume_snapshots.list(
  6081. 500 search_opts={'limit': oshelpers.os_result_limit(self.provider,
  6082. 501 limit),
  6083. 502 'marker': marker})]
  6084. 503 return oshelpers.to_server_paged_list(self.provider, cb_snaps, limit)
  6085. Total time: 0 s
  6086. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6087. Function: create at line 505
  6088. Line # Hits Time Per Hit % Time Line Contents
  6089. ==============================================================
  6090. 505 @dispatch(event="provider.storage.snapshots.create",
  6091. 506 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  6092. 507 @profile
  6093. 508 def create(self, label, volume, description=None):
  6094. 509 OpenStackSnapshot.assert_valid_resource_label(label)
  6095. 510 volume_id = (volume.id if isinstance(volume, OpenStackVolume)
  6096. 511 else volume)
  6097. 512
  6098. 513 os_snap = self.provider.cinder.volume_snapshots.create(
  6099. 514 volume_id, name=label,
  6100. 515 description=description)
  6101. 516 return OpenStackSnapshot(self.provider, os_snap)
  6102. Total time: 0 s
  6103. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6104. Function: delete at line 518
  6105. Line # Hits Time Per Hit % Time Line Contents
  6106. ==============================================================
  6107. 518 @dispatch(event="provider.storage.snapshots.delete",
  6108. 519 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  6109. 520 @profile
  6110. 521 def delete(self, snapshot):
  6111. 522 s = (snapshot if isinstance(snapshot, OpenStackSnapshot) else
  6112. 523 self.get(snapshot))
  6113. 524 if s:
  6114. 525 # pylint:disable=protected-access
  6115. 526 s._snapshot.delete()
  6116. Total time: 0 s
  6117. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6118. Function: get at line 534
  6119. Line # Hits Time Per Hit % Time Line Contents
  6120. ==============================================================
  6121. 534 @dispatch(event="provider.storage.buckets.get",
  6122. 535 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  6123. 536 @profile
  6124. 537 def get(self, bucket_id):
  6125. 538 """
  6126. 539 Returns a bucket given its ID. Returns ``None`` if the bucket
  6127. 540 does not exist.
  6128. 541 """
  6129. 542 _, container_list = self.provider.swift.get_account(
  6130. 543 prefix=bucket_id)
  6131. 544 if container_list:
  6132. 545 return OpenStackBucket(self.provider,
  6133. 546 next((c for c in container_list
  6134. 547 if c['name'] == bucket_id), None))
  6135. 548 else:
  6136. 549 log.debug("Bucket %s was not found.", bucket_id)
  6137. 550 return None
  6138. Total time: 0 s
  6139. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6140. Function: find at line 552
  6141. Line # Hits Time Per Hit % Time Line Contents
  6142. ==============================================================
  6143. 552 @dispatch(event="provider.storage.buckets.find",
  6144. 553 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  6145. 554 @profile
  6146. 555 def find(self, **kwargs):
  6147. 556 name = kwargs.pop('name', None)
  6148. 557
  6149. 558 # All kwargs should have been popped at this time.
  6150. 559 if len(kwargs) > 0:
  6151. 560 raise InvalidParamException(
  6152. 561 "Unrecognised parameters for search: %s. Supported "
  6153. 562 "attributes: %s" % (kwargs, 'name'))
  6154. 563 _, container_list = self.provider.swift.get_account()
  6155. 564 cb_buckets = [OpenStackBucket(self.provider, c)
  6156. 565 for c in container_list
  6157. 566 if name in c.get("name")]
  6158. 567 return oshelpers.to_server_paged_list(self.provider, cb_buckets)
  6159. Total time: 0 s
  6160. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6161. Function: list at line 569
  6162. Line # Hits Time Per Hit % Time Line Contents
  6163. ==============================================================
  6164. 569 @dispatch(event="provider.storage.buckets.list",
  6165. 570 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  6166. 571 @profile
  6167. 572 def list(self, limit=None, marker=None):
  6168. 573 _, container_list = self.provider.swift.get_account(
  6169. 574 limit=oshelpers.os_result_limit(self.provider, limit),
  6170. 575 marker=marker)
  6171. 576 cb_buckets = [OpenStackBucket(self.provider, c)
  6172. 577 for c in container_list]
  6173. 578 return oshelpers.to_server_paged_list(self.provider, cb_buckets, limit)
  6174. Total time: 0 s
  6175. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6176. Function: create at line 580
  6177. Line # Hits Time Per Hit % Time Line Contents
  6178. ==============================================================
  6179. 580 @dispatch(event="provider.storage.buckets.create",
  6180. 581 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  6181. 582 @profile
  6182. 583 def create(self, name, location=None):
  6183. 584 OpenStackBucket.assert_valid_resource_name(name)
  6184. 585 location = location or self.provider.region_name
  6185. 586 try:
  6186. 587 self.provider.swift.head_container(name)
  6187. 588 raise DuplicateResourceException(
  6188. 589 'Bucket already exists with name {0}'.format(name))
  6189. 590 except SwiftClientException:
  6190. 591 self.provider.swift.put_container(name)
  6191. 592 return self.get(name)
  6192. Total time: 0 s
  6193. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6194. Function: delete at line 594
  6195. Line # Hits Time Per Hit % Time Line Contents
  6196. ==============================================================
  6197. 594 @dispatch(event="provider.storage.buckets.delete",
  6198. 595 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  6199. 596 @profile
  6200. 597 def delete(self, bucket):
  6201. 598 b_id = bucket.id if isinstance(bucket, OpenStackBucket) else bucket
  6202. 599 self.provider.swift.delete_container(b_id)
  6203. Total time: 0 s
  6204. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6205. Function: get at line 607
  6206. Line # Hits Time Per Hit % Time Line Contents
  6207. ==============================================================
  6208. 607 @profile
  6209. 608 def get(self, bucket, name):
  6210. 609 """
  6211. 610 Retrieve a given object from this bucket.
  6212. 611 """
  6213. 612 # Swift always returns a reference for the container first,
  6214. 613 # followed by a list containing references to objects.
  6215. 614 _, object_list = self.provider.swift.get_container(
  6216. 615 bucket.name, prefix=name)
  6217. 616 # Loop through list of objects looking for an exact name vs. a prefix
  6218. 617 for obj in object_list:
  6219. 618 if obj.get('name') == name:
  6220. 619 return OpenStackBucketObject(self.provider,
  6221. 620 bucket,
  6222. 621 obj)
  6223. 622 return None
  6224. Total time: 0 s
  6225. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6226. Function: list at line 624
  6227. Line # Hits Time Per Hit % Time Line Contents
  6228. ==============================================================
  6229. 624 @profile
  6230. 625 def list(self, bucket, limit=None, marker=None, prefix=None):
  6231. 626 """
  6232. 627 List all objects within this bucket.
  6233. 628
  6234. 629 :rtype: BucketObject
  6235. 630 :return: List of all available BucketObjects within this bucket.
  6236. 631 """
  6237. 632 _, object_list = self.provider.swift.get_container(
  6238. 633 bucket.name,
  6239. 634 limit=oshelpers.os_result_limit(self.provider, limit),
  6240. 635 marker=marker, prefix=prefix)
  6241. 636 cb_objects = [OpenStackBucketObject(
  6242. 637 self.provider, bucket, obj) for obj in object_list]
  6243. 638
  6244. 639 return oshelpers.to_server_paged_list(
  6245. 640 self.provider,
  6246. 641 cb_objects,
  6247. 642 limit)
  6248. Total time: 0 s
  6249. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6250. Function: find at line 644
  6251. Line # Hits Time Per Hit % Time Line Contents
  6252. ==============================================================
  6253. 644 @profile
  6254. 645 def find(self, bucket, **kwargs):
  6255. 646 _, obj_list = self.provider.swift.get_container(bucket.name)
  6256. 647 cb_objs = [OpenStackBucketObject(self.provider, bucket, obj)
  6257. 648 for obj in obj_list]
  6258. 649 filters = ['name']
  6259. 650 matches = cb_helpers.generic_find(filters, kwargs, cb_objs)
  6260. 651 return ClientPagedResultList(self.provider, list(matches))
  6261. Total time: 0 s
  6262. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6263. Function: create at line 653
  6264. Line # Hits Time Per Hit % Time Line Contents
  6265. ==============================================================
  6266. 653 @profile
  6267. 654 def create(self, bucket, object_name):
  6268. 655 self.provider.swift.put_object(bucket.name, object_name, None)
  6269. 656 return self.get(bucket, object_name)
  6270. Total time: 0 s
  6271. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6272. Function: get at line 690
  6273. Line # Hits Time Per Hit % Time Line Contents
  6274. ==============================================================
  6275. 690 @profile
  6276. 691 def get(self, image_id):
  6277. 692 """
  6278. 693 Returns an Image given its id
  6279. 694 """
  6280. 695 log.debug("Getting OpenStack Image with the id: %s", image_id)
  6281. 696 try:
  6282. 697 return OpenStackMachineImage(
  6283. 698 self.provider, self.provider.os_conn.image.get_image(image_id))
  6284. 699 except (NotFoundException, ResourceNotFound):
  6285. 700 log.debug("Image %s not found", image_id)
  6286. 701 return None
  6287. Total time: 0 s
  6288. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6289. Function: find at line 703
  6290. Line # Hits Time Per Hit % Time Line Contents
  6291. ==============================================================
  6292. 703 @profile
  6293. 704 def find(self, **kwargs):
  6294. 705 filters = ['label']
  6295. 706 obj_list = self
  6296. 707 return cb_helpers.generic_find(filters, kwargs, obj_list)
  6297. Total time: 0 s
  6298. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6299. Function: list at line 709
  6300. Line # Hits Time Per Hit % Time Line Contents
  6301. ==============================================================
  6302. 709 @profile
  6303. 710 def list(self, filter_by_owner=True, limit=None, marker=None):
  6304. 711 """
  6305. 712 List all images.
  6306. 713 """
  6307. 714 project_id = None
  6308. 715 if filter_by_owner:
  6309. 716 project_id = self.provider.os_conn.session.get_project_id()
  6310. 717 os_images = self.provider.os_conn.image.images(
  6311. 718 owner=project_id,
  6312. 719 limit=oshelpers.os_result_limit(self.provider, limit),
  6313. 720 marker=marker)
  6314. 721
  6315. 722 cb_images = [
  6316. 723 OpenStackMachineImage(self.provider, img)
  6317. 724 for img in os_images]
  6318. 725 return oshelpers.to_server_paged_list(self.provider, cb_images, limit)
  6319. Total time: 0 s
  6320. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6321. Function: create_launch_config at line 783
  6322. Line # Hits Time Per Hit % Time Line Contents
  6323. ==============================================================
  6324. 783 @profile
  6325. 784 def create_launch_config(self):
  6326. 785 return BaseLaunchConfig(self.provider)
  6327. Total time: 0 s
  6328. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6329. Function: create at line 787
  6330. Line # Hits Time Per Hit % Time Line Contents
  6331. ==============================================================
  6332. 787 @dispatch(event="provider.compute.instances.create",
  6333. 788 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  6334. 789 @profile
  6335. 790 def create(self, label, image, vm_type, subnet, zone,
  6336. 791 key_pair=None, vm_firewalls=None, user_data=None,
  6337. 792 launch_config=None, **kwargs):
  6338. 793 OpenStackInstance.assert_valid_resource_label(label)
  6339. 794 image_id = image.id if isinstance(image, MachineImage) else image
  6340. 795 vm_size = vm_type.id if \
  6341. 796 isinstance(vm_type, VMType) else \
  6342. 797 self.provider.compute.vm_types.find(
  6343. 798 name=vm_type)[0].id
  6344. 799 if isinstance(subnet, Subnet):
  6345. 800 subnet_id = subnet.id
  6346. 801 net_id = subnet.network_id
  6347. 802 else:
  6348. 803 subnet_id = subnet
  6349. 804 net_id = (self.provider.networking.subnets
  6350. 805 .get(subnet_id).network_id
  6351. 806 if subnet_id else None)
  6352. 807 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  6353. 808 key_pair_name = key_pair.name if \
  6354. 809 isinstance(key_pair, KeyPair) else key_pair
  6355. 810 bdm = None
  6356. 811 if launch_config:
  6357. 812 bdm = self._to_block_device_mapping(launch_config)
  6358. 813
  6359. 814 # Security groups must be passed in as a list of IDs and attached to a
  6360. 815 # port if a port is being created. Otherwise, the security groups must
  6361. 816 # be passed in as a list of names to the servers.create() call.
  6362. 817 # OpenStack will respect the port's security groups first and then
  6363. 818 # fall-back to the named security groups.
  6364. 819 sg_name_list = []
  6365. 820 nics = None
  6366. 821 if subnet_id:
  6367. 822 log.debug("Creating network port for %s in subnet: %s",
  6368. 823 label, subnet_id)
  6369. 824 sg_list = []
  6370. 825 if vm_firewalls:
  6371. 826 if isinstance(vm_firewalls, list) and \
  6372. 827 isinstance(vm_firewalls[0], VMFirewall):
  6373. 828 sg_list = vm_firewalls
  6374. 829 else:
  6375. 830 sg_list = (self.provider.security.vm_firewalls
  6376. 831 .find(label=sg) for sg in vm_firewalls)
  6377. 832 sg_list = (sg[0] for sg in sg_list if sg)
  6378. 833 sg_id_list = [sg.id for sg in sg_list]
  6379. 834 port_def = {
  6380. 835 "port": {
  6381. 836 "admin_state_up": True,
  6382. 837 "name": OpenStackInstance._generate_name_from_label(
  6383. 838 label, 'cb-port'),
  6384. 839 "network_id": net_id,
  6385. 840 "fixed_ips": [{"subnet_id": subnet_id}],
  6386. 841 "security_groups": sg_id_list
  6387. 842 }
  6388. 843 }
  6389. 844 port_id = self.provider.neutron.create_port(port_def)['port']['id']
  6390. 845 nics = [{'net-id': net_id, 'port-id': port_id}]
  6391. 846 else:
  6392. 847 if vm_firewalls:
  6393. 848 if isinstance(vm_firewalls, list) and \
  6394. 849 isinstance(vm_firewalls[0], VMFirewall):
  6395. 850 sg_name_list = [sg.name for sg in vm_firewalls]
  6396. 851 else:
  6397. 852 sg_list = (self.provider.security.vm_firewalls.get(sg)
  6398. 853 for sg in vm_firewalls)
  6399. 854 sg_name_list = (sg[0].name for sg in sg_list if sg)
  6400. 855
  6401. 856 log.debug("Launching in subnet %s", subnet_id)
  6402. 857 os_instance = self.provider.nova.servers.create(
  6403. 858 label,
  6404. 859 None if self._has_root_device(launch_config) else image_id,
  6405. 860 vm_size,
  6406. 861 min_count=1,
  6407. 862 max_count=1,
  6408. 863 availability_zone=zone_id,
  6409. 864 key_name=key_pair_name,
  6410. 865 security_groups=sg_name_list,
  6411. 866 userdata=str(user_data) or None,
  6412. 867 block_device_mapping_v2=bdm,
  6413. 868 nics=nics)
  6414. 869 return OpenStackInstance(self.provider, os_instance)
  6415. Total time: 0 s
  6416. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6417. Function: find at line 871
  6418. Line # Hits Time Per Hit % Time Line Contents
  6419. ==============================================================
  6420. 871 @dispatch(event="provider.compute.instances.find",
  6421. 872 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  6422. 873 @profile
  6423. 874 def find(self, **kwargs):
  6424. 875 label = kwargs.pop('label', None)
  6425. 876
  6426. 877 # All kwargs should have been popped at this time.
  6427. 878 if len(kwargs) > 0:
  6428. 879 raise InvalidParamException(
  6429. 880 "Unrecognised parameters for search: %s. Supported "
  6430. 881 "attributes: %s" % (kwargs, 'label'))
  6431. 882
  6432. 883 search_opts = {'name': label}
  6433. 884 cb_insts = [
  6434. 885 OpenStackInstance(self.provider, inst)
  6435. 886 for inst in self.provider.nova.servers.list(
  6436. 887 search_opts=search_opts,
  6437. 888 limit=oshelpers.os_result_limit(self.provider),
  6438. 889 marker=None)]
  6439. 890 return oshelpers.to_server_paged_list(self.provider, cb_insts)
  6440. Total time: 0 s
  6441. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6442. Function: list at line 892
  6443. Line # Hits Time Per Hit % Time Line Contents
  6444. ==============================================================
  6445. 892 @dispatch(event="provider.compute.instances.list",
  6446. 893 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  6447. 894 @profile
  6448. 895 def list(self, limit=None, marker=None):
  6449. 896 """
  6450. 897 List all instances.
  6451. 898 """
  6452. 899 cb_insts = [
  6453. 900 OpenStackInstance(self.provider, inst)
  6454. 901 for inst in self.provider.nova.servers.list(
  6455. 902 limit=oshelpers.os_result_limit(self.provider, limit),
  6456. 903 marker=marker)]
  6457. 904 return oshelpers.to_server_paged_list(self.provider, cb_insts, limit)
  6458. Total time: 0 s
  6459. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6460. Function: get at line 906
  6461. Line # Hits Time Per Hit % Time Line Contents
  6462. ==============================================================
  6463. 906 @dispatch(event="provider.compute.instances.get",
  6464. 907 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  6465. 908 @profile
  6466. 909 def get(self, instance_id):
  6467. 910 """
  6468. 911 Returns an instance given its id.
  6469. 912 """
  6470. 913 try:
  6471. 914 os_instance = self.provider.nova.servers.get(instance_id)
  6472. 915 return OpenStackInstance(self.provider, os_instance)
  6473. 916 except NovaNotFound:
  6474. 917 log.debug("Instance %s was not found.", instance_id)
  6475. 918 return None
  6476. Total time: 0 s
  6477. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6478. Function: delete at line 920
  6479. Line # Hits Time Per Hit % Time Line Contents
  6480. ==============================================================
  6481. 920 @dispatch(event="provider.compute.instances.delete",
  6482. 921 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  6483. 922 @profile
  6484. 923 def delete(self, instance):
  6485. 924 ins = (instance if isinstance(instance, OpenStackInstance) else
  6486. 925 self.get(instance))
  6487. 926 if ins:
  6488. 927 # pylint:disable=protected-access
  6489. 928 os_instance = ins._os_instance
  6490. 929 # delete the port we created when launching
  6491. 930 # Assumption: it's the first interface in the list
  6492. 931 iface_list = os_instance.interface_list()
  6493. 932 if iface_list:
  6494. 933 self.provider.neutron.delete_port(iface_list[0].port_id)
  6495. 934 os_instance.delete()
  6496. Total time: 0 s
  6497. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6498. Function: list at line 942
  6499. Line # Hits Time Per Hit % Time Line Contents
  6500. ==============================================================
  6501. 942 @dispatch(event="provider.compute.vm_types.list",
  6502. 943 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  6503. 944 @profile
  6504. 945 def list(self, limit=None, marker=None):
  6505. 946 cb_itypes = [
  6506. 947 OpenStackVMType(self.provider, obj)
  6507. 948 for obj in self.provider.nova.flavors.list(
  6508. 949 limit=oshelpers.os_result_limit(self.provider, limit),
  6509. 950 marker=marker)]
  6510. 951
  6511. 952 return oshelpers.to_server_paged_list(self.provider, cb_itypes, limit)
  6512. Total time: 0 s
  6513. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6514. Function: get at line 960
  6515. Line # Hits Time Per Hit % Time Line Contents
  6516. ==============================================================
  6517. 960 @dispatch(event="provider.compute.regions.get",
  6518. 961 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  6519. 962 @profile
  6520. 963 def get(self, region_id):
  6521. 964 log.debug("Getting OpenStack Region with the id: %s", region_id)
  6522. 965 region = (r for r in self if r.id == region_id)
  6523. 966 return next(region, None)
  6524. Total time: 0 s
  6525. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6526. Function: list at line 968
  6527. Line # Hits Time Per Hit % Time Line Contents
  6528. ==============================================================
  6529. 968 @dispatch(event="provider.compute.regions.list",
  6530. 969 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  6531. 970 @profile
  6532. 971 def list(self, limit=None, marker=None):
  6533. 972 # pylint:disable=protected-access
  6534. 973 if self.provider._keystone_version == 3:
  6535. 974 os_regions = [OpenStackRegion(self.provider, region)
  6536. 975 for region in self.provider.keystone.regions.list()]
  6537. 976 return ClientPagedResultList(self.provider, os_regions,
  6538. 977 limit=limit, marker=marker)
  6539. 978 else:
  6540. 979 # Keystone v3 onwards supports directly listing regions
  6541. 980 # but for v2, this convoluted method is necessary.
  6542. 981 regions = (
  6543. 982 endpoint.get('region') or endpoint.get('region_id')
  6544. 983 for svc in self.provider.keystone.service_catalog.get_data()
  6545. 984 for endpoint in svc.get('endpoints', [])
  6546. 985 )
  6547. 986 regions = set(region for region in regions if region)
  6548. 987 os_regions = [OpenStackRegion(self.provider, region)
  6549. 988 for region in regions]
  6550. 989
  6551. 990 return ClientPagedResultList(self.provider, os_regions,
  6552. 991 limit=limit, marker=marker)
  6553. Total time: 0 s
  6554. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6555. Function: get at line 1035
  6556. Line # Hits Time Per Hit % Time Line Contents
  6557. ==============================================================
  6558. 1035 @dispatch(event="provider.networking.networks.get",
  6559. 1036 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  6560. 1037 @profile
  6561. 1038 def get(self, network_id):
  6562. 1039 network = (n for n in self if n.id == network_id)
  6563. 1040 return next(network, None)
  6564. Total time: 0 s
  6565. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6566. Function: list at line 1042
  6567. Line # Hits Time Per Hit % Time Line Contents
  6568. ==============================================================
  6569. 1042 @dispatch(event="provider.networking.networks.list",
  6570. 1043 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  6571. 1044 @profile
  6572. 1045 def list(self, limit=None, marker=None):
  6573. 1046 networks = [OpenStackNetwork(self.provider, network)
  6574. 1047 for network in self.provider.neutron.list_networks()
  6575. 1048 .get('networks') if network]
  6576. 1049 return ClientPagedResultList(self.provider, networks,
  6577. 1050 limit=limit, marker=marker)
  6578. Total time: 0 s
  6579. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6580. Function: find at line 1052
  6581. Line # Hits Time Per Hit % Time Line Contents
  6582. ==============================================================
  6583. 1052 @dispatch(event="provider.networking.networks.find",
  6584. 1053 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  6585. 1054 @profile
  6586. 1055 def find(self, **kwargs):
  6587. 1056 label = kwargs.pop('label', None)
  6588. 1057
  6589. 1058 # All kwargs should have been popped at this time.
  6590. 1059 if len(kwargs) > 0:
  6591. 1060 raise InvalidParamException(
  6592. 1061 "Unrecognised parameters for search: %s. Supported "
  6593. 1062 "attributes: %s" % (kwargs, 'label'))
  6594. 1063
  6595. 1064 log.debug("Searching for OpenStack Network with label: %s", label)
  6596. 1065 networks = [OpenStackNetwork(self.provider, network)
  6597. 1066 for network in self.provider.neutron.list_networks(
  6598. 1067 name=label)
  6599. 1068 .get('networks') if network]
  6600. 1069 return ClientPagedResultList(self.provider, networks)
  6601. Total time: 0 s
  6602. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6603. Function: create at line 1071
  6604. Line # Hits Time Per Hit % Time Line Contents
  6605. ==============================================================
  6606. 1071 @dispatch(event="provider.networking.networks.create",
  6607. 1072 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  6608. 1073 @profile
  6609. 1074 def create(self, label, cidr_block):
  6610. 1075 OpenStackNetwork.assert_valid_resource_label(label)
  6611. 1076 net_info = {'name': label or ""}
  6612. 1077 network = self.provider.neutron.create_network({'network': net_info})
  6613. 1078 cb_net = OpenStackNetwork(self.provider, network.get('network'))
  6614. 1079 if label:
  6615. 1080 cb_net.label = label
  6616. 1081 return cb_net
  6617. Total time: 0 s
  6618. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6619. Function: delete at line 1083
  6620. Line # Hits Time Per Hit % Time Line Contents
  6621. ==============================================================
  6622. 1083 @dispatch(event="provider.networking.networks.delete",
  6623. 1084 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  6624. 1085 @profile
  6625. 1086 def delete(self, network):
  6626. 1087 network = (network if isinstance(network, OpenStackNetwork) else
  6627. 1088 self.get(network))
  6628. 1089 if not network:
  6629. 1090 return
  6630. 1091 if not network.external and network.id in str(
  6631. 1092 self.provider.neutron.list_networks()):
  6632. 1093 # If there are ports associated with the network, it won't delete
  6633. 1094 ports = self.provider.neutron.list_ports(
  6634. 1095 network_id=network.id).get('ports', [])
  6635. 1096 for port in ports:
  6636. 1097 try:
  6637. 1098 self.provider.neutron.delete_port(port.get('id'))
  6638. 1099 except PortNotFoundClient:
  6639. 1100 # Ports could have already been deleted if instances
  6640. 1101 # are terminated etc. so exceptions can be safely ignored
  6641. 1102 pass
  6642. 1103 self.provider.neutron.delete_network(network.id)
  6643. Total time: 0 s
  6644. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6645. Function: get at line 1111
  6646. Line # Hits Time Per Hit % Time Line Contents
  6647. ==============================================================
  6648. 1111 @dispatch(event="provider.networking.subnets.get",
  6649. 1112 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  6650. 1113 @profile
  6651. 1114 def get(self, subnet_id):
  6652. 1115 subnet = (s for s in self if s.id == subnet_id)
  6653. 1116 return next(subnet, None)
  6654. Total time: 0 s
  6655. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6656. Function: list at line 1118
  6657. Line # Hits Time Per Hit % Time Line Contents
  6658. ==============================================================
  6659. 1118 @dispatch(event="provider.networking.subnets.list",
  6660. 1119 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  6661. 1120 @profile
  6662. 1121 def list(self, network=None, limit=None, marker=None):
  6663. 1122 if network:
  6664. 1123 network_id = (network.id if isinstance(network, OpenStackNetwork)
  6665. 1124 else network)
  6666. 1125 subnets = [subnet for subnet in self if network_id ==
  6667. 1126 subnet.network_id]
  6668. 1127 else:
  6669. 1128 subnets = [OpenStackSubnet(self.provider, subnet) for subnet in
  6670. 1129 self.provider.neutron.list_subnets().get('subnets', [])]
  6671. 1130 return ClientPagedResultList(self.provider, subnets,
  6672. 1131 limit=limit, marker=marker)
  6673. Total time: 0 s
  6674. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6675. Function: create at line 1133
  6676. Line # Hits Time Per Hit % Time Line Contents
  6677. ==============================================================
  6678. 1133 @dispatch(event="provider.networking.subnets.create",
  6679. 1134 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  6680. 1135 @profile
  6681. 1136 def create(self, label, network, cidr_block, zone):
  6682. 1137 """zone param is ignored."""
  6683. 1138 OpenStackSubnet.assert_valid_resource_label(label)
  6684. 1139 network_id = (network.id if isinstance(network, OpenStackNetwork)
  6685. 1140 else network)
  6686. 1141 subnet_info = {'name': label, 'network_id': network_id,
  6687. 1142 'cidr': cidr_block, 'ip_version': 4}
  6688. 1143 subnet = (self.provider.neutron.create_subnet({'subnet': subnet_info})
  6689. 1144 .get('subnet'))
  6690. 1145 cb_subnet = OpenStackSubnet(self.provider, subnet)
  6691. 1146 return cb_subnet
  6692. Total time: 0 s
  6693. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6694. Function: delete at line 1148
  6695. Line # Hits Time Per Hit % Time Line Contents
  6696. ==============================================================
  6697. 1148 @dispatch(event="provider.networking.subnets.delete",
  6698. 1149 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  6699. 1150 @profile
  6700. 1151 def delete(self, subnet):
  6701. 1152 sn_id = subnet.id if isinstance(subnet, OpenStackSubnet) else subnet
  6702. 1153 self.provider.neutron.delete_subnet(sn_id)
  6703. Total time: 0 s
  6704. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6705. Function: get_or_create_default at line 1155
  6706. Line # Hits Time Per Hit % Time Line Contents
  6707. ==============================================================
  6708. 1155 @profile
  6709. 1156 def get_or_create_default(self, zone):
  6710. 1157 """
  6711. 1158 Subnet zone is not supported by OpenStack and is thus ignored.
  6712. 1159 """
  6713. 1160 try:
  6714. 1161 sn = self.find(label=OpenStackSubnet.CB_DEFAULT_SUBNET_LABEL)
  6715. 1162 if sn:
  6716. 1163 return sn[0]
  6717. 1164 # No default subnet look for default network, then create subnet
  6718. 1165 net = self.provider.networking.networks.get_or_create_default()
  6719. 1166 sn = self.provider.networking.subnets.create(
  6720. 1167 label=OpenStackSubnet.CB_DEFAULT_SUBNET_LABEL,
  6721. 1168 cidr_block=OpenStackSubnet.CB_DEFAULT_SUBNET_IPV4RANGE,
  6722. 1169 network=net, zone=zone)
  6723. 1170 router = self.provider.networking.routers.get_or_create_default(
  6724. 1171 net)
  6725. 1172 router.attach_subnet(sn)
  6726. 1173 gateway = net.gateways.get_or_create()
  6727. 1174 router.attach_gateway(gateway)
  6728. 1175 return sn
  6729. 1176 except NeutronClientException:
  6730. 1177 return None
  6731. Total time: 0 s
  6732. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6733. Function: get at line 1185
  6734. Line # Hits Time Per Hit % Time Line Contents
  6735. ==============================================================
  6736. 1185 @dispatch(event="provider.networking.routers.get",
  6737. 1186 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  6738. 1187 @profile
  6739. 1188 def get(self, router_id):
  6740. 1189 log.debug("Getting OpenStack Router with the id: %s", router_id)
  6741. 1190 router = self.provider.os_conn.get_router(router_id)
  6742. 1191 return OpenStackRouter(self.provider, router) if router else None
  6743. Total time: 0 s
  6744. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6745. Function: list at line 1193
  6746. Line # Hits Time Per Hit % Time Line Contents
  6747. ==============================================================
  6748. 1193 @dispatch(event="provider.networking.routers.list",
  6749. 1194 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  6750. 1195 @profile
  6751. 1196 def list(self, limit=None, marker=None):
  6752. 1197 routers = self.provider.os_conn.list_routers()
  6753. 1198 os_routers = [OpenStackRouter(self.provider, r) for r in routers]
  6754. 1199 return ClientPagedResultList(self.provider, os_routers, limit=limit,
  6755. 1200 marker=marker)
  6756. Total time: 0 s
  6757. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6758. Function: find at line 1202
  6759. Line # Hits Time Per Hit % Time Line Contents
  6760. ==============================================================
  6761. 1202 @dispatch(event="provider.networking.routers.find",
  6762. 1203 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  6763. 1204 @profile
  6764. 1205 def find(self, **kwargs):
  6765. 1206 obj_list = self
  6766. 1207 filters = ['label']
  6767. 1208 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  6768. 1209 return ClientPagedResultList(self._provider, list(matches))
  6769. Total time: 0 s
  6770. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6771. Function: create at line 1211
  6772. Line # Hits Time Per Hit % Time Line Contents
  6773. ==============================================================
  6774. 1211 @dispatch(event="provider.networking.routers.create",
  6775. 1212 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  6776. 1213 @profile
  6777. 1214 def create(self, label, network):
  6778. 1215 """Parameter ``network`` is not used by OpenStack."""
  6779. 1216 router = self.provider.os_conn.create_router(name=label)
  6780. 1217 return OpenStackRouter(self.provider, router)
  6781. Total time: 0 s
  6782. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6783. Function: delete at line 1219
  6784. Line # Hits Time Per Hit % Time Line Contents
  6785. ==============================================================
  6786. 1219 @dispatch(event="provider.networking.routers.delete",
  6787. 1220 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  6788. 1221 @profile
  6789. 1222 def delete(self, router):
  6790. 1223 r_id = router.id if isinstance(router, OpenStackRouter) else router
  6791. 1224 self.provider.os_conn.delete_router(r_id)
  6792. Total time: 0 s
  6793. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6794. Function: get_or_create at line 1249
  6795. Line # Hits Time Per Hit % Time Line Contents
  6796. ==============================================================
  6797. 1249 @dispatch(event="provider.networking.gateways.get_or_create",
  6798. 1250 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  6799. 1251 @profile
  6800. 1252 def get_or_create(self, network):
  6801. 1253 """For OS, inet gtw is any net that has `external` property set."""
  6802. 1254 external_nets = (n for n in self._provider.networking.networks
  6803. 1255 if n.external)
  6804. 1256 for net in external_nets:
  6805. 1257 if self._check_fip_connectivity(network, net):
  6806. 1258 return OpenStackInternetGateway(self._provider, net)
  6807. 1259 return None
  6808. Total time: 0 s
  6809. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6810. Function: delete at line 1261
  6811. Line # Hits Time Per Hit % Time Line Contents
  6812. ==============================================================
  6813. 1261 @dispatch(event="provider.networking.gateways.delete",
  6814. 1262 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  6815. 1263 @profile
  6816. 1264 def delete(self, network, gateway):
  6817. 1265 pass
  6818. Total time: 0 s
  6819. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6820. Function: list at line 1267
  6821. Line # Hits Time Per Hit % Time Line Contents
  6822. ==============================================================
  6823. 1267 @dispatch(event="provider.networking.gateways.list",
  6824. 1268 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  6825. 1269 @profile
  6826. 1270 def list(self, network, limit=None, marker=None):
  6827. 1271 log.debug("OpenStack listing of all current internet gateways")
  6828. 1272 igl = [OpenStackInternetGateway(self._provider, n)
  6829. 1273 for n in self._provider.networking.networks
  6830. 1274 if n.external and self._check_fip_connectivity(network, n)]
  6831. 1275 return ClientPagedResultList(self._provider, igl, limit=limit,
  6832. 1276 marker=marker)
  6833. Total time: 0 s
  6834. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6835. Function: get at line 1284
  6836. Line # Hits Time Per Hit % Time Line Contents
  6837. ==============================================================
  6838. 1284 @dispatch(event="provider.networking.floating_ips.get",
  6839. 1285 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  6840. 1286 @profile
  6841. 1287 def get(self, gateway, fip_id):
  6842. 1288 try:
  6843. 1289 return OpenStackFloatingIP(
  6844. 1290 self.provider,
  6845. 1291 self.provider.os_conn.network.get_ip(fip_id))
  6846. 1292 except (ResourceNotFound, NotFoundException):
  6847. 1293 log.debug("Floating IP %s not found.", fip_id)
  6848. 1294 return None
  6849. Total time: 0 s
  6850. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6851. Function: list at line 1296
  6852. Line # Hits Time Per Hit % Time Line Contents
  6853. ==============================================================
  6854. 1296 @dispatch(event="provider.networking.floating_ips.list",
  6855. 1297 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  6856. 1298 @profile
  6857. 1299 def list(self, gateway, limit=None, marker=None):
  6858. 1300 fips = [OpenStackFloatingIP(self.provider, fip)
  6859. 1301 for fip in self.provider.os_conn.network.ips(
  6860. 1302 floating_network_id=gateway.id
  6861. 1303 )]
  6862. 1304 return ClientPagedResultList(self.provider, fips,
  6863. 1305 limit=limit, marker=marker)
  6864. Total time: 0 s
  6865. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6866. Function: create at line 1307
  6867. Line # Hits Time Per Hit % Time Line Contents
  6868. ==============================================================
  6869. 1307 @dispatch(event="provider.networking.floating_ips.create",
  6870. 1308 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  6871. 1309 @profile
  6872. 1310 def create(self, gateway):
  6873. 1311 return OpenStackFloatingIP(
  6874. 1312 self.provider, self.provider.os_conn.network.create_ip(
  6875. 1313 floating_network_id=gateway.id))
  6876. Total time: 0 s
  6877. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6878. Function: delete at line 1315
  6879. Line # Hits Time Per Hit % Time Line Contents
  6880. ==============================================================
  6881. 1315 @dispatch(event="provider.networking.floating_ips.delete",
  6882. 1316 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  6883. 1317 @profile
  6884. 1318 def delete(self, gateway, fip):
  6885. 1319 if isinstance(fip, OpenStackFloatingIP):
  6886. 1320 # pylint:disable=protected-access
  6887. 1321 os_ip = fip._ip
  6888. 1322 else:
  6889. 1323 try:
  6890. 1324 os_ip = self.provider.os_conn.network.get_ip(fip)
  6891. 1325 except (ResourceNotFound, NotFoundException):
  6892. 1326 log.debug("Floating IP %s not found.", fip)
  6893. 1327 return True
  6894. 1328 os_ip.delete(self._provider.os_conn.session)