openstack-block_store.res 550 KB

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