azure-compute.res 546 KB

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