2
0

azure-region.res 543 KB

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