gcp-compute.res 544 KB

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