openstack-image.res 546 KB

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