azure-cloud_factory.res 543 KB

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