openstack-compute.res 554 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700
  1. cloudbridge.test.test_compute_service.CloudComputeServiceTestCase
  2. Error during cleanup: CloudBridgeBaseException: Unable to complete operation on subnet 0b8a4758-2741-4893-a281-c1800b2c5998: One or more ports have an IP allocation from this subnet.
  3. Neutron server returns request_ids: ['req-069e73eb-05f5-4458-b0f6-c91bc62e6446'] from exception type: <class 'neutronclient.common.exceptions.Conflict'>
  4. Error during cleanup: CloudBridgeBaseException: ConflictException: 409: Client Error for url: http://130.56.249.49:9696/v2.0/security-groups/f1d2ea25-5850-4b1f-8789-34cdf4ae2da4, {"NeutronError": {"message": "Security Group f1d2ea25-5850-4b1f-8789-34cdf4ae2da4 in use.", "type": "SecurityGroupInUse", "detail": ""}} from exception type: <class 'openstack.exceptions.ConflictException'>
  5. Test output
  6. s.EEE.
  7. ======================================================================
  8. ERROR: test_crud_instance (cloudbridge.test.test_compute_service.CloudComputeServiceTestCase)
  9. ----------------------------------------------------------------------
  10. Traceback (most recent call last):
  11. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 45, in wrap_exception
  12. return next_handler.invoke(event_args, *args, **kwargs)
  13. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 110, in invoke
  14. result = self.callback(*args, **kwargs)
  15. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/line_profiler.py", line 115, in wrapper
  16. result = func(*args, **kwds)
  17. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py", line 868, in create
  18. nics=nics)
  19. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/v2/servers.py", line 1327, in create
  20. return self._boot(response_key, *boot_args, **boot_kwargs)
  21. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/v2/servers.py", line 776, in _boot
  22. return_raw=return_raw, **kwargs)
  23. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/base.py", line 366, in _create
  24. resp, body = self.api.client.post(url, body=body)
  25. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/keystoneauth1/adapter.py", line 357, in post
  26. return self.request(url, 'POST', **kwargs)
  27. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/client.py", line 83, in request
  28. raise exceptions.from_response(resp, body, url, method)
  29. novaclient.exceptions.BadRequest: Can not find requested image (HTTP 400) (Request-ID: req-abda1555-9666-43cc-85d9-f5fe92697d32)
  30. The above exception was the direct cause of the following exception:
  31. Traceback (most recent call last):
  32. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 41, in wrapper
  33. func(self, *args, **kwargs)
  34. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/test_compute_service.py", line 74, in test_crud_instance
  35. custom_check_delete=check_deleted)
  36. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/standard_interface_tests.py", line 339, in check_crud
  37. obj = create_func(label)
  38. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/test_compute_service.py", line 47, in create_inst
  39. subnet=subnet, user_data={})
  40. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 207, in get_test_instance
  41. user_data=user_data)
  42. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 192, in create_test_instance
  43. user_data=user_data)
  44. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/middleware.py", line 74, in wrapper
  45. return dispatcher.dispatch(self, event, *args, **kwargs)
  46. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 218, in dispatch
  47. return handlers[0].invoke(event_args, *args, **kwargs)
  48. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 78, in invoke
  49. result = self.callback(event_args, *args, **kwargs)
  50. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 55, in wrap_exception
  51. six.raise_from(cb_ex, e)
  52. File "<string>", line 3, in raise_from
  53. cloudbridge.cloud.interfaces.exceptions.CloudBridgeBaseException: CloudBridgeBaseException: Can not find requested image (HTTP 400) (Request-ID: req-abda1555-9666-43cc-85d9-f5fe92697d32) from exception type: <class 'novaclient.exceptions.BadRequest'>
  54. ======================================================================
  55. ERROR: test_instance_methods (cloudbridge.test.test_compute_service.CloudComputeServiceTestCase)
  56. ----------------------------------------------------------------------
  57. Traceback (most recent call last):
  58. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 45, in wrap_exception
  59. return next_handler.invoke(event_args, *args, **kwargs)
  60. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 110, in invoke
  61. result = self.callback(*args, **kwargs)
  62. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/line_profiler.py", line 115, in wrapper
  63. result = func(*args, **kwds)
  64. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py", line 868, in create
  65. nics=nics)
  66. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/v2/servers.py", line 1327, in create
  67. return self._boot(response_key, *boot_args, **boot_kwargs)
  68. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/v2/servers.py", line 776, in _boot
  69. return_raw=return_raw, **kwargs)
  70. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/base.py", line 366, in _create
  71. resp, body = self.api.client.post(url, body=body)
  72. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/keystoneauth1/adapter.py", line 357, in post
  73. return self.request(url, 'POST', **kwargs)
  74. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/client.py", line 83, in request
  75. raise exceptions.from_response(resp, body, url, method)
  76. novaclient.exceptions.BadRequest: Can not find requested image (HTTP 400) (Request-ID: req-74b2f0be-3720-46c7-b73a-93756e6f272f)
  77. The above exception was the direct cause of the following exception:
  78. Traceback (most recent call last):
  79. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 41, in wrapper
  80. func(self, *args, **kwargs)
  81. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/test_compute_service.py", line 340, in test_instance_methods
  82. subnet=subnet)
  83. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 207, in get_test_instance
  84. user_data=user_data)
  85. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 192, in create_test_instance
  86. user_data=user_data)
  87. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/middleware.py", line 74, in wrapper
  88. return dispatcher.dispatch(self, event, *args, **kwargs)
  89. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 218, in dispatch
  90. return handlers[0].invoke(event_args, *args, **kwargs)
  91. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 78, in invoke
  92. result = self.callback(event_args, *args, **kwargs)
  93. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 55, in wrap_exception
  94. six.raise_from(cb_ex, e)
  95. File "<string>", line 3, in raise_from
  96. cloudbridge.cloud.interfaces.exceptions.CloudBridgeBaseException: CloudBridgeBaseException: Can not find requested image (HTTP 400) (Request-ID: req-74b2f0be-3720-46c7-b73a-93756e6f272f) from exception type: <class 'novaclient.exceptions.BadRequest'>
  97. ======================================================================
  98. ERROR: test_instance_properties (cloudbridge.test.test_compute_service.CloudComputeServiceTestCase)
  99. ----------------------------------------------------------------------
  100. Traceback (most recent call last):
  101. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 45, in wrap_exception
  102. return next_handler.invoke(event_args, *args, **kwargs)
  103. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 110, in invoke
  104. result = self.callback(*args, **kwargs)
  105. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/line_profiler.py", line 115, in wrapper
  106. result = func(*args, **kwds)
  107. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py", line 868, in create
  108. nics=nics)
  109. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/v2/servers.py", line 1327, in create
  110. return self._boot(response_key, *boot_args, **boot_kwargs)
  111. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/v2/servers.py", line 776, in _boot
  112. return_raw=return_raw, **kwargs)
  113. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/base.py", line 366, in _create
  114. resp, body = self.api.client.post(url, body=body)
  115. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/keystoneauth1/adapter.py", line 357, in post
  116. return self.request(url, 'POST', **kwargs)
  117. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/novaclient/client.py", line 83, in request
  118. raise exceptions.from_response(resp, body, url, method)
  119. novaclient.exceptions.BadRequest: Can not find requested image (HTTP 400) (Request-ID: req-651d0ec1-307c-4760-a55e-aaeeaa505bcd)
  120. The above exception was the direct cause of the following exception:
  121. Traceback (most recent call last):
  122. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 41, in wrapper
  123. func(self, *args, **kwargs)
  124. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/test_compute_service.py", line 104, in test_instance_properties
  125. subnet=subnet)
  126. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 207, in get_test_instance
  127. user_data=user_data)
  128. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/test/helpers/__init__.py", line 192, in create_test_instance
  129. user_data=user_data)
  130. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/middleware.py", line 74, in wrapper
  131. return dispatcher.dispatch(self, event, *args, **kwargs)
  132. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 218, in dispatch
  133. return handlers[0].invoke(event_args, *args, **kwargs)
  134. File "/Users/alex/Desktop/work/line/lib/python3.6/site-packages/pyeventsystem/events.py", line 78, in invoke
  135. result = self.callback(event_args, *args, **kwargs)
  136. File "/Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/middleware.py", line 55, in wrap_exception
  137. six.raise_from(cb_ex, e)
  138. File "<string>", line 3, in raise_from
  139. cloudbridge.cloud.interfaces.exceptions.CloudBridgeBaseException: CloudBridgeBaseException: Can not find requested image (HTTP 400) (Request-ID: req-651d0ec1-307c-4760-a55e-aaeeaa505bcd) from exception type: <class 'novaclient.exceptions.BadRequest'>
  140. ----------------------------------------------------------------------
  141. Ran 6 tests in 41.244s
  142. FAILED (errors=3, skipped=1)
  143. Wrote profile results to run_single.py.lprof
  144. Timer unit: 1e-06 s
  145. Total time: 0 s
  146. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  147. Function: find at line 81
  148. Line # Hits Time Per Hit % Time Line Contents
  149. ==============================================================
  150. 81 @dispatch(event="provider.security.vm_firewalls.find",
  151. 82 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  152. 83 @profile
  153. 84 def find(self, **kwargs):
  154. 85 obj_list = self
  155. 86 filters = ['label']
  156. 87 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  157. 88
  158. 89 # All kwargs should have been popped at this time.
  159. 90 if len(kwargs) > 0:
  160. 91 raise InvalidParamException(
  161. 92 "Unrecognised parameters for search: %s. Supported "
  162. 93 "attributes: %s" % (kwargs, ", ".join(filters)))
  163. 94
  164. 95 return ClientPagedResultList(self.provider,
  165. 96 matches if matches else [])
  166. Total time: 0 s
  167. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  168. Function: get at line 111
  169. Line # Hits Time Per Hit % Time Line Contents
  170. ==============================================================
  171. 111 @dispatch(event="provider.security.vm_firewall_rules.get",
  172. 112 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  173. 113 @profile
  174. 114 def get(self, firewall, rule_id):
  175. 115 matches = [rule for rule in firewall.rules if rule.id == rule_id]
  176. 116 if matches:
  177. 117 return matches[0]
  178. 118 else:
  179. 119 return None
  180. Total time: 0 s
  181. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  182. Function: find at line 121
  183. Line # Hits Time Per Hit % Time Line Contents
  184. ==============================================================
  185. 121 @dispatch(event="provider.security.vm_firewall_rules.find",
  186. 122 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  187. 123 @profile
  188. 124 def find(self, firewall, **kwargs):
  189. 125 obj_list = firewall.rules
  190. 126 filters = ['name', 'direction', 'protocol', 'from_port', 'to_port',
  191. 127 'cidr', 'src_dest_fw', 'src_dest_fw_id']
  192. 128 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  193. 129 return ClientPagedResultList(self._provider, list(matches))
  194. Total time: 0 s
  195. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  196. Function: find at line 163
  197. Line # Hits Time Per Hit % Time Line Contents
  198. ==============================================================
  199. 163 @dispatch(event="provider.storage.buckets.find",
  200. 164 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  201. 165 @profile
  202. 166 def find(self, **kwargs):
  203. 167 obj_list = self
  204. 168 filters = ['name']
  205. 169 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  206. 170
  207. 171 # All kwargs should have been popped at this time.
  208. 172 if len(kwargs) > 0:
  209. 173 raise InvalidParamException(
  210. 174 "Unrecognised parameters for search: %s. Supported "
  211. 175 "attributes: %s" % (kwargs, ", ".join(filters)))
  212. 176
  213. 177 return ClientPagedResultList(self.provider,
  214. 178 matches if matches else [])
  215. Total time: 0 s
  216. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  217. Function: get at line 218
  218. Line # Hits Time Per Hit % Time Line Contents
  219. ==============================================================
  220. 218 @dispatch(event="provider.compute.vm_types.get",
  221. 219 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  222. 220 @profile
  223. 221 def get(self, vm_type_id):
  224. 222 vm_type = (t for t in self if t.id == vm_type_id)
  225. 223 return next(vm_type, None)
  226. Total time: 9.72766 s
  227. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  228. Function: find at line 225
  229. Line # Hits Time Per Hit % Time Line Contents
  230. ==============================================================
  231. 225 @dispatch(event="provider.compute.vm_types.find",
  232. 226 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  233. 227 @profile
  234. 228 def find(self, **kwargs):
  235. 229 4 4.0 1.0 0.0 obj_list = self
  236. 230 4 3.0 0.8 0.0 filters = ['name']
  237. 231 4 9727539.0 2431884.8 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  238. 232 4 118.0 29.5 0.0 return ClientPagedResultList(self._provider, list(matches))
  239. Total time: 0 s
  240. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  241. Function: find at line 242
  242. Line # Hits Time Per Hit % Time Line Contents
  243. ==============================================================
  244. 242 @dispatch(event="provider.compute.regions.find",
  245. 243 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  246. 244 @profile
  247. 245 def find(self, **kwargs):
  248. 246 obj_list = self
  249. 247 filters = ['name']
  250. 248 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  251. 249 return ClientPagedResultList(self._provider, list(matches))
  252. Total time: 0 s
  253. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  254. Function: get_or_create_default at line 270
  255. Line # Hits Time Per Hit % Time Line Contents
  256. ==============================================================
  257. 270 @profile
  258. 271 def get_or_create_default(self):
  259. 272 networks = self.provider.networking.networks.find(
  260. 273 label=BaseNetwork.CB_DEFAULT_NETWORK_LABEL)
  261. 274
  262. 275 if networks:
  263. 276 return networks[0]
  264. 277 else:
  265. 278 log.info("Creating a CloudBridge-default network labeled %s",
  266. 279 BaseNetwork.CB_DEFAULT_NETWORK_LABEL)
  267. 280 return self.provider.networking.networks.create(
  268. 281 BaseNetwork.CB_DEFAULT_NETWORK_LABEL, '10.0.0.0/16')
  269. Total time: 0 s
  270. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  271. Function: find at line 283
  272. Line # Hits Time Per Hit % Time Line Contents
  273. ==============================================================
  274. 283 @dispatch(event="provider.networking.networks.find",
  275. 284 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  276. 285 @profile
  277. 286 def find(self, **kwargs):
  278. 287 obj_list = self
  279. 288 filters = ['label']
  280. 289 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  281. 290
  282. 291 # All kwargs should have been popped at this time.
  283. 292 if len(kwargs) > 0:
  284. 293 raise TypeError("Unrecognised parameters for search: %s."
  285. 294 " Supported attributes: %s" % (kwargs,
  286. 295 ", ".join(filters)))
  287. 296
  288. 297 return ClientPagedResultList(self.provider,
  289. 298 matches if matches else [])
  290. Total time: 3.56473 s
  291. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  292. Function: find at line 308
  293. Line # Hits Time Per Hit % Time Line Contents
  294. ==============================================================
  295. 308 @dispatch(event="provider.networking.subnets.find",
  296. 309 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  297. 310 @profile
  298. 311 def find(self, network=None, **kwargs):
  299. 312 2 2.0 1.0 0.0 if not network:
  300. 313 2 1.0 0.5 0.0 obj_list = self
  301. 314 else:
  302. 315 obj_list = network.subnets
  303. 316 2 1.0 0.5 0.0 filters = ['label']
  304. 317 2 3564667.0 1782333.5 100.0 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  305. 318 2 59.0 29.5 0.0 return ClientPagedResultList(self._provider, list(matches))
  306. Total time: 0 s
  307. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  308. Function: get_or_create_default at line 320
  309. Line # Hits Time Per Hit % Time Line Contents
  310. ==============================================================
  311. 320 @profile
  312. 321 def get_or_create_default(self, zone):
  313. 322 # Look for a CB-default subnet
  314. 323 matches = self.find(label=BaseSubnet.CB_DEFAULT_SUBNET_LABEL)
  315. 324 if matches:
  316. 325 return matches[0]
  317. 326
  318. 327 # No provider-default Subnet exists, try to create it (net + subnets)
  319. 328 network = self.provider.networking.networks.get_or_create_default()
  320. 329 subnet = self.create(BaseSubnet.CB_DEFAULT_SUBNET_LABEL, network,
  321. 330 BaseSubnet.CB_DEFAULT_SUBNET_IPV4RANGE, zone)
  322. 331 return subnet
  323. Total time: 0 s
  324. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  325. Function: get_or_create_default at line 341
  326. Line # Hits Time Per Hit % Time Line Contents
  327. ==============================================================
  328. 341 @profile
  329. 342 def get_or_create_default(self, network):
  330. 343 net_id = network.id if isinstance(network, Network) else network
  331. 344 routers = self.provider.networking.routers.find(
  332. 345 label=BaseRouter.CB_DEFAULT_ROUTER_LABEL)
  333. 346 for router in routers:
  334. 347 if router.network_id == net_id:
  335. 348 return router
  336. 349 else:
  337. 350 return self.provider.networking.routers.create(
  338. 351 network=net_id, label=BaseRouter.CB_DEFAULT_ROUTER_LABEL)
  339. Total time: 0 s
  340. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/base/services.py
  341. Function: find at line 375
  342. Line # Hits Time Per Hit % Time Line Contents
  343. ==============================================================
  344. 375 @dispatch(event="provider.networking.floating_ips.find",
  345. 376 priority=BaseCloudService.STANDARD_EVENT_PRIORITY)
  346. 377 @profile
  347. 378 def find(self, gateway, **kwargs):
  348. 379 obj_list = gateway.floating_ips
  349. 380 filters = ['name', 'public_ip']
  350. 381 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  351. 382 return ClientPagedResultList(self._provider, list(matches))
  352. Total time: 0 s
  353. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  354. Function: label at line 88
  355. Line # Hits Time Per Hit % Time Line Contents
  356. ==============================================================
  357. 88 @label.setter
  358. 89 # pylint:disable=arguments-differ
  359. 90 @profile
  360. 91 def label(self, value):
  361. 92 self.assert_valid_resource_label(value)
  362. 93 self._ec2_image.create_tags(Tags=[{'Key': 'Name',
  363. 94 'Value': value or ""}])
  364. Total time: 0 s
  365. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  366. Function: refresh at line 134
  367. Line # Hits Time Per Hit % Time Line Contents
  368. ==============================================================
  369. 134 @profile
  370. 135 def refresh(self):
  371. 136 self._ec2_image.reload()
  372. Total time: 0 s
  373. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  374. Function: label at line 254
  375. Line # Hits Time Per Hit % Time Line Contents
  376. ==============================================================
  377. 254 @label.setter
  378. 255 # pylint:disable=arguments-differ
  379. 256 @profile
  380. 257 def label(self, value):
  381. 258 self.assert_valid_resource_label(value)
  382. 259 self._ec2_instance.create_tags(Tags=[{'Key': 'Name',
  383. 260 'Value': value or ""}])
  384. Total time: 0 s
  385. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  386. Function: refresh at line 376
  387. Line # Hits Time Per Hit % Time Line Contents
  388. ==============================================================
  389. 376 @profile
  390. 377 def refresh(self):
  391. 378 try:
  392. 379 self._ec2_instance.reload()
  393. 380 self._unknown_state = False
  394. 381 except ClientError:
  395. 382 # The instance no longer exists and cannot be refreshed.
  396. 383 # set the state to unknown
  397. 384 self._unknown_state = True
  398. Total time: 0 s
  399. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  400. Function: label at line 426
  401. Line # Hits Time Per Hit % Time Line Contents
  402. ==============================================================
  403. 426 @label.setter
  404. 427 # pylint:disable=arguments-differ
  405. 428 @profile
  406. 429 def label(self, value):
  407. 430 self.assert_valid_resource_label(value)
  408. 431 self._volume.create_tags(Tags=[{'Key': 'Name', 'Value': value or ""}])
  409. Total time: 0 s
  410. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  411. Function: description at line 437
  412. Line # Hits Time Per Hit % Time Line Contents
  413. ==============================================================
  414. 437 @description.setter
  415. 438 @profile
  416. 439 def description(self, value):
  417. 440 self._volume.create_tags(Tags=[{'Key': 'Description',
  418. 441 'Value': value or ""}])
  419. Total time: 0 s
  420. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  421. Function: refresh at line 509
  422. Line # Hits Time Per Hit % Time Line Contents
  423. ==============================================================
  424. 509 @profile
  425. 510 def refresh(self):
  426. 511 try:
  427. 512 self._volume.reload()
  428. 513 self._unknown_state = False
  429. 514 except ClientError:
  430. 515 # The volume no longer exists and cannot be refreshed.
  431. 516 # set the status to unknown
  432. 517 self._unknown_state = True
  433. Total time: 0 s
  434. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  435. Function: label at line 552
  436. Line # Hits Time Per Hit % Time Line Contents
  437. ==============================================================
  438. 552 @label.setter
  439. 553 # pylint:disable=arguments-differ
  440. 554 @profile
  441. 555 def label(self, value):
  442. 556 self.assert_valid_resource_label(value)
  443. 557 self._snapshot.create_tags(Tags=[{'Key': 'Name',
  444. 558 'Value': value or ""}])
  445. Total time: 0 s
  446. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  447. Function: description at line 564
  448. Line # Hits Time Per Hit % Time Line Contents
  449. ==============================================================
  450. 564 @description.setter
  451. 565 @profile
  452. 566 def description(self, value):
  453. 567 self._snapshot.create_tags(Tags=[{
  454. 568 'Key': 'Description', 'Value': value or ""}])
  455. Total time: 0 s
  456. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  457. Function: refresh at line 593
  458. Line # Hits Time Per Hit % Time Line Contents
  459. ==============================================================
  460. 593 @profile
  461. 594 def refresh(self):
  462. 595 try:
  463. 596 self._snapshot.reload()
  464. 597 self._unknown_state = False
  465. 598 except ClientError:
  466. 599 # The snapshot no longer exists and cannot be refreshed.
  467. 600 # set the status to unknown
  468. 601 self._unknown_state = True
  469. Total time: 0 s
  470. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  471. Function: label at line 640
  472. Line # Hits Time Per Hit % Time Line Contents
  473. ==============================================================
  474. 640 @label.setter
  475. 641 # pylint:disable=arguments-differ
  476. 642 @profile
  477. 643 def label(self, value):
  478. 644 self.assert_valid_resource_label(value)
  479. 645 self._vm_firewall.create_tags(Tags=[{'Key': 'Name',
  480. 646 'Value': value or ""}])
  481. Total time: 0 s
  482. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  483. Function: description at line 655
  484. Line # Hits Time Per Hit % Time Line Contents
  485. ==============================================================
  486. 655 @description.setter
  487. 656 # pylint:disable=arguments-differ
  488. 657 @profile
  489. 658 def description(self, value):
  490. 659 self._vm_firewall.create_tags(Tags=[{'Key': 'Description',
  491. 660 'Value': value or ""}])
  492. Total time: 0 s
  493. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  494. Function: refresh at line 670
  495. Line # Hits Time Per Hit % Time Line Contents
  496. ==============================================================
  497. 670 @profile
  498. 671 def refresh(self):
  499. 672 self._vm_firewall.reload()
  500. Total time: 0 s
  501. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  502. Function: refresh at line 814
  503. Line # Hits Time Per Hit % Time Line Contents
  504. ==============================================================
  505. 814 @profile
  506. 815 def refresh(self):
  507. 816 self._obj.load()
  508. Total time: 0 s
  509. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  510. Function: label at line 896
  511. Line # Hits Time Per Hit % Time Line Contents
  512. ==============================================================
  513. 896 @label.setter
  514. 897 # pylint:disable=arguments-differ
  515. 898 @profile
  516. 899 def label(self, value):
  517. 900 self.assert_valid_resource_label(value)
  518. 901 self._vpc.create_tags(Tags=[{'Key': 'Name', 'Value': value or ""}])
  519. Total time: 0 s
  520. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  521. Function: refresh at line 930
  522. Line # Hits Time Per Hit % Time Line Contents
  523. ==============================================================
  524. 930 @profile
  525. 931 def refresh(self):
  526. 932 try:
  527. 933 self._vpc.reload()
  528. 934 self._unknown_state = False
  529. 935 except ClientError:
  530. 936 # The network no longer exists and cannot be refreshed.
  531. 937 # set the status to unknown
  532. 938 self._unknown_state = True
  533. Total time: 0 s
  534. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  535. Function: label at line 975
  536. Line # Hits Time Per Hit % Time Line Contents
  537. ==============================================================
  538. 975 @label.setter
  539. 976 # pylint:disable=arguments-differ
  540. 977 @profile
  541. 978 def label(self, value):
  542. 979 self.assert_valid_resource_label(value)
  543. 980 self._subnet.create_tags(Tags=[{'Key': 'Name', 'Value': value or ""}])
  544. Total time: 0 s
  545. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  546. Function: refresh at line 1006
  547. Line # Hits Time Per Hit % Time Line Contents
  548. ==============================================================
  549. 1006 @profile
  550. 1007 def refresh(self):
  551. 1008 try:
  552. 1009 self._subnet.reload()
  553. 1010 self._unknown_state = False
  554. 1011 except ClientError:
  555. 1012 # subnet no longer exists
  556. 1013 self._unknown_state = True
  557. Total time: 0 s
  558. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  559. Function: refresh at line 1038
  560. Line # Hits Time Per Hit % Time Line Contents
  561. ==============================================================
  562. 1038 @profile
  563. 1039 def refresh(self):
  564. 1040 self._ip.reload()
  565. Total time: 0 s
  566. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  567. Function: label at line 1061
  568. Line # Hits Time Per Hit % Time Line Contents
  569. ==============================================================
  570. 1061 @label.setter
  571. 1062 # pylint:disable=arguments-differ
  572. 1063 @profile
  573. 1064 def label(self, value):
  574. 1065 self.assert_valid_resource_label(value)
  575. 1066 self._route_table.create_tags(Tags=[{'Key': 'Name',
  576. 1067 'Value': value or ""}])
  577. Total time: 0 s
  578. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  579. Function: refresh at line 1069
  580. Line # Hits Time Per Hit % Time Line Contents
  581. ==============================================================
  582. 1069 @profile
  583. 1070 def refresh(self):
  584. 1071 try:
  585. 1072 self._route_table.reload()
  586. 1073 except ClientError:
  587. 1074 self._route_table.associations = None
  588. Total time: 0 s
  589. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/resources.py
  590. Function: refresh at line 1135
  591. Line # Hits Time Per Hit % Time Line Contents
  592. ==============================================================
  593. 1135 @profile
  594. 1136 def refresh(self):
  595. 1137 try:
  596. 1138 self._gateway.reload()
  597. 1139 except ClientError:
  598. 1140 self._gateway.state = GatewayState.UNKNOWN
  599. Total time: 0 s
  600. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  601. Function: get at line 106
  602. Line # Hits Time Per Hit % Time Line Contents
  603. ==============================================================
  604. 106 @dispatch(event="provider.security.key_pairs.get",
  605. 107 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  606. 108 @profile
  607. 109 def get(self, key_pair_id):
  608. 110 log.debug("Getting Key Pair Service %s", key_pair_id)
  609. 111 return self.svc.get(key_pair_id)
  610. Total time: 0 s
  611. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  612. Function: list at line 113
  613. Line # Hits Time Per Hit % Time Line Contents
  614. ==============================================================
  615. 113 @dispatch(event="provider.security.key_pairs.list",
  616. 114 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  617. 115 @profile
  618. 116 def list(self, limit=None, marker=None):
  619. 117 return self.svc.list(limit=limit, marker=marker)
  620. Total time: 0 s
  621. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  622. Function: find at line 119
  623. Line # Hits Time Per Hit % Time Line Contents
  624. ==============================================================
  625. 119 @dispatch(event="provider.security.key_pairs.find",
  626. 120 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  627. 121 @profile
  628. 122 def find(self, **kwargs):
  629. 123 name = kwargs.pop('name', None)
  630. 124
  631. 125 # All kwargs should have been popped at this time.
  632. 126 if len(kwargs) > 0:
  633. 127 raise InvalidParamException(
  634. 128 "Unrecognised parameters for search: %s. Supported "
  635. 129 "attributes: %s" % (kwargs, 'name'))
  636. 130
  637. 131 log.debug("Searching for Key Pair %s", name)
  638. 132 return self.svc.find(filter_name='key-name', filter_value=name)
  639. Total time: 0 s
  640. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  641. Function: create at line 134
  642. Line # Hits Time Per Hit % Time Line Contents
  643. ==============================================================
  644. 134 @dispatch(event="provider.security.key_pairs.create",
  645. 135 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  646. 136 @profile
  647. 137 def create(self, name, public_key_material=None):
  648. 138 AWSKeyPair.assert_valid_resource_name(name)
  649. 139 private_key = None
  650. 140 if not public_key_material:
  651. 141 public_key_material, private_key = cb_helpers.generate_key_pair()
  652. 142 try:
  653. 143 kp = self.svc.create('import_key_pair', KeyName=name,
  654. 144 PublicKeyMaterial=public_key_material)
  655. 145 kp.material = private_key
  656. 146 return kp
  657. 147 except ClientError as e:
  658. 148 if e.response['Error']['Code'] == 'InvalidKeyPair.Duplicate':
  659. 149 raise DuplicateResourceException(
  660. 150 'Keypair already exists with name {0}'.format(name))
  661. 151 else:
  662. 152 raise e
  663. Total time: 0 s
  664. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  665. Function: delete at line 154
  666. Line # Hits Time Per Hit % Time Line Contents
  667. ==============================================================
  668. 154 @dispatch(event="provider.security.key_pairs.delete",
  669. 155 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  670. 156 @profile
  671. 157 def delete(self, key_pair):
  672. 158 key_pair = (key_pair if isinstance(key_pair, AWSKeyPair) else
  673. 159 self.get(key_pair))
  674. 160 if key_pair:
  675. 161 # pylint:disable=protected-access
  676. 162 key_pair._key_pair.delete()
  677. Total time: 0 s
  678. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  679. Function: get at line 173
  680. Line # Hits Time Per Hit % Time Line Contents
  681. ==============================================================
  682. 173 @dispatch(event="provider.security.vm_firewalls.get",
  683. 174 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  684. 175 @profile
  685. 176 def get(self, vm_firewall_id):
  686. 177 log.debug("Getting Firewall Service with the id: %s", vm_firewall_id)
  687. 178 return self.svc.get(vm_firewall_id)
  688. Total time: 0 s
  689. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  690. Function: list at line 180
  691. Line # Hits Time Per Hit % Time Line Contents
  692. ==============================================================
  693. 180 @dispatch(event="provider.security.vm_firewalls.list",
  694. 181 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  695. 182 @profile
  696. 183 def list(self, limit=None, marker=None):
  697. 184 return self.svc.list(limit=limit, marker=marker)
  698. Total time: 0 s
  699. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  700. Function: create at line 186
  701. Line # Hits Time Per Hit % Time Line Contents
  702. ==============================================================
  703. 186 @cb_helpers.deprecated_alias(network_id='network')
  704. 187 @dispatch(event="provider.security.vm_firewalls.create",
  705. 188 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  706. 189 @profile
  707. 190 def create(self, label, network, description=None):
  708. 191 AWSVMFirewall.assert_valid_resource_label(label)
  709. 192 name = AWSVMFirewall._generate_name_from_label(label, 'cb-fw')
  710. 193 network_id = network.id if isinstance(network, Network) else network
  711. 194 obj = self.svc.create('create_security_group', GroupName=name,
  712. 195 Description=name,
  713. 196 VpcId=network_id)
  714. 197 obj.label = label
  715. 198 obj.description = description
  716. 199 return obj
  717. Total time: 0 s
  718. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  719. Function: find at line 201
  720. Line # Hits Time Per Hit % Time Line Contents
  721. ==============================================================
  722. 201 @dispatch(event="provider.security.vm_firewalls.find",
  723. 202 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  724. 203 @profile
  725. 204 def find(self, **kwargs):
  726. 205 # Filter by name or label
  727. 206 label = kwargs.pop('label', None)
  728. 207 log.debug("Searching for Firewall Service %s", label)
  729. 208 # All kwargs should have been popped at this time.
  730. 209 if len(kwargs) > 0:
  731. 210 raise InvalidParamException(
  732. 211 "Unrecognised parameters for search: %s. Supported "
  733. 212 "attributes: %s" % (kwargs, 'label'))
  734. 213 return self.svc.find(filter_name='tag:Name',
  735. 214 filter_value=label)
  736. Total time: 0 s
  737. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  738. Function: delete at line 216
  739. Line # Hits Time Per Hit % Time Line Contents
  740. ==============================================================
  741. 216 @dispatch(event="provider.security.vm_firewalls.delete",
  742. 217 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  743. 218 @profile
  744. 219 def delete(self, vm_firewall):
  745. 220 firewall = (vm_firewall if isinstance(vm_firewall, AWSVMFirewall)
  746. 221 else self.get(vm_firewall))
  747. 222 if firewall:
  748. 223 # pylint:disable=protected-access
  749. 224 firewall._vm_firewall.delete()
  750. Total time: 0 s
  751. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  752. Function: list at line 232
  753. Line # Hits Time Per Hit % Time Line Contents
  754. ==============================================================
  755. 232 @dispatch(event="provider.security.vm_firewall_rules.list",
  756. 233 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  757. 234 @profile
  758. 235 def list(self, firewall, limit=None, marker=None):
  759. 236 # pylint:disable=protected-access
  760. 237 rules = [AWSVMFirewallRule(firewall,
  761. 238 TrafficDirection.INBOUND, r)
  762. 239 for r in firewall._vm_firewall.ip_permissions]
  763. 240 # pylint:disable=protected-access
  764. 241 rules = rules + [
  765. 242 AWSVMFirewallRule(
  766. 243 firewall, TrafficDirection.OUTBOUND, r)
  767. 244 for r in firewall._vm_firewall.ip_permissions_egress]
  768. 245 return ClientPagedResultList(self.provider, rules,
  769. 246 limit=limit, marker=marker)
  770. Total time: 0 s
  771. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  772. Function: create at line 248
  773. Line # Hits Time Per Hit % Time Line Contents
  774. ==============================================================
  775. 248 @dispatch(event="provider.security.vm_firewall_rules.create",
  776. 249 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  777. 250 @profile
  778. 251 def create(self, firewall, direction, protocol=None, from_port=None,
  779. 252 to_port=None, cidr=None, src_dest_fw=None):
  780. 253 src_dest_fw_id = (
  781. 254 src_dest_fw.id if isinstance(src_dest_fw, AWSVMFirewall)
  782. 255 else src_dest_fw)
  783. 256
  784. 257 # pylint:disable=protected-access
  785. 258 ip_perm_entry = AWSVMFirewallRule._construct_ip_perms(
  786. 259 protocol, from_port, to_port, cidr, src_dest_fw_id)
  787. 260 # Filter out empty values to please Boto
  788. 261 ip_perms = [trim_empty_params(ip_perm_entry)]
  789. 262
  790. 263 try:
  791. 264 if direction == TrafficDirection.INBOUND:
  792. 265 # pylint:disable=protected-access
  793. 266 firewall._vm_firewall.authorize_ingress(
  794. 267 IpPermissions=ip_perms)
  795. 268 elif direction == TrafficDirection.OUTBOUND:
  796. 269 # pylint:disable=protected-access
  797. 270 firewall._vm_firewall.authorize_egress(
  798. 271 IpPermissions=ip_perms)
  799. 272 else:
  800. 273 raise InvalidValueException("direction", direction)
  801. 274 firewall.refresh()
  802. 275 return AWSVMFirewallRule(firewall, direction, ip_perm_entry)
  803. 276 except ClientError as ec2e:
  804. 277 if ec2e.response['Error']['Code'] == "InvalidPermission.Duplicate":
  805. 278 return AWSVMFirewallRule(
  806. 279 firewall, direction, ip_perm_entry)
  807. 280 else:
  808. 281 raise ec2e
  809. Total time: 0 s
  810. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  811. Function: delete at line 283
  812. Line # Hits Time Per Hit % Time Line Contents
  813. ==============================================================
  814. 283 @dispatch(event="provider.security.vm_firewall_rules.delete",
  815. 284 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  816. 285 @profile
  817. 286 def delete(self, firewall, rule):
  818. 287 # pylint:disable=protected-access
  819. 288 ip_perm_entry = rule._construct_ip_perms(
  820. 289 rule.protocol, rule.from_port, rule.to_port,
  821. 290 rule.cidr, rule.src_dest_fw_id)
  822. 291
  823. 292 # Filter out empty values to please Boto
  824. 293 ip_perms = [trim_empty_params(ip_perm_entry)]
  825. 294
  826. 295 # pylint:disable=protected-access
  827. 296 if rule.direction == TrafficDirection.INBOUND:
  828. 297 firewall._vm_firewall.revoke_ingress(
  829. 298 IpPermissions=ip_perms)
  830. 299 else:
  831. 300 # pylint:disable=protected-access
  832. 301 firewall._vm_firewall.revoke_egress(
  833. 302 IpPermissions=ip_perms)
  834. 303 firewall.refresh()
  835. Total time: 0 s
  836. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  837. Function: get at line 342
  838. Line # Hits Time Per Hit % Time Line Contents
  839. ==============================================================
  840. 342 @dispatch(event="provider.storage.volumes.get",
  841. 343 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  842. 344 @profile
  843. 345 def get(self, volume_id):
  844. 346 return self.svc.get(volume_id)
  845. Total time: 0 s
  846. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  847. Function: find at line 348
  848. Line # Hits Time Per Hit % Time Line Contents
  849. ==============================================================
  850. 348 @dispatch(event="provider.storage.volumes.find",
  851. 349 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  852. 350 @profile
  853. 351 def find(self, **kwargs):
  854. 352 label = kwargs.pop('label', None)
  855. 353
  856. 354 # All kwargs should have been popped at this time.
  857. 355 if len(kwargs) > 0:
  858. 356 raise InvalidParamException(
  859. 357 "Unrecognised parameters for search: %s. Supported "
  860. 358 "attributes: %s" % (kwargs, 'label'))
  861. 359
  862. 360 log.debug("Searching for AWS Volume Service %s", label)
  863. 361 return self.svc.find(filter_name='tag:Name', filter_value=label)
  864. Total time: 0 s
  865. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  866. Function: list at line 363
  867. Line # Hits Time Per Hit % Time Line Contents
  868. ==============================================================
  869. 363 @dispatch(event="provider.storage.volumes.list",
  870. 364 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  871. 365 @profile
  872. 366 def list(self, limit=None, marker=None):
  873. 367 return self.svc.list(limit=limit, marker=marker)
  874. Total time: 0 s
  875. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  876. Function: create at line 369
  877. Line # Hits Time Per Hit % Time Line Contents
  878. ==============================================================
  879. 369 @dispatch(event="provider.storage.volumes.create",
  880. 370 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  881. 371 @profile
  882. 372 def create(self, label, size, zone, snapshot=None, description=None):
  883. 373 AWSVolume.assert_valid_resource_label(label)
  884. 374 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  885. 375 snapshot_id = snapshot.id if isinstance(
  886. 376 snapshot, AWSSnapshot) and snapshot else snapshot
  887. 377
  888. 378 cb_vol = self.svc.create('create_volume', Size=size,
  889. 379 AvailabilityZone=zone_id,
  890. 380 SnapshotId=snapshot_id)
  891. 381 # Wait until ready to tag instance
  892. 382 cb_vol.wait_till_ready()
  893. 383 cb_vol.label = label
  894. 384 if description:
  895. 385 cb_vol.description = description
  896. 386 return cb_vol
  897. Total time: 0 s
  898. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  899. Function: delete at line 388
  900. Line # Hits Time Per Hit % Time Line Contents
  901. ==============================================================
  902. 388 @dispatch(event="provider.storage.volumes.delete",
  903. 389 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  904. 390 @profile
  905. 391 def delete(self, vol):
  906. 392 volume = vol if isinstance(vol, AWSVolume) else self.get(vol)
  907. 393 if volume:
  908. 394 # pylint:disable=protected-access
  909. 395 volume._volume.delete()
  910. Total time: 0 s
  911. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  912. Function: get at line 406
  913. Line # Hits Time Per Hit % Time Line Contents
  914. ==============================================================
  915. 406 @dispatch(event="provider.storage.snapshots.get",
  916. 407 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  917. 408 @profile
  918. 409 def get(self, snapshot_id):
  919. 410 return self.svc.get(snapshot_id)
  920. Total time: 0 s
  921. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  922. Function: find at line 412
  923. Line # Hits Time Per Hit % Time Line Contents
  924. ==============================================================
  925. 412 @dispatch(event="provider.storage.snapshots.find",
  926. 413 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  927. 414 @profile
  928. 415 def find(self, **kwargs):
  929. 416 # Filter by description or label
  930. 417 label = kwargs.get('label', None)
  931. 418
  932. 419 obj_list = []
  933. 420 if label:
  934. 421 log.debug("Searching for AWS Snapshot with label %s", label)
  935. 422 obj_list.extend(self.svc.find(filter_name='tag:Name',
  936. 423 filter_value=label,
  937. 424 OwnerIds=['self']))
  938. 425 else:
  939. 426 obj_list = list(self)
  940. 427 filters = ['label']
  941. 428 return cb_helpers.generic_find(filters, kwargs, obj_list)
  942. Total time: 0 s
  943. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  944. Function: list at line 430
  945. Line # Hits Time Per Hit % Time Line Contents
  946. ==============================================================
  947. 430 @dispatch(event="provider.storage.snapshots.list",
  948. 431 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  949. 432 @profile
  950. 433 def list(self, limit=None, marker=None):
  951. 434 return self.svc.list(limit=limit, marker=marker,
  952. 435 OwnerIds=['self'])
  953. Total time: 0 s
  954. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  955. Function: create at line 437
  956. Line # Hits Time Per Hit % Time Line Contents
  957. ==============================================================
  958. 437 @dispatch(event="provider.storage.snapshots.create",
  959. 438 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  960. 439 @profile
  961. 440 def create(self, label, volume, description=None):
  962. 441 AWSSnapshot.assert_valid_resource_label(label)
  963. 442 volume_id = volume.id if isinstance(volume, AWSVolume) else volume
  964. 443
  965. 444 cb_snap = self.svc.create('create_snapshot', VolumeId=volume_id)
  966. 445 # Wait until ready to tag instance
  967. 446 cb_snap.wait_till_ready()
  968. 447 cb_snap.label = label
  969. 448 if cb_snap.description:
  970. 449 cb_snap.description = description
  971. 450 return cb_snap
  972. Total time: 0 s
  973. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  974. Function: delete at line 452
  975. Line # Hits Time Per Hit % Time Line Contents
  976. ==============================================================
  977. 452 @dispatch(event="provider.storage.snapshots.delete",
  978. 453 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  979. 454 @profile
  980. 455 def delete(self, snapshot):
  981. 456 snapshot = (snapshot if isinstance(snapshot, AWSSnapshot) else
  982. 457 self.get(snapshot))
  983. 458 if snapshot:
  984. 459 # pylint:disable=protected-access
  985. 460 snapshot._snapshot.delete()
  986. Total time: 0 s
  987. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  988. Function: get at line 471
  989. Line # Hits Time Per Hit % Time Line Contents
  990. ==============================================================
  991. 471 @dispatch(event="provider.storage.buckets.get",
  992. 472 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  993. 473 @profile
  994. 474 def get(self, bucket_id):
  995. 475 """
  996. 476 Returns a bucket given its ID. Returns ``None`` if the bucket
  997. 477 does not exist.
  998. 478 """
  999. 479 try:
  1000. 480 # Make a call to make sure the bucket exists. There's an edge case
  1001. 481 # where a 403 response can occur when the bucket exists but the
  1002. 482 # user simply does not have permissions to access it. See below.
  1003. 483 self.provider.s3_conn.meta.client.head_bucket(Bucket=bucket_id)
  1004. 484 return AWSBucket(self.provider,
  1005. 485 self.provider.s3_conn.Bucket(bucket_id))
  1006. 486 except ClientError as e:
  1007. 487 # If 403, it means the bucket exists, but the user does not have
  1008. 488 # permissions to access the bucket. However, limited operations
  1009. 489 # may be permitted (with a session token for example), so return a
  1010. 490 # Bucket instance to allow further operations.
  1011. 491 # http://stackoverflow.com/questions/32331456/using-boto-upload-file-to-s3-
  1012. 492 # sub-folder-when-i-have-no-permissions-on-listing-fo
  1013. 493 if e.response['Error']['Code'] == "403":
  1014. 494 log.warning("AWS Bucket %s already exists but user doesn't "
  1015. 495 "have enough permissions to access the bucket",
  1016. 496 bucket_id)
  1017. 497 return AWSBucket(self.provider,
  1018. 498 self.provider.s3_conn.Bucket(bucket_id))
  1019. 499 # For all other responses, it's assumed that the bucket does not exist.
  1020. 500 return None
  1021. Total time: 0 s
  1022. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1023. Function: list at line 502
  1024. Line # Hits Time Per Hit % Time Line Contents
  1025. ==============================================================
  1026. 502 @dispatch(event="provider.storage.buckets.list",
  1027. 503 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  1028. 504 @profile
  1029. 505 def list(self, limit=None, marker=None):
  1030. 506 return self.svc.list(limit=limit, marker=marker)
  1031. Total time: 0 s
  1032. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1033. Function: create at line 508
  1034. Line # Hits Time Per Hit % Time Line Contents
  1035. ==============================================================
  1036. 508 @dispatch(event="provider.storage.buckets.create",
  1037. 509 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  1038. 510 @profile
  1039. 511 def create(self, name, location=None):
  1040. 512 AWSBucket.assert_valid_resource_name(name)
  1041. 513 location = location or self.provider.region_name
  1042. 514 # Due to an API issue in S3, specifying us-east-1 as a
  1043. 515 # LocationConstraint results in an InvalidLocationConstraint.
  1044. 516 # Therefore, it must be special-cased and omitted altogether.
  1045. 517 # See: https://github.com/boto/boto3/issues/125
  1046. 518 # In addition, us-east-1 also behaves differently when it comes
  1047. 519 # to raising duplicate resource exceptions, so perform a manual
  1048. 520 # check
  1049. 521 if location == 'us-east-1':
  1050. 522 try:
  1051. 523 # check whether bucket already exists
  1052. 524 self.provider.s3_conn.meta.client.head_bucket(Bucket=name)
  1053. 525 except ClientError as e:
  1054. 526 if e.response['Error']['Code'] == "404":
  1055. 527 # bucket doesn't exist, go ahead and create it
  1056. 528 return self.svc.create('create_bucket', Bucket=name)
  1057. 529 raise DuplicateResourceException(
  1058. 530 'Bucket already exists with name {0}'.format(name))
  1059. 531 else:
  1060. 532 try:
  1061. 533 return self.svc.create('create_bucket', Bucket=name,
  1062. 534 CreateBucketConfiguration={
  1063. 535 'LocationConstraint': location
  1064. 536 })
  1065. 537 except ClientError as e:
  1066. 538 if e.response['Error']['Code'] == "BucketAlreadyOwnedByYou":
  1067. 539 raise DuplicateResourceException(
  1068. 540 'Bucket already exists with name {0}'.format(name))
  1069. 541 else:
  1070. 542 raise
  1071. Total time: 0 s
  1072. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1073. Function: delete at line 544
  1074. Line # Hits Time Per Hit % Time Line Contents
  1075. ==============================================================
  1076. 544 @dispatch(event="provider.storage.buckets.delete",
  1077. 545 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  1078. 546 @profile
  1079. 547 def delete(self, bucket):
  1080. 548 b = bucket if isinstance(bucket, AWSBucket) else self.get(bucket)
  1081. 549 if b:
  1082. 550 # pylint:disable=protected-access
  1083. 551 b._bucket.delete()
  1084. Total time: 0 s
  1085. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1086. Function: get at line 559
  1087. Line # Hits Time Per Hit % Time Line Contents
  1088. ==============================================================
  1089. 559 @profile
  1090. 560 def get(self, bucket, object_id):
  1091. 561 try:
  1092. 562 # pylint:disable=protected-access
  1093. 563 obj = bucket._bucket.Object(object_id)
  1094. 564 # load() throws an error if object does not exist
  1095. 565 obj.load()
  1096. 566 return AWSBucketObject(self.provider, obj)
  1097. 567 except ClientError:
  1098. 568 return None
  1099. Total time: 0 s
  1100. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1101. Function: list at line 570
  1102. Line # Hits Time Per Hit % Time Line Contents
  1103. ==============================================================
  1104. 570 @profile
  1105. 571 def list(self, bucket, limit=None, marker=None, prefix=None):
  1106. 572 if prefix:
  1107. 573 # pylint:disable=protected-access
  1108. 574 boto_objs = bucket._bucket.objects.filter(Prefix=prefix)
  1109. 575 else:
  1110. 576 # pylint:disable=protected-access
  1111. 577 boto_objs = bucket._bucket.objects.all()
  1112. 578 objects = [AWSBucketObject(self.provider, obj) for obj in boto_objs]
  1113. 579 return ClientPagedResultList(self.provider, objects,
  1114. 580 limit=limit, marker=marker)
  1115. Total time: 0 s
  1116. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1117. Function: find at line 582
  1118. Line # Hits Time Per Hit % Time Line Contents
  1119. ==============================================================
  1120. 582 @profile
  1121. 583 def find(self, bucket, **kwargs):
  1122. 584 # pylint:disable=protected-access
  1123. 585 obj_list = [AWSBucketObject(self.provider, o)
  1124. 586 for o in bucket._bucket.objects.all()]
  1125. 587 filters = ['name']
  1126. 588 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  1127. 589 return ClientPagedResultList(self.provider, list(matches),
  1128. 590 limit=None, marker=None)
  1129. Total time: 0 s
  1130. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1131. Function: create at line 592
  1132. Line # Hits Time Per Hit % Time Line Contents
  1133. ==============================================================
  1134. 592 @profile
  1135. 593 def create(self, bucket, name):
  1136. 594 # pylint:disable=protected-access
  1137. 595 obj = bucket._bucket.Object(name)
  1138. 596 return AWSBucketObject(self.provider, obj)
  1139. Total time: 0 s
  1140. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1141. Function: get at line 633
  1142. Line # Hits Time Per Hit % Time Line Contents
  1143. ==============================================================
  1144. 633 @profile
  1145. 634 def get(self, image_id):
  1146. 635 log.debug("Getting AWS Image Service with the id: %s", image_id)
  1147. 636 return self.svc.get(image_id)
  1148. Total time: 0 s
  1149. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1150. Function: find at line 638
  1151. Line # Hits Time Per Hit % Time Line Contents
  1152. ==============================================================
  1153. 638 @profile
  1154. 639 def find(self, **kwargs):
  1155. 640 # Filter by name or label
  1156. 641 label = kwargs.pop('label', None)
  1157. 642 # Popped here, not used in the generic find
  1158. 643 owner = kwargs.pop('owners', None)
  1159. 644
  1160. 645 # All kwargs should have been popped at this time.
  1161. 646 if len(kwargs) > 0:
  1162. 647 raise InvalidParamException(
  1163. 648 "Unrecognised parameters for search: %s. Supported "
  1164. 649 "attributes: %s" % (kwargs, 'label'))
  1165. 650
  1166. 651 extra_args = {}
  1167. 652 if owner:
  1168. 653 extra_args.update(Owners=owner)
  1169. 654
  1170. 655 # The original list is made by combining both searches by "tag:Name"
  1171. 656 # and "AMI name" to allow for searches of public images
  1172. 657 if label:
  1173. 658 log.debug("Searching for AWS Image Service %s", label)
  1174. 659 obj_list = []
  1175. 660 obj_list.extend(self.svc.find(filter_name='name',
  1176. 661 filter_value=label, **extra_args))
  1177. 662 obj_list.extend(self.svc.find(filter_name='tag:Name',
  1178. 663 filter_value=label, **extra_args))
  1179. 664 return obj_list
  1180. 665 else:
  1181. 666 return []
  1182. Total time: 0 s
  1183. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1184. Function: list at line 668
  1185. Line # Hits Time Per Hit % Time Line Contents
  1186. ==============================================================
  1187. 668 @profile
  1188. 669 def list(self, filter_by_owner=True, limit=None, marker=None):
  1189. 670 return self.svc.list(Owners=['self'] if filter_by_owner else
  1190. 671 ['amazon', 'self'],
  1191. 672 limit=limit, marker=marker)
  1192. Total time: 0 s
  1193. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1194. Function: create_launch_config at line 765
  1195. Line # Hits Time Per Hit % Time Line Contents
  1196. ==============================================================
  1197. 765 @profile
  1198. 766 def create_launch_config(self):
  1199. 767 return AWSLaunchConfig(self.provider)
  1200. Total time: 0 s
  1201. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1202. Function: create at line 769
  1203. Line # Hits Time Per Hit % Time Line Contents
  1204. ==============================================================
  1205. 769 @dispatch(event="provider.compute.instances.create",
  1206. 770 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  1207. 771 @profile
  1208. 772 def create(self, label, image, vm_type, subnet, zone,
  1209. 773 key_pair=None, vm_firewalls=None, user_data=None,
  1210. 774 launch_config=None, **kwargs):
  1211. 775 AWSInstance.assert_valid_resource_label(label)
  1212. 776 image_id = image.id if isinstance(image, MachineImage) else image
  1213. 777 vm_size = vm_type.id if \
  1214. 778 isinstance(vm_type, VMType) else vm_type
  1215. 779 subnet = (self.provider.networking.subnets.get(subnet)
  1216. 780 if isinstance(subnet, str) else subnet)
  1217. 781 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  1218. 782 key_pair_name = key_pair.name if isinstance(
  1219. 783 key_pair,
  1220. 784 KeyPair) else key_pair
  1221. 785 if launch_config:
  1222. 786 bdm = self._process_block_device_mappings(launch_config)
  1223. 787 else:
  1224. 788 bdm = None
  1225. 789
  1226. 790 subnet_id, zone_id, vm_firewall_ids = \
  1227. 791 self._resolve_launch_options(subnet, zone_id, vm_firewalls)
  1228. 792
  1229. 793 placement = {'AvailabilityZone': zone_id} if zone_id else None
  1230. 794 inst = self.svc.create('create_instances',
  1231. 795 ImageId=image_id,
  1232. 796 MinCount=1,
  1233. 797 MaxCount=1,
  1234. 798 KeyName=key_pair_name,
  1235. 799 SecurityGroupIds=vm_firewall_ids or None,
  1236. 800 UserData=str(user_data) or None,
  1237. 801 InstanceType=vm_size,
  1238. 802 Placement=placement,
  1239. 803 BlockDeviceMappings=bdm,
  1240. 804 SubnetId=subnet_id
  1241. 805 )
  1242. 806 if inst and len(inst) == 1:
  1243. 807 # Wait until the resource exists
  1244. 808 # pylint:disable=protected-access
  1245. 809 inst[0]._wait_till_exists()
  1246. 810 # Tag the instance w/ the name
  1247. 811 inst[0].label = label
  1248. 812 return inst[0]
  1249. 813 raise ValueError(
  1250. 814 'Expected a single object response, got a list: %s' % inst)
  1251. Total time: 0 s
  1252. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1253. Function: get at line 816
  1254. Line # Hits Time Per Hit % Time Line Contents
  1255. ==============================================================
  1256. 816 @dispatch(event="provider.compute.instances.get",
  1257. 817 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  1258. 818 @profile
  1259. 819 def get(self, instance_id):
  1260. 820 return self.svc.get(instance_id)
  1261. Total time: 0 s
  1262. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1263. Function: find at line 822
  1264. Line # Hits Time Per Hit % Time Line Contents
  1265. ==============================================================
  1266. 822 @dispatch(event="provider.compute.instances.find",
  1267. 823 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  1268. 824 @profile
  1269. 825 def find(self, **kwargs):
  1270. 826 label = kwargs.pop('label', None)
  1271. 827
  1272. 828 # All kwargs should have been popped at this time.
  1273. 829 if len(kwargs) > 0:
  1274. 830 raise InvalidParamException(
  1275. 831 "Unrecognised parameters for search: %s. Supported "
  1276. 832 "attributes: %s" % (kwargs, 'label'))
  1277. 833
  1278. 834 return self.svc.find(filter_name='tag:Name', filter_value=label)
  1279. Total time: 0 s
  1280. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1281. Function: list at line 836
  1282. Line # Hits Time Per Hit % Time Line Contents
  1283. ==============================================================
  1284. 836 @dispatch(event="provider.compute.instances.list",
  1285. 837 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  1286. 838 @profile
  1287. 839 def list(self, limit=None, marker=None):
  1288. 840 return self.svc.list(limit=limit, marker=marker)
  1289. Total time: 0 s
  1290. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1291. Function: delete at line 842
  1292. Line # Hits Time Per Hit % Time Line Contents
  1293. ==============================================================
  1294. 842 @dispatch(event="provider.compute.instances.delete",
  1295. 843 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  1296. 844 @profile
  1297. 845 def delete(self, instance):
  1298. 846 aws_inst = (instance if isinstance(instance, AWSInstance) else
  1299. 847 self.get(instance))
  1300. 848 if aws_inst:
  1301. 849 # pylint:disable=protected-access
  1302. 850 aws_inst._ec2_instance.terminate()
  1303. Total time: 0 s
  1304. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1305. Function: list at line 881
  1306. Line # Hits Time Per Hit % Time Line Contents
  1307. ==============================================================
  1308. 881 @dispatch(event="provider.compute.vm_types.list",
  1309. 882 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  1310. 883 @profile
  1311. 884 def list(self, limit=None, marker=None):
  1312. 885 vm_types = [AWSVMType(self.provider, vm_type)
  1313. 886 for vm_type in self.instance_data]
  1314. 887 return ClientPagedResultList(self.provider, vm_types,
  1315. 888 limit=limit, marker=marker)
  1316. Total time: 0 s
  1317. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1318. Function: get at line 896
  1319. Line # Hits Time Per Hit % Time Line Contents
  1320. ==============================================================
  1321. 896 @dispatch(event="provider.compute.regions.get",
  1322. 897 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  1323. 898 @profile
  1324. 899 def get(self, region_id):
  1325. 900 log.debug("Getting AWS Region Service with the id: %s",
  1326. 901 region_id)
  1327. 902 region = [r for r in self if r.id == region_id]
  1328. 903 if region:
  1329. 904 return region[0]
  1330. 905 else:
  1331. 906 return None
  1332. Total time: 0 s
  1333. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1334. Function: list at line 908
  1335. Line # Hits Time Per Hit % Time Line Contents
  1336. ==============================================================
  1337. 908 @dispatch(event="provider.compute.regions.list",
  1338. 909 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  1339. 910 @profile
  1340. 911 def list(self, limit=None, marker=None):
  1341. 912 regions = [
  1342. 913 AWSRegion(self.provider, region) for region in
  1343. 914 self.provider.ec2_conn.meta.client.describe_regions()
  1344. 915 .get('Regions', [])]
  1345. 916 return ClientPagedResultList(self.provider, regions,
  1346. 917 limit=limit, marker=marker)
  1347. Total time: 0 s
  1348. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1349. Function: get at line 963
  1350. Line # Hits Time Per Hit % Time Line Contents
  1351. ==============================================================
  1352. 963 @dispatch(event="provider.networking.networks.get",
  1353. 964 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  1354. 965 @profile
  1355. 966 def get(self, network_id):
  1356. 967 return self.svc.get(network_id)
  1357. Total time: 0 s
  1358. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1359. Function: list at line 969
  1360. Line # Hits Time Per Hit % Time Line Contents
  1361. ==============================================================
  1362. 969 @dispatch(event="provider.networking.networks.list",
  1363. 970 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  1364. 971 @profile
  1365. 972 def list(self, limit=None, marker=None):
  1366. 973 return self.svc.list(limit=limit, marker=marker)
  1367. Total time: 0 s
  1368. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1369. Function: find at line 975
  1370. Line # Hits Time Per Hit % Time Line Contents
  1371. ==============================================================
  1372. 975 @dispatch(event="provider.networking.networks.find",
  1373. 976 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  1374. 977 @profile
  1375. 978 def find(self, **kwargs):
  1376. 979 label = kwargs.pop('label', None)
  1377. 980
  1378. 981 # All kwargs should have been popped at this time.
  1379. 982 if len(kwargs) > 0:
  1380. 983 raise InvalidParamException(
  1381. 984 "Unrecognised parameters for search: %s. Supported "
  1382. 985 "attributes: %s" % (kwargs, 'label'))
  1383. 986
  1384. 987 log.debug("Searching for AWS Network Service %s", label)
  1385. 988 return self.svc.find(filter_name='tag:Name', filter_value=label)
  1386. Total time: 0 s
  1387. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1388. Function: create at line 990
  1389. Line # Hits Time Per Hit % Time Line Contents
  1390. ==============================================================
  1391. 990 @dispatch(event="provider.networking.networks.create",
  1392. 991 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  1393. 992 @profile
  1394. 993 def create(self, label, cidr_block):
  1395. 994 AWSNetwork.assert_valid_resource_label(label)
  1396. 995
  1397. 996 cb_net = self.svc.create('create_vpc', CidrBlock=cidr_block)
  1398. 997 # Wait until ready to tag instance
  1399. 998 cb_net.wait_till_ready()
  1400. 999 if label:
  1401. 1000 cb_net.label = label
  1402. 1001 return cb_net
  1403. Total time: 0 s
  1404. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1405. Function: delete at line 1003
  1406. Line # Hits Time Per Hit % Time Line Contents
  1407. ==============================================================
  1408. 1003 @dispatch(event="provider.networking.networks.delete",
  1409. 1004 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  1410. 1005 @profile
  1411. 1006 def delete(self, network):
  1412. 1007 network = (network if isinstance(network, AWSNetwork)
  1413. 1008 else self.get(network))
  1414. 1009 if network:
  1415. 1010 # pylint:disable=protected-access
  1416. 1011 network._vpc.delete()
  1417. Total time: 0 s
  1418. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1419. Function: get_or_create_default at line 1013
  1420. Line # Hits Time Per Hit % Time Line Contents
  1421. ==============================================================
  1422. 1013 @profile
  1423. 1014 def get_or_create_default(self):
  1424. 1015 # # Look for provided default network
  1425. 1016 # for net in self.provider.networking.networks:
  1426. 1017 # pylint:disable=protected-access
  1427. 1018 # if net._vpc.is_default:
  1428. 1019 # return net
  1429. 1020
  1430. 1021 # No provider-default, try CB-default instead
  1431. 1022 default_nets = self.provider.networking.networks.find(
  1432. 1023 label=AWSNetwork.CB_DEFAULT_NETWORK_LABEL)
  1433. 1024 if default_nets:
  1434. 1025 return default_nets[0]
  1435. 1026
  1436. 1027 else:
  1437. 1028 log.info("Creating a CloudBridge-default network labeled %s",
  1438. 1029 AWSNetwork.CB_DEFAULT_NETWORK_LABEL)
  1439. 1030 return self.provider.networking.networks.create(
  1440. 1031 label=AWSNetwork.CB_DEFAULT_NETWORK_LABEL,
  1441. 1032 cidr_block=AWSNetwork.CB_DEFAULT_IPV4RANGE)
  1442. Total time: 0 s
  1443. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1444. Function: get at line 1043
  1445. Line # Hits Time Per Hit % Time Line Contents
  1446. ==============================================================
  1447. 1043 @dispatch(event="provider.networking.subnets.get",
  1448. 1044 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  1449. 1045 @profile
  1450. 1046 def get(self, subnet_id):
  1451. 1047 return self.svc.get(subnet_id)
  1452. Total time: 0 s
  1453. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1454. Function: list at line 1049
  1455. Line # Hits Time Per Hit % Time Line Contents
  1456. ==============================================================
  1457. 1049 @dispatch(event="provider.networking.subnets.list",
  1458. 1050 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  1459. 1051 @profile
  1460. 1052 def list(self, network=None, limit=None, marker=None):
  1461. 1053 network_id = network.id if isinstance(network, AWSNetwork) else network
  1462. 1054 if network_id:
  1463. 1055 return self.svc.find(
  1464. 1056 filter_name='vpc-id', filter_value=network_id,
  1465. 1057 limit=limit, marker=marker)
  1466. 1058 else:
  1467. 1059 return self.svc.list(limit=limit, marker=marker)
  1468. Total time: 0 s
  1469. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1470. Function: find at line 1061
  1471. Line # Hits Time Per Hit % Time Line Contents
  1472. ==============================================================
  1473. 1061 @dispatch(event="provider.networking.subnets.find",
  1474. 1062 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  1475. 1063 @profile
  1476. 1064 def find(self, network=None, **kwargs):
  1477. 1065 label = kwargs.pop('label', None)
  1478. 1066
  1479. 1067 # All kwargs should have been popped at this time.
  1480. 1068 if len(kwargs) > 0:
  1481. 1069 raise InvalidParamException(
  1482. 1070 "Unrecognised parameters for search: %s. Supported "
  1483. 1071 "attributes: %s" % (kwargs, 'label'))
  1484. 1072
  1485. 1073 log.debug("Searching for AWS Subnet Service %s", label)
  1486. 1074 return self.svc.find(filter_name='tag:Name', filter_value=label)
  1487. Total time: 0 s
  1488. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1489. Function: create at line 1076
  1490. Line # Hits Time Per Hit % Time Line Contents
  1491. ==============================================================
  1492. 1076 @dispatch(event="provider.networking.subnets.create",
  1493. 1077 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  1494. 1078 @profile
  1495. 1079 def create(self, label, network, cidr_block, zone):
  1496. 1080 AWSSubnet.assert_valid_resource_label(label)
  1497. 1081 zone_name = zone.name if isinstance(
  1498. 1082 zone, AWSPlacementZone) else zone
  1499. 1083
  1500. 1084 network_id = network.id if isinstance(network, AWSNetwork) else network
  1501. 1085
  1502. 1086 subnet = self.svc.create('create_subnet',
  1503. 1087 VpcId=network_id,
  1504. 1088 CidrBlock=cidr_block,
  1505. 1089 AvailabilityZone=zone_name)
  1506. 1090 if label:
  1507. 1091 subnet.label = label
  1508. 1092 return subnet
  1509. Total time: 0 s
  1510. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1511. Function: delete at line 1094
  1512. Line # Hits Time Per Hit % Time Line Contents
  1513. ==============================================================
  1514. 1094 @dispatch(event="provider.networking.subnets.delete",
  1515. 1095 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  1516. 1096 @profile
  1517. 1097 def delete(self, subnet):
  1518. 1098 sn = subnet if isinstance(subnet, AWSSubnet) else self.get(subnet)
  1519. 1099 if sn:
  1520. 1100 # pylint:disable=protected-access
  1521. 1101 sn._subnet.delete()
  1522. Total time: 0 s
  1523. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1524. Function: get_or_create_default at line 1103
  1525. Line # Hits Time Per Hit % Time Line Contents
  1526. ==============================================================
  1527. 1103 @profile
  1528. 1104 def get_or_create_default(self, zone):
  1529. 1105 zone_name = zone.name if isinstance(zone, AWSPlacementZone) else zone
  1530. 1106
  1531. 1107 # # Look for provider default subnet in current zone
  1532. 1108 # if zone_name:
  1533. 1109 # snl = self.svc.find('availabilityZone', zone_name)
  1534. 1110 #
  1535. 1111 # else:
  1536. 1112 # snl = self.svc.list()
  1537. 1113 # # Find first available default subnet by sorted order
  1538. 1114 # # of availability zone. Prefer zone us-east-1a over 1e,
  1539. 1115 # # because newer zones tend to have less compatibility
  1540. 1116 # # with different instance types (e.g. c5.large not available
  1541. 1117 # # on us-east-1e as of 14 Dec. 2017).
  1542. 1118 # # pylint:disable=protected-access
  1543. 1119 # snl.sort(key=lambda sn: sn._subnet.availability_zone)
  1544. 1120 #
  1545. 1121 # for sn in snl:
  1546. 1122 # # pylint:disable=protected-access
  1547. 1123 # if sn._subnet.default_for_az:
  1548. 1124 # return sn
  1549. 1125
  1550. 1126 # If no provider-default subnet has been found, look for
  1551. 1127 # cloudbridge-default by label. We suffix labels by availability zone,
  1552. 1128 # thus we add the wildcard for the regular expression to find the
  1553. 1129 # subnet
  1554. 1130 snl = self.find(label=AWSSubnet.CB_DEFAULT_SUBNET_LABEL + "*")
  1555. 1131
  1556. 1132 if snl:
  1557. 1133 # pylint:disable=protected-access
  1558. 1134 snl.sort(key=lambda sn: sn._subnet.availability_zone)
  1559. 1135 if not zone_name:
  1560. 1136 return snl[0]
  1561. 1137 for subnet in snl:
  1562. 1138 if subnet.zone.name == zone_name:
  1563. 1139 return subnet
  1564. 1140
  1565. 1141 # No default Subnet exists, try to create a CloudBridge-specific
  1566. 1142 # subnet. This involves creating the network, subnets, internet
  1567. 1143 # gateway, and connecting it all together so that the network has
  1568. 1144 # Internet connectivity.
  1569. 1145
  1570. 1146 # Check if a default net already exists and get it or create on
  1571. 1147 default_net = self.provider.networking.networks.get_or_create_default()
  1572. 1148
  1573. 1149 # Get/create an internet gateway for the default network and a
  1574. 1150 # corresponding router if it does not already exist.
  1575. 1151 # NOTE: Comment this out because the docs instruct users to setup
  1576. 1152 # network connectivity manually. There's a bit of discrepancy here
  1577. 1153 # though because the provider-default network will have Internet
  1578. 1154 # connectivity (unlike the CloudBridge-default network with this
  1579. 1155 # being commented) and is hence left in the codebase.
  1580. 1156 # default_gtw = default_net.gateways.get_or_create()
  1581. 1157 # router_label = "{0}-router".format(
  1582. 1158 # AWSNetwork.CB_DEFAULT_NETWORK_LABEL)
  1583. 1159 # default_routers = self.provider.networking.routers.find(
  1584. 1160 # label=router_label)
  1585. 1161 # if len(default_routers) == 0:
  1586. 1162 # default_router = self.provider.networking.routers.create(
  1587. 1163 # router_label, default_net)
  1588. 1164 # default_router.attach_gateway(default_gtw)
  1589. 1165 # else:
  1590. 1166 # default_router = default_routers[0]
  1591. 1167
  1592. 1168 # Create a subnet in each of the region's zones
  1593. 1169 region = self.provider.compute.regions.get(self.provider.region_name)
  1594. 1170 default_sn = None
  1595. 1171
  1596. 1172 # Determine how many subnets we'll need for the default network and the
  1597. 1173 # number of available zones. We need to derive a non-overlapping
  1598. 1174 # network size for each subnet within the parent net so figure those
  1599. 1175 # subnets here. `<net>.subnets` method will do this but we need to give
  1600. 1176 # it a prefix. Determining that prefix depends on the size of the
  1601. 1177 # network and should be incorporate the number of zones. So iterate
  1602. 1178 # over potential number of subnets until enough can be created to
  1603. 1179 # accommodate the number of available zones. That is where the fixed
  1604. 1180 # number comes from in the for loop as that many iterations will yield
  1605. 1181 # more potential subnets than any region has zones.
  1606. 1182 ip_net = ipaddress.ip_network(AWSNetwork.CB_DEFAULT_IPV4RANGE)
  1607. 1183 for x in range(5):
  1608. 1184 if len(region.zones) <= len(list(ip_net.subnets(
  1609. 1185 prefixlen_diff=x))):
  1610. 1186 prefixlen_diff = x
  1611. 1187 break
  1612. 1188 subnets = list(ip_net.subnets(prefixlen_diff=prefixlen_diff))
  1613. 1189
  1614. 1190 for i, z in reversed(list(enumerate(region.zones))):
  1615. 1191 sn_label = "{0}-{1}".format(AWSSubnet.CB_DEFAULT_SUBNET_LABEL,
  1616. 1192 z.id[-1])
  1617. 1193 log.info("Creating a default CloudBridge subnet %s: %s" %
  1618. 1194 (sn_label, str(subnets[i])))
  1619. 1195 sn = self.create(sn_label, default_net, str(subnets[i]), z)
  1620. 1196 # Create a route table entry between the SN and the inet gateway
  1621. 1197 # See note above about why this is commented
  1622. 1198 # default_router.attach_subnet(sn)
  1623. 1199 if zone and zone_name == z.name:
  1624. 1200 default_sn = sn
  1625. 1201 # No specific zone was supplied; return the last created subnet
  1626. 1202 # The list was originally reversed to have the last subnet be in zone a
  1627. 1203 if not default_sn:
  1628. 1204 default_sn = sn
  1629. 1205 return default_sn
  1630. Total time: 0 s
  1631. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1632. Function: get at line 1217
  1633. Line # Hits Time Per Hit % Time Line Contents
  1634. ==============================================================
  1635. 1217 @dispatch(event="provider.networking.routers.get",
  1636. 1218 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  1637. 1219 @profile
  1638. 1220 def get(self, router_id):
  1639. 1221 return self.svc.get(router_id)
  1640. Total time: 0 s
  1641. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1642. Function: find at line 1223
  1643. Line # Hits Time Per Hit % Time Line Contents
  1644. ==============================================================
  1645. 1223 @dispatch(event="provider.networking.routers.find",
  1646. 1224 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  1647. 1225 @profile
  1648. 1226 def find(self, **kwargs):
  1649. 1227 label = kwargs.pop('label', None)
  1650. 1228
  1651. 1229 # All kwargs should have been popped at this time.
  1652. 1230 if len(kwargs) > 0:
  1653. 1231 raise InvalidParamException(
  1654. 1232 "Unrecognised parameters for search: %s. Supported "
  1655. 1233 "attributes: %s" % (kwargs, 'label'))
  1656. 1234
  1657. 1235 log.debug("Searching for AWS Router Service %s", label)
  1658. 1236 return self.svc.find(filter_name='tag:Name', filter_value=label)
  1659. Total time: 0 s
  1660. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1661. Function: list at line 1238
  1662. Line # Hits Time Per Hit % Time Line Contents
  1663. ==============================================================
  1664. 1238 @dispatch(event="provider.networking.routers.list",
  1665. 1239 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  1666. 1240 @profile
  1667. 1241 def list(self, limit=None, marker=None):
  1668. 1242 return self.svc.list(limit=limit, marker=marker)
  1669. Total time: 0 s
  1670. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1671. Function: create at line 1244
  1672. Line # Hits Time Per Hit % Time Line Contents
  1673. ==============================================================
  1674. 1244 @dispatch(event="provider.networking.routers.create",
  1675. 1245 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  1676. 1246 @profile
  1677. 1247 def create(self, label, network):
  1678. 1248 network_id = network.id if isinstance(network, AWSNetwork) else network
  1679. 1249
  1680. 1250 cb_router = self.svc.create('create_route_table', VpcId=network_id)
  1681. 1251 if label:
  1682. 1252 cb_router.label = label
  1683. 1253 return cb_router
  1684. Total time: 0 s
  1685. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1686. Function: delete at line 1255
  1687. Line # Hits Time Per Hit % Time Line Contents
  1688. ==============================================================
  1689. 1255 @dispatch(event="provider.networking.routers.delete",
  1690. 1256 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  1691. 1257 @profile
  1692. 1258 def delete(self, router):
  1693. 1259 r = router if isinstance(router, AWSRouter) else self.get(router)
  1694. 1260 if r:
  1695. 1261 # pylint:disable=protected-access
  1696. 1262 r._route_table.delete()
  1697. Total time: 0 s
  1698. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1699. Function: get_or_create at line 1273
  1700. Line # Hits Time Per Hit % Time Line Contents
  1701. ==============================================================
  1702. 1273 @dispatch(event="provider.networking.gateways.get_or_create",
  1703. 1274 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  1704. 1275 @profile
  1705. 1276 def get_or_create(self, network):
  1706. 1277 network_id = network.id if isinstance(
  1707. 1278 network, AWSNetwork) else network
  1708. 1279 # Don't filter by label because it may conflict with at least the
  1709. 1280 # default VPC that most accounts have but that network is typically
  1710. 1281 # without a name.
  1711. 1282 gtw = self.svc.find(filter_name='attachment.vpc-id',
  1712. 1283 filter_value=network_id)
  1713. 1284 if gtw:
  1714. 1285 return gtw[0] # There can be only one gtw attached to a VPC
  1715. 1286 # Gateway does not exist so create one and attach to the supplied net
  1716. 1287 cb_gateway = self.svc.create('create_internet_gateway')
  1717. 1288 cb_gateway._gateway.create_tags(
  1718. 1289 Tags=[{'Key': 'Name',
  1719. 1290 'Value': AWSInternetGateway.CB_DEFAULT_INET_GATEWAY_NAME
  1720. 1291 }])
  1721. 1292 cb_gateway._gateway.attach_to_vpc(VpcId=network_id)
  1722. 1293 return cb_gateway
  1723. Total time: 0 s
  1724. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1725. Function: delete at line 1295
  1726. Line # Hits Time Per Hit % Time Line Contents
  1727. ==============================================================
  1728. 1295 @dispatch(event="provider.networking.gateways.delete",
  1729. 1296 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  1730. 1297 @profile
  1731. 1298 def delete(self, network, gateway):
  1732. 1299 gw = (gateway if isinstance(gateway, AWSInternetGateway)
  1733. 1300 else self.svc.get(gateway))
  1734. 1301 try:
  1735. 1302 if gw.network_id:
  1736. 1303 # pylint:disable=protected-access
  1737. 1304 gw._gateway.detach_from_vpc(VpcId=gw.network_id)
  1738. 1305 except ClientError as e:
  1739. 1306 log.warn("Error deleting gateway {0}: {1}".format(self.id, e))
  1740. 1307 # pylint:disable=protected-access
  1741. 1308 gw._gateway.delete()
  1742. Total time: 0 s
  1743. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1744. Function: list at line 1310
  1745. Line # Hits Time Per Hit % Time Line Contents
  1746. ==============================================================
  1747. 1310 @dispatch(event="provider.networking.gateways.list",
  1748. 1311 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  1749. 1312 @profile
  1750. 1313 def list(self, network, limit=None, marker=None):
  1751. 1314 log.debug("Listing current AWS internet gateways for net %s.",
  1752. 1315 network.id)
  1753. 1316 fltr = [{'Name': 'attachment.vpc-id', 'Values': [network.id]}]
  1754. 1317 return self.svc.list(limit=None, marker=None, Filters=fltr)
  1755. Total time: 0 s
  1756. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1757. Function: get at line 1328
  1758. Line # Hits Time Per Hit % Time Line Contents
  1759. ==============================================================
  1760. 1328 @dispatch(event="provider.networking.floating_ips.get",
  1761. 1329 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  1762. 1330 @profile
  1763. 1331 def get(self, gateway, fip_id):
  1764. 1332 log.debug("Getting AWS Floating IP Service with the id: %s", fip_id)
  1765. 1333 return self.svc.get(fip_id)
  1766. Total time: 0 s
  1767. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1768. Function: list at line 1335
  1769. Line # Hits Time Per Hit % Time Line Contents
  1770. ==============================================================
  1771. 1335 @dispatch(event="provider.networking.floating_ips.list",
  1772. 1336 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  1773. 1337 @profile
  1774. 1338 def list(self, gateway, limit=None, marker=None):
  1775. 1339 return self.svc.list(limit, marker)
  1776. Total time: 0 s
  1777. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1778. Function: create at line 1341
  1779. Line # Hits Time Per Hit % Time Line Contents
  1780. ==============================================================
  1781. 1341 @dispatch(event="provider.networking.floating_ips.create",
  1782. 1342 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  1783. 1343 @profile
  1784. 1344 def create(self, gateway):
  1785. 1345 log.debug("Creating a floating IP under gateway %s", gateway)
  1786. 1346 ip = self.provider.ec2_conn.meta.client.allocate_address(
  1787. 1347 Domain='vpc')
  1788. 1348 return AWSFloatingIP(
  1789. 1349 self.provider,
  1790. 1350 self.provider.ec2_conn.VpcAddress(ip.get('AllocationId')))
  1791. Total time: 0 s
  1792. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/aws/services.py
  1793. Function: delete at line 1352
  1794. Line # Hits Time Per Hit % Time Line Contents
  1795. ==============================================================
  1796. 1352 @dispatch(event="provider.networking.floating_ips.delete",
  1797. 1353 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  1798. 1354 @profile
  1799. 1355 def delete(self, gateway, fip):
  1800. 1356 if isinstance(fip, AWSFloatingIP):
  1801. 1357 # pylint:disable=protected-access
  1802. 1358 aws_fip = fip._ip
  1803. 1359 else:
  1804. 1360 aws_fip = self.svc.get_raw(fip)
  1805. 1361 aws_fip.release()
  1806. Total time: 0 s
  1807. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1808. Function: label at line 81
  1809. Line # Hits Time Per Hit % Time Line Contents
  1810. ==============================================================
  1811. 81 @label.setter
  1812. 82 @profile
  1813. 83 def label(self, value):
  1814. 84 self.assert_valid_resource_label(value)
  1815. 85 self._vm_firewall.tags.update(Label=value or "")
  1816. 86 self._provider.azure_client.update_vm_firewall_tags(
  1817. 87 self.id, self._vm_firewall.tags)
  1818. Total time: 0 s
  1819. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1820. Function: description at line 93
  1821. Line # Hits Time Per Hit % Time Line Contents
  1822. ==============================================================
  1823. 93 @description.setter
  1824. 94 @profile
  1825. 95 def description(self, value):
  1826. 96 self._vm_firewall.tags.update(Description=value or "")
  1827. 97 self._provider.azure_client.\
  1828. 98 update_vm_firewall_tags(self.id,
  1829. 99 self._vm_firewall.tags)
  1830. Total time: 0 s
  1831. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1832. Function: refresh at line 105
  1833. Line # Hits Time Per Hit % Time Line Contents
  1834. ==============================================================
  1835. 105 @profile
  1836. 106 def refresh(self):
  1837. 107 """
  1838. 108 Refreshes the security group with tags if required.
  1839. 109 """
  1840. 110 try:
  1841. 111 self._vm_firewall = self._provider.azure_client. \
  1842. 112 get_vm_firewall(self.id)
  1843. 113 if not self._vm_firewall.tags:
  1844. 114 self._vm_firewall.tags = {}
  1845. 115 except (CloudError, ValueError) as cloud_error:
  1846. 116 log.exception(cloud_error.message)
  1847. Total time: 0 s
  1848. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1849. Function: refresh at line 265
  1850. Line # Hits Time Per Hit % Time Line Contents
  1851. ==============================================================
  1852. 265 @profile
  1853. 266 def refresh(self):
  1854. 267 self._key = self._provider.azure_client.get_blob(
  1855. 268 self._container.id, self._key.id)
  1856. Total time: 0 s
  1857. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1858. Function: label at line 354
  1859. Line # Hits Time Per Hit % Time Line Contents
  1860. ==============================================================
  1861. 354 @label.setter
  1862. 355 # pylint:disable=arguments-differ
  1863. 356 @profile
  1864. 357 def label(self, value):
  1865. 358 """
  1866. 359 Set the volume label.
  1867. 360 """
  1868. 361 self.assert_valid_resource_label(value)
  1869. 362 self._volume.tags.update(Label=value or "")
  1870. 363 self._provider.azure_client. \
  1871. 364 update_disk_tags(self.id,
  1872. 365 self._volume.tags)
  1873. Total time: 0 s
  1874. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1875. Function: description at line 371
  1876. Line # Hits Time Per Hit % Time Line Contents
  1877. ==============================================================
  1878. 371 @description.setter
  1879. 372 @profile
  1880. 373 def description(self, value):
  1881. 374 self._volume.tags.update(Description=value or "")
  1882. 375 self._provider.azure_client. \
  1883. 376 update_disk_tags(self.id,
  1884. 377 self._volume.tags)
  1885. Total time: 0 s
  1886. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1887. Function: refresh at line 452
  1888. Line # Hits Time Per Hit % Time Line Contents
  1889. ==============================================================
  1890. 452 @profile
  1891. 453 def refresh(self):
  1892. 454 """
  1893. 455 Refreshes the state of this volume by re-querying the cloud provider
  1894. 456 for its latest state.
  1895. 457 """
  1896. 458 try:
  1897. 459 self._volume = self._provider.azure_client. \
  1898. 460 get_disk(self.id)
  1899. 461 self._update_state()
  1900. 462 except (CloudError, ValueError) as cloud_error:
  1901. 463 log.exception(cloud_error.message)
  1902. 464 # The volume no longer exists and cannot be refreshed.
  1903. 465 # set the state to unknown
  1904. 466 self._state = 'unknown'
  1905. Total time: 0 s
  1906. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1907. Function: label at line 509
  1908. Line # Hits Time Per Hit % Time Line Contents
  1909. ==============================================================
  1910. 509 @label.setter
  1911. 510 # pylint:disable=arguments-differ
  1912. 511 @profile
  1913. 512 def label(self, value):
  1914. 513 """
  1915. 514 Set the snapshot label.
  1916. 515 """
  1917. 516 self.assert_valid_resource_label(value)
  1918. 517 self._snapshot.tags.update(Label=value or "")
  1919. 518 self._provider.azure_client. \
  1920. 519 update_snapshot_tags(self.id,
  1921. 520 self._snapshot.tags)
  1922. Total time: 0 s
  1923. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1924. Function: description at line 526
  1925. Line # Hits Time Per Hit % Time Line Contents
  1926. ==============================================================
  1927. 526 @description.setter
  1928. 527 @profile
  1929. 528 def description(self, value):
  1930. 529 self._snapshot.tags.update(Description=value or "")
  1931. 530 self._provider.azure_client. \
  1932. 531 update_snapshot_tags(self.id,
  1933. 532 self._snapshot.tags)
  1934. Total time: 0 s
  1935. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1936. Function: refresh at line 551
  1937. Line # Hits Time Per Hit % Time Line Contents
  1938. ==============================================================
  1939. 551 @profile
  1940. 552 def refresh(self):
  1941. 553 """
  1942. 554 Refreshes the state of this snapshot by re-querying the cloud provider
  1943. 555 for its latest state.
  1944. 556 """
  1945. 557 try:
  1946. 558 self._snapshot = self._provider.azure_client. \
  1947. 559 get_snapshot(self.id)
  1948. 560 self._state = self._snapshot.provisioning_state
  1949. 561 except (CloudError, ValueError) as cloud_error:
  1950. 562 log.exception(cloud_error.message)
  1951. 563 # The snapshot no longer exists and cannot be refreshed.
  1952. 564 # set the state to unknown
  1953. 565 self._state = 'unknown'
  1954. Total time: 0 s
  1955. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1956. Function: label at line 629
  1957. Line # Hits Time Per Hit % Time Line Contents
  1958. ==============================================================
  1959. 629 @label.setter
  1960. 630 @profile
  1961. 631 def label(self, value):
  1962. 632 """
  1963. 633 Set the image label when it is a private image.
  1964. 634 """
  1965. 635 if not self.is_gallery_image:
  1966. 636 self.assert_valid_resource_label(value)
  1967. 637 self._image.tags.update(Label=value or "")
  1968. 638 self._provider.azure_client. \
  1969. 639 update_image_tags(self.id, self._image.tags)
  1970. Total time: 0 s
  1971. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1972. Function: description at line 655
  1973. Line # Hits Time Per Hit % Time Line Contents
  1974. ==============================================================
  1975. 655 @description.setter
  1976. 656 @profile
  1977. 657 def description(self, value):
  1978. 658 """
  1979. 659 Set the image description.
  1980. 660 """
  1981. 661 if not self.is_gallery_image:
  1982. 662 self._image.tags.update(Description=value or "")
  1983. 663 self._provider.azure_client. \
  1984. 664 update_image_tags(self.id, self._image.tags)
  1985. Total time: 0 s
  1986. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  1987. Function: refresh at line 705
  1988. Line # Hits Time Per Hit % Time Line Contents
  1989. ==============================================================
  1990. 705 @profile
  1991. 706 def refresh(self):
  1992. 707 """
  1993. 708 Refreshes the state of this instance by re-querying the cloud provider
  1994. 709 for its latest state.
  1995. 710 """
  1996. 711 if not self.is_gallery_image:
  1997. 712 try:
  1998. 713 self._image = self._provider.azure_client.get_image(self.id)
  1999. 714 self._state = self._image.provisioning_state
  2000. 715 except CloudError as cloud_error:
  2001. 716 log.exception(cloud_error.message)
  2002. 717 # image no longer exists
  2003. 718 self._state = "unknown"
  2004. Total time: 0 s
  2005. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2006. Function: label at line 757
  2007. Line # Hits Time Per Hit % Time Line Contents
  2008. ==============================================================
  2009. 757 @label.setter
  2010. 758 # pylint:disable=arguments-differ
  2011. 759 @profile
  2012. 760 def label(self, value):
  2013. 761 """
  2014. 762 Set the network label.
  2015. 763 """
  2016. 764 self.assert_valid_resource_label(value)
  2017. 765 self._network.tags.update(Label=value or "")
  2018. 766 self._provider.azure_client. \
  2019. 767 update_network_tags(self.id, self._network)
  2020. Total time: 0 s
  2021. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2022. Function: refresh at line 782
  2023. Line # Hits Time Per Hit % Time Line Contents
  2024. ==============================================================
  2025. 782 @profile
  2026. 783 def refresh(self):
  2027. 784 """
  2028. 785 Refreshes the state of this network by re-querying the cloud provider
  2029. 786 for its latest state.
  2030. 787 """
  2031. 788 try:
  2032. 789 self._network = self._provider.azure_client.\
  2033. 790 get_network(self.id)
  2034. 791 self._state = self._network.provisioning_state
  2035. 792 except (CloudError, ValueError) as cloud_error:
  2036. 793 log.exception(cloud_error.message)
  2037. 794 # The network no longer exists and cannot be refreshed.
  2038. 795 # set the state to unknown
  2039. 796 self._state = 'unknown'
  2040. Total time: 0 s
  2041. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2042. Function: refresh at line 852
  2043. Line # Hits Time Per Hit % Time Line Contents
  2044. ==============================================================
  2045. 852 @profile
  2046. 853 def refresh(self):
  2047. 854 # Gateway is not needed as it doesn't exist in Azure, so just
  2048. 855 # getting the Floating IP again from the client
  2049. 856 # pylint:disable=protected-access
  2050. 857 fip = self._provider.networking._floating_ips.get(None, self.id)
  2051. 858 # pylint:disable=protected-access
  2052. 859 self._ip = fip._ip
  2053. Total time: 0 s
  2054. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2055. Function: label at line 957
  2056. Line # Hits Time Per Hit % Time Line Contents
  2057. ==============================================================
  2058. 957 @label.setter
  2059. 958 # pylint:disable=arguments-differ
  2060. 959 @profile
  2061. 960 def label(self, value):
  2062. 961 self.assert_valid_resource_label(value)
  2063. 962 network = self.network
  2064. 963 # pylint:disable=protected-access
  2065. 964 az_network = network._network
  2066. 965 kwargs = {self.tag_name: value or ""}
  2067. 966 az_network.tags.update(**kwargs)
  2068. 967 self._provider.azure_client.update_network_tags(
  2069. 968 az_network.id, az_network)
  2070. Total time: 0 s
  2071. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2072. Function: refresh at line 999
  2073. Line # Hits Time Per Hit % Time Line Contents
  2074. ==============================================================
  2075. 999 @profile
  2076. 1000 def refresh(self):
  2077. 1001 """
  2078. 1002 Refreshes the state of this network by re-querying the cloud provider
  2079. 1003 for its latest state.
  2080. 1004 """
  2081. 1005 try:
  2082. 1006 self._subnet = self._provider.azure_client. \
  2083. 1007 get_subnet(self.id)
  2084. 1008 self._state = self._subnet.provisioning_state
  2085. 1009 except (CloudError, ValueError) as cloud_error:
  2086. 1010 log.exception(cloud_error.message)
  2087. 1011 # The subnet no longer exists and cannot be refreshed.
  2088. 1012 # set the state to unknown
  2089. 1013 self._state = 'unknown'
  2090. Total time: 0 s
  2091. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2092. Function: label at line 1086
  2093. Line # Hits Time Per Hit % Time Line Contents
  2094. ==============================================================
  2095. 1086 @label.setter
  2096. 1087 # pylint:disable=arguments-differ
  2097. 1088 @profile
  2098. 1089 def label(self, value):
  2099. 1090 """
  2100. 1091 Set the instance label.
  2101. 1092 """
  2102. 1093 self.assert_valid_resource_label(value)
  2103. 1094 self._vm.tags.update(Label=value or "")
  2104. 1095 self._provider.azure_client. \
  2105. 1096 update_vm_tags(self.id, self._vm)
  2106. Total time: 0 s
  2107. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2108. Function: refresh at line 1340
  2109. Line # Hits Time Per Hit % Time Line Contents
  2110. ==============================================================
  2111. 1340 @profile
  2112. 1341 def refresh(self):
  2113. 1342 """
  2114. 1343 Refreshes the state of this instance by re-querying the cloud provider
  2115. 1344 for its latest state.
  2116. 1345 """
  2117. 1346 try:
  2118. 1347 self._vm = self._provider.azure_client.get_vm(self.id)
  2119. 1348 if not self._vm.tags:
  2120. 1349 self._vm.tags = {}
  2121. 1350 self._update_state()
  2122. 1351 except (CloudError, ValueError) as cloud_error:
  2123. 1352 log.exception(cloud_error.message)
  2124. 1353 # The volume no longer exists and cannot be refreshed.
  2125. 1354 # set the state to unknown
  2126. 1355 self._state = 'unknown'
  2127. Total time: 0 s
  2128. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2129. Function: label at line 1461
  2130. Line # Hits Time Per Hit % Time Line Contents
  2131. ==============================================================
  2132. 1461 @label.setter
  2133. 1462 # pylint:disable=arguments-differ
  2134. 1463 @profile
  2135. 1464 def label(self, value):
  2136. 1465 """
  2137. 1466 Set the router label.
  2138. 1467 """
  2139. 1468 self.assert_valid_resource_label(value)
  2140. 1469 self._route_table.tags.update(Label=value or "")
  2141. 1470 self._provider.azure_client. \
  2142. 1471 update_route_table_tags(self._route_table.name,
  2143. 1472 self._route_table)
  2144. Total time: 0 s
  2145. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2146. Function: refresh at line 1474
  2147. Line # Hits Time Per Hit % Time Line Contents
  2148. ==============================================================
  2149. 1474 @profile
  2150. 1475 def refresh(self):
  2151. 1476 self._route_table = self._provider.azure_client. \
  2152. 1477 get_route_table(self._route_table.name)
  2153. Total time: 0 s
  2154. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/resources.py
  2155. Function: refresh at line 1533
  2156. Line # Hits Time Per Hit % Time Line Contents
  2157. ==============================================================
  2158. 1533 @profile
  2159. 1534 def refresh(self):
  2160. 1535 pass
  2161. Total time: 0 s
  2162. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2163. Function: get at line 93
  2164. Line # Hits Time Per Hit % Time Line Contents
  2165. ==============================================================
  2166. 93 @dispatch(event="provider.security.vm_firewalls.get",
  2167. 94 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  2168. 95 @profile
  2169. 96 def get(self, vm_firewall_id):
  2170. 97 try:
  2171. 98 fws = self.provider.azure_client.get_vm_firewall(vm_firewall_id)
  2172. 99 return AzureVMFirewall(self.provider, fws)
  2173. 100 except (CloudError, InvalidValueException) as cloud_error:
  2174. 101 # Azure raises the cloud error if the resource not available
  2175. 102 log.exception(cloud_error)
  2176. 103 return None
  2177. Total time: 0 s
  2178. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2179. Function: list at line 105
  2180. Line # Hits Time Per Hit % Time Line Contents
  2181. ==============================================================
  2182. 105 @dispatch(event="provider.security.vm_firewalls.list",
  2183. 106 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  2184. 107 @profile
  2185. 108 def list(self, limit=None, marker=None):
  2186. 109 fws = [AzureVMFirewall(self.provider, fw)
  2187. 110 for fw in self.provider.azure_client.list_vm_firewall()]
  2188. 111 return ClientPagedResultList(self.provider, fws, limit, marker)
  2189. Total time: 0 s
  2190. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2191. Function: create at line 113
  2192. Line # Hits Time Per Hit % Time Line Contents
  2193. ==============================================================
  2194. 113 @cb_helpers.deprecated_alias(network_id='network')
  2195. 114 @dispatch(event="provider.security.vm_firewalls.create",
  2196. 115 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  2197. 116 @profile
  2198. 117 def create(self, label, network, description=None):
  2199. 118 AzureVMFirewall.assert_valid_resource_label(label)
  2200. 119 name = AzureVMFirewall._generate_name_from_label(label, "cb-fw")
  2201. 120 net = network.id if isinstance(network, Network) else network
  2202. 121 parameters = {"location": self.provider.region_name,
  2203. 122 "tags": {'Label': label,
  2204. 123 'network_id': net}}
  2205. 124
  2206. 125 if description:
  2207. 126 parameters['tags'].update(Description=description)
  2208. 127
  2209. 128 fw = self.provider.azure_client.create_vm_firewall(name,
  2210. 129 parameters)
  2211. 130
  2212. 131 # Add default rules to negate azure default rules.
  2213. 132 # See: https://github.com/CloudVE/cloudbridge/issues/106
  2214. 133 # pylint:disable=protected-access
  2215. 134 for rule in fw.default_security_rules:
  2216. 135 rule_name = "cb-override-" + rule.name
  2217. 136 # Transpose rules to priority 4001 onwards, because
  2218. 137 # only 0-4096 are allowed for custom rules
  2219. 138 rule.priority = rule.priority - 61440
  2220. 139 rule.access = "Deny"
  2221. 140 self.provider.azure_client.create_vm_firewall_rule(
  2222. 141 fw.id, rule_name, rule)
  2223. 142
  2224. 143 # Add a new custom rule allowing all outbound traffic to the internet
  2225. 144 parameters = {"priority": 3000,
  2226. 145 "protocol": "*",
  2227. 146 "source_port_range": "*",
  2228. 147 "source_address_prefix": "*",
  2229. 148 "destination_port_range": "*",
  2230. 149 "destination_address_prefix": "Internet",
  2231. 150 "access": "Allow",
  2232. 151 "direction": "Outbound"}
  2233. 152 result = self.provider.azure_client.create_vm_firewall_rule(
  2234. 153 fw.id, "cb-default-internet-outbound", parameters)
  2235. 154 fw.security_rules.append(result)
  2236. 155
  2237. 156 cb_fw = AzureVMFirewall(self.provider, fw)
  2238. 157 return cb_fw
  2239. Total time: 0 s
  2240. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2241. Function: delete at line 159
  2242. Line # Hits Time Per Hit % Time Line Contents
  2243. ==============================================================
  2244. 159 @dispatch(event="provider.security.vm_firewalls.delete",
  2245. 160 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  2246. 161 @profile
  2247. 162 def delete(self, vm_firewall):
  2248. 163 fw_id = (vm_firewall.id if isinstance(vm_firewall, AzureVMFirewall)
  2249. 164 else vm_firewall)
  2250. 165 self.provider.azure_client.delete_vm_firewall(fw_id)
  2251. Total time: 0 s
  2252. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2253. Function: list at line 173
  2254. Line # Hits Time Per Hit % Time Line Contents
  2255. ==============================================================
  2256. 173 @dispatch(event="provider.security.vm_firewall_rules.list",
  2257. 174 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  2258. 175 @profile
  2259. 176 def list(self, firewall, limit=None, marker=None):
  2260. 177 # Filter out firewall rules with priority < 3500 because values
  2261. 178 # between 3500 and 4096 are assumed to be owned by cloudbridge
  2262. 179 # default rules.
  2263. 180 # pylint:disable=protected-access
  2264. 181 rules = [AzureVMFirewallRule(firewall, rule) for rule
  2265. 182 in firewall._vm_firewall.security_rules
  2266. 183 if rule.priority < 3500]
  2267. 184 return ClientPagedResultList(self.provider, rules,
  2268. 185 limit=limit, marker=marker)
  2269. Total time: 0 s
  2270. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2271. Function: create at line 187
  2272. Line # Hits Time Per Hit % Time Line Contents
  2273. ==============================================================
  2274. 187 @dispatch(event="provider.security.vm_firewall_rules.create",
  2275. 188 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  2276. 189 @profile
  2277. 190 def create(self, firewall, direction, protocol=None, from_port=None,
  2278. 191 to_port=None, cidr=None, src_dest_fw=None):
  2279. 192 if protocol and from_port and to_port:
  2280. 193 return self._create_rule(firewall, direction, protocol, from_port,
  2281. 194 to_port, cidr)
  2282. 195 elif src_dest_fw:
  2283. 196 result = None
  2284. 197 fw = (self.provider.security.vm_firewalls.get(src_dest_fw)
  2285. 198 if isinstance(src_dest_fw, str) else src_dest_fw)
  2286. 199 for rule in fw.rules:
  2287. 200 result = self._create_rule(
  2288. 201 rule.direction, rule.protocol, rule.from_port,
  2289. 202 rule.to_port, rule.cidr)
  2290. 203 return result
  2291. 204 else:
  2292. 205 return None
  2293. Total time: 0 s
  2294. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2295. Function: delete at line 238
  2296. Line # Hits Time Per Hit % Time Line Contents
  2297. ==============================================================
  2298. 238 @dispatch(event="provider.security.vm_firewall_rules.delete",
  2299. 239 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  2300. 240 @profile
  2301. 241 def delete(self, firewall, rule):
  2302. 242 rule_id = rule.id if isinstance(rule, AzureVMFirewallRule) else rule
  2303. 243 fw_name = firewall.name
  2304. 244 self.provider.azure_client. \
  2305. 245 delete_vm_firewall_rule(rule_id, fw_name)
  2306. 246 for i, o in enumerate(firewall._vm_firewall.security_rules):
  2307. 247 if o.id == rule_id:
  2308. 248 # pylint:disable=protected-access
  2309. 249 del firewall._vm_firewall.security_rules[i]
  2310. 250 break
  2311. Total time: 0 s
  2312. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2313. Function: get at line 259
  2314. Line # Hits Time Per Hit % Time Line Contents
  2315. ==============================================================
  2316. 259 @dispatch(event="provider.security.key_pairs.get",
  2317. 260 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  2318. 261 @profile
  2319. 262 def get(self, key_pair_id):
  2320. 263 try:
  2321. 264 key_pair = self.provider.azure_client.\
  2322. 265 get_public_key(key_pair_id)
  2323. 266
  2324. 267 if key_pair:
  2325. 268 return AzureKeyPair(self.provider, key_pair)
  2326. 269 return None
  2327. 270 except AzureException as error:
  2328. 271 log.debug("KeyPair %s was not found.", key_pair_id)
  2329. 272 log.debug(error)
  2330. 273 return None
  2331. Total time: 0 s
  2332. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2333. Function: list at line 275
  2334. Line # Hits Time Per Hit % Time Line Contents
  2335. ==============================================================
  2336. 275 @dispatch(event="provider.security.key_pairs.list",
  2337. 276 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  2338. 277 @profile
  2339. 278 def list(self, limit=None, marker=None):
  2340. 279 key_pairs, resume_marker = self.provider.azure_client.list_public_keys(
  2341. 280 AzureKeyPairService.PARTITION_KEY, marker=marker,
  2342. 281 limit=limit or self.provider.config.default_result_limit)
  2343. 282 results = [AzureKeyPair(self.provider, key_pair)
  2344. 283 for key_pair in key_pairs]
  2345. 284 return ServerPagedResultList(is_truncated=resume_marker,
  2346. 285 marker=resume_marker,
  2347. 286 supports_total=False,
  2348. 287 data=results)
  2349. Total time: 0 s
  2350. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2351. Function: find at line 289
  2352. Line # Hits Time Per Hit % Time Line Contents
  2353. ==============================================================
  2354. 289 @dispatch(event="provider.security.key_pairs.find",
  2355. 290 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  2356. 291 @profile
  2357. 292 def find(self, **kwargs):
  2358. 293 obj_list = self
  2359. 294 filters = ['name']
  2360. 295 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2361. 296
  2362. 297 # All kwargs should have been popped at this time.
  2363. 298 if len(kwargs) > 0:
  2364. 299 raise InvalidParamException(
  2365. 300 "Unrecognised parameters for search: %s. Supported "
  2366. 301 "attributes: %s" % (kwargs, ", ".join(filters)))
  2367. 302
  2368. 303 return ClientPagedResultList(self.provider,
  2369. 304 matches if matches else [])
  2370. Total time: 0 s
  2371. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2372. Function: create at line 306
  2373. Line # Hits Time Per Hit % Time Line Contents
  2374. ==============================================================
  2375. 306 @dispatch(event="provider.security.key_pairs.create",
  2376. 307 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  2377. 308 @profile
  2378. 309 def create(self, name, public_key_material=None):
  2379. 310 AzureKeyPair.assert_valid_resource_name(name)
  2380. 311 key_pair = self.get(name)
  2381. 312
  2382. 313 if key_pair:
  2383. 314 raise DuplicateResourceException(
  2384. 315 'Keypair already exists with name {0}'.format(name))
  2385. 316
  2386. 317 private_key = None
  2387. 318 if not public_key_material:
  2388. 319 public_key_material, private_key = cb_helpers.generate_key_pair()
  2389. 320
  2390. 321 entity = {
  2391. 322 'PartitionKey': AzureKeyPairService.PARTITION_KEY,
  2392. 323 'RowKey': str(uuid.uuid4()),
  2393. 324 'Name': name,
  2394. 325 'Key': public_key_material
  2395. 326 }
  2396. 327
  2397. 328 self.provider.azure_client.create_public_key(entity)
  2398. 329 key_pair = self.get(name)
  2399. 330 key_pair.material = private_key
  2400. 331 return key_pair
  2401. Total time: 0 s
  2402. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2403. Function: delete at line 333
  2404. Line # Hits Time Per Hit % Time Line Contents
  2405. ==============================================================
  2406. 333 @dispatch(event="provider.security.key_pairs.delete",
  2407. 334 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  2408. 335 @profile
  2409. 336 def delete(self, key_pair):
  2410. 337 key_pair = (key_pair if isinstance(key_pair, AzureKeyPair) else
  2411. 338 self.get(key_pair))
  2412. 339 if key_pair:
  2413. 340 # pylint:disable=protected-access
  2414. 341 self.provider.azure_client.delete_public_key(key_pair._key_pair)
  2415. Total time: 0 s
  2416. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2417. Function: get at line 375
  2418. Line # Hits Time Per Hit % Time Line Contents
  2419. ==============================================================
  2420. 375 @dispatch(event="provider.storage.volumes.get",
  2421. 376 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  2422. 377 @profile
  2423. 378 def get(self, volume_id):
  2424. 379 try:
  2425. 380 volume = self.provider.azure_client.get_disk(volume_id)
  2426. 381 return AzureVolume(self.provider, volume)
  2427. 382 except (CloudError, InvalidValueException) as cloud_error:
  2428. 383 # Azure raises the cloud error if the resource not available
  2429. 384 log.exception(cloud_error)
  2430. 385 return None
  2431. Total time: 0 s
  2432. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2433. Function: find at line 387
  2434. Line # Hits Time Per Hit % Time Line Contents
  2435. ==============================================================
  2436. 387 @dispatch(event="provider.storage.volumes.find",
  2437. 388 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  2438. 389 @profile
  2439. 390 def find(self, **kwargs):
  2440. 391 obj_list = self
  2441. 392 filters = ['label']
  2442. 393 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2443. 394
  2444. 395 # All kwargs should have been popped at this time.
  2445. 396 if len(kwargs) > 0:
  2446. 397 raise InvalidParamException(
  2447. 398 "Unrecognised parameters for search: %s. Supported "
  2448. 399 "attributes: %s" % (kwargs, ", ".join(filters)))
  2449. 400
  2450. 401 return ClientPagedResultList(self.provider,
  2451. 402 matches if matches else [])
  2452. Total time: 0 s
  2453. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2454. Function: list at line 404
  2455. Line # Hits Time Per Hit % Time Line Contents
  2456. ==============================================================
  2457. 404 @dispatch(event="provider.storage.volumes.list",
  2458. 405 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  2459. 406 @profile
  2460. 407 def list(self, limit=None, marker=None):
  2461. 408 azure_vols = self.provider.azure_client.list_disks()
  2462. 409 cb_vols = [AzureVolume(self.provider, vol) for vol in azure_vols]
  2463. 410 return ClientPagedResultList(self.provider, cb_vols,
  2464. 411 limit=limit, marker=marker)
  2465. Total time: 0 s
  2466. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2467. Function: create at line 413
  2468. Line # Hits Time Per Hit % Time Line Contents
  2469. ==============================================================
  2470. 413 @dispatch(event="provider.storage.volumes.create",
  2471. 414 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  2472. 415 @profile
  2473. 416 def create(self, label, size, zone, snapshot=None, description=None):
  2474. 417 AzureVolume.assert_valid_resource_label(label)
  2475. 418 disk_name = AzureVolume._generate_name_from_label(label, "cb-vol")
  2476. 419 tags = {'Label': label}
  2477. 420
  2478. 421 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  2479. 422 snapshot = (self.provider.storage.snapshots.get(snapshot)
  2480. 423 if snapshot and isinstance(snapshot, str) else snapshot)
  2481. 424
  2482. 425 if description:
  2483. 426 tags.update(Description=description)
  2484. 427
  2485. 428 if snapshot:
  2486. 429 params = {
  2487. 430 'location':
  2488. 431 zone_id or self.provider.azure_client.region_name,
  2489. 432 'creation_data': {
  2490. 433 'create_option': DiskCreateOption.copy,
  2491. 434 'source_uri': snapshot.resource_id
  2492. 435 },
  2493. 436 'tags': tags
  2494. 437 }
  2495. 438
  2496. 439 disk = self.provider.azure_client.create_snapshot_disk(disk_name,
  2497. 440 params)
  2498. 441
  2499. 442 else:
  2500. 443 params = {
  2501. 444 'location':
  2502. 445 zone_id or self.provider.region_name,
  2503. 446 'disk_size_gb': size,
  2504. 447 'creation_data': {
  2505. 448 'create_option': DiskCreateOption.empty
  2506. 449 },
  2507. 450 'tags': tags
  2508. 451 }
  2509. 452
  2510. 453 disk = self.provider.azure_client.create_empty_disk(disk_name,
  2511. 454 params)
  2512. 455
  2513. 456 azure_vol = self.provider.azure_client.get_disk(disk.id)
  2514. 457 cb_vol = AzureVolume(self.provider, azure_vol)
  2515. 458
  2516. 459 return cb_vol
  2517. Total time: 0 s
  2518. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2519. Function: delete at line 461
  2520. Line # Hits Time Per Hit % Time Line Contents
  2521. ==============================================================
  2522. 461 @dispatch(event="provider.storage.volumes.delete",
  2523. 462 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  2524. 463 @profile
  2525. 464 def delete(self, volume_id):
  2526. 465 vol_id = (volume_id.id if isinstance(volume_id, AzureVolume)
  2527. 466 else volume_id)
  2528. 467 self.provider.azure_client.delete_disk(vol_id)
  2529. Total time: 0 s
  2530. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2531. Function: get at line 474
  2532. Line # Hits Time Per Hit % Time Line Contents
  2533. ==============================================================
  2534. 474 @dispatch(event="provider.storage.snapshots.get",
  2535. 475 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  2536. 476 @profile
  2537. 477 def get(self, snapshot_id):
  2538. 478 try:
  2539. 479 snapshot = self.provider.azure_client.get_snapshot(snapshot_id)
  2540. 480 return AzureSnapshot(self.provider, snapshot)
  2541. 481 except (CloudError, InvalidValueException) as cloud_error:
  2542. 482 # Azure raises the cloud error if the resource not available
  2543. 483 log.exception(cloud_error)
  2544. 484 return None
  2545. Total time: 0 s
  2546. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2547. Function: find at line 486
  2548. Line # Hits Time Per Hit % Time Line Contents
  2549. ==============================================================
  2550. 486 @dispatch(event="provider.storage.snapshots.find",
  2551. 487 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  2552. 488 @profile
  2553. 489 def find(self, **kwargs):
  2554. 490 obj_list = self
  2555. 491 filters = ['label']
  2556. 492 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2557. 493
  2558. 494 # All kwargs should have been popped at this time.
  2559. 495 if len(kwargs) > 0:
  2560. 496 raise InvalidParamException(
  2561. 497 "Unrecognised parameters for search: %s. Supported "
  2562. 498 "attributes: %s" % (kwargs, ", ".join(filters)))
  2563. 499
  2564. 500 return ClientPagedResultList(self.provider,
  2565. 501 matches if matches else [])
  2566. Total time: 0 s
  2567. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2568. Function: list at line 503
  2569. Line # Hits Time Per Hit % Time Line Contents
  2570. ==============================================================
  2571. 503 @dispatch(event="provider.storage.snapshots.list",
  2572. 504 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  2573. 505 @profile
  2574. 506 def list(self, limit=None, marker=None):
  2575. 507 snaps = [AzureSnapshot(self.provider, obj)
  2576. 508 for obj in
  2577. 509 self.provider.azure_client.list_snapshots()]
  2578. 510 return ClientPagedResultList(self.provider, snaps, limit, marker)
  2579. Total time: 0 s
  2580. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2581. Function: create at line 512
  2582. Line # Hits Time Per Hit % Time Line Contents
  2583. ==============================================================
  2584. 512 @dispatch(event="provider.storage.snapshots.create",
  2585. 513 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  2586. 514 @profile
  2587. 515 def create(self, label, volume, description=None):
  2588. 516 AzureSnapshot.assert_valid_resource_label(label)
  2589. 517 snapshot_name = AzureSnapshot._generate_name_from_label(label,
  2590. 518 "cb-snap")
  2591. 519 tags = {'Label': label}
  2592. 520 if description:
  2593. 521 tags.update(Description=description)
  2594. 522
  2595. 523 volume = (self.provider.storage.volumes.get(volume)
  2596. 524 if isinstance(volume, str) else volume)
  2597. 525
  2598. 526 params = {
  2599. 527 'location': self.provider.azure_client.region_name,
  2600. 528 'creation_data': {
  2601. 529 'create_option': DiskCreateOption.copy,
  2602. 530 'source_uri': volume.resource_id
  2603. 531 },
  2604. 532 'disk_size_gb': volume.size,
  2605. 533 'tags': tags
  2606. 534 }
  2607. 535
  2608. 536 azure_snap = self.provider.azure_client.create_snapshot(snapshot_name,
  2609. 537 params)
  2610. 538 return AzureSnapshot(self.provider, azure_snap)
  2611. Total time: 0 s
  2612. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2613. Function: delete at line 540
  2614. Line # Hits Time Per Hit % Time Line Contents
  2615. ==============================================================
  2616. 540 @dispatch(event="provider.storage.snapshots.delete",
  2617. 541 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  2618. 542 @profile
  2619. 543 def delete(self, snapshot_id):
  2620. 544 snap_id = (snapshot_id.id if isinstance(snapshot_id, AzureSnapshot)
  2621. 545 else snapshot_id)
  2622. 546 self.provider.azure_client.delete_snapshot(snap_id)
  2623. Total time: 0 s
  2624. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2625. Function: get at line 553
  2626. Line # Hits Time Per Hit % Time Line Contents
  2627. ==============================================================
  2628. 553 @dispatch(event="provider.storage.buckets.get",
  2629. 554 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  2630. 555 @profile
  2631. 556 def get(self, bucket_id):
  2632. 557 """
  2633. 558 Returns a bucket given its ID. Returns ``None`` if the bucket
  2634. 559 does not exist.
  2635. 560 """
  2636. 561 try:
  2637. 562 bucket = self.provider.azure_client.get_container(bucket_id)
  2638. 563 return AzureBucket(self.provider, bucket)
  2639. 564 except AzureException as error:
  2640. 565 log.exception(error)
  2641. 566 return None
  2642. Total time: 0 s
  2643. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2644. Function: list at line 568
  2645. Line # Hits Time Per Hit % Time Line Contents
  2646. ==============================================================
  2647. 568 @dispatch(event="provider.storage.buckets.list",
  2648. 569 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  2649. 570 @profile
  2650. 571 def list(self, limit=None, marker=None):
  2651. 572 buckets = [AzureBucket(self.provider, bucket)
  2652. 573 for bucket
  2653. 574 in self.provider.azure_client.list_containers()[0]]
  2654. 575 return ClientPagedResultList(self.provider, buckets,
  2655. 576 limit=limit, marker=marker)
  2656. Total time: 0 s
  2657. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2658. Function: create at line 578
  2659. Line # Hits Time Per Hit % Time Line Contents
  2660. ==============================================================
  2661. 578 @dispatch(event="provider.storage.buckets.create",
  2662. 579 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  2663. 580 @profile
  2664. 581 def create(self, name, location=None):
  2665. 582 """
  2666. 583 Create a new bucket.
  2667. 584 """
  2668. 585 AzureBucket.assert_valid_resource_name(name)
  2669. 586 bucket = self.provider.azure_client.create_container(name)
  2670. 587 return AzureBucket(self.provider, bucket)
  2671. Total time: 0 s
  2672. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2673. Function: delete at line 589
  2674. Line # Hits Time Per Hit % Time Line Contents
  2675. ==============================================================
  2676. 589 @dispatch(event="provider.storage.buckets.delete",
  2677. 590 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  2678. 591 @profile
  2679. 592 def delete(self, bucket):
  2680. 593 """
  2681. 594 Delete this bucket.
  2682. 595 """
  2683. 596 b_id = bucket.id if isinstance(bucket, AzureBucket) else bucket
  2684. 597 self.provider.azure_client.delete_container(b_id)
  2685. Total time: 0 s
  2686. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2687. Function: get at line 604
  2688. Line # Hits Time Per Hit % Time Line Contents
  2689. ==============================================================
  2690. 604 @profile
  2691. 605 def get(self, bucket, object_id):
  2692. 606 """
  2693. 607 Retrieve a given object from this bucket.
  2694. 608 """
  2695. 609 try:
  2696. 610 obj = self.provider.azure_client.get_blob(bucket.name,
  2697. 611 object_id)
  2698. 612 return AzureBucketObject(self.provider, bucket, obj)
  2699. 613 except AzureException as azureEx:
  2700. 614 log.exception(azureEx)
  2701. 615 return None
  2702. Total time: 0 s
  2703. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2704. Function: list at line 617
  2705. Line # Hits Time Per Hit % Time Line Contents
  2706. ==============================================================
  2707. 617 @profile
  2708. 618 def list(self, bucket, limit=None, marker=None, prefix=None):
  2709. 619 """
  2710. 620 List all objects within this bucket.
  2711. 621
  2712. 622 :rtype: BucketObject
  2713. 623 :return: List of all available BucketObjects within this bucket.
  2714. 624 """
  2715. 625 objects = [AzureBucketObject(self.provider, bucket, obj)
  2716. 626 for obj in
  2717. 627 self.provider.azure_client.list_blobs(
  2718. 628 bucket.name, prefix=prefix)]
  2719. 629 return ClientPagedResultList(self.provider, objects,
  2720. 630 limit=limit, marker=marker)
  2721. Total time: 0 s
  2722. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2723. Function: find at line 632
  2724. Line # Hits Time Per Hit % Time Line Contents
  2725. ==============================================================
  2726. 632 @profile
  2727. 633 def find(self, bucket, **kwargs):
  2728. 634 obj_list = [AzureBucketObject(self.provider, bucket, obj)
  2729. 635 for obj in
  2730. 636 self.provider.azure_client.list_blobs(bucket.name)]
  2731. 637 filters = ['name']
  2732. 638 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2733. 639 return ClientPagedResultList(self.provider, list(matches))
  2734. Total time: 0 s
  2735. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2736. Function: create at line 641
  2737. Line # Hits Time Per Hit % Time Line Contents
  2738. ==============================================================
  2739. 641 @profile
  2740. 642 def create(self, bucket, name):
  2741. 643 self.provider.azure_client.create_blob_from_text(
  2742. 644 bucket.name, name, '')
  2743. 645 return self.get(bucket, name)
  2744. Total time: 0 s
  2745. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2746. Function: get at line 677
  2747. Line # Hits Time Per Hit % Time Line Contents
  2748. ==============================================================
  2749. 677 @profile
  2750. 678 def get(self, image_id):
  2751. 679 """
  2752. 680 Returns an Image given its id
  2753. 681 """
  2754. 682 try:
  2755. 683 image = self.provider.azure_client.get_image(image_id)
  2756. 684 return AzureMachineImage(self.provider, image)
  2757. 685 except (CloudError, InvalidValueException) as cloud_error:
  2758. 686 # Azure raises the cloud error if the resource not available
  2759. 687 log.exception(cloud_error)
  2760. 688 return None
  2761. Total time: 0 s
  2762. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2763. Function: find at line 690
  2764. Line # Hits Time Per Hit % Time Line Contents
  2765. ==============================================================
  2766. 690 @profile
  2767. 691 def find(self, **kwargs):
  2768. 692 obj_list = self
  2769. 693 filters = ['label']
  2770. 694 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2771. 695
  2772. 696 # All kwargs should have been popped at this time.
  2773. 697 if len(kwargs) > 0:
  2774. 698 raise InvalidParamException(
  2775. 699 "Unrecognised parameters for search: %s. Supported "
  2776. 700 "attributes: %s" % (kwargs, ", ".join(filters)))
  2777. 701
  2778. 702 return ClientPagedResultList(self.provider,
  2779. 703 matches if matches else [])
  2780. Total time: 0 s
  2781. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2782. Function: list at line 705
  2783. Line # Hits Time Per Hit % Time Line Contents
  2784. ==============================================================
  2785. 705 @profile
  2786. 706 def list(self, filter_by_owner=True, limit=None, marker=None):
  2787. 707 """
  2788. 708 List all images.
  2789. 709 """
  2790. 710 azure_images = self.provider.azure_client.list_images()
  2791. 711 azure_gallery_refs = self.provider.azure_client.list_gallery_refs() \
  2792. 712 if not filter_by_owner else []
  2793. 713 cb_images = [AzureMachineImage(self.provider, img)
  2794. 714 for img in azure_images + azure_gallery_refs]
  2795. 715 return ClientPagedResultList(self.provider, cb_images,
  2796. 716 limit=limit, marker=marker)
  2797. Total time: 0 s
  2798. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2799. Function: create_launch_config at line 859
  2800. Line # Hits Time Per Hit % Time Line Contents
  2801. ==============================================================
  2802. 859 @profile
  2803. 860 def create_launch_config(self):
  2804. 861 return AzureLaunchConfig(self.provider)
  2805. Total time: 0 s
  2806. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2807. Function: create at line 863
  2808. Line # Hits Time Per Hit % Time Line Contents
  2809. ==============================================================
  2810. 863 @dispatch(event="provider.compute.instances.create",
  2811. 864 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  2812. 865 @profile
  2813. 866 def create(self, label, image, vm_type, subnet, zone,
  2814. 867 key_pair=None, vm_firewalls=None, user_data=None,
  2815. 868 launch_config=None, **kwargs):
  2816. 869 AzureInstance.assert_valid_resource_label(label)
  2817. 870 instance_name = AzureInstance._generate_name_from_label(label,
  2818. 871 "cb-ins")
  2819. 872
  2820. 873 image = (image if isinstance(image, AzureMachineImage) else
  2821. 874 self.provider.compute.images.get(image))
  2822. 875 if not isinstance(image, AzureMachineImage):
  2823. 876 raise Exception("Provided image %s is not a valid azure image"
  2824. 877 % image)
  2825. 878
  2826. 879 instance_size = vm_type.id if \
  2827. 880 isinstance(vm_type, VMType) else vm_type
  2828. 881
  2829. 882 if not subnet:
  2830. 883 # Azure has only a single zone per region; use the current one
  2831. 884 zone = self.provider.compute.regions.get(
  2832. 885 self.provider.region_name).zones[0]
  2833. 886 subnet = self.provider.networking.subnets.get_or_create_default(
  2834. 887 zone)
  2835. 888 else:
  2836. 889 subnet = (self.provider.networking.subnets.get(subnet)
  2837. 890 if isinstance(subnet, str) else subnet)
  2838. 891
  2839. 892 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  2840. 893
  2841. 894 subnet_id, zone_id, vm_firewall_id = \
  2842. 895 self._resolve_launch_options(instance_name,
  2843. 896 subnet, zone_id, vm_firewalls)
  2844. 897
  2845. 898 storage_profile = self._create_storage_profile(image, launch_config,
  2846. 899 instance_name, zone_id)
  2847. 900
  2848. 901 nic_params = {
  2849. 902 'location': self.provider.region_name,
  2850. 903 'ip_configurations': [{
  2851. 904 'name': instance_name + '_ip_config',
  2852. 905 'private_ip_allocation_method': 'Dynamic',
  2853. 906 'subnet': {
  2854. 907 'id': subnet_id
  2855. 908 }
  2856. 909 }]
  2857. 910 }
  2858. 911
  2859. 912 if vm_firewall_id:
  2860. 913 nic_params['network_security_group'] = {
  2861. 914 'id': vm_firewall_id
  2862. 915 }
  2863. 916 nic_info = self.provider.azure_client.create_nic(
  2864. 917 instance_name + '_nic',
  2865. 918 nic_params
  2866. 919 )
  2867. 920 # #! indicates shell script
  2868. 921 ud = '#cloud-config\n' + user_data \
  2869. 922 if user_data and not user_data.startswith('#!')\
  2870. 923 and not user_data.startswith('#cloud-config') else user_data
  2871. 924
  2872. 925 # Key_pair is mandatory in azure and it should not be None.
  2873. 926 temp_key_pair = None
  2874. 927 if key_pair:
  2875. 928 key_pair = (key_pair if isinstance(key_pair, AzureKeyPair)
  2876. 929 else self.provider.security.key_pairs.get(key_pair))
  2877. 930 else:
  2878. 931 # Create a temporary keypair if none is provided to keep Azure
  2879. 932 # happy, but the private key will be discarded, so it'll be all
  2880. 933 # but useless. However, this will allow an instance to be launched
  2881. 934 # without specifying a keypair, so users may still be able to login
  2882. 935 # if they have a preinstalled keypair/password baked into the image
  2883. 936 temp_kp_name = "".join(["cb-default-kp-",
  2884. 937 str(uuid.uuid5(uuid.NAMESPACE_OID,
  2885. 938 instance_name))[-6:]])
  2886. 939 key_pair = self.provider.security.key_pairs.create(
  2887. 940 name=temp_kp_name)
  2888. 941 temp_key_pair = key_pair
  2889. 942
  2890. 943 params = {
  2891. 944 'location': zone_id or self.provider.region_name,
  2892. 945 'os_profile': {
  2893. 946 'admin_username': self.provider.vm_default_user_name,
  2894. 947 'computer_name': instance_name,
  2895. 948 'linux_configuration': {
  2896. 949 "disable_password_authentication": True,
  2897. 950 "ssh": {
  2898. 951 "public_keys": [{
  2899. 952 "path":
  2900. 953 "/home/{}/.ssh/authorized_keys".format(
  2901. 954 self.provider.vm_default_user_name),
  2902. 955 "key_data": key_pair._key_pair.Key
  2903. 956 }]
  2904. 957 }
  2905. 958 }
  2906. 959 },
  2907. 960 'hardware_profile': {
  2908. 961 'vm_size': instance_size
  2909. 962 },
  2910. 963 'network_profile': {
  2911. 964 'network_interfaces': [{
  2912. 965 'id': nic_info.id
  2913. 966 }]
  2914. 967 },
  2915. 968 'storage_profile': storage_profile,
  2916. 969 'tags': {'Label': label}
  2917. 970 }
  2918. 971
  2919. 972 for disk_def in storage_profile.get('data_disks', []):
  2920. 973 params['tags'] = dict(disk_def.get('tags', {}), **params['tags'])
  2921. 974
  2922. 975 if user_data:
  2923. 976 custom_data = base64.b64encode(bytes(ud, 'utf-8'))
  2924. 977 params['os_profile']['custom_data'] = str(custom_data, 'utf-8')
  2925. 978
  2926. 979 if not temp_key_pair:
  2927. 980 params['tags'].update(Key_Pair=key_pair.id)
  2928. 981
  2929. 982 try:
  2930. 983 vm = self.provider.azure_client.create_vm(instance_name, params)
  2931. 984 except Exception as e:
  2932. 985 # If VM creation fails, attempt to clean up intermediary resources
  2933. 986 self.provider.azure_client.delete_nic(nic_info.id)
  2934. 987 for disk_def in storage_profile.get('data_disks', []):
  2935. 988 if disk_def.get('tags', {}).get('delete_on_terminate'):
  2936. 989 disk_id = disk_def.get('managed_disk', {}).get('id')
  2937. 990 if disk_id:
  2938. 991 vol = self.provider.storage.volumes.get(disk_id)
  2939. 992 vol.delete()
  2940. 993 raise e
  2941. 994 finally:
  2942. 995 if temp_key_pair:
  2943. 996 temp_key_pair.delete()
  2944. 997 return AzureInstance(self.provider, vm)
  2945. Total time: 0 s
  2946. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2947. Function: list at line 999
  2948. Line # Hits Time Per Hit % Time Line Contents
  2949. ==============================================================
  2950. 999 @dispatch(event="provider.compute.instances.list",
  2951. 1000 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  2952. 1001 @profile
  2953. 1002 def list(self, limit=None, marker=None):
  2954. 1003 """
  2955. 1004 List all instances.
  2956. 1005 """
  2957. 1006 instances = [AzureInstance(self.provider, inst)
  2958. 1007 for inst in self.provider.azure_client.list_vm()]
  2959. 1008 return ClientPagedResultList(self.provider, instances,
  2960. 1009 limit=limit, marker=marker)
  2961. Total time: 0 s
  2962. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2963. Function: get at line 1011
  2964. Line # Hits Time Per Hit % Time Line Contents
  2965. ==============================================================
  2966. 1011 @dispatch(event="provider.compute.instances.get",
  2967. 1012 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  2968. 1013 @profile
  2969. 1014 def get(self, instance_id):
  2970. 1015 """
  2971. 1016 Returns an instance given its id. Returns None
  2972. 1017 if the object does not exist.
  2973. 1018 """
  2974. 1019 try:
  2975. 1020 vm = self.provider.azure_client.get_vm(instance_id)
  2976. 1021 return AzureInstance(self.provider, vm)
  2977. 1022 except (CloudError, InvalidValueException) as cloud_error:
  2978. 1023 # Azure raises the cloud error if the resource not available
  2979. 1024 log.exception(cloud_error)
  2980. 1025 return None
  2981. Total time: 0 s
  2982. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  2983. Function: find at line 1027
  2984. Line # Hits Time Per Hit % Time Line Contents
  2985. ==============================================================
  2986. 1027 @dispatch(event="provider.compute.instances.find",
  2987. 1028 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  2988. 1029 @profile
  2989. 1030 def find(self, **kwargs):
  2990. 1031 obj_list = self
  2991. 1032 filters = ['label']
  2992. 1033 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  2993. 1034
  2994. 1035 # All kwargs should have been popped at this time.
  2995. 1036 if len(kwargs) > 0:
  2996. 1037 raise InvalidParamException(
  2997. 1038 "Unrecognised parameters for search: %s. Supported "
  2998. 1039 "attributes: %s" % (kwargs, ", ".join(filters)))
  2999. 1040
  3000. 1041 return ClientPagedResultList(self.provider,
  3001. 1042 matches if matches else [])
  3002. Total time: 0 s
  3003. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3004. Function: delete at line 1044
  3005. Line # Hits Time Per Hit % Time Line Contents
  3006. ==============================================================
  3007. 1044 @dispatch(event="provider.compute.instances.delete",
  3008. 1045 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  3009. 1046 @profile
  3010. 1047 def delete(self, instance):
  3011. 1048 """
  3012. 1049 Permanently terminate this instance.
  3013. 1050 After deleting the VM. we are deleting the network interface
  3014. 1051 associated to the instance, and also removing OS disk and data disks
  3015. 1052 where tag with name 'delete_on_terminate' has value True.
  3016. 1053 """
  3017. 1054 ins = (instance if isinstance(instance, AzureInstance) else
  3018. 1055 self.get(instance))
  3019. 1056 if not instance:
  3020. 1057 return
  3021. 1058
  3022. 1059 # Remove IPs first to avoid a network interface conflict
  3023. 1060 # pylint:disable=protected-access
  3024. 1061 for public_ip_id in ins._public_ip_ids:
  3025. 1062 ins.remove_floating_ip(public_ip_id)
  3026. 1063 self.provider.azure_client.deallocate_vm(ins.id)
  3027. 1064 self.provider.azure_client.delete_vm(ins.id)
  3028. 1065 # pylint:disable=protected-access
  3029. 1066 for nic_id in ins._nic_ids:
  3030. 1067 self.provider.azure_client.delete_nic(nic_id)
  3031. 1068 # pylint:disable=protected-access
  3032. 1069 for data_disk in ins._vm.storage_profile.data_disks:
  3033. 1070 if data_disk.managed_disk:
  3034. 1071 # pylint:disable=protected-access
  3035. 1072 if ins._vm.tags.get('delete_on_terminate',
  3036. 1073 'False') == 'True':
  3037. 1074 self.provider.azure_client. \
  3038. 1075 delete_disk(data_disk.managed_disk.id)
  3039. 1076 # pylint:disable=protected-access
  3040. 1077 if ins._vm.storage_profile.os_disk.managed_disk:
  3041. 1078 self.provider.azure_client. \
  3042. 1079 delete_disk(ins._vm.storage_profile.os_disk.managed_disk.id)
  3043. Total time: 0 s
  3044. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3045. Function: list at line 1095
  3046. Line # Hits Time Per Hit % Time Line Contents
  3047. ==============================================================
  3048. 1095 @dispatch(event="provider.compute.vm_types.list",
  3049. 1096 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  3050. 1097 @profile
  3051. 1098 def list(self, limit=None, marker=None):
  3052. 1099 vm_types = [AzureVMType(self.provider, vm_type)
  3053. 1100 for vm_type in self.instance_data]
  3054. 1101 return ClientPagedResultList(self.provider, vm_types,
  3055. 1102 limit=limit, marker=marker)
  3056. Total time: 0 s
  3057. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3058. Function: get at line 1109
  3059. Line # Hits Time Per Hit % Time Line Contents
  3060. ==============================================================
  3061. 1109 @dispatch(event="provider.compute.regions.get",
  3062. 1110 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  3063. 1111 @profile
  3064. 1112 def get(self, region_id):
  3065. 1113 region = None
  3066. 1114 for azureRegion in self.provider.azure_client.list_locations():
  3067. 1115 if azureRegion.name == region_id:
  3068. 1116 region = AzureRegion(self.provider, azureRegion)
  3069. 1117 break
  3070. 1118 return region
  3071. Total time: 0 s
  3072. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3073. Function: list at line 1120
  3074. Line # Hits Time Per Hit % Time Line Contents
  3075. ==============================================================
  3076. 1120 @dispatch(event="provider.compute.regions.list",
  3077. 1121 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  3078. 1122 @profile
  3079. 1123 def list(self, limit=None, marker=None):
  3080. 1124 regions = [AzureRegion(self.provider, region)
  3081. 1125 for region in self.provider.azure_client.list_locations()]
  3082. 1126 return ClientPagedResultList(self.provider, regions,
  3083. 1127 limit=limit, marker=marker)
  3084. Total time: 0 s
  3085. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3086. Function: get at line 1168
  3087. Line # Hits Time Per Hit % Time Line Contents
  3088. ==============================================================
  3089. 1168 @dispatch(event="provider.networking.networks.get",
  3090. 1169 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  3091. 1170 @profile
  3092. 1171 def get(self, network_id):
  3093. 1172 try:
  3094. 1173 network = self.provider.azure_client.get_network(network_id)
  3095. 1174 return AzureNetwork(self.provider, network)
  3096. 1175 except (CloudError, InvalidValueException) as cloud_error:
  3097. 1176 # Azure raises the cloud error if the resource not available
  3098. 1177 log.exception(cloud_error)
  3099. 1178 return None
  3100. Total time: 0 s
  3101. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3102. Function: list at line 1180
  3103. Line # Hits Time Per Hit % Time Line Contents
  3104. ==============================================================
  3105. 1180 @dispatch(event="provider.networking.networks.list",
  3106. 1181 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  3107. 1182 @profile
  3108. 1183 def list(self, limit=None, marker=None):
  3109. 1184 networks = [AzureNetwork(self.provider, network)
  3110. 1185 for network in self.provider.azure_client.list_networks()]
  3111. 1186 return ClientPagedResultList(self.provider, networks,
  3112. 1187 limit=limit, marker=marker)
  3113. Total time: 0 s
  3114. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3115. Function: create at line 1189
  3116. Line # Hits Time Per Hit % Time Line Contents
  3117. ==============================================================
  3118. 1189 @dispatch(event="provider.networking.networks.create",
  3119. 1190 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  3120. 1191 @profile
  3121. 1192 def create(self, label, cidr_block):
  3122. 1193 AzureNetwork.assert_valid_resource_label(label)
  3123. 1194 params = {
  3124. 1195 'location': self.provider.azure_client.region_name,
  3125. 1196 'address_space': {
  3126. 1197 'address_prefixes': [cidr_block]
  3127. 1198 },
  3128. 1199 'tags': {'Label': label}
  3129. 1200 }
  3130. 1201
  3131. 1202 network_name = AzureNetwork._generate_name_from_label(label, 'cb-net')
  3132. 1203
  3133. 1204 az_network = self.provider.azure_client.create_network(network_name,
  3134. 1205 params)
  3135. 1206 cb_network = AzureNetwork(self.provider, az_network)
  3136. 1207 return cb_network
  3137. Total time: 0 s
  3138. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3139. Function: delete at line 1209
  3140. Line # Hits Time Per Hit % Time Line Contents
  3141. ==============================================================
  3142. 1209 @dispatch(event="provider.networking.networks.delete",
  3143. 1210 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  3144. 1211 @profile
  3145. 1212 def delete(self, network):
  3146. 1213 net_id = network.id if isinstance(network, AzureNetwork) else network
  3147. 1214 if net_id:
  3148. 1215 self.provider.azure_client.delete_network(net_id)
  3149. Total time: 0 s
  3150. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3151. Function: get at line 1245
  3152. Line # Hits Time Per Hit % Time Line Contents
  3153. ==============================================================
  3154. 1245 @dispatch(event="provider.networking.subnets.get",
  3155. 1246 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  3156. 1247 @profile
  3157. 1248 def get(self, subnet_id):
  3158. 1249 """
  3159. 1250 Azure does not provide an api to get the subnet directly by id.
  3160. 1251 It also requires the network id.
  3161. 1252 To make it consistent across the providers the following code
  3162. 1253 gets the specific code from the subnet list.
  3163. 1254 """
  3164. 1255 try:
  3165. 1256 azure_subnet = self.provider.azure_client.get_subnet(subnet_id)
  3166. 1257 return AzureSubnet(self.provider,
  3167. 1258 azure_subnet) if azure_subnet else None
  3168. 1259 except (CloudError, InvalidValueException) as cloud_error:
  3169. 1260 # Azure raises the cloud error if the resource not available
  3170. 1261 log.exception(cloud_error)
  3171. 1262 return None
  3172. Total time: 0 s
  3173. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3174. Function: list at line 1264
  3175. Line # Hits Time Per Hit % Time Line Contents
  3176. ==============================================================
  3177. 1264 @dispatch(event="provider.networking.subnets.list",
  3178. 1265 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  3179. 1266 @profile
  3180. 1267 def list(self, network=None, limit=None, marker=None):
  3181. 1268 return ClientPagedResultList(self.provider,
  3182. 1269 self._list_subnets(network),
  3183. 1270 limit=limit, marker=marker)
  3184. Total time: 0 s
  3185. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3186. Function: find at line 1272
  3187. Line # Hits Time Per Hit % Time Line Contents
  3188. ==============================================================
  3189. 1272 @dispatch(event="provider.networking.subnets.find",
  3190. 1273 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  3191. 1274 @profile
  3192. 1275 def find(self, network=None, **kwargs):
  3193. 1276 obj_list = self._list_subnets(network)
  3194. 1277 filters = ['label']
  3195. 1278 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  3196. 1279
  3197. 1280 return ClientPagedResultList(self.provider,
  3198. 1281 matches if matches else [])
  3199. Total time: 0 s
  3200. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3201. Function: create at line 1283
  3202. Line # Hits Time Per Hit % Time Line Contents
  3203. ==============================================================
  3204. 1283 @dispatch(event="provider.networking.subnets.create",
  3205. 1284 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  3206. 1285 @profile
  3207. 1286 def create(self, label, network, cidr_block, zone):
  3208. 1287 AzureSubnet.assert_valid_resource_label(label)
  3209. 1288 # Although Subnet doesn't support tags in Azure, we use the parent
  3210. 1289 # Network's tags to track its subnets' labels
  3211. 1290 subnet_name = AzureSubnet._generate_name_from_label(label, "cb-sn")
  3212. 1291
  3213. 1292 network_id = network.id \
  3214. 1293 if isinstance(network, Network) else network
  3215. 1294
  3216. 1295 subnet_info = self.provider.azure_client\
  3217. 1296 .create_subnet(
  3218. 1297 network_id,
  3219. 1298 subnet_name,
  3220. 1299 {
  3221. 1300 'address_prefix': cidr_block
  3222. 1301 }
  3223. 1302 )
  3224. 1303
  3225. 1304 subnet = AzureSubnet(self.provider, subnet_info)
  3226. 1305 subnet.label = label
  3227. 1306 return subnet
  3228. Total time: 0 s
  3229. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3230. Function: delete at line 1308
  3231. Line # Hits Time Per Hit % Time Line Contents
  3232. ==============================================================
  3233. 1308 @dispatch(event="provider.networking.subnets.delete",
  3234. 1309 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  3235. 1310 @profile
  3236. 1311 def delete(self, subnet):
  3237. 1312 sn = subnet if isinstance(subnet, AzureSubnet) else self.get(subnet)
  3238. 1313 if sn:
  3239. 1314 self.provider.azure_client.delete_subnet(sn.id)
  3240. 1315 # Although Subnet doesn't support labels, we use the parent
  3241. 1316 # Network's tags to track the subnet's labels, thus that
  3242. 1317 # network-level tag must be deleted with the subnet
  3243. 1318 net_id = sn.network_id
  3244. 1319 az_network = self.provider.azure_client.get_network(net_id)
  3245. 1320 az_network.tags.pop(sn.tag_name)
  3246. 1321 self.provider.azure_client.update_network_tags(
  3247. 1322 az_network.id, az_network)
  3248. Total time: 0 s
  3249. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3250. Function: get at line 1329
  3251. Line # Hits Time Per Hit % Time Line Contents
  3252. ==============================================================
  3253. 1329 @dispatch(event="provider.networking.routers.get",
  3254. 1330 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  3255. 1331 @profile
  3256. 1332 def get(self, router_id):
  3257. 1333 try:
  3258. 1334 route = self.provider.azure_client.get_route_table(router_id)
  3259. 1335 return AzureRouter(self.provider, route)
  3260. 1336 except (CloudError, InvalidValueException) as cloud_error:
  3261. 1337 # Azure raises the cloud error if the resource not available
  3262. 1338 log.exception(cloud_error)
  3263. 1339 return None
  3264. Total time: 0 s
  3265. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3266. Function: find at line 1341
  3267. Line # Hits Time Per Hit % Time Line Contents
  3268. ==============================================================
  3269. 1341 @dispatch(event="provider.networking.routers.find",
  3270. 1342 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  3271. 1343 @profile
  3272. 1344 def find(self, **kwargs):
  3273. 1345 obj_list = self
  3274. 1346 filters = ['label']
  3275. 1347 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  3276. 1348
  3277. 1349 # All kwargs should have been popped at this time.
  3278. 1350 if len(kwargs) > 0:
  3279. 1351 raise InvalidParamException(
  3280. 1352 "Unrecognised parameters for search: %s. Supported "
  3281. 1353 "attributes: %s" % (kwargs, ", ".join(filters)))
  3282. 1354
  3283. 1355 return ClientPagedResultList(self.provider,
  3284. 1356 matches if matches else [])
  3285. Total time: 0 s
  3286. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3287. Function: list at line 1358
  3288. Line # Hits Time Per Hit % Time Line Contents
  3289. ==============================================================
  3290. 1358 @dispatch(event="provider.networking.routers.list",
  3291. 1359 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  3292. 1360 @profile
  3293. 1361 def list(self, limit=None, marker=None):
  3294. 1362 routes = [AzureRouter(self.provider, route)
  3295. 1363 for route in
  3296. 1364 self.provider.azure_client.list_route_tables()]
  3297. 1365 return ClientPagedResultList(self.provider,
  3298. 1366 routes,
  3299. 1367 limit=limit, marker=marker)
  3300. Total time: 0 s
  3301. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3302. Function: create at line 1369
  3303. Line # Hits Time Per Hit % Time Line Contents
  3304. ==============================================================
  3305. 1369 @dispatch(event="provider.networking.routers.create",
  3306. 1370 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  3307. 1371 @profile
  3308. 1372 def create(self, label, network):
  3309. 1373 router_name = AzureRouter._generate_name_from_label(label, "cb-router")
  3310. 1374
  3311. 1375 parameters = {"location": self.provider.region_name,
  3312. 1376 "tags": {'Label': label}}
  3313. 1377
  3314. 1378 route = self.provider.azure_client. \
  3315. 1379 create_route_table(router_name, parameters)
  3316. 1380 return AzureRouter(self.provider, route)
  3317. Total time: 0 s
  3318. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3319. Function: delete at line 1382
  3320. Line # Hits Time Per Hit % Time Line Contents
  3321. ==============================================================
  3322. 1382 @dispatch(event="provider.networking.routers.delete",
  3323. 1383 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  3324. 1384 @profile
  3325. 1385 def delete(self, router):
  3326. 1386 r = router if isinstance(router, AzureRouter) else self.get(router)
  3327. 1387 if r:
  3328. 1388 self.provider.azure_client.delete_route_table(r.name)
  3329. Total time: 0 s
  3330. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3331. Function: get_or_create at line 1403
  3332. Line # Hits Time Per Hit % Time Line Contents
  3333. ==============================================================
  3334. 1403 @dispatch(event="provider.networking.gateways.get_or_create",
  3335. 1404 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  3336. 1405 @profile
  3337. 1406 def get_or_create(self, network):
  3338. 1407 return self._gateway_singleton(network)
  3339. Total time: 0 s
  3340. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3341. Function: list at line 1409
  3342. Line # Hits Time Per Hit % Time Line Contents
  3343. ==============================================================
  3344. 1409 @dispatch(event="provider.networking.gateways.list",
  3345. 1410 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  3346. 1411 @profile
  3347. 1412 def list(self, network, limit=None, marker=None):
  3348. 1413 gws = [self._gateway_singleton(network)]
  3349. 1414 return ClientPagedResultList(self.provider,
  3350. 1415 gws,
  3351. 1416 limit=limit, marker=marker)
  3352. Total time: 0 s
  3353. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3354. Function: delete at line 1418
  3355. Line # Hits Time Per Hit % Time Line Contents
  3356. ==============================================================
  3357. 1418 @dispatch(event="provider.networking.gateways.delete",
  3358. 1419 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  3359. 1420 @profile
  3360. 1421 def delete(self, network, gateway):
  3361. 1422 pass
  3362. Total time: 0 s
  3363. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3364. Function: get at line 1430
  3365. Line # Hits Time Per Hit % Time Line Contents
  3366. ==============================================================
  3367. 1430 @dispatch(event="provider.networking.floating_ips.get",
  3368. 1431 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  3369. 1432 @profile
  3370. 1433 def get(self, gateway, fip_id):
  3371. 1434 try:
  3372. 1435 az_ip = self.provider.azure_client.get_floating_ip(fip_id)
  3373. 1436 except (CloudError, InvalidValueException) as cloud_error:
  3374. 1437 # Azure raises the cloud error if the resource not available
  3375. 1438 log.exception(cloud_error)
  3376. 1439 return None
  3377. 1440 return AzureFloatingIP(self.provider, az_ip)
  3378. Total time: 0 s
  3379. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3380. Function: list at line 1442
  3381. Line # Hits Time Per Hit % Time Line Contents
  3382. ==============================================================
  3383. 1442 @dispatch(event="provider.networking.floating_ips.list",
  3384. 1443 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  3385. 1444 @profile
  3386. 1445 def list(self, gateway, limit=None, marker=None):
  3387. 1446 floating_ips = [AzureFloatingIP(self.provider, floating_ip)
  3388. 1447 for floating_ip in self.provider.azure_client.
  3389. 1448 list_floating_ips()]
  3390. 1449 return ClientPagedResultList(self.provider, floating_ips,
  3391. 1450 limit=limit, marker=marker)
  3392. Total time: 0 s
  3393. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3394. Function: create at line 1452
  3395. Line # Hits Time Per Hit % Time Line Contents
  3396. ==============================================================
  3397. 1452 @dispatch(event="provider.networking.floating_ips.create",
  3398. 1453 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  3399. 1454 @profile
  3400. 1455 def create(self, gateway):
  3401. 1456 public_ip_parameters = {
  3402. 1457 'location': self.provider.azure_client.region_name,
  3403. 1458 'public_ip_allocation_method': 'Static'
  3404. 1459 }
  3405. 1460
  3406. 1461 public_ip_name = AzureFloatingIP._generate_name_from_label(
  3407. 1462 None, 'cb-fip-')
  3408. 1463
  3409. 1464 floating_ip = self.provider.azure_client.\
  3410. 1465 create_floating_ip(public_ip_name, public_ip_parameters)
  3411. 1466 return AzureFloatingIP(self.provider, floating_ip)
  3412. Total time: 0 s
  3413. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/azure/services.py
  3414. Function: delete at line 1468
  3415. Line # Hits Time Per Hit % Time Line Contents
  3416. ==============================================================
  3417. 1468 @dispatch(event="provider.networking.floating_ips.delete",
  3418. 1469 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  3419. 1470 @profile
  3420. 1471 def delete(self, gateway, fip):
  3421. 1472 fip_id = fip.id if isinstance(fip, AzureFloatingIP) else fip
  3422. 1473 self.provider.azure_client.delete_floating_ip(fip_id)
  3423. Total time: 0 s
  3424. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3425. Function: label at line 482
  3426. Line # Hits Time Per Hit % Time Line Contents
  3427. ==============================================================
  3428. 482 @label.setter
  3429. 483 @profile
  3430. 484 def label(self, value):
  3431. 485 self.assert_valid_resource_label(value)
  3432. 486 tag_name = "_".join(["firewall", self.name, "label"])
  3433. 487 helpers.modify_or_add_metadata_item(self._provider, tag_name, value)
  3434. Total time: 0 s
  3435. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3436. Function: description at line 508
  3437. Line # Hits Time Per Hit % Time Line Contents
  3438. ==============================================================
  3439. 508 @description.setter
  3440. 509 @profile
  3441. 510 def description(self, value):
  3442. 511 # Change the description on all rules
  3443. 512 for fw in self._delegate.iter_firewalls(self._vm_firewall,
  3444. 513 self._network.name):
  3445. 514 fw['description'] = value or ''
  3446. 515 response = (self._provider
  3447. 516 .gcp_compute
  3448. 517 .firewalls()
  3449. 518 .update(project=self._provider.project_name,
  3450. 519 firewall=fw['name'],
  3451. 520 body=fw)
  3452. 521 .execute())
  3453. 522 self._provider.wait_for_operation(response)
  3454. 523 # Set back to None so that the next time the user gets it, it updates
  3455. 524 # but don't force update here to avoid more overhead
  3456. 525 self._description = None
  3457. Total time: 0 s
  3458. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3459. Function: refresh at line 542
  3460. Line # Hits Time Per Hit % Time Line Contents
  3461. ==============================================================
  3462. 542 @profile
  3463. 543 def refresh(self):
  3464. 544 fw = self._provider.security.vm_firewalls.get(self.id)
  3465. 545 # restore all internal state
  3466. 546 if fw:
  3467. 547 # pylint:disable=protected-access
  3468. 548 self._delegate = fw._delegate
  3469. 549 # pylint:disable=protected-access
  3470. 550 self._description = fw._description
  3471. 551 # pylint:disable=protected-access
  3472. 552 self._network = fw._network
  3473. 553 # pylint:disable=protected-access
  3474. 554 self._rule_container = fw._rule_container
  3475. Total time: 0 s
  3476. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3477. Function: label at line 713
  3478. Line # Hits Time Per Hit % Time Line Contents
  3479. ==============================================================
  3480. 713 @label.setter
  3481. 714 # pylint:disable=arguments-differ
  3482. 715 @profile
  3483. 716 def label(self, value):
  3484. 717 req = (self._provider
  3485. 718 .gcp_compute
  3486. 719 .images()
  3487. 720 .setLabels(project=self._provider.project_name,
  3488. 721 resource=self.name,
  3489. 722 body={}))
  3490. 723
  3491. 724 helpers.change_label(self, 'cblabel', value, '_gcp_image', req)
  3492. Total time: 0 s
  3493. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3494. Function: refresh at line 761
  3495. Line # Hits Time Per Hit % Time Line Contents
  3496. ==============================================================
  3497. 761 @profile
  3498. 762 def refresh(self):
  3499. 763 """
  3500. 764 Refreshes the state of this instance by re-querying the cloud provider
  3501. 765 for its latest state.
  3502. 766 """
  3503. 767 image = self._provider.compute.images.get(self.id)
  3504. 768 if image:
  3505. 769 # pylint:disable=protected-access
  3506. 770 self._gcp_image = image._gcp_image
  3507. 771 else:
  3508. 772 # image no longer exists
  3509. 773 self._gcp_image['status'] = MachineImageState.UNKNOWN
  3510. Total time: 0 s
  3511. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3512. Function: label at line 822
  3513. Line # Hits Time Per Hit % Time Line Contents
  3514. ==============================================================
  3515. 822 @label.setter
  3516. 823 # pylint:disable=arguments-differ
  3517. 824 @profile
  3518. 825 def label(self, value):
  3519. 826 req = (self._provider
  3520. 827 .gcp_compute
  3521. 828 .instances()
  3522. 829 .setLabels(project=self._provider.project_name,
  3523. 830 zone=self.zone_name,
  3524. 831 instance=self.name,
  3525. 832 body={}))
  3526. 833
  3527. 834 helpers.change_label(self, 'cblabel', value, '_gcp_instance', req)
  3528. Total time: 0 s
  3529. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3530. Function: refresh at line 1237
  3531. Line # Hits Time Per Hit % Time Line Contents
  3532. ==============================================================
  3533. 1237 @profile
  3534. 1238 def refresh(self):
  3535. 1239 """
  3536. 1240 Refreshes the state of this instance by re-querying the cloud provider
  3537. 1241 for its latest state.
  3538. 1242 """
  3539. 1243 inst = self._provider.compute.instances.get(self.id)
  3540. 1244 if inst:
  3541. 1245 # pylint:disable=protected-access
  3542. 1246 self._gcp_instance = inst._gcp_instance
  3543. 1247 else:
  3544. 1248 # instance no longer exists
  3545. 1249 self._gcp_instance['status'] = InstanceState.UNKNOWN
  3546. Total time: 0 s
  3547. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3548. Function: label at line 1305
  3549. Line # Hits Time Per Hit % Time Line Contents
  3550. ==============================================================
  3551. 1305 @label.setter
  3552. 1306 @profile
  3553. 1307 def label(self, value):
  3554. 1308 self.assert_valid_resource_label(value)
  3555. 1309 tag_name = "_".join(["network", self.name, "label"])
  3556. 1310 helpers.modify_or_add_metadata_item(self._provider, tag_name, value)
  3557. Total time: 0 s
  3558. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3559. Function: refresh at line 1340
  3560. Line # Hits Time Per Hit % Time Line Contents
  3561. ==============================================================
  3562. 1340 @profile
  3563. 1341 def refresh(self):
  3564. 1342 net = self._provider.networking.networks.get(self.id)
  3565. 1343 if net:
  3566. 1344 # pylint:disable=protected-access
  3567. 1345 self._network = net._network
  3568. 1346 else:
  3569. 1347 # network no longer exists
  3570. 1348 self._network['status'] = NetworkState.UNKNOWN
  3571. Total time: 0 s
  3572. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3573. Function: refresh at line 1390
  3574. Line # Hits Time Per Hit % Time Line Contents
  3575. ==============================================================
  3576. 1390 @profile
  3577. 1391 def refresh(self):
  3578. 1392 # pylint:disable=protected-access
  3579. 1393 fip = self._provider.networking._floating_ips.get(None, self.id)
  3580. 1394 # pylint:disable=protected-access
  3581. 1395 self._ip = fip._ip
  3582. 1396 self._process_ip_users()
  3583. Total time: 0 s
  3584. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3585. Function: label at line 1445
  3586. Line # Hits Time Per Hit % Time Line Contents
  3587. ==============================================================
  3588. 1445 @label.setter
  3589. 1446 @profile
  3590. 1447 def label(self, value):
  3591. 1448 self.assert_valid_resource_label(value)
  3592. 1449 tag_name = "_".join(["router", self.name, "label"])
  3593. 1450 helpers.modify_or_add_metadata_item(self._provider, tag_name, value)
  3594. Total time: 0 s
  3595. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3596. Function: refresh at line 1457
  3597. Line # Hits Time Per Hit % Time Line Contents
  3598. ==============================================================
  3599. 1457 @profile
  3600. 1458 def refresh(self):
  3601. 1459 router = self._provider.networking.routers.get(self.id)
  3602. 1460 if router:
  3603. 1461 # pylint:disable=protected-access
  3604. 1462 self._router = router._router
  3605. 1463 else:
  3606. 1464 # router no longer exists
  3607. 1465 self._router['status'] = RouterState.UNKNOWN
  3608. Total time: 0 s
  3609. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3610. Function: refresh at line 1523
  3611. Line # Hits Time Per Hit % Time Line Contents
  3612. ==============================================================
  3613. 1523 @profile
  3614. 1524 def refresh(self):
  3615. 1525 pass
  3616. Total time: 0 s
  3617. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3618. Function: label at line 1565
  3619. Line # Hits Time Per Hit % Time Line Contents
  3620. ==============================================================
  3621. 1565 @label.setter
  3622. 1566 @profile
  3623. 1567 def label(self, value):
  3624. 1568 self.assert_valid_resource_label(value)
  3625. 1569 tag_name = "_".join(["subnet", self.name, "label"])
  3626. 1570 helpers.modify_or_add_metadata_item(self._provider, tag_name, value)
  3627. Total time: 0 s
  3628. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3629. Function: refresh at line 1603
  3630. Line # Hits Time Per Hit % Time Line Contents
  3631. ==============================================================
  3632. 1603 @profile
  3633. 1604 def refresh(self):
  3634. 1605 subnet = self._provider.networking.subnets.get(self.id)
  3635. 1606 if subnet:
  3636. 1607 # pylint:disable=protected-access
  3637. 1608 self._subnet = subnet._subnet
  3638. 1609 else:
  3639. 1610 # subnet no longer exists
  3640. 1611 self._subnet['status'] = SubnetState.UNKNOWN
  3641. Total time: 0 s
  3642. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3643. Function: label at line 1643
  3644. Line # Hits Time Per Hit % Time Line Contents
  3645. ==============================================================
  3646. 1643 @label.setter
  3647. 1644 @profile
  3648. 1645 def label(self, value):
  3649. 1646 req = (self._provider
  3650. 1647 .gcp_compute
  3651. 1648 .disks()
  3652. 1649 .setLabels(project=self._provider.project_name,
  3653. 1650 zone=self.zone_name,
  3654. 1651 resource=self.name,
  3655. 1652 body={}))
  3656. 1653
  3657. 1654 helpers.change_label(self, 'cblabel', value, '_volume', req)
  3658. Total time: 0 s
  3659. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3660. Function: description at line 1663
  3661. Line # Hits Time Per Hit % Time Line Contents
  3662. ==============================================================
  3663. 1663 @description.setter
  3664. 1664 @profile
  3665. 1665 def description(self, value):
  3666. 1666 req = (self._provider
  3667. 1667 .gcp_compute
  3668. 1668 .disks()
  3669. 1669 .setLabels(project=self._provider.project_name,
  3670. 1670 zone=self.zone_name,
  3671. 1671 resource=self.name,
  3672. 1672 body={}))
  3673. 1673
  3674. 1674 helpers.change_label(self, 'description', value, '_volume', req)
  3675. Total time: 0 s
  3676. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3677. Function: refresh at line 1789
  3678. Line # Hits Time Per Hit % Time Line Contents
  3679. ==============================================================
  3680. 1789 @profile
  3681. 1790 def refresh(self):
  3682. 1791 """
  3683. 1792 Refreshes the state of this volume by re-querying the cloud provider
  3684. 1793 for its latest state.
  3685. 1794 """
  3686. 1795 vol = self._provider.storage.volumes.get(self.id)
  3687. 1796 if vol:
  3688. 1797 # pylint:disable=protected-access
  3689. 1798 self._volume = vol._volume
  3690. 1799 else:
  3691. 1800 # volume no longer exists
  3692. 1801 self._volume['status'] = VolumeState.UNKNOWN
  3693. Total time: 0 s
  3694. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3695. Function: label at line 1831
  3696. Line # Hits Time Per Hit % Time Line Contents
  3697. ==============================================================
  3698. 1831 @label.setter
  3699. 1832 # pylint:disable=arguments-differ
  3700. 1833 @profile
  3701. 1834 def label(self, value):
  3702. 1835 req = (self._provider
  3703. 1836 .gcp_compute
  3704. 1837 .snapshots()
  3705. 1838 .setLabels(project=self._provider.project_name,
  3706. 1839 resource=self.name,
  3707. 1840 body={}))
  3708. 1841
  3709. 1842 helpers.change_label(self, 'cblabel', value, '_snapshot', req)
  3710. Total time: 0 s
  3711. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3712. Function: description at line 1851
  3713. Line # Hits Time Per Hit % Time Line Contents
  3714. ==============================================================
  3715. 1851 @description.setter
  3716. 1852 @profile
  3717. 1853 def description(self, value):
  3718. 1854 req = (self._provider
  3719. 1855 .gcp_compute
  3720. 1856 .snapshots()
  3721. 1857 .setLabels(project=self._provider.project_name,
  3722. 1858 resource=self.name,
  3723. 1859 body={}))
  3724. 1860
  3725. 1861 helpers.change_label(self, 'description', value, '_snapshot', req)
  3726. Total time: 0 s
  3727. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3728. Function: refresh at line 1880
  3729. Line # Hits Time Per Hit % Time Line Contents
  3730. ==============================================================
  3731. 1880 @profile
  3732. 1881 def refresh(self):
  3733. 1882 """
  3734. 1883 Refreshes the state of this snapshot by re-querying the cloud provider
  3735. 1884 for its latest state.
  3736. 1885 """
  3737. 1886 snap = self._provider.storage.snapshots.get(self.id)
  3738. 1887 if snap:
  3739. 1888 # pylint:disable=protected-access
  3740. 1889 self._snapshot = snap._snapshot
  3741. 1890 else:
  3742. 1891 # snapshot no longer exists
  3743. 1892 self._snapshot['status'] = SnapshotState.UNKNOWN
  3744. Total time: 0 s
  3745. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/resources.py
  3746. Function: refresh at line 2018
  3747. Line # Hits Time Per Hit % Time Line Contents
  3748. ==============================================================
  3749. 2018 @profile
  3750. 2019 def refresh(self):
  3751. 2020 # pylint:disable=protected-access
  3752. 2021 self._obj = self.bucket.objects.get(self.id)._obj
  3753. Total time: 0 s
  3754. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3755. Function: get at line 91
  3756. Line # Hits Time Per Hit % Time Line Contents
  3757. ==============================================================
  3758. 91 @dispatch(event="provider.security.key_pairs.get",
  3759. 92 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  3760. 93 @profile
  3761. 94 def get(self, key_pair_id):
  3762. 95 """
  3763. 96 Returns a KeyPair given its ID.
  3764. 97 """
  3765. 98 for kp in self:
  3766. 99 if kp.id == key_pair_id:
  3767. 100 return kp
  3768. 101 else:
  3769. 102 return None
  3770. Total time: 0 s
  3771. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3772. Function: list at line 104
  3773. Line # Hits Time Per Hit % Time Line Contents
  3774. ==============================================================
  3775. 104 @dispatch(event="provider.security.key_pairs.list",
  3776. 105 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  3777. 106 @profile
  3778. 107 def list(self, limit=None, marker=None):
  3779. 108 key_pairs = []
  3780. 109 for item in helpers.find_matching_metadata_items(
  3781. 110 self.provider, GCPKeyPair.KP_TAG_REGEX):
  3782. 111 metadata_value = json.loads(item['value'])
  3783. 112 kp_info = GCPKeyPair.GCPKeyInfo(**metadata_value)
  3784. 113 key_pairs.append(GCPKeyPair(self.provider, kp_info))
  3785. 114 return ClientPagedResultList(self.provider, key_pairs,
  3786. 115 limit=limit, marker=marker)
  3787. Total time: 0 s
  3788. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3789. Function: find at line 117
  3790. Line # Hits Time Per Hit % Time Line Contents
  3791. ==============================================================
  3792. 117 @dispatch(event="provider.security.key_pairs.find",
  3793. 118 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  3794. 119 @profile
  3795. 120 def find(self, **kwargs):
  3796. 121 """
  3797. 122 Searches for a key pair by a given list of attributes.
  3798. 123 """
  3799. 124 obj_list = self
  3800. 125 filters = ['id', 'name']
  3801. 126 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  3802. 127
  3803. 128 # All kwargs should have been popped at this time.
  3804. 129 if len(kwargs) > 0:
  3805. 130 raise InvalidParamException(
  3806. 131 "Unrecognised parameters for search: %s. Supported "
  3807. 132 "attributes: %s" % (kwargs, ", ".join(filters)))
  3808. 133
  3809. 134 return ClientPagedResultList(self.provider,
  3810. 135 matches if matches else [])
  3811. Total time: 0 s
  3812. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3813. Function: create at line 137
  3814. Line # Hits Time Per Hit % Time Line Contents
  3815. ==============================================================
  3816. 137 @dispatch(event="provider.security.key_pairs.create",
  3817. 138 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  3818. 139 @profile
  3819. 140 def create(self, name, public_key_material=None):
  3820. 141 GCPKeyPair.assert_valid_resource_name(name)
  3821. 142 private_key = None
  3822. 143 if not public_key_material:
  3823. 144 public_key_material, private_key = cb_helpers.generate_key_pair()
  3824. 145 # TODO: Add support for other formats not assume ssh-rsa
  3825. 146 elif "ssh-rsa" not in public_key_material:
  3826. 147 public_key_material = "ssh-rsa {}".format(public_key_material)
  3827. 148 kp_info = GCPKeyPair.GCPKeyInfo(name, public_key_material)
  3828. 149 metadata_value = json.dumps(kp_info._asdict())
  3829. 150 try:
  3830. 151 helpers.add_metadata_item(self.provider,
  3831. 152 GCPKeyPair.KP_TAG_PREFIX + name,
  3832. 153 metadata_value)
  3833. 154 return GCPKeyPair(self.provider, kp_info, private_key)
  3834. 155 except googleapiclient.errors.HttpError as err:
  3835. 156 if err.resp.get('content-type', '').startswith('application/json'):
  3836. 157 message = (json.loads(err.content).get('error', {})
  3837. 158 .get('errors', [{}])[0].get('message'))
  3838. 159 if "duplicate keys" in message:
  3839. 160 raise DuplicateResourceException(
  3840. 161 'A KeyPair with name {0} already exists'.format(name))
  3841. 162 raise
  3842. Total time: 0 s
  3843. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3844. Function: delete at line 164
  3845. Line # Hits Time Per Hit % Time Line Contents
  3846. ==============================================================
  3847. 164 @dispatch(event="provider.security.key_pairs.delete",
  3848. 165 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  3849. 166 @profile
  3850. 167 def delete(self, key_pair):
  3851. 168 key_pair = (key_pair if isinstance(key_pair, GCPKeyPair) else
  3852. 169 self.get(key_pair))
  3853. 170 if key_pair:
  3854. 171 helpers.remove_metadata_item(
  3855. 172 self.provider, GCPKeyPair.KP_TAG_PREFIX + key_pair.name)
  3856. Total time: 0 s
  3857. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3858. Function: get at line 181
  3859. Line # Hits Time Per Hit % Time Line Contents
  3860. ==============================================================
  3861. 181 @dispatch(event="provider.security.vm_firewalls.get",
  3862. 182 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  3863. 183 @profile
  3864. 184 def get(self, vm_firewall_id):
  3865. 185 tag, network_name = \
  3866. 186 self._delegate.get_tag_network_from_id(vm_firewall_id)
  3867. 187 if tag is None:
  3868. 188 return None
  3869. 189 network = self.provider.networking.networks.get(network_name)
  3870. 190 return GCPVMFirewall(self._delegate, tag, network)
  3871. Total time: 0 s
  3872. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3873. Function: list at line 192
  3874. Line # Hits Time Per Hit % Time Line Contents
  3875. ==============================================================
  3876. 192 @dispatch(event="provider.security.vm_firewalls.list",
  3877. 193 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  3878. 194 @profile
  3879. 195 def list(self, limit=None, marker=None):
  3880. 196 vm_firewalls = []
  3881. 197 for tag, network_name in self._delegate.tag_networks:
  3882. 198 network = self.provider.networking.networks.get(
  3883. 199 network_name)
  3884. 200 vm_firewall = GCPVMFirewall(self._delegate, tag, network)
  3885. 201 vm_firewalls.append(vm_firewall)
  3886. 202 return ClientPagedResultList(self.provider, vm_firewalls,
  3887. 203 limit=limit, marker=marker)
  3888. Total time: 0 s
  3889. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3890. Function: create at line 205
  3891. Line # Hits Time Per Hit % Time Line Contents
  3892. ==============================================================
  3893. 205 @dispatch(event="provider.security.vm_firewalls.create",
  3894. 206 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  3895. 207 @profile
  3896. 208 def create(self, label, network, description=None):
  3897. 209 GCPVMFirewall.assert_valid_resource_label(label)
  3898. 210 network = (network if isinstance(network, GCPNetwork)
  3899. 211 else self.provider.networking.networks.get(network))
  3900. 212 fw = GCPVMFirewall(self._delegate, label, network, description)
  3901. 213 fw.label = label
  3902. 214 # This rule exists implicitly. Add it explicitly so that the firewall
  3903. 215 # is not empty and the rule is shown by list/get/find methods.
  3904. 216 # pylint:disable=protected-access
  3905. 217 self.provider.security._vm_firewall_rules.create_with_priority(
  3906. 218 fw, direction=TrafficDirection.OUTBOUND, protocol='tcp',
  3907. 219 priority=65534, cidr='0.0.0.0/0')
  3908. 220 return fw
  3909. Total time: 0 s
  3910. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3911. Function: delete at line 222
  3912. Line # Hits Time Per Hit % Time Line Contents
  3913. ==============================================================
  3914. 222 @dispatch(event="provider.security.vm_firewalls.delete",
  3915. 223 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  3916. 224 @profile
  3917. 225 def delete(self, vm_firewall):
  3918. 226 fw_id = (vm_firewall.id if isinstance(vm_firewall, GCPVMFirewall)
  3919. 227 else vm_firewall)
  3920. 228 return self._delegate.delete_tag_network_with_id(fw_id)
  3921. Total time: 0 s
  3922. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3923. Function: find_by_network_and_tags at line 230
  3924. Line # Hits Time Per Hit % Time Line Contents
  3925. ==============================================================
  3926. 230 @profile
  3927. 231 def find_by_network_and_tags(self, network_name, tags):
  3928. 232 """
  3929. 233 Finds non-empty VM firewalls by network name and VM firewall names
  3930. 234 (tags). If no matching VM firewall is found, an empty list is returned.
  3931. 235 """
  3932. 236 vm_firewalls = []
  3933. 237 for tag, net_name in self._delegate.tag_networks:
  3934. 238 if network_name != net_name:
  3935. 239 continue
  3936. 240 if tag not in tags:
  3937. 241 continue
  3938. 242 network = self.provider.networking.networks.get(net_name)
  3939. 243 vm_firewalls.append(
  3940. 244 GCPVMFirewall(self._delegate, tag, network))
  3941. 245 return vm_firewalls
  3942. Total time: 0 s
  3943. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3944. Function: list at line 254
  3945. Line # Hits Time Per Hit % Time Line Contents
  3946. ==============================================================
  3947. 254 @dispatch(event="provider.security.vm_firewall_rules.list",
  3948. 255 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  3949. 256 @profile
  3950. 257 def list(self, firewall, limit=None, marker=None):
  3951. 258 rules = []
  3952. 259 for fw in firewall.delegate.iter_firewalls(
  3953. 260 firewall.name, firewall.network.name):
  3954. 261 rule = GCPVMFirewallRule(firewall, fw['id'])
  3955. 262 if rule.is_dummy_rule():
  3956. 263 self._dummy_rule = rule
  3957. 264 else:
  3958. 265 rules.append(rule)
  3959. 266 return ClientPagedResultList(self.provider, rules,
  3960. 267 limit=limit, marker=marker)
  3961. Total time: 0 s
  3962. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3963. Function: create_with_priority at line 284
  3964. Line # Hits Time Per Hit % Time Line Contents
  3965. ==============================================================
  3966. 284 @profile
  3967. 285 def create_with_priority(self, firewall, direction, protocol, priority,
  3968. 286 from_port=None, to_port=None, cidr=None,
  3969. 287 src_dest_fw=None):
  3970. 288 port = GCPVMFirewallRuleService.to_port_range(from_port, to_port)
  3971. 289 src_dest_tag = None
  3972. 290 src_dest_fw_id = None
  3973. 291 if src_dest_fw:
  3974. 292 src_dest_tag = src_dest_fw.name
  3975. 293 src_dest_fw_id = src_dest_fw.id
  3976. 294 if not firewall.delegate.add_firewall(
  3977. 295 firewall.name, direction, protocol, priority, port, cidr,
  3978. 296 src_dest_tag, firewall.description,
  3979. 297 firewall.network.name):
  3980. 298 return None
  3981. 299 rules = self.find(firewall, direction=direction, protocol=protocol,
  3982. 300 from_port=from_port, to_port=to_port, cidr=cidr,
  3983. 301 src_dest_fw_id=src_dest_fw_id)
  3984. 302 if len(rules) < 1:
  3985. 303 return None
  3986. 304 return rules[0]
  3987. Total time: 0 s
  3988. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  3989. Function: create at line 306
  3990. Line # Hits Time Per Hit % Time Line Contents
  3991. ==============================================================
  3992. 306 @dispatch(event="provider.security.vm_firewall_rules.create",
  3993. 307 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  3994. 308 @profile
  3995. 309 def create(self, firewall, direction, protocol, from_port=None,
  3996. 310 to_port=None, cidr=None, src_dest_fw=None):
  3997. 311 return self.create_with_priority(firewall, direction, protocol,
  3998. 312 1000, from_port, to_port, cidr,
  3999. 313 src_dest_fw)
  4000. Total time: 0 s
  4001. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4002. Function: delete at line 315
  4003. Line # Hits Time Per Hit % Time Line Contents
  4004. ==============================================================
  4005. 315 @dispatch(event="provider.security.vm_firewall_rules.delete",
  4006. 316 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  4007. 317 @profile
  4008. 318 def delete(self, firewall, rule):
  4009. 319 rule = (rule if isinstance(rule, GCPVMFirewallRule)
  4010. 320 else self.get(firewall, rule))
  4011. 321 if rule.is_dummy_rule():
  4012. 322 return True
  4013. 323 firewall.delegate.delete_firewall_id(rule._rule)
  4014. Total time: 0 s
  4015. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4016. Function: get at line 341
  4017. Line # Hits Time Per Hit % Time Line Contents
  4018. ==============================================================
  4019. 341 @dispatch(event="provider.compute.vm_types.get",
  4020. 342 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  4021. 343 @profile
  4022. 344 def get(self, vm_type_id):
  4023. 345 vm_type = self.provider.get_resource('machineTypes', vm_type_id)
  4024. 346 return GCPVMType(self.provider, vm_type) if vm_type else None
  4025. Total time: 0 s
  4026. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4027. Function: find at line 348
  4028. Line # Hits Time Per Hit % Time Line Contents
  4029. ==============================================================
  4030. 348 @dispatch(event="provider.compute.vm_types.find",
  4031. 349 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  4032. 350 @profile
  4033. 351 def find(self, **kwargs):
  4034. 352 matched_inst_types = []
  4035. 353 for inst_type in self.instance_data:
  4036. 354 is_match = True
  4037. 355 for key, value in kwargs.items():
  4038. 356 if key not in inst_type:
  4039. 357 raise InvalidParamException(
  4040. 358 "Unrecognised parameters for search: %s." % key)
  4041. 359 if inst_type.get(key) != value:
  4042. 360 is_match = False
  4043. 361 break
  4044. 362 if is_match:
  4045. 363 matched_inst_types.append(
  4046. 364 GCPVMType(self.provider, inst_type))
  4047. 365 return matched_inst_types
  4048. Total time: 0 s
  4049. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4050. Function: list at line 367
  4051. Line # Hits Time Per Hit % Time Line Contents
  4052. ==============================================================
  4053. 367 @dispatch(event="provider.compute.vm_types.list",
  4054. 368 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  4055. 369 @profile
  4056. 370 def list(self, limit=None, marker=None):
  4057. 371 inst_types = [GCPVMType(self.provider, inst_type)
  4058. 372 for inst_type in self.instance_data]
  4059. 373 return ClientPagedResultList(self.provider, inst_types,
  4060. 374 limit=limit, marker=marker)
  4061. Total time: 0 s
  4062. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4063. Function: get at line 382
  4064. Line # Hits Time Per Hit % Time Line Contents
  4065. ==============================================================
  4066. 382 @dispatch(event="provider.compute.regions.get",
  4067. 383 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  4068. 384 @profile
  4069. 385 def get(self, region_id):
  4070. 386 region = self.provider.get_resource('regions', region_id,
  4071. 387 region=region_id)
  4072. 388 return GCPRegion(self.provider, region) if region else None
  4073. Total time: 0 s
  4074. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4075. Function: list at line 390
  4076. Line # Hits Time Per Hit % Time Line Contents
  4077. ==============================================================
  4078. 390 @dispatch(event="provider.compute.regions.list",
  4079. 391 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  4080. 392 @profile
  4081. 393 def list(self, limit=None, marker=None):
  4082. 394 max_result = limit if limit is not None and limit < 500 else 500
  4083. 395 regions_response = (self.provider
  4084. 396 .gcp_compute
  4085. 397 .regions()
  4086. 398 .list(project=self.provider.project_name,
  4087. 399 maxResults=max_result,
  4088. 400 pageToken=marker)
  4089. 401 .execute())
  4090. 402 regions = [GCPRegion(self.provider, region)
  4091. 403 for region in regions_response['items']]
  4092. 404 if len(regions) > max_result:
  4093. 405 log.warning('Expected at most %d results; got %d',
  4094. 406 max_result, len(regions))
  4095. 407 return ServerPagedResultList('nextPageToken' in regions_response,
  4096. 408 regions_response.get('nextPageToken'),
  4097. 409 False, data=regions)
  4098. Total time: 0 s
  4099. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4100. Function: get at line 435
  4101. Line # Hits Time Per Hit % Time Line Contents
  4102. ==============================================================
  4103. 435 @profile
  4104. 436 def get(self, image_id):
  4105. 437 """
  4106. 438 Returns an Image given its id
  4107. 439 """
  4108. 440 image = self.provider.get_resource('images', image_id)
  4109. 441 if image:
  4110. 442 return GCPMachineImage(self.provider, image)
  4111. 443 self._retrieve_public_images()
  4112. 444 for public_image in self._public_images:
  4113. 445 if public_image.id == image_id or public_image.name == image_id:
  4114. 446 return public_image
  4115. 447 return None
  4116. Total time: 0 s
  4117. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4118. Function: find at line 449
  4119. Line # Hits Time Per Hit % Time Line Contents
  4120. ==============================================================
  4121. 449 @profile
  4122. 450 def find(self, limit=None, marker=None, **kwargs):
  4123. 451 """
  4124. 452 Searches for an image by a given list of attributes
  4125. 453 """
  4126. 454 label = kwargs.pop('label', None)
  4127. 455
  4128. 456 # All kwargs should have been popped at this time.
  4129. 457 if len(kwargs) > 0:
  4130. 458 raise InvalidParamException(
  4131. 459 "Unrecognised parameters for search: %s. Supported "
  4132. 460 "attributes: %s" % (kwargs, 'label'))
  4133. 461
  4134. 462 # Retrieve all available images by setting limit to sys.maxsize
  4135. 463 images = [image for image in self if image.label == label]
  4136. 464 return ClientPagedResultList(self.provider, images,
  4137. 465 limit=limit, marker=marker)
  4138. Total time: 0 s
  4139. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4140. Function: list at line 467
  4141. Line # Hits Time Per Hit % Time Line Contents
  4142. ==============================================================
  4143. 467 @profile
  4144. 468 def list(self, limit=None, marker=None):
  4145. 469 """
  4146. 470 List all images.
  4147. 471 """
  4148. 472 self._retrieve_public_images()
  4149. 473 images = []
  4150. 474 if (self.provider.project_name not in
  4151. 475 GCPImageService._PUBLIC_IMAGE_PROJECTS):
  4152. 476 for image in helpers.iter_all(
  4153. 477 self.provider.gcp_compute.images(),
  4154. 478 project=self.provider.project_name):
  4155. 479 images.append(GCPMachineImage(self.provider, image))
  4156. 480 images.extend(self._public_images)
  4157. 481 return ClientPagedResultList(self.provider, images,
  4158. 482 limit=limit, marker=marker)
  4159. Total time: 0 s
  4160. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4161. Function: create at line 490
  4162. Line # Hits Time Per Hit % Time Line Contents
  4163. ==============================================================
  4164. 490 @dispatch(event="provider.compute.instances.create",
  4165. 491 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  4166. 492 @profile
  4167. 493 def create(self, label, image, vm_type, subnet, zone=None,
  4168. 494 key_pair=None, vm_firewalls=None, user_data=None,
  4169. 495 launch_config=None, **kwargs):
  4170. 496 """
  4171. 497 Creates a new virtual machine instance.
  4172. 498 """
  4173. 499 GCPInstance.assert_valid_resource_name(label)
  4174. 500 zone_name = self.provider.default_zone
  4175. 501 if zone:
  4176. 502 if not isinstance(zone, GCPPlacementZone):
  4177. 503 zone = GCPPlacementZone(
  4178. 504 self.provider,
  4179. 505 self.provider.get_resource('zones', zone))
  4180. 506 zone_name = zone.name
  4181. 507 if not isinstance(vm_type, GCPVMType):
  4182. 508 vm_type = self.provider.compute.vm_types.get(vm_type)
  4183. 509
  4184. 510 network_interface = {'accessConfigs': [{'type': 'ONE_TO_ONE_NAT',
  4185. 511 'name': 'External NAT'}]}
  4186. 512 if subnet:
  4187. 513 network_interface['subnetwork'] = subnet.id
  4188. 514 else:
  4189. 515 network_interface['network'] = 'global/networks/default'
  4190. 516
  4191. 517 num_roots = 0
  4192. 518 disks = []
  4193. 519 boot_disk = None
  4194. 520 if isinstance(launch_config, GCPLaunchConfig):
  4195. 521 for disk in launch_config.block_devices:
  4196. 522 if not disk.source:
  4197. 523 volume_name = 'disk-{0}'.format(uuid.uuid4())
  4198. 524 volume_size = disk.size if disk.size else 1
  4199. 525 volume = self.provider.storage.volumes.create(
  4200. 526 volume_name, volume_size, zone)
  4201. 527 volume.wait_till_ready()
  4202. 528 source_field = 'source'
  4203. 529 source_value = volume.id
  4204. 530 elif isinstance(disk.source, GCPMachineImage):
  4205. 531 source_field = 'initializeParams'
  4206. 532 # Explicitly set diskName; otherwise, instance label will
  4207. 533 # be used by default which may collide with existing disks.
  4208. 534 source_value = {
  4209. 535 'sourceImage': disk.source.id,
  4210. 536 'diskName': 'image-disk-{0}'.format(uuid.uuid4()),
  4211. 537 'diskSizeGb': disk.size if disk.size else 20}
  4212. 538 elif isinstance(disk.source, GCPVolume):
  4213. 539 source_field = 'source'
  4214. 540 source_value = disk.source.id
  4215. 541 elif isinstance(disk.source, GCPSnapshot):
  4216. 542 volume = disk.source.create_volume(zone, size=disk.size)
  4217. 543 volume.wait_till_ready()
  4218. 544 source_field = 'source'
  4219. 545 source_value = volume.id
  4220. 546 else:
  4221. 547 log.warning('Unknown disk source')
  4222. 548 continue
  4223. 549 autoDelete = True
  4224. 550 if disk.delete_on_terminate is not None:
  4225. 551 autoDelete = disk.delete_on_terminate
  4226. 552 num_roots += 1 if disk.is_root else 0
  4227. 553 if disk.is_root and not boot_disk:
  4228. 554 boot_disk = {'boot': True,
  4229. 555 'autoDelete': autoDelete,
  4230. 556 source_field: source_value}
  4231. 557 else:
  4232. 558 disks.append({'boot': False,
  4233. 559 'autoDelete': autoDelete,
  4234. 560 source_field: source_value})
  4235. 561
  4236. 562 if num_roots > 1:
  4237. 563 log.warning('The launch config contains %d boot disks. Will '
  4238. 564 'use the first one', num_roots)
  4239. 565 if image:
  4240. 566 if boot_disk:
  4241. 567 log.warning('A boot image is given while the launch config '
  4242. 568 'contains a boot disk, too. The launch config '
  4243. 569 'will be used.')
  4244. 570 else:
  4245. 571 if not isinstance(image, GCPMachineImage):
  4246. 572 image = self.provider.compute.images.get(image)
  4247. 573 # Explicitly set diskName; otherwise, instance name will be
  4248. 574 # used by default which may conflict with existing disks.
  4249. 575 boot_disk = {
  4250. 576 'boot': True,
  4251. 577 'autoDelete': True,
  4252. 578 'initializeParams': {
  4253. 579 'sourceImage': image.id,
  4254. 580 'diskName': 'image-disk-{0}'.format(uuid.uuid4())}}
  4255. 581
  4256. 582 if not boot_disk:
  4257. 583 log.warning('No boot disk is given for instance %s.', label)
  4258. 584 return None
  4259. 585 # The boot disk must be the first disk attached to the instance.
  4260. 586 disks.insert(0, boot_disk)
  4261. 587
  4262. 588 config = {
  4263. 589 'name': GCPInstance._generate_name_from_label(label, 'cb-inst'),
  4264. 590 'machineType': vm_type.resource_url,
  4265. 591 'disks': disks,
  4266. 592 'networkInterfaces': [network_interface]
  4267. 593 }
  4268. 594
  4269. 595 if vm_firewalls and isinstance(vm_firewalls, list):
  4270. 596 vm_firewall_names = []
  4271. 597 if isinstance(vm_firewalls[0], VMFirewall):
  4272. 598 vm_firewall_names = [f.name for f in vm_firewalls]
  4273. 599 elif isinstance(vm_firewalls[0], str):
  4274. 600 vm_firewall_names = vm_firewalls
  4275. 601 if len(vm_firewall_names) > 0:
  4276. 602 config['tags'] = {}
  4277. 603 config['tags']['items'] = vm_firewall_names
  4278. 604
  4279. 605 if user_data:
  4280. 606 entry = {'key': 'user-data', 'value': user_data}
  4281. 607 config['metadata'] = {'items': [entry]}
  4282. 608
  4283. 609 if key_pair:
  4284. 610 if not isinstance(key_pair, GCPKeyPair):
  4285. 611 key_pair = self._provider.security.key_pairs.get(key_pair)
  4286. 612 if key_pair:
  4287. 613 kp = key_pair._key_pair
  4288. 614 kp_entry = {
  4289. 615 "key": "ssh-keys",
  4290. 616 # Format is not removed from public key portion
  4291. 617 "value": "{}:{} {}".format(
  4292. 618 self.provider.vm_default_user_name,
  4293. 619 kp.public_key,
  4294. 620 kp.name)
  4295. 621 }
  4296. 622 meta = config.get('metadata', {})
  4297. 623 if meta:
  4298. 624 items = meta.get('items', [])
  4299. 625 items.append(kp_entry)
  4300. 626 else:
  4301. 627 config['metadata'] = {'items': [kp_entry]}
  4302. 628
  4303. 629 config['labels'] = {'cblabel': label}
  4304. 630
  4305. 631 operation = (self.provider
  4306. 632 .gcp_compute.instances()
  4307. 633 .insert(project=self.provider.project_name,
  4308. 634 zone=zone_name,
  4309. 635 body=config)
  4310. 636 .execute())
  4311. 637 instance_id = operation.get('targetLink')
  4312. 638 self.provider.wait_for_operation(operation, zone=zone_name)
  4313. 639 cb_inst = self.get(instance_id)
  4314. 640 return cb_inst
  4315. Total time: 0 s
  4316. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4317. Function: get at line 642
  4318. Line # Hits Time Per Hit % Time Line Contents
  4319. ==============================================================
  4320. 642 @dispatch(event="provider.compute.instances.get",
  4321. 643 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  4322. 644 @profile
  4323. 645 def get(self, instance_id):
  4324. 646 """
  4325. 647 Returns an instance given its name. Returns None
  4326. 648 if the object does not exist.
  4327. 649
  4328. 650 A GCP instance is uniquely identified by its selfLink, which is used
  4329. 651 as its id.
  4330. 652 """
  4331. 653 instance = self.provider.get_resource('instances', instance_id)
  4332. 654 return GCPInstance(self.provider, instance) if instance else None
  4333. Total time: 0 s
  4334. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4335. Function: find at line 656
  4336. Line # Hits Time Per Hit % Time Line Contents
  4337. ==============================================================
  4338. 656 @dispatch(event="provider.compute.instances.find",
  4339. 657 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  4340. 658 @profile
  4341. 659 def find(self, limit=None, marker=None, **kwargs):
  4342. 660 """
  4343. 661 Searches for instances by instance label.
  4344. 662 :return: a list of Instance objects
  4345. 663 """
  4346. 664 label = kwargs.pop('label', None)
  4347. 665
  4348. 666 # All kwargs should have been popped at this time.
  4349. 667 if len(kwargs) > 0:
  4350. 668 raise InvalidParamException(
  4351. 669 "Unrecognised parameters for search: %s. Supported "
  4352. 670 "attributes: %s" % (kwargs, 'label'))
  4353. 671
  4354. 672 instances = [instance for instance in self.list()
  4355. 673 if instance.label == label]
  4356. 674 return ClientPagedResultList(self.provider, instances,
  4357. 675 limit=limit, marker=marker)
  4358. Total time: 0 s
  4359. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4360. Function: list at line 677
  4361. Line # Hits Time Per Hit % Time Line Contents
  4362. ==============================================================
  4363. 677 @dispatch(event="provider.compute.instances.list",
  4364. 678 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  4365. 679 @profile
  4366. 680 def list(self, limit=None, marker=None):
  4367. 681 """
  4368. 682 List all instances.
  4369. 683 """
  4370. 684 # For GCP API, Acceptable values are 0 to 500, inclusive.
  4371. 685 # (Default: 500).
  4372. 686 max_result = limit if limit is not None and limit < 500 else 500
  4373. 687 response = (self.provider
  4374. 688 .gcp_compute
  4375. 689 .instances()
  4376. 690 .list(project=self.provider.project_name,
  4377. 691 zone=self.provider.default_zone,
  4378. 692 maxResults=max_result,
  4379. 693 pageToken=marker)
  4380. 694 .execute())
  4381. 695 instances = [GCPInstance(self.provider, inst)
  4382. 696 for inst in response.get('items', [])]
  4383. 697 if len(instances) > max_result:
  4384. 698 log.warning('Expected at most %d results; got %d',
  4385. 699 max_result, len(instances))
  4386. 700 return ServerPagedResultList('nextPageToken' in response,
  4387. 701 response.get('nextPageToken'),
  4388. 702 False, data=instances)
  4389. Total time: 0 s
  4390. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4391. Function: delete at line 704
  4392. Line # Hits Time Per Hit % Time Line Contents
  4393. ==============================================================
  4394. 704 @dispatch(event="provider.compute.instances.delete",
  4395. 705 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  4396. 706 @profile
  4397. 707 def delete(self, instance):
  4398. 708 instance = (instance if isinstance(instance, GCPInstance) else
  4399. 709 self.get(instance))
  4400. 710 if instance:
  4401. 711 (self._provider
  4402. 712 .gcp_compute
  4403. 713 .instances()
  4404. 714 .delete(project=self.provider.project_name,
  4405. 715 zone=instance.zone_name,
  4406. 716 instance=instance.name)
  4407. 717 .execute())
  4408. Total time: 0 s
  4409. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4410. Function: create_launch_config at line 719
  4411. Line # Hits Time Per Hit % Time Line Contents
  4412. ==============================================================
  4413. 719 @profile
  4414. 720 def create_launch_config(self):
  4415. 721 return GCPLaunchConfig(self.provider)
  4416. Total time: 0 s
  4417. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4418. Function: get at line 786
  4419. Line # Hits Time Per Hit % Time Line Contents
  4420. ==============================================================
  4421. 786 @dispatch(event="provider.networking.networks.get",
  4422. 787 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  4423. 788 @profile
  4424. 789 def get(self, network_id):
  4425. 790 network = self.provider.get_resource('networks', network_id)
  4426. 791 return GCPNetwork(self.provider, network) if network else None
  4427. Total time: 0 s
  4428. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4429. Function: find at line 793
  4430. Line # Hits Time Per Hit % Time Line Contents
  4431. ==============================================================
  4432. 793 @dispatch(event="provider.networking.networks.find",
  4433. 794 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  4434. 795 @profile
  4435. 796 def find(self, limit=None, marker=None, **kwargs):
  4436. 797 """
  4437. 798 GCP networks are global. There is at most one network with a given
  4438. 799 name.
  4439. 800 """
  4440. 801 obj_list = self
  4441. 802 filters = ['name', 'label']
  4442. 803 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  4443. 804 return ClientPagedResultList(self._provider, list(matches),
  4444. 805 limit=limit, marker=marker)
  4445. Total time: 0 s
  4446. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4447. Function: list at line 807
  4448. Line # Hits Time Per Hit % Time Line Contents
  4449. ==============================================================
  4450. 807 @dispatch(event="provider.networking.networks.list",
  4451. 808 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  4452. 809 @profile
  4453. 810 def list(self, limit=None, marker=None, filter=None):
  4454. 811 # TODO: Decide whether we keep filter in 'list'
  4455. 812 networks = []
  4456. 813 response = (self.provider
  4457. 814 .gcp_compute
  4458. 815 .networks()
  4459. 816 .list(project=self.provider.project_name,
  4460. 817 filter=filter)
  4461. 818 .execute())
  4462. 819 for network in response.get('items', []):
  4463. 820 networks.append(GCPNetwork(self.provider, network))
  4464. 821 return ClientPagedResultList(self.provider, networks,
  4465. 822 limit=limit, marker=marker)
  4466. Total time: 0 s
  4467. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4468. Function: create at line 824
  4469. Line # Hits Time Per Hit % Time Line Contents
  4470. ==============================================================
  4471. 824 @dispatch(event="provider.networking.networks.create",
  4472. 825 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  4473. 826 @profile
  4474. 827 def create(self, label, cidr_block):
  4475. 828 """
  4476. 829 Creates an auto mode VPC network with default subnets. It is possible
  4477. 830 to add additional subnets later.
  4478. 831 """
  4479. 832 GCPNetwork.assert_valid_resource_label(label)
  4480. 833 name = GCPNetwork._generate_name_from_label(label, 'cbnet')
  4481. 834 body = {'name': name}
  4482. 835 # This results in a custom mode network
  4483. 836 body['autoCreateSubnetworks'] = False
  4484. 837 response = (self.provider
  4485. 838 .gcp_compute
  4486. 839 .networks()
  4487. 840 .insert(project=self.provider.project_name,
  4488. 841 body=body)
  4489. 842 .execute())
  4490. 843 self.provider.wait_for_operation(response)
  4491. 844 cb_net = self.get(name)
  4492. 845 cb_net.label = label
  4493. 846 return cb_net
  4494. Total time: 0 s
  4495. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4496. Function: get_or_create_default at line 848
  4497. Line # Hits Time Per Hit % Time Line Contents
  4498. ==============================================================
  4499. 848 @profile
  4500. 849 def get_or_create_default(self):
  4501. 850 default_nets = self.provider.networking.networks.find(
  4502. 851 label=GCPNetwork.CB_DEFAULT_NETWORK_LABEL)
  4503. 852 if default_nets:
  4504. 853 return default_nets[0]
  4505. 854 else:
  4506. 855 log.info("Creating a CloudBridge-default network labeled %s",
  4507. 856 GCPNetwork.CB_DEFAULT_NETWORK_LABEL)
  4508. 857 return self.create(
  4509. 858 label=GCPNetwork.CB_DEFAULT_NETWORK_LABEL,
  4510. 859 cidr_block=GCPNetwork.CB_DEFAULT_IPV4RANGE)
  4511. Total time: 0 s
  4512. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4513. Function: delete at line 861
  4514. Line # Hits Time Per Hit % Time Line Contents
  4515. ==============================================================
  4516. 861 @dispatch(event="provider.networking.networks.delete",
  4517. 862 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  4518. 863 @profile
  4519. 864 def delete(self, network):
  4520. 865 # Accepts network object
  4521. 866 if isinstance(network, GCPNetwork):
  4522. 867 name = network.name
  4523. 868 # Accepts both name and ID
  4524. 869 elif 'googleapis' in network:
  4525. 870 name = network.split('/')[-1]
  4526. 871 else:
  4527. 872 name = network
  4528. 873 response = (self.provider
  4529. 874 .gcp_compute
  4530. 875 .networks()
  4531. 876 .delete(project=self.provider.project_name,
  4532. 877 network=name)
  4533. 878 .execute())
  4534. 879 self.provider.wait_for_operation(response)
  4535. 880 # Remove label
  4536. 881 tag_name = "_".join(["network", name, "label"])
  4537. 882 if not helpers.remove_metadata_item(self.provider, tag_name):
  4538. 883 log.warning('No label was found associated with this network '
  4539. 884 '"{}" when deleted.'.format(network))
  4540. 885 return True
  4541. Total time: 0 s
  4542. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4543. Function: get at line 893
  4544. Line # Hits Time Per Hit % Time Line Contents
  4545. ==============================================================
  4546. 893 @dispatch(event="provider.networking.routers.get",
  4547. 894 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  4548. 895 @profile
  4549. 896 def get(self, router_id):
  4550. 897 router = self.provider.get_resource(
  4551. 898 'routers', router_id, region=self.provider.region_name)
  4552. 899 return GCPRouter(self.provider, router) if router else None
  4553. Total time: 0 s
  4554. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4555. Function: find at line 901
  4556. Line # Hits Time Per Hit % Time Line Contents
  4557. ==============================================================
  4558. 901 @dispatch(event="provider.networking.routers.find",
  4559. 902 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  4560. 903 @profile
  4561. 904 def find(self, limit=None, marker=None, **kwargs):
  4562. 905 obj_list = self
  4563. 906 filters = ['name', 'label']
  4564. 907 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  4565. 908 return ClientPagedResultList(self._provider, list(matches),
  4566. 909 limit=limit, marker=marker)
  4567. Total time: 0 s
  4568. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4569. Function: list at line 911
  4570. Line # Hits Time Per Hit % Time Line Contents
  4571. ==============================================================
  4572. 911 @dispatch(event="provider.networking.routers.list",
  4573. 912 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  4574. 913 @profile
  4575. 914 def list(self, limit=None, marker=None):
  4576. 915 region = self.provider.region_name
  4577. 916 max_result = limit if limit is not None and limit < 500 else 500
  4578. 917 response = (self.provider
  4579. 918 .gcp_compute
  4580. 919 .routers()
  4581. 920 .list(project=self.provider.project_name,
  4582. 921 region=region,
  4583. 922 maxResults=max_result,
  4584. 923 pageToken=marker)
  4585. 924 .execute())
  4586. 925 routers = []
  4587. 926 for router in response.get('items', []):
  4588. 927 routers.append(GCPRouter(self.provider, router))
  4589. 928 if len(routers) > max_result:
  4590. 929 log.warning('Expected at most %d results; go %d',
  4591. 930 max_result, len(routers))
  4592. 931 return ServerPagedResultList('nextPageToken' in response,
  4593. 932 response.get('nextPageToken'),
  4594. 933 False, data=routers)
  4595. Total time: 0 s
  4596. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4597. Function: create at line 935
  4598. Line # Hits Time Per Hit % Time Line Contents
  4599. ==============================================================
  4600. 935 @dispatch(event="provider.networking.routers.create",
  4601. 936 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  4602. 937 @profile
  4603. 938 def create(self, label, network):
  4604. 939 log.debug("Creating GCP Router Service with params "
  4605. 940 "[label: %s network: %s]", label, network)
  4606. 941 GCPRouter.assert_valid_resource_label(label)
  4607. 942 name = GCPRouter._generate_name_from_label(label, 'cb-router')
  4608. 943
  4609. 944 if not isinstance(network, GCPNetwork):
  4610. 945 network = self.provider.networking.networks.get(network)
  4611. 946 network_url = network.resource_url
  4612. 947 region_name = self.provider.region_name
  4613. 948 response = (self.provider
  4614. 949 .gcp_compute
  4615. 950 .routers()
  4616. 951 .insert(project=self.provider.project_name,
  4617. 952 region=region_name,
  4618. 953 body={'name': name,
  4619. 954 'network': network_url})
  4620. 955 .execute())
  4621. 956 self.provider.wait_for_operation(response, region=region_name)
  4622. 957 cb_router = self.get(name)
  4623. 958 cb_router.label = label
  4624. 959 return cb_router
  4625. Total time: 0 s
  4626. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4627. Function: delete at line 961
  4628. Line # Hits Time Per Hit % Time Line Contents
  4629. ==============================================================
  4630. 961 @dispatch(event="provider.networking.routers.delete",
  4631. 962 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  4632. 963 @profile
  4633. 964 def delete(self, router):
  4634. 965 r = router if isinstance(router, GCPRouter) else self.get(router)
  4635. 966 if r:
  4636. 967 (self.provider
  4637. 968 .gcp_compute
  4638. 969 .routers()
  4639. 970 .delete(project=self.provider.project_name,
  4640. 971 region=r.region_name,
  4641. 972 router=r.name)
  4642. 973 .execute())
  4643. 974 # Remove label
  4644. 975 tag_name = "_".join(["router", r.name, "label"])
  4645. 976 if not helpers.remove_metadata_item(self.provider, tag_name):
  4646. 977 log.warning('No label was found associated with this router '
  4647. 978 '"{}" when deleted.'.format(r.name))
  4648. Total time: 0 s
  4649. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4650. Function: get at line 996
  4651. Line # Hits Time Per Hit % Time Line Contents
  4652. ==============================================================
  4653. 996 @dispatch(event="provider.networking.subnets.get",
  4654. 997 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  4655. 998 @profile
  4656. 999 def get(self, subnet_id):
  4657. 1000 subnet = self.provider.get_resource('subnetworks', subnet_id)
  4658. 1001 return GCPSubnet(self.provider, subnet) if subnet else None
  4659. Total time: 0 s
  4660. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4661. Function: list at line 1003
  4662. Line # Hits Time Per Hit % Time Line Contents
  4663. ==============================================================
  4664. 1003 @dispatch(event="provider.networking.subnets.list",
  4665. 1004 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  4666. 1005 @profile
  4667. 1006 def list(self, network=None, zone=None, limit=None, marker=None):
  4668. 1007 """
  4669. 1008 If the zone is not given, we list all subnets in the default region.
  4670. 1009 """
  4671. 1010 filter = None
  4672. 1011 if network is not None:
  4673. 1012 network = (network if isinstance(network, GCPNetwork)
  4674. 1013 else self.provider.networking.networks.get(network))
  4675. 1014 filter = 'network eq %s' % network.resource_url
  4676. 1015 if zone:
  4677. 1016 region_name = self._zone_to_region(zone)
  4678. 1017 else:
  4679. 1018 region_name = self.provider.region_name
  4680. 1019 subnets = []
  4681. 1020 response = (self.provider
  4682. 1021 .gcp_compute
  4683. 1022 .subnetworks()
  4684. 1023 .list(project=self.provider.project_name,
  4685. 1024 region=region_name,
  4686. 1025 filter=filter)
  4687. 1026 .execute())
  4688. 1027 for subnet in response.get('items', []):
  4689. 1028 subnets.append(GCPSubnet(self.provider, subnet))
  4690. 1029 return ClientPagedResultList(self.provider, subnets,
  4691. 1030 limit=limit, marker=marker)
  4692. Total time: 0 s
  4693. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4694. Function: create at line 1032
  4695. Line # Hits Time Per Hit % Time Line Contents
  4696. ==============================================================
  4697. 1032 @dispatch(event="provider.networking.subnets.create",
  4698. 1033 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  4699. 1034 @profile
  4700. 1035 def create(self, label, network, cidr_block, zone):
  4701. 1036 """
  4702. 1037 GCP subnets are regional. The region is inferred from the zone;
  4703. 1038 otherwise, the default region, as set in the
  4704. 1039 provider, is used.
  4705. 1040
  4706. 1041 If a subnet with overlapping IP range exists already, we return that
  4707. 1042 instead of creating a new subnet. In this case, other parameters, i.e.
  4708. 1043 the name and the zone, are ignored.
  4709. 1044 """
  4710. 1045 GCPSubnet.assert_valid_resource_label(label)
  4711. 1046 name = GCPSubnet._generate_name_from_label(label, 'cbsubnet')
  4712. 1047 region_name = self._zone_to_region(zone)
  4713. 1048 # for subnet in self.iter(network=network):
  4714. 1049 # if BaseNetwork.cidr_blocks_overlap(subnet.cidr_block, cidr_block):
  4715. 1050 # if subnet.region_name != region_name:
  4716. 1051 # log.error('Failed to create subnetwork in region %s: '
  4717. 1052 # 'the given IP range %s overlaps with a '
  4718. 1053 # 'subnetwork in a different region %s',
  4719. 1054 # region_name, cidr_block, subnet.region_name)
  4720. 1055 # return None
  4721. 1056 # return subnet
  4722. 1057 # if subnet.label == label and subnet.region_name == region_name:
  4723. 1058 # return subnet
  4724. 1059
  4725. 1060 body = {'ipCidrRange': cidr_block,
  4726. 1061 'name': name,
  4727. 1062 'network': network.resource_url,
  4728. 1063 'region': region_name
  4729. 1064 }
  4730. 1065 response = (self.provider
  4731. 1066 .gcp_compute
  4732. 1067 .subnetworks()
  4733. 1068 .insert(project=self.provider.project_name,
  4734. 1069 region=region_name,
  4735. 1070 body=body)
  4736. 1071 .execute())
  4737. 1072 self.provider.wait_for_operation(response, region=region_name)
  4738. 1073 cb_subnet = self.get(name)
  4739. 1074 cb_subnet.label = label
  4740. 1075 return cb_subnet
  4741. Total time: 0 s
  4742. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4743. Function: delete at line 1077
  4744. Line # Hits Time Per Hit % Time Line Contents
  4745. ==============================================================
  4746. 1077 @dispatch(event="provider.networking.subnets.delete",
  4747. 1078 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  4748. 1079 @profile
  4749. 1080 def delete(self, subnet):
  4750. 1081 sn = subnet if isinstance(subnet, GCPSubnet) else self.get(subnet)
  4751. 1082 if not sn:
  4752. 1083 return
  4753. 1084 response = (self.provider
  4754. 1085 .gcp_compute
  4755. 1086 .subnetworks()
  4756. 1087 .delete(project=self.provider.project_name,
  4757. 1088 region=sn.region_name,
  4758. 1089 subnetwork=sn.name)
  4759. 1090 .execute())
  4760. 1091 self.provider.wait_for_operation(response, region=sn.region_name)
  4761. 1092 # Remove label
  4762. 1093 tag_name = "_".join(["subnet", sn.name, "label"])
  4763. 1094 if not helpers.remove_metadata_item(self._provider, tag_name):
  4764. 1095 log.warning('No label was found associated with this subnet '
  4765. 1096 '"{}" when deleted.'.format(sn.name))
  4766. Total time: 0 s
  4767. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4768. Function: get_or_create_default at line 1098
  4769. Line # Hits Time Per Hit % Time Line Contents
  4770. ==============================================================
  4771. 1098 @profile
  4772. 1099 def get_or_create_default(self, zone):
  4773. 1100 """
  4774. 1101 Return an existing or create a new subnet for the supplied zone.
  4775. 1102
  4776. 1103 In GCP, subnets are a regional resource so a single subnet can services
  4777. 1104 an entire region. The supplied zone parameter is used to derive the
  4778. 1105 parent region under which the default subnet then exists.
  4779. 1106 """
  4780. 1107 # In case the supplied zone param is `None`, resort to the default one
  4781. 1108 region = self._zone_to_region(zone or self.provider.default_zone,
  4782. 1109 return_name_only=False)
  4783. 1110 # Check if a default subnet already exists for the given region/zone
  4784. 1111 for sn in self.find(label=GCPSubnet.CB_DEFAULT_SUBNET_LABEL):
  4785. 1112 if sn.region == region.id:
  4786. 1113 return sn
  4787. 1114 # No default subnet in the supplied zone. Look for a default network,
  4788. 1115 # then create a subnet whose address space does not overlap with any
  4789. 1116 # other existing subnets. If there are existing subnets, this process
  4790. 1117 # largely assumes the subnet address spaces are contiguous when it
  4791. 1118 # does the calculations (e.g., 10.0.0.0/24, 10.0.1.0/24).
  4792. 1119 cidr_block = GCPSubnet.CB_DEFAULT_SUBNET_IPV4RANGE
  4793. 1120 net = self.provider.networking.networks.get_or_create_default()
  4794. 1121 if net.subnets:
  4795. 1122 max_sn = net.subnets[0]
  4796. 1123 # Find the maximum address subnet address space within the network
  4797. 1124 for esn in net.subnets:
  4798. 1125 if (ipaddress.ip_network(esn.cidr_block) >
  4799. 1126 ipaddress.ip_network(max_sn.cidr_block)):
  4800. 1127 max_sn = esn
  4801. 1128 max_sn_ipa = ipaddress.ip_network(max_sn.cidr_block)
  4802. 1129 # Find the next available subnet after the max one, based on the
  4803. 1130 # max subnet size
  4804. 1131 next_sn_address = (
  4805. 1132 next(max_sn_ipa.hosts()) + max_sn_ipa.num_addresses - 1)
  4806. 1133 cidr_block = "{}/{}".format(next_sn_address, max_sn_ipa.prefixlen)
  4807. 1134 sn = self.provider.networking.subnets.create(
  4808. 1135 label=GCPSubnet.CB_DEFAULT_SUBNET_LABEL,
  4809. 1136 cidr_block=cidr_block, network=net, zone=zone)
  4810. 1137 router = self.provider.networking.routers.get_or_create_default(net)
  4811. 1138 router.attach_subnet(sn)
  4812. 1139 gateway = net.gateways.get_or_create()
  4813. 1140 router.attach_gateway(gateway)
  4814. 1141 return sn
  4815. Total time: 0 s
  4816. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4817. Function: get at line 1196
  4818. Line # Hits Time Per Hit % Time Line Contents
  4819. ==============================================================
  4820. 1196 @dispatch(event="provider.storage.volumes.get",
  4821. 1197 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  4822. 1198 @profile
  4823. 1199 def get(self, volume_id):
  4824. 1200 vol = self.provider.get_resource('disks', volume_id)
  4825. 1201 return GCPVolume(self.provider, vol) if vol else None
  4826. Total time: 0 s
  4827. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4828. Function: find at line 1203
  4829. Line # Hits Time Per Hit % Time Line Contents
  4830. ==============================================================
  4831. 1203 @dispatch(event="provider.storage.volumes.find",
  4832. 1204 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  4833. 1205 @profile
  4834. 1206 def find(self, limit=None, marker=None, **kwargs):
  4835. 1207 """
  4836. 1208 Searches for a volume by a given list of attributes.
  4837. 1209 """
  4838. 1210 label = kwargs.pop('label', None)
  4839. 1211
  4840. 1212 # All kwargs should have been popped at this time.
  4841. 1213 if len(kwargs) > 0:
  4842. 1214 raise InvalidParamException(
  4843. 1215 "Unrecognised parameters for search: %s. Supported "
  4844. 1216 "attributes: %s" % (kwargs, 'label'))
  4845. 1217
  4846. 1218 filtr = 'labels.cblabel eq ' + label
  4847. 1219 max_result = limit if limit is not None and limit < 500 else 500
  4848. 1220 response = (self.provider
  4849. 1221 .gcp_compute
  4850. 1222 .disks()
  4851. 1223 .list(project=self.provider.project_name,
  4852. 1224 zone=self.provider.default_zone,
  4853. 1225 filter=filtr,
  4854. 1226 maxResults=max_result,
  4855. 1227 pageToken=marker)
  4856. 1228 .execute())
  4857. 1229 gcp_vols = [GCPVolume(self.provider, vol)
  4858. 1230 for vol in response.get('items', [])]
  4859. 1231 if len(gcp_vols) > max_result:
  4860. 1232 log.warning('Expected at most %d results; got %d',
  4861. 1233 max_result, len(gcp_vols))
  4862. 1234 return ServerPagedResultList('nextPageToken' in response,
  4863. 1235 response.get('nextPageToken'),
  4864. 1236 False, data=gcp_vols)
  4865. Total time: 0 s
  4866. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4867. Function: list at line 1238
  4868. Line # Hits Time Per Hit % Time Line Contents
  4869. ==============================================================
  4870. 1238 @dispatch(event="provider.storage.volumes.list",
  4871. 1239 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  4872. 1240 @profile
  4873. 1241 def list(self, limit=None, marker=None):
  4874. 1242 """
  4875. 1243 List all volumes.
  4876. 1244
  4877. 1245 limit: The maximum number of volumes to return. The returned
  4878. 1246 ResultList's is_truncated property can be used to determine
  4879. 1247 whether more records are available.
  4880. 1248 """
  4881. 1249 # For GCP API, Acceptable values are 0 to 500, inclusive.
  4882. 1250 # (Default: 500).
  4883. 1251 max_result = limit if limit is not None and limit < 500 else 500
  4884. 1252 response = (self.provider
  4885. 1253 .gcp_compute
  4886. 1254 .disks()
  4887. 1255 .list(project=self.provider.project_name,
  4888. 1256 zone=self.provider.default_zone,
  4889. 1257 maxResults=max_result,
  4890. 1258 pageToken=marker)
  4891. 1259 .execute())
  4892. 1260 gcp_vols = [GCPVolume(self.provider, vol)
  4893. 1261 for vol in response.get('items', [])]
  4894. 1262 if len(gcp_vols) > max_result:
  4895. 1263 log.warning('Expected at most %d results; got %d',
  4896. 1264 max_result, len(gcp_vols))
  4897. 1265 return ServerPagedResultList('nextPageToken' in response,
  4898. 1266 response.get('nextPageToken'),
  4899. 1267 False, data=gcp_vols)
  4900. Total time: 0 s
  4901. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4902. Function: create at line 1269
  4903. Line # Hits Time Per Hit % Time Line Contents
  4904. ==============================================================
  4905. 1269 @dispatch(event="provider.storage.volumes.create",
  4906. 1270 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  4907. 1271 @profile
  4908. 1272 def create(self, label, size, zone, snapshot=None, description=None):
  4909. 1273 GCPVolume.assert_valid_resource_label(label)
  4910. 1274 name = GCPVolume._generate_name_from_label(label, 'cb-vol')
  4911. 1275 if not isinstance(zone, GCPPlacementZone):
  4912. 1276 zone = GCPPlacementZone(
  4913. 1277 self.provider,
  4914. 1278 self.provider.get_resource('zones', zone))
  4915. 1279 zone_name = zone.name
  4916. 1280 snapshot_id = snapshot.id if isinstance(
  4917. 1281 snapshot, GCPSnapshot) and snapshot else snapshot
  4918. 1282 labels = {'cblabel': label}
  4919. 1283 if description:
  4920. 1284 labels['description'] = description
  4921. 1285 disk_body = {
  4922. 1286 'name': name,
  4923. 1287 'sizeGb': size,
  4924. 1288 'type': 'zones/{0}/diskTypes/{1}'.format(zone_name, 'pd-standard'),
  4925. 1289 'sourceSnapshot': snapshot_id,
  4926. 1290 'labels': labels
  4927. 1291 }
  4928. 1292 operation = (self.provider
  4929. 1293 .gcp_compute
  4930. 1294 .disks()
  4931. 1295 .insert(
  4932. 1296 project=self._provider.project_name,
  4933. 1297 zone=zone_name,
  4934. 1298 body=disk_body)
  4935. 1299 .execute())
  4936. 1300 cb_vol = self.get(operation.get('targetLink'))
  4937. 1301 return cb_vol
  4938. Total time: 0 s
  4939. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4940. Function: delete at line 1303
  4941. Line # Hits Time Per Hit % Time Line Contents
  4942. ==============================================================
  4943. 1303 @dispatch(event="provider.storage.volumes.delete",
  4944. 1304 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  4945. 1305 @profile
  4946. 1306 def delete(self, volume):
  4947. 1307 volume = volume if isinstance(volume, GCPVolume) else self.get(volume)
  4948. 1308 if volume:
  4949. 1309 (self._provider.gcp_compute
  4950. 1310 .disks()
  4951. 1311 .delete(project=self.provider.project_name,
  4952. 1312 zone=volume.zone_name,
  4953. 1313 disk=volume.name)
  4954. 1314 .execute())
  4955. Total time: 0 s
  4956. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4957. Function: get at line 1322
  4958. Line # Hits Time Per Hit % Time Line Contents
  4959. ==============================================================
  4960. 1322 @dispatch(event="provider.storage.snapshots.get",
  4961. 1323 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  4962. 1324 @profile
  4963. 1325 def get(self, snapshot_id):
  4964. 1326 snapshot = self.provider.get_resource('snapshots', snapshot_id)
  4965. 1327 return GCPSnapshot(self.provider, snapshot) if snapshot else None
  4966. Total time: 0 s
  4967. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  4968. Function: find at line 1329
  4969. Line # Hits Time Per Hit % Time Line Contents
  4970. ==============================================================
  4971. 1329 @dispatch(event="provider.storage.snapshots.find",
  4972. 1330 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  4973. 1331 @profile
  4974. 1332 def find(self, limit=None, marker=None, **kwargs):
  4975. 1333 label = kwargs.pop('label', None)
  4976. 1334
  4977. 1335 # All kwargs should have been popped at this time.
  4978. 1336 if len(kwargs) > 0:
  4979. 1337 raise InvalidParamException(
  4980. 1338 "Unrecognised parameters for search: %s. Supported "
  4981. 1339 "attributes: %s" % (kwargs, 'label'))
  4982. 1340
  4983. 1341 filtr = 'labels.cblabel eq ' + label
  4984. 1342 max_result = limit if limit is not None and limit < 500 else 500
  4985. 1343 response = (self.provider
  4986. 1344 .gcp_compute
  4987. 1345 .snapshots()
  4988. 1346 .list(project=self.provider.project_name,
  4989. 1347 filter=filtr,
  4990. 1348 maxResults=max_result,
  4991. 1349 pageToken=marker)
  4992. 1350 .execute())
  4993. 1351 snapshots = [GCPSnapshot(self.provider, snapshot)
  4994. 1352 for snapshot in response.get('items', [])]
  4995. 1353 if len(snapshots) > max_result:
  4996. 1354 log.warning('Expected at most %d results; got %d',
  4997. 1355 max_result, len(snapshots))
  4998. 1356 return ServerPagedResultList('nextPageToken' in response,
  4999. 1357 response.get('nextPageToken'),
  5000. 1358 False, data=snapshots)
  5001. Total time: 0 s
  5002. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5003. Function: list at line 1360
  5004. Line # Hits Time Per Hit % Time Line Contents
  5005. ==============================================================
  5006. 1360 @dispatch(event="provider.storage.snapshots.list",
  5007. 1361 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  5008. 1362 @profile
  5009. 1363 def list(self, limit=None, marker=None):
  5010. 1364 max_result = limit if limit is not None and limit < 500 else 500
  5011. 1365 response = (self.provider
  5012. 1366 .gcp_compute
  5013. 1367 .snapshots()
  5014. 1368 .list(project=self.provider.project_name,
  5015. 1369 maxResults=max_result,
  5016. 1370 pageToken=marker)
  5017. 1371 .execute())
  5018. 1372 snapshots = [GCPSnapshot(self.provider, snapshot)
  5019. 1373 for snapshot in response.get('items', [])]
  5020. 1374 if len(snapshots) > max_result:
  5021. 1375 log.warning('Expected at most %d results; got %d',
  5022. 1376 max_result, len(snapshots))
  5023. 1377 return ServerPagedResultList('nextPageToken' in response,
  5024. 1378 response.get('nextPageToken'),
  5025. 1379 False, data=snapshots)
  5026. Total time: 0 s
  5027. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5028. Function: create at line 1381
  5029. Line # Hits Time Per Hit % Time Line Contents
  5030. ==============================================================
  5031. 1381 @dispatch(event="provider.storage.snapshots.create",
  5032. 1382 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  5033. 1383 @profile
  5034. 1384 def create(self, label, volume, description=None):
  5035. 1385 GCPSnapshot.assert_valid_resource_label(label)
  5036. 1386 name = GCPSnapshot._generate_name_from_label(label, 'cbsnap')
  5037. 1387 volume_name = volume.name if isinstance(volume, GCPVolume) else volume
  5038. 1388 labels = {'cblabel': label}
  5039. 1389 if description:
  5040. 1390 labels['description'] = description
  5041. 1391 snapshot_body = {
  5042. 1392 "name": name,
  5043. 1393 "labels": labels
  5044. 1394 }
  5045. 1395 operation = (self.provider
  5046. 1396 .gcp_compute
  5047. 1397 .disks()
  5048. 1398 .createSnapshot(
  5049. 1399 project=self.provider.project_name,
  5050. 1400 zone=self.provider.default_zone,
  5051. 1401 disk=volume_name, body=snapshot_body)
  5052. 1402 .execute())
  5053. 1403 if 'zone' not in operation:
  5054. 1404 return None
  5055. 1405 self.provider.wait_for_operation(operation,
  5056. 1406 zone=self.provider.default_zone)
  5057. 1407 cb_snap = self.get(name)
  5058. 1408 return cb_snap
  5059. Total time: 0 s
  5060. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5061. Function: delete at line 1410
  5062. Line # Hits Time Per Hit % Time Line Contents
  5063. ==============================================================
  5064. 1410 @dispatch(event="provider.storage.snapshots.delete",
  5065. 1411 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  5066. 1412 @profile
  5067. 1413 def delete(self, snapshot):
  5068. 1414 snapshot = (snapshot if isinstance(snapshot, GCPSnapshot)
  5069. 1415 else self.get(snapshot))
  5070. 1416 if snapshot:
  5071. 1417 (self.provider
  5072. 1418 .gcp_compute
  5073. 1419 .snapshots()
  5074. 1420 .delete(project=self.provider.project_name,
  5075. 1421 snapshot=snapshot.name)
  5076. 1422 .execute())
  5077. Total time: 0 s
  5078. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5079. Function: get at line 1430
  5080. Line # Hits Time Per Hit % Time Line Contents
  5081. ==============================================================
  5082. 1430 @dispatch(event="provider.storage.buckets.get",
  5083. 1431 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  5084. 1432 @profile
  5085. 1433 def get(self, bucket_id):
  5086. 1434 """
  5087. 1435 Returns a bucket given its ID. Returns ``None`` if the bucket
  5088. 1436 does not exist or if the user does not have permission to access the
  5089. 1437 bucket.
  5090. 1438 """
  5091. 1439 bucket = self.provider.get_resource('buckets', bucket_id)
  5092. 1440 return GCPBucket(self.provider, bucket) if bucket else None
  5093. Total time: 0 s
  5094. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5095. Function: find at line 1442
  5096. Line # Hits Time Per Hit % Time Line Contents
  5097. ==============================================================
  5098. 1442 @dispatch(event="provider.storage.buckets.find",
  5099. 1443 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  5100. 1444 @profile
  5101. 1445 def find(self, limit=None, marker=None, **kwargs):
  5102. 1446 name = kwargs.pop('name', None)
  5103. 1447
  5104. 1448 # All kwargs should have been popped at this time.
  5105. 1449 if len(kwargs) > 0:
  5106. 1450 raise InvalidParamException(
  5107. 1451 "Unrecognised parameters for search: %s. Supported "
  5108. 1452 "attributes: %s" % (kwargs, 'name'))
  5109. 1453
  5110. 1454 buckets = [bucket for bucket in self if name in bucket.name]
  5111. 1455 return ClientPagedResultList(self.provider, buckets, limit=limit,
  5112. 1456 marker=marker)
  5113. Total time: 0 s
  5114. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5115. Function: list at line 1458
  5116. Line # Hits Time Per Hit % Time Line Contents
  5117. ==============================================================
  5118. 1458 @dispatch(event="provider.storage.buckets.list",
  5119. 1459 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  5120. 1460 @profile
  5121. 1461 def list(self, limit=None, marker=None):
  5122. 1462 """
  5123. 1463 List all containers.
  5124. 1464 """
  5125. 1465 max_result = limit if limit is not None and limit < 500 else 500
  5126. 1466 response = (self.provider
  5127. 1467 .gcp_storage
  5128. 1468 .buckets()
  5129. 1469 .list(project=self.provider.project_name,
  5130. 1470 maxResults=max_result,
  5131. 1471 pageToken=marker)
  5132. 1472 .execute())
  5133. 1473 buckets = []
  5134. 1474 for bucket in response.get('items', []):
  5135. 1475 buckets.append(GCPBucket(self.provider, bucket))
  5136. 1476 if len(buckets) > max_result:
  5137. 1477 log.warning('Expected at most %d results; got %d',
  5138. 1478 max_result, len(buckets))
  5139. 1479 return ServerPagedResultList('nextPageToken' in response,
  5140. 1480 response.get('nextPageToken'),
  5141. 1481 False, data=buckets)
  5142. Total time: 0 s
  5143. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5144. Function: create at line 1483
  5145. Line # Hits Time Per Hit % Time Line Contents
  5146. ==============================================================
  5147. 1483 @dispatch(event="provider.storage.buckets.create",
  5148. 1484 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  5149. 1485 @profile
  5150. 1486 def create(self, name, location=None):
  5151. 1487 GCPBucket.assert_valid_resource_name(name)
  5152. 1488 body = {'name': name}
  5153. 1489 if location:
  5154. 1490 body['location'] = location
  5155. 1491 try:
  5156. 1492 response = (self.provider
  5157. 1493 .gcp_storage
  5158. 1494 .buckets()
  5159. 1495 .insert(project=self.provider.project_name,
  5160. 1496 body=body)
  5161. 1497 .execute())
  5162. 1498 # GCP has a rate limit of 1 operation per 2 seconds for bucket
  5163. 1499 # creation/deletion: https://cloud.google.com/storage/quotas.
  5164. 1500 # Throttle here to avoid future failures.
  5165. 1501 time.sleep(2)
  5166. 1502 return GCPBucket(self.provider, response)
  5167. 1503 except googleapiclient.errors.HttpError as http_error:
  5168. 1504 # 409 = conflict
  5169. 1505 if http_error.resp.status in [409]:
  5170. 1506 raise DuplicateResourceException(
  5171. 1507 'Bucket already exists with name {0}'.format(name))
  5172. 1508 else:
  5173. 1509 raise
  5174. Total time: 0 s
  5175. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5176. Function: delete at line 1511
  5177. Line # Hits Time Per Hit % Time Line Contents
  5178. ==============================================================
  5179. 1511 @dispatch(event="provider.storage.buckets.delete",
  5180. 1512 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  5181. 1513 @profile
  5182. 1514 def delete(self, bucket):
  5183. 1515 """
  5184. 1516 Delete this bucket.
  5185. 1517 """
  5186. 1518 b = bucket if isinstance(bucket, GCPBucket) else self.get(bucket)
  5187. 1519 if b:
  5188. 1520 (self.provider
  5189. 1521 .gcp_storage
  5190. 1522 .buckets()
  5191. 1523 .delete(bucket=b.name)
  5192. 1524 .execute())
  5193. 1525 # GCP has a rate limit of 1 operation per 2 seconds for bucket
  5194. 1526 # creation/deletion: https://cloud.google.com/storage/quotas.
  5195. 1527 # Throttle here to avoid future failures.
  5196. 1528 time.sleep(2)
  5197. Total time: 0 s
  5198. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5199. Function: get at line 1536
  5200. Line # Hits Time Per Hit % Time Line Contents
  5201. ==============================================================
  5202. 1536 @profile
  5203. 1537 def get(self, bucket, name):
  5204. 1538 """
  5205. 1539 Retrieve a given object from this bucket.
  5206. 1540 """
  5207. 1541 obj = self.provider.get_resource('objects', name,
  5208. 1542 bucket=bucket.name)
  5209. 1543 return GCPBucketObject(self.provider, bucket, obj) if obj else None
  5210. Total time: 0 s
  5211. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5212. Function: list at line 1545
  5213. Line # Hits Time Per Hit % Time Line Contents
  5214. ==============================================================
  5215. 1545 @profile
  5216. 1546 def list(self, bucket, limit=None, marker=None, prefix=None):
  5217. 1547 """
  5218. 1548 List all objects within this bucket.
  5219. 1549 """
  5220. 1550 max_result = limit if limit is not None and limit < 500 else 500
  5221. 1551 response = (self.provider
  5222. 1552 .gcp_storage
  5223. 1553 .objects()
  5224. 1554 .list(bucket=bucket.name,
  5225. 1555 prefix=prefix if prefix else '',
  5226. 1556 maxResults=max_result,
  5227. 1557 pageToken=marker)
  5228. 1558 .execute())
  5229. 1559 objects = []
  5230. 1560 for obj in response.get('items', []):
  5231. 1561 objects.append(GCPBucketObject(self.provider, bucket, obj))
  5232. 1562 if len(objects) > max_result:
  5233. 1563 log.warning('Expected at most %d results; got %d',
  5234. 1564 max_result, len(objects))
  5235. 1565 return ServerPagedResultList('nextPageToken' in response,
  5236. 1566 response.get('nextPageToken'),
  5237. 1567 False, data=objects)
  5238. Total time: 0 s
  5239. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5240. Function: find at line 1569
  5241. Line # Hits Time Per Hit % Time Line Contents
  5242. ==============================================================
  5243. 1569 @profile
  5244. 1570 def find(self, bucket, limit=None, marker=None, **kwargs):
  5245. 1571 filters = ['name']
  5246. 1572 matches = cb_helpers.generic_find(filters, kwargs, bucket.objects)
  5247. 1573 return ClientPagedResultList(self._provider, list(matches),
  5248. 1574 limit=limit, marker=marker)
  5249. Total time: 0 s
  5250. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5251. Function: create at line 1586
  5252. Line # Hits Time Per Hit % Time Line Contents
  5253. ==============================================================
  5254. 1586 @profile
  5255. 1587 def create(self, bucket, name):
  5256. 1588 response = self._create_object_with_media_body(
  5257. 1589 bucket,
  5258. 1590 name,
  5259. 1591 googleapiclient.http.MediaIoBaseUpload(
  5260. 1592 io.BytesIO(b''), mimetype='plain/text'))
  5261. 1593 return GCPBucketObject(self._provider,
  5262. 1594 bucket,
  5263. 1595 response) if response else None
  5264. Total time: 0 s
  5265. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5266. Function: get_or_create at line 1610
  5267. Line # Hits Time Per Hit % Time Line Contents
  5268. ==============================================================
  5269. 1610 @dispatch(event="provider.networking.gateways.get_or_create",
  5270. 1611 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  5271. 1612 @profile
  5272. 1613 def get_or_create(self, network):
  5273. 1614 return self._default_internet_gateway
  5274. Total time: 0 s
  5275. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5276. Function: delete at line 1616
  5277. Line # Hits Time Per Hit % Time Line Contents
  5278. ==============================================================
  5279. 1616 @dispatch(event="provider.networking.gateways.delete",
  5280. 1617 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  5281. 1618 @profile
  5282. 1619 def delete(self, network, gateway):
  5283. 1620 pass
  5284. Total time: 0 s
  5285. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5286. Function: list at line 1622
  5287. Line # Hits Time Per Hit % Time Line Contents
  5288. ==============================================================
  5289. 1622 @dispatch(event="provider.networking.gateways.list",
  5290. 1623 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  5291. 1624 @profile
  5292. 1625 def list(self, network, limit=None, marker=None):
  5293. 1626 gws = [self._default_internet_gateway]
  5294. 1627 return ClientPagedResultList(self._provider,
  5295. 1628 gws,
  5296. 1629 limit=limit, marker=marker)
  5297. Total time: 0 s
  5298. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5299. Function: get at line 1637
  5300. Line # Hits Time Per Hit % Time Line Contents
  5301. ==============================================================
  5302. 1637 @dispatch(event="provider.networking.floating_ips.get",
  5303. 1638 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  5304. 1639 @profile
  5305. 1640 def get(self, gateway, floating_ip_id):
  5306. 1641 fip = self.provider.get_resource('addresses', floating_ip_id)
  5307. 1642 return (GCPFloatingIP(self.provider, fip)
  5308. 1643 if fip else None)
  5309. Total time: 0 s
  5310. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5311. Function: list at line 1645
  5312. Line # Hits Time Per Hit % Time Line Contents
  5313. ==============================================================
  5314. 1645 @dispatch(event="provider.networking.floating_ips.list",
  5315. 1646 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  5316. 1647 @profile
  5317. 1648 def list(self, gateway, limit=None, marker=None):
  5318. 1649 max_result = limit if limit is not None and limit < 500 else 500
  5319. 1650 response = (self.provider
  5320. 1651 .gcp_compute
  5321. 1652 .addresses()
  5322. 1653 .list(project=self.provider.project_name,
  5323. 1654 region=self.provider.region_name,
  5324. 1655 maxResults=max_result,
  5325. 1656 pageToken=marker)
  5326. 1657 .execute())
  5327. 1658 ips = [GCPFloatingIP(self.provider, ip)
  5328. 1659 for ip in response.get('items', [])]
  5329. 1660 if len(ips) > max_result:
  5330. 1661 log.warning('Expected at most %d results; got %d',
  5331. 1662 max_result, len(ips))
  5332. 1663 return ServerPagedResultList('nextPageToken' in response,
  5333. 1664 response.get('nextPageToken'),
  5334. 1665 False, data=ips)
  5335. Total time: 0 s
  5336. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5337. Function: create at line 1667
  5338. Line # Hits Time Per Hit % Time Line Contents
  5339. ==============================================================
  5340. 1667 @dispatch(event="provider.networking.floating_ips.create",
  5341. 1668 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  5342. 1669 @profile
  5343. 1670 def create(self, gateway):
  5344. 1671 region_name = self.provider.region_name
  5345. 1672 ip_name = 'ip-{0}'.format(uuid.uuid4())
  5346. 1673 response = (self.provider
  5347. 1674 .gcp_compute
  5348. 1675 .addresses()
  5349. 1676 .insert(project=self.provider.project_name,
  5350. 1677 region=region_name,
  5351. 1678 body={'name': ip_name})
  5352. 1679 .execute())
  5353. 1680 self.provider.wait_for_operation(response, region=region_name)
  5354. 1681 return self.get(gateway, ip_name)
  5355. Total time: 0 s
  5356. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/gcp/services.py
  5357. Function: delete at line 1683
  5358. Line # Hits Time Per Hit % Time Line Contents
  5359. ==============================================================
  5360. 1683 @dispatch(event="provider.networking.floating_ips.delete",
  5361. 1684 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  5362. 1685 @profile
  5363. 1686 def delete(self, gateway, fip):
  5364. 1687 fip = (fip if isinstance(fip, GCPFloatingIP)
  5365. 1688 else self.get(gateway, fip))
  5366. 1689 project_name = self.provider.project_name
  5367. 1690 # First, delete the forwarding rule, if there is any.
  5368. 1691 # pylint:disable=protected-access
  5369. 1692 if fip._rule:
  5370. 1693 response = (self.provider
  5371. 1694 .gcp_compute
  5372. 1695 .forwardingRules()
  5373. 1696 .delete(project=project_name,
  5374. 1697 region=fip.region_name,
  5375. 1698 forwardingRule=fip._rule['name'])
  5376. 1699 .execute())
  5377. 1700 self.provider.wait_for_operation(response,
  5378. 1701 region=fip.region_name)
  5379. 1702
  5380. 1703 # Release the address.
  5381. 1704 response = (self.provider
  5382. 1705 .gcp_compute
  5383. 1706 .addresses()
  5384. 1707 .delete(project=project_name,
  5385. 1708 region=fip.region_name,
  5386. 1709 address=fip._ip['name'])
  5387. 1710 .execute())
  5388. 1711 self.provider.wait_for_operation(response,
  5389. 1712 region=fip.region_name)
  5390. Total time: 0 s
  5391. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5392. Function: label at line 108
  5393. Line # Hits Time Per Hit % Time Line Contents
  5394. ==============================================================
  5395. 108 @label.setter
  5396. 109 # pylint:disable=arguments-differ
  5397. 110 @profile
  5398. 111 def label(self, value):
  5399. 112 """
  5400. 113 Set the image label.
  5401. 114 """
  5402. 115 self.assert_valid_resource_label(value)
  5403. 116 self._provider.os_conn.image.update_image(
  5404. 117 self._os_image, name=value or "")
  5405. Total time: 0 s
  5406. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5407. Function: refresh at line 148
  5408. Line # Hits Time Per Hit % Time Line Contents
  5409. ==============================================================
  5410. 148 @profile
  5411. 149 def refresh(self):
  5412. 150 """
  5413. 151 Refreshes the state of this instance by re-querying the cloud provider
  5414. 152 for its latest state.
  5415. 153 """
  5416. 154 log.debug("Refreshing OpenStack Machine Image")
  5417. 155 image = self._provider.compute.images.get(self.id)
  5418. 156 if image:
  5419. 157 # pylint:disable=protected-access
  5420. 158 self._os_image = image._os_image
  5421. 159 else:
  5422. 160 # The image no longer exists and cannot be refreshed.
  5423. 161 # set the status to unknown
  5424. 162 self._os_image.status = 'unknown'
  5425. Total time: 0 s
  5426. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5427. Function: label at line 312
  5428. Line # Hits Time Per Hit % Time Line Contents
  5429. ==============================================================
  5430. 312 @label.setter
  5431. 313 # pylint:disable=arguments-differ
  5432. 314 @profile
  5433. 315 def label(self, value):
  5434. 316 """
  5435. 317 Set the instance label.
  5436. 318 """
  5437. 319 self.assert_valid_resource_label(value)
  5438. 320
  5439. 321 self._os_instance.name = value
  5440. 322 self._os_instance.update(name=value or "cb-inst")
  5441. Total time: 0 s
  5442. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5443. Function: refresh at line 493
  5444. Line # Hits Time Per Hit % Time Line Contents
  5445. ==============================================================
  5446. 493 @profile
  5447. 494 def refresh(self):
  5448. 495 """
  5449. 496 Refreshes the state of this instance by re-querying the cloud provider
  5450. 497 for its latest state.
  5451. 498 """
  5452. 499 instance = self._provider.compute.instances.get(
  5453. 500 self.id)
  5454. 501 if instance:
  5455. 502 # pylint:disable=protected-access
  5456. 503 self._os_instance = instance._os_instance
  5457. 504 else:
  5458. 505 # The instance no longer exists and cannot be refreshed.
  5459. 506 # set the status to unknown
  5460. 507 self._os_instance.status = 'unknown'
  5461. Total time: 0 s
  5462. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5463. Function: label at line 582
  5464. Line # Hits Time Per Hit % Time Line Contents
  5465. ==============================================================
  5466. 582 @label.setter
  5467. 583 # pylint:disable=arguments-differ
  5468. 584 @profile
  5469. 585 def label(self, value):
  5470. 586 """
  5471. 587 Set the volume label.
  5472. 588 """
  5473. 589 self.assert_valid_resource_label(value)
  5474. 590 self._volume.name = value
  5475. 591 self._volume.update(name=value or "")
  5476. Total time: 0 s
  5477. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5478. Function: description at line 597
  5479. Line # Hits Time Per Hit % Time Line Contents
  5480. ==============================================================
  5481. 597 @description.setter
  5482. 598 @profile
  5483. 599 def description(self, value):
  5484. 600 self._volume.description = value
  5485. 601 self._volume.update(description=value)
  5486. Total time: 0 s
  5487. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5488. Function: refresh at line 662
  5489. Line # Hits Time Per Hit % Time Line Contents
  5490. ==============================================================
  5491. 662 @profile
  5492. 663 def refresh(self):
  5493. 664 """
  5494. 665 Refreshes the state of this volume by re-querying the cloud provider
  5495. 666 for its latest state.
  5496. 667 """
  5497. 668 vol = self._provider.storage.volumes.get(
  5498. 669 self.id)
  5499. 670 if vol:
  5500. 671 # pylint:disable=protected-access
  5501. 672 self._volume = vol._volume # pylint:disable=protected-access
  5502. 673 else:
  5503. 674 # The volume no longer exists and cannot be refreshed.
  5504. 675 # set the status to unknown
  5505. 676 self._volume.status = 'unknown'
  5506. Total time: 0 s
  5507. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5508. Function: label at line 710
  5509. Line # Hits Time Per Hit % Time Line Contents
  5510. ==============================================================
  5511. 710 @label.setter
  5512. 711 # pylint:disable=arguments-differ
  5513. 712 @profile
  5514. 713 def label(self, value):
  5515. 714 """
  5516. 715 Set the snapshot label.
  5517. 716 """
  5518. 717 self.assert_valid_resource_label(value)
  5519. 718 self._snapshot.name = value
  5520. 719 self._snapshot.update(name=value or "")
  5521. Total time: 0 s
  5522. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5523. Function: description at line 725
  5524. Line # Hits Time Per Hit % Time Line Contents
  5525. ==============================================================
  5526. 725 @description.setter
  5527. 726 @profile
  5528. 727 def description(self, value):
  5529. 728 self._snapshot.description = value
  5530. 729 self._snapshot.update(description=value)
  5531. Total time: 0 s
  5532. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5533. Function: refresh at line 748
  5534. Line # Hits Time Per Hit % Time Line Contents
  5535. ==============================================================
  5536. 748 @profile
  5537. 749 def refresh(self):
  5538. 750 """
  5539. 751 Refreshes the state of this snapshot by re-querying the cloud provider
  5540. 752 for its latest state.
  5541. 753 """
  5542. 754 snap = self._provider.storage.snapshots.get(
  5543. 755 self.id)
  5544. 756 if snap:
  5545. 757 # pylint:disable=protected-access
  5546. 758 self._snapshot = snap._snapshot
  5547. 759 else:
  5548. 760 # The snapshot no longer exists and cannot be refreshed.
  5549. 761 # set the status to unknown
  5550. 762 self._snapshot.status = 'unknown'
  5551. Total time: 1.24232 s
  5552. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5553. Function: label at line 811
  5554. Line # Hits Time Per Hit % Time Line Contents
  5555. ==============================================================
  5556. 811 @label.setter
  5557. 812 @profile
  5558. 813 def label(self, value):
  5559. 814 """
  5560. 815 Set the network label.
  5561. 816 """
  5562. 817 1 9.0 9.0 0.0 self.assert_valid_resource_label(value)
  5563. 818 1 6.0 6.0 0.0 self._provider.neutron.update_network(
  5564. 819 1 832175.0 832175.0 67.0 self.id, {'network': {'name': value or ""}})
  5565. 820 1 410128.0 410128.0 33.0 self.refresh()
  5566. Total time: 1.343 s
  5567. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5568. Function: refresh at line 842
  5569. Line # Hits Time Per Hit % Time Line Contents
  5570. ==============================================================
  5571. 842 @profile
  5572. 843 def refresh(self):
  5573. 844 """Refresh the state of this network by re-querying the provider."""
  5574. 845 3 1342994.0 447664.7 100.0 network = self._provider.networking.networks.get(self.id)
  5575. 846 3 3.0 1.0 0.0 if network:
  5576. 847 # pylint:disable=protected-access
  5577. 848 1 2.0 2.0 0.0 self._network = network._network
  5578. 849 else:
  5579. 850 # Network no longer exists
  5580. 851 2 4.0 2.0 0.0 self._network = {}
  5581. Total time: 0 s
  5582. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5583. Function: label at line 877
  5584. Line # Hits Time Per Hit % Time Line Contents
  5585. ==============================================================
  5586. 877 @label.setter
  5587. 878 @profile
  5588. 879 def label(self, value): # pylint:disable=arguments-differ
  5589. 880 """
  5590. 881 Set the subnet label.
  5591. 882 """
  5592. 883 self.assert_valid_resource_label(value)
  5593. 884 self._provider.neutron.update_subnet(
  5594. 885 self.id, {'subnet': {'name': value or ""}})
  5595. 886 self._subnet['name'] = value
  5596. Total time: 0 s
  5597. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5598. Function: refresh at line 910
  5599. Line # Hits Time Per Hit % Time Line Contents
  5600. ==============================================================
  5601. 910 @profile
  5602. 911 def refresh(self):
  5603. 912 subnet = self._provider.networking.subnets.get(self.id)
  5604. 913 if subnet:
  5605. 914 # pylint:disable=protected-access
  5606. 915 self._subnet = subnet._subnet
  5607. 916 self._state = SubnetState.AVAILABLE
  5608. 917 else:
  5609. 918 # subnet no longer exists
  5610. 919 self._state = SubnetState.UNKNOWN
  5611. Total time: 0 s
  5612. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5613. Function: refresh at line 944
  5614. Line # Hits Time Per Hit % Time Line Contents
  5615. ==============================================================
  5616. 944 @profile
  5617. 945 def refresh(self):
  5618. 946 net = self._provider.networking.networks.get(
  5619. 947 self._ip.floating_network_id)
  5620. 948 gw = net.gateways.get_or_create()
  5621. 949 fip = gw.floating_ips.get(self.id)
  5622. 950 # pylint:disable=protected-access
  5623. 951 self._ip = fip._ip
  5624. Total time: 0 s
  5625. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5626. Function: label at line 976
  5627. Line # Hits Time Per Hit % Time Line Contents
  5628. ==============================================================
  5629. 976 @label.setter
  5630. 977 @profile
  5631. 978 def label(self, value): # pylint:disable=arguments-differ
  5632. 979 """
  5633. 980 Set the router label.
  5634. 981 """
  5635. 982 self.assert_valid_resource_label(value)
  5636. 983 self._router = self._provider.os_conn.update_router(self.id, value)
  5637. Total time: 0 s
  5638. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5639. Function: refresh at line 985
  5640. Line # Hits Time Per Hit % Time Line Contents
  5641. ==============================================================
  5642. 985 @profile
  5643. 986 def refresh(self):
  5644. 987 self._router = self._provider.os_conn.get_router(self.id)
  5645. Total time: 0 s
  5646. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5647. Function: refresh at line 1070
  5648. Line # Hits Time Per Hit % Time Line Contents
  5649. ==============================================================
  5650. 1070 @profile
  5651. 1071 def refresh(self):
  5652. 1072 """Refresh the state of this network by re-querying the provider."""
  5653. 1073 network = self._provider.networking.networks.get(self.id)
  5654. 1074 if network:
  5655. 1075 # pylint:disable=protected-access
  5656. 1076 self._gateway_net = network._network
  5657. 1077 else:
  5658. 1078 # subnet no longer exists
  5659. 1079 self._gateway_net.state = NetworkState.UNKNOWN
  5660. Total time: 0 s
  5661. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5662. Function: description at line 1137
  5663. Line # Hits Time Per Hit % Time Line Contents
  5664. ==============================================================
  5665. 1137 @description.setter
  5666. 1138 @profile
  5667. 1139 def description(self, value):
  5668. 1140 if not value:
  5669. 1141 value = ""
  5670. 1142 value += " [{}{}]".format(self._network_id_tag,
  5671. 1143 self.network_id)
  5672. 1144 self._provider.os_conn.network.update_security_group(
  5673. 1145 self.id, description=value)
  5674. 1146 self.refresh()
  5675. Total time: 0 s
  5676. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5677. Function: label at line 1159
  5678. Line # Hits Time Per Hit % Time Line Contents
  5679. ==============================================================
  5680. 1159 @label.setter
  5681. 1160 # pylint:disable=arguments-differ
  5682. 1161 @profile
  5683. 1162 def label(self, value):
  5684. 1163 self.assert_valid_resource_label(value)
  5685. 1164 self._provider.os_conn.network.update_security_group(
  5686. 1165 self.id, name=value or "")
  5687. 1166 self.refresh()
  5688. Total time: 0 s
  5689. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5690. Function: refresh at line 1172
  5691. Line # Hits Time Per Hit % Time Line Contents
  5692. ==============================================================
  5693. 1172 @profile
  5694. 1173 def refresh(self):
  5695. 1174 self._vm_firewall = self._provider.os_conn.network.get_security_group(
  5696. 1175 self.id)
  5697. Total time: 0 s
  5698. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/resources.py
  5699. Function: refresh at line 1345
  5700. Line # Hits Time Per Hit % Time Line Contents
  5701. ==============================================================
  5702. 1345 @profile
  5703. 1346 def refresh(self):
  5704. 1347 self._obj = self.cbcontainer.objects.get(self.id)._obj
  5705. Total time: 0 s
  5706. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5707. Function: get_or_create_ec2_credentials at line 101
  5708. Line # Hits Time Per Hit % Time Line Contents
  5709. ==============================================================
  5710. 101 @profile
  5711. 102 def get_or_create_ec2_credentials(self):
  5712. 103 """
  5713. 104 A provider specific method than returns the ec2 credentials for the
  5714. 105 current user, or creates a new pair if one doesn't exist.
  5715. 106 """
  5716. 107 keystone = self.provider.keystone
  5717. 108 if hasattr(keystone, 'ec2'):
  5718. 109 user_id = keystone.session.get_user_id()
  5719. 110 user_creds = [cred for cred in keystone.ec2.list(user_id) if
  5720. 111 cred.tenant_id == keystone.session.get_project_id()]
  5721. 112 if user_creds:
  5722. 113 return user_creds[0]
  5723. 114 else:
  5724. 115 return keystone.ec2.create(
  5725. 116 user_id, keystone.session.get_project_id())
  5726. 117
  5727. 118 return None
  5728. Total time: 0 s
  5729. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5730. Function: get_ec2_endpoints at line 120
  5731. Line # Hits Time Per Hit % Time Line Contents
  5732. ==============================================================
  5733. 120 @profile
  5734. 121 def get_ec2_endpoints(self):
  5735. 122 """
  5736. 123 A provider specific method than returns the ec2 endpoints if
  5737. 124 available.
  5738. 125 """
  5739. 126 keystone = self.provider.keystone
  5740. 127 ec2_url = keystone.session.get_endpoint(service_type='ec2')
  5741. 128 s3_url = keystone.session.get_endpoint(service_type='s3')
  5742. 129
  5743. 130 return {'ec2_endpoint': ec2_url,
  5744. 131 's3_endpoint': s3_url}
  5745. Total time: 0 s
  5746. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5747. Function: get at line 139
  5748. Line # Hits Time Per Hit % Time Line Contents
  5749. ==============================================================
  5750. 139 @dispatch(event="provider.security.key_pairs.get",
  5751. 140 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  5752. 141 @profile
  5753. 142 def get(self, key_pair_id):
  5754. 143 """
  5755. 144 Returns a KeyPair given its id.
  5756. 145 """
  5757. 146 log.debug("Returning KeyPair with the id %s", key_pair_id)
  5758. 147 try:
  5759. 148 return OpenStackKeyPair(
  5760. 149 self.provider, self.provider.nova.keypairs.get(key_pair_id))
  5761. 150 except NovaNotFound:
  5762. 151 log.debug("KeyPair %s was not found.", key_pair_id)
  5763. 152 return None
  5764. Total time: 0 s
  5765. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5766. Function: list at line 154
  5767. Line # Hits Time Per Hit % Time Line Contents
  5768. ==============================================================
  5769. 154 @dispatch(event="provider.security.key_pairs.list",
  5770. 155 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  5771. 156 @profile
  5772. 157 def list(self, limit=None, marker=None):
  5773. 158 """
  5774. 159 List all key pairs associated with this account.
  5775. 160
  5776. 161 :rtype: ``list`` of :class:`.KeyPair`
  5777. 162 :return: list of KeyPair objects
  5778. 163 """
  5779. 164 keypairs = self.provider.nova.keypairs.list()
  5780. 165 results = [OpenStackKeyPair(self.provider, kp)
  5781. 166 for kp in keypairs]
  5782. 167 log.debug("Listing all key pairs associated with OpenStack "
  5783. 168 "Account: %s", results)
  5784. 169 return ClientPagedResultList(self.provider, results,
  5785. 170 limit=limit, marker=marker)
  5786. Total time: 2.4398 s
  5787. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5788. Function: find at line 172
  5789. Line # Hits Time Per Hit % Time Line Contents
  5790. ==============================================================
  5791. 172 @dispatch(event="provider.security.key_pairs.find",
  5792. 173 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  5793. 174 @profile
  5794. 175 def find(self, **kwargs):
  5795. 176 1 1.0 1.0 0.0 name = kwargs.pop('name', None)
  5796. 177
  5797. 178 # All kwargs should have been popped at this time.
  5798. 179 1 1.0 1.0 0.0 if len(kwargs) > 0:
  5799. 180 raise InvalidParamException(
  5800. 181 "Unrecognised parameters for search: %s. Supported "
  5801. 182 "attributes: %s" % (kwargs, 'name'))
  5802. 183
  5803. 184 1 2439732.0 2439732.0 100.0 keypairs = self.provider.nova.keypairs.findall(name=name)
  5804. 185 1 4.0 4.0 0.0 results = [OpenStackKeyPair(self.provider, kp)
  5805. 186 1 3.0 3.0 0.0 for kp in keypairs]
  5806. 187 1 12.0 12.0 0.0 log.debug("Searching for %s in: %s", name, keypairs)
  5807. 188 1 46.0 46.0 0.0 return ClientPagedResultList(self.provider, results)
  5808. Total time: 3.09715 s
  5809. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5810. Function: create at line 190
  5811. Line # Hits Time Per Hit % Time Line Contents
  5812. ==============================================================
  5813. 190 @dispatch(event="provider.security.key_pairs.create",
  5814. 191 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  5815. 192 @profile
  5816. 193 def create(self, name, public_key_material=None):
  5817. 194 1 8.0 8.0 0.0 OpenStackKeyPair.assert_valid_resource_name(name)
  5818. 195 1 2450763.0 2450763.0 79.1 existing_kp = self.find(name=name)
  5819. 196 1 1.0 1.0 0.0 if existing_kp:
  5820. 197 raise DuplicateResourceException(
  5821. 198 'Keypair already exists with name {0}'.format(name))
  5822. 199
  5823. 200 1 1.0 1.0 0.0 private_key = None
  5824. 201 1 1.0 1.0 0.0 if not public_key_material:
  5825. 202 1 81076.0 81076.0 2.6 public_key_material, private_key = cb_helpers.generate_key_pair()
  5826. 203
  5827. 204 1 7.0 7.0 0.0 kp = self.provider.nova.keypairs.create(name,
  5828. 205 1 565276.0 565276.0 18.3 public_key=public_key_material)
  5829. 206 1 15.0 15.0 0.0 cb_kp = OpenStackKeyPair(self.provider, kp)
  5830. 207 1 3.0 3.0 0.0 cb_kp.material = private_key
  5831. 208 1 1.0 1.0 0.0 return cb_kp
  5832. Total time: 0.510433 s
  5833. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5834. Function: delete at line 210
  5835. Line # Hits Time Per Hit % Time Line Contents
  5836. ==============================================================
  5837. 210 @dispatch(event="provider.security.key_pairs.delete",
  5838. 211 priority=BaseKeyPairService.STANDARD_EVENT_PRIORITY)
  5839. 212 @profile
  5840. 213 def delete(self, key_pair):
  5841. 214 1 3.0 3.0 0.0 keypair = (key_pair if isinstance(key_pair, OpenStackKeyPair)
  5842. 215 else self.get(key_pair))
  5843. 216 1 1.0 1.0 0.0 if keypair:
  5844. 217 # pylint:disable=protected-access
  5845. 218 1 510429.0 510429.0 100.0 keypair._key_pair.delete()
  5846. Total time: 0 s
  5847. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5848. Function: get at line 226
  5849. Line # Hits Time Per Hit % Time Line Contents
  5850. ==============================================================
  5851. 226 @dispatch(event="provider.security.vm_firewalls.get",
  5852. 227 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  5853. 228 @profile
  5854. 229 def get(self, vm_firewall_id):
  5855. 230 try:
  5856. 231 return OpenStackVMFirewall(
  5857. 232 self.provider,
  5858. 233 self.provider.os_conn.network
  5859. 234 .get_security_group(vm_firewall_id))
  5860. 235 except (ResourceNotFound, NotFoundException):
  5861. 236 log.debug("Firewall %s not found.", vm_firewall_id)
  5862. 237 return None
  5863. Total time: 0 s
  5864. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5865. Function: list at line 239
  5866. Line # Hits Time Per Hit % Time Line Contents
  5867. ==============================================================
  5868. 239 @dispatch(event="provider.security.vm_firewalls.list",
  5869. 240 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  5870. 241 @profile
  5871. 242 def list(self, limit=None, marker=None):
  5872. 243 firewalls = [
  5873. 244 OpenStackVMFirewall(self.provider, fw)
  5874. 245 for fw in self.provider.os_conn.network.security_groups()]
  5875. 246
  5876. 247 return ClientPagedResultList(self.provider, firewalls,
  5877. 248 limit=limit, marker=marker)
  5878. Total time: 2.07037 s
  5879. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5880. Function: create at line 250
  5881. Line # Hits Time Per Hit % Time Line Contents
  5882. ==============================================================
  5883. 250 @cb_helpers.deprecated_alias(network_id='network')
  5884. 251 @dispatch(event="provider.security.vm_firewalls.create",
  5885. 252 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  5886. 253 @profile
  5887. 254 def create(self, label, network, description=None):
  5888. 255 1 8.0 8.0 0.0 OpenStackVMFirewall.assert_valid_resource_label(label)
  5889. 256 1 1.0 1.0 0.0 net_id = network.id if isinstance(network, Network) else network
  5890. 257 # We generally simulate a network being associated with a firewall
  5891. 258 # by storing the supplied value in the firewall description field that
  5892. 259 # is not modifiable after creation; however, because of some networking
  5893. 260 # specificity in Nectar, we must also allow an empty network id value.
  5894. 261 1 1.0 1.0 0.0 if not net_id:
  5895. 262 net_id = ""
  5896. 263 1 1.0 1.0 0.0 if not description:
  5897. 264 description = ""
  5898. 265 1 1.0 1.0 0.0 description += " [{}{}]".format(OpenStackVMFirewall._network_id_tag,
  5899. 266 1 3.0 3.0 0.0 net_id)
  5900. 267 1 1260211.0 1260211.0 60.9 sg = self.provider.os_conn.network.create_security_group(
  5901. 268 1 810110.0 810110.0 39.1 name=label, description=description)
  5902. 269 1 2.0 2.0 0.0 if sg:
  5903. 270 1 30.0 30.0 0.0 return OpenStackVMFirewall(self.provider, sg)
  5904. 271 return None
  5905. Total time: 0.36989 s
  5906. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5907. Function: delete at line 273
  5908. Line # Hits Time Per Hit % Time Line Contents
  5909. ==============================================================
  5910. 273 @dispatch(event="provider.security.vm_firewalls.delete",
  5911. 274 priority=BaseVMFirewallService.STANDARD_EVENT_PRIORITY)
  5912. 275 @profile
  5913. 276 def delete(self, vm_firewall):
  5914. 277 1 3.0 3.0 0.0 fw = (vm_firewall if isinstance(vm_firewall, OpenStackVMFirewall)
  5915. 278 else self.get(vm_firewall))
  5916. 279 1 1.0 1.0 0.0 if fw:
  5917. 280 # pylint:disable=protected-access
  5918. 281 1 369886.0 369886.0 100.0 fw._vm_firewall.delete(self.provider.os_conn.session)
  5919. Total time: 0 s
  5920. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5921. Function: list at line 289
  5922. Line # Hits Time Per Hit % Time Line Contents
  5923. ==============================================================
  5924. 289 @dispatch(event="provider.security.vm_firewall_rules.list",
  5925. 290 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  5926. 291 @profile
  5927. 292 def list(self, firewall, limit=None, marker=None):
  5928. 293 # pylint:disable=protected-access
  5929. 294 rules = [OpenStackVMFirewallRule(firewall, r)
  5930. 295 for r in firewall._vm_firewall.security_group_rules]
  5931. 296 return ClientPagedResultList(self.provider, rules,
  5932. 297 limit=limit, marker=marker)
  5933. Total time: 0 s
  5934. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5935. Function: create at line 299
  5936. Line # Hits Time Per Hit % Time Line Contents
  5937. ==============================================================
  5938. 299 @dispatch(event="provider.security.vm_firewall_rules.create",
  5939. 300 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  5940. 301 @profile
  5941. 302 def create(self, firewall, direction, protocol=None, from_port=None,
  5942. 303 to_port=None, cidr=None, src_dest_fw=None):
  5943. 304 src_dest_fw_id = (src_dest_fw.id if isinstance(src_dest_fw,
  5944. 305 OpenStackVMFirewall)
  5945. 306 else src_dest_fw)
  5946. 307
  5947. 308 try:
  5948. 309 if direction == TrafficDirection.INBOUND:
  5949. 310 os_direction = 'ingress'
  5950. 311 elif direction == TrafficDirection.OUTBOUND:
  5951. 312 os_direction = 'egress'
  5952. 313 else:
  5953. 314 raise InvalidValueException("direction", direction)
  5954. 315 # pylint:disable=protected-access
  5955. 316 rule = self.provider.os_conn.network.create_security_group_rule(
  5956. 317 security_group_id=firewall.id,
  5957. 318 direction=os_direction,
  5958. 319 port_range_max=to_port,
  5959. 320 port_range_min=from_port,
  5960. 321 protocol=protocol,
  5961. 322 remote_ip_prefix=cidr,
  5962. 323 remote_group_id=src_dest_fw_id)
  5963. 324 firewall.refresh()
  5964. 325 return OpenStackVMFirewallRule(firewall, rule.to_dict())
  5965. 326 except HttpException as e:
  5966. 327 firewall.refresh()
  5967. 328 # 409=Conflict, raised for duplicate rule
  5968. 329 if e.status_code == 409:
  5969. 330 existing = self.find(firewall, direction=direction,
  5970. 331 protocol=protocol, from_port=from_port,
  5971. 332 to_port=to_port, cidr=cidr,
  5972. 333 src_dest_fw_id=src_dest_fw_id)
  5973. 334 return existing[0]
  5974. 335 else:
  5975. 336 raise e
  5976. Total time: 0 s
  5977. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5978. Function: delete at line 338
  5979. Line # Hits Time Per Hit % Time Line Contents
  5980. ==============================================================
  5981. 338 @dispatch(event="provider.security.vm_firewall_rules.delete",
  5982. 339 priority=BaseVMFirewallRuleService.STANDARD_EVENT_PRIORITY)
  5983. 340 @profile
  5984. 341 def delete(self, firewall, rule):
  5985. 342 rule_id = (rule.id if isinstance(rule, OpenStackVMFirewallRule)
  5986. 343 else rule)
  5987. 344 self.provider.os_conn.network.delete_security_group_rule(rule_id)
  5988. 345 firewall.refresh()
  5989. Total time: 0 s
  5990. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  5991. Function: get at line 381
  5992. Line # Hits Time Per Hit % Time Line Contents
  5993. ==============================================================
  5994. 381 @dispatch(event="provider.storage.volumes.get",
  5995. 382 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  5996. 383 @profile
  5997. 384 def get(self, volume_id):
  5998. 385 try:
  5999. 386 return OpenStackVolume(
  6000. 387 self.provider, self.provider.cinder.volumes.get(volume_id))
  6001. 388 except CinderNotFound:
  6002. 389 log.debug("Volume %s was not found.", volume_id)
  6003. 390 return None
  6004. Total time: 0 s
  6005. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6006. Function: find at line 392
  6007. Line # Hits Time Per Hit % Time Line Contents
  6008. ==============================================================
  6009. 392 @dispatch(event="provider.storage.volumes.find",
  6010. 393 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  6011. 394 @profile
  6012. 395 def find(self, **kwargs):
  6013. 396 label = kwargs.pop('label', None)
  6014. 397
  6015. 398 # All kwargs should have been popped at this time.
  6016. 399 if len(kwargs) > 0:
  6017. 400 raise InvalidParamException(
  6018. 401 "Unrecognised parameters for search: %s. Supported "
  6019. 402 "attributes: %s" % (kwargs, 'label'))
  6020. 403
  6021. 404 log.debug("Searching for an OpenStack Volume with the label %s", label)
  6022. 405 search_opts = {'name': label}
  6023. 406 cb_vols = [
  6024. 407 OpenStackVolume(self.provider, vol)
  6025. 408 for vol in self.provider.cinder.volumes.list(
  6026. 409 search_opts=search_opts,
  6027. 410 limit=oshelpers.os_result_limit(self.provider),
  6028. 411 marker=None)]
  6029. 412
  6030. 413 return oshelpers.to_server_paged_list(self.provider, cb_vols)
  6031. Total time: 0 s
  6032. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6033. Function: list at line 415
  6034. Line # Hits Time Per Hit % Time Line Contents
  6035. ==============================================================
  6036. 415 @dispatch(event="provider.storage.volumes.list",
  6037. 416 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  6038. 417 @profile
  6039. 418 def list(self, limit=None, marker=None):
  6040. 419 cb_vols = [
  6041. 420 OpenStackVolume(self.provider, vol)
  6042. 421 for vol in self.provider.cinder.volumes.list(
  6043. 422 limit=oshelpers.os_result_limit(self.provider, limit),
  6044. 423 marker=marker)]
  6045. 424
  6046. 425 return oshelpers.to_server_paged_list(self.provider, cb_vols, limit)
  6047. Total time: 0 s
  6048. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6049. Function: create at line 427
  6050. Line # Hits Time Per Hit % Time Line Contents
  6051. ==============================================================
  6052. 427 @dispatch(event="provider.storage.volumes.create",
  6053. 428 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  6054. 429 @profile
  6055. 430 def create(self, label, size, zone, snapshot=None, description=None):
  6056. 431 OpenStackVolume.assert_valid_resource_label(label)
  6057. 432 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  6058. 433 snapshot_id = snapshot.id if isinstance(
  6059. 434 snapshot, OpenStackSnapshot) and snapshot else snapshot
  6060. 435
  6061. 436 os_vol = self.provider.cinder.volumes.create(
  6062. 437 size, name=label, description=description,
  6063. 438 availability_zone=zone_id, snapshot_id=snapshot_id)
  6064. 439 return OpenStackVolume(self.provider, os_vol)
  6065. Total time: 0 s
  6066. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6067. Function: delete at line 441
  6068. Line # Hits Time Per Hit % Time Line Contents
  6069. ==============================================================
  6070. 441 @dispatch(event="provider.storage.volumes.delete",
  6071. 442 priority=BaseVolumeService.STANDARD_EVENT_PRIORITY)
  6072. 443 @profile
  6073. 444 def delete(self, volume):
  6074. 445 volume = (volume if isinstance(volume, OpenStackVolume)
  6075. 446 else self.get(volume))
  6076. 447 if volume:
  6077. 448 # pylint:disable=protected-access
  6078. 449 volume._volume.delete()
  6079. Total time: 0 s
  6080. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6081. Function: get at line 457
  6082. Line # Hits Time Per Hit % Time Line Contents
  6083. ==============================================================
  6084. 457 @dispatch(event="provider.storage.snapshots.get",
  6085. 458 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  6086. 459 @profile
  6087. 460 def get(self, snapshot_id):
  6088. 461 try:
  6089. 462 return OpenStackSnapshot(
  6090. 463 self.provider,
  6091. 464 self.provider.cinder.volume_snapshots.get(snapshot_id))
  6092. 465 except CinderNotFound:
  6093. 466 log.debug("Snapshot %s was not found.", snapshot_id)
  6094. 467 return None
  6095. Total time: 0 s
  6096. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6097. Function: find at line 469
  6098. Line # Hits Time Per Hit % Time Line Contents
  6099. ==============================================================
  6100. 469 @dispatch(event="provider.storage.snapshots.find",
  6101. 470 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  6102. 471 @profile
  6103. 472 def find(self, **kwargs):
  6104. 473 label = kwargs.pop('label', None)
  6105. 474
  6106. 475 # All kwargs should have been popped at this time.
  6107. 476 if len(kwargs) > 0:
  6108. 477 raise InvalidParamException(
  6109. 478 "Unrecognised parameters for search: %s. Supported "
  6110. 479 "attributes: %s" % (kwargs, 'label'))
  6111. 480
  6112. 481 search_opts = {'name': label, # TODO: Cinder is ignoring name
  6113. 482 'limit': oshelpers.os_result_limit(self.provider),
  6114. 483 'marker': None}
  6115. 484 log.debug("Searching for an OpenStack snapshot with the following "
  6116. 485 "params: %s", search_opts)
  6117. 486 cb_snaps = [
  6118. 487 OpenStackSnapshot(self.provider, snap) for
  6119. 488 snap in self.provider.cinder.volume_snapshots.list(search_opts)
  6120. 489 if snap.name == label]
  6121. 490
  6122. 491 return oshelpers.to_server_paged_list(self.provider, cb_snaps)
  6123. Total time: 0 s
  6124. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6125. Function: list at line 493
  6126. Line # Hits Time Per Hit % Time Line Contents
  6127. ==============================================================
  6128. 493 @dispatch(event="provider.storage.snapshots.list",
  6129. 494 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  6130. 495 @profile
  6131. 496 def list(self, limit=None, marker=None):
  6132. 497 cb_snaps = [
  6133. 498 OpenStackSnapshot(self.provider, snap) for
  6134. 499 snap in self.provider.cinder.volume_snapshots.list(
  6135. 500 search_opts={'limit': oshelpers.os_result_limit(self.provider,
  6136. 501 limit),
  6137. 502 'marker': marker})]
  6138. 503 return oshelpers.to_server_paged_list(self.provider, cb_snaps, limit)
  6139. Total time: 0 s
  6140. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6141. Function: create at line 505
  6142. Line # Hits Time Per Hit % Time Line Contents
  6143. ==============================================================
  6144. 505 @dispatch(event="provider.storage.snapshots.create",
  6145. 506 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  6146. 507 @profile
  6147. 508 def create(self, label, volume, description=None):
  6148. 509 OpenStackSnapshot.assert_valid_resource_label(label)
  6149. 510 volume_id = (volume.id if isinstance(volume, OpenStackVolume)
  6150. 511 else volume)
  6151. 512
  6152. 513 os_snap = self.provider.cinder.volume_snapshots.create(
  6153. 514 volume_id, name=label,
  6154. 515 description=description)
  6155. 516 return OpenStackSnapshot(self.provider, os_snap)
  6156. Total time: 0 s
  6157. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6158. Function: delete at line 518
  6159. Line # Hits Time Per Hit % Time Line Contents
  6160. ==============================================================
  6161. 518 @dispatch(event="provider.storage.snapshots.delete",
  6162. 519 priority=BaseSnapshotService.STANDARD_EVENT_PRIORITY)
  6163. 520 @profile
  6164. 521 def delete(self, snapshot):
  6165. 522 s = (snapshot if isinstance(snapshot, OpenStackSnapshot) else
  6166. 523 self.get(snapshot))
  6167. 524 if s:
  6168. 525 # pylint:disable=protected-access
  6169. 526 s._snapshot.delete()
  6170. Total time: 0 s
  6171. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6172. Function: get at line 534
  6173. Line # Hits Time Per Hit % Time Line Contents
  6174. ==============================================================
  6175. 534 @dispatch(event="provider.storage.buckets.get",
  6176. 535 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  6177. 536 @profile
  6178. 537 def get(self, bucket_id):
  6179. 538 """
  6180. 539 Returns a bucket given its ID. Returns ``None`` if the bucket
  6181. 540 does not exist.
  6182. 541 """
  6183. 542 _, container_list = self.provider.swift.get_account(
  6184. 543 prefix=bucket_id)
  6185. 544 if container_list:
  6186. 545 return OpenStackBucket(self.provider,
  6187. 546 next((c for c in container_list
  6188. 547 if c['name'] == bucket_id), None))
  6189. 548 else:
  6190. 549 log.debug("Bucket %s was not found.", bucket_id)
  6191. 550 return None
  6192. Total time: 0 s
  6193. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6194. Function: find at line 552
  6195. Line # Hits Time Per Hit % Time Line Contents
  6196. ==============================================================
  6197. 552 @dispatch(event="provider.storage.buckets.find",
  6198. 553 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  6199. 554 @profile
  6200. 555 def find(self, **kwargs):
  6201. 556 name = kwargs.pop('name', None)
  6202. 557
  6203. 558 # All kwargs should have been popped at this time.
  6204. 559 if len(kwargs) > 0:
  6205. 560 raise InvalidParamException(
  6206. 561 "Unrecognised parameters for search: %s. Supported "
  6207. 562 "attributes: %s" % (kwargs, 'name'))
  6208. 563 _, container_list = self.provider.swift.get_account()
  6209. 564 cb_buckets = [OpenStackBucket(self.provider, c)
  6210. 565 for c in container_list
  6211. 566 if name in c.get("name")]
  6212. 567 return oshelpers.to_server_paged_list(self.provider, cb_buckets)
  6213. Total time: 0 s
  6214. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6215. Function: list at line 569
  6216. Line # Hits Time Per Hit % Time Line Contents
  6217. ==============================================================
  6218. 569 @dispatch(event="provider.storage.buckets.list",
  6219. 570 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  6220. 571 @profile
  6221. 572 def list(self, limit=None, marker=None):
  6222. 573 _, container_list = self.provider.swift.get_account(
  6223. 574 limit=oshelpers.os_result_limit(self.provider, limit),
  6224. 575 marker=marker)
  6225. 576 cb_buckets = [OpenStackBucket(self.provider, c)
  6226. 577 for c in container_list]
  6227. 578 return oshelpers.to_server_paged_list(self.provider, cb_buckets, limit)
  6228. Total time: 0 s
  6229. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6230. Function: create at line 580
  6231. Line # Hits Time Per Hit % Time Line Contents
  6232. ==============================================================
  6233. 580 @dispatch(event="provider.storage.buckets.create",
  6234. 581 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  6235. 582 @profile
  6236. 583 def create(self, name, location=None):
  6237. 584 OpenStackBucket.assert_valid_resource_name(name)
  6238. 585 location = location or self.provider.region_name
  6239. 586 try:
  6240. 587 self.provider.swift.head_container(name)
  6241. 588 raise DuplicateResourceException(
  6242. 589 'Bucket already exists with name {0}'.format(name))
  6243. 590 except SwiftClientException:
  6244. 591 self.provider.swift.put_container(name)
  6245. 592 return self.get(name)
  6246. Total time: 0 s
  6247. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6248. Function: delete at line 594
  6249. Line # Hits Time Per Hit % Time Line Contents
  6250. ==============================================================
  6251. 594 @dispatch(event="provider.storage.buckets.delete",
  6252. 595 priority=BaseBucketService.STANDARD_EVENT_PRIORITY)
  6253. 596 @profile
  6254. 597 def delete(self, bucket):
  6255. 598 b_id = bucket.id if isinstance(bucket, OpenStackBucket) else bucket
  6256. 599 self.provider.swift.delete_container(b_id)
  6257. Total time: 0 s
  6258. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6259. Function: get at line 607
  6260. Line # Hits Time Per Hit % Time Line Contents
  6261. ==============================================================
  6262. 607 @profile
  6263. 608 def get(self, bucket, name):
  6264. 609 """
  6265. 610 Retrieve a given object from this bucket.
  6266. 611 """
  6267. 612 # Swift always returns a reference for the container first,
  6268. 613 # followed by a list containing references to objects.
  6269. 614 _, object_list = self.provider.swift.get_container(
  6270. 615 bucket.name, prefix=name)
  6271. 616 # Loop through list of objects looking for an exact name vs. a prefix
  6272. 617 for obj in object_list:
  6273. 618 if obj.get('name') == name:
  6274. 619 return OpenStackBucketObject(self.provider,
  6275. 620 bucket,
  6276. 621 obj)
  6277. 622 return None
  6278. Total time: 0 s
  6279. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6280. Function: list at line 624
  6281. Line # Hits Time Per Hit % Time Line Contents
  6282. ==============================================================
  6283. 624 @profile
  6284. 625 def list(self, bucket, limit=None, marker=None, prefix=None):
  6285. 626 """
  6286. 627 List all objects within this bucket.
  6287. 628
  6288. 629 :rtype: BucketObject
  6289. 630 :return: List of all available BucketObjects within this bucket.
  6290. 631 """
  6291. 632 _, object_list = self.provider.swift.get_container(
  6292. 633 bucket.name,
  6293. 634 limit=oshelpers.os_result_limit(self.provider, limit),
  6294. 635 marker=marker, prefix=prefix)
  6295. 636 cb_objects = [OpenStackBucketObject(
  6296. 637 self.provider, bucket, obj) for obj in object_list]
  6297. 638
  6298. 639 return oshelpers.to_server_paged_list(
  6299. 640 self.provider,
  6300. 641 cb_objects,
  6301. 642 limit)
  6302. Total time: 0 s
  6303. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6304. Function: find at line 644
  6305. Line # Hits Time Per Hit % Time Line Contents
  6306. ==============================================================
  6307. 644 @profile
  6308. 645 def find(self, bucket, **kwargs):
  6309. 646 _, obj_list = self.provider.swift.get_container(bucket.name)
  6310. 647 cb_objs = [OpenStackBucketObject(self.provider, bucket, obj)
  6311. 648 for obj in obj_list]
  6312. 649 filters = ['name']
  6313. 650 matches = cb_helpers.generic_find(filters, kwargs, cb_objs)
  6314. 651 return ClientPagedResultList(self.provider, list(matches))
  6315. Total time: 0 s
  6316. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6317. Function: create at line 653
  6318. Line # Hits Time Per Hit % Time Line Contents
  6319. ==============================================================
  6320. 653 @profile
  6321. 654 def create(self, bucket, object_name):
  6322. 655 self.provider.swift.put_object(bucket.name, object_name, None)
  6323. 656 return self.get(bucket, object_name)
  6324. Total time: 3.02151 s
  6325. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6326. Function: get at line 690
  6327. Line # Hits Time Per Hit % Time Line Contents
  6328. ==============================================================
  6329. 690 @profile
  6330. 691 def get(self, image_id):
  6331. 692 """
  6332. 693 Returns an Image given its id
  6333. 694 """
  6334. 695 1 10.0 10.0 0.0 log.debug("Getting OpenStack Image with the id: %s", image_id)
  6335. 696 1 0.0 0.0 0.0 try:
  6336. 697 1 0.0 0.0 0.0 return OpenStackMachineImage(
  6337. 698 1 3021456.0 3021456.0 100.0 self.provider, self.provider.os_conn.image.get_image(image_id))
  6338. 699 1 3.0 3.0 0.0 except (NotFoundException, ResourceNotFound):
  6339. 700 1 10.0 10.0 0.0 log.debug("Image %s not found", image_id)
  6340. 701 1 36.0 36.0 0.0 return None
  6341. Total time: 0 s
  6342. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6343. Function: find at line 703
  6344. Line # Hits Time Per Hit % Time Line Contents
  6345. ==============================================================
  6346. 703 @profile
  6347. 704 def find(self, **kwargs):
  6348. 705 filters = ['label']
  6349. 706 obj_list = self
  6350. 707 return cb_helpers.generic_find(filters, kwargs, obj_list)
  6351. Total time: 0 s
  6352. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6353. Function: list at line 709
  6354. Line # Hits Time Per Hit % Time Line Contents
  6355. ==============================================================
  6356. 709 @profile
  6357. 710 def list(self, filter_by_owner=True, limit=None, marker=None):
  6358. 711 """
  6359. 712 List all images.
  6360. 713 """
  6361. 714 project_id = None
  6362. 715 if filter_by_owner:
  6363. 716 project_id = self.provider.os_conn.session.get_project_id()
  6364. 717 os_images = self.provider.os_conn.image.images(
  6365. 718 owner=project_id,
  6366. 719 limit=oshelpers.os_result_limit(self.provider, limit),
  6367. 720 marker=marker)
  6368. 721
  6369. 722 cb_images = [
  6370. 723 OpenStackMachineImage(self.provider, img)
  6371. 724 for img in os_images]
  6372. 725 return oshelpers.to_server_paged_list(self.provider, cb_images, limit)
  6373. Total time: 7e-06 s
  6374. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6375. Function: create_launch_config at line 783
  6376. Line # Hits Time Per Hit % Time Line Contents
  6377. ==============================================================
  6378. 783 @profile
  6379. 784 def create_launch_config(self):
  6380. 785 1 7.0 7.0 100.0 return BaseLaunchConfig(self.provider)
  6381. Total time: 13.802 s
  6382. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6383. Function: create at line 787
  6384. Line # Hits Time Per Hit % Time Line Contents
  6385. ==============================================================
  6386. 787 @dispatch(event="provider.compute.instances.create",
  6387. 788 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  6388. 789 @profile
  6389. 790 def create(self, label, image, vm_type, subnet, zone,
  6390. 791 key_pair=None, vm_firewalls=None, user_data=None,
  6391. 792 launch_config=None, **kwargs):
  6392. 793 13 189.0 14.5 0.0 OpenStackInstance.assert_valid_resource_label(label)
  6393. 794 3 10.0 3.3 0.0 image_id = image.id if isinstance(image, MachineImage) else image
  6394. 795 vm_size = vm_type.id if \
  6395. 796 3 7.0 2.3 0.0 isinstance(vm_type, VMType) else \
  6396. 797 3 20.0 6.7 0.0 self.provider.compute.vm_types.find(
  6397. 798 3 7000174.0 2333391.3 50.7 name=vm_type)[0].id
  6398. 799 3 11.0 3.7 0.0 if isinstance(subnet, Subnet):
  6399. 800 3 16.0 5.3 0.0 subnet_id = subnet.id
  6400. 801 3 11.0 3.7 0.0 net_id = subnet.network_id
  6401. 802 else:
  6402. 803 subnet_id = subnet
  6403. 804 net_id = (self.provider.networking.subnets
  6404. 805 .get(subnet_id).network_id
  6405. 806 if subnet_id else None)
  6406. 807 3 8.0 2.7 0.0 zone_id = zone.id if isinstance(zone, PlacementZone) else zone
  6407. 808 key_pair_name = key_pair.name if \
  6408. 809 3 13.0 4.3 0.0 isinstance(key_pair, KeyPair) else key_pair
  6409. 810 3 6.0 2.0 0.0 bdm = None
  6410. 811 3 7.0 2.3 0.0 if launch_config:
  6411. 812 bdm = self._to_block_device_mapping(launch_config)
  6412. 813
  6413. 814 # Security groups must be passed in as a list of IDs and attached to a
  6414. 815 # port if a port is being created. Otherwise, the security groups must
  6415. 816 # be passed in as a list of names to the servers.create() call.
  6416. 817 # OpenStack will respect the port's security groups first and then
  6417. 818 # fall-back to the named security groups.
  6418. 819 3 7.0 2.3 0.0 sg_name_list = []
  6419. 820 3 6.0 2.0 0.0 nics = None
  6420. 821 3 8.0 2.7 0.0 if subnet_id:
  6421. 822 3 9.0 3.0 0.0 log.debug("Creating network port for %s in subnet: %s",
  6422. 823 3 23.0 7.7 0.0 label, subnet_id)
  6423. 824 3 7.0 2.3 0.0 sg_list = []
  6424. 825 3 6.0 2.0 0.0 if vm_firewalls:
  6425. 826 1 3.0 3.0 0.0 if isinstance(vm_firewalls, list) and \
  6426. 827 1 3.0 3.0 0.0 isinstance(vm_firewalls[0], VMFirewall):
  6427. 828 1 2.0 2.0 0.0 sg_list = vm_firewalls
  6428. 829 else:
  6429. 830 sg_list = (self.provider.security.vm_firewalls
  6430. 831 .find(label=sg) for sg in vm_firewalls)
  6431. 832 sg_list = (sg[0] for sg in sg_list if sg)
  6432. 833 3 29.0 9.7 0.0 sg_id_list = [sg.id for sg in sg_list]
  6433. 834 port_def = {
  6434. 835 3 6.0 2.0 0.0 "port": {
  6435. 836 3 8.0 2.7 0.0 "admin_state_up": True,
  6436. 837 3 10.0 3.3 0.0 "name": OpenStackInstance._generate_name_from_label(
  6437. 838 3 190.0 63.3 0.0 label, 'cb-port'),
  6438. 839 3 6.0 2.0 0.0 "network_id": net_id,
  6439. 840 3 8.0 2.7 0.0 "fixed_ips": [{"subnet_id": subnet_id}],
  6440. 841 3 9.0 3.0 0.0 "security_groups": sg_id_list
  6441. 842 }
  6442. 843 }
  6443. 844 3 3157095.0 1052365.0 22.9 port_id = self.provider.neutron.create_port(port_def)['port']['id']
  6444. 845 3 16.0 5.3 0.0 nics = [{'net-id': net_id, 'port-id': port_id}]
  6445. 846 else:
  6446. 847 if vm_firewalls:
  6447. 848 if isinstance(vm_firewalls, list) and \
  6448. 849 isinstance(vm_firewalls[0], VMFirewall):
  6449. 850 sg_name_list = [sg.name for sg in vm_firewalls]
  6450. 851 else:
  6451. 852 sg_list = (self.provider.security.vm_firewalls.get(sg)
  6452. 853 for sg in vm_firewalls)
  6453. 854 sg_name_list = (sg[0].name for sg in sg_list if sg)
  6454. 855
  6455. 856 3 35.0 11.7 0.0 log.debug("Launching in subnet %s", subnet_id)
  6456. 857 3 36.0 12.0 0.0 os_instance = self.provider.nova.servers.create(
  6457. 858 3 8.0 2.7 0.0 label,
  6458. 859 3 16.0 5.3 0.0 None if self._has_root_device(launch_config) else image_id,
  6459. 860 3 8.0 2.7 0.0 vm_size,
  6460. 861 3 8.0 2.7 0.0 min_count=1,
  6461. 862 3 8.0 2.7 0.0 max_count=1,
  6462. 863 3 8.0 2.7 0.0 availability_zone=zone_id,
  6463. 864 3 8.0 2.7 0.0 key_name=key_pair_name,
  6464. 865 3 8.0 2.7 0.0 security_groups=sg_name_list,
  6465. 866 3 13.0 4.3 0.0 userdata=str(user_data) or None,
  6466. 867 3 8.0 2.7 0.0 block_device_mapping_v2=bdm,
  6467. 868 3 3643903.0 1214634.3 26.4 nics=nics)
  6468. 869 return OpenStackInstance(self.provider, os_instance)
  6469. Total time: 0 s
  6470. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6471. Function: find at line 871
  6472. Line # Hits Time Per Hit % Time Line Contents
  6473. ==============================================================
  6474. 871 @dispatch(event="provider.compute.instances.find",
  6475. 872 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  6476. 873 @profile
  6477. 874 def find(self, **kwargs):
  6478. 875 label = kwargs.pop('label', None)
  6479. 876
  6480. 877 # All kwargs should have been popped at this time.
  6481. 878 if len(kwargs) > 0:
  6482. 879 raise InvalidParamException(
  6483. 880 "Unrecognised parameters for search: %s. Supported "
  6484. 881 "attributes: %s" % (kwargs, 'label'))
  6485. 882
  6486. 883 search_opts = {'name': label}
  6487. 884 cb_insts = [
  6488. 885 OpenStackInstance(self.provider, inst)
  6489. 886 for inst in self.provider.nova.servers.list(
  6490. 887 search_opts=search_opts,
  6491. 888 limit=oshelpers.os_result_limit(self.provider),
  6492. 889 marker=None)]
  6493. 890 return oshelpers.to_server_paged_list(self.provider, cb_insts)
  6494. Total time: 0 s
  6495. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6496. Function: list at line 892
  6497. Line # Hits Time Per Hit % Time Line Contents
  6498. ==============================================================
  6499. 892 @dispatch(event="provider.compute.instances.list",
  6500. 893 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  6501. 894 @profile
  6502. 895 def list(self, limit=None, marker=None):
  6503. 896 """
  6504. 897 List all instances.
  6505. 898 """
  6506. 899 cb_insts = [
  6507. 900 OpenStackInstance(self.provider, inst)
  6508. 901 for inst in self.provider.nova.servers.list(
  6509. 902 limit=oshelpers.os_result_limit(self.provider, limit),
  6510. 903 marker=marker)]
  6511. 904 return oshelpers.to_server_paged_list(self.provider, cb_insts, limit)
  6512. Total time: 0 s
  6513. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6514. Function: get at line 906
  6515. Line # Hits Time Per Hit % Time Line Contents
  6516. ==============================================================
  6517. 906 @dispatch(event="provider.compute.instances.get",
  6518. 907 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  6519. 908 @profile
  6520. 909 def get(self, instance_id):
  6521. 910 """
  6522. 911 Returns an instance given its id.
  6523. 912 """
  6524. 913 try:
  6525. 914 os_instance = self.provider.nova.servers.get(instance_id)
  6526. 915 return OpenStackInstance(self.provider, os_instance)
  6527. 916 except NovaNotFound:
  6528. 917 log.debug("Instance %s was not found.", instance_id)
  6529. 918 return None
  6530. Total time: 0 s
  6531. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6532. Function: delete at line 920
  6533. Line # Hits Time Per Hit % Time Line Contents
  6534. ==============================================================
  6535. 920 @dispatch(event="provider.compute.instances.delete",
  6536. 921 priority=BaseInstanceService.STANDARD_EVENT_PRIORITY)
  6537. 922 @profile
  6538. 923 def delete(self, instance):
  6539. 924 ins = (instance if isinstance(instance, OpenStackInstance) else
  6540. 925 self.get(instance))
  6541. 926 if ins:
  6542. 927 # pylint:disable=protected-access
  6543. 928 os_instance = ins._os_instance
  6544. 929 # delete the port we created when launching
  6545. 930 # Assumption: it's the first interface in the list
  6546. 931 iface_list = os_instance.interface_list()
  6547. 932 if iface_list:
  6548. 933 self.provider.neutron.delete_port(iface_list[0].port_id)
  6549. 934 os_instance.delete()
  6550. Total time: 9.66376 s
  6551. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6552. Function: list at line 942
  6553. Line # Hits Time Per Hit % Time Line Contents
  6554. ==============================================================
  6555. 942 @dispatch(event="provider.compute.vm_types.list",
  6556. 943 priority=BaseVMTypeService.STANDARD_EVENT_PRIORITY)
  6557. 944 @profile
  6558. 945 def list(self, limit=None, marker=None):
  6559. 946 cb_itypes = [
  6560. 947 8 10.0 1.2 0.0 OpenStackVMType(self.provider, obj)
  6561. 948 8 1864288.0 233036.0 19.3 for obj in self.provider.nova.flavors.list(
  6562. 949 8 236.0 29.5 0.0 limit=oshelpers.os_result_limit(self.provider, limit),
  6563. 950 8 7798932.0 974866.5 80.7 marker=marker)]
  6564. 951
  6565. 952 8 292.0 36.5 0.0 return oshelpers.to_server_paged_list(self.provider, cb_itypes, limit)
  6566. Total time: 0 s
  6567. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6568. Function: get at line 960
  6569. Line # Hits Time Per Hit % Time Line Contents
  6570. ==============================================================
  6571. 960 @dispatch(event="provider.compute.regions.get",
  6572. 961 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  6573. 962 @profile
  6574. 963 def get(self, region_id):
  6575. 964 log.debug("Getting OpenStack Region with the id: %s", region_id)
  6576. 965 region = (r for r in self if r.id == region_id)
  6577. 966 return next(region, None)
  6578. Total time: 0 s
  6579. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6580. Function: list at line 968
  6581. Line # Hits Time Per Hit % Time Line Contents
  6582. ==============================================================
  6583. 968 @dispatch(event="provider.compute.regions.list",
  6584. 969 priority=BaseRegionService.STANDARD_EVENT_PRIORITY)
  6585. 970 @profile
  6586. 971 def list(self, limit=None, marker=None):
  6587. 972 # pylint:disable=protected-access
  6588. 973 if self.provider._keystone_version == 3:
  6589. 974 os_regions = [OpenStackRegion(self.provider, region)
  6590. 975 for region in self.provider.keystone.regions.list()]
  6591. 976 return ClientPagedResultList(self.provider, os_regions,
  6592. 977 limit=limit, marker=marker)
  6593. 978 else:
  6594. 979 # Keystone v3 onwards supports directly listing regions
  6595. 980 # but for v2, this convoluted method is necessary.
  6596. 981 regions = (
  6597. 982 endpoint.get('region') or endpoint.get('region_id')
  6598. 983 for svc in self.provider.keystone.service_catalog.get_data()
  6599. 984 for endpoint in svc.get('endpoints', [])
  6600. 985 )
  6601. 986 regions = set(region for region in regions if region)
  6602. 987 os_regions = [OpenStackRegion(self.provider, region)
  6603. 988 for region in regions]
  6604. 989
  6605. 990 return ClientPagedResultList(self.provider, os_regions,
  6606. 991 limit=limit, marker=marker)
  6607. Total time: 1.72135 s
  6608. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6609. Function: get at line 1035
  6610. Line # Hits Time Per Hit % Time Line Contents
  6611. ==============================================================
  6612. 1035 @dispatch(event="provider.networking.networks.get",
  6613. 1036 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  6614. 1037 @profile
  6615. 1038 def get(self, network_id):
  6616. 1039 4 13.0 3.2 0.0 network = (n for n in self if n.id == network_id)
  6617. 1040 4 1721333.0 430333.2 100.0 return next(network, None)
  6618. Total time: 1.69941 s
  6619. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6620. Function: list at line 1042
  6621. Line # Hits Time Per Hit % Time Line Contents
  6622. ==============================================================
  6623. 1042 @dispatch(event="provider.networking.networks.list",
  6624. 1043 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  6625. 1044 @profile
  6626. 1045 def list(self, limit=None, marker=None):
  6627. 1046 4 5.0 1.2 0.0 networks = [OpenStackNetwork(self.provider, network)
  6628. 1047 4 1698958.0 424739.5 100.0 for network in self.provider.neutron.list_networks()
  6629. 1048 4 280.0 70.0 0.0 .get('networks') if network]
  6630. 1049 4 9.0 2.2 0.0 return ClientPagedResultList(self.provider, networks,
  6631. 1050 4 157.0 39.2 0.0 limit=limit, marker=marker)
  6632. Total time: 0 s
  6633. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6634. Function: find at line 1052
  6635. Line # Hits Time Per Hit % Time Line Contents
  6636. ==============================================================
  6637. 1052 @dispatch(event="provider.networking.networks.find",
  6638. 1053 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  6639. 1054 @profile
  6640. 1055 def find(self, **kwargs):
  6641. 1056 label = kwargs.pop('label', None)
  6642. 1057
  6643. 1058 # All kwargs should have been popped at this time.
  6644. 1059 if len(kwargs) > 0:
  6645. 1060 raise InvalidParamException(
  6646. 1061 "Unrecognised parameters for search: %s. Supported "
  6647. 1062 "attributes: %s" % (kwargs, 'label'))
  6648. 1063
  6649. 1064 log.debug("Searching for OpenStack Network with label: %s", label)
  6650. 1065 networks = [OpenStackNetwork(self.provider, network)
  6651. 1066 for network in self.provider.neutron.list_networks(
  6652. 1067 name=label)
  6653. 1068 .get('networks') if network]
  6654. 1069 return ClientPagedResultList(self.provider, networks)
  6655. Total time: 3.46815 s
  6656. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6657. Function: create at line 1071
  6658. Line # Hits Time Per Hit % Time Line Contents
  6659. ==============================================================
  6660. 1071 @dispatch(event="provider.networking.networks.create",
  6661. 1072 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  6662. 1073 @profile
  6663. 1074 def create(self, label, cidr_block):
  6664. 1075 1 8.0 8.0 0.0 OpenStackNetwork.assert_valid_resource_label(label)
  6665. 1076 1 1.0 1.0 0.0 net_info = {'name': label or ""}
  6666. 1077 1 2225770.0 2225770.0 64.2 network = self.provider.neutron.create_network({'network': net_info})
  6667. 1078 1 38.0 38.0 0.0 cb_net = OpenStackNetwork(self.provider, network.get('network'))
  6668. 1079 1 1.0 1.0 0.0 if label:
  6669. 1080 1 1242335.0 1242335.0 35.8 cb_net.label = label
  6670. 1081 1 1.0 1.0 0.0 return cb_net
  6671. Total time: 4.68956 s
  6672. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6673. Function: delete at line 1083
  6674. Line # Hits Time Per Hit % Time Line Contents
  6675. ==============================================================
  6676. 1083 @dispatch(event="provider.networking.networks.delete",
  6677. 1084 priority=BaseNetworkService.STANDARD_EVENT_PRIORITY)
  6678. 1085 @profile
  6679. 1086 def delete(self, network):
  6680. 1087 1 3.0 3.0 0.0 network = (network if isinstance(network, OpenStackNetwork) else
  6681. 1088 self.get(network))
  6682. 1089 1 1.0 1.0 0.0 if not network:
  6683. 1090 return
  6684. 1091 1 7.0 7.0 0.0 if not network.external and network.id in str(
  6685. 1092 1 358126.0 358126.0 7.6 self.provider.neutron.list_networks()):
  6686. 1093 # If there are ports associated with the network, it won't delete
  6687. 1094 1 8.0 8.0 0.0 ports = self.provider.neutron.list_ports(
  6688. 1095 1 441220.0 441220.0 9.4 network_id=network.id).get('ports', [])
  6689. 1096 3 8.0 2.7 0.0 for port in ports:
  6690. 1097 2 2.0 1.0 0.0 try:
  6691. 1098 2 1842265.0 921132.5 39.3 self.provider.neutron.delete_port(port.get('id'))
  6692. 1099 except PortNotFoundClient:
  6693. 1100 # Ports could have already been deleted if instances
  6694. 1101 # are terminated etc. so exceptions can be safely ignored
  6695. 1102 pass
  6696. 1103 1 2047921.0 2047921.0 43.7 self.provider.neutron.delete_network(network.id)
  6697. Total time: 0 s
  6698. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6699. Function: get at line 1111
  6700. Line # Hits Time Per Hit % Time Line Contents
  6701. ==============================================================
  6702. 1111 @dispatch(event="provider.networking.subnets.get",
  6703. 1112 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  6704. 1113 @profile
  6705. 1114 def get(self, subnet_id):
  6706. 1115 subnet = (s for s in self if s.id == subnet_id)
  6707. 1116 return next(subnet, None)
  6708. Total time: 3.89371 s
  6709. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6710. Function: list at line 1118
  6711. Line # Hits Time Per Hit % Time Line Contents
  6712. ==============================================================
  6713. 1118 @dispatch(event="provider.networking.subnets.list",
  6714. 1119 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  6715. 1120 @profile
  6716. 1121 def list(self, network=None, limit=None, marker=None):
  6717. 1122 4 5.0 1.2 0.0 if network:
  6718. 1123 1 4.0 4.0 0.0 network_id = (network.id if isinstance(network, OpenStackNetwork)
  6719. 1124 else network)
  6720. 1125 1 47.0 47.0 0.0 subnets = [subnet for subnet in self if network_id ==
  6721. 1126 subnet.network_id]
  6722. 1127 else:
  6723. 1128 3 3.0 1.0 0.0 subnets = [OpenStackSubnet(self.provider, subnet) for subnet in
  6724. 1129 3 3893477.0 1297825.7 100.0 self.provider.neutron.list_subnets().get('subnets', [])]
  6725. 1130 4 15.0 3.8 0.0 return ClientPagedResultList(self.provider, subnets,
  6726. 1131 4 163.0 40.8 0.0 limit=limit, marker=marker)
  6727. Total time: 0.560666 s
  6728. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6729. Function: create at line 1133
  6730. Line # Hits Time Per Hit % Time Line Contents
  6731. ==============================================================
  6732. 1133 @dispatch(event="provider.networking.subnets.create",
  6733. 1134 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  6734. 1135 @profile
  6735. 1136 def create(self, label, network, cidr_block, zone):
  6736. 1137 """zone param is ignored."""
  6737. 1138 1 9.0 9.0 0.0 OpenStackSubnet.assert_valid_resource_label(label)
  6738. 1139 1 3.0 3.0 0.0 network_id = (network.id if isinstance(network, OpenStackNetwork)
  6739. 1140 else network)
  6740. 1141 1 1.0 1.0 0.0 subnet_info = {'name': label, 'network_id': network_id,
  6741. 1142 1 1.0 1.0 0.0 'cidr': cidr_block, 'ip_version': 4}
  6742. 1143 1 560631.0 560631.0 100.0 subnet = (self.provider.neutron.create_subnet({'subnet': subnet_info})
  6743. 1144 1 3.0 3.0 0.0 .get('subnet'))
  6744. 1145 1 17.0 17.0 0.0 cb_subnet = OpenStackSubnet(self.provider, subnet)
  6745. 1146 1 1.0 1.0 0.0 return cb_subnet
  6746. Total time: 0.3819 s
  6747. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6748. Function: delete at line 1148
  6749. Line # Hits Time Per Hit % Time Line Contents
  6750. ==============================================================
  6751. 1148 @dispatch(event="provider.networking.subnets.delete",
  6752. 1149 priority=BaseSubnetService.STANDARD_EVENT_PRIORITY)
  6753. 1150 @profile
  6754. 1151 def delete(self, subnet):
  6755. 1152 1 4.0 4.0 0.0 sn_id = subnet.id if isinstance(subnet, OpenStackSubnet) else subnet
  6756. 1153 1 381896.0 381896.0 100.0 self.provider.neutron.delete_subnet(sn_id)
  6757. Total time: 3.58635 s
  6758. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6759. Function: get_or_create_default at line 1155
  6760. Line # Hits Time Per Hit % Time Line Contents
  6761. ==============================================================
  6762. 1155 @profile
  6763. 1156 def get_or_create_default(self, zone):
  6764. 1157 """
  6765. 1158 Subnet zone is not supported by OpenStack and is thus ignored.
  6766. 1159 """
  6767. 1160 2 4.0 2.0 0.0 try:
  6768. 1161 2 3586339.0 1793169.5 100.0 sn = self.find(label=OpenStackSubnet.CB_DEFAULT_SUBNET_LABEL)
  6769. 1162 2 3.0 1.5 0.0 if sn:
  6770. 1163 2 3.0 1.5 0.0 return sn[0]
  6771. 1164 # No default subnet look for default network, then create subnet
  6772. 1165 net = self.provider.networking.networks.get_or_create_default()
  6773. 1166 sn = self.provider.networking.subnets.create(
  6774. 1167 label=OpenStackSubnet.CB_DEFAULT_SUBNET_LABEL,
  6775. 1168 cidr_block=OpenStackSubnet.CB_DEFAULT_SUBNET_IPV4RANGE,
  6776. 1169 network=net, zone=zone)
  6777. 1170 router = self.provider.networking.routers.get_or_create_default(
  6778. 1171 net)
  6779. 1172 router.attach_subnet(sn)
  6780. 1173 gateway = net.gateways.get_or_create()
  6781. 1174 router.attach_gateway(gateway)
  6782. 1175 return sn
  6783. 1176 except NeutronClientException:
  6784. 1177 return None
  6785. Total time: 0 s
  6786. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6787. Function: get at line 1185
  6788. Line # Hits Time Per Hit % Time Line Contents
  6789. ==============================================================
  6790. 1185 @dispatch(event="provider.networking.routers.get",
  6791. 1186 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  6792. 1187 @profile
  6793. 1188 def get(self, router_id):
  6794. 1189 log.debug("Getting OpenStack Router with the id: %s", router_id)
  6795. 1190 router = self.provider.os_conn.get_router(router_id)
  6796. 1191 return OpenStackRouter(self.provider, router) if router else None
  6797. Total time: 0 s
  6798. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6799. Function: list at line 1193
  6800. Line # Hits Time Per Hit % Time Line Contents
  6801. ==============================================================
  6802. 1193 @dispatch(event="provider.networking.routers.list",
  6803. 1194 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  6804. 1195 @profile
  6805. 1196 def list(self, limit=None, marker=None):
  6806. 1197 routers = self.provider.os_conn.list_routers()
  6807. 1198 os_routers = [OpenStackRouter(self.provider, r) for r in routers]
  6808. 1199 return ClientPagedResultList(self.provider, os_routers, limit=limit,
  6809. 1200 marker=marker)
  6810. Total time: 0 s
  6811. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6812. Function: find at line 1202
  6813. Line # Hits Time Per Hit % Time Line Contents
  6814. ==============================================================
  6815. 1202 @dispatch(event="provider.networking.routers.find",
  6816. 1203 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  6817. 1204 @profile
  6818. 1205 def find(self, **kwargs):
  6819. 1206 obj_list = self
  6820. 1207 filters = ['label']
  6821. 1208 matches = cb_helpers.generic_find(filters, kwargs, obj_list)
  6822. 1209 return ClientPagedResultList(self._provider, list(matches))
  6823. Total time: 0 s
  6824. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6825. Function: create at line 1211
  6826. Line # Hits Time Per Hit % Time Line Contents
  6827. ==============================================================
  6828. 1211 @dispatch(event="provider.networking.routers.create",
  6829. 1212 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  6830. 1213 @profile
  6831. 1214 def create(self, label, network):
  6832. 1215 """Parameter ``network`` is not used by OpenStack."""
  6833. 1216 router = self.provider.os_conn.create_router(name=label)
  6834. 1217 return OpenStackRouter(self.provider, router)
  6835. Total time: 0 s
  6836. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6837. Function: delete at line 1219
  6838. Line # Hits Time Per Hit % Time Line Contents
  6839. ==============================================================
  6840. 1219 @dispatch(event="provider.networking.routers.delete",
  6841. 1220 priority=BaseRouterService.STANDARD_EVENT_PRIORITY)
  6842. 1221 @profile
  6843. 1222 def delete(self, router):
  6844. 1223 r_id = router.id if isinstance(router, OpenStackRouter) else router
  6845. 1224 self.provider.os_conn.delete_router(r_id)
  6846. Total time: 0 s
  6847. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6848. Function: get_or_create at line 1249
  6849. Line # Hits Time Per Hit % Time Line Contents
  6850. ==============================================================
  6851. 1249 @dispatch(event="provider.networking.gateways.get_or_create",
  6852. 1250 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  6853. 1251 @profile
  6854. 1252 def get_or_create(self, network):
  6855. 1253 """For OS, inet gtw is any net that has `external` property set."""
  6856. 1254 external_nets = (n for n in self._provider.networking.networks
  6857. 1255 if n.external)
  6858. 1256 for net in external_nets:
  6859. 1257 if self._check_fip_connectivity(network, net):
  6860. 1258 return OpenStackInternetGateway(self._provider, net)
  6861. 1259 return None
  6862. Total time: 0 s
  6863. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6864. Function: delete at line 1261
  6865. Line # Hits Time Per Hit % Time Line Contents
  6866. ==============================================================
  6867. 1261 @dispatch(event="provider.networking.gateways.delete",
  6868. 1262 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  6869. 1263 @profile
  6870. 1264 def delete(self, network, gateway):
  6871. 1265 pass
  6872. Total time: 0 s
  6873. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6874. Function: list at line 1267
  6875. Line # Hits Time Per Hit % Time Line Contents
  6876. ==============================================================
  6877. 1267 @dispatch(event="provider.networking.gateways.list",
  6878. 1268 priority=BaseGatewayService.STANDARD_EVENT_PRIORITY)
  6879. 1269 @profile
  6880. 1270 def list(self, network, limit=None, marker=None):
  6881. 1271 log.debug("OpenStack listing of all current internet gateways")
  6882. 1272 igl = [OpenStackInternetGateway(self._provider, n)
  6883. 1273 for n in self._provider.networking.networks
  6884. 1274 if n.external and self._check_fip_connectivity(network, n)]
  6885. 1275 return ClientPagedResultList(self._provider, igl, limit=limit,
  6886. 1276 marker=marker)
  6887. Total time: 0 s
  6888. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6889. Function: get at line 1284
  6890. Line # Hits Time Per Hit % Time Line Contents
  6891. ==============================================================
  6892. 1284 @dispatch(event="provider.networking.floating_ips.get",
  6893. 1285 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  6894. 1286 @profile
  6895. 1287 def get(self, gateway, fip_id):
  6896. 1288 try:
  6897. 1289 return OpenStackFloatingIP(
  6898. 1290 self.provider,
  6899. 1291 self.provider.os_conn.network.get_ip(fip_id))
  6900. 1292 except (ResourceNotFound, NotFoundException):
  6901. 1293 log.debug("Floating IP %s not found.", fip_id)
  6902. 1294 return None
  6903. Total time: 0 s
  6904. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6905. Function: list at line 1296
  6906. Line # Hits Time Per Hit % Time Line Contents
  6907. ==============================================================
  6908. 1296 @dispatch(event="provider.networking.floating_ips.list",
  6909. 1297 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  6910. 1298 @profile
  6911. 1299 def list(self, gateway, limit=None, marker=None):
  6912. 1300 fips = [OpenStackFloatingIP(self.provider, fip)
  6913. 1301 for fip in self.provider.os_conn.network.ips(
  6914. 1302 floating_network_id=gateway.id
  6915. 1303 )]
  6916. 1304 return ClientPagedResultList(self.provider, fips,
  6917. 1305 limit=limit, marker=marker)
  6918. Total time: 0 s
  6919. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6920. Function: create at line 1307
  6921. Line # Hits Time Per Hit % Time Line Contents
  6922. ==============================================================
  6923. 1307 @dispatch(event="provider.networking.floating_ips.create",
  6924. 1308 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  6925. 1309 @profile
  6926. 1310 def create(self, gateway):
  6927. 1311 return OpenStackFloatingIP(
  6928. 1312 self.provider, self.provider.os_conn.network.create_ip(
  6929. 1313 floating_network_id=gateway.id))
  6930. Total time: 0 s
  6931. File: /Users/alex/Desktop/work/cloudbridge/cloudbridge/cloud/providers/openstack/services.py
  6932. Function: delete at line 1315
  6933. Line # Hits Time Per Hit % Time Line Contents
  6934. ==============================================================
  6935. 1315 @dispatch(event="provider.networking.floating_ips.delete",
  6936. 1316 priority=BaseFloatingIPService.STANDARD_EVENT_PRIORITY)
  6937. 1317 @profile
  6938. 1318 def delete(self, gateway, fip):
  6939. 1319 if isinstance(fip, OpenStackFloatingIP):
  6940. 1320 # pylint:disable=protected-access
  6941. 1321 os_ip = fip._ip
  6942. 1322 else:
  6943. 1323 try:
  6944. 1324 os_ip = self.provider.os_conn.network.get_ip(fip)
  6945. 1325 except (ResourceNotFound, NotFoundException):
  6946. 1326 log.debug("Floating IP %s not found.", fip)
  6947. 1327 return True
  6948. 1328 os_ip.delete(self._provider.os_conn.session)