Surprise! We've been running on hardware provided by BuyVM for a few months and wanted to show them a little appreciation.
Running a paste site comes with unique challenges, ones that aren't always obvious and hard to control. As such, BuyVM offered us a home where we could worry less about the hosting side of things and focus on maintaining a clean and useful service! Go check them out and show them some love!
Description: ovirt-setup-log
Submitted by elnin0 on October 20, 2014

Section 1 (Text)

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706

2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/log=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFileHandle=file:'<open file '/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log', mode 'a' at 0x213c5d0>'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFileName=str:'/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilter=_MyLoggerFilter:'filter'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilterKeys=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logRemoveAtExit=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage boot METHOD otopi.plugins.otopi.dialog.misc.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/dialect=str:'human'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage boot METHOD otopi.plugins.otopi.dialog.human.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/boundary=str:'--=451b80dc-996f-432e-9e4f-2b29ef6d1141=--'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage boot METHOD otopi.plugins.otopi.dialog.machine.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage boot METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.connection.Plugin._boot
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilterKeys=list:'['OVESETUP_DB/password']'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage boot METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._boot
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilterKeys=list:'['OVESETUP_DB/password', 'OVESETUP_CONFIG/adminPassword']'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage boot METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._boot
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilterKeys=list:'['OVESETUP_DB/password', 'OVESETUP_CONFIG/adminPassword', 'OVESETUP_PKI/storePassword']'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage boot METHOD otopi.plugins.otopi.core.misc.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:467 SEQUENCE DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE boot
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.core.misc.Plugin._preinit (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.core.misc.Plugin._preinit (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.log.Plugin._init (otopi.core.log.init)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.dialog.misc.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.dialog.human.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.dialog.machine.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.connection.Plugin._boot (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._boot (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._boot (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.misc.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._boot (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.system.info.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.config.Plugin._init (otopi.core.config.init)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._init (otopi.packagers.detection)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.system.command.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.core.misc.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.transaction.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.dialog.cli.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.firewalld.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.iptables.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.ssh.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.system.clock.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.system.reboot.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.core.answerfile.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.core.offlinepackager.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.core.postinstall.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.core.uninstall.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.network.firewall_manager.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.network.firewall_manager_firewalld.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.system.hostile_services.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.core.engine.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.connection.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.pgpass.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.core.protocols.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.system.apache.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.system.environment.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.core.misc.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.dialog.preview.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.network.hostname.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.system.environment.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.core.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.cpu.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.storage.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.engine.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.root.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.appmode.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.domain_type.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.iso_domain.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.macrange.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.public_glance_repository.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.core.misc.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.distro-rpm.packages.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.memcheck.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.asynctasks.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.dbvalidations.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.core.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.misc.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.config.java.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.config.jboss.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.provisioning.postgres.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.pki.Plugin._init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._setup_existence (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.config.Plugin._post_init (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.log.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.misc.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine_root_ssh.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.cpu.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.firewalld.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.hostname.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.services.openrc.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.services.rhel.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.services.systemd.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.system.clock.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.system.reboot.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.network.firewall_manager_firewalld.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.network.firewall_manager_human.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.network.firewall_manager_iptables.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine_manual_files.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.system.hostile_services.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.core.misc.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.connection.Plugin._setup (osetup.db.connection.setup)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.core.misc.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.core.protocols.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.system.apache.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._keep_only_valid_firewall_managers (osetup.keep.only.valid.firewall.managers)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.network.hostname.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.core.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.root.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.jboss.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.connection.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.distro-rpm.packages.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event.Plugin._log_setup_event_setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE internal_packages
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.transaction.Plugin._pre_prepare (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.hostname.Plugin._internal_packages (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._internal_packages_end (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.transaction.Plugin._pre_end (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE programs
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.system.command.Plugin._programs (otopi.system.command.detection)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.services.systemd.Plugin._programs (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.services.rhel.Plugin._programs (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.services.openrc.Plugin._programs (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE late_setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._setup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._late_setup_service_state (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE customization
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.firewalld.Plugin._customization (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.config.Plugin._customize1 (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.dialog.cli.Plugin._customize (otopi.dialog.cli.customization)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.dialog.titles.Plugin._title_s_product_options (osetup.dialog.titles.productoptions.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.core.misc.Plugin._customization (osetup.engine.core.enable)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._customization (setup.config.websocket-proxy.customization)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.dialog.titles.Plugin._title_e_product_options (osetup.dialog.titles.productoptions.end)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.core.Plugin._continueSetupWithoutAIO (osetup.aio.config.not.available)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_packages (osetup.dialog.titles.packaging.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages.Plugin._customization (osetup.distro-rpm.package.update.check)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_packages (osetup.dialog.titles.packages.end)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_allinone (osetup.dialog.titles.allinone.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.core.Plugin._constomization (osetup.aio.config.available)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._customization (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.storage.Plugin._customization (osetup.aio.config.storage)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_allinone (osetup.dialog.titles.allinone.end)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_network (osetup.dialog.titles.network.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._customization_is_requested (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._customization (osetup.net.firewallmanager.available)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.firewall.Plugin._configuration (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.firewall.Plugin._configuration (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.config.firewall.Plugin._configuration (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.network.hostname.Plugin._customization (osetup.config.protocols.customization)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.protocols.Plugin._customization (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._network_owners_config_customized (osetup.network.owners.config.customized)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_network (osetup.dialog.titles.network.end)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_database (osetup.dialog.titles.database.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._customization_enable (osetup.engine.provisioning.pgsql.allow)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._customization (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.connection.Plugin._customization_enable (osetup.engine.db.connection.allow)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.connection.Plugin._customization (osetup.db.connection.customization)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._db_owners_connections_customized (osetup.db.owners.connections.customized)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_database (osetup.dialog.titles.database.end)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_engine (osetup.dialog.titles.engine.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._customization (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.appmode.Plugin._customization_enable (osetup.engine.config.appmode.allow)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.appmode.Plugin._customization (osetup.config.applicationMode.available)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.domain_type.Plugin._customization (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_engine (osetup.dialog.titles.engine.end)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_pki (osetup.dialog.titles.pki.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._customization_enable (osetup.engine.pki.ca.allow)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._customization (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_pki (osetup.dialog.titles.pki.end)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_apache (osetup.dialog.titles.apache.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.root.Plugin._customization (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._customization (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_apache (osetup.dialog.titles.apache.end)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_system (osetup.dialog.titles.system.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._customization_firewall (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._customization_enable (osetup.engine.system.nfs.allow)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._customization (osetup.system.nfs.available)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.iso_domain.Plugin._customization (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.fence_kdump_listener.config.Plugin._customization_disable (osetup.engine.kdump.allow)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.fence_kdump_listener.config.Plugin._customization_firewall (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_system (osetup.dialog.titles.system.end)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_misc (osetup.dialog.titles.misc.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_misc (osetup.dialog.titles.misc.end)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._firewall (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.config.Plugin._customize2 (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._customization_firewall (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE validation
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.misc.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._validation_enable (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux.Plugin._validation_enable (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.asynctasks.Plugin._validateEnv (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux.Plugin._validation_enable (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._validate_enable (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.firewalld.Plugin._validation (otopi.network.firewalld.validation)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.hostname.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.iptables.Plugin._validate (otopi.network.iptables.validation)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.ssh.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.core.engine.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.pgpass.Plugin._validation (osetup.db.connection.credentials.early)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.cpu.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._validation_enable (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.schema.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.memcheck.Plugin._validateMemory (osetup.memory.check)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.memcheck.Plugin._validateContinueLowMemory (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.asynctasks.Plugin._validateZombies (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._validate_ssl (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.config.java.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.pki.Plugin._validate (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.dialog.preview.Plugin._customization (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.asynctasks.Plugin._validateAsyncTasks (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.dbvalidations.Plugin._validation (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE transaction-prepare
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.transaction.Plugin._main_prepare (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.system.hostile_services.Plugin._transaction_begin (osetup.system.hostile.detection)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.core.engine.Plugin._transactionBegin (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.core.fence_kdump_listener.Plugin._transactionBegin (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.websocket_proxy.core.Plugin._transactionBegin (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE early_misc
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.firewalld.Plugin._early_misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.dbvalidations.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE packages
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.iptables.Plugin._packages (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages.Plugin.packages (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._packages (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE misc
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.config.jboss.Plugin._jboss (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.system.command.Plugin._misc (otopi.system.command.redetection)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl.Plugin._misc (osetup.system.sysctl.available)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.firewalld.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.iptables.Plugin._store_iptables (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.ssh.Plugin._append_key (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.system.clock.Plugin._set_clock (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.pgpass.Plugin._misc (osetup.db.connection.credentials.late)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._prepare_examples (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.core.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.storage.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.engine.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.root.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.database.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.jboss.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.protocols.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.tools.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.schema.Plugin._misc (osetup.db.schema)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.connection.Plugin._connection (osetup.db.connection.available)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.appmode.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.domain_type.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.iso_domain.Plugin._add_iso_domain_to_db (osetup.config.iso_domain.available)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.macrange.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._miscAlways (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._miscNewDatabase (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.public_glance_repository.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.legacy.osinfo.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._misc (osetup.pki.ca.available)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.ca.Plugin._misc (osetup.config.encryption.available)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._miscEncrypted (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin.miscOptions (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh.Plugin._misc (osetup.pki.ssh.available)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.answerfile_fixup.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._check_separate (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._misc_VDC (setup.config.websocket-proxy.remote_vdc)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._misc_config (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.pki.Plugin._misc_pki (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.misc.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.core.postinstall.Plugin._misc (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE cleanup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.transaction.Plugin._main_end (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE closeup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.firewalld.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.network.iptables.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.dialog.titles.Plugin._title_s_summary (osetup.dialog.titles.summary.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.memcheck.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.protocols.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.dialog.titles.Plugin._title_e_summary (osetup.dialog.titles.summary.end)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.system.hostile_services.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._closeup (osetup.aio.config.ssh)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.fence_kdump_listener.config.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.legacy.osinfo.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.engine.Plugin._closeup (osetup.core.engine.start)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.system.apache.Plugin._closeup (osetup.apache.core.restart)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm.Plugin._closeup (osetup.aio.config.vdsm)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.system.reboot.Plugin._closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event.Plugin._log_setup_event_closeup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE cleanup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.core.misc.Plugin._cleanup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine.Plugin._cleanup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.pki.Plugin._cleanup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.core.uninstall.Plugin._cleanup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.core.answerfile.Plugin._cleanup (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE pre-terminate
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.misc.Plugin._preTerminate (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.dialog.cli.Plugin._pre_terminate (otopi.dialog.cli.termination)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE terminate
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.ovirt_engine_common.base.core.misc.Plugin._terminate (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.dialog.human.Plugin._terminate (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.dialog.machine.Plugin._terminate (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.core.log.Plugin._terminate (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:469 STAGE reboot
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:474     METHOD otopi.plugins.otopi.system.reboot.Plugin._reboot (None)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpSequence:476 SEQUENCE DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/aborted=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/debug=int:'0'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/error=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/exceptionInfo=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/executionDirectory=str:'/root'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/log=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/pluginGroups=str:'otopi:ovirt-engine-common:ovirt-engine-setup'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/pluginPath=str:'/usr/share/otopi/plugins:/usr/share/ovirt-engine/setup/bin/../plugins'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/suppressEnvironmentKeys=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/configFileName=str:'/etc/ovirt-engine-setup.conf'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/failOnPrioOverride=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logDir=str:'/var/log/ovirt-engine/setup'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFileHandle=file:'<open file '/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log', mode 'a' at 0x213c5d0>'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFileName=str:'/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFileNamePrefix=str:'ovirt-engine-setup'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilter=_MyLoggerFilter:'filter'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilterKeys=list:'['OVESETUP_DB/password', 'OVESETUP_CONFIG/adminPassword', 'OVESETUP_PKI/storePassword']'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logRemoveAtExit=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/randomizeEvents=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/boundary=str:'--=451b80dc-996f-432e-9e4f-2b29ef6d1141=--'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/dialect=str:'human'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV INFO/PACKAGE_NAME=str:'otopi'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV INFO/PACKAGE_VERSION=str:'1.3.0'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV INFO/PACKAGE_NAME=str:'otopi'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV INFO/PACKAGE_VERSION=str:'1.3.0'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage boot METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._boot
Loaded plugins: fastestmirror, versionlock
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/keepAliveInterval=int:'30'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumDisabledPlugins=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumEnabledPlugins=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumExpireCache=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage boot METHOD otopi.plugins.otopi.system.info.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.system.info info._init:48 SYSTEM INFORMATION - BEGIN
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.system.info info._init:49 executable /usr/bin/python
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.system.info info._init:50 python /usr/bin/python
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.system.info info._init:51 platform linux2
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.system.info info._init:52 distribution ('CentOS', '6.5', 'Final')
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.system.info info._init:53 host 'ex1.gecko.hs-heilbronn.de'
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.system.info info._init:59 uid 0 euid 0 gid 0 egid 0
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.system.info info._init:61 SYSTEM INFORMATION - END
2014-10-20 14:30:50 INFO otopi.context context.runSequence:417 Stage: Initializing
2014-10-20 14:30:50 DEBUG otopi.context context.runSequence:421 STAGE init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.otopi.core.config.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/enable=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configureRootRedirectionDefault=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossHome=str:'/usr/share/ovirt-engine-jboss-as'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager._init:204 Registering yum packager
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumRollback=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumpackagerEnabled=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.otopi.system.command.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/commandPath=str:'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.base.core.misc.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.plugins.ovirt_engine_common.base.core.misc misc._init:99 Package: ovirt-engine-3.5.0.1 (3.5.0.1-1.el6)
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/developerMode=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/generatedByVersion=str:'3.5.0.1'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/setupAttributesModules=list:'[<module 'ovirt_engine_setup.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/constants.pyc'>]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/upgradeSupportedVersions=str:'3.0,3.1,3.2,3.3,3.4,3.5'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.otopi.core.transaction.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/internalPackageTransaction=Transaction:'transaction'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/mainTransaction=Transaction:'transaction'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/modifiedFiles=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.otopi.dialog.cli.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/cliVersion=int:'1'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/customization=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.otopi.network.firewalld.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/firewalldAvailable=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/firewalldDisableServices=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/firewalldEnable=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.otopi.network.iptables.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/iptablesEnable=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.otopi.network.ssh.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/sshEnable=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/sshUser=str:''
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.otopi.system.clock.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/clockMaxGap=int:'5'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/clockSet=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.otopi.system.reboot.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/reboot=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/rebootAllow=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/rebootDeferTime=int:'10'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.base.core.answerfile.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.base.core.offlinepackager.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/offlinePackager=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.base.core.postinstall.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/generatePostInstall=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.base.core.uninstall.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/registerUninstallGroups=RegisterGroups:'<otopi.plugins.ovirt_engine_common.base.core.uninstall.RegisterGroups object at 0x17e2390>'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/uninstallUnremovableFiles=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.base.network.firewall_manager.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/firewallManagers=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.base.network.firewall_manager_firewalld.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldServices=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldSubst=dict:'{}'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilterKeys=list:'['OVESETUP_DB/password', 'OVESETUP_CONFIG/adminPassword', 'OVESETUP_PKI/storePassword', 'OVESETUP_CONFIG/remoteEngineHostRootPassword']'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineSetupStyles=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.base.system.hostile_services.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/hostileServices=str:'ovirt-engine-dwhd,ovirt-engine-notifier'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.core.engine.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.connection.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/newDatabase=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.pgpass.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.core.protocols.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/httpPort=int:'80'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/httpsPort=int:'443'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossAjpPort=int:'8702'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossDebugAddress=str:'127.0.0.1:8787'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossHttpPort=int:'8080'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossHttpsPort=int:'8443'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.system.apache.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/httpdService=str:'httpd'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/needRestart=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.system.environment.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/groupKvm=str:'kvm'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userApache=str:'apache'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userPostgres=str:'postgres'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userRoot=str:'root'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userVdsm=str:'vdsm'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.base.core.misc.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/action=str:'setup'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.base.dialog.preview.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/validFirewallManagers=str:''
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.base.network.hostname.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/fqdnNonLoopback=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/fqdnReverseValidation=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.base.system.environment.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/groupEngine=str:'ovirt'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userEngine=str:'ovirt'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.core.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.cpu.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/supported=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.storage.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/storageDomainDefaultDir=str:'/var/lib/images'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/localCluster=str:'local_cluster'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/localDataCenter=str:'local_datacenter'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/localHost=str:'local_host'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.engine.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configFileOvirtEngine=str:'/etc/httpd/conf.d/z-ovirt-engine-proxy.conf'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.root.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configFileOvirtRoot=str:'/etc/httpd/conf.d/ovirt-engine-root-redirect.conf'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.appmode.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.domain_type.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/storageIsLocal=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.iso_domain.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainDefaultMountPoint=str:'/var/lib/exports/iso'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainExists=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.macrange.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/macRangePool=str:'00:1a:4a:e2:37:00-00:1a:4a:e2:37:ff'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.public_glance_repository.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/addOvirtGlanceRepository=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.core.misc.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.distro-rpm.packages.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/enginePackages=str:'ovirt-engine'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/engineSetupPackages=str:'ovirt-engine-setup'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/upgradeYumGroup=str:'ovirt-engine-3.4'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PKI/country=str:'US'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PKI/storePassword=str:'**FILTERED**'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.memcheck.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckEnabled=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckMinimumMB=int:'4096'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckRecommendedMB=int:'16384'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckThreshold=int:'90'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/nfsConfigEnabled_legacyInPostInstall=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/selinuxContexts=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/selinuxRestorePaths=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.asynctasks.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ASYNC/clearTasks=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ASYNC/clearTasksWait=int:'20'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.dbvalidations.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.core.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/enable=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.misc.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configured=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configFileSsl=str:'/etc/httpd/conf.d/ssl.conf'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.config.java.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.config.jboss.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossNeeded=bool:'False'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/versionLockApply=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/versionLockFilter=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/packagesSetup=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/packagesUpgradeList=list:'[]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.provisioning.postgres.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresConf=str:'/var/lib/pgsql/data/postgresql.conf'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresListenAddress=str:''*''
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresMaxConn=int:'150'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresPgHba=str:'/var/lib/pgsql/data/pg_hba.conf'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresPgVersion=str:'/var/lib/pgsql/data/PG_VERSION'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresService=str:'postgresql'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/shmmax=int:'68719476736'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/websocketProxyHost=str:'localhost'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/websocketProxyPort=int:'6100'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage init METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.pki.Plugin._init
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/keySize=int:'2048'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 INFO otopi.context context.runSequence:417 Stage: Environment setup
2014-10-20 14:30:50 DEBUG otopi.context context.runSequence:421 STAGE setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._setup_existence
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.core.config.Plugin._post_init
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Configuration files: ['/etc/ovirt-engine-setup.conf.d/10-packaging-aio.conf', '/etc/ovirt-engine-setup.conf.d/10-packaging-jboss.conf', '/etc/ovirt-engine-setup.conf.d/10-packaging.conf']
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.core.log.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Log file: /var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.core.misc.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Version: otopi-1.3.0 (otopi-1.3.0-1.el6)
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Cleaning caches: ['expire-cache'].
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine_root_ssh.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineSetupStyles=list:'[<otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine_root_ssh._RootSshManager object at 0x26be0d0>]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.cpu.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: processor	: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: vendor_id	: GenuineIntel
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu family	: 6
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model		: 60
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model name	: Intel(R) Xeon(R) CPU E3-1246 v3 @ 3.50GHz
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: stepping	: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu MHz		: 800.000
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache size	: 8192 KB
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: physical id	: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: siblings	: 8
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: core id		: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu cores	: 4
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: apicid		: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: initial apicid	: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu_exception	: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpuid level	: 13
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: wp		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: bogomips	: 7000.51
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: clflush size	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache_alignment	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: address sizes	: 39 bits physical, 48 bits virtual
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: power management:
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: 
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: processor	: 1
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: vendor_id	: GenuineIntel
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu family	: 6
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model		: 60
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model name	: Intel(R) Xeon(R) CPU E3-1246 v3 @ 3.50GHz
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: stepping	: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu MHz		: 800.000
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache size	: 8192 KB
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: physical id	: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: siblings	: 8
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: core id		: 1
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu cores	: 4
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: apicid		: 2
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: initial apicid	: 2
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu_exception	: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpuid level	: 13
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: wp		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: bogomips	: 7000.51
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: clflush size	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache_alignment	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: address sizes	: 39 bits physical, 48 bits virtual
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: power management:
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: 
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: processor	: 2
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: vendor_id	: GenuineIntel
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu family	: 6
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model		: 60
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model name	: Intel(R) Xeon(R) CPU E3-1246 v3 @ 3.50GHz
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: stepping	: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu MHz		: 800.000
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache size	: 8192 KB
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: physical id	: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: siblings	: 8
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: core id		: 2
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu cores	: 4
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: apicid		: 4
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: initial apicid	: 4
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu_exception	: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpuid level	: 13
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: wp		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: bogomips	: 7000.51
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: clflush size	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache_alignment	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: address sizes	: 39 bits physical, 48 bits virtual
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: power management:
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: 
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: processor	: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: vendor_id	: GenuineIntel
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu family	: 6
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model		: 60
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model name	: Intel(R) Xeon(R) CPU E3-1246 v3 @ 3.50GHz
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: stepping	: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu MHz		: 800.000
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache size	: 8192 KB
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: physical id	: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: siblings	: 8
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: core id		: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu cores	: 4
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: apicid		: 6
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: initial apicid	: 6
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu_exception	: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpuid level	: 13
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: wp		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: bogomips	: 7000.51
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: clflush size	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache_alignment	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: address sizes	: 39 bits physical, 48 bits virtual
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: power management:
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: 
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: processor	: 4
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: vendor_id	: GenuineIntel
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu family	: 6
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model		: 60
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model name	: Intel(R) Xeon(R) CPU E3-1246 v3 @ 3.50GHz
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: stepping	: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu MHz		: 3501.000
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache size	: 8192 KB
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: physical id	: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: siblings	: 8
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: core id		: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu cores	: 4
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: apicid		: 1
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: initial apicid	: 1
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu_exception	: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpuid level	: 13
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: wp		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: bogomips	: 7000.51
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: clflush size	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache_alignment	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: address sizes	: 39 bits physical, 48 bits virtual
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: power management:
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: 
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: processor	: 5
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: vendor_id	: GenuineIntel
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu family	: 6
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model		: 60
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model name	: Intel(R) Xeon(R) CPU E3-1246 v3 @ 3.50GHz
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: stepping	: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu MHz		: 800.000
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache size	: 8192 KB
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: physical id	: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: siblings	: 8
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: core id		: 1
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu cores	: 4
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: apicid		: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: initial apicid	: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu_exception	: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpuid level	: 13
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: wp		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: bogomips	: 7000.51
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: clflush size	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache_alignment	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: address sizes	: 39 bits physical, 48 bits virtual
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: power management:
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: 
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: processor	: 6
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: vendor_id	: GenuineIntel
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu family	: 6
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model		: 60
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model name	: Intel(R) Xeon(R) CPU E3-1246 v3 @ 3.50GHz
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: stepping	: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu MHz		: 800.000
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache size	: 8192 KB
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: physical id	: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: siblings	: 8
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: core id		: 2
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu cores	: 4
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: apicid		: 5
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: initial apicid	: 5
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu_exception	: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpuid level	: 13
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: wp		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: bogomips	: 7000.51
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: clflush size	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache_alignment	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: address sizes	: 39 bits physical, 48 bits virtual
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: power management:
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: 
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: processor	: 7
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: vendor_id	: GenuineIntel
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu family	: 6
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model		: 60
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: model name	: Intel(R) Xeon(R) CPU E3-1246 v3 @ 3.50GHz
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: stepping	: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu MHz		: 800.000
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache size	: 8192 KB
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: physical id	: 0
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: siblings	: 8
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: core id		: 3
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpu cores	: 4
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: apicid		: 7
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: initial apicid	: 7
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: fpu_exception	: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cpuid level	: 13
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: wp		: yes
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: bogomips	: 7000.51
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: clflush size	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: cache_alignment	: 64
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: address sizes	: 39 bits physical, 48 bits virtual
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: power management:
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.getVendor:49 cpuinfo: 
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware._prdmsr:122 prdmsr: 5
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware._vmx_enabled_by_bios:137 vmx bios: True
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware._cpuid:85 cpuid: (198339, 1050624, 2147154943, 3219913727)
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware._cpu_has_vmx_support:92 vmx support: True
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware._isVirtualizationEnabled:186 virtualization support GenuineIntel (cpu: True, bios: True)
2014-10-20 14:30:50 DEBUG otopi.ovirt_host_deploy.hardware hardware.detect:198 Hardware supports virtualization
2014-10-20 14:30:50 INFO otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.cpu cpu._setup:116 Hardware supports virtualization
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/supported=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.network.firewalld.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.network.hostname.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.services.openrc.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.services.rhel.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.services.systemd.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.system.clock.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.otopi.system.reboot.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.base.network.firewall_manager_firewalld.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/firewallManagers=list:'[<otopi.plugins.ovirt_engine_common.base.network.firewall_manager_firewalld._FirewalldManager object at 0x26be810>]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.base.network.firewall_manager_human.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/firewallManagers=list:'[<otopi.plugins.ovirt_engine_common.base.network.firewall_manager_firewalld._FirewalldManager object at 0x26be810>, <otopi.plugins.ovirt_engine_common.base.network.firewall_manager_human._HumanManager object at 0x26be850>]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.base.network.firewall_manager_iptables.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/firewallManagers=list:'[<otopi.plugins.ovirt_engine_common.base.network.firewall_manager_firewalld._FirewalldManager object at 0x26be810>, <otopi.plugins.ovirt_engine_common.base.network.firewall_manager_human._HumanManager object at 0x26be850>, <otopi.plugins.ovirt_engine_common.base.network.firewall_manager_iptables._IpTablesManager object at 0x26be790>]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/remoteEngine=RemoteEngine:'<ovirt_engine_setup.remote_engine.RemoteEngine object at 0x26be890>'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine_manual_files.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineSetupStyles=list:'[<otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine_root_ssh._RootSshManager object at 0x26be0d0>, <otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine_manual_files._ManualFiles object at 0x26be8d0>]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.base.system.hostile_services.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.core.misc.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/setupAttributesModules=list:'[<module 'ovirt_engine_setup.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/constants.pyc'>, <module 'ovirt_engine_setup.engine.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine/constants.pyc'>]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.connection.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.core.misc.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/setupAttributesModules=list:'[<module 'ovirt_engine_setup.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/constants.pyc'>, <module 'ovirt_engine_setup.engine.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine/constants.pyc'>, <module 'ovirt_engine_setup.engine_common.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine_common/constants.pyc'>]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.core.protocols.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/publicHttpPort=int:'80'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/publicHttpsPort=int:'443'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.system.apache.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._keep_only_valid_firewall_managers
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.base.network.hostname.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.core.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.root.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.jboss.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossNeeded=bool:'True'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.connection.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.distro-rpm.packages.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/versionLockApply=list:'['ovirt-engine', 'ovirt-engine-backend', 'ovirt-engine-dbscripts', 'ovirt-engine-restapi', 'ovirt-engine-tools', 'ovirt-engine-userportal', 'ovirt-engine-webadmin-portal']'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/versionLockFilter=list:'['ovirt-engine']'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/packagesSetup=list:'['ovirt-engine-setup']'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/packagesUpgradeList=list:'[{'packages': ['ovirt-engine'], 'group': 'ovirt-engine-3.4'}]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/uninstallUnremovableFiles=list:'['/etc/exports']'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._setup
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/setupAttributesModules=list:'[<module 'ovirt_engine_setup.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/constants.pyc'>, <module 'ovirt_engine_setup.engine.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine/constants.pyc'>, <module 'ovirt_engine_setup.engine_common.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine_common/constants.pyc'>, <module 'ovirt_engine_setup.websocket_proxy.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/websocket_proxy/constants.pyc'>]'
2014-10-20 14:30:50 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage setup METHOD otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event.Plugin._log_setup_event_setup
2014-10-20 14:30:50 DEBUG otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/ovirt-engine-log-setup-event.sh', '--notes=Start of setup'), executable='None', cwd='None', env=None
2014-10-20 14:30:50 DEBUG otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/ovirt-engine-log-setup-event.sh', '--notes=Start of setup'), rc=0
2014-10-20 14:30:50 DEBUG otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event plugin.execute:861 execute-output: ('/usr/share/ovirt-engine/bin/ovirt-engine-log-setup-event.sh', '--notes=Start of setup') stdout:


2014-10-20 14:30:50 DEBUG otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event plugin.execute:866 execute-output: ('/usr/share/ovirt-engine/bin/ovirt-engine-log-setup-event.sh', '--notes=Start of setup') stderr:


2014-10-20 14:30:50 INFO otopi.context context.runSequence:417 Stage: Environment packages setup
2014-10-20 14:30:50 DEBUG otopi.context context.runSequence:421 STAGE internal_packages
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage internal_packages METHOD otopi.plugins.otopi.core.transaction.Plugin._pre_prepare
2014-10-20 14:30:50 DEBUG otopi.transaction transaction._prepare:77 preparing 'Yum Transaction'
Loaded plugins: fastestmirror, versionlock
2014-10-20 14:30:50 DEBUG otopi.context context._executeMethod:138 Stage internal_packages METHOD otopi.plugins.otopi.network.hostname.Plugin._internal_packages
2014-10-20 14:30:50 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum queue package iproute for install
Loading mirror speeds from cached hostfile
2014-10-20 14:30:55 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: ovirt-3.5-epel/metalink (0%)
2014-10-20 14:30:55 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: ovirt-3.5-epel/metalink 28 k(100%)
 * base: mirror.checkdomain.de
 * extras: mirror.checkdomain.de
 * ovirt-3.5: ftp.nluug.nl
 * ovirt-3.5-epel: mirrors.n-ix.net
 * ovirt-3.5-jpackage-6.0-generic: sunsite.informatik.rwth-aachen.de
 * updates: mirror.checkdomain.de
2014-10-20 14:31:01 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdg_kgnvtmp.xml (0%)
2014-10-20 14:31:01 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdg_kgnvtmp.xml 3.7 k(100%)
2014-10-20 14:31:02 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdk6ULxitmp.xml (0%)
2014-10-20 14:31:02 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdk6ULxitmp.xml 3.3 k(100%)
2014-10-20 14:31:02 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdj_Ketptmp.xml (0%)
2014-10-20 14:31:02 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdj_Ketptmp.xml 2.9 k(100%)
2014-10-20 14:31:02 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Not using downloaded repomd.xml because it is older than what we have:
  Current   : Mon Oct 20 08:56:44 2014
  Downloaded: Fri Oct 17 12:28:19 2014
2014-10-20 14:31:02 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdv1atKctmp.xml (0%)
2014-10-20 14:31:02 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdv1atKctmp.xml 2.9 k(100%)
2014-10-20 14:31:03 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdRlnYLDtmp.xml (0%)
2014-10-20 14:31:03 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdRlnYLDtmp.xml 2.9 k(100%)
2014-10-20 14:31:03 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomd1L1h58tmp.xml (0%)
2014-10-20 14:31:03 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomd1L1h58tmp.xml 951 (100%)
2014-10-20 14:31:03 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdut5FVMtmp.xml (0%)
2014-10-20 14:31:03 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdut5FVMtmp.xml 3.0 k(100%)
2014-10-20 14:31:03 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdvdKGXVtmp.xml (0%)
2014-10-20 14:31:03 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Downloading: repomdvdKGXVtmp.xml 3.4 k(100%)
2014-10-20 14:31:03 DEBUG otopi.context context._executeMethod:138 Stage internal_packages METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._internal_packages_end
2014-10-20 14:31:03 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Building transaction
2014-10-20 14:31:03 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Empty transaction
2014-10-20 14:31:03 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Transaction Summary:
2014-10-20 14:31:03 DEBUG otopi.context context._executeMethod:138 Stage internal_packages METHOD otopi.plugins.otopi.core.transaction.Plugin._pre_end
2014-10-20 14:31:03 DEBUG otopi.transaction transaction.commit:159 committing 'Yum Transaction'
Loaded plugins: fastestmirror, versionlock
2014-10-20 14:31:04 INFO otopi.context context.runSequence:417 Stage: Programs detection
2014-10-20 14:31:04 DEBUG otopi.context context.runSequence:421 STAGE programs
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:138 Stage programs METHOD otopi.plugins.otopi.system.command.Plugin._programs
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/chkconfig=str:'/sbin/chkconfig'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/date=str:'/bin/date'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/dig=str:'/usr/bin/dig'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/exportfs=str:'/usr/sbin/exportfs'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/hwclock=str:'/sbin/hwclock'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/initctl=str:'/sbin/initctl'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/ip=str:'/sbin/ip'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/ntpq=str:'/usr/sbin/ntpq'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/pg_dump=str:'/usr/bin/pg_dump'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/pg_restore=str:'/usr/bin/pg_restore'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/psql=str:'/usr/bin/psql'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/reboot=str:'/sbin/reboot'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/restorecon=str:'/sbin/restorecon'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/rpm=str:'/bin/rpm'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/selinuxenabled=str:'/usr/sbin/selinuxenabled'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/semanage=str:'/usr/sbin/semanage'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/service=str:'/sbin/service'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/ssh-keygen=str:'/usr/bin/ssh-keygen'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/sshd=str:'/usr/sbin/sshd'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/sysctl=str:'/sbin/sysctl'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:138 Stage programs METHOD otopi.plugins.otopi.services.systemd.Plugin._programs
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:138 Stage programs METHOD otopi.plugins.otopi.services.rhel.Plugin._programs
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel rhel._programs:72 registering rhel provider
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:138 Stage programs METHOD otopi.plugins.otopi.services.openrc.Plugin._programs
2014-10-20 14:31:04 INFO otopi.context context.runSequence:417 Stage: Environment setup
2014-10-20 14:31:04 DEBUG otopi.context context.runSequence:421 STAGE late_setup
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:138 Stage late_setup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._setup
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service nfs-server exists
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'nfs-server'), executable='None', cwd='None', env=None
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'nfs-server'), rc=1
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'nfs-server') stdout:


2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'nfs-server') stderr:
initctl: Unknown job: nfs-server

2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service nfs-server exists False upstart=False
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service nfs exists
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'nfs'), executable='None', cwd='None', env=None
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'nfs'), rc=1
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'nfs') stdout:


2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'nfs') stderr:
initctl: Unknown job: nfs

2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service nfs exists True upstart=False
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/nfsServiceName=str:'nfs'
2014-10-20 14:31:04 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:138 Stage late_setup METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._late_setup_service_state
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel rhel.status:138 check service ovirt-websocket-proxy status
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), executable='None', cwd='None', env=None
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), rc=1
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stdout:


2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stderr:
initctl: Unknown job: ovirt-websocket-proxy

2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'ovirt-websocket-proxy', 'status'), executable='None', cwd='None', env=None
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'ovirt-websocket-proxy', 'status'), rc=3
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'ovirt-websocket-proxy', 'status') stdout:
ovirt-websocket-proxy is stopped

2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'ovirt-websocket-proxy', 'status') stderr:


2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel rhel.status:147 service ovirt-websocket-proxy status False
2014-10-20 14:31:04 INFO otopi.context context.runSequence:417 Stage: Environment customization
2014-10-20 14:31:04 DEBUG otopi.context context.runSequence:421 STAGE customization
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.otopi.network.firewalld.Plugin._customization
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service firewalld exists
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'firewalld'), executable='None', cwd='None', env=None
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'firewalld'), rc=1
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'firewalld') stdout:


2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'firewalld') stderr:
initctl: Unknown job: firewalld

2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service firewalld exists False upstart=False
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.otopi.core.config.Plugin._customize1
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.otopi.dialog.cli.Plugin._customize
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_common.base.dialog.titles.Plugin._title_s_product_options
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== PRODUCT OPTIONS ==--
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:31:04 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.core.misc.Plugin._customization
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_ENGINE_ENABLE
2014-10-20 14:31:04 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Configure Engine on this host (Yes, No) [Yes]: 
2014-10-20 14:31:07 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:31:07 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/enable=bool:'True'
2014-10-20 14:31:07 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ENGINE_CORE/enable=bool:'True'
2014-10-20 14:31:07 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:31:07 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._customization
2014-10-20 14:31:07 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_CONFIG_WEBSOCKET_PROXY
2014-10-20 14:31:07 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Configure WebSocket Proxy on this host (Yes, No) [Yes]: 
2014-10-20 14:31:48 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:31:48 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/websocketProxyConfig=bool:'True'
2014-10-20 14:31:48 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:31:48 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_common.base.dialog.titles.Plugin._title_e_product_options
2014-10-20 14:31:48 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.core.Plugin._continueSetupWithoutAIO
2014-10-20 14:31:48 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:31:48 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_packages
2014-10-20 14:31:48 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:31:48 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== PACKAGES ==--
2014-10-20 14:31:48 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:31:48 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages.Plugin._customization
2014-10-20 14:31:48 INFO otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages packages._customization:335 Checking for product updates...
2014-10-20 14:31:54 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages packages.verbose:179 Yum: Downloading: base/group_gz (0%)
2014-10-20 14:31:54 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages packages.verbose:179 Yum: Downloading: base/group_gz 220 k(100%)
2014-10-20 14:31:55 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages packages.verbose:179 Yum: Downloading: ovirt-3.5-epel/group_gz (0%)
2014-10-20 14:31:55 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages packages.verbose:179 Yum: Downloading: ovirt-3.5-epel/group_gz 237 k(100%)
2014-10-20 14:31:55 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages packages.verbose:179 Yum: queue package ovirt-engine for install
2014-10-20 14:31:55 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages packages.verbose:179 Yum: queue package ovirt-engine for update
2014-10-20 14:31:55 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages packages.verbose:179 Yum: Building transaction
2014-10-20 14:31:55 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages packages.verbose:179 Yum: Empty transaction
2014-10-20 14:31:55 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages packages.verbose:179 Yum: Transaction Summary:
2014-10-20 14:31:55 INFO otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages packages._customization:342 No product updates found
2014-10-20 14:31:55 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_packages
2014-10-20 14:31:55 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_allinone
2014-10-20 14:31:55 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:31:55 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== ALL IN ONE CONFIGURATION ==--
2014-10-20 14:31:55 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:31:55 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.core.Plugin._constomization
2014-10-20 14:31:55 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_AIO_CONFIGURE
2014-10-20 14:31:55 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Configure VDSM on this host? (Yes, No) [No]: 
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:RECEIVE    Yes
2014-10-20 14:32:31 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:32:31 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/configure=bool:'True'
2014-10-20 14:32:31 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/fqdnNonLoopback=bool:'True'
2014-10-20 14:32:31 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/fqdnReverseValidation=bool:'True'
2014-10-20 14:32:31 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:32:31 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._customization
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service sshd exists
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'sshd'), executable='None', cwd='None', env=None
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'sshd'), rc=1
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'sshd') stdout:


2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'sshd') stderr:
initctl: Unknown job: sshd

2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service sshd exists True upstart=False
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel rhel.status:138 check service sshd status
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'sshd'), executable='None', cwd='None', env=None
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'sshd'), rc=1
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'sshd') stdout:


2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'sshd') stderr:
initctl: Unknown job: sshd

2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'sshd', 'status'), executable='None', cwd='None', env=None
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'sshd', 'status'), rc=0
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'sshd', 'status') stdout:
openssh-daemon (pid  1299) is running...

2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'sshd', 'status') stderr:


2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.services.rhel rhel.status:147 service sshd status True
2014-10-20 14:32:31 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd plugin.executeRaw:785 execute: ('/usr/sbin/sshd', '-T'), executable='None', cwd='None', env=None
2014-10-20 14:32:31 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd plugin.executeRaw:803 execute-result: ('/usr/sbin/sshd', '-T'), rc=0
2014-10-20 14:32:31 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd plugin.execute:861 execute-output: ('/usr/sbin/sshd', '-T') stdout:
port 22
protocol 2
addressfamily any
listenaddress 0.0.0.0:22
listenaddress [::]:22
usepam 1
serverkeybits 1024
logingracetime 120
keyregenerationinterval 3600
x11displayoffset 10
maxauthtries 6
maxsessions 10
clientaliveinterval 0
clientalivecountmax 3
permitrootlogin yes
ignorerhosts yes
ignoreuserknownhosts no
rhostsrsaauthentication no
hostbasedauthentication no
hostbasedusesnamefrompacketonly no
rsaauthentication yes
pubkeyauthentication yes
kerberosauthentication no
kerberosorlocalpasswd yes
kerberosticketcleanup yes
gssapiauthentication no
gssapicleanupcredentials yes
passwordauthentication yes
kbdinteractiveauthentication no
challengeresponseauthentication no
printmotd yes
printlastlog yes
x11forwarding yes
x11uselocalhost yes
strictmodes yes
tcpkeepalive yes
permitemptypasswords no
permituserenvironment no
uselogin no
compression delayed
gatewayports no
showpatchlevel no
usedns yes
allowtcpforwarding yes
useprivilegeseparation yes
kerberosusekuserok yes
pidfile /var/run/sshd.pid
xauthlocation /usr/bin/xauth
authorizedkeysfile .ssh/authorized_keys
authorizedkeysfile2 .ssh/authorized_keys2
loglevel INFO
syslogfacility AUTHPRIV
hostkey /etc/ssh/ssh_host_rsa_key
hostkey /etc/ssh/ssh_host_dsa_key
acceptenv LANG
acceptenv LC_CTYPE
acceptenv LC_NUMERIC
acceptenv LC_TIME
acceptenv LC_COLLATE
acceptenv LC_MONETARY
acceptenv LC_MESSAGES
acceptenv LC_PAPER
acceptenv LC_NAME
acceptenv LC_ADDRESS
acceptenv LC_TELEPHONE
acceptenv LC_MEASUREMENT
acceptenv LC_IDENTIFICATION
acceptenv LC_ALL
acceptenv LANGUAGE
acceptenv XMODIFIERS
subsystem sftp /usr/libexec/openssh/sftp-server
maxstartups 10:30:100
permittunnel no
permitopen any

2014-10-20 14:32:31 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd plugin.execute:866 execute-output: ('/usr/sbin/sshd', '-T') stderr:


2014-10-20 14:32:31 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:32:31 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/sshdPort=int:'22'
2014-10-20 14:32:31 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:32:31 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.storage.Plugin._customization
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_AIO_STORAGE_DOMAIN_DIR
2014-10-20 14:32:31 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Local storage domain path [/var/lib/images]: 
2014-10-20 14:32:35 DEBUG otopi.ovirt_engine_setup.domains domains.check_valid_path:90 validate '/var/lib/images' as a valid mount point
2014-10-20 14:32:35 DEBUG otopi.ovirt_engine_setup.domains domains.check_base_writable:104 Attempting to write temp file to /var/lib
2014-10-20 14:32:35 DEBUG otopi.ovirt_engine_setup.domains domains.check_available_space:122 Checking available space on /var/lib
2014-10-20 14:32:35 DEBUG otopi.ovirt_engine_setup.domains domains.check_available_space:129 Available space on /var/lib is 195660Mb
2014-10-20 14:32:35 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_AIO_STORAGE_DOMAIN_NAME
2014-10-20 14:32:35 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Local storage domain name [local_storage]: 
2014-10-20 14:32:36 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:32:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/storageDomainDir=str:'/var/lib/images'
2014-10-20 14:32:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/storageDomainName=str:'local_storage'
2014-10-20 14:32:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/selinuxContexts=list:'[{'pattern': '/var/lib/images(/.*)?', 'type': 'public_content_rw_t'}]'
2014-10-20 14:32:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/selinuxRestorePaths=list:'['/var/lib/images']'
2014-10-20 14:32:36 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:32:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_allinone
2014-10-20 14:32:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_network
2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== NETWORK CONFIGURATION ==--
2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:32:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._customization_is_requested
2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service iptables exists
2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'iptables'), executable='None', cwd='None', env=None
2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'iptables'), rc=1
2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'iptables') stdout:


2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'iptables') stderr:
initctl: Unknown job: iptables

2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service iptables exists True upstart=False
2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Setup can automatically configure the firewall on this system.
2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Note: automatic configuration of the firewall may overwrite current settings.
2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_UPDATE_FIREWALL
2014-10-20 14:32:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Do you want Setup to configure the firewall? (Yes, No) [Yes]: 
2014-10-20 14:32:38 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:32:38 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/updateFirewall=bool:'True'
2014-10-20 14:32:38 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:32:38 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._customization
2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.services.rhel rhel.status:138 check service iptables status
2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'iptables'), executable='None', cwd='None', env=None
2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'iptables'), rc=1
2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'iptables') stdout:


2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'iptables') stderr:
initctl: Unknown job: iptables

2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'iptables', 'status'), executable='None', cwd='None', env=None
2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'iptables', 'status'), rc=3
2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'iptables', 'status') stdout:
iptables: Firewall is not running.

2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'iptables', 'status') stderr:


2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.services.rhel rhel.status:147 service iptables status False
2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 The following firewall managers were detected on this system: iptables
2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_CONFIG_FIREWALL_MANAGER
2014-10-20 14:32:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Firewall manager to configure (iptables): 
2014-10-20 14:32:42 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:RECEIVE    iptables
2014-10-20 14:32:42 INFO otopi.plugins.ovirt_engine_setup.base.network.firewall_manager firewall_manager._customization:191 iptables will be configured as firewall manager.
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/firewallManager=str:'iptables'
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:32:42 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.firewall.Plugin._configuration
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldServices=list:'[{'directory': 'aio', 'name': 'ovirt-aio'}]'
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:32:42 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.firewall.Plugin._configuration
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldSubst=dict:'{'@JBOSS_HTTP_PORT@': None, '@JBOSS_HTTPS_PORT@': None}'
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:32:42 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.config.firewall.Plugin._configuration
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldServices=list:'[{'directory': 'aio', 'name': 'ovirt-aio'}, {'directory': 'ovirt-common', 'name': 'ovirt-http'}, {'directory': 'ovirt-common', 'name': 'ovirt-https'}]'
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldSubst=dict:'{'@HTTPS_PORT@': 443, '@JBOSS_HTTP_PORT@': None, '@HTTP_PORT@': 80, '@JBOSS_HTTPS_PORT@': None}'
2014-10-20 14:32:42 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:32:42 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.base.network.hostname.Plugin._customization
2014-10-20 14:32:42 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_NETWORK_FQDN
2014-10-20 14:32:42 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Host fully qualified DNS name of this server [ex1.gecko.hs-heilbronn.de]: 
2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname hostname._validateFQDNresolvability:217 ex1.gecko.hs-heilbronn.de resolves to: set(['148.251.139.133'])
2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.executeRaw:785 execute: ['/usr/bin/dig', 'ex1.gecko.hs-heilbronn.de'], executable='None', cwd='None', env=None
2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.executeRaw:803 execute-result: ['/usr/bin/dig', 'ex1.gecko.hs-heilbronn.de'], rc=0
2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.execute:861 execute-output: ['/usr/bin/dig', 'ex1.gecko.hs-heilbronn.de'] stdout:

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> ex1.gecko.hs-heilbronn.de
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32788
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 1

;; QUESTION SECTION:
;ex1.gecko.hs-heilbronn.de.	IN	A

;; ANSWER SECTION:
ex1.gecko.hs-heilbronn.de. 3600	IN	A	148.251.139.133

;; AUTHORITY SECTION:
hs-heilbronn.de.	3600	IN	NS	dns1.belwue.de.
hs-heilbronn.de.	3600	IN	NS	deneb.dfn.de.
hs-heilbronn.de.	3600	IN	NS	dns3.belwue.de.
hs-heilbronn.de.	3600	IN	NS	dns1.rz.hs-heilbronn.de.

;; ADDITIONAL SECTION:
dns1.rz.hs-heilbronn.de. 241	IN	A	141.7.1.18

;; Query time: 20 msec
;; SERVER: 213.133.99.99#53(213.133.99.99)
;; WHEN: Mon Oct 20 14:32:46 2014
;; MSG SIZE  rcvd: 166


2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.execute:866 execute-output: ['/usr/bin/dig', 'ex1.gecko.hs-heilbronn.de'] stderr:


2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.executeRaw:785 execute: ['/usr/bin/dig', '-x', '148.251.139.133'], executable='None', cwd='None', env=None
2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.executeRaw:803 execute-result: ['/usr/bin/dig', '-x', '148.251.139.133'], rc=0
2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.execute:861 execute-output: ['/usr/bin/dig', '-x', '148.251.139.133'] stdout:

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -x 148.251.139.133
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3611
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 0

;; QUESTION SECTION:
;133.139.251.148.in-addr.arpa.	IN	PTR

;; ANSWER SECTION:
133.139.251.148.in-addr.arpa. 86400 IN	PTR	ex1.gecko.hs-heilbronn.de.

;; AUTHORITY SECTION:
139.251.148.in-addr.arpa. 48870	IN	NS	ns1.your-server.de.
139.251.148.in-addr.arpa. 48870	IN	NS	ns.second-ns.com.
139.251.148.in-addr.arpa. 48870	IN	NS	ns3.second-ns.de.

;; Query time: 11 msec
;; SERVER: 213.133.99.99#53(213.133.99.99)
;; WHEN: Mon Oct 20 14:32:46 2014
;; MSG SIZE  rcvd: 173


2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.execute:866 execute-output: ['/usr/bin/dig', '-x', '148.251.139.133'] stderr:


2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.executeRaw:785 execute: ('/sbin/ip', 'addr'), executable='None', cwd='None', env=None
2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.executeRaw:803 execute-result: ('/sbin/ip', 'addr'), rc=0
2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.execute:861 execute-output: ('/sbin/ip', 'addr') stdout:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 44:8a:5b:9b:a0:7d brd ff:ff:ff:ff:ff:ff
    inet 148.251.139.133 peer 148.251.139.129/32 brd 148.251.139.133 scope global eth0
    inet6 2a01:4f8:210:4384::2/64 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::468a:5bff:fe9b:a07d/64 scope link 
       valid_lft forever preferred_lft forever

2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname plugin.execute:866 execute-output: ('/sbin/ip', 'addr') stderr:


2014-10-20 14:32:46 DEBUG otopi.plugins.ovirt_engine_setup.base.network.hostname hostname._getNonLoopbackAddresses:165 addresses: [u'148.251.139.133']
2014-10-20 14:32:46 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:32:46 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/fqdn=str:'ex1.gecko.hs-heilbronn.de'
2014-10-20 14:32:46 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:32:46 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.protocols.Plugin._customization
2014-10-20 14:32:46 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:32:46 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ENGINE_CONFIG/fqdn=str:'ex1.gecko.hs-heilbronn.de'
2014-10-20 14:32:46 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:32:46 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._network_owners_config_customized
2014-10-20 14:32:46 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_network
2014-10-20 14:32:46 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_database
2014-10-20 14:32:46 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:32:46 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== DATABASE CONFIGURATION ==--
2014-10-20 14:32:46 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:32:46 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._customization_enable
2014-10-20 14:32:46 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:32:46 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._customization
2014-10-20 14:32:46 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_PROVISIONING_POSTGRES_LOCATION
2014-10-20 14:32:46 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Where is the Engine database located? (Local, Remote) [Local]: 
2014-10-20 14:32:48 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_PROVISIONING_POSTGRES_ENABLED
2014-10-20 14:32:48 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Setup can configure the local postgresql server automatically for the engine to run. This may conflict with existing applications.
2014-10-20 14:32:48 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Would you like Setup to automatically configure postgresql and create Engine database, or prefer to perform that manually? (Automatic, Manual) [Automatic]: 
2014-10-20 14:32:58 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:32:58 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/database=str:'engine'
2014-10-20 14:32:58 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/host=str:'localhost'
2014-10-20 14:32:58 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/password=str:'**FILTERED**'
2014-10-20 14:32:58 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/port=int:'5432'
2014-10-20 14:32:58 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/secured=bool:'False'
2014-10-20 14:32:58 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/securedHostValidation=bool:'False'
2014-10-20 14:32:58 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/user=str:'engine'
2014-10-20 14:32:58 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresProvisioningEnabled=bool:'True'
2014-10-20 14:32:58 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:32:58 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.connection.Plugin._customization_enable
2014-10-20 14:32:58 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.connection.Plugin._customization
2014-10-20 14:32:58 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select count(*) as count
                from pg_catalog.pg_tables
                where schemaname = 'public';
            ', args: {}
2014-10-20 14:32:58 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:169 Creating own connection
2014-10-20 14:32:58 DEBUG otopi.ovirt_engine_setup.engine_common.database database.getCredentials:816 database connection failed
Traceback (most recent call last):
  File "/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine_common/database.py", line 814, in getCredentials
    ] = self.isNewDatabase()
  File "/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine_common/database.py", line 351, in isNewDatabase
    transaction=False,
  File "/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine_common/database.py", line 178, in execute
    database=database,
  File "/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine_common/database.py", line 112, in connect
    sslmode=sslmode,
OperationalError: could not connect to server: Connection refused
	Is the server running on host "localhost" and accepting
	TCP/IP connections on port 5432?

2014-10-20 14:32:58 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._db_owners_connections_customized
2014-10-20 14:32:58 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_database
2014-10-20 14:32:58 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_engine
2014-10-20 14:32:58 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:32:58 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== OVIRT ENGINE CONFIGURATION ==--
2014-10-20 14:32:58 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:32:58 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._customization
2014-10-20 14:32:58 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_CONFIG_ADMIN_SETUP
2014-10-20 14:32:58 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Engine admin password: 
2014-10-20 14:33:07 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_CONFIG_ADMIN_SETUP
2014-10-20 14:33:07 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Confirm engine admin password: 
2014-10-20 14:33:08 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:33:08 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/adminPassword=str:'**FILTERED**'
2014-10-20 14:33:08 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:33:08 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.appmode.Plugin._customization_enable
2014-10-20 14:33:08 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.appmode.Plugin._customization
2014-10-20 14:33:08 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_CONFIG_APPLICATION_MODE
2014-10-20 14:33:08 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Application mode (Both, Virt, Gluster) [Both]: 
2014-10-20 14:35:16 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:RECEIVE    Virt
2014-10-20 14:35:16 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:35:16 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/applicationMode=str:'virt'
2014-10-20 14:35:16 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:35:16 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.domain_type.Plugin._customization
2014-10-20 14:35:16 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_engine
2014-10-20 14:35:16 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_pki
2014-10-20 14:35:16 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:35:16 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== PKI CONFIGURATION ==--
2014-10-20 14:35:16 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:35:16 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._customization_enable
2014-10-20 14:35:16 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._customization
2014-10-20 14:35:16 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_PKI_ORG
2014-10-20 14:35:16 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Organization name for certificate [gecko.hs-heilbronn.de]: 
2014-10-20 14:35:21 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:35:21 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PKI/organization=str:'gecko.hs-heilbronn.de'
2014-10-20 14:35:21 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:35:21 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_pki
2014-10-20 14:35:21 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_apache
2014-10-20 14:35:21 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:35:21 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== APACHE CONFIGURATION ==--
2014-10-20 14:35:21 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:35:21 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.root.Plugin._customization
2014-10-20 14:35:21 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Setup can configure the default page of the web server to present the application home page. This may conflict with existing applications.
2014-10-20 14:35:21 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_APACHE_CONFIG_ROOT_REDIRECTION
2014-10-20 14:35:21 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Do you wish to set the application as the default page of the web server? (Yes, No) [Yes]: 
2014-10-20 14:35:24 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:35:24 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configureRootRedirection=bool:'True'
2014-10-20 14:35:24 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:35:24 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._customization
2014-10-20 14:35:24 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Setup can configure apache to use SSL using a certificate issued from the internal CA.
2014-10-20 14:35:24 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_APACHE_CONFIG_SSL
2014-10-20 14:35:24 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Do you wish Setup to configure that, or prefer to perform that manually? (Automatic, Manual) [Automatic]: 
2014-10-20 14:36:19 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:36:19 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configureSsl=bool:'True'
2014-10-20 14:36:19 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:36:19 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_apache
2014-10-20 14:36:19 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_system
2014-10-20 14:36:19 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:36:19 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== SYSTEM CONFIGURATION ==--
2014-10-20 14:36:19 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:36:19 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._customization_firewall
2014-10-20 14:36:19 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:36:19 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldServices=list:'[{'directory': 'aio', 'name': 'ovirt-aio'}, {'directory': 'ovirt-common', 'name': 'ovirt-http'}, {'directory': 'ovirt-common', 'name': 'ovirt-https'}, {'directory': 'websocket-proxy', 'name': 'ovirt-websocket-proxy'}]'
2014-10-20 14:36:19 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldSubst=dict:'{'@WEBSOCKET_PROXY_PORT@': 6100, '@HTTPS_PORT@': 443, '@JBOSS_HTTP_PORT@': None, '@HTTP_PORT@': 80, '@JBOSS_HTTPS_PORT@': None}'
2014-10-20 14:36:19 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:36:19 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._customization_enable
2014-10-20 14:36:19 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._customization
2014-10-20 14:36:19 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query NFS_CONFIG_ENABLED
2014-10-20 14:36:19 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Configure an NFS share on this server to be used as an ISO Domain? (Yes, No) [Yes]: 
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:RECEIVE    no
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/nfsConfigEnabled=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.iso_domain.Plugin._customization
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.fence_kdump_listener.config.Plugin._customization_disable
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.fence_kdump_listener.config.Plugin._customization_firewall
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldServices=list:'[{'directory': 'aio', 'name': 'ovirt-aio'}, {'directory': 'ovirt-common', 'name': 'ovirt-http'}, {'directory': 'ovirt-common', 'name': 'ovirt-https'}, {'directory': 'websocket-proxy', 'name': 'ovirt-websocket-proxy'}, {'directory': 'ovirt-engine', 'name': 'ovirt-fence-kdump-listener'}]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_system
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_s_misc
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== MISC CONFIGURATION ==--
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.dialog.titles.Plugin._title_e_misc
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== END OF CONFIGURATION ==--
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._firewall
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.otopi.core.config.Plugin._customize2
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage customization METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._customization_firewall
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldServices=list:'[{'directory': 'aio', 'name': 'ovirt-aio'}, {'directory': 'ovirt-common', 'name': 'ovirt-http'}, {'directory': 'ovirt-common', 'name': 'ovirt-https'}, {'directory': 'websocket-proxy', 'name': 'ovirt-websocket-proxy'}, {'directory': 'ovirt-engine', 'name': 'ovirt-fence-kdump-listener'}, {'directory': 'ovirt-common', 'name': 'ovirt-postgres'}]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:40:36 INFO otopi.context context.runSequence:417 Stage: Setup validation
2014-10-20 14:40:36 DEBUG otopi.context context.runSequence:421 STAGE validation
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.otopi.core.misc.Plugin._validation
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/aborted=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/debug=int:'0'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/error=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/exceptionInfo=list:'[]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/executionDirectory=str:'/root'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/log=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/pluginGroups=str:'otopi:ovirt-engine-common:ovirt-engine-setup'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/pluginPath=str:'/usr/share/otopi/plugins:/usr/share/ovirt-engine/setup/bin/../plugins'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/suppressEnvironmentKeys=list:'[]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/chkconfig=str:'/sbin/chkconfig'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/chronyc=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/date=str:'/bin/date'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/dig=str:'/usr/bin/dig'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/exportfs=str:'/usr/sbin/exportfs'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/firewall-cmd=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/hwclock=str:'/sbin/hwclock'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/initctl=str:'/sbin/initctl'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/ip=str:'/sbin/ip'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/ntpq=str:'/usr/sbin/ntpq'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/pg_dump=str:'/usr/bin/pg_dump'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/pg_restore=str:'/usr/bin/pg_restore'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/postgresql-setup=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/psql=str:'/usr/bin/psql'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/rc=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/rc-update=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/reboot=str:'/sbin/reboot'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/restorecon=str:'/sbin/restorecon'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/rpm=str:'/bin/rpm'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/selinuxenabled=str:'/usr/sbin/selinuxenabled'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/semanage=str:'/usr/sbin/semanage'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/service=str:'/sbin/service'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/ssh-keygen=str:'/usr/bin/ssh-keygen'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/sshd=str:'/usr/sbin/sshd'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/sysctl=str:'/sbin/sysctl'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/systemctl=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/configFileAppend=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/configFileName=str:'/etc/ovirt-engine-setup.conf'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/failOnPrioOverride=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/internalPackageTransaction=Transaction:'transaction'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logDir=str:'/var/log/ovirt-engine/setup'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFileHandle=file:'<open file '/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log', mode 'a' at 0x213c5d0>'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFileName=str:'/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFileNamePrefix=str:'ovirt-engine-setup'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilter=_MyLoggerFilter:'filter'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilterKeys=list:'['OVESETUP_DB/password', 'OVESETUP_CONFIG/adminPassword', 'OVESETUP_PKI/storePassword', 'OVESETUP_CONFIG/remoteEngineHostRootPassword']'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logRemoveAtExit=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/mainTransaction=Transaction:'transaction'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/modifiedFiles=list:'[]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/randomizeEvents=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/boundary=str:'--=451b80dc-996f-432e-9e4f-2b29ef6d1141=--'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/cliVersion=int:'1'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/customization=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/dialect=str:'human'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV INFO/PACKAGE_NAME=str:'otopi'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV INFO/PACKAGE_VERSION=str:'1.3.0'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/firewalldAvailable=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/firewalldDisableServices=list:'[]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/firewalldEnable=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/iptablesEnable=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/iptablesRules=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/sshEnable=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/sshKey=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/sshUser=str:''
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/enableUpgrade=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/requireRollback=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/versionLockApply=list:'['ovirt-engine', 'ovirt-engine-backend', 'ovirt-engine-dbscripts', 'ovirt-engine-restapi', 'ovirt-engine-tools', 'ovirt-engine-userportal', 'ovirt-engine-webadmin-portal']'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/versionLockFilter=list:'['ovirt-engine']'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/configure=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/continueWithoutAIO=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/enable=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/localCluster=str:'local_cluster'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/localDataCenter=str:'local_datacenter'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/localHost=str:'local_host'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/sshdPort=int:'22'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/storageDomainDefaultDir=str:'/var/lib/images'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/storageDomainDir=str:'/var/lib/images'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/storageDomainName=str:'local_storage'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/supported=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/vdsmCpu=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configFileOvirtEngine=str:'/etc/httpd/conf.d/z-ovirt-engine-proxy.conf'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configFileOvirtRoot=str:'/etc/httpd/conf.d/ovirt-engine-root-redirect.conf'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configFileSsl=str:'/etc/httpd/conf.d/ssl.conf'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configureRootRedirection=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configureRootRedirectionDefault=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configureSsl=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configured=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/enable=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/httpdService=str:'httpd'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/needRestart=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ASYNC/clearTasks=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ASYNC/clearTasksWait=int:'20'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/addOvirtGlanceRepository=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/adminPassword=str:'**FILTERED**'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/applicationMode=str:'virt'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/firewallManager=str:'iptables'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/firewallManagers=list:'[<otopi.plugins.ovirt_engine_common.base.network.firewall_manager_firewalld._FirewalldManager object at 0x26be810>, <otopi.plugins.ovirt_engine_common.base.network.firewall_manager_human._HumanManager object at 0x26be850>, <otopi.plugins.ovirt_engine_common.base.network.firewall_manager_iptables._IpTablesManager object at 0x26be790>]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/fqdn=str:'ex1.gecko.hs-heilbronn.de'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/fqdnNonLoopback=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/fqdnReverseValidation=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/httpPort=int:'80'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/httpsPort=int:'443'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainACL=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainDefaultMountPoint=str:'/var/lib/exports/iso'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainExists=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainMountPoint=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainName=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainSdUuid=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainStorageDir=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/javaHome=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossAjpPort=int:'8702'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossDebugAddress=str:'127.0.0.1:8787'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossDirectHttpPort=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossDirectHttpsPort=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossHome=str:'/usr/share/ovirt-engine-jboss-as'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossHttpPort=int:'8080'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossHttpsPort=int:'8443'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossNeeded=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/keySize=int:'2048'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/macRangePool=str:'00:1a:4a:e2:37:00-00:1a:4a:e2:37:ff'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/publicHttpPort=int:'80'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/publicHttpsPort=int:'443'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineCer=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineHostClientKey=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineHostKnownHosts=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineHostRootPassword=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineHostSshPort=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineSetupStyle=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineSetupStyles=list:'[<otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine_root_ssh._RootSshManager object at 0x26be0d0>, <otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine_manual_files._ManualFiles object at 0x26be8d0>]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/storageIsLocal=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/storageType=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/updateFirewall=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/validFirewallManagers=str:''
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/websocketProxyConfig=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/websocketProxyHost=str:'localhost'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/websocketProxyPort=int:'6100'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/wspCertificateChain=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/action=str:'setup'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/answerFile=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/developerMode=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/engineStop=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/generatePostInstall=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/generatedByVersion=str:'3.5.0.1'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/offlinePackager=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/originalGeneratedByVersion=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/registerUninstallGroups=RegisterGroups:'<otopi.plugins.ovirt_engine_common.base.core.uninstall.RegisterGroups object at 0x17e2390>'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/remoteEngine=RemoteEngine:'<ovirt_engine_setup.remote_engine.RemoteEngine object at 0x26be890>'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/setupAttributesModules=list:'[<module 'ovirt_engine_setup.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/constants.pyc'>, <module 'ovirt_engine_setup.engine.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine/constants.pyc'>, <module 'ovirt_engine_setup.engine_common.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine_common/constants.pyc'>, <module 'ovirt_engine_setup.websocket_proxy.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/websocket_proxy/constants.pyc'>]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/uninstallUnremovableFiles=list:'['/etc/exports']'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/upgradeSupportedVersions=str:'3.0,3.1,3.2,3.3,3.4,3.5'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/connection=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/database=str:'engine'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/fixDbViolations=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/host=str:'localhost'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/newDatabase=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/password=str:'**FILTERED**'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/pgPassFile=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/port=int:'5432'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/secured=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/securedHostValidation=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/statement=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/user=str:'engine'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DIALOG/confirmSettings=NoneType:'None'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ENGINE_CONFIG/fqdn=str:'ex1.gecko.hs-heilbronn.de'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ENGINE_CORE/enable=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldServices=list:'[{'directory': 'aio', 'name': 'ovirt-aio'}, {'directory': 'ovirt-common', 'name': 'ovirt-http'}, {'directory': 'ovirt-common', 'name': 'ovirt-https'}, {'directory': 'websocket-proxy', 'name': 'ovirt-websocket-proxy'}, {'directory': 'ovirt-engine', 'name': 'ovirt-fence-kdump-listener'}, {'directory': 'ovirt-common', 'name': 'ovirt-postgres'}]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldSubst=dict:'{'@WEBSOCKET_PROXY_PORT@': 6100, '@HTTPS_PORT@': 443, '@JBOSS_HTTP_PORT@': None, '@HTTP_PORT@': 80, '@JBOSS_HTTPS_PORT@': None}'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PKI/country=str:'US'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PKI/organization=str:'gecko.hs-heilbronn.de'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PKI/storePassword=str:'**FILTERED**'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresConf=str:'/var/lib/pgsql/data/postgresql.conf'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresListenAddress=str:''*''
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresMaxConn=int:'150'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresPgHba=str:'/var/lib/pgsql/data/pg_hba.conf'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresPgVersion=str:'/var/lib/pgsql/data/PG_VERSION'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresProvisioningEnabled=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresService=str:'postgresql'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/enginePackages=str:'ovirt-engine'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/engineSetupPackages=str:'ovirt-engine-setup'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/packagesSetup=list:'['ovirt-engine-setup']'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/packagesUpgradeList=list:'[{'packages': ['ovirt-engine'], 'group': 'ovirt-engine-3.4'}]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/upgradeYumGroup=str:'ovirt-engine-3.4'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/groupEngine=str:'ovirt'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/groupKvm=str:'kvm'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/hostileServices=str:'ovirt-engine-dwhd,ovirt-engine-notifier'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckEnabled=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckMinimumMB=int:'4096'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckRecommendedMB=int:'16384'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckThreshold=int:'90'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/nfsConfigEnabled=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/nfsConfigEnabled_legacyInPostInstall=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/nfsServiceName=str:'nfs'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/selinuxContexts=list:'[{'pattern': '/var/lib/images(/.*)?', 'type': 'public_content_rw_t'}]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/selinuxRestorePaths=list:'['/var/lib/images']'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/shmmax=int:'68719476736'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userApache=str:'apache'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userEngine=str:'ovirt'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userPostgres=str:'postgres'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userRoot=str:'root'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userVdsm=str:'vdsm'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/keepAliveInterval=int:'30'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumDisabledPlugins=list:'[]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumEnabledPlugins=list:'[]'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumExpireCache=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumRollback=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumpackagerEnabled=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/clockMaxGap=int:'5'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/clockSet=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/commandPath=str:'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/reboot=bool:'False'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/rebootAllow=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/rebootDeferTime=int:'10'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._validation_enable
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux.Plugin._validation_enable
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.asynctasks.Plugin._validateEnv
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux.Plugin._validation_enable
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._validate_enable
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._validation
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/iptablesEnable=bool:'True'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/iptablesRules=str:'# Generated by ovirt-engine installer
#filtering rules
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5900:6923 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 49152:49216 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 7410 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 6100 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

#drop all rule
-A INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-aio=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
    <short>ovirt-aio</short>
    <description>oVirt configured aio service</description>
    <port protocol="tcp" port="5900-6923"/>
    <port protocol="tcp" port="49152-49216"/>
</service>
'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-fence-kdump-listener=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>ovirt-fence-kdump-listener</short>
  <description>oVirt configured fence_kdump listener service</description>
  <port protocol="udp" port="7410"/>
</service>
'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-http=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>ovirt-http</short>
  <description>oVirt configured http service</description>
  <port protocol="tcp" port="80"/>
</service>
'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-https=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>ovirt-https</short>
  <description>oVirt configured https service</description>
  <port protocol="tcp" port="443"/>
</service>
'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-postgres=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>ovirt-postgres</short>
  <description>oVirt configured postgres service</description>
  <port protocol="tcp" port="5432"/>
</service>
'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-websocket-proxy=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>ovirt-websocket-proxy</short>
  <description>oVirt configured WebSocket Proxy service</description>
  <port protocol="tcp" port="6100"/>
</service>
'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/uninstallUnremovableFiles=list:'['/etc/exports', '/etc/sysconfig/iptables']'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.otopi.network.firewalld.Plugin._validation
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.otopi.network.hostname.Plugin._validation
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.network.hostname hostname._validation:73 my name: ex1.gecko.hs-heilbronn.de
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.network.hostname plugin.executeRaw:785 execute: ('/sbin/ip', 'addr', 'show'), executable='None', cwd='None', env=None
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.network.hostname plugin.executeRaw:803 execute-result: ('/sbin/ip', 'addr', 'show'), rc=0
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.network.hostname plugin.execute:861 execute-output: ('/sbin/ip', 'addr', 'show') stdout:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 44:8a:5b:9b:a0:7d brd ff:ff:ff:ff:ff:ff
    inet 148.251.139.133 peer 148.251.139.129/32 brd 148.251.139.133 scope global eth0
    inet6 2a01:4f8:210:4384::2/64 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::468a:5bff:fe9b:a07d/64 scope link 
       valid_lft forever preferred_lft forever

2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.network.hostname plugin.execute:866 execute-output: ('/sbin/ip', 'addr', 'show') stderr:


2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.network.hostname hostname._validation:110 my addresses: ['2a01:4f8:210:4384::2', '2a01:4f8:210:4384::2', '2a01:4f8:210:4384::2', '148.251.139.133', '148.251.139.133', '148.251.139.133']
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.network.hostname hostname._validation:111 local addresses: [u'2a01:4f8:210:4384::2', u'fe80::468a:5bff:fe9b:a07d']
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.otopi.network.iptables.Plugin._validate
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.otopi.network.ssh.Plugin._validation
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.core.engine.Plugin._validation
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service ovirt-engine exists
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-engine'), executable='None', cwd='None', env=None
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-engine'), rc=1
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stdout:


2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stderr:
initctl: Unknown job: ovirt-engine

2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service ovirt-engine exists True upstart=False
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel rhel.status:138 check service ovirt-engine status
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-engine'), executable='None', cwd='None', env=None
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-engine'), rc=1
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stdout:


2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stderr:
initctl: Unknown job: ovirt-engine

2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'ovirt-engine', 'status'), executable='None', cwd='None', env=None
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'ovirt-engine', 'status'), rc=3
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'ovirt-engine', 'status') stdout:
ovirt-engine is stopped

2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'ovirt-engine', 'status') stderr:


2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel rhel.status:147 service ovirt-engine status False
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.pgpass.Plugin._validation
2014-10-20 14:40:36 DEBUG otopi.plugins.ovirt_engine_common.ovirt_engine.db.pgpass plugin.executeRaw:785 execute: ('/usr/bin/psql', '-V'), executable='None', cwd='None', env=None
2014-10-20 14:40:36 DEBUG otopi.plugins.ovirt_engine_common.ovirt_engine.db.pgpass plugin.executeRaw:803 execute-result: ('/usr/bin/psql', '-V'), rc=0
2014-10-20 14:40:36 DEBUG otopi.plugins.ovirt_engine_common.ovirt_engine.db.pgpass plugin.execute:861 execute-output: ('/usr/bin/psql', '-V') stdout:
psql (PostgreSQL) 8.4.20
contains support for command-line editing

2014-10-20 14:40:36 DEBUG otopi.plugins.ovirt_engine_common.ovirt_engine.db.pgpass plugin.execute:866 execute-output: ('/usr/bin/psql', '-V') stderr:


2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/pgPassFile=str:'/tmp/tmpQPzfwa'
2014-10-20 14:40:36 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:40:36 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.cpu.Plugin._validation
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel rhel.status:138 check service libvirtd status
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'libvirtd'), executable='None', cwd='None', env=None
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'libvirtd'), rc=1
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'libvirtd') stdout:


2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'libvirtd') stderr:
initctl: Unknown job: libvirtd

2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'libvirtd', 'status'), executable='None', cwd='None', env=None
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'libvirtd', 'status'), rc=3
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'libvirtd', 'status') stdout:
libvirtd is stopped

2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'libvirtd', 'status') stderr:


2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel rhel.status:147 service libvirtd status False
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 starting service libvirtd
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'libvirtd'), executable='None', cwd='None', env=None
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'libvirtd'), rc=1
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'libvirtd') stdout:


2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'libvirtd') stderr:
initctl: Unknown job: libvirtd

2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'libvirtd', 'start'), executable='None', cwd='None', env=None
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'libvirtd', 'start'), rc=0
2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'libvirtd', 'start') stdout:
Starting libvirtd daemon: [  OK  ]

2014-10-20 14:40:36 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'libvirtd', 'start') stderr:


2014-10-20 14:40:36 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.cpu cpu._getCompatibleCpuModels:80 Attempting to load the caps vdsm module
2014-10-20 14:40:37 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.cpu cpu._validation:131 Compatible CPU models are: [u'model_Haswell', u'model_Nehalem', u'model_Conroe', u'model_coreduo', u'model_core2duo', u'model_Penryn', u'model_Westmere', u'model_n270', u'model_SandyBridge']
2014-10-20 14:40:37 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 stopping service libvirtd
2014-10-20 14:40:37 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'libvirtd'), executable='None', cwd='None', env=None
2014-10-20 14:40:37 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'libvirtd'), rc=1
2014-10-20 14:40:37 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'libvirtd') stdout:


2014-10-20 14:40:37 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'libvirtd') stderr:
initctl: Unknown job: libvirtd

2014-10-20 14:40:37 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'libvirtd', 'stop'), executable='None', cwd='None', env=None
2014-10-20 14:40:37 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'libvirtd', 'stop'), rc=0
2014-10-20 14:40:37 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'libvirtd', 'stop') stdout:
Stopping libvirtd daemon: [  OK  ]

2014-10-20 14:40:37 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'libvirtd', 'stop') stderr:


2014-10-20 14:40:37 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:40:37 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/vdsmCpu=str:'Intel Haswell Family'
2014-10-20 14:40:37 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:40:37 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._validation
2014-10-20 14:40:37 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm.Plugin._validation
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._validation_enable
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.schema.Plugin._validation
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._validation
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service postgresql exists
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'postgresql'), executable='None', cwd='None', env=None
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'postgresql'), rc=1
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'postgresql') stdout:


2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'postgresql') stderr:
initctl: Unknown job: postgresql

2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service postgresql exists True upstart=False
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._validation
2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs exportfs._validation:166 move=False, generate=False
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.memcheck.Plugin._validateMemory
2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.system.memcheck memcheck._validateMemory:127 Checking total memory
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.memcheck.Plugin._validateContinueLowMemory
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux.Plugin._validation
2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux plugin.executeRaw:785 execute: ('/usr/sbin/selinuxenabled',), executable='None', cwd='None', env=None
2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux plugin.executeRaw:803 execute-result: ('/usr/sbin/selinuxenabled',), rc=1
2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux plugin.execute:861 execute-output: ('/usr/sbin/selinuxenabled',) stdout:


2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux plugin.execute:866 execute-output: ('/usr/sbin/selinuxenabled',) stderr:


2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.asynctasks.Plugin._validateZombies
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux.Plugin._validation
2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux plugin.executeRaw:785 execute: ('/usr/sbin/selinuxenabled',), executable='None', cwd='None', env=None
2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux plugin.executeRaw:803 execute-result: ('/usr/sbin/selinuxenabled',), rc=1
2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux plugin.execute:861 execute-output: ('/usr/sbin/selinuxenabled',) stdout:


2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux plugin.execute:866 execute-output: ('/usr/sbin/selinuxenabled',) stderr:


2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._validate_ssl
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.config.java.Plugin._validation
2014-10-20 14:40:38 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:40:38 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/javaHome=unicode:'/usr/lib/jvm/jre'
2014-10-20 14:40:38 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl.Plugin._validation
2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.executeRaw:785 execute: ('/sbin/sysctl', '-n', 'kernel.shmmax'), executable='None', cwd='None', env=None
2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.executeRaw:803 execute-result: ('/sbin/sysctl', '-n', 'kernel.shmmax'), rc=0
2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.execute:861 execute-output: ('/sbin/sysctl', '-n', 'kernel.shmmax') stdout:
33554432

2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.execute:866 execute-output: ('/sbin/sysctl', '-n', 'kernel.shmmax') stderr:


2014-10-20 14:40:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl sysctl._validation:81 sysctl shared memory is 33554432 lower than 68719476736
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.pki.Plugin._validate
2014-10-20 14:40:38 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.base.dialog.preview.Plugin._customization
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== CONFIGURATION PREVIEW ==--
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Application mode                        : virt
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Datacenter storage type                 : False
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Firewall manager                        : iptables
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Update Firewall                         : True
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Host FQDN                               : ex1.gecko.hs-heilbronn.de
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Engine database name                    : engine
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Engine database secured connection      : False
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Engine database host                    : localhost
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Engine database user name               : engine
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Engine database host name validation    : False
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Engine database port                    : 5432
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Engine installation                     : True
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 PKI organization                        : gecko.hs-heilbronn.de
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Configure VDSM on this host             : True
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Local storage domain directory          : /var/lib/images
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Configure local Engine database         : True
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Set application as default page         : True
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Configure Apache SSL                    : True
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Configure WebSocket Proxy               : True
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human human.queryString:153 query OVESETUP_DIALOG_CONFIRM_SETTINGS
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:40:38 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Please confirm installation settings (OK, Cancel) [OK]: 
2014-10-20 14:40:57 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:40:57 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DIALOG/confirmSettings=bool:'True'
2014-10-20 14:40:57 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.asynctasks.Plugin._validateAsyncTasks
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:138 Stage validation METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.dbvalidations.Plugin._validation
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:57 INFO otopi.context context.runSequence:417 Stage: Transaction setup
2014-10-20 14:40:57 DEBUG otopi.context context.runSequence:421 STAGE transaction-prepare
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:138 Stage transaction-prepare METHOD otopi.plugins.otopi.core.transaction.Plugin._main_prepare
2014-10-20 14:40:57 DEBUG otopi.transaction transaction._prepare:77 preparing 'Yum Transaction'
Loaded plugins: fastestmirror, versionlock
2014-10-20 14:40:57 DEBUG otopi.transaction transaction._prepare:77 preparing 'Database Transaction'
2014-10-20 14:40:57 DEBUG otopi.transaction transaction._prepare:77 preparing 'Version Lock Transaction'
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:138 Stage transaction-prepare METHOD otopi.plugins.ovirt_engine_common.base.system.hostile_services.Plugin._transaction_begin
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service ovirt-engine-dwhd exists
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-engine-dwhd'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-engine-dwhd'), rc=1
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine-dwhd') stdout:


2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine-dwhd') stderr:
initctl: Unknown job: ovirt-engine-dwhd

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service ovirt-engine-dwhd exists False upstart=False
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service ovirt-engine-notifier exists
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-engine-notifier'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-engine-notifier'), rc=1
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine-notifier') stdout:


2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine-notifier') stderr:
initctl: Unknown job: ovirt-engine-notifier

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service ovirt-engine-notifier exists True upstart=False
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.status:138 check service ovirt-engine-notifier status
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-engine-notifier'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-engine-notifier'), rc=1
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine-notifier') stdout:


2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine-notifier') stderr:
initctl: Unknown job: ovirt-engine-notifier

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'ovirt-engine-notifier', 'status'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'ovirt-engine-notifier', 'status'), rc=3
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'ovirt-engine-notifier', 'status') stdout:
ovirt-engine-notifier is stopped

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'ovirt-engine-notifier', 'status') stderr:


2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.status:147 service ovirt-engine-notifier status False
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:138 Stage transaction-prepare METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.core.engine.Plugin._transactionBegin
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service ovirt-engine exists
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-engine'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-engine'), rc=1
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stdout:


2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stderr:
initctl: Unknown job: ovirt-engine

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service ovirt-engine exists True upstart=False
2014-10-20 14:40:57 INFO otopi.plugins.ovirt_engine_common.ovirt_engine.core.engine engine._transactionBegin:93 Stopping engine service
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 stopping service ovirt-engine
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-engine'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-engine'), rc=1
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stdout:


2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stderr:
initctl: Unknown job: ovirt-engine

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'ovirt-engine', 'stop'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'ovirt-engine', 'stop'), rc=0
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'ovirt-engine', 'stop') stdout:
Stopping oVirt Engine: [FAILED]

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'ovirt-engine', 'stop') stderr:


2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:138 Stage transaction-prepare METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.core.fence_kdump_listener.Plugin._transactionBegin
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service ovirt-fence-kdump-listener exists
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener'), rc=1
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener') stdout:


2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener') stderr:
initctl: Unknown job: ovirt-fence-kdump-listener

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service ovirt-fence-kdump-listener exists True upstart=False
2014-10-20 14:40:57 INFO otopi.plugins.ovirt_engine_common.ovirt_engine.core.fence_kdump_listener fence_kdump_listener._transactionBegin:51 Stopping ovirt-fence-kdump-listener service
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 stopping service ovirt-fence-kdump-listener
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener'), rc=1
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener') stdout:


2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener') stderr:
initctl: Unknown job: ovirt-fence-kdump-listener

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'ovirt-fence-kdump-listener', 'stop'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'ovirt-fence-kdump-listener', 'stop'), rc=0
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'ovirt-fence-kdump-listener', 'stop') stdout:
Stopping oVirt fence_kdump listener: [FAILED]

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'ovirt-fence-kdump-listener', 'stop') stderr:


2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:138 Stage transaction-prepare METHOD otopi.plugins.ovirt_engine_common.websocket_proxy.core.Plugin._transactionBegin
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service ovirt-websocket-proxy exists
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), rc=1
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stdout:


2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stderr:
initctl: Unknown job: ovirt-websocket-proxy

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service ovirt-websocket-proxy exists True upstart=False
2014-10-20 14:40:57 INFO otopi.plugins.ovirt_engine_common.websocket_proxy.core core._transactionBegin:51 Stopping websocket-proxy service
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 stopping service ovirt-websocket-proxy
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), rc=1
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stdout:


2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stderr:
initctl: Unknown job: ovirt-websocket-proxy

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'ovirt-websocket-proxy', 'stop'), executable='None', cwd='None', env=None
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'ovirt-websocket-proxy', 'stop'), rc=0
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'ovirt-websocket-proxy', 'stop') stdout:
Stopping oVirt Engine websockets proxy: [FAILED]

2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'ovirt-websocket-proxy', 'stop') stderr:


2014-10-20 14:40:57 INFO otopi.context context.runSequence:417 Stage: Misc configuration
2014-10-20 14:40:57 DEBUG otopi.context context.runSequence:421 STAGE early_misc
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:138 Stage early_misc METHOD otopi.plugins.otopi.network.firewalld.Plugin._early_misc
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:138 Stage early_misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.dbvalidations.Plugin._misc
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:40:57 INFO otopi.context context.runSequence:417 Stage: Package installation
2014-10-20 14:40:57 DEBUG otopi.context context.runSequence:421 STAGE packages
2014-10-20 14:40:57 DEBUG otopi.context context._executeMethod:138 Stage packages METHOD otopi.plugins.otopi.network.iptables.Plugin._packages
2014-10-20 14:40:57 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum queue package iptables for install
Loading mirror speeds from cached hostfile
 * base: mirror.checkdomain.de
 * extras: mirror.checkdomain.de
 * ovirt-3.5: ftp.nluug.nl
 * ovirt-3.5-epel: mirrors.n-ix.net
 * ovirt-3.5-jpackage-6.0-generic: sunsite.informatik.rwth-aachen.de
 * updates: mirror.checkdomain.de
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:138 Stage packages METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages.Plugin.packages
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:138 Stage packages METHOD otopi.plugins.otopi.packagers.yumpackager.Plugin._packages
2014-10-20 14:41:04 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Building transaction
2014-10-20 14:41:04 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Empty transaction
2014-10-20 14:41:04 DEBUG otopi.plugins.otopi.packagers.yumpackager yumpackager.verbose:88 Yum Transaction Summary:
2014-10-20 14:41:04 INFO otopi.context context.runSequence:417 Stage: Misc configuration
2014-10-20 14:41:04 DEBUG otopi.context context.runSequence:421 STAGE misc
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.config.jboss.Plugin._jboss
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.otopi.system.command.Plugin._misc
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl.Plugin._misc
2014-10-20 14:41:04 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/sysctl.d/ovirt-postgresql.conf''
2014-10-20 14:41:04 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/sysctl.d/ovirt-postgresql.conf' missing
2014-10-20 14:41:04 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.executeRaw:785 execute: ('/sbin/sysctl', '-p', '/etc/sysctl.d/ovirt-postgresql.conf.uPcIn0.tmp'), executable='None', cwd='None', env=None
2014-10-20 14:41:04 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.executeRaw:803 execute-result: ('/sbin/sysctl', '-p', '/etc/sysctl.d/ovirt-postgresql.conf.uPcIn0.tmp'), rc=0
2014-10-20 14:41:04 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.execute:861 execute-output: ('/sbin/sysctl', '-p', '/etc/sysctl.d/ovirt-postgresql.conf.uPcIn0.tmp') stdout:
kernel.shmmax = 68719476736

2014-10-20 14:41:04 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.execute:866 execute-output: ('/sbin/sysctl', '-p', '/etc/sysctl.d/ovirt-postgresql.conf.uPcIn0.tmp') stderr:


2014-10-20 14:41:04 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.executeRaw:785 execute: ('/sbin/sysctl', '-n', 'kernel.shmmax'), executable='None', cwd='None', env=None
2014-10-20 14:41:04 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.executeRaw:803 execute-result: ('/sbin/sysctl', '-n', 'kernel.shmmax'), rc=0
2014-10-20 14:41:04 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.execute:861 execute-output: ('/sbin/sysctl', '-n', 'kernel.shmmax') stdout:
68719476736

2014-10-20 14:41:04 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.system.sysctl plugin.execute:866 execute-output: ('/sbin/sysctl', '-n', 'kernel.shmmax') stderr:


2014-10-20 14:41:04 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:41:04 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/uninstallUnremovableFiles=list:'['/etc/exports', '/etc/sysconfig/iptables', '/etc/sysctl.d/ovirt-postgresql.conf']'
2014-10-20 14:41:04 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.otopi.network.firewalld.Plugin._misc
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.otopi.network.iptables.Plugin._store_iptables
2014-10-20 14:41:04 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/sysconfig/iptables''
2014-10-20 14:41:04 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/sysconfig/iptables' missing
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.otopi.network.ssh.Plugin._append_key
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.otopi.system.clock.Plugin._set_clock
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:41:04 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._misc
2014-10-20 14:41:04 INFO otopi.ovirt_engine_setup.engine_common.postgres postgres._initDbIfRequired:235 Initializing PostgreSQL
2014-10-20 14:41:04 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres plugin.executeRaw:785 execute: ('/etc/init.d/postgresql', 'initdb'), executable='None', cwd='None', env=None
2014-10-20 14:41:08 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres plugin.executeRaw:803 execute-result: ('/etc/init.d/postgresql', 'initdb'), rc=0
2014-10-20 14:41:08 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres plugin.execute:861 execute-output: ('/etc/init.d/postgresql', 'initdb') stdout:
Initializing database: [  OK  ]

2014-10-20 14:41:08 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres plugin.execute:866 execute-output: ('/etc/init.d/postgresql', 'initdb') stderr:


2014-10-20 14:41:08 INFO otopi.ovirt_engine_setup.engine_common.postgres postgres.provision:507 Creating PostgreSQL 'engine' database
2014-10-20 14:41:08 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/var/lib/pgsql/data/pg_hba.conf''
2014-10-20 14:41:08 DEBUG otopi.filetransaction filetransaction.prepare:196 file '/var/lib/pgsql/data/pg_hba.conf' exists
2014-10-20 14:41:08 DEBUG otopi.filetransaction filetransaction.prepare:200 file '/var/lib/pgsql/data/pg_hba.conf' already has content
2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 stopping service postgresql
2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'postgresql'), executable='None', cwd='None', env=None
2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'postgresql'), rc=1
2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'postgresql') stdout:


2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'postgresql') stderr:
initctl: Unknown job: postgresql

2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'postgresql', 'stop'), executable='None', cwd='None', env=None
2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'postgresql', 'stop'), rc=0
2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'postgresql', 'stop') stdout:
Stopping postgresql service: [  OK  ]

2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'postgresql', 'stop') stderr:


2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 starting service postgresql
2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'postgresql'), executable='None', cwd='None', env=None
2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'postgresql'), rc=1
2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'postgresql') stdout:


2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'postgresql') stderr:
initctl: Unknown job: postgresql

2014-10-20 14:41:08 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'postgresql', 'start'), executable='None', cwd='None', env=None
2014-10-20 14:41:10 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'postgresql', 'start'), rc=0
2014-10-20 14:41:10 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'postgresql', 'start') stdout:
Starting postgresql service: [  OK  ]

2014-10-20 14:41:10 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'postgresql', 'start') stderr:


2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.postgres postgres._waitForDatabase:430 Attempting to connect database
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select 1
                ', args: {}
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:169 Creating own connection
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'?column?': 1}]
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.tryDatabaseConnect:315 Connection succeeded
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select count(*) as count
                from pg_database
                where datname = %(database)s
            ', args: {'database': 'engine'}
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:169 Creating own connection
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 0L}]
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select count(*) as count
                from pg_user
                where usename = %(user)s
            ', args: {'user': 'engine'}
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:169 Creating own connection
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 0L}]
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    create role engine
                    with
                        login
                        encrypted password %(password)s
                ', args: {'password': '**FILTERED**'}
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:169 Creating own connection
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    create database engine
                    owner  engine
                    
                    template template0
                    encoding 'UTF8'
                    lc_collate 'en_US.UTF-8'
                    lc_ctype 'en_US.UTF-8'
                
                ', args: {'password': '**FILTERED**'}
2014-10-20 14:41:10 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:169 Creating own connection
2014-10-20 14:41:15 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:41:15 DEBUG otopi.transaction transaction.abort:131 aborting 'File transaction for '/var/lib/pgsql/data/pg_hba.conf''
2014-10-20 14:41:15 INFO otopi.ovirt_engine_setup.engine_common.postgres postgres.provision:551 Configuring PostgreSQL
2014-10-20 14:41:15 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/var/lib/pgsql/data/postgresql.conf''
2014-10-20 14:41:15 DEBUG otopi.filetransaction filetransaction.prepare:196 file '/var/lib/pgsql/data/postgresql.conf' exists
2014-10-20 14:41:15 DEBUG otopi.filetransaction filetransaction.prepare:230 backup '/var/lib/pgsql/data/postgresql.conf'->'/var/lib/pgsql/data/postgresql.conf.20141020144115'
2014-10-20 14:41:15 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/var/lib/pgsql/data/pg_hba.conf''
2014-10-20 14:41:15 DEBUG otopi.filetransaction filetransaction.prepare:196 file '/var/lib/pgsql/data/pg_hba.conf' exists
2014-10-20 14:41:15 DEBUG otopi.filetransaction filetransaction.prepare:230 backup '/var/lib/pgsql/data/pg_hba.conf'->'/var/lib/pgsql/data/pg_hba.conf.20141020144115'
2014-10-20 14:41:15 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/var/lib/pgsql/data/pg_hba.conf''
2014-10-20 14:41:15 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /var/lib/pgsql/data/pg_hba.conf
2014-10-20 14:41:15 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:41:15 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/var/lib/pgsql/data/postgresql.conf''
2014-10-20 14:41:15 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /var/lib/pgsql/data/postgresql.conf
2014-10-20 14:41:15 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel rhel.startup:151 set service postgresql startup to True
2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'postgresql'), executable='None', cwd='None', env=None
2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'postgresql'), rc=1
2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'postgresql') stdout:


2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'postgresql') stderr:
initctl: Unknown job: postgresql

2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/chkconfig', 'postgresql', 'on'), executable='None', cwd='None', env=None
2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/chkconfig', 'postgresql', 'on'), rc=0
2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/chkconfig', 'postgresql', 'on') stdout:


2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/chkconfig', 'postgresql', 'on') stderr:


2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 stopping service postgresql
2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'postgresql'), executable='None', cwd='None', env=None
2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'postgresql'), rc=1
2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'postgresql') stdout:


2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'postgresql') stderr:
initctl: Unknown job: postgresql

2014-10-20 14:41:15 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'postgresql', 'stop'), executable='None', cwd='None', env=None
2014-10-20 14:41:16 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'postgresql', 'stop'), rc=0
2014-10-20 14:41:16 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'postgresql', 'stop') stdout:
Stopping postgresql service: [  OK  ]

2014-10-20 14:41:16 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'postgresql', 'stop') stderr:


2014-10-20 14:41:16 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 starting service postgresql
2014-10-20 14:41:16 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'postgresql'), executable='None', cwd='None', env=None
2014-10-20 14:41:16 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'postgresql'), rc=1
2014-10-20 14:41:16 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'postgresql') stdout:


2014-10-20 14:41:16 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'postgresql') stderr:
initctl: Unknown job: postgresql

2014-10-20 14:41:16 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'postgresql', 'start'), executable='None', cwd='None', env=None
2014-10-20 14:41:18 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'postgresql', 'start'), rc=0
2014-10-20 14:41:18 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'postgresql', 'start') stdout:
Starting postgresql service: [  OK  ]

2014-10-20 14:41:18 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'postgresql', 'start') stderr:


2014-10-20 14:41:18 DEBUG otopi.ovirt_engine_setup.engine_common.postgres postgres._waitForDatabase:430 Attempting to connect database
2014-10-20 14:41:18 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select 1
                ', args: {}
2014-10-20 14:41:18 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:169 Creating own connection
2014-10-20 14:41:18 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'?column?': 1}]
2014-10-20 14:41:18 DEBUG otopi.ovirt_engine_setup.engine_common.database database.tryDatabaseConnect:315 Connection succeeded
2014-10-20 14:41:18 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:41:18 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/modifiedFiles=list:'['/var/lib/pgsql/data/pg_hba.conf', '/var/lib/pgsql/data/postgresql.conf']'
2014-10-20 14:41:18 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/uninstallUnremovableFiles=list:'['/etc/exports', '/etc/sysconfig/iptables', '/etc/sysctl.d/ovirt-postgresql.conf', '/var/lib/pgsql/data/postgresql.conf', '/var/lib/pgsql/data/pg_hba.conf']'
2014-10-20 14:41:18 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_common.ovirt_engine.db.pgpass.Plugin._misc
2014-10-20 14:41:18 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:41:18 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/pgPassFile=str:'/tmp/tmplSY6K_'
2014-10-20 14:41:18 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._prepare_examples
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-aio.xml''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/firewalld/ovirt-aio.xml' missing
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-http.xml''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/firewalld/ovirt-http.xml' missing
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-https.xml''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/firewalld/ovirt-https.xml' missing
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-websocket-proxy.xml''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/firewalld/ovirt-websocket-proxy.xml' missing
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-fence-kdump-listener.xml''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/firewalld/ovirt-fence-kdump-listener.xml' missing
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-postgres.xml''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/firewalld/ovirt-postgres.xml' missing
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/iptables.example''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/iptables.example' missing
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.core.Plugin._misc
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine-setup.conf.d/20-setup-aio.conf''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine-setup.conf.d/20-setup-aio.conf' missing
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.storage.Plugin._misc
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/var/lib/images/.keep''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/var/lib/images/.keep' missing
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm.Plugin._misc
2014-10-20 14:41:18 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:41:18 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/needRestart=bool:'True'
2014-10-20 14:41:18 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.engine.Plugin._misc
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/httpd/conf.d/z-ovirt-engine-proxy.conf''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/httpd/conf.d/z-ovirt-engine-proxy.conf' missing
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.apache.root.Plugin._misc
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/httpd/conf.d/ovirt-engine-root-redirect.conf''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/httpd/conf.d/ovirt-engine-root-redirect.conf' missing
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.database.Plugin._misc
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/engine.conf.d/10-setup-database.conf''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/engine.conf.d/10-setup-database.conf' missing
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.jboss.Plugin._misc
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/engine.conf.d/10-setup-jboss.conf''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/engine.conf.d/10-setup-jboss.conf' missing
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/notifier/notifier.conf.d/10-setup-jboss.conf''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/notifier/notifier.conf.d/10-setup-jboss.conf' missing
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.protocols.Plugin._misc
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/engine.conf.d/10-setup-protocols.conf''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/engine.conf.d/10-setup-protocols.conf' missing
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.tools.Plugin._misc
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/isouploader.conf.d/10-engine-setup.conf''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/isouploader.conf.d/10-engine-setup.conf' missing
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/imageuploader.conf.d/10-engine-setup.conf''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/imageuploader.conf.d/10-engine-setup.conf' missing
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/logcollector.conf.d/10-engine-setup.conf''
2014-10-20 14:41:18 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/logcollector.conf.d/10-engine-setup.conf' missing
2014-10-20 14:41:18 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.schema.Plugin._misc
2014-10-20 14:41:18 DEBUG otopi.transaction transaction._prepare:77 preparing 'Engine schema Transaction'
2014-10-20 14:41:18 INFO otopi.plugins.ovirt_engine_setup.ovirt_engine.db.schema schema._misc:252 Creating/refreshing Engine database schema
2014-10-20 14:41:18 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.db.schema plugin.executeRaw:785 execute: ['/usr/share/ovirt-engine/dbscripts/schema.sh', '-s', 'localhost', '-p', '5432', '-u', 'engine', '-d', 'engine', '-l', '/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log', '-c', 'apply'], executable='None', cwd='None', env={'LESSOPEN': '|/usr/bin/lesspipe.sh %s', 'SSH_CLIENT': '141.7.157.203 50719 22', 'CVS_RSH': 'ssh', 'LOGNAME': 'root', 'USER': 'root', 'HOME': '/root', 'PATH': '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin', 'LANG': 'en_US.UTF-8', 'TERM': 'ansi', 'SHELL': '/bin/bash', 'SHLVL': '1', 'G_BROKEN_FILENAMES': '1', 'HISTSIZE': '1000', 'PYTHONPATH': '/usr/share/ovirt-engine/setup/bin/..::', 'OTOPI_LOGFILE': '/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log', 'LS_OPTIONS': '--human --color=always', 'DBFUNC_DB_PGPASSFILE': '/tmp/tmplSY6K_', 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:', 'SSH_TTY': '/dev/pts/0', 'HOSTNAME': 'ex1.gecko.hs-heilbronn.de', 'HISTCONTROL': 'ignoredups', 'PWD': '/root', 'MAIL': '/var/spool/mail/root', 'SSH_CONNECTION': '141.7.157.203 50719 148.251.139.133 22', 'OTOPI_EXECDIR': '/root'}
********* QUERY **********
select 1;
**************************

        1

********* QUERY **********
copy (
		select count(*) as count
		from pg_catalog.pg_tables
		where
			tablename = 'schema_version' and
			schemaname = 'public'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
			select count(*)
			from pg_language
			where lanname='plpgsql'
		) to stdout with delimiter as '|';
**************************

********* QUERY **********
create language 'plpgsql';
**************************

CREATE LANGUAGE
********* QUERY **********
ALTER DATABASE "engine" SET client_min_messages=ERROR;
**************************

ALTER DATABASE
********* QUERY **********
CREATE TABLE action_version_map (
    action_type integer NOT NULL,
    cluster_minimal_version character varying(40) NOT NULL,
    storage_pool_minimal_version character varying(40) NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE ad_groups (
    id uuid NOT NULL,
    name character varying(256) NOT NULL,
    status integer NOT NULL,
    domain character varying(100),
    distinguishedname character varying(4000) DEFAULT NULL::character varying
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE async_tasks (
    task_id uuid NOT NULL,
    action_type integer NOT NULL,
    status integer NOT NULL,
    result integer NOT NULL,
    action_parameters text,
    action_params_class character varying(256),
    step_id uuid,
    command_id uuid NOT NULL,
    started_at timestamp with time zone,
    storage_pool_id uuid,
    task_type integer DEFAULT 0 NOT NULL,
    task_parameters text,
    task_params_class character varying(256)
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE async_tasks_entities (
    async_task_id uuid NOT NULL,
    entity_id uuid NOT NULL,
    entity_type character varying(128)
);
**************************

CREATE TABLE
********* QUERY **********
CREATE SEQUENCE audit_log_seq INCREMENT BY 1 START WITH 1;
**************************

CREATE SEQUENCE
********* QUERY **********
CREATE TABLE audit_log (
    audit_log_id bigint DEFAULT nextval('audit_log_seq'::regclass) NOT NULL,
    user_id uuid,
    user_name character varying(255),
    vm_id uuid,
    vm_name character varying(255),
    vm_template_id uuid,
    vm_template_name character varying(40),
    vds_id uuid,
    vds_name character varying(255),
    log_time timestamp with time zone NOT NULL,
    log_type_name character varying(100) DEFAULT ''::character varying,
    log_type integer NOT NULL,
    severity integer NOT NULL,
    message text NOT NULL,
    processed boolean DEFAULT false NOT NULL,
    storage_pool_id uuid,
    storage_pool_name character varying(40),
    storage_domain_id uuid,
    storage_domain_name character varying(250),
    vds_group_id uuid,
    vds_group_name character varying(255),
    correlation_id character varying(50),
    job_id uuid,
    quota_id uuid,
    quota_name character varying(60),
    gluster_volume_id uuid,
    gluster_volume_name character varying(1000),
    origin character varying(255) DEFAULT 'oVirt'::character varying,
    custom_event_id integer DEFAULT (-1),
    event_flood_in_sec integer DEFAULT 30,
    custom_data text DEFAULT ''::text,
    deleted boolean DEFAULT false
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE base_disks (
    disk_id uuid NOT NULL,
    disk_interface character varying(32) NOT NULL,
    wipe_after_delete boolean DEFAULT false NOT NULL,
    propagate_errors character varying(32) DEFAULT 'Off'::character varying NOT NULL,
    disk_alias character varying(255),
    disk_description character varying(500),
    shareable boolean DEFAULT false,
    boot boolean DEFAULT false NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE bookmarks (
    bookmark_id uuid NOT NULL,
    bookmark_name character varying(40),
    bookmark_value character varying(300) NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE business_entity_snapshot (
    id uuid NOT NULL,
    command_id uuid NOT NULL,
    command_type character varying(256) NOT NULL,
    entity_id character varying(128),
    entity_type character varying(128),
    entity_snapshot text,
    snapshot_class character varying(128),
    snapshot_type integer,
    insertion_order integer,
    started_at timestamp with time zone DEFAULT now()
);
**************************

CREATE TABLE
********* QUERY **********
CREATE SEQUENCE custom_actions_seq INCREMENT BY 1 START WITH 1;
**************************

CREATE SEQUENCE
********* QUERY **********
CREATE TABLE custom_actions (
    action_id integer DEFAULT nextval('custom_actions_seq'::regclass) NOT NULL,
    action_name character varying(50) NOT NULL,
    path character varying(300) NOT NULL,
    tab integer NOT NULL,
    description character varying(4000)
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE disk_image_dynamic (
    image_id uuid NOT NULL,
    read_rate integer,
    write_rate integer,
    actual_size bigint NOT NULL,
    read_latency_seconds numeric(18,9),
    write_latency_seconds numeric(18,9),
    flush_latency_seconds numeric(18,9),
    _update_date timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE disk_lun_map (
    disk_id uuid NOT NULL,
    lun_id character varying NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE dwh_history_timekeeping (
    var_name character varying(50) NOT NULL,
    var_value character varying(255),
    var_datetime timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE event_map (
    event_up_name character varying(100) NOT NULL,
    event_down_name character varying(100) NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE event_notification_hist (
    subscriber_id uuid NOT NULL,
    event_name character varying(100) NOT NULL,
    audit_log_id bigint NOT NULL,
    method_type character(10) NOT NULL,
    sent_at timestamp with time zone NOT NULL,
    status boolean NOT NULL,
    reason character(255)
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE event_notification_methods (
    method_id integer NOT NULL,
    method_type character(10) NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE event_subscriber (
    subscriber_id uuid NOT NULL,
    event_up_name character varying(100) NOT NULL,
    method_id integer NOT NULL,
    method_address character varying(255),
    tag_name character varying(50) DEFAULT ''::character varying NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE gluster_hooks (
    id uuid NOT NULL,
    cluster_id uuid NOT NULL,
    gluster_command character varying(128) NOT NULL,
    stage character varying(50) NOT NULL,
    name character varying(256) NOT NULL,
    hook_status character varying(50),
    content_type character varying(50),
    checksum character varying(256),
    content text,
    conflict_status integer DEFAULT 0 NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    _update_date timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE gluster_server_hooks (
    hook_id uuid NOT NULL,
    server_id uuid NOT NULL,
    hook_status character varying(50),
    content_type character varying(50),
    checksum character varying(256),
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    _update_date timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE gluster_volume_access_protocols (
    volume_id uuid NOT NULL,
    access_protocol character varying(32) NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE gluster_volume_bricks (
    volume_id uuid NOT NULL,
    server_id uuid NOT NULL,
    brick_dir character varying(4096) NOT NULL,
    status character varying(32) NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    _update_date timestamp with time zone,
    id uuid NOT NULL,
    brick_order integer DEFAULT 0
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE gluster_volume_options (
    volume_id uuid NOT NULL,
    option_key character varying(8192) NOT NULL,
    option_val character varying(8192) NOT NULL,
    id uuid NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE gluster_volume_transport_types (
    volume_id uuid NOT NULL,
    transport_type character varying(32) NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE gluster_volumes (
    id uuid NOT NULL,
    cluster_id uuid NOT NULL,
    vol_name character varying(1000) NOT NULL,
    vol_type character varying(32) NOT NULL,
    status character varying(32) NOT NULL,
    replica_count integer DEFAULT 0 NOT NULL,
    stripe_count integer DEFAULT 0 NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    _update_date timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE image_storage_domain_map (
    image_id uuid NOT NULL,
    storage_domain_id uuid NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE images (
    image_guid uuid NOT NULL,
    creation_date timestamp with time zone NOT NULL,
    size bigint NOT NULL,
    it_guid uuid NOT NULL,
    parentid uuid,
    imagestatus integer DEFAULT 0,
    lastmodified timestamp with time zone,
    vm_snapshot_id uuid,
    volume_type integer DEFAULT 2 NOT NULL,
    volume_format integer DEFAULT 4 NOT NULL,
    image_group_id uuid,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    quota_id uuid,
    active boolean DEFAULT false NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE job (
    job_id uuid NOT NULL,
    action_type character varying(50) NOT NULL,
    description text NOT NULL,
    status character varying(32) NOT NULL,
    owner_id uuid,
    visible boolean DEFAULT true NOT NULL,
    start_time timestamp with time zone NOT NULL,
    end_time timestamp with time zone,
    last_update_time timestamp with time zone,
    correlation_id character varying(50) NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE job_subject_entity (
    job_id uuid NOT NULL,
    entity_id uuid NOT NULL,
    entity_type character varying(32) NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE lun_storage_server_connection_map (
    lun_id character varying(255) NOT NULL,
    storage_server_connection character varying(50) NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE luns (
    physical_volume_id character varying(50),
    lun_id character varying(255) NOT NULL,
    volume_group_id character varying(50) NOT NULL,
    serial character varying(4000),
    lun_mapping integer,
    vendor_id character varying(50),
    product_id character varying(50),
    device_size integer DEFAULT 0
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE materialized_views (
    mv_name name NOT NULL,
    v_name name NOT NULL,
    refresh_rate_in_sec integer,
    last_refresh timestamp with time zone,
    avg_cost_ms integer DEFAULT 0 NOT NULL,
    min_refresh_rate_in_sec integer DEFAULT 0,
    custom boolean DEFAULT false,
    active boolean DEFAULT true
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE network (
    id uuid NOT NULL,
    name character varying(50) NOT NULL,
    description character varying(4000),
    type integer,
    addr character varying(50),
    subnet character varying(20),
    gateway character varying(20),
    vlan_id integer,
    stp boolean DEFAULT false NOT NULL,
    storage_pool_id uuid,
    mtu integer,
    vm_network boolean DEFAULT true NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE network_cluster (
    network_id uuid NOT NULL,
    cluster_id uuid NOT NULL,
    status integer DEFAULT 0 NOT NULL,
    is_display boolean DEFAULT false NOT NULL,
    required boolean DEFAULT true NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE permissions (
    id uuid NOT NULL,
    role_id uuid NOT NULL,
    ad_element_id uuid NOT NULL,
    object_id uuid NOT NULL,
    object_type_id integer NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE quota (
    id uuid NOT NULL,
    storage_pool_id uuid NOT NULL,
    quota_name character varying(65) NOT NULL,
    description character varying(250),
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    threshold_vds_group_percentage integer DEFAULT 80,
    threshold_storage_percentage integer DEFAULT 80,
    grace_vds_group_percentage integer DEFAULT 20,
    grace_storage_percentage integer DEFAULT 20
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE quota_limitation (
    id uuid NOT NULL,
    quota_id uuid NOT NULL,
    storage_id uuid,
    vds_group_id uuid,
    virtual_cpu integer,
    mem_size_mb bigint,
    storage_size_gb bigint
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE repo_file_meta_data (
    repo_domain_id uuid NOT NULL,
    repo_file_name character varying(256) NOT NULL,
    size bigint DEFAULT 0,
    date_created timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    last_refreshed bigint DEFAULT 0,
    file_type integer DEFAULT 0
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE roles (
    id uuid NOT NULL,
    name character varying(126) NOT NULL,
    description character varying(4000),
    is_readonly boolean NOT NULL,
    role_type integer NOT NULL,
    allows_viewing_children boolean DEFAULT false NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE roles_groups (
    role_id uuid NOT NULL,
    action_group_id integer NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE roles_relations (
    role_id uuid NOT NULL,
    role_container_id uuid NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE SEQUENCE schema_version_seq INCREMENT BY 1 START WITH 1;
**************************

CREATE SEQUENCE
********* QUERY **********
CREATE TABLE schema_version (
    id integer DEFAULT nextval('schema_version_seq'::regclass) NOT NULL,
    version character varying(10) NOT NULL,
    script character varying(255) NOT NULL,
    checksum character varying(128),
    installed_by character varying(63) NOT NULL,
    started_at timestamp without time zone DEFAULT now(),
    ended_at timestamp without time zone,
    state character varying(15) NOT NULL,
    current boolean NOT NULL,
    comment text DEFAULT ''::text
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE snapshots (
    snapshot_id uuid NOT NULL,
    vm_id uuid NOT NULL,
    snapshot_type character varying(32) NOT NULL,
    status character varying(32) NOT NULL,
    description character varying(4000),
    creation_date timestamp with time zone NOT NULL,
    app_list text,
    vm_configuration text,
    _create_date timestamp with time zone DEFAULT now(),
    _update_date timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE step (
    step_id uuid NOT NULL,
    parent_step_id uuid,
    job_id uuid NOT NULL,
    step_type character varying(32) NOT NULL,
    description text NOT NULL,
    step_number integer NOT NULL,
    status character varying(32) NOT NULL,
    start_time timestamp with time zone NOT NULL,
    end_time timestamp with time zone,
    correlation_id character varying(50) NOT NULL,
    external_id uuid,
    external_system_type character varying(32)
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE storage_domain_dynamic (
    id uuid NOT NULL,
    available_disk_size integer,
    used_disk_size integer,
    _update_date timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE storage_domain_static (
    id uuid NOT NULL,
    storage character varying(250) NOT NULL,
    storage_name character varying(250) NOT NULL,
    storage_domain_type integer NOT NULL,
    storage_type integer NOT NULL,
    storage_domain_format_type character varying(50) DEFAULT '0'::character varying NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    recoverable boolean DEFAULT true NOT NULL,
    last_time_used_as_master bigint
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE storage_pool (
    id uuid NOT NULL,
    name character varying(40) NOT NULL,
    description character varying(4000) NOT NULL,
    storage_pool_type integer NOT NULL,
    storage_pool_format_type character varying(50),
    status integer NOT NULL,
    master_domain_version integer NOT NULL,
    spm_vds_id uuid,
    compatibility_version character varying(40) DEFAULT '2.2'::character varying NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    quota_enforcement_type integer
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE storage_pool_iso_map (
    storage_id uuid NOT NULL,
    storage_pool_id uuid NOT NULL,
    status integer,
    owner integer
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE storage_server_connections (
    id character varying(50) NOT NULL,
    connection character varying(250) NOT NULL,
    user_name character varying(50),
    password character varying(50),
    iqn character varying(128),
    port character varying(50),
    portal character varying(50),
    storage_type integer NOT NULL,
    mount_options character varying(500),
    vfs_type character varying(128),
    nfs_version character varying(4),
    nfs_timeo smallint,
    nfs_retrans smallint
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE tags (
    tag_id uuid NOT NULL,
    tag_name character varying(50) DEFAULT ''::character varying NOT NULL,
    description character varying(4000),
    parent_id uuid,
    readonly boolean,
    type integer DEFAULT 0 NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE tags_user_group_map (
    tag_id uuid NOT NULL,
    group_id uuid NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE tags_user_map (
    tag_id uuid NOT NULL,
    user_id uuid NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE tags_vds_map (
    tag_id uuid NOT NULL,
    vds_id uuid NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE tags_vm_map (
    tag_id uuid NOT NULL,
    vm_id uuid NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    defaultdisplaytype integer DEFAULT 0
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE tags_vm_pool_map (
    tag_id uuid NOT NULL,
    vm_pool_id uuid NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE users (
    user_id uuid NOT NULL,
    name character varying(255),
    surname character varying(255),
    domain character varying(255) NOT NULL,
    username character varying(255) NOT NULL,
    groups character varying NOT NULL,
    department character varying(255),
    role character varying(255),
    user_icon_path character varying(255),
    desktop_device character varying(255),
    email character varying(255),
    note character varying(255),
    status integer NOT NULL,
    session_count integer DEFAULT 0 NOT NULL,
    last_admin_check_status boolean DEFAULT false NOT NULL,
    group_ids text
);
**************************

CREATE TABLE
********* QUERY **********
CREATE SEQUENCE vdc_db_log_seq INCREMENT BY 1 START WITH 1;
**************************

CREATE SEQUENCE
********* QUERY **********
CREATE TABLE vdc_db_log (
    error_id bigint DEFAULT nextval('vdc_db_log_seq'::regclass) NOT NULL,
    occured_at timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone NOT NULL,
    error_code character varying(16) NOT NULL,
    error_message character varying(2048),
    error_proc character varying(126),
    error_line integer
);
**************************

CREATE TABLE
********* QUERY **********
CREATE SEQUENCE vdc_options_seq INCREMENT BY 1 START WITH 1;
**************************

CREATE SEQUENCE
********* QUERY **********
CREATE TABLE vdc_options (
    option_id integer DEFAULT nextval('vdc_options_seq'::regclass) NOT NULL,
    option_name character varying(100) NOT NULL,
    option_value character varying(4000) NOT NULL,
    version character varying(40) DEFAULT 'general'::character varying NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vds_dynamic (
    vds_id uuid NOT NULL,
    status integer NOT NULL,
    cpu_cores integer,
    cpu_model character varying(255),
    cpu_speed_mh numeric(18,0),
    if_total_speed character varying(40),
    kvm_enabled boolean,
    physical_mem_mb integer,
    mem_commited integer DEFAULT 0,
    vm_active integer DEFAULT 0,
    vm_count integer DEFAULT 0 NOT NULL,
    vm_migrating integer DEFAULT 0,
    reserved_mem integer,
    guest_overhead integer,
    software_version character varying(40),
    version_name character varying(40),
    build_name character varying(40),
    previous_status integer,
    cpu_flags character varying(4000),
    cpu_over_commit_time_stamp timestamp with time zone,
    vms_cores_count integer,
    pending_vcpus_count integer,
    cpu_sockets integer,
    net_config_dirty boolean,
    supported_cluster_levels character varying(40),
    host_os character varying(4000),
    kvm_version character varying(4000),
    spice_version character varying(4000),
    kernel_version character varying(4000),
    iscsi_initiator_name character varying(4000),
    transparent_hugepages_state integer DEFAULT 0 NOT NULL,
    anonymous_hugepages integer DEFAULT 0 NOT NULL,
    hooks character varying(4000) DEFAULT ''::character varying,
    _update_date timestamp with time zone,
    non_operational_reason integer DEFAULT 0 NOT NULL,
    pending_vmem_size integer DEFAULT 0 NOT NULL,
    rpm_version character varying(256) DEFAULT NULL::character varying,
    supported_engines character varying(40),
    libvirt_version character varying(256) DEFAULT NULL::character varying,
    cpu_threads integer,
    hw_manufacturer character varying(255),
    hw_product_name character varying(255),
    hw_version character varying(255),
    hw_serial_number character varying(255),
    hw_uuid character varying(255),
    hw_family character varying(255)
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vds_groups (
    vds_group_id uuid NOT NULL,
    name character varying(40) NOT NULL,
    description character varying(4000),
    cpu_name character varying(255),
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    selection_algorithm integer DEFAULT 0 NOT NULL,
    high_utilization integer DEFAULT 75 NOT NULL,
    low_utilization integer DEFAULT 0 NOT NULL,
    cpu_over_commit_duration_minutes integer DEFAULT 2 NOT NULL,
    storage_pool_id uuid,
    max_vds_memory_over_commit integer DEFAULT 100 NOT NULL,
    compatibility_version character varying(40) DEFAULT '2.2'::character varying NOT NULL,
    transparent_hugepages boolean DEFAULT false NOT NULL,
    migrate_on_error integer DEFAULT 1 NOT NULL,
    virt_service boolean DEFAULT true NOT NULL,
    gluster_service boolean DEFAULT false NOT NULL,
    count_threads_as_cores boolean DEFAULT false NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vds_interface (
    id uuid NOT NULL,
    name character varying(50) NOT NULL,
    network_name character varying(50),
    vds_id uuid,
    mac_addr character varying(59),
    is_bond boolean DEFAULT false,
    bond_name character varying(50),
    bond_type integer,
    bond_opts character varying(4000),
    vlan_id integer,
    speed integer,
    addr character varying(20),
    subnet character varying(20),
    gateway character varying(20),
    boot_protocol integer,
    type integer DEFAULT 0,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    mtu integer,
    bridged boolean DEFAULT true NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vds_interface_statistics (
    id uuid NOT NULL,
    vds_id uuid,
    rx_rate numeric(18,0),
    tx_rate numeric(18,0),
    rx_drop numeric(18,0),
    tx_drop numeric(18,0),
    iface_status integer,
    _update_date timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vds_spm_id_map (
    storage_pool_id uuid NOT NULL,
    vds_spm_id integer NOT NULL,
    vds_id uuid NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vds_static (
    vds_id uuid NOT NULL,
    vds_name character varying(255) NOT NULL,
    ip character varying(255),
    vds_unique_id character varying(128),
    host_name character varying(255) NOT NULL,
    port integer NOT NULL,
    vds_group_id uuid NOT NULL,
    server_ssl_enabled boolean,
    vds_type integer DEFAULT 0 NOT NULL,
    vds_strength integer DEFAULT 100 NOT NULL,
    pm_type character varying(20),
    pm_user character varying(50),
    pm_password text,
    pm_port integer,
    pm_options character varying(4000) DEFAULT ''::character varying NOT NULL,
    pm_enabled boolean DEFAULT false NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    otp_validity bigint,
    vds_spm_priority smallint DEFAULT 5,
    recoverable boolean DEFAULT true NOT NULL,
    sshkeyfingerprint character varying(128),
    pm_proxy_preferences character varying(255) DEFAULT ''::character varying,
    pm_secondary_ip character varying(255),
    pm_secondary_type character varying(20),
    pm_secondary_user character varying(50),
    pm_secondary_password text,
    pm_secondary_port integer,
    pm_secondary_options character varying(4000),
    pm_secondary_concurrent boolean DEFAULT false,
    console_address character varying(255) DEFAULT NULL::character varying,
    CONSTRAINT vds_static_vds_spm_priority_check CHECK (((vds_spm_priority >= (-1)) AND (vds_spm_priority <= 10)))
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vds_statistics (
    vds_id uuid NOT NULL,
    cpu_idle numeric(18,0) DEFAULT 0,
    cpu_load numeric(18,0) DEFAULT 0,
    cpu_sys numeric(18,0) DEFAULT 0,
    cpu_user numeric(18,0) DEFAULT 0,
    usage_mem_percent integer DEFAULT 0,
    usage_cpu_percent integer DEFAULT 0,
    usage_network_percent integer,
    mem_available bigint,
    mem_shared bigint,
    swap_free bigint,
    swap_total bigint,
    ksm_cpu_percent integer DEFAULT 0,
    ksm_pages bigint,
    ksm_state boolean,
    _update_date timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vm_device (
    device_id uuid NOT NULL,
    vm_id uuid NOT NULL,
    type character varying(30) NOT NULL,
    device character varying(30) NOT NULL,
    address character varying(255) NOT NULL,
    boot_order integer DEFAULT 0,
    spec_params text,
    is_managed boolean DEFAULT false NOT NULL,
    is_plugged boolean,
    is_readonly boolean DEFAULT false NOT NULL,
    _create_date timestamp with time zone DEFAULT now(),
    _update_date timestamp with time zone,
    alias character varying(255) DEFAULT ''::character varying
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vm_dynamic (
    vm_guid uuid NOT NULL,
    status integer NOT NULL,
    vm_ip text,
    vm_host character varying(255),
    vm_pid integer,
    last_start_time timestamp with time zone,
    guest_cur_user_name character varying(255),
    guest_last_login_time timestamp with time zone,
    guest_last_logout_time timestamp with time zone,
    guest_os character varying(255),
    run_on_vds uuid,
    migrating_to_vds uuid,
    app_list text,
    display integer,
    acpi_enable boolean,
    session integer,
    display_ip character varying(255),
    display_type integer,
    kvm_enable boolean,
    display_secure_port integer,
    utc_diff integer,
    last_vds_run_on uuid,
    client_ip character varying(255),
    guest_requested_memory integer,
    hibernation_vol_handle character varying(255),
    boot_sequence integer,
    exit_status integer DEFAULT 0 NOT NULL,
    pause_status integer DEFAULT 0 NOT NULL,
    exit_message character varying(4000),
    hash character varying(30),
    console_user_id uuid,
    guest_agent_nics_hash integer,
    console_cur_user_name character varying(255)
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vm_guest_agent_interfaces (
    vm_id uuid NOT NULL,
    interface_name text,
    mac_address character varying(59),
    ipv4_addresses text,
    ipv6_addresses text
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vm_interface (
    id uuid NOT NULL,
    network_name character varying(50),
    vm_guid uuid,
    vmt_guid uuid,
    mac_addr character varying(20),
    name character varying(50) NOT NULL,
    speed integer,
    type integer DEFAULT 0,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    port_mirroring boolean DEFAULT false NOT NULL,
    linked boolean DEFAULT true NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vm_interface_statistics (
    id uuid NOT NULL,
    vm_id uuid,
    rx_rate numeric(18,0),
    tx_rate numeric(18,0),
    rx_drop numeric(18,0),
    tx_drop numeric(18,0),
    iface_status integer,
    _update_date timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vm_ovf_generations (
    vm_guid uuid NOT NULL,
    storage_pool_id uuid,
    ovf_generation bigint DEFAULT 0
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vm_pool_map (
    vm_pool_id uuid,
    vm_guid uuid NOT NULL
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vm_pools (
    vm_pool_id uuid NOT NULL,
    vm_pool_name character varying(255) NOT NULL,
    vm_pool_description character varying(4000) NOT NULL,
    vm_pool_type integer,
    parameters character varying(200),
    vds_group_id uuid,
    prestarted_vms smallint DEFAULT 0
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vm_static (
    vm_guid uuid NOT NULL,
    vm_name character varying(255) NOT NULL,
    mem_size_mb integer NOT NULL,
    vmt_guid uuid NOT NULL,
    os integer DEFAULT 0 NOT NULL,
    description character varying(4000),
    vds_group_id uuid NOT NULL,
    domain character varying(40),
    creation_date timestamp with time zone,
    num_of_monitors integer NOT NULL,
    is_initialized boolean,
    is_auto_suspend boolean DEFAULT false,
    num_of_sockets integer DEFAULT 1 NOT NULL,
    cpu_per_socket integer DEFAULT 1 NOT NULL,
    usb_policy integer,
    time_zone character varying(40),
    is_stateless boolean,
    fail_back boolean DEFAULT false NOT NULL,
    _create_date timestamp with time zone DEFAULT ('now'::text)::timestamp without time zone,
    _update_date timestamp with time zone,
    dedicated_vm_for_vds uuid,
    auto_startup boolean,
    vm_type integer DEFAULT 0 NOT NULL,
    nice_level integer DEFAULT 0 NOT NULL,
    default_boot_sequence integer DEFAULT 0 NOT NULL,
    default_display_type integer DEFAULT 0 NOT NULL,
    priority integer DEFAULT 0 NOT NULL,
    iso_path character varying(4000) DEFAULT ''::character varying,
    origin integer DEFAULT 0,
    initrd_url character varying(4000),
    kernel_url character varying(4000),
    kernel_params character varying(4000),
    migration_support integer DEFAULT 0 NOT NULL,
    userdefined_properties character varying(4000),
    predefined_properties character varying(4000),
    min_allocated_mem integer DEFAULT 0 NOT NULL,
    entity_type character varying(32) NOT NULL,
    child_count integer DEFAULT 0,
    template_status integer,
    quota_id uuid,
    allow_console_reconnect boolean DEFAULT false NOT NULL,
    cpu_pinning character varying(4000) DEFAULT NULL::character varying,
    is_smartcard_enabled boolean DEFAULT false,
    host_cpu_flags boolean DEFAULT false,
    db_generation bigint DEFAULT 1,
    is_delete_protected boolean DEFAULT false,
    is_disabled boolean DEFAULT false
);
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE vm_statistics (
    vm_guid uuid NOT NULL,
    cpu_user numeric(18,0) DEFAULT 0,
    cpu_sys numeric(18,0) DEFAULT 0,
    elapsed_time numeric(18,0) DEFAULT 0,
    usage_network_percent integer DEFAULT 0,
    usage_mem_percent integer DEFAULT 0,
    usage_cpu_percent integer DEFAULT 0,
    disks_usage text,
    _update_date timestamp with time zone
);
**************************

CREATE TABLE
********* QUERY **********
ALTER TABLE ONLY disk_lun_map
    ADD CONSTRAINT disk_lun_map_pk PRIMARY KEY (disk_id, lun_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volumes
    ADD CONSTRAINT gluster_volumes_name_unique UNIQUE (cluster_id, vol_name);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volume_bricks
    ADD CONSTRAINT idx_gluster_volume_bricks_volume_server_brickdir UNIQUE (volume_id, server_id, brick_dir);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volume_options
    ADD CONSTRAINT idx_gluster_volume_options_volume_id_option_key UNIQUE (volume_id, option_key);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY materialized_views
    ADD CONSTRAINT materialized_views_pkey PRIMARY KEY (mv_name);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY action_version_map
    ADD CONSTRAINT pk_action_version_map PRIMARY KEY (action_type);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY ad_groups
    ADD CONSTRAINT pk_ad_group_id PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY async_tasks
    ADD CONSTRAINT pk_async_tasks PRIMARY KEY (task_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY audit_log
    ADD CONSTRAINT pk_audit_log PRIMARY KEY (audit_log_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY bookmarks
    ADD CONSTRAINT pk_bookmarks PRIMARY KEY (bookmark_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY custom_actions
    ADD CONSTRAINT pk_custom_actions PRIMARY KEY (action_name, tab);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY disk_image_dynamic
    ADD CONSTRAINT pk_disk_image_dynamic PRIMARY KEY (image_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY base_disks
    ADD CONSTRAINT pk_disks PRIMARY KEY (disk_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY event_map
    ADD CONSTRAINT pk_event_map PRIMARY KEY (event_up_name);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY event_notification_methods
    ADD CONSTRAINT pk_event_notification_methods PRIMARY KEY (method_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY event_subscriber
    ADD CONSTRAINT pk_event_subscriber PRIMARY KEY (subscriber_id, event_up_name, method_id, tag_name);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_hooks
    ADD CONSTRAINT pk_gluster_hooks PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volume_access_protocols
    ADD CONSTRAINT pk_gluster_volume_access_protocols PRIMARY KEY (volume_id, access_protocol);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volume_bricks
    ADD CONSTRAINT pk_gluster_volume_bricks PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volume_options
    ADD CONSTRAINT pk_gluster_volume_options PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volume_transport_types
    ADD CONSTRAINT pk_gluster_volume_transport_types PRIMARY KEY (volume_id, transport_type);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volumes
    ADD CONSTRAINT pk_gluster_volumes PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY business_entity_snapshot
    ADD CONSTRAINT pk_id PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY image_storage_domain_map
    ADD CONSTRAINT pk_image_storage_domain_map PRIMARY KEY (image_id, storage_domain_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY images
    ADD CONSTRAINT pk_images PRIMARY KEY (image_guid);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY job
    ADD CONSTRAINT pk_jobs PRIMARY KEY (job_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY job_subject_entity
    ADD CONSTRAINT pk_jobs_subject_entity PRIMARY KEY (job_id, entity_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY lun_storage_server_connection_map
    ADD CONSTRAINT pk_lun_storage_server_connection_map PRIMARY KEY (lun_id, storage_server_connection);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY luns
    ADD CONSTRAINT pk_luns PRIMARY KEY (lun_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY network
    ADD CONSTRAINT pk_network PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY network_cluster
    ADD CONSTRAINT pk_network_cluster PRIMARY KEY (network_id, cluster_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY permissions
    ADD CONSTRAINT pk_permissions_id PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY quota
    ADD CONSTRAINT pk_quota PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY quota_limitation
    ADD CONSTRAINT pk_quota_limitation PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY repo_file_meta_data
    ADD CONSTRAINT pk_repo_file_meta_data PRIMARY KEY (repo_domain_id, repo_file_name);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY roles_groups
    ADD CONSTRAINT pk_roles_groups PRIMARY KEY (role_id, action_group_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY roles
    ADD CONSTRAINT pk_roles_id PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY roles_relations
    ADD CONSTRAINT pk_roles_relations PRIMARY KEY (role_id, role_container_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY snapshots
    ADD CONSTRAINT pk_snapshots PRIMARY KEY (snapshot_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY step
    ADD CONSTRAINT pk_steps PRIMARY KEY (step_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY storage_domain_static
    ADD CONSTRAINT pk_storage PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY storage_domain_dynamic
    ADD CONSTRAINT pk_storage_domain_dynamic PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY storage_pool_iso_map
    ADD CONSTRAINT pk_storage_domain_pool_map PRIMARY KEY (storage_id, storage_pool_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY storage_pool
    ADD CONSTRAINT pk_storage_pool PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY storage_server_connections
    ADD CONSTRAINT pk_storage_server PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags
    ADD CONSTRAINT pk_tags_id PRIMARY KEY (tag_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_user_group_map
    ADD CONSTRAINT pk_tags_user_group_map PRIMARY KEY (tag_id, group_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_user_map
    ADD CONSTRAINT pk_tags_user_map PRIMARY KEY (tag_id, user_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_vds_map
    ADD CONSTRAINT pk_tags_vds_map PRIMARY KEY (tag_id, vds_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_vm_map
    ADD CONSTRAINT pk_tags_vm_map PRIMARY KEY (tag_id, vm_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_vm_pool_map
    ADD CONSTRAINT pk_tags_vm_pool_map PRIMARY KEY (tag_id, vm_pool_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY users
    ADD CONSTRAINT pk_users PRIMARY KEY (user_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vdc_db_log
    ADD CONSTRAINT pk_vdc_db_log PRIMARY KEY (error_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vdc_options
    ADD CONSTRAINT pk_vdc_options PRIMARY KEY (option_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_dynamic
    ADD CONSTRAINT pk_vds_dynamic PRIMARY KEY (vds_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_groups
    ADD CONSTRAINT pk_vds_groups PRIMARY KEY (vds_group_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_interface
    ADD CONSTRAINT pk_vds_interface PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_interface_statistics
    ADD CONSTRAINT pk_vds_interface_statistics PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_spm_id_map
    ADD CONSTRAINT pk_vds_spm_id_map PRIMARY KEY (storage_pool_id, vds_spm_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_static
    ADD CONSTRAINT pk_vds_static PRIMARY KEY (vds_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_statistics
    ADD CONSTRAINT pk_vds_statistics PRIMARY KEY (vds_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_device
    ADD CONSTRAINT pk_vm_device PRIMARY KEY (device_id, vm_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_dynamic
    ADD CONSTRAINT pk_vm_dynamic PRIMARY KEY (vm_guid);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_interface
    ADD CONSTRAINT pk_vm_interface PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_interface_statistics
    ADD CONSTRAINT pk_vm_interface_statistics PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_pool_map
    ADD CONSTRAINT pk_vm_pool_map PRIMARY KEY (vm_guid);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_pools
    ADD CONSTRAINT pk_vm_pools PRIMARY KEY (vm_pool_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_static
    ADD CONSTRAINT pk_vm_static PRIMARY KEY (vm_guid);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_statistics
    ADD CONSTRAINT pk_vm_statistics PRIMARY KEY (vm_guid);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY quota
    ADD CONSTRAINT quota_quota_name_unique UNIQUE (quota_name);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY schema_version
    ADD CONSTRAINT schema_version_primary_key PRIMARY KEY (id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY business_entity_snapshot
    ADD CONSTRAINT uq_command_id_entity_id UNIQUE (command_id, entity_id, entity_type, snapshot_type);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_static
    ADD CONSTRAINT vds_static_host_name_unique UNIQUE (host_name);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_static
    ADD CONSTRAINT vds_static_vds_name_unique UNIQUE (vds_name);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_ovf_generations
    ADD CONSTRAINT vm_ovf_generations_pkey PRIMARY KEY (vm_guid);
**************************

ALTER TABLE
********* QUERY **********
CREATE UNIQUE INDEX audit_log_origin_custom_event_id_idx ON audit_log USING btree (origin, custom_event_id) WHERE ((origin)::text !~~* 'ovirt'::text);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_audit_correlation_id ON audit_log USING btree (correlation_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_audit_log_job_id ON audit_log USING btree (job_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_audit_log_log_time ON audit_log USING btree (log_time);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_audit_log_storage_domain_name ON audit_log USING btree (storage_domain_name);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_audit_log_storage_pool_name ON audit_log USING btree (storage_pool_name);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_audit_log_user_name ON audit_log USING btree (user_name);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_audit_log_vds_name ON audit_log USING btree (vds_name);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_audit_log_vm_name ON audit_log USING btree (vm_name);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_audit_log_vm_template_name ON audit_log USING btree (vm_template_name);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_business_entity_snapshot_command_id ON business_entity_snapshot USING btree (command_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE UNIQUE INDEX idx_combined_ad_role_object ON permissions USING btree (ad_element_id, role_id, object_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_gluster_hooks_cluster_id ON gluster_hooks USING btree (cluster_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE UNIQUE INDEX idx_gluster_hooks_unique ON gluster_hooks USING btree (cluster_id, gluster_command, stage, name);
**************************

CREATE INDEX
********* QUERY **********
CREATE UNIQUE INDEX idx_gluster_server_hooks_unique ON gluster_server_hooks USING btree (hook_id, server_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_gluster_volume_access_protocols_volume_id ON gluster_volume_access_protocols USING btree (volume_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_gluster_volume_bricks_volume_id ON gluster_volume_bricks USING btree (volume_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_gluster_volume_options_volume_id ON gluster_volume_options USING btree (volume_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_gluster_volume_transport_types_volume_id ON gluster_volume_transport_types USING btree (volume_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_gluster_volumes_cluster_id ON gluster_volumes USING btree (cluster_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_job_subject_entity_entity_id ON job_subject_entity USING btree (entity_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_network_storage_pool_id ON network USING btree (storage_pool_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_permissions_ad_element_id ON permissions USING btree (ad_element_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_permissions_object_id ON permissions USING btree (object_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_permissions_role_id ON permissions USING btree (role_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_quota_limitation_quota_id ON quota_limitation USING btree (quota_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_quota_limitation_storage_id ON quota_limitation USING btree (storage_id) WHERE (storage_id IS NOT NULL);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_quota_limitation_vds_group_id ON quota_limitation USING btree (vds_group_id) WHERE (vds_group_id IS NOT NULL);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_repo_file_file_type ON repo_file_meta_data USING btree (file_type);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_roles_groups_action_group_id ON roles_groups USING btree (action_group_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_step_job_id ON step USING btree (job_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_step_parent_step_id ON step USING btree (parent_step_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_storage_pool_id ON quota USING btree (storage_pool_id) WHERE (storage_pool_id IS NOT NULL);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_vds_interface_vds_id ON vds_interface USING btree (vds_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_vm_dynamic_run_on_vds ON vm_dynamic USING btree (run_on_vds);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_vm_guest_agent_interfaces_vm_id ON vm_guest_agent_interfaces USING btree (vm_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_vm_interface_vm_vmt_guid ON vm_interface USING btree (vm_guid, vmt_guid);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_vm_ovf_generations_storage_pool_id ON vm_ovf_generations USING btree (storage_pool_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_vm_ovf_generations_vm_guid ON vm_ovf_generations USING btree (vm_guid);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX idx_vm_static_vm_name ON vm_static USING btree (vm_name);
**************************

CREATE INDEX
********* QUERY **********
CREATE INDEX ix_vdc_options ON vdc_options USING btree (option_name);
**************************

CREATE INDEX
********* QUERY **********
ALTER TABLE ONLY disk_lun_map
    ADD CONSTRAINT disk_lun_to_disk_fk FOREIGN KEY (disk_id) REFERENCES base_disks(disk_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY disk_lun_map
    ADD CONSTRAINT disk_lun_to_lun_fk FOREIGN KEY (lun_id) REFERENCES luns(lun_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY async_tasks_entities
    ADD CONSTRAINT fk_async_task_entity FOREIGN KEY (async_task_id) REFERENCES async_tasks(task_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY disk_image_dynamic
    ADD CONSTRAINT fk_disk_image_dynamic_images FOREIGN KEY (image_id) REFERENCES images(image_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY event_notification_hist
    ADD CONSTRAINT fk_event_notification_hist_audit_log FOREIGN KEY (audit_log_id) REFERENCES audit_log(audit_log_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY event_notification_hist
    ADD CONSTRAINT fk_event_notification_users FOREIGN KEY (subscriber_id) REFERENCES users(user_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY event_subscriber
    ADD CONSTRAINT fk_event_subscriber_event_map FOREIGN KEY (event_up_name) REFERENCES event_map(event_up_name) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY event_subscriber
    ADD CONSTRAINT fk_event_subscriber_event_notification_methods FOREIGN KEY (method_id) REFERENCES event_notification_methods(method_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY event_subscriber
    ADD CONSTRAINT fk_event_subscriber_users FOREIGN KEY (subscriber_id) REFERENCES users(user_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY image_storage_domain_map
    ADD CONSTRAINT fk_image_storage_domain_map_images FOREIGN KEY (image_id) REFERENCES images(image_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY image_storage_domain_map
    ADD CONSTRAINT fk_image_storage_domain_map_storage_domain_static FOREIGN KEY (storage_domain_id) REFERENCES storage_domain_static(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY job_subject_entity
    ADD CONSTRAINT fk_job_subject_entity_job FOREIGN KEY (job_id) REFERENCES job(job_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY lun_storage_server_connection_map
    ADD CONSTRAINT fk_lun_storage_server_connection_map_luns FOREIGN KEY (lun_id) REFERENCES luns(lun_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY lun_storage_server_connection_map
    ADD CONSTRAINT fk_lun_storage_server_connection_map_storage_server_connections FOREIGN KEY (storage_server_connection) REFERENCES storage_server_connections(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY network_cluster
    ADD CONSTRAINT fk_network_cluster_network FOREIGN KEY (network_id) REFERENCES network(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY network_cluster
    ADD CONSTRAINT fk_network_cluster_vds_groups FOREIGN KEY (cluster_id) REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY network
    ADD CONSTRAINT fk_network_storage_pool FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE SET NULL;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY permissions
    ADD CONSTRAINT fk_permissions_roles FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY repo_file_meta_data
    ADD CONSTRAINT fk_repo_file_meta_data_storage_domain_static FOREIGN KEY (repo_domain_id) REFERENCES storage_domain_static(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY roles_groups
    ADD CONSTRAINT fk_roles_groups_action_id FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY roles_relations
    ADD CONSTRAINT fk_roles_relations_container_id FOREIGN KEY (role_container_id) REFERENCES roles(id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY roles_relations
    ADD CONSTRAINT fk_roles_relations_role_id FOREIGN KEY (role_id) REFERENCES roles(id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY snapshots
    ADD CONSTRAINT fk_snapshot_vm FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY step
    ADD CONSTRAINT fk_step_job FOREIGN KEY (job_id) REFERENCES job(job_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY storage_domain_dynamic
    ADD CONSTRAINT fk_storage_domain_dynamic_storage_domain_static FOREIGN KEY (id) REFERENCES storage_domain_static(id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY storage_pool_iso_map
    ADD CONSTRAINT fk_storage_domain_pool_map_storage_domain_static FOREIGN KEY (storage_id) REFERENCES storage_domain_static(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY storage_pool_iso_map
    ADD CONSTRAINT fk_storage_domain_pool_map_storage_pool FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_vm_pool_map
    ADD CONSTRAINT fk_tags_vm_pool_map_tag FOREIGN KEY (tag_id) REFERENCES tags(tag_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_vm_pool_map
    ADD CONSTRAINT fk_tags_vm_pool_map_vm_pool FOREIGN KEY (vm_pool_id) REFERENCES vm_pools(vm_pool_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_groups
    ADD CONSTRAINT fk_vds_groups_storage_pool_id FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE SET NULL;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_pools
    ADD CONSTRAINT fk_vds_groups_vm_pools FOREIGN KEY (vds_group_id) REFERENCES vds_groups(vds_group_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_interface_statistics
    ADD CONSTRAINT fk_vds_interface_statistics_vds_static FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_interface
    ADD CONSTRAINT fk_vds_interface_vds_interface FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_spm_id_map
    ADD CONSTRAINT fk_vds_spm_id_map_storage_pool FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_spm_id_map
    ADD CONSTRAINT fk_vds_spm_id_map_vds_id FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_static
    ADD CONSTRAINT fk_vds_static_vm_static FOREIGN KEY (dedicated_vm_for_vds) REFERENCES vds_static(vds_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_device
    ADD CONSTRAINT fk_vm_device_vm_static FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_guest_agent_interfaces
    ADD CONSTRAINT fk_vm_guest_agent_interfaces FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_interface_statistics
    ADD CONSTRAINT fk_vm_interface_statistics_vm_static FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_interface
    ADD CONSTRAINT fk_vm_interface_vm_static FOREIGN KEY (vm_guid) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_interface
    ADD CONSTRAINT fk_vm_interface_vm_static_template FOREIGN KEY (vmt_guid) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_hooks
    ADD CONSTRAINT gluster_hooks_cluster_id_fkey FOREIGN KEY (cluster_id) REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_server_hooks
    ADD CONSTRAINT gluster_server_hooks_hook_id_fkey FOREIGN KEY (hook_id) REFERENCES gluster_hooks(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_server_hooks
    ADD CONSTRAINT gluster_server_hooks_server_id_fkey FOREIGN KEY (server_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volume_access_protocols
    ADD CONSTRAINT gluster_volume_access_protocols_volume_id_fkey FOREIGN KEY (volume_id) REFERENCES gluster_volumes(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volume_bricks
    ADD CONSTRAINT gluster_volume_bricks_server_id_fkey FOREIGN KEY (server_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volume_bricks
    ADD CONSTRAINT gluster_volume_bricks_volume_id_fkey FOREIGN KEY (volume_id) REFERENCES gluster_volumes(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volume_options
    ADD CONSTRAINT gluster_volume_options_volume_id_fkey FOREIGN KEY (volume_id) REFERENCES gluster_volumes(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volume_transport_types
    ADD CONSTRAINT gluster_volume_transport_types_volume_id_fkey FOREIGN KEY (volume_id) REFERENCES gluster_volumes(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY gluster_volumes
    ADD CONSTRAINT gluster_volumes_cluster_id_fkey FOREIGN KEY (cluster_id) REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY images
    ADD CONSTRAINT image_templates_images FOREIGN KEY (it_guid) REFERENCES images(image_guid);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY quota_limitation
    ADD CONSTRAINT quota_limitation_quota_id_fkey FOREIGN KEY (quota_id) REFERENCES quota(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY quota_limitation
    ADD CONSTRAINT quota_limitation_storage_id_fkey FOREIGN KEY (storage_id) REFERENCES storage_domain_static(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY quota_limitation
    ADD CONSTRAINT quota_limitation_vds_group_id_fkey FOREIGN KEY (vds_group_id) REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY quota
    ADD CONSTRAINT quota_storage_pool_id_fkey FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_user_group_map
    ADD CONSTRAINT tags_user_group_map_tag FOREIGN KEY (tag_id) REFERENCES tags(tag_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_user_map
    ADD CONSTRAINT tags_user_map_tag FOREIGN KEY (tag_id) REFERENCES tags(tag_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_user_map
    ADD CONSTRAINT tags_user_map_user FOREIGN KEY (user_id) REFERENCES users(user_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_user_group_map
    ADD CONSTRAINT tags_user_map_user_group FOREIGN KEY (group_id) REFERENCES ad_groups(id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_vds_map
    ADD CONSTRAINT tags_vds_map_tag FOREIGN KEY (tag_id) REFERENCES tags(tag_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_vds_map
    ADD CONSTRAINT tags_vds_map_vds FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_vm_map
    ADD CONSTRAINT tags_vm_map_tag FOREIGN KEY (tag_id) REFERENCES tags(tag_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY tags_vm_map
    ADD CONSTRAINT tags_vm_map_vm FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_static
    ADD CONSTRAINT vds_groups_vds_static FOREIGN KEY (vds_group_id) REFERENCES vds_groups(vds_group_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_static
    ADD CONSTRAINT vds_groups_vm_static FOREIGN KEY (vds_group_id) REFERENCES vds_groups(vds_group_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_dynamic
    ADD CONSTRAINT vds_static_vds_dynamic FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vds_statistics
    ADD CONSTRAINT vds_static_vds_statistics FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_dynamic
    ADD CONSTRAINT vds_static_vm_dynamic_m FOREIGN KEY (migrating_to_vds) REFERENCES vds_static(vds_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_dynamic
    ADD CONSTRAINT vds_static_vm_dynamic_r FOREIGN KEY (run_on_vds) REFERENCES vds_static(vds_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_pool_map
    ADD CONSTRAINT vm_guid_pools FOREIGN KEY (vm_guid) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_ovf_generations
    ADD CONSTRAINT vm_ovf_generations_storage_pool_id_fkey FOREIGN KEY (storage_pool_id) REFERENCES storage_pool(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_pool_map
    ADD CONSTRAINT vm_pools_vm FOREIGN KEY (vm_pool_id) REFERENCES vm_pools(vm_pool_id);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_dynamic
    ADD CONSTRAINT vm_static_vm_dynamic FOREIGN KEY (vm_guid) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_statistics
    ADD CONSTRAINT vm_static_vm_statistics FOREIGN KEY (vm_guid) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ONLY vm_static
    ADD CONSTRAINT vm_templates_vm_static FOREIGN KEY (vmt_guid) REFERENCES vm_static(vm_guid);
**************************

ALTER TABLE
********* QUERY **********
DROP TYPE IF EXISTS idTextType CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE idtexttype AS (
        id text
);
**************************

CREATE TYPE
********* QUERY **********
DROP TYPE IF EXISTS idUuidType CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE iduuidtype AS (
        id uuid
);
**************************

CREATE TYPE
********* QUERY **********
DROP TYPE IF EXISTS booleanResultType CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE booleanresulttype AS (
        result boolean
);
**************************

CREATE TYPE
********* QUERY **********
DROP TYPE IF EXISTS authzEntryInfoType CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE authzentryinfotype AS (
        name text,
        namespace character varying(2048),
        authz character varying(255)
);
**************************

CREATE TYPE
********* QUERY **********
CREATE OR REPLACE FUNCTION getGlobalIds(v_name VARCHAR(4000))
RETURNS UUID IMMUTABLE STRICT
   AS $function$
   DECLARE
   v_id  UUID;
BEGIN
   if (v_name = 'system') then
      v_id := 'AAA00000-0000-0000-0000-123456789AAA';
   elsif (v_name = 'everyone') then
      v_id := 'EEE00000-0000-0000-0000-123456789EEE';
   -- bottom is an object which all the objects in the system are its parents
   -- useful to denote we want all objects when checking for permissions
   elsif (v_name = 'bottom') then
      v_id := 'BBB00000-0000-0000-0000-123456789BBB';
   end if;
   return  v_id;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fnSplitter(ids TEXT)  RETURNS SETOF idTextType IMMUTABLE AS
$function$
BEGIN
	RETURN QUERY
		SELECT regexp_split_to_table(ids, ',') AS id;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fnSplitterUuid(ids TEXT)  RETURNS SETOF UUID IMMUTABLE AS
$function$
BEGIN
 IF ids != '' THEN
	RETURN QUERY
		SELECT CAST(regexp_split_to_table(ids, ',') AS UUID);
 END IF;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fnSplitterWithSeperator(ids TEXT, separator VARCHAR(10))  RETURNS SETOF idTextType IMMUTABLE AS
$function$
BEGIN
  RETURN QUERY
    SELECT regexp_split_to_table(ids, separator) AS id;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS user_permissions CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE user_permissions AS (
        permission_id uuid,
        role_id uuid,
        user_id uuid
);
**************************

CREATE TYPE
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_user_permissions(v_userId IN uuid) RETURNS SETOF user_permissions STABLE AS
$function$
DECLARE

BEGIN
	RETURN QUERY
	    SELECT
		    permissions.id AS permission_id,
		    permissions.role_id,
		    permissions.ad_element_id AS user_id
	    FROM permissions
		INNER JOIN users ON permissions.ad_element_id = users.user_id
	    WHERE users.user_id = v_userId

	    UNION

	    SELECT
		    permissions.id AS permission_id,
		    permissions.role_id,
		    temp.user_id AS user_id
	    FROM permissions INNER JOIN
	    (
		    -- get all groups of admin users
		    SELECT ad_groups.id group_id, users.user_id
		    FROM ad_groups, users
		    WHERE ad_groups.id IN
		    (SELECT * FROM fnsplitteruuid(users.group_ids))
			AND users.user_id = v_userId ) temp
		ON permissions.ad_element_id = temp.group_id;

END; $function$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_get_entity_parents(v_entity_id IN uuid, v_object_type IN int4) RETURNS SETOF idUuidType STABLE AS
$function$
/*	Gets a list of all parent GUID to the system root (including)

	Object Types (compatible with VdcObjectType, XXX entries are unused currently)
		Unknown XXX,
		System XXX,
        Bottom = 0,
		VM = 2,
		VDS = 3,
		VmTemplate = 4,
		VmPool = 5,
		AdElements XXX,
		Tags XXX,
		Bookmarks XXX,
		VdsGroups = 9,
		MultiLevelAdministration XXX,
		Storage = 11,
		EventNotification XXX,
		ImportExport XXX,
		StoragePool = 14,
		User = 15,
		Role = 16,
		Quota = 17,
		GlusterVolume = 18,
        Disk = 19,
        Network = 20,
        VNICProfile = 27,
        DiskProfile = 29
        CpuProfile = 30
*/
DECLARE
	v_entity_type int4 := v_object_type;
	system_root_id uuid;
	cluster_id uuid;
	ds_id uuid;
	v_image_id uuid;
	v_storage_id uuid;
    v_vm_id uuid;
    v_storage_pool_id uuid;
    v_profile_network_id uuid;
    v_disk_profile_storage_id uuid;
    v_cpu_profile_cluster_id uuid;

BEGIN

	system_root_id := ( SELECT getGlobalIds('system') ); -- hardcoded also in MLA Handler
	CASE
	WHEN v_entity_type = 0 THEN -- Bottom
		RETURN QUERY
			SELECT object_id
			FROM permissions;
	WHEN v_entity_type = 2 THEN -- VM
        -- get cluster id
		cluster_id := ( SELECT vds_group_id FROM vm_static WHERE vm_guid = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 3 THEN -- VDS
        -- get cluster id
		cluster_id := ( SELECT vds_group_id FROM vds_static WHERE vds_id = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 4 THEN -- Template
		-- get image id first
		v_image_id := ( SELECT image_guid FROM images i JOIN vm_device vd ON i.image_group_id = vd.device_id WHERE vm_id = v_entity_id limit 1);
		-- get the storage id from images
		v_storage_id := ( SELECT storage_domain_id FROM image_storage_domain_map WHERE image_id = v_image_id limit 1);
		-- finally get data center id
		ds_id := ( SELECT storage_pool_id FROM storage_pool_iso_map WHERE storage_id = v_storage_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 5 THEN -- VM Pool
        -- get cluster id
		cluster_id := ( SELECT vds_group_id FROM vm_pools WHERE vm_pool_id = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 9 THEN -- Cluster
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = v_entity_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 11 THEN -- Storage Domain

		RETURN QUERY
			SELECT system_root_id AS id
			UNION ALL
			SELECT storage_pool_id as id FROM storage_pool_iso_map WHERE storage_id = v_entity_id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 17 THEN -- Quota
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM quota WHERE id = v_entity_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 18 THEN -- GlusterVolume
        -- get cluster id
		cluster_id := ( SELECT v.cluster_id FROM gluster_volumes v WHERE id = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;

	WHEN v_entity_type = 19 THEN -- Disk

        -- get data center, storage domain and vm
        SELECT INTO ds_id, v_storage_id, v_vm_id
                    storage_pool_id, storage_id, vm_id
        FROM images_storage_domain_view
        LEFT OUTER JOIN vm_device ON vm_device.device_id = images_storage_domain_view.disk_id
        WHERE image_group_id = v_entity_id;

        -- get cluster
        cluster_id := ( SELECT vds_group_id FROM vm_static WHERE vm_guid = v_vm_id );

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT ds_id AS id
            UNION
            SELECT v_storage_id AS id
            UNION
            SELECT v_vm_id AS id
            UNION
            SELECT cluster_id AS id
            UNION
            SELECT v_entity_id AS id;

	WHEN v_entity_type = 20 THEN -- Network

        SELECT INTO v_storage_pool_id
                    network.storage_pool_id
        FROM network
        WHERE network.id = v_entity_id;

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT v_storage_pool_id AS id
            UNION
            SELECT v_entity_id AS id;

	WHEN v_entity_type = 27 THEN -- VNICProfile

        SELECT INTO v_profile_network_id
                    vnic_profiles.network_id
        FROM vnic_profiles
        WHERE vnic_profiles.id = v_entity_id;
        SELECT INTO v_storage_pool_id
                    network.storage_pool_id
        FROM network
        WHERE network.id = v_profile_network_id;

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT v_storage_pool_id AS id
            UNION
            SELECT v_profile_network_id AS id
            UNION
            SELECT v_entity_id AS id;

        WHEN v_entity_type = 29 THEN -- DiskProfile

        SELECT INTO v_disk_profile_storage_id
                    disk_profiles.storage_domain_id
        FROM disk_profiles
        WHERE disk_profiles.id = v_entity_id;
        SELECT INTO v_storage_pool_id
                    storage_pool_iso_map.storage_pool_id
        FROM storage_pool_iso_map
        WHERE storage_pool_iso_map.storage_id = v_disk_profile_storage_id;

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT v_storage_pool_id AS id
            UNION
            SELECT v_disk_profile_storage_id AS id
            UNION
            SELECT v_entity_id AS id;

        WHEN v_entity_type = 30 THEN -- CpuProfile

        SELECT INTO v_cpu_profile_cluster_id
                    cpu_profiles.cluster_id
        FROM cpu_profiles
        WHERE cpu_profiles.id = v_entity_id;
        SELECT INTO v_storage_pool_id
                    vds_groups.storage_pool_id
        FROM vds_groups
        WHERE vds_groups.vds_group_id = v_cpu_profile_cluster_id;

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT v_storage_pool_id AS id
            UNION
            SELECT v_cpu_profile_cluster_id AS id
            UNION
            SELECT v_entity_id AS id;

    WHEN v_entity_type = 23 THEN -- Gluster Hook

        -- get cluster id
        cluster_id := ( SELECT cluster_id FROM gluster_hooks WHERE id = v_entity_id );
        -- get data center id
        ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT ds_id AS id
            UNION
            SELECT cluster_id AS id
            UNION
            SELECT v_entity_id AS id;

	WHEN v_entity_type = 25 THEN -- Gluster Service

        -- get cluster id
        cluster_id := ( SELECT vds_group_id FROM vds_static WHERE vds_id = v_entity_id );
        -- get data center id
        ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT ds_id AS id
            UNION
            SELECT cluster_id AS id
            UNION
            SELECT v_entity_id AS id;
	ELSE
		IF v_entity_type IN ( 1,14,15,16 ) THEN -- Data Center, users and roles are under system
			RETURN QUERY
				SELECT system_root_id AS id
				UNION
				SELECT v_entity_id AS id;
		END IF;
	END CASE;
END;$function$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_get_disk_commited_value_by_storage(v_storage_domain_id IN uuid) RETURNS integer STABLE AS
$function$
DECLARE
    result integer;
    mult bigint;

BEGIN
	mult := ( SELECT
	    		COALESCE(SUM(
                       CASE
                           WHEN (images_storage_domain_view.active = true
                                 AND (images_storage_domain_view.entity_type IS NULL OR       -- Floating disk
                                      images_storage_domain_view.entity_type <> 'TEMPLATE'))  -- or a VM
                               THEN images_storage_domain_view.size
                           ELSE images_storage_domain_view.actual_size
                       END),0)
				FROM images_storage_domain_view
				WHERE images_storage_domain_view.storage_id = v_storage_domain_id );
        -- convert to GB from bytes
	mult := CAST((mult * 0.000000000931322574615478515625) AS bigint);
    result := CAST(mult as integer);

	RETURN result;
END;$function$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_get_actual_images_size_by_storage(v_storage_domain_id IN uuid) RETURNS integer STABLE AS
$function$
DECLARE
    result integer;
    mult bigint;

BEGIN
	mult := ( SELECT
	    		COALESCE(SUM(disk_image_dynamic.actual_size),0)
				FROM images_storage_domain_view JOIN
	    			disk_image_dynamic ON ( images_storage_domain_view.image_guid = disk_image_dynamic.image_id )
				WHERE images_storage_domain_view.storage_id = v_storage_domain_id );
        -- convert to GB from bytes
	mult := CAST((mult * 0.000000000931322574615478515625) AS bigint);
    result := CAST(mult as integer);

	RETURN result;
END;$function$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_get_storage_domain_shared_status_by_domain_id(v_storage_domain_id UUID,
	v_storage_status INTEGER,
	v_storage_domain_type INTEGER)
RETURNS INTEGER
   AS $function$
   DECLARE
   v_result  INTEGER;
   v_rowsCount  INTEGER;
   v_status  INTEGER;
BEGIN
    if (v_storage_domain_type != 2) then
      if (v_storage_status is null) then
         v_result := 0;
      else
         -- if 1 row and status active (3) then domain is active (1)
         if v_storage_status = 3 then
            v_result := 1;
		 -- if 1 row and status not active then domain is inactive (2)
         else
            v_result := 2;
         end if;
      end if;
    else
      BEGIN
         CREATE TEMPORARY TABLE tt_TEMP22
         (
            status INTEGER,
            count INTEGER
         ) WITH OIDS;
         exception when others then
         truncate table tt_TEMP22;
      END;
      delete from tt_TEMP22;
      Insert INTO tt_TEMP22
      select status, count(storage_id) from storage_pool_iso_map
      where storage_id = v_storage_domain_id
      group by status;

      select count(*) INTO v_rowsCount from tt_TEMP22;

      -- if return 0 rows then the domain is unattached
      if (v_rowsCount = 0) then
         v_result := 0;
      else
         if (v_rowsCount = 1) then
	        -- if 1 row and status active (3) then domain is active (1)
            if v_storage_status = 3 then
               v_result := 1;
		    -- if 1 row and status not active then domain is inactive (2)
            else
               v_result := 2;
            end if;
	      -- else (if return more then 1 row)
          else
            select   count(*) INTO v_rowsCount from tt_TEMP22 where status = 3;
            if (v_rowsCount > 0) then
               v_result := 3;
			   -- non of the statuses is active
            else
               v_result := 2;
          end if;
         end if;
      end if;
    end if;
   return v_result;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_authz_entry_info(v_ad_element_id IN uuid) RETURNS AuthzEntryInfoType STABLE AS
$function$
DECLARE
    result authzEntryInfoType;

BEGIN
   if (v_ad_element_id = getGlobalIds('everyone')) then
      select 'Everyone','*','' into result;
   else
      select(COALESCE(name,'') || ' ' || COALESCE(surname,'') || ' (' || COALESCE(username,'') || '@' || COALESCE(domain,'') || ')'), namespace, domain INTO result from users where user_id = v_ad_element_id;
      if (result is null) then
         select   name, namespace, domain INTO result from ad_groups where ID = v_ad_element_id;
      end if;
   end if;
   return result;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_get_ad_element_name(v_ad_element_id IN uuid) RETURNS text STABLE AS
$function$
DECLARE
    result text;

BEGIN
   if (v_ad_element_id = getGlobalIds('everyone')) then
      result := 'Everyone';
   else
      select(COALESCE(name,'') || ' ' || COALESCE(surname,'') || ' (' || COALESCE(username,'') || '@' || COALESCE(domain,'') || ')') INTO result from users where user_id = v_ad_element_id;
      if (result is null) then
         select   name INTO result from ad_groups where ID = v_ad_element_id;
      end if;
   end if;
   return result;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_get_entity_name(v_entity_id IN uuid, v_object_type IN int4) RETURNS text STABLE AS
$function$
/*    Gets object name by its id and type

    Object Types (compatible with VdcObjectType, XXX entries are unused currently)
        Unknown XXX,
        System XXX,
        VM = 2,
        VDS = 3,
        VmTemplate = 4,
        VmPool = 5,
        AdElements XXX,
        Tags XXX,
        Bookmarks XXX,
        VdsGroups = 9,
        MultiLevelAdministration XXX,
        Storage = 11,
        EventNotification XXX,
        ImportExport XXX,
        StoragePool = 14,
        User = 15,
        Role = 16,
        Quota = 17,
        GlusterVolume = 18,
        Disk = 19,
        Network = 20,
        VNICProfile = 27,
        DiskProfile = 29
        CpuProfile = 30
*/
DECLARE
    v_entity_type int4 := v_object_type;
    result text;

BEGIN

    CASE
    WHEN v_entity_type = 1 THEN
        result := 'System';
    WHEN v_entity_type = 2 OR v_entity_type = 4 THEN
        result := ( SELECT vm_name FROM vm_static WHERE vm_guid = v_entity_id );
    WHEN v_entity_type = 3 THEN
        result := ( SELECT vds_name FROM vds_static WHERE vds_id = v_entity_id );
    WHEN v_entity_type = 5 THEN
        result := ( SELECT vm_pool_name FROM vm_pools WHERE vm_pool_id = v_entity_id );
    WHEN v_entity_type = 7 THEN
        result := ( SELECT tag_name FROM tags WHERE tag_id = v_entity_id );
    WHEN v_entity_type = 8 THEN
        result := ( SELECT bookmark_name FROM bookmarks WHERE bookmark_id = v_entity_id );
    WHEN v_entity_type = 9 THEN
        result := ( SELECT name FROM vds_groups WHERE vds_group_id = v_entity_id );
    WHEN v_entity_type = 11 THEN
        result := ( SELECT storage_name FROM storage_domain_static WHERE id = v_entity_id );
    WHEN v_entity_type = 14 THEN
        result := ( SELECT name FROM storage_pool WHERE id = v_entity_id );
    WHEN v_entity_type = 15 THEN
        result := ( SELECT username FROM users WHERE user_id = v_entity_id );
    WHEN v_entity_type = 16 THEN
        result := ( SELECT name FROM roles WHERE id = v_entity_id );
    WHEN v_entity_type = 17 THEN
        result := ( SELECT quota_name FROM quota WHERE id = v_entity_id );
   WHEN v_entity_type = 18 THEN
        result := ( SELECT vol_name FROM gluster_volumes WHERE id = v_entity_id );
    WHEN v_entity_type = 19 THEN
        result := ( SELECT disk_alias FROM base_disks WHERE disk_id = v_entity_id );
    WHEN v_entity_type = 20 THEN
        result := ( SELECT name FROM network WHERE id = v_entity_id );
    WHEN v_entity_type = 23 THEN
        result := ( SELECT concat(gluster_command,'-',stage,'-',name) FROM gluster_hooks where id = v_entity_id );
    WHEN v_entity_type = 25 THEN
        result := ( SELECT service_name FROM gluster_services where id = v_entity_id );
    WHEN v_entity_type = 27 THEN
        result := ( SELECT name FROM vnic_profiles where id = v_entity_id );
    WHEN v_entity_type = 29 THEN
        result := ( SELECT name FROM disk_profiles where id = v_entity_id );
    WHEN v_entity_type = 30 THEN
        result := ( SELECT name FROM cpu_profiles where id = v_entity_id );
    ELSE
        result := 'Unknown type ' ||  v_entity_type;
    END CASE;

--      -- This should be written to an error var or include object_id that is missing
--    IF result IS NULL THEN
--        result := v_entity_id || '' NOT FOUND'';
--    END IF;
    RETURN result;
END;$function$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION getUserAndGroupsById(v_id UUID)
RETURNS SETOF idUuidType STABLE
   AS $function$
BEGIN
   RETURN QUERY
   select ID from ad_groups,users where users.user_id = v_id
   and ad_groups.id in(select * from fnsplitteruuid(users.group_ids))
   UNION
   select v_id
   UNION
   -- user is also member of 'Everyone'
   select 'EEE00000-0000-0000-0000-123456789EEE';
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION getElementIdsByIdAndGroups(v_id UUID,v_group_ids text)
RETURNS SETOF idUuidType STABLE
   AS $function$
BEGIN
  RETURN QUERY
  select * from fnsplitteruuid(v_group_ids)
  UNION
  select v_id
  UNION
  -- user is also member of 'Everyone'
  select 'EEE00000-0000-0000-0000-123456789EEE';
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS vds_group_usage_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE vds_group_usage_rs AS (
        virtual_cpu_usage integer,
        mem_size_mb_usage bigint
);
**************************

CREATE TYPE
********* QUERY **********
CREATE OR REPLACE FUNCTION getNonCountableQutoaVmStatuses()
RETURNS SETOF INTEGER IMMUTABLE
    AS $BODY$
BEGIN
    RETURN query select 0 union select 13 union select 14 union select 15;
--(Down(0), Suspended(13), ImageIllegal(14), ImageLocked(15))
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CalculateVdsGroupUsage(v_quota_id UUID, v_vds_group_id UUID)
RETURNS SETOF vds_group_usage_rs STABLE
AS $function$
BEGIN
    RETURN QUERY SELECT cast(COALESCE(sum(num_of_sockets * cpu_per_socket), 0) as INTEGER) as virtual_cpu_usage,
    COALESCE(sum(mem_size_mb), 0) as mem_size_mb_usage
    FROM vm_static,vm_dynamic
    WHERE quota_id = v_quota_id
      AND vm_dynamic.vm_guid = vm_static.vm_guid
      AND vm_dynamic.status not in (SELECT getNonCountableQutoaVmStatuses())
      AND (v_vds_group_id = vm_static.vds_group_id or v_vds_group_id IS NULL);
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS all_vds_group_usage_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE all_vds_group_usage_rs AS (
        quota_vds_group_id uuid,
        quota_id uuid,
        vds_group_id uuid,
        vds_group_name character varying(40),
        virtual_cpu integer,
        virtual_cpu_usage integer,
        mem_size_mb bigint,
        mem_size_mb_usage bigint
);
**************************

CREATE TYPE
********* QUERY **********
CREATE OR REPLACE FUNCTION calculateAllVdsGroupUsage()
RETURNS SETOF all_vds_group_usage_rs STABLE
AS $function$
BEGIN
    RETURN QUERY SELECT
        quota_limitation.id AS quota_vds_group_id,
        quota_limitation.quota_id as quota_id,
        quota_limitation.vds_group_id as vds_group_id,
        vds_groups.name AS vds_group_name,
        quota_limitation.virtual_cpu,
        cast(COALESCE(sum(num_of_sockets * cpu_per_socket * cast(vm_dynamic.status not in (SELECT getNonCountableQutoaVmStatuses()) as INTEGER)), 0) as INTEGER) as virtual_cpu_usage,
        quota_limitation.mem_size_mb,
        COALESCE(sum(vm_static.mem_size_mb), 0) as mem_size_mb_usage
    FROM quota_limitation
        LEFT JOIN vm_static ON vm_static.quota_id = quota_limitation.quota_id
        LEFT JOIN vm_dynamic ON vm_dynamic.vm_guid = vm_static.vm_guid
        LEFT JOIN vds_groups ON vds_groups.vds_group_id = vm_static.vds_group_id
    WHERE quota_limitation.virtual_cpu IS NOT NULL
        AND quota_limitation.mem_size_mb IS NOT NULL
    GROUP BY quota_limitation.quota_id, quota_limitation.vds_group_id, vds_group_name, quota_limitation.virtual_cpu, quota_limitation.mem_size_mb,
        vm_static.quota_id, vds_groups.vds_group_id, vm_static.vds_group_id, quota_limitation.id;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS all_storage_usage_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE all_storage_usage_rs AS (
        quota_storage_id uuid,
        quota_id uuid,
        storage_id uuid,
        storage_name character varying(250),
        storage_size_gb bigint,
        storage_size_gb_usage double precision
);
**************************

CREATE TYPE
********* QUERY **********
CREATE OR REPLACE FUNCTION calculateAllStorageUsage()
RETURNS SETOF all_storage_usage_rs STABLE
AS $function$
BEGIN
    -- Summarize size of all disks that are active.
    RETURN QUERY SELECT
        quota_limitation.id AS quota_storage_id,
        quota_limitation.quota_id as quota_id,
        quota_limitation.storage_id as storage_id,
        storage_domain_static.storage_name,
        quota_limitation.storage_size_gb,
        cast(COALESCE(sum(size * cast(active as integer) + disk_image_dynamic.actual_size * cast((not active) as integer)) / 1073741824 ,0) as double precision)  as storage_usage -- 1073741824 is 1024^3 (for GB)
    FROM quota_limitation
        LEFT JOIN image_storage_domain_map ON quota_limitation.quota_id = image_storage_domain_map.quota_id
        LEFT JOIN images ON images.image_guid = image_storage_domain_map.image_id
        LEFT JOIN disk_image_dynamic ON images.image_guid = disk_image_dynamic.image_id
        LEFT JOIN storage_domain_static ON image_storage_domain_map.storage_domain_id = storage_domain_static.id
    WHERE quota_limitation.storage_size_gb IS NOT NULL
    GROUP BY quota_limitation.quota_id, storage_id,quota_limitation.id,storage_domain_static.storage_name,quota_limitation.storage_size_gb;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CalculateStorageUsage(v_quota_id UUID, v_storage_id UUID)
RETURNS double precision STABLE
AS $function$
DECLARE
	v_virtual_size double precision;
	v_actual_size double precision;
BEGIN
	-- Summarize size of all disks that are active.
    SELECT COALESCE(sum(size) / (1024 * 1024 * 1024),0) INTO v_virtual_size
	FROM disk_image_dynamic, images_storage_domain_view
	WHERE image_guid = disk_image_dynamic.image_id
    AND image_guid in (SELECT image_guid FROM  images WHERE  active = TRUE)
	AND quota_id = v_quota_id
    AND (v_storage_id = images_storage_domain_view.storage_id or v_storage_id IS NULL);

	-- Summarize the actual size of all the rest disks that are read only disks such as snapshots, not active, template disks.
	SELECT COALESCE(sum(disk_image_dynamic.actual_size) / (1024 * 1024 * 1024),0) INTO v_actual_size
	FROM disk_image_dynamic, images_storage_domain_view
	WHERE image_guid = disk_image_dynamic.image_id
    AND image_guid not in (SELECT image_guid
                           FROM   images i JOIN vm_device vd ON i.image_group_id = vd.device_id
                           WHERE  active = TRUE)
	AND quota_id = v_quota_id
	AND (v_storage_id = images_storage_domain_view.storage_id or v_storage_id IS NULL);
	RETURN v_actual_size + v_virtual_size;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function create_uuid_sequence() returns void
as $procedure$
begin
  if not exists (select 1 from information_schema.sequences where sequence_name = 'uuid_sequence') then
    create sequence uuid_sequence increment by 1 start with 1;
  end if;
end; $procedure$
language plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select create_uuid_sequence();
**************************

 

********* QUERY **********
drop function create_uuid_sequence();
**************************

DROP FUNCTION
********* QUERY **********
create or replace function uuid_generate_v1() returns uuid STABLE
as $procedure$
declare
    v_val bigint;
    v_4_part char(4);
    v_8_part char(8);
    v_12_part char(12);
    v_4_part_max int;
begin
    -- The only part we should use modulo is the 4 digit part, all the
    -- rest are really big numbers (i.e 16^8 - 1 and 16^12 - 1)
    -- The use of round(random() * 1000 is for getting a different id
    -- for DC/Cluster in different installations
    v_4_part_max = 65535; -- this is 16^4 -1
    v_val := nextval('uuid_sequence');
    v_4_part := lpad(to_hex(v_val % v_4_part_max), 4, '0');
    v_8_part := lpad(to_hex(v_val), 8, '0');
    v_12_part := lpad(to_hex((v_val + (round(random() * 1000))::bigint)), 12, '0');
    return v_8_part || v_4_part || v_4_part || v_4_part || v_12_part;
end; $procedure$
language plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_get_comparable_ip_list(text) RETURNS inet[] IMMUTABLE STRICT
AS $procedure$
BEGIN
CASE
    WHEN ($1 IS NULL) OR ($1 ~ E'^\s*$') THEN
        RETURN NULL;
    ELSE
        RETURN regexp_split_to_array(trim(both from $1), E'\s+')::inet[];
END CASE;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_add_column(v_table varchar(128), v_column varchar(128), v_column_def text)
returns void
AS $procedure$
declare
v_sql text;

begin
	if (not exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ADD COLUMN ' || v_column || ' ' || v_column_def;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_drop_column(v_table varchar(128), v_column varchar(128))
returns void
AS $procedure$
declare
v_sql text;
begin
        if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
            begin
                v_sql := 'ALTER TABLE ' || v_table || ' DROP COLUMN ' || v_column;
                EXECUTE v_sql;
            end;
        end if;
end;$procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_change_column_type(v_table varchar(128), v_column varchar(128),
                                                    v_type varchar(128), v_new_type varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column and (udt_name ilike v_type or data_type ilike v_type))) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ALTER COLUMN ' || v_column || ' TYPE ' || v_new_type;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_rename_column(v_table varchar(128), v_column varchar(128), v_new_name varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' RENAME COLUMN ' || v_column || ' TO ' || v_new_name;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (not exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            insert into vdc_options (option_name, option_value, version) values (v_option_name, v_option_value, v_version);
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value_all_versions(v_option_name varchar(100))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name)) then
        begin
            delete from vdc_options where option_name ilike v_option_name;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value(v_option_name varchar(100), v_version text)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version)))) then
        begin
            delete from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version));
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_for_version(v_version text)
returns void
AS $procedure$
BEGIN
     delete from vdc_options where version in (select ID from fnSplitter(v_version));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            update  vdc_options set option_value = v_option_value
            where option_name ilike v_option_name and version = v_version;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_default_config_value(v_option_name varchar(100),v_default_option_value varchar(4000),v_option_value varchar(4000),v_version varchar(40),v_ignore_default_value_case boolean)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            if (v_ignore_default_value_case)
            then
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value ilike v_default_option_value and version = v_version;
            else
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value = v_default_option_value and version = v_version;
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_rename_config_key(v_old_option_name varchar(100),v_new_option_name varchar(100),v_version varchar(40))
returns void
AS $procedure$
DECLARE
    v_current_option_value varchar(4000);
begin
    if (exists (select 1 from vdc_options where option_name ilike v_old_option_name and version = v_version)) then
       v_current_option_value:=option_value from vdc_options where option_name ilike v_old_option_name and version = v_version;
       update vdc_options set option_name = v_new_option_name, option_value = v_current_option_value
           where  option_name ilike v_old_option_name and version = v_version;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_create_constraint (
    v_table varchar(128), v_constraint varchar(128), v_constraint_sql text)
returns void
AS $procedure$
begin
    if  NOT EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' ADD CONSTRAINT ' || v_constraint || ' ' || v_constraint_sql;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_drop_constraint (
    v_table varchar(128), v_constraint varchar(128))
returns void
AS $procedure$
begin
    if  EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' DROP CONSTRAINT ' || v_constraint || ' CASCADE';
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION CheckDBConnection() RETURNS SETOF integer IMMUTABLE
   AS $procedure$
BEGIN
    RETURN QUERY SELECT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_functions_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'drop function if exists ' || ns.nspname || '.' || proname || '(' || oidvectortypes(proargtypes) || ') cascade;' from pg_proc inner join pg_namespace ns on (pg_proc.pronamespace=ns.oid) where ns.nspname = 'public' order by proname;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_views_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP VIEW if exists ' || table_name || ' CASCADE;' from information_schema.views where table_schema = 'public' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_tables_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP TABLE if exists ' || table_name || ' CASCADE;' from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_seq_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP SEQUENCE if exists ' || sequence_name || ' CASCADE;' from information_schema.sequences  where sequence_schema = 'public' order by sequence_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_user_types_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT 'DROP TYPE if exists ' || c.relname::information_schema.sql_identifier || ' CASCADE;'
   FROM pg_namespace n, pg_class c, pg_type t
   WHERE n.oid = c.relnamespace and t.typrelid = c.oid and c.relkind = 'c'::"char" and
   n.nspname = 'public'
   ORDER BY  c.relname::information_schema.sql_identifier;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_get_column_size( v_table varchar(64), v_column varchar(64)) returns integer STABLE
   AS $procedure$
   declare
   retvalue  integer;
BEGIN
   retvalue := character_maximum_length from information_schema.columns
    where
    table_name ilike v_table and column_name ilike v_column and
    table_schema = 'public' and udt_name in ('char','varchar');
   return retvalue;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION attach_user_to_role (
    v_domain_entry_id text,
    v_user_name VARCHAR(255),
    v_domain VARCHAR(255),
    v_role_name VARCHAR(255)
)
RETURNS void AS
$BODY$
DECLARE
   gen_user_id uuid;
   input_role_id uuid;
BEGIN
   select uuid_generate_v1() into gen_user_id;
   select roles.id into input_role_id from roles where roles.name = v_role_name;
   -- The external identifier is the user identifier converted to an array of
   -- bytes:
   insert into users(user_id,external_id,name,domain,username,groups,active,last_admin_check_status) select gen_user_id, v_domain_entry_id, v_user_name, v_domain, v_user_name,'',true,true where not exists (select gen_user_id,name,domain,username,groups,active from users where external_id = v_domain_entry_id);
   insert into permissions(id,role_id,ad_element_id,object_id,object_type_id) select uuid_generate_v1(),  input_role_id, gen_user_id, getGlobalIds('system'), 1 where not exists(select role_id,ad_element_id,object_id,object_type_id from permissions where role_id = input_role_id and ad_element_id = gen_user_id and object_id= getGlobalIds('system') and object_type_id = 1);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_add_action_group_to_role(v_role_id UUID, v_action_group_id INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
       INSERT INTO roles_groups(role_id,action_group_id)
       SELECT v_role_id, v_action_group_id
       WHERE NOT EXISTS (SELECT 1
                         FROM roles_groups
                         WHERE role_id = v_role_id
                         AND action_group_id = v_action_group_id);
RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_split_config_value(v_option_name character varying, v_old_option_value character varying, v_new_option_value character varying, v_update_from_version character varying)
  RETURNS void AS
$BODY$
declare
v_old_value varchar(4000);
v_cur cursor for select distinct version from vdc_options where version <> 'general' order by version;
v_version varchar(40);
v_index integer;
v_count integer;
v_total_count integer;
v_version_count integer;
begin
    v_total_count := count(version) from vdc_options where option_name = v_option_name;
    v_old_value := option_value from vdc_options where option_name = v_option_name and version = 'general';
    v_version_count := count(distinct version) from vdc_options where version <> 'general';
    if (v_total_count <= v_version_count) then
        begin
            if (v_old_value IS NULL) then
                v_old_value := v_old_option_value;
            end if;
            v_count := count(distinct version) from vdc_options where version <> 'general';
            v_index := 1;
        open v_cur;
        loop
            fetch v_cur into v_version;
            exit when not found;
            -- We shouldn't update if already exists
            if (not exists (select 1 from vdc_options where option_name = v_option_name and version = v_version)) then
                -- Might not work well for versions such as 3.10, but we currently don't have any
                if (v_version >= v_update_from_version) then
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_new_option_value, v_version);
                else
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_old_value, v_version);
                end if;
            end if;
            v_index := v_index +1;
        end loop;
        close v_cur;
        delete from vdc_options where option_name = v_option_name and version = 'general';
        end;
    end if;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_grant_action_group_to_all_roles_filter(v_action_group_id integer, uuid[])
  RETURNS void AS
$BODY$
declare
v_role_id_to_filter alias for $2;
begin
    insert into roles_groups (role_id, action_group_id)
    select distinct role_id, v_action_group_id
    from roles_groups rg
    where not ARRAY [role_id] <@ v_role_id_to_filter and not exists (select 1 from roles_groups where role_id = rg.role_id and action_group_id = v_action_group_id);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_mask_object(v_object regclass) RETURNS setof record as
$BODY$
DECLARE
    v_sql TEXT;
    v_table record;
    v_table_name TEXT;
    temprec record;
BEGIN
    -- get full table/view name from v_object (i.e <namespace>.<name>)
    select c.relname, n.nspname INTO v_table
        FROM pg_class c join pg_namespace n on c.relnamespace = n.oid WHERE c.oid = v_object;
    -- try to get filtered query syntax from previous execution
    if exists (select 1 from object_column_white_list_sql where object_name = v_table.relname) then
	select sql into v_sql from object_column_white_list_sql where object_name = v_table.relname;
    else
        v_table_name := quote_ident( v_table.nspname ) || '.' || quote_ident( v_table.relname );
        -- compose sql statement while skipping values for columns not defined in object_column_white_list for this table.
        for temprec in select a.attname, t.typname
                       FROM pg_attribute a join pg_type t on a.atttypid = t.oid
                       WHERE a.attrelid = v_object AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
        loop
            v_sql := coalesce( v_sql || ', ', 'SELECT ' );
            if exists(select 1 from object_column_white_list
               where object_name = v_table.relname and column_name = temprec.attname) then
               v_sql := v_sql || quote_ident( temprec.attname );
            ELSE
               v_sql := v_sql || 'NULL::' || quote_ident( temprec.typname ) || ' as ' || quote_ident( temprec.attname );
            END IF;
        END LOOP;
        v_sql := v_sql || ' FROM ' || v_table_name;
        v_sql := 'SELECT x::' || v_table_name || ' as rec FROM (' || v_sql || ') as x';
        -- save generated query for further use
        insert into object_column_white_list_sql(object_name,sql) values (v_table.relname, v_sql);
    end if;
    RETURN QUERY EXECUTE v_sql;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_column_to_object_white_list(v_object_name varchar(128), v_column_name varchar(128))
returns void
AS $procedure$
begin
    if (not exists (select 1 from object_column_white_list
                    where object_name = v_object_name and column_name = v_column_name)) then
        begin
            -- verify that there is such object in db
            if exists (select 1 from information_schema.columns
                       where table_name = v_object_name and column_name = v_column_name) then
                insert into object_column_white_list (object_name, column_name) values (v_object_name, v_column_name);
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_disk(v_id UUID)
returns void
AS $procedure$
declare
    OK integer;
    LOCKED integer;
begin
    OK:=1;
    LOCKED:=2;
    update images set imagestatus = OK where imagestatus = LOCKED and
    image_group_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_snapshot(v_id UUID)
returns void
AS $procedure$
declare
    OK varchar;
    LOCKED varchar;
begin
    OK:='OK';
    LOCKED:='LOCKED';
    update snapshots set status = OK where status = LOCKED and snapshot_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_entity(v_object_type varchar(10), v_name varchar(255), v_recursive boolean)
returns void
AS $procedure$
declare
    DOWN integer;
    OK integer;
    LOCKED integer;
    TEMPLATE_OK integer;
    TEMPLATE_LOCKED integer;
    IMAGE_LOCKED integer;
    SNAPSHOT_OK varchar;
    SNAPSHOT_LOCKED varchar;
    v_id UUID;
begin
    DOWN:=0;
    OK:=1;
    LOCKED:=2;
    TEMPLATE_OK:=0;
    TEMPLATE_LOCKED:=1;
    IMAGE_LOCKED:=15;
    SNAPSHOT_OK:='OK';
    SNAPSHOT_LOCKED:='LOCKED';
    v_id := vm_guid from vm_static where vm_name = v_name and entity_type ilike v_object_type;
    -- set VM status to DOWN
    if (v_object_type = 'vm') then
        update vm_dynamic set status = DOWN where status = IMAGE_LOCKED and vm_guid  = v_id;
    -- set Template status to OK
    else
        if (v_object_type = 'template') then
            update vm_static set template_status = TEMPLATE_OK where template_status = TEMPLATE_LOCKED and vm_guid  = v_id;
        end if;
    end if;
    --unlock images and snapshots  if recursive flag is set
    if (v_recursive) then
        update images set imagestatus = OK where imagestatus = LOCKED and
        image_group_id in (select device_id from vm_device where vm_id = v_id and is_plugged);

        update snapshots set status = SNAPSHOT_OK where status ilike SNAPSHOT_LOCKED and vm_id = v_id;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/* Displays DC id , DC name, SPM Host id , SPM Host name and number of async tasks awaiting.

1) create a record type with DC name, DC id, SPM host id, SPM host name, count

2) get all distinct DC ids from async_tasks table

3) Run a cursor for each result in 2)

   a) get DC name
   b) get SPM Host id & name if available
   c) get count of tasks

   return current record

4) return set of generated records
*/
DROP TYPE IF EXISTS async_tasks_info_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE async_tasks_info_rs AS (
        dc_id uuid,
        dc_name character varying,
        spm_host_id uuid,
        spm_host_name character varying,
        task_count integer
);
**************************

CREATE TYPE
********* QUERY **********
create or replace FUNCTION fn_db_get_async_tasks()
returns SETOF async_tasks_info_rs STABLE
AS $procedure$
DECLARE
    v_record async_tasks_info_rs;

    -- selects storage_pool_id uuid found in async_tasks
    v_tasks_cursor cursor for select distinct storage_pool_id from async_tasks;
begin

    OPEN v_tasks_cursor;
    FETCH v_tasks_cursor into v_record.dc_id;
    WHILE FOUND LOOP
        -- get dc_name and SPM Host id
        v_record.dc_name := name from storage_pool where id = v_record.dc_id;
        v_record.spm_host_id :=
            spm_vds_id from storage_pool where id = v_record.dc_id;
        -- get Host name if we have non NULL SPM Host
        if (v_record.spm_host_id IS NOT NULL) then
            v_record.spm_host_name :=
                vds_name from vds_static where vds_id = v_record.spm_host_id;
        else
            v_record.spm_host_name:='';
        end if;
        -- get tasks count for this DC
        v_record.task_count := count(*) from async_tasks
            where position (cast(v_record.dc_id as varchar) in action_parameters) > 0;
        -- return the record
        RETURN NEXT v_record;
        FETCH v_tasks_cursor into v_record.dc_id;
    END LOOP;
    CLOSE v_tasks_cursor;
    -- return full set of generated records
    RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_remove_csv_config_value(v_option_name varchar(100), v_value varchar(4000), v_version varchar(40))
returns void
AS $procedure$
DECLARE
v varchar[];
e varchar;
v_result varchar;
v_sep varchar(1);
BEGIN
v_result := '';
v_sep := '';
    v := string_to_array(option_value, ',') from vdc_options where option_name = v_option_name and version = v_version;
    FOR e in select unnest(v)
    LOOP
        IF (e != v_value) THEN
            v_result := v_result || v_sep || e;
            v_sep := ',';
        END IF;
    END LOOP;
    UPDATE vdc_options set option_value = v_result where option_name = v_option_name and version = v_version;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
INSERT INTO vdc_options(option_name, option_value, version) values ('AutoRegistrationDefaultVdsGroupID', uuid_generate_v1(),'general');
**************************

INSERT 0 1
********* QUERY **********
Create or replace FUNCTION insert_data()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_id_0000 UUID;
   v_storage_pool_id UUID;
   v_cluster_id UUID;
   v_id_0009 UUID;
BEGIN
   v_id_0000 := '00000000-0000-0000-0000-000000000000';
   v_storage_pool_id := uuid_generate_v1();
   v_cluster_id := option_value from vdc_options where option_name = 'AutoRegistrationDefaultVdsGroupID' and version = 'general';
   v_id_0009 := '00000000-0000-0000-0000-000000000009';


-- INSERT DATA to schema_version
INSERT INTO schema_version(version,script,checksum,installed_by,ended_at,state,current)
  values ('03030000','upgrade/03_03_0000_set_version.sql','0','engine',now(),'INSTALLED',true);

-- INSERT everyone TO ad_groups
INSERT into ad_groups (id,name,status,domain,distinguishedname)
 SELECT getGlobalIds('everyone'),
 'Everyone',
 1,
 '',
 ''
where not exists (
 SELECT id from ad_groups where id = getGlobalIds('everyone'));

--INSERTING DATA INTO TABLE storage_pool

INSERT INTO storage_pool (id,name,description,storage_pool_type,status,master_domain_version,compatibility_version) select v_storage_pool_id,'Default','The default Data Center',1,0,0,'3.5';
--INSERTING DATA INTO TABLE vds_groups

INSERT INTO vds_groups (vds_group_id,name,description,storage_pool_id,compatibility_version,transparent_hugepages) select v_cluster_id,'Default','The default server cluster',v_storage_pool_id,'3.5',true;

--INSERTING DATA INTO NETWORK table

INSERT INTO network (id,name,description,storage_pool_id) SELECT v_id_0009, 'ovirtmgmt', 'Management Network', v_storage_pool_id;
INSERT INTO network_cluster (network_id, cluster_id, status) SELECT v_id_0009,v_cluster_id,1;

INSERT INTO vm_static (vm_guid, vm_name, mem_size_mb, vmt_guid, os, description, vds_group_id, domain, creation_date, num_of_monitors, is_initialized, is_auto_suspend, num_of_sockets, cpu_per_socket, usb_policy, time_zone, is_stateless, fail_back, _create_date, _update_date, dedicated_vm_for_vds, auto_startup, vm_type, nice_level, default_boot_sequence, default_display_type, priority, iso_path, origin, initrd_url, kernel_url, kernel_params, migration_support, userdefined_properties, predefined_properties, min_allocated_mem, entity_type, child_count, template_status, quota_id, allow_console_reconnect, cpu_pinning, is_smartcard_enabled) VALUES ('00000000-0000-0000-0000-000000000000', 'Blank', 1024, '00000000-0000-0000-0000-000000000000', 0, 'Blank template', v_cluster_id , '', '2008-04-01 00:00:00+03', 1, NULL, false, 1, 1, 1, NULL, NULL, false, '2013-12-25 15:31:54.367179+02', '2013-12-25 15:31:53.239308+02', NULL, NULL, 0, 0, 0, 0, 0, '', 0, NULL, NULL, NULL, 0, NULL, NULL, 0, 'TEMPLATE', 0, 0, NULL, false, NULL, false);


INSERT INTO event_map(event_up_name, event_down_name) values('VDC_STOP', 'VDC_START');

INSERT INTO event_map(event_up_name, event_down_name) values('IRS_FAILURE', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('IRS_DISK_SPACE_LOW', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('IRS_DISK_SPACE_LOW_ERROR', 'UNASSIGNED');

INSERT INTO event_map(event_up_name, event_down_name) values('VDS_FAILURE', 'VDS_ACTIVATE');
INSERT INTO event_map(event_up_name, event_down_name) values('USER_VDS_MAINTENANCE', 'VDS_ACTIVATE');
INSERT INTO event_map(event_up_name, event_down_name) values('USER_VDS_MAINTENANCE_MIGRATION_FAILED', 'USER_VDS_MAINTENANCE');
INSERT INTO event_map(event_up_name, event_down_name) values('VDS_ACTIVATE_FAILED', 'VDS_ACTIVATE');
INSERT INTO event_map(event_up_name, event_down_name) values('VDS_RECOVER_FAILED', 'VDS_RECOVER');
INSERT INTO event_map(event_up_name, event_down_name) values('VDS_SLOW_STORAGE_RESPONSE_TIME', 'VDS_ACTIVATE');
INSERT INTO event_map(event_up_name, event_down_name) values('VDS_APPROVE_FAILED', 'VDS_APPROVE');
INSERT INTO event_map(event_up_name, event_down_name) values('VDS_INSTALL_FAILED', 'VDS_INSTALL');

INSERT INTO event_map(event_up_name, event_down_name) values('VM_FAILURE', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('VM_MIGRATION_START', 'VM_MIGRATION_DONE');
INSERT INTO event_map(event_up_name, event_down_name) values('VM_MIGRATION_FAILED', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('VM_MIGRATION_FAILED_FROM_TO', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('VM_NOT_RESPONDING', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('DWH_STOPPED', 'DWH_STARTED');
INSERT INTO event_map(event_up_name, event_down_name) values('DWH_ERROR', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('VDS_TIME_DRIFT_ALERT', '');


INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_CREATE', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_CREATE_FAILED', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_START', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_START_FAILED', 'GLUSTER_VOLUME_START');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_STOP', 'GLUSTER_VOLUME_START');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_STOP_FAILED', 'GLUSTER_VOLUME_STOP');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_OPTION_SET', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_OPTION_SET_FAILED', 'GLUSTER_VOLUME_OPTION_SET');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_OPTIONS_RESET', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_OPTIONS_RESET_FAILED', 'GLUSTER_VOLUME_OPTIONS_RESET');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_DELETE', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_DELETE_FAILED', 'GLUSTER_VOLUME_DELETE');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REBALANCE_START', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REBALANCE_START_FAILED', 'GLUSTER_VOLUME_REBALANCE_START');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REMOVE_BRICKS', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REMOVE_BRICKS_FAILED', 'GLUSTER_VOLUME_REMOVE_BRICKS');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REPLACE_BRICK_FAILED', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REPLACE_BRICK_START', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REPLACE_BRICK_START_FAILED', 'GLUSTER_VOLUME_REPLACE_BRICK_START');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_ADD_BRICK', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_ADD_BRICK_FAILED', 'GLUSTER_VOLUME_ADD_BRICK');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_SERVER_REMOVE_FAILED', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_SERVER_ADD_FAILED', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_CREATED_FROM_CLI', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_DELETED_FROM_CLI', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_OPTION_SET_FROM_CLI', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_OPTION_RESET_FROM_CLI', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_PROPERTIES_CHANGED_FROM_CLI', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_BRICK_ADDED_FROM_CLI', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_BRICK_REMOVED_FROM_CLI', 'UNASSIGNED');
INSERT INTO event_map(event_up_name, event_down_name) values('GLUSTER_SERVER_REMOVED_FROM_CLI', 'UNASSIGNED');
insert into event_map(event_up_name, event_down_name) values('HA_VM_RESTART_FAILED', '');
insert into event_map(event_up_name, event_down_name) values('HA_VM_FAILED', '');
insert into event_map(event_up_name, event_down_name) values('SYSTEM_DEACTIVATED_STORAGE_DOMAIN', '');
insert into event_map(event_up_name, event_down_name) values('VDS_SET_NONOPERATIONAL', '');
insert into event_map(event_up_name, event_down_name) values('VDS_SET_NONOPERATIONAL_IFACE_DOWN', '');
insert into event_map(event_up_name, event_down_name) values('VDS_SET_NONOPERATIONAL_DOMAIN', '');
insert into event_map(event_up_name, event_down_name) values('SYSTEM_CHANGE_STORAGE_POOL_STATUS_NO_HOST_FOR_SPM', '');
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_STARTED_FROM_CLI', 'UNASSIGNED');
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_STOPPED_FROM_CLI', 'UNASSIGNED');
insert into event_map(event_up_name, event_down_name) values('VDS_HIGH_MEM_USE', '');
insert into event_map(event_up_name, event_down_name) values('VDS_HIGH_NETWORK_USE', '');
insert into event_map(event_up_name, event_down_name) values('VDS_HIGH_CPU_USE', '');
insert into event_map(event_up_name, event_down_name) values('VDS_HIGH_SWAP_USE', '');
insert into event_map(event_up_name, event_down_name) values('VDS_LOW_SWAP', '');
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_OPTION_CHANGED_FROM_CLI', 'UNASSIGNED');

INSERT INTO action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    SELECT 41, '3.1', '3.1';

INSERT INTO action_version_map values(158, '3.1','3.0');
INSERT INTO action_version_map (action_type,cluster_minimal_version,storage_pool_minimal_version) values (52,'3.1','3.1');
INSERT INTO action_version_map values(1009, '3.1','*');



INSERT INTO images (image_guid, creation_date, size, it_guid, parentid, imagestatus, lastmodified, vm_snapshot_id, volume_type, volume_format, image_group_id, _create_date, _update_date, quota_id, active) VALUES ('00000000-0000-0000-0000-000000000000', '2008-04-01 00:00:00+03', 85899345920, '00000000-0000-0000-0000-000000000000', NULL, 0, NULL, NULL, 2, 4, NULL, '2013-12-25 15:31:57.219114+02', NULL, NULL, true);

INSERT INTO vm_device (device_id, vm_id, type, device, address, boot_order, spec_params, is_managed, is_plugged, is_readonly, _create_date, _update_date, alias) VALUES ('00000006-0006-0006-0006-000000000006', '00000000-0000-0000-0000-000000000000', 'video', 'cirrus', '', NULL, '{ "vram" : "65536" }', true, NULL, false, '2013-12-25 22:54:23.416857+02', NULL, '');

-- Inserting data to history timekeeping
Insert into dwh_history_timekeeping  VALUES('lastSync',NULL,to_timestamp('01/01/2000', 'DD/MM/YYYY'));

--OVF
INSERT INTO vm_ovf_generations
      (SELECT vm.vm_guid, sp.id, 1
       FROM vm_static vm ,storage_pool sp, vds_groups vg
       WHERE vg.storage_pool_id = sp.id AND vm.vds_group_id = vg.vds_group_id);


RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT insert_data();
**************************

 

********* QUERY **********
drop function insert_data();
**************************

DROP FUNCTION
********* QUERY **********
/******************************************************************************************************
                                         DWH DATA
******************************************************************************************************/

Insert into dwh_history_timekeeping  SELECT 'lastFullHostCheck',NULL,to_timestamp('01/01/2000', 'DD/MM/YYYY');
**************************

INSERT 0 1
********* QUERY **********
Create or replace FUNCTION insert_predefined_roles()
RETURNS VOID
   AS $procedure$
   DECLARE
   --Roles
   v_SUPER_USER_ID UUID;
   v_POWER_USER_ID UUID;
   v_USER_ID UUID;
   v_CLUSTER_ADMIN_ID UUID;
   v_DATA_CENTER_ADMIN_ID UUID;
   v_STORAGE_ADMIN_ID UUID;
   v_HOST_ADMIN_ID UUID;
   v_NETWORK_ADMIN_ID UUID;
   v_VM_ADMIN_ID UUID;
   v_VM_POOL_ADMIN_ID UUID;
   v_TEMPLATE_ADMIN_ID UUID;
   v_TEMPLATE_USER_ID UUID;
   v_QUOTA_CONSUMER_USER_ID UUID;
   v_DISK_OPERATOR_USER_ID UUID;
   v_DISK_CREATOR_USER_ID UUID;
   v_GLUSTER_ADMIN_ROLE_ID UUID;
   v_VM_CREATOR_USER_ID UUID;
   v_TEMPLATE_CREATOR_USER_ID UUID;
   v_TEMPLATE_OWNER_USER_ID UUID;
   v_LOCAL_ADMIN_ID UUID;
   v_NETWORK_USER_ID UUID;
   v_EXTERNAL_EVENT_CREATOR_ID UUID;
   --Permissions
   v_CREATE_VM INTEGER;
   v_DELETE_VM INTEGER;
   v_EDIT_VM_PROPERTIES INTEGER;
   v_VM_BASIC_OPERATIONS INTEGER;
   v_CHANGE_VM_CD INTEGER;
   v_MIGRATE_VM INTEGER;
   v_CONNECT_TO_VM INTEGER;
   v_IMPORT_EXPORT_VM INTEGER;
   v_CONFIGURE_VM_NETWORK INTEGER;
   v_CONFIGURE_VM_STORAGE INTEGER;
   v_MOVE_VM INTEGER;
   v_MANIPULATE_VM_SNAPSHOTS INTEGER;
   v_FORCE_CONNECT_VM INTEGER;
   v_CUSTOM_PROPERTIES INTEGER;
   v_CREATE_HOST INTEGER;
   v_EDIT_HOST_CONFIGURATION INTEGER;
   v_DELETE_HOST INTEGER;
   v_MANIPULATE_HOST INTEGER;
   v_CONFIGURE_HOST_NETWORK INTEGER;
   v_CREATE_TEMPLATE INTEGER;
   v_EDIT_TEMPLATE_PROPERTIES INTEGER;
   v_DELETE_TEMPLATE INTEGER;
   v_COPY_TEMPLATE INTEGER;
   v_CONFIGURE_TEMPLATE_NETWORK INTEGER;
   v_CREATE_VM_POOL INTEGER;
   v_EDIT_VM_POOL_CONFIGURATION INTEGER;
   v_DELETE_VM_POOL INTEGER;
   v_VM_POOL_BASIC_OPERATIONS INTEGER;
   v_CREATE_CLUSTER INTEGER;
   v_EDIT_CLUSTER_CONFIGURATION INTEGER;
   v_DELETE_CLUSTER INTEGER;
   v_ASSIGN_CLUSTER_NETWORK INTEGER;
   v_CONFIGURE_CLUSTER_NETWORK INTEGER;
   v_MANIPULATE_USERS INTEGER;
   v_MANIPULATE_ROLES INTEGER;
   v_MANIPULATE_PERMISSIONS INTEGER;
   v_EDIT_STORAGE_DOMAIN_CONFIGURATION INTEGER;
   v_DELETE_STORAGE_DOMAIN INTEGER;
   v_MANIPULATE_STORAGE_DOMAIN INTEGER;
   v_CREATE_STORAGE_POOL INTEGER;
   v_DELETE_STORAGE_POOL INTEGER;
   v_EDIT_STORAGE_POOL_CONFIGURATION INTEGER;
   v_CONFIGURE_STORAGE_POOL_NETWORK INTEGER;
   v_CREATE_STORAGE_POOL_NETWORK INTEGER;
   v_DELETE_STORAGE_POOL_NETWORK INTEGER;
   v_CONFIGURE_ENGINE INTEGER;
   v_MANIPULATE_QUOTA INTEGER;
   v_CONSUME_QUOTA INTEGER;
   v_CREATE_GLUSTER_VOLUME INTEGER;
   v_MANIPULATE_GLUSTER_VOLUME INTEGER;
   v_DELETE_GLUSTER_VOLUME INTEGER;
   v_CREATE_STORAGE_DOMAIN INTEGER;
   v_LIVE_MIGRATE_DISK INTEGER;
   v_LIVE_MIGRATE_DISKS INTEGER;
   v_CREATE_DISK INTEGER;
   v_ATTACH_DISK INTEGER;
   v_EDIT_DISK_PROPERTIES INTEGER;
   v_CONFIGURE_DISK_STORAGE INTEGER;
   v_DELETE_DISK INTEGER;
   v_CONFIGURE_STORAGE_POOL_VM_INTERFACE INTEGER;
   v_LOGIN INTEGER;
   v_EXTERNAL_EVENT_INJECTION INTEGER;
   -- Action Types
   v_CREATE_GLUSTER_VOLUME_BRICKS INTEGER;
   v_SET_GLUSTER_VOLUME INTEGER;
   v_START_GLUSTER_VOLUME INTEGER;
   v_STOP_GLUSTER_VOLUME INTEGER;
   v_RESET_GLUSTER_VOLUME INTEGER;
   v_DELETE_GLUSTER_VOLUME_BRICKS INTEGER;
   v_REMOVE_GLUTER_VOLUME_BRICKS INTEGER;
   v_REBALANCE_GLUSTER_VOLUME INTEGER;
   v_REPLACE_GLUSTER_VOLUME_BRICKS INTEGER;
   v_ADD_GLUSTER_VOLUME_BRICKS INTEGER;
   v_START_GLUSTER_VOLUME_PROFILE INTEGER;
   v_STOP_LUSTER_VOLUME_PROFILE INTEGER;
   v_REMOVE_GLUSTER_SERVER INTEGER;

   --Other
   v_ADMIN_USER_ID UUID;

BEGIN
   v_SUPER_USER_ID := '00000000-0000-0000-0000-000000000001';
   v_POWER_USER_ID := '00000000-0000-0000-0001-000000000002';
   v_USER_ID := '00000000-0000-0000-0001-000000000001';
   v_CLUSTER_ADMIN_ID := 'DEF00001-0000-0000-0000-DEF000000001';
   v_DATA_CENTER_ADMIN_ID := 'DEF00002-0000-0000-0000-DEF000000002';
   v_STORAGE_ADMIN_ID := 'DEF00003-0000-0000-0000-DEF000000003';
   v_HOST_ADMIN_ID := 'DEF00004-0000-0000-0000-DEF000000004';
   v_NETWORK_ADMIN_ID := 'DEF00005-0000-0000-0000-DEF000000005';
   v_VM_ADMIN_ID := 'DEF00006-0000-0000-0000-DEF000000006';
   v_VM_POOL_ADMIN_ID := 'DEF00007-0000-0000-0000-DEF000000007';
   v_TEMPLATE_ADMIN_ID := 'DEF00008-0000-0000-0000-DEF000000008';
   v_TEMPLATE_USER_ID := 'DEF00009-0000-0000-0000-DEF000000009';
   v_QUOTA_CONSUMER_USER_ID := 'DEF0000a-0000-0000-0000-DEF00000000a';
   v_DISK_OPERATOR_USER_ID := 'DEF0000A-0000-0000-0000-DEF00000000B';
   v_DISK_CREATOR_USER_ID := 'DEF0000A-0000-0000-0000-DEF00000000C';
   v_GLUSTER_ADMIN_ROLE_ID := 'DEF0000B-0000-0000-0000-DEF00000000B';
   v_VM_CREATOR_USER_ID := 'DEF0000A-0000-0000-0000-DEF00000000D';
   v_TEMPLATE_CREATOR_USER_ID := 'DEF0000A-0000-0000-0000-DEF00000000E';
   v_TEMPLATE_OWNER_USER_ID := 'DEF0000A-0000-0000-0000-DEF00000000F';
   v_LOCAL_ADMIN_ID := 'FDFC627C-D875-11E0-90F0-83DF133B58CC';
   v_NETWORK_USER_ID := 'DEF0000A-0000-0000-0000-DEF000000010';
   v_EXTERNAL_EVENT_CREATOR_ID := 'DEF0000C-0000-0000-0000-DEF000000000';
   v_CREATE_VM := 1;
   v_DELETE_VM := 2;
   v_EDIT_VM_PROPERTIES := 3;
   v_VM_BASIC_OPERATIONS := 4;
   v_CHANGE_VM_CD := 5;
   v_MIGRATE_VM := 6;
   v_CONNECT_TO_VM := 7;
   v_IMPORT_EXPORT_VM := 8;
   v_CONFIGURE_VM_NETWORK := 9;
   v_CONFIGURE_VM_STORAGE := 10;
   v_MOVE_VM := 11;
   v_MANIPULATE_VM_SNAPSHOTS := 12;
   v_FORCE_CONNECT_VM := 13;
   v_CUSTOM_PROPERTIES := 14;
   v_CREATE_HOST := 100;
   v_EDIT_HOST_CONFIGURATION := 101;
   v_DELETE_HOST := 102;
   v_MANIPULATE_HOST := 103;
   v_CONFIGURE_HOST_NETWORK := 104;
   v_CREATE_TEMPLATE := 200;
   v_EDIT_TEMPLATE_PROPERTIES := 201;
   v_DELETE_TEMPLATE := 202;
   v_COPY_TEMPLATE := 203;
   v_CONFIGURE_TEMPLATE_NETWORK := 204;
   v_CREATE_VM_POOL := 300;
   v_EDIT_VM_POOL_CONFIGURATION := 301;
   v_DELETE_VM_POOL := 302;
   v_VM_POOL_BASIC_OPERATIONS := 303;
   v_CREATE_CLUSTER := 400;
   v_EDIT_CLUSTER_CONFIGURATION := 401;
   v_DELETE_CLUSTER := 402;
   v_CONFIGURE_CLUSTER_NETWORK := 403;
   v_ASSIGN_CLUSTER_NETWORK := 404;
   v_MANIPULATE_USERS := 500;
   v_MANIPULATE_ROLES := 501;
   v_MANIPULATE_PERMISSIONS := 502;
   v_CREATE_STORAGE_DOMAIN := 600;
   v_EDIT_STORAGE_DOMAIN_CONFIGURATION := 601;
   v_DELETE_STORAGE_DOMAIN := 602;
   v_MANIPULATE_STORAGE_DOMAIN := 603;
   v_CREATE_STORAGE_POOL := 700;
   v_DELETE_STORAGE_POOL := 701;
   v_EDIT_STORAGE_POOL_CONFIGURATION := 702;
   v_CONFIGURE_STORAGE_POOL_NETWORK := 703;
   v_CREATE_STORAGE_POOL_NETWORK := 704;
   v_DELETE_STORAGE_POOL_NETWORK := 705;
   v_CONFIGURE_ENGINE := 800;
   v_MANIPULATE_QUOTA := 900;
   v_CONSUME_QUOTA := 901;
   v_CREATE_GLUSTER_VOLUME := 1000;
   v_MANIPULATE_GLUSTER_VOLUME := 1001;
   v_DELETE_GLUSTER_VOLUME := 1002;
   v_LIVE_MIGRATE_DISK := 1010;
   v_LIVE_MIGRATE_DISKS := 1011;
   v_CREATE_DISK := 1100;
   v_ATTACH_DISK := 1101;
   v_EDIT_DISK_PROPERTIES := 1102;
   v_CONFIGURE_DISK_STORAGE := 1103;
   v_DELETE_DISK := 1104;
   v_CONFIGURE_STORAGE_POOL_VM_INTERFACE := 1200;
   v_LOGIN := 1300;
   v_EXTERNAL_EVENT_INJECTION := 1500;
   -- Action Types
   v_CREATE_GLUSTER_VOLUME_BRICKS := 1400;
   v_SET_GLUSTER_VOLUME := 1401;
   v_START_GLUSTER_VOLUME := 1402;
   v_STOP_GLUSTER_VOLUME := 1403;
   v_RESET_GLUSTER_VOLUME := 1404;
   v_DELETE_GLUSTER_VOLUME_BRICKS := 1405;
   v_REMOVE_GLUTER_VOLUME_BRICKS := 1406;
   v_REBALANCE_GLUSTER_VOLUME := 1407;
   v_REPLACE_GLUSTER_VOLUME_BRICKS := 1408;
   v_ADD_GLUSTER_VOLUME_BRICKS := 1409;
   v_START_GLUSTER_VOLUME_PROFILE := 1410;
   v_STOP_LUSTER_VOLUME_PROFILE := 1411;
   v_REMOVE_GLUSTER_SERVER := 1412;



INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT  v_SUPER_USER_ID,'SuperUser','Roles management administrator',true,1,true;

---Vm Groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CREATE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_DELETE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_EDIT_VM_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_VM_BASIC_OPERATIONS);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CHANGE_VM_CD);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_MIGRATE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CONNECT_TO_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_IMPORT_EXPORT_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CONFIGURE_VM_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CONFIGURE_VM_STORAGE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_MOVE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_MANIPULATE_VM_SNAPSHOTS);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CREATE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_EDIT_HOST_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_DELETE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_MANIPULATE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CONFIGURE_HOST_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CREATE_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_EDIT_TEMPLATE_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_DELETE_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_COPY_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CONFIGURE_TEMPLATE_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CREATE_VM_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_EDIT_VM_POOL_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_DELETE_VM_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_VM_POOL_BASIC_OPERATIONS);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CREATE_CLUSTER);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_EDIT_CLUSTER_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_DELETE_CLUSTER);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CONFIGURE_CLUSTER_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_MANIPULATE_USERS);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_MANIPULATE_ROLES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_MANIPULATE_PERMISSIONS);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CREATE_STORAGE_DOMAIN);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_EDIT_STORAGE_DOMAIN_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_DELETE_STORAGE_DOMAIN);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_MANIPULATE_STORAGE_DOMAIN);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CREATE_STORAGE_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_DELETE_STORAGE_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_EDIT_STORAGE_POOL_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CONFIGURE_STORAGE_POOL_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CREATE_STORAGE_POOL_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_DELETE_STORAGE_POOL_NETWORK);
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_USER_ID,'UserRole','Standard User Role',true,2,true;
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CONFIGURE_ENGINE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_USER_ID,v_VM_BASIC_OPERATIONS);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_USER_ID,v_CHANGE_VM_CD);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_USER_ID,v_CONNECT_TO_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_USER_ID,v_VM_POOL_BASIC_OPERATIONS);

--PoewerUser role
---------------
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_POWER_USER_ID,'PowerUserRole','User Role, allowed to create VMs, Templates and Disks',true,2,false;


---Vm Groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_POWER_USER_ID,v_CREATE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_POWER_USER_ID,v_CREATE_TEMPLATE);

-------------
--CLUSTER_ADMIN role
---------------
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_CLUSTER_ADMIN_ID,'ClusterAdmin','Administrator Role, permission for all the objects underneath a specific Cluster',true,1,true;


---Vm Groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CREATE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_DELETE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_EDIT_VM_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_VM_BASIC_OPERATIONS);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CHANGE_VM_CD);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_MIGRATE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CONNECT_TO_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_IMPORT_EXPORT_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CONFIGURE_VM_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CONFIGURE_VM_STORAGE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_MOVE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_MANIPULATE_VM_SNAPSHOTS);
-- vm pools actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CREATE_VM_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_EDIT_VM_POOL_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_DELETE_VM_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_VM_POOL_BASIC_OPERATIONS);
-- host (vds) actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CREATE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_EDIT_HOST_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_DELETE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_MANIPULATE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CONFIGURE_HOST_NETWORK);
-- clusters actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CREATE_CLUSTER);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_EDIT_CLUSTER_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_DELETE_CLUSTER);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CONFIGURE_CLUSTER_NETWORK);

-------------
--DATA_CENTER_ADMIN role
---------------
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_DATA_CENTER_ADMIN_ID,'DataCenterAdmin','Administrator Role, permission for all the objects underneath a specific Data Center, except Storage',true,1,true;

---Vm Groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CREATE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_DELETE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_EDIT_VM_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_VM_BASIC_OPERATIONS);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CHANGE_VM_CD);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_MIGRATE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CONNECT_TO_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_IMPORT_EXPORT_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CONFIGURE_VM_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CONFIGURE_VM_STORAGE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_MOVE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_MANIPULATE_VM_SNAPSHOTS);
-- templates actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CREATE_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_EDIT_TEMPLATE_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_DELETE_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_COPY_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CONFIGURE_TEMPLATE_NETWORK);
-- vm pools actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CREATE_VM_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_EDIT_VM_POOL_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_DELETE_VM_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_VM_POOL_BASIC_OPERATIONS);
-- host (vds) actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CREATE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_EDIT_HOST_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_DELETE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_MANIPULATE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CONFIGURE_HOST_NETWORK);
-- clusters actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CREATE_CLUSTER);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_EDIT_CLUSTER_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_DELETE_CLUSTER);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CONFIGURE_CLUSTER_NETWORK);
-- storage pool actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CREATE_STORAGE_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_DELETE_STORAGE_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_EDIT_STORAGE_POOL_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CONFIGURE_STORAGE_POOL_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CREATE_STORAGE_POOL_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_DELETE_STORAGE_POOL_NETWORK);

-------------
--STORAGE_ADMIN role
---------------
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_STORAGE_ADMIN_ID,'StorageAdmin','Administrator Role, permission for all operations on a specific Storage Domain',true,1,true;

-- storage domains actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_STORAGE_ADMIN_ID,v_CREATE_STORAGE_DOMAIN);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_STORAGE_ADMIN_ID,v_EDIT_STORAGE_DOMAIN_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_STORAGE_ADMIN_ID,v_DELETE_STORAGE_DOMAIN);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_STORAGE_ADMIN_ID,v_MANIPULATE_STORAGE_DOMAIN);

-------------
--HOST_ADMIN role
---------------

INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_HOST_ADMIN_ID,'HostAdmin','Administrator Role, permission for all operations on a specific Host',true,1,true;

-- host (vds) actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_HOST_ADMIN_ID,v_CREATE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_HOST_ADMIN_ID,v_EDIT_HOST_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_HOST_ADMIN_ID,v_DELETE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_HOST_ADMIN_ID,v_MANIPULATE_HOST);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_HOST_ADMIN_ID,v_CONFIGURE_HOST_NETWORK);
-- storage domains actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_HOST_ADMIN_ID,v_CREATE_STORAGE_DOMAIN);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_HOST_ADMIN_ID,v_EDIT_STORAGE_DOMAIN_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_HOST_ADMIN_ID,v_DELETE_STORAGE_DOMAIN);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_HOST_ADMIN_ID,v_MANIPULATE_STORAGE_DOMAIN);


-------------
--NETWORK_ADMIN role
---------------

INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_NETWORK_ADMIN_ID,'NetworkAdmin','Administrator Role, permission for all operations on a specific Logical Network',true,1,true;
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_NETWORK_ADMIN_ID,v_CONFIGURE_HOST_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_NETWORK_ADMIN_ID,v_CONFIGURE_CLUSTER_NETWORK);

-------------
--VM_ADMIN role
---------------

INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_VM_ADMIN_ID,'UserVmManager','User Role, with permission for any operation on Vms',true,2,true;

-- insert local admin user to users table and assign superuser permissions
INSERT INTO users(user_id,name,domain,username,groups,status)
        SELECT v_LOCAL_ADMIN_ID, 'admin', 'internal', 'admin@internal','',1;

INSERT INTO permissions(id,role_id,ad_element_id,object_id,object_type_id)
        SELECT uuid_generate_v1(), v_SUPER_USER_ID, v_LOCAL_ADMIN_ID, getGlobalIds('system'), 1;

---Vm Groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_CREATE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_DELETE_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_EDIT_VM_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_VM_BASIC_OPERATIONS);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_CHANGE_VM_CD);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_CONNECT_TO_VM);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_CONFIGURE_VM_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_CONFIGURE_VM_STORAGE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_MANIPULATE_VM_SNAPSHOTS);

-------------
--VM_POOL_ADMIN role
---------------
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_VM_POOL_ADMIN_ID,'VmPoolAdmin','Administrator Role, permission for all operations on a specific VM Pool',true,1,true;

-- vm pools actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_POOL_ADMIN_ID,v_CREATE_VM_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_POOL_ADMIN_ID,v_EDIT_VM_POOL_CONFIGURATION);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_POOL_ADMIN_ID,v_DELETE_VM_POOL);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_POOL_ADMIN_ID,v_VM_POOL_BASIC_OPERATIONS);
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_TEMPLATE_ADMIN_ID,'TemplateAdmin','Administrator Role, permission for all operations on a specific Template',true,1,true;
-- templates actions groups
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_ADMIN_ID,v_CREATE_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_ADMIN_ID,v_EDIT_TEMPLATE_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_ADMIN_ID,v_DELETE_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_ADMIN_ID,v_COPY_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_ADMIN_ID,v_CONFIGURE_TEMPLATE_NETWORK);

-------------
--TEMPLATE_USER role
---------------
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_TEMPLATE_USER_ID,'TemplateUser','Template User',true,2,false;

INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_QUOTA_CONSUMER_USER_ID, 'QuotaConsumer','User Role, permissions to consume the Quota resources',true,2,false;

-- MAKE BLANK TEMPLATE PUBLIC
INSERT INTO permissions (id,role_id,ad_element_id,object_id,object_type_id)
 SELECT uuid_generate_v1(),
 v_TEMPLATE_USER_ID, -- TemplateUser
 getGlobalIds('everyone'),
 '00000000-0000-0000-0000-000000000000',    -- blank template id --
 4;                                          -- template object type id --

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_USER_ID,v_CREATE_VM);
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_DATA_CENTER_ADMIN_ID, v_MANIPULATE_QUOTA;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_SUPER_USER_ID, v_MANIPULATE_QUOTA;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_DATA_CENTER_ADMIN_ID, v_CONSUME_QUOTA;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_SUPER_USER_ID, v_CONSUME_QUOTA;
INSERT INTO roles_groups (role_id,action_group_id) SELECT v_SUPER_USER_ID, v_FORCE_CONNECT_VM;

-- Disks

-----------------
---SuperUser role
-----------------

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CREATE_DISK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_ATTACH_DISK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_EDIT_DISK_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_CONFIGURE_DISK_STORAGE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID,v_DELETE_DISK);


----------------
--PowerUser role
----------------

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_POWER_USER_ID,v_CREATE_DISK);

--------------------
--CLUSTER_ADMIN role
--------------------

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CREATE_DISK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_ATTACH_DISK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_EDIT_DISK_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_CONFIGURE_DISK_STORAGE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_CLUSTER_ADMIN_ID,v_DELETE_DISK);


------------------------
--DATA_CENTER_ADMIN role
------------------------

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CREATE_DISK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_ATTACH_DISK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_EDIT_DISK_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_CONFIGURE_DISK_STORAGE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID,v_DELETE_DISK);

--------------------
--STORAGE_ADMIN role
--------------------

-- CREATE_DISK
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_STORAGE_ADMIN_ID,v_CREATE_DISK);
-- ATTACH_DISK
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_STORAGE_ADMIN_ID,v_ATTACH_DISK);
-- EDIT_DISK_PROPERTIES
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_STORAGE_ADMIN_ID,v_EDIT_DISK_PROPERTIES);
-- CONFIGURE_DISK_STORAGE
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_STORAGE_ADMIN_ID,v_CONFIGURE_DISK_STORAGE);
-- DELETE_DISK
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_STORAGE_ADMIN_ID,v_DELETE_DISK);


---------------
--VM_ADMIN role
---------------

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_CREATE_DISK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_ATTACH_DISK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_EDIT_DISK_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_ADMIN_ID,v_DELETE_DISK);

--------------------------
-- DISK_OPERATOR_USER role
--------------------------
DELETE FROM roles_groups WHERE role_id = v_DISK_OPERATOR_USER_ID;
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_DISK_OPERATOR_USER_ID, 'DiskOperator', 'User Role, permissions for all operations on a specific disk', true, 2, true;

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DISK_OPERATOR_USER_ID,v_CREATE_DISK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DISK_OPERATOR_USER_ID,v_ATTACH_DISK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DISK_OPERATOR_USER_ID,v_EDIT_DISK_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DISK_OPERATOR_USER_ID,v_DELETE_DISK);

-------------------------
-- DISK_CREATOR_USER role
-------------------------
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_DISK_CREATOR_USER_ID, 'DiskCreator', 'User Role, permission to create Disks', true, 2, false;

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_DISK_CREATOR_USER_ID,v_CREATE_DISK);

-- Gluster

INSERT INTO roles_groups(role_id,action_group_id) SELECT v_SUPER_USER_ID, v_CREATE_GLUSTER_VOLUME;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_SUPER_USER_ID, v_MANIPULATE_GLUSTER_VOLUME;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_SUPER_USER_ID, v_DELETE_GLUSTER_VOLUME;

--------------
-- GLUSTER_ADMIN_USER role
--------------
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_GLUSTER_ADMIN_ROLE_ID, 'GlusterAdmin','Administrator Role, permissions for operations on Gluster objects',true,1,true;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, v_CREATE_GLUSTER_VOLUME;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, v_MANIPULATE_GLUSTER_VOLUME;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, v_DELETE_GLUSTER_VOLUME;


-------------------------
-- VM_CREATOR_USER role
-------------------------
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_VM_CREATOR_USER_ID, 'VmCreator', 'User Role, permission to create VMs', true, 2, false;
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_VM_CREATOR_USER_ID, v_CREATE_VM);


-----------------------------
-- TEMPALTE_CREATOR_USER role
-----------------------------
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_TEMPLATE_CREATOR_USER_ID, 'TemplateCreator', 'User Role, permission to create Templates', true, 2, false;

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_CREATOR_USER_ID, v_CREATE_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES( v_DATA_CENTER_ADMIN_ID, v_CONFIGURE_STORAGE_POOL_VM_INTERFACE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES( v_SUPER_USER_ID, v_CONFIGURE_STORAGE_POOL_VM_INTERFACE);

-----------------------------
-- TEMPALTE_OWNER_USER role
-----------------------------
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_TEMPLATE_OWNER_USER_ID, 'TemplateOwner', 'User Role, permissions for all operations on Templates', true, 2, true;

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_OWNER_USER_ID, v_EDIT_TEMPLATE_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_OWNER_USER_ID, v_DELETE_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_OWNER_USER_ID, v_COPY_TEMPLATE);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_OWNER_USER_ID, v_CONFIGURE_TEMPLATE_NETWORK);
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_TEMPLATE_OWNER_USER_ID, v_LOGIN);

-- Custom properties

INSERT INTO roles_groups (role_id, action_group_id) values(v_SUPER_USER_ID,v_CUSTOM_PROPERTIES);
INSERT INTO roles_groups (role_id, action_group_id) values(v_CLUSTER_ADMIN_ID, v_CUSTOM_PROPERTIES);
INSERT INTO roles_groups (role_id, action_group_id) values(v_DATA_CENTER_ADMIN_ID,v_CUSTOM_PROPERTIES);
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_VM_CREATOR_USER_ID, v_CREATE_DISK;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_CLUSTER_ADMIN_ID, v_MANIPULATE_PERMISSIONS;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_DATA_CENTER_ADMIN_ID, v_MANIPULATE_PERMISSIONS;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_TEMPLATE_OWNER_USER_ID, v_MANIPULATE_PERMISSIONS;
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_DISK_OPERATOR_USER_ID, v_MANIPULATE_PERMISSIONS;
INSERT INTO roles_groups(role_id,action_group_id)SELECT v_VM_ADMIN_ID, v_MANIPULATE_PERMISSIONS;
INSERT INTO roles_groups(role_id,action_group_id)SELECT v_VM_POOL_ADMIN_ID, v_CREATE_VM;

-- Login

INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_DATA_CENTER_ADMIN_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_POWER_USER_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_DISK_CREATOR_USER_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_TEMPLATE_CREATOR_USER_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_TEMPLATE_ADMIN_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_STORAGE_ADMIN_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_VM_ADMIN_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_SUPER_USER_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_VM_CREATOR_USER_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_DISK_OPERATOR_USER_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_CLUSTER_ADMIN_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_USER_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_HOST_ADMIN_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_VM_POOL_ADMIN_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_NETWORK_ADMIN_ID, v_LOGIN);
INSERT INTO roles_groups (role_id, action_group_id) VALUES (v_GLUSTER_ADMIN_ROLE_ID, v_LOGIN);

-- Networking
-- Add ASSIGN_CLUSTER_NETWORK
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_SUPER_USER_ID, v_ASSIGN_CLUSTER_NETWORK);

-- Add ASSIGN_CLUSTER_NETWORK
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_DATA_CENTER_ADMIN_ID, v_ASSIGN_CLUSTER_NETWORK);

-- Add ASSIGN_CLUSTER_NETWORK
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_NETWORK_ADMIN_ID, v_ASSIGN_CLUSTER_NETWORK);

-- Add PORT_MIRRORING
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_NETWORK_ADMIN_ID, v_CONFIGURE_STORAGE_POOL_VM_INTERFACE);

-- Add CONFIGURE_STORAGE_POOL_NETWORK
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_NETWORK_ADMIN_ID ,v_CONFIGURE_STORAGE_POOL_NETWORK);

-- Add CREATE_STORAGE_POOL_NETWORK
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_NETWORK_ADMIN_ID ,v_CREATE_STORAGE_POOL_NETWORK);

-- Add DELETE_STORAGE_POOL_NETWORK
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_NETWORK_ADMIN_ID ,v_DELETE_STORAGE_POOL_NETWORK);

-- Add CONFIGURE_VM_NETWORK
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_NETWORK_ADMIN_ID ,v_CONFIGURE_VM_NETWORK);

-- Add CONFIGURE_TEMPLATE_NETWORK
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_NETWORK_ADMIN_ID ,v_CONFIGURE_TEMPLATE_NETWORK);

-- ADD NetworkUser Role
INSERT INTO roles(id,name,description,is_readonly,role_type) values(v_NETWORK_USER_ID, 'NetworkUser', 'Network User', true, 2);

-- Add CONFIGURE_VM_NETWORK
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_NETWORK_USER_ID, v_CONFIGURE_VM_NETWORK);

-- Add CONFIGURE_TEMPLATE_NETWORK
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_NETWORK_USER_ID, v_CONFIGURE_TEMPLATE_NETWORK);


-------------------------------------------------------
-- Grant NetworkUser role to 'everyone' on all networks
-------------------------------------------------------

INSERT INTO permissions (id,role_id, ad_element_id, object_id, object_type_id)
    (SELECT uuid_generate_v1(), v_NETWORK_USER_ID, getGlobalIds('everyone'), id, 20 FROM network);

-- grant admin poweruser role on system
v_ADMIN_USER_ID := user_id from users where username = 'admin@internal';
insert into permissions(id,role_id,ad_element_id,object_id,object_type_id)
    values (uuid_generate_v1(), v_POWER_USER_ID, v_ADMIN_USER_ID, getGlobalIds('system'), 1);

-- Add External Event Injection priviledge to super user
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_SUPER_USER_ID, v_EXTERNAL_EVENT_INJECTION);

-----------------------------------
-- EXTERNAL_EVENT_CREATOR_USER role
-----------------------------------

INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children)
    values(v_EXTERNAL_EVENT_CREATOR_ID, 'ExternalEventsCreator', 'External Events Creator', true, 2, false);

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_EXTERNAL_EVENT_CREATOR_ID, v_EXTERNAL_EVENT_INJECTION);

-----------------------------------
-- GLUSTER VOLUME
-----------------------------------

-- Create gluster volume
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_CREATE_GLUSTER_VOLUME_BRICKS, '3.1', '*');

-- Set gluster volume option
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_SET_GLUSTER_VOLUME, '3.1', '*');

-- Start gluster volume
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_START_GLUSTER_VOLUME, '3.1', '*');

-- Stop gluster volume
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_STOP_GLUSTER_VOLUME, '3.1', '*');

-- Reset gluster volume options
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_RESET_GLUSTER_VOLUME, '3.1', '*');

-- Delete gluster volume
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_DELETE_GLUSTER_VOLUME_BRICKS, '3.1', '*');

-- Gluster volume remove bricks
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_REMOVE_GLUTER_VOLUME_BRICKS, '3.1', '*');

-- Start gluster volume rebalance
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_REBALANCE_GLUSTER_VOLUME, '3.1', '*');

-- Replace gluster volume bricks
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_REPLACE_GLUSTER_VOLUME_BRICKS, '3.1', '*');

-- Add bricks to Gluster volume
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_ADD_GLUSTER_VOLUME_BRICKS, '3.1', '*');

-- Start Gluster volume profile
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_START_GLUSTER_VOLUME_PROFILE, '3.2', '*');

-- Stop gluster volume profile
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_STOP_LUSTER_VOLUME_PROFILE, '3.2', '*');

-- Remove gluster server
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version)
    values(v_REMOVE_GLUSTER_SERVER, '3.2', '*');

-- QUOTA
INSERT INTO roles_groups(role_id,action_group_id)
    values(v_QUOTA_CONSUMER_USER_ID, v_CONSUME_QUOTA);

-- Add Login Permission
INSERT INTO roles_groups(role_id, action_group_id) VALUES(v_NETWORK_USER_ID, v_LOGIN);

-- lsm_version_support
insert into action_version_map values (v_LIVE_MIGRATE_DISK, '3.2', '3.2');
insert into action_version_map values (v_LIVE_MIGRATE_DISKS, '3.2', '3.2');


 RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT insert_predefined_roles();
**************************

 

********* QUERY **********
drop function insert_predefined_roles();
**************************

DROP FUNCTION
********* QUERY **********
select 3030000;
**************************

  3030000

********* QUERY **********
Create or replace FUNCTION fn_db_add_column(v_table varchar(128), v_column varchar(128), v_column_def text)
returns void
AS $procedure$
declare
v_sql text;

begin
	if (not exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ADD COLUMN ' || v_column || ' ' || v_column_def;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_drop_column(v_table varchar(128), v_column varchar(128))
returns void
AS $procedure$
declare
v_sql text;
begin
        if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
            begin
                v_sql := 'ALTER TABLE ' || v_table || ' DROP COLUMN ' || v_column;
                EXECUTE v_sql;
            end;
        end if;
end;$procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_change_column_type(v_table varchar(128), v_column varchar(128),
                                                    v_type varchar(128), v_new_type varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column and (udt_name ilike v_type or data_type ilike v_type))) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ALTER COLUMN ' || v_column || ' TYPE ' || v_new_type;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_rename_column(v_table varchar(128), v_column varchar(128), v_new_name varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' RENAME COLUMN ' || v_column || ' TO ' || v_new_name;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (not exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            insert into vdc_options (option_name, option_value, version) values (v_option_name, v_option_value, v_version);
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value_all_versions(v_option_name varchar(100))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name)) then
        begin
            delete from vdc_options where option_name ilike v_option_name;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value(v_option_name varchar(100), v_version text)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version)))) then
        begin
            delete from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version));
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_for_version(v_version text)
returns void
AS $procedure$
BEGIN
     delete from vdc_options where version in (select ID from fnSplitter(v_version));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            update  vdc_options set option_value = v_option_value
            where option_name ilike v_option_name and version = v_version;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_default_config_value(v_option_name varchar(100),v_default_option_value varchar(4000),v_option_value varchar(4000),v_version varchar(40),v_ignore_default_value_case boolean)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            if (v_ignore_default_value_case)
            then
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value ilike v_default_option_value and version = v_version;
            else
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value = v_default_option_value and version = v_version;
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_rename_config_key(v_old_option_name varchar(100),v_new_option_name varchar(100),v_version varchar(40))
returns void
AS $procedure$
DECLARE
    v_current_option_value varchar(4000);
begin
    if (exists (select 1 from vdc_options where option_name ilike v_old_option_name and version = v_version)) then
       v_current_option_value:=option_value from vdc_options where option_name ilike v_old_option_name and version = v_version;
       update vdc_options set option_name = v_new_option_name, option_value = v_current_option_value
           where  option_name ilike v_old_option_name and version = v_version;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_create_constraint (
    v_table varchar(128), v_constraint varchar(128), v_constraint_sql text)
returns void
AS $procedure$
begin
    if  NOT EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' ADD CONSTRAINT ' || v_constraint || ' ' || v_constraint_sql;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_drop_constraint (
    v_table varchar(128), v_constraint varchar(128))
returns void
AS $procedure$
begin
    if  EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' DROP CONSTRAINT ' || v_constraint || ' CASCADE';
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION CheckDBConnection() RETURNS SETOF integer IMMUTABLE
   AS $procedure$
BEGIN
    RETURN QUERY SELECT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_functions_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'drop function if exists ' || ns.nspname || '.' || proname || '(' || oidvectortypes(proargtypes) || ') cascade;' from pg_proc inner join pg_namespace ns on (pg_proc.pronamespace=ns.oid) where ns.nspname = 'public' order by proname;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_views_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP VIEW if exists ' || table_name || ' CASCADE;' from information_schema.views where table_schema = 'public' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_tables_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP TABLE if exists ' || table_name || ' CASCADE;' from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_seq_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP SEQUENCE if exists ' || sequence_name || ' CASCADE;' from information_schema.sequences  where sequence_schema = 'public' order by sequence_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_user_types_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT 'DROP TYPE if exists ' || c.relname::information_schema.sql_identifier || ' CASCADE;'
   FROM pg_namespace n, pg_class c, pg_type t
   WHERE n.oid = c.relnamespace and t.typrelid = c.oid and c.relkind = 'c'::"char" and
   n.nspname = 'public'
   ORDER BY  c.relname::information_schema.sql_identifier;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_get_column_size( v_table varchar(64), v_column varchar(64)) returns integer STABLE
   AS $procedure$
   declare
   retvalue  integer;
BEGIN
   retvalue := character_maximum_length from information_schema.columns
    where
    table_name ilike v_table and column_name ilike v_column and
    table_schema = 'public' and udt_name in ('char','varchar');
   return retvalue;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION attach_user_to_role (
    v_domain_entry_id text,
    v_user_name VARCHAR(255),
    v_domain VARCHAR(255),
    v_role_name VARCHAR(255)
)
RETURNS void AS
$BODY$
DECLARE
   gen_user_id uuid;
   input_role_id uuid;
BEGIN
   select uuid_generate_v1() into gen_user_id;
   select roles.id into input_role_id from roles where roles.name = v_role_name;
   -- The external identifier is the user identifier converted to an array of
   -- bytes:
   insert into users(user_id,external_id,name,domain,username,groups,active,last_admin_check_status) select gen_user_id, v_domain_entry_id, v_user_name, v_domain, v_user_name,'',true,true where not exists (select gen_user_id,name,domain,username,groups,active from users where external_id = v_domain_entry_id);
   insert into permissions(id,role_id,ad_element_id,object_id,object_type_id) select uuid_generate_v1(),  input_role_id, gen_user_id, getGlobalIds('system'), 1 where not exists(select role_id,ad_element_id,object_id,object_type_id from permissions where role_id = input_role_id and ad_element_id = gen_user_id and object_id= getGlobalIds('system') and object_type_id = 1);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_add_action_group_to_role(v_role_id UUID, v_action_group_id INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
       INSERT INTO roles_groups(role_id,action_group_id)
       SELECT v_role_id, v_action_group_id
       WHERE NOT EXISTS (SELECT 1
                         FROM roles_groups
                         WHERE role_id = v_role_id
                         AND action_group_id = v_action_group_id);
RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_split_config_value(v_option_name character varying, v_old_option_value character varying, v_new_option_value character varying, v_update_from_version character varying)
  RETURNS void AS
$BODY$
declare
v_old_value varchar(4000);
v_cur cursor for select distinct version from vdc_options where version <> 'general' order by version;
v_version varchar(40);
v_index integer;
v_count integer;
v_total_count integer;
v_version_count integer;
begin
    v_total_count := count(version) from vdc_options where option_name = v_option_name;
    v_old_value := option_value from vdc_options where option_name = v_option_name and version = 'general';
    v_version_count := count(distinct version) from vdc_options where version <> 'general';
    if (v_total_count <= v_version_count) then
        begin
            if (v_old_value IS NULL) then
                v_old_value := v_old_option_value;
            end if;
            v_count := count(distinct version) from vdc_options where version <> 'general';
            v_index := 1;
        open v_cur;
        loop
            fetch v_cur into v_version;
            exit when not found;
            -- We shouldn't update if already exists
            if (not exists (select 1 from vdc_options where option_name = v_option_name and version = v_version)) then
                -- Might not work well for versions such as 3.10, but we currently don't have any
                if (v_version >= v_update_from_version) then
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_new_option_value, v_version);
                else
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_old_value, v_version);
                end if;
            end if;
            v_index := v_index +1;
        end loop;
        close v_cur;
        delete from vdc_options where option_name = v_option_name and version = 'general';
        end;
    end if;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_grant_action_group_to_all_roles_filter(v_action_group_id integer, uuid[])
  RETURNS void AS
$BODY$
declare
v_role_id_to_filter alias for $2;
begin
    insert into roles_groups (role_id, action_group_id)
    select distinct role_id, v_action_group_id
    from roles_groups rg
    where not ARRAY [role_id] <@ v_role_id_to_filter and not exists (select 1 from roles_groups where role_id = rg.role_id and action_group_id = v_action_group_id);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_mask_object(v_object regclass) RETURNS setof record as
$BODY$
DECLARE
    v_sql TEXT;
    v_table record;
    v_table_name TEXT;
    temprec record;
BEGIN
    -- get full table/view name from v_object (i.e <namespace>.<name>)
    select c.relname, n.nspname INTO v_table
        FROM pg_class c join pg_namespace n on c.relnamespace = n.oid WHERE c.oid = v_object;
    -- try to get filtered query syntax from previous execution
    if exists (select 1 from object_column_white_list_sql where object_name = v_table.relname) then
	select sql into v_sql from object_column_white_list_sql where object_name = v_table.relname;
    else
        v_table_name := quote_ident( v_table.nspname ) || '.' || quote_ident( v_table.relname );
        -- compose sql statement while skipping values for columns not defined in object_column_white_list for this table.
        for temprec in select a.attname, t.typname
                       FROM pg_attribute a join pg_type t on a.atttypid = t.oid
                       WHERE a.attrelid = v_object AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
        loop
            v_sql := coalesce( v_sql || ', ', 'SELECT ' );
            if exists(select 1 from object_column_white_list
               where object_name = v_table.relname and column_name = temprec.attname) then
               v_sql := v_sql || quote_ident( temprec.attname );
            ELSE
               v_sql := v_sql || 'NULL::' || quote_ident( temprec.typname ) || ' as ' || quote_ident( temprec.attname );
            END IF;
        END LOOP;
        v_sql := v_sql || ' FROM ' || v_table_name;
        v_sql := 'SELECT x::' || v_table_name || ' as rec FROM (' || v_sql || ') as x';
        -- save generated query for further use
        insert into object_column_white_list_sql(object_name,sql) values (v_table.relname, v_sql);
    end if;
    RETURN QUERY EXECUTE v_sql;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_column_to_object_white_list(v_object_name varchar(128), v_column_name varchar(128))
returns void
AS $procedure$
begin
    if (not exists (select 1 from object_column_white_list
                    where object_name = v_object_name and column_name = v_column_name)) then
        begin
            -- verify that there is such object in db
            if exists (select 1 from information_schema.columns
                       where table_name = v_object_name and column_name = v_column_name) then
                insert into object_column_white_list (object_name, column_name) values (v_object_name, v_column_name);
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_disk(v_id UUID)
returns void
AS $procedure$
declare
    OK integer;
    LOCKED integer;
begin
    OK:=1;
    LOCKED:=2;
    update images set imagestatus = OK where imagestatus = LOCKED and
    image_group_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_snapshot(v_id UUID)
returns void
AS $procedure$
declare
    OK varchar;
    LOCKED varchar;
begin
    OK:='OK';
    LOCKED:='LOCKED';
    update snapshots set status = OK where status = LOCKED and snapshot_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_entity(v_object_type varchar(10), v_name varchar(255), v_recursive boolean)
returns void
AS $procedure$
declare
    DOWN integer;
    OK integer;
    LOCKED integer;
    TEMPLATE_OK integer;
    TEMPLATE_LOCKED integer;
    IMAGE_LOCKED integer;
    SNAPSHOT_OK varchar;
    SNAPSHOT_LOCKED varchar;
    v_id UUID;
begin
    DOWN:=0;
    OK:=1;
    LOCKED:=2;
    TEMPLATE_OK:=0;
    TEMPLATE_LOCKED:=1;
    IMAGE_LOCKED:=15;
    SNAPSHOT_OK:='OK';
    SNAPSHOT_LOCKED:='LOCKED';
    v_id := vm_guid from vm_static where vm_name = v_name and entity_type ilike v_object_type;
    -- set VM status to DOWN
    if (v_object_type = 'vm') then
        update vm_dynamic set status = DOWN where status = IMAGE_LOCKED and vm_guid  = v_id;
    -- set Template status to OK
    else
        if (v_object_type = 'template') then
            update vm_static set template_status = TEMPLATE_OK where template_status = TEMPLATE_LOCKED and vm_guid  = v_id;
        end if;
    end if;
    --unlock images and snapshots  if recursive flag is set
    if (v_recursive) then
        update images set imagestatus = OK where imagestatus = LOCKED and
        image_group_id in (select device_id from vm_device where vm_id = v_id and is_plugged);

        update snapshots set status = SNAPSHOT_OK where status ilike SNAPSHOT_LOCKED and vm_id = v_id;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/* Displays DC id , DC name, SPM Host id , SPM Host name and number of async tasks awaiting.

1) create a record type with DC name, DC id, SPM host id, SPM host name, count

2) get all distinct DC ids from async_tasks table

3) Run a cursor for each result in 2)

   a) get DC name
   b) get SPM Host id & name if available
   c) get count of tasks

   return current record

4) return set of generated records
*/
DROP TYPE IF EXISTS async_tasks_info_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE async_tasks_info_rs AS (
        dc_id uuid,
        dc_name character varying,
        spm_host_id uuid,
        spm_host_name character varying,
        task_count integer
);
**************************

CREATE TYPE
********* QUERY **********
create or replace FUNCTION fn_db_get_async_tasks()
returns SETOF async_tasks_info_rs STABLE
AS $procedure$
DECLARE
    v_record async_tasks_info_rs;

    -- selects storage_pool_id uuid found in async_tasks
    v_tasks_cursor cursor for select distinct storage_pool_id from async_tasks;
begin

    OPEN v_tasks_cursor;
    FETCH v_tasks_cursor into v_record.dc_id;
    WHILE FOUND LOOP
        -- get dc_name and SPM Host id
        v_record.dc_name := name from storage_pool where id = v_record.dc_id;
        v_record.spm_host_id :=
            spm_vds_id from storage_pool where id = v_record.dc_id;
        -- get Host name if we have non NULL SPM Host
        if (v_record.spm_host_id IS NOT NULL) then
            v_record.spm_host_name :=
                vds_name from vds_static where vds_id = v_record.spm_host_id;
        else
            v_record.spm_host_name:='';
        end if;
        -- get tasks count for this DC
        v_record.task_count := count(*) from async_tasks
            where position (cast(v_record.dc_id as varchar) in action_parameters) > 0;
        -- return the record
        RETURN NEXT v_record;
        FETCH v_tasks_cursor into v_record.dc_id;
    END LOOP;
    CLOSE v_tasks_cursor;
    -- return full set of generated records
    RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_remove_csv_config_value(v_option_name varchar(100), v_value varchar(4000), v_version varchar(40))
returns void
AS $procedure$
DECLARE
v varchar[];
e varchar;
v_result varchar;
v_sep varchar(1);
BEGIN
v_result := '';
v_sep := '';
    v := string_to_array(option_value, ',') from vdc_options where option_name = v_option_name and version = v_version;
    FOR e in select unnest(v)
    LOOP
        IF (e != v_value) THEN
            v_result := v_result || v_sep || e;
            v_sep := ',';
        END IF;
    END LOOP;
    UPDATE vdc_options set option_value = v_result where option_name = v_option_name and version = v_version;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select * from generate_drop_all_views_syntax();
**************************


********* QUERY **********
Create or replace FUNCTION fn_db_add_column(v_table varchar(128), v_column varchar(128), v_column_def text)
returns void
AS $procedure$
declare
v_sql text;

begin
	if (not exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ADD COLUMN ' || v_column || ' ' || v_column_def;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_drop_column(v_table varchar(128), v_column varchar(128))
returns void
AS $procedure$
declare
v_sql text;
begin
        if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
            begin
                v_sql := 'ALTER TABLE ' || v_table || ' DROP COLUMN ' || v_column;
                EXECUTE v_sql;
            end;
        end if;
end;$procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_change_column_type(v_table varchar(128), v_column varchar(128),
                                                    v_type varchar(128), v_new_type varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column and (udt_name ilike v_type or data_type ilike v_type))) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ALTER COLUMN ' || v_column || ' TYPE ' || v_new_type;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_rename_column(v_table varchar(128), v_column varchar(128), v_new_name varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' RENAME COLUMN ' || v_column || ' TO ' || v_new_name;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (not exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            insert into vdc_options (option_name, option_value, version) values (v_option_name, v_option_value, v_version);
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value_all_versions(v_option_name varchar(100))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name)) then
        begin
            delete from vdc_options where option_name ilike v_option_name;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value(v_option_name varchar(100), v_version text)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version)))) then
        begin
            delete from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version));
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_for_version(v_version text)
returns void
AS $procedure$
BEGIN
     delete from vdc_options where version in (select ID from fnSplitter(v_version));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            update  vdc_options set option_value = v_option_value
            where option_name ilike v_option_name and version = v_version;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_default_config_value(v_option_name varchar(100),v_default_option_value varchar(4000),v_option_value varchar(4000),v_version varchar(40),v_ignore_default_value_case boolean)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            if (v_ignore_default_value_case)
            then
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value ilike v_default_option_value and version = v_version;
            else
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value = v_default_option_value and version = v_version;
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_rename_config_key(v_old_option_name varchar(100),v_new_option_name varchar(100),v_version varchar(40))
returns void
AS $procedure$
DECLARE
    v_current_option_value varchar(4000);
begin
    if (exists (select 1 from vdc_options where option_name ilike v_old_option_name and version = v_version)) then
       v_current_option_value:=option_value from vdc_options where option_name ilike v_old_option_name and version = v_version;
       update vdc_options set option_name = v_new_option_name, option_value = v_current_option_value
           where  option_name ilike v_old_option_name and version = v_version;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_create_constraint (
    v_table varchar(128), v_constraint varchar(128), v_constraint_sql text)
returns void
AS $procedure$
begin
    if  NOT EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' ADD CONSTRAINT ' || v_constraint || ' ' || v_constraint_sql;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_drop_constraint (
    v_table varchar(128), v_constraint varchar(128))
returns void
AS $procedure$
begin
    if  EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' DROP CONSTRAINT ' || v_constraint || ' CASCADE';
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION CheckDBConnection() RETURNS SETOF integer IMMUTABLE
   AS $procedure$
BEGIN
    RETURN QUERY SELECT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_functions_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'drop function if exists ' || ns.nspname || '.' || proname || '(' || oidvectortypes(proargtypes) || ') cascade;' from pg_proc inner join pg_namespace ns on (pg_proc.pronamespace=ns.oid) where ns.nspname = 'public' order by proname;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_views_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP VIEW if exists ' || table_name || ' CASCADE;' from information_schema.views where table_schema = 'public' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_tables_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP TABLE if exists ' || table_name || ' CASCADE;' from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_seq_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP SEQUENCE if exists ' || sequence_name || ' CASCADE;' from information_schema.sequences  where sequence_schema = 'public' order by sequence_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_user_types_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT 'DROP TYPE if exists ' || c.relname::information_schema.sql_identifier || ' CASCADE;'
   FROM pg_namespace n, pg_class c, pg_type t
   WHERE n.oid = c.relnamespace and t.typrelid = c.oid and c.relkind = 'c'::"char" and
   n.nspname = 'public'
   ORDER BY  c.relname::information_schema.sql_identifier;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_get_column_size( v_table varchar(64), v_column varchar(64)) returns integer STABLE
   AS $procedure$
   declare
   retvalue  integer;
BEGIN
   retvalue := character_maximum_length from information_schema.columns
    where
    table_name ilike v_table and column_name ilike v_column and
    table_schema = 'public' and udt_name in ('char','varchar');
   return retvalue;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION attach_user_to_role (
    v_domain_entry_id text,
    v_user_name VARCHAR(255),
    v_domain VARCHAR(255),
    v_role_name VARCHAR(255)
)
RETURNS void AS
$BODY$
DECLARE
   gen_user_id uuid;
   input_role_id uuid;
BEGIN
   select uuid_generate_v1() into gen_user_id;
   select roles.id into input_role_id from roles where roles.name = v_role_name;
   -- The external identifier is the user identifier converted to an array of
   -- bytes:
   insert into users(user_id,external_id,name,domain,username,groups,active,last_admin_check_status) select gen_user_id, v_domain_entry_id, v_user_name, v_domain, v_user_name,'',true,true where not exists (select gen_user_id,name,domain,username,groups,active from users where external_id = v_domain_entry_id);
   insert into permissions(id,role_id,ad_element_id,object_id,object_type_id) select uuid_generate_v1(),  input_role_id, gen_user_id, getGlobalIds('system'), 1 where not exists(select role_id,ad_element_id,object_id,object_type_id from permissions where role_id = input_role_id and ad_element_id = gen_user_id and object_id= getGlobalIds('system') and object_type_id = 1);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_add_action_group_to_role(v_role_id UUID, v_action_group_id INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
       INSERT INTO roles_groups(role_id,action_group_id)
       SELECT v_role_id, v_action_group_id
       WHERE NOT EXISTS (SELECT 1
                         FROM roles_groups
                         WHERE role_id = v_role_id
                         AND action_group_id = v_action_group_id);
RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_split_config_value(v_option_name character varying, v_old_option_value character varying, v_new_option_value character varying, v_update_from_version character varying)
  RETURNS void AS
$BODY$
declare
v_old_value varchar(4000);
v_cur cursor for select distinct version from vdc_options where version <> 'general' order by version;
v_version varchar(40);
v_index integer;
v_count integer;
v_total_count integer;
v_version_count integer;
begin
    v_total_count := count(version) from vdc_options where option_name = v_option_name;
    v_old_value := option_value from vdc_options where option_name = v_option_name and version = 'general';
    v_version_count := count(distinct version) from vdc_options where version <> 'general';
    if (v_total_count <= v_version_count) then
        begin
            if (v_old_value IS NULL) then
                v_old_value := v_old_option_value;
            end if;
            v_count := count(distinct version) from vdc_options where version <> 'general';
            v_index := 1;
        open v_cur;
        loop
            fetch v_cur into v_version;
            exit when not found;
            -- We shouldn't update if already exists
            if (not exists (select 1 from vdc_options where option_name = v_option_name and version = v_version)) then
                -- Might not work well for versions such as 3.10, but we currently don't have any
                if (v_version >= v_update_from_version) then
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_new_option_value, v_version);
                else
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_old_value, v_version);
                end if;
            end if;
            v_index := v_index +1;
        end loop;
        close v_cur;
        delete from vdc_options where option_name = v_option_name and version = 'general';
        end;
    end if;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_grant_action_group_to_all_roles_filter(v_action_group_id integer, uuid[])
  RETURNS void AS
$BODY$
declare
v_role_id_to_filter alias for $2;
begin
    insert into roles_groups (role_id, action_group_id)
    select distinct role_id, v_action_group_id
    from roles_groups rg
    where not ARRAY [role_id] <@ v_role_id_to_filter and not exists (select 1 from roles_groups where role_id = rg.role_id and action_group_id = v_action_group_id);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_mask_object(v_object regclass) RETURNS setof record as
$BODY$
DECLARE
    v_sql TEXT;
    v_table record;
    v_table_name TEXT;
    temprec record;
BEGIN
    -- get full table/view name from v_object (i.e <namespace>.<name>)
    select c.relname, n.nspname INTO v_table
        FROM pg_class c join pg_namespace n on c.relnamespace = n.oid WHERE c.oid = v_object;
    -- try to get filtered query syntax from previous execution
    if exists (select 1 from object_column_white_list_sql where object_name = v_table.relname) then
	select sql into v_sql from object_column_white_list_sql where object_name = v_table.relname;
    else
        v_table_name := quote_ident( v_table.nspname ) || '.' || quote_ident( v_table.relname );
        -- compose sql statement while skipping values for columns not defined in object_column_white_list for this table.
        for temprec in select a.attname, t.typname
                       FROM pg_attribute a join pg_type t on a.atttypid = t.oid
                       WHERE a.attrelid = v_object AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
        loop
            v_sql := coalesce( v_sql || ', ', 'SELECT ' );
            if exists(select 1 from object_column_white_list
               where object_name = v_table.relname and column_name = temprec.attname) then
               v_sql := v_sql || quote_ident( temprec.attname );
            ELSE
               v_sql := v_sql || 'NULL::' || quote_ident( temprec.typname ) || ' as ' || quote_ident( temprec.attname );
            END IF;
        END LOOP;
        v_sql := v_sql || ' FROM ' || v_table_name;
        v_sql := 'SELECT x::' || v_table_name || ' as rec FROM (' || v_sql || ') as x';
        -- save generated query for further use
        insert into object_column_white_list_sql(object_name,sql) values (v_table.relname, v_sql);
    end if;
    RETURN QUERY EXECUTE v_sql;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_column_to_object_white_list(v_object_name varchar(128), v_column_name varchar(128))
returns void
AS $procedure$
begin
    if (not exists (select 1 from object_column_white_list
                    where object_name = v_object_name and column_name = v_column_name)) then
        begin
            -- verify that there is such object in db
            if exists (select 1 from information_schema.columns
                       where table_name = v_object_name and column_name = v_column_name) then
                insert into object_column_white_list (object_name, column_name) values (v_object_name, v_column_name);
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_disk(v_id UUID)
returns void
AS $procedure$
declare
    OK integer;
    LOCKED integer;
begin
    OK:=1;
    LOCKED:=2;
    update images set imagestatus = OK where imagestatus = LOCKED and
    image_group_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_snapshot(v_id UUID)
returns void
AS $procedure$
declare
    OK varchar;
    LOCKED varchar;
begin
    OK:='OK';
    LOCKED:='LOCKED';
    update snapshots set status = OK where status = LOCKED and snapshot_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_entity(v_object_type varchar(10), v_name varchar(255), v_recursive boolean)
returns void
AS $procedure$
declare
    DOWN integer;
    OK integer;
    LOCKED integer;
    TEMPLATE_OK integer;
    TEMPLATE_LOCKED integer;
    IMAGE_LOCKED integer;
    SNAPSHOT_OK varchar;
    SNAPSHOT_LOCKED varchar;
    v_id UUID;
begin
    DOWN:=0;
    OK:=1;
    LOCKED:=2;
    TEMPLATE_OK:=0;
    TEMPLATE_LOCKED:=1;
    IMAGE_LOCKED:=15;
    SNAPSHOT_OK:='OK';
    SNAPSHOT_LOCKED:='LOCKED';
    v_id := vm_guid from vm_static where vm_name = v_name and entity_type ilike v_object_type;
    -- set VM status to DOWN
    if (v_object_type = 'vm') then
        update vm_dynamic set status = DOWN where status = IMAGE_LOCKED and vm_guid  = v_id;
    -- set Template status to OK
    else
        if (v_object_type = 'template') then
            update vm_static set template_status = TEMPLATE_OK where template_status = TEMPLATE_LOCKED and vm_guid  = v_id;
        end if;
    end if;
    --unlock images and snapshots  if recursive flag is set
    if (v_recursive) then
        update images set imagestatus = OK where imagestatus = LOCKED and
        image_group_id in (select device_id from vm_device where vm_id = v_id and is_plugged);

        update snapshots set status = SNAPSHOT_OK where status ilike SNAPSHOT_LOCKED and vm_id = v_id;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/* Displays DC id , DC name, SPM Host id , SPM Host name and number of async tasks awaiting.

1) create a record type with DC name, DC id, SPM host id, SPM host name, count

2) get all distinct DC ids from async_tasks table

3) Run a cursor for each result in 2)

   a) get DC name
   b) get SPM Host id & name if available
   c) get count of tasks

   return current record

4) return set of generated records
*/
DROP TYPE IF EXISTS async_tasks_info_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE async_tasks_info_rs AS (
        dc_id uuid,
        dc_name character varying,
        spm_host_id uuid,
        spm_host_name character varying,
        task_count integer
);
**************************

CREATE TYPE
********* QUERY **********
create or replace FUNCTION fn_db_get_async_tasks()
returns SETOF async_tasks_info_rs STABLE
AS $procedure$
DECLARE
    v_record async_tasks_info_rs;

    -- selects storage_pool_id uuid found in async_tasks
    v_tasks_cursor cursor for select distinct storage_pool_id from async_tasks;
begin

    OPEN v_tasks_cursor;
    FETCH v_tasks_cursor into v_record.dc_id;
    WHILE FOUND LOOP
        -- get dc_name and SPM Host id
        v_record.dc_name := name from storage_pool where id = v_record.dc_id;
        v_record.spm_host_id :=
            spm_vds_id from storage_pool where id = v_record.dc_id;
        -- get Host name if we have non NULL SPM Host
        if (v_record.spm_host_id IS NOT NULL) then
            v_record.spm_host_name :=
                vds_name from vds_static where vds_id = v_record.spm_host_id;
        else
            v_record.spm_host_name:='';
        end if;
        -- get tasks count for this DC
        v_record.task_count := count(*) from async_tasks
            where position (cast(v_record.dc_id as varchar) in action_parameters) > 0;
        -- return the record
        RETURN NEXT v_record;
        FETCH v_tasks_cursor into v_record.dc_id;
    END LOOP;
    CLOSE v_tasks_cursor;
    -- return full set of generated records
    RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_remove_csv_config_value(v_option_name varchar(100), v_value varchar(4000), v_version varchar(40))
returns void
AS $procedure$
DECLARE
v varchar[];
e varchar;
v_result varchar;
v_sep varchar(1);
BEGIN
v_result := '';
v_sep := '';
    v := string_to_array(option_value, ',') from vdc_options where option_name = v_option_name and version = v_version;
    FOR e in select unnest(v)
    LOOP
        IF (e != v_value) THEN
            v_result := v_result || v_sep || e;
            v_sep := ',';
        END IF;
    END LOOP;
    UPDATE vdc_options set option_value = v_result where option_name = v_option_name and version = v_version;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select * from generate_drop_all_functions_syntax();
**************************

 drop function if exists public.attach_user_to_role(text, character varying, character varying, character varying) cascade;
 drop function if exists public.calculateallstorageusage() cascade;
 drop function if exists public.calculateallvdsgroupusage() cascade;
 drop function if exists public.calculatestorageusage(uuid, uuid) cascade;
 drop function if exists public.calculatevdsgroupusage(uuid, uuid) cascade;
 drop function if exists public.checkdbconnection() cascade;
 drop function if exists public.fn_authz_entry_info(uuid) cascade;
 drop function if exists public.fn_db_add_action_group_to_role(uuid, integer) cascade;
 drop function if exists public.fn_db_add_column(character varying, character varying, text) cascade;
 drop function if exists public.fn_db_add_column_to_object_white_list(character varying, character varying) cascade;
 drop function if exists public.fn_db_add_config_value(character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_change_column_type(character varying, character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_create_constraint(character varying, character varying, text) cascade;
 drop function if exists public.fn_db_delete_config_for_version(text) cascade;
 drop function if exists public.fn_db_delete_config_value(character varying, text) cascade;
 drop function if exists public.fn_db_delete_config_value_all_versions(character varying) cascade;
 drop function if exists public.fn_db_drop_column(character varying, character varying) cascade;
 drop function if exists public.fn_db_drop_constraint(character varying, character varying) cascade;
 drop function if exists public.fn_db_get_async_tasks() cascade;
 drop function if exists public.fn_db_grant_action_group_to_all_roles_filter(integer, uuid[]) cascade;
 drop function if exists public.fn_db_mask_object(regclass) cascade;
 drop function if exists public.fn_db_remove_csv_config_value(character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_rename_column(character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_rename_config_key(character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_split_config_value(character varying, character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_unlock_disk(uuid) cascade;
 drop function if exists public.fn_db_unlock_entity(character varying, character varying, boolean) cascade;
 drop function if exists public.fn_db_unlock_snapshot(uuid) cascade;
 drop function if exists public.fn_db_update_config_value(character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_update_default_config_value(character varying, character varying, character varying, character varying, boolean) cascade;
 drop function if exists public.fn_get_actual_images_size_by_storage(uuid) cascade;
 drop function if exists public.fn_get_ad_element_name(uuid) cascade;
 drop function if exists public.fn_get_column_size(character varying, character varying) cascade;
 drop function if exists public.fn_get_comparable_ip_list(text) cascade;
 drop function if exists public.fn_get_disk_commited_value_by_storage(uuid) cascade;
 drop function if exists public.fn_get_entity_name(uuid, integer) cascade;
 drop function if exists public.fn_get_entity_parents(uuid, integer) cascade;
 drop function if exists public.fn_get_storage_domain_shared_status_by_domain_id(uuid, integer, integer) cascade;
 drop function if exists public.fn_user_permissions(uuid) cascade;
 drop function if exists public.fnsplitter(text) cascade;
 drop function if exists public.fnsplitteruuid(text) cascade;
 drop function if exists public.fnsplitterwithseperator(text, character varying) cascade;
 drop function if exists public.generate_drop_all_functions_syntax() cascade;
 drop function if exists public.generate_drop_all_seq_syntax() cascade;
 drop function if exists public.generate_drop_all_tables_syntax() cascade;
 drop function if exists public.generate_drop_all_user_types_syntax() cascade;
 drop function if exists public.generate_drop_all_views_syntax() cascade;
 drop function if exists public.getelementidsbyidandgroups(uuid, text) cascade;
 drop function if exists public.getglobalids(character varying) cascade;
 drop function if exists public.getnoncountablequtoavmstatuses() cascade;
 drop function if exists public.getuserandgroupsbyid(uuid) cascade;
 drop function if exists public.uuid_generate_v1() cascade;

********* QUERY **********
 drop function if exists public.attach_user_to_role(text, character varying, character varying, character varying) cascade;
 drop function if exists public.calculateallstorageusage() cascade;
 drop function if exists public.calculateallvdsgroupusage() cascade;
 drop function if exists public.calculatestorageusage(uuid, uuid) cascade;
 drop function if exists public.calculatevdsgroupusage(uuid, uuid) cascade;
 drop function if exists public.checkdbconnection() cascade;
 drop function if exists public.fn_authz_entry_info(uuid) cascade;
 drop function if exists public.fn_db_add_action_group_to_role(uuid, integer) cascade;
 drop function if exists public.fn_db_add_column(character varying, character varying, text) cascade;
 drop function if exists public.fn_db_add_column_to_object_white_list(character varying, character varying) cascade;
 drop function if exists public.fn_db_add_config_value(character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_change_column_type(character varying, character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_create_constraint(character varying, character varying, text) cascade;
 drop function if exists public.fn_db_delete_config_for_version(text) cascade;
 drop function if exists public.fn_db_delete_config_value(character varying, text) cascade;
 drop function if exists public.fn_db_delete_config_value_all_versions(character varying) cascade;
 drop function if exists public.fn_db_drop_column(character varying, character varying) cascade;
 drop function if exists public.fn_db_drop_constraint(character varying, character varying) cascade;
 drop function if exists public.fn_db_get_async_tasks() cascade;
 drop function if exists public.fn_db_grant_action_group_to_all_roles_filter(integer, uuid[]) cascade;
 drop function if exists public.fn_db_mask_object(regclass) cascade;
 drop function if exists public.fn_db_remove_csv_config_value(character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_rename_column(character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_rename_config_key(character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_split_config_value(character varying, character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_unlock_disk(uuid) cascade;
 drop function if exists public.fn_db_unlock_entity(character varying, character varying, boolean) cascade;
 drop function if exists public.fn_db_unlock_snapshot(uuid) cascade;
 drop function if exists public.fn_db_update_config_value(character varying, character varying, character varying) cascade;
 drop function if exists public.fn_db_update_default_config_value(character varying, character varying, character varying, character varying, boolean) cascade;
 drop function if exists public.fn_get_actual_images_size_by_storage(uuid) cascade;
 drop function if exists public.fn_get_ad_element_name(uuid) cascade;
 drop function if exists public.fn_get_column_size(character varying, character varying) cascade;
 drop function if exists public.fn_get_comparable_ip_list(text) cascade;
 drop function if exists public.fn_get_disk_commited_value_by_storage(uuid) cascade;
 drop function if exists public.fn_get_entity_name(uuid, integer) cascade;
 drop function if exists public.fn_get_entity_parents(uuid, integer) cascade;
 drop function if exists public.fn_get_storage_domain_shared_status_by_domain_id(uuid, integer, integer) cascade;
 drop function if exists public.fn_user_permissions(uuid) cascade;
 drop function if exists public.fnsplitter(text) cascade;
 drop function if exists public.fnsplitteruuid(text) cascade;
 drop function if exists public.fnsplitterwithseperator(text, character varying) cascade;
 drop function if exists public.generate_drop_all_functions_syntax() cascade;
 drop function if exists public.generate_drop_all_seq_syntax() cascade;
 drop function if exists public.generate_drop_all_tables_syntax() cascade;
 drop function if exists public.generate_drop_all_user_types_syntax() cascade;
 drop function if exists public.generate_drop_all_views_syntax() cascade;
 drop function if exists public.getelementidsbyidandgroups(uuid, text) cascade;
 drop function if exists public.getglobalids(character varying) cascade;
 drop function if exists public.getnoncountablequtoavmstatuses() cascade;
 drop function if exists public.getuserandgroupsbyid(uuid) cascade;
 drop function if exists public.uuid_generate_v1() cascade;
**************************

DROP FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS idTextType CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE idtexttype AS (
        id text
);
**************************

CREATE TYPE
********* QUERY **********
DROP TYPE IF EXISTS idUuidType CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE iduuidtype AS (
        id uuid
);
**************************

CREATE TYPE
********* QUERY **********
DROP TYPE IF EXISTS booleanResultType CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE booleanresulttype AS (
        result boolean
);
**************************

CREATE TYPE
********* QUERY **********
DROP TYPE IF EXISTS authzEntryInfoType CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE authzentryinfotype AS (
        name text,
        namespace character varying(2048),
        authz character varying(255)
);
**************************

CREATE TYPE
********* QUERY **********
CREATE OR REPLACE FUNCTION getGlobalIds(v_name VARCHAR(4000))
RETURNS UUID IMMUTABLE STRICT
   AS $function$
   DECLARE
   v_id  UUID;
BEGIN
   if (v_name = 'system') then
      v_id := 'AAA00000-0000-0000-0000-123456789AAA';
   elsif (v_name = 'everyone') then
      v_id := 'EEE00000-0000-0000-0000-123456789EEE';
   -- bottom is an object which all the objects in the system are its parents
   -- useful to denote we want all objects when checking for permissions
   elsif (v_name = 'bottom') then
      v_id := 'BBB00000-0000-0000-0000-123456789BBB';
   end if;
   return  v_id;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fnSplitter(ids TEXT)  RETURNS SETOF idTextType IMMUTABLE AS
$function$
BEGIN
	RETURN QUERY
		SELECT regexp_split_to_table(ids, ',') AS id;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fnSplitterUuid(ids TEXT)  RETURNS SETOF UUID IMMUTABLE AS
$function$
BEGIN
 IF ids != '' THEN
	RETURN QUERY
		SELECT CAST(regexp_split_to_table(ids, ',') AS UUID);
 END IF;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fnSplitterWithSeperator(ids TEXT, separator VARCHAR(10))  RETURNS SETOF idTextType IMMUTABLE AS
$function$
BEGIN
  RETURN QUERY
    SELECT regexp_split_to_table(ids, separator) AS id;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS user_permissions CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE user_permissions AS (
        permission_id uuid,
        role_id uuid,
        user_id uuid
);
**************************

CREATE TYPE
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_user_permissions(v_userId IN uuid) RETURNS SETOF user_permissions STABLE AS
$function$
DECLARE

BEGIN
	RETURN QUERY
	    SELECT
		    permissions.id AS permission_id,
		    permissions.role_id,
		    permissions.ad_element_id AS user_id
	    FROM permissions
		INNER JOIN users ON permissions.ad_element_id = users.user_id
	    WHERE users.user_id = v_userId

	    UNION

	    SELECT
		    permissions.id AS permission_id,
		    permissions.role_id,
		    temp.user_id AS user_id
	    FROM permissions INNER JOIN
	    (
		    -- get all groups of admin users
		    SELECT ad_groups.id group_id, users.user_id
		    FROM ad_groups, users
		    WHERE ad_groups.id IN
		    (SELECT * FROM fnsplitteruuid(users.group_ids))
			AND users.user_id = v_userId ) temp
		ON permissions.ad_element_id = temp.group_id;

END; $function$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_get_entity_parents(v_entity_id IN uuid, v_object_type IN int4) RETURNS SETOF idUuidType STABLE AS
$function$
/*	Gets a list of all parent GUID to the system root (including)

	Object Types (compatible with VdcObjectType, XXX entries are unused currently)
		Unknown XXX,
		System XXX,
        Bottom = 0,
		VM = 2,
		VDS = 3,
		VmTemplate = 4,
		VmPool = 5,
		AdElements XXX,
		Tags XXX,
		Bookmarks XXX,
		VdsGroups = 9,
		MultiLevelAdministration XXX,
		Storage = 11,
		EventNotification XXX,
		ImportExport XXX,
		StoragePool = 14,
		User = 15,
		Role = 16,
		Quota = 17,
		GlusterVolume = 18,
        Disk = 19,
        Network = 20,
        VNICProfile = 27,
        DiskProfile = 29
        CpuProfile = 30
*/
DECLARE
	v_entity_type int4 := v_object_type;
	system_root_id uuid;
	cluster_id uuid;
	ds_id uuid;
	v_image_id uuid;
	v_storage_id uuid;
    v_vm_id uuid;
    v_storage_pool_id uuid;
    v_profile_network_id uuid;
    v_disk_profile_storage_id uuid;
    v_cpu_profile_cluster_id uuid;

BEGIN

	system_root_id := ( SELECT getGlobalIds('system') ); -- hardcoded also in MLA Handler
	CASE
	WHEN v_entity_type = 0 THEN -- Bottom
		RETURN QUERY
			SELECT object_id
			FROM permissions;
	WHEN v_entity_type = 2 THEN -- VM
        -- get cluster id
		cluster_id := ( SELECT vds_group_id FROM vm_static WHERE vm_guid = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 3 THEN -- VDS
        -- get cluster id
		cluster_id := ( SELECT vds_group_id FROM vds_static WHERE vds_id = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 4 THEN -- Template
		-- get image id first
		v_image_id := ( SELECT image_guid FROM images i JOIN vm_device vd ON i.image_group_id = vd.device_id WHERE vm_id = v_entity_id limit 1);
		-- get the storage id from images
		v_storage_id := ( SELECT storage_domain_id FROM image_storage_domain_map WHERE image_id = v_image_id limit 1);
		-- finally get data center id
		ds_id := ( SELECT storage_pool_id FROM storage_pool_iso_map WHERE storage_id = v_storage_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 5 THEN -- VM Pool
        -- get cluster id
		cluster_id := ( SELECT vds_group_id FROM vm_pools WHERE vm_pool_id = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 9 THEN -- Cluster
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = v_entity_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 11 THEN -- Storage Domain

		RETURN QUERY
			SELECT system_root_id AS id
			UNION ALL
			SELECT storage_pool_id as id FROM storage_pool_iso_map WHERE storage_id = v_entity_id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 17 THEN -- Quota
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM quota WHERE id = v_entity_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT v_entity_id AS id;
	WHEN v_entity_type = 18 THEN -- GlusterVolume
        -- get cluster id
		cluster_id := ( SELECT v.cluster_id FROM gluster_volumes v WHERE id = v_entity_id );
		-- get data center id
		ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

		RETURN QUERY
			SELECT system_root_id AS id
			UNION
			SELECT ds_id AS id
			UNION
			SELECT cluster_id AS id
			UNION
			SELECT v_entity_id AS id;

	WHEN v_entity_type = 19 THEN -- Disk

        -- get data center, storage domain and vm
        SELECT INTO ds_id, v_storage_id, v_vm_id
                    storage_pool_id, storage_id, vm_id
        FROM images_storage_domain_view
        LEFT OUTER JOIN vm_device ON vm_device.device_id = images_storage_domain_view.disk_id
        WHERE image_group_id = v_entity_id;

        -- get cluster
        cluster_id := ( SELECT vds_group_id FROM vm_static WHERE vm_guid = v_vm_id );

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT ds_id AS id
            UNION
            SELECT v_storage_id AS id
            UNION
            SELECT v_vm_id AS id
            UNION
            SELECT cluster_id AS id
            UNION
            SELECT v_entity_id AS id;

	WHEN v_entity_type = 20 THEN -- Network

        SELECT INTO v_storage_pool_id
                    network.storage_pool_id
        FROM network
        WHERE network.id = v_entity_id;

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT v_storage_pool_id AS id
            UNION
            SELECT v_entity_id AS id;

	WHEN v_entity_type = 27 THEN -- VNICProfile

        SELECT INTO v_profile_network_id
                    vnic_profiles.network_id
        FROM vnic_profiles
        WHERE vnic_profiles.id = v_entity_id;
        SELECT INTO v_storage_pool_id
                    network.storage_pool_id
        FROM network
        WHERE network.id = v_profile_network_id;

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT v_storage_pool_id AS id
            UNION
            SELECT v_profile_network_id AS id
            UNION
            SELECT v_entity_id AS id;

        WHEN v_entity_type = 29 THEN -- DiskProfile

        SELECT INTO v_disk_profile_storage_id
                    disk_profiles.storage_domain_id
        FROM disk_profiles
        WHERE disk_profiles.id = v_entity_id;
        SELECT INTO v_storage_pool_id
                    storage_pool_iso_map.storage_pool_id
        FROM storage_pool_iso_map
        WHERE storage_pool_iso_map.storage_id = v_disk_profile_storage_id;

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT v_storage_pool_id AS id
            UNION
            SELECT v_disk_profile_storage_id AS id
            UNION
            SELECT v_entity_id AS id;

        WHEN v_entity_type = 30 THEN -- CpuProfile

        SELECT INTO v_cpu_profile_cluster_id
                    cpu_profiles.cluster_id
        FROM cpu_profiles
        WHERE cpu_profiles.id = v_entity_id;
        SELECT INTO v_storage_pool_id
                    vds_groups.storage_pool_id
        FROM vds_groups
        WHERE vds_groups.vds_group_id = v_cpu_profile_cluster_id;

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT v_storage_pool_id AS id
            UNION
            SELECT v_cpu_profile_cluster_id AS id
            UNION
            SELECT v_entity_id AS id;

    WHEN v_entity_type = 23 THEN -- Gluster Hook

        -- get cluster id
        cluster_id := ( SELECT cluster_id FROM gluster_hooks WHERE id = v_entity_id );
        -- get data center id
        ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT ds_id AS id
            UNION
            SELECT cluster_id AS id
            UNION
            SELECT v_entity_id AS id;

	WHEN v_entity_type = 25 THEN -- Gluster Service

        -- get cluster id
        cluster_id := ( SELECT vds_group_id FROM vds_static WHERE vds_id = v_entity_id );
        -- get data center id
        ds_id := ( SELECT storage_pool_id FROM vds_groups WHERE vds_group_id = cluster_id );

        RETURN QUERY
            SELECT system_root_id AS id
            UNION
            SELECT ds_id AS id
            UNION
            SELECT cluster_id AS id
            UNION
            SELECT v_entity_id AS id;
	ELSE
		IF v_entity_type IN ( 1,14,15,16 ) THEN -- Data Center, users and roles are under system
			RETURN QUERY
				SELECT system_root_id AS id
				UNION
				SELECT v_entity_id AS id;
		END IF;
	END CASE;
END;$function$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_get_disk_commited_value_by_storage(v_storage_domain_id IN uuid) RETURNS integer STABLE AS
$function$
DECLARE
    result integer;
    mult bigint;

BEGIN
	mult := ( SELECT
	    		COALESCE(SUM(
                       CASE
                           WHEN (images_storage_domain_view.active = true
                                 AND (images_storage_domain_view.entity_type IS NULL OR       -- Floating disk
                                      images_storage_domain_view.entity_type <> 'TEMPLATE'))  -- or a VM
                               THEN images_storage_domain_view.size
                           ELSE images_storage_domain_view.actual_size
                       END),0)
				FROM images_storage_domain_view
				WHERE images_storage_domain_view.storage_id = v_storage_domain_id );
        -- convert to GB from bytes
	mult := CAST((mult * 0.000000000931322574615478515625) AS bigint);
    result := CAST(mult as integer);

	RETURN result;
END;$function$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_get_actual_images_size_by_storage(v_storage_domain_id IN uuid) RETURNS integer STABLE AS
$function$
DECLARE
    result integer;
    mult bigint;

BEGIN
	mult := ( SELECT
	    		COALESCE(SUM(disk_image_dynamic.actual_size),0)
				FROM images_storage_domain_view JOIN
	    			disk_image_dynamic ON ( images_storage_domain_view.image_guid = disk_image_dynamic.image_id )
				WHERE images_storage_domain_view.storage_id = v_storage_domain_id );
        -- convert to GB from bytes
	mult := CAST((mult * 0.000000000931322574615478515625) AS bigint);
    result := CAST(mult as integer);

	RETURN result;
END;$function$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_get_storage_domain_shared_status_by_domain_id(v_storage_domain_id UUID,
	v_storage_status INTEGER,
	v_storage_domain_type INTEGER)
RETURNS INTEGER
   AS $function$
   DECLARE
   v_result  INTEGER;
   v_rowsCount  INTEGER;
   v_status  INTEGER;
BEGIN
    if (v_storage_domain_type != 2) then
      if (v_storage_status is null) then
         v_result := 0;
      else
         -- if 1 row and status active (3) then domain is active (1)
         if v_storage_status = 3 then
            v_result := 1;
		 -- if 1 row and status not active then domain is inactive (2)
         else
            v_result := 2;
         end if;
      end if;
    else
      BEGIN
         CREATE TEMPORARY TABLE tt_TEMP22
         (
            status INTEGER,
            count INTEGER
         ) WITH OIDS;
         exception when others then
         truncate table tt_TEMP22;
      END;
      delete from tt_TEMP22;
      Insert INTO tt_TEMP22
      select status, count(storage_id) from storage_pool_iso_map
      where storage_id = v_storage_domain_id
      group by status;

      select count(*) INTO v_rowsCount from tt_TEMP22;

      -- if return 0 rows then the domain is unattached
      if (v_rowsCount = 0) then
         v_result := 0;
      else
         if (v_rowsCount = 1) then
	        -- if 1 row and status active (3) then domain is active (1)
            if v_storage_status = 3 then
               v_result := 1;
		    -- if 1 row and status not active then domain is inactive (2)
            else
               v_result := 2;
            end if;
	      -- else (if return more then 1 row)
          else
            select   count(*) INTO v_rowsCount from tt_TEMP22 where status = 3;
            if (v_rowsCount > 0) then
               v_result := 3;
			   -- non of the statuses is active
            else
               v_result := 2;
          end if;
         end if;
      end if;
    end if;
   return v_result;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_authz_entry_info(v_ad_element_id IN uuid) RETURNS AuthzEntryInfoType STABLE AS
$function$
DECLARE
    result authzEntryInfoType;

BEGIN
   if (v_ad_element_id = getGlobalIds('everyone')) then
      select 'Everyone','*','' into result;
   else
      select(COALESCE(name,'') || ' ' || COALESCE(surname,'') || ' (' || COALESCE(username,'') || '@' || COALESCE(domain,'') || ')'), namespace, domain INTO result from users where user_id = v_ad_element_id;
      if (result is null) then
         select   name, namespace, domain INTO result from ad_groups where ID = v_ad_element_id;
      end if;
   end if;
   return result;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_get_ad_element_name(v_ad_element_id IN uuid) RETURNS text STABLE AS
$function$
DECLARE
    result text;

BEGIN
   if (v_ad_element_id = getGlobalIds('everyone')) then
      result := 'Everyone';
   else
      select(COALESCE(name,'') || ' ' || COALESCE(surname,'') || ' (' || COALESCE(username,'') || '@' || COALESCE(domain,'') || ')') INTO result from users where user_id = v_ad_element_id;
      if (result is null) then
         select   name INTO result from ad_groups where ID = v_ad_element_id;
      end if;
   end if;
   return result;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION public.fn_get_entity_name(v_entity_id IN uuid, v_object_type IN int4) RETURNS text STABLE AS
$function$
/*    Gets object name by its id and type

    Object Types (compatible with VdcObjectType, XXX entries are unused currently)
        Unknown XXX,
        System XXX,
        VM = 2,
        VDS = 3,
        VmTemplate = 4,
        VmPool = 5,
        AdElements XXX,
        Tags XXX,
        Bookmarks XXX,
        VdsGroups = 9,
        MultiLevelAdministration XXX,
        Storage = 11,
        EventNotification XXX,
        ImportExport XXX,
        StoragePool = 14,
        User = 15,
        Role = 16,
        Quota = 17,
        GlusterVolume = 18,
        Disk = 19,
        Network = 20,
        VNICProfile = 27,
        DiskProfile = 29
        CpuProfile = 30
*/
DECLARE
    v_entity_type int4 := v_object_type;
    result text;

BEGIN

    CASE
    WHEN v_entity_type = 1 THEN
        result := 'System';
    WHEN v_entity_type = 2 OR v_entity_type = 4 THEN
        result := ( SELECT vm_name FROM vm_static WHERE vm_guid = v_entity_id );
    WHEN v_entity_type = 3 THEN
        result := ( SELECT vds_name FROM vds_static WHERE vds_id = v_entity_id );
    WHEN v_entity_type = 5 THEN
        result := ( SELECT vm_pool_name FROM vm_pools WHERE vm_pool_id = v_entity_id );
    WHEN v_entity_type = 7 THEN
        result := ( SELECT tag_name FROM tags WHERE tag_id = v_entity_id );
    WHEN v_entity_type = 8 THEN
        result := ( SELECT bookmark_name FROM bookmarks WHERE bookmark_id = v_entity_id );
    WHEN v_entity_type = 9 THEN
        result := ( SELECT name FROM vds_groups WHERE vds_group_id = v_entity_id );
    WHEN v_entity_type = 11 THEN
        result := ( SELECT storage_name FROM storage_domain_static WHERE id = v_entity_id );
    WHEN v_entity_type = 14 THEN
        result := ( SELECT name FROM storage_pool WHERE id = v_entity_id );
    WHEN v_entity_type = 15 THEN
        result := ( SELECT username FROM users WHERE user_id = v_entity_id );
    WHEN v_entity_type = 16 THEN
        result := ( SELECT name FROM roles WHERE id = v_entity_id );
    WHEN v_entity_type = 17 THEN
        result := ( SELECT quota_name FROM quota WHERE id = v_entity_id );
   WHEN v_entity_type = 18 THEN
        result := ( SELECT vol_name FROM gluster_volumes WHERE id = v_entity_id );
    WHEN v_entity_type = 19 THEN
        result := ( SELECT disk_alias FROM base_disks WHERE disk_id = v_entity_id );
    WHEN v_entity_type = 20 THEN
        result := ( SELECT name FROM network WHERE id = v_entity_id );
    WHEN v_entity_type = 23 THEN
        result := ( SELECT concat(gluster_command,'-',stage,'-',name) FROM gluster_hooks where id = v_entity_id );
    WHEN v_entity_type = 25 THEN
        result := ( SELECT service_name FROM gluster_services where id = v_entity_id );
    WHEN v_entity_type = 27 THEN
        result := ( SELECT name FROM vnic_profiles where id = v_entity_id );
    WHEN v_entity_type = 29 THEN
        result := ( SELECT name FROM disk_profiles where id = v_entity_id );
    WHEN v_entity_type = 30 THEN
        result := ( SELECT name FROM cpu_profiles where id = v_entity_id );
    ELSE
        result := 'Unknown type ' ||  v_entity_type;
    END CASE;

--      -- This should be written to an error var or include object_id that is missing
--    IF result IS NULL THEN
--        result := v_entity_id || '' NOT FOUND'';
--    END IF;
    RETURN result;
END;$function$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION getUserAndGroupsById(v_id UUID)
RETURNS SETOF idUuidType STABLE
   AS $function$
BEGIN
   RETURN QUERY
   select ID from ad_groups,users where users.user_id = v_id
   and ad_groups.id in(select * from fnsplitteruuid(users.group_ids))
   UNION
   select v_id
   UNION
   -- user is also member of 'Everyone'
   select 'EEE00000-0000-0000-0000-123456789EEE';
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION getElementIdsByIdAndGroups(v_id UUID,v_group_ids text)
RETURNS SETOF idUuidType STABLE
   AS $function$
BEGIN
  RETURN QUERY
  select * from fnsplitteruuid(v_group_ids)
  UNION
  select v_id
  UNION
  -- user is also member of 'Everyone'
  select 'EEE00000-0000-0000-0000-123456789EEE';
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS vds_group_usage_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE vds_group_usage_rs AS (
        virtual_cpu_usage integer,
        mem_size_mb_usage bigint
);
**************************

CREATE TYPE
********* QUERY **********
CREATE OR REPLACE FUNCTION getNonCountableQutoaVmStatuses()
RETURNS SETOF INTEGER IMMUTABLE
    AS $BODY$
BEGIN
    RETURN query select 0 union select 13 union select 14 union select 15;
--(Down(0), Suspended(13), ImageIllegal(14), ImageLocked(15))
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CalculateVdsGroupUsage(v_quota_id UUID, v_vds_group_id UUID)
RETURNS SETOF vds_group_usage_rs STABLE
AS $function$
BEGIN
    RETURN QUERY SELECT cast(COALESCE(sum(num_of_sockets * cpu_per_socket), 0) as INTEGER) as virtual_cpu_usage,
    COALESCE(sum(mem_size_mb), 0) as mem_size_mb_usage
    FROM vm_static,vm_dynamic
    WHERE quota_id = v_quota_id
      AND vm_dynamic.vm_guid = vm_static.vm_guid
      AND vm_dynamic.status not in (SELECT getNonCountableQutoaVmStatuses())
      AND (v_vds_group_id = vm_static.vds_group_id or v_vds_group_id IS NULL);
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS all_vds_group_usage_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE all_vds_group_usage_rs AS (
        quota_vds_group_id uuid,
        quota_id uuid,
        vds_group_id uuid,
        vds_group_name character varying(40),
        virtual_cpu integer,
        virtual_cpu_usage integer,
        mem_size_mb bigint,
        mem_size_mb_usage bigint
);
**************************

CREATE TYPE
********* QUERY **********
CREATE OR REPLACE FUNCTION calculateAllVdsGroupUsage()
RETURNS SETOF all_vds_group_usage_rs STABLE
AS $function$
BEGIN
    RETURN QUERY SELECT
        quota_limitation.id AS quota_vds_group_id,
        quota_limitation.quota_id as quota_id,
        quota_limitation.vds_group_id as vds_group_id,
        vds_groups.name AS vds_group_name,
        quota_limitation.virtual_cpu,
        cast(COALESCE(sum(num_of_sockets * cpu_per_socket * cast(vm_dynamic.status not in (SELECT getNonCountableQutoaVmStatuses()) as INTEGER)), 0) as INTEGER) as virtual_cpu_usage,
        quota_limitation.mem_size_mb,
        COALESCE(sum(vm_static.mem_size_mb), 0) as mem_size_mb_usage
    FROM quota_limitation
        LEFT JOIN vm_static ON vm_static.quota_id = quota_limitation.quota_id
        LEFT JOIN vm_dynamic ON vm_dynamic.vm_guid = vm_static.vm_guid
        LEFT JOIN vds_groups ON vds_groups.vds_group_id = vm_static.vds_group_id
    WHERE quota_limitation.virtual_cpu IS NOT NULL
        AND quota_limitation.mem_size_mb IS NOT NULL
    GROUP BY quota_limitation.quota_id, quota_limitation.vds_group_id, vds_group_name, quota_limitation.virtual_cpu, quota_limitation.mem_size_mb,
        vm_static.quota_id, vds_groups.vds_group_id, vm_static.vds_group_id, quota_limitation.id;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS all_storage_usage_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE all_storage_usage_rs AS (
        quota_storage_id uuid,
        quota_id uuid,
        storage_id uuid,
        storage_name character varying(250),
        storage_size_gb bigint,
        storage_size_gb_usage double precision
);
**************************

CREATE TYPE
********* QUERY **********
CREATE OR REPLACE FUNCTION calculateAllStorageUsage()
RETURNS SETOF all_storage_usage_rs STABLE
AS $function$
BEGIN
    -- Summarize size of all disks that are active.
    RETURN QUERY SELECT
        quota_limitation.id AS quota_storage_id,
        quota_limitation.quota_id as quota_id,
        quota_limitation.storage_id as storage_id,
        storage_domain_static.storage_name,
        quota_limitation.storage_size_gb,
        cast(COALESCE(sum(size * cast(active as integer) + disk_image_dynamic.actual_size * cast((not active) as integer)) / 1073741824 ,0) as double precision)  as storage_usage -- 1073741824 is 1024^3 (for GB)
    FROM quota_limitation
        LEFT JOIN image_storage_domain_map ON quota_limitation.quota_id = image_storage_domain_map.quota_id
        LEFT JOIN images ON images.image_guid = image_storage_domain_map.image_id
        LEFT JOIN disk_image_dynamic ON images.image_guid = disk_image_dynamic.image_id
        LEFT JOIN storage_domain_static ON image_storage_domain_map.storage_domain_id = storage_domain_static.id
    WHERE quota_limitation.storage_size_gb IS NOT NULL
    GROUP BY quota_limitation.quota_id, storage_id,quota_limitation.id,storage_domain_static.storage_name,quota_limitation.storage_size_gb;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CalculateStorageUsage(v_quota_id UUID, v_storage_id UUID)
RETURNS double precision STABLE
AS $function$
DECLARE
	v_virtual_size double precision;
	v_actual_size double precision;
BEGIN
	-- Summarize size of all disks that are active.
    SELECT COALESCE(sum(size) / (1024 * 1024 * 1024),0) INTO v_virtual_size
	FROM disk_image_dynamic, images_storage_domain_view
	WHERE image_guid = disk_image_dynamic.image_id
    AND image_guid in (SELECT image_guid FROM  images WHERE  active = TRUE)
	AND quota_id = v_quota_id
    AND (v_storage_id = images_storage_domain_view.storage_id or v_storage_id IS NULL);

	-- Summarize the actual size of all the rest disks that are read only disks such as snapshots, not active, template disks.
	SELECT COALESCE(sum(disk_image_dynamic.actual_size) / (1024 * 1024 * 1024),0) INTO v_actual_size
	FROM disk_image_dynamic, images_storage_domain_view
	WHERE image_guid = disk_image_dynamic.image_id
    AND image_guid not in (SELECT image_guid
                           FROM   images i JOIN vm_device vd ON i.image_group_id = vd.device_id
                           WHERE  active = TRUE)
	AND quota_id = v_quota_id
	AND (v_storage_id = images_storage_domain_view.storage_id or v_storage_id IS NULL);
	RETURN v_actual_size + v_virtual_size;
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function create_uuid_sequence() returns void
as $procedure$
begin
  if not exists (select 1 from information_schema.sequences where sequence_name = 'uuid_sequence') then
    create sequence uuid_sequence increment by 1 start with 1;
  end if;
end; $procedure$
language plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select create_uuid_sequence();
**************************

 

********* QUERY **********
drop function create_uuid_sequence();
**************************

DROP FUNCTION
********* QUERY **********
create or replace function uuid_generate_v1() returns uuid STABLE
as $procedure$
declare
    v_val bigint;
    v_4_part char(4);
    v_8_part char(8);
    v_12_part char(12);
    v_4_part_max int;
begin
    -- The only part we should use modulo is the 4 digit part, all the
    -- rest are really big numbers (i.e 16^8 - 1 and 16^12 - 1)
    -- The use of round(random() * 1000 is for getting a different id
    -- for DC/Cluster in different installations
    v_4_part_max = 65535; -- this is 16^4 -1
    v_val := nextval('uuid_sequence');
    v_4_part := lpad(to_hex(v_val % v_4_part_max), 4, '0');
    v_8_part := lpad(to_hex(v_val), 8, '0');
    v_12_part := lpad(to_hex((v_val + (round(random() * 1000))::bigint)), 12, '0');
    return v_8_part || v_4_part || v_4_part || v_4_part || v_12_part;
end; $procedure$
language plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_get_comparable_ip_list(text) RETURNS inet[] IMMUTABLE STRICT
AS $procedure$
BEGIN
CASE
    WHEN ($1 IS NULL) OR ($1 ~ E'^\s*$') THEN
        RETURN NULL;
    ELSE
        RETURN regexp_split_to_array(trim(both from $1), E'\s+')::inet[];
END CASE;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_add_column(v_table varchar(128), v_column varchar(128), v_column_def text)
returns void
AS $procedure$
declare
v_sql text;

begin
	if (not exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ADD COLUMN ' || v_column || ' ' || v_column_def;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_drop_column(v_table varchar(128), v_column varchar(128))
returns void
AS $procedure$
declare
v_sql text;
begin
        if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
            begin
                v_sql := 'ALTER TABLE ' || v_table || ' DROP COLUMN ' || v_column;
                EXECUTE v_sql;
            end;
        end if;
end;$procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_change_column_type(v_table varchar(128), v_column varchar(128),
                                                    v_type varchar(128), v_new_type varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column and (udt_name ilike v_type or data_type ilike v_type))) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ALTER COLUMN ' || v_column || ' TYPE ' || v_new_type;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_rename_column(v_table varchar(128), v_column varchar(128), v_new_name varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' RENAME COLUMN ' || v_column || ' TO ' || v_new_name;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (not exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            insert into vdc_options (option_name, option_value, version) values (v_option_name, v_option_value, v_version);
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value_all_versions(v_option_name varchar(100))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name)) then
        begin
            delete from vdc_options where option_name ilike v_option_name;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value(v_option_name varchar(100), v_version text)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version)))) then
        begin
            delete from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version));
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_for_version(v_version text)
returns void
AS $procedure$
BEGIN
     delete from vdc_options where version in (select ID from fnSplitter(v_version));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            update  vdc_options set option_value = v_option_value
            where option_name ilike v_option_name and version = v_version;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_default_config_value(v_option_name varchar(100),v_default_option_value varchar(4000),v_option_value varchar(4000),v_version varchar(40),v_ignore_default_value_case boolean)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            if (v_ignore_default_value_case)
            then
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value ilike v_default_option_value and version = v_version;
            else
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value = v_default_option_value and version = v_version;
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_rename_config_key(v_old_option_name varchar(100),v_new_option_name varchar(100),v_version varchar(40))
returns void
AS $procedure$
DECLARE
    v_current_option_value varchar(4000);
begin
    if (exists (select 1 from vdc_options where option_name ilike v_old_option_name and version = v_version)) then
       v_current_option_value:=option_value from vdc_options where option_name ilike v_old_option_name and version = v_version;
       update vdc_options set option_name = v_new_option_name, option_value = v_current_option_value
           where  option_name ilike v_old_option_name and version = v_version;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_create_constraint (
    v_table varchar(128), v_constraint varchar(128), v_constraint_sql text)
returns void
AS $procedure$
begin
    if  NOT EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' ADD CONSTRAINT ' || v_constraint || ' ' || v_constraint_sql;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_drop_constraint (
    v_table varchar(128), v_constraint varchar(128))
returns void
AS $procedure$
begin
    if  EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' DROP CONSTRAINT ' || v_constraint || ' CASCADE';
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION CheckDBConnection() RETURNS SETOF integer IMMUTABLE
   AS $procedure$
BEGIN
    RETURN QUERY SELECT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_functions_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'drop function if exists ' || ns.nspname || '.' || proname || '(' || oidvectortypes(proargtypes) || ') cascade;' from pg_proc inner join pg_namespace ns on (pg_proc.pronamespace=ns.oid) where ns.nspname = 'public' order by proname;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_views_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP VIEW if exists ' || table_name || ' CASCADE;' from information_schema.views where table_schema = 'public' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_tables_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP TABLE if exists ' || table_name || ' CASCADE;' from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_seq_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP SEQUENCE if exists ' || sequence_name || ' CASCADE;' from information_schema.sequences  where sequence_schema = 'public' order by sequence_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_user_types_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT 'DROP TYPE if exists ' || c.relname::information_schema.sql_identifier || ' CASCADE;'
   FROM pg_namespace n, pg_class c, pg_type t
   WHERE n.oid = c.relnamespace and t.typrelid = c.oid and c.relkind = 'c'::"char" and
   n.nspname = 'public'
   ORDER BY  c.relname::information_schema.sql_identifier;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_get_column_size( v_table varchar(64), v_column varchar(64)) returns integer STABLE
   AS $procedure$
   declare
   retvalue  integer;
BEGIN
   retvalue := character_maximum_length from information_schema.columns
    where
    table_name ilike v_table and column_name ilike v_column and
    table_schema = 'public' and udt_name in ('char','varchar');
   return retvalue;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION attach_user_to_role (
    v_domain_entry_id text,
    v_user_name VARCHAR(255),
    v_domain VARCHAR(255),
    v_role_name VARCHAR(255)
)
RETURNS void AS
$BODY$
DECLARE
   gen_user_id uuid;
   input_role_id uuid;
BEGIN
   select uuid_generate_v1() into gen_user_id;
   select roles.id into input_role_id from roles where roles.name = v_role_name;
   -- The external identifier is the user identifier converted to an array of
   -- bytes:
   insert into users(user_id,external_id,name,domain,username,groups,active,last_admin_check_status) select gen_user_id, v_domain_entry_id, v_user_name, v_domain, v_user_name,'',true,true where not exists (select gen_user_id,name,domain,username,groups,active from users where external_id = v_domain_entry_id);
   insert into permissions(id,role_id,ad_element_id,object_id,object_type_id) select uuid_generate_v1(),  input_role_id, gen_user_id, getGlobalIds('system'), 1 where not exists(select role_id,ad_element_id,object_id,object_type_id from permissions where role_id = input_role_id and ad_element_id = gen_user_id and object_id= getGlobalIds('system') and object_type_id = 1);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_add_action_group_to_role(v_role_id UUID, v_action_group_id INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
       INSERT INTO roles_groups(role_id,action_group_id)
       SELECT v_role_id, v_action_group_id
       WHERE NOT EXISTS (SELECT 1
                         FROM roles_groups
                         WHERE role_id = v_role_id
                         AND action_group_id = v_action_group_id);
RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_split_config_value(v_option_name character varying, v_old_option_value character varying, v_new_option_value character varying, v_update_from_version character varying)
  RETURNS void AS
$BODY$
declare
v_old_value varchar(4000);
v_cur cursor for select distinct version from vdc_options where version <> 'general' order by version;
v_version varchar(40);
v_index integer;
v_count integer;
v_total_count integer;
v_version_count integer;
begin
    v_total_count := count(version) from vdc_options where option_name = v_option_name;
    v_old_value := option_value from vdc_options where option_name = v_option_name and version = 'general';
    v_version_count := count(distinct version) from vdc_options where version <> 'general';
    if (v_total_count <= v_version_count) then
        begin
            if (v_old_value IS NULL) then
                v_old_value := v_old_option_value;
            end if;
            v_count := count(distinct version) from vdc_options where version <> 'general';
            v_index := 1;
        open v_cur;
        loop
            fetch v_cur into v_version;
            exit when not found;
            -- We shouldn't update if already exists
            if (not exists (select 1 from vdc_options where option_name = v_option_name and version = v_version)) then
                -- Might not work well for versions such as 3.10, but we currently don't have any
                if (v_version >= v_update_from_version) then
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_new_option_value, v_version);
                else
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_old_value, v_version);
                end if;
            end if;
            v_index := v_index +1;
        end loop;
        close v_cur;
        delete from vdc_options where option_name = v_option_name and version = 'general';
        end;
    end if;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_grant_action_group_to_all_roles_filter(v_action_group_id integer, uuid[])
  RETURNS void AS
$BODY$
declare
v_role_id_to_filter alias for $2;
begin
    insert into roles_groups (role_id, action_group_id)
    select distinct role_id, v_action_group_id
    from roles_groups rg
    where not ARRAY [role_id] <@ v_role_id_to_filter and not exists (select 1 from roles_groups where role_id = rg.role_id and action_group_id = v_action_group_id);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_mask_object(v_object regclass) RETURNS setof record as
$BODY$
DECLARE
    v_sql TEXT;
    v_table record;
    v_table_name TEXT;
    temprec record;
BEGIN
    -- get full table/view name from v_object (i.e <namespace>.<name>)
    select c.relname, n.nspname INTO v_table
        FROM pg_class c join pg_namespace n on c.relnamespace = n.oid WHERE c.oid = v_object;
    -- try to get filtered query syntax from previous execution
    if exists (select 1 from object_column_white_list_sql where object_name = v_table.relname) then
	select sql into v_sql from object_column_white_list_sql where object_name = v_table.relname;
    else
        v_table_name := quote_ident( v_table.nspname ) || '.' || quote_ident( v_table.relname );
        -- compose sql statement while skipping values for columns not defined in object_column_white_list for this table.
        for temprec in select a.attname, t.typname
                       FROM pg_attribute a join pg_type t on a.atttypid = t.oid
                       WHERE a.attrelid = v_object AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
        loop
            v_sql := coalesce( v_sql || ', ', 'SELECT ' );
            if exists(select 1 from object_column_white_list
               where object_name = v_table.relname and column_name = temprec.attname) then
               v_sql := v_sql || quote_ident( temprec.attname );
            ELSE
               v_sql := v_sql || 'NULL::' || quote_ident( temprec.typname ) || ' as ' || quote_ident( temprec.attname );
            END IF;
        END LOOP;
        v_sql := v_sql || ' FROM ' || v_table_name;
        v_sql := 'SELECT x::' || v_table_name || ' as rec FROM (' || v_sql || ') as x';
        -- save generated query for further use
        insert into object_column_white_list_sql(object_name,sql) values (v_table.relname, v_sql);
    end if;
    RETURN QUERY EXECUTE v_sql;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_column_to_object_white_list(v_object_name varchar(128), v_column_name varchar(128))
returns void
AS $procedure$
begin
    if (not exists (select 1 from object_column_white_list
                    where object_name = v_object_name and column_name = v_column_name)) then
        begin
            -- verify that there is such object in db
            if exists (select 1 from information_schema.columns
                       where table_name = v_object_name and column_name = v_column_name) then
                insert into object_column_white_list (object_name, column_name) values (v_object_name, v_column_name);
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_disk(v_id UUID)
returns void
AS $procedure$
declare
    OK integer;
    LOCKED integer;
begin
    OK:=1;
    LOCKED:=2;
    update images set imagestatus = OK where imagestatus = LOCKED and
    image_group_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_snapshot(v_id UUID)
returns void
AS $procedure$
declare
    OK varchar;
    LOCKED varchar;
begin
    OK:='OK';
    LOCKED:='LOCKED';
    update snapshots set status = OK where status = LOCKED and snapshot_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_entity(v_object_type varchar(10), v_name varchar(255), v_recursive boolean)
returns void
AS $procedure$
declare
    DOWN integer;
    OK integer;
    LOCKED integer;
    TEMPLATE_OK integer;
    TEMPLATE_LOCKED integer;
    IMAGE_LOCKED integer;
    SNAPSHOT_OK varchar;
    SNAPSHOT_LOCKED varchar;
    v_id UUID;
begin
    DOWN:=0;
    OK:=1;
    LOCKED:=2;
    TEMPLATE_OK:=0;
    TEMPLATE_LOCKED:=1;
    IMAGE_LOCKED:=15;
    SNAPSHOT_OK:='OK';
    SNAPSHOT_LOCKED:='LOCKED';
    v_id := vm_guid from vm_static where vm_name = v_name and entity_type ilike v_object_type;
    -- set VM status to DOWN
    if (v_object_type = 'vm') then
        update vm_dynamic set status = DOWN where status = IMAGE_LOCKED and vm_guid  = v_id;
    -- set Template status to OK
    else
        if (v_object_type = 'template') then
            update vm_static set template_status = TEMPLATE_OK where template_status = TEMPLATE_LOCKED and vm_guid  = v_id;
        end if;
    end if;
    --unlock images and snapshots  if recursive flag is set
    if (v_recursive) then
        update images set imagestatus = OK where imagestatus = LOCKED and
        image_group_id in (select device_id from vm_device where vm_id = v_id and is_plugged);

        update snapshots set status = SNAPSHOT_OK where status ilike SNAPSHOT_LOCKED and vm_id = v_id;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/* Displays DC id , DC name, SPM Host id , SPM Host name and number of async tasks awaiting.

1) create a record type with DC name, DC id, SPM host id, SPM host name, count

2) get all distinct DC ids from async_tasks table

3) Run a cursor for each result in 2)

   a) get DC name
   b) get SPM Host id & name if available
   c) get count of tasks

   return current record

4) return set of generated records
*/
DROP TYPE IF EXISTS async_tasks_info_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE async_tasks_info_rs AS (
        dc_id uuid,
        dc_name character varying,
        spm_host_id uuid,
        spm_host_name character varying,
        task_count integer
);
**************************

CREATE TYPE
********* QUERY **********
create or replace FUNCTION fn_db_get_async_tasks()
returns SETOF async_tasks_info_rs STABLE
AS $procedure$
DECLARE
    v_record async_tasks_info_rs;

    -- selects storage_pool_id uuid found in async_tasks
    v_tasks_cursor cursor for select distinct storage_pool_id from async_tasks;
begin

    OPEN v_tasks_cursor;
    FETCH v_tasks_cursor into v_record.dc_id;
    WHILE FOUND LOOP
        -- get dc_name and SPM Host id
        v_record.dc_name := name from storage_pool where id = v_record.dc_id;
        v_record.spm_host_id :=
            spm_vds_id from storage_pool where id = v_record.dc_id;
        -- get Host name if we have non NULL SPM Host
        if (v_record.spm_host_id IS NOT NULL) then
            v_record.spm_host_name :=
                vds_name from vds_static where vds_id = v_record.spm_host_id;
        else
            v_record.spm_host_name:='';
        end if;
        -- get tasks count for this DC
        v_record.task_count := count(*) from async_tasks
            where position (cast(v_record.dc_id as varchar) in action_parameters) > 0;
        -- return the record
        RETURN NEXT v_record;
        FETCH v_tasks_cursor into v_record.dc_id;
    END LOOP;
    CLOSE v_tasks_cursor;
    -- return full set of generated records
    RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_remove_csv_config_value(v_option_name varchar(100), v_value varchar(4000), v_version varchar(40))
returns void
AS $procedure$
DECLARE
v varchar[];
e varchar;
v_result varchar;
v_sep varchar(1);
BEGIN
v_result := '';
v_sep := '';
    v := string_to_array(option_value, ',') from vdc_options where option_name = v_option_name and version = v_version;
    FOR e in select unnest(v)
    LOOP
        IF (e != v_value) THEN
            v_result := v_result || v_sep || e;
            v_sep := ',';
        END IF;
    END LOOP;
    UPDATE vdc_options set option_value = v_result where option_name = v_option_name and version = v_version;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT setval('vdc_options_seq', max(option_id)) FROM vdc_options;
**************************

      1

********* QUERY **********
SELECT setval('custom_actions_seq', max(action_id)) FROM custom_actions;
**************************

       

********* QUERY **********
SELECT setval('vdc_db_log_seq', max(error_id)) FROM vdc_db_log;
**************************

       

********* QUERY **********
SELECT setval('audit_log_seq', max(audit_log_id)) FROM audit_log;
**************************

       

********* QUERY **********
SELECT setval('schema_version_seq', max(id)) FROM schema_version;
**************************

      1

********* QUERY **********
/************************************************************************************
                DATABASE APPLICATION CONFIGURATION FILE

This file is used to update the vdc_options configuration table.
The following sections are available:
    Add Section
    Update section (w/o overriding current value)
    Delete section
    Split config section
    Simple upgrades not available using a fn_db* function call
    Complex upgrades using temporary functions

In each section (except simple/function sections), entries are ordered by key,
please keep this when modifing this file.

PLEASE NOTE THAT THIS SCRIPT MUST REMAIN RE-ENTRANT!

************************************************************************************/



select fn_db_rename_config_key('AuditLogAgingThreashold', 'AuditLogAgingThreshold', 'general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('ClientConsoleModeDefault', 'ClientModeSpiceDefault', 'general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('PowerClientAutoApprovePatterns','AutoApprovePatterns','general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('PowerClientAutoRegistrationDefaultVdsGroupID','AutoRegistrationDefaultVdsGroupID','general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('PowerClientAutoInstallCertificateOnApprove','AutoInstallCertificateOnApprove','general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('UseSecureConnectionWithServers', 'EncryptHostCommunication', 'general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('SpiceReleaseCursorKeys', 'ConsoleReleaseCursorKeys', 'general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('SpiceToggleFullScreenKeys', 'ConsoleToggleFullScreenKeys', 'general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('SSHInactivityTimoutSeconds', 'SSHInactivityTimeoutSeconds', 'general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('SSHInactivityHardTimoutSeconds', 'SSHInactivityHardTimeoutSeconds', 'general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('StorageDomainFalureTimeoutInMinutes', 'StorageDomainFailureTimeoutInMinutes', 'general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('VdsLoadBalancingeIntervalInMinutes', 'VdsLoadBalancingIntervalInMinutes', 'general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('VdsRecoveryTimeoutInMintues', 'VdsRecoveryTimeoutInMinutes', 'general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('UknownTaskPrePollingLapse', 'UnknownTaskPrePollingLapse', 'general');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('GlusterAysncTasksSupport', 'GlusterAsyncTasksSupport', '3.0');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('GlusterAysncTasksSupport', 'GlusterAsyncTasksSupport', '3.1');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('GlusterAysncTasksSupport', 'GlusterAsyncTasksSupport', '3.2');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('GlusterAysncTasksSupport', 'GlusterAsyncTasksSupport', '3.3');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('NormalizedMgmgNetworkEnabled', 'NormalizedMgmtNetworkEnabled', '3.0');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('NormalizedMgmgNetworkEnabled', 'NormalizedMgmtNetworkEnabled', '3.1');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('NormalizedMgmgNetworkEnabled', 'NormalizedMgmtNetworkEnabled', '3.2');
**************************

 

********* QUERY **********
select fn_db_rename_config_key('DefaultMtu', 'DefaultMTU', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AbortMigrationOnError','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AbortMigrationOnError','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AbortMigrationOnError','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AbortMigrationOnError','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('BootstrapMinimalVdsmVersion','4.9','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CpuPinMigrationEnabled','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CpuPinningEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AdminDomain','internal','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AdminPassword','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AdminUser','admin','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AdUserId','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AdUserName','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AdUserPassword','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AdvancedNFSOptionsEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AgentAppName','ovirt-guest-agent-common,ovirt-guest-agent','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AllowClusterWithVirtGlusterEnabled','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AllowDuplicateMacAddresses','false','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ApplicationMode','255','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AsyncCommandPollingRateInSeconds','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AsyncTaskPollingRate','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AsyncTaskStatusCacheRefreshRateInSeconds','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AsyncTaskStatusCachingTimeInMinutes','1','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AsyncTaskZombieTaskLifeInMinutes','300','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AuditLogAgingThreshold','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AuditLogCleanupTime','03:35:35','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CommandCoordinatorThreadPoolSize','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CommandEntityAgingThreshold','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CommandEntityCleanupTime','03:35:35','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OnlyRequiredNetworksMandatoryForVdsSelection','false','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AuthenticationMethod','LDAP','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AutoApprovePatterns','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AutoInstallCertificateOnApprove','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AutoRecoverySchedule','0 0/5 * * * ?','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AutoRegistrationDefaultVdsGroupID','99408929-82CF-4DC7-A532-9D998063FA95','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AutoRepoDomainRefreshTime','60','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('BlockMigrationOnSwapUsagePercentage','0','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CipherSuite','DEFAULT','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ConfigDir','/etc/engine','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ConnectToServerTimeoutInSeconds','20','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterEmulatedMachines','rhel6.2.0,pc-1.0','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterEmulatedMachines','rhel6.3.0,pc-1.0','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterEmulatedMachines','rhel6.4.0,pc-1.0','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterEmulatedMachines','rhel6.4.0,pc-1.0,pseries','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterEmulatedMachines','rhel6.5.0,pc-1.0,pseries','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterEmulatedMachines','rhel6.5.0,pc-1.0,pseries','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CpuOverCommitDurationMinutes','2','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DataDir','/usr/share/engine','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DBEngine','Postgres','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DebugTimerLogging','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultMaxThreadPoolSize','500','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultMinThreadPoolSize','50','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultMaxThreadWaitQueueSize','100','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultWindowsTimeZone','GMT Standard Time','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultGeneralTimeZone','Etc/GMT','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultWorkgroup','WORKGROUP','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DisableFenceAtStartupInSec','300','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DirectLUNDiskEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DomainName','example.com','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('EnableHostTimeDrift','false','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('EnableSpiceRootCertificateValidation','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('EnableSwapCheck','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('EnableUSBAsDefault','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('EnableVdsLoadBalancing','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('EngineMode','Active','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FailedJobCleanupTimeInMinutes','60','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceAgentDefaultParams','ilo3:lanplus,power_wait=4;ilo4:lanplus,power_wait=4','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CustomFenceAgentDefaultParams','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceAgentMapping','drac7=ipmilan,ilo2=ilo,ilo3=ipmilan,ilo4=ipmilan','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CustomFenceAgentMapping','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CustomFencePowerWaitParam','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceProxyDefaultPreferences','cluster,dc','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceQuietTimeBetweenOperationsInSec','180','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceStartStatusDelayBetweenRetriesInSec','60','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceStartStatusRetries','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceStopStatusDelayBetweenRetriesInSec','60','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceStopStatusRetries','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FencePowerWaitParam','apc=power_wait,apc_snmp=power_wait,bladecenter=power_wait,cisco_ucs=power_wait,drac5=power_wait,drac7=power_wait,eps=delay,hpblade=power_wait,ilo=power_wait,ilo2=power_wait,ilo3=power_wait,ilo4=power_wait,ipmilan=power_wait,rsa=power_wait,rsb=power_wait,wti=power_wait','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FilteringLUNsEnabled','true','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FindFenceProxyDelayBetweenRetriesInSec','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FindFenceProxyRetries','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FreeSpaceCriticalLowInGB','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FreeSpaceLow','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VirtIoRngDeviceSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VirtIoRngDeviceSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VirtIoRngDeviceSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VirtIoRngDeviceSupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VirtIoRngDeviceSupported','false', '3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VirtIoRngDeviceSupported','true', '3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterHooksEnabled', 'false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterHooksEnabled', 'false', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterHooksEnabled', 'false', '3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterHostUUIDSupport', 'false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterHostUUIDSupport', 'false', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterHostUUIDSupport', 'false', '3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterRefreshHeavyWeight', 'false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterRefreshHeavyWeight', 'false', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterRefreshRateHooks', '7200', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterRefreshRateLight', '5', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterRefreshRateHeavy', '300', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterServicesEnabled', 'false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterServicesEnabled', 'false', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterServicesEnabled', 'false', '3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterSupport', 'false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterSupportForceCreateVolume', 'false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterSupportForceCreateVolume', 'false', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterSupportForceCreateVolume', 'false', '3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterSupportForceCreateVolume', 'false', '3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterVolumeOptionGroupVirtValue','virt','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterVolumeOptionOwnerUserVirtValue','36','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterVolumeOptionOwnerGroupVirtValue','36','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterRefreshRateTasks', '60', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterAsyncTasksSupport', 'false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterAsyncTasksSupport', 'false', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterAsyncTasksSupport', 'false', '3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterAsyncTasksSupport', 'false', '3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterPeerStatusRetries', '2', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterTaskMinWaitForCleanupInMins', '10', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('KeystoneAuthUrl', '', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GuestToolsSetupIsoPrefix','ovirt-guest-tools-','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HardwareInfoEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HardwareInfoEnabled','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HighUtilizationForEvenlyDistribute','75','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HighUtilizationForPowerSave','75','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HostPreparingForMaintenanceIdleTime', '300', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HostTimeDriftInSec','300','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HotPlugEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HotPlugCpuSupported','{"x86_64":"false","ppc64":"false"}','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HotPlugCpuSupported','{"x86_64":"false","ppc64":"false"}','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HotPlugCpuSupported','{"x86_64":"false","ppc64":"false"}','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HotPlugCpuSupported','{"x86_64":"false","ppc64":"false"}','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HotPlugCpuSupported','{"x86_64":"true","ppc64":"false"}','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HotPlugCpuSupported','{"x86_64":"true","ppc64":"false"}','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IsMigrationSupported','{"undefined": "true", "x86_64": "true", "ppc64" : "false" }','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IsMemorySnapshotSupported','{"undefined": "true", "x86_64": "true", "ppc64" : "false" }','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IsSuspendSupported','{"undefined": "true", "x86_64": "true", "ppc64" : "false" }','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MigrationSupportForNativeUsb','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MigrationSupportForNativeUsb','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NetworkLinkingSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NetworkLinkingSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DisconnectPoolOnReconstruct','0,2','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('InitStorageSparseSizeInGB','1','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('TunnelMigrationEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('TunnelMigrationEnabled','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('TunnelMigrationEnabled','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MigrationNetworkEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MigrationNetworkEnabled','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MigrationNetworkEnabled','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MultipleGatewaysSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MultipleGatewaysSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MultipleGatewaysSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MemorySnapshotSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MemorySnapshotSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MemorySnapshotSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OsRepositoryConfDir','/osinfo.conf.d','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VirtIoScsiEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VirtIoScsiEnabled','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VirtIoScsiEnabled','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NormalizedMgmtNetworkEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NormalizedMgmtNetworkEnabled','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NormalizedMgmtNetworkEnabled','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IterationsWithBalloonProblem','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MomPoliciesOnHostSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MomPoliciesOnHostSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MomPoliciesOnHostSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NetworkQosSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NetworkQosSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NetworkQosSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StorageQosSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StorageQosSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StorageQosSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StorageQosSupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StorageQosSupported','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CpuQosSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CpuQosSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CpuQosSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CpuQosSupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CpuQosSupported','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HostNetworkQosSupported', 'false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HostNetworkQosSupported', 'false', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HostNetworkQosSupported', 'false', '3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HostNetworkQosSupported', 'false', '3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CloudInitSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CloudInitSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CloudInitSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultSysprepLocale','en_US','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ImportGlanceImageAsTemplate','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ImportGlanceImageAsTemplate','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ImportGlanceImageAsTemplate','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ImportGlanceImageAsTemplate','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HotPlugDiskSnapshotSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HotPlugDiskSnapshotSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HotPlugDiskSnapshotSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GetFileStats','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GetFileStats','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GetFileStats','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GetFileStats','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultRouteSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultRouteSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultRouteSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultRouteSupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SerialNumberPolicySupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SerialNumberPolicySupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SerialNumberPolicySupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SerialNumberPolicySupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SerialNumberPolicySupported','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OvfStoreOnAnyDomain','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OvfStoreOnAnyDomain','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OvfStoreOnAnyDomain','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OvfStoreOnAnyDomain','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OvfStoreOnAnyDomain','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('BootMenuSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('BootMenuSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('BootMenuSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('BootMenuSupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('BootMenuSupported','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IscsiMultipathingSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IscsiMultipathingSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IscsiMultipathingSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IscsiMultipathingSupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ImportDataStorageDomain','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ImportDataStorageDomain','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ImportDataStorageDomain','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ImportDataStorageDomain','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ImportDataStorageDomain','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MixedDomainTypesInDataCenter','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MixedDomainTypesInDataCenter','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MixedDomainTypesInDataCenter','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MixedDomainTypesInDataCenter','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MixedDomainTypesInDataCenter','true','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MixedDomainTypesInDataCenter','true','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterRequiredRngSourcesDefault','','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterRequiredRngSourcesDefault','','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterRequiredRngSourcesDefault','','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterRequiredRngSourcesDefault','','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterRequiredRngSourcesDefault','','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClusterRequiredRngSourcesDefault','','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceCopyPasteToggleSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceCopyPasteToggleSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceCopyPasteToggleSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceCopyPasteToggleSupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceCopyPasteToggleSupported','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceFileTransferToggleSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceFileTransferToggleSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceFileTransferToggleSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceFileTransferToggleSupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceFileTransferToggleSupported','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceFileTransferToggleSupported','false','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StoragePoolMemoryBackend','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StoragePoolMemoryBackend','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StoragePoolMemoryBackend','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StoragePoolMemoryBackend','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StoragePoolMemoryBackend','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('JsonProtocolSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('JsonProtocolSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('JsonProtocolSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('JsonProtocolSupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('JsonProtocolSupported','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmSlaPolicySupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmSlaPolicySupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmSlaPolicySupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmSlaPolicySupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmSlaPolicySupported','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceProxyDefault','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('InstallVds','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IoOpTimeoutSec','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IPTablesConfig',
'# oVirt default firewall configuration. Automatically generated by vdsm bootstrap script.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
# vdsm
-A INPUT -p tcp --dport @VDSM_PORT@ -j ACCEPT
# libvirt tls
-A INPUT -p tcp --dport 16514 -j ACCEPT
# SSH
-A INPUT -p tcp --dport @SSH_PORT@ -j ACCEPT
# guest consoles
-A INPUT -p tcp -m multiport --dports 5900:6923 -j ACCEPT
# migration
-A INPUT -p tcp -m multiport --dports 49152:49216 -j ACCEPT
# snmp
-A INPUT -p udp --dport 161 -j ACCEPT
# Reject any other input traffic
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -m physdev ! --physdev-is-bridged -j REJECT --reject-with icmp-host-prohibited
COMMIT
','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IPTablesConfigForGluster',
'
# glusterd
-A INPUT -p tcp -m tcp --dport 24007 -j ACCEPT

# gluster swift
-A INPUT -p tcp -m tcp --dport 8080  -j ACCEPT

# portmapper
-A INPUT -p udp -m udp --dport 111   -j ACCEPT
-A INPUT -p tcp -m tcp --dport 38465 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 38466 -j ACCEPT

# nfs
-A INPUT -p tcp -m tcp --dport 38467 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 2049  -j ACCEPT
-A INPUT -p tcp -m tcp --dport 38469 -j ACCEPT

# nrpe
-A INPUT -p tcp --dport 5666 -j ACCEPT

# status
-A INPUT -p tcp -m tcp --dport 39543 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 55863 -j ACCEPT

# nlockmgr
-A INPUT -p tcp -m tcp --dport 38468 -j ACCEPT
-A INPUT -p udp -m udp --dport 963   -j ACCEPT
-A INPUT -p tcp -m tcp --dport 965   -j ACCEPT

# ctdbd
-A INPUT -p tcp -m tcp --dport 4379  -j ACCEPT

# smbd
-A INPUT -p tcp -m tcp --dport 139   -j ACCEPT
-A INPUT -p tcp -m tcp --dport 445   -j ACCEPT

# Ports for gluster volume bricks (default 100 ports)
-A INPUT -p tcp -m tcp --dport 24009:24108 -j ACCEPT
','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IPTablesConfigForVirt',
'
# libvirt tls
-A INPUT -p tcp --dport 16514 -j ACCEPT

# guest consoles
-A INPUT -p tcp -m multiport --dports 5900:6923 -j ACCEPT

# migration
-A INPUT -p tcp -m multiport --dports 49152:49216 -j ACCEPT
', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IPTablesConfigSiteCustom','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('IsMultilevelAdministrationOn','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('JobCleanupRateInMinutes','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('JobPageSize','100','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LdapQueryPageSize','1000','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LDAPQueryTimeout','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LDAPConnectTimeout','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LDAPOperationTimeout','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LDAPSecurityAuthentication','GSSAPI','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LDAPServerPort','389','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LdapServers','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LDAPProviderTypes','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LeaseRetries','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LeaseTimeSec','60','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LicenseCertificateFingerPrint','5f 38 41 89 b1 33 49 0c 24 13 6b b3 e5 ba 9e c7 fd 83 80 3b','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LiveMergeSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LiveMergeSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LiveMergeSupported','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LiveMergeSupported','false','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LiveMergeSupported','false','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LiveSnapshotEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LocalAdminPassword','123456','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LockPolicy','ON','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LockRenewalIntervalSec','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LogPhysicalMemoryThresholdInMB','1024','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LowUtilizationForEvenlyDistribute','0','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LowUtilizationForPowerSave','20','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MacPoolRanges','00:1A:4A:16:01:51-00:1A:4A:16:01:e6','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ManagedDevicesWhiteList','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ManagementNetwork','ovirtmgmt','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxAuditLogMessageLength','10000','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxBlockDiskSize','8192','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxLDAPQueryPartsNumber','100','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxMacsCountInPool','100000','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumberOfHostsInStoragePool','250','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfCpuPerSocket','16','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfCpuPerSocket','16','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfCpuPerSocket','16','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfCpuPerSocket','16','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfCpuPerSocket','16','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfCpuPerSocket','16','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmCpus','64','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmCpus','160','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmCpus','160','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmCpus','160','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmCpus','160','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmCpus','160','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmSockets','16','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmSockets','16','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmSockets','16','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmSockets','16','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmSockets','16','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfVmSockets','16','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxRerunVmOnVdsCount','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxStorageVdsDelayCheckSec','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxStorageVdsTimeoutCheckSec','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxVdsMemOverCommit','200','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxVdsMemOverCommitForServers','150','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxVdsNameLength','255','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxVmNameLengthNonWindows','64','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxVmNameLengthWindows','15','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxVmsInPool','1000','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MinimalETLVersion','3.0.0','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NativeUSBEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NicDHCPDelayGraceInMS','60','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NonVmNetworkSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NumberOfFailedRunsOnVds','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NumberOfUSBSlots','4','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NumberVmRefreshesBeforeSave','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportBridgesReportByVDSM','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportBridgesReportByVDSM','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MacAntiSpoofingFilterRulesSupported','false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MacAntiSpoofingFilterRulesSupported','false', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('EnableMACAntiSpoofingFilterRules','true', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterFsStorageEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterFsStorageEnabled','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlusterFsStorageEnabled','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxSchedulerWeight','1000','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MTUOverrideSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PortMirroringSupported','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PortMirroringSupported','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpeedOptimizationSchedulingThreshold','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SchedulerAllowOverBooking','false','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SchedulerOverBookingThreshold','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UploadFileMaxTimeInMinutes','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('RetrieveDataMaxTimeInMinutes','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StorageDomainOvfStoreCount','2','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OrganizationName','oVirt','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OriginType','OVIRT','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OvfVirtualSystemType','ENGINE','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OvirtInitialSupportedIsoVersion','2.5.5:5.8','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OvirtIsoPrefix','^ovirt-node-iso-([0-9].*)\.iso$:^rhevh-([0-9].*)\.iso$','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OvirtNodeOS','^ovirt.*$:^rhev.*$','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('oVirtISOsRepositoryPath','/usr/share/ovirt-node-iso:/usr/share/rhev-hypervisor','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('oVirtUpgradeScriptName','/usr/share/vdsm-reg/vdsm-upgrade','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('oVirtUploadPath','/data/updates/ovirt-node-image.iso','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OvfUpdateIntervalInMinutes','60','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OvfItemsCountPerUpdate','100','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PayloadSize','8192','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PMHealthCheckEnabled','false','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PMHealthCheckIntervalInSec','3600','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PosixStorageEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PostgresI18NPrefix','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PostgresLikeSyntax','ILIKE','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PostgresPagingSyntax',E' OFFSET (%1$s -1) LIMIT %2$s','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PostgresPagingType','Offset','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PostgresSearchTemplate',E'SELECT * FROM (%2$s) %1$s) as T1 %3$s','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PredefinedVMProperties','sap_agent=^(true|false)$;sndbuf=^[0-9]+$;vhost=^(([a-zA-Z0-9_]*):(true|false))(,(([a-zA-Z0-9_]*):(true|false)))*$;viodiskcache=^(none|writeback|writethrough)$','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PredefinedVMProperties','sap_agent=^(true|false)$;sndbuf=^[0-9]+$;vhost=^(([a-zA-Z0-9_]*):(true|false))(,(([a-zA-Z0-9_]*):(true|false)))*$;viodiskcache=^(none|writeback|writethrough)$','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PredefinedVMProperties','sap_agent=^(true|false)$;sndbuf=^[0-9]+$;vhost=^(([a-zA-Z0-9_]*):(true|false))(,(([a-zA-Z0-9_]*):(true|false)))*$;viodiskcache=^(none|writeback|writethrough)$','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PredefinedVMProperties','sap_agent=^(true|false)$;sndbuf=^[0-9]+$;vhost=^(([a-zA-Z0-9_]*):(true|false))(,(([a-zA-Z0-9_]*):(true|false)))*$;viodiskcache=^(none|writeback|writethrough)$','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PredefinedVMProperties','sap_agent=^(true|false)$;sndbuf=^[0-9]+$;vhost=^(([a-zA-Z0-9_]*):(true|false))(,(([a-zA-Z0-9_]*):(true|false)))*$;viodiskcache=^(none|writeback|writethrough)$','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PredefinedVMProperties','sap_agent=^(true|false)$;sndbuf=^[0-9]+$;vhost=^(([a-zA-Z0-9_]*):(true|false))(,(([a-zA-Z0-9_]*):(true|false)))*$;viodiskcache=^(none|writeback|writethrough)$','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ProductRPMVersion','3.0.0.0','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('QuotaGraceStorage','20','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('QuotaGraceVdsGroup','20','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('QuotaThresholdStorage','80','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('QuotaThresholdVdsGroup','80','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('RhevhLocalFSPath','/data/images/','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SANWipeAfterDelete','false','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SASL_QOP','auth-conf','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SearchResultsLimit','100','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SendSMPOnRunVm','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SendVmTicketUID','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64;','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64;','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 8:Intel Haswell Family:vmx,nx,model_Haswell:Haswell:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64; 6:AMD Opteron G5:svm,nx,model_Opteron_G5:Opteron_G5:x86_64;','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 8:Intel Haswell Family:vmx,nx,model_Haswell:Haswell:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64; 6:AMD Opteron G5:svm,nx,model_Opteron_G5:Opteron_G5:x86_64; :IBM POWER 7 v2.0:powernv,model_POWER7_v2.0:POWER7_v2.0:ppc64; :IBM POWER 7 v2.1:powernv,model_POWER7_v2.1:POWER7_v2.1:ppc64; :IBM POWER 7 v2.3:powernv,model_POWER7_v2.3:POWER7_v2.3:ppc64; :IBM POWER 7+ v2.1:powernv,model_POWER7+_v2.1:POWER7+_v2.1:ppc64; :IBM POWER 8 v1.0:powernv,model_POWER8_v1.0:POWER8_v1.0:ppc64;','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 8:Intel Haswell Family:vmx,nx,model_Haswell:Haswell:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64; 6:AMD Opteron G5:svm,nx,model_Opteron_G5:Opteron_G5:x86_64; 3:IBM POWER 8:powernv,model_power8:power8:ppc64;','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 8:Intel Haswell Family:vmx,nx,model_Haswell:Haswell:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64; 6:AMD Opteron G5:svm,nx,model_Opteron_G5:Opteron_G5:x86_64; 3:IBM POWER 8:powernv,model_power8:power8:ppc64;','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ServerRebootTimeout','300','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SetupNetworksPollingTimeout','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ShareableDiskEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SignCertTimeoutInSeconds','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceDriverNameInGuest','RHEV-Spice','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ConsoleReleaseCursorKeys','shift+f12','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ConsoleToggleFullScreenKeys','shift+f11','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpiceUsbAutoShare','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('WANDisableEffects','animation','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('WANColorDepth','16','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpmCommandFailOverRetries','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SPMFailOverAttempts','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SpmVCpuConsumption','1','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SSHInactivityTimeoutSeconds','300','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SSHInactivityHardTimeoutSeconds','1800','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SSLEnabled','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StorageDomainFailureTimeoutInMinutes','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StorageDomainNameSizeLimit','50','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StoragePoolNameSizeLimit','40','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StoragePoolNonOperationalResetTimeoutInMin','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('StoragePoolRefreshTimeInSeconds','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HostStorageConnectionAndPoolRefreshTimeInSeconds','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SucceededJobCleanupTimeInMinutes','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportedClusterLevels','3.0','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportedStorageFormats','0,2','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportedStorageFormats','0,2,3','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportedStorageFormats','0,2,3','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportedStorageFormats','0,2,3','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportedStorageFormats','0,2,3','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportedStorageFormats','0,2,3','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportedVDSMVersions','4.9,4.10,4.11,4.12,4.13,4.14','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportForceCreateVG','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportForceExtendVG','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportForceExtendVG','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrep2K3Path','/etc/ovirt-engine/sysprep/sysprep.2k3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrep2K8Path','/etc/ovirt-engine/sysprep/sysprep.2k8x86','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrep2K8R2Path','/etc/ovirt-engine/sysprep/sysprep.2k8','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrep2K8x64Path','/etc/ovirt-engine/sysprep/sysprep.2k8','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrepDefaultPassword','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrepDefaultUser','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrepWindows7Path','/etc/ovirt-engine/sysprep/sysprep.w7','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrepWindows7x64Path','/etc/ovirt-engine/sysprep/sysprep.w7x64','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrepWindows8Path','/etc/ovirt-engine/sysprep/sysprep.w8','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrepWindows8x64Path','/etc/ovirt-engine/sysprep/sysprep.w8x64','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrepWindows2012x64Path','/etc/ovirt-engine/sysprep/sysprep.2k12x64','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SysPrepXPPath','/etc/ovirt-engine/sysprep/sysprep.xp','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ThrottlerMaxWaitForVdsUpdateInMillis','10000','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('TimeoutToResetVdsInSeconds','60','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DelayResetForSpmInSeconds','20','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DelayResetPerVmInSeconds','0.5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('EncryptHostCommunication','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('TimeToReduceFailedRunOnVdsInMinutes','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UnknownTaskPrePollingLapse','60000','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UserSessionHardLimit','600','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UserDefinedVMProperties','','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UserDefinedVMProperties','','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UserDefinedVMProperties','','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UserDefinedVMProperties','','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UserDefinedVMProperties','','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UserDefinedVMProperties','','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UserRefreshRate','3600','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UserSessionTimeOutInterval','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UtilizationThresholdInPercent','80','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ValidNumOfMonitors','1,2,4','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VcpuConsumptionPercentage','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdcVersion','3.0.0.0','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VDSAttemptsToResetCount','2','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsCertificateValidityInYears','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('vdsConnectionTimeout','2','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceOptionMapping','alom:secure=secure,port=ipport;apc:secure=secure,port=ipport,slot=port;bladecenter:secure=secure,port=ipport,slot=port;drac5:secure=secure,port=ipport;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceOptionMapping','alom:secure=secure,port=ipport;apc:secure=secure,port=ipport,slot=port;bladecenter:secure=secure,port=ipport,slot=port;drac5:secure=secure,port=ipport;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceOptionMapping','apc:secure=secure,port=ipport,slot=port;apc_snmp:port=port;bladecenter:secure=secure,port=ipport,slot=port;cisco_ucs:secure=ssl,slot=port;drac5:secure=secure,slot=port;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;ilo2:secure=ssl,port=ipport;ilo3:;ilo4:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceOptionMapping','apc:secure=secure,port=ipport,slot=port;apc_snmp:port=port;bladecenter:secure=secure,port=ipport,slot=port;cisco_ucs:secure=ssl,slot=port;drac5:secure=secure,slot=port;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;ilo2:secure=ssl,port=ipport;ilo3:;ilo4:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceOptionMapping','apc:secure=secure,port=ipport,slot=port;apc_snmp:port=port;bladecenter:secure=secure,port=ipport,slot=port;cisco_ucs:secure=ssl,slot=port;drac5:secure=secure,slot=port;drac7:;eps:slot=port;hpblade:port=port;ilo:secure=ssl,port=ipport;ipmilan:;ilo2:secure=ssl,port=ipport;ilo3:;ilo4:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceOptionMapping','apc:secure=secure,port=ipport,slot=port;apc_snmp:port=port;bladecenter:secure=secure,port=ipport,slot=port;cisco_ucs:secure=ssl,slot=port;drac5:secure=secure,slot=port;drac7:;eps:slot=port;hpblade:port=port;ilo:secure=ssl,port=ipport;ipmilan:;ilo2:secure=ssl,port=ipport;ilo3:;ilo4:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CustomVdsFenceOptionMapping','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceOptions','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceOptionTypes','secure=bool,port=int,slot=int','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceType','alom,apc,bladecenter,drac5,eps,ilo,ilo3,ipmilan,rsa,rsb,wti,cisco_ucs','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceType','alom,apc,bladecenter,drac5,eps,ilo,ilo3,ipmilan,rsa,rsb,wti,cisco_ucs','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceType','apc,apc_snmp,bladecenter,cisco_ucs,drac5,eps,ilo,ilo2,ilo3,ilo4,ipmilan,rsa,rsb,wti','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceType','apc,apc_snmp,bladecenter,cisco_ucs,drac5,eps,ilo,ilo2,ilo3,ilo4,ipmilan,rsa,rsb,wti','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceType','apc,apc_snmp,bladecenter,cisco_ucs,drac5,drac7,eps,hpblade,ilo,ilo2,ilo3,ilo4,ipmilan,rsa,rsb,wti','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsFenceType','apc,apc_snmp,bladecenter,cisco_ucs,drac5,drac7,eps,hpblade,ilo,ilo2,ilo3,ilo4,ipmilan,rsa,rsb,wti','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CustomVdsFenceType','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('vdsHeartbeatInSeconds','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsLoadBalancingIntervalInMinutes','1','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsLocalDisksCriticallyLowFreeSpace','100','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsLocalDisksLowFreeSpace','500','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsRecoveryTimeoutInMinutes','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsRefreshRate','2','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('vdsRetries','0','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsSelectionAlgorithm','None','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('vdsTimeout','180','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VM32BitMaxMemorySizeInMB','20480','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VM64BitMaxMemorySizeInMB','524288','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VM64BitMaxMemorySizeInMB','2097152','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VM64BitMaxMemorySizeInMB','2097152','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VM64BitMaxMemorySizeInMB','2097152','3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VM64BitMaxMemorySizeInMB','4096000','3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VM64BitMaxMemorySizeInMB','4096000','3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmGracefulShutdownMessage','System Administrator has initiated shutdown of this Virtual Machine. Virtual Machine is shutting down.','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmGracefulShutdownTimeout','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VMMinMemorySizeInMB','256','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmPoolMaxSubsequentFailures','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmPoolMonitorBatchSize','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmPoolMonitorIntervalInMinutes','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmPoolMonitorMaxAttempts','3','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VmPriorityMaxValue','100','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AutoStartVmsRunnerIntervalInSeconds','1','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('RetryToRunAutoStartVmIntervalInSeconds','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxNumOfTriesToRunFailedAutoStartVm','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VncKeyboardLayout','en-us','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VncKeyboardLayoutValidValues','ar,da,de,de-ch,en-gb,en-us,es,et,fi,fo,fr,fr-be,fr-ca,fr-ch,hr,hu,is,it,ja,lt,lv,mk,nl,nl-be,no,pl,pt,pt-br,ru,sl,sv,th,tr','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('WaitForVdsInitInSec','60','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NetworkConnectivityCheckTimeoutInSeconds','120','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AutoRecoveryAllowedTypes','{\"storage domains\":\"true\",\"hosts\":\"true\"}','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClientModeSpiceDefault','Auto','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClientModeVncDefault','Native','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ClientModeRdpDefault','Auto','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UseFqdnForRdpIfAvailable','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('WebSocketProxy','Off','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('WebSocketProxyTicketValiditySeconds','120','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LogMaxPhysicalMemoryUsedThresholdInPercentage', '95', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LogMaxCpuUsedThresholdInPercentage', '95', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LogMaxNetworkUsedThresholdInPercentage', '95', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LogMinFreeSwapThresholdInMB', '256', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('LogMaxSwapUsedThresholdInPercentage', '95', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportCustomDeviceProperties', 'false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportCustomDeviceProperties', 'false', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportCustomDeviceProperties', 'false', '3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CustomDeviceProperties', '', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CustomDeviceProperties', '', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CustomDeviceProperties', '', '3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CustomDeviceProperties', '', '3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CustomDeviceProperties', '', '3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CustomDeviceProperties', '', '3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NetworkCustomPropertiesSupported', 'false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NetworkCustomPropertiesSupported', 'false', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NetworkCustomPropertiesSupported', 'false', '3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NetworkCustomPropertiesSupported', 'false', '3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('NetworkCustomPropertiesSupported', 'false', '3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PreDefinedNetworkCustomProperties', $q$bridge_opts=^[^\s=]+=[^\s=]+(\s+[^\s=]+=[^\s=]+)*$$q$, '3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UserDefinedNetworkCustomProperties', '', '3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SshSoftFencingCommand', 'service vdsmd restart', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SshSoftFencingCommand', 'service vdsmd restart', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SshSoftFencingCommand', 'service vdsmd restart', '3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SshSoftFencingCommand', '/usr/bin/vdsm-tool service-restart vdsmd', '3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SshSoftFencingCommand', '/usr/bin/vdsm-tool service-restart vdsmd', '3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SshSoftFencingCommand', '/usr/bin/vdsm-tool service-restart vdsmd', '3.5');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SecureConnectionWithOATServers','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('PollUri','AttestationService/resources/PollHosts','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AttestationTruststore','TrustStore.jks','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AttestationPort','8443','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AttestationTruststorePass','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AttestationServer','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AttestationFirstStageSize','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxAverageNetworkQoSValue','1024','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxPeakNetworkQoSValue','2048','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('MaxBurstNetworkQoSValue','10240','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('UserMessageOfTheDay','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('QoSInboundAverageDefaultValue','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('QoSInboundPeakDefaultValue','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('QoSInboundBurstDefaultValue','100','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('QoSOutboundAverageDefaultValue','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('QoSOutboundPeakDefaultValue','10','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('QoSOutboundBurstDefaultValue','100','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SingleQxlPciEnabled','false','3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SingleQxlPciEnabled','false','3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SingleQxlPciEnabled','false','3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ExternalSchedulerServiceURL','http://localhost:18781/','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ExternalSchedulerConnectionTimeout','100','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ExternalSchedulerEnabled','false','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ExternalSchedulerResponseTimeout','120000','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DwhHeartBeatInterval', '30', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DisconnectDwh', '0', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlanceImageListSize','20','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('GlanceImageTotalListSize','500','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('OverUtilizationForHaReservation','200','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ScaleDownForHaReservation','1','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('EnableVdsHaReservation','true','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('VdsHaReservationIntervalInMinutes','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultMaximumMigrationDowntime','0','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('ChangePasswordMsg','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultSerialNumberPolicy','HOST_ID','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultCustomSerialNumber','Dummy serial number.','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('DefaultMTU', '1500', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceKdumpDestinationAddress','','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceKdumpDestinationPort','7410','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceKdumpMessageInterval','5','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('FenceKdumpListenerTimeout','90','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('KdumpStartedTimeout','30','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('AlertOnNumberOfLVs','300','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('CSRFProtection','false','general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SkipFencingIfSDActiveSupported', 'false', '3.0');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SkipFencingIfSDActiveSupported', 'false', '3.1');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SkipFencingIfSDActiveSupported', 'false', '3.2');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SkipFencingIfSDActiveSupported', 'false', '3.3');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SkipFencingIfSDActiveSupported', 'false', '3.4');
**************************

 

********* QUERY **********
select fn_db_add_config_value('HostStorageLeaseAliveCheckingInterval', '90', 'general');
**************************

 

********* QUERY **********
select fn_db_add_config_value('SupportNUMAMigration','false','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('AutoRecoveryAllowedTypes','{\"storage domains\":\"true\",\"hosts\":\"true\"}','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('BootstrapMinimalVdsmVersion','4.9','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('DBEngine','Postgres','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('DefaultTimeZone','(GMT) GMT Standard Time','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('FenceAgentDefaultParams','ilo3:lanplus,power_wait=4;ilo4:lanplus,power_wait=4','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('FenceAgentMapping','drac7=ipmilan,ilo2=ilo,ilo3=ipmilan,ilo4=ipmilan','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('FenceStartStatusDelayBetweenRetriesInSec','10','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('FenceStartStatusRetries','18','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('FenceStopStatusDelayBetweenRetriesInSec','10','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('FenceStopStatusRetries','18','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('IPTablesConfig','
# oVirt default firewall configuration. Automatically generated by vdsm bootstrap script.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -i lo -j ACCEPT
# vdsm
-A INPUT -p tcp --dport @VDSM_PORT@ -j ACCEPT
# SSH
-A INPUT -p tcp --dport @SSH_PORT@ -j ACCEPT
# snmp
-A INPUT -p udp --dport 161 -j ACCEPT

@CUSTOM_RULES@

# Reject any other input traffic
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -m physdev ! --physdev-is-bridged -j REJECT --reject-with icmp-host-prohibited
COMMIT
','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('IPTablesConfigForGluster',
'
# glusterd
-A INPUT -p tcp -m tcp --dport 24007 -j ACCEPT

# gluster swift
-A INPUT -p tcp -m tcp --dport 8080  -j ACCEPT

# portmapper
-A INPUT -p udp -m udp --dport 111   -j ACCEPT
-A INPUT -p tcp -m tcp --dport 38465 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 38466 -j ACCEPT

# nfs
-A INPUT -p tcp -m tcp --dport 111   -j ACCEPT
-A INPUT -p tcp -m tcp --dport 38467 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 2049  -j ACCEPT
-A INPUT -p tcp -m tcp --dport 38469 -j ACCEPT

# nrpe
-A INPUT -p tcp --dport 5666 -j ACCEPT

# status
-A INPUT -p tcp -m tcp --dport 39543 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 55863 -j ACCEPT

# nlockmgr
-A INPUT -p tcp -m tcp --dport 38468 -j ACCEPT
-A INPUT -p udp -m udp --dport 963   -j ACCEPT
-A INPUT -p tcp -m tcp --dport 965   -j ACCEPT

# ctdbd
-A INPUT -p tcp -m tcp --dport 4379  -j ACCEPT

# smbd
-A INPUT -p tcp -m tcp --dport 139   -j ACCEPT
-A INPUT -p tcp -m tcp --dport 445   -j ACCEPT

# Ports for gluster volume bricks (default 100 ports)
-A INPUT -p tcp -m tcp --dport 24009:24108 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 49152:49251 -j ACCEPT
','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('IPTablesConfigForVirt',
'
# libvirt tls
-A INPUT -p tcp --dport 16514 -j ACCEPT

# guest consoles
-A INPUT -p tcp -m multiport --dports 5900:6923 -j ACCEPT

# migration
-A INPUT -p tcp -m multiport --dports 49152:49216 -j ACCEPT
', 'general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('IsMultilevelAdministrationOn','true','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('MaxNumOfVmCpus','64','3.0');
**************************

 

********* QUERY **********
select fn_db_update_config_value('MaxNumOfVmCpus','160','3.1');
**************************

 

********* QUERY **********
select fn_db_update_config_value('MaxNumOfVmCpus','160','3.2');
**************************

 

********* QUERY **********
select fn_db_update_config_value('MigrationSupportForNativeUsb','false','3.0');
**************************

 

********* QUERY **********
select fn_db_update_config_value('MigrationSupportForNativeUsb','false','3.1');
**************************

 

********* QUERY **********
select fn_db_update_config_value('MinimalETLVersion','3.5.0','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('OvirtInitialSupportedIsoVersion','2.5.5:5.8','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('OvirtIsoPrefix','^ovirt-node-iso-([0-9].*)\.iso$:^rhevh-([0-9].*)\.iso$','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('OvirtNodeOS','^ovirt.*$:^rhev.*$','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('oVirtISOsRepositoryPath','/usr/share/ovirt-node-iso:/usr/share/rhev-hypervisor','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('PostgresPagingSyntax','OFFSET (%1$s -1) LIMIT %2$s','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('PostgresSearchTemplate','SELECT * FROM (%2$s) %1$s) as T1 %3$s','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('RhevhLocalFSPath','/data/images/rhev','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64;','3.0');
**************************

 

********* QUERY **********
select fn_db_update_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64;','3.1');
**************************

 

********* QUERY **********
select fn_db_update_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 8:Intel Haswell Family:vmx,nx,model_Haswell:Haswell:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64; 6:AMD Opteron G5:svm,nx,model_Opteron_G5:Opteron_G5:x86_64;','3.2');
**************************

 

********* QUERY **********
select fn_db_update_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 8:Intel Haswell Family:vmx,nx,model_Haswell:Haswell:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64; 6:AMD Opteron G5:svm,nx,model_Opteron_G5:Opteron_G5:x86_64; :IBM POWER 7 v2.0:powernv,model_POWER7_v2.0:POWER7_v2.0:ppc64; :IBM POWER 7 v2.1:powernv,model_POWER7_v2.1:POWER7_v2.1:ppc64; :IBM POWER 7 v2.3:powernv,model_POWER7_v2.3:POWER7_v2.3:ppc64; :IBM POWER 7+ v2.1:powernv,model_POWER7+_v2.1:POWER7+_v2.1:ppc64; :IBM POWER 8 v1.0:powernv,model_POWER8_v1.0:POWER8_v1.0:ppc64;','3.3');
**************************

 

********* QUERY **********
select fn_db_update_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 8:Intel Haswell Family:vmx,nx,model_Haswell:Haswell:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64; 6:AMD Opteron G5:svm,nx,model_Opteron_G5:Opteron_G5:x86_64; 3:IBM POWER 8:powernv,model_power8:power8:ppc64;','3.4');
**************************

 

********* QUERY **********
select fn_db_update_config_value('ServerCPUList','3:Intel Conroe Family:vmx,nx,model_Conroe:Conroe:x86_64; 4:Intel Penryn Family:vmx,nx,model_Penryn:Penryn:x86_64; 5:Intel Nehalem Family:vmx,nx,model_Nehalem:Nehalem:x86_64; 6:Intel Westmere Family:aes,vmx,nx,model_Westmere:Westmere:x86_64; 7:Intel SandyBridge Family:vmx,nx,model_SandyBridge:SandyBridge:x86_64; 8:Intel Haswell Family:vmx,nx,model_Haswell:Haswell:x86_64; 2:AMD Opteron G1:svm,nx,model_Opteron_G1:Opteron_G1:x86_64; 3:AMD Opteron G2:svm,nx,model_Opteron_G2:Opteron_G2:x86_64; 4:AMD Opteron G3:svm,nx,model_Opteron_G3:Opteron_G3:x86_64; 5:AMD Opteron G4:svm,nx,model_Opteron_G4:Opteron_G4:x86_64; 6:AMD Opteron G5:svm,nx,model_Opteron_G5:Opteron_G5:x86_64; 3:IBM POWER 8:powernv,model_power8:power8:ppc64;','3.5');
**************************

 

********* QUERY **********
select fn_db_update_config_value('ClusterEmulatedMachines','rhel6.4.0,pc-1.0,pseries','3.3');
**************************

 

********* QUERY **********
select fn_db_update_config_value('SpiceDriverNameInGuest','{"windows": "RHEV-Spice", "linux" : "xorg-x11-drv-qxl" }','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('SupportedClusterLevels','3.0,3.1,3.2,3.3,3.4,3.5','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('SupportedStorageFormats','0,2,3','3.1,3.2,3.3,3.4,3.5');
**************************

 

********* QUERY **********
select fn_db_update_config_value('SupportedVDSMVersions','4.9,4.10,4.11,4.12,4.13,4.14,4.15','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdcVersion','3.5.0.0','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('ProductRPMVersion','3.5.0.0','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsFenceOptionMapping','alom:secure=secure,port=ipport;apc:secure=secure,port=ipport,slot=port;bladecenter:secure=secure,port=ipport,slot=port;drac5:secure=secure,port=ipport;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.0');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsFenceOptionMapping','alom:secure=secure,port=ipport;apc:secure=secure,port=ipport,slot=port;bladecenter:secure=secure,port=ipport,slot=port;drac5:secure=secure,port=ipport;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.1');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsFenceOptionMapping','apc:secure=secure,port=ipport,slot=port;apc_snmp:port=port;bladecenter:secure=secure,port=ipport,slot=port;cisco_ucs:secure=ssl,slot=port;drac5:secure=secure,slot=port;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;ilo2:secure=ssl,port=ipport;ilo3:;ilo4:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.2');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsFenceOptionMapping','apc:secure=secure,port=ipport,slot=port;apc_snmp:port=port;bladecenter:secure=secure,port=ipport,slot=port;cisco_ucs:secure=ssl,slot=port;drac5:secure=secure,slot=port;eps:slot=port;ilo:secure=ssl,port=ipport;ipmilan:;ilo2:secure=ssl,port=ipport;ilo3:;ilo4:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.3');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsFenceOptionMapping','apc:secure=secure,port=ipport,slot=port;apc_snmp:port=port;bladecenter:secure=secure,port=ipport,slot=port;cisco_ucs:secure=ssl,slot=port;drac5:secure=secure,slot=port;drac7:;eps:slot=port;hpblade:port=port;ilo:secure=ssl,port=ipport;ipmilan:;ilo2:secure=ssl,port=ipport;ilo3:;ilo4:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.4');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsFenceOptionMapping','apc:secure=secure,port=ipport,slot=port;apc_snmp:port=port;bladecenter:secure=secure,port=ipport,slot=port;cisco_ucs:secure=ssl,slot=port;drac5:secure=secure,slot=port;drac7:;eps:slot=port;hpblade:port=port;ilo:secure=ssl,port=ipport;ipmilan:;ilo2:secure=ssl,port=ipport;ilo3:;ilo4:;rsa:secure=secure,port=ipport;rsb:;wti:secure=secure,port=ipport,slot=port','3.5');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsFenceType','alom,apc,bladecenter,drac5,eps,ilo,ilo3,ipmilan,rsa,rsb,wti,cisco_ucs','3.0');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsFenceType','alom,apc,bladecenter,drac5,eps,ilo,ilo3,ipmilan,rsa,rsb,wti,cisco_ucs','3.1');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsFenceType','apc,apc_snmp,bladecenter,cisco_ucs,drac5,eps,ilo,ilo2,ilo3,ilo4,ipmilan,rsa,rsb,wti','3.2');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsFenceType','apc,apc_snmp,bladecenter,cisco_ucs,drac5,drac7,eps,hpblade,ilo,ilo2,ilo3,ilo4,ipmilan,rsa,rsb,wti','3.4');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsFenceType','apc,apc_snmp,bladecenter,cisco_ucs,drac5,drac7,eps,hpblade,ilo,ilo2,ilo3,ilo4,ipmilan,rsa,rsb,wti','3.5');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VdsRefreshRate','3','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VmGracefulShutdownMessage','System Administrator has initiated shutdown of this Virtual Machine. Virtual Machine is shutting down.','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('DisconnectPoolOnReconstruct','0,2,3','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('SupportBridgesReportByVDSM','false','3.1');
**************************

 

********* QUERY **********
select fn_db_update_config_value('AgentAppName','ovirt-guest-agent-common,ovirt-guest-agent','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VM64BitMaxMemorySizeInMB','2097152','3.1');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VM64BitMaxMemorySizeInMB','2097152','3.2');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VM64BitMaxMemorySizeInMB','2097152','3.3');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VM64BitMaxMemorySizeInMB','4096000','3.4');
**************************

 

********* QUERY **********
select fn_db_update_config_value('VM64BitMaxMemorySizeInMB','4096000','3.5');
**************************

 

********* QUERY **********
select fn_db_update_config_value('AutoStartVmsRunnerIntervalInSeconds','1','general');
**************************

 

********* QUERY **********
select fn_db_update_config_value('CustomDeviceProperties', '{type=interface;prop={SecurityGroups=^(?:(?:[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}, *)*[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}|)$}}', '3.4');
**************************

 

********* QUERY **********
select fn_db_update_config_value('CustomDeviceProperties', '{type=interface;prop={SecurityGroups=^(?:(?:[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}, *)*[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}|)$}}', '3.5');
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('AdUserId','example.com:00000000-0000-0000-0000-000000000000','','general',false);
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('AdUserName','example.com:SampleUser','','general',false);
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('AdUserPassword','example.com:SamplePassword','','general',false);
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('AsyncTaskZombieTaskLifeInMinutes','300','3000','general',false);
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('DomainName','example.com','','general',false);
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('LDAPSecurityAuthentication','GSSAPI','default:GSSAPI','general',false);
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('LDAPSecurityAuthentication','SIMPLE','default:SIMPLE','general',false);
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('VdsLocalDisksCriticallyLowFreeSpace','100','500','general',false);
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('VdsLocalDisksLowFreeSpace','1000', '100','general',false);
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('GuestToolsSetupIsoPrefix','RHEV-toolsSetup_', 'ovirt-guest-tools-','general', false);
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('vdsConnectionTimeout', '180', '2', 'general', false);
**************************

 

********* QUERY **********
select fn_db_update_default_config_value('vdsRetries', '3', '0', 'general', false);
**************************

 

********* QUERY **********
select fn_db_delete_config_value('AsyncPollingCyclesBeforeCallbackCleanup','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('AsyncPollingCyclesBeforeRefreshSuspend','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('AutoMode','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('AutoSuspendTimeInMinutes','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('CABaseDirectory','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('CACertificatePath','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('CAEngineKey','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('CBCCertificateScriptName','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('CBCCloseCertificateScriptName','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('CbcCheckOnVdsChange','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('CertAlias','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('CertificateFileName','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('CertificateFingerPrint','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('CertificatePassword','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('CustomPublicConfig_AppsWebSite','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('DebugSearchLogging','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('DefaultWorkgroup','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ENMailDomain','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ENMailEnableSsl','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ENMailHost','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ENMailIsBodyHtml','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ENMailPassword','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ENMailPort','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ENMailUseDefaultCredentials','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ENMailUser','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('FreeSpaceCriticalLow','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('HotPlugUnsupportedOsList','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('HotPlugSupportedOsList','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ImagesSyncronizationTimeout','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('keystorePass','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('keystoreUrl','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('LdapServers','3.0');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('LicenseCertificateFingerPrint','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('LogDBCommands','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('LogVdsRegistration','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('LogXmlRpcData','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('NetConsolePort','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ProductKey2003','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ProductKey2003x64','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ProductKey2008','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ProductKey2008R2','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ProductKey2008x64','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ProductKey','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ProductKeyWindow7','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ProductKeyWindow7x64','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ProductKeyWindows8','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ProductKeyWindows8x64','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ProductKeyWindows2012x64','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('VdsFenceOptionMapping','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAllowUsingAsIRS','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientGUI','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAllowRunningGuestsWithoutTools','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAutoAdjustMemoryBaseOnAvailableMemory','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAutoAdjustMemory','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAutoAdjustMemoryGeneralReserve','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAutoAdjustMemoryLog','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAutoAdjustMemoryMaxMemory','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAutoAdjustMemoryModulus','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAutoAdjustMemorySpicePerMonitorReserve','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAutoAdjustMemorySpicePerSessionReserve','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAutoMigrateFromPowerClientToVdsWhenConnectingFromRegularClient','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientAutoMigrateToPowerClientOnConnect','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientDedicatedVmLaunchOnVdsWhilePowerClientStarts','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientLogDetection','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientMaxNumberOfConcurrentVMs','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientRunVmShouldVerifyPendingVMsAsWell','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PowerClientSpiceDynamicCompressionManagement','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PredefinedVMProperties','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('PublicURLPort','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('RDPLoginWithFQN','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('RedirectServletReportsPageError','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('RenewGuestIpOnVdsSubnetChange','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('RenewGuestIpOnVdsSubnetChangeOnParseError','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('RpmsRepositoryUrl','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SignLockFile','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SignScriptName','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SQLServerI18NPrefix','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SQLServerLikeSyntax','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SQLServerPagingSyntax','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SQLServerPagingType','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SQLServerSearchTemplate','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ScriptsPath','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SearchesRefreshRateInSeconds','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SelectCommandTimeout','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SysPrep3.0Path','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('TruststorePass','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('TruststoreUrl','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('UseENGINERepositoryRPMs','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('UseVdsBrokerInProc','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('UseSecureConnectionWithServers','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('VM64BitMaxMemorySizeInMB','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('VdcBootStrapUrl','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('VdsErrorsFileName','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('VM64BitMaxMemorySizeInMB','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('LogVdsRegistration','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_for_version('2.2');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('IsNeedSupportForOldVgAPI', '2.2,3.0');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('LimitNumberOfNetworkInterfaces', '2.2,3.0,3.1,3.2');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('LocalStorageEnabled','2.2,3.0,3.1,3.2');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SupportCustomProperties','2.2,3.0,3.1,3.2');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SupportGetDevicesVisibility','2.2,3.0,3.1,3.2');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SupportStorageFormat','2.2,3.0,3.1,3.2');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('UseRtl8139_pv','2.2,3.0,3.1,3.2');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('VdsFenceOptions','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('VirtualMachineDomainName','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('AuditLogAgingThreashold','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('ClientConsoleModeDefault','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('LiveStorageMigrationEnabled','3.0');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('LiveStorageMigrationEnabled','3.1');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('LiveStorageMigrationEnabled','3.2');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('DiskConfigurationList','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('DefaultTimeZone','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('NumberOfVmsForTopSizeVms','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value_all_versions('EmulatedMachine');
**************************

 

********* QUERY **********
select fn_db_delete_config_value_all_versions('ENGINEEARLib');
**************************

 

********* QUERY **********
SELECT fn_db_delete_config_value_all_versions('AdminDomain');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('AverageToPeakRatio','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('AverageToBurstRatio','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('DocsURL','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('VirtIoScsiUnsupportedOsList','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('EnableMACAntiSpoofingFilterRules', '3.0');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('EnableMACAntiSpoofingFilterRules', '3.1');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SSHInactivityTimoutSeconds','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('SSHInactivityHardTimoutSeconds','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('StorageDomainFalureTimeoutInMinutes','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('VdsLoadBalancingeIntervalInMinutes','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('VdsRecoveryTimeoutInMintues','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('UknownTaskPrePollingLapse','general');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('GlusterAysncTasksSupport','3.0,3.1,3.2,3.3');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('NormalizedMgmgNetworkEnabled','3.0,3.1,3.2');
**************************

 

********* QUERY **********
select fn_db_delete_config_value('HotPlugCpuEnabled','3.0,3.1,3.2,3.3,3.4,3.5');
**************************

 

********* QUERY **********
select fn_db_split_config_value('SpiceSecureChannels','smain,sinputs','smain,sinputs,scursor,splayback,srecord,sdisplay,susbredir,ssmartcard', '3.1');
**************************

 

********* QUERY **********
update vdc_options set version = '3.0' where version = '2.3';
**************************

UPDATE 0
********* QUERY **********
CREATE OR REPLACE FUNCTION __temp_upgrade_remove_default_security_auth(a_input VARCHAR(40))
  RETURNS void AS
$BODY$
   DECLARE
   v_entry VARCHAR(4000);
   v_pos integer;
BEGIN
    v_entry := option_value FROM vdc_options WHERE option_name='LDAPSecurityAuthentication';
    v_pos := strpos(lower(v_entry), ',' || lower(a_input) || ',');

    IF (v_pos = 0) THEN
                UPDATE vdc_options
                SET option_value = regexp_replace(option_value, ',?' || a_input || ',?' ,'','i')
                WHERE option_name = 'LDAPSecurityAuthentication';
    ELSE
                UPDATE vdc_options
                SET option_value = regexp_replace(option_value, ',' || a_input || ',' ,',','i')
                WHERE option_name = 'LDAPSecurityAuthentication';
    END IF;

END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_upgrade_remove_default_security_auth('default:GSSAPI');
**************************

 

********* QUERY **********
SELECT __temp_upgrade_remove_default_security_auth('default:SIMPLE');
**************************

 

********* QUERY **********
DROP FUNCTION __temp_upgrade_remove_default_security_auth(VARCHAR);
**************************

DROP FUNCTION
********* QUERY **********
create or replace function __temp_update_ldap_provier_types()
RETURNS void
AS $procedure$
    DECLARE
    v_domains text;
    v_provider_types text;
    v_temp text;
    v_values record;
    boo smallint;

BEGIN

    v_temp := '';
    v_domains := (SELECT option_value FROM vdc_options where option_name = 'DomainName');
    v_provider_types := (SELECT option_value FROM vdc_options where option_name = 'LDAPProviderTypes');
    boo := (SELECT count(*) from regexp_matches(v_provider_types ,'[:]'));

    IF (boo = 0) THEN

        FOR v_values in select regexp_split_to_table(v_domains, ',') as val
        LOOP
            IF (length(v_values.val) > 0) THEN
                v_temp := v_temp || v_values.val || ':general,';
            END IF;
        END LOOP;

        v_temp = rtrim(v_temp,',');

        UPDATE vdc_options SET option_value = v_temp where option_name = 'LDAPProviderTypes';

    END IF;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT  __temp_update_ldap_provier_types();
**************************

 

********* QUERY **********
DROP FUNCTION __temp_update_ldap_provier_types();
**************************

DROP FUNCTION
********* QUERY **********
create or replace function __temp_set_pg_major_release()
RETURNS void
AS $procedure$
DECLARE
    v_pg_major_release char(1);
BEGIN
    -- the folowing evaluates currently to 8 on PG 8.x and to 9 on PG 9.x
    v_pg_major_release:=substring ((string_to_array(version(),' '))[2],1,1);
    perform fn_db_add_config_value('PgMajorRelease',v_pg_major_release,'general');
    -- ensure that if PG was upgraded we will get the right value
    perform fn_db_update_config_value('PgMajorRelease',v_pg_major_release,'general');
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT  __temp_set_pg_major_release();
**************************

 

********* QUERY **********
DROP FUNCTION __temp_set_pg_major_release();
**************************

DROP FUNCTION
********* QUERY **********
/**********************************************************************************************
   Currently we have a bug that upgarde 03010250 was cherry-picked and installed after 03010130
   This caused all scripts between 03010140 and 03010240 not to run.
   This scripts removes the 03010250 from schema_version and updates 03010130 to be the curent version
   So, after that , all scripts from 03010140 and up will run
   Since 03010250 was a configuration change that is already handled in the new config.sql, no other handling is needed.
**********************************************************************************************/
update schema_version set current = true where version = '03010130'
and exists(select 1 from schema_version where version = '03010250' and current = true);
**************************

UPDATE 0
********* QUERY **********
delete from schema_version
where version = '03010250' and current = true;
**************************

DELETE 0
********* QUERY **********
select fn_db_add_column('vds_dynamic','supported_engines','varchar(40)');
**************************

 

********* QUERY **********
CREATE FUNCTION __temp__0030_add_materialized_views_table()
RETURNS VOID
AS $procedure$
BEGIN
    IF not exists (select 1 from information_schema.tables where table_name ='materialized_views') then
        CREATE TABLE materialized_views (
          mv_name NAME NOT NULL PRIMARY KEY,
          v_name NAME NOT NULL,
          refresh_rate_in_sec INTEGER,
          last_refresh TIMESTAMP WITH TIME ZONE,
          avg_cost_ms int not null default 0
        );
    END IF;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp__0030_add_materialized_views_table();
**************************

 

********* QUERY **********
DROP FUNCTION __temp__0030_add_materialized_views_table();
**************************

DROP FUNCTION
********* QUERY **********
select fn_db_add_column('materialized_views', 'min_refresh_rate_in_sec', 'int default 0');
**************************

 

********* QUERY **********
select fn_db_add_column('materialized_views', 'custom', 'boolean default false');
**************************

 

********* QUERY **********
select fn_db_add_column('materialized_views', 'active', 'boolean default true');
**************************

 

********* QUERY **********
ALTER TABLE schema_version ALTER COLUMN installed_by TYPE varchar(63);
**************************

ALTER TABLE
********* QUERY **********
/*
This file adds Snapshot Materialized Views support to Postgres.
A Snapshot Materialized View is actually a table built on top of
a real view that enables to select data from the Snapshot Materialized View
easily and efficiently.
Candidates for Snapshot Materialized Views are views that are based on
slowly-changing data. The Snapshot Materialized Views is actually
functioning as a cache.
The Snapshot Materialized View is refreshed per request.
The Snapshot Materialized View definitions are stored in the materialized_views table.

Flow:
1) Create the Materialized View by calling:
   CreateMaterializedView - if you are creating a new view
   CreateMaterializedViewAs - If you want to preserve the original view name
                              in this case the original view will be renamed
                              and the new Materialized View will have the original
                              view name.
   The following should be called for Custom Materialized Views
   CreateCustomMaterializedView
   CreateCustomMaterializedViewAs
2) If your Snapshot Materialized View is my_mt you should create Stored Procedures:
    MtDropmy_mtIndexes - Drops indexes on my_mt
    MtCreatemy_mtIndexes - Creates needed indexes on my_mt
    Those indexes should be defined in the "Snapshot Materialized Views Index Definitions Section"
    in post_upgrade/0020_create_materialized_views.sql file.

   Those SP are called automatically when a Snapshot Materialized View is refreshed
   to boost refresh performance.

3) You can call IsMaterializedViewRefreshed to check if it is time to refresh the view
   and if yes call RefreshMaterializedView manually.
   or
   You can define a cron job that calls RefreshAllMaterializedViews that loops over
   all  Snapshot Materialized Views and refreshes it automatically
   RefreshAllMaterializedViews recieves a boolean v_force flag, please set this flag to false
   when calling it from a cron job in order to update the materialized views only when needed.
   (This SP is called with v_force = true after create/upgrade DB)

There are also additional functions :
   CreateAllMaterializedViewsiIndexes - Creates indexes for all Snapshot Materialized views
   DropMaterializedView - Drops the Materialized View
   DropAllMaterializedViews - Drop all Materialized Views
   DropAllCustomMaterializedViews - Drop all custom Materialized Views
   UpdateMaterializedViewRefreshRate - Updates the Materialized View refresh rate
   UpdateMaterializedViewMinRefreshRate - Updates the Materialized View minimal refresh rate
   ActivateMaterializedView - activates/decativates a  Materialized View
   ActivateAllMaterializedViews - activates/decativates all Materialized Views

In addition, you can create a file named create_materialized_views.sql under dbscripts/upgrade/post_upgrade/custom/
This file may include other custom materialized views settings and is executed by the create/upgrade database scripts.

NOTE : Materialized Views are automatically refreshed upon create/upgrade
*/




CREATE OR REPLACE FUNCTION to_interval (sec INTEGER) RETURNS INTERVAL AS $$
BEGIN
  RETURN (sec || ' seconds')::INTERVAL;
END;
$$ LANGUAGE 'plpgsql' IMMUTABLE STRICT;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedView(v_matview NAME, v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                  v_custom BOOLEAN, v_min_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;

     IF FOUND THEN
         RAISE EXCEPTION 'Materialized view % already exists.',
           v_matview;
     END IF;
     IF current_user != usename from pg_database , pg_user where datdba=usesysid and datname=current_database THEN
         RAISE EXCEPTION 'Materialized view % should be created with user ''engine''.',
           v_matview;
     END IF;

     EXECUTE 'REVOKE ALL ON ' || v_view_name || ' FROM PUBLIC';

     EXECUTE 'GRANT SELECT ON ' || v_view_name || ' TO PUBLIC';

     EXECUTE 'CREATE TABLE ' || v_matview || ' AS SELECT * FROM ' || v_view_name;

     EXECUTE 'REVOKE ALL ON ' || v_matview || ' FROM PUBLIC';

     EXECUTE 'GRANT SELECT ON ' || v_matview || ' TO PUBLIC';

     INSERT INTO materialized_views (mv_name, v_name, refresh_rate_in_sec, last_refresh, custom, min_refresh_rate_in_sec)
       VALUES (v_matview, v_view_name, v_refresh_rate_in_sec, CURRENT_TIMESTAMP, v_custom, v_min_refresh_rate_in_sec);

     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedView(v_matview NAME, v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                  v_min_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
 BEGIN
     PERFORM CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, false,  v_min_refresh_rate_in_sec);
     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateCustomMaterializedView(v_matview NAME, v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                        v_min_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
 BEGIN
     PERFORM CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, true,  v_min_refresh_rate_in_sec);
     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedView(v_matview NAME, v_view_name NAME, v_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
BEGIN
     PERFORM  CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, false, 0);
END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateCustomMaterializedView(v_matview NAME, v_view_name NAME, v_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
BEGIN
     PERFORM  CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, true, 0);
END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedViewAs(v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                    v_custom BOOLEAN, v_min_refesh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
     v_renamed_view NAME;
 BEGIN
     IF FOUND THEN
         RAISE EXCEPTION 'Materialized view % already exists.',
           v_view_name;
     END IF;

     v_renamed_view := v_view_name || '_mt_base';
     EXECUTE  'ALTER VIEW ' ||  v_view_name || ' RENAME TO ' || v_renamed_view;
     perform CreateMaterializedView(v_view_name, v_renamed_view, v_refresh_rate_in_sec, v_custom, v_min_refesh_rate_in_sec);

     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedViewAs(v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                    v_min_refesh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
 BEGIN
     PERFORM CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, false, v_min_refesh_rate_in_sec);
     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateCustomMaterializedViewAs(v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                          v_min_refesh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
 BEGIN
     PERFORM CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, true, v_min_refesh_rate_in_sec);
     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedViewAs(v_view_name NAME, v_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
BEGIN
    PERFORM  CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, false, 0);
END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateCustomMaterializedViewAs(v_view_name NAME, v_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
BEGIN
    PERFORM  CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, true, 0);
END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION DropMaterializedView(v_matview NAME)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN

     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;

     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
     END IF;

     EXECUTE 'DROP TABLE ' || v_matview || ' CASCADE';
     DELETE FROM materialized_views WHERE mv_name=v_matview;

     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION DropAllMaterializedViews()
RETURNS void
AS $procedure$
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views;
    v_record materialized_views%ROWTYPE;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           perform DropMaterializedView(v_record.mv_name);
       END LOOP;
       CLOSE v_cur;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION DropAllCustomMaterializedViews()
RETURNS void
AS $procedure$
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views where custom;
    v_record materialized_views%ROWTYPE;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           perform DropMaterializedView(v_record.mv_name);
       END LOOP;
       CLOSE v_cur;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION IsMaterializedViewRefreshed(v_matview NAME)
 RETURNS boolean STABLE
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
     v_is_refreshed boolean;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
    END IF;

    -- check if materialized View should refresh
    v_is_refreshed := (((CURRENT_TIMESTAMP - to_interval(refresh_rate_in_sec)) <= last_refresh) and
                      ((CURRENT_TIMESTAMP - to_interval(min_refresh_rate_in_sec)) <= last_refresh)) or
                      not active from materialized_views
                       where mv_name = v_matview;
    RETURN v_is_refreshed;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION RefreshMaterializedView(v_matview NAME)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
     v_drop_index_sp NAME;
     v_create_index_sp NAME;
     v_start_time TIMESTAMP WITH TIME ZONE;
     v_avg_cost_ms int;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
    END IF;

    -- get start time
    v_start_time:=CURRENT_TIMESTAMP;
    -- SP for Drop / create Index should follow naming convention Mt[Drop|Create]<v_matview>Indexes
    v_drop_index_sp := 'MtDrop' || v_matview || 'Indexes';
    v_create_index_sp := 'MtCreate' || v_matview || 'Indexes';

    IF NOT EXISTS (select 1 from information_schema.routines where routine_name ilike v_drop_index_sp) THEN
        v_drop_index_sp := NULL;
    END IF;

    IF NOT EXISTS (select 1 from information_schema.routines where routine_name ilike v_create_index_sp) THEN
        v_create_index_sp := NULL;
    END IF;

    -- Lock materialized_views table until refresh completes to prevent duplicate refreshes by other threads
    LOCK TABLE materialized_views;
    -- taking a lock on the snapshot materialized view until it refreshed
    EXECUTE 'LOCK TABLE ' || v_matview;
    -- drop indexes on the snapshot materialized view if exists
    IF (v_drop_index_sp IS NOT NULL) THEN
        EXECUTE 'select ' || v_drop_index_sp || '()';
    END IF;
    -- refresh the view
    EXECUTE 'TRUNCATE TABLE ' || v_matview;
    EXECUTE 'INSERT INTO ' || v_matview
        || ' SELECT * FROM ' || v_entry.v_name;
    -- restore  indexes on the snapshot materialized view if exists
    IF (v_create_index_sp IS NOT NULL) THEN
        EXECUTE 'select ' || v_create_index_sp || '()';
    END IF;
    -- update last refresh time and average cost in [ms]
    IF (v_entry.avg_cost_ms = 0) THEN
        v_avg_cost_ms:=EXTRACT(EPOCH FROM current_timestamp - v_start_time) * 1000;
    ELSE
        v_avg_cost_ms:=((EXTRACT(EPOCH FROM current_timestamp - v_start_time) * 1000) + v_entry.avg_cost_ms)/2;
    END IF;
    update materialized_views set last_refresh = CURRENT_TIMESTAMP,
                                  avg_cost_ms = v_avg_cost_ms
                              where  mv_name = v_matview;
    RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION RefreshAllMaterializedViews(v_force boolean)
RETURNS void
AS $procedure$
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views;
    v_record materialized_views%ROWTYPE;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views and refresh only needed snapshots
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           IF ((v_force and v_record.min_refresh_rate_in_sec = 0) or not IsMaterializedViewRefreshed(v_record.mv_name)) THEN
              perform RefreshMaterializedView(v_record.mv_name);
           END IF;
       END LOOP;
       CLOSE v_cur;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateAllMaterializedViewsiIndexes()
RETURNS void
AS $procedure$
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views;
    v_record materialized_views%ROWTYPE;
    v_create_index_sp NAME;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views and create indexes(if defined)
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           v_create_index_sp := 'MtCreate' || v_record.mv_name || 'Indexes';
           -- Check if SP that creates the indexes exists
           IF NOT EXISTS (select 1 from information_schema.routines where routine_name ilike v_create_index_sp) THEN
               v_create_index_sp := NULL;
           END IF;
           IF (v_create_index_sp IS NOT NULL) THEN
               EXECUTE 'select ' || v_create_index_sp || '()';
           END IF;
       END LOOP;
       CLOSE v_cur;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpdateMaterializedViewRefreshRate(v_matview NAME, v_refresh_rate INTEGER)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
    END IF;

    update materialized_views set refresh_rate_in_sec = v_refresh_rate
    where  mv_name = v_matview;
    RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpdateMaterializedViewMinRefreshRate(v_matview NAME, v_min_refresh_rate INTEGER)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
    END IF;

    update materialized_views set min_refresh_rate_in_sec = v_min_refresh_rate
    where  mv_name = v_matview;
    RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION ActivateMaterializedView(v_matview NAME, v_active BOOLEAN)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
    END IF;

    update materialized_views set active = v_active
    where  mv_name = v_matview;
    RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION ActivateAllMaterializedViews(v_active BOOLEAN)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
    update materialized_views set active = v_active;
    RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select DropAllMaterializedViews();
**************************

 

********* QUERY **********
copy (
		select version
		from schema_version
		where current = true
		order by id
		LIMIT 1
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '14657ad84e48a1fb0553b2d14b913a50' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('network_cluster', 'migration', 'boolean NOT NULL DEFAULT false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030010'),
						'upgrade/03_03_0010_add_migration_to_network_cluster.sql',
						'14657ad84e48a1fb0553b2d14b913a50',
						'engine',
						cast(trim('2014-10-20 14:41:37.526104+02') as timestamp),
						cast(trim('2014-10-20 14:41:37.578256+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '63618f380f89992d792718ac880c612f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_insert_predefined_gluster_hooks_roles()
RETURNS VOID
   AS $procedure$
   DECLARE
      v_super_user_id_0001 UUID;
      v_GLUSTER_ADMIN_ROLE_ID UUID;
BEGIN
      v_super_user_id_0001 := '00000000-0000-0000-0000-000000000001';
      v_GLUSTER_ADMIN_ROLE_ID := 'DEF0000b-0000-0000-0000-DEF00000000b';

--MANIPULATE_GLUSTER_HOOK
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_super_user_id_0001, 1003
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_super_user_id_0001 and action_group_id=1003);

-- Map all manipulate gluster hook action groups to the gluster admin role
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, 1003
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=1003);

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp_insert_predefined_gluster_hooks_roles();
**************************

 

********* QUERY **********
drop function __temp_insert_predefined_gluster_hooks_roles();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030020'),
						'upgrade/03_03_0020_add_gluster_hooks_roles.sql',
						'63618f380f89992d792718ac880c612f',
						'engine',
						cast(trim('2014-10-20 14:41:37.596257+02') as timestamp),
						cast(trim('2014-10-20 14:41:37.698681+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'b0e32a380ee4d3329a546bfde1d6376e' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO roles_groups(role_id,action_group_id)
select
    id,
    15 
from roles
where
    name in ('SuperUser', 'ClusterAdmin', 'DataCenterAdmin')
    and id not in (
       select role_id from roles_groups rg
       where
           rg.role_id in (select id from roles where name in ('SuperUser', 'ClusterAdmin', 'DataCenterAdmin')
           and rg.action_group_id = 15));
**************************

INSERT 0 3
********* QUERY **********
INSERT INTO roles_groups(role_id,action_group_id)
select
    id,
    205 
from roles
where
    name in ('SuperUser', 'DataCenterAdmin', 'TemplateAdmin')
    and id not in (
       select role_id from roles_groups rg
       where
           rg.role_id in (select id from roles where name in ('SuperUser', 'DataCenterAdmin', 'TemplateAdmin')
           and rg.action_group_id = 205));
**************************

INSERT 0 3
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030030'),
						'upgrade/03_03_0030_add_edit_admin_vm_props.sql',
						'b0e32a380ee4d3329a546bfde1d6376e',
						'engine',
						cast(trim('2014-10-20 14:41:37.745204+02') as timestamp),
						cast(trim('2014-10-20 14:41:37.829892+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '88f85d30bb24d7812614a5cb38ff67f6' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'is_run_and_pause', 'boolean NOT NULL DEFAULT false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030040'),
						'upgrade/03_03_0040_add_run_and_pause_to_vm.sql',
						'88f85d30bb24d7812614a5cb38ff67f6',
						'engine',
						cast(trim('2014-10-20 14:41:37.851946+02') as timestamp),
						cast(trim('2014-10-20 14:41:38.009261+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3edad27779af5e251733e06078b097cd' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_rename_column('repo_file_meta_data', 'repo_file_name', 'repo_image_id');
**************************

 

********* QUERY **********
select fn_db_add_column('repo_file_meta_data', 'repo_image_name', 'varchar(256)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030050'),
						'upgrade/03_03_0050_repo_file_id.sql',
						'3edad27779af5e251733e06078b097cd',
						'engine',
						cast(trim('2014-10-20 14:41:38.028161+02') as timestamp),
						cast(trim('2014-10-20 14:41:38.099084+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'd042caf4334fad676ba3de539bee496d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_drop_column('users','fn_db_drop_column');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030060'),
						'upgrade/03_03_0060_drop_desktop_device.sql',
						'd042caf4334fad676ba3de539bee496d',
						'engine',
						cast(trim('2014-10-20 14:41:38.116323+02') as timestamp),
						cast(trim('2014-10-20 14:41:38.194101+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '7f0d66775591a4b929ef6d093e4a551d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_drop_column('users','user_icon_path');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030070'),
						'upgrade/03_03_0070_drop_iconpath.sql',
						'7f0d66775591a4b929ef6d093e4a551d',
						'engine',
						cast(trim('2014-10-20 14:41:38.220882+02') as timestamp),
						cast(trim('2014-10-20 14:41:38.253096+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '0a1f47a0d9c28a5c2435557463f4a7ae' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
drop table if exists roles_relations;
**************************

DROP TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030080'),
						'upgrade/03_03_0080_drop_roles_relations.sql',
						'0a1f47a0d9c28a5c2435557463f4a7ae',
						'engine',
						cast(trim('2014-10-20 14:41:38.296895+02') as timestamp),
						cast(trim('2014-10-20 14:41:38.378211+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '23a0dc5122d0af152ace8c76340e3da3' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into action_version_map values (1001, '3.3', '3.3');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030090'),
						'upgrade/03_03_0090_edit_storage_conn_version_support.sql',
						'23a0dc5122d0af152ace8c76340e3da3',
						'engine',
						cast(trim('2014-10-20 14:41:38.419839+02') as timestamp),
						cast(trim('2014-10-20 14:41:38.473305+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '8fabb2467eb8c825e21926269ad48938' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE images SET imagestatus = 4 WHERE imagestatus = 3;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030100'),
						'upgrade/03_03_0100_update_imagestatus_invalid_to_illegal.sql',
						'8fabb2467eb8c825e21926269ad48938',
						'engine',
						cast(trim('2014-10-20 14:41:38.491273+02') as timestamp),
						cast(trim('2014-10-20 14:41:38.526065+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '44be16c6adca0aa0150f513e6d3f74fb' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_drop_column ('storage_pool_iso_map', 'owner');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030110'),
						'upgrade/03_03_0110_drop_storage_owner.sql',
						'44be16c6adca0aa0150f513e6d3f74fb',
						'engine',
						cast(trim('2014-10-20 14:41:38.568195+02') as timestamp),
						cast(trim('2014-10-20 14:41:38.60195+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '32d9393e3868b4df8afb0d5f756f9cd7' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_pools', 'max_assigned_vms_per_user', 'smallint default 1');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030120'),
						'upgrade/03_03_0120_add_max_assigned_vms_per_user.sql',
						'32d9393e3868b4df8afb0d5f756f9cd7',
						'engine',
						cast(trim('2014-10-20 14:41:38.637294+02') as timestamp),
						cast(trim('2014-10-20 14:41:38.756494+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'bdf04686a2b4357bbeb88f21a31824b3' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_add_gluster_services_tables() returns void
AS $procedure$
BEGIN
    -- Service Types
    CREATE TABLE gluster_service_types
    (
        service_type VARCHAR(100) NOT NULL,
        CONSTRAINT pk_gluster_service_types PRIMARY KEY(service_type)
    ) WITH OIDS;

    -- Services ( There can be multiple services under a given service type )
    CREATE TABLE gluster_services
    (
        id UUID NOT NULL,
        service_type VARCHAR(100) NOT NULL references gluster_service_types(service_type) ON DELETE CASCADE,
        service_name VARCHAR(100) NOT NULL,
        CONSTRAINT pk_gluster_services PRIMARY KEY(id),
        CONSTRAINT unique_gluster_services_type_name UNIQUE (service_type, service_name)
    ) WITH OIDS;

    -- Cluster-Services
    CREATE TABLE gluster_cluster_services
    (
        cluster_id UUID NOT NULL references vds_groups(vds_group_id) ON DELETE CASCADE,
        service_type VARCHAR(100) NOT NULL references gluster_service_types(service_type) ON DELETE CASCADE,
        status VARCHAR(32) NOT NULL,
        _create_date TIMESTAMP WITH TIME ZONE NOT NULL default LOCALTIMESTAMP,
        _update_date TIMESTAMP WITH TIME ZONE,
        CONSTRAINT pk_gluster_cluster_services PRIMARY KEY(cluster_id, service_type)
    ) WITH OIDS;

    -- Create partial index for fetching services of a cluster
    CREATE INDEX IDX_gluster_cluster_services_cluster_id ON gluster_cluster_services(cluster_id);

    -- Server-Services
    CREATE TABLE gluster_server_services
    (
        id UUID NOT NULL,
        server_id UUID NOT NULL references vds_static(vds_id) ON DELETE CASCADE,
        service_id UUID NOT NULL references gluster_services(id) ON DELETE CASCADE,
        pid INTEGER,
        status VARCHAR(32) NOT NULL,
        message VARCHAR(1000),
        _create_date TIMESTAMP WITH TIME ZONE NOT NULL default LOCALTIMESTAMP,
        _update_date TIMESTAMP WITH TIME ZONE,
        CONSTRAINT pk_gluster_server_services PRIMARY KEY(id),
        CONSTRAINT unique_gluster_server_services_server_service UNIQUE (server_id, service_id)
    ) WITH OIDS;

    -- Create partial index for fetching services of a server
    CREATE INDEX IDX_gluster_server_services_server_id ON gluster_server_services(server_id);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp_add_gluster_services_tables();
**************************

 

********* QUERY **********
drop function __temp_add_gluster_services_tables();
**************************

DROP FUNCTION
********* QUERY **********
Create or replace FUNCTION __temp_insert_services() RETURNS VOID
AS $procedure$
BEGIN

-- Service Types
INSERT INTO gluster_service_types(service_type) values ('GLUSTER');
INSERT INTO gluster_service_types(service_type) values ('GLUSTER_SWIFT');
INSERT INTO gluster_service_types(service_type) values ('SMB');

-- Services
-- glusterd
INSERT INTO gluster_services(id, service_type, service_name)
    SELECT uuid_generate_v1(), 'GLUSTER', 'glusterd';

-- gluster-swift-proxy
INSERT INTO gluster_services(id, service_type, service_name)
    SELECT uuid_generate_v1(), 'GLUSTER_SWIFT', 'gluster-swift-proxy';

-- gluster-swift-container
INSERT INTO gluster_services(id, service_type, service_name)
    SELECT uuid_generate_v1(), 'GLUSTER_SWIFT', 'gluster-swift-container';

-- gluster-swift-proxy
INSERT INTO gluster_services(id, service_type, service_name)
    SELECT uuid_generate_v1(), 'GLUSTER_SWIFT', 'gluster-swift-object';

-- gluster-swift-proxy
INSERT INTO gluster_services(id, service_type, service_name)
    SELECT uuid_generate_v1(), 'GLUSTER_SWIFT', 'gluster-swift-account';

-- memcached
INSERT INTO gluster_services(id, service_type, service_name)
    SELECT uuid_generate_v1(), 'GLUSTER_SWIFT', 'memcached';

-- smb
INSERT INTO gluster_services(id, service_type, service_name)
    SELECT uuid_generate_v1(), 'SMB', 'smb';

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_insert_services();
**************************

 

********* QUERY **********
DROP function __temp_insert_services();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030130'),
						'upgrade/03_03_0130_add_gluster_services_tables.sql',
						'bdf04686a2b4357bbeb88f21a31824b3',
						'engine',
						cast(trim('2014-10-20 14:41:38.781375+02') as timestamp),
						cast(trim('2014-10-20 14:41:39.119784+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'dc857d7c5892ea725181f1078c6f8e82' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_add_gluster_server_table()
RETURNS void
AS $function$
BEGIN
    CREATE TABLE gluster_server
    (
      server_id UUID NOT NULL references vds_static(vds_id) ON DELETE CASCADE,
      gluster_server_uuid UUID NOT NULL,
      CONSTRAINT pk_gluster_server PRIMARY KEY(server_id)
    ) WITH OIDS;
    CREATE UNIQUE INDEX IDX_gluster_server_unique ON gluster_server(server_id, gluster_server_uuid);
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp_add_gluster_server_table();
**************************

 

********* QUERY **********
drop function __temp_add_gluster_server_table();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030140'),
						'upgrade/03_03_0140_add_gluster_server_table.sql',
						'dc857d7c5892ea725181f1078c6f8e82',
						'engine',
						cast(trim('2014-10-20 14:41:39.144406+02') as timestamp),
						cast(trim('2014-10-20 14:41:39.298788+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ae7ed87dcab412c54b0934358319f4bf' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE providers
(
    id UUID CONSTRAINT providers_pk PRIMARY KEY,
    name VARCHAR(128) NOT NULL,
    description VARCHAR(4000),
    url VARCHAR(512) NOT NULL,
    provider_type VARCHAR(32) NOT NULL,
    auth_required BOOLEAN NOT NULL,
    auth_username VARCHAR(64),
    auth_password TEXT,
    _create_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    _update_date TIMESTAMP WITH TIME ZONE
);
**************************

CREATE TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030150'),
						'upgrade/03_03_0150_add_providers_table.sql',
						'ae7ed87dcab412c54b0934358319f4bf',
						'engine',
						cast(trim('2014-10-20 14:41:39.317133+02') as timestamp),
						cast(trim('2014-10-20 14:41:39.436884+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e970c6a5ec6cbd64488ff8bea564a1f1' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vm_static set mem_size_mb = 1024 where vm_guid = '00000000-0000-0000-0000-000000000000' and mem_size_mb < 1024;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030160'),
						'upgrade/03_03_0160_increase_guest_ram.sql',
						'e970c6a5ec6cbd64488ff8bea564a1f1',
						'engine',
						cast(trim('2014-10-20 14:41:39.478487+02') as timestamp),
						cast(trim('2014-10-20 14:41:39.504461+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '6ff9cc7e1943ec549e8bf02234904034' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_dynamic', 'last_watchdog_event', 'bigint');
**************************

 

********* QUERY **********
select fn_db_add_column('vm_dynamic', 'last_watchdog_action', 'varchar(8)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030170'),
						'upgrade/03_03_0170_watchdog.sql',
						'6ff9cc7e1943ec549e8bf02234904034',
						'engine',
						cast(trim('2014-10-20 14:41:39.539794+02') as timestamp),
						cast(trim('2014-10-20 14:41:39.63149+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '2273f644a116b0b3f752b0c75a72009f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_device', 'custom_properties', 'TEXT');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030180'),
						'upgrade/03_03_0180_add_device_custom_prop.sql',
						'2273f644a116b0b3f752b0c75a72009f',
						'engine',
						cast(trim('2014-10-20 14:41:39.649979+02') as timestamp),
						cast(trim('2014-10-20 14:41:39.68556+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '4de97c27650b670b485b35f8402dcaca' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('snapshots', 'memory_volume', 'character varying(255)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030190'),
						'upgrade/03_03_0190_add_memory_volume_to_snapshots.sql',
						'4de97c27650b670b485b35f8402dcaca',
						'engine',
						cast(trim('2014-10-20 14:41:39.730121+02') as timestamp),
						cast(trim('2014-10-20 14:41:39.819242+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'd3b6d7e1e539cc516147a40a593db799' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_insert_predefined_gluster_service_roles()
RETURNS VOID
   AS $procedure$
   DECLARE
      v_super_user_id_0001 UUID;
      v_GLUSTER_ADMIN_ROLE_ID UUID;
      v_ACTION_GROUP_ID_GLUSTER_SERVICE INTEGER;
BEGIN
      v_super_user_id_0001 := '00000000-0000-0000-0000-000000000001';
      v_GLUSTER_ADMIN_ROLE_ID := 'DEF0000b-0000-0000-0000-DEF00000000b';
      v_ACTION_GROUP_ID_GLUSTER_SERVICE := 1004;

--MANIPULATE_GLUSTER_SERVER_SERVICES
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_super_user_id_0001, v_ACTION_GROUP_ID_GLUSTER_SERVICE
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_super_user_id_0001 and action_group_id=v_ACTION_GROUP_ID_GLUSTER_SERVICE);

-- Map all gluster service action groups to the gluster admin role
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, v_ACTION_GROUP_ID_GLUSTER_SERVICE
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=v_ACTION_GROUP_ID_GLUSTER_SERVICE);

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp_insert_predefined_gluster_service_roles();
**************************

 

********* QUERY **********
drop function __temp_insert_predefined_gluster_service_roles();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030200'),
						'upgrade/03_03_0200_add_gluster_service_roles.sql',
						'd3b6d7e1e539cc516147a40a593db799',
						'engine',
						cast(trim('2014-10-20 14:41:39.85911+02') as timestamp),
						cast(trim('2014-10-20 14:41:39.916716+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ed0a9dc6c1df3521b22b7cb7889abb93' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_dynamic', 'hbas', 'text default null');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030210'),
						'upgrade/03_03_0210_add_hbas_col.sql',
						'ed0a9dc6c1df3521b22b7cb7889abb93',
						'engine',
						cast(trim('2014-10-20 14:41:39.963676+02') as timestamp),
						cast(trim('2014-10-20 14:41:40.048721+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3ae0cd0201dddd7097362f0e2caa2987' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('audit_log', 'call_stack', 'TEXT DEFAULT ''''');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030220'),
						'upgrade/03_03_0220_add_call_stack_to_audit_log.sql',
						'3ae0cd0201dddd7097362f0e2caa2987',
						'engine',
						cast(trim('2014-10-20 14:41:40.089027+02') as timestamp),
						cast(trim('2014-10-20 14:41:40.380693+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '8a265bce277ddd5f937977db81257b57' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update action_version_map set cluster_minimal_version = '3.1' where action_type = 1412;
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030230'),
						'upgrade/03_03_0230_update_removeglusterserver_action_version_map.sql',
						'8a265bce277ddd5f937977db81257b57',
						'engine',
						cast(trim('2014-10-20 14:41:40.399071+02') as timestamp),
						cast(trim('2014-10-20 14:41:40.44099+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'f712b853fe78bd771f05093f451a58da' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_HOOK_ENABLE', 'GLUSTER_HOOK_ENABLE_FAILED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_HOOK_ENABLE_FAILED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_HOOK_DISABLE', 'GLUSTER_HOOK_DISABLE_FAILED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_HOOK_DISABLE_FAILED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_HOOK_DETECTED_NEW', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_HOOK_CONFLICT_DETECTED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_HOOK_DETECTED_DELETE', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_HOOK_ADDED', 'GLUSTER_HOOK_ADD_FAILED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_HOOK_ADD_FAILED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_HOOK_REMOVED', 'GLUSTER_HOOK_REMOVE_FAILED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_HOOK_REMOVE_FAILED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_SERVICE_STARTED', 'GLUSTER_SERVICE_START_FAILED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_SERVICE_START_FAILED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_SERVICE_STOPPED', 'GLUSTER_SERVICE_STOP_FAILED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_SERVICE_STOP_FAILED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_SERVICE_RESTARTED', 'GLUSTER_SERVICE_RESTART_FAILED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_SERVICE_RESTART_FAILED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030240'),
						'upgrade/03_03_0240_add_gluster_hooks_services_events.sql',
						'f712b853fe78bd771f05093f451a58da',
						'engine',
						cast(trim('2014-10-20 14:41:40.471949+02') as timestamp),
						cast(trim('2014-10-20 14:41:40.669018+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '34cff43ab6e7eb4e6ddc468fadd9895a' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE vm_dynamic AS vd
SET utc_diff = 0
FROM vm_static AS vs
WHERE vd.vm_guid = vs.vm_guid AND vs.os IN(5, 7, 8, 9, 13, 14, 15, 18, 19);
**************************

UPDATE 0
********* QUERY **********
UPDATE vm_static
SET time_zone = NULL
WHERE os IN(5, 7, 8, 9, 13, 14, 15, 18, 19);
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030250'),
						'upgrade/03_03_0250_upgrade_utcdiff_and_timezone_for_linux.sql',
						'34cff43ab6e7eb4e6ddc468fadd9895a',
						'engine',
						cast(trim('2014-10-20 14:41:40.687602+02') as timestamp),
						cast(trim('2014-10-20 14:41:40.769576+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '621d4e9fdbb22d285209344522149dfb' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('base_disks', 'sgio', 'SMALLINT DEFAULT NULL');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030260'),
						'upgrade/03_03_0260_add_base_disks_sgio_column.sql',
						'621d4e9fdbb22d285209344522149dfb',
						'engine',
						cast(trim('2014-10-20 14:41:40.815206+02') as timestamp),
						cast(trim('2014-10-20 14:41:40.893698+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '2c4eaeff183598467ab8d909886bfef4' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_action_group_to_role('def00002-0000-0000-0000-def000000002', 1105);
**************************

 

********* QUERY **********
select fn_db_add_action_group_to_role('00000000-0000-0000-0000-000000000001', 1105);
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030270'),
						'upgrade/03_03_0270_add_permission_to_configure_sgio.sql',
						'2c4eaeff183598467ab8d909886bfef4',
						'engine',
						cast(trim('2014-10-20 14:41:40.929631+02') as timestamp),
						cast(trim('2014-10-20 14:41:41.01837+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '57379977f9f0cdfa875ccc6523a322a6' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('storage_pool', 'free_text_comment', 'text');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030280'),
						'upgrade/03_03_0280_add_comment_storage_pool.sql',
						'57379977f9f0cdfa875ccc6523a322a6',
						'engine',
						cast(trim('2014-10-20 14:41:41.036632+02') as timestamp),
						cast(trim('2014-10-20 14:41:41.117172+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'd163dcb673e89f20ccb9883bafedbe66' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('providers', 'custom_properties', 'TEXT');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030290'),
						'upgrade/03_03_0290_add_custom_properties_to_providers.sql',
						'd163dcb673e89f20ccb9883bafedbe66',
						'engine',
						cast(trim('2014-10-20 14:41:41.135134+02') as timestamp),
						cast(trim('2014-10-20 14:41:41.165925+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '109ae5d625554b9543d3603b8e0421ac' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('providers', 'tenant_name', 'VARCHAR(128)');
**************************

 

********* QUERY **********
select fn_db_add_column('providers', 'plugin_type', 'VARCHAR(64)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030300'),
						'upgrade/03_03_0300_add_tenant_and_plugin_type_to_providers.sql',
						'109ae5d625554b9543d3603b8e0421ac',
						'engine',
						cast(trim('2014-10-20 14:41:41.184218+02') as timestamp),
						cast(trim('2014-10-20 14:41:41.23393+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ef07f127231fd254f1ac526dc06f7a8b' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
ALTER TABLE network ADD COLUMN provider_network_provider_id UUID CONSTRAINT fk_network_provided_by REFERENCES providers(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE network ADD COLUMN provider_network_external_id TEXT;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030310'),
						'upgrade/03_03_0310_add_provided_by_to_network.sql',
						'ef07f127231fd254f1ac526dc06f7a8b',
						'engine',
						cast(trim('2014-10-20 14:41:41.276188+02') as timestamp),
						cast(trim('2014-10-20 14:41:41.344769+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'adf2c330ad04864a438238a4a3465b0b' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('base_disks', 'alignment', 'smallint default 0');
**************************

 

********* QUERY **********
select fn_db_add_column('base_disks', 'last_alignment_scan', 'timestamp with time zone');
**************************

 

********* QUERY **********
insert into action_version_map values (232, '3.3', '*');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030320'),
						'upgrade/03_03_0320_base_disks_alignment.sql',
						'adf2c330ad04864a438238a4a3465b0b',
						'engine',
						cast(trim('2014-10-20 14:41:41.366779+02') as timestamp),
						cast(trim('2014-10-20 14:41:41.518025+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'f9f3700b4af48c9d5cdf3171f3a5c27c' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vds_dynamic', 'supported_emulated_machines', 'character varying(255)');
**************************

 

********* QUERY **********
SELECT fn_db_add_column('vds_groups', 'emulated_machine', 'character varying(40)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030330'),
						'upgrade/03_03_0330_add_emulated_machine_to_host_and_cluster.sql',
						'f9f3700b4af48c9d5cdf3171f3a5c27c',
						'engine',
						cast(trim('2014-10-20 14:41:41.53613+02') as timestamp),
						cast(trim('2014-10-20 14:41:41.621496+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '7bf799b7b3f1af8297bd470159f05fea' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE vds_groups SET emulated_machine = (
  SELECT option_value from vdc_options
   WHERE option_name = 'EmulatedMachine'
   AND version = vds_groups.compatibility_version);
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030340'),
						'upgrade/03_03_0340_upgrade_to_cluster_emulated_machine.sql',
						'7bf799b7b3f1af8297bd470159f05fea',
						'engine',
						cast(trim('2014-10-20 14:41:41.639754+02') as timestamp),
						cast(trim('2014-10-20 14:41:41.681452+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '045b9941a8075bb8775ca6c0b08e8693' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('async_tasks', 'vdsm_task_id', 'UUID DEFAULT NULL');
**************************

 

********* QUERY **********
CREATE INDEX IDX_vdsm_task_id ON async_tasks(vdsm_task_id);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030350'),
						'upgrade/03_03_0350_add_vdsm_task_id_and_index_to_async_tasks.sql',
						'045b9941a8075bb8775ca6c0b08e8693',
						'engine',
						cast(trim('2014-10-20 14:41:41.719415+02') as timestamp),
						cast(trim('2014-10-20 14:41:41.790423+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'dcf3623c26e94a3359048b8cac8ebeba' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('async_tasks', 'root_command_id', 'UUID DEFAULT NULL');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030360'),
						'upgrade/03_03_0360_add_root_command_id_to_async_tasks.sql',
						'dcf3623c26e94a3359048b8cac8ebeba',
						'engine',
						cast(trim('2014-10-20 14:41:41.836032+02') as timestamp),
						cast(trim('2014-10-20 14:41:41.917586+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'bdd57b3dba231b0abddc12c003cdeb78' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_groups', 'trusted_service', 'boolean not null default false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030370'),
						'upgrade/03_03_0370_add_trusted_service_to_vds_groups.sql',
						'bdd57b3dba231b0abddc12c003cdeb78',
						'engine',
						cast(trim('2014-10-20 14:41:41.938328+02') as timestamp),
						cast(trim('2014-10-20 14:41:42.076457+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'd42a3a305b824dee627b6df68b995311' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_drop_column('vm_templates', 'is_auto_suspend');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030380'),
						'upgrade/03_03_0380_remove_auto_suspend.sql',
						'd42a3a305b824dee627b6df68b995311',
						'engine',
						cast(trim('2014-10-20 14:41:42.122492+02') as timestamp),
						cast(trim('2014-10-20 14:41:42.205407+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '0fdc27335402e2fdf052a11d4f379b09' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'created_by_user_id', 'UUID default NULL');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030390'),
						'upgrade/03_03_0390_add_created_by_user_id_column.sql',
						'0fdc27335402e2fdf052a11d4f379b09',
						'engine',
						cast(trim('2014-10-20 14:41:42.245716+02') as timestamp),
						cast(trim('2014-10-20 14:41:42.329053+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '0864debce07384c0183d125b836c796c' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_drop_column('users', 'session_count');
**************************

 

********* QUERY **********
select fn_db_drop_column('users', 'desktop_device');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030400'),
						'upgrade/03_03_0400_remove_unused_colums_from_user.sql',
						'0864debce07384c0183d125b836c796c',
						'engine',
						cast(trim('2014-10-20 14:41:42.375028+02') as timestamp),
						cast(trim('2014-10-20 14:41:42.469652+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '321362c10a0ea1ed1cbc0d6df582abd5' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update base_disks set alignment=0 where alignment is null;
**************************

UPDATE 0
********* QUERY **********
alter table base_disks alter column alignment set not null;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030410'),
						'upgrade/03_03_0410_alignment_not_null.sql',
						'321362c10a0ea1ed1cbc0d6df582abd5',
						'engine',
						cast(trim('2014-10-20 14:41:42.509055+02') as timestamp),
						cast(trim('2014-10-20 14:41:42.557086+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'b69f6c08efd1204628367957e922c761' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('storage_domain_static', 'storage_description', 'VARCHAR(4000)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030420'),
						'upgrade/03_03_0420_add_storage_static_description_column.sql',
						'b69f6c08efd1204628367957e922c761',
						'engine',
						cast(trim('2014-10-20 14:41:42.575195+02') as timestamp),
						cast(trim('2014-10-20 14:41:42.606111+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '4068a6da0ae03d632d6c50e7cef7c3f4' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_groups', 'tunnel_migration', 'boolean NOT NULL default false');
**************************

 

********* QUERY **********
select fn_db_add_column('vm_static', 'tunnel_migration', 'boolean');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030430'),
						'upgrade/03_03_0430_add_tunnel_migration.sql',
						'4068a6da0ae03d632d6c50e7cef7c3f4',
						'engine',
						cast(trim('2014-10-20 14:41:42.635002+02') as timestamp),
						cast(trim('2014-10-20 14:41:42.777502+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '26902644988ab6f408677f7547e5e09a' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_statistics', 'mem_free', 'BIGINT');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030440'),
						'upgrade/03_03_0440_add_free_mem_to_vds_statistics.sql',
						'26902644988ab6f408677f7547e5e09a',
						'engine',
						cast(trim('2014-10-20 14:41:42.800508+02') as timestamp),
						cast(trim('2014-10-20 14:41:42.887257+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '20e68aad0fe70b0ca5a752cf52e41bb5' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('job', 'is_external', 'boolean default false');
**************************

 

********* QUERY **********
select fn_db_add_column('job', 'is_auto_cleared', 'boolean default true');
**************************

 

********* QUERY **********
select fn_db_add_column('step', 'is_external', 'boolean default false');
**************************

 

********* QUERY **********
INSERT INTO roles_groups(role_id,action_group_id) SELECT '00000000-0000-0000-0000-000000000001',1500
    WHERE NOT EXISTS (SELECT role_id,action_group_id
    from roles_groups
    WHERE role_id = '00000000-0000-0000-0000-000000000001' and
          action_group_id = 1500);
**************************

INSERT 0 0
********* QUERY **********
Create or replace FUNCTION __temp_insert_predefined_externa_tasks_creator_role()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_external_task_creator_user_id UUID;
BEGIN
   v_external_task_creator_user_id := 'DEF0000D-0000-0000-0000-DEF000000000';

INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children) SELECT v_external_task_creator_user_id, 'ExternalTasksCreator', 'External Tasks Creator', true, 2, false
WHERE NOT EXISTS (SELECT id,name,description,is_readonly,role_type
                  FROM roles
                  WHERE id = v_external_task_creator_user_id
                  AND name='ExternalTasksCreator'
                  AND description='External Tasks Creator'
                  AND is_readonly=true
                  AND role_type=2);

INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_external_task_creator_user_id, 1500);

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_insert_predefined_externa_tasks_creator_role();
**************************

 

********* QUERY **********
DROP function __temp_insert_predefined_externa_tasks_creator_role();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030450'),
						'upgrade/03_03_0450_add_external_tasks_support.sql',
						'20e68aad0fe70b0ca5a752cf52e41bb5',
						'engine',
						cast(trim('2014-10-20 14:41:42.914391+02') as timestamp),
						cast(trim('2014-10-20 14:41:43.235128+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'cda2b0460123aea8dba5b55b4d7984b1' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE network_qos
(
  id uuid NOT NULL,
  name VARCHAR(50) NOT NULL,
  storage_pool_id uuid NOT NULL,
  inbound_average INTEGER,
  inbound_peak INTEGER,
  inbound_burst INTEGER,
  outbound_average INTEGER,
  outbound_peak INTEGER,
  outbound_burst INTEGER,
  _create_date TIMESTAMP WITH TIME ZONE default LOCALTIMESTAMP,
  _update_date TIMESTAMP WITH TIME ZONE default NULL,
  CONSTRAINT PK_network_qos_id PRIMARY KEY (id)
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
ALTER TABLE network_qos ADD CONSTRAINT network_qos_storage_pool_fk
FOREIGN KEY(storage_pool_id) REFERENCES storage_pool(id) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
CREATE INDEX IDX_network_qos_storage_pool_id ON network_qos
(storage_pool_id);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030460'),
						'upgrade/03_03_0460_add_network_qos_table.sql',
						'cda2b0460123aea8dba5b55b4d7984b1',
						'engine',
						cast(trim('2014-10-20 14:41:43.254675+02') as timestamp),
						cast(trim('2014-10-20 14:41:43.358418+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e7efbb2058c89cc1e02469c5544dd2f7' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into action_version_map (action_type, cluster_minimal_version, storage_pool_minimal_version) values(1013, '3.3', '3.3');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030470'),
						'upgrade/03_03_0470_add_extend_image_size_action_version_map.sql',
						'e7efbb2058c89cc1e02469c5544dd2f7',
						'engine',
						cast(trim('2014-10-20 14:41:43.376282+02') as timestamp),
						cast(trim('2014-10-20 14:41:43.446263+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '4c602aa8a350503e46a32a4d3a78932d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE policy_units
(
    id UUID CONSTRAINT policy_unit_pk PRIMARY KEY,
    name VARCHAR(128) NOT NULL,
    is_internal BOOLEAN NOT NULL,
    has_filter BOOLEAN NOT NULL,
    has_function BOOLEAN NOT NULL,
    has_balance BOOLEAN NOT NULL,
    custom_properties_regex text
);
**************************

CREATE TABLE
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, has_filter, has_function, has_balance, custom_properties_regex) VALUES ('84e6ddee-ab0d-42dd-82f0-c297779db5e5', 'Migration', true, true, false, false, NULL);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, has_filter, has_function, has_balance, custom_properties_regex) VALUES ('a267eddb-768d-45fd-9dbb-6ebcee343508', 'MigrationDomain', true, true, false, false, NULL);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, has_filter, has_function, has_balance, custom_properties_regex) VALUES ('12262ab6-9690-4bc3-a2b3-35573b172d54', 'PinToHost', true, true, false, false, NULL);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, has_filter, has_function, has_balance, custom_properties_regex) VALUES ('6d636bf6-a35c-4f9d-b68d-0731f720cddc', 'CPU', true, true, false, false, NULL);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, has_filter, has_function, has_balance, custom_properties_regex) VALUES ('c9ddbb34-0e1d-4061-a8d7-b0893fa80932', 'Memory', true, true, false, false, NULL);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, has_filter, has_function, has_balance, custom_properties_regex) VALUES ('72163d1c-9468-4480-99d9-0888664eb143', 'Network', true, true, false, false, NULL);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, has_filter, has_function, has_balance, custom_properties_regex) VALUES ('38440000-8cf0-14bd-c43e-10b96e4ef00a', 'None', true, false, true, true, NULL);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, has_filter, has_function, has_balance, custom_properties_regex) VALUES ('736999d0-1023-46a4-9a75-1316ed50e151', 'PowerSaving', true, false, true, true, '{
  "CpuOverCommitDurationMinutes" : "^([1-9])$",
  "HighUtilization" : "^([5-9][0-9])$",
  "LowUtilization" : "^([1-4][0-9])$"
}');
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, has_filter, has_function, has_balance, custom_properties_regex) VALUES ('7db4ab05-81ab-42e8-868a-aee2df483ed2', 'EvenDistribution', true, false, true, true, '{
  "CpuOverCommitDurationMinutes" : "^([1-9])$",
  "HighUtilization" : "^([5-9][0-9])$"
}');
**************************

INSERT 0 1
********* QUERY **********
CREATE TABLE cluster_policies
(
    id UUID CONSTRAINT cluster_policy_pk PRIMARY KEY,
    name VARCHAR(128) NOT NULL,
    description VARCHAR(4000),
    is_locked BOOLEAN NOT NULL,
    is_default BOOLEAN NOT NULL,
    custom_properties text
);
**************************

CREATE TABLE
********* QUERY **********
INSERT INTO cluster_policies (id, name, description, is_locked, is_default, custom_properties) VALUES ('20d25257-b4bd-4589-92a6-c4c5c5d3fd1a', 'Evenly_Distributed', '', true, false, '{
  "CpuOverCommitDurationMinutes" : "2",
  "HighUtilization" : "80"
}');
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policies (id, name, description, is_locked, is_default, custom_properties) VALUES ('5a2b0939-7d46-4b73-a469-e9c2c7fc6a53', 'Power_Saving', '', true, false, '{
  "CpuOverCommitDurationMinutes" : "2",
  "HighUtilization" : "80",
  "LowUtilization" : "20"
}');
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policies (id, name, description, is_locked, is_default, custom_properties) VALUES ('b4ed2332-a7ac-4d5f-9596-99a439cb2812', 'None', '', true, true, NULL);
**************************

INSERT 0 1
********* QUERY **********
CREATE TABLE cluster_policy_units
(
    cluster_policy_id UUID,
    policy_unit_id UUID,
    is_filter_selected BOOLEAN NOT NULL,
    filter_sequence INTEGER DEFAULT 0,
    is_function_selected BOOLEAN NOT NULL,
    factor INTEGER DEFAULT 1,
    is_balance_selected BOOLEAN,
    CONSTRAINT FK_cluster_policy_id FOREIGN KEY(cluster_policy_id) REFERENCES cluster_policies(id) ON UPDATE NO ACTION ON DELETE CASCADE,
    CONSTRAINT FK_policy_unit_id FOREIGN KEY(policy_unit_id) REFERENCES policy_units(id) ON UPDATE NO ACTION ON DELETE CASCADE
);
**************************

CREATE TABLE
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('20d25257-b4bd-4589-92a6-c4c5c5d3fd1a', '84e6ddee-ab0d-42dd-82f0-c297779db5e5', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('20d25257-b4bd-4589-92a6-c4c5c5d3fd1a', 'c9ddbb34-0e1d-4061-a8d7-b0893fa80932', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('20d25257-b4bd-4589-92a6-c4c5c5d3fd1a', '6d636bf6-a35c-4f9d-b68d-0731f720cddc', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('20d25257-b4bd-4589-92a6-c4c5c5d3fd1a', '12262ab6-9690-4bc3-a2b3-35573b172d54', true, -1, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('20d25257-b4bd-4589-92a6-c4c5c5d3fd1a', '7db4ab05-81ab-42e8-868a-aee2df483ed2', false, 0, true, 1, true);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('20d25257-b4bd-4589-92a6-c4c5c5d3fd1a', '72163d1c-9468-4480-99d9-0888664eb143', true, 1, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('20d25257-b4bd-4589-92a6-c4c5c5d3fd1a', 'a267eddb-768d-45fd-9dbb-6ebcee343508', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('5a2b0939-7d46-4b73-a469-e9c2c7fc6a53', '84e6ddee-ab0d-42dd-82f0-c297779db5e5', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('5a2b0939-7d46-4b73-a469-e9c2c7fc6a53', 'c9ddbb34-0e1d-4061-a8d7-b0893fa80932', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('5a2b0939-7d46-4b73-a469-e9c2c7fc6a53', '736999d0-1023-46a4-9a75-1316ed50e151', false, 0, true, 1, true);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('5a2b0939-7d46-4b73-a469-e9c2c7fc6a53', '6d636bf6-a35c-4f9d-b68d-0731f720cddc', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('5a2b0939-7d46-4b73-a469-e9c2c7fc6a53', '12262ab6-9690-4bc3-a2b3-35573b172d54', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('5a2b0939-7d46-4b73-a469-e9c2c7fc6a53', '72163d1c-9468-4480-99d9-0888664eb143', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('5a2b0939-7d46-4b73-a469-e9c2c7fc6a53', 'a267eddb-768d-45fd-9dbb-6ebcee343508', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('b4ed2332-a7ac-4d5f-9596-99a439cb2812', '38440000-8cf0-14bd-c43e-10b96e4ef00a', false, 0, true, 1, true);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('b4ed2332-a7ac-4d5f-9596-99a439cb2812', '84e6ddee-ab0d-42dd-82f0-c297779db5e5', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('b4ed2332-a7ac-4d5f-9596-99a439cb2812', 'c9ddbb34-0e1d-4061-a8d7-b0893fa80932', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('b4ed2332-a7ac-4d5f-9596-99a439cb2812', '6d636bf6-a35c-4f9d-b68d-0731f720cddc', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('b4ed2332-a7ac-4d5f-9596-99a439cb2812', '12262ab6-9690-4bc3-a2b3-35573b172d54', true, -1, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('b4ed2332-a7ac-4d5f-9596-99a439cb2812', '72163d1c-9468-4480-99d9-0888664eb143', true, 1, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) VALUES ('b4ed2332-a7ac-4d5f-9596-99a439cb2812', 'a267eddb-768d-45fd-9dbb-6ebcee343508', true, 0, false, 0, false);
**************************

INSERT 0 1
********* QUERY **********
select fn_db_add_column('vds_groups', 'cluster_policy_id', 'UUID');
**************************

 

********* QUERY **********
select fn_db_add_column('vds_groups', 'cluster_policy_custom_properties', 'text');
**************************

 

********* QUERY **********
UPDATE vds_groups
SET    cluster_policy_id = '20d25257-b4bd-4589-92a6-c4c5c5d3fd1a',
	       cluster_policy_custom_properties =
'{
  "CpuOverCommitDurationMinutes" : "'|| cpu_over_commit_duration_minutes ||'",
  "HighUtilization" : "' || high_utilization ||'"
}'
WHERE  selection_algorithm = 1;
**************************

UPDATE 0
********* QUERY **********
UPDATE vds_groups
SET    cluster_policy_id = '5a2b0939-7d46-4b73-a469-e9c2c7fc6a53',
cluster_policy_custom_properties =
'{
  "CpuOverCommitDurationMinutes" : "'|| cpu_over_commit_duration_minutes ||'",
  "HighUtilization" : "' || high_utilization ||'",
  "LowUtilization" : "' || low_utilization ||'"
}'
WHERE  selection_algorithm = 2;
**************************

UPDATE 0
********* QUERY **********
UPDATE vds_groups
SET    cluster_policy_id = 'b4ed2332-a7ac-4d5f-9596-99a439cb2812'
WHERE  selection_algorithm = 0

OR cluster_policy_id IS NULL;
**************************

UPDATE 1
********* QUERY **********
select fn_db_create_constraint('vds_groups', 'vds_groups_cluster_policy', 'FOREIGN KEY(cluster_policy_id) REFERENCES cluster_policies(id)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030480'),
						'upgrade/03_03_0480_upgrade_cluster_policy.sql',
						'4c602aa8a350503e46a32a4d3a78932d',
						'engine',
						cast(trim('2014-10-20 14:41:43.488973+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.039503+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '37d69cebc37f8b0e2262ff268ae7849b' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('providers', 'agent_configuration', 'TEXT');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030490'),
						'upgrade/03_03_0490_add_agent_configuration_to_provider.sql',
						'37d69cebc37f8b0e2262ff268ae7849b',
						'engine',
						cast(trim('2014-10-20 14:41:44.058022+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.096359+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'cc8a8b6b02daaab78b2c07aba6ec33c5' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_groups', 'enable_balloon', 'boolean not null default false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030500'),
						'upgrade/03_03_0500_add_enable_balloon_to_vds_groups.sql',
						'cc8a8b6b02daaab78b2c07aba6ec33c5',
						'engine',
						cast(trim('2014-10-20 14:41:44.138293+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.207042+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e1c9e3855c9a8515619a50aa47a08c87' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_static', 'ssh_username', 'VARCHAR(255)');
**************************

 

********* QUERY **********
select fn_db_add_column('vds_static', 'ssh_port', 'INTEGER');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030510'),
						'upgrade/03_03_0510_add_vds_ssh_fields.sql',
						'e1c9e3855c9a8515619a50aa47a08c87',
						'engine',
						cast(trim('2014-10-20 14:41:44.231774+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.322167+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '89d23482613c815d4bfaef05fa593590' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('network', 'free_text_comment', 'text');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030520'),
						'upgrade/03_03_0520_add_comment_network.sql',
						'89d23482613c815d4bfaef05fa593590',
						'engine',
						cast(trim('2014-10-20 14:41:44.340225+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.373465+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '1163d17d614e09967e96f56d99e24153' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_static', 'free_text_comment', 'text');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030530'),
						'upgrade/03_03_0530_add_comment_vds_static.sql',
						'1163d17d614e09967e96f56d99e24153',
						'engine',
						cast(trim('2014-10-20 14:41:44.3992+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.432626+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '6826c2deffeed563884484bc93cc4fc0' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_groups', 'free_text_comment', 'text');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030540'),
						'upgrade/03_03_0540_add_comment_vds_groups.sql',
						'6826c2deffeed563884484bc93cc4fc0',
						'engine',
						cast(trim('2014-10-20 14:41:44.462946+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.496468+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e45ce0da39ef38767a9af2089c155f88' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into action_version_map values (1014, '3.3', '*');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030550'),
						'upgrade/03_03_0550_glance_import_command.sql',
						'e45ce0da39ef38767a9af2089c155f88',
						'engine',
						cast(trim('2014-10-20 14:41:44.538482+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.564206+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '61333e3af8dd9870b45750b3fc6ab17e' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into action_version_map values (1015, '3.3', '*');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030560'),
						'upgrade/03_03_0560_glance_export_command.sql',
						'61333e3af8dd9870b45750b3fc6ab17e',
						'engine',
						cast(trim('2014-10-20 14:41:44.598556+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.676732+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'd23f4e822fcab373747d9e3d6850752f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('storage_domain_static', 'storage_comment', 'text');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030570'),
						'upgrade/03_03_0570_add_comment_storage_domain_static.sql',
						'd23f4e822fcab373747d9e3d6850752f',
						'engine',
						cast(trim('2014-10-20 14:41:44.718538+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.746358+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'f9dd5604cb14525d614151469b5bfc28' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_drop_column('vds_groups', 'selection_algorithm');
**************************

 

********* QUERY **********
select fn_db_drop_column('vds_groups', 'high_utilization');
**************************

 

********* QUERY **********
select fn_db_drop_column('vds_groups', 'low_utilization');
**************************

 

********* QUERY **********
select fn_db_drop_column('vds_groups', 'cpu_over_commit_duration_minutes');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030580'),
						'upgrade/03_03_0580_remove_selection_algorithm_columns.sql',
						'f9dd5604cb14525d614151469b5bfc28',
						'engine',
						cast(trim('2014-10-20 14:41:44.790649+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.909306+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '49acc482703246c80d759f969b83edb5' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'free_text_comment', 'text');
**************************

 

********* QUERY **********
select fn_db_add_column('vm_pools', 'vm_pool_comment', 'text');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030590'),
						'upgrade/03_03_0590_add_comment_vm_static_and_pool.sql',
						'49acc482703246c80d759f969b83edb5',
						'engine',
						cast(trim('2014-10-20 14:41:44.927636+02') as timestamp),
						cast(trim('2014-10-20 14:41:44.973438+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e539a82b81b20e02bb05a4a9d0a2ff5e' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('VDS_UNTRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('USER_UPDATE_VM_FROM_TRUSTED_TO_UNTRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('USER_UPDATE_VM_FROM_UNTRUSTED_TO_TRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('IMPORTEXPORT_IMPORT_VM_FROM_TRUSTED_TO_UNTRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('IMPORTEXPORT_IMPORT_VM_FROM_UNTRUSTED_TO_TRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('USER_ADD_VM_FROM_TRUSTED_TO_UNTRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('USER_ADD_VM_FROM_UNTRUSTED_TO_TRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('IMPORTEXPORT_IMPORT_TEMPLATE_FROM_TRUSTED_TO_UNTRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('IMPORTEXPORT_IMPORT_TEMPLATE_FROM_UNTRUSTED_TO_TRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('USER_ADD_VM_TEMPLATE_FROM_TRUSTED_TO_UNTRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('USER_ADD_VM_TEMPLATE_FROM_UNTRUSTED_TO_TRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('USER_UPDATE_VM_TEMPLATE_FROM_TRUSTED_TO_UNTRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('USER_UPDATE_VM_TEMPLATE_FROM_UNTRUSTED_TO_TRUSTED', '');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030600'),
						'upgrade/03_03_0600_add_trusted_service_notifications.sql',
						'e539a82b81b20e02bb05a4a9d0a2ff5e',
						'engine',
						cast(trim('2014-10-20 14:41:44.996815+02') as timestamp),
						cast(trim('2014-10-20 14:41:45.200931+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ddd0fe73a751aa4c006598b3691d2df6' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vm_static set default_display_type = 1 where vm_guid = '00000000-0000-0000-0000-000000000000';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030610'),
						'upgrade/03_03_0610_spice_as_default_display_type_on_blank_template.sql',
						'ddd0fe73a751aa4c006598b3691d2df6',
						'engine',
						cast(trim('2014-10-20 14:41:45.247217+02') as timestamp),
						cast(trim('2014-10-20 14:41:45.328221+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '7eea8208937f8feb9cc1118e3ffbb675' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
create or replace function __temp_add_external_id_to_users() returns void
as $function$
begin
  if (not exists (select 1 from information_schema.columns where table_name ilike 'users' and column_name ilike 'external_id')) then
    alter table users add column external_id bytea not null default '';
    update users set external_id = decode(replace(user_id::text, '-', ''), 'hex');
    perform fn_db_create_constraint('users', 'users_domain_external_id_unique', 'unique (domain, external_id)');
  end if;
end; $function$
language plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp_add_external_id_to_users();
**************************

 

********* QUERY **********
drop function __temp_add_external_id_to_users();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030620'),
						'upgrade/03_03_0620_add_external_id_to_users.sql',
						'7eea8208937f8feb9cc1118e3ffbb675',
						'engine',
						cast(trim('2014-10-20 14:41:45.369215+02') as timestamp),
						cast(trim('2014-10-20 14:41:45.49+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '032a02a250b9920451b029ca91f19584' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('VM_STATUS_RESTORED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_SERVER_REMOVE', 'GLUSTER_SERVER_REMOVE_FAILED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_OPTION_ADDED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_OPTION_MODIFIED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_OPTIONS_RESET_ALL', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_PROFILE_START', 'GLUSTER_VOLUME_PROFILE_START_FAILED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_PROFILE_START_FAILED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_PROFILE_STOP', 'GLUSTER_VOLUME_PROFILE_STOP_FAILED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_PROFILE_STOP_FAILED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030630'),
						'upgrade/03_03_0630_add_missing_event_map.sql',
						'032a02a250b9920451b029ca91f19584',
						'engine',
						cast(trim('2014-10-20 14:41:45.537052+02') as timestamp),
						cast(trim('2014-10-20 14:41:45.690234+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '861882357bafaa6baaafacaba1783975' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vds_static set ssh_username='root' where ssh_username is null;
**************************

UPDATE 0
********* QUERY **********
update vds_static set ssh_port=22 where ssh_port is null;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030640'),
						'upgrade/03_03_0640_default_vdsstatic_values_to_ssh_fields.sql',
						'861882357bafaa6baaafacaba1783975',
						'engine',
						cast(trim('2014-10-20 14:41:45.708179+02') as timestamp),
						cast(trim('2014-10-20 14:41:45.749112+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '990e32dae84250ad9d4380d6055eeb3c' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'single_qxl_pci', 'BOOLEAN NOT NULL DEFAULT FALSE');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030650'),
						'upgrade/03_03_0650_add_signle_qxl_pci_column.sql',
						'990e32dae84250ad9d4380d6055eeb3c',
						'engine',
						cast(trim('2014-10-20 14:41:45.795277+02') as timestamp),
						cast(trim('2014-10-20 14:41:45.947766+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '6cba9baffcf58bc26bce8970c527d375' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE vm_static set os = 0 where os = 6;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030660'),
						'upgrade/03_03_0660_alter_os_type_unassigned_to_other.sql',
						'6cba9baffcf58bc26bce8970c527d375',
						'engine',
						cast(trim('2014-10-20 14:41:45.966263+02') as timestamp),
						cast(trim('2014-10-20 14:41:46.038866+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'eaa2d4f025a49d60aab436098ea8fcb0' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('policy_units', 'type', 'smallint default 0');
**************************

 

********* QUERY **********
UPDATE policy_units SET type = 2 WHERE has_balance = true;
**************************

UPDATE 3
********* QUERY **********
SELECT fn_db_drop_column('policy_units', 'has_filter');
**************************

 

********* QUERY **********
SELECT fn_db_drop_column('policy_units', 'has_function');
**************************

 

********* QUERY **********
SELECT fn_db_drop_column('policy_units', 'has_balance');
**************************

 

********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, custom_properties_regex, type) VALUES ('38440000-8cf0-14bd-c43e-10b96e4ef00b', 'None', true, NULL, 1);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, custom_properties_regex, type) VALUES ('736999d0-1023-46a4-9a75-1316ed50e15b', 'PowerSaving', true, NULL, 1);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, custom_properties_regex, type) VALUES ('7db4ab05-81ab-42e8-868a-aee2df483edb', 'EvenDistribution', true, NULL, 1);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected)
SELECT cluster_policy_id, '38440000-8cf0-14bd-c43e-10b96e4ef00b', is_filter_selected, filter_sequence, false, factor, is_balance_selected
FROM cluster_policy_units
WHERE policy_unit_id = '38440000-8cf0-14bd-c43e-10b96e4ef00a' AND is_function_selected = true;
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected)
SELECT cluster_policy_id, '736999d0-1023-46a4-9a75-1316ed50e15b', is_filter_selected, filter_sequence, false, factor, is_balance_selected
FROM cluster_policy_units
WHERE policy_unit_id = '736999d0-1023-46a4-9a75-1316ed50e151' AND is_function_selected = true;
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected)
SELECT cluster_policy_id, '7db4ab05-81ab-42e8-868a-aee2df483edb', is_filter_selected, filter_sequence, false, factor, is_balance_selected
FROM cluster_policy_units
WHERE policy_unit_id = '7db4ab05-81ab-42e8-868a-aee2df483ed2' AND is_function_selected = true;
**************************

INSERT 0 1
********* QUERY **********
DELETE FROM cluster_policy_units WHERE is_function_selected = true AND is_filter_selected = false AND is_balance_selected = false;
**************************

DELETE 0
********* QUERY **********
SELECT fn_db_drop_column('cluster_policy_units', 'is_filter_selected');
**************************

 

********* QUERY **********
SELECT fn_db_drop_column('cluster_policy_units', 'is_function_selected');
**************************

 

********* QUERY **********
SELECT fn_db_drop_column('cluster_policy_units', 'is_balance_selected');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030670'),
						'upgrade/03_03_0670_allow_single_logic_for_policy_unit.sql',
						'eaa2d4f025a49d60aab436098ea8fcb0',
						'engine',
						cast(trim('2014-10-20 14:41:46.057652+02') as timestamp),
						cast(trim('2014-10-20 14:41:46.347165+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '2dbab629d1955c8a968a75b4e68cc87d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'cpu_shares', 'integer not null default 0');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030680'),
						'upgrade/03_03_0680_add_cpu_shares_to_vm.sql',
						'2dbab629d1955c8a968a75b4e68cc87d',
						'engine',
						cast(trim('2014-10-20 14:41:46.365325+02') as timestamp),
						cast(trim('2014-10-20 14:41:46.460456+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '5e791c91f298ca662f275e21524e9e30' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('policy_units', 'enabled', 'boolean default TRUE NOT NULL');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030690'),
						'upgrade/03_03_0690_add_enabled_column_to_policy_unit.sql',
						'5e791c91f298ca662f275e21524e9e30',
						'engine',
						cast(trim('2014-10-20 14:41:46.478451+02') as timestamp),
						cast(trim('2014-10-20 14:41:46.569234+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '8a6d1a83664bf61ba09682a7dad9adc7' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_dynamic', 'is_run_once', 'boolean NOT NULL DEFAULT false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030700'),
						'upgrade/03_03_0700_add_is_run_once_to_vm_dynamic.sql',
						'8a6d1a83664bf61ba09682a7dad9adc7',
						'engine',
						cast(trim('2014-10-20 14:41:46.588155+02') as timestamp),
						cast(trim('2014-10-20 14:41:46.687412+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'f48faa57cf2e239f8a50826beef07454' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE vnic_profiles
(
  id UUID NOT NULL CONSTRAINT pk_vnic_profiles_id PRIMARY KEY,
  name VARCHAR(50) NOT NULL,
  network_id UUID NOT NULL,
  port_mirroring BOOLEAN NOT NULL,
  custom_properties TEXT,
  description TEXT,
  _create_date TIMESTAMP WITH TIME ZONE default LOCALTIMESTAMP,
  _update_date TIMESTAMP WITH TIME ZONE,
  FOREIGN KEY (network_id) REFERENCES network(id) ON DELETE CASCADE
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
DROP INDEX IF EXISTS IDX_vnic_profiles_network_id;
**************************

DROP INDEX
********* QUERY **********
CREATE INDEX IDX_vnic_profiles_network_id ON vnic_profiles(network_id);
**************************

CREATE INDEX
********* QUERY **********
SELECT fn_db_add_column('vm_interface', 'vnic_profile_id', 'UUID');
**************************

 

********* QUERY **********
DROP INDEX IF EXISTS IDX_vm_interface_vnic_profile_id;
**************************

DROP INDEX
********* QUERY **********
CREATE INDEX IDX_vm_interface_vnic_profile_id ON vm_interface(vnic_profile_id);
**************************

CREATE INDEX
********* QUERY **********
ALTER TABLE vm_interface ADD CONSTRAINT FK_vm_interface_vnic_profile_id FOREIGN KEY(vnic_profile_id)
REFERENCES vnic_profiles(id);
**************************

ALTER TABLE
********* QUERY **********
Create or replace FUNCTION __temp_has_port_mirroring_vm_interfaces(v_network_id UUID) RETURNS BOOLEAN
   AS $procedure$
BEGIN
   RETURN ((SELECT COUNT(1)
   FROM vm_interface
   INNER JOIN vm_static
   ON vm_static.vm_guid = vm_interface.vm_guid
   INNER JOIN network_cluster
   ON network_cluster.cluster_id = vm_static.vds_group_id
   INNER JOIN network
   ON network.id = network_cluster.network_id
   AND network.name = vm_interface.network_name
   WHERE network.id = v_network_id
   AND port_mirroring = TRUE) > 0);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION __temp_has_port_mirroring_template_interfaces(v_network_id UUID) RETURNS BOOLEAN
   AS $procedure$
BEGIN
   RETURN ((SELECT COUNT(1)
   FROM vm_interface
   INNER JOIN vm_static
   ON vm_static.vm_guid = vm_interface.vmt_guid
   INNER JOIN network_cluster
   ON network_cluster.cluster_id = vm_static.vds_group_id
   INNER JOIN network
   ON network.id = network_cluster.network_id
   AND network.name = vm_interface.network_name
   WHERE network.id = v_network_id
   AND port_mirroring = TRUE) > 0);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
INSERT INTO vnic_profiles(id, name, network_id, port_mirroring)
       SELECT uuid_generate_v1(),
        network.name,
        network.id,
        FALSE
       FROM network
       WHERE network.vm_network IS TRUE;
**************************

INSERT 17984 1
********* QUERY **********
INSERT INTO vnic_profiles(id, name, network_id, port_mirroring)
       SELECT uuid_generate_v1(),
        network.name || '_pm',
        network.id,
        TRUE
       FROM network
       WHERE network.vm_network IS TRUE
       AND (__temp_has_port_mirroring_template_interfaces(network.id) OR __temp_has_port_mirroring_vm_interfaces(network.id));
**************************

INSERT 0 0
********* QUERY **********
UPDATE vm_interface
SET vnic_profile_id = vnic_profiles.id
       FROM vnic_profiles
       JOIN network ON network.id = vnic_profiles.network_id
       JOIN vds_groups ON network.storage_pool_id = vds_groups.storage_pool_id
       JOIN vm_static ON vm_static.vds_group_id = vds_groups.vds_group_id
       WHERE (vm_interface.vm_guid = vm_static.vm_guid
              OR vm_interface.vmt_guid = vm_static.vm_guid)
       AND vm_interface.port_mirroring = vnic_profiles.port_mirroring
       AND vm_interface.network_name = network.name;
**************************

UPDATE 0
********* QUERY **********
SELECT fn_db_drop_column ('port_mirroring', 'vm_interface');
**************************

 

********* QUERY **********
Create or replace FUNCTION __temp_set_vnic_profiles_permissions()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_NETWORK_ADMIN_ID UUID;
   v_VNIC_PROFILE_USER_ID UUID;
   v_NETWORK_USER_ID UUID;

BEGIN
   v_NETWORK_ADMIN_ID := 'DEF00005-0000-0000-0000-DEF000000005';
   v_VNIC_PROFILE_USER_ID := 'DEF00020-0000-0000-0000-DEF000000010';
   v_NETWORK_USER_ID := 'DEF0000A-0000-0000-0000-DEF000000010';

------------------------------------------------
--- Update existing roles with new Action Groups
------------------------------------------------
-- Add ActionGroup 1203 (CONFIGURE_NETWORK_VNIC_PROFILE) to any role which contains ActionGroup 703 (CONFIGURE_STORAGE_POOL_NETWORK)
    INSERT INTO roles_groups (role_id, action_group_id)
    SELECT DISTINCT role_id, 1203
    FROM roles_groups a
    WHERE NOT EXISTS (SELECT 1
                      FROM roles_groups b
                      WHERE b.role_id = a.role_id
                      AND b.action_group_id = 1203)
    AND EXISTS (SELECT 1
                FROM roles_groups b
                WHERE b.role_id = a.role_id
                AND b.action_group_id = 703);

-- Add ActionGroup 1204 (CREATE_NETWORK_VNIC_PROFILE) to any role which contains ActionGroup 704 (CREATE_STORAGE_POOL_NETWORK)
    INSERT INTO roles_groups (role_id, action_group_id)
    SELECT DISTINCT role_id, 1204
    FROM roles_groups a
    WHERE NOT EXISTS (SELECT 1
                      FROM roles_groups b
                      WHERE b.role_id = a.role_id
                      AND b.action_group_id = 1204)
    AND EXISTS (SELECT 1
                FROM roles_groups b
                WHERE b.role_id = a.role_id
                AND b.action_group_id = 704);

-- Add ActionGroup 1205 (DELETE_NETWORK_VNIC_PROFILE) to any role which contains ActionGroup 705 (DELETE_STORAGE_POOL_NETWORK)
    INSERT INTO roles_groups (role_id, action_group_id)
    SELECT DISTINCT role_id, 1205
    FROM roles_groups a
    WHERE NOT EXISTS (SELECT 1
                      FROM roles_groups b
                      WHERE b.role_id = a.role_id
                      AND b.action_group_id = 1205)
    AND EXISTS (SELECT 1
                FROM roles_groups b
                WHERE b.role_id = a.role_id
                AND b.action_group_id = 705);

----------------------------
-- UPDATE NETWORK_ADMIN role
----------------------------

-- Add CONFIGURE_NETWORK_VNIC_PROFILE
    PERFORM fn_db_add_action_group_to_role(v_NETWORK_ADMIN_ID, 1203);

-- Add CREATE_NETWORK_VNIC_PROFILE
    PERFORM fn_db_add_action_group_to_role(v_NETWORK_ADMIN_ID, 1204);

-- Add DELETE_NETWORK_VNIC_PROFILE
    PERFORM fn_db_add_action_group_to_role(v_NETWORK_ADMIN_ID ,1205);

------------------------
-- ADD VNIC_PROFILE_USER role
------------------------
    INSERT INTO roles(id,name,description,is_readonly,role_type) SELECT v_VNIC_PROFILE_USER_ID, 'VnicProfileUser', 'VM Network Interface Profile User', true, 2
    WHERE NOT EXISTS (SELECT id,name,description,is_readonly,role_type
                      FROM roles
                      WHERE id = v_VNIC_PROFILE_USER_ID
                      AND name='VnicProfileUser'
                      AND description='VM Network Interface Profile User'
                      AND is_readonly=true
                      AND role_type=2);

-- Add CONFIGURE_VM_NETWORK
    PERFORM fn_db_add_action_group_to_role(v_VNIC_PROFILE_USER_ID, 9);

-- Add CONFIGURE_TEMPLATE_NETWORK
    PERFORM fn_db_add_action_group_to_role(v_VNIC_PROFILE_USER_ID, 204);

-- Add LOGIN
    PERFORM fn_db_add_action_group_to_role(v_VNIC_PROFILE_USER_ID, 1300);

---------------------------
-- Grant permission to use the created VNIC profiles to each user which have NetworkUser permission to use the network of the profile
---------------------------
    INSERT INTO permissions (id, role_id, ad_element_id, object_id, object_type_id)
          (SELECT uuid_generate_v1(),
                 v_VNIC_PROFILE_USER_ID,
                 ad_element_id,
                 vnic_profiles.id,
                 27
           FROM permissions
           INNER JOIN vnic_profiles ON vnic_profiles.network_id = permissions.object_id
           WHERE permissions.object_type_id = 20
           AND permissions.role_id = v_NETWORK_USER_ID
           AND NOT EXISTS (SELECT 1
                           FROM permissions p
                           WHERE p.role_id = v_VNIC_PROFILE_USER_ID
                           AND p.ad_element_id = permissions.ad_element_id
                           AND p.object_id = vnic_profiles.id
                           AND object_type_id = 27));


---------------------------
-- Replace any NetworkUser role with VNICProfileUser, on all object types, except networks (which were handeled in the INSERT above)
---------------------------
    UPDATE permissions
    SET role_id = v_VNIC_PROFILE_USER_ID
    WHERE role_id = v_NETWORK_USER_ID AND object_type_id != 20;

---------------------------
-- Delete NetworkUser permissions
---------------------------
    DELETE FROM permissions
    WHERE role_id = v_NETWORK_USER_ID;

---------------------------
-- Delete NetworkUser role
---------------------------
    DELETE FROM roles
    WHERE id = v_NETWORK_USER_ID;

------------------------------------------------
-- Delete Port Mirroring Action Group from Roles
------------------------------------------------
    DELETE FROM roles_groups
    WHERE action_group_id = 1200;


END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_set_vnic_profiles_permissions();
**************************

 

********* QUERY **********
DROP function __temp_set_vnic_profiles_permissions();
**************************

DROP FUNCTION
********* QUERY **********
DROP function __temp_has_port_mirroring_vm_interfaces(UUID);
**************************

DROP FUNCTION
********* QUERY **********
DROP function __temp_has_port_mirroring_template_interfaces(UUID);
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030710'),
						'upgrade/03_03_0710_add_profile_to_network_interface.sql',
						'f48faa57cf2e239f8a50826beef07454',
						'engine',
						cast(trim('2014-10-20 14:41:46.70604+02') as timestamp),
						cast(trim('2014-10-20 14:41:47.025473+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '6753cd3b20d17f13f04a8fe2053aad5c' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_drop_column('vm_interface', 'network_name');
**************************

 

********* QUERY **********
SELECT fn_db_drop_column('vm_interface', 'port_mirroring');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030720'),
						'upgrade/03_03_0720_drop_columns_from_vm_interface.sql',
						'6753cd3b20d17f13f04a8fe2053aad5c',
						'engine',
						cast(trim('2014-10-20 14:41:47.06825+02') as timestamp),
						cast(trim('2014-10-20 14:41:47.114148+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '7e8c66b9e054db8bfa1a07fc8e7895ba' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vdc_options set option_value='' where option_name='AttestationServer';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030730'),
						'upgrade/03_03_0730_update_attestation_server.sql',
						'7e8c66b9e054db8bfa1a07fc8e7895ba',
						'engine',
						cast(trim('2014-10-20 14:41:47.158233+02') as timestamp),
						cast(trim('2014-10-20 14:41:47.185135+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'c635e848573440648bfddc6e0d121c04' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('policy_units', 'description', 'text');
**************************

 

********* QUERY **********
UPDATE policy_units SET description =
CASE
    WHEN name = 'Migration' THEN 'While migrating a VM, filters out the VM''s running host'
    WHEN name = 'MigrationDomain' THEN 'Filters out hosts from different VM''s migration domain, and all non-UP state hosts'
    WHEN name = 'PinToHost' THEN 'Filters out all hosts that VM is not pinned to'
    WHEN name = 'CPU' THEN 'Filters out hosts with less CPUs than VM''s CPUs'
    WHEN name = 'Memory' THEN 'Filters out hosts that have insufficient memory to run the VM'
    WHEN name = 'Network' THEN 'Filters out hosts that are missing networks required by VM NICs, or missing cluster''s display network'


    WHEN id = '38440000-8cf0-14bd-c43e-10b96e4ef00a' THEN 'No load balancing operation'

    WHEN id = '38440000-8cf0-14bd-c43e-10b96e4ef00b' THEN 'Follows Even Distribution weight module'


    WHEN id = '736999d0-1023-46a4-9a75-1316ed50e151' THEN 'Load balancing VMs in cluster according to hosts CPU load, striving cluster''s hosts CPU load to be over ''LowUtilization'' and under ''HighUtilization'''

    WHEN id = '736999d0-1023-46a4-9a75-1316ed50e15b' THEN 'Gives hosts with higher CPU usage, higher weight (means that hosts with lower CPU usage are more likely to be selected)'


    WHEN id = '7db4ab05-81ab-42e8-868a-aee2df483ed2' THEN 'Load balancing VMs in cluster according to hosts CPU load, striving cluster''s hosts CPU load to be under ''HighUtilization'''

    WHEN id = '7db4ab05-81ab-42e8-868a-aee2df483edb' THEN 'Gives hosts with lower CPU usage, higher weight (means that hosts with higher CPU usage are more likely to be selected)'
END;
**************************

UPDATE 12
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030740'),
						'upgrade/03_03_0740_add_description_to_policy_unit.sql',
						'c635e848573440648bfddc6e0d121c04',
						'engine',
						cast(trim('2014-10-20 14:41:47.222399+02') as timestamp),
						cast(trim('2014-10-20 14:41:47.319178+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '05d5709e53f5168e8d1f4b1ba4033c01' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vnic_profiles', 'network_qos_id', 'UUID');
**************************

 

********* QUERY **********
DROP INDEX IF EXISTS IDX_vnic_profiles_network_qos_id;
**************************

DROP INDEX
********* QUERY **********
CREATE INDEX IDX_vnic_profiles_network_qos_id ON vnic_profiles(network_qos_id);
**************************

CREATE INDEX
********* QUERY **********
select fn_db_create_constraint('vnic_profiles', 'FK_vnic_profiles_network_qos_id', 'FOREIGN KEY (network_qos_id) REFERENCES network_qos(id) ON DELETE SET NULL');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030750'),
						'upgrade/03_03_0750_add_network_qos_id_to_vnic_profiles.sql',
						'05d5709e53f5168e8d1f4b1ba4033c01',
						'engine',
						cast(trim('2014-10-20 14:41:47.359237+02') as timestamp),
						cast(trim('2014-10-20 14:41:47.447211+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'c4522ca5c52ec4174f40267543f492c5' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_preserve_network_user_role_id()
RETURNS VOID
AS $procedure$
DECLARE
    v_VNIC_PROFILE_USER_ID UUID;
    v_NETWORK_USER_ID UUID;

BEGIN
    v_VNIC_PROFILE_USER_ID := 'DEF00020-0000-0000-0000-DEF000000010';
    v_NETWORK_USER_ID := 'DEF0000A-0000-0000-0000-DEF000000010';

------------------------------------------------------
-- Update VnicProfileUser roleId to NetworkUser roleId
------------------------------------------------------
    ALTER TABLE roles_groups DROP CONSTRAINT fk_roles_groups_action_id;
    ALTER TABLE permissions DROP CONSTRAINT fk_permissions_roles;

    UPDATE roles
    SET id = v_NETWORK_USER_ID
    WHERE id = v_VNIC_PROFILE_USER_ID;

    UPDATE permissions
    SET role_id = v_NETWORK_USER_ID
    WHERE role_id = v_VNIC_PROFILE_USER_ID;

    UPDATE roles_groups
    SET role_id = v_NETWORK_USER_ID
    WHERE role_id = v_VNIC_PROFILE_USER_ID;

    ALTER TABLE roles_groups ADD CONSTRAINT fk_roles_groups_action_id FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE;
    ALTER TABLE permissions ADD CONSTRAINT fk_permissions_roles FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_preserve_network_user_role_id();
**************************

 

********* QUERY **********
DROP FUNCTION __temp_preserve_network_user_role_id();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030760'),
						'upgrade/03_03_0760_preserve_network_user_id_for_vnic_profile.sql',
						'c4522ca5c52ec4174f40267543f492c5',
						'engine',
						cast(trim('2014-10-20 14:41:47.488772+02') as timestamp),
						cast(trim('2014-10-20 14:41:47.539535+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '274f7a4eb8d400fed7611fa6e802eb8f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
ALTER TABLE vm_interface DROP CONSTRAINT fk_vm_interface_vnic_profile_id;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE vm_interface ADD CONSTRAINT fk_vm_interface_vnic_profile_id FOREIGN KEY (vnic_profile_id) REFERENCES vnic_profiles(id) ON DELETE SET NULL;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030770'),
						'upgrade/03_03_0770_alter_vm_interface_vnic_profile_fk.sql',
						'274f7a4eb8d400fed7611fa6e802eb8f',
						'engine',
						cast(trim('2014-10-20 14:41:47.557493+02') as timestamp),
						cast(trim('2014-10-20 14:41:47.612307+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '74640430f3f97950a46f2b6258882c2c' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vm_static
set time_zone = NULL
where time_zone = '';
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030780'),
						'upgrade/03_03_0780_convert_empty_timezone_to_null.sql',
						'74640430f3f97950a46f2b6258882c2c',
						'engine',
						cast(trim('2014-10-20 14:41:47.647209+02') as timestamp),
						cast(trim('2014-10-20 14:41:47.663764+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '945d75162ad7fb49d1a703dd123faf85' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
DELETE FROM policy_units WHERE id = 'a267eddb-768d-45fd-9dbb-6ebcee343508';
**************************

DELETE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030790'),
						'upgrade/03_03_0790_remove_migration_domain_filter.sql',
						'945d75162ad7fb49d1a703dd123faf85',
						'engine',
						cast(trim('2014-10-20 14:41:47.69086+02') as timestamp),
						cast(trim('2014-10-20 14:41:47.771209+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '33457aaf71dd232cddc160279b0ee620' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'vnc_keyboard_layout', 'VARCHAR(16) default null');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030800'),
						'upgrade/03_03_0800_add_vm_vnc_keyboard_layout.sql',
						'33457aaf71dd232cddc160279b0ee620',
						'engine',
						cast(trim('2014-10-20 14:41:47.801891+02') as timestamp),
						cast(trim('2014-10-20 14:41:47.897891+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '884a2c6fa87fde2fc9692d6b60b20bef' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('roles', 'app_mode', 'INTEGER');
**************************

 

********* QUERY **********
UPDATE roles
SET app_mode = (CASE WHEN name in ('UserRole', 'PowerUserRole', 'DataCenterAdmin', 'StorageAdmin', 'UserVmManager', 'VmPoolAdmin', 'TemplateAdmin', 'TemplateUser', 'QuotaConsumer', 'TemplateOwner', 'DiskOperator', 'DiskCreator', 'VmCreator', 'TemplateCreator', 'VnicProfileUser', 'UserTemplateBasedVm')
				THEN 1
				WHEN name='GlusterAdmin'
				THEN 2
				WHEN name in ('ClusterAdmin', 'SuperUser', 'HostAdmin', 'NetworkAdmin', 'ExternalEventsCreator', 'ExternalTasksCreator')
				THEN 255
				ELSE 255
				END);
**************************

UPDATE 22
********* QUERY **********
ALTER TABLE roles ALTER COLUMN app_mode SET NOT NULL;
**************************

ALTER TABLE
********* QUERY **********
CREATE INDEX IDX_roles__app_mode ON roles(app_mode);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030810'),
						'upgrade/03_03_0810_add_app_mode_to_roles.sql',
						'884a2c6fa87fde2fc9692d6b60b20bef',
						'engine',
						cast(trim('2014-10-20 14:41:47.91604+02') as timestamp),
						cast(trim('2014-10-20 14:41:48.048881+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '24203193c8fba359e2a56d068b013cb7' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('gluster_volumes', 'task_id', 'uuid');
**************************

 

********* QUERY **********
SELECT fn_db_add_column('gluster_volume_bricks', 'task_id', 'uuid');
**************************

 

********* QUERY **********
CREATE INDEX IDX_step_external_id ON step(external_id);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030820'),
						'upgrade/03_03_0820_add_task_id_to_volumeandbricks.sql',
						'24203193c8fba359e2a56d068b013cb7',
						'engine',
						cast(trim('2014-10-20 14:41:48.070931+02') as timestamp),
						cast(trim('2014-10-20 14:41:48.198558+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ea2acce934513bd745fcb050d721c380' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REBALANCE_STOP', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REBALANCE_STOP_FAILED', 'GLUSTER_VOLUME_REBALANCE_STOP');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030830'),
						'upgrade/03_03_0830_add_stop_rebalance_gluster_volume_to_event_map.sql',
						'ea2acce934513bd745fcb050d721c380',
						'engine',
						cast(trim('2014-10-20 14:41:48.217135+02') as timestamp),
						cast(trim('2014-10-20 14:41:48.298142+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '88afac0e6b7ec133fe4987aad00ba851' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE INDEX IDX_job_start_time ON job(start_time);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030840'),
						'upgrade/03_03_0840_add_job_start_time_index.sql',
						'88afac0e6b7ec133fe4987aad00ba851',
						'engine',
						cast(trim('2014-10-20 14:41:48.316196+02') as timestamp),
						cast(trim('2014-10-20 14:41:48.408643+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'aa0fcfafd9c56b7de67b06a9041781ad' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update roles set name ='UserTemplateBasedVm'
where id = 'DEF00009-0000-0000-0000-DEF000000009';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030850'),
						'upgrade/03_03_0850_rename_template_user_role.sql',
						'aa0fcfafd9c56b7de67b06a9041781ad',
						'engine',
						cast(trim('2014-10-20 14:41:48.424151+02') as timestamp),
						cast(trim('2014-10-20 14:41:48.456694+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '2f3b7741eb66a6c4e63e4e8040be0324' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_fix_user_vm_manager_role()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_VM_ADMIN_ID UUID;
BEGIN
   v_VM_ADMIN_ID := 'DEF00006-0000-0000-0000-DEF000000006';

-- Remove the import export vm action group from USER_VM_MANAGER role
DELETE FROM roles_groups
WHERE  role_id = v_VM_ADMIN_ID
AND    action_group_id = 8;

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_fix_user_vm_manager_role();
**************************

 

********* QUERY **********
DROP function __temp_fix_user_vm_manager_role();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030860'),
						'upgrade/03_03_0860_remove_import_export_permissions_from_vm_user_manager.sql',
						'2f3b7741eb66a6c4e63e4e8040be0324',
						'engine',
						cast(trim('2014-10-20 14:41:48.474788+02') as timestamp),
						cast(trim('2014-10-20 14:41:48.534899+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '20f487f0d97e57ea73e770c7b897a6e9' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vds_groups', 'detect_emulated_machine', 'BOOLEAN DEFAULT FALSE');
**************************

 

********* QUERY **********
UPDATE vds_groups set detect_emulated_machine = 'true' where emulated_machine is null;
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030870'),
						'upgrade/03_03_0870_add_detect_emulated_machine_to_cluster.sql',
						'20f487f0d97e57ea73e770c7b897a6e9',
						'engine',
						cast(trim('2014-10-20 14:41:48.58104+02') as timestamp),
						cast(trim('2014-10-20 14:41:48.716731+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'c2c056c31aafd1164703aaf995e8632c' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Insert into dwh_history_timekeeping  VALUES('lastOsinfoUpdate',NULL,to_timestamp('01/01/2000', 'DD/MM/YYYY'));
**************************

INSERT 0 1
********* QUERY **********
CREATE TABLE dwh_osinfo (
  os_id INTEGER NOT NULL,
  os_name VARCHAR(255),
  CONSTRAINT pk_os_id PRIMARY KEY(os_id)
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030880'),
						'upgrade/03_03_0880_add_dwh_osinfo_table.sql',
						'c2c056c31aafd1164703aaf995e8632c',
						'engine',
						cast(trim('2014-10-20 14:41:48.737692+02') as timestamp),
						cast(trim('2014-10-20 14:41:48.799193+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'a50800283727293978bdf4f385052b77' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO roles_groups(role_id,action_group_id)
    SELECT '00000000-0000-0000-0001-000000000001', 
            1106                                   
    WHERE NOT EXISTS (
        SELECT * FROM roles_groups
            WHERE role_id='00000000-0000-0000-0001-000000000001' and
                  action_group_id=1106
    );
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO roles_groups(role_id,action_group_id)
    SELECT 'def00008-0000-0000-0000-def000000008', 
            1106                                   
    WHERE NOT EXISTS (
        SELECT * FROM roles_groups
            WHERE role_id='def00008-0000-0000-0000-def000000008' and
                  action_group_id=1106
    );
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO roles_groups(role_id,action_group_id)
    SELECT '00000000-0000-0000-0000-000000000001', 
            1106                                   
    WHERE NOT EXISTS (
        SELECT * FROM roles_groups
            WHERE role_id='00000000-0000-0000-0000-000000000001' and
                  action_group_id=1106
    );
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO roles_groups(role_id,action_group_id)
    SELECT 'def00003-0000-0000-0000-def000000003', 
            1106                                   
    WHERE NOT EXISTS (
        SELECT * FROM roles_groups
            WHERE role_id='def00003-0000-0000-0000-def000000003' and
                  action_group_id=1106
    );
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO roles_groups(role_id,action_group_id)
    SELECT '00000000-0000-0000-0001-000000000002', 
            1106                                   
    WHERE NOT EXISTS (
        SELECT * FROM roles_groups
            WHERE role_id='00000000-0000-0000-0001-000000000002' and
                  action_group_id=1106
    );
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030890'),
						'upgrade/03_03_0890_image_domains_permissions.sql',
						'a50800283727293978bdf4f385052b77',
						'engine',
						cast(trim('2014-10-20 14:41:48.817469+02') as timestamp),
						cast(trim('2014-10-20 14:41:48.898818+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ce97ffa9d2e7613565d1d88132f3d5de' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE images
SET    quota_id = NULL
WHERE  quota_id NOT IN (SELECT id FROM quota);
**************************

UPDATE 1
********* QUERY **********
UPDATE vm_static
SET    quota_id = NULL
WHERE  quota_id NOT IN (SELECT id FROM quota);
**************************

UPDATE 1
********* QUERY **********
ALTER TABLE images ADD CONSTRAINT fk_images_quota FOREIGN KEY (quota_id) REFERENCES quota(id) ON DELETE SET NULL;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE vm_static ADD CONSTRAINT fk_vm_static_quota FOREIGN KEY (quota_id) REFERENCES quota(id) ON DELETE SET NULL;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030900'),
						'upgrade/03_03_0900_quota_id_foreign_key.sql',
						'ce97ffa9d2e7613565d1d88132f3d5de',
						'engine',
						cast(trim('2014-10-20 14:41:48.917399+02') as timestamp),
						cast(trim('2014-10-20 14:41:49.029515+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'f0cfc8a3d39bbb61d7570b959c51831b' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
DELETE FROM policy_units WHERE id = '84e6ddee-ab0d-42dd-82f0-c297779db5e5';
**************************

DELETE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030910'),
						'upgrade/03_03_0910_remove_migration_filter.sql',
						'f0cfc8a3d39bbb61d7570b959c51831b',
						'engine',
						cast(trim('2014-10-20 14:41:49.047453+02') as timestamp),
						cast(trim('2014-10-20 14:41:49.118267+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'd571d5e094bd5701b73d94dae4d443d9' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_dynamic', 'vm_fqdn', 'TEXT DEFAULT ''''');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030920'),
						'upgrade/03_03_0920_add_fqdn_to_vm_dynamic.sql',
						'd571d5e094bd5701b73d94dae4d443d9',
						'engine',
						cast(trim('2014-10-20 14:41:49.136949+02') as timestamp),
						cast(trim('2014-10-20 14:41:49.289157+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ed6010f56953ba4cf4fe122ce0e9ce1a' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_dynamic', 'cpu_name', 'varchar(255)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030930'),
						'upgrade/03_03_0930_add_cpu_name_to_vm_dynamic.sql',
						'ed6010f56953ba4cf4fe122ce0e9ce1a',
						'engine',
						cast(trim('2014-10-20 14:41:49.307496+02') as timestamp),
						cast(trim('2014-10-20 14:41:49.346232+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '32120ee3a7d62ea0179dee171f02941d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, custom_properties_regex, type, enabled, description) VALUES ('438b052c-90ab-40e8-9be0-a22560202ea6', 'CPU-Level', true, NULL, 0, true, 'Runs VMs only on hosts with a proper CPU level');
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) VALUES ('20d25257-b4bd-4589-92a6-c4c5c5d3fd1a', '438b052c-90ab-40e8-9be0-a22560202ea6', 0, 0);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) VALUES ('5a2b0939-7d46-4b73-a469-e9c2c7fc6a53', '438b052c-90ab-40e8-9be0-a22560202ea6', 0, 0);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) VALUES ('b4ed2332-a7ac-4d5f-9596-99a439cb2812', '438b052c-90ab-40e8-9be0-a22560202ea6', 0, 0);
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030940'),
						'upgrade/03_03_0940_add_cpu_level_policy_unit.sql',
						'32120ee3a7d62ea0179dee171f02941d',
						'engine',
						cast(trim('2014-10-20 14:41:49.388293+02') as timestamp),
						cast(trim('2014-10-20 14:41:49.448184+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3dea9bd8eff3161611809d8098113344' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE policy_units SET name='OptimalForPowerSaving' WHERE id='736999d0-1023-46a4-9a75-1316ed50e151';
**************************

UPDATE 1
********* QUERY **********
UPDATE policy_units SET name='OptimalForPowerSaving' WHERE id='736999d0-1023-46a4-9a75-1316ed50e15b';
**************************

UPDATE 1
********* QUERY **********
UPDATE policy_units SET name='OptimalForEvenDistribution' WHERE id='7db4ab05-81ab-42e8-868a-aee2df483ed2';
**************************

UPDATE 1
********* QUERY **********
UPDATE policy_units SET name='OptimalForEvenDistribution' WHERE id='7db4ab05-81ab-42e8-868a-aee2df483edb';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030950'),
						'upgrade/03_03_0950_change_policy_names.sql',
						'3dea9bd8eff3161611809d8098113344',
						'engine',
						cast(trim('2014-10-20 14:41:49.466102+02') as timestamp),
						cast(trim('2014-10-20 14:41:49.568813+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '562db867159794b87b8e8087d7ade2d1' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO dwh_history_timekeeping VALUES('heartBeat', NULL, to_timestamp('01/01/2000', 'DD/MM/YYYY'));
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030960'),
						'upgrade/03_03_0960_add_dwh_heartbeat.sql',
						'562db867159794b87b8e8087d7ade2d1',
						'engine',
						cast(trim('2014-10-20 14:41:49.587847+02') as timestamp),
						cast(trim('2014-10-20 14:41:49.666723+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'de57f1db1bf172974e0d38be2807ab03' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('START_REMOVING_GLUSTER_VOLUME_BRICKS', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('START_REMOVING_GLUSTER_VOLUME_BRICKS_FAILED', 'START_REMOVING_GLUSTER_VOLUME_BRICKS');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030970'),
						'upgrade/03_03_0970_add_start_remove_gluster_volume_brick_to_event_map.sql',
						'de57f1db1bf172974e0d38be2807ab03',
						'engine',
						cast(trim('2014-10-20 14:41:49.708489+02') as timestamp),
						cast(trim('2014-10-20 14:41:49.757915+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '55338f3e06afea74da09d5e6f638c1f5' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE images
SET    vm_snapshot_id = NULL
WHERE  image_group_id NOT IN (SELECT device_id FROM vm_device);
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030980'),
						'upgrade/03_03_0980_clear_snapshot_id_of_floating_disks.sql',
						'55338f3e06afea74da09d5e6f638c1f5',
						'engine',
						cast(trim('2014-10-20 14:41:49.804602+02') as timestamp),
						cast(trim('2014-10-20 14:41:49.874151+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '863471b00575de09c70fe38264f7a80d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE cluster_policy_units SET filter_sequence=-1 WHERE cluster_policy_id='5a2b0939-7d46-4b73-a469-e9c2c7fc6a53' and policy_unit_id='12262ab6-9690-4bc3-a2b3-35573b172d54';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03030990'),
						'upgrade/03_03_0990_pin_to_host_first_in_powersaving_policy.sql',
						'863471b00575de09c70fe38264f7a80d',
						'engine',
						cast(trim('2014-10-20 14:41:49.902456+02') as timestamp),
						cast(trim('2014-10-20 14:41:49.936948+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'd5ffb43021d6bf95736bb419dce86e8e' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'instance_type_id', 'uuid default null');
**************************

 

********* QUERY **********
select fn_db_add_column('vm_static', 'image_type_id', 'uuid default null');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040010'),
						'upgrade/03_04_0010_add_instance_type_to_vm.sql',
						'd5ffb43021d6bf95736bb419dce86e8e',
						'engine',
						cast(trim('2014-10-20 14:41:49.978553+02') as timestamp),
						cast(trim('2014-10-20 14:41:50.02225+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '8ec875e63637626cd1fc34bfbee16f43' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_insert_predefined_roles_03_03_instance_types()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_INSTANCE_CREATOR_ID UUID;
   v_USER_INSTANCE_MANAGER_ID UUID;

BEGIN
   v_INSTANCE_CREATOR_ID := 'DEF00011-0000-0000-0000-DEF000000011';
   v_USER_INSTANCE_MANAGER_ID := 'DEF00012-0000-0000-0000-DEF000000012';

------------------------
-- ADD INSTANCE_CREATOR role
------------------------
DELETE FROM roles_groups WHERE role_id = v_INSTANCE_CREATOR_ID;
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children,app_mode) select v_INSTANCE_CREATOR_ID, 'InstanceCreator', 'User Role, permission to create Instances', true, 2, false, 1
WHERE NOT EXISTS (SELECT id
                  FROM roles
                  WHERE id = v_INSTANCE_CREATOR_ID);

-- Add CREATE_INSTANCE(16)
PERFORM fn_db_add_action_group_to_role(v_INSTANCE_CREATOR_ID,16);
-- Add CREATE_DISK(1100)
PERFORM fn_db_add_action_group_to_role(v_INSTANCE_CREATOR_ID,1100);
-- Add LOGIN(1300)
PERFORM fn_db_add_action_group_to_role(v_INSTANCE_CREATOR_ID,1300);


------------------------
-- ADD USER_INSTANCE_MANAGER role
------------------------
DELETE FROM roles_groups WHERE role_id = v_USER_INSTANCE_MANAGER_ID;
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children,app_mode) select v_USER_INSTANCE_MANAGER_ID, 'UserInstanceManager', 'User Role, with permission for any operation on Instances', true, 2, false, 1
WHERE NOT EXISTS (SELECT id
                  FROM roles
                  WHERE id = v_USER_INSTANCE_MANAGER_ID);

-- Add DELETE_VM(2)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,2);
-- Add EDIT_VM_PROPERTIES(3)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,3);
-- Add VM_BASIC_OPERATIONS(4)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,4);
-- Add CHANGE_VM_CD(5)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,5);
-- Add CONNECT_TO_VM(7)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,7);
-- Add IMPORT_EXPORT_VM(8)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,8);
-- Add CONFIGURE_VM_STORAGE(10)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,10);
-- Add MANIPULATE_VM_SNAPSHOTS(12)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,12);
-- Add CREATE_DISK(1100)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,1100);
-- Add ATTACH_DISK(1101)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,1101);
-- Add EDIT_DISK_PROPERTIES(1102)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,1102);
-- Add DELETE_DISK(1104)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,1104);
-- Add LOGIN(1300)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,1300);
-- Add MANIPULATE_PERMISSIONS(502)
PERFORM fn_db_add_action_group_to_role(v_USER_INSTANCE_MANAGER_ID,502);

 RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_insert_predefined_roles_03_03_instance_types();
**************************

 

********* QUERY **********
DROP function __temp_insert_predefined_roles_03_03_instance_types();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040020'),
						'upgrade/03_04_0020_add_instance_permissions.sql',
						'8ec875e63637626cd1fc34bfbee16f43',
						'engine',
						cast(trim('2014-10-20 14:41:50.059551+02') as timestamp),
						cast(trim('2014-10-20 14:41:50.116195+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '63f31857c334677cfc8b042234c86bde' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_statistics', 'ha_score', 'INTEGER NOT NULL DEFAULT 0');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040030'),
						'upgrade/03_04_0030_add_ha_score_to_vds_statistics.sql',
						'63f31857c334677cfc8b042234c86bde',
						'engine',
						cast(trim('2014-10-20 14:41:50.158201+02') as timestamp),
						cast(trim('2014-10-20 14:41:50.211396+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3f254a4a85bf40f17bfc1c6ea4ef74de' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, custom_properties_regex, type, enabled, description) VALUES ('e659c871-0bf1-4ccc-b748-f28f5d08dffd', 'HA', true, NULL, 0, true, 'Runs the hosted engine VM only on hosts with a positive score');
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, custom_properties_regex, type, enabled, description) VALUES ('98e92667-6161-41fb-b3fa-34f820ccbc4b', 'HA', true, NULL, 1, true, 'Weights hosts according to their HA score');
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) VALUES ('20d25257-b4bd-4589-92a6-c4c5c5d3fd1a', 'e659c871-0bf1-4ccc-b748-f28f5d08dffd', 0, 0);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) VALUES ('5a2b0939-7d46-4b73-a469-e9c2c7fc6a53', 'e659c871-0bf1-4ccc-b748-f28f5d08dffd', 0, 0);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) VALUES ('b4ed2332-a7ac-4d5f-9596-99a439cb2812', 'e659c871-0bf1-4ccc-b748-f28f5d08dffd', 0, 0);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) VALUES ('20d25257-b4bd-4589-92a6-c4c5c5d3fd1a', '98e92667-6161-41fb-b3fa-34f820ccbc4b', 0, 1);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) VALUES ('5a2b0939-7d46-4b73-a469-e9c2c7fc6a53', '98e92667-6161-41fb-b3fa-34f820ccbc4b', 0, 1);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) VALUES ('b4ed2332-a7ac-4d5f-9596-99a439cb2812', '98e92667-6161-41fb-b3fa-34f820ccbc4b', 0, 1);
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040040'),
						'upgrade/03_04_0040_add_ha_policy_units.sql',
						'3f254a4a85bf40f17bfc1c6ea4ef74de',
						'engine',
						cast(trim('2014-10-20 14:41:50.236795+02') as timestamp),
						cast(trim('2014-10-20 14:41:50.339959+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3977c2b068b9d22d903f7a0925406e37' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vm_static set os = 5 where os = 100;
**************************

UPDATE 0
********* QUERY **********
update vm_static set os = 1 where os = 200;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040050'),
						'upgrade/03_04_0050_move_rename_of_other_linux_type.sql',
						'3977c2b068b9d22d903f7a0925406e37',
						'engine',
						cast(trim('2014-10-20 14:41:50.361228+02') as timestamp),
						cast(trim('2014-10-20 14:41:50.431523+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'c9786a3a67d5ffa23f14cb45be3168d2' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_device', 'snapshot_id', 'UUID REFERENCES SNAPSHOTS(snapshot_id) ON DELETE CASCADE DEFAULT NULL');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040060'),
						'upgrade/03_04_0060_add_snapshot_id_column_to_vm_device.sql',
						'c9786a3a67d5ffa23f14cb45be3168d2',
						'engine',
						cast(trim('2014-10-20 14:41:50.460619+02') as timestamp),
						cast(trim('2014-10-20 14:41:50.495564+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '0190b94f2e7a07126c36c28fcc6359f6' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE INDEX idx_network_external_id ON network(provider_network_external_id) WHERE provider_network_external_id IS NOT NULL;
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040070'),
						'upgrade/03_04_0070_index_network_by_external_id.sql',
						'0190b94f2e7a07126c36c28fcc6359f6',
						'engine',
						cast(trim('2014-10-20 14:41:50.538384+02') as timestamp),
						cast(trim('2014-10-20 14:41:50.585404+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '2e8edf8df1b23008e2840c909e91ec7d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_BRICK_STATUS_CHANGED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040080'),
						'upgrade/03_04_0080_add_brick_status_change_event_map.sql',
						'2e8edf8df1b23008e2840c909e91ec7d',
						'engine',
						cast(trim('2014-10-20 14:41:50.603487+02') as timestamp),
						cast(trim('2014-10-20 14:41:50.637269+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'a9da543d11997e2458bb47b99ff73a58' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE OR REPLACE FUNCTION __temp_move_quota_id() RETURNS void
AS $FUNCTION$
BEGIN
  IF (NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name ILIKE 'image_storage_domain_map' AND column_name ILIKE 'quota_id')) THEN
    -- add quota id column to the image-storage map table
    PERFORM fn_db_add_column('image_storage_domain_map','quota_id', 'UUID NULL');
    -- copy old quota from images table
    UPDATE image_storage_domain_map SET quota_id = (SELECT quota_id FROM images WHERE image_id = image_guid);
    -- create a FK to quota table to that column
    ALTER TABLE image_storage_domain_map ADD CONSTRAINT fk_image_storage_domain_map_quota FOREIGN KEY (quota_id) REFERENCES quota(id) ON DELETE SET NULL;
    -- remove quota_id column from images table
    PERFORM fn_db_drop_column ('images', 'quota_id');
END IF;
END; $FUNCTION$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT  __temp_move_quota_id();
**************************

 

********* QUERY **********
DROP FUNCTION __temp_move_quota_id();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040090'),
						'upgrade/03_04_0090_move_quota_id.sql',
						'a9da543d11997e2458bb47b99ff73a58',
						'engine',
						cast(trim('2014-10-20 14:41:50.683513+02') as timestamp),
						cast(trim('2014-10-20 14:41:50.799426+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'b3e0f09287c328e5f77b4675878158a3' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_add_host_permissions_to_gluster_admin_role()
RETURNS VOID
   AS $procedure$
   DECLARE
      v_GLUSTER_ADMIN_ROLE_ID UUID;
BEGIN
      v_GLUSTER_ADMIN_ROLE_ID := 'DEF0000b-0000-0000-0000-DEF00000000b';

--CREATE_CLUSTER
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, 400
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=400);

--EDIT_CLUSTER_CONFIGURATION
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, 401
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=401);

--DELETE_CLUSTER
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, 402
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=402);

--CONFIGURE_CLUSTER_NETWORK
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, 403
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=403);

--ASSIGN_CLUSTER_NETWORK
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, 404
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=404);

--CREATE_HOST
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, 100
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=100);

--EDIT_HOST_CONFIGURATION
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, 101
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=101);

--DELETE_HOST
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, 102
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=102);

--MANIPULATE_HOST
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, 103
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=103);

--CONFIGURE_HOST_NETWORK
INSERT INTO roles_groups(role_id,action_group_id) SELECT v_GLUSTER_ADMIN_ROLE_ID, 104
WHERE not exists (SELECT role_id, action_group_id FROM roles_groups
        WHERE role_id=v_GLUSTER_ADMIN_ROLE_ID and action_group_id=104);

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp_add_host_permissions_to_gluster_admin_role();
**************************

 

********* QUERY **********
drop function __temp_add_host_permissions_to_gluster_admin_role();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040100'),
						'upgrade/03_04_0100_add_cluster_host_permissions_to_gluster_admin_role.sql',
						'b3e0f09287c328e5f77b4675878158a3',
						'engine',
						cast(trim('2014-10-20 14:41:50.817497+02') as timestamp),
						cast(trim('2014-10-20 14:41:50.88714+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3dea9bd8eff3161611809d8098113344' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040110'),
						'upgrade/03_04_0110_change_policy_names.sql',
						'3dea9bd8eff3161611809d8098113344',
						'engine',
						cast(trim('2014-10-20 14:41:50.932045+02') as timestamp),
						cast(trim('2014-10-20 14:41:50.981692+02') as timestamp),
						'SKIPPED',
						false,
						'Installed already by 03030950'
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '92cfbf51b3c7ec8b7237174dafe81a27' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_dynamic', 'gluster_version', 'varchar(4000)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040120'),
						'upgrade/03_04_0120_add_gluster_version_to_vds_dynamic.sql',
						'92cfbf51b3c7ec8b7237174dafe81a27',
						'engine',
						cast(trim('2014-10-20 14:41:51.011956+02') as timestamp),
						cast(trim('2014-10-20 14:41:51.047803+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '37e6eaabbc3266ff3c83f8aed1d3258b' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
DROP INDEX if exists IDX_job_start_time;
**************************

DROP INDEX
********* QUERY **********
CREATE INDEX IDX_job_start_time ON job(start_time);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040130'),
						'upgrade/03_04_0130_add_start_time_idx_job.sql',
						'37e6eaabbc3266ff3c83f8aed1d3258b',
						'engine',
						cast(trim('2014-10-20 14:41:51.088828+02') as timestamp),
						cast(trim('2014-10-20 14:41:51.145201+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e1a08bba589ea13cc0408f619813ac6a' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'sso_method', 'VARCHAR(32) NOT NULL DEFAULT ''guest_agent''');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040140'),
						'upgrade/03_04_0140_add_sso_method_to_vm_static.sql',
						'e1a08bba589ea13cc0408f619813ac6a',
						'engine',
						cast(trim('2014-10-20 14:41:51.169401+02') as timestamp),
						cast(trim('2014-10-20 14:41:51.326826+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e9d8210d28a0de4fe945732a2a81fe64' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REBALANCE_FINISHED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_MIGRATE_BRICK_DATA_FINISHED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040150'),
						'upgrade/03_04_0150_gluster_async_tasks_finished_event_map.sql',
						'e9d8210d28a0de4fe945732a2a81fe64',
						'engine',
						cast(trim('2014-10-20 14:41:51.368303+02') as timestamp),
						cast(trim('2014-10-20 14:41:51.40447+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '07093445ebe47847f6849a6b25ffbdeb' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_insert_read_only_admin_role()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_ROLE_ID UUID;
BEGIN
   v_ROLE_ID := 'DEF0000C-0000-0000-0000-DEF00000000C';

DELETE FROM roles_groups WHERE role_id = v_ROLE_ID;
INSERT INTO roles(id,name,description,is_readonly,role_type,allows_viewing_children,app_mode) SELECT v_ROLE_ID, 'ReadOnlyAdmin', 'Read Only Administrator Role', true, 1, true, 1
WHERE NOT EXISTS (SELECT id,name,description,is_readonly,role_type
                  FROM roles
                  WHERE id = v_ROLE_ID
                  AND name='ReadOnlyAdmin'
                  AND description='Read Only Administrator Role'
                  AND is_readonly=true
                  AND role_type=1);

-- Allowing this role to login
INSERT INTO roles_groups(role_id,action_group_id) VALUES(v_ROLE_ID, 1300);

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_insert_read_only_admin_role();
**************************

 

********* QUERY **********
DROP function __temp_insert_read_only_admin_role();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040160'),
						'upgrade/03_04_0160_create_read_only_admin_role.sql',
						'07093445ebe47847f6849a6b25ffbdeb',
						'engine',
						cast(trim('2014-10-20 14:41:51.427447+02') as timestamp),
						cast(trim('2014-10-20 14:41:51.479103+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '0926c4fc405221786acc97eb50e9c2c1' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_groups', 'architecture', 'INTEGER  NOT NULL DEFAULT 0');
**************************

 

********* QUERY **********
UPDATE vds_groups SET architecture = 1 where cpu_name is not NULL and architecture = 0;
**************************

UPDATE 0
********* QUERY **********
UPDATE vds_groups AS c SET architecture = 1 WHERE c.cpu_name is null and exists (select 1 from vm_static where vm_static.vds_group_id = c.vds_group_id and vm_static.vm_guid != '00000000-0000-0000-0000-000000000000');
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040170'),
						'upgrade/03_04_0170_add_architecture_name_column.sql',
						'0926c4fc405221786acc97eb50e9c2c1',
						'engine',
						cast(trim('2014-10-20 14:41:51.497224+02') as timestamp),
						cast(trim('2014-10-20 14:41:51.646579+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '28661ac96b720f6b002774695b833607' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_groups', 'optimization_type', 'smallint default 0');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040180'),
						'upgrade/03_04_0180_add_vds_group_optimization_field.sql',
						'28661ac96b720f6b002774695b833607',
						'engine',
						cast(trim('2014-10-20 14:41:51.688486+02') as timestamp),
						cast(trim('2014-10-20 14:41:51.76951+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3ebfb0d2f0e35b190a8f1f1b4609ae9f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REMOVE_BRICKS_STOP', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REMOVE_BRICKS_STOP_FAILED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040190'),
						'upgrade/03_04_0190_gluster_async_tasks_stop_remove-brick_event_map.sql',
						'3ebfb0d2f0e35b190a8f1f1b4609ae9f',
						'engine',
						cast(trim('2014-10-20 14:41:51.787772+02') as timestamp),
						cast(trim('2014-10-20 14:41:51.840557+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '0f399f7c05ca20c59ee991367f9b103c' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REBALANCE_START_DETECTED_FROM_CLI', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('START_REMOVING_GLUSTER_VOLUME_BRICKS_DETECTED_FROM_CLI', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040200'),
						'upgrade/03_04_0200_gluster_async_tasks_fromcli_event_map.sql',
						'0f399f7c05ca20c59ee991367f9b103c',
						'engine',
						cast(trim('2014-10-20 14:41:51.887122+02') as timestamp),
						cast(trim('2014-10-20 14:41:51.978198+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ae8fd303c8c87051c514b0d12616591a' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE storage_domain_static SET storage_type = 0 WHERE storage_type = -1;
**************************

UPDATE 0
********* QUERY **********
UPDATE storage_pool SET storage_pool_type = 0 WHERE storage_pool_type = -1;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040210'),
						'upgrade/03_04_0210_replace_storage_type_all_with_unknown.sql',
						'ae8fd303c8c87051c514b0d12616591a',
						'engine',
						cast(trim('2014-10-20 14:41:52.024615+02') as timestamp),
						cast(trim('2014-10-20 14:41:52.104777+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '1929e483fac20e769027989048620c55' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('VM_CONSOLE_CONNECTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('VM_CONSOLE_DISCONNECTED', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('VM_SET_TICKET', '');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040220'),
						'upgrade/03_04_0220_add_console_events.sql',
						'1929e483fac20e769027989048620c55',
						'engine',
						cast(trim('2014-10-20 14:41:52.148152+02') as timestamp),
						cast(trim('2014-10-20 14:41:52.199188+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '7c6181c01c67e1f099f9b19dba982d51' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('VM_DOWN_ERROR', '');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('VDS_INITIATED_RUN_VM_FAIL', '');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040230'),
						'upgrade/03_04_0230_vm_down_error_and_vds_initiated_run_fail_event_map.sql',
						'7c6181c01c67e1f099f9b19dba982d51',
						'engine',
						cast(trim('2014-10-20 14:41:52.245758+02') as timestamp),
						cast(trim('2014-10-20 14:41:52.329203+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'b278b951715db212dbf8d0c9ea312aef' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_REBALANCE_NOT_FOUND_FROM_CLI', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('REMOVE_GLUSTER_VOLUME_BRICKS_NOT_FOUND_FROM_CLI', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040240'),
						'upgrade/03_04_0240_gluster_async_tasks_notfound_fromcli_event_map.sql',
						'b278b951715db212dbf8d0c9ea312aef',
						'engine',
						cast(trim('2014-10-20 14:41:52.34749+02') as timestamp),
						cast(trim('2014-10-20 14:41:52.399546+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'be0fd40be801a2ebffcf029e356a2500' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
alter table users add column active boolean not null default false;
**************************

ALTER TABLE
********* QUERY **********
update users set active = status::boolean;
**************************

UPDATE 1
********* QUERY **********
alter table users drop column status;
**************************

ALTER TABLE
********* QUERY **********
alter table ad_groups add column active boolean not null default false;
**************************

ALTER TABLE
********* QUERY **********
update ad_groups set active = status::boolean;
**************************

UPDATE 1
********* QUERY **********
alter table ad_groups drop column status;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040250'),
						'upgrade/03_04_0250_rename_user_and_group_status_to_active.sql',
						'be0fd40be801a2ebffcf029e356a2500',
						'engine',
						cast(trim('2014-10-20 14:41:52.439172+02') as timestamp),
						cast(trim('2014-10-20 14:41:52.63914+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '8a5004294554af4d4930ae73075e5302' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
alter table ad_groups add column external_id bytea not null default '';
**************************

ALTER TABLE
********* QUERY **********
update ad_groups set external_id = decode(replace(id::text, '-', ''), 'hex');
**************************

UPDATE 1
********* QUERY **********
select fn_db_create_constraint('ad_groups', 'groups_domain_external_id_unique', 'unique (domain, external_id)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040260'),
						'upgrade/03_04_0260_add_external_id_to_groups.sql',
						'8a5004294554af4d4930ae73075e5302',
						'engine',
						cast(trim('2014-10-20 14:41:52.657523+02') as timestamp),
						cast(trim('2014-10-20 14:41:52.77226+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '2413e4ae02d943619a0a8a91d9c6b970' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE INDEX IDX_gluster_bricks_task_id ON gluster_volume_bricks(task_id);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040270'),
						'upgrade/03_04_0270_add_task_id_idx_gluster_bricks.sql',
						'2413e4ae02d943619a0a8a91d9c6b970',
						'engine',
						cast(trim('2014-10-20 14:41:52.790962+02') as timestamp),
						cast(trim('2014-10-20 14:41:52.848468+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'c3ebb0eeb63fa4a066ef3f6a6e5ded8e' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'original_template_id', 'UUID default null');
**************************

 

********* QUERY **********
select fn_db_add_column('vm_static', 'original_template_name', 'VARCHAR(255) default null');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040280'),
						'upgrade/03_04_0280_add_original_template_to_vm_static.sql',
						'c3ebb0eeb63fa4a066ef3f6a6e5ded8e',
						'engine',
						cast(trim('2014-10-20 14:41:52.866461+02') as timestamp),
						cast(trim('2014-10-20 14:41:53.037192+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'd760094f81a4819b019e89e48cb03971' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_groups', 'spice_proxy', 'varchar(255)');
**************************

 

********* QUERY **********
select fn_db_add_column('vm_pools', 'spice_proxy', 'varchar(255)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040290'),
						'upgrade/03_04_0290_add_spice_proxy_to_vds_groups_and_vm_pools.sql',
						'd760094f81a4819b019e89e48cb03971',
						'engine',
						cast(trim('2014-10-20 14:41:53.086194+02') as timestamp),
						cast(trim('2014-10-20 14:41:53.188628+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3c77e70807009c3aa5d0f015c806a2da' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('network', 'label', 'text');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040300'),
						'upgrade/03_04_0300_add_label_column_to_networks.sql',
						'3c77e70807009c3aa5d0f015c806a2da',
						'engine',
						cast(trim('2014-10-20 14:41:53.236967+02') as timestamp),
						cast(trim('2014-10-20 14:41:53.328104+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '6ae3a6405c257409eaea6785380a32c6' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_interface', 'labels', 'text');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040310'),
						'upgrade/03_04_0310_add_labels_column_to_vds_interfaces.sql',
						'6ae3a6405c257409eaea6785380a32c6',
						'engine',
						cast(trim('2014-10-20 14:41:53.347532+02') as timestamp),
						cast(trim('2014-10-20 14:41:53.39486+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '95fe97ead68a20188cdd60aba6db219b' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_statistics','anonymous_hugepages', 'INTEGER NULL');
**************************

 

********* QUERY **********
UPDATE vds_statistics vs SET anonymous_hugepages = (SELECT anonymous_hugepages FROM vds_dynamic vd WHERE vs.vds_id = vd.vds_id);
**************************

UPDATE 0
********* QUERY **********
select fn_db_drop_column ('vds_dynamic', 'anonymous_hugepages');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040320'),
						'upgrade/03_04_0320_move_anonymousHugePages.sql',
						'95fe97ead68a20188cdd60aba6db219b',
						'engine',
						cast(trim('2014-10-20 14:41:53.437793+02') as timestamp),
						cast(trim('2014-10-20 14:41:53.490164+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '6f98be3b8fb3d715ecf9ff8f1747fcbb' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE OR REPLACE FUNCTION __temp_add_admin_operations_action_groups()
  RETURNS void AS
$BODY$
   DECLARE
      v_roles_to_filter_out uuid[];
      v_TAG_MANAGER_ROLE_ID uuid;
      v_BOOKMARK_MANAGER_ROLE_ID uuid;
      v_EVENT_NOTIFICATION_MANAGER_ROLE_ID uuid;
BEGIN
   v_TAG_MANAGER_ROLE_ID := 'DEF00011-0000-0000-0000-DEF000000013';
   v_BOOKMARK_MANAGER_ROLE_ID := 'DEF00011-0000-0000-0000-DEF000000014';
   v_EVENT_NOTIFICATION_MANAGER_ROLE_ID := 'DEF00011-0000-0000-0000-DEF000000015';

   -- We only add these action groups to ADMIN roles that have an action group that isn't the login permissions one
   v_roles_to_filter_out := array(select id from roles where role_type = 2 or (exists (select * from roles_groups where role_id = id) and not exists (select * from roles_groups where role_id = id and action_group_id != 1300)));

   -- Adding the TAG_MANAGEMENT action group
   perform fn_db_grant_action_group_to_all_roles_filter(1301, v_roles_to_filter_out);

   -- Adding the BOOKMARK_MANAGEMENT action group
   perform fn_db_grant_action_group_to_all_roles_filter(1302, v_roles_to_filter_out);

   -- Adding the EVENT_NOTIFICATION_MANAGEMENT action group
   perform fn_db_grant_action_group_to_all_roles_filter(1303, v_roles_to_filter_out);

   -- Adding the TagManager role
   DELETE FROM roles_groups WHERE role_id = v_TAG_MANAGER_ROLE_ID;

   INSERT INTO roles(id, name, description, is_readonly, role_type, allows_viewing_children, app_mode) SELECT v_TAG_MANAGER_ROLE_ID, 'TagManager', 'Tag Manager', true, 1, false, 255
   WHERE NOT EXISTS (SELECT id
                     FROM roles
                     WHERE id = v_TAG_MANAGER_ROLE_ID);

   INSERT INTO roles_groups values(v_TAG_MANAGER_ROLE_ID, 1301);
   INSERT INTO roles_groups values(v_TAG_MANAGER_ROLE_ID, 1300);

   -- Adding the BookmarkManager role
   DELETE FROM roles_groups WHERE role_id = v_BOOKMARK_MANAGER_ROLE_ID;

   INSERT INTO roles(id, name, description, is_readonly, role_type, allows_viewing_children, app_mode) SELECT v_BOOKMARK_MANAGER_ROLE_ID, 'BookmarkManager', 'Bookmark Manager', true, 1, false, 255
   WHERE NOT EXISTS (SELECT id
                     FROM roles
                     WHERE id = v_BOOKMARK_MANAGER_ROLE_ID);

   INSERT INTO roles_groups values(v_BOOKMARK_MANAGER_ROLE_ID, 1302);
   INSERT INTO roles_groups values(v_BOOKMARK_MANAGER_ROLE_ID, 1300);

   -- Adding the EventNotificationManager role
   DELETE FROM roles_groups WHERE role_id = v_EVENT_NOTIFICATION_MANAGER_ROLE_ID;

   INSERT INTO roles(id, name, description, is_readonly, role_type, allows_viewing_children, app_mode) SELECT v_EVENT_NOTIFICATION_MANAGER_ROLE_ID, 'EventNotificationManager', 'Event Notification Manager', true, 1, false, 255
   WHERE NOT EXISTS (SELECT id
                     FROM roles
                     WHERE id = v_EVENT_NOTIFICATION_MANAGER_ROLE_ID);

   INSERT INTO roles_groups values(v_EVENT_NOTIFICATION_MANAGER_ROLE_ID, 1303);
   INSERT INTO roles_groups values(v_EVENT_NOTIFICATION_MANAGER_ROLE_ID, 1300);

END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp_add_admin_operations_action_groups();
**************************

 

********* QUERY **********
drop function __temp_add_admin_operations_action_groups();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040330'),
						'upgrade/03_04_0330_add_admin_operations_action_groups_and_roles.sql',
						'6f98be3b8fb3d715ecf9ff8f1747fcbb',
						'engine',
						cast(trim('2014-10-20 14:41:53.536954+02') as timestamp),
						cast(trim('2014-10-20 14:41:53.628216+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ff56ce3cf88976e4c561dfb7e48355c7' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_add_action_groups_of_network_labels_03_04_0340()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_SUPER_USER_ID_0001 UUID;
   v_DATA_CENTER_ADMIN_ID UUID;
   v_NETWORK_ADMIN_ID UUID;
   v_HOST_ADMIN_ID UUID;

BEGIN
   v_SUPER_USER_ID_0001 := '00000000-0000-0000-0000-000000000001';
   v_DATA_CENTER_ADMIN_ID := 'DEF00002-0000-0000-0000-DEF000000002';
   v_NETWORK_ADMIN_ID := 'DEF00005-0000-0000-0000-DEF000000005';
   v_HOST_ADMIN_ID := 'DEF00004-0000-0000-0000-DEF000000004';

------------------------------------------------
--- Update existing roles with new Action Groups
------------------------------------------------

-- Action 163: LabelNetwork
-- Action 164: UnlabelNetwork
-- Action 165: LabelNic
-- Action 166: UnlabelNic

-------------------------
--- Update SuperUser role
-------------------------
PERFORM fn_db_add_action_group_to_role(v_SUPER_USER_ID_0001, 163);
PERFORM fn_db_add_action_group_to_role(v_SUPER_USER_ID_0001, 164);
PERFORM fn_db_add_action_group_to_role(v_SUPER_USER_ID_0001, 165);
PERFORM fn_db_add_action_group_to_role(v_SUPER_USER_ID_0001, 166);

--------------------------------
-- UPDATE DATA_CENTER_ADMIN role
--------------------------------
PERFORM fn_db_add_action_group_to_role(v_DATA_CENTER_ADMIN_ID, 163);
PERFORM fn_db_add_action_group_to_role(v_DATA_CENTER_ADMIN_ID, 164);
PERFORM fn_db_add_action_group_to_role(v_DATA_CENTER_ADMIN_ID, 165);
PERFORM fn_db_add_action_group_to_role(v_DATA_CENTER_ADMIN_ID, 166);

----------------------------
-- UPDATE NETWORK_ADMIN role
----------------------------
PERFORM fn_db_add_action_group_to_role(v_NETWORK_ADMIN_ID, 163);
PERFORM fn_db_add_action_group_to_role(v_NETWORK_ADMIN_ID, 164);
PERFORM fn_db_add_action_group_to_role(v_NETWORK_ADMIN_ID, 165);
PERFORM fn_db_add_action_group_to_role(v_NETWORK_ADMIN_ID, 166);

----------------------------
-- UPDATE HOST_ADMIN role
----------------------------
PERFORM fn_db_add_action_group_to_role(v_HOST_ADMIN_ID, 165);
PERFORM fn_db_add_action_group_to_role(v_HOST_ADMIN_ID, 166);


 RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_add_action_groups_of_network_labels_03_04_0340();
**************************

 

********* QUERY **********
DROP function __temp_add_action_groups_of_network_labels_03_04_0340();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040340'),
						'upgrade/03_04_0340_add_network_labels_action_groups.sql',
						'ff56ce3cf88976e4c561dfb7e48355c7',
						'engine',
						cast(trim('2014-10-20 14:41:53.648981+02') as timestamp),
						cast(trim('2014-10-20 14:41:53.718453+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '9c587817ecc1e175598d3271b8d91754' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
ALTER TABLE network_qos
      ALTER COLUMN name DROP NOT NULL,
      ALTER COLUMN storage_pool_id DROP NOT NULL;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040350'),
						'upgrade/03_04_0350_relax_network_qos_constraints.sql',
						'9c587817ecc1e175598d3271b8d91754',
						'engine',
						cast(trim('2014-10-20 14:41:53.766288+02') as timestamp),
						cast(trim('2014-10-20 14:41:53.846768+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '32d659cbbc415a5b63c5569d7bed3d29' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('network', 'qos_id', 'UUID');
**************************

 

********* QUERY **********
SELECT fn_db_create_constraint('network', 'fk_network_qos_id', 'FOREIGN KEY (qos_id) REFERENCES network_qos(id) ON DELETE SET NULL');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040360'),
						'upgrade/03_04_0360_add_qos_id_to_network.sql',
						'32d659cbbc415a5b63c5569d7bed3d29',
						'engine',
						cast(trim('2014-10-20 14:41:53.896331+02') as timestamp),
						cast(trim('2014-10-20 14:41:53.978222+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'a6aeeee79f2617c01517a98ad7396cf0' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vds_interface', 'qos_overridden', 'boolean NOT NULL DEFAULT false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040370'),
						'upgrade/03_04_0370_add_qos_overridden_to_vds_interface.sql',
						'a6aeeee79f2617c01517a98ad7396cf0',
						'engine',
						cast(trim('2014-10-20 14:41:54.026341+02') as timestamp),
						cast(trim('2014-10-20 14:41:54.178846+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '762ce9adc03d468b90fbbd3502636903' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_dynamic', 'last_stop_time', 'timestamp with time zone');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040380'),
						'upgrade/03_04_0380_add_last_stop_time_to_vm_dynamic.sql',
						'762ce9adc03d468b90fbbd3502636903',
						'engine',
						cast(trim('2014-10-20 14:41:54.207802+02') as timestamp),
						cast(trim('2014-10-20 14:41:54.297838+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '580aee7c34801bd4f6005217487ff11a' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_groups', 'ha_reservation', 'boolean not null default false');
**************************

 

********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, custom_properties_regex, type, description) VALUES ('7f262d70-6cac-11e3-981f-0800200c9a66', 'OptimalForHaReservation', true, '{
  "ScaleDown" : "(100|[1-9]|[1-9][0-9])$"
}', 1, 'Weights hosts according to their HA score regardless of hosted engine');
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) SELECT cluster_policies.id, '7f262d70-6cac-11e3-981f-0800200c9a66', 0, 1 FROM cluster_policies;
**************************

INSERT 0 3
********* QUERY **********
INSERT INTO event_map(event_up_name, event_down_name) VALUES ('CLUSTER_ALERT_HA_RESERVATION', '');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040390'),
						'upgrade/03_04_0390_add_ha_reservation.sql',
						'580aee7c34801bd4f6005217487ff11a',
						'engine',
						cast(trim('2014-10-20 14:41:54.345681+02') as timestamp),
						cast(trim('2014-10-20 14:41:54.506569+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '1c8df49d692499c49de73e9f055a260a' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO dwh_history_timekeeping(var_name,var_value) SELECT 'DwhCurrentlyRunning','0' WHERE not exists (SELECT 1 FROM dwh_history_timekeeping WHERE var_name = 'DwhCurrentlyRunning');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040400'),
						'upgrade/03_04_0400_add_var_on_dwh_status.sql',
						'1c8df49d692499c49de73e9f055a260a',
						'engine',
						cast(trim('2014-10-20 14:41:54.528392+02') as timestamp),
						cast(trim('2014-10-20 14:41:54.607949+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'f7310beca6b3baef6084b68b3e205b31' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, type, enabled, custom_properties_regex, description) VALUES
('d58c8e32-44e1-418f-9222-52cd887bf9e0', 'OptimalForEvenGuestDistribution', true, 2, true,
'{
  "HighVmCount" : "^([0-9][0-9]*)$",
  "MigrationThreshold" : "^([5-9][0-9]*)$",
  "SpmVmGrace":"^([5-9][0-9]*)$"
}',
 'Even VM count distribution policy'
);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policies (id, name, description, is_locked, is_default, custom_properties) VALUES (
'8d5d7bec-68de-4a67-b53e-0ac54686d579','VM_Evenly_Distributed', '', true, false,
'{
  "HighVmCount" : "10",
  "MigrationThreshold" : "5",
  "SpmVmGrace" : "5"
}');
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor) VALUES ('8d5d7bec-68de-4a67-b53e-0ac54686d579', 'd58c8e32-44e1-418f-9222-52cd887bf9e0', 0, 1);
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040410'),
						'upgrade/03_04_0410_add_even_guest_distribution_policy.sql',
						'f7310beca6b3baef6084b68b3e205b31',
						'engine',
						cast(trim('2014-10-20 14:41:54.632959+02') as timestamp),
						cast(trim('2014-10-20 14:41:54.738421+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '33552acdb8c1ad56e946ce96db476358' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_static', 'disable_auto_pm', 'BOOLEAN default false');
**************************

 

********* QUERY **********
select fn_db_add_column('vds_dynamic', 'controlled_by_pm_policy', 'BOOLEAN default false');
**************************

 

********* QUERY **********
UPDATE vds_dynamic set controlled_by_pm_policy=true WHERE status=3;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040420'),
						'upgrade/03_04_0420_add_vds_pm_flags.sql',
						'33552acdb8c1ad56e946ce96db476358',
						'engine',
						cast(trim('2014-10-20 14:41:54.757498+02') as timestamp),
						cast(trim('2014-10-20 14:41:54.988316+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '5446d0003b4e2cb6e50f4ca8b7d54b10' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE policy_units SET custom_properties_regex='{
  "CpuOverCommitDurationMinutes" : "^([1-9])$",
  "HighUtilization" : "^([5-9][0-9])$",
  "LowUtilization" : "^([1-4][0-9])$",
  "HostsInReserve": "^[0-9][0-9]*$",
  "EnableAutomaticHostPowerManagement": "^(true|false)$"
}' WHERE id='736999d0-1023-46a4-9a75-1316ed50e151';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040430'),
						'upgrade/03_04_0430_add_power_management_to_cluster_policy.sql',
						'5446d0003b4e2cb6e50f4ca8b7d54b10',
						'engine',
						cast(trim('2014-10-20 14:41:55.008193+02') as timestamp),
						cast(trim('2014-10-20 14:41:55.050386+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '08e3b932bfd35de5096ed2a8246c8f2d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE affinity_groups
(
    id UUID NOT NULL CONSTRAINT affinity_group_pk PRIMARY KEY,
    name VARCHAR(128) NOT NULL,
    description VARCHAR(4000),
    cluster_id UUID NOT NULL CONSTRAINT affinity_group_cluster_id_fk REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE,
    positive BOOLEAN NOT NULL DEFAULT TRUE,
    enforcing BOOLEAN NOT NULL DEFAULT TRUE,
    _create_date TIMESTAMP WITH TIME ZONE default LOCALTIMESTAMP,
    _update_date TIMESTAMP WITH TIME ZONE default NULL
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
CREATE INDEX IDX_affinity_group_cluster_id ON affinity_groups(cluster_id);
**************************

CREATE INDEX
********* QUERY **********
CREATE TABLE affinity_group_members
(
    affinity_group_id UUID NOT NULL CONSTRAINT affinity_group_member_affinity_id_fk REFERENCES affinity_groups(id) ON DELETE CASCADE,
    vm_id UUID NOT NULL CONSTRAINT affinity_group_member_vm_id_fk REFERENCES vm_static(vm_guid) ON DELETE CASCADE
);
**************************

CREATE TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040440'),
						'upgrade/03_04_0440_create_affinity_group_tables.sql',
						'08e3b932bfd35de5096ed2a8246c8f2d',
						'engine',
						cast(trim('2014-10-20 14:41:55.097312+02') as timestamp),
						cast(trim('2014-10-20 14:41:55.24031+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3974d01f629e099d0c0d11553ccd9eff' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO roles_groups(role_id,action_group_id) VALUES('00000000-0000-0000-0000-000000000001', 1550);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO roles_groups(role_id,action_group_id) VALUES('DEF00002-0000-0000-0000-DEF000000002', 1550);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO roles_groups(role_id,action_group_id) VALUES('DEF00001-0000-0000-0000-DEF000000001', 1550);
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040450'),
						'upgrade/03_04_0450_add_affinity_group_action_group.sql',
						'3974d01f629e099d0c0d11553ccd9eff',
						'engine',
						cast(trim('2014-10-20 14:41:55.289301+02') as timestamp),
						cast(trim('2014-10-20 14:41:55.395325+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '32ab3909c5cba69324ca2d5020b05def' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO policy_units(id, name, is_internal, custom_properties_regex, type, enabled, description)
VALUES ('84e6ddee-ab0d-42dd-82f0-c297779db566', 'VmAffinityGroups', TRUE, NULL, 0, true, 'Enables Affinity Groups hard enforcement for VMs; VMs in group are required to run either on the same hypervisor host (positive) or on independent hypervisor hosts (negative)');
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor)
SELECT cluster_policies.id, '84e6ddee-ab0d-42dd-82f0-c297779db566', 0, 0
FROM cluster_policies;
**************************

INSERT 0 4
********* QUERY **********
INSERT INTO policy_units(id, name, is_internal, custom_properties_regex, type, enabled, description)
VALUES ('84e6ddee-ab0d-42dd-82f0-c297779db567', 'VmAffinityGroups', TRUE, NULL, 1, true, 'Enables Affinity Groups soft enforcement for VMs; VMs in group are most likely to run either on the same hypervisor host (positive) or on independent hypervisor hosts (negative)');
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor)
SELECT cluster_policies.id, '84e6ddee-ab0d-42dd-82f0-c297779db567', 0, 1
FROM cluster_policies;
**************************

INSERT 0 4
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040460'),
						'upgrade/03_04_0460_add_affinity_group_filter_and_weight.sql',
						'32ab3909c5cba69324ca2d5020b05def',
						'engine',
						cast(trim('2014-10-20 14:41:55.438299+02') as timestamp),
						cast(trim('2014-10-20 14:41:55.508014+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e747bf9f65d2bec76e6574707b6e231a' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into action_version_map values (6, '3.4', '*');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040470'),
						'upgrade/03_04_0470_add_reboot_command.sql',
						'e747bf9f65d2bec76e6574707b6e231a',
						'engine',
						cast(trim('2014-10-20 14:41:55.528812+02') as timestamp),
						cast(trim('2014-10-20 14:41:55.562919+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ac1b7518d2b142a8173a09d7361dfe55' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'migration_downtime', 'integer default null');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040480'),
						'upgrade/03_04_0480_add_vm_migration_downtime.sql',
						'ac1b7518d2b142a8173a09d7361dfe55',
						'engine',
						cast(trim('2014-10-20 14:41:55.594442+02') as timestamp),
						cast(trim('2014-10-20 14:41:55.667556+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '7a4596c214f991867bb865b1ffe8feaf' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_groups', 'enable_ksm', 'boolean not null default true');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040490'),
						'upgrade/03_04_0490_add_enable_ksm_to_vds_groups.sql',
						'7a4596c214f991867bb865b1ffe8feaf',
						'engine',
						cast(trim('2014-10-20 14:41:55.694563+02') as timestamp),
						cast(trim('2014-10-20 14:41:55.825215+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '773d220ff630d81a237b47a124553922' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE iscsi_bonds
(
   id UUID NOT NULL,
   name varchar(50) NOT NULL,
   description varchar(4000),
   storage_pool_id UUID NOT NULL,
   CONSTRAINT PK_iscsi_bonds PRIMARY KEY(id),
   CONSTRAINT FK_iscsi_bonds_storage_pool FOREIGN KEY(storage_pool_id)
       REFERENCES storage_pool(id) ON DELETE CASCADE
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE iscsi_bonds_networks_map
(
   iscsi_bond_id UUID NOT NULL,
   network_id UUID NOT NULL,
   CONSTRAINT PK_iscsi_bonds_networks_map PRIMARY KEY(iscsi_bond_id,network_id),
   CONSTRAINT FK_iscsi_bonds_networks_map_iscsi_bond_id FOREIGN KEY(iscsi_bond_id)
       REFERENCES iscsi_bonds(id) ON DELETE CASCADE,
   CONSTRAINT FK_iscsi_bonds_networks_map_network_id FOREIGN KEY(network_id)
       REFERENCES network(id) ON DELETE CASCADE
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE iscsi_bonds_storage_connections_map
(
   iscsi_bond_id UUID NOT NULL,
   connection_id varchar(50) NOT NULL,
   CONSTRAINT PK_iscsi_bonds_storage_connections_map PRIMARY KEY(iscsi_bond_id,connection_id),
   CONSTRAINT FK_iscsi_bonds_storage_connections_map_iscsi_bond_id FOREIGN KEY(iscsi_bond_id)
       REFERENCES iscsi_bonds(id) ON DELETE CASCADE,
   CONSTRAINT FK_iscsi_bonds_storage_connections_map_connection_id FOREIGN KEY(connection_id)
       REFERENCES storage_server_connections(id) ON DELETE CASCADE
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040500'),
						'upgrade/03_04_0500_add_iscsi_bond.sql',
						'773d220ff630d81a237b47a124553922',
						'engine',
						cast(trim('2014-10-20 14:41:55.85114+02') as timestamp),
						cast(trim('2014-10-20 14:41:56.069183+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ad0d2f486704100ec927a59b93c83d56' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vds_static set pm_proxy_preferences = 'cluster,dc' where pm_enabled and pm_proxy_preferences = '';
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040510'),
						'upgrade/03_04_0510_set_proxy_preferences_default.sql',
						'ad0d2f486704100ec927a59b93c83d56',
						'engine',
						cast(trim('2014-10-20 14:41:56.090077+02') as timestamp),
						cast(trim('2014-10-20 14:41:56.132313+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '6499e09b35627d7485bf490a698567af' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE gluster_volume_details
(
    volume_id UUID NOT NULL REFERENCES gluster_volumes(id) ON DELETE CASCADE,
    total_space BIGINT,
    used_space BIGINT,
    free_space BIGINT,
    _update_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT LOCALTIMESTAMP,
    CONSTRAINT pk_gluster_volume_details PRIMARY KEY(volume_id)
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
CREATE TABLE gluster_volume_brick_details
(
    brick_id UUID NOT NULL REFERENCES gluster_volume_bricks(id) ON DELETE CASCADE,
    total_space BIGINT,
    used_space BIGINT,
    free_space BIGINT,
    _update_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT LOCALTIMESTAMP,
    CONSTRAINT pk_gluster_volume_brick_details PRIMARY KEY(brick_id)
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040520'),
						'upgrade/03_04_0520_add_tables_for_gluster_volume_and_brick_details.sql',
						'6499e09b35627d7485bf490a698567af',
						'engine',
						cast(trim('2014-10-20 14:41:56.163945+02') as timestamp),
						cast(trim('2014-10-20 14:41:56.267196+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '5fe6824a23f2b10bc8d1f5aa0904d680' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_DETAILS_REFRESH', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_DETAILS_REFRESH_FAILED', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040530'),
						'upgrade/03_04_0530_gluster_refresh_gluster_volume_details-event_map.sql',
						'5fe6824a23f2b10bc8d1f5aa0904d680',
						'engine',
						cast(trim('2014-10-20 14:41:56.314971+02') as timestamp),
						cast(trim('2014-10-20 14:41:56.408786+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e18b821a82850843c41f0481052521be' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('storage_pool', 'is_local', 'boolean');
**************************

 

********* QUERY **********
create or replace function __temp_update_storage_domain_is_local() returns void
as $function$
begin
	if (exists (select 1 from information_schema.columns where table_name ilike 'storage_pool' and column_name ilike 'storage_pool_type')) then
		update storage_pool set is_local = (storage_pool_type=4);
	end if;
end; $function$
language plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp_update_storage_domain_is_local();
**************************

 

********* QUERY **********
drop function __temp_update_storage_domain_is_local();
**************************

DROP FUNCTION
********* QUERY **********
ALTER TABLE storage_pool ALTER COLUMN storage_pool_type DROP NOT NULL;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040540'),
						'upgrade/03_04_0540_remove_storage_pool_type.sql',
						'e18b821a82850843c41f0481052521be',
						'engine',
						cast(trim('2014-10-20 14:41:56.430084+02') as timestamp),
						cast(trim('2014-10-20 14:41:56.520208+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '1015cf2947a698c600297d39509706bc' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'template_version_number', 'INTEGER DEFAULT NULL');
**************************

 

********* QUERY **********
select fn_db_add_column('vm_static', 'template_version_name', 'varchar(40) DEFAULT NULL');
**************************

 

********* QUERY **********
update vm_static set template_version_number=1;
**************************

UPDATE 1
********* QUERY **********
update vm_static set vmt_guid = vm_guid where entity_type='TEMPLATE';
**************************

UPDATE 1
********* QUERY **********
update vm_static set template_version_name = 'base version' where entity_type='TEMPLATE';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040550'),
						'upgrade/03_04_0550_add_template_version_to_vm_static.sql',
						'1015cf2947a698c600297d39509706bc',
						'engine',
						cast(trim('2014-10-20 14:41:56.565198+02') as timestamp),
						cast(trim('2014-10-20 14:41:56.757926+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '8625b7d0e4695c7244c47aca2166fbb4' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE vm_init
(
    vm_id UUID NOT NULL,
    host_name TEXT DEFAULT NULL,
    domain TEXT DEFAULT NULL,
    authorized_keys TEXT DEFAULT NULL,
    regenerate_keys BOOLEAN DEFAULT FALSE,
    time_zone VARCHAR(40) DEFAULT NULL,
    dns_servers TEXT DEFAULT NULL,
    dns_search_domains TEXT DEFAULT NULL,
    networks TEXT DEFAULT NULL,
    password TEXT DEFAULT NULL,
    winkey VARCHAR(30) DEFAULT NULL,
    custom_script TEXT DEFAULT NULL,
    CONSTRAINT pk_vm_init PRIMARY KEY (vm_id),
    CONSTRAINT vm_static_vm_init FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
INSERT into vm_init (vm_id, domain, time_zone) SELECT
vm_guid, domain, time_zone from vm_static
WHERE domain is NOT null OR time_zone is NOT null;
**************************

INSERT 18307 1
********* QUERY **********
ALTER TABLE vm_static DROP COLUMN domain CASCADE;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040560'),
						'upgrade/03_04_0560_add_vm_init_table.sql',
						'8625b7d0e4695c7244c47aca2166fbb4',
						'engine',
						cast(trim('2014-10-20 14:41:56.776223+02') as timestamp),
						cast(trim('2014-10-20 14:41:56.919645+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '71629cc4cdc710a72475f547ae78eaf5' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO policy_units (id, name, is_internal, type, enabled, custom_properties_regex, description) VALUES
('3ba8c988-f779-42c0-90ce-caa8243edee7', 'OptimalForEvenGuestDistribution', true, 1, true, NULL,
 'Weights host according the number of running VMs');
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor)
VALUES ('8d5d7bec-68de-4a67-b53e-0ac54686d579', '3ba8c988-f779-42c0-90ce-caa8243edee7', 0, 1);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor)
VALUES ('8d5d7bec-68de-4a67-b53e-0ac54686d579', '12262ab6-9690-4bc3-a2b3-35573b172d54', -1, 0);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor)
VALUES ('8d5d7bec-68de-4a67-b53e-0ac54686d579', '72163d1c-9468-4480-99d9-0888664eb143', 1, 0);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor)
SELECT '8d5d7bec-68de-4a67-b53e-0ac54686d579', policy_units.id, 0, 1 FROM policy_units
WHERE not exists (SELECT id FROM cluster_policy_units
                        WHERE cluster_policy_id = '8d5d7bec-68de-4a67-b53e-0ac54686d579'
                        AND policy_unit_id = policy_units.id)
AND policy_units.type = 0
AND policy_units.is_internal = true;
**************************

INSERT 0 4
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor)
VALUES ('8d5d7bec-68de-4a67-b53e-0ac54686d579', '7f262d70-6cac-11e3-981f-0800200c9a66', 0, 1);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, filter_sequence, factor)
VALUES ('8d5d7bec-68de-4a67-b53e-0ac54686d579', '98e92667-6161-41fb-b3fa-34f820ccbc4b', 0, 1);
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040570'),
						'upgrade/03_04_0570_add_all_basic_filters_to_even_guest_policy.sql',
						'71629cc4cdc710a72475f547ae78eaf5',
						'engine',
						cast(trim('2014-10-20 14:41:56.938034+02') as timestamp),
						cast(trim('2014-10-20 14:41:57.039037+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ce1f90457eb1bed1f085b4af30185071' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('VDS_INITIATED_RUN_VM_FAILED', '');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040580'),
						'upgrade/03_04_0580_add_restart_different_host_event.sql',
						'ce1f90457eb1bed1f085b4af30185071',
						'engine',
						cast(trim('2014-10-20 14:41:57.057382+02') as timestamp),
						cast(trim('2014-10-20 14:41:57.12914+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'd646eb15f4d2bb2148dbd40a433da2e7' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_change_column_type('storage_server_connections','password','varchar','text');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040590'),
						'upgrade/03_04_0590_change_storage_server_connections_password_length.sql',
						'd646eb15f4d2bb2148dbd40a433da2e7',
						'engine',
						cast(trim('2014-10-20 14:41:57.14621+02') as timestamp),
						cast(trim('2014-10-20 14:41:57.269182+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '34b74bd1e459b34cc60d4e59f87c6219' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_dynamic', 'current_cd', 'varchar(4000) default null');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040600'),
						'upgrade/03_04_0600_add_current_cd_to_vm_dynamic.sql',
						'34b74bd1e459b34cc60d4e59f87c6219',
						'engine',
						cast(trim('2014-10-20 14:41:57.287907+02') as timestamp),
						cast(trim('2014-10-20 14:41:57.39095+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '821fb4b4f4b2471dc57ffd883dbc7ae8' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update event_map set event_down_name = 'VDS_DETECTED' where event_up_name='VDS_SET_NONOPERATIONAL';
**************************

UPDATE 1
********* QUERY **********
update event_map set event_down_name = 'VDS_DETECTED' where event_up_name='VDS_SET_NONOPERATIONAL_IFACE_DOWN';
**************************

UPDATE 1
********* QUERY **********
update event_map set event_down_name = 'VDS_DETECTED' where event_up_name='VDS_SET_NONOPERATIONAL_DOMAIN';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040610'),
						'upgrade/03_04_0610_map_vds_detected_to_event_map.sql',
						'821fb4b4f4b2471dc57ffd883dbc7ae8',
						'engine',
						cast(trim('2014-10-20 14:41:57.414477+02') as timestamp),
						cast(trim('2014-10-20 14:41:57.508403+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '0f766ba280012cc20b5d66355e59080f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update users set username = regexp_replace(username, '@.*', '');
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040620'),
						'upgrade/03_04_0620_remove_directory_suffix_from_login_name.sql',
						'0f766ba280012cc20b5d66355e59080f',
						'engine',
						cast(trim('2014-10-20 14:41:57.52686+02') as timestamp),
						cast(trim('2014-10-20 14:41:57.606889+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '0e58b30629213beaf97ab57da9a554a0' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE users SET last_admin_check_status=TRUE WHERE user_id = 'FDFC627C-D875-11E0-90F0-83DF133B58CC';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040630'),
						'upgrade/03_04_0630_fix_admin_internal_permissions.sql',
						'0e58b30629213beaf97ab57da9a554a0',
						'engine',
						cast(trim('2014-10-20 14:41:57.648624+02') as timestamp),
						cast(trim('2014-10-20 14:41:57.675035+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3954122943e15cafb5f3d9e679c01248' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE policy_units set custom_properties_regex =
'{
  "HighVmCount" : "^([0-9]|[1-9][0-9]+)$",
  "MigrationThreshold" : "^([2-9]|[1-9][0-9]+)$",
  "SpmVmGrace":"^([0-9]|[1-9][0-9]+)$"
}'
where id = 'd58c8e32-44e1-418f-9222-52cd887bf9e0';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03040640'),
						'upgrade/03_04_0640_fix_even_guest_distribution_parameters.sql',
						'3954122943e15cafb5f3d9e679c01248',
						'engine',
						cast(trim('2014-10-20 14:41:57.712399+02') as timestamp),
						cast(trim('2014-10-20 14:41:57.788271+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '6499e09b35627d7485bf490a698567af' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050010'),
						'upgrade/03_05_0010_add_tables_for_gluster_volume_and_brick_details.sql',
						'6499e09b35627d7485bf490a698567af',
						'engine',
						cast(trim('2014-10-20 14:41:57.806631+02') as timestamp),
						cast(trim('2014-10-20 14:41:57.851484+02') as timestamp),
						'SKIPPED',
						false,
						'Installed already by 03040520'
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '5fe6824a23f2b10bc8d1f5aa0904d680' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050020'),
						'upgrade/03_05_0020_gluster_refresh_gluster_volume_details-event_map.sql',
						'5fe6824a23f2b10bc8d1f5aa0904d680',
						'engine',
						cast(trim('2014-10-20 14:41:57.889641+02') as timestamp),
						cast(trim('2014-10-20 14:41:57.901728+02') as timestamp),
						'SKIPPED',
						false,
						'Installed already by 03040530'
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '07ce60c1d0de2764751fed166a01598a' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_statistics', 'ha_configured', 'BOOLEAN NOT NULL DEFAULT FALSE');
**************************

 

********* QUERY **********
select fn_db_add_column('vds_statistics', 'ha_active', 'BOOLEAN NOT NULL DEFAULT FALSE');
**************************

 

********* QUERY **********
select fn_db_add_column('vds_statistics', 'ha_global_maintenance', 'BOOLEAN NOT NULL DEFAULT FALSE');
**************************

 

********* QUERY **********
select fn_db_add_column('vds_statistics', 'ha_local_maintenance', 'BOOLEAN NOT NULL DEFAULT FALSE');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050030'),
						'upgrade/03_05_0030_add_ha_columns_to_vds_statistics.sql',
						'07ce60c1d0de2764751fed166a01598a',
						'engine',
						cast(trim('2014-10-20 14:41:57.927582+02') as timestamp),
						cast(trim('2014-10-20 14:41:58.149705+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ac2fd91283cbcdbb22c8d616ddddb0ff' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO event_map(event_up_name, event_down_name) values('USER_VDS_MAINTENANCE_MANUAL_HA', 'VDS_ACTIVATE');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050040'),
						'upgrade/03_05_0040_add_ha_maintenance_events.sql',
						'ac2fd91283cbcdbb22c8d616ddddb0ff',
						'engine',
						cast(trim('2014-10-20 14:41:58.168027+02') as timestamp),
						cast(trim('2014-10-20 14:41:58.210487+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'feabc7bc7bb7ff749f075be48538c92e' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
ALTER TABLE event_subscriber DROP CONSTRAINT fk_event_subscriber_event_notification_methods;
**************************

ALTER TABLE
********* QUERY **********
DROP TABLE event_notification_methods ;
**************************

DROP TABLE
********* QUERY **********
ALTER TABLE event_subscriber ADD COLUMN notification_method CHARACTER VARYING(32) DEFAULT 'EMAIL'
  CHECK (notification_method IN ('EMAIL', 'SNMP_TRAP'));
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE event_subscriber DROP CONSTRAINT pk_event_subscriber;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE event_subscriber
  ADD CONSTRAINT pk_event_subscriber PRIMARY KEY (subscriber_id, event_up_name, notification_method, tag_name);
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE event_subscriber DROP COLUMN method_id;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE event_subscriber ALTER notification_method SET NOT NULL;
**************************

ALTER TABLE
********* QUERY **********
UPDATE event_subscriber AS es
SET method_address = u.email
FROM event_subscriber AS es2
  INNER JOIN users u ON es2.subscriber_id = u.user_id
WHERE (es.method_address is NULL OR trim(both from es.method_address) = '');
**************************

UPDATE 0
********* QUERY **********
ALTER TABLE event_notification_hist DROP COLUMN subscriber_id;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050050'),
						'upgrade/03_05_0050_event_notification_methods.sql',
						'feabc7bc7bb7ff749f075be48538c92e',
						'engine',
						cast(trim('2014-10-20 14:41:58.256465+02') as timestamp),
						cast(trim('2014-10-20 14:41:58.458521+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '03ffe543a142f001053e3ffedd22aeae' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update event_map set event_down_name = 'VDS_DETECTED' where event_up_name='VDS_FAILURE';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050060'),
						'upgrade/03_05_0060_event_map_vds_failure.sql',
						'03ffe543a142f001053e3ffedd22aeae',
						'engine',
						cast(trim('2014-10-20 14:41:58.499078+02') as timestamp),
						cast(trim('2014-10-20 14:41:58.525846+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '8741793705486ebcf2fe913efbf643d4' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
ALTER TABLE event_subscriber RENAME COLUMN notification_method TO nmx;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE event_subscriber ADD COLUMN notification_method CHARACTER VARYING(32);
**************************

ALTER TABLE
********* QUERY **********
UPDATE event_subscriber SET notification_method = 'smtp' WHERE nmx = 'EMAIL';
**************************

UPDATE 0
********* QUERY **********
UPDATE event_subscriber SET notification_method = 'snmp' WHERE nmx = 'SNMP_TRAP';
**************************

UPDATE 0
********* QUERY **********
ALTER TABLE event_subscriber DROP COLUMN nmx;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE event_subscriber ADD CONSTRAINT event_subscriber_method_check CHECK (notification_method IN ('smtp', 'snmp'));
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050070'),
						'upgrade/03_05_0070_fix_event_notfication_method.sql',
						'8741793705486ebcf2fe913efbf643d4',
						'engine',
						cast(trim('2014-10-20 14:41:58.565223+02') as timestamp),
						cast(trim('2014-10-20 14:41:58.678373+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3f4dda75146e664754c932522c4bc6f9' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION _temp_add_missing_manipulate_users_permissions()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_ADD_USERS_AND_GROUPS_FROM_DIRECTORY INTEGER;
   v_MANIPULATE_PERMISSIONS INTEGER;
BEGIN
   v_ADD_USERS_AND_GROUPS_FROM_DIRECTORY = 503;
   v_MANIPULATE_PERMISSIONS = 502;
   INSERT INTO ROLES_GROUPS(role_id,action_group_id)
   SELECT rg.role_id, v_ADD_USERS_AND_GROUPS_FROM_DIRECTORY
   FROM ROLES_GROUPS rg
   WHERE
   action_group_id = v_MANIPULATE_PERMISSIONS
   AND NOT EXISTS (SELECT 1
                   FROM ROLES_GROUPS rg2
                   WHERE rg2.role_id = rg.role_id
                   AND action_group_id = v_ADD_USERS_AND_GROUPS_FROM_DIRECTORY);
   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT  _temp_add_missing_manipulate_users_permissions();
**************************

 

********* QUERY **********
drop function  _temp_add_missing_manipulate_users_permissions();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050080'),
						'upgrade/03_05_0080_add_missing_manipulate_users_permissions.sql',
						'3f4dda75146e664754c932522c4bc6f9',
						'engine',
						cast(trim('2014-10-20 14:41:58.723218+02') as timestamp),
						cast(trim('2014-10-20 14:41:58.819158+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e8e76c44aa9fdfc3c9b25614f8d985d5' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
DELETE FROM roles_groups WHERE action_group_id in (163, 164, 165, 166);
**************************

DELETE 14
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050090'),
						'upgrade/03_05_0090_delete_network_labels_action_groups.sql',
						'e8e76c44aa9fdfc3c9b25614f8d985d5',
						'engine',
						cast(trim('2014-10-20 14:41:58.837497+02') as timestamp),
						cast(trim('2014-10-20 14:41:58.881043+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'f6ee521065330a42df8480683e2d5691' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE policy_units set custom_properties_regex = '{
  "CpuOverCommitDurationMinutes" : "^([1-9][0-9]*)$",
  "HighUtilization" : "^([5-9][0-9])$",
  "LowUtilization" : "^([0-9]|[1-4][0-9])$"
}'
WHERE id = '736999d0-1023-46a4-9a75-1316ed50e151';
**************************

UPDATE 1
********* QUERY **********
UPDATE policy_units set custom_properties_regex = '{
  "CpuOverCommitDurationMinutes" : "^([1-9][0-9]*)$",
  "HighUtilization" : "^([5-9][0-9])$"
}'
WHERE id = '7db4ab05-81ab-42e8-868a-aee2df483ed2';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050100'),
						'upgrade/03_05_0100_allow_values_higher_9_for_cpuovercommit.sql',
						'f6ee521065330a42df8480683e2d5691',
						'engine',
						cast(trim('2014-10-20 14:41:58.911936+02') as timestamp),
						cast(trim('2014-10-20 14:41:58.957054+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'a8490b31e224dcafd3a2821bcd7c6979' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'serial_number_policy', 'smallint default null');
**************************

 

********* QUERY **********
select fn_db_add_column('vm_static', 'custom_serial_number', 'varchar(255) default null');
**************************

 

********* QUERY **********
select fn_db_add_column('vds_groups', 'serial_number_policy', 'smallint default null');
**************************

 

********* QUERY **********
select fn_db_add_column('vds_groups', 'custom_serial_number', 'varchar(255) default null');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050110'),
						'upgrade/03_05_0110_add_vm_serial_number_policy.sql',
						'a8490b31e224dcafd3a2821bcd7c6979',
						'engine',
						cast(trim('2014-10-20 14:41:59.00369+02') as timestamp),
						cast(trim('2014-10-20 14:41:59.238315+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'a4f0b99e7d82a7d9fd633df06d49927e' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE storage_domains_ovf_info
(
   storage_domain_id UUID REFERENCES storage_domain_static(id) ON DELETE CASCADE,
   status INTEGER DEFAULT 0,
   ovf_disk_id UUID PRIMARY KEY REFERENCES base_disks(disk_id) ON DELETE CASCADE,
   stored_ovfs_ids TEXT,
   last_updated TIMESTAMP WITH TIME ZONE
);
**************************

CREATE TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050120'),
						'upgrade/03_05_0120_add_storage_domain_ovf.sql',
						'a4f0b99e7d82a7d9fd633df06d49927e',
						'engine',
						cast(trim('2014-10-20 14:41:59.25725+02') as timestamp),
						cast(trim('2014-10-20 14:41:59.378931+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '50e5445fac0ab91cfb2a6050e26f96b2' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vm_ovf_generations', 'ovf_data', 'text');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050130'),
						'upgrade/03_05_0130_add_ovf_data_column.sql',
						'50e5445fac0ab91cfb2a6050e26f96b2',
						'engine',
						cast(trim('2014-10-20 14:41:59.396064+02') as timestamp),
						cast(trim('2014-10-20 14:41:59.490196+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '329b8ee3da59a0a14a621823effe4a3c' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_add_install_vds_upgrade_node_action_group_03_05_0140()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_SUPER_USER_ID_0001 UUID;
   v_DATA_CENTER_ADMIN_ID UUID;
   v_CLUSTER_ADMIN_ID UUID;

BEGIN
   v_SUPER_USER_ID_0001 := '00000000-0000-0000-0000-000000000001';
   v_DATA_CENTER_ADMIN_ID := 'DEF00002-0000-0000-0000-DEF000000002';
   v_CLUSTER_ADMIN_ID := 'DEF00001-0000-0000-0000-DEF000000001';

-------------------------
--- Update SuperUser role
-------------------------
PERFORM fn_db_add_action_group_to_role(v_SUPER_USER_ID_0001, 130);
PERFORM fn_db_add_action_group_to_role(v_SUPER_USER_ID_0001, 131);

--------------------------------
-- UPDATE DATA_CENTER_ADMIN role
--------------------------------
PERFORM fn_db_add_action_group_to_role(v_DATA_CENTER_ADMIN_ID, 130);
PERFORM fn_db_add_action_group_to_role(v_DATA_CENTER_ADMIN_ID, 131);

--------------------------------
-- UPDATE CLUSTER_ADMIN role
--------------------------------
PERFORM fn_db_add_action_group_to_role(v_CLUSTER_ADMIN_ID, 130);
PERFORM fn_db_add_action_group_to_role(v_CLUSTER_ADMIN_ID, 131);

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_add_install_vds_upgrade_node_action_group_03_05_0140();
**************************

 

********* QUERY **********
DROP function __temp_add_install_vds_upgrade_node_action_group_03_05_0140();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050140'),
						'upgrade/03_05_0140_add_install_vds_upgrade_ovirt_node_action_group.sql',
						'329b8ee3da59a0a14a621823effe4a3c',
						'engine',
						cast(trim('2014-10-20 14:41:59.510444+02') as timestamp),
						cast(trim('2014-10-20 14:41:59.569626+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e1af151d7f6dfa6c67297eba8be35e58' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_fix_user_vm_manager_role()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_VM_ADMIN_ID UUID;
BEGIN
   v_VM_ADMIN_ID := 'def00012-0000-0000-0000-def000000012';

-- Remove the import export vm action group from USER_VM_MANAGER role
DELETE FROM roles_groups
WHERE  role_id = v_VM_ADMIN_ID
AND    action_group_id = 8;

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_fix_user_vm_manager_role();
**************************

 

********* QUERY **********
DROP function __temp_fix_user_vm_manager_role();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050150'),
						'upgrade/03_05_0150_remove_import_export_permission_from_user_instance_manager_role.sql',
						'e1af151d7f6dfa6c67297eba8be35e58',
						'engine',
						cast(trim('2014-10-20 14:41:59.588134+02') as timestamp),
						cast(trim('2014-10-20 14:41:59.64888+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'fb885bc1c0048763375d6fa1ac9ea034' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
ALTER TABLE event_subscriber DROP CONSTRAINT fk_event_subscriber_event_map;
**************************

ALTER TABLE
********* QUERY **********
update event_subscriber set event_up_name = 'HOST_INTERFACE_HIGH_NETWORK_USE' where event_up_name='VDS_HIGH_NETWORK_USE';
**************************

UPDATE 0
********* QUERY **********
update event_map set event_up_name = 'HOST_INTERFACE_HIGH_NETWORK_USE' where event_up_name='VDS_HIGH_NETWORK_USE';
**************************

UPDATE 1
********* QUERY **********
ALTER TABLE event_subscriber ADD CONSTRAINT fk_event_subscriber_event_map FOREIGN KEY (event_up_name) REFERENCES event_map(event_up_name) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050160'),
						'upgrade/03_05_0160_add_host_interface_high_network_use_event.sql',
						'fb885bc1c0048763375d6fa1ac9ea034',
						'engine',
						cast(trim('2014-10-20 14:41:59.666853+02') as timestamp),
						cast(trim('2014-10-20 14:41:59.771269+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '6dad2d9d8cad07d6edebf575b8eb4735' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_statistics', 'boot_time', 'BIGINT');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050170'),
						'upgrade/03_05_0170_add_boot_time_to_vds_statistics.sql',
						'6dad2d9d8cad07d6edebf575b8eb4735',
						'engine',
						cast(trim('2014-10-20 14:41:59.812957+02') as timestamp),
						cast(trim('2014-10-20 14:41:59.897951+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '144f59f2832f9be70cf02631ea85074f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
alter table vm_init
add column input_locale VARCHAR(256) DEFAULT NULL,
add column ui_language VARCHAR(256) DEFAULT NULL,
add column system_locale VARCHAR(256) DEFAULT NULL,
add column user_locale VARCHAR(256) DEFAULT NULL;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050180'),
						'upgrade/03_05_0180_vm_init_add_sysprep_locale.sql',
						'144f59f2832f9be70cf02631ea85074f',
						'engine',
						cast(trim('2014-10-20 14:41:59.943289+02') as timestamp),
						cast(trim('2014-10-20 14:42:00.069096+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'b0ec8b51da128b6a5c035474cc78f54a' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
alter table vm_init
add column user_name VARCHAR(256) DEFAULT NULL;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050190'),
						'upgrade/03_05_0190_vm_init_add_user_name.sql',
						'b0ec8b51da128b6a5c035474cc78f54a',
						'engine',
						cast(trim('2014-10-20 14:42:00.087432+02') as timestamp),
						cast(trim('2014-10-20 14:42:00.179809+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '1443c55b4695947c44ca5286fb4b0edd' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
alter table vm_init
add column active_directory_ou VARCHAR(256) DEFAULT NULL;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050200'),
						'upgrade/03_05_0200_vm_init_add_active_directory_ou.sql',
						'1443c55b4695947c44ca5286fb4b0edd',
						'engine',
						cast(trim('2014-10-20 14:42:00.22617+02') as timestamp),
						cast(trim('2014-10-20 14:42:00.337682+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'b4d98e282a9d33cb5c03eaf0c7023c1c' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_change_group_ids_03_05_0210()
RETURNS VOID
   AS $procedure$
BEGIN


--If there is no external_id set at users, populate it with content based on the id
update ad_groups set external_id = decode(replace(CAST(id as text),'-',''),'HEX') where encode(external_id,'HEX') = '';


--groups.external_id holds a hex representation of the id of groups at ldap directories.
-- This script sets the guid representation at ad_groups.id, and modifies all relevant references,
--using the following steps:

--1. Adding temp column for mapping from old uuid to new uuid
PERFORM fn_db_add_column('ad_groups', 'temp_id', 'uuid');
--Filling the new column with guid repreentation of external_id
UPDATE ad_groups SET temp_id = CAST(substring(encode(external_id,'hex') FROM 1 FOR 8) || '-' ||
       substring(encode(external_id,'hex') FROM 9 FOR 4) || '-' ||
       substring(encode(external_id,'hex') FROM 13 FOR 4) || '-' ||
       substring(encode(external_id,'hex') FROM 17 FOR 4) || '-' ||
       substring(encode(external_id,'hex') FROM 21 FOR 12) AS uuid);

--2. Changing relevant group_id appearances in other tables
ALTER TABLE tags_user_group_map drop constraint tags_user_map_user_group;

UPDATE tags_user_group_map m set group_id = (
       SELECT temp_id FROM ad_groups WHERE id = m.group_id
);

UPDATE permissions p SET ad_element_id = (
       SELECT temp_id FROM ad_groups g1 WHERE g1.id = p.ad_element_id
) WHERE EXISTS (
       SELECT id from ad_groups where id =  p.ad_element_id
);

--3. Fixing group_ids at users
CREATE temp TABLE tmp_users_groups  ON COMMIT DROP AS
       SELECT fnsplitteruuid(group_ids) AS group_id, user_id FROM users;
UPDATE tmp_users_groups t SET group_id = (
       SELECT temp_id FROM ad_groups WHERE id = t.group_id
);
CREATE temp TABLE tmp_users_group_ids  ON COMMIT DROP AS
       SELECT user_id, array_to_string(array_agg(group_id), ',') group_ids FROM tmp_users_groups GROUP BY user_id;
UPDATE users u SET group_ids = (
        SELECT group_ids FROM tmp_users_group_ids WHERE user_id = u.user_id
);
UPDATE ad_groups SET id = temp_id;
--4. Cleanup
--DROP TABLE tmp_users_group_ids;
--DROP TABLE tmp_users_groups;
ALTER TABLE tags_user_group_map add constraint "tags_user_map_user_group" FOREIGN KEY (group_id) REFERENCES ad_groups(id);

PERFORM fn_db_drop_column('ad_groups','temp_id');
RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT  __temp_change_group_ids_03_05_0210();
**************************

 

********* QUERY **********
DROP FUNCTION __temp_change_group_ids_03_05_0210();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050210'),
						'upgrade/03_05_0210_change_group_ids.sql',
						'b4d98e282a9d33cb5c03eaf0c7023c1c',
						'engine',
						cast(trim('2014-10-20 14:42:00.356243+02') as timestamp),
						cast(trim('2014-10-20 14:42:00.46925+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '90af4811c4dab5add0b153416132dffa' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_update_user_ids_03_05_0220()
RETURNS VOID
   AS $procedure$
BEGIN

--If there is no external_id set at users, populate it with content based on the user_id
update users set external_id = decode(replace(CAST(user_id as text),'-',''),'HEX') where encode(external_id,'HEX') = '';

--users.external_id holds a hex representation of the id of users at ldap directories.
-- This script sets the guid representation at users.id, and modifies all relevant references,
--using the following steps:

--1. Adding temp column for mapping from old uuid to new uuid
PERFORM fn_db_add_column('users', 'temp_id', 'uuid');
--Filling the new column with guid repreentation of external_id
UPDATE users SET temp_id = CAST(substring(encode(external_id,'hex') FROM 1 FOR 8) || '-' ||
       substring(encode(external_id,'hex') FROM 9 FOR 4) || '-' ||
       substring(encode(external_id,'hex') FROM 13 FOR 4) || '-' ||
       substring(encode(external_id,'hex') FROM 17 FOR 4) || '-' ||
       substring(encode(external_id,'hex') FROM 21 FOR 12) AS uuid);

--2. Changing relevant group_id appearances in other tables
ALTER TABLE tags_user_map drop constraint "tags_user_map_user";
UPDATE tags_user_map m set user_id = (
       SELECT temp_id FROM users WHERE user_id = m.user_id);

UPDATE permissions p SET ad_element_id = (
       SELECT temp_id FROM users u1 WHERE u1.user_id = p.ad_element_id
) WHERE EXISTS (
       SELECT user_id from users where user_id =  p.ad_element_id
);

UPDATE users SET user_id = temp_id;
--3. Cleanup
ALTER TABLE tags_user_map add constraint "tags_user_map_user" FOREIGN KEY (user_id) REFERENCES users(user_id);
PERFORM fn_db_drop_column('users','temp_id');
RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT  __temp_update_user_ids_03_05_0220();
**************************

 

********* QUERY **********
DROP FUNCTION __temp_update_user_ids_03_05_0220();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050220'),
						'upgrade/03_05_0220_update_user_ids.sql',
						'90af4811c4dab5add0b153416132dffa',
						'engine',
						cast(trim('2014-10-20 14:42:00.490734+02') as timestamp),
						cast(trim('2014-10-20 14:42:00.608911+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '5954e2d839c458b31c8f636b98f5d060' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('HOST_INTERFACE_STATE_DOWN', 'HOST_INTERFACE_STATE_UP');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name) values('HOST_BOND_SLAVE_STATE_DOWN', 'HOST_BOND_SLAVE_STATE_UP');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050230'),
						'upgrade/03_05_0230_add_host_interface_status_change_events.sql',
						'5954e2d839c458b31c8f636b98f5d060',
						'engine',
						cast(trim('2014-10-20 14:42:00.627916+02') as timestamp),
						cast(trim('2014-10-20 14:42:00.709493+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '54aaca4624f1d747521f8539f90e2c85' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
ALTER TABLE users ALTER COLUMN external_id DROP DEFAULT;
**************************

ALTER TABLE
********* QUERY **********
SELECT fn_db_change_column_type('users', 'external_id', 'bytea', 'text');
**************************

 

********* QUERY **********
ALTER TABLE users ALTER COLUMN external_id SET NOT NULL;
**************************

ALTER TABLE
********* QUERY **********
ALTER TABLE ad_groups ALTER COLUMN external_id DROP DEFAULT;
**************************

ALTER TABLE
********* QUERY **********
SELECT fn_db_change_column_type('ad_groups', 'external_id', 'bytea', 'text');
**************************

 

********* QUERY **********
ALTER TABLE ad_groups ALTER COLUMN external_id SET NOT NULL;
**************************

ALTER TABLE
********* QUERY **********
UPDATE ad_groups SET external_id = CAST( id AS text );
**************************

UPDATE 1
********* QUERY **********
UPDATE users SET external_id = CAST (user_id as text );
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050240'),
						'upgrade/03_05_0240_change_external_id_to_string.sql',
						'54aaca4624f1d747521f8539f90e2c85',
						'engine',
						cast(trim('2014-10-20 14:42:00.731942+02') as timestamp),
						cast(trim('2014-10-20 14:42:01.008558+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '983a280ca928836dae0e0213291b6297' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_dynamic', 'reason', 'text');
**************************

 

********* QUERY **********
select fn_db_add_column('vds_groups', 'optional_reason', 'boolean not null default false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050250'),
						'upgrade/03_05_0250_add_reason_columns.sql',
						'983a280ca928836dae0e0213291b6297',
						'engine',
						cast(trim('2014-10-20 14:42:01.025788+02') as timestamp),
						cast(trim('2014-10-20 14:42:01.16981+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'f02ba42fd10e432ffe44931fc2f78a97' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_dynamic', 'exit_reason', 'integer default -1');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050260'),
						'upgrade/03_05_0260_add_exit_reason_to_vm_dynamic.sql',
						'f02ba42fd10e432ffe44931fc2f78a97',
						'engine',
						cast(trim('2014-10-20 14:42:01.217374+02') as timestamp),
						cast(trim('2014-10-20 14:42:01.368909+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'c906e895cbaa8f264b8b0da44bbeb2e9' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vm_static
set template_version_name=vm_name
where entity_type='TEMPLATE' and template_version_number>1 and
(template_version_name is null or template_version_name='');
**************************

UPDATE 0
********* QUERY **********
update vm_static vm1
set vm_name=
  (select vm2.vm_name from vm_static vm2
   where vm2.vm_guid = vm1.vmt_guid)
where entity_type='TEMPLATE' and template_version_number>1;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050270'),
						'upgrade/03_05_0270_update_template_version_naming.sql',
						'c906e895cbaa8f264b8b0da44bbeb2e9',
						'engine',
						cast(trim('2014-10-20 14:42:01.386139+02') as timestamp),
						cast(trim('2014-10-20 14:42:01.455951+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '29d9fe5782715d6aeabd322048a86ee7' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'is_boot_menu_enabled', 'boolean not null default false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050280'),
						'upgrade/03_05_0280_add_vm_boot_menu.sql',
						'29d9fe5782715d6aeabd322048a86ee7',
						'engine',
						cast(trim('2014-10-20 14:42:01.500739+02') as timestamp),
						cast(trim('2014-10-20 14:42:01.649136+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '433942876ca82605012225b8b097eb88' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
ALTER TABLE vm_static ALTER COLUMN vds_group_id DROP NOT NULL;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050290'),
						'upgrade/03_05_0290_drop_vds_group_id_constraint_from_vm_static.sql',
						'433942876ca82605012225b8b097eb88',
						'engine',
						cast(trim('2014-10-20 14:42:01.668344+02') as timestamp),
						cast(trim('2014-10-20 14:42:01.727357+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'd8dbe912f05981a9ff5d88ffda6d5eea' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vds_static', 'pm_detect_kdump', 'BOOLEAN NOT NULL DEFAULT FALSE');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050300'),
						'upgrade/03_05_0300_add_host_kdump_detection.sql',
						'd8dbe912f05981a9ff5d88ffda6d5eea',
						'engine',
						cast(trim('2014-10-20 14:42:01.773561+02') as timestamp),
						cast(trim('2014-10-20 14:42:01.938896+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'c3bd57e139de5736c3501c12f8aed196' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vds_dynamic', 'kdump_status', 'SMALLINT NOT NULL DEFAULT -1');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050310'),
						'upgrade/03_05_0310_add_host_kdump_status.sql',
						'c3bd57e139de5736c3501c12f8aed196',
						'engine',
						cast(trim('2014-10-20 14:42:01.961351+02') as timestamp),
						cast(trim('2014-10-20 14:42:02.097156+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '9c15a0ce8e92d4c022f6b7e6dad6cc6b' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vds_interface', 'custom_properties', 'text');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050320'),
						'upgrade/03_05_0320_add_vds_interface_custom_properties.sql',
						'9c15a0ce8e92d4c022f6b7e6dad6cc6b',
						'engine',
						cast(trim('2014-10-20 14:42:02.143387+02') as timestamp),
						cast(trim('2014-10-20 14:42:02.229163+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'cc65cd3924e0c064ff29af84b713138a' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE network
SET label=NULL
WHERE provider_network_external_id IS NOT NULL;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050330'),
						'upgrade/03_05_0330_nullify_external_network_labels.sql',
						'cc65cd3924e0c064ff29af84b713138a',
						'engine',
						cast(trim('2014-10-20 14:42:02.274083+02') as timestamp),
						cast(trim('2014-10-20 14:42:02.343302+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'dc3c7608e930f54f25087b1993ed6dfc' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_statistics', 'migration_progress_percent', 'integer default 0');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050340'),
						'upgrade/03_05_0340_add_migration_progress_percent_to_vm_dynamic.sql',
						'dc3c7608e930f54f25087b1993ed6dfc',
						'engine',
						cast(trim('2014-10-20 14:42:02.388673+02') as timestamp),
						cast(trim('2014-10-20 14:42:02.528826+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '6822029e2bbedfad5ed2376d59006be1' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
delete from event_map
where event_up_name in (
	'NETWORK_UPDATE_DISPLAY_FOR_CLUSTER_WITH_ACTIVE_VM',
	'NETWORK_UPDATE_DISPLAY_FOR_HOST_WITH_ACTIVE_VM');
**************************

DELETE 0
********* QUERY **********
insert into event_map(event_up_name, event_down_name)
values('NETWORK_UPDATE_DISPLAY_FOR_CLUSTER_WITH_ACTIVE_VM', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
insert into event_map(event_up_name, event_down_name)
values('NETWORK_UPDATE_DISPLAY_FOR_HOST_WITH_ACTIVE_VM', 'UNASSIGNED');
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050350'),
						'upgrade/03_05_0350_add_display_network_change_events.sql',
						'6822029e2bbedfad5ed2376d59006be1',
						'engine',
						cast(trim('2014-10-20 14:42:02.546986+02') as timestamp),
						cast(trim('2014-10-20 14:42:02.649524+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '0615b912497be6e07894ac7a404ee8d8' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE OR REPLACE FUNCTION __temp_add_audit_log_operation_action_groups()
  RETURNS void AS
$BODY$
   DECLARE
      v_roles_to_filter_out uuid[];
      v_AUDIT_LOG_MANAGER_ROLE_ID uuid;
BEGIN
   v_AUDIT_LOG_MANAGER_ROLE_ID := 'DEF00011-0000-0000-0000-DEF000000016';

   -- We only add these action groups to ADMIN roles that have an action group that isn't the login permissions one
   v_roles_to_filter_out := array(select id from roles where role_type = 2 or (exists (select * from roles_groups where role_id = id) and not exists (select * from roles_groups where role_id = id and action_group_id != 1300)));

   -- Adding the TAG_MANAGEMENT action group
   perform fn_db_grant_action_group_to_all_roles_filter(1304, v_roles_to_filter_out);

   -- Adding the TagManager role
   DELETE FROM roles_groups WHERE role_id = v_AUDIT_LOG_MANAGER_ROLE_ID;

   INSERT INTO roles(id, name, description, is_readonly, role_type, allows_viewing_children, app_mode) SELECT v_AUDIT_LOG_MANAGER_ROLE_ID, 'AuditLogManager', 'Audit Log Manager', true, 1, false, 255
   WHERE NOT EXISTS (SELECT id
                     FROM roles
                     WHERE id = v_AUDIT_LOG_MANAGER_ROLE_ID);

   INSERT INTO roles_groups values(v_AUDIT_LOG_MANAGER_ROLE_ID, 1304);
   INSERT INTO roles_groups values(v_AUDIT_LOG_MANAGER_ROLE_ID, 1300);

END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp_add_audit_log_operation_action_groups();
**************************

 

********* QUERY **********
drop function __temp_add_audit_log_operation_action_groups();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050360'),
						'upgrade/03_05_0360_add_audit_log_operation_action_group_and_roles.sql',
						'0615b912497be6e07894ac7a404ee8d8',
						'engine',
						cast(trim('2014-10-20 14:42:02.689239+02') as timestamp),
						cast(trim('2014-10-20 14:42:02.739243+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'df6555e62d3347bc2b5329f7aefc240f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_interface', 'base_interface', 'varchar(50)');
**************************

 

********* QUERY **********
update vds_interface set base_interface = substring(name from '(.*)\.[^\.]*') where vlan_id is not NULL;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050370'),
						'upgrade/03_05_0370_add_base_interface_column_to_vds_interfaces.sql',
						'df6555e62d3347bc2b5329f7aefc240f',
						'engine',
						cast(trim('2014-10-20 14:42:02.757247+02') as timestamp),
						cast(trim('2014-10-20 14:42:02.834856+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'a7970c56ead8ac50992e30c98043cc86' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE policy_units SET custom_properties_regex='{
  "CpuOverCommitDurationMinutes" : "^([1-9][0-9]*)$",
  "HighUtilization" : "^([5-9][0-9])$",
  "LowUtilization" : "^([0-9]|[1-4][0-9])$",
  "HostsInReserve": "^[0-9][0-9]*$",
  "EnableAutomaticHostPowerManagement": "^(true|false)$"
}' WHERE id='736999d0-1023-46a4-9a75-1316ed50e151';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050380'),
						'upgrade/03_05_0380_reintroduce_powersaving_variables.sql',
						'a7970c56ead8ac50992e30c98043cc86',
						'engine',
						cast(trim('2014-10-20 14:42:02.878731+02') as timestamp),
						cast(trim('2014-10-20 14:42:02.949786+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e49398055417067fab92b3613dda8a08' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_dynamic', 'guest_cpu_count', 'INTEGER');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050390'),
						'upgrade/03_05_0390_add_guest_cpu_count_to_vm_dynamic.sql',
						'e49398055417067fab92b3613dda8a08',
						'engine',
						cast(trim('2014-10-20 14:42:02.968237+02') as timestamp),
						cast(trim('2014-10-20 14:42:03.004093+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'f28cb0cc01fc0f0bc98b1d102966e377' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE INDEX IDX_snapshots_snapshot_type ON snapshots(snapshot_type);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050400'),
						'upgrade/03_05_0400_index_for_snapshot_type.sql',
						'f28cb0cc01fc0f0bc98b1d102966e377',
						'engine',
						cast(trim('2014-10-20 14:42:03.039271+02') as timestamp),
						cast(trim('2014-10-20 14:42:03.138251+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '9bfa1afc2a343117726d312a4cb0a213' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_dynamic', 'selinux_enforce_mode', 'INTEGER');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050410'),
						'upgrade/03_05_0410_add_selinux_to_vds_dynamic.sql',
						'9bfa1afc2a343117726d312a4cb0a213',
						'engine',
						cast(trim('2014-10-20 14:42:03.15673+02') as timestamp),
						cast(trim('2014-10-20 14:42:03.215814+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ff72604dccdf6469de8c50fa979f2156' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update providers
set agent_configuration = replace (agent_configuration, '"qpidConfiguration" : {', E'"messagingConfiguration" : {\n    "brokerType" : "QPID",');
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050420'),
						'upgrade/03_05_0420_generalize_messaging_broker_type.sql',
						'ff72604dccdf6469de8c50fa979f2156',
						'engine',
						cast(trim('2014-10-20 14:42:03.23444+02') as timestamp),
						cast(trim('2014-10-20 14:42:03.290637+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '10ac58bb1d43eab9a414aeb95e05b2dc' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_add_numa_tables() returns void
AS $procedure$
BEGIN
    -- Numa nodes table
    CREATE TABLE numa_node
    (
        numa_node_id UUID NOT NULL,
        vds_id UUID,
        vm_id UUID,
        numa_node_index SMALLINT,
        mem_total BIGINT,
        cpu_count SMALLINT,
        mem_free BIGINT,
        usage_mem_percent INTEGER,
        cpu_sys numeric(5,2),
        cpu_user numeric(5,2),
        cpu_idle numeric(5,2),
        usage_cpu_percent INTEGER,
        distance text,
        CONSTRAINT pk_numa_node PRIMARY KEY(numa_node_id),
        CONSTRAINT fk_numa_node_vds FOREIGN KEY(vds_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE,
        CONSTRAINT fk_numa_node_vm FOREIGN KEY(vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE
    );

    -- Create partial index for numa nodes
    CREATE INDEX IDX_numa_node_vds_id ON numa_node(vds_id);
    CREATE INDEX IDX_numa_node_vm_id ON numa_node(vm_id);

    -- Vds cpu statistics table
    CREATE TABLE vds_cpu_statistics
    (
        vds_cpu_id UUID NOT NULL,
        vds_id UUID NOT NULL,
        cpu_core_id SMALLINT,
        cpu_sys numeric(5,2),
        cpu_user numeric(5,2),
        cpu_idle numeric(5,2),
        usage_cpu_percent INTEGER,
        CONSTRAINT pk_vds_cpu_statistics PRIMARY KEY(vds_cpu_id),
        CONSTRAINT fk_vds_cpu_statistics_vds FOREIGN KEY(vds_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE
    );

    -- Create partial index for vds cpu statistics
    CREATE INDEX IDX_vds_cpu_statistics_vds_id ON vds_cpu_statistics(vds_id);

    -- Numa nodes internal connection table
    CREATE TABLE vm_vds_numa_node_map
    (
        id UUID NOT NULL,
        vm_numa_node_id UUID NOT NULL,
        vds_numa_node_id UUID,
        vds_numa_node_index SMALLINT,
        is_pinned BOOLEAN DEFAULT false NOT NULL,
        CONSTRAINT pk_vm_vds_numa_node_map PRIMARY KEY(id),
        CONSTRAINT fk_vm_vds_numa_node_map_vds_numa_node FOREIGN KEY(vds_numa_node_id) REFERENCES numa_node(numa_node_id) ON DELETE SET NULL,
        CONSTRAINT fk_vm_vds_numa_node_map_vm_numa_node FOREIGN KEY(vm_numa_node_id) REFERENCES numa_node(numa_node_id) ON DELETE CASCADE
    );

    -- Create partial index for numa node map
    CREATE INDEX IDX_vm_vds_numa_node_map_vm_numa_node_id ON vm_vds_numa_node_map(vm_numa_node_id);
    CREATE INDEX IDX_vm_vds_numa_node_map_vds_numa_node_id ON vm_vds_numa_node_map(vds_numa_node_id);

    -- Numa node cpus table
    CREATE TABLE numa_node_cpu_map
    (
        id UUID NOT NULL,
        numa_node_id UUID NOT NULL,
        cpu_core_id INTEGER,
        CONSTRAINT pk_numa_node_cpu_map PRIMARY KEY(id),
        CONSTRAINT fk_numa_node_cpu_map_numa_node FOREIGN KEY(numa_node_id) REFERENCES numa_node(numa_node_id) ON DELETE CASCADE
    );

    -- Create partial index for numa node cpu map
    CREATE INDEX IDX_numa_node_cpu_map_numa_node_id ON numa_node_cpu_map(numa_node_id);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp_add_numa_tables();
**************************

 

********* QUERY **********
drop function __temp_add_numa_tables();
**************************

DROP FUNCTION
********* QUERY **********
Create or replace FUNCTION __temp_add_numa_columns() returns void
AS $procedure$
BEGIN
    -- Add columns in table vm_static
    PERFORM fn_db_add_column('vm_static', 'numatune_mode', 'varchar(20)');

    -- Add columns in table vds_dynamic
    PERFORM fn_db_add_column('vds_dynamic', 'auto_numa_balancing', 'smallint');
    PERFORM fn_db_add_column('vds_dynamic', 'is_numa_supported', 'boolean');

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select __temp_add_numa_columns();
**************************

 

********* QUERY **********
drop function __temp_add_numa_columns();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050430'),
						'upgrade/03_05_0430_add_numa_tables_and_columns.sql',
						'10ac58bb1d43eab9a414aeb95e05b2dc',
						'engine',
						cast(trim('2014-10-20 14:42:03.321226+02') as timestamp),
						cast(trim('2014-10-20 14:42:03.657586+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '961f022fa17f16ef388681403d188c27' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('users', '_create_date', 'timestamp with time zone DEFAULT CURRENT_TIMESTAMP');
**************************

 

********* QUERY **********
SELECT fn_db_add_column('users', '_update_date', 'timestamp with time zone');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050440'),
						'upgrade/03_05_0440_add_create_and_update_dates_to_users_table.sql',
						'961f022fa17f16ef388681403d188c27',
						'engine',
						cast(trim('2014-10-20 14:42:03.675807+02') as timestamp),
						cast(trim('2014-10-20 14:42:03.78816+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '009e1ca1910dba5c3299f7070e561787' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vm_static set numatune_mode ='preferred';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050450'),
						'upgrade/03_05_0450_set_default_value_for_numa_tune_mode.sql',
						'009e1ca1910dba5c3299f7070e561787',
						'engine',
						cast(trim('2014-10-20 14:42:03.806964+02') as timestamp),
						cast(trim('2014-10-20 14:42:03.879155+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '4a249884378c2787d8d2d2d92c128aec' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE FUNCTION __temp_set_display_migration() RETURNS VOID AS $$
DECLARE
    mgmt_name CHARACTER VARYING(15);
BEGIN
    SELECT option_value
    FROM vdc_options
    WHERE option_name='ManagementNetwork'
    INTO mgmt_name;

    UPDATE network_cluster nc1
    SET is_display = true
    WHERE EXISTS (SELECT 1
                  FROM network
                  WHERE network.id = nc1.network_id AND name = mgmt_name)
        AND NOT EXISTS (SELECT 1
                        FROM network_cluster nc2
                        WHERE nc2.cluster_id = nc1.cluster_id AND nc2.is_display);

    UPDATE network_cluster nc1
    SET migration = true
    WHERE EXISTS (SELECT 1
                  FROM network
                  WHERE network.id = nc1.network_id AND name = mgmt_name)
        AND NOT EXISTS (SELECT 1
                        FROM network_cluster nc2
                        WHERE nc2.cluster_id = nc1.cluster_id AND nc2.migration);
END;
$$ LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_set_display_migration();
**************************

 

********* QUERY **********
DROP FUNCTION __temp_set_display_migration();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050460'),
						'upgrade/03_05_0460_set_display_migration_cluster_network.sql',
						'4a249884378c2787d8d2d2d92c128aec',
						'engine',
						cast(trim('2014-10-20 14:42:03.897237+02') as timestamp),
						cast(trim('2014-10-20 14:42:03.999135+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '5d3b6047971973fb9ac5143ff9fd4b21' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE vm_static as a
SET child_count =(SELECT COUNT(*) FROM vm_static as b WHERE a.vm_guid = b.vmt_guid and entity_type = 'VM');
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050470'),
						'upgrade/03_05_0470_update_vm_static_child_count.sql',
						'5d3b6047971973fb9ac5143ff9fd4b21',
						'engine',
						cast(trim('2014-10-20 14:42:04.017572+02') as timestamp),
						cast(trim('2014-10-20 14:42:04.060335+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '2a369ed5c06b4f5e9a1226f806446627' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
alter table vm_init
add column org_name VARCHAR(256) DEFAULT NULL;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050480'),
						'upgrade/03_05_0480_add_org_name_for_sysprep.sql',
						'2a369ed5c06b4f5e9a1226f806446627',
						'engine',
						cast(trim('2014-10-20 14:42:04.106468+02') as timestamp),
						cast(trim('2014-10-20 14:42:04.238613+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'c75aa917b43ee25f513fb14a9004ce87' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
delete from vm_device a
where device='smartcard'
    and device_id not in (
        select device_id from vm_device where vm_id=a.vm_id and device='smartcard' limit 1);
**************************

DELETE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050490'),
						'upgrade/03_05_0490_remove_duplicate_smartcards.sql',
						'c75aa917b43ee25f513fb14a9004ce87',
						'engine',
						cast(trim('2014-10-20 14:42:04.256974+02') as timestamp),
						cast(trim('2014-10-20 14:42:04.327391+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '09fd2bcc67e2c43b46cccaec37f9d138' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_groups', 'required_rng_sources', 'varchar(255)');
**************************

 

********* QUERY **********
UPDATE vds_groups SET required_rng_sources = 'RANDOM' WHERE cast(compatibility_version as float) >= 3.5;
**************************

UPDATE 1
********* QUERY **********
select fn_db_add_column('vds_dynamic', 'supported_rng_sources', 'varchar(255)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050500'),
						'upgrade/03_05_0500_add_rng_device_columns.sql',
						'09fd2bcc67e2c43b46cccaec37f9d138',
						'engine',
						cast(trim('2014-10-20 14:42:04.368768+02') as timestamp),
						cast(trim('2014-10-20 14:42:04.428256+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '62f334d941f846569109d1f209aa0bce' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE unregistered_ovf_of_entities
(
   entity_guid UUID,
   entity_name VARCHAR(255) NOT NULL,
   entity_type VARCHAR(32) NOT NULL,
   architecture INTEGER,
   lowest_comp_version VARCHAR(40),
   storage_domain_id UUID,
   ovf_data TEXT,
   ovf_extra_data TEXT,
   CONSTRAINT pk_entity_guid_storage_domain_unregistered PRIMARY KEY(entity_guid, storage_domain_id)
);
**************************

CREATE TABLE
********* QUERY **********
ALTER TABLE unregistered_ovf_of_entities add constraint fk_unregistered_ovf_of_entities_storage_domain FOREIGN KEY (storage_domain_id) REFERENCES storage_domain_static(id)  ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050510'),
						'upgrade/03_05_0510_unregistered_ovf_of_entities.sql',
						'62f334d941f846569109d1f209aa0bce',
						'engine',
						cast(trim('2014-10-20 14:42:04.446921+02') as timestamp),
						cast(trim('2014-10-20 14:42:04.568817+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '5e3107c4c71f37c16dfc0081764df9b3' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE policy_units SET description='Gives hosts with higher CPU usage, lower weight (means that hosts with higher CPU usage are more likely to be selected)' WHERE id = '736999d0-1023-46a4-9a75-1316ed50e15b';
**************************

UPDATE 1
********* QUERY **********
UPDATE policy_units SET description='Gives hosts with lower CPU usage, lower weight (means that hosts with lower CPU usage are more likely to be selected)' WHERE id = '7db4ab05-81ab-42e8-868a-aee2df483edb';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050520'),
						'upgrade/03_05_0520_fix_description_of_balancing_policy_units.sql',
						'5e3107c4c71f37c16dfc0081764df9b3',
						'engine',
						cast(trim('2014-10-20 14:42:04.585934+02') as timestamp),
						cast(trim('2014-10-20 14:42:04.668641+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'be5938c01964970ee44039d0b0e76f0f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
DELETE from event_map where event_up_name = 'VDS_INITIATED_RUN_VM_FAIL';
**************************

DELETE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050530'),
						'upgrade/03_05_0530_remove_unused_event.sql',
						'be5938c01964970ee44039d0b0e76f0f',
						'engine',
						cast(trim('2014-10-20 14:42:04.7091+02') as timestamp),
						cast(trim('2014-10-20 14:42:04.735865+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '035fa5f8fa411067c1877bf722c29728' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vm_static', 'is_spice_file_transfer_enabled', 'boolean not null default true');
**************************

 

********* QUERY **********
select fn_db_add_column('vm_static', 'is_spice_copy_paste_enabled', 'boolean not null default true');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050540'),
						'upgrade/03_05_0540_add_spice_transfer_toggle.sql',
						'035fa5f8fa411067c1877bf722c29728',
						'engine',
						cast(trim('2014-10-20 14:42:04.778727+02') as timestamp),
						cast(trim('2014-10-20 14:42:05.020419+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '0809aee6013689fcf6166329387aecc4' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_dynamic', 'is_live_snapshot_supported', 'boolean not null default true');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050550'),
						'upgrade/03_05_0550_add_live_snapshot_support.sql',
						'0809aee6013689fcf6166329387aecc4',
						'engine',
						cast(trim('2014-10-20 14:42:05.051901+02') as timestamp),
						cast(trim('2014-10-20 14:42:05.129552+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '7dccff60f90e12097d50dee8435ce031' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('users', 'namespace', 'varchar(2048) default ''*''');
**************************

 

********* QUERY **********
select fn_db_add_column('ad_groups', 'namespace', 'varchar(2048) default ''*''');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050560'),
						'upgrade/03_05_0560_aaa_add_namespace.sql',
						'7dccff60f90e12097d50dee8435ce031',
						'engine',
						cast(trim('2014-10-20 14:42:05.1549+02') as timestamp),
						cast(trim('2014-10-20 14:42:05.387413+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '95402941e8fb65a23c1be1711a45ef59' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE images
SET imagestatus = 4
FROM snapshots
WHERE images.vm_snapshot_id = snapshots.snapshot_id
AND snapshots.status = 'BROKEN';
**************************

UPDATE 0
********* QUERY **********
UPDATE snapshots
SET status = 'OK'
WHERE status = 'BROKEN';
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050570'),
						'upgrade/03_05_0570_deprecate_broken_snapshots.sql',
						'95402941e8fb65a23c1be1711a45ef59',
						'engine',
						cast(trim('2014-10-20 14:42:05.434437+02') as timestamp),
						cast(trim('2014-10-20 14:42:05.517275+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3c4293c1763fba7597382d13c16ee16c' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION do_insert_instance_type(v_name VARCHAR(255), v_description VARCHAR(4000), v_mem_size integer, v_num_of_sockets integer, v_cpu_per_socket integer) RETURNS VOID
   AS $procedure$
DECLARE
	v_instance_type_id UUID;
BEGIN
v_instance_type_id := uuid_generate_v1();

INSERT INTO vm_static
            (vm_guid,
             vm_name,
             mem_size_mb,
             vmt_guid,
             os,
             description,
             vds_group_id,
             creation_date,
             num_of_monitors,
             is_initialized,
             is_auto_suspend,
             num_of_sockets,
             cpu_per_socket,
             usb_policy,
             time_zone,
             is_stateless,
             fail_back,
             _create_date,
             _update_date,
             dedicated_vm_for_vds,
             auto_startup,
             vm_type,
             nice_level,
             default_boot_sequence,
             default_display_type,
             priority,
             iso_path,
             origin,
             initrd_url,
             kernel_url,
             kernel_params,
             migration_support,
             userdefined_properties,
             predefined_properties,
             min_allocated_mem,
             entity_type,
             child_count,
             template_status,
             quota_id,
             allow_console_reconnect,
             cpu_pinning,
             is_smartcard_enabled)
VALUES      (v_instance_type_id,
             v_name,
             v_mem_size,
             v_instance_type_id,
             0,
             v_description,
             NULL,
             '2014-05-05 00:00:00+03',
             1,
             NULL,
             false,
             v_num_of_sockets,
             v_cpu_per_socket,
             1,
             NULL,
             NULL,
             false,
             '2013-12-25 15:31:54.367179+02',
             '2013-12-25 15:31:53.239308+02',
             NULL,
             NULL,
             0,
             0,
             0,
             1,
             0,
             '',
             0,
             NULL,
             NULL,
             NULL,
             0,
             NULL,
             NULL,
             0,
             'INSTANCE_TYPE',
             0,
             0,
             NULL,
             false,
             NULL,
             false);

INSERT INTO permissions(id,
                         role_id,
                         ad_element_id,
                         object_id,
                         object_type_id)
	     SELECT uuid_generate_v1(),
             'DEF00009-0000-0000-0000-DEF000000009', -- UserTemplateBasedVm
             'EEE00000-0000-0000-0000-123456789EEE', -- Everyone
             v_instance_type_id,
             4 -- template
      ;

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION insert_default_instance_types() RETURNS VOID
   AS $procedure$

BEGIN

perform do_insert_instance_type('Tiny', 'Tiny instance type', 512, 1, 1);
perform do_insert_instance_type('Small', 'Small instance type', 2048, 1, 1);
perform do_insert_instance_type('Medium', 'Medium instance type', 4096, 1, 1);
perform do_insert_instance_type('Large', 'Large instance type', 8192, 2, 1);
perform do_insert_instance_type('XLarge', 'Extra Large instance type', 16384, 4, 1);

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
select insert_default_instance_types();
**************************

 

********* QUERY **********
drop function insert_default_instance_types();
**************************

DROP FUNCTION
********* QUERY **********
drop function do_insert_instance_type(v_name VARCHAR(255), v_description VARCHAR(4000), v_mem_size integer, v_num_of_sockets integer, v_cpu_per_socket integer);
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050580'),
						'upgrade/03_05_0580_add_default_instance_types.sql',
						'3c4293c1763fba7597382d13c16ee16c',
						'engine',
						cast(trim('2014-10-20 14:42:05.558833+02') as timestamp),
						cast(trim('2014-10-20 14:42:05.628911+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ad0205f7bbd76f7c3484a6e69a897ccd' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vm_static set time_zone=(select option_value from vdc_options where option_name = 'DefaultWindowsTimeZone') where time_zone is NULL and os in (select os_id from dwh_osinfo where os_name ilike '%windows%') and vm_guid != '00000000-0000-0000-0000-000000000000';
**************************

UPDATE 0
********* QUERY **********
update vm_static set time_zone=(select option_value from vdc_options where option_name = 'DefaultGeneralTimeZone') where time_zone is NULL and os not in (select os_id from dwh_osinfo where os_name ilike '%windows%') and vm_guid != '00000000-0000-0000-0000-000000000000';
**************************

UPDATE 5
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050590'),
						'upgrade/03_05_0590_set_default_time_zone.sql',
						'ad0205f7bbd76f7c3484a6e69a897ccd',
						'engine',
						cast(trim('2014-10-20 14:42:05.646225+02') as timestamp),
						cast(trim('2014-10-20 14:42:05.728189+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'afe0fd01716963b36635aa00117d3c9f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
ALTER TABLE images DROP CONSTRAINT image_templates_images;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050600'),
						'upgrade/03_05_0600_drop_images_fk.sql',
						'afe0fd01716963b36635aa00117d3c9f',
						'engine',
						cast(trim('2014-10-20 14:42:05.77493+02') as timestamp),
						cast(trim('2014-10-20 14:42:05.849025+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '9056f5e77325bee56f388b63e34267b2' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE command_entities
(
    command_id UUID NOT NULL,
    command_type integer NOT NULL,
    root_command_id UUID DEFAULT NULL,
    action_parameters text,
    action_parameters_class varchar(256),
    created_at TIMESTAMP WITH TIME ZONE,
    status varchar(20) DEFAULT NULL,
    CONSTRAINT pk_command_entities PRIMARY KEY(command_id)
);
**************************

CREATE TABLE
********* QUERY **********
CREATE INDEX idx_root_command_id ON command_entities(root_command_id) WHERE root_command_id IS NOT NULL;
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050610'),
						'upgrade/03_05_0610_add_command_entity_table.sql',
						'9056f5e77325bee56f388b63e34267b2',
						'engine',
						cast(trim('2014-10-20 14:42:05.867537+02') as timestamp),
						cast(trim('2014-10-20 14:42:05.973804+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '381323f5832d0ec6637866ec1caa5e7f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE cluster_policies SET name = 'evenly_distributed' WHERE name =  'Evenly_Distributed';
**************************

UPDATE 1
********* QUERY **********
UPDATE cluster_policies SET name = 'power_saving' WHERE name =  'Power_Saving';
**************************

UPDATE 1
********* QUERY **********
UPDATE cluster_policies SET name = 'none' WHERE name =  'None';
**************************

UPDATE 1
********* QUERY **********
UPDATE cluster_policies SET name = 'vm_evenly_distributed' WHERE name =  'VM_Evenly_Distributed';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050620'),
						'upgrade/03_05_0620_lowercase_default_cluster_policies_names.sql',
						'381323f5832d0ec6637866ec1caa5e7f',
						'engine',
						cast(trim('2014-10-20 14:42:05.993073+02') as timestamp),
						cast(trim('2014-10-20 14:42:06.058951+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '252d39ba56de127146bcaaeccb04ba3f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vds_static', 'protocol', 'SMALLINT NOT NULL DEFAULT 0');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050630'),
						'upgrade/03_05_0630_add_host_protocol.sql',
						'252d39ba56de127146bcaaeccb04ba3f',
						'engine',
						cast(trim('2014-10-20 14:42:06.105609+02') as timestamp),
						cast(trim('2014-10-20 14:42:06.256763+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'fcc7481bf4866042df9646cd16f4cde9' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE external_variable (
  var_name VARCHAR(100) NOT NULL,
  var_value VARCHAR(4000),
  _update_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT LOCALTIMESTAMP,
  CONSTRAINT pk_external_variable PRIMARY KEY(var_name)
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050640'),
						'upgrade/03_05_0640_add_external_variable.sql',
						'fcc7481bf4866042df9646cd16f4cde9',
						'engine',
						cast(trim('2014-10-20 14:42:06.274779+02') as timestamp),
						cast(trim('2014-10-20 14:42:06.340129+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3db84fa310408632f0848586bfae6df4' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE vds_kdump_status (
    vds_id UUID NOT NULL,
    status VARCHAR(20) NOT NULL,
    address VARCHAR(255) NOT NULL,
    CONSTRAINT pk_vds_kdump_status PRIMARY KEY(vds_id),
    CONSTRAINT fk_vds_kdump_status_vds_static
        FOREIGN KEY (vds_id) REFERENCES vds_static(vds_id) ON DELETE CASCADE
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
CREATE INDEX idx_vds_kdump_status_status ON vds_kdump_status(status);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050650'),
						'upgrade/03_05_0650_add_vds_kdump_status.sql',
						'3db84fa310408632f0848586bfae6df4',
						'engine',
						cast(trim('2014-10-20 14:42:06.363244+02') as timestamp),
						cast(trim('2014-10-20 14:42:06.504351+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '4f6a301feaebccb5e2a18c83052c48bb' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_drop_column ('async_tasks', 'action_parameters');
**************************

 

********* QUERY **********
select fn_db_drop_column ('async_tasks', 'action_params_class');
**************************

 

********* QUERY **********
select fn_db_drop_column ('async_tasks', 'root_command_id');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050660'),
						'upgrade/03_05_0660_remove_command_from_async_tasks.sql',
						'4f6a301feaebccb5e2a18c83052c48bb',
						'engine',
						cast(trim('2014-10-20 14:42:06.547832+02') as timestamp),
						cast(trim('2014-10-20 14:42:06.598985+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'cb407acaa7be3a278361036c225feb00' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('command_entities', 'callback_enabled', 'boolean default false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050670'),
						'upgrade/03_05_0670_add_cmd_entity_callback_enabled.sql',
						'cb407acaa7be3a278361036c225feb00',
						'engine',
						cast(trim('2014-10-20 14:42:06.616945+02') as timestamp),
						cast(trim('2014-10-20 14:42:06.768685+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '375dc0d8e71ce26aeb3b021ff2d33a3e' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('command_entities', 'callback_notified', 'boolean default false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050680'),
						'upgrade/03_05_0680_add_cmd_entity_callback_notified.sql',
						'375dc0d8e71ce26aeb3b021ff2d33a3e',
						'engine',
						cast(trim('2014-10-20 14:42:06.786638+02') as timestamp),
						cast(trim('2014-10-20 14:42:06.929571+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'c493140a6de6188ad213e7bf7d5d316f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('command_entities', 'return_value', 'text');
**************************

 

********* QUERY **********
select fn_db_add_column('command_entities', 'return_value_class', 'varchar(256)');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050690'),
						'upgrade/03_05_0690_add_cmd_entity_return_value.sql',
						'c493140a6de6188ad213e7bf7d5d316f',
						'engine',
						cast(trim('2014-10-20 14:42:06.947432+02') as timestamp),
						cast(trim('2014-10-20 14:42:06.998563+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '8b8f2782f0547867d6cdbc33e80687ac' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE vm_jobs
(
     vm_job_id UUID NOT NULL,
     vm_id UUID NOT NULL,
     job_state INTEGER DEFAULT 0 NOT NULL,
     job_type INTEGER NOT NULL,
     block_job_type INTEGER,
     bandwidth INTEGER,
     cursor_cur BIGINT,
     cursor_end BIGINT,
     image_group_id UUID,
     CONSTRAINT pk_vm_jobs PRIMARY KEY(vm_job_id)
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
CREATE INDEX IDX_vm_jobs_vm_id ON vm_jobs(vm_id);
**************************

CREATE INDEX
********* QUERY **********
ALTER TABLE ONLY vm_jobs
    ADD CONSTRAINT fk_vm_jobs_vm_static FOREIGN KEY (vm_id) REFERENCES vm_static(vm_guid) ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050700'),
						'upgrade/03_05_0700_create_vm_jobs_table.sql',
						'8b8f2782f0547867d6cdbc33e80687ac',
						'engine',
						cast(trim('2014-10-20 14:42:07.015476+02') as timestamp),
						cast(trim('2014-10-20 14:42:07.149012+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '4052e44109b3829bfe45dda25635452d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO ROLES_GROUPS(role_id,action_group_id)
    VALUES('DEF00008-0000-0000-0000-DEF000000008', 502);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO ROLES_GROUPS(role_id,action_group_id)
    VALUES('DEF00008-0000-0000-0000-DEF000000008', 503);
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050710'),
						'upgrade/03_05_0710_add_manipulate_permissions_for_template_admin.sql',
						'4052e44109b3829bfe45dda25635452d',
						'engine',
						cast(trim('2014-10-20 14:42:07.167377+02') as timestamp),
						cast(trim('2014-10-20 14:42:07.220277+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '401aaf9a355d657a92de4d0bd3e5c6da' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE INDEX IDX_unregistered_ovf_of_entities_storage_domain_id ON unregistered_ovf_of_entities(storage_domain_id);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050720'),
						'upgrade/03_05_0720_index_for_stoarge_domain_id_in_unregistered_ovf_of_entities.sql',
						'401aaf9a355d657a92de4d0bd3e5c6da',
						'engine',
						cast(trim('2014-10-20 14:42:07.266113+02') as timestamp),
						cast(trim('2014-10-20 14:42:07.347023+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '9f391723ab1a0779bdfabe9e5cbcab9f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
ALTER TABLE disk_image_dynamic DROP CONSTRAINT fk_disk_image_dynamic_images;
**************************

ALTER TABLE
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_image_deleted() RETURNS TRIGGER AS $$
BEGIN
    DELETE FROM disk_image_dynamic dim WHERE DIM.image_id = OLD.image_guid;
    RETURN OLD;
END;
$$ LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE TRIGGER delete_disk_image_dynamic_for_image BEFORE DELETE ON IMAGES FOR EACH ROW
EXECUTE PROCEDURE fn_image_deleted()
**************************

CREATE TRIGGER
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050730'),
						'upgrade/03_05_0730_drop_disk_image_dynamic_fk.sql',
						'9f391723ab1a0779bdfabe9e5cbcab9f',
						'engine',
						cast(trim('2014-10-20 14:42:07.366552+02') as timestamp),
						cast(trim('2014-10-20 14:42:07.418974+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '39e7babc1790e0e00170dab2ac439c31' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vm_static s set min_allocated_mem = (select mem_size_mb from vm_static where vm_guid = s.vm_guid) where s.min_allocated_mem = 0 and entity_type = 'INSTANCE_TYPE';
**************************

UPDATE 5
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050740'),
						'upgrade/03_05_0740_min_allocated_memory_on_instance_type.sql',
						'39e7babc1790e0e00170dab2ac439c31',
						'engine',
						cast(trim('2014-10-20 14:42:07.439004+02') as timestamp),
						cast(trim('2014-10-20 14:42:07.518492+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'c78e763da87f6bdfadb27d85fe49458e' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
DELETE FROM disk_image_dynamic
WHERE image_id NOT IN (SELECT image_guid FROM images);
**************************

DELETE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050750'),
						'upgrade/03_05_0750_delete_orphand_disk_image_dynamic_records.sql',
						'c78e763da87f6bdfadb27d85fe49458e',
						'engine',
						cast(trim('2014-10-20 14:42:07.536462+02') as timestamp),
						cast(trim('2014-10-20 14:42:07.600992+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e68282af5c0f20005eee9db013fa5d50' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE vds_groups SET cpu_name = 'Intel Haswell Family' WHERE cpu_name = 'Intel Haswell';
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050760'),
						'upgrade/03_05_0760_update_haswell_vds_to_new_name.sql',
						'e68282af5c0f20005eee9db013fa5d50',
						'engine',
						cast(trim('2014-10-20 14:42:07.632799+02') as timestamp),
						cast(trim('2014-10-20 14:42:07.702671+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '1db86a77ba72ce4a1e6374245a0a2e1b' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update users set name = username where domain='internal';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050770'),
						'upgrade/03_05_0770_set_name_for_internal_user.sql',
						'1db86a77ba72ce4a1e6374245a0a2e1b',
						'engine',
						cast(trim('2014-10-20 14:42:07.732285+02') as timestamp),
						cast(trim('2014-10-20 14:42:07.765202+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '9b42cb74020184652b1cf9ca8521856d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('command_entities', 'job_id', 'UUID DEFAULT NULL');
**************************

 

********* QUERY **********
select fn_db_add_column('command_entities', 'step_id', 'UUID DEFAULT NULL');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050780'),
						'upgrade/03_05_0780_add_job_step_ids_to_command_entities.sql',
						'9b42cb74020184652b1cf9ca8521856d',
						'engine',
						cast(trim('2014-10-20 14:42:07.81719+02') as timestamp),
						cast(trim('2014-10-20 14:42:07.907856+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ea234bcccebcf4ec5e3ada7fd325658d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('command_entities', 'executed', 'boolean default false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050790'),
						'upgrade/03_05_0790_add_executed_to_command_entities.sql',
						'ea234bcccebcf4ec5e3ada7fd325658d',
						'engine',
						cast(trim('2014-10-20 14:42:07.927718+02') as timestamp),
						cast(trim('2014-10-20 14:42:08.020119+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ed8dc29e8a271c9d1231f2948c0b724f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vm_static set
origin=
    case
        when exists (select * from vdc_options where option_name = 'OriginType' and option_value = 'RHEV')
        then 0
        else 3
    end
where vm_guid='00000000-0000-0000-0000-000000000000';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050800'),
						'upgrade/03_05_0800_update_blank_template_origin_type.sql',
						'ed8dc29e8a271c9d1231f2948c0b724f',
						'engine',
						cast(trim('2014-10-20 14:42:08.038356+02') as timestamp),
						cast(trim('2014-10-20 14:42:08.075821+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3eae5f0e42050fb4b35d8ff8acb33ec3' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE base_disks
SET sgio = NULL
WHERE base_disks.disk_id IN (SELECT device_id FROM vm_device WHERE is_readonly = TRUE);
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050810'),
						'upgrade/03_05_0810_update_sgio_for_readonly_disks.sql',
						'3eae5f0e42050fb4b35d8ff8acb33ec3',
						'engine',
						cast(trim('2014-10-20 14:42:08.118219+02') as timestamp),
						cast(trim('2014-10-20 14:42:08.13472+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '4ea8dd52ef16801e80a8b9c785d6ab6e' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE vds_groups SET required_rng_sources = ''
WHERE cast(compatibility_version as float) <= 3.5
 AND cast (vds_group_id as text) = (select option_value from vdc_options where option_name = 'AutoRegistrationDefaultVdsGroupID');
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050820'),
						'upgrade/03_05_0820_reset_rng_sources.sql',
						'4ea8dd52ef16801e80a8b9c785d6ab6e',
						'engine',
						cast(trim('2014-10-20 14:42:08.159812+02') as timestamp),
						cast(trim('2014-10-20 14:42:08.238538+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '62394f326e95b91f58761edcac1045dc' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_static', 'host_provider_id', 'UUID');
**************************

 

********* QUERY **********
ALTER TABLE vds_static ADD CONSTRAINT fk_vds_static_host_provider_id FOREIGN KEY (host_provider_id) REFERENCES providers(id) ON DELETE SET NULL;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050830'),
						'upgrade/03_05_0830_add_provider_host_id_vdsstatic.sql',
						'62394f326e95b91f58761edcac1045dc',
						'engine',
						cast(trim('2014-10-20 14:42:08.256966+02') as timestamp),
						cast(trim('2014-10-20 14:42:08.350753+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '0786621ebc6849561782b3d783712863' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('vds_dynamic', 'is_live_merge_supported', 'boolean not null default true');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050840'),
						'upgrade/03_05_0840_add_live_merge_supported.sql',
						'0786621ebc6849561782b3d783712863',
						'engine',
						cast(trim('2014-10-20 14:42:08.368729+02') as timestamp),
						cast(trim('2014-10-20 14:42:08.468552+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'b10e7c5650faa51f51f70ec668b03104' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vds_groups', 'skip_fencing_if_sd_active', 'boolean DEFAULT false');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050850'),
						'upgrade/03_05_0850_skip_fencing_when_sd_is_alive.sql',
						'b10e7c5650faa51f51f70ec668b03104',
						'engine',
						cast(trim('2014-10-20 14:42:08.487046+02') as timestamp),
						cast(trim('2014-10-20 14:42:08.566531+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '437092e7be64e5fca4cbc56163929494' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE vm_device SET address = ''
WHERE is_managed AND device = 'disk' AND NOT is_plugged;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050860'),
						'upgrade/03_05_0860_clear_address_for_unplugged_disks.sql',
						'437092e7be64e5fca4cbc56163929494',
						'engine',
						cast(trim('2014-10-20 14:42:08.590165+02') as timestamp),
						cast(trim('2014-10-20 14:42:08.668151+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '7b0161f7d98392f6a7ee36746efb88f0' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_rename_column('async_tasks', 'task_parameters', 'action_parameters');
**************************

 

********* QUERY **********
select fn_db_rename_column('async_tasks', 'task_params_class', 'action_params_class');
**************************

 

********* QUERY **********
select fn_db_rename_column('command_entities', 'action_parameters', 'command_parameters');
**************************

 

********* QUERY **********
select fn_db_rename_column('command_entities', 'action_parameters_class', 'command_params_class');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050870'),
						'upgrade/03_05_0870_rename_async_tasks_columns.sql',
						'7b0161f7d98392f6a7ee36746efb88f0',
						'engine',
						cast(trim('2014-10-20 14:42:08.686181+02') as timestamp),
						cast(trim('2014-10-20 14:42:08.789262+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'fb1715183db420fb3f3a897fe5e33691' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO dwh_history_timekeeping VALUES('dwhHostname', NULL, NULL);
**************************

INSERT 0 1
********* QUERY **********
INSERT INTO dwh_history_timekeeping VALUES('dwhUuid', NULL, NULL);
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050880'),
						'upgrade/03_05_0880_add_dwh_hostname_and_uuid.sql',
						'fb1715183db420fb3f3a897fe5e33691',
						'engine',
						cast(trim('2014-10-20 14:42:08.8063+02') as timestamp),
						cast(trim('2014-10-20 14:42:08.88865+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '7ff663d26c754e27b8562e884f30c79f' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_drop_column ('ad_groups', 'active');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050890'),
						'upgrade/03_05_0890_remove_active_column_from_groups.sql',
						'7ff663d26c754e27b8562e884f30c79f',
						'engine',
						cast(trim('2014-10-20 14:42:08.906986+02') as timestamp),
						cast(trim('2014-10-20 14:42:08.989193+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '3e7d1799e37609886e05c80b36d18893' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vds_groups', 'skip_fencing_if_connectivity_broken', 'boolean DEFAULT false');
**************************

 

********* QUERY **********
SELECT fn_db_add_column('vds_groups', 'hosts_with_broken_connectivity_threshold', 'smallint DEFAULT 50');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050900'),
						'upgrade/03_05_0900_skip_fencing_when_connectivity_broken.sql',
						'3e7d1799e37609886e05c80b36d18893',
						'engine',
						cast(trim('2014-10-20 14:42:09.029219+02') as timestamp),
						cast(trim('2014-10-20 14:42:09.177232+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e7d5246a45d15d25715b055caf97e227' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vds_groups', 'fencing_enabled', 'boolean DEFAULT true');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050910'),
						'upgrade/03_05_0910_disable_fencing_in_cluster.sql',
						'e7d5246a45d15d25715b055caf97e227',
						'engine',
						cast(trim('2014-10-20 14:42:09.218903+02') as timestamp),
						cast(trim('2014-10-20 14:42:09.30238+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '5ce4e9fade642e8b138edcb182b499ba' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE network
SET label = NULL
WHERE provider_network_external_id IS NOT NULL;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050920'),
						'upgrade/03_05_0920_remove_external_network_labels.sql',
						'5ce4e9fade642e8b138edcb182b499ba',
						'engine',
						cast(trim('2014-10-20 14:42:09.322252+02') as timestamp),
						cast(trim('2014-10-20 14:42:09.388222+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '7309ccc0bbacc19bd3df6835f34544a8' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE images SET volume_type = 2 WHERE volume_type = 1 AND volume_format = 4;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050930'),
						'upgrade/03_05_0930_convert_cow_preallocated_to_cow_sparse.sql',
						'7309ccc0bbacc19bd3df6835f34544a8',
						'engine',
						cast(trim('2014-10-20 14:42:09.406223+02') as timestamp),
						cast(trim('2014-10-20 14:42:09.47324+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '025abccb8ef8aa33f4cda71a6607fdfe' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE qos
(
  id uuid NOT NULL,
  qos_type SMALLINT NOT NULL,
  name VARCHAR(50) NOT NULL,
  description TEXT,
  storage_pool_id uuid NOT NULL,
  max_throughput INTEGER,
  max_read_throughput INTEGER,
  max_write_throughput INTEGER,
  max_iops INTEGER,
  max_read_iops INTEGER,
  max_write_iops INTEGER,
  _create_date TIMESTAMP WITH TIME ZONE default LOCALTIMESTAMP,
  _update_date TIMESTAMP WITH TIME ZONE default NULL,
  CONSTRAINT PK_qos_id PRIMARY KEY (id)
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
ALTER TABLE qos ADD CONSTRAINT fk_qos_storage_pool FOREIGN KEY (storage_pool_id)
      REFERENCES storage_pool (id)
      ON UPDATE NO ACTION ON DELETE CASCADE;
**************************

ALTER TABLE
********* QUERY **********
CREATE INDEX IDX_qos_storage_pool_id ON qos (storage_pool_id);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050940'),
						'upgrade/03_05_0940_add_qos_table.sql',
						'025abccb8ef8aa33f4cda71a6607fdfe',
						'engine',
						cast(trim('2014-10-20 14:42:09.519385+02') as timestamp),
						cast(trim('2014-10-20 14:42:09.685673+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '45aad4361bb9e94625e0ff4f4b5dfac7' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE disk_profiles
(
  id UUID PRIMARY KEY,
  name VARCHAR(50) NOT NULL,
  storage_domain_id UUID NOT NULL,
  qos_id UUID,
  description TEXT,
  _create_date TIMESTAMP WITH TIME ZONE default LOCALTIMESTAMP,
  _update_date TIMESTAMP WITH TIME ZONE,
  FOREIGN KEY (storage_domain_id) REFERENCES storage_domain_static(id) ON DELETE CASCADE,
  FOREIGN KEY (qos_id) REFERENCES qos(id) ON DELETE SET NULL
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
DROP INDEX IF EXISTS IDX_disk_profiles_storage_domain_id;
**************************

DROP INDEX
********* QUERY **********
CREATE INDEX IDX_disk_profiles_storage_domain_id ON disk_profiles(storage_domain_id);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050950'),
						'upgrade/03_05_0950_add_disk_profiles_table.sql',
						'45aad4361bb9e94625e0ff4f4b5dfac7',
						'engine',
						cast(trim('2014-10-20 14:42:09.728429+02') as timestamp),
						cast(trim('2014-10-20 14:42:09.836483+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '52daebd94e928f8ae11ce5720b585f20' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
INSERT INTO roles_groups (role_id, action_group_id)
SELECT DISTINCT role_id, 1560
FROM roles_groups a
WHERE NOT EXISTS (SELECT 1
                      FROM roles_groups b
                      WHERE b.role_id = a.role_id
                      AND b.action_group_id = 1560)
    AND EXISTS (SELECT 1
                FROM roles_groups b
                WHERE b.role_id = a.role_id
                AND (b.action_group_id = 601 OR b.action_group_id = 603));
**************************

INSERT 0 3
********* QUERY **********
INSERT INTO roles_groups (role_id, action_group_id)
SELECT DISTINCT role_id, 1561
FROM roles_groups a
WHERE NOT EXISTS (SELECT 1
                      FROM roles_groups b
                      WHERE b.role_id = a.role_id
                      AND b.action_group_id = 1561)
    AND EXISTS (SELECT 1
                FROM roles_groups b
                WHERE b.role_id = a.role_id
                AND b.action_group_id = 600);
**************************

INSERT 0 3
********* QUERY **********
INSERT INTO roles_groups (role_id, action_group_id)
SELECT DISTINCT role_id, 1562
FROM roles_groups a
WHERE NOT EXISTS (SELECT 1
                      FROM roles_groups b
                      WHERE b.role_id = a.role_id
                      AND b.action_group_id = 1562)
    AND EXISTS (SELECT 1
                FROM roles_groups b
                WHERE b.role_id = a.role_id
                AND b.action_group_id = 602);
**************************

INSERT 0 3
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050960'),
						'upgrade/03_05_0960_add_disk_profile_action_groups.sql',
						'52daebd94e928f8ae11ce5720b585f20',
						'engine',
						cast(trim('2014-10-20 14:42:09.878361+02') as timestamp),
						cast(trim('2014-10-20 14:42:09.928644+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'ede7d79adaed3de625e0e180b066a0c1' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('image_storage_domain_map', 'disk_profile_id', 'UUID NULL');
**************************

 

********* QUERY **********
DROP INDEX IF EXISTS IDX_image_storage_domain_map_profile_id;
**************************

DROP INDEX
********* QUERY **********
CREATE INDEX IDX_image_storage_domain_map_profile_id ON image_storage_domain_map(disk_profile_id);
**************************

CREATE INDEX
********* QUERY **********
ALTER TABLE image_storage_domain_map ADD CONSTRAINT FK_image_storage_domain_map_disk_profile_id FOREIGN KEY(disk_profile_id)
REFERENCES disk_profiles(id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE SET NULL;
**************************

ALTER TABLE
********* QUERY **********
INSERT INTO disk_profiles(id, name, storage_domain_id)
  SELECT uuid_generate_v1(),
    storage_domain_static.storage_name,
    storage_domain_static.id
  FROM storage_pool LEFT OUTER JOIN storage_pool_iso_map ON storage_pool.id = storage_pool_iso_map.storage_pool_id
  LEFT OUTER JOIN storage_domain_static ON storage_pool_iso_map.storage_id = storage_domain_static.id
  WHERE (storage_domain_static.storage_domain_type = 0 OR
    storage_domain_static.storage_domain_type = 1) AND
    cast(storage_pool.compatibility_version as float) >= 3.5;
**************************

INSERT 0 0
********* QUERY **********
UPDATE image_storage_domain_map
  SET disk_profile_id = disk_profiles.id
  FROM disk_profiles
  WHERE image_storage_domain_map.storage_domain_id = disk_profiles.storage_domain_id;
**************************

UPDATE 0
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050970'),
						'upgrade/03_05_0970_disk_profile_for_disk_image.sql',
						'ede7d79adaed3de625e0e180b066a0c1',
						'engine',
						cast(trim('2014-10-20 14:42:09.947101+02') as timestamp),
						cast(trim('2014-10-20 14:42:10.085394+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '8b1e76c45a6855f65f07356ccaf4113e' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
CREATE TABLE cpu_profiles
(
  id UUID PRIMARY KEY,
  name VARCHAR(50) NOT NULL,
  cluster_id UUID NOT NULL,
  qos_id UUID,
  description TEXT,
  _create_date TIMESTAMP WITH TIME ZONE default LOCALTIMESTAMP,
  _update_date TIMESTAMP WITH TIME ZONE,
  FOREIGN KEY (cluster_id) REFERENCES vds_groups(vds_group_id) ON DELETE CASCADE,
  FOREIGN KEY (qos_id) REFERENCES qos(id) ON DELETE SET NULL
) WITH OIDS;
**************************

CREATE TABLE
********* QUERY **********
DROP INDEX IF EXISTS IDX_cpu_profiles_cluster_id;
**************************

DROP INDEX
********* QUERY **********
CREATE INDEX IDX_cpu_profiles_cluster_id ON cpu_profiles(cluster_id);
**************************

CREATE INDEX
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050980'),
						'upgrade/03_05_0980_add_cpu_profiles_table.sql',
						'8b1e76c45a6855f65f07356ccaf4113e',
						'engine',
						cast(trim('2014-10-20 14:42:10.12816+02') as timestamp),
						cast(trim('2014-10-20 14:42:10.228813+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'e02ea7f83ad872218441c4fcdc49d54c' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('qos', 'cpu_limit', 'SMALLINT DEFAULT NULL');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03050990'),
						'upgrade/03_05_0990_add_cpu_limit_to_qos_table.sql',
						'e02ea7f83ad872218441c4fcdc49d54c',
						'engine',
						cast(trim('2014-10-20 14:42:10.248352+02') as timestamp),
						cast(trim('2014-10-20 14:42:10.336636+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'a3cac957441328d0b01d78bc29d64656' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('vm_static', 'cpu_profile_id', 'UUID NULL');
**************************

 

********* QUERY **********
DROP INDEX IF EXISTS IDX_vm_static_cpu_profile_id;
**************************

DROP INDEX
********* QUERY **********
CREATE INDEX IDX_vm_static_cpu_profile_id ON vm_static(cpu_profile_id);
**************************

CREATE INDEX
********* QUERY **********
ALTER TABLE vm_static ADD CONSTRAINT FK_vm_static_cpu_profile_id FOREIGN KEY(cpu_profile_id)
REFERENCES cpu_profiles(id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE SET NULL;
**************************

ALTER TABLE
********* QUERY **********
INSERT INTO cpu_profiles(id, name, cluster_id)
  SELECT uuid_generate_v1(),
    vds_groups.name,
    vds_groups.vds_group_id
  FROM vds_groups
  WHERE cast(compatibility_version as float) >= 3.5;
**************************

INSERT 18855 1
********* QUERY **********
UPDATE vm_static
  SET cpu_profile_id = cpu_profiles.id
  FROM cpu_profiles
  WHERE vm_static.vds_group_id = cpu_profiles.cluster_id;
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03051000'),
						'upgrade/03_05_1000_add_cpu_profile_id_to_vm_static.sql',
						'a3cac957441328d0b01d78bc29d64656',
						'engine',
						cast(trim('2014-10-20 14:42:10.378441+02') as timestamp),
						cast(trim('2014-10-20 14:42:10.479098+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'fc50a5ee598dbaf3d58c8f3e29f2fb88' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
UPDATE vm_static SET cpu_profile_id = NULL where vm_guid = '00000000-0000-0000-0000-000000000000';
**************************

UPDATE 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03051010'),
						'upgrade/03_05_1010_remove_blank_template_cpu_profile.sql',
						'fc50a5ee598dbaf3d58c8f3e29f2fb88',
						'engine',
						cast(trim('2014-10-20 14:42:10.497059+02') as timestamp),
						cast(trim('2014-10-20 14:42:10.569831+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '48164c72dd519fa9f786d04513ffd541' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
update vm_device set is_managed=true where device='virtio-serial';
**************************

UPDATE 0
********* QUERY **********
Create or replace FUNCTION __temp_add_missing_virio_serial_devices()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_vm_guid UUID;
BEGIN
   FOR v_vm_guid in (select vm_guid from vm_static where entity_type!='INSTANCE_TYPE' and vm_guid not in (select vm_id from vm_device where device='virtio-serial')) LOOP
      INSERT INTO vm_device (device_id, vm_id, type, device, address, spec_params, is_managed, is_plugged, custom_properties, snapshot_id)
	VALUES ((SELECT uuid_generate_v1()), v_vm_guid, 'controller', 'virtio-serial', '', '', true, true, '', NULL);
   END LOOP;

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_add_missing_virio_serial_devices();
**************************

 

********* QUERY **********
DROP function __temp_add_missing_virio_serial_devices();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03051020'),
						'upgrade/03_05_1020_change_virtio_serial_to_managed_device.sql',
						'48164c72dd519fa9f786d04513ffd541',
						'engine',
						cast(trim('2014-10-20 14:42:10.588785+02') as timestamp),
						cast(trim('2014-10-20 14:42:10.697028+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '8db41131fd32d309451bf1a2ae367846' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
SELECT fn_db_add_column('qos', 'inbound_average', 'SMALLINT DEFAULT NULL');
**************************

 

********* QUERY **********
SELECT fn_db_add_column('qos', 'inbound_peak', 'SMALLINT DEFAULT NULL');
**************************

 

********* QUERY **********
SELECT fn_db_add_column('qos', 'inbound_burst', 'SMALLINT DEFAULT NULL');
**************************

 

********* QUERY **********
SELECT fn_db_add_column('qos', 'outbound_average', 'SMALLINT DEFAULT NULL');
**************************

 

********* QUERY **********
SELECT fn_db_add_column('qos', 'outbound_peak', 'SMALLINT DEFAULT NULL');
**************************

 

********* QUERY **********
SELECT fn_db_add_column('qos', 'outbound_burst', 'SMALLINT DEFAULT NULL');
**************************

 

********* QUERY **********
INSERT INTO qos(
       id, qos_type, name, description, storage_pool_id, inbound_average, inbound_peak, inbound_burst,
       outbound_average, outbound_peak, outbound_burst, _create_date,
       _update_date)
SELECT id, 3, name, NULL, storage_pool_id, inbound_average, inbound_peak, inbound_burst,
       outbound_average, outbound_peak, outbound_burst, _create_date,
       _update_date
FROM network_qos;
**************************

INSERT 0 0
********* QUERY **********
SELECT fn_db_drop_constraint('vnic_profiles', 'FK_vnic_profiles_network_qos_id');
**************************

 

********* QUERY **********
SELECT fn_db_drop_constraint('network', 'fk_network_qos_id');
**************************

 

********* QUERY **********
DROP TABLE network_qos;
**************************

DROP TABLE
********* QUERY **********
SELECT fn_db_create_constraint('vnic_profiles', 'fk_vnic_profiles_network_qos_id', 'FOREIGN KEY (network_qos_id) REFERENCES qos(id) ON DELETE SET NULL');
**************************

 

********* QUERY **********
SELECT fn_db_create_constraint('network', 'fk_network_qos_id', 'FOREIGN KEY (qos_id) REFERENCES qos(id) ON DELETE SET NULL');
**************************

 

********* QUERY **********
ALTER TABLE qos
      ALTER COLUMN name DROP NOT NULL,
      ALTER COLUMN storage_pool_id DROP NOT NULL;
**************************

ALTER TABLE
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03051030'),
						'upgrade/03_05_1030_refactor_network_qos.sql',
						'8db41131fd32d309451bf1a2ae367846',
						'engine',
						cast(trim('2014-10-20 14:42:10.738749+02') as timestamp),
						cast(trim('2014-10-20 14:42:10.919196+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'a9d4400bdcf1ceea3778d5523f11456b' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
Create or replace FUNCTION __temp_remove_install_vds_upgrade_node_action_group_03_06_0360()
RETURNS VOID
   AS $procedure$
   DECLARE
   v_SUPER_USER_ID_0001 UUID;
   v_DATA_CENTER_ADMIN_ID UUID;
   v_CLUSTER_ADMIN_ID UUID;

BEGIN
   v_SUPER_USER_ID_0001 := '00000000-0000-0000-0000-000000000001';
   v_DATA_CENTER_ADMIN_ID := 'DEF00002-0000-0000-0000-DEF000000002';
   v_CLUSTER_ADMIN_ID := 'DEF00001-0000-0000-0000-DEF000000001';

-------------------------
--- Update SuperUser role
-------------------------
DELETE FROM roles_groups WHERE role_id = v_SUPER_USER_ID_0001 AND action_group_id=130;
DELETE FROM roles_groups WHERE role_id = v_SUPER_USER_ID_0001 AND action_group_id=131;

--------------------------------
-- UPDATE DATA_CENTER_ADMIN role
--------------------------------
DELETE FROM roles_groups WHERE role_id = v_DATA_CENTER_ADMIN_ID AND action_group_id=130;
DELETE FROM roles_groups WHERE role_id = v_DATA_CENTER_ADMIN_ID AND action_group_id=131;

--------------------------------
-- UPDATE CLUSTER_ADMIN role
--------------------------------
DELETE FROM roles_groups WHERE role_id = v_CLUSTER_ADMIN_ID AND action_group_id=130;
DELETE FROM roles_groups WHERE role_id = v_CLUSTER_ADMIN_ID AND action_group_id=131;

RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT __temp_remove_install_vds_upgrade_node_action_group_03_06_0360();
**************************

 

********* QUERY **********
DROP function __temp_remove_install_vds_upgrade_node_action_group_03_06_0360();
**************************

DROP FUNCTION
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03051040'),
						'upgrade/03_05_1040_remove_install_vds_upgrade_ovirt_node_action_group.sql',
						'a9d4400bdcf1ceea3778d5523f11456b',
						'engine',
						cast(trim('2014-10-20 14:42:10.936456+02') as timestamp),
						cast(trim('2014-10-20 14:42:10.989462+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = '57018b279c962805f034c6cea285ef9d' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_add_column('async_tasks', 'root_command_id', 'UUID DEFAULT NULL');
**************************

 

********* QUERY **********
select fn_db_drop_column ('async_tasks', 'action_parameters');
**************************

 

********* QUERY **********
select fn_db_drop_column ('async_tasks', 'action_params_class');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03051050'),
						'upgrade/03_05_1050_async_tasks_add_root_command_id.sql',
						'57018b279c962805f034c6cea285ef9d',
						'engine',
						cast(trim('2014-10-20 14:42:11.007805+02') as timestamp),
						cast(trim('2014-10-20 14:42:11.069071+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********
copy (
		select version
		from schema_version
		where
			checksum = 'abf83fbb84d3a0979085473e9a46a540' and
			state = 'INSTALLED'
	) to stdout with delimiter as '|';
**************************

********* QUERY **********
select fn_db_update_config_value('EnableHostTimeDrift', 'true', 'general');
**************************

 

********* QUERY **********
copy (select now()) to stdout with delimiter as '|';
**************************

********* QUERY **********

					insert into schema_version(
						version,
						script,
						checksum,
						installed_by,
						started_at,
						ended_at,
						state,
						current,
						comment
					)
					values (
						trim('03051060'),
						'upgrade/03_05_1060_set_time_drift_validation.sql',
						'abf83fbb84d3a0979085473e9a46a540',
						'engine',
						cast(trim('2014-10-20 14:42:11.087544+02') as timestamp),
						cast(trim('2014-10-20 14:42:11.131224+02') as timestamp),
						'INSTALLED',
						false,
						''
					);
				
**************************

INSERT 0 1
********* QUERY **********
copy (
			select max(id)
			from schema_version
			where state in ('INSTALLED','SKIPPED')
		) to stdout with delimiter as '|';
**************************

********* QUERY **********

		update schema_version
		set current=(id=270);
	
**************************

UPDATE 270
********* QUERY **********
CREATE OR REPLACE VIEW storage_domain_static_view
AS
SELECT     storage_domain_static.id as id,
			storage_domain_static.storage as storage,
			storage_domain_static.storage_name as storage_name,
			storage_domain_static.storage_description as storage_description,
			storage_domain_static.storage_comment as storage_comment,
			storage_pool_iso_map.storage_pool_id as storage_pool_id,
                        storage_pool_iso_map.status as status,
			storage_domain_static.storage_domain_type as storage_domain_type,
			storage_domain_static.storage_type as storage_type,
                        storage_domain_static.storage_domain_format_type as storage_domain_format_type,
            storage_domain_static.last_time_used_as_master as last_time_used_as_master,
			storage_pool.name as storage_pool_name,
			unregistered_entities.storage_domain_id IS NOT NULL AS contains_unregistered_entities
FROM        storage_domain_static LEFT OUTER JOIN
storage_pool_iso_map on storage_pool_iso_map.storage_id = storage_domain_static.id
LEFT OUTER JOIN storage_pool ON storage_pool.id = storage_pool_iso_map.storage_pool_id
LEFT OUTER JOIN (SELECT DISTINCT storage_domain_id
                 FROM unregistered_ovf_of_entities) AS unregistered_entities ON unregistered_entities.storage_domain_id = storage_domain_static.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vms_for_disk_view
AS
SELECT array_agg(vm_name) as array_vm_names,device_id,entity_type
FROM vm_static
JOIN vm_device ON vm_static.vm_guid = vm_device.vm_id
WHERE device = 'disk'
GROUP BY device_id, entity_type;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW images_storage_domain_view
AS

SELECT images.image_guid as image_guid,
    storage_domain_static_view.storage_name as storage_name,
    storage_domain_static_view.storage as storage_path,
	storage_domain_static_view.storage_pool_id as storage_pool_id,
	storage_domain_static_view.storage_type as storage_type,
	images.creation_date as creation_date,
    images.size as size,
    images.it_guid as it_guid,
    snapshots.description as description,
    images.ParentId as ParentId,
    images.lastModified as lastModified,
    snapshots.app_list as app_list,
    image_storage_domain_map.storage_domain_id as storage_id,
    images.vm_snapshot_id as vm_snapshot_id,
    images.volume_type as volume_type,
    images.volume_format as volume_format,
    images.imageStatus as imageStatus,
    images.image_group_id as image_group_id,
    images.active,
    vms_for_disk_view.entity_type as entity_type,
    array_to_string(vms_for_disk_view.array_vm_names, ',') as vm_names,
    COALESCE(array_upper(vms_for_disk_view.array_vm_names,1),0) as number_of_vms,
    base_disks.disk_id,
    base_disks.disk_alias as disk_alias,
    base_disks.disk_description as disk_description,
    base_disks.shareable as shareable,
    base_disks.disk_interface,
    base_disks.wipe_after_delete as wipe_after_delete,
    base_disks.propagate_errors,
    base_disks.boot as boot,
    base_disks.sgio as sgio,
    image_storage_domain_map.quota_id as quota_id,
    quota.quota_name as quota_name,
    storage_pool.quota_enforcement_type,
    image_storage_domain_map.disk_profile_id as disk_profile_id,
    disk_profiles.name as disk_profile_name,
    disk_image_dynamic.actual_size as actual_size,
    disk_image_dynamic.read_rate as read_rate,
    disk_image_dynamic.write_rate as write_rate,
    disk_image_dynamic.read_latency_seconds as read_latency_seconds,
    disk_image_dynamic.write_latency_seconds as write_latency_seconds,
    disk_image_dynamic.flush_latency_seconds as flush_latency_seconds,
    base_disks.alignment as alignment,
    base_disks.last_alignment_scan as last_alignment_scan,
    EXISTS (SELECT 1 FROM storage_domains_ovf_info WHERE images.image_group_id = storage_domains_ovf_info.ovf_disk_id) as ovf_store,
    storage_domain_static_view.contains_unregistered_entities as contains_unregistered_entities
FROM
images
left outer join disk_image_dynamic on images.image_guid = disk_image_dynamic.image_id
LEFT OUTER JOIN base_disks ON images.image_group_id = base_disks.disk_id
LEFT OUTER JOIN vms_for_disk_view on vms_for_disk_view.device_id = images.image_group_id
LEFT JOIN image_storage_domain_map ON image_storage_domain_map.image_id = images.image_guid
LEFT OUTER JOIN storage_domain_static_view ON image_storage_domain_map.storage_domain_id = storage_domain_static_view.id
LEFT OUTER JOIN snapshots ON images.vm_snapshot_id = snapshots.snapshot_id
LEFT OUTER JOIN quota ON image_storage_domain_map.quota_id = quota.id
LEFT OUTER JOIN disk_profiles ON image_storage_domain_map.disk_profile_id = disk_profiles.id
LEFT OUTER JOIN storage_pool ON storage_pool.id = storage_domain_static_view.storage_pool_id
WHERE images.image_guid != '00000000-0000-0000-0000-000000000000';
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW storage_domain_file_repos
AS
SELECT
storage_domain_static.id as storage_domain_id,
			storage_domain_static.storage_domain_type as storage_domain_type,
	        storage_pool_iso_map.storage_pool_id as storage_pool_id,
	       	storage_pool_iso_map.status as storage_domain_status,
	repo_file_meta_data.repo_image_id as repo_image_id,
		repo_file_meta_data.size as size,
		repo_file_meta_data.date_created as date_created,
		repo_file_meta_data.last_refreshed as last_refreshed,
		repo_file_meta_data.file_type as file_type,
	vds_dynamic.status as vds_status,
    storage_pool.status as storage_pool_status
FROM storage_domain_static
INNER JOIN storage_pool_iso_map ON storage_domain_static.id = storage_pool_iso_map.storage_id
INNER JOIN storage_pool ON storage_pool.id = storage_pool_iso_map.storage_pool_id
INNER JOIN vds_dynamic ON vds_dynamic.vds_id = storage_pool.spm_vds_id
LEFT OUTER JOIN repo_file_meta_data ON storage_pool_iso_map.storage_id = repo_file_meta_data.repo_domain_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW storage_for_image_view
AS
SELECT images.image_guid as image_id,
	   array_to_string(array_agg(storage_domain_static.storage), ',') as storage_path,
	   array_to_string(array_agg(storage_domain_static.id), ',') storage_id,
	   array_to_string(array_agg(storage_domain_static.storage_type), ',') storage_type,
	   array_to_string(array_agg(storage_domain_static.storage_name), ',') as storage_name,
	   array_to_string(array_agg(COALESCE(CAST(quota.id as varchar), '')), ',') as quota_id,
	   array_to_string(array_agg(COALESCE(quota.quota_name, '')), ',') as quota_name,
           array_to_string(array_agg(COALESCE(CAST(disk_profiles.id as varchar), '')), ',') as disk_profile_id,
	   array_to_string(array_agg(COALESCE(disk_profiles.name, '')), ',') as disk_profile_name
FROM images
LEFT JOIN image_storage_domain_map ON image_storage_domain_map.image_id = images.image_guid
LEFT OUTER JOIN storage_domain_static ON image_storage_domain_map.storage_domain_id = storage_domain_static.id
LEFT OUTER JOIN quota ON image_storage_domain_map.quota_id = quota.id
LEFT OUTER JOIN disk_profiles ON image_storage_domain_map.disk_profile_id = disk_profiles.id
GROUP BY images.image_guid;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vm_images_view
AS
SELECT                storage_for_image_view.storage_id as storage_id, storage_for_image_view.storage_path as storage_path, storage_for_image_view.storage_name as storage_name,
					  storage_for_image_view.storage_type, images_storage_domain_view.storage_pool_id as storage_pool_id, images_storage_domain_view.image_guid as image_guid,
                      images_storage_domain_view.creation_date as creation_date, disk_image_dynamic.actual_size as actual_size, disk_image_dynamic.read_rate as read_rate,
                      disk_image_dynamic.read_latency_seconds as read_latency_seconds, disk_image_dynamic.write_latency_seconds as write_latency_seconds,
                      disk_image_dynamic.flush_latency_seconds as flush_latency_seconds, disk_image_dynamic.write_rate as write_rate,
                      images_storage_domain_view.size as size, images_storage_domain_view.it_guid as it_guid,
                      images_storage_domain_view.description as description,
                      images_storage_domain_view.ParentId as ParentId, images_storage_domain_view.imageStatus as imageStatus, images_storage_domain_view.lastModified as lastModified,
                      images_storage_domain_view.app_list as app_list, images_storage_domain_view.vm_snapshot_id as vm_snapshot_id,
                      images_storage_domain_view.volume_type as volume_type, images_storage_domain_view.image_group_id as image_group_id,
                      images_storage_domain_view.active as active, images_storage_domain_view.volume_format as volume_format,
                      images_storage_domain_view.disk_interface as disk_interface, images_storage_domain_view.boot as boot, images_storage_domain_view.wipe_after_delete as wipe_after_delete, images_storage_domain_view.propagate_errors as propagate_errors, images_storage_domain_view.sgio as sgio,
                      images_storage_domain_view.entity_type as entity_type,images_storage_domain_view.number_of_vms as number_of_vms,images_storage_domain_view.vm_names as vm_names,
                      storage_for_image_view.quota_id as quota_id, storage_for_image_view.quota_name as quota_name, images_storage_domain_view.quota_enforcement_type,
                      storage_for_image_view.disk_profile_id as disk_profile_id, storage_for_image_view.disk_profile_name as disk_profile_name,
                      images_storage_domain_view.disk_id, images_storage_domain_view.disk_alias as disk_alias, images_storage_domain_view.disk_description as disk_description,images_storage_domain_view.shareable as shareable,
                      images_storage_domain_view.alignment as alignment, images_storage_domain_view.last_alignment_scan as last_alignment_scan, images_storage_domain_view.ovf_store as ovf_store
FROM         images_storage_domain_view
INNER JOIN disk_image_dynamic ON images_storage_domain_view.image_guid = disk_image_dynamic.image_id
INNER JOIN storage_for_image_view ON images_storage_domain_view.image_guid = storage_for_image_view.image_id
WHERE images_storage_domain_view.active = TRUE;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW all_disks_including_snapshots
AS
SELECT storage_impl.*,
       bd.disk_id, 
       bd.disk_interface,
       bd.wipe_after_delete,
       bd.propagate_errors,
       bd.disk_alias,
       bd.disk_description,
       bd.shareable,
       bd.boot,
       bd.sgio,
       bd.alignment,
       bd.last_alignment_scan
FROM
(
    SELECT 0 AS disk_storage_type,
           storage_for_image_view.storage_id as storage_id, 
           storage_for_image_view.storage_path as storage_path,
           storage_for_image_view.storage_name as storage_name,
           storage_for_image_view.storage_type as storage_type,
           storage_pool_id,
           image_guid, 
           creation_date,
           actual_size,
           read_rate,
           write_rate,
           read_latency_seconds,
           write_latency_seconds,
           flush_latency_seconds,
           size,
           it_guid,
           imageStatus,
           lastModified,
           volume_type,
           volume_format,
           image_group_id,
           description, 
           ParentId,
           app_list,
           vm_snapshot_id,
           active,
           entity_type,
           number_of_vms,
           vm_names,
           storage_for_image_view.quota_id as quota_id, 
           storage_for_image_view.quota_name as quota_name,
           quota_enforcement_type,
           ovf_store,
           storage_for_image_view.disk_profile_id as disk_profile_id, 
           storage_for_image_view.disk_profile_name as disk_profile_name,
           null AS lun_id, 
           null AS physical_volume_id,
           null AS volume_group_id,
           null AS serial,
           null AS lun_mapping,
           null AS vendor_id,
           null AS product_id,
           null AS device_size
    FROM images_storage_domain_view
    INNER JOIN storage_for_image_view ON images_storage_domain_view.image_guid = storage_for_image_view.image_id
    UNION
    SELECT 1 AS disk_storage_type,
           null AS storage_id, 
           null AS storage_path,
           null AS storage_name,
           null AS storage_type,
           null AS storage_pool_id,
           null AS image_guid, 
           null AS creation_date,
           null AS actual_size,
           null AS read_rate,
           null AS write_rate,
           null AS read_latency_seconds,
           null AS write_latency_seconds,
           null AS flush_latency_seconds,
           null AS size,
           null AS it_guid,
           null AS imageStatus,
           null AS lastModified,
           null AS volume_type,
           null AS volume_format,
           dlm.disk_id AS image_group_id,
           null AS description, 
           null AS ParentId,
           null AS app_list,
           null AS vm_snapshot_id,
           null AS active,
           vms_for_disk_view.entity_type,
           COALESCE(array_upper(vms_for_disk_view.array_vm_names,1),0) as number_of_vms,
           array_to_string(vms_for_disk_view.array_vm_names, ',') as vm_names,
           null AS quota_id, 
           null AS quota_name,
           null AS quota_enforcement_type,
           false as ovf_store,
           null AS disk_profile_id, 
           null AS disk_profile_name,
           l.lun_id, 
           l.physical_volume_id,
           l.volume_group_id,
           l.serial,
           l.lun_mapping,
           l.vendor_id,
           l.product_id,
           l.device_size
    FROM disk_lun_map dlm
    JOIN luns l ON l.lun_id = dlm.lun_id
    LEFT JOIN vms_for_disk_view on vms_for_disk_view.device_id = dlm.disk_id
) AS storage_impl
JOIN base_disks bd ON bd.disk_id = storage_impl.image_group_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW all_disks
AS
SELECT *
FROM all_disks_including_snapshots
WHERE active IS NULL OR active = TRUE;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW storage_domains
AS
SELECT
storage_domain_static.id as id,
		storage_domain_static.storage as storage,
		storage_domain_static.storage_name as storage_name,
		storage_domain_static.storage_description as storage_description,
		storage_domain_static.storage_comment as storage_comment,
        storage_pool_iso_map.storage_pool_id as storage_pool_id,
		storage_domain_dynamic.available_disk_size as available_disk_size,
		storage_domain_dynamic.used_disk_size as used_disk_size,
		fn_get_disk_commited_value_by_storage(storage_domain_static.id) as commited_disk_size,
		fn_get_actual_images_size_by_storage(storage_domain_static.id) as actual_images_size,
        storage_pool_iso_map.status as status,
		storage_pool.name as storage_pool_name,
		storage_domain_static.storage_type as storage_type,
		storage_domain_static.storage_domain_type as storage_domain_type,
                storage_domain_static.storage_domain_format_type as storage_domain_format_type,
        storage_domain_static.last_time_used_as_master as last_time_used_as_master,
        fn_get_storage_domain_shared_status_by_domain_id(storage_domain_static.id,storage_pool_iso_map.status,storage_domain_static.storage_domain_type) as storage_domain_shared_status,
	storage_domain_static.recoverable as recoverable,
	unregistered_entities.storage_domain_id IS NOT NULL AS contains_unregistered_entities
FROM    storage_domain_static
INNER JOIN storage_domain_dynamic ON storage_domain_static.id = storage_domain_dynamic.id
LEFT OUTER JOIN storage_pool_iso_map ON storage_domain_static.id = storage_pool_iso_map.storage_id
LEFT OUTER JOIN storage_pool ON storage_pool_iso_map.storage_pool_id = storage_pool.id
LEFT OUTER JOIN (SELECT DISTINCT storage_domain_id
                 FROM unregistered_ovf_of_entities) AS unregistered_entities ON unregistered_entities.storage_domain_id = storage_domain_static.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW storage_domains_without_storage_pools
AS
SELECT DISTINCT
storage_domain_static.id as id, storage_domain_static.storage as storage, storage_domain_static.storage_name as storage_name, storage_domain_static.storage_description as storage_description,
		storage_domain_static.storage_comment as storage_comment, storage_domain_static.storage_type as storage_type, storage_domain_static.storage_domain_type as storage_domain_type,
                storage_domain_static.storage_domain_format_type as storage_domain_format_type,
        storage_domain_static.last_time_used_as_master as last_time_used_as_master,
		null as storage_pool_id, null as storage_pool_name,
		storage_domain_dynamic.available_disk_size as available_disk_size,
		storage_domain_dynamic.used_disk_size as used_disk_size,
		fn_get_disk_commited_value_by_storage(storage_domain_static.id) as commited_disk_size,
		fn_get_actual_images_size_by_storage(storage_domain_static.id) as actual_images_size,
	        null as status,
        fn_get_storage_domain_shared_status_by_domain_id(storage_domain_static.id,storage_pool_iso_map.status,storage_domain_static.storage_domain_type) as storage_domain_shared_status,
		storage_domain_static.recoverable as recoverable,
		unregistered_entities.storage_domain_id IS NOT NULL AS contains_unregistered_entities
FROM
storage_domain_static
INNER JOIN storage_domain_dynamic ON storage_domain_static.id = storage_domain_dynamic.id
LEFT OUTER JOIN storage_pool_iso_map ON storage_domain_static.id = storage_pool_iso_map.storage_id
LEFT OUTER JOIN (SELECT DISTINCT storage_domain_id
                 FROM unregistered_ovf_of_entities) AS unregistered_entities ON unregistered_entities.storage_domain_id = storage_domain_static.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW storage_domains_for_search
AS
SELECT
                storage_domain_static.id as id, storage_domain_static.storage as storage, storage_domain_static.storage_name as storage_name, storage_domain_static.storage_description as storage_description,
                storage_domain_static.storage_comment as storage_comment, storage_domain_static.storage_type as storage_type, storage_domain_static.storage_domain_type as storage_domain_type,
                storage_domain_static.storage_domain_format_type as storage_domain_format_type,
                storage_domain_static.last_time_used_as_master as last_time_used_as_master,
                CASE
                          WHEN status_table.is_multi_domain THEN NULL
                          WHEN status_table.status IS NULL THEN 2 
                          ELSE status_table.status END as status,
                status_table.storage_pool_id as storage_pool_id, storage_pool.name as storage_pool_name,
                storage_domain_dynamic.available_disk_size as available_disk_size,
                storage_domain_dynamic.used_disk_size as used_disk_size,
                fn_get_disk_commited_value_by_storage(storage_domain_static.id) as commited_disk_size,
		fn_get_actual_images_size_by_storage(storage_domain_static.id) as actual_images_size,
                fn_get_storage_domain_shared_status_by_domain_id(storage_domain_static.id,status_table.status,storage_domain_static.storage_domain_type) as storage_domain_shared_status,
                storage_domain_static.recoverable as recoverable,
                unregistered_entities.storage_domain_id IS NOT NULL AS contains_unregistered_entities
FROM
                storage_domain_static
INNER JOIN
                storage_domain_dynamic ON storage_domain_static.id = storage_domain_dynamic.id
LEFT OUTER JOIN
                (SELECT storage_pool_id,storage_id, count(storage_id) > 1 as is_multi_domain, max(status) AS status
                 FROM storage_pool_iso_map
                 GROUP BY storage_id, storage_pool_id) AS status_table ON storage_domain_static.id=status_table.storage_id
LEFT OUTER JOIN storage_pool ON status_table.storage_pool_id = storage_pool.id
LEFT OUTER JOIN (SELECT DISTINCT storage_domain_id
                 FROM unregistered_ovf_of_entities) AS unregistered_entities ON unregistered_entities.storage_domain_id = storage_domain_static.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW luns_view
AS
SELECT
luns.*, storage_domain_static.id as storage_id, storage_domain_static.storage_name as storage_name,
        disk_lun_map.disk_id as disk_id, all_disks.disk_alias as disk_alias
FROM luns
LEFT OUTER JOIN storage_domain_static ON luns.volume_group_id = storage_domain_static.storage
LEFT OUTER JOIN disk_lun_map ON luns.lun_id = disk_lun_map.lun_id
LEFT OUTER JOIN all_disks ON disk_lun_map.disk_id = all_disks.disk_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vm_templates_view
AS
SELECT
vm_templates.vm_guid as vmt_guid,
       vm_templates.vm_name as name,
       vm_templates.mem_size_mb as mem_size_mb,
       vm_templates.os as os,
       vm_templates.creation_date as creation_date,
       vm_templates.child_count as child_count,
       vm_templates.num_of_sockets as num_of_sockets,
       vm_templates.cpu_per_socket as cpu_per_socket,
       vm_templates.num_of_sockets*vm_templates.cpu_per_socket as num_of_cpus,
       vm_templates.description as description,
       vm_templates.free_text_comment as free_text_comment,
       vm_templates.vds_group_id as vds_group_id,
       vm_templates.num_of_monitors as num_of_monitors,
       vm_templates.single_qxl_pci as single_qxl_pci,
       vm_templates.allow_console_reconnect as allow_console_reconnect,
       vm_templates.template_status as status,
       vm_templates.usb_policy as usb_policy,
       vm_templates.time_zone as time_zone,
       vm_templates.fail_back as fail_back,
       vds_groups.name as vds_group_name,
       vds_groups.trusted_service as trusted_service,
       vm_templates.vm_type as vm_type,
       vm_templates.nice_level as nice_level,
       vm_templates.cpu_shares as cpu_shares,
       storage_pool.id as storage_pool_id,
       storage_pool.name as storage_pool_name,
       storage_pool.quota_enforcement_type as quota_enforcement_type,
       vm_templates.default_boot_sequence as default_boot_sequence,
       vm_templates.default_display_type as default_display_type,
       vm_templates.priority as priority,
       vm_templates.auto_startup as auto_startup,
       vm_templates.is_stateless as is_stateless,
       vm_templates.is_smartcard_enabled as is_smartcard_enabled,
       vm_templates.is_delete_protected as is_delete_protected,
       vm_templates.sso_method as sso_method,
       vm_templates.iso_path as iso_path,
       vm_templates.origin as origin,
       vm_templates.initrd_url as initrd_url,
       vm_templates.kernel_url as kernel_url,
       vm_templates.kernel_params as kernel_params,
       vm_templates.quota_id as quota_id,
       quota.quota_name as quota_name,
       vm_templates.db_generation as db_generation,
       vm_templates.migration_support,
       vm_templates.dedicated_vm_for_vds,
       vm_templates.is_disabled,
       vm_templates.tunnel_migration,
       vm_templates.vnc_keyboard_layout as vnc_keyboard_layout,
       vm_templates.min_allocated_mem as min_allocated_mem,
       vm_templates.is_run_and_pause as is_run_and_pause,
       vm_templates.created_by_user_id as created_by_user_id,
       vm_templates.entity_type,
       vm_templates.migration_downtime as migration_downtime,
       vds_groups.architecture as architecture,
       vm_templates.template_version_number as template_version_number,
       vm_templates.vmt_guid as base_template_id,
       vm_templates.template_version_name as template_version_name,
       vm_templates.serial_number_policy as serial_number_policy,
       vm_templates.custom_serial_number as custom_serial_number,
       vm_templates.is_boot_menu_enabled as is_boot_menu_enabled,
       vm_templates.is_spice_file_transfer_enabled as is_spice_file_transfer_enabled,
       vm_templates.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled,
       vm_templates.cpu_profile_id as cpu_profile_id,
       vm_templates.numatune_mode as numatune_mode
FROM       vm_static AS vm_templates  LEFT OUTER JOIN
vds_groups ON vm_templates.vds_group_id = vds_groups.vds_group_id
left outer JOIN
storage_pool ON storage_pool.id = vds_groups.storage_pool_id
left outer JOIN
quota ON vm_templates.quota_id = quota.id
WHERE entity_type = 'TEMPLATE' OR entity_type = 'INSTANCE_TYPE' OR entity_type = 'IMAGE_TYPE';
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vm_templates_with_plug_info
as
SELECT vm_templates_view.*, image_guid, image_group_id, is_plugged
FROM vm_templates_view
INNER JOIN vm_device vd ON vd.vm_id = vm_templates_view.vmt_guid
INNER JOIN images ON images.image_group_id = vd.device_id AND images.active = TRUE;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vm_templates_storage_domain
AS
	SELECT            vm_templates.vm_guid AS vmt_guid, vm_templates.vm_name AS name, vm_templates.mem_size_mb,
                      vm_templates.os, vm_templates.creation_date,
                      vm_templates.child_count, vm_templates.num_of_sockets, vm_templates.cpu_per_socket,
	                  vm_templates.num_of_sockets*vm_templates.cpu_per_socket AS num_of_cpus, vm_templates.description, vm_templates.free_text_comment,
	                  vm_templates.vds_group_id, vm_templates.num_of_monitors, vm_templates.single_qxl_pci, vm_templates.allow_console_reconnect, vm_templates.template_status AS status,
	                  vm_templates.usb_policy, vm_templates.time_zone, vm_templates.fail_back,
	                  vds_groups.name AS vds_group_name, vm_templates.vm_type, vm_templates.nice_level, vm_templates.cpu_shares, storage_pool.id AS storage_pool_id, storage_pool.name
                      AS storage_pool_name,
	                  vm_templates.default_boot_sequence, vm_templates.default_display_type, vm_templates.priority, vm_templates.auto_startup,
	                  vm_templates.is_stateless, vm_templates.iso_path, vm_templates.origin, vm_templates.initrd_url, vm_templates.kernel_url,
	                  vm_templates.kernel_params, image_storage_domain_map.storage_domain_id AS storage_id,
                    quota.quota_name as quota_name, vm_templates.is_disabled, vm_templates.min_allocated_mem, vm_templates.is_run_and_pause, vm_templates.created_by_user_id,
                    vm_templates.migration_downtime,
                    vm_templates.entity_type, vds_groups.architecture,
                    vm_templates.template_version_number as template_version_number, vm_templates.vmt_guid as base_template_id,
                    vm_templates.template_version_name as template_version_name,
                    vm_templates.serial_number_policy as serial_number_policy, vm_templates.custom_serial_number as custom_serial_number,
                    vm_templates.is_boot_menu_enabled as is_boot_menu_enabled,
                    vm_templates.is_spice_file_transfer_enabled as is_spice_file_transfer_enabled, vm_templates.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled,
                    vm_templates.cpu_profile_id as cpu_profile_id, vm_templates.numatune_mode as numatune_mode
FROM                  vm_static AS vm_templates LEFT OUTER JOIN
	                  vds_groups ON vm_templates.vds_group_id = vds_groups.vds_group_id LEFT OUTER JOIN
                      storage_pool ON storage_pool.id = vds_groups.storage_pool_id INNER JOIN
                      vm_device ON vm_device.vm_id = vm_templates.vm_guid LEFT JOIN
	                  images ON images.image_group_id = vm_device.device_id
	                  LEFT JOIN image_storage_domain_map ON image_storage_domain_map.image_id = images.image_guid
                          LEFT OUTER JOIN quota quota on quota.id = vm_templates.quota_id
WHERE      entity_type = 'TEMPLATE' OR entity_type = 'INSTANCE_TYPE' OR entity_type = 'IMAGE_TYPE'
UNION
SELECT                vm_templates_1.vm_guid AS vmt_guid, vm_templates_1.vm_name AS name, vm_templates_1.mem_size_mb, vm_templates_1.os, vm_templates_1.creation_date,
                      vm_templates_1.child_count, vm_templates_1.num_of_sockets, vm_templates_1.cpu_per_socket,
                      vm_templates_1.num_of_sockets*vm_templates_1.cpu_per_socket AS num_of_cpus, vm_templates_1.description, vm_templates_1.free_text_comment, vm_templates_1.vds_group_id,
                      vm_templates_1.num_of_monitors, vm_templates_1.single_qxl_pci, vm_templates_1.allow_console_reconnect, vm_templates_1.template_status AS status, vm_templates_1.usb_policy, vm_templates_1.time_zone,
                      vm_templates_1.fail_back, vds_groups_1.name AS vds_group_name, vm_templates_1.vm_type,
                      vm_templates_1.nice_level, vm_templates_1.cpu_shares, storage_pool_1.id AS storage_pool_id,
                      storage_pool_1.name AS storage_pool_name, vm_templates_1.default_boot_sequence, vm_templates_1.default_display_type,
                      vm_templates_1.priority, vm_templates_1.auto_startup, vm_templates_1.is_stateless, vm_templates_1.iso_path, vm_templates_1.origin,
                      vm_templates_1.initrd_url, vm_templates_1.kernel_url, vm_templates_1.kernel_params,
                      image_storage_domain_map.storage_domain_id AS storage_id,
                      quota.quota_name as quota_name, vm_templates_1.is_disabled, vm_templates_1.min_allocated_mem, vm_templates_1.is_run_and_pause, vm_templates_1.created_by_user_id,
                      vm_templates_1.migration_downtime,
                      vm_templates_1.entity_type, vds_groups_1.architecture,
                      vm_templates_1.template_version_number as template_version_number, vm_templates_1.vmt_guid as base_template_id,
                      vm_templates_1.template_version_name as template_version_name,
                      vm_templates_1.serial_number_policy as serial_number_policy,
                      vm_templates_1.custom_serial_number as custom_serial_number,
                      vm_templates_1.is_boot_menu_enabled as is_boot_menu_enabled,
                      vm_templates_1.is_spice_file_transfer_enabled as is_spice_file_transfer_enabled,
                      vm_templates_1.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled,
                      vm_templates_1.cpu_profile_id as cpu_profile_id,
                      vm_templates_1.numatune_mode as numatune_mode
FROM                  vm_static AS vm_templates_1 LEFT OUTER JOIN
                      vds_groups AS vds_groups_1 ON vm_templates_1.vds_group_id = vds_groups_1.vds_group_id LEFT OUTER JOIN
                      storage_pool AS storage_pool_1 ON storage_pool_1.id = vds_groups_1.storage_pool_id INNER JOIN
                      vm_device AS vm_device_1 ON vm_device_1.vm_id = vm_templates_1.vm_guid INNER JOIN
                      images AS images_1 ON images_1.image_group_id = vm_device_1.device_id INNER JOIN
                      image_storage_domain_map ON image_storage_domain_map.image_id = images_1.image_guid
                      LEFT OUTER JOIN quota quota on quota.id = vm_templates_1.quota_id
WHERE                 entity_type = 'TEMPLATE' OR entity_type = 'INSTANCE_TYPE' OR entity_type = 'IMAGE_TYPE';
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW instance_types_view
AS
	SELECT * from vm_templates_view where entity_type = 'INSTANCE_TYPE';
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW instance_types_storage_domain
AS
	SELECT * from vm_templates_storage_domain where entity_type = 'INSTANCE_TYPE';
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW image_types_view
AS
	SELECT * from vm_templates_view where entity_type = 'IMAGE_TYPE';
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW image_types_storage_domain
AS
	SELECT * from vm_templates_storage_domain where entity_type = 'IMAGE_TYPE';
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vm_pool_map_view
AS
SELECT
vm_pool_map.vm_guid as vm_guid,
vm_pool_map.vm_pool_id as vm_pool_id,
vm_pools.vm_pool_name as vm_pool_name,
vm_pools.spice_proxy as vm_pool_spice_proxy
from vm_pool_map
INNER JOIN vm_pools
ON vm_pool_map.vm_pool_id = vm_pools.vm_pool_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW tags_vm_pool_map_view
AS
SELECT		tags.tag_id as tag_id,
			tags.tag_name as tag_name,
			tags.parent_id as parent_id,
			tags.readonly as readonly, tags.type as type,
			tags_vm_pool_map.vm_pool_id as vm_pool_id
FROM        tags INNER JOIN
tags_vm_pool_map ON tags.tag_id = tags_vm_pool_map.tag_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW tags_vm_map_view
AS
SELECT     tags.tag_id as tag_id,
		   tags.tag_name as tag_name,
		   tags.parent_id as parent_id,
		   tags.readonly as readonly,
		   tags.type as type,
           tags_vm_map.vm_id as vm_id
FROM       tags INNER JOIN
tags_vm_map ON tags.tag_id = tags_vm_map.tag_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW tags_vds_map_view
AS
SELECT     tags.tag_id as tag_id,
		   tags.tag_name as tag_name,
		   tags.parent_id as parent_id,
		   tags.readonly as readonly,
		   tags.type as type,
           tags_vds_map.vds_id as vds_id
FROM       tags INNER JOIN
tags_vds_map ON tags.tag_id = tags_vds_map.tag_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW tags_user_map_view
AS
SELECT     tags.tag_id as tag_id,
           tags.tag_name as tag_name,
		   tags.parent_id as parent_id,
		   tags.readonly as readonly,
		   tags.type as type,
           tags_user_map.user_id as user_id
FROM       tags INNER JOIN
tags_user_map ON tags.tag_id = tags_user_map.tag_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW tags_user_group_map_view
AS
SELECT     tags.tag_id as tag_id,
			tags.tag_name as tag_name,
			tags.parent_id as parent_id,
			tags.readonly as readonly,
		   tags.type as type,
			 tags_user_group_map.group_id as group_id
FROM         tags_user_group_map INNER JOIN
tags ON tags_user_group_map.tag_id = tags.tag_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vms
AS
SELECT     vm_static.vm_name as vm_name, vm_static.mem_size_mb as vm_mem_size_mb, vm_static.nice_level as nice_level, vm_static.cpu_shares as cpu_shares,
                      vm_static.vmt_guid as vmt_guid, vm_static.os as vm_os, vm_static.description as vm_description, vm_static.free_text_comment as vm_comment, vm_static.vds_group_id as vds_group_id,
                      vm_static.creation_date as vm_creation_date, vm_static.auto_startup as auto_startup, vm_static.is_stateless as is_stateless,
                      vm_static.is_smartcard_enabled as is_smartcard_enabled, vm_static.is_delete_protected as is_delete_protected, vm_static.sso_method as sso_method, vm_static.dedicated_vm_for_vds as dedicated_vm_for_vds,
                      vm_static.fail_back as fail_back, vm_static.default_boot_sequence as default_boot_sequence, vm_static.vm_type as vm_type, vm_pool_map_view.vm_pool_spice_proxy as vm_pool_spice_proxy,
                      vds_groups.name as vds_group_name, vds_groups.transparent_hugepages as transparent_hugepages, vds_groups.trusted_service as trusted_service,
                      storage_pool.id as storage_pool_id, storage_pool.name as storage_pool_name,
                      vds_groups.description as vds_group_description, vds_groups.spice_proxy as vds_group_spice_proxy, vm_templates.vm_name as vmt_name,
                      vm_templates.mem_size_mb as vmt_mem_size_mb, vm_templates.os as vmt_os, vm_templates.creation_date as vmt_creation_date,
                      vm_templates.child_count as vmt_child_count, vm_templates.num_of_sockets as vmt_num_of_sockets,
                      vm_templates.cpu_per_socket as vmt_cpu_per_socket, vm_templates.num_of_sockets*vm_templates.cpu_per_socket as vmt_num_of_cpus,
                      vm_templates.description as vmt_description, vm_dynamic.status as status, vm_dynamic.vm_ip as vm_ip, vm_dynamic.vm_host as vm_host,
                      vm_dynamic.vm_pid as vm_pid, vm_dynamic.last_start_time as last_start_time, vm_dynamic.guest_cur_user_name as guest_cur_user_name, vm_dynamic.console_cur_user_name as console_cur_user_name,
                      vm_dynamic.guest_last_login_time as guest_last_login_time, vm_dynamic.guest_last_logout_time as guest_last_logout_time, vm_dynamic.guest_os as guest_os,
                      vm_dynamic.console_user_id as console_user_id, vm_dynamic.guest_agent_nics_hash as guest_agent_nics_hash,
                      vm_dynamic.run_on_vds as run_on_vds, vm_dynamic.migrating_to_vds as migrating_to_vds, vm_dynamic.app_list as app_list, vm_dynamic.display as display, vm_dynamic.hibernation_vol_handle as hibernation_vol_handle,
                      vm_pool_map_view.vm_pool_name as vm_pool_name, vm_pool_map_view.vm_pool_id as vm_pool_id, vm_static.vm_guid as vm_guid, vm_static.num_of_monitors as num_of_monitors, vm_static.single_qxl_pci as single_qxl_pci, vm_static.allow_console_reconnect as allow_console_reconnect, vm_static.is_initialized as is_initialized,
                      vm_static.num_of_sockets as num_of_sockets, vm_static.cpu_per_socket as cpu_per_socket, vm_static.usb_policy as usb_policy, vm_dynamic.acpi_enable as acpi_enable, vm_dynamic.session as session,
                      vm_static.num_of_sockets*vm_static.cpu_per_socket as num_of_cpus,
                      vm_static.quota_id as quota_id, quota.quota_name as quota_name, storage_pool.quota_enforcement_type as quota_enforcement_type,
                      vm_dynamic.display_ip as display_ip, vm_dynamic.display_type as display_type, vm_dynamic.kvm_enable as kvm_enable, vm_dynamic.boot_sequence as boot_sequence,
                      vm_dynamic.display_secure_port as display_secure_port, vm_dynamic.utc_diff as utc_diff, vm_dynamic.last_vds_run_on as last_vds_run_on,
					  vm_dynamic.client_ip as client_ip,vm_dynamic.guest_requested_memory as guest_requested_memory, vm_static.time_zone as time_zone, vm_statistics.cpu_user as cpu_user, vm_statistics.cpu_sys as cpu_sys,
                      vm_statistics.elapsed_time as elapsed_time, vm_statistics.usage_network_percent as usage_network_percent,
                      vm_statistics.usage_mem_percent as usage_mem_percent, vm_statistics.migration_progress_percent as migration_progress_percent, vm_statistics.usage_cpu_percent as usage_cpu_percent, vds_static.vds_name as run_on_vds_name, vds_groups.cpu_name as vds_group_cpu_name,
                      vm_static.default_display_type as default_display_type, vm_static.priority as priority,vm_static.iso_path as iso_path, vm_static.origin as origin, vds_groups.compatibility_version as vds_group_compatibility_version,
                      vm_static.initrd_url as initrd_url, vm_static.kernel_url as kernel_url, vm_static.kernel_params as kernel_params, vm_dynamic.pause_status as pause_status, vm_dynamic.exit_message as exit_message, vm_dynamic.exit_status as exit_status,vm_static.migration_support as migration_support,vm_static.predefined_properties as predefined_properties,vm_static.userdefined_properties as userdefined_properties,vm_static.min_allocated_mem as min_allocated_mem,  vm_dynamic.hash as hash, vm_static.cpu_pinning as cpu_pinning, vm_static.db_generation as db_generation, vm_static.host_cpu_flags as host_cpu_flags,
                      vm_static.tunnel_migration as tunnel_migration, vm_static.vnc_keyboard_layout as vnc_keyboard_layout, vm_static.is_run_and_pause as is_run_and_pause, vm_static.created_by_user_id as created_by_user_id,
                      vm_dynamic.last_watchdog_event as last_watchdog_event, vm_dynamic.last_watchdog_action as last_watchdog_action, vm_dynamic.is_run_once as is_run_once, vm_dynamic.vm_fqdn as vm_fqdn, vm_dynamic.cpu_name as cpu_name, vm_dynamic.current_cd as current_cd, vm_dynamic.reason as reason, vm_dynamic.exit_reason as exit_reason,
                      vm_static.instance_type_id as instance_type_id, vm_static.image_type_id as image_type_id, vds_groups.architecture as architecture, vm_static.original_template_id as original_template_id, vm_static.original_template_name as original_template_name, vm_dynamic.last_stop_time as last_stop_time,
                      vm_static.migration_downtime as migration_downtime, vm_static.template_version_number as template_version_number,
                      vm_static.serial_number_policy as serial_number_policy, vm_static.custom_serial_number as custom_serial_number,
                      vm_static.is_boot_menu_enabled as is_boot_menu_enabled, vm_dynamic.guest_cpu_count as guest_cpu_count,
                      (snapshots.snapshot_id is not null) as next_run_config_exists,
                      vm_static.numatune_mode as numatune_mode,
                      vm_static.is_spice_file_transfer_enabled as is_spice_file_transfer_enabled, vm_static.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled,
                      vm_static.cpu_profile_id as cpu_profile_id
FROM         vm_static INNER JOIN
vm_dynamic ON vm_static.vm_guid = vm_dynamic.vm_guid INNER JOIN
vm_static AS vm_templates ON vm_static.vmt_guid = vm_templates.vm_guid INNER JOIN
vm_statistics ON vm_static.vm_guid = vm_statistics.vm_guid INNER JOIN
vds_groups ON vm_static.vds_group_id = vds_groups.vds_group_id LEFT OUTER JOIN
storage_pool ON vm_static.vds_group_id = vds_groups.vds_group_id
and vds_groups.storage_pool_id = storage_pool.id LEFT OUTER JOIN
quota ON vm_static.quota_id = quota.id LEFT OUTER JOIN
vds_static ON vm_dynamic.run_on_vds = vds_static.vds_id LEFT OUTER JOIN
vm_pool_map_view ON vm_static.vm_guid = vm_pool_map_view.vm_guid
left outer join snapshots on vm_static.vm_guid = snapshots.vm_id and snapshot_type='NEXT_RUN'
WHERE vm_static.entity_type = 'VM';
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vms_with_tags
AS
SELECT      vms.vm_name, vms.vm_mem_size_mb, vms.nice_level, vms.cpu_shares, vms.vmt_guid, vms.vm_os, vms.vm_description, vms.vm_comment,
            vms.vds_group_id, vms.vm_creation_date, vms.auto_startup, vms.is_stateless, vms.is_smartcard_enabled, vms.is_delete_protected,
            vms.sso_method, vms.dedicated_vm_for_vds, vms.fail_back, vms.default_boot_sequence, vms.vm_type,
            vms.vds_group_name, vms.storage_pool_id, vms.storage_pool_name,
            vms.vds_group_description, vms.vmt_name, vms.vmt_mem_size_mb, vms.vmt_os, vms.vmt_creation_date,
            vms.vmt_child_count, vms.vmt_num_of_sockets, vms.vmt_cpu_per_socket, vms.vmt_description, vms.status, vms.vm_ip,
            vms.vm_host, vms.vmt_num_of_sockets * vms.vmt_cpu_per_socket AS vmt_num_of_cpus, vms.vm_pid,
            vms.last_start_time, vms.last_stop_time, vms.guest_cur_user_name, vms.console_cur_user_name, vms.guest_last_login_time, vms.console_user_id,
            vms.guest_last_logout_time, vms.guest_os, vms.run_on_vds, vms.migrating_to_vds, vms.app_list, vms.display,
            vms.hibernation_vol_handle, vms.vm_pool_name, vms.vm_pool_id, vms.vm_guid, vms.num_of_monitors, vms.single_qxl_pci,
            vms.allow_console_reconnect,
            vms.is_initialized, vms.num_of_sockets, vms.cpu_per_socket, vms.usb_policy, vms.acpi_enable,
            vms.session, vms.num_of_sockets * vms.cpu_per_socket AS num_of_cpus, vms.display_ip, vms.display_type,
            vms.kvm_enable, vms.boot_sequence, vms.display_secure_port, vms.utc_diff, vms.last_vds_run_on, vms.client_ip,
            vms.guest_requested_memory, vms.time_zone, vms.cpu_user, vms.cpu_sys, vms.elapsed_time,
            vms.usage_network_percent, vms.usage_mem_percent, vms.migration_progress_percent, vms.usage_cpu_percent, vms.run_on_vds_name,
            vms.vds_group_cpu_name, tags_vm_map_view.tag_name, tags_vm_map_view.tag_id, vms.default_display_type, vms.priority,
            vms.vds_group_compatibility_version, vms.initrd_url, vms.kernel_url, vms.kernel_params, vms.pause_status,
            vms.exit_status, vms.exit_message, vms.min_allocated_mem, storage_domain_static.id AS storage_id,
            vms.quota_id as quota_id, vms.quota_name as quota_name, vms.tunnel_migration as tunnel_migration,
            vms.vnc_keyboard_layout as vnc_keyboard_layout, vms.is_run_and_pause as is_run_and_pause, vms.created_by_user_id as created_by_user_id, vms.vm_fqdn, vms.cpu_name as cpu_name,
            vms.vm_pool_spice_proxy as vm_pool_spice_proxy, vms.vds_group_spice_proxy as vds_group_spice_proxy,
            vms.instance_type_id as instance_type_id, vms.image_type_id as image_type_id, vms.architecture as architecture, vms.original_template_id as original_template_id, vms.original_template_name as original_template_name,
            vms.migration_downtime as migration_downtime, vms.template_version_number as template_version_number,
            vms.current_cd as current_cd, vms.reason as reason,
            vms.serial_number_policy as serial_number_policy, vms.custom_serial_number as custom_serial_number, vms.exit_reason as exit_reason,
            vms.is_boot_menu_enabled as is_boot_menu_enabled, vms.guest_cpu_count as guest_cpu_count,
            (snapshots.snapshot_id is not null) as next_run_config_exists,
            vms.numatune_mode,
            vms.is_spice_file_transfer_enabled, vms.is_spice_copy_paste_enabled,
            vms.cpu_profile_id
FROM        vms LEFT OUTER JOIN
            tags_vm_map_view ON vms.vm_guid = tags_vm_map_view.vm_id LEFT OUTER JOIN
            vm_device ON vm_device.vm_id = vms.vm_guid LEFT OUTER JOIN
            images ON images.image_group_id = vm_device.device_id LEFT OUTER JOIN
            image_storage_domain_map ON image_storage_domain_map.image_id = images.image_guid LEFT OUTER JOIN
            storage_domain_static ON storage_domain_static.id = image_storage_domain_map.storage_domain_id
            left outer join snapshots on vms.vm_guid = snapshots.vm_id and snapshot_type='NEXT_RUN'
WHERE       images.active IS NULL OR images.active = TRUE;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW server_vms
as
SELECT * FROM vms
WHERE vm_type = '1';
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vms_with_plug_info
as
SELECT *
FROM vms
INNER JOIN vm_device vd ON vd.vm_id = vms.vm_guid;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW desktop_vms
as
SELECT * FROM vms
WHERE vm_type = '0';
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vds
as
SELECT     vds_groups.vds_group_id as vds_group_id, vds_groups.name as vds_group_name, vds_groups.description as vds_group_description, vds_groups.architecture as architecture,
                      vds_static.vds_id as vds_id, vds_static.vds_name as vds_name, vds_static.ip as ip, vds_static.vds_unique_id as vds_unique_id,
                      vds_static.host_name as host_name, vds_static.free_text_comment as free_text_comment,
                      vds_static.port as port, vds_static.vds_strength as vds_strength, vds_static.server_SSL_enabled as server_SSL_enabled, vds_static.vds_type as vds_type,
                      vds_static.pm_type as pm_type, vds_static.pm_user as pm_user, vds_static.pm_password as pm_password, vds_static.pm_port as pm_port,
                      vds_static.pm_options as pm_options, vds_static.pm_enabled as pm_enabled,
                      vds_static.pm_proxy_preferences as pm_proxy_preferences,vds_static.pm_secondary_ip as pm_secondary_ip,
                      vds_static.pm_secondary_options as pm_secondary_options, vds_static.pm_secondary_port as pm_secondary_port,
                      vds_static.pm_secondary_password as pm_secondary_password, vds_static.pm_secondary_user as pm_secondary_user,
                      vds_static.pm_secondary_type as pm_secondary_type, vds_static.pm_secondary_concurrent as pm_secondary_concurrent, vds_static.pm_detect_kdump as pm_detect_kdump,
                      vds_static.vds_spm_priority as vds_spm_priority, vds_dynamic.hooks as hooks,vds_dynamic.status as status,
                      vds_dynamic.cpu_cores as cpu_cores, vds_dynamic.cpu_threads as cpu_threads, vds_dynamic.cpu_model as cpu_model, vds_dynamic.cpu_speed_mh as cpu_speed_mh,
                      vds_dynamic.if_total_speed as if_total_speed, vds_dynamic.kvm_enabled as kvm_enabled, vds_dynamic.physical_mem_mb as physical_mem_mb,
                      vds_dynamic.pending_vcpus_count as pending_vcpus_count, vds_dynamic.pending_vmem_size as pending_vmem_size,vds_dynamic.mem_commited as mem_commited, vds_dynamic.vm_active as vm_active, vds_dynamic.vm_count as vm_count,
                      vds_dynamic.vm_migrating as vm_migrating, vds_dynamic.vms_cores_count as vms_cores_count, vds_dynamic.cpu_over_commit_time_stamp as cpu_over_commit_time_stamp,
                      vds_groups.max_vds_memory_over_commit as max_vds_memory_over_commit, vds_dynamic.net_config_dirty as net_config_dirty, vds_groups.count_threads_as_cores as count_threads_as_cores,
                      storage_pool.id as storage_pool_id, storage_pool.name as storage_pool_name, vds_dynamic.reserved_mem as reserved_mem,
                      vds_dynamic.guest_overhead as guest_overhead, vds_dynamic.rpm_version as rpm_version, vds_dynamic.software_version as software_version, vds_dynamic.version_name as version_name, vds_dynamic.build_name as build_name,
                      vds_dynamic.previous_status as previous_status, vds_statistics.cpu_idle as cpu_idle, vds_statistics.cpu_load as cpu_load, vds_statistics.cpu_sys as cpu_sys, vds_statistics.cpu_user as cpu_user,
                      vds_statistics.usage_mem_percent as usage_mem_percent, vds_statistics.usage_cpu_percent as usage_cpu_percent, vds_statistics.usage_network_percent as usage_network_percent,
                      vds_statistics.mem_available as mem_available, vds_statistics.mem_free as mem_free, vds_statistics.mem_shared as mem_shared, vds_statistics.swap_free as swap_free,
					  vds_statistics.swap_total as swap_total,  vds_statistics.ksm_cpu_percent as ksm_cpu_percent,  vds_statistics.ksm_pages as ksm_pages,  vds_statistics.ksm_state as ksm_state,
                      vds_dynamic.cpu_flags as cpu_flags,vds_groups.cpu_name as vds_group_cpu_name, vds_dynamic.cpu_sockets as cpu_sockets, vds_spm_id_map.vds_spm_id as vds_spm_id, vds_static.otp_validity as otp_validity,
                      CASE WHEN storage_pool.spm_vds_id = vds_static.vds_id THEN CASE WHEN storage_pool.status = 5 THEN 1 ELSE 2 END ELSE 0 END as spm_status, vds_dynamic.supported_cluster_levels as supported_cluster_levels, vds_dynamic.supported_engines as supported_engines, vds_groups.compatibility_version as vds_group_compatibility_version,
                      vds_groups.virt_service as vds_group_virt_service, vds_groups.gluster_service as vds_group_gluster_service,
                      vds_dynamic.host_os as host_os, vds_dynamic.kvm_version as kvm_version, vds_dynamic.libvirt_version as libvirt_version, vds_dynamic.spice_version as spice_version, vds_dynamic.gluster_version as gluster_version, vds_dynamic.kernel_version as kernel_version, vds_dynamic.iscsi_initiator_name as iscsi_initiator_name,
                      vds_dynamic.transparent_hugepages_state as transparent_hugepages_state, vds_statistics.anonymous_hugepages as anonymous_hugepages, vds_dynamic.non_operational_reason as non_operational_reason,
			vds_static.recoverable as recoverable, vds_static.sshKeyFingerprint as sshKeyFingerprint, vds_static.host_provider_id as host_provider_id, vds_dynamic.hw_manufacturer as hw_manufacturer, vds_dynamic.hw_product_name as hw_product_name, vds_dynamic.hw_version as hw_version,
                      vds_dynamic.hw_serial_number as hw_serial_number, vds_dynamic.hw_uuid as hw_uuid, vds_dynamic.hw_family as hw_family, vds_static.console_address as console_address,
                      vds_dynamic.hbas as hbas, vds_dynamic.supported_emulated_machines as supported_emulated_machines, vds_dynamic.supported_rng_sources as supported_rng_sources, vds_static.ssh_port as ssh_port, vds_static.ssh_username as ssh_username, vds_statistics.ha_score as ha_score,
                      vds_statistics.ha_configured as ha_configured, vds_statistics.ha_active as ha_active, vds_statistics.ha_global_maintenance as ha_global_maintenance,
                      vds_statistics.ha_local_maintenance as ha_local_maintenance, vds_static.disable_auto_pm as disable_auto_pm, vds_dynamic.controlled_by_pm_policy as controlled_by_pm_policy, vds_statistics.boot_time as boot_time,
                      vds_dynamic.kdump_status as kdump_status, vds_dynamic.selinux_enforce_mode as selinux_enforce_mode,
                      vds_dynamic.auto_numa_balancing as auto_numa_balancing, vds_dynamic.is_numa_supported as is_numa_supported, vds_dynamic.is_live_snapshot_supported as is_live_snapshot_supported, vds_static.protocol as protocol,
                      vds_dynamic.is_live_merge_supported as is_live_merge_supported
FROM         vds_groups INNER JOIN
vds_static ON vds_groups.vds_group_id = vds_static.vds_group_id INNER JOIN
vds_dynamic ON vds_static.vds_id = vds_dynamic.vds_id INNER JOIN
vds_statistics ON vds_static.vds_id = vds_statistics.vds_id LEFT OUTER JOIN
storage_pool ON vds_groups.storage_pool_id = storage_pool.id LEFT OUTER JOIN
vds_spm_id_map ON vds_static.vds_id = vds_spm_id_map.vds_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vds_with_tags
as
SELECT     vds_groups.vds_group_id, vds_groups.name AS vds_group_name, vds_groups.description AS vds_group_description, vds_groups.architecture as architecture,
                      vds_static.vds_id, vds_static.vds_name, vds_static.ip, vds_static.vds_unique_id,
                      vds_static.host_name, vds_static.free_text_comment, vds_static.port, vds_static.vds_strength, vds_static.server_SSL_enabled, vds_static.vds_type,
                      vds_static.pm_type, vds_static.pm_user, vds_static.pm_password, vds_static.pm_port,
                      vds_dynamic.hw_product_name, vds_dynamic.hw_version, vds_dynamic.hw_serial_number, vds_dynamic.hw_uuid, vds_dynamic.hw_family,
                      vds_static.pm_options, vds_static.pm_enabled, vds_static.pm_proxy_preferences as pm_proxy_preferences,
                      vds_static.pm_secondary_ip as pm_secondary_ip,
                      vds_static.pm_secondary_options as pm_secondary_options, vds_static.pm_secondary_port as pm_secondary_port,
                      vds_static.pm_secondary_password as pm_secondary_password, vds_static.pm_secondary_user as pm_secondary_user,
                      vds_static.pm_secondary_type as pm_secondary_type, vds_static.pm_secondary_concurrent as pm_secondary_concurrent, vds_static.pm_detect_kdump as pm_detect_kdump,
                      vds_dynamic.hooks, vds_dynamic.status, vds_dynamic.cpu_cores,
                      vds_dynamic.cpu_threads, vds_dynamic.cpu_model, vds_dynamic.cpu_speed_mh, vds_dynamic.if_total_speed, vds_dynamic.kvm_enabled,
                      vds_dynamic.physical_mem_mb, vds_dynamic.pending_vcpus_count, vds_dynamic.pending_vmem_size,
                      vds_dynamic.mem_commited, vds_dynamic.vm_active, vds_dynamic.vm_count, vds_dynamic.vm_migrating,
                      vds_dynamic.vms_cores_count, vds_dynamic.cpu_over_commit_time_stamp,
                      vds_dynamic.net_config_dirty, vds_groups.max_vds_memory_over_commit, vds_groups.count_threads_as_cores,
                      storage_pool.id AS storage_pool_id, storage_pool.name AS storage_pool_name, tags_vds_map_view.tag_name,
                      tags_vds_map_view.tag_id, vds_dynamic.reserved_mem, vds_dynamic.guest_overhead, vds_dynamic.rpm_version, vds_dynamic.software_version,
                      vds_dynamic.version_name, vds_dynamic.build_name, vds_dynamic.previous_status, vds_statistics.cpu_idle,
                      vds_statistics.cpu_load, vds_statistics.cpu_sys, vds_statistics.cpu_user, vds_statistics.usage_mem_percent,
                      vds_statistics.usage_cpu_percent, vds_statistics.usage_network_percent, vds_statistics.mem_available, vds_statistics.mem_free,
                      vds_statistics.mem_shared, vds_statistics.swap_free, vds_statistics.swap_total, vds_statistics.ksm_cpu_percent,
                      vds_statistics.ksm_pages, vds_statistics.ksm_state, vds_dynamic.cpu_flags, vds_groups.cpu_name AS vds_group_cpu_name,
                      vds_dynamic.cpu_sockets, vds_spm_id_map.vds_spm_id, vds_static.otp_validity as otp_validity, vds_static.console_address as console_address,
                      CASE WHEN storage_pool.spm_vds_id = vds_static.vds_id THEN CASE WHEN storage_pool.status = 5 THEN 1 ELSE 2 END ELSE 0 END AS
spm_status, vds_dynamic.supported_cluster_levels, vds_dynamic.supported_engines,
                      vds_groups.compatibility_version AS vds_group_compatibility_version, vds_dynamic.host_os, vds_dynamic.kvm_version, vds_dynamic.libvirt_version,
                      vds_dynamic.spice_version, vds_dynamic.gluster_version, vds_dynamic.kernel_version, vds_dynamic.iscsi_initiator_name,
                      vds_dynamic.transparent_hugepages_state, vds_statistics.anonymous_hugepages, vds_dynamic.non_operational_reason,
                      storage_pool_iso_map.storage_id, vds_static.ssh_port, vds_static.ssh_username, vds_statistics.ha_score,
                      vds_statistics.ha_configured, vds_statistics.ha_active, vds_statistics.ha_global_maintenance, vds_statistics.ha_local_maintenance,
                      vds_static.disable_auto_pm as disable_auto_pm, vds_dynamic.controlled_by_pm_policy as controlled_by_pm_policy,
                      vds_statistics.boot_time, vds_dynamic.kdump_status as kdump_status, vds_dynamic.selinux_enforce_mode as selinux_enforce_mode,
                      vds_dynamic.auto_numa_balancing as auto_numa_balancing, vds_dynamic.is_numa_supported as is_numa_supported,
                      vds_dynamic.supported_rng_sources as supported_rng_sources,
                      vds_dynamic.is_live_snapshot_supported as is_live_snapshot_supported, vds_static.protocol as protocol,
                      vds_dynamic.is_live_merge_supported as is_live_merge_supported
FROM         vds_groups INNER JOIN
vds_static ON vds_groups.vds_group_id = vds_static.vds_group_id INNER JOIN
vds_dynamic ON vds_static.vds_id = vds_dynamic.vds_id INNER JOIN
vds_statistics ON vds_static.vds_id = vds_statistics.vds_id LEFT OUTER JOIN
storage_pool ON vds_groups.storage_pool_id = storage_pool.id LEFT OUTER JOIN
tags_vds_map_view ON vds_static.vds_id = tags_vds_map_view.vds_id LEFT OUTER JOIN
vds_spm_id_map ON vds_static.vds_id = vds_spm_id_map.vds_id LEFT OUTER JOIN
storage_pool_iso_map ON storage_pool_iso_map.storage_pool_id = storage_pool.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW users_and_groups_to_vm_pool_map_view
AS
select	p.vm_pool_id as vm_pool_id, p.vm_pool_name as vm_pool_name, per.ad_element_id as user_id
FROM    vm_pools AS p
INNER JOIN permissions as per on per.object_id = p.vm_pool_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vdc_users
AS
SELECT     'user' as user_group, users_1.name as name, users_1.user_id as user_id, users_1.surname as surname, users_1.domain as domain, users_1.username as username, users_1.groups as groups, users_1.department as department,
                      users_1.role as role, users_1.email as email, users_1.note as note, users_1.active as active, 0 as vm_admin,
                      users_1.last_admin_check_status as last_admin_check_status, users_1.group_ids as group_ids,
                      users_1.external_id as external_id, users_1.namespace as namespace
FROM         users AS users_1
UNION
SELECT     'group' as user_group, ad_groups.name as name, ad_groups.id as id, '' as surname, ad_groups.domain as domain, '' as username, '' as groups, '' as department, '' as role,
                      '' as email, '' as note, true as active, 1 as vm_admin, null as last_admin_check_status, '' as group_ids,
                      ad_groups.external_id as external_id, ad_groups.namespace as namespace
FROM         ad_groups;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vdc_users_with_tags
AS
SELECT     users_1.user_group as user_group, users_1.name as name, permissions.object_id as vm_guid, users_1.user_id as user_id, users_1.surname as surname, users_1.domain as domain,
                      users_1.username as username, users_1.groups as groups, users_1.department as department, users_1.role as role, roles1.name as mla_role, users_1.email as email,
                      users_1.note as note, users_1.active as active, users_1.vm_admin as vm_admin, tags_user_map_view_1.tag_name as tag_name, tags_user_map_view_1.tag_id as tag_id, users_1.last_admin_check_status as last_admin_check_status, users_1.group_ids as group_ids,
                      pools.vm_pool_name as vm_pool_name
FROM         vdc_users AS users_1 LEFT OUTER JOIN
users_and_groups_to_vm_pool_map_view AS pools ON users_1.user_id = pools.user_id LEFT OUTER JOIN
permissions ON users_1.user_id = permissions.ad_element_id LEFT OUTER JOIN
tags ON tags.type = 1 LEFT OUTER JOIN
tags_user_map_view AS tags_user_map_view_1 ON users_1.user_id = tags_user_map_view_1.user_id LEFT OUTER JOIN
roles AS roles1 ON roles1.id = permissions.role_id
WHERE     (users_1.user_group = 'user')
UNION
SELECT     users_2.user_group as user_group, users_2.name as name, permissions_1.object_id as vm_guid, users_2.user_id as user_id, users_2.surname as surname, users_2.domain as domain,
                      users_2.username as username, users_2.groups as groups, users_2.department as department, users_2.role as role, roles2.name as mla_role, users_2.email as email,
                      users_2.note as note, users_2.active as active, users_2.vm_admin as vm_admin, tags_user_group_map_view.tag_name as tag_name, tags_user_group_map_view.tag_id as tag_id,
                      users_2.last_admin_check_status as last_admin_check_status, users_2.group_ids as group_ids , pools1.vm_pool_name as vm_pool_name
FROM         vdc_users AS users_2 LEFT OUTER JOIN
users_and_groups_to_vm_pool_map_view AS pools1 ON users_2.user_id = pools1.user_id LEFT OUTER JOIN
permissions AS permissions_1 ON users_2.user_id = permissions_1.ad_element_id LEFT OUTER JOIN
tags AS tags_1 ON tags_1.type = 1 LEFT OUTER JOIN
tags_user_group_map_view ON users_2.user_id = tags_user_group_map_view.group_id LEFT OUTER JOIN
roles AS roles2 ON roles2.id = permissions_1.role_id
WHERE     (users_2.user_group = 'group');
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vm_pools_view AS
 SELECT vm_pools.vm_pool_id, vm_pools.vm_pool_name, vm_pools.vm_pool_description, vm_pools.vm_pool_comment, vm_pools.vm_pool_type, vm_pools.parameters, vm_pools.prestarted_vms, vm_pools.vds_group_id, vds_groups.name AS vds_group_name, vds_groups.architecture AS architecture, storage_pool.name as storage_pool_name, storage_pool.id as storage_pool_id, vm_pools.max_assigned_vms_per_user as max_assigned_vms_per_user,
 vm_pools.spice_proxy as spice_proxy
   FROM vm_pools
   JOIN vds_groups ON vm_pools.vds_group_id = vds_groups.vds_group_id
   LEFT JOIN storage_pool ON storage_pool.id = vds_groups.storage_pool_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vm_pools_full_view AS
 SELECT vmp.vm_pool_id, vmp.vm_pool_name, vmp.vm_pool_description, vmp.vm_pool_comment, vmp.vm_pool_type, vmp.parameters, vmp.prestarted_vms, vmp.vds_group_id, vmp.vds_group_name, vmp.architecture, vmp.max_assigned_vms_per_user, vmp.spice_proxy as spice_proxy, ( SELECT count(vm_pool_map.vm_pool_id) AS expr1
           FROM vm_pools_view v1
      LEFT JOIN vm_pool_map ON v1.vm_pool_id = vm_pool_map.vm_pool_id AND v1.vm_pool_id = vmp.vm_pool_id) AS assigned_vm_count, ( SELECT count(v2.vm_pool_id) AS expr1
           FROM vm_pools v2
      LEFT JOIN vm_pool_map vm_pool_map_1 ON v2.vm_pool_id = vm_pool_map_1.vm_pool_id AND v2.vm_pool_id = vmp.vm_pool_id
   LEFT JOIN vm_dynamic ON vm_pool_map_1.vm_guid = vm_dynamic.vm_guid
  WHERE vm_dynamic.status <> ALL (ARRAY[0, 15])
  GROUP BY v2.vm_pool_id) AS vm_running_count, vmp.storage_pool_name, vmp.storage_pool_id
   FROM vm_pools_view vmp;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW permissions_view
AS
SELECT     permissions.id as id, permissions.role_id as role_id, permissions.ad_element_id as ad_element_id, permissions.object_id as object_id, permissions.object_type_id as object_type_id,
	       roles.name as role_name, roles.role_type as role_type, roles.allows_viewing_children as allows_viewing_children, roles.app_mode as app_mode, fn_get_entity_name(permissions.object_id,permissions.object_type_id) as object_name,
			(fn_authz_entry_info(permissions.ad_element_id)).name as owner_name, (fn_authz_entry_info(permissions.ad_element_id)).namespace as namespace, (fn_authz_entry_info(permissions.ad_element_id)).authz as authz
FROM         permissions INNER JOIN
roles ON permissions.role_id = roles.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW internal_permissions_view
AS
SELECT     permissions.id as id, permissions.role_id as role_id, permissions.ad_element_id as ad_element_id, permissions.object_id as object_id, permissions.object_type_id as object_type_id,
	       roles.name as role_name, roles.role_type as role_type, roles.allows_viewing_children as allows_viewing_children
FROM         permissions
INNER JOIN roles ON permissions.role_id = roles.id;
**************************

CREATE VIEW
********* QUERY **********
/*************************************************
        vds/vm/ interface view
*************************************************/
CREATE OR REPLACE VIEW vds_interface_view AS
  SELECT vds_interface_statistics.rx_rate, vds_interface_statistics.tx_rate, vds_interface_statistics.rx_drop,
      vds_interface_statistics.tx_drop, vds_interface_statistics.iface_status, vds_interface.type, vds_interface.gateway,
      vds_interface.subnet, vds_interface.addr, vds_interface.speed, vds_interface.base_interface, vds_interface.vlan_id, vds_interface.bond_type,
      vds_interface.bond_name, vds_interface.is_bond, vds_interface.bond_opts, vds_interface.mac_addr,
      vds_interface.network_name, vds_interface.name, vds_static.vds_id, vds_static.vds_name,  vds_interface.id,
      vds_interface.boot_protocol, vds_interface.mtu as mtu, vds_interface.bridged, 1 AS is_vds, vds_interface.qos_overridden AS qos_overridden,
      vds_interface.labels as labels, vds_interface.custom_properties AS custom_properties, vds_static.vds_group_id as vds_group_id
  FROM vds_interface_statistics
  JOIN vds_interface ON vds_interface_statistics.id = vds_interface.id
  JOIN vds_static ON vds_interface.vds_id = vds_static.vds_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vm_interface_view AS
  SELECT vm_interface_statistics.rx_rate, vm_interface_statistics.tx_rate, vm_interface_statistics.rx_drop,
      vm_interface_statistics.tx_drop, vm_interface_statistics.iface_status, vm_interface.type, vm_interface.speed,
      vm_interface.mac_addr, network.name AS network_name, vm_interface.name, vm_interface.vnic_profile_id, vm_static.vm_guid, vm_interface.vmt_guid,
      vm_static.vm_name, vm_interface.id, 0 AS boot_protocol, 0 AS is_vds, vm_device.is_plugged,
      vm_device.custom_properties, vnic_profiles.port_mirroring AS port_mirroring, vm_interface.linked,
      vm_static.vds_group_id AS vds_group_id, vm_static.entity_type AS vm_entity_type, vnic_profiles.name AS vnic_profile_name
  FROM vm_interface_statistics
  JOIN vm_interface ON vm_interface_statistics.id = vm_interface.id
  JOIN vm_static ON vm_interface.vm_guid = vm_static.vm_guid
  JOIN vm_device ON vm_interface.vm_guid = vm_device.vm_id AND vm_interface.id = vm_device.device_id
  LEFT JOIN (vnic_profiles JOIN network ON network.id = vnic_profiles.network_id) ON vnic_profiles.id = vm_interface.vnic_profile_id
  UNION
  SELECT vm_interface_statistics.rx_rate, vm_interface_statistics.tx_rate, vm_interface_statistics.rx_drop,
      vm_interface_statistics.tx_drop, vm_interface_statistics.iface_status, vm_interface.type, vm_interface.speed,
      vm_interface.mac_addr, network.name AS network_name, vm_interface.name, vm_interface.vnic_profile_id, NULL::uuid as vm_guid,
      vm_interface.vmt_guid, vm_templates.vm_name AS vm_name, vm_interface.id, 0 AS boot_protocol, 0 AS is_vds,
      vm_device.is_plugged as is_plugged, vm_device.custom_properties as custom_properties, vnic_profiles.port_mirroring AS port_mirroring,
      vm_interface.linked, vm_templates.vds_group_id AS vds_group_id, vm_templates.entity_type AS vm_entity_type, vnic_profiles.name AS vnic_profile_name
  FROM vm_interface_statistics
  RIGHT JOIN vm_interface ON vm_interface_statistics.id = vm_interface.id
  JOIN vm_static AS vm_templates ON vm_interface.vmt_guid = vm_templates.vm_guid
  JOIN vm_device ON vm_interface.vmt_guid = vm_device.vm_id AND vm_interface.id = vm_device.device_id
  LEFT JOIN (vnic_profiles JOIN network ON network.id = vnic_profiles.network_id) ON vnic_profiles.id = vm_interface.vnic_profile_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW storage_pool_with_storage_domain
AS
SELECT     storage_pool.id as id, storage_pool.name as name, storage_pool.description as description, storage_pool.free_text_comment as free_text_comment, storage_pool.status as status, storage_pool.is_local as is_local,
		   storage_pool.master_domain_version as master_domain_version, storage_pool.spm_vds_id as spm_vds_id, storage_pool.compatibility_version as compatibility_version, storage_pool._create_date as _create_date,
		   storage_pool._update_date as _update_date, storage_pool_iso_map.storage_id as storage_id, storage_pool_iso_map.storage_pool_id as storage_pool_id,
		   storage_domain_static.storage_type as storage_type, storage_domain_static.storage_domain_type as storage_domain_type,
                   storage_domain_static.storage_domain_format_type as storage_domain_format_type,
		   storage_domain_static.storage_name as storage_name, storage_domain_static.storage as storage,
		   storage_domain_static.last_time_used_as_master as last_time_used_as_master
FROM         storage_pool LEFT OUTER JOIN
		   storage_pool_iso_map ON storage_pool.id = storage_pool_iso_map.storage_pool_id LEFT OUTER JOIN
		   storage_domain_static ON storage_pool_iso_map.storage_id = storage_domain_static.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vds_groups_storage_domain
AS
SELECT     vds_groups.vds_group_id, vds_groups.name, vds_groups.description, vds_groups.free_text_comment, vds_groups.cpu_name, vds_groups._create_date,
                      vds_groups._update_date, vds_groups.storage_pool_id,
                      vds_groups.max_vds_memory_over_commit, vds_groups.count_threads_as_cores, vds_groups.compatibility_version,
                      vds_groups.transparent_hugepages, vds_groups.migrate_on_error, vds_groups.architecture,
                      storage_pool_iso_map.storage_id, storage_pool.name AS storage_pool_name
FROM vds_groups
LEFT JOIN storage_pool_iso_map ON vds_groups.storage_pool_id = storage_pool_iso_map.storage_pool_id
LEFT JOIN storage_pool ON vds_groups.storage_pool_id = storage_pool.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vds_groups_view
AS
SELECT vds_groups.*,
       storage_pool.name AS storage_pool_name,
       cluster_policies.name AS cluster_policy_name
FROM vds_groups
LEFT JOIN storage_pool ON vds_groups.storage_pool_id = storage_pool.id
LEFT JOIN cluster_policies ON vds_groups.cluster_policy_id = cluster_policies.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW storage_domains_with_hosts_view
AS
SELECT
storage_domain_static.id,
		storage_domain_static.storage,
		storage_domain_static.storage_name,
		storage_domain_static.storage_description as storage_description,
		storage_domain_static.storage_comment as storage_comment,
		storage_domain_dynamic.available_disk_size,
		storage_domain_dynamic.used_disk_size,
		fn_get_disk_commited_value_by_storage(storage_domain_static.id) as commited_disk_size,
		fn_get_actual_images_size_by_storage(storage_domain_static.id) as actual_images_size,
		storage_pool.name as storage_pool_name,
		storage_domain_static.storage_type,
		storage_domain_static.storage_domain_type,
                storage_domain_static.storage_domain_format_type,
        storage_domain_static.last_time_used_as_master as last_time_used_as_master,
		fn_get_storage_domain_shared_status_by_domain_id(storage_domain_static.id,storage_pool_iso_map.status,storage_domain_static.storage_domain_type) AS
		storage_domain_shared_status,
		vds_groups.vds_group_id,
		vds_static.vds_id,
		storage_pool_iso_map.storage_pool_id,
		vds_static.recoverable
FROM storage_domain_static
	INNER JOIN storage_domain_dynamic ON storage_domain_static.id = storage_domain_dynamic.id
	LEFT OUTER JOIN storage_pool_iso_map ON storage_domain_static.id = storage_pool_iso_map.storage_id
	LEFT OUTER JOIN storage_pool ON storage_pool_iso_map.storage_pool_id = storage_pool.id
	LEFT OUTER JOIN vds_groups ON storage_pool_iso_map.storage_pool_id = vds_groups.storage_pool_id
	LEFT OUTER JOIN vds_static ON vds_groups.vds_group_id = vds_static.vds_group_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vm_images_storage_domains_view
AS
SELECT vm_images_view.storage_id, vm_images_view.storage_path, vm_images_view.storage_pool_id,
       vm_images_view.image_guid, vm_images_view.creation_date, vm_images_view.actual_size, vm_images_view.read_rate, vm_images_view.write_rate,
       vm_images_view.size, vm_images_view.it_guid, vm_images_view.description, vm_images_view.parentid,
       vm_images_view.imagestatus, vm_images_view.lastmodified, vm_images_view.app_list, vm_images_view.vm_snapshot_id, vm_images_view.volume_type,
       vm_images_view.image_group_id, vm_images_view.active, vm_images_view.volume_format, vm_images_view.disk_interface,
       vm_images_view.boot, vm_images_view.wipe_after_delete, vm_images_view.propagate_errors, vm_images_view.entity_type, vm_images_view.number_of_vms, vm_images_view.vm_names, vm_images_view.quota_id,
       vm_images_view.quota_name, vm_images_view.disk_profile_id, vm_images_view.disk_profile_name, vm_images_view.disk_alias, vm_images_view.disk_description, vm_images_view.sgio,
       storage_domains_with_hosts_view.id, storage_domains_with_hosts_view.storage, storage_domains_with_hosts_view.storage_name,
       storage_domains_with_hosts_view.available_disk_size, storage_domains_with_hosts_view.used_disk_size,
       storage_domains_with_hosts_view.commited_disk_size, storage_domains_with_hosts_view.actual_images_size, storage_domains_with_hosts_view.storage_type,
       storage_domains_with_hosts_view.storage_domain_type, storage_domains_with_hosts_view.storage_domain_format_type,
       storage_domains_with_hosts_view.storage_domain_shared_status, storage_domains_with_hosts_view.vds_group_id,
       storage_domains_with_hosts_view.vds_id, storage_domains_with_hosts_view.recoverable, storage_domains_with_hosts_view.storage_pool_name,
       storage_domains_with_hosts_view.storage_name as name
FROM vm_images_view
INNER JOIN images_storage_domain_view ON vm_images_view.image_guid = images_storage_domain_view.image_guid
INNER JOIN storage_domains_with_hosts_view ON storage_domains_with_hosts_view.id = images_storage_domain_view.storage_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW quota_view
AS
SELECT q.id as quota_id,
    q.storage_pool_id as storage_pool_id,
    storage_pool.name as storage_pool_name,
    q.quota_name as quota_name,
    q.description as description,
    q.threshold_vds_group_percentage as threshold_vds_group_percentage,
    q.threshold_storage_percentage as threshold_storage_percentage,
    q.grace_vds_group_percentage as grace_vds_group_percentage,
    q.grace_storage_percentage as grace_storage_percentage,
    storage_pool.quota_enforcement_type as quota_enforcement_type
FROM  storage_pool, quota q
WHERE storage_pool.id = q.storage_pool_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW quota_global_view
AS
SELECT q_limit.quota_id as quota_id,
    q.storage_pool_id as storage_pool_id,
    storage_pool.name as storage_pool_name,
    q.quota_name as quota_name,
    q.description as description,
    q.threshold_vds_group_percentage as threshold_vds_group_percentage,
    q.threshold_storage_percentage as threshold_storage_percentage,
    q.grace_vds_group_percentage as grace_vds_group_percentage,
    q.grace_storage_percentage as grace_storage_percentage,
    virtual_cpu,
    (CalculateVdsGroupUsage(quota_id,null)).virtual_cpu_usage,
    mem_size_mb,
    (CalculateVdsGroupUsage(quota_id,null)).mem_size_mb_usage,
    storage_size_gb,
    CalculateStorageUsage(quota_id,null) as storage_size_gb_usage,
    storage_pool.quota_enforcement_type as quota_enforcement_type
FROM  storage_pool, quota q LEFT OUTER JOIN
quota_limitation q_limit on q_limit.quota_id = q.id
WHERE storage_pool.id = q.storage_pool_id
AND q_limit.vds_group_id IS NULL
AND q_limit.storage_id IS NULL;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW quota_limitations_view
AS
SELECT q_limit.quota_id as quota_id,
    q.storage_pool_id as storage_pool_id,
    storage_pool.name as storage_pool_name,
    q.quota_name as quota_name,
    q.description as description,
    q.threshold_vds_group_percentage as threshold_vds_group_percentage,
    q.threshold_storage_percentage as threshold_storage_percentage,
    q.grace_vds_group_percentage as grace_vds_group_percentage,
    q.grace_storage_percentage as grace_storage_percentage,
    virtual_cpu,
    mem_size_mb,
    storage_size_gb,
    storage_pool.quota_enforcement_type as quota_enforcement_type,
    vds_group_id,
    storage_id,
    (COALESCE(vds_group_id, storage_id) IS NULL ) AS is_global,
    (COALESCE(virtual_cpu, mem_size_mb, storage_size_gb) IS NULL) AS is_empty
FROM  quota q
INNER JOIN storage_pool ON storage_pool.id = q.storage_pool_id
LEFT OUTER JOIN quota_limitation q_limit on q_limit.quota_id = q.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW quota_storage_view
AS
SELECT q_limit.id as quota_storage_id,
    q_limit.quota_id as quota_id,
    storage_id,
    storage_domain_static.storage_name as storage_name,
    storage_size_gb,
    CalculateStorageUsage(quota_id,storage_id) as storage_size_gb_usage
FROM   quota_limitation q_limit, quota q, storage_domain_static
WHERE  q_limit.quota_id = q.id
AND  q_limit.vds_group_id IS NULL
AND  q_limit.storage_id IS NOT NULL
AND  storage_domain_static.id = q_limit.storage_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW quota_vds_group_view
AS
SELECT q_limit.id as quota_vds_group_id,
    q_limit.quota_id as quota_id,
    q_limit.vds_group_id,
    vds_groups.name as vds_group_name,
    virtual_cpu,
    (CalculateVdsGroupUsage(quota_id,q_limit.vds_group_id)).virtual_cpu_usage as virtual_cpu_usage,
    mem_size_mb,
    (CalculateVdsGroupUsage(quota_id,q_limit.vds_group_id)).mem_size_mb_usage as mem_size_mb_usage
FROM   quota_limitation q_limit, quota q, vds_groups
WHERE  q_limit.quota_id = q.id
AND  q_limit.vds_group_id IS NOT NULL
AND  q_limit.storage_id IS NULL
AND  vds_groups.vds_group_id = q_limit.vds_group_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW network_cluster_view
AS
SELECT network_cluster.cluster_id AS cluster_id, network_cluster.network_id AS network_id, network.name as network_name,
       network_cluster.status as status, network_cluster.required as required, network_cluster.is_display as is_display,
       network_cluster.migration as migration, vds_groups.name as cluster_name
FROM network_cluster
INNER JOIN network ON network_cluster.network_id = network.id
INNER JOIN vds_groups ON network_cluster.cluster_id = vds_groups.vds_group_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW network_vds_view
AS
SELECT network.id AS network_id,
    network.name as network_name,
    vds_static.vds_name as vds_name
FROM vds_interface
INNER JOIN vds_static ON vds_interface.vds_id = vds_static.vds_id
INNER JOIN network ON vds_interface.network_name = network.name
INNER JOIN network_cluster ON network_cluster.network_id = network.id
WHERE network_cluster.cluster_id = vds_static.vds_group_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW network_view
AS
SELECT network.id AS id,
   network.name AS name,
   network.description AS description,
   network.free_text_comment AS free_text_comment,
   network.type AS type,
   network.addr AS addr,
   network.subnet AS subnet,
   network.gateway AS gateway,
   network.vlan_id AS vlan_id,
   network.stp AS stp,
   network.mtu AS mtu,
   network.vm_network AS vm_network,
   network.storage_pool_id AS storage_pool_id,
   network.provider_network_provider_id AS provider_network_provider_id,
   network.provider_network_external_id AS provider_network_external_id,
   network.qos_id AS qos_id,
   network.label AS label,
   storage_pool.name AS storage_pool_name,
   storage_pool.compatibility_version AS compatibility_version,
   providers.name AS provider_name
FROM network
INNER JOIN storage_pool ON network.storage_pool_id = storage_pool.id
LEFT JOIN providers ON network.provider_network_provider_id = providers.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vnic_profiles_view
AS
SELECT vnic_profiles.id AS id,
       vnic_profiles.name AS name,
       vnic_profiles.network_id as network_id,
       vnic_profiles.network_qos_id as network_qos_id,
       vnic_profiles.port_mirroring as port_mirroring,
       vnic_profiles.custom_properties as custom_properties,
       vnic_profiles.description as description,
       network.name as network_name,
       qos.name as network_qos_name,
       storage_pool.name as data_center_name,
       storage_pool.compatibility_version as compatibility_version,
       storage_pool.id as data_center_id
FROM vnic_profiles
INNER JOIN network ON vnic_profiles.network_id = network.id
LEFT JOIN qos ON vnic_profiles.network_qos_id = qos.id
INNER JOIN storage_pool ON network.storage_pool_id = storage_pool.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_flat_groups
AS
SELECT users.user_id AS user_id, fnSplitterUuid(users.group_ids) AS granted_id
FROM   users
UNION ALL

SELECT user_id, user_id FROM users
UNION ALL

SELECT user_id, 'EEE00000-0000-0000-0000-123456789EEE'
FROM   users;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vds_groups_permissions_view_base (entity_id, granted_id)
AS
SELECT       object_id, ad_element_id
FROM         internal_permissions_view
WHERE        object_type_id = 9 AND role_type = 2

UNION ALL
SELECT       DISTINCT vds_group_id, ad_element_id
FROM         vm_static
INNER JOIN   internal_permissions_view ON object_id = vm_guid AND (object_type_id = 2 OR object_type_id = 4) AND role_type=2 and vds_group_id is not null

UNION ALL
SELECT       vds_group_id, ad_element_id
FROM         vds_groups
INNER JOIN   internal_permissions_view ON object_id = vds_groups.storage_pool_id AND object_type_id = 14 AND role_type = 2

UNION ALL
SELECT       vds_group_id, ad_element_id
FROM         internal_permissions_view
CROSS JOIN   vds_groups
WHERE        object_type_id = 1 AND role_type=2;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vds_groups_permissions_view (entity_id, user_id)
AS
SELECT       DISTINCT entity_id, user_id
FROM         user_vds_groups_permissions_view_base
NATURAL JOIN user_flat_groups;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_storage_pool_permissions_view_base (entity_id, granted_id)
AS
SELECT     object_id, ad_element_id
FROM       internal_permissions_view
WHERE      object_type_id = 14 AND role_type = 2

UNION ALL
SELECT     storage_pool_id, ad_element_id
FROM       vds_groups
INNER JOIN internal_permissions_view ON object_id = vds_groups.vds_group_id AND object_type_id = 9 AND role_type = 2

UNION ALL
SELECT     storage_pool_id, ad_element_id
FROM       vds_groups
INNER JOIN vm_pools ON vds_groups.vds_group_id = vm_pools.vds_group_id
INNER JOIN internal_permissions_view ON object_id = vm_pools.vm_pool_id AND object_type_id = 5 AND role_type = 2

UNION ALL
SELECT     storage_pool_id, ad_element_id
FROM       vm_static
INNER JOIN vds_groups ON vds_groups.vds_group_id = vm_static.vds_group_id
INNER JOIN internal_permissions_view ON object_id = vm_guid AND object_type_id = 2 AND role_type = 2

UNION ALL
SELECT     storage_pool.id, ad_element_id
FROM       internal_permissions_view
CROSS JOIN storage_pool
WHERE      object_type_id = 1 AND role_type = 2;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_storage_pool_permissions_view (entity_id, user_id)
AS
SELECT       DISTINCT entity_id, user_id
FROM         user_storage_pool_permissions_view_base
NATURAL JOIN user_flat_groups;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_storage_domain_permissions_view_base (entity_id, granted_id)
AS
SELECT     object_id, ad_element_id
FROM       internal_permissions_view
WHERE      object_type_id = 11 AND role_type = 2

UNION ALL
SELECT     storage_domains.id, ad_element_id
FROM       storage_domains
INNER JOIN vds_groups ON vds_groups.storage_pool_id = storage_domains.storage_pool_id
INNER JOIN vm_static ON vds_groups.vds_group_id = vm_static.vds_group_id
INNER JOIN internal_permissions_view ON object_id = vm_static.vm_guid AND object_type_id = 2 AND role_type = 2

UNION ALL
SELECT     storage_id, ad_element_id
FROM       vm_templates_storage_domain
INNER JOIN internal_permissions_view ON vmt_guid = internal_permissions_view.object_id AND object_type_id = 4 AND role_type = 2

UNION ALL
SELECT     storage_id, ad_element_id
FROM       vm_static
INNER JOIN vm_templates_storage_domain ON vm_static.vmt_guid = vm_templates_storage_domain.vmt_guid
INNER JOIN internal_permissions_view ON vm_static.vm_guid = object_id AND objecT_type_id = 2 AND role_type = 2

UNION ALL
SELECT     storage_domains.id, ad_element_id
FROM       storage_domains
INNER JOIN internal_permissions_view ON object_id = storage_domains.storage_pool_id AND object_type_id = 14 AND role_type = 2

UNION ALL
SELECT     storage_domains.id, ad_element_id
FROM       internal_permissions_view
CROSS JOIN storage_domains
WHERE      object_type_id = 1 AND role_type = 2;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_storage_domain_permissions_view (entity_id, user_id)
AS
SELECT       DISTINCT entity_id, user_id
FROM         user_storage_domain_permissions_view_base
NATURAL JOIN user_flat_groups;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vds_permissions_view_base (entity_id, granted_id)
AS
SELECT     object_id, ad_element_id
FROM       internal_permissions_view
WHERE      object_type_id = 3 AND role_type = 2

UNION ALL
SELECT     vds_id, ad_element_id
FROM       vds
INNER JOIN internal_permissions_view ON (object_id = vds_group_id    AND object_type_id = 9) OR
                                    (object_id = storage_pool_id AND object_type_id = 14) AND role_type = 2

UNION ALL
SELECT     vds_id, ad_element_id
FROM       internal_permissions_view
CROSS JOIN vds
WHERE      object_type_id = 1 AND role_type = 2;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vds_permissions_view (entity_id, user_id)
AS
SELECT       DISTINCT entity_id, user_id
FROM         user_vds_permissions_view_base
NATURAL JOIN user_flat_groups;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vm_pool_permissions_view_base (entity_id, granted_id)
AS
SELECT     object_id, ad_element_id
FROM       internal_permissions_view
WHERE      object_type_id = 5 AND role_type = 2

UNION ALL
SELECT     vm_pool_id, ad_element_id
FROM       vm_pool_map
INNER JOIN internal_permissions_view ON object_id = vm_guid AND object_type_id = 2 AND role_type = 2

UNION ALL
SELECT     vm_pool_id, ad_element_id
FROM       vm_pools
INNER JOIN internal_permissions_view ON object_id = vds_group_id AND object_type_id = 9 AND allows_viewing_children AND role_type = 2

UNION ALL
SELECT     vm_pool_id, ad_element_id
FROM       vm_pools
INNER JOIN vds_groups ON vm_pools.vds_group_id =  vds_groups.vds_group_id
INNER JOIN internal_permissions_view ON object_id = storage_pool_id AND object_type_id = 14 AND allows_viewing_children AND role_type = 2

UNION ALL
SELECT     vm_pool_id, ad_element_id
FROM       internal_permissions_view
CROSS JOIN vm_pools
WHERE      object_type_id = 1 AND allows_viewing_children AND role_type = 2;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vm_pool_permissions_view (entity_id, user_id)
AS
SELECT       DISTINCT entity_id, user_id
FROM         user_vm_pool_permissions_view_base
NATURAL JOIN user_flat_groups;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vm_template_permissions_view_base (entity_id, granted_id)
AS
SELECT     object_id, ad_element_id
FROM       internal_permissions_view
WHERE      object_type_id = 4 AND role_type = 2

UNION ALL
SELECT     vmt_guid, ad_element_id
FROM       vm_static
INNER JOIN internal_permissions_view ON object_id = vm_static.vm_guid AND object_type_id = 2 AND role_type = 2

UNION ALL
SELECT     vm_guid, ad_element_id
FROM       vm_static
INNER JOIN vds_groups ON vds_groups.vds_group_id = vm_static.vds_group_id
INNER JOIN internal_permissions_view ON object_id = storage_pool_id AND object_type_id = 14 AND allows_viewing_children AND role_type = 2 AND vm_static.entity_type::text = 'TEMPLATE'::text

UNION ALL
SELECT     vm_guid, ad_element_id
FROM       internal_permissions_view
CROSS JOIN vm_static
WHERE      object_type_id = 1 AND allows_viewing_children AND role_type = 2 AND
(vm_static.entity_type::text = 'TEMPLATE'::text OR vm_static.entity_type::text = 'INSTANCE_TYPE'::text
 OR vm_static.entity_type::text = 'IMAGE_TYPE'::text);
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vm_template_permissions_view (entity_id, user_id)
AS
SELECT       DISTINCT entity_id, user_id
FROM         user_vm_template_permissions_view_base
NATURAL JOIN user_flat_groups;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vm_permissions_view_base (entity_id, granted_id)
AS
SELECT     object_id, ad_element_id
FROM       internal_permissions_view
WHERE      object_type_id = 2 AND role_type = 2

UNION ALL
SELECT     vm_guid, ad_element_id
FROM       vm_static
INNER JOIN internal_permissions_view ON object_id = vds_group_id AND object_type_id = 9 AND allows_viewing_children AND role_type = 2

UNION ALL
SELECT     vm_guid, ad_element_id
FROM       vm_static
INNER JOIN vds_groups ON vds_groups.vds_group_id = vm_static.vds_group_id
INNER JOIN internal_permissions_view ON object_id = storage_pool_id AND object_type_id = 14 AND allows_viewing_children AND role_type = 2

UNION ALL
SELECT     vm_guid, ad_element_id
FROM       internal_permissions_view
CROSS JOIN vm_static
WHERE      object_type_id = 1 AND allows_viewing_children AND role_type = 2;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vm_permissions_view (entity_id, user_id)
AS
SELECT       DISTINCT entity_id, user_id
FROM         user_vm_permissions_view_base
NATURAL JOIN user_flat_groups;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_disk_permissions_view_base (entity_id, granted_id)
AS
SELECT     object_id, ad_element_id
FROM       internal_permissions_view
WHERE      object_type_id = 19 AND role_type = 2

UNION ALL
SELECT     device_id, user_vm_permissions_view.user_id as ad_element_id
FROM       vm_device
INNER JOIN user_vm_permissions_view ON user_vm_permissions_view.entity_id = vm_device.vm_id
WHERE      vm_device.type = 'disk' and vm_device.device = 'disk'

UNION ALL
SELECT     device_id, user_vm_template_permissions_view.user_id as ad_element_id
FROM       vm_device
INNER JOIN user_vm_template_permissions_view ON user_vm_template_permissions_view.entity_id = vm_device.vm_id
WHERE      type = 'disk' and device = 'disk'

UNION ALL
SELECT     images.image_group_id, ad_element_id
FROM       image_storage_domain_map
INNER JOIN images ON images.image_guid = image_storage_domain_map.image_id
INNER JOIN internal_permissions_view ON object_id = storage_domain_id AND object_type_id = 11 AND allows_viewing_children AND role_type = 2

UNION ALL
SELECT     images.image_group_id, ad_element_id
FROM       image_storage_domain_map
INNER JOIN storage_pool_iso_map ON image_storage_domain_map.storage_domain_id = storage_pool_iso_map.storage_id
INNER JOIN images ON images.image_guid = image_storage_domain_map.image_id
INNER JOIN internal_permissions_view ON object_id = storage_pool_id AND object_type_id = 14 AND allows_viewing_children AND role_type = 2

UNION ALL
SELECT     device_id, ad_element_id
FROM       internal_permissions_view
CROSS JOIN vm_device
WHERE      object_type_id = 1 AND allows_viewing_children AND role_type = 2;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_disk_permissions_view (entity_id, user_id)
AS
SELECT       DISTINCT entity_id, user_id
FROM         user_disk_permissions_view_base
NATURAL JOIN user_flat_groups;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_permissions_permissions_view (entity_id, user_id)
AS
SELECT       DISTINCT id, user_id
FROM         internal_permissions_view
JOIN         user_flat_groups ON granted_id = ad_element_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_object_permissions_view AS
 SELECT DISTINCT permissions.object_id AS entity_id, user_flat_groups.user_id
   FROM permissions
   JOIN roles ON permissions.role_id = roles.id
   JOIN user_flat_groups ON user_flat_groups.granted_id = permissions.ad_element_id
   WHERE permissions.ad_element_id != getGlobalIds('everyone');
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_db_users_permissions_view AS
 SELECT DISTINCT permissions.ad_element_id, roles_groups.role_id, roles_groups.action_group_id
   FROM permissions
   JOIN roles_groups ON permissions.role_id = roles_groups.role_id
   WHERE roles_groups.action_group_id = 502;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW vm_device_view
AS
SELECT device_id, vm_id, type, device, address, boot_order, spec_params,
       is_managed, is_plugged, is_readonly, alias, custom_properties, snapshot_id
  FROM vm_device;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vnic_profile_permissions_view_base (entity_id, granted_id)
AS
SELECT     object_id, ad_element_id
FROM       internal_permissions_view
WHERE      object_type_id = 27 AND role_type = 2

UNION ALL
SELECT     vnic_profiles.id, ad_element_id
FROM       vnic_profiles
INNER JOIN internal_permissions_view ON object_id = network_id
WHERE      object_type_id = 20 AND allows_viewing_children AND role_type = 2

UNION ALL
SELECT     vnic_profiles.id, ad_element_id
FROM       vnic_profiles
INNER JOIN network ON network.id = network_id
INNER JOIN internal_permissions_view ON object_id = network.storage_pool_id
WHERE      object_type_id = 14 AND role_type = 2 AND allows_viewing_children

UNION ALL
SELECT     vnic_profiles.id, ad_element_id
FROM       vnic_profiles
INNER JOIN network_cluster ON network_cluster.network_id = vnic_profiles.network_id
INNER JOIN internal_permissions_view ON object_id = network_cluster.cluster_id
WHERE      object_type_id = 9 AND role_type = 2 AND allows_viewing_children

UNION ALL
SELECT DISTINCT vnic_profile_id, ad_element_id
FROM       vm_interface
INNER JOIN internal_permissions_view ON object_id = vm_guid
WHERE object_type_id = 2 AND role_type = 2

UNION ALL
SELECT DISTINCT    vnic_profile_id, ad_element_id
FROM       vm_interface
INNER JOIN internal_permissions_view ON object_id = vmt_guid
WHERE object_type_id = 4 AND role_type = 2

UNION ALL
SELECT     vnic_profiles.id, ad_element_id
FROM       internal_permissions_view
CROSS JOIN vnic_profiles
WHERE      object_type_id = 1 AND allows_viewing_children AND role_type = 2;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_vnic_profile_permissions_view (entity_id, user_id)
AS
SELECT       DISTINCT entity_id, user_id
FROM         user_vnic_profile_permissions_view_base
NATURAL JOIN user_flat_groups;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_network_permissions_view_base (entity_id, granted_id)
AS

SELECT     network.id, user_id
FROM       network
INNER JOIN vnic_profiles ON network_id = network.id
INNER JOIN user_vnic_profile_permissions_view ON entity_id = vnic_profiles.id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW user_network_permissions_view (entity_id, user_id)
AS
SELECT       DISTINCT entity_id, user_id
FROM         user_network_permissions_view_base
NATURAL JOIN user_flat_groups;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW gluster_volumes_view
AS
SELECT gluster_volumes.*,
       vds_groups.name AS vds_group_name
FROM gluster_volumes
INNER JOIN vds_groups ON gluster_volumes.cluster_id = vds_groups.vds_group_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW gluster_volume_bricks_view
AS
SELECT gluster_volume_bricks.*,
       vds_static.host_name AS vds_name,
       gluster_volumes.vol_name AS volume_name
FROM gluster_volume_bricks
INNER JOIN vds_static ON vds_static.vds_id = gluster_volume_bricks.server_id
INNER JOIN gluster_volumes ON gluster_volumes.id = gluster_volume_bricks.volume_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW gluster_volume_task_steps
AS
SELECT step.*,
       gluster_volumes.id as volume_id,
       job.job_id as job_job_id,
       job.action_type,
       job.description as job_description,
       job.status as job_status,
       job.start_time as job_start_time,
       job.end_time as job_end_time
FROM gluster_volumes
INNER JOIN job_subject_entity js ON js.entity_id = gluster_volumes.id
INNER JOIN job on job.job_id = js.job_id
               AND job.action_type in ('StartRebalanceGlusterVolume', 'StartRemoveGlusterVolumeBricks')
LEFT OUTER JOIN step on step.external_id = gluster_volumes.task_id AND step.external_system_type = 'GLUSTER'
                AND step.job_id = js.job_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW gluster_server_services_view
AS
SELECT gluster_server_services.*,
       gluster_services.service_name,
       gluster_services.service_type,
       vds_static.vds_name
FROM gluster_server_services
INNER JOIN gluster_services ON gluster_server_services.service_id = gluster_services.id
INNER JOIN vds_static ON gluster_server_services.server_id = vds_static.vds_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW gluster_server_hooks_view
AS
SELECT gluster_server_hooks.*,
       vds_static.vds_name AS server_name
FROM gluster_server_hooks
INNER JOIN vds_static ON gluster_server_hooks.server_id = vds_static.vds_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW affinity_groups_view
AS
SELECT affinity_groups.*,
       array_to_string(array_agg(affinity_group_members.vm_id), ',') as vm_ids,
       array_to_string(array_agg(vm_static.vm_name), ',') as vm_names
FROM affinity_groups
LEFT JOIN affinity_group_members ON affinity_group_members.affinity_group_id = affinity_groups.id
LEFT JOIN vm_static ON vm_static.vm_guid = affinity_group_members.vm_id

GROUP BY affinity_groups.id, affinity_groups.name, affinity_groups.description,
         affinity_groups.cluster_id, affinity_groups.positive, affinity_groups.enforcing,
         affinity_groups._create_date, affinity_groups._update_date;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW numa_node_cpus_view
AS
SELECT numa_node.numa_node_id,
       numa_node.vds_id,
       numa_node.vm_id,
       numa_node_cpu_map.cpu_core_id
FROM numa_node
INNER JOIN numa_node_cpu_map ON numa_node.numa_node_id = numa_node_cpu_map.numa_node_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW numa_node_assignment_view
AS
SELECT vm_vds_numa_node_map.vm_numa_node_id as assigned_vm_numa_node_id,
       vm_vds_numa_node_map.is_pinned as is_pinned,
       vm_vds_numa_node_map.vds_numa_node_index as last_run_in_vds_numa_node_index,
       vm_numa_node.vm_id as vm_numa_node_vm_id,
       vm_numa_node.numa_node_index as vm_numa_node_index,
       vm_numa_node.mem_total as vm_numa_node_mem_total,
       vm_numa_node.cpu_count as vm_numa_node_cpu_count,
       vm_numa_node.mem_free as vm_numa_node_mem_free,
       vm_numa_node.usage_mem_percent as vm_numa_node_usage_mem_percent,
       vm_numa_node.cpu_sys as vm_numa_node_cpu_sys,
       vm_numa_node.cpu_user as vm_numa_node_cpu_user,
       vm_numa_node.cpu_idle as vm_numa_node_cpu_idle,
       vm_numa_node.usage_cpu_percent as vm_numa_node_usage_cpu_percent,
       vm_numa_node.distance as vm_numa_node_distance,
       run_in_vds_numa_node.numa_node_id as run_in_vds_numa_node_id,
       run_in_vds_numa_node.vds_id as run_in_vds_id,
       run_in_vds_numa_node.numa_node_index as run_in_vds_numa_node_index,
       run_in_vds_numa_node.mem_total as run_in_vds_numa_node_mem_total,
       run_in_vds_numa_node.cpu_count as run_in_vds_numa_node_cpu_count,
       run_in_vds_numa_node.mem_free as run_in_vds_numa_node_mem_free,
       run_in_vds_numa_node.usage_mem_percent as run_in_vds_numa_node_usage_mem_percent,
       run_in_vds_numa_node.cpu_sys as run_in_vds_numa_node_cpu_sys,
       run_in_vds_numa_node.cpu_user as run_in_vds_numa_node_cpu_user,
       run_in_vds_numa_node.cpu_idle as run_in_vds_numa_node_cpu_idle,
       run_in_vds_numa_node.usage_cpu_percent as run_in_vds_numa_node_usage_cpu_percent,
       run_in_vds_numa_node.distance as run_in_vds_numa_node_distance
FROM vm_vds_numa_node_map
LEFT OUTER JOIN numa_node as vm_numa_node on vm_vds_numa_node_map.vm_numa_node_id = vm_numa_node.numa_node_id
LEFT OUTER JOIN numa_node as run_in_vds_numa_node on vm_vds_numa_node_map.vds_numa_node_id = run_in_vds_numa_node.numa_node_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW numa_node_with_vds_group_view
AS
SELECT vm_numa_node.numa_node_id as vm_numa_node_id,
       vm_numa_node.vm_id as vm_numa_node_vm_id,
       vm_numa_node.numa_node_index as vm_numa_node_index,
       vm_numa_node.mem_total as vm_numa_node_mem_total,
       vm_numa_node.cpu_count as vm_numa_node_cpu_count,
       vm_numa_node.mem_free as vm_numa_node_mem_free,
       vm_numa_node.usage_mem_percent as vm_numa_node_usage_mem_percent,
       vm_numa_node.cpu_sys as vm_numa_node_cpu_sys,
       vm_numa_node.cpu_user as vm_numa_node_cpu_user,
       vm_numa_node.cpu_idle as vm_numa_node_cpu_idle,
       vm_numa_node.usage_cpu_percent as vm_numa_node_usage_cpu_percent,
       vm_numa_node.distance as vm_numa_node_distance,
       vm_static.vds_group_id
FROM numa_node as vm_numa_node
LEFT OUTER JOIN vm_static on vm_numa_node.vm_id = vm_static.vm_guid;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_datacenter_configuration_history_view
AS
SELECT     	id AS datacenter_id,
			name AS datacenter_name,
			description AS datacenter_description,
			is_local AS is_local_storage,
			_create_date AS create_date,
            _update_date AS update_date
FROM        storage_pool
WHERE     	(_create_date >
                          (SELECT     var_datetime
                           FROM          dwh_history_timekeeping
                           WHERE      (var_name = 'lastSync'))) OR
            (_update_date >
                          (SELECT     var_datetime
                           FROM          dwh_history_timekeeping AS history_timekeeping_1
                           WHERE      (var_name = 'lastSync')));
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_datacenter_history_view
AS
SELECT
    id as datacenter_id,
	cast(status as smallint) as datacenter_status
FROM storage_pool;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_storage_domain_configuration_history_view
AS
SELECT     	id AS storage_domain_id,
			storage_name AS storage_domain_name,
			cast(storage_domain_type as smallint) as storage_domain_type,
			cast(storage_type as smallint) as storage_type,
			_create_date AS create_date,
            _update_date AS update_date
FROM        storage_domain_static
WHERE     (_create_date >
                          (SELECT     var_datetime
                           FROM          dwh_history_timekeeping
                           WHERE      (var_name = 'lastSync'))) OR
          (_update_date >
                          (SELECT     var_datetime
                           FROM          dwh_history_timekeeping AS history_timekeeping_1
                           WHERE      (var_name = 'lastSync')));
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_datacenter_storage_map_history_view
AS
SELECT DISTINCT storage_pool_id AS datacenter_id,
                storage_id AS storage_domain_id
FROM storage_pool_iso_map;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_storage_domain_history_view
AS
SELECT storage_domain_dynamic.id as storage_domain_id,
       fn_get_storage_domain_shared_status_by_domain_id(storage_domain_static.id, status_table.status, storage_domain_static.storage_domain_type) AS storage_domain_status,
       storage_domain_dynamic.available_disk_size as available_disk_size_gb,
       storage_domain_dynamic.used_disk_size as used_disk_size_gb
FROM storage_domain_dynamic
         INNER JOIN storage_domain_static ON (storage_domain_dynamic.id = storage_domain_static.id)
             LEFT OUTER JOIN (SELECT storage_id, max(status) AS status
                              FROM storage_pool_iso_map
                              GROUP BY storage_id) AS status_table ON storage_domain_static.id=status_table.storage_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_cluster_configuration_history_view
AS
SELECT     	vds_group_id AS cluster_id,
			name AS cluster_name,
			description as cluster_description,
			storage_pool_id AS datacenter_id,
			cpu_name,
			compatibility_version,
            _create_date AS create_date,
			_update_date AS update_date
FROM        vds_groups
WHERE     (_create_date >
                          (SELECT     var_datetime
                           FROM          dwh_history_timekeeping
                           WHERE      (var_name = 'lastSync'))) OR
          (_update_date >
                          (SELECT     var_datetime
                           FROM          dwh_history_timekeeping AS history_timekeeping_1
                           WHERE      (var_name = 'lastSync')));
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_host_configuration_history_view
AS
SELECT     	a.vds_id AS host_id,
			a.vds_unique_id AS host_unique_id,
			a.vds_name AS host_name,
			a.vds_group_id AS cluster_id,
			cast(a.vds_type as smallint) AS host_type,
			a.host_name AS fqdn_or_ip,
			b.physical_mem_mb AS memory_size_mb,
			cast(c.swap_total as int) as swap_size_mb,
			b.cpu_model,
			cast(b.cpu_cores as smallint) AS number_of_cores,
                        cast(b.cpu_sockets as smallint) AS number_of_sockets,
                        b.cpu_speed_mh,
			b.host_os,
			a.ip as pm_ip_address,
			b.kernel_version,
			b.kvm_version,
			b.libvirt_version,
			b.software_version as vdsm_version,
			a.port AS vdsm_port,
			a._create_date AS create_date,
			a._update_date AS update_date
FROM        vds_static AS a
			INNER JOIN
					vds_dynamic AS b ON a.vds_id = b.vds_id
			INNER JOIN
					vds_statistics AS c ON c.vds_id = a.vds_id
WHERE     (a._create_date >
                          (SELECT     var_datetime
                           FROM          dwh_history_timekeeping
                           WHERE      (var_name = 'lastSync'))) OR
          (a._update_date >
                          (SELECT     var_datetime
                           FROM          dwh_history_timekeeping AS history_timekeeping_1
                           WHERE      (var_name = 'lastSync')));
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_host_configuration_full_check_view
AS
SELECT     	a.vds_id AS host_id,
			a.vds_unique_id AS host_unique_id,
			a.vds_name AS host_name,
			a.vds_group_id AS cluster_id,
			cast(a.vds_type as smallint) AS host_type,
			a.host_name AS fqdn_or_ip,
			b.physical_mem_mb AS memory_size_mb,
			cast(c.swap_total as int) as swap_size_mb,
			b.cpu_model,
			cast(b.cpu_cores as smallint) AS number_of_cores,
                        cast(b.cpu_sockets as smallint) AS number_of_sockets,
                        b.cpu_speed_mh,
			b.host_os,
			a.ip as pm_ip_address,
			b.kernel_version,
			b.kvm_version,
			b.libvirt_version,
      			CASE SUBSTR(b.software_version,1,3)
				WHEN '4.4' THEN '2.1' || SUBSTR(b.software_version,4,LENGTH(b.software_version))
				WHEN '4.5' THEN '2.2' || SUBSTR(b.software_version,4,LENGTH(b.software_version))
				WHEN '4.9' THEN '2.3' || SUBSTR(b.software_version,4,LENGTH(b.software_version))
	   	        ELSE b.software_version
	 	        END as vdsm_version,
			a.port AS vdsm_port,
			a._create_date AS create_date,
			a._update_date AS update_date
FROM        vds_static AS a
			INNER JOIN
					vds_dynamic AS b ON a.vds_id = b.vds_id
			INNER JOIN
					vds_statistics AS c ON c.vds_id = a.vds_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_host_history_view
AS
SELECT
	b.vds_id as host_id,
	cast(b.status as smallint) as host_status,
	cast(c.usage_mem_percent as smallint) as memory_usage_percent,
	cast(c.usage_cpu_percent as smallint) as cpu_usage_percent,
	cast(c.ksm_cpu_percent as smallint) as ksm_cpu_percent,
	cast(c.cpu_load as int) as cpu_load,
	cast(c.cpu_sys as smallint) as system_cpu_usage_percent,
	cast(c.cpu_user as smallint) as user_cpu_usage_percent,
	cast((c.swap_total - c.swap_free) as int) as swap_used_mb,
	cast(b.vm_active as smallint) as vm_active,
	cast(b.vm_count as smallint) as total_vms,
	b.vms_cores_count as total_vms_vcpus,
	c.mem_shared as ksm_shared_memory_mb
FROM vds_dynamic b, vds_statistics c
where	b.vds_id  = c.vds_id;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_host_interface_configuration_history_view AS
SELECT  a.id AS host_interface_id,
		a.name AS host_interface_name,
		a.vds_id AS host_id,
		cast(a.type as smallint) as host_interface_type,
		a.speed as host_interface_speed_bps,
		a.mac_addr AS mac_address,
		a.network_name as logical_network_name,
		a.addr AS ip_address,
		a.gateway,
		a.is_bond AS bond,
		a.bond_name,
		a.vlan_id,
		a._create_date AS create_date,
		a._update_date AS update_date
FROM         vds_interface as a
WHERE     ((a._create_date >
                          (SELECT     var_datetime
                            FROM          dwh_history_timekeeping
                            WHERE      (var_name = 'lastSync'))) OR
           (a._update_date >
                          (SELECT     var_datetime
                            FROM          dwh_history_timekeeping AS history_timekeeping_1
                            WHERE      (var_name = 'lastSync')))) AND
		   (a.is_bond IS NULL OR
		   a.is_bond = false OR
		   (a.is_bond = true and a.name in (SELECT b.bond_name
										FROM vds_interface AS b
										where b.is_bond is null and b.vds_id = a.vds_id)));
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_host_interface_history_view
AS
SELECT     vds_interface_statistics.id as host_interface_id,
		   cast(vds_interface_statistics.rx_rate as smallint) as receive_rate_percent,
		   cast(vds_interface_statistics.tx_rate as smallint) as transmit_rate_percent
FROM       vds_interface_statistics;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_vm_configuration_history_view
AS
SELECT     	a.vm_guid AS vm_id,
			a.vm_name,
			a.description as vm_description,
			cast(a.vm_type as smallint) as vm_type,
			a.vds_group_id AS cluster_id,
			a.vmt_guid AS template_id,
            b.vm_name AS template_name,
			cast(a.cpu_per_socket as smallint) as cpu_per_socket,
			cast(a.num_of_sockets as smallint) AS number_of_sockets,
			a.mem_size_mb AS memory_size_mb,
            cast(a.os as smallint) AS operating_system,
			a.dedicated_vm_for_vds AS default_host,
			a.auto_startup AS high_availability,
            a.is_initialized AS initialized,
			a.is_stateless AS stateless,
			a.fail_back,
			cast(a.usb_policy as smallint) as usb_policy,
			a.time_zone,
			c.vm_pool_id,
			d.vm_pool_name,
			e.user_id AS created_by_user_id,
			a._create_date AS create_date,
            a._update_date AS update_date
FROM        vm_static as a
				INNER JOIN vm_static as b ON a.vmt_guid = b.vm_guid
				LEFT OUTER JOIN vm_pool_map as c ON a.vm_guid = c. vm_guid
					LEFT OUTER JOIN vm_pools as d ON c.vm_pool_id = d.vm_pool_id
				LEFT OUTER JOIN users as e ON a.created_by_user_id = e.user_id
WHERE     (a.entity_type = 'VM' AND b.entity_type = 'TEMPLATE') AND
          ((a._create_date >
                          (SELECT     var_datetime
                           FROM       dwh_history_timekeeping
                           WHERE      (var_name = 'lastSync'))) OR
          (a._update_date >
                          (SELECT     var_datetime
                           FROM       dwh_history_timekeeping AS history_timekeeping_1
                           WHERE      (var_name = 'lastSync'))) OR
          (b._update_date >
                          (SELECT     var_datetime
                           FROM       dwh_history_timekeeping AS history_timekeeping_1
                           WHERE      (var_name = 'lastSync'))));
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_vm_history_view
AS
SELECT
	c.vm_guid as vm_id,
	cast(b.status as smallint) as vm_status,
	cast(c.usage_cpu_percent as smallint) as cpu_usage_percent,
	cast(c.usage_mem_percent as smallint) as memory_usage_percent,
	cast(
		(c.cpu_sys / (vm_static.cpu_per_socket * vm_static.num_of_sockets))
		as smallint
	)
	as system_cpu_usage_percent,
	cast(
		(c.cpu_user / (vm_static.cpu_per_socket * vm_static.num_of_sockets))
		as smallint
	)
	as user_cpu_usage_percent,
	c.disks_usage,
	b.vm_ip,
	b.vm_fqdn,
	b.client_ip as vm_client_ip,
	b.console_user_id as current_user_id,
	CASE
		WHEN b.guest_cur_user_name IS NULL THEN FALSE
		ELSE TRUE
	END as user_logged_in_to_guest,
	b.run_on_vds as currently_running_on_host
FROM vm_dynamic b
    LEFT OUTER JOIN
        vm_statistics c ON  c.vm_guid = b.vm_guid
    INNER JOIN
        vm_static ON c.vm_guid = vm_static.vm_guid;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_vm_interface_configuration_history_view
AS
SELECT     	vm_interface.id AS vm_interface_id,
            vm_interface.name AS vm_interface_name,
            vm_interface.vm_guid AS vm_id,
            cast(vm_interface.type as smallint) as vm_interface_type,
            vm_interface.speed as vm_interface_speed_bps,
            vm_interface.mac_addr AS mac_address,
            network.name AS logical_network_name,
            vm_interface._create_date AS create_date,
            vm_interface._update_date AS update_date
FROM        vm_interface
            LEFT OUTER JOIN (vnic_profiles JOIN network ON network.id = vnic_profiles.network_id)
            ON vnic_profiles.id = vm_interface.vnic_profile_id
WHERE     vmt_guid IS NULL AND
          ((vm_interface._create_date >
                          (SELECT     var_datetime
                           FROM          dwh_history_timekeeping
                           WHERE      (var_name = 'lastSync'))) OR
          (vm_interface._update_date >
                          (SELECT     var_datetime
                           FROM          dwh_history_timekeeping AS history_timekeeping_1
                           WHERE      (var_name = 'lastSync'))));
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_vm_interface_history_view
AS
SELECT     vm_interface_statistics.id as vm_interface_id,
		   cast(vm_interface_statistics.rx_rate as smallint) as receive_rate_percent,
		   cast(vm_interface_statistics.tx_rate as smallint) as transmit_rate_percent
FROM       vm_interface_statistics;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_vm_disk_configuration_history_view
AS
SELECT d.disk_id AS vm_disk_id,
       d.disk_alias as vm_disk_name,
       d.disk_description as vm_disk_description,
       i.image_guid AS image_id,
       image_storage_domain_map.storage_domain_id as storage_domain_id,
       cast(i.size / 1048576 as int) as vm_disk_size_mb,
       cast(i.volume_type as smallint) AS vm_disk_type,
       cast(i.volume_format as smallint) AS vm_disk_format,
       CASE
           WHEN d.disk_interface = 'IDE' THEN cast(0 as smallint)
           WHEN d.disk_interface = 'SCSI' THEN cast(1 as smallint)
           WHEN d.disk_interface = 'VirtIO' THEN cast(2 as smallint)
       END AS vm_disk_interface,
       d.shareable as is_shared,
       i._create_date AS create_date,
       i._update_date AS update_date
FROM   images as i
           INNER JOIN
               base_disks as d ON i.image_group_id = d.disk_id
           INNER JOIN
               image_storage_domain_map ON image_storage_domain_map.image_id = i.image_guid
           LEFT OUTER JOIN vm_device ON vm_device.device_id = i.image_group_id
                               LEFT OUTER JOIN vm_static ON vm_static.vm_guid = vm_device.vm_id
WHERE     i.active = true AND
          (vm_static.entity_type = 'VM' OR vm_static.entity_type IS NULL) AND
          ((i._create_date >
                          (SELECT     var_datetime
                           FROM         dwh_history_timekeeping
                           WHERE      (var_name = 'lastSync'))) OR
          (i._update_date >
                          (SELECT     var_datetime
                           FROM         dwh_history_timekeeping AS history_timekeeping_1
                           WHERE      (var_name = 'lastSync'))));
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_disk_vm_map_history_view
AS
SELECT image_guid as vm_disk_id,
       vm_device.vm_id
  FROM vm_device
           INNER JOIN
               images ON vm_device.device_id = images.image_group_id
WHERE images.active = true;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_vm_device_history_view
AS
SELECT device_id,
       vm_id,
       type,
       address,
       is_managed,
       is_plugged,
       is_readonly,
       _create_date as create_date,
       _update_date as update_date
  FROM vm_device
WHERE  ((type = 'disk' AND
       device = 'disk') OR
       (type = 'interface')) AND
       ((_create_date >  (SELECT     var_datetime
                         FROM         dwh_history_timekeeping
                         WHERE      (var_name = 'lastSync'))) OR
       (_update_date >  (SELECT     var_datetime
                         FROM         dwh_history_timekeeping AS history_timekeeping_1
                         WHERE      (var_name = 'lastSync'))));
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_vm_disks_history_view
AS
SELECT  d.disk_id as vm_disk_id,
	images.image_guid as image_id,
	cast(images.imageStatus as smallint) as vm_disk_status,
	cast(disk_image_dynamic.actual_size / 1048576 as int) as vm_disk_actual_size_mb,
	disk_image_dynamic.read_rate as read_rate_bytes_per_second,
	disk_image_dynamic.read_latency_seconds as read_latency_seconds,
	disk_image_dynamic.write_rate as write_rate_bytes_per_second,
	disk_image_dynamic.write_latency_seconds as write_latency_seconds,
	disk_image_dynamic.flush_latency_seconds as flush_latency_seconds
FROM    images
            INNER JOIN
                 disk_image_dynamic ON images.image_guid = disk_image_dynamic.image_id
            INNER JOIN
                 base_disks as d ON images.image_group_id = d.disk_id
            LEFT OUTER JOIN vm_device ON vm_device.device_id = images.image_group_id
                                LEFT OUTER JOIN vm_static ON vm_static.vm_guid = vm_device.vm_id
WHERE images.active = true AND
      (vm_static.entity_type = 'VM' OR vm_static.entity_type IS NULL);
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_remove_tags_relations_history_view AS
SELECT    tag_id as entity_id,
		  parent_id as parent_id
FROM      tags
UNION ALL
SELECT    vds_id as vds_id,
          tag_id as tag_id
FROM      tags_vds_map
UNION ALL
SELECT     vm_pool_id as vm_pool_id,
           tag_id as tag_id
FROM       tags_vm_pool_map
UNION ALL
SELECT     vm_id as vm_id,
		   tag_id as tag_id
FROM       tags_vm_map
UNION ALL
SELECT     user_id as user_id,
		   tag_id as tag_id
FROM       tags_user_map
UNION ALL
SELECT    group_id as group_id,
		  tag_id as tag_id
FROM      tags_user_group_map;
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_add_tags_relations_history_view AS
SELECT    tag_id as entity_id,
		  parent_id as parent_id,
		  cast(18 as smallint) as entity_type,
		  _create_date as attach_date,
		  _update_date as move_date
FROM      tags
WHERE	  (_create_date >(SELECT     var_datetime as var_datetime
					      FROM          dwh_history_timekeeping
					      WHERE      (var_name = 'lastSync'))) OR
		  (_update_date >(SELECT     var_datetime as var_datetime
					   	  FROM       dwh_history_timekeeping AS history_timekeeping_1
						  WHERE      (var_name = 'lastSync')))
UNION ALL
SELECT    vds_id as vds_id,
          tag_id as tag_id,
          cast(3 as smallint),
		  _create_date,
		  null
FROM      tags_vds_map
WHERE	  _create_date >(SELECT     var_datetime as var_datetime
					      FROM          dwh_history_timekeeping
					      WHERE      (var_name = 'lastSync'))
UNION ALL
SELECT     vm_pool_id as vm_pool_id,
           tag_id as tag_id,
		   cast(5 as smallint),
		  _create_date,
		  null
FROM       tags_vm_pool_map
WHERE	  _create_date >(SELECT     var_datetime as var_datetime
					      FROM          dwh_history_timekeeping
					      WHERE      (var_name = 'lastSync'))
UNION ALL
SELECT     vm_id as vm_id,
		   tag_id as tag_id,
		   cast(2 as smallint),
		  _create_date,
		  null
FROM       tags_vm_map
WHERE	  _create_date >(SELECT     var_datetime as var_datetime
					      FROM          dwh_history_timekeeping
					      WHERE      (var_name = 'lastSync'))
UNION ALL
SELECT     user_id as user_id,
		   tag_id as tag_id,
		   cast(15 as smallint),
		  _create_date,
		  null
FROM       tags_user_map
WHERE	  _create_date >(SELECT     var_datetime as var_datetime
					      FROM          dwh_history_timekeeping
					      WHERE      (var_name = 'lastSync'))
UNION ALL
SELECT    group_id as group_id,
		  tag_id as tag_id,
		  cast(17 as smallint),
		  _create_date,
		  null
FROM      tags_user_group_map
WHERE	  _create_date >(SELECT     var_datetime as var_datetime
					      FROM          dwh_history_timekeeping
					      WHERE      (var_name = 'lastSync'));
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_tags_details_history_view AS
SELECT     	tag_id as tag_id,
			tag_name as tag_name,
			description as tag_description,
			_create_date as create_date,
			_update_date as update_date
FROM       tags
WHERE     (_create_date >(SELECT     var_datetime as var_datetime
						  FROM       dwh_history_timekeeping
						  WHERE      (var_name = 'lastSync'))) OR
          (_update_date >(SELECT     var_datetime as var_datetime
						  FROM       dwh_history_timekeeping AS history_timekeeping_1
						  WHERE      (var_name = 'lastSync')));
**************************

CREATE VIEW
********* QUERY **********
CREATE OR REPLACE VIEW dwh_users_history_view
AS
SELECT
    user_id,
    name AS first_name,
    surname AS last_name,
    domain,
    username,
    department,
    role AS user_role_title,
    email,
    external_id,
    active,
    _create_date AS create_date,
    _update_date AS update_date
FROM users;
**************************

CREATE VIEW
********* QUERY **********
Create or replace FUNCTION Insertaction_version_map(v_action_type INTEGER,
	v_cluster_minimal_version VARCHAR(40),
	v_storage_pool_minimal_version VARCHAR(40))
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO action_version_map(action_type, cluster_minimal_version, storage_pool_minimal_version)
	VALUES(v_action_type, v_cluster_minimal_version, v_storage_pool_minimal_version);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deleteaction_version_map(v_action_type INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM action_version_map
   WHERE action_type = v_action_type;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromaction_version_map() RETURNS SETOF action_version_map STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM action_version_map;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getaction_version_mapByaction_type(v_action_type INTEGER) RETURNS SETOF action_version_map STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM action_version_map
   WHERE action_type = v_action_type;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_delete_version_map(v_cluster_version varchar(10), v_sp_version varchar(40))
returns void
AS $procedure$
BEGIN
   DELETE
   FROM action_version_map
   WHERE cluster_minimal_version = v_cluster_version
     AND storage_pool_minimal_version = v_sp_version;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertGroup(v_id UUID,
	v_name VARCHAR(255),
	v_domain VARCHAR(100),
	v_distinguishedname VARCHAR(4000),
	v_external_id TEXT,
	v_namespace VARCHAR(2048))
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO ad_groups(id, name,domain,distinguishedname,external_id, namespace)
	VALUES(v_id, v_name,v_domain,v_distinguishedname,v_external_id, v_namespace);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGroup(v_id UUID,
	v_name VARCHAR(255),
	v_domain VARCHAR(100),
	v_distinguishedname VARCHAR(4000),
	v_external_id TEXT,
	v_namespace VARCHAR(2048))
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE ad_groups
      SET name = v_name,domain = v_domain,distinguishedname = v_distinguishedname,external_id = v_external_id, namespace = v_namespace
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGroup(v_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM tags_user_group_map
      WHERE group_id = v_id;
      DELETE FROM ad_groups
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllGroups() RETURNS SETOF ad_groups STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM ad_groups;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGroupById(v_id UUID) RETURNS SETOF ad_groups STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM ad_groups
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGroupByExternalId(v_domain VARCHAR(100), v_external_id TEXT) RETURNS SETOF ad_groups STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM ad_groups
      WHERE domain = v_domain AND external_id = v_external_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGroupByName(v_name VARCHAR(256)) RETURNS SETOF ad_groups STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM ad_groups
      WHERE name = v_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION getAllAffinityGroupsByVmId(v_vm_id UUID) RETURNS SETOF affinity_groups_view STABLE
AS $procedure$
BEGIN
   RETURN QUERY
    SELECT affinity_groups_view.*
    FROM affinity_groups_view
    JOIN affinity_group_members ON v_vm_id = affinity_group_members.vm_id
    AND affinity_group_members.affinity_group_id = affinity_groups_view.id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION getAllAffinityGroupsByClusterId(v_cluster_id UUID) RETURNS SETOF affinity_groups_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM affinity_groups_view
    WHERE cluster_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAffinityGroupByAffinityGroupId(v_id UUID) RETURNS SETOF affinity_groups_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM affinity_groups_view
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAffinityGroupByName(v_name VARCHAR(255)) RETURNS SETOF affinity_groups_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM affinity_groups_view
    WHERE name = v_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertAffinityGroupWithMembers(
    v_id UUID,
    v_name VARCHAR(255),
    v_description VARCHAR(4000),
    v_cluster_id UUID,
    v_positive BOOLEAN,
    v_enforcing BOOLEAN,
    v_vm_ids VARCHAR(4000)
)
RETURNS VOID
AS $procedure$
DECLARE
    iter_id UUID;
BEGIN
    INSERT INTO affinity_groups(
        id,
        name,
        description,
        cluster_id,
        positive,
        enforcing)
    VALUES(
        v_id,
        v_name,
        v_description,
        v_cluster_id,
        v_positive,
        v_enforcing);
    FOR iter_id IN (SELECT * FROM fnsplitteruuid(v_vm_ids))
    LOOP
        INSERT INTO affinity_group_members(
            affinity_group_id,
            vm_id)
        VALUES(
            v_id,
            iter_id);
    END LOOP;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteAffinityGroup(v_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE
    FROM affinity_groups
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateAffinityGroupWithMembers(
    v_id UUID,
    v_name VARCHAR(255),
    v_description VARCHAR(4000),
    v_cluster_id UUID,
    v_positive BOOLEAN,
    v_enforcing BOOLEAN,
    v_vm_ids VARCHAR(4000)
)
RETURNS VOID
AS $procedure$
BEGIN
    PERFORM DeleteAffinityGroup(v_id);
    PERFORM InsertAffinityGroupWithMembers(
        v_id,
        v_name,
        v_description,
        v_cluster_id,
        v_positive,
        v_enforcing,
        v_vm_ids);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION RemoveVmFromAffinityGroups(v_vm_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE
    FROM affinity_group_members
    WHERE vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromDisks(v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF all_disks STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   all_disks
    WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM user_disk_permissions_view
                                        WHERE user_id = v_user_id AND entity_id = disk_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetDiskByDiskId(v_disk_id UUID, v_user_id UUID, v_is_filtered boolean)
RETURNS SETOF all_disks STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   all_disks
    WHERE  image_group_id = v_disk_id
    AND    (NOT v_is_filtered OR EXISTS (SELECT 1
                                         FROM user_disk_permissions_view
                                         WHERE user_id = v_user_id AND entity_id = v_disk_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetDisksVmGuid(v_vm_guid UUID, v_only_plugged BOOLEAN, v_user_id UUID, v_is_filtered BOOLEAN)
RETURNS SETOF all_disks_including_snapshots STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT all_disks_including_snapshots.*
      FROM all_disks_including_snapshots
      LEFT JOIN vm_device ON vm_device.device_id = all_disks_including_snapshots.image_group_id AND (NOT v_only_plugged OR is_plugged)
      WHERE vm_device.vm_id = v_vm_guid
      AND ((vm_device.snapshot_id IS NULL AND all_disks_including_snapshots.active IS NOT FALSE)
          OR vm_device.snapshot_id = all_disks_including_snapshots.vm_snapshot_id)
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_disk_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = all_disks_including_snapshots.disk_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS disks_basic_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE disks_basic_rs AS (disk_id UUID,disk_alias varchar(255),size BIGINT);
**************************

CREATE TYPE
********* QUERY **********
Create or replace FUNCTION GetDisksVmGuidBasicView(v_vm_guid UUID, v_only_plugged BOOLEAN, v_user_id UUID, v_is_filtered BOOLEAN)
RETURNS SETOF disks_basic_rs STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT disk_id,disk_alias, size
      FROM images
      LEFT OUTER JOIN base_disks ON images.image_group_id = base_disks.disk_id
      LEFT JOIN vm_device ON vm_device.device_id = image_group_id AND (NOT v_only_plugged OR is_plugged)
      WHERE vm_device.vm_id = v_vm_guid
      AND images.active = true
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_disk_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = disk_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmBootActiveDisk(v_vm_guid UUID) RETURNS SETOF all_disks STABLE AS $procedure$
BEGIN
      RETURN QUERY SELECT all_disks.*
      FROM all_disks
      JOIN vm_device ON vm_device.device_id = all_disks.image_group_id
      WHERE vm_device.vm_id = v_vm_guid AND boot = TRUE AND vm_device.snapshot_id IS NULL;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllAttachableDisksByPoolId(v_storage_pool_id UUID, v_vm_id uuid,  v_user_id UUID, v_is_filtered BOOLEAN)
RETURNS SETOF all_disks STABLE
   AS $procedure$
BEGIN
    RETURN QUERY SELECT distinct all_disks.*
    FROM all_disks
    WHERE (v_storage_pool_id IS NULL OR all_disks.storage_pool_id = v_storage_pool_id)
    AND (all_disks.number_of_vms = 0 OR all_disks.shareable)
        -- ImageStatus.ILLEGAL=4 / imagestatus IS NULL -> LunDiski / ImageStatus.Locked=2
        AND (all_disks.imagestatus IS NULL OR (all_disks.imagestatus != 4 AND all_disks.imagestatus != 2))
        AND (v_vm_id IS NULL OR v_vm_id NOT IN (SELECT vm_id FROM vm_device WHERE vm_device.device_id = all_disks.image_group_id))
    AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_disk_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = disk_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertasync_tasks(v_action_type INTEGER,
	v_result INTEGER,
	v_status INTEGER,
	v_vdsm_task_id UUID,
	v_task_id UUID,
	v_step_id UUID,
	v_command_id UUID,
	v_root_command_id UUID,
        v_started_at timestamp WITH TIME ZONE,
	v_storage_pool_id UUID,
	v_async_task_type INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO async_tasks(action_type, result, status, vdsm_task_id, task_id, step_id, command_id, root_command_id, started_at,storage_pool_id, task_type)
	VALUES(v_action_type, v_result, v_status, v_vdsm_task_id, v_task_id, v_step_id, v_command_id, v_root_command_id, v_started_at, v_storage_pool_id, v_async_task_type);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updateasync_tasks(v_action_type INTEGER,
	v_result INTEGER,
	v_status INTEGER,
	v_vdsm_task_id UUID,
	v_task_id UUID,
	v_step_id UUID,
	v_command_id UUID,
	v_root_command_id UUID,
        v_storage_pool_id UUID)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE async_tasks
      SET action_type = v_action_type,
          result = v_result,
          status = v_status,
          step_id = v_step_id,
          command_id = v_command_id,
          root_command_id = v_root_command_id,
          vdsm_task_id = v_vdsm_task_id,
          storage_pool_id = v_storage_pool_id
      WHERE task_id = v_task_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertOrUpdateAsyncTasks(v_action_type INTEGER,
	v_result INTEGER,
	v_status INTEGER,
	v_vdsm_task_id UUID,
	v_task_id UUID,
	v_step_id UUID,
	v_command_id UUID,
	v_root_command_id UUID,
        v_started_at timestamp WITH TIME ZONE,
	v_storage_pool_id UUID,
	v_async_task_type INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      IF NOT EXISTS (SELECT 1 from async_tasks where async_tasks.task_id = v_task_id) THEN
            PERFORM Insertasync_tasks(v_action_type, v_result, v_status, v_vdsm_task_id, v_task_id,
            v_step_id, v_command_id, v_root_command_id, v_started_at, v_storage_pool_id, v_async_task_type);
      ELSE
            PERFORM Updateasync_tasks(v_action_type, v_result, v_status, v_vdsm_task_id, v_task_id, v_step_id, v_command_id, v_root_command_id, v_storage_pool_id);
      END IF;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertAsyncTaskEntities(
        v_task_id UUID,
        v_entity_id UUID,
        v_entity_type varchar(128))
RETURNS VOID
   AS $procedure$
BEGIN
      IF NOT EXISTS (SELECT 1 from async_tasks_entities where async_task_id = v_task_id and entity_id = v_entity_id) THEN
            INSERT INTO async_tasks_entities (async_task_id,entity_id,entity_type) VALUES (v_task_id, v_entity_id, v_entity_type);
      END IF;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetAsyncTasksIdsByEntityId(v_entity_id UUID)
RETURNS SETOF idUuidType STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT async_task_id from async_tasks_entities where entity_id = v_entity_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION  GetAsyncTaskEntitiesByTaskId(v_task_id UUID)
RETURNS SETOF async_tasks_entities STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM async_tasks_entities
   WHERE async_task_id = v_task_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deleteasync_tasks(v_task_id UUID)
RETURNS integer
   AS $procedure$
DECLARE
deleted_rows int;
BEGIN
   DELETE FROM async_tasks
   WHERE task_id = v_task_id;
   GET DIAGNOSTICS deleted_rows = ROW_COUNT;
   RETURN deleted_rows;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteAsyncTasksByVdsmTaskId(v_vdsm_task_id UUID)
RETURNS integer
   AS $procedure$
DECLARE
deleted_rows int;
BEGIN
   DELETE FROM async_tasks
   WHERE vdsm_task_id = v_vdsm_task_id;
   GET DIAGNOSTICS deleted_rows = ROW_COUNT;
   RETURN deleted_rows;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAsyncTasksByStoragePoolId(v_storage_pool_id UUID)
RETURNS SETOF idUuidType STABLE
  AS $procedure$
BEGIN
   RETURN QUERY SELECT async_tasks.task_id
   FROM  async_tasks
   WHERE storage_pool_id = v_storage_pool_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromasync_tasks() RETURNS SETOF async_tasks STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM async_tasks;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getasync_tasksBytask_id(v_task_id UUID) RETURNS SETOF async_tasks STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM async_tasks
   WHERE task_id = v_task_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAsyncTasksByEntityId(v_entity_id UUID) RETURNS SETOF async_tasks STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT async_tasks.*
   FROM async_tasks
   JOIN async_tasks_entities ON async_task_id = task_id
   WHERE entity_id = v_entity_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAsyncTasksByVdsmTaskId(v_vdsm_task_id UUID) RETURNS SETOF async_tasks STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM async_tasks
   WHERE vdsm_task_id = v_vdsm_task_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertAuditLog(INOUT v_audit_log_id INTEGER ,
 v_log_time TIMESTAMP WITH TIME ZONE,
 v_log_type INTEGER,
    v_log_type_name VARCHAR(100),
 v_severity INTEGER,
 v_message text,
 v_user_id UUID ,
 v_user_name VARCHAR(255) ,
 v_vds_id UUID ,
 v_vds_name VARCHAR(255) ,
 v_vm_id UUID ,
 v_vm_name VARCHAR(255) ,
 v_vm_template_id UUID ,
    v_vm_template_name VARCHAR(40) ,
    v_storage_pool_id UUID ,
    v_storage_pool_name VARCHAR(40) ,
    v_storage_domain_id UUID ,
    v_storage_domain_name VARCHAR(250) ,
    v_vds_group_id UUID ,
    v_vds_group_name VARCHAR(255),
    v_quota_id UUID,
    v_quota_name VARCHAR(60),
    v_correlation_id VARCHAR(50),
    v_job_id UUID,
    v_gluster_volume_id UUID,
    v_gluster_volume_name VARCHAR(1000),
    v_call_stack text)
   AS $procedure$
   DECLARE
   v_min_alret_severity  INTEGER;
BEGIN
      v_min_alret_severity := 10;
	-- insert regular log messages (non alerts)
      if (v_severity < v_min_alret_severity) then

INSERT INTO audit_log(LOG_TIME, log_type, log_type_name, severity,message, user_id, USER_NAME, vds_id, VDS_NAME, vm_id, VM_NAME,vm_template_id,VM_TEMPLATE_NAME,storage_pool_id,STORAGE_POOL_NAME,storage_domain_id,STORAGE_DOMAIN_NAME,vds_group_id,vds_group_name, correlation_id, job_id, quota_id, quota_name, gluster_volume_id, gluster_volume_name, call_stack)
		VALUES(v_log_time, v_log_type, v_log_type_name, v_severity, v_message, v_user_id, v_user_name, v_vds_id, v_vds_name, v_vm_id, v_vm_name,v_vm_template_id,v_vm_template_name,v_storage_pool_id,v_storage_pool_name,v_storage_domain_id,v_storage_domain_name,v_vds_group_id,v_vds_group_name, v_correlation_id, v_job_id, v_quota_id, v_quota_name, v_gluster_volume_id, v_gluster_volume_name, v_call_stack);

         v_audit_log_id := CURRVAL('audit_log_seq');
      else
         if (not exists(select audit_log_id from audit_log where vds_name = v_vds_name and log_type = v_log_type and not deleted)) then

INSERT INTO audit_log(LOG_TIME, log_type, log_type_name, severity,message, user_id, USER_NAME, vds_id, VDS_NAME, vm_id, VM_NAME,vm_template_id,VM_TEMPLATE_NAME,storage_pool_id,STORAGE_POOL_NAME,storage_domain_id,STORAGE_DOMAIN_NAME,vds_group_id,vds_group_name, correlation_id, job_id, quota_id, quota_name, gluster_volume_id, gluster_volume_name, call_stack)
			VALUES(v_log_time, v_log_type, v_log_type_name, v_severity, v_message, v_user_id, v_user_name, v_vds_id, v_vds_name, v_vm_id, v_vm_name,v_vm_template_id,v_vm_template_name,v_storage_pool_id,v_storage_pool_name,v_storage_domain_id,v_storage_domain_name,v_vds_group_id,v_vds_group_name, v_correlation_id, v_job_id, v_quota_id, v_quota_name, v_gluster_volume_id, v_gluster_volume_name, v_call_stack);

            v_audit_log_id := CURRVAL('audit_log_seq');
         else
            select   audit_log_id INTO v_audit_log_id from audit_log where vds_name = v_vds_name and log_type = v_log_type;
         end if;
      end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertExternalAuditLog(INOUT v_audit_log_id INTEGER ,
    v_log_time TIMESTAMP WITH TIME ZONE,
    v_log_type INTEGER,
    v_log_type_name VARCHAR(100),
    v_severity INTEGER,
    v_message text,
    v_user_id UUID ,
    v_user_name VARCHAR(255) ,
    v_vds_id UUID ,
    v_vds_name VARCHAR(255) ,
    v_vm_id UUID ,
    v_vm_name VARCHAR(255) ,
    v_vm_template_id UUID ,
    v_vm_template_name VARCHAR(40) ,
    v_storage_pool_id UUID ,
    v_storage_pool_name VARCHAR(40) ,
    v_storage_domain_id UUID ,
    v_storage_domain_name VARCHAR(250) ,
    v_vds_group_id UUID ,
    v_vds_group_name VARCHAR(255),
    v_quota_id UUID,
    v_quota_name VARCHAR(60),
    v_correlation_id VARCHAR(50),
    v_job_id UUID,
    v_gluster_volume_id UUID,
    v_gluster_volume_name VARCHAR(1000),
    v_call_stack text,
    v_origin VARCHAR(25),
    v_custom_event_id INTEGER,
    v_event_flood_in_sec INTEGER,
    v_custom_data text)
AS $procedure$
DECLARE
    v_max_message_length INTEGER;
    v_truncated_message text;
BEGIN

   -- truncate message if exceeds configured max length. truncated messages will be ended
   -- with "..." to indicate that message is incomplete due to size limits.

   v_truncated_message := v_message;
   v_max_message_length := cast(option_value as int) FROM vdc_options WHERE option_name = 'MaxAuditLogMessageLength' and version = 'general';
   IF (v_max_message_length IS NOT NULL and length(v_message) > v_max_message_length) THEN
      v_truncated_message := substr(v_message, 1, v_max_message_length -3) || '...';
   END IF;
   INSERT INTO audit_log(LOG_TIME, log_type, log_type_name, severity,message, user_id, USER_NAME, vds_id, VDS_NAME, vm_id, VM_NAME,vm_template_id,VM_TEMPLATE_NAME,storage_pool_id,STORAGE_POOL_NAME,storage_domain_id,STORAGE_DOMAIN_NAME,vds_group_id,vds_group_name, correlation_id, job_id, quota_id, quota_name, gluster_volume_id, gluster_volume_name, call_stack, origin, custom_event_id, event_flood_in_sec, custom_data )
		VALUES(v_log_time, v_log_type, v_log_type_name, v_severity, v_truncated_message, v_user_id, v_user_name, v_vds_id, v_vds_name, v_vm_id, v_vm_name,v_vm_template_id,v_vm_template_name,v_storage_pool_id,v_storage_pool_name,v_storage_domain_id,v_storage_domain_name,v_vds_group_id,v_vds_group_name, v_correlation_id, v_job_id, v_quota_id, v_quota_name, v_gluster_volume_id, v_gluster_volume_name, v_call_stack, v_origin, v_custom_event_id, v_event_flood_in_sec, v_custom_data);

   v_audit_log_id := CURRVAL('audit_log_seq');
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteAuditLog(v_audit_log_id INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE audit_log SET deleted = true
      WHERE audit_log_id = v_audit_log_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION ClearAllDismissedAuditLogs()
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE audit_log SET deleted = false;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromAuditLog(v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF audit_log STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM audit_log a
      WHERE NOT deleted AND
     (NOT v_is_filtered OR EXISTS (SELECT 1
                                   FROM   user_vm_permissions_view pv, user_object_permissions_view dpv
                                   WHERE  pv.user_id = v_user_id AND pv.entity_id = a.vm_id AND pv.entity_id = dpv.entity_id)
                        OR EXISTS (SELECT 1
                                   FROM user_vm_template_permissions_view pv, user_object_permissions_view dpv
                                   WHERE pv.user_id = v_user_id AND pv.entity_id = a.vm_template_id AND pv.entity_id = dpv.entity_id)
                        OR EXISTS (SELECT 1
                                   FROM user_vds_permissions_view pv, user_object_permissions_view dpv
                                   WHERE pv.user_id = v_user_id AND pv.entity_id = a.vds_id AND pv.entity_id = dpv.entity_id)
                        OR EXISTS (SELECT 1
                                   FROM user_storage_pool_permissions_view pv, user_object_permissions_view dpv
                                   WHERE pv.user_id = v_user_id AND pv.entity_id = a.storage_pool_id AND pv.entity_id = dpv.entity_id)
                        OR EXISTS (SELECT 1
                                   FROM user_storage_domain_permissions_view pv, user_object_permissions_view dpv
                                   WHERE pv.user_id = v_user_id AND pv.entity_id = a.storage_domain_id AND pv.entity_id = dpv.entity_id)
                        OR EXISTS (SELECT 1
                                   FROM user_vds_groups_permissions_view pv, user_object_permissions_view dpv
                                   WHERE pv.user_id = v_user_id AND pv.entity_id = a.vds_group_id AND pv.entity_id = dpv.entity_id)
     );
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAuditLogByAuditLogId(v_audit_log_id INTEGER) RETURNS SETOF audit_log STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM audit_log
      WHERE audit_log_id = v_audit_log_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAuditLogByVMId(v_vm_id UUID, v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF audit_log STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM   audit_log
      WHERE  not deleted and vm_id = v_vm_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = vm_id));


END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAuditLogByVMTemplateId(v_vm_template_id UUID, v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF audit_log STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM   audit_log
      WHERE  not deleted and vm_template_id = v_vm_template_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_template_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = vm_template_id));


END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAuditLogLaterThenDate(v_date TIMESTAMP WITH TIME ZONE)
RETURNS SETOF audit_log STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM audit_log
      WHERE not deleted and LOG_TIME >= v_date;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteAuditLogOlderThenDate(v_date TIMESTAMP WITH TIME ZONE)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_id  INTEGER;
   SWV_RowCount INTEGER;
BEGIN
        -- get first the id from which to remove in order to use index
      select   audit_log_id INTO v_id FROM audit_log WHERE LOG_TIME < v_date   order by audit_log_id desc LIMIT 1;
        -- check if there are candidates to remove
      GET DIAGNOSTICS SWV_RowCount = ROW_COUNT;
      if (SWV_RowCount > 0) then
         DELETE FROM audit_log
         WHERE audit_log_id <= v_id and
         audit_log_id not in(select audit_log_id from event_notification_hist);
      end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteAuditAlertLogByVdsIDAndType(v_vds_id UUID,
    v_log_type INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE audit_log set deleted = true
      where vds_id = v_vds_id and log_type = v_log_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteAuditLogAlertsByVdsID(v_vds_id UUID,
    v_delete_config_alerts BOOLEAN=true)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_min_alret_severity  INTEGER;
   v_no_config_alret_type  INTEGER;
   v_no_max_alret_type  INTEGER;
BEGIN
      v_min_alret_severity := 10;
      v_no_config_alret_type := 9000;
      v_no_max_alret_type := 9005;
      if (v_delete_config_alerts = true) then
         UPDATE audit_log set deleted = true
         where vds_id = v_vds_id and severity >= v_min_alret_severity and
         log_type  between v_no_config_alret_type and v_no_max_alret_type;
      else
         UPDATE audit_log set deleted = true
         where vds_id = v_vds_id and severity >= v_min_alret_severity and
         log_type  between v_no_config_alret_type + 1 and v_no_max_alret_type;
      end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/*
Used to find out how many seconds to wait after Start/Stop/Restart PM operations
v_vds_name     - The host name
v_event        - The event [USER_VDS_STOP | USER_VDS_START | USER_VDS_RESTART]
v_wait_for_sec - Configurable time in seconds to wait from last operation.
Returns : The number of seconds we have to wait (negative value means we can do the operation immediately)
*/
Create or replace FUNCTION get_seconds_to_wait_before_pm_operation(v_vds_name varchar(255), v_event varchar(100), v_wait_for_sec INTEGER ) RETURNS INTEGER STABLE
   AS $procedure$
declare v_last_event_dt timestamp with time zone;
declare v_now_dt timestamp with time zone;
BEGIN
      if exists(select 1 from audit_log where vds_name = v_vds_name and log_type_name = v_event) then
       begin
          v_last_event_dt := log_time
          from audit_log
          where vds_name = v_vds_name and log_type_name = v_event
          order by audit_log_id desc limit 1;
          v_now_dt :=  CURRENT_TIMESTAMP;
          RETURN cast((extract(epoch from v_last_event_dt) + v_wait_for_sec) - extract(epoch from v_now_dt) as int);
       end;
     else
          RETURN 0;
     end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAuditLogByOriginAndCustomEventId(v_origin varchar(255), v_custom_event_id INTEGER) RETURNS SETOF audit_log STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM audit_log
      WHERE origin = v_origin and custom_event_id = v_custom_event_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertBaseDisk(
    v_disk_id UUID,
    v_disk_interface VARCHAR(32),
    v_wipe_after_delete BOOLEAN,
    v_propagate_errors VARCHAR(32),
    v_disk_alias VARCHAR(50),
    v_disk_description VARCHAR(500),
    v_shareable BOOLEAN,
    v_boot BOOLEAN,
    v_sgio INTEGER,
    v_alignment SMALLINT,
    v_last_alignment_scan TIMESTAMP WITH TIME ZONE)
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO base_disks(
        disk_id,
        disk_interface,
        wipe_after_delete,
        propagate_errors,
        disk_alias,
        disk_description,
        shareable,
        boot,
        sgio,
        alignment,
        last_alignment_scan)
    VALUES(
        v_disk_id,
        v_disk_interface,
        v_wipe_after_delete,
        v_propagate_errors,
        v_disk_alias,
        v_disk_description,
        v_shareable,
        v_boot,
        v_sgio,
        v_alignment,
        v_last_alignment_scan);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateBaseDisk(
    v_disk_id UUID,
    v_disk_interface VARCHAR(32),
    v_wipe_after_delete BOOLEAN,
    v_propagate_errors VARCHAR(32),
    v_disk_alias VARCHAR(50),
    v_disk_description VARCHAR(500),
    v_shareable BOOLEAN,
    v_boot BOOLEAN,
    v_sgio INTEGER,
    v_alignment SMALLINT,
    v_last_alignment_scan TIMESTAMP WITH TIME ZONE)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE base_disks
    SET    disk_interface = v_disk_interface,
           wipe_after_delete = v_wipe_after_delete,
           propagate_errors = v_propagate_errors,
           disk_alias = v_disk_alias,
           disk_description = v_disk_description,
           shareable = v_shareable,
           boot = v_boot,
           sgio = v_sgio,
           alignment = v_alignment,
           last_alignment_scan = v_last_alignment_scan
    WHERE  disk_id = v_disk_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteBaseDisk(v_disk_id UUID)
RETURNS VOID
AS $procedure$
DECLARE
    v_val  UUID;
BEGIN
    DELETE
    FROM   base_disks
    WHERE  disk_id = v_disk_id;

    -- Delete the disk's permissions
   DELETE FROM permissions WHERE object_id = v_disk_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromBaseDisks() RETURNS SETOF base_disks STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   base_disks;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetBaseDiskByBaseDiskId(v_disk_id UUID)
RETURNS SETOF base_disks STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   base_disks
    WHERE  disk_id = v_disk_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertBookmark(v_bookmark_id UUID,
	v_bookmark_name VARCHAR(40),
	v_bookmark_value VARCHAR(300))
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO bookmarks(bookmark_Id,bookmark_name, bookmark_value)
	VALUES(v_bookmark_id, v_bookmark_name, v_bookmark_value);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateBookmark(v_bookmark_id UUID,
    v_bookmark_name VARCHAR(40),
	v_bookmark_value VARCHAR(300))
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE bookmarks
      SET bookmark_name = v_bookmark_name,bookmark_value = v_bookmark_value
      WHERE bookmark_Id = v_bookmark_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteBookmark(v_bookmark_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM bookmarks
      WHERE bookmark_Id = v_bookmark_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromBookmarks() RETURNS SETOF bookmarks STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM bookmarks;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetBookmarkBybookmark_name(v_bookmark_name VARCHAR(40))
RETURNS SETOF bookmarks STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM bookmarks
      WHERE bookmark_name = v_bookmark_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetBookmarkBybookmark_id(v_bookmark_id UUID)
RETURNS SETOF bookmarks STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM bookmarks
      WHERE bookmark_Id = v_bookmark_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllVm_poolsByUser_id_with_groups_and_UserRoles(v_user_id UUID)
RETURNS SETOF vm_pools_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT pools.*
	FROM vm_pools_view pools
    INNER JOIN user_vm_pool_permissions_view ON user_id = v_user_id AND entity_id = pools.vm_pool_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION insert_entity_snapshot(v_id uuid, v_command_id uuid,v_command_type character varying , v_entity_id character varying, v_entity_type character varying, v_entity_snapshot text, v_snapshot_class character varying, v_snapshot_type INTEGER,v_insertion_order INTEGER)
  RETURNS void AS
$procedure$
BEGIN
	BEGIN
		INSERT INTO business_entity_snapshot(id, command_id, command_type, entity_id,entity_type,entity_snapshot, snapshot_class, snapshot_type,insertion_order)
				VALUES(v_id, v_command_id, v_command_type, v_entity_id,v_entity_type,v_entity_snapshot, v_snapshot_class, v_snapshot_type,v_insertion_order);
	END;

   RETURN;
END; $procedure$
  LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION get_entity_snapshot_by_id(v_id uuid)
  RETURNS SETOF business_entity_snapshot STABLE AS
$procedure$
BEGIN
      RETURN QUERY SELECT business_entity_snapshot.*
      FROM business_entity_snapshot
      WHERE id = v_id;
END; $procedure$
  LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION get_entity_snapshot_by_command_id(v_command_id uuid)
  RETURNS SETOF business_entity_snapshot STABLE AS
$procedure$
BEGIN
      RETURN QUERY SELECT business_entity_snapshot.*
      FROM business_entity_snapshot
      WHERE command_id = v_command_id order by insertion_order desc;
END; $procedure$
  LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS get_all_commands_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE get_all_commands_rs  AS(command_id UUID, command_type varchar(256));
**************************

CREATE TYPE
********* QUERY **********
CREATE OR REPLACE FUNCTION get_all_commands()
  RETURNS SETOF get_all_commands_rs STABLE AS
$procedure$
BEGIN
      RETURN QUERY SELECT distinct business_entity_snapshot.command_id, business_entity_snapshot.command_type
      FROM business_entity_snapshot;

END; $procedure$
  LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION delete_entity_snapshot_by_command_id(v_command_id uuid)
  RETURNS void AS
$procedure$
BEGIN
	BEGIN
		delete from business_entity_snapshot where command_id = v_command_id;
	END;
	RETURN;
END; $procedure$
  LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromClusterPolicys() RETURNS SETOF cluster_policies STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   cluster_policies;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetClusterPolicyByClusterPolicyId(v_id UUID) RETURNS SETOF cluster_policies STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   cluster_policies
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertClusterPolicy(
    v_id UUID,
    v_name VARCHAR(128),
    v_description VARCHAR(4000),
    v_is_locked BOOLEAN,
    v_is_default BOOLEAN,
    v_custom_properties text)
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO cluster_policies(
        id,
        name,
        description,
        is_locked,
        is_default,
        custom_properties)
    VALUES(
        v_id,
        v_name,
        v_description,
        v_is_locked,
        v_is_default,
        v_custom_properties);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateClusterPolicy(
    v_id UUID,
    v_name VARCHAR(128),
    v_description VARCHAR(4000),
    v_is_locked BOOLEAN,
    v_is_default BOOLEAN,
    v_custom_properties text)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE cluster_policies
    SET    name = v_name,
           description = v_description,
           is_locked = v_is_locked,
           is_default = v_is_default,
           custom_properties = v_custom_properties
    WHERE  id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteClusterPolicy(v_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE
    FROM   cluster_policies
    WHERE  id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromClusterPolicyUnits() RETURNS SETOF cluster_policy_units STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   cluster_policy_units;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetClusterPolicyUnitsByClusterPolicyId(v_id UUID) RETURNS SETOF cluster_policy_units STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   cluster_policy_units
    WHERE cluster_policy_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteClusterPolicyUnitsByClusterPolicyId(v_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE
    FROM   cluster_policy_units
    WHERE  cluster_policy_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertClusterPolicyUnit(
    v_cluster_policy_id UUID,
    v_policy_unit_id UUID,
    v_filter_sequence int,
    v_factor int)
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO cluster_policy_units(
        cluster_policy_id,
        policy_unit_id,
        filter_sequence,
        factor)
    VALUES(
        v_cluster_policy_id,
        v_policy_unit_id,
        v_filter_sequence,
        v_factor);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION InsertCommandEntity (v_command_id uuid,
       v_command_type int,
       v_root_command_id uuid,
       v_job_id uuid,
       v_step_id uuid,
       v_command_parameters text,
       v_command_params_class varchar(256),
       v_status varchar(20),
       v_executed boolean,
       v_callback_enabled boolean,
       v_return_value text,
       v_return_value_class varchar(256))
RETURNS VOID
   AS $procedure$
BEGIN
       INSERT INTO command_entities(command_id, command_type, root_command_id, job_id, step_id, command_parameters, command_params_class, created_at, status, executed, callback_enabled, return_value, return_value_class)
              VALUES(v_command_id, v_command_type, v_root_command_id, v_job_id, v_step_id, v_command_parameters, v_command_params_class, NOW(), v_status, v_executed, v_callback_enabled, v_return_value, v_return_value_class);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpdateCommandEntity (v_command_id uuid,
       v_command_type int,
       v_root_command_id uuid,
       v_job_id uuid,
       v_step_id uuid,
       v_command_parameters text,
       v_command_params_class varchar(256),
       v_status varchar(20),
       v_executed boolean,
       v_callback_enabled boolean,
       v_return_value text,
       v_return_value_class varchar(256))
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE command_entities
      SET command_type = v_command_type ,
          root_command_id = v_root_command_id,
          job_id = v_job_id,
          step_id = v_step_id,
          command_parameters = v_command_parameters,
          command_params_class = v_command_params_class,
          status = v_status,
          executed = v_executed,
          callback_enabled = v_callback_enabled,
          return_value = v_return_value,
          return_value_class = v_return_value_class
      WHERE command_id = v_command_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpdateCommandEntityStatus (v_command_id uuid,
       v_status varchar(20))
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE command_entities
      SET status = v_status
      WHERE command_id = v_command_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpdateCommandEntityExecuted(v_command_id uuid,
       v_executed boolean)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE command_entities
      SET executed = v_executed
      WHERE command_id = v_command_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpdateCommandEntityNotified(v_command_id uuid,
       v_callback_notified boolean)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE command_entities
      SET callback_notified = v_callback_notified
      WHERE command_id = v_command_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION InsertOrUpdateCommandEntity (v_command_id uuid,
       v_command_type int,
       v_root_command_id uuid,
       v_job_id uuid,
       v_step_id uuid,
       v_command_parameters text,
       v_command_params_class varchar(256),
       v_status varchar(20),
       v_executed boolean,
       v_callback_enabled boolean,
       v_return_value text,
       v_return_value_class varchar(256))
RETURNS VOID
   AS $procedure$
BEGIN
      IF NOT EXISTS (SELECT 1 from command_entities where command_id = v_command_id) THEN
            PERFORM InsertCommandEntity (v_command_id, v_command_type, v_root_command_id, v_job_id, v_step_id, v_command_parameters, v_command_params_class, v_status, v_executed, v_callback_enabled, v_return_value, v_return_value_class);
      ELSE
            PERFORM UpdateCommandEntity (v_command_id, v_command_type, v_root_command_id, v_job_id, v_step_id, v_command_parameters, v_command_params_class, v_status, v_executed, v_callback_enabled, v_return_value, v_return_value_class);
      END IF;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetCommandEntityByCommandEntityId (v_command_id uuid)
RETURNS SETOF command_entities
   AS $procedure$
BEGIN
      RETURN QUERY SELECT command_entities.*
      FROM command_entities
      WHERE command_id = v_command_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetAllFromCommandEntities ()
RETURNS SETOF command_entities
   AS $procedure$
BEGIN
      RETURN QUERY SELECT * from command_entities;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION DeleteCommandEntity(v_command_id uuid)
RETURNS VOID
   AS $procedure$
BEGIN
      BEGIN
              delete from command_entities where command_id = v_command_id;
      END;
      RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteCommandEntitiesOlderThanDate(v_date TIMESTAMP WITH TIME ZONE)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_id  INTEGER;
   SWV_RowCount INTEGER;
BEGIN
      DELETE FROM command_entities
      WHERE CREATED_AT < v_date and
      command_id NOT IN(SELECT command_id FROM async_tasks);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_add_column(v_table varchar(128), v_column varchar(128), v_column_def text)
returns void
AS $procedure$
declare
v_sql text;

begin
	if (not exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ADD COLUMN ' || v_column || ' ' || v_column_def;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_drop_column(v_table varchar(128), v_column varchar(128))
returns void
AS $procedure$
declare
v_sql text;
begin
        if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
            begin
                v_sql := 'ALTER TABLE ' || v_table || ' DROP COLUMN ' || v_column;
                EXECUTE v_sql;
            end;
        end if;
end;$procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_change_column_type(v_table varchar(128), v_column varchar(128),
                                                    v_type varchar(128), v_new_type varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column and (udt_name ilike v_type or data_type ilike v_type))) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ALTER COLUMN ' || v_column || ' TYPE ' || v_new_type;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_rename_column(v_table varchar(128), v_column varchar(128), v_new_name varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' RENAME COLUMN ' || v_column || ' TO ' || v_new_name;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (not exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            insert into vdc_options (option_name, option_value, version) values (v_option_name, v_option_value, v_version);
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value_all_versions(v_option_name varchar(100))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name)) then
        begin
            delete from vdc_options where option_name ilike v_option_name;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value(v_option_name varchar(100), v_version text)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version)))) then
        begin
            delete from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version));
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_for_version(v_version text)
returns void
AS $procedure$
BEGIN
     delete from vdc_options where version in (select ID from fnSplitter(v_version));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            update  vdc_options set option_value = v_option_value
            where option_name ilike v_option_name and version = v_version;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_default_config_value(v_option_name varchar(100),v_default_option_value varchar(4000),v_option_value varchar(4000),v_version varchar(40),v_ignore_default_value_case boolean)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            if (v_ignore_default_value_case)
            then
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value ilike v_default_option_value and version = v_version;
            else
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value = v_default_option_value and version = v_version;
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_rename_config_key(v_old_option_name varchar(100),v_new_option_name varchar(100),v_version varchar(40))
returns void
AS $procedure$
DECLARE
    v_current_option_value varchar(4000);
begin
    if (exists (select 1 from vdc_options where option_name ilike v_old_option_name and version = v_version)) then
       v_current_option_value:=option_value from vdc_options where option_name ilike v_old_option_name and version = v_version;
       update vdc_options set option_name = v_new_option_name, option_value = v_current_option_value
           where  option_name ilike v_old_option_name and version = v_version;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_create_constraint (
    v_table varchar(128), v_constraint varchar(128), v_constraint_sql text)
returns void
AS $procedure$
begin
    if  NOT EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' ADD CONSTRAINT ' || v_constraint || ' ' || v_constraint_sql;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_drop_constraint (
    v_table varchar(128), v_constraint varchar(128))
returns void
AS $procedure$
begin
    if  EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' DROP CONSTRAINT ' || v_constraint || ' CASCADE';
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION CheckDBConnection() RETURNS SETOF integer IMMUTABLE
   AS $procedure$
BEGIN
    RETURN QUERY SELECT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_functions_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'drop function if exists ' || ns.nspname || '.' || proname || '(' || oidvectortypes(proargtypes) || ') cascade;' from pg_proc inner join pg_namespace ns on (pg_proc.pronamespace=ns.oid) where ns.nspname = 'public' order by proname;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_views_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP VIEW if exists ' || table_name || ' CASCADE;' from information_schema.views where table_schema = 'public' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_tables_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP TABLE if exists ' || table_name || ' CASCADE;' from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_seq_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP SEQUENCE if exists ' || sequence_name || ' CASCADE;' from information_schema.sequences  where sequence_schema = 'public' order by sequence_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_user_types_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT 'DROP TYPE if exists ' || c.relname::information_schema.sql_identifier || ' CASCADE;'
   FROM pg_namespace n, pg_class c, pg_type t
   WHERE n.oid = c.relnamespace and t.typrelid = c.oid and c.relkind = 'c'::"char" and
   n.nspname = 'public'
   ORDER BY  c.relname::information_schema.sql_identifier;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_get_column_size( v_table varchar(64), v_column varchar(64)) returns integer STABLE
   AS $procedure$
   declare
   retvalue  integer;
BEGIN
   retvalue := character_maximum_length from information_schema.columns
    where
    table_name ilike v_table and column_name ilike v_column and
    table_schema = 'public' and udt_name in ('char','varchar');
   return retvalue;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION attach_user_to_role (
    v_domain_entry_id text,
    v_user_name VARCHAR(255),
    v_domain VARCHAR(255),
    v_role_name VARCHAR(255)
)
RETURNS void AS
$BODY$
DECLARE
   gen_user_id uuid;
   input_role_id uuid;
BEGIN
   select uuid_generate_v1() into gen_user_id;
   select roles.id into input_role_id from roles where roles.name = v_role_name;
   -- The external identifier is the user identifier converted to an array of
   -- bytes:
   insert into users(user_id,external_id,name,domain,username,groups,active,last_admin_check_status) select gen_user_id, v_domain_entry_id, v_user_name, v_domain, v_user_name,'',true,true where not exists (select gen_user_id,name,domain,username,groups,active from users where external_id = v_domain_entry_id);
   insert into permissions(id,role_id,ad_element_id,object_id,object_type_id) select uuid_generate_v1(),  input_role_id, gen_user_id, getGlobalIds('system'), 1 where not exists(select role_id,ad_element_id,object_id,object_type_id from permissions where role_id = input_role_id and ad_element_id = gen_user_id and object_id= getGlobalIds('system') and object_type_id = 1);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_add_action_group_to_role(v_role_id UUID, v_action_group_id INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
       INSERT INTO roles_groups(role_id,action_group_id)
       SELECT v_role_id, v_action_group_id
       WHERE NOT EXISTS (SELECT 1
                         FROM roles_groups
                         WHERE role_id = v_role_id
                         AND action_group_id = v_action_group_id);
RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_split_config_value(v_option_name character varying, v_old_option_value character varying, v_new_option_value character varying, v_update_from_version character varying)
  RETURNS void AS
$BODY$
declare
v_old_value varchar(4000);
v_cur cursor for select distinct version from vdc_options where version <> 'general' order by version;
v_version varchar(40);
v_index integer;
v_count integer;
v_total_count integer;
v_version_count integer;
begin
    v_total_count := count(version) from vdc_options where option_name = v_option_name;
    v_old_value := option_value from vdc_options where option_name = v_option_name and version = 'general';
    v_version_count := count(distinct version) from vdc_options where version <> 'general';
    if (v_total_count <= v_version_count) then
        begin
            if (v_old_value IS NULL) then
                v_old_value := v_old_option_value;
            end if;
            v_count := count(distinct version) from vdc_options where version <> 'general';
            v_index := 1;
        open v_cur;
        loop
            fetch v_cur into v_version;
            exit when not found;
            -- We shouldn't update if already exists
            if (not exists (select 1 from vdc_options where option_name = v_option_name and version = v_version)) then
                -- Might not work well for versions such as 3.10, but we currently don't have any
                if (v_version >= v_update_from_version) then
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_new_option_value, v_version);
                else
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_old_value, v_version);
                end if;
            end if;
            v_index := v_index +1;
        end loop;
        close v_cur;
        delete from vdc_options where option_name = v_option_name and version = 'general';
        end;
    end if;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_grant_action_group_to_all_roles_filter(v_action_group_id integer, uuid[])
  RETURNS void AS
$BODY$
declare
v_role_id_to_filter alias for $2;
begin
    insert into roles_groups (role_id, action_group_id)
    select distinct role_id, v_action_group_id
    from roles_groups rg
    where not ARRAY [role_id] <@ v_role_id_to_filter and not exists (select 1 from roles_groups where role_id = rg.role_id and action_group_id = v_action_group_id);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_mask_object(v_object regclass) RETURNS setof record as
$BODY$
DECLARE
    v_sql TEXT;
    v_table record;
    v_table_name TEXT;
    temprec record;
BEGIN
    -- get full table/view name from v_object (i.e <namespace>.<name>)
    select c.relname, n.nspname INTO v_table
        FROM pg_class c join pg_namespace n on c.relnamespace = n.oid WHERE c.oid = v_object;
    -- try to get filtered query syntax from previous execution
    if exists (select 1 from object_column_white_list_sql where object_name = v_table.relname) then
	select sql into v_sql from object_column_white_list_sql where object_name = v_table.relname;
    else
        v_table_name := quote_ident( v_table.nspname ) || '.' || quote_ident( v_table.relname );
        -- compose sql statement while skipping values for columns not defined in object_column_white_list for this table.
        for temprec in select a.attname, t.typname
                       FROM pg_attribute a join pg_type t on a.atttypid = t.oid
                       WHERE a.attrelid = v_object AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
        loop
            v_sql := coalesce( v_sql || ', ', 'SELECT ' );
            if exists(select 1 from object_column_white_list
               where object_name = v_table.relname and column_name = temprec.attname) then
               v_sql := v_sql || quote_ident( temprec.attname );
            ELSE
               v_sql := v_sql || 'NULL::' || quote_ident( temprec.typname ) || ' as ' || quote_ident( temprec.attname );
            END IF;
        END LOOP;
        v_sql := v_sql || ' FROM ' || v_table_name;
        v_sql := 'SELECT x::' || v_table_name || ' as rec FROM (' || v_sql || ') as x';
        -- save generated query for further use
        insert into object_column_white_list_sql(object_name,sql) values (v_table.relname, v_sql);
    end if;
    RETURN QUERY EXECUTE v_sql;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_column_to_object_white_list(v_object_name varchar(128), v_column_name varchar(128))
returns void
AS $procedure$
begin
    if (not exists (select 1 from object_column_white_list
                    where object_name = v_object_name and column_name = v_column_name)) then
        begin
            -- verify that there is such object in db
            if exists (select 1 from information_schema.columns
                       where table_name = v_object_name and column_name = v_column_name) then
                insert into object_column_white_list (object_name, column_name) values (v_object_name, v_column_name);
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_disk(v_id UUID)
returns void
AS $procedure$
declare
    OK integer;
    LOCKED integer;
begin
    OK:=1;
    LOCKED:=2;
    update images set imagestatus = OK where imagestatus = LOCKED and
    image_group_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_snapshot(v_id UUID)
returns void
AS $procedure$
declare
    OK varchar;
    LOCKED varchar;
begin
    OK:='OK';
    LOCKED:='LOCKED';
    update snapshots set status = OK where status = LOCKED and snapshot_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_entity(v_object_type varchar(10), v_name varchar(255), v_recursive boolean)
returns void
AS $procedure$
declare
    DOWN integer;
    OK integer;
    LOCKED integer;
    TEMPLATE_OK integer;
    TEMPLATE_LOCKED integer;
    IMAGE_LOCKED integer;
    SNAPSHOT_OK varchar;
    SNAPSHOT_LOCKED varchar;
    v_id UUID;
begin
    DOWN:=0;
    OK:=1;
    LOCKED:=2;
    TEMPLATE_OK:=0;
    TEMPLATE_LOCKED:=1;
    IMAGE_LOCKED:=15;
    SNAPSHOT_OK:='OK';
    SNAPSHOT_LOCKED:='LOCKED';
    v_id := vm_guid from vm_static where vm_name = v_name and entity_type ilike v_object_type;
    -- set VM status to DOWN
    if (v_object_type = 'vm') then
        update vm_dynamic set status = DOWN where status = IMAGE_LOCKED and vm_guid  = v_id;
    -- set Template status to OK
    else
        if (v_object_type = 'template') then
            update vm_static set template_status = TEMPLATE_OK where template_status = TEMPLATE_LOCKED and vm_guid  = v_id;
        end if;
    end if;
    --unlock images and snapshots  if recursive flag is set
    if (v_recursive) then
        update images set imagestatus = OK where imagestatus = LOCKED and
        image_group_id in (select device_id from vm_device where vm_id = v_id and is_plugged);

        update snapshots set status = SNAPSHOT_OK where status ilike SNAPSHOT_LOCKED and vm_id = v_id;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/* Displays DC id , DC name, SPM Host id , SPM Host name and number of async tasks awaiting.

1) create a record type with DC name, DC id, SPM host id, SPM host name, count

2) get all distinct DC ids from async_tasks table

3) Run a cursor for each result in 2)

   a) get DC name
   b) get SPM Host id & name if available
   c) get count of tasks

   return current record

4) return set of generated records
*/
DROP TYPE IF EXISTS async_tasks_info_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE async_tasks_info_rs AS (
        dc_id uuid,
        dc_name character varying,
        spm_host_id uuid,
        spm_host_name character varying,
        task_count integer
);
**************************

CREATE TYPE
********* QUERY **********
create or replace FUNCTION fn_db_get_async_tasks()
returns SETOF async_tasks_info_rs STABLE
AS $procedure$
DECLARE
    v_record async_tasks_info_rs;

    -- selects storage_pool_id uuid found in async_tasks
    v_tasks_cursor cursor for select distinct storage_pool_id from async_tasks;
begin

    OPEN v_tasks_cursor;
    FETCH v_tasks_cursor into v_record.dc_id;
    WHILE FOUND LOOP
        -- get dc_name and SPM Host id
        v_record.dc_name := name from storage_pool where id = v_record.dc_id;
        v_record.spm_host_id :=
            spm_vds_id from storage_pool where id = v_record.dc_id;
        -- get Host name if we have non NULL SPM Host
        if (v_record.spm_host_id IS NOT NULL) then
            v_record.spm_host_name :=
                vds_name from vds_static where vds_id = v_record.spm_host_id;
        else
            v_record.spm_host_name:='';
        end if;
        -- get tasks count for this DC
        v_record.task_count := count(*) from async_tasks
            where position (cast(v_record.dc_id as varchar) in action_parameters) > 0;
        -- return the record
        RETURN NEXT v_record;
        FETCH v_tasks_cursor into v_record.dc_id;
    END LOOP;
    CLOSE v_tasks_cursor;
    -- return full set of generated records
    RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_remove_csv_config_value(v_option_name varchar(100), v_value varchar(4000), v_version varchar(40))
returns void
AS $procedure$
DECLARE
v varchar[];
e varchar;
v_result varchar;
v_sep varchar(1);
BEGIN
v_result := '';
v_sep := '';
    v := string_to_array(option_value, ',') from vdc_options where option_name = v_option_name and version = v_version;
    FOR e in select unnest(v)
    LOOP
        IF (e != v_value) THEN
            v_result := v_result || v_sep || e;
            v_sep := ',';
        END IF;
    END LOOP;
    UPDATE vdc_options set option_value = v_result where option_name = v_option_name and version = v_version;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetCpuProfileByCpuProfileId(v_id UUID)
RETURNS SETOF cpu_profiles STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM cpu_profiles
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertCpuProfile(v_id UUID,
  v_name VARCHAR(50),
  v_cluster_id UUID,
  v_qos_id UUID,
  v_description TEXT)
RETURNS VOID
   AS $procedure$
BEGIN

   INSERT INTO cpu_profiles(id, name, cluster_id, qos_id, description)
       VALUES(v_id, v_name, v_cluster_id, v_qos_id, v_description);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateCpuProfile(v_id UUID,
  v_name VARCHAR(50),
  v_cluster_id UUID,
  v_qos_id UUID,
  v_description TEXT)
RETURNS VOID
   AS $procedure$
BEGIN

   UPDATE cpu_profiles
   SET id = v_id, name = v_name, cluster_id = v_cluster_id, qos_id = v_qos_id,
       description = v_description, _update_date = LOCALTIMESTAMP
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteCpuProfile(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val UUID;
BEGIN

    DELETE FROM cpu_profiles
    WHERE id = v_id;

    -- Delete the cpu profiles permissions
    DELETE FROM permissions WHERE object_id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromCpuProfiles()
RETURNS SETOF cpu_profiles STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM cpu_profiles;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetCpuProfilesByClusterId(v_cluster_id UUID,  v_user_id UUID, v_is_filtered boolean)
RETURNS SETOF cpu_profiles STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM cpu_profiles
   WHERE cluster_id = v_cluster_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_vds_groups_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = v_cluster_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetCpuProfilesByQosId(v_qos_id UUID)
RETURNS SETOF cpu_profiles STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM cpu_profiles
   WHERE qos_id = v_qos_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertcustom_actions(INOUT v_action_id INTEGER ,
	v_action_name VARCHAR(50),
	v_path VARCHAR(300),
	v_tab INTEGER ,
	v_description VARCHAR(4000))
   AS $procedure$
BEGIN
INSERT INTO custom_actions(action_name, path, tab, description)
	VALUES(v_action_name, v_path, v_tab, v_description);

      v_action_id := CURRVAL('custom_actions_seq');
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatecustom_actions(v_action_id INTEGER,
	v_action_name VARCHAR(50),
	v_path VARCHAR(300),
	v_tab INTEGER ,
	v_description VARCHAR(4000))
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE custom_actions
      SET action_name = v_action_name,path = v_path,tab = v_tab,description = v_description
      WHERE action_id = v_action_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletecustom_actions(v_action_id INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM custom_actions
      WHERE action_id = v_action_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromcustom_actions() RETURNS SETOF custom_actions STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM custom_actions;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getcustom_actionsByaction_id(v_action_id INTEGER)
RETURNS SETOF custom_actions STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM custom_actions
      WHERE action_id = v_action_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getcustom_actionsByTab_id(v_tab INTEGER) RETURNS SETOF custom_actions STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM custom_actions
      WHERE tab = v_tab;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getcustom_actionsByNameAndTab(v_action_name VARCHAR(50),
	v_tab INTEGER) RETURNS SETOF custom_actions STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM custom_actions
      WHERE tab = v_tab and action_name = v_action_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertdisk_image_dynamic(v_image_id UUID,
	v_read_rate INTEGER ,
	v_write_rate INTEGER ,
	v_actual_size BIGINT,
	v_read_latency_seconds numeric(18,9),
	v_write_latency_seconds numeric(18,9),
	v_flush_latency_seconds numeric(18,9)
)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO disk_image_dynamic(image_id, read_rate, write_rate, actual_size, read_latency_seconds, write_latency_seconds, flush_latency_seconds)
	VALUES(v_image_id, v_read_rate, v_write_rate, v_actual_size, v_read_latency_seconds, v_write_latency_seconds, v_flush_latency_seconds);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatedisk_image_dynamic(v_image_id UUID,
	v_read_rate INTEGER ,
	v_write_rate INTEGER ,
	v_actual_size BIGINT ,
	v_read_latency_seconds numeric(18,9) ,
	v_write_latency_seconds numeric(18,9) ,
	v_flush_latency_seconds numeric(18,9))
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE disk_image_dynamic
      SET read_rate = v_read_rate,write_rate = v_write_rate,actual_size = v_actual_size,read_latency_seconds = v_read_latency_seconds,write_latency_seconds = v_write_latency_seconds,flush_latency_seconds = v_flush_latency_seconds, _update_date = LOCALTIMESTAMP
      WHERE image_id = v_image_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatedisk_image_dynamic_by_disk_id_and_vm_id(v_image_group_id UUID,
  v_vm_id UUID,
	v_read_rate INTEGER ,
	v_write_rate INTEGER ,
	v_actual_size BIGINT ,
	v_read_latency_seconds numeric(18,9) ,
	v_write_latency_seconds numeric(18,9) ,
	v_flush_latency_seconds numeric(18,9))
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE disk_image_dynamic
      SET read_rate = v_read_rate,write_rate = v_write_rate,actual_size = v_actual_size,read_latency_seconds = v_read_latency_seconds,write_latency_seconds = v_write_latency_seconds,flush_latency_seconds = v_flush_latency_seconds, _update_date = LOCALTIMESTAMP
      WHERE image_id in (SELECT distinct image_guid
    		FROM   images
    		WHERE  image_group_id = v_image_group_id and active = true)
    		AND EXISTS (SELECT 1 FROM vm_device vmd
    		            WHERE vmd.vm_id = v_vm_id AND vmd.device_id = v_image_group_id AND vmd.snapshot_id is NULL);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletedisk_image_dynamic(v_image_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM disk_image_dynamic
   WHERE image_id = v_image_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromdisk_image_dynamic() RETURNS SETOF disk_image_dynamic STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM disk_image_dynamic;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getdisk_image_dynamicByimage_id(v_image_id UUID)
RETURNS SETOF disk_image_dynamic STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM disk_image_dynamic
   WHERE image_id = v_image_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TRIGGER IF EXISTS delete_disk_image_dynamic_for_image ON images;
**************************

DROP TRIGGER
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_image_deleted() RETURNS TRIGGER AS $$
BEGIN
    DELETE FROM disk_image_dynamic dim WHERE DIM.image_id = OLD.image_guid;
    RETURN OLD;
END;
$$ LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE TRIGGER delete_disk_image_dynamic_for_image BEFORE DELETE ON IMAGES FOR EACH ROW
EXECUTE PROCEDURE fn_image_deleted();
**************************

CREATE TRIGGER
********* QUERY **********
Create or replace FUNCTION GetImageByImageGuid(v_image_guid UUID)
RETURNS SETOF vm_images_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM vm_images_view
      WHERE image_guid = v_image_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAncestralImageByImageGuid(v_image_guid UUID)
RETURNS SETOF images_storage_domain_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY WITH RECURSIVE ancestor_image(image_guid, parentid) AS (
         SELECT image_guid, parentid
         FROM images
         WHERE image_guid = v_image_guid
         UNION ALL
         SELECT i.image_guid, i.parentid
         FROM images i, ancestor_image ai
         WHERE i.image_guid = ai.parentid
      )
      SELECT i.*
      FROM ancestor_image ai, images_storage_domain_view i
      WHERE ai.parentid = '00000000-0000-0000-0000-000000000000'
      AND ai.image_guid = i.image_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotByGuid(v_image_guid UUID)
RETURNS SETOF images_storage_domain_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view images_storage_domain_view
      WHERE image_guid = v_image_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotsByStorageDomainId(v_storage_domain_id UUID)
RETURNS SETOF images_storage_domain_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view images_storage_domain_view
      WHERE storage_id = v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotByParentGuid(v_parent_guid UUID)
RETURNS SETOF images_storage_domain_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view images_storage_domain_view
      WHERE ParentId = v_parent_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotByLeafGuid(v_image_guid UUID)
RETURNS SETOF images_storage_domain_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY WITH RECURSIVE image_list AS (
          SELECT *
          FROM   images_storage_domain_view
          WHERE  image_guid = v_image_guid
          UNION ALL
          SELECT images_storage_domain_view.*
          FROM   images_storage_domain_view
          JOIN   image_list ON
                 image_list.parentid = images_storage_domain_view.image_guid AND
                 image_list.image_group_id = images_storage_domain_view.image_group_id
      )
      SELECT *
      FROM image_list;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmImageByImageGuid(v_image_guid UUID)
RETURNS SETOF vm_images_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM vm_images_view
      WHERE image_guid = v_image_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotsByVmSnapshotId(v_vm_snapshot_id UUID)
RETURNS SETOF images_storage_domain_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view images_storage_domain_view
      WHERE vm_snapshot_id = v_vm_snapshot_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAttachedDiskSnapshotsToVm(v_vm_guid UUID, v_is_plugged BOOLEAN)
RETURNS SETOF images_storage_domain_view
   AS $procedure$
BEGIN
      RETURN QUERY SELECT images_storage_domain_view.*
      FROM images_storage_domain_view
      JOIN vm_device ON vm_device.device_id = images_storage_domain_view.disk_id
      WHERE vm_device.vm_id = v_vm_guid AND (v_is_plugged IS NULL OR vm_device.is_plugged = v_is_plugged)
            AND vm_device.snapshot_id IS NOT NULL
            AND vm_device.snapshot_id = images_storage_domain_view.vm_snapshot_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotsByImageGroupId(v_image_group_id UUID)
RETURNS SETOF images_storage_domain_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view images_storage_domain_view
      WHERE image_group_id = v_image_group_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetDiskSnapshotForVmSnapshot(v_image_group_id UUID, v_vm_snapshot_id UUID)
RETURNS SETOF images_storage_domain_view
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM images_storage_domain_view
      WHERE image_group_id = v_image_group_id
      AND vm_snapshot_id = v_vm_snapshot_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllForStorageDomain(v_storage_domain_id UUID)
RETURNS SETOF images_storage_domain_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT images_storage_domain_view.*
      FROM  images_storage_domain_view
      WHERE active AND images_storage_domain_view.storage_id = v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetImagesWhichHaveNoDisk(v_vm_id UUID)
RETURNS SETOF images_storage_domain_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT i.*
      FROM   images_storage_domain_view i
      JOIN   snapshots s ON (i.vm_snapshot_id = s.snapshot_id)
      WHERE  s.vm_id = v_vm_id
      AND    NOT EXISTS (
          SELECT 1
          FROM   base_disks d
          WHERE  d.disk_id = i.image_group_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertDiskLunMap(
    v_disk_id UUID,
    v_lun_id VARCHAR(50))
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO disk_lun_map(
        disk_id,
        lun_id)
    VALUES(
        v_disk_id,
        v_lun_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteDiskLunMap(v_disk_id UUID, v_lun_id VARCHAR(50))
RETURNS VOID
AS $procedure$
BEGIN
    DELETE
    FROM   disk_lun_map
    WHERE  disk_id = v_disk_id
    AND    lun_id = v_lun_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromDiskLunMaps() RETURNS SETOF disk_lun_map STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   disk_lun_map;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetDiskLunMapByDiskLunMapId(v_disk_id UUID, v_lun_id VARCHAR(50))
RETURNS SETOF disk_lun_map STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   disk_lun_map
    WHERE  disk_id = v_disk_id
    AND    lun_id = v_lun_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetDiskLunMapByLunId(v_lun_id VARCHAR(50))
RETURNS SETOF disk_lun_map STABLE
AS $procedure$
BEGIN
	RETURN QUERY
    SELECT *
    FROM   disk_lun_map
    WHERE  lun_id = v_lun_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetDiskProfileByDiskProfileId(v_id UUID)
RETURNS SETOF disk_profiles STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM disk_profiles
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertDiskProfile(v_id UUID,
  v_name VARCHAR(50),
  v_storage_domain_id UUID,
  v_qos_id UUID,
  v_description TEXT)
RETURNS VOID
   AS $procedure$
BEGIN

   INSERT INTO disk_profiles(id, name, storage_domain_id, qos_id, description)
       VALUES(v_id, v_name, v_storage_domain_id, v_qos_id, v_description);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateDiskProfile(v_id UUID,
  v_name VARCHAR(50),
  v_storage_domain_id UUID,
  v_qos_id UUID,
  v_description TEXT)
RETURNS VOID
   AS $procedure$
BEGIN

   UPDATE disk_profiles
   SET id = v_id, name = v_name, storage_domain_id = v_storage_domain_id, qos_id = v_qos_id,
       description = v_description, _update_date = LOCALTIMESTAMP
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteDiskProfile(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val UUID;
BEGIN

    DELETE FROM disk_profiles
    WHERE id = v_id;

    -- Delete the disk profiles permissions
    DELETE FROM permissions WHERE object_id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromDiskProfiles()
RETURNS SETOF disk_profiles STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM disk_profiles;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetDiskProfilesByStorageDomainId(v_storage_domain_id UUID,  v_user_id UUID, v_is_filtered boolean)
RETURNS SETOF disk_profiles STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM disk_profiles
   WHERE storage_domain_id = v_storage_domain_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_storage_domain_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = v_storage_domain_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION nullifyQosForStorageDomain(v_storage_domain_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
UPDATE disk_profiles
   SET qos_id = NULL
   WHERE storage_domain_id = v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetDiskProfilesByQosId(v_qos_id UUID)
RETURNS SETOF disk_profiles STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM disk_profiles
   WHERE qos_id = v_qos_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateDwhHistoryTimekeeping(v_var_name VARCHAR(50),
    v_var_value VARCHAR(255),
    v_var_datetime TIMESTAMP WITH TIME ZONE)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE dwh_history_timekeeping
      SET var_value = v_var_value,
          var_datetime = v_var_datetime
      WHERE var_name = v_var_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetDwhHistoryTimekeepingByVarName(v_var_name VARCHAR(50))
RETURNS SETOF dwh_history_timekeeping STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM dwh_history_timekeeping
   WHERE var_name = v_var_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION clear_osinfo()
  RETURNS VOID
AS $procedure$
BEGIN
      TRUNCATE dwh_osinfo;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION insert_osinfo(v_os_id INTEGER , v_os_name VARCHAR(255))
RETURNS VOID
   AS $procedure$
BEGIN
      INSERT into dwh_osinfo (os_id, os_name) VALUES (v_os_id, v_os_name);
      UPDATE dwh_history_timekeeping SET var_datetime = now() where var_name = 'lastOsinfoUpdate';
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION insertevent_notification_hist(v_audit_log_id BIGINT,
	v_event_name VARCHAR(100),
	v_method_type  CHAR(10),
	v_reason CHAR(255) ,
	v_sent_at TIMESTAMP WITH TIME ZONE,
	v_status BOOLEAN)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO event_notification_hist(audit_log_id, event_name, method_type, reason, sent_at, status)
	VALUES(v_audit_log_id, v_event_name, v_method_type, v_reason, v_sent_at, v_status);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertevent_subscriber(v_event_up_name VARCHAR(100),
	v_notification_method VARCHAR(32),
    v_method_address VARCHAR(255),
	v_subscriber_id UUID,
	v_tag_name VARCHAR(50))
RETURNS VOID
   AS $procedure$
BEGIN
      if not exists(select * from  event_subscriber where
      subscriber_id = v_subscriber_id and
      event_up_name = v_event_up_name and
      notification_method = v_notification_method and
      tag_name = v_tag_name) then

INSERT INTO event_subscriber(event_up_name, notification_method, method_address, subscriber_id, tag_name)
			VALUES(v_event_up_name, v_notification_method, v_method_address, v_subscriber_id,v_tag_name);
      end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getevent_subscriberBysubscriber_id(v_subscriber_id UUID)
RETURNS SETOF event_subscriber STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM event_subscriber
   WHERE subscriber_id = v_subscriber_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deleteevent_subscriber(v_event_up_name VARCHAR(100) ,
  v_notification_method VARCHAR(32),
	v_subscriber_id UUID,
    v_tag_name VARCHAR(50))
RETURNS VOID
   AS $procedure$
BEGIN
      if (v_tag_name IS NULL) then
         delete from event_subscriber
         where event_up_name = v_event_up_name
         and notification_method = v_notification_method
         and subscriber_id = v_subscriber_id;
      else
         delete from event_subscriber
         where event_up_name = v_event_up_name
         and notification_method = v_notification_method
         and subscriber_id = v_subscriber_id
         and tag_name = v_tag_name;
      end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetEventMapByName(v_event_name VARCHAR(100))
RETURNS SETOF event_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      from event_map
      where event_up_name = v_event_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deleteevent_notification_hist(v_sent_at TIMESTAMP)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM event_notification_hist WHERE sent_at < v_sent_at;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION InsertExternalVariable(
        v_var_name VARCHAR(100),
        v_var_value VARCHAR(4000))
RETURNS VOID
    AS $procedure$
BEGIN
    INSERT INTO external_variable(
            var_name,
            var_value
        ) VALUES (
            v_var_name,
            v_var_value
        );
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpdateExternalVariable(
        v_var_name VARCHAR(100),
        v_var_value VARCHAR(4000))
RETURNS BOOLEAN
    AS $procedure$
BEGIN
    UPDATE external_variable
        SET
            var_value = v_var_value,
            _update_date = LOCALTIMESTAMP
        WHERE var_name = v_var_name;
    RETURN found;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpsertExternalVariable(
        v_var_name VARCHAR(100),
        v_var_value VARCHAR(4000))
RETURNS VOID
    AS $procedure$
DECLARE
    record_found BOOLEAN;
BEGIN
    SELECT UpdateExternalVariable(
        v_var_name,
        v_var_value
    ) INTO record_found;

    IF NOT record_found THEN
        PERFORM InsertExternalVariable(
                v_var_name,
                v_var_value
        );
    END IF;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION DeleteExternalVariable(
        v_var_name VARCHAR(100))
RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM external_variable
        WHERE var_name = v_var_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetExternalVariableByName(
        v_var_name VARCHAR(100))
RETURNS SETOF external_variable STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT external_variable.*
        FROM external_variable
        WHERE var_name = v_var_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/* ----------------------------------------------------------------
 Stored procedures for database operations on Gluster Hooks
 related tables:
      - gluster_hooks
      - gluster_server_hooks
----------------------------------------------------------------*/
Create or replace FUNCTION InsertGlusterHook(v_id UUID,
                                             v_cluster_id UUID,
                                             v_gluster_command VARCHAR(128),
                                             v_stage VARCHAR(50),
                                             v_name VARCHAR(256),
                                             v_hook_status VARCHAR(50),
                                             v_content_type VARCHAR(50),
                                             v_checksum VARCHAR(256),
                                             v_content TEXT,
                                             v_conflict_status INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO gluster_hooks(id, cluster_id, gluster_command, stage, name, hook_status,
    content_type, checksum, content, conflict_status)
    VALUES (v_id, v_cluster_id, v_gluster_command, v_stage, v_name,v_hook_status,
    v_content_type, v_checksum, v_content, v_conflict_status);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterHookById(v_id UUID,
                                              v_includeContent BOOLEAN=false)
RETURNS SETOF gluster_hooks STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT id, cluster_id, gluster_command, stage, name,
    hook_status, content_type, checksum,
    CASE v_includeContent WHEN true THEN content
                          ELSE null::text
    END as content,
    conflict_status,
    _create_date, _update_date
    FROM  gluster_hooks
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterHookContentById(v_id UUID)
RETURNS SETOF text STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT content
    FROM  gluster_hooks
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterHooksByClusterId(v_cluster_id UUID)
RETURNS SETOF gluster_hooks STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT id, cluster_id, gluster_command, stage, name,
    hook_status, content_type, checksum, null::text as content, conflict_status,
    _create_date, _update_date
    FROM  gluster_hooks
    WHERE cluster_id = v_cluster_id order by gluster_command asc, stage asc;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServerHooksById(v_id UUID)
RETURNS SETOF gluster_server_hooks_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_server_hooks_view
    WHERE hook_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterHook(v_cluster_id UUID,
                                          v_gluster_command VARCHAR(1000),
                                          v_stage VARCHAR(100),
                                          v_name VARCHAR(1000),
                                          v_includeContent BOOLEAN=false)
RETURNS SETOF gluster_hooks STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT id, cluster_id, gluster_command, stage, name,
    hook_status, content_type, checksum,
    CASE v_includeContent WHEN true THEN content
                          ELSE null::text
    END as content,
    conflict_status,
    _create_date, _update_date
    FROM  gluster_hooks
    WHERE cluster_id = v_cluster_id AND gluster_command = v_gluster_command
    AND stage = v_stage AND name = v_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterHookById(v_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM gluster_hooks
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterHook(v_cluster_id UUID,
                                             v_gluster_command VARCHAR(1000),
                                             v_stage VARCHAR(100),
                                             v_name VARCHAR(1000))
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM gluster_hooks
    WHERE cluster_id = v_cluster_id AND gluster_command = v_gluster_command
    AND stage = v_stage AND name = v_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteAllGlusterHooks(v_cluster_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM gluster_hooks
    WHERE cluster_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterHooksByIds(v_ids TEXT)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM gluster_hooks
    WHERE id in (select * from fnSplitterUuid(v_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterHookConflictStatus(v_id UUID,
                                                           v_conflict_status INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE gluster_hooks
    SET conflict_status = v_conflict_status,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterHookContentType(v_id UUID,
                                                        v_content_type VARCHAR(100))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE gluster_hooks
    SET content_type = v_content_type,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterHookContent(v_id UUID,
                                                    v_checksum VARCHAR(256),
                                                    v_content text)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE gluster_hooks
    SET checksum = v_checksum,
        content = v_content,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterHook(v_id UUID,
                                             v_hook_status VARCHAR(50),
                                             v_content_type VARCHAR(50),
                                             v_checksum VARCHAR(256),
                                             v_content TEXT,
                                             v_conflict_status INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE gluster_hooks
    SET hook_status = v_hook_status,
        content_type = v_content_type,
        checksum = v_checksum,
        content = v_content,
        conflict_status = v_conflict_status,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterHookStatus(v_id UUID,
                                                   v_hook_status VARCHAR(50))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE gluster_hooks
    SET hook_status = v_hook_status,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertGlusterServerHook(v_hook_id UUID,
                                                   v_server_id UUID,
                                                   v_hook_status VARCHAR(50),
                                                   v_content_type VARCHAR(50),
                                                   v_checksum VARCHAR(256))
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO gluster_server_hooks(hook_id, server_id, hook_status, content_type, checksum)
    VALUES(v_hook_id, v_server_id, v_hook_status, v_content_type, v_checksum);
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id = v_hook_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServerHook(v_hook_id UUID,
                                                v_server_id UUID)
RETURNS SETOF gluster_server_hooks_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_server_hooks_view
    WHERE hook_id = v_hook_id AND server_id = v_server_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterServerHook(v_hook_id UUID,
                                                   v_server_id UUID,
                                                   v_hook_status VARCHAR(50),
                                                   v_content_type VARCHAR(50),
                                                   v_checksum VARCHAR(256))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE gluster_server_hooks
    SET hook_status = v_hook_status,
        content_type = v_content_type,
        checksum = v_checksum,
        _update_date = LOCALTIMESTAMP
    WHERE hook_id = v_hook_id AND server_id = v_server_id;
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id = v_hook_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterServerHookStatus(v_hook_id UUID,
                                                         v_server_id UUID,
                                                         v_hook_status VARCHAR(100))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE gluster_server_hooks
    SET hook_status = v_hook_status,
        _update_date = LOCALTIMESTAMP
    WHERE hook_id = v_hook_id AND server_id = v_server_id;
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id = v_hook_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterServerHookChecksum(v_hook_id UUID,
                                                           v_server_id UUID,
                                                           v_checksum VARCHAR(100))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE gluster_server_hooks
    SET checksum = v_checksum,
        _update_date = LOCALTIMESTAMP
    WHERE hook_id = v_hook_id AND server_id = v_server_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterServerHookById(v_hook_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM gluster_server_hooks
    WHERE hook_id = v_hook_id;
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id = v_hook_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterServerHooksByIds(v_ids TEXT)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM gluster_server_hooks
    WHERE hook_id in (select * from fnSplitterUuid(v_ids));
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id in (select * from fnSplitterUuid(v_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterServerHook(v_hook_id UUID,
                                                   v_server_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM gluster_server_hooks
    WHERE hook_id = v_hook_id AND server_id = v_server_id;
    UPDATE gluster_hooks
    SET _update_date = LOCALTIMESTAMP
    WHERE id = v_hook_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/*--------------------------------------------------------------
Stored procedures for database operations on gluster_server table
--------------------------------------------------------------*/
Create or replace FUNCTION InsertGlusterServer(v_server_id UUID,
                                            v_gluster_server_uuid UUID)
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO gluster_server(server_id, gluster_server_uuid)
    VALUES (v_server_id, v_gluster_server_uuid);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServerByServerId(v_server_id UUID)
RETURNS SETOF gluster_server STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT server_id, gluster_server_uuid
    FROM gluster_server
    WHERE server_id = v_server_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServerByGlusterServerUUID(v_gluster_server_uuid UUID)
RETURNS SETOF gluster_server STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT server_id, gluster_server_uuid
    FROM gluster_server
    WHERE gluster_server_uuid = v_gluster_server_uuid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterServer(v_server_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM gluster_server
    WHERE server_id = v_server_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterServerByGlusterServerUUID(v_gluster_server_uuid UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM gluster_server
    WHERE gluster_server_uuid = v_gluster_server_uuid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterServer(v_server_id UUID,
                                            v_gluster_server_uuid UUID)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE gluster_server
    SET gluster_server_uuid = v_gluster_server_uuid
    WHERE server_id = v_server_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/* ----------------------------------------------------------------
 Stored procedures for database operations on Services
 related tables:
      - gluster_service_types
      - gluster_services
      - gluster_cluster_services
      - gluster_server_services
----------------------------------------------------------------*/

Create or replace FUNCTION GetGlusterServiceTypes()
    RETURNS SETOF gluster_service_types STABLE
    AS $procedure$
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_service_types;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServicesByType(v_service_type VARCHAR(100))
    RETURNS SETOF gluster_services STABLE
    AS $procedure$
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_services
    WHERE   service_type = v_service_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterClusterServicesByClusterId(v_cluster_id UUID)
    RETURNS SETOF gluster_cluster_services STABLE
    AS $procedure$
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_cluster_services
    WHERE   cluster_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterClusterServicesByClusterIdAndServiceType(v_cluster_id UUID,
                                                                v_service_type VARCHAR(100))
    RETURNS SETOF gluster_cluster_services STABLE
    AS $procedure$
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_cluster_services
    WHERE   cluster_id = v_cluster_id
    AND     service_type = v_service_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServerServicesByServerId(v_server_id UUID)
    RETURNS SETOF gluster_server_services_view STABLE
    AS $procedure$
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_server_services_view
    WHERE   server_id = v_server_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServerServicesByClusterId(v_cluster_id UUID)
    RETURNS SETOF gluster_server_services_view STABLE
    AS $procedure$
BEGIN
    RETURN  QUERY SELECT s.*
    FROM    gluster_server_services_view s, vds_static v
    WHERE   s.server_id = v.vds_id
    AND     v.vds_group_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServerServicesByClusterIdAndServiceType(v_cluster_id UUID, v_service_type VARCHAR(100))
    RETURNS SETOF gluster_server_services_view STABLE
    AS $procedure$
BEGIN
    RETURN  QUERY SELECT s.*
    FROM    gluster_server_services_view s, vds_static v
    WHERE   s.server_id = v.vds_id
    AND     v.vds_group_id = v_cluster_id
    AND     s.service_type = v_service_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServerServicesByServerIdAndServiceType(v_server_id UUID, v_service_type VARCHAR(100))
    RETURNS SETOF gluster_server_services_view STABLE
    AS $procedure$
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_server_services_view
    WHERE   server_id = v_server_id
    AND     service_type = v_service_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServiceByGlusterServiceId(v_id UUID)
RETURNS SETOF gluster_services STABLE
AS $procedure$
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_services
    WHERE   id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServerServiceByGlusterServerServiceId(v_id UUID)
RETURNS SETOF gluster_server_services_view STABLE
AS $procedure$
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_server_services_view
    WHERE   id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromGlusterServerServices()
RETURNS SETOF gluster_server_services_view STABLE
AS $procedure$
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_server_services_view;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterServiceByTypeAndName(v_service_type VARCHAR(100),
                                                        v_service_name VARCHAR(100))
RETURNS SETOF gluster_services STABLE
AS $procedure$
BEGIN
    RETURN  QUERY SELECT *
    FROM    gluster_services
    WHERE   service_type = v_service_type
    AND     service_name = v_service_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromGlusterServices()
RETURNS SETOF gluster_services STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT * FROM gluster_services;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertGlusterClusterService(v_cluster_id UUID,
                                                v_service_type VARCHAR(100),
                                                v_status VARCHAR(32))
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO gluster_cluster_services(cluster_id, service_type, status)
    VALUES (v_cluster_id, v_service_type, v_status);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertGlusterServerService(v_id UUID,
                                                v_server_id UUID,
                                                v_service_id UUID,
                                                v_pid INTEGER,
                                                v_status VARCHAR(32),
                                                v_message VARCHAR(1000))
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO gluster_server_services(id, server_id, service_id, pid, status, message)
    VALUES (v_id, v_server_id, v_service_id, v_pid, v_status, v_message);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterClusterService(v_cluster_id UUID,
                                                    v_service_type VARCHAR(100),
                                                    v_status VARCHAR(32))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE  gluster_cluster_services
    SET     status = v_status,
            _update_date = LOCALTIMESTAMP
    WHERE   cluster_id = v_cluster_id
    AND     service_type = v_service_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterServerService(v_id UUID,
                                                v_pid INTEGER,
                                                v_status VARCHAR(32),
                                                v_message VARCHAR(1000))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE  gluster_server_services
    SET     pid = v_pid,
            status = v_status,
            message = v_message,
            _update_date = LOCALTIMESTAMP
    WHERE   id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterServerServiceByServerIdAndServiceType(v_server_id UUID,
                                                v_service_id UUID,
                                                v_pid INTEGER,
                                                v_status VARCHAR(32),
                                                v_message VARCHAR(1000))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE  gluster_server_services
    SET     pid = v_pid,
            status = v_status,
            message = v_message,
            _update_date = LOCALTIMESTAMP
    WHERE   server_id = v_server_id
    AND     service_id = v_service_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterServerService(v_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM gluster_server_services
    WHERE   id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/* ----------------------------------------------------------------
 Stored procedures for database operations on Gluster Volume
 related tables:
      - gluster_volumes
      - gluster_volume_bricks
      - gluster_volume_options
      - gluster_volume_access_protocols
      - gluster_volume_transport_types
----------------------------------------------------------------*/
Create or replace FUNCTION InsertGlusterVolume(v_id UUID, v_cluster_id UUID,
                                                v_vol_name VARCHAR(1000),
                                                v_vol_type VARCHAR(32),
                                                v_status VARCHAR(32),
                                                v_replica_count INTEGER,
                                                v_stripe_count INTEGER)
    RETURNS VOID
    AS $procedure$
BEGIN
    INSERT INTO gluster_volumes (id, cluster_id, vol_name, vol_type,
        status, replica_count, stripe_count)
    VALUES (v_id,  v_cluster_id, v_vol_name, v_vol_type,
        v_status, v_replica_count,  v_stripe_count);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertGlusterVolumeDetails(v_volume_id UUID,
                                                v_total_space bigint,
                                                v_used_space bigint,
                                                v_free_space bigint)
    RETURNS VOID
    AS $procedure$
BEGIN
    INSERT INTO gluster_volume_details (volume_id, total_space, used_space, free_space, _update_date)
    VALUES (v_volume_id, v_total_space, v_used_space, v_free_space, LOCALTIMESTAMP);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertGlusterVolumeBrick(v_id UUID, v_volume_id UUID,
                                                    v_server_id UUID,
                                                    v_brick_dir VARCHAR(4096),
                                                    v_brick_order INTEGER,
                                                    v_status VARCHAR(32))
    RETURNS VOID
    AS $procedure$
BEGIN
    INSERT INTO gluster_volume_bricks (id, volume_id, server_id, brick_dir, brick_order, status)
    VALUES (v_id, v_volume_id, v_server_id, v_brick_dir, v_brick_order, v_status);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertGlusterVolumeBrickDetails(v_brick_id UUID,
                                                v_total_space bigint,
                                                v_used_space bigint,
                                                v_free_space bigint)
    RETURNS VOID
    AS $procedure$
BEGIN
    INSERT INTO gluster_volume_brick_details (brick_id, total_space, used_space, free_space, _update_date)
    VALUES (v_brick_id, v_total_space, v_used_space, v_free_space, LOCALTIMESTAMP);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertGlusterVolumeOption(v_id UUID, v_volume_id UUID,
                                                    v_option_key VARCHAR(8192),
                                                    v_option_val VARCHAR(8192))
    RETURNS VOID
    AS $procedure$
BEGIN
    INSERT INTO gluster_volume_options (id, volume_id, option_key, option_val)
    VALUES (v_id, v_volume_id, v_option_key, v_option_val);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertGlusterVolumeAccessProtocol(v_volume_id UUID,
                                                    v_access_protocol VARCHAR(32))
    RETURNS VOID
    AS $procedure$
BEGIN
    INSERT INTO gluster_volume_access_protocols (volume_id, access_protocol)
    VALUES (v_volume_id, v_access_protocol);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertGlusterVolumeTransportType(v_volume_id UUID,
                                                    v_transport_type VARCHAR(32))
    RETURNS VOID
    AS $procedure$
BEGIN
    INSERT INTO gluster_volume_transport_types (volume_id, transport_type)
    VALUES (v_volume_id, v_transport_type);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterVolumesByClusterGuid(v_cluster_id UUID)
    RETURNS SETOF gluster_volumes_view STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volumes_view
    WHERE cluster_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterVolumesByOption(v_cluster_id UUID,
                                                       v_status VARCHAR(32),
                                                       v_option_key VARCHAR(8192),
                                                       v_option_val VARCHAR(8192))
RETURNS SETOF gluster_volumes_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volumes_view
    WHERE cluster_id = v_cluster_id AND status = v_status
    AND id IN (SELECT volume_id FROM gluster_volume_options
    WHERE option_key=v_option_key AND option_val=v_option_val);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterVolumesByStatusTypesAndOption(v_cluster_id UUID,
                                                                  v_status VARCHAR(32),
                                                                  v_vol_types text,
                                                                  v_option_key VARCHAR(8192),
                                                                  v_option_val VARCHAR(8192))
RETURNS SETOF gluster_volumes_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volumes_view
    WHERE cluster_id = v_cluster_id AND status = v_status
    AND vol_type IN (SELECT ID FROM fnSplitter(v_vol_types))
    AND id IN (SELECT volume_id FROM gluster_volume_options
    WHERE option_key=v_option_key AND option_val=v_option_val);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterVolumesByStatusAndTypes(v_cluster_id UUID,
                                                         v_status VARCHAR(32),
                                                         v_vol_types text)
RETURNS SETOF gluster_volumes_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volumes_view
    WHERE cluster_id = v_cluster_id AND status = v_status
    AND vol_type IN (SELECT ID FROM fnSplitter(v_vol_types));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterVolumeById(v_volume_id UUID)
    RETURNS SETOF gluster_volumes_view STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM gluster_volumes_view
    WHERE id = v_volume_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterVolumeByName(v_cluster_id UUID,
                                            v_vol_name VARCHAR(1000))
RETURNS SETOF gluster_volumes_view STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM gluster_volumes_view
    WHERE cluster_id = v_cluster_id and vol_name = v_vol_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterVolumeByGlusterTaskId(v_task_id UUID)
RETURNS SETOF gluster_volumes_view STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM gluster_volumes_view
    WHERE task_id = v_task_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterVolumeDetailsById(v_volume_id UUID)
    RETURNS SETOF gluster_volume_details STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volume_details
    WHERE volume_id = v_volume_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterBrickById(v_id UUID)
    RETURNS SETOF gluster_volume_bricks_view STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM gluster_volume_bricks_view
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetBricksByGlusterVolumeGuid(v_volume_id UUID)
    RETURNS SETOF gluster_volume_bricks_view STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volume_bricks_view
    WHERE volume_id = v_volume_id
    ORDER BY brick_order;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterVolumeBricksByServerGuid(v_server_id UUID)
RETURNS SETOF gluster_volume_bricks_view STABLE
AS $procedure$
BEGIN
RETURN QUERY SELECT *
FROM  gluster_volume_bricks_view
WHERE server_id = v_server_id
ORDER BY brick_order;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetBrickByServerIdAndDirectory(v_server_id UUID, v_brick_dir VARCHAR(4096))
    RETURNS SETOF gluster_volume_bricks_view STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volume_bricks_view
    WHERE server_id = v_server_id
    AND brick_dir = v_brick_dir;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetBricksByTaskId(v_task_id UUID)
RETURNS SETOF gluster_volume_bricks_view STABLE
AS $procedure$
BEGIN
RETURN QUERY SELECT *
FROM  gluster_volume_bricks_view
WHERE task_id = v_task_id
ORDER BY brick_order;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetBrickDetailsById(v_brick_id UUID)
    RETURNS SETOF gluster_volume_brick_details STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volume_brick_details
    WHERE brick_id = v_brick_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterOptionById(v_id UUID)
    RETURNS SETOF gluster_volume_options STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM gluster_volume_options
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetOptionsByGlusterVolumeGuid(v_volume_id UUID)
    RETURNS SETOF gluster_volume_options STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM  gluster_volume_options
    WHERE volume_id = v_volume_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAccessProtocolsByGlusterVolumeGuid(v_volume_id UUID)
    RETURNS SETOF gluster_volume_access_protocols STABLE
       AS $procedure$
BEGIN
       RETURN QUERY SELECT *
       FROM  gluster_volume_access_protocols
       WHERE volume_id = v_volume_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetGlusterTaskByGlusterVolumeGuid(v_volume_id UUID)
    RETURNS SETOF gluster_volume_task_steps STABLE
       AS $procedure$
BEGIN
       RETURN QUERY SELECT gluster_volume_task_steps.*
       FROM  gluster_volume_task_steps, gluster_volumes vol
       WHERE volume_id = v_volume_id AND vol.id = volume_id
       AND (job_status = 'STARTED' OR (job_status != 'STARTED' AND external_id = vol.task_id))
       ORDER BY job_start_time desc LIMIT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTransportTypesByGlusterVolumeGuid(v_volume_id UUID)
    RETURNS SETOF gluster_volume_transport_types STABLE
       AS $procedure$
BEGIN
       RETURN QUERY SELECT *
       FROM  gluster_volume_transport_types
       WHERE volume_id = v_volume_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterVolumeByGuid(v_volume_id UUID)
    RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM gluster_volumes
    WHERE id = v_volume_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterVolumesByGuids(v_volume_ids VARCHAR(5000))
    RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM gluster_volumes
    WHERE id in (select * from fnSplitterUuid(v_volume_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterVolumeByName(v_cluster_id UUID,
                                                    v_vol_name VARCHAR(1000))
    RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM gluster_volumes
    WHERE cluster_id = v_cluster_id
    AND   vol_name = v_vol_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterVolumesByClusterId(v_cluster_id UUID)
    RETURNS VOID
    AS $procedure$
BEGIN
DELETE FROM gluster_volumes
WHERE cluster_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterVolumeBrick(v_id UUID)
    RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM gluster_volume_bricks
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterVolumeBricks(v_ids VARCHAR(5000))
    RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM gluster_volume_bricks
    WHERE id in (select * from fnSplitterUuid(v_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterVolumeOption(v_id UUID)
    RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM gluster_volume_options
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterVolumeOptions(v_ids VARCHAR(5000))
    RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM gluster_volume_options
    WHERE id in (select * from fnSplitterUuid(v_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterVolumeAccessProtocol(v_volume_id UUID,
                                                    v_access_protocol VARCHAR(32))
    RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM gluster_volume_access_protocols
    WHERE volume_id = v_volume_id
    AND   access_protocol = v_access_protocol;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteGlusterVolumeTransportType(v_volume_id UUID,
                                                    v_transport_type VARCHAR(32))
    RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM gluster_volume_transport_types
    WHERE volume_id = v_volume_id
    AND   transport_type = v_transport_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterVolume(v_id UUID,
                                                v_cluster_id UUID,
                                                v_vol_name VARCHAR(1000),
                                                v_vol_type VARCHAR(32),
                                                v_status VARCHAR(32),
                                                v_replica_count INTEGER,
                                                v_stripe_count INTEGER)
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE gluster_volumes
    SET cluster_id = v_cluster_id,
        vol_name = v_vol_name,
        vol_type = v_vol_type,
        status = v_status,
        replica_count = v_replica_count,
        stripe_count = v_stripe_count,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterVolumeDetails(v_volume_id UUID,
                                                v_total_space bigint,
                                                v_used_space bigint,
                                                v_free_space bigint)
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE gluster_volume_details
    SET
        total_space = v_total_space,
        used_space = v_used_space,
        free_space = v_free_space,
        _update_date = LOCALTIMESTAMP
    WHERE volume_id = v_volume_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterVolumeBrick(v_id UUID,
                                                    v_new_id UUID,
                                                    v_new_server_id UUID,
                                                    v_new_brick_dir VARCHAR(4096),
                                                    v_new_status VARCHAR(32))
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE gluster_volume_bricks
    SET    id = v_new_id,
           server_id = v_new_server_id,
           brick_dir = v_new_brick_dir,
           status = v_new_status,
           _update_date = LOCALTIMESTAMP
    WHERE  id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterVolumeBrickDetails(v_brick_id UUID,
                                                v_total_space bigint,
                                                v_used_space bigint,
                                                v_free_space bigint)
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE gluster_volume_brick_details
    SET
        total_space = v_total_space,
        used_space = v_used_space,
        free_space = v_free_space,
        _update_date = LOCALTIMESTAMP
    WHERE brick_id = v_brick_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterVolumeBrickStatus(v_id UUID,
                                                        v_status VARCHAR(32))
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE  gluster_volume_bricks
    SET     status = v_status,
            _update_date = LOCALTIMESTAMP
    WHERE   id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterVolumeBrickOrder(v_id UUID, v_brick_order INTEGER)
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE  gluster_volume_bricks
    SET     brick_order = v_brick_order,
            _update_date = LOCALTIMESTAMP
    WHERE   id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterVolumeStatus(v_volume_id UUID,
                                                    v_status VARCHAR(32))
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE gluster_volumes
    SET
        status = v_status,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_volume_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterVolumeAsyncTask(v_volume_id UUID,
                                                    v_task_id UUID)
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE gluster_volumes
    SET
        task_id = v_task_id,
        _update_date = LOCALTIMESTAMP
    WHERE id = v_volume_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterVolumeBrickAsyncTask(v_id UUID, v_task_id UUID)
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE  gluster_volume_bricks
    SET     task_id = v_task_id,
            _update_date = LOCALTIMESTAMP
    WHERE   id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterBrickTaskByServerIdBrickDir(v_server_id UUID,
                                                                    v_brick_dir VARCHAR(200),
                                                                    v_task_id UUID)
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE  gluster_volume_bricks
    SET     task_id = v_task_id,
            _update_date = LOCALTIMESTAMP
    WHERE   server_id = v_server_id
    AND brick_dir = v_brick_dir;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterVolumeStatusByName(v_cluster_id UUID,
                                                    v_vol_name VARCHAR(1000),
                                                    v_status VARCHAR(32))
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE gluster_volumes
    SET
        status = v_status,
        _update_date = LOCALTIMESTAMP
    WHERE cluster_id = v_cluster_id
    AND   vol_name = v_vol_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateGlusterVolumeOption(v_id UUID, v_option_val VARCHAR(8192))
    RETURNS VOID
    AS $procedure$
BEGIN
    UPDATE gluster_volume_options
    SET option_val = v_option_val
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateReplicaCount(v_volume_id UUID,
        v_replica_count INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
UPDATE gluster_volumes
SET
replica_count = v_replica_count,
_update_date = LOCALTIMESTAMP
WHERE id = v_volume_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertImage(
    v_creation_date TIMESTAMP WITH TIME ZONE,
    v_image_guid UUID,
    v_it_guid UUID,
    v_size BIGINT,
    v_ParentId UUID,
    v_imageStatus INTEGER ,
    v_lastModified TIMESTAMP WITH TIME ZONE,
    v_vm_snapshot_id UUID ,
    v_volume_type INTEGER,
    v_volume_format INTEGER,
    v_image_group_id UUID ,
    v_active BOOLEAN)
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO images(
        creation_date,
        image_guid,
        it_guid,
        size,
        ParentId,
        imageStatus,
        lastModified,
        vm_snapshot_id,
        volume_type,
        image_group_id,
        volume_format,
        active)
    VALUES(
        v_creation_date,
        v_image_guid,
        v_it_guid,
        v_size,
        v_ParentId,
        v_imageStatus,
        v_lastModified,
        v_vm_snapshot_id,
        v_volume_type,
        v_image_group_id,
        v_volume_format,
        v_active);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateImageStatus(
    v_image_id UUID,
    v_status INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE images
    SET    imageStatus = v_status
    WHERE  image_guid = v_image_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateStatusOfImagesByImageGroupId(
    v_image_group_id UUID,
    v_status INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE images
    SET    imageStatus = v_status
    WHERE  image_group_id = v_image_group_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateImageVmSnapshotId(
    v_image_id UUID,
    v_vm_snapshot_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE images
    SET    vm_snapshot_id = v_vm_snapshot_id
    WHERE  image_guid = v_image_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateImageSize(
    v_image_id UUID,
    v_size BIGINT,
    v_lastModified TIMESTAMP WITH TIME ZONE)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE images
    SET    size = v_size,
           lastModified = v_lastModified
    WHERE  image_guid = v_image_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateImage(
    v_creation_date TIMESTAMP WITH TIME ZONE,
    v_image_guid UUID,
    v_it_guid UUID,
    v_size BIGINT,
    v_ParentId UUID,
    v_imageStatus INTEGER ,
    v_lastModified TIMESTAMP WITH TIME ZONE,
    v_vm_snapshot_id UUID ,
    v_volume_type INTEGER,
    v_volume_format INTEGER,
    v_image_group_id UUID ,
    v_active BOOLEAN)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE images
    SET    creation_date = v_creation_date,
           it_guid = v_it_guid,
           size = v_size,
           ParentId = v_ParentId,
           imageStatus = v_imageStatus,
           lastModified = v_lastModified,
           vm_snapshot_id = v_vm_snapshot_id,
           volume_type = v_volume_type,
           image_group_id = v_image_group_id,
           volume_format = v_volume_format,
           active = v_active,
           _update_date = LOCALTIMESTAMP
    WHERE  image_guid = v_image_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteImage(v_image_guid UUID)
RETURNS VOID
AS $procedure$
DECLARE
    v_val  UUID;
BEGIN
    DELETE
    FROM   images
    WHERE  image_guid = v_image_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromImages() RETURNS SETOF images STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   images;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetImageByImageId(v_image_guid UUID)
RETURNS SETOF images STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   images
    WHERE  image_guid = v_image_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertimage_storage_domain_map(v_image_id UUID,
    v_storage_domain_id UUID,
    v_quota_id UUID,
    v_disk_profile_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO image_storage_domain_map(image_id, storage_domain_id, quota_id, disk_profile_id)
	VALUES(v_image_id, v_storage_domain_id, v_quota_id, v_disk_profile_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deleteimage_storage_domain_map(v_image_id UUID,
	v_storage_domain_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM image_storage_domain_map
   WHERE image_id = v_image_id AND storage_domain_id = v_storage_domain_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deleteimage_storage_domain_map_by_image_id(v_image_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM image_storage_domain_map
   WHERE image_id = v_image_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getimage_storage_domain_mapByimage_id(v_image_id UUID)
RETURNS SETOF image_storage_domain_map STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM image_storage_domain_map
   WHERE image_id = v_image_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getimage_storage_domain_mapBystorage_domain_id(v_storage_domain_id UUID) RETURNS SETOF image_storage_domain_map STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM image_storage_domain_map
   WHERE storage_domain_id = v_storage_domain_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateQuotaForImageAndSnapshots(v_disk_id UUID, v_storage_domain_id UUID, v_quota_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
UPDATE image_storage_domain_map as isdm
    SET quota_id = v_quota_id
    FROM images as i
    WHERE i.image_group_id = v_disk_id AND i.image_guid = isdm.image_id AND storage_domain_id = v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateDiskProfileByImageGroupId(v_image_group_id UUID, v_storage_domain_id UUID, v_disk_profile_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
UPDATE image_storage_domain_map as isdm
    SET disk_profile_id = v_disk_profile_id
    FROM images as i
    WHERE i.image_group_id = v_image_group_id AND i.image_guid = isdm.image_id AND storage_domain_id = v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION inst_update_default_storage_pool_type(v_is_local boolean)
RETURNS VOID
   AS $procedure$
BEGIN
         UPDATE storage_pool
         SET is_local = v_is_local, _update_date = LOCALTIMESTAMP
         WHERE storage_pool.name = 'Default' and not exists
         (select 1 from storage_domains where storage_domains.storage_pool_name = 'Default');
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION inst_add_iso_storage_domain(v_storage_domain_id UUID, v_name VARCHAR(250), v_connection_id uuid, v_connection VARCHAR(250),v_available int, v_used int)
RETURNS VOID
   AS $procedure$
   DECLARE
BEGIN
    if not exists (select 1 from storage_server_connections where connection = v_connection) then
        -- Insert storage server connection info
        perform Insertstorage_server_connections(v_connection,cast(v_connection_id as varchar(250)),NULL,NULL,NULL,NULL,1,NULL,NULL,NULL,NULL,NULL,NULL);
        -- Insert storage domain static info
        perform Insertstorage_domain_static(v_storage_domain_id,cast(v_connection_id as varchar(250)),v_name,v_name,'',1,2,'0',0);
        -- Insert storage domain dynamic  info
        perform Insertstorage_domain_dynamic(v_available,v_storage_domain_id,v_used);
    end if;
    exception
        when others then
	    RAISE EXCEPTION 'NUM:%, DETAILS:%', SQLSTATE, SQLERRM;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION inst_update_service_type(v_cluster_id uuid, v_virt_service boolean,
                                                     v_gluster_service boolean)
returns void
AS $procedure$
begin
    update  vds_groups set virt_service = v_virt_service, gluster_service = v_gluster_service
    where vds_group_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION inst_add_glance_provider(
    v_provider_id UUID,
    v_provider_name VARCHAR(128),
    v_provider_description VARCHAR(4000),
    v_provider_url VARCHAR(512),
    v_storage_domain_id UUID
)
RETURNS VOID
AS $procedure$
BEGIN
    -- Adding the Glance provider
    insert into providers(id, name, description, url, provider_type, auth_required)
    select v_provider_id, v_provider_name, v_provider_description, v_provider_url, 'OPENSTACK_IMAGE', false
    where not exists (select id from providers where id = v_provider_id);

    -- Adding a proper storage domain static entry
    insert into storage_domain_static(id, storage, storage_name, storage_domain_type, storage_type, storage_domain_format_type, recoverable)
    select v_storage_domain_id, v_provider_id, v_provider_name, 4, 8, 0, true
    where not exists (select id from storage_domain_static where id = v_storage_domain_id);

    -- Adding a proper storage domain dynamic entry
    insert into storage_domain_dynamic(id, available_disk_size, used_disk_size)
    select v_storage_domain_id, 0, 0
    where not exists (select id from storage_domain_dynamic where id = v_storage_domain_id);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetIscsiBondByIscsiBondId(v_id UUID) RETURNS SETOF iscsi_bonds STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT iscsi_bonds.*
      FROM iscsi_bonds
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromIscsiBonds() RETURNS SETOF iscsi_bonds STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT iscsi_bonds.*
      FROM iscsi_bonds;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetIscsiBondsByStoragePoolId(v_storage_pool_id UUID) RETURNS SETOF iscsi_bonds STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT iscsi_bonds.*
      FROM iscsi_bonds
      WHERE storage_pool_id = v_storage_pool_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNetworksByIscsiBondId(v_iscsi_bond_id UUID) RETURNS SETOF UUID STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT iscsi_bonds_networks_map.network_id
      FROM iscsi_bonds_networks_map
      WHERE iscsi_bond_id = v_iscsi_bond_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetIscsiBondsByNetworkId(v_network_id UUID) RETURNS SETOF iscsi_bonds  STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT iscsi_bonds.*
      FROM iscsi_bonds_networks_map, iscsi_bonds
      WHERE iscsi_bonds.id = iscsi_bonds_networks_map.iscsi_bond_id
      AND network_id = v_network_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertIscsiBond(v_id UUID,
  v_name VARCHAR(50),
  v_description VARCHAR(4000),
  v_storage_pool_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      INSERT INTO iscsi_bonds(id, name, description, storage_pool_id)
      VALUES(v_id, v_name, v_description, v_storage_pool_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateIscsiBond(v_id UUID,
  v_name VARCHAR(50),
  v_description VARCHAR(4000))
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE iscsi_bonds
      SET name = v_name, description = v_description
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteIscsiBond(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val UUID;
BEGIN
      DELETE FROM iscsi_bonds WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION AddNetworkToIscsiBond(v_iscsi_bond_id UUID, v_network_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      INSERT INTO iscsi_bonds_networks_map(iscsi_bond_id, network_id)
      VALUES(v_iscsi_bond_id, v_network_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION RemoveNetworkFromIscsiBond(v_iscsi_bond_id UUID, v_network_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM iscsi_bonds_networks_map
      WHERE iscsi_bond_id = v_iscsi_bond_id and network_id = v_network_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION AddConnectionToIscsiBond(v_iscsi_bond_id UUID, v_connection_id VARCHAR(50))
RETURNS VOID
   AS $procedure$
BEGIN
      INSERT INTO iscsi_bonds_storage_connections_map(iscsi_bond_id, connection_id)
      VALUES(v_iscsi_bond_id, v_connection_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION RemoveConnectionFromIscsiBond(v_iscsi_bond_id UUID, v_connection_id VARCHAR(50))
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM iscsi_bonds_storage_connections_map
      WHERE iscsi_bond_id = v_iscsi_bond_id and connection_id = v_connection_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetConnectionsByIscsiBondId(v_iscsi_bond_id UUID) RETURNS SETOF VARCHAR(50) STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT iscsi_bonds_storage_connections_map.connection_id
      FROM iscsi_bonds_storage_connections_map
      WHERE iscsi_bond_id = v_iscsi_bond_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertJob(
    v_job_id UUID,
    v_action_type VARCHAR(50),
    v_description TEXT,
    v_status VARCHAR(32),
    v_owner_id UUID,
    v_visible BOOLEAN,
    v_start_time TIMESTAMP WITH TIME ZONE,
    v_end_time TIMESTAMP WITH TIME ZONE,
    v_last_update_time TIMESTAMP WITH TIME ZONE,
    v_correlation_id VARCHAR(50),
    v_is_external boolean,
    v_is_auto_cleared boolean)
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO job(
        job_id,
        action_type,
        description,
        status,
        owner_id,
        visible,
        start_time,
        end_time,
        last_update_time,
        correlation_id,
        is_external,
        is_auto_cleared)
    VALUES (
        v_job_id,
        v_action_type,
        v_description,
        v_status,
        v_owner_id,
        v_visible,
        v_start_time,
        v_end_time,
        v_last_update_time,
        v_correlation_id,
        v_is_external,
        v_is_auto_cleared);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetJobByJobId(v_job_id UUID)
RETURNS SETOF job STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB
    WHERE job_id = v_job_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllJobs()
RETURNS SETOF job STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB
    where status != 'UNKNOWN'
    order by start_time DESC;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetJobsByOffsetAndPageSize(v_position INTEGER, v_page_size INTEGER)
RETURNS SETOF job STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    (SELECT job.*
    FROM JOB
    WHERE status = 'STARTED'
    ORDER BY last_update_time desc)
    UNION ALL
    (SELECT job.*
    FROM JOB
    WHERE status not in ('STARTED','UNKNOWN')
    ORDER BY last_update_time desc)
    OFFSET v_position LIMIT v_page_size;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetJobsByCorrelationId(v_correlation_id VARCHAR(50))
RETURNS SETOF job STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT job.*
    FROM JOB
    WHERE correlation_id = v_correlation_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateJob(
    v_job_id UUID,
    v_action_type VARCHAR(50),
    v_description TEXT,
    v_status VARCHAR(32),
    v_owner_id UUID,
    v_visible BOOLEAN,
    v_start_time TIMESTAMP WITH TIME ZONE,
    v_end_time TIMESTAMP WITH TIME ZONE,
    v_last_update_time TIMESTAMP WITH TIME ZONE,
    v_correlation_id VARCHAR(50))
RETURNS VOID
AS $procedure$
BEGIN
    update job
    SET action_type = v_action_type,
        description = v_description,
        status = v_status,
        owner_id = v_owner_id,
        visible = v_visible,
        start_time = v_start_time,
        end_time = v_end_time,
        last_update_time = v_last_update_time,
        correlation_id = v_correlation_id
    WHERE job_id = v_job_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateJobLastUpdateTime(
    v_job_id UUID,
    v_last_update_time TIMESTAMP WITH TIME ZONE)
RETURNS VOID
AS $procedure$
BEGIN
    update job
    SET last_update_time = v_last_update_time
    WHERE job_id = v_job_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteJobOlderThanDateWithStatus(
    v_end_time TIMESTAMP WITH TIME ZONE,
    v_status TEXT)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM job
    WHERE is_auto_cleared
    AND end_time < v_end_time
    AND status = any (string_to_array(v_status,',')::VARCHAR[] );
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteJob(
    v_job_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM job
    WHERE job_id = v_job_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertJobSubjectEntity(
    v_job_id UUID,
    v_entity_id UUID,
    v_entity_type VARCHAR(32))
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO job_subject_entity(
        job_id,
        entity_id,
        entity_type)
    VALUES (
        v_job_id,
        v_entity_id,
        v_entity_type);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetJobSubjectEntityByJobId(v_job_id UUID)
RETURNS SETOF job_subject_entity STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT job_subject_entity.*
    FROM job_subject_entity
    WHERE job_id = v_job_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllJobIdsByEntityId(
    v_entity_id UUID)
RETURNS SETOF UUID STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT job_subject_entity.job_id
    FROM job_subject_entity
    WHERE entity_id = v_entity_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertStep(
    v_step_id UUID,
    v_parent_step_id UUID,
    v_job_id UUID,
    v_step_type VARCHAR(32),
    v_description TEXT,
    v_step_number INTEGER,
    v_status VARCHAR(32),
    v_start_time TIMESTAMP WITH TIME ZONE,
    v_end_time TIMESTAMP WITH TIME ZONE,
    v_correlation_id VARCHAR(50),
    v_external_id UUID,
    v_external_system_type VARCHAR(32),
    v_is_external boolean)
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO step(
        step_id,
        parent_step_id,
        job_id,
        step_type,
        description,
        step_number,
        status,
        start_time,
        end_time,
        correlation_id,
        external_id,
        external_system_type,
        is_external)
    VALUES (
        v_step_id,
        v_parent_step_id,
        v_job_id,
        v_step_type,
        v_description,
        v_step_number,
        v_status,
        v_start_time,
        v_end_time,
        v_correlation_id,
        v_external_id,
        v_external_system_type,
        v_is_external);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateStep(
    v_step_id UUID,
    v_parent_step_id UUID,
    v_job_id UUID,
    v_step_type VARCHAR(32),
    v_description TEXT,
    v_step_number INTEGER,
    v_status VARCHAR(32),
    v_start_time TIMESTAMP WITH TIME ZONE,
    v_end_time TIMESTAMP WITH TIME ZONE,
    v_correlation_id VARCHAR(50),
    v_external_id UUID,
    v_external_system_type VARCHAR(32))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE step
    SET parent_step_id = v_parent_step_id,
        job_id = v_job_id,
        step_type = v_step_type,
        description = v_description,
        step_number = v_step_number,
        status = v_status,
        start_time = v_start_time,
        end_time = v_end_time,
        correlation_id = v_correlation_id,
        external_id = v_external_id,
        external_system_type = v_external_system_type
    WHERE step_id = v_step_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateStepStatusAndEndTime(
    v_step_id UUID,
    v_status VARCHAR(32),
    v_end_time TIMESTAMP WITH TIME ZONE)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE step
    SET status = v_status,
        end_time = v_end_time
    WHERE step_id = v_step_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateStepExternalIdAndType(
    v_step_id UUID,
    v_external_id UUID,
    v_external_system_type VARCHAR(32))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE step
    SET external_id = v_external_id,
        external_system_type = v_external_system_type
    WHERE step_id = v_step_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetStepByStepId(v_step_id UUID)
RETURNS SETOF step STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT step.*
    FROM step
    WHERE step_id = v_step_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetStepsByJobId(v_job_id UUID)
RETURNS SETOF step STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT step.*
    FROM step
    WHERE job_id = v_job_id
    ORDER BY parent_step_id nulls first, step_number;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetStepsByParentStepId(v_parent_step_id UUID)
RETURNS SETOF step STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT step.*
    FROM step
    WHERE parent_step_id = v_parent_step_id
    ORDER BY step_number;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllSteps()
RETURNS SETOF step STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT step.*
    FROM step;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteStep(
    v_step_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM step
    WHERE step_id = v_step_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION updateJobStepsCompleted(
    v_job_id UUID,
    v_status VARCHAR(32),
    v_end_time TIMESTAMP WITH TIME ZONE
    )
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE step
    SET status = v_status,
        end_time = v_end_time
    WHERE job_id = v_job_id
    AND   status = 'STARTED'
    AND   STATUS != v_status;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateStartedExecutionEntitiesToUnknown(
    v_end_time TIMESTAMP WITH TIME ZONE
    )
RETURNS VOID
AS $procedure$
BEGIN

update job
set status = 'UNKNOWN',
    end_time = v_end_time,
    last_update_time = v_end_time
where job.status = 'STARTED'
and job_id not in (select job_id
                   from step
                   where external_id is not null);

update step
set status = 'UNKNOWN',
    end_time = v_end_time
where status = 'STARTED'
and job_id not in (select step.job_id
                   from step step
                   where step.external_id is not null);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteRunningJobsOfTasklessCommands()
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM job
    WHERE (status = 'STARTED'
    AND    action_type IN ('MigrateVm', 'MigrateVmToServer', 'RunVm', 'RunVmOnce'))
    AND    job_id not in (select job_id from step where step_id in (select step_id from async_tasks));

    DELETE FROM job
    WHERE job_id IN
          (SELECT job_id from step WHERE (status = 'STARTED' AND step_type='MIGRATE_VM'));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteCompletedJobsOlderThanDate(
    v_succeeded_end_time TIMESTAMP WITH TIME ZONE,
    v_failed_end_time TIMESTAMP WITH TIME ZONE
    )
RETURNS VOID
AS $procedure$
BEGIN
    DELETE FROM job
    WHERE (is_auto_cleared
    AND ((end_time < v_succeeded_end_time
    AND    status = 'FINISHED')
    OR    (end_time < v_failed_end_time
    AND    status IN ('FAILED', 'ABORTED', 'UNKNOWN'))));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION CheckIfJobHasTasks(
    v_job_id UUID)
RETURNS SETOF booleanResultType STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT EXISTS(
        SELECT *
        FROM   step
        WHERE  job_id = v_job_id
        AND    external_id is not null
        AND    external_system_type in ('VDSM','GLUSTER'));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetStepsByExternalTaskId(v_external_id UUID)
RETURNS SETOF step STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT step.*
    FROM step
    WHERE external_id = v_external_id
    ORDER BY parent_step_id nulls first, step_number;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetExternalIdsFromSteps(v_status VARCHAR(32),
                                                   v_external_system_type VARCHAR(32))
RETURNS SETOF UUID STABLE
AS $procedure$
BEGIN
    RETURN QUERY SELECT step.external_id
    FROM step
    INNER JOIN job ON step.job_id = job.job_id
    WHERE job.status = v_status
    AND step.external_system_type = v_external_system_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/*
This file adds Snapshot Materialized Views support to Postgres.
A Snapshot Materialized View is actually a table built on top of
a real view that enables to select data from the Snapshot Materialized View
easily and efficiently.
Candidates for Snapshot Materialized Views are views that are based on
slowly-changing data. The Snapshot Materialized Views is actually
functioning as a cache.
The Snapshot Materialized View is refreshed per request.
The Snapshot Materialized View definitions are stored in the materialized_views table.

Flow:
1) Create the Materialized View by calling:
   CreateMaterializedView - if you are creating a new view
   CreateMaterializedViewAs - If you want to preserve the original view name
                              in this case the original view will be renamed
                              and the new Materialized View will have the original
                              view name.
   The following should be called for Custom Materialized Views
   CreateCustomMaterializedView
   CreateCustomMaterializedViewAs
2) If your Snapshot Materialized View is my_mt you should create Stored Procedures:
    MtDropmy_mtIndexes - Drops indexes on my_mt
    MtCreatemy_mtIndexes - Creates needed indexes on my_mt
    Those indexes should be defined in the "Snapshot Materialized Views Index Definitions Section"
    in post_upgrade/0020_create_materialized_views.sql file.

   Those SP are called automatically when a Snapshot Materialized View is refreshed
   to boost refresh performance.

3) You can call IsMaterializedViewRefreshed to check if it is time to refresh the view
   and if yes call RefreshMaterializedView manually.
   or
   You can define a cron job that calls RefreshAllMaterializedViews that loops over
   all  Snapshot Materialized Views and refreshes it automatically
   RefreshAllMaterializedViews recieves a boolean v_force flag, please set this flag to false
   when calling it from a cron job in order to update the materialized views only when needed.
   (This SP is called with v_force = true after create/upgrade DB)

There are also additional functions :
   CreateAllMaterializedViewsiIndexes - Creates indexes for all Snapshot Materialized views
   DropMaterializedView - Drops the Materialized View
   DropAllMaterializedViews - Drop all Materialized Views
   DropAllCustomMaterializedViews - Drop all custom Materialized Views
   UpdateMaterializedViewRefreshRate - Updates the Materialized View refresh rate
   UpdateMaterializedViewMinRefreshRate - Updates the Materialized View minimal refresh rate
   ActivateMaterializedView - activates/decativates a  Materialized View
   ActivateAllMaterializedViews - activates/decativates all Materialized Views

In addition, you can create a file named create_materialized_views.sql under dbscripts/upgrade/post_upgrade/custom/
This file may include other custom materialized views settings and is executed by the create/upgrade database scripts.

NOTE : Materialized Views are automatically refreshed upon create/upgrade
*/




CREATE OR REPLACE FUNCTION to_interval (sec INTEGER) RETURNS INTERVAL AS $$
BEGIN
  RETURN (sec || ' seconds')::INTERVAL;
END;
$$ LANGUAGE 'plpgsql' IMMUTABLE STRICT;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedView(v_matview NAME, v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                  v_custom BOOLEAN, v_min_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;

     IF FOUND THEN
         RAISE EXCEPTION 'Materialized view % already exists.',
           v_matview;
     END IF;
     IF current_user != usename from pg_database , pg_user where datdba=usesysid and datname=current_database THEN
         RAISE EXCEPTION 'Materialized view % should be created with user ''engine''.',
           v_matview;
     END IF;

     EXECUTE 'REVOKE ALL ON ' || v_view_name || ' FROM PUBLIC';

     EXECUTE 'GRANT SELECT ON ' || v_view_name || ' TO PUBLIC';

     EXECUTE 'CREATE TABLE ' || v_matview || ' AS SELECT * FROM ' || v_view_name;

     EXECUTE 'REVOKE ALL ON ' || v_matview || ' FROM PUBLIC';

     EXECUTE 'GRANT SELECT ON ' || v_matview || ' TO PUBLIC';

     INSERT INTO materialized_views (mv_name, v_name, refresh_rate_in_sec, last_refresh, custom, min_refresh_rate_in_sec)
       VALUES (v_matview, v_view_name, v_refresh_rate_in_sec, CURRENT_TIMESTAMP, v_custom, v_min_refresh_rate_in_sec);

     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedView(v_matview NAME, v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                  v_min_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
 BEGIN
     PERFORM CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, false,  v_min_refresh_rate_in_sec);
     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateCustomMaterializedView(v_matview NAME, v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                        v_min_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
 BEGIN
     PERFORM CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, true,  v_min_refresh_rate_in_sec);
     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedView(v_matview NAME, v_view_name NAME, v_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
BEGIN
     PERFORM  CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, false, 0);
END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateCustomMaterializedView(v_matview NAME, v_view_name NAME, v_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
BEGIN
     PERFORM  CreateMaterializedView(v_matview, v_view_name, v_refresh_rate_in_sec, true, 0);
END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedViewAs(v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                    v_custom BOOLEAN, v_min_refesh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
     v_renamed_view NAME;
 BEGIN
     IF FOUND THEN
         RAISE EXCEPTION 'Materialized view % already exists.',
           v_view_name;
     END IF;

     v_renamed_view := v_view_name || '_mt_base';
     EXECUTE  'ALTER VIEW ' ||  v_view_name || ' RENAME TO ' || v_renamed_view;
     perform CreateMaterializedView(v_view_name, v_renamed_view, v_refresh_rate_in_sec, v_custom, v_min_refesh_rate_in_sec);

     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedViewAs(v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                    v_min_refesh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
 BEGIN
     PERFORM CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, false, v_min_refesh_rate_in_sec);
     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateCustomMaterializedViewAs(v_view_name NAME, v_refresh_rate_in_sec INTEGER,
                                                          v_min_refesh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
 BEGIN
     PERFORM CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, true, v_min_refesh_rate_in_sec);
     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateMaterializedViewAs(v_view_name NAME, v_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
BEGIN
    PERFORM  CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, false, 0);
END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateCustomMaterializedViewAs(v_view_name NAME, v_refresh_rate_in_sec INTEGER)
 RETURNS VOID
AS $procedure$
BEGIN
    PERFORM  CreateMaterializedViewAs(v_view_name, v_refresh_rate_in_sec, true, 0);
END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION DropMaterializedView(v_matview NAME)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN

     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;

     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
     END IF;

     EXECUTE 'DROP TABLE ' || v_matview || ' CASCADE';
     DELETE FROM materialized_views WHERE mv_name=v_matview;

     RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION DropAllMaterializedViews()
RETURNS void
AS $procedure$
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views;
    v_record materialized_views%ROWTYPE;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           perform DropMaterializedView(v_record.mv_name);
       END LOOP;
       CLOSE v_cur;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION DropAllCustomMaterializedViews()
RETURNS void
AS $procedure$
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views where custom;
    v_record materialized_views%ROWTYPE;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           perform DropMaterializedView(v_record.mv_name);
       END LOOP;
       CLOSE v_cur;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION IsMaterializedViewRefreshed(v_matview NAME)
 RETURNS boolean STABLE
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
     v_is_refreshed boolean;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
    END IF;

    -- check if materialized View should refresh
    v_is_refreshed := (((CURRENT_TIMESTAMP - to_interval(refresh_rate_in_sec)) <= last_refresh) and
                      ((CURRENT_TIMESTAMP - to_interval(min_refresh_rate_in_sec)) <= last_refresh)) or
                      not active from materialized_views
                       where mv_name = v_matview;
    RETURN v_is_refreshed;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION RefreshMaterializedView(v_matview NAME)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
     v_drop_index_sp NAME;
     v_create_index_sp NAME;
     v_start_time TIMESTAMP WITH TIME ZONE;
     v_avg_cost_ms int;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
    END IF;

    -- get start time
    v_start_time:=CURRENT_TIMESTAMP;
    -- SP for Drop / create Index should follow naming convention Mt[Drop|Create]<v_matview>Indexes
    v_drop_index_sp := 'MtDrop' || v_matview || 'Indexes';
    v_create_index_sp := 'MtCreate' || v_matview || 'Indexes';

    IF NOT EXISTS (select 1 from information_schema.routines where routine_name ilike v_drop_index_sp) THEN
        v_drop_index_sp := NULL;
    END IF;

    IF NOT EXISTS (select 1 from information_schema.routines where routine_name ilike v_create_index_sp) THEN
        v_create_index_sp := NULL;
    END IF;

    -- Lock materialized_views table until refresh completes to prevent duplicate refreshes by other threads
    LOCK TABLE materialized_views;
    -- taking a lock on the snapshot materialized view until it refreshed
    EXECUTE 'LOCK TABLE ' || v_matview;
    -- drop indexes on the snapshot materialized view if exists
    IF (v_drop_index_sp IS NOT NULL) THEN
        EXECUTE 'select ' || v_drop_index_sp || '()';
    END IF;
    -- refresh the view
    EXECUTE 'TRUNCATE TABLE ' || v_matview;
    EXECUTE 'INSERT INTO ' || v_matview
        || ' SELECT * FROM ' || v_entry.v_name;
    -- restore  indexes on the snapshot materialized view if exists
    IF (v_create_index_sp IS NOT NULL) THEN
        EXECUTE 'select ' || v_create_index_sp || '()';
    END IF;
    -- update last refresh time and average cost in [ms]
    IF (v_entry.avg_cost_ms = 0) THEN
        v_avg_cost_ms:=EXTRACT(EPOCH FROM current_timestamp - v_start_time) * 1000;
    ELSE
        v_avg_cost_ms:=((EXTRACT(EPOCH FROM current_timestamp - v_start_time) * 1000) + v_entry.avg_cost_ms)/2;
    END IF;
    update materialized_views set last_refresh = CURRENT_TIMESTAMP,
                                  avg_cost_ms = v_avg_cost_ms
                              where  mv_name = v_matview;
    RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION RefreshAllMaterializedViews(v_force boolean)
RETURNS void
AS $procedure$
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views;
    v_record materialized_views%ROWTYPE;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views and refresh only needed snapshots
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           IF ((v_force and v_record.min_refresh_rate_in_sec = 0) or not IsMaterializedViewRefreshed(v_record.mv_name)) THEN
              perform RefreshMaterializedView(v_record.mv_name);
           END IF;
       END LOOP;
       CLOSE v_cur;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION CreateAllMaterializedViewsiIndexes()
RETURNS void
AS $procedure$
DECLARE
    v_cur CURSOR FOR SELECT * FROM materialized_views;
    v_record materialized_views%ROWTYPE;
    v_create_index_sp NAME;
BEGIN
       OPEN v_cur;
       -- loop on all entries in materialized_views and create indexes(if defined)
       LOOP
           FETCH v_cur INTO v_record;
           EXIT WHEN NOT FOUND;
           v_create_index_sp := 'MtCreate' || v_record.mv_name || 'Indexes';
           -- Check if SP that creates the indexes exists
           IF NOT EXISTS (select 1 from information_schema.routines where routine_name ilike v_create_index_sp) THEN
               v_create_index_sp := NULL;
           END IF;
           IF (v_create_index_sp IS NOT NULL) THEN
               EXECUTE 'select ' || v_create_index_sp || '()';
           END IF;
       END LOOP;
       CLOSE v_cur;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpdateMaterializedViewRefreshRate(v_matview NAME, v_refresh_rate INTEGER)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
    END IF;

    update materialized_views set refresh_rate_in_sec = v_refresh_rate
    where  mv_name = v_matview;
    RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpdateMaterializedViewMinRefreshRate(v_matview NAME, v_min_refresh_rate INTEGER)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
    END IF;

    update materialized_views set min_refresh_rate_in_sec = v_min_refresh_rate
    where  mv_name = v_matview;
    RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION ActivateMaterializedView(v_matview NAME, v_active BOOLEAN)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
     SELECT * INTO v_entry FROM materialized_views WHERE mv_name = v_matview;
     IF NOT FOUND THEN
         RAISE EXCEPTION 'Materialized view % does not exist.', v_matview;
    END IF;

    update materialized_views set active = v_active
    where  mv_name = v_matview;
    RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION ActivateAllMaterializedViews(v_active BOOLEAN)
 RETURNS VOID
AS $procedure$
DECLARE
     v_entry materialized_views%ROWTYPE;
 BEGIN
    update materialized_views set active = v_active;
    RETURN;
 END; $procedure$
 LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertPermission(v_ad_element_id UUID,
	v_id UUID,
	v_role_id UUID,
	v_object_id UUID,
	v_object_type_id INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO permissions(ad_element_id, id, role_id, object_id, object_type_id)
	VALUES(v_ad_element_id, v_id, v_role_id, v_object_id, v_object_type_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeletePermission(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM permissions  WHERE id = v_id     FOR UPDATE;

   DELETE FROM permissions
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetPermissionsByid(v_id UUID)
RETURNS SETOF permissions_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION get_user_permissions_for_domain(v_name VARCHAR(255), v_domain VARCHAR(255))
RETURNS SETOF permissions_view STABLE
   AS $procedure$
   DECLARE
   v_user_name VARCHAR(255);
   v_index  INTEGER;
BEGIN
-- find if name already includes domain (@)
   v_index := POSITION('@' IN v_name);

   if (v_index > 0) then
      v_user_name := substr(v_name, 0, v_index);
   else
      v_user_name := v_name;
   end if;
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE permissions_view.ad_element_id in (
                SELECT users.user_id
                FROM users
                WHERE users.domain = v_domain
                AND (users.name = v_user_name OR
                     users.name = v_user_name || '@' || upper(v_domain)
                    ));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetConsumedPermissionsForQuotaId(v_quota_id UUID)
RETURNS SETOF permissions_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY    SELECT *
   FROM permissions_view
   WHERE role_id in (SELECT role_id FROM ROLES_groups where action_group_id = 901)
     AND object_id in(select id from  fn_get_entity_parents(v_quota_id,17));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetPermissionsByAdElementId(v_ad_element_id UUID, v_user_id UUID, v_is_filtered BOOLEAN, v_app_mode INTEGER)
RETURNS SETOF permissions_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE (permissions_view.app_mode & v_app_mode) > 0
   AND (permissions_view.ad_element_id = v_ad_element_id
    OR    ad_element_id IN (SELECT * FROM getUserAndGroupsById(v_ad_element_id)))
   AND (NOT v_is_filtered OR EXISTS (SELECT 1 FROM user_permissions_permissions_view WHERE user_id = v_user_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetPermissionsByRoleId(v_role_id UUID)
RETURNS SETOF permissions_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE role_id = v_role_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetPermissionsByRoleIdAndAdElementId(v_role_id UUID,
	v_ad_element_id UUID) RETURNS SETOF permissions_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE role_id = v_role_id and ad_element_id = v_ad_element_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetPermissionsByRoleIdAndAdElementIdAndObjectId(v_role_id UUID,
	v_ad_element_id UUID,v_object_id UUID)
RETURNS SETOF permissions_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE role_id = v_role_id and ad_element_id = v_ad_element_id and object_id = v_object_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetDirectPermissionsByAdElementId(v_ad_element_id UUID)
RETURNS SETOF permissions_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE permissions_view.ad_element_id = v_ad_element_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertRole(v_description VARCHAR(4000) ,
	v_id UUID,
	v_name VARCHAR(126),
	v_is_readonly BOOLEAN,
	v_role_type INTEGER,
        v_allows_viewing_children BOOLEAN,
    v_app_mode INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO roles(description, id, name, is_readonly, role_type, allows_viewing_children, app_mode)
	VALUES(v_description, v_id, v_name, v_is_readonly, v_role_type, v_allows_viewing_children, v_app_mode);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateRole(v_description VARCHAR(4000) ,
	v_id UUID,
	v_name VARCHAR(126),
	v_is_readonly BOOLEAN,
	v_role_type INTEGER,
        v_allows_viewing_children BOOLEAN)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE roles
      SET description    = v_description,
          name           = v_name,
          is_readonly    = v_is_readonly,
          role_type      = v_role_type,
          allows_viewing_children = v_allows_viewing_children
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteRole(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
    -- in order to force locking parent before children
   select   id INTO v_val FROM roles  WHERE id = v_id     FOR UPDATE;

   DELETE FROM roles
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromRole(v_app_mode INTEGER) RETURNS SETOF roles STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM roles
   WHERE (roles.app_mode & v_app_mode) > 0;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetRolsByid(v_id UUID) RETURNS SETOF roles STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM roles
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetRoleByName(v_name VARCHAR(126))
RETURNS SETOF roles STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM roles
   WHERE name = v_name;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllRolesByUserIdAndGroupIds(v_user_id UUID, v_group_ids text, v_app_mode INTEGER)
RETURNS SETOF roles STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT roles.*
   FROM roles INNER JOIN
   permissions ON permissions.role_id = roles.id
   WHERE (roles.app_mode & v_app_mode) > 0
   AND (permissions.ad_element_id = v_user_id
   or permissions.ad_element_id in(select id from getElementIdsByIdAndGroups(v_user_id, v_group_ids)));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetPermissionByRoleId(v_role_id UUID)
RETURNS SETOF permissions STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   from permissions
   where role_id = v_role_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION get_entity_permissions(v_user_id UUID,v_action_group_id INTEGER,v_object_id UUID,v_object_type_id INTEGER)
RETURNS SETOF UUID STABLE
	
   AS $procedure$
   DECLARE
   v_everyone_object_id  UUID;
BEGIN
   v_everyone_object_id := getGlobalIds('everyone'); -- hardcoded also in MLA Handler
   RETURN QUERY
   select   id from permissions where
		-- get all roles of action
   role_id in(select role_id from roles_groups where action_group_id = v_action_group_id)
		-- get allparents of object
   and (object_id in(select id from  fn_get_entity_parents(v_object_id,v_object_type_id)))
		-- get user and his groups
   and (ad_element_id = v_everyone_object_id or
   ad_element_id = v_user_id or ad_element_id in(select * from getUserAndGroupsById(v_user_id)))   LIMIT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION get_entity_permissions_for_user_and_groups(v_user_id UUID,v_group_ids text,v_action_group_id INTEGER,v_object_id UUID,v_object_type_id INTEGER,
v_ignore_everyone BOOLEAN)
RETURNS SETOF UUID STABLE
	
   AS $procedure$
   DECLARE
   v_everyone_object_id  UUID;
BEGIN
   v_everyone_object_id := getGlobalIds('everyone'); -- hardcoded also in MLA Handler
   RETURN QUERY
   select   id from permissions where
		-- get all roles of action
   role_id in(select role_id from roles_groups where action_group_id = v_action_group_id)
		-- get allparents of object
   and (object_id in(select id from  fn_get_entity_parents(v_object_id,v_object_type_id)))
		-- get user and his groups
   and ((NOT v_ignore_everyone and ad_element_id = v_everyone_object_id) or
   ad_element_id = v_user_id or ad_element_id in(select * from fnsplitteruuid(v_group_ids)))   LIMIT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insert_roles_groups(v_action_group_id INTEGER,
	v_role_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO roles_groups(action_group_id, role_id)
	VALUES(v_action_group_id, v_role_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Delete_roles_groups(v_action_group_id INTEGER,
	v_role_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM roles_groups
   WHERE action_group_id = v_action_group_id AND role_id = v_role_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Get_roles_groups_By_action_group_id_And_By_role_id(v_action_group_id INTEGER,v_role_id UUID) RETURNS SETOF roles_groups STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM roles_groups
   where
   action_group_id = v_action_group_id AND
   role_id = v_role_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Get_role_groups_By_role_id(v_role_id UUID)
RETURNS SETOF roles_groups STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM roles_groups
   where
   role_id = v_role_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetPermissionsByEntityId(v_id UUID, v_user_id UUID, v_is_filtered BOOLEAN, v_app_mode INTEGER)
RETURNS SETOF permissions_view STABLE
	
	
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE  (permissions_view.app_mode & v_app_mode) > 0
   AND object_id = v_id
   AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   GetUserPermissionsByEntityId(v_id, v_user_id, v_is_filtered)));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllUsersWithPermissionsOnEntityByEntityId(v_id UUID, v_user_id UUID, v_is_filtered BOOLEAN,  v_app_mode INTEGER)
RETURNS SETOF permissions_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE (permissions_view.app_mode & v_app_mode) > 0
   AND object_id = v_id
   AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   GetAllUsersWithPermissionsByEntityId(v_id, v_user_id, v_is_filtered)));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetUserPermissionsByEntityId(v_id UUID, v_user_id UUID, v_is_filtered BOOLEAN)
RETURNS SETOF permissions_view STABLE
    
    
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view p
   WHERE object_id = v_id
   AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_flat_groups u
                                       WHERE  p.ad_element_id = u.granted_id
                                       AND    u.user_id       = v_user_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllUsersWithPermissionsByEntityId(v_id UUID, v_user_id UUID, v_is_filtered BOOLEAN)
RETURNS SETOF permissions_view STABLE
   AS $procedure$
   declare r_type int4;
BEGIN
   for r_type in (SELECT DISTINCT role_type FROM permissions_view p WHERE object_id = v_id)
   LOOP
     RETURN QUERY SELECT *
     FROM permissions_view p
     WHERE object_id in (select id from fn_get_entity_parents(v_id, r_type))
     AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_flat_groups u
                                       WHERE  p.ad_element_id = u.granted_id
                                       AND    u.user_id       = v_user_id));
    END LOOP;
    return;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeletePermissionsByEntityId(v_id UUID)
RETURNS VOID
	
	
   AS $procedure$
BEGIN
   DELETE FROM permissions
   WHERE object_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetRoleActionGroupsByRoleId(v_id UUID)
RETURNS SETOF roles_groups STABLE
	
	
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM roles_groups
   WHERE role_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetPermissionsTreeByEntityId
(v_id UUID, v_object_type_id INTEGER, v_user_id UUID, v_is_filtered BOOLEAN, v_app_mode INTEGER)
RETURNS SETOF permissions_view STABLE
	
	
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM   permissions_view p
   WHERE  (p.app_mode & v_app_mode) > 0
   AND  object_id in(select id from  fn_get_entity_parents(v_id,v_object_type_id))
   AND    (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_flat_groups u
                                        WHERE  p.ad_element_id = u.granted_id
                                        AND    u.user_id       = v_user_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetPermissionsByRoleIdAndObjectId(v_role_id UUID,
	v_object_id UUID) RETURNS SETOF permissions_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE role_id = v_role_id and object_id = v_object_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetForRoleAndAdElementAndObject_wGroupCheck(v_role_id UUID,
	v_ad_element_id UUID, v_object_id UUID) RETURNS SETOF permissions_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM permissions_view
   WHERE role_id = v_role_id and object_id = v_object_id and ad_element_id in (
         select * from getUserAndGroupsById(v_ad_element_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertnetwork(v_addr VARCHAR(50) ,
	v_description VARCHAR(4000) ,
	v_free_text_comment text,
	v_id UUID,
	v_name VARCHAR(50),
	v_subnet VARCHAR(20) ,
	v_gateway VARCHAR(20) ,
	v_type INTEGER ,
	v_vlan_id INTEGER ,
	v_stp BOOLEAN ,
    	v_storage_pool_id UUID,
	v_mtu INTEGER,
	v_vm_network BOOLEAN,
	v_provider_network_provider_id UUID,
	v_provider_network_external_id TEXT,
	v_qos_id UUID,
	v_label TEXT)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO network(addr, description, free_text_comment, id, name, subnet, gateway, type, vlan_id, stp, storage_pool_id, mtu, vm_network, provider_network_provider_id, provider_network_external_id, qos_id, label)
	VALUES(v_addr, v_description, v_free_text_comment, v_id, v_name, v_subnet, v_gateway, v_type, v_vlan_id, v_stp, v_storage_pool_id, v_mtu, v_vm_network, v_provider_network_provider_id, v_provider_network_external_id, v_qos_id, v_label);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatenetwork(v_addr VARCHAR(50) ,
	v_description VARCHAR(4000) ,
	v_free_text_comment text,
	v_id UUID,
	v_name VARCHAR(50),
	v_subnet VARCHAR(20) ,
	v_gateway VARCHAR(20) ,
	v_type INTEGER ,
	v_vlan_id INTEGER ,
	v_stp BOOLEAN ,
	v_storage_pool_id UUID,
	v_mtu INTEGER,
	v_vm_network BOOLEAN,
	v_provider_network_provider_id UUID,
	v_provider_network_external_id TEXT,
	v_qos_id UUID,
	v_label TEXT)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE network
      SET addr = v_addr,description = v_description, free_text_comment = v_free_text_comment, name = v_name,subnet = v_subnet,
      gateway = v_gateway,type = v_type,vlan_id = v_vlan_id,
      stp = v_stp,storage_pool_id = v_storage_pool_id, mtu = v_mtu,
      vm_network = v_vm_network,
      provider_network_provider_id = v_provider_network_provider_id,
      provider_network_external_id = v_provider_network_external_id,
      qos_id = v_qos_id,
      label = v_label
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletenetwork(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM network  WHERE id = v_id     FOR UPDATE;

   DELETE FROM network
   WHERE id = v_id;

   -- Delete the network's permissions
   DELETE FROM permissions WHERE object_id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromnetwork(v_user_id uuid, v_is_filtered boolean) RETURNS SETOF network STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM network
   WHERE NOT v_is_filtered OR EXISTS (SELECT 1
                                      FROM   user_network_permissions_view
                                      WHERE  user_id = v_user_id AND entity_id = network.id);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetnetworkByid(v_id UUID, v_user_id uuid, v_is_filtered boolean) RETURNS SETOF network STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM network
   WHERE id = v_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                    FROM   user_network_permissions_view
                                    WHERE  user_id = v_user_id AND entity_id = v_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetnetworkByName(v_networkName VARCHAR(50))
RETURNS SETOF network STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM network
   WHERE name = v_networkName;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNetworkByNameAndDataCenter(v_name VARCHAR(50), v_storage_pool_id UUID)
RETURNS SETOF network STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT network.*
   FROM network
   WHERE network.name = v_name
   AND   network.storage_pool_id = v_storage_pool_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNetworkByNameAndCluster(v_name VARCHAR(50), v_cluster_id UUID)
RETURNS SETOF network STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT network.*
   FROM network
   WHERE network.name = v_name
   AND EXISTS (SELECT 1
               FROM network_cluster
               WHERE network.id = network_cluster.network_id
               AND   network_cluster.cluster_id = v_cluster_id);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllNetworkByStoragePoolId(v_id UUID, v_user_id uuid, v_is_filtered boolean)
RETURNS SETOF network STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM network
   WHERE storage_pool_id = v_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_network_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = network.id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS networkViewClusterType CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE networkViewClusterType AS(id uuid,name VARCHAR(50),description VARCHAR(4000), free_text_comment text, type INTEGER,
            addr VARCHAR(50),subnet VARCHAR(20),gateway VARCHAR(20),vlan_id INTEGER,stp BOOLEAN,storage_pool_id UUID,
	    mtu INTEGER, vm_network BOOLEAN, label TEXT,
	    provider_network_provider_id UUID, provider_network_external_id TEXT, qos_id UUID,
	    network_id UUID,cluster_id UUID, status INTEGER, is_display BOOLEAN,
	    required BOOLEAN, migration BOOLEAN);
**************************

CREATE TYPE
********* QUERY **********
Create or replace FUNCTION GetAllNetworkByClusterId(v_id UUID, v_user_id uuid, v_is_filtered boolean)
RETURNS SETOF networkViewClusterType STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT
    DISTINCT
    network.id,
    network.name,
    network.description,
    network.free_text_comment,
    network.type,
    network.addr,
    network.subnet,
    network.gateway,
    network.vlan_id,
    network.stp,
    network.storage_pool_id,
    network.mtu,
    network.vm_network,
    network.label,
    network.provider_network_provider_id,
    network.provider_network_external_id,
    network.qos_id,
    network_cluster.network_id,
    network_cluster.cluster_id,
    network_cluster.status,
    network_cluster.is_display,
    network_cluster.required,
    network_cluster.migration
   FROM network
   INNER JOIN network_cluster
   ON network.id = network_cluster.network_id
   WHERE network_cluster.cluster_id = v_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_network_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = network.id))
   ORDER BY network.name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllNetworksByNetworkProviderId(v_id UUID)
RETURNS SETOF network STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   network
    WHERE  provider_network_provider_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllNetworkViewsByNetworkProviderId(v_id UUID)
RETURNS SETOF network_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   network_view
    WHERE  provider_network_provider_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllNetworkLabelsByDataCenterId(v_id UUID)
RETURNS SETOF TEXT STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT DISTINCT label
    FROM network
    WHERE network.storage_pool_id = v_id
    AND label IS NOT NULL;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertvds_interface(v_addr VARCHAR(20) ,
 v_bond_name VARCHAR(50) ,
 v_bond_type INTEGER ,
 v_gateway VARCHAR(20) ,
 v_id UUID,
 v_is_bond BOOLEAN ,
 v_bond_opts VARCHAR(4000) ,
 v_mac_addr VARCHAR(20) ,
 v_name VARCHAR(50),
 v_network_name VARCHAR(50) ,
 v_speed INTEGER ,
 v_subnet VARCHAR(20) ,
 v_boot_protocol INTEGER ,
 v_type INTEGER ,
 v_vds_id UUID,
 v_base_interface VARCHAR(50) ,
 v_vlan_id INTEGER,
 v_mtu INTEGER,
 v_bridged BOOLEAN,
 v_qos_overridden BOOLEAN,
 v_labels TEXT,
 v_custom_properties TEXT)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO vds_interface(addr, bond_name, bond_type, gateway, id, is_bond, bond_opts, mac_addr, name, network_name, speed, subnet, boot_protocol, type, VDS_ID, base_interface, vlan_id, mtu, bridged, qos_overridden, labels, custom_properties)
	VALUES(v_addr, v_bond_name, v_bond_type, v_gateway, v_id, v_is_bond, v_bond_opts, v_mac_addr, v_name, v_network_name, v_speed, v_subnet, v_boot_protocol, v_type, v_vds_id, v_base_interface, v_vlan_id, v_mtu, v_bridged, v_qos_overridden, v_labels, v_custom_properties);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatevds_interface(v_addr VARCHAR(20) ,
 v_bond_name VARCHAR(50) ,
 v_bond_type INTEGER ,
 v_gateway VARCHAR(20) ,
 v_id UUID,
 v_is_bond BOOLEAN ,
 v_bond_opts VARCHAR(4000) ,
 v_mac_addr VARCHAR(20) ,
 v_name VARCHAR(50),
 v_network_name VARCHAR(50) ,
 v_speed INTEGER ,
 v_subnet VARCHAR(20) ,
 v_boot_protocol INTEGER ,
 v_type INTEGER ,
 v_vds_id UUID,
 v_base_interface VARCHAR(50),
 v_vlan_id INTEGER,
 v_mtu INTEGER,
 v_bridged BOOLEAN,
 v_qos_overridden BOOLEAN,
 v_labels TEXT,
 v_custom_properties TEXT)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE vds_interface
      SET addr = v_addr,bond_name = v_bond_name,bond_type = v_bond_type,gateway = v_gateway,
      is_bond = v_is_bond,bond_opts = v_bond_opts,mac_addr = v_mac_addr,
      name = v_name,network_name = v_network_name,speed = v_speed,
      subnet = v_subnet,boot_protocol = v_boot_protocol,
      type = v_type,VDS_ID = v_vds_id,base_interface = v_base_interface,vlan_id = v_vlan_id,_update_date = LOCALTIMESTAMP, mtu = v_mtu,
      bridged = v_bridged, qos_overridden = v_qos_overridden, labels = v_labels,
      custom_properties = v_custom_properties
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletevds_interface(v_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM vds_interface
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getinterface_viewByvds_id(v_vds_id UUID, v_user_id UUID, v_is_filtered boolean)
RETURNS SETOF vds_interface_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vds_interface_view
   WHERE vds_id = v_vds_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_vds_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = v_vds_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetHostNetworksByCluster(v_cluster_id UUID)
RETURNS TABLE(vds_id UUID, network_name VARCHAR) STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT vds_static.vds_id, vds_interface.network_name
   FROM vds_static
   JOIN vds_interface ON vds_interface.vds_id = vds_static.vds_id
   AND vds_static.vds_group_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getinterface_viewByAddr(v_cluster_id UUID, v_addr VARCHAR(50))
RETURNS SETOF vds_interface_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT vds_interface_view.*
   FROM vds_interface_view
   INNER JOIN vds_static
   ON vds_interface_view.vds_id = vds_static.vds_id
   WHERE vds_interface_view.addr = v_addr
   AND vds_static.vds_group_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsManagedInterfaceByVdsId(v_vds_id UUID, v_user_id UUID, v_is_filtered boolean)
RETURNS SETOF vds_interface_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vds_interface_view
   -- Checking if the 2nd bit in the type column is set, meaning that the interface is managed
   WHERE vds_id = v_vds_id AND (type & 2) = 2
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_vds_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = v_vds_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsInterfacesByNetworkId(v_network_id UUID) RETURNS SETOF vds_interface_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT vds_interface_view.*
   FROM vds_interface_view
   INNER JOIN vds
   ON vds.vds_id = vds_interface_view.vds_id
   INNER JOIN network_cluster
   ON network_cluster.cluster_id = vds.vds_group_id
   INNER JOIN network
   ON network.id = network_cluster.network_id
   AND network.name = vds_interface_view.network_name
   WHERE network.id = v_network_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsInterfaceById(v_vds_interface_id UUID) RETURNS SETOF vds_interface_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vds_interface_view
   WHERE id = v_vds_interface_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetInterfacesByClusterId(v_cluster_id UUID)
RETURNS SETOF vds_interface_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT vds_interface_view.*
   FROM vds_interface_view
   INNER JOIN vds_static
   ON vds_interface_view.vds_id = vds_static.vds_id
   WHERE vds_static.vds_group_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetInterfacesByDataCenterId(v_data_center_id UUID)
RETURNS SETOF vds_interface_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT vds_interface_view.*
   FROM vds_interface_view
   INNER JOIN vds_static
   ON vds_interface_view.vds_id = vds_static.vds_id
   INNER JOIN vds_groups
   ON vds_static.vds_group_id = vds_groups.vds_group_id
   WHERE vds_groups.storage_pool_id = v_data_center_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVmInterface(v_id UUID,
    v_mac_addr VARCHAR(20) ,
    v_name VARCHAR(50),
    v_speed INTEGER ,
    v_vnic_profile_id UUID ,
    v_vm_guid UUID ,
    v_vmt_guid UUID ,
    v_type INTEGER,
    v_linked BOOLEAN)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO vm_interface(id, mac_addr, name, speed, vnic_profile_id, vm_guid, vmt_guid, type, linked)
       VALUES(v_id, v_mac_addr, v_name, v_speed, v_vnic_profile_id, v_vm_guid, v_vmt_guid, v_type, v_linked);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmInterface(v_id UUID,
    v_mac_addr VARCHAR(20) ,
    v_name VARCHAR(50),
    v_speed INTEGER ,
    v_vnic_profile_id UUID ,
    v_vm_guid UUID ,
    v_vmt_guid UUID ,
    v_type INTEGER,
    v_linked BOOLEAN)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE vm_interface
      SET mac_addr = v_mac_addr,name = v_name, speed = v_speed, vnic_profile_id = v_vnic_profile_id, vm_guid = v_vm_guid,
      vmt_guid = v_vmt_guid,type = v_type, _update_date = LOCALTIMESTAMP, linked = v_linked
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVmInterface(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN

   -- Get (and keep) a shared lock with "right to upgrade to exclusive"
   -- in order to force locking parent before children
   select   id INTO v_val FROM vm_interface  WHERE id = v_id     FOR UPDATE;

   DELETE FROM vm_interface
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmInterfaceByVmInterfaceId(v_id UUID) RETURNS SETOF vm_interface STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface
   WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVmInterfaces() RETURNS SETOF vm_interface STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmInterfacesByVmId(v_vm_id UUID)
RETURNS SETOF vm_interface STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface
   WHERE vm_guid = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmInterfaceByTemplateId(v_template_id UUID)
RETURNS SETOF vm_interface STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface
   WHERE vmt_guid = v_template_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmInterfacesByNetworkId(v_network_id UUID) RETURNS SETOF vm_interface STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT vm_interface.*
   FROM vm_interface
   INNER JOIN vnic_profiles ON vm_interface.vnic_profile_id = vnic_profiles.id
   INNER JOIN vm_static on vm_interface.vm_guid = vm_static.vm_guid
   WHERE vnic_profiles.network_id = v_network_id
   AND vm_static.entity_type = 'VM';
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplateInterfacesByNetworkId(v_network_id UUID) RETURNS SETOF vm_interface STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT vm_interface.*
   FROM vm_interface
   INNER JOIN vm_static on vm_interface.vmt_guid = vm_static.vm_guid
   INNER JOIN vnic_profiles ON vm_interface.vnic_profile_id = vnic_profiles.id
   WHERE vnic_profiles.network_id = v_network_id
   AND vm_static.entity_type  = 'TEMPLATE';
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetMacsByDataCenterId(v_data_center_id UUID) RETURNS SETOF varchar STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT mac_addr
   FROM vm_interface
   WHERE EXISTS (SELECT 1
                 FROM vm_static
                 JOIN vds_groups ON vm_static.vds_group_id = vds_groups.vds_group_id
                 WHERE vds_groups.storage_pool_id = v_data_center_id
                 AND vm_static.vm_guid = vm_interface.vm_guid);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVmNetworkInterfaceViews() RETURNS SETOF vm_interface_view STABLE
AS $procedure$
BEGIN
RETURN QUERY SELECT *
FROM vm_interface_view;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmNetworkInterfaceViewByVmNetworkInterfaceViewId(v_id UUID)
RETURNS SETOF vm_interface_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface_view
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetPluggedVmInterfacesByMac(v_mac_address VARCHAR(20))
RETURNS SETOF vm_interface_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface_view
   WHERE mac_addr = v_mac_address
   AND is_plugged = true;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmNetworkInterfaceViewByVmId(v_vm_id UUID, v_user_id UUID, v_is_filtered BOOLEAN)
RETURNS SETOF vm_interface_view STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface_view
   WHERE vm_guid = v_vm_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
   FROM   user_vm_permissions_view
   WHERE  user_id = v_user_id AND entity_id = v_vm_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmNetworkInterfaceViewByTemplateId(v_template_id UUID, v_user_id UUID, v_is_filtered boolean)
RETURNS SETOF vm_interface_view STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vm_interface_view
   WHERE vmt_guid = v_template_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
   FROM   user_vm_template_permissions_view
   WHERE  user_id = v_user_id AND entity_id = v_template_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmInterfaceViewsByNetworkId(v_network_id UUID) RETURNS SETOF vm_interface_view STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT vm_interface_view.*
   FROM vm_interface_view
   INNER JOIN vnic_profiles ON vnic_profiles.id = vm_interface_view.vnic_profile_id
   WHERE vnic_profiles.network_id = v_network_id
   AND vm_interface_view.vm_entity_type = 'VM';
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplateInterfaceViewsByNetworkId(v_network_id UUID) RETURNS SETOF vm_interface_view STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT vm_interface_view.*
   FROM vm_interface_view
   INNER JOIN vnic_profiles ON vnic_profiles.id = vm_interface_view.vnic_profile_id
   WHERE vnic_profiles.network_id = v_network_id
   AND vm_interface_view.vm_entity_type = 'TEMPLATE';
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getvm_interface_statisticsById(v_id UUID) RETURNS SETOF vm_interface_statistics STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM vm_interface_statistics
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertvm_interface_statistics(v_id UUID,
	v_rx_drop DECIMAL(18,0) ,
	v_rx_rate DECIMAL(18,0) ,
	v_tx_drop DECIMAL(18,0) ,
	v_tx_rate DECIMAL(18,0) ,
	v_iface_status INTEGER ,
	v_vm_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO vm_interface_statistics(id, rx_drop, rx_rate, tx_drop, tx_rate, vm_id, iface_status)
	VALUES(v_id, v_rx_drop, v_rx_rate, v_tx_drop, v_tx_rate, v_vm_id,v_iface_status);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatevm_interface_statistics(v_id UUID,
 v_rx_drop DECIMAL(18,0) ,
 v_rx_rate DECIMAL(18,0) ,
 v_tx_drop DECIMAL(18,0) ,
 v_tx_rate DECIMAL(18,0) ,
 v_iface_status INTEGER ,
 v_vm_id UUID)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE vm_interface_statistics
      SET rx_drop = v_rx_drop,rx_rate = v_rx_rate,tx_drop = v_tx_drop,tx_rate = v_tx_rate,
      vm_id = v_vm_id,iface_status = v_iface_status, _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletevm_interface_statistics(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM vm_interface_statistics  WHERE id = v_id     FOR UPDATE;

   DELETE FROM vm_interface_statistics
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmGuestAgentInterfacesByVmId(v_vm_id UUID, v_user_id UUID, v_filtered BOOLEAN)
RETURNS SETOF vm_guest_agent_interfaces STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM vm_guest_agent_interfaces
   WHERE vm_id = v_vm_id
   AND (NOT v_filtered OR EXISTS (SELECT 1
                                  FROM   user_vm_permissions_view
                                  WHERE  user_id = v_user_id AND entity_id = v_vm_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVmGuestAgentInterfacesByVmId(v_vm_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   DELETE FROM vm_guest_agent_interfaces
   WHERE vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVmGuestAgentInterface(v_vm_id UUID,
   v_interface_name VARCHAR(50),
   v_mac_address VARCHAR(59),
   v_ipv4_addresses text,
   v_ipv6_addresses text)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO vm_guest_agent_interfaces(vm_id, interface_name, mac_address, ipv4_addresses, ipv6_addresses)
       VALUES(v_vm_id, v_interface_name, v_mac_address, v_ipv4_addresses, v_ipv6_addresses);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertvds_interface_statistics(v_id UUID,
	v_rx_drop DECIMAL(18,0) ,
	v_rx_rate DECIMAL(18,0) ,
	v_tx_drop DECIMAL(18,0) ,
	v_tx_rate DECIMAL(18,0) ,
	v_iface_status INTEGER ,
	v_vds_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO vds_interface_statistics(id, rx_drop, rx_rate, tx_drop, tx_rate, vds_id, iface_status)
	VALUES(v_id, v_rx_drop, v_rx_rate, v_tx_drop, v_tx_rate, v_vds_id,v_iface_status);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatevds_interface_statistics(v_id UUID,
 v_rx_drop DECIMAL(18,0) ,
 v_rx_rate DECIMAL(18,0) ,
 v_tx_drop DECIMAL(18,0) ,
 v_tx_rate DECIMAL(18,0) ,
 v_iface_status INTEGER ,
 v_vds_id UUID)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE vds_interface_statistics
      SET rx_drop = v_rx_drop,rx_rate = v_rx_rate,tx_drop = v_tx_drop,tx_rate = v_tx_rate,
      vds_id = v_vds_id,iface_status = v_iface_status, _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletevds_interface_statistics(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM vds_interface_statistics  WHERE id = v_id     FOR UPDATE;

   DELETE FROM vds_interface_statistics
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertnetwork_cluster(v_cluster_id UUID,
   v_network_id UUID,
   v_status INTEGER,
   v_is_display BOOLEAN,
   v_required BOOLEAN,
   v_migration BOOLEAN)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO network_cluster(cluster_id, network_id, status, is_display, required, migration)
	VALUES(v_cluster_id, v_network_id, v_status, v_is_display, v_required, v_migration);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatenetwork_cluster(v_cluster_id UUID,
    v_network_id UUID,
    v_status INTEGER,
    v_is_display BOOLEAN,
    v_required BOOLEAN,
    v_migration BOOLEAN)
RETURNS VOID
   AS $procedure$
BEGIN
   UPDATE network_cluster
   SET status = v_status,is_display = v_is_display, required = v_required, migration = v_migration
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatenetwork_cluster_status(v_cluster_id UUID,
        v_network_id UUID,
        v_status INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
   UPDATE network_cluster
   SET status = v_status
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletenetwork_cluster(v_cluster_id UUID,
	v_network_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM network_cluster
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromnetwork_cluster() RETURNS SETOF network_cluster STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM network_cluster;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromnetwork_clusterByClusterId(v_cluster_id UUID)
RETURNS SETOF network_cluster STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM network_cluster
   WHERE cluster_id = v_cluster_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromnetwork_clusterByNetworkId(v_network_id UUID)
RETURNS SETOF network_cluster STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM network_cluster
   WHERE network_id = v_network_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getnetwork_clusterBycluster_idAndBynetwork_id(v_cluster_id UUID,
 v_network_id UUID) RETURNS SETOF network_cluster STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM network_cluster
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetvmStaticByGroupIdAndNetwork(v_groupId UUID,
     v_networkName VARCHAR(50)) RETURNS SETOF vm_static STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT
   vm_static.* from vm_static
   inner join vm_interface_view
   on vm_static.vm_guid = vm_interface_view.vm_guid
   and network_name = v_networkName
   and vm_static.vds_group_id = v_groupId;


END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION set_network_exclusively_as_display(v_cluster_id UUID, v_network_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   UPDATE network_cluster
   SET is_display = true
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;

   IF FOUND THEN
       UPDATE network_cluster
       SET is_display = false
       WHERE cluster_id = v_cluster_id AND network_id != v_network_id;
   END IF;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION set_network_exclusively_as_migration(v_cluster_id UUID, v_network_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   UPDATE network_cluster
   SET migration = true
   WHERE cluster_id = v_cluster_id AND network_id = v_network_id;

   IF FOUND THEN
       UPDATE network_cluster
       SET migration = false
       WHERE cluster_id = v_cluster_id AND network_id != v_network_id;
   END IF;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVnicProfileByVnicProfileId(v_id UUID)
RETURNS SETOF vnic_profiles STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM vnic_profiles
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVnicProfile(v_id UUID,
  v_name VARCHAR(50),
  v_network_id UUID,
  v_network_qos_id UUID,
  v_port_mirroring BOOLEAN,
  v_custom_properties TEXT,
  v_description TEXT)
RETURNS VOID
   AS $procedure$
BEGIN

   INSERT INTO vnic_profiles(id, name, network_id, network_qos_id, port_mirroring, custom_properties, description)
       VALUES(v_id, v_name, v_network_id, v_network_qos_id, v_port_mirroring, v_custom_properties, v_description);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVnicProfile(v_id UUID,
  v_name VARCHAR(50),
  v_network_id UUID,
  v_network_qos_id UUID,
  v_port_mirroring BOOLEAN,
  v_custom_properties TEXT,
  v_description TEXT)
RETURNS VOID
   AS $procedure$
BEGIN

   UPDATE vnic_profiles
   SET id = v_id, name = v_name, network_id = v_network_id, network_qos_id = v_network_qos_id,
   port_mirroring = v_port_mirroring, custom_properties = v_custom_properties,
   description = v_description,_update_date = LOCALTIMESTAMP
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVnicProfile(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val UUID;
BEGIN

    DELETE FROM vnic_profiles
    WHERE id = v_id;

    -- Delete the vnic profiles permissions
    DELETE FROM permissions WHERE object_id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVnicProfiles()
RETURNS SETOF vnic_profiles STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM vnic_profiles;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVnicProfilesByNetworkId(v_network_id UUID)
RETURNS SETOF vnic_profiles STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM vnic_profiles
   WHERE network_id = v_network_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVnicProfileViewByVnicProfileViewId(v_id UUID, v_user_id uuid, v_is_filtered boolean)
RETURNS SETOF vnic_profiles_view STABLE
AS $procedure$
BEGIN

RETURN QUERY SELECT *
FROM vnic_profiles_view
WHERE id = v_id
AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                  FROM   user_vnic_profile_permissions_view
                                  WHERE  user_id = v_user_id AND entity_id = vnic_profiles_view.id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVnicProfileViews(v_user_id uuid, v_is_filtered boolean)
RETURNS SETOF vnic_profiles_view STABLE
AS $procedure$
BEGIN

RETURN QUERY SELECT *
FROM vnic_profiles_view
WHERE NOT v_is_filtered OR EXISTS (SELECT 1
                                   FROM   user_vnic_profile_permissions_view
                                   WHERE  user_id = v_user_id AND entity_id = vnic_profiles_view.id);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVnicProfileViewsByNetworkId(v_network_id UUID, v_user_id uuid, v_is_filtered boolean)
RETURNS SETOF vnic_profiles_view STABLE
AS $procedure$
BEGIN

RETURN QUERY SELECT *
FROM vnic_profiles_view
WHERE network_id = v_network_id
AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                  FROM   user_vnic_profile_permissions_view
                                  WHERE  user_id = v_user_id AND entity_id = vnic_profiles_view.id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVnicProfileViewsByDataCenterId(v_id UUID, v_user_id uuid, v_is_filtered boolean)
RETURNS SETOF vnic_profiles_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vnic_profiles_view
    WHERE  data_center_id = v_id
    AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                      FROM   user_vnic_profile_permissions_view
                                      WHERE  user_id = v_user_id AND entity_id = vnic_profiles_view.id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVnicProfileViewsByNetworkQosId(v_network_qos_id UUID) RETURNS SETOF vnic_profiles_view STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM vnic_profiles_view
   WHERE network_qos_id = v_network_qos_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetIscsiIfacesByHostIdAndStorageTargetId(v_host_id UUID, v_target_id varchar(50)) RETURNS SETOF vds_interface_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT vds_interface_view.*
   FROM vds_interface_view,
        network_cluster,
        network,
        iscsi_bonds_networks_map,
        iscsi_bonds_storage_connections_map
   WHERE
       iscsi_bonds_storage_connections_map.connection_id = v_target_id AND
       iscsi_bonds_storage_connections_map.iscsi_bond_id = iscsi_bonds_networks_map.iscsi_bond_id AND
       iscsi_bonds_networks_map.network_id = network.id AND
       network.id = network_cluster.network_id AND
       network.name = vds_interface_view.network_name AND
       network_cluster.cluster_id = vds_interface_view.vds_group_id AND
       vds_interface_view.vds_id = v_host_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION RenameManagementNetwork(v_name varchar(50)) RETURNS VOID
   AS $procedure$
DECLARE
    v_old_name  varchar(4000);
BEGIN
    select option_value into v_old_name from vdc_options where option_name = 'ManagementNetwork' and version = 'general';
    perform fn_db_update_config_value('ManagementNetwork', v_name, 'general');
    update network set name = v_name where name = v_old_name;
    update vnic_profiles set name = v_name where name = v_old_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertNumaNode(v_numa_node_id UUID,
 v_vds_id UUID,
 v_vm_id UUID,
 v_numa_node_index SMALLINT,
 v_mem_total BIGINT,
 v_cpu_count SMALLINT,
 v_mem_free BIGINT,
 v_usage_mem_percent INTEGER,
 v_cpu_sys DECIMAL(5,2),
 v_cpu_user DECIMAL(5,2),
 v_cpu_idle DECIMAL(5,2),
 v_usage_cpu_percent INTEGER,
 v_distance text)
RETURNS VOID
   AS $procedure$
BEGIN

   BEGIN
      INSERT INTO numa_node(numa_node_id, vds_id, vm_id, numa_node_index, mem_total, cpu_count, mem_free, usage_mem_percent, cpu_sys, cpu_user, cpu_idle, usage_cpu_percent, distance)
      VALUES(v_numa_node_id, v_vds_id, v_vm_id, v_numa_node_index, v_mem_total, v_cpu_count, v_mem_free, v_usage_mem_percent, v_cpu_sys, v_cpu_user, v_cpu_idle, v_usage_cpu_percent, v_distance);
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateNumaNode(v_numa_node_id UUID,
 v_numa_node_index SMALLINT,
 v_mem_total BIGINT,
 v_cpu_count SMALLINT,
 v_distance text)
RETURNS VOID
   AS $procedure$
BEGIN

   BEGIN
      UPDATE numa_node
      SET numa_node_index = v_numa_node_index,
      mem_total = v_mem_total, cpu_count = v_cpu_count,
      distance = v_distance
      WHERE numa_node_id = v_numa_node_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateNumaNodeStatistics(v_numa_node_id UUID,
 v_mem_free BIGINT,
 v_usage_mem_percent INTEGER,
 v_cpu_sys DECIMAL(5,2),
 v_cpu_user DECIMAL(5,2),
 v_cpu_idle DECIMAL(5,2),
 v_usage_cpu_percent INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN

   BEGIN
      UPDATE numa_node
      SET mem_free = v_mem_free, usage_mem_percent = v_usage_mem_percent, cpu_sys = v_cpu_sys,
      cpu_user = v_cpu_user, cpu_idle = v_cpu_idle, usage_cpu_percent = v_usage_cpu_percent
      WHERE numa_node_id = v_numa_node_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteNumaNode(v_numa_node_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   BEGIN
      DELETE FROM numa_node
      WHERE numa_node_id = v_numa_node_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromNumaNode() RETURNS SETOF numa_node STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node.*
      FROM numa_node;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNumaNodeByNumaNodeId(v_numa_node_id UUID) RETURNS SETOF numa_node STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node.*
      FROM numa_node
      WHERE numa_node_id = v_numa_node_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNumaNodeByVdsId(v_vds_id UUID) RETURNS SETOF numa_node STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node.*
      FROM numa_node
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNumaNodeByVmId(v_vm_id UUID) RETURNS SETOF numa_node STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node.*
      FROM numa_node
      WHERE vm_id = v_vm_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertNumaNodeCpu(v_id UUID,
 v_numa_node_id UUID,
 v_cpu_core_id INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN

   BEGIN
      INSERT INTO numa_node_cpu_map(id, numa_node_id, cpu_core_id)
      VALUES(v_id, v_numa_node_id, v_cpu_core_id);
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteNumaNodeCpuByNumaNodeId(v_numa_node_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   BEGIN
      DELETE FROM numa_node_cpu_map
      WHERE numa_node_id = v_numa_node_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromNumaNodeCpuMap() RETURNS SETOF numa_node_cpu_map STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node_cpu_map.*
      FROM numa_node_cpu_map;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNumaNodeCpuByNumaNodeId(v_numa_node_id UUID) RETURNS SETOF integer STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node_cpu_map.cpu_core_id
      FROM numa_node_cpu_map
      WHERE numa_node_id = v_numa_node_id
      ORDER BY numa_node_cpu_map.cpu_core_id ASC;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertNumaNodeMap(v_id UUID,
 v_vm_numa_node_id UUID,
 v_vds_numa_node_id UUID,
 v_vds_numa_node_index SMALLINT,
 v_is_pinned BOOLEAN)
RETURNS VOID
   AS $procedure$
BEGIN

   BEGIN
      INSERT INTO vm_vds_numa_node_map(id, vm_numa_node_id, vds_numa_node_id, vds_numa_node_index, is_pinned)
      VALUES(v_id, v_vm_numa_node_id, v_vds_numa_node_id, v_vds_numa_node_index, v_is_pinned);
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteNumaNodeMapByVmNumaNodeId(v_vm_numa_node_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   BEGIN
      DELETE FROM vm_vds_numa_node_map
      WHERE vm_numa_node_id = v_vm_numa_node_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteNumaNodeMapByVdsNumaNodeId(v_vds_numa_node_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   BEGIN
      DELETE FROM vm_vds_numa_node_map
      WHERE vds_numa_node_id = v_vds_numa_node_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteUnpinnedNumaNodeMapByVmNumaNodeId(v_vm_numa_node_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   BEGIN
      DELETE FROM vm_vds_numa_node_map
      WHERE vm_numa_node_id = v_vm_numa_node_id AND is_pinned = FALSE;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNumaNodeCpuByVdsId(v_vds_id UUID) RETURNS SETOF numa_node_cpus_view STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node_cpus_view.*
      FROM numa_node_cpus_view
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNumaNodeCpuByVmId(v_vm_id UUID) RETURNS SETOF numa_node_cpus_view STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node_cpus_view.*
      FROM numa_node_cpus_view
      WHERE vm_id = v_vm_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmNumaNodeByVdsNumaNodeIdWithPinnedInfo(v_vds_numa_node_id UUID, v_is_pinned BOOLEAN) RETURNS SETOF numa_node STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node_assignment_view.assigned_vm_numa_node_id,
      numa_node_assignment_view.run_in_vds_id,
      numa_node_assignment_view.vm_numa_node_vm_id,
      numa_node_assignment_view.vm_numa_node_index,
      numa_node_assignment_view.vm_numa_node_mem_total,
      numa_node_assignment_view.vm_numa_node_cpu_count,
      numa_node_assignment_view.vm_numa_node_mem_free,
      numa_node_assignment_view.vm_numa_node_usage_mem_percent,
      numa_node_assignment_view.vm_numa_node_cpu_sys,
      numa_node_assignment_view.vm_numa_node_cpu_user,
      numa_node_assignment_view.vm_numa_node_cpu_idle,
      numa_node_assignment_view.vm_numa_node_usage_cpu_percent,
      numa_node_assignment_view.vm_numa_node_distance
      FROM numa_node_assignment_view
      WHERE run_in_vds_numa_node_id = v_vds_numa_node_id AND is_pinned = v_is_pinned;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmNumaNodeByVdsNumaNodeId(v_vds_numa_node_id UUID) RETURNS SETOF numa_node STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node_assignment_view.assigned_vm_numa_node_id,
      numa_node_assignment_view.run_in_vds_id,
      numa_node_assignment_view.vm_numa_node_vm_id,
      numa_node_assignment_view.vm_numa_node_index,
      numa_node_assignment_view.vm_numa_node_mem_total,
      numa_node_assignment_view.vm_numa_node_cpu_count,
      numa_node_assignment_view.vm_numa_node_mem_free,
      numa_node_assignment_view.vm_numa_node_usage_mem_percent,
      numa_node_assignment_view.vm_numa_node_cpu_sys,
      numa_node_assignment_view.vm_numa_node_cpu_user,
      numa_node_assignment_view.vm_numa_node_cpu_idle,
      numa_node_assignment_view.vm_numa_node_usage_cpu_percent,
      numa_node_assignment_view.vm_numa_node_distance
      FROM numa_node_assignment_view
      WHERE run_in_vds_numa_node_id = v_vds_numa_node_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllAssignedNumaNodeInfomation() RETURNS SETOF numa_node_assignment_view STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node_assignment_view.*
      FROM numa_node_assignment_view;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetLastRunInPnodeInfoByVmId(v_vm_id UUID) RETURNS SETOF numa_node_assignment_view STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node_assignment_view.*
      FROM numa_node_assignment_view
      WHERE vm_numa_node_vm_id = v_vm_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmNumaNodeByVdsGroup(v_vds_group_id UUID) RETURNS SETOF numa_node_with_vds_group_view STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT numa_node_with_vds_group_view.*
      FROM numa_node_with_vds_group_view
      WHERE vds_group_id = v_vds_group_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromPolicyUnits() RETURNS SETOF policy_units STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   policy_units;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetPolicyUnitByPolicyUnitId(v_id UUID) RETURNS SETOF policy_units STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   policy_units
    WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertPolicyUnit(
    v_id UUID,
    v_name VARCHAR(128),
    v_description text,
    v_is_internal BOOLEAN,
    v_type SMALLINT,
    v_custom_properties_regex text,
    v_enabled BOOLEAN)
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO policy_units(
        id,
        name,
        description,
        is_internal,
        type,
        custom_properties_regex,
        enabled)
    VALUES(
        v_id,
        v_name,
        v_description,
        v_is_internal,
        v_type,
        v_custom_properties_regex,
        v_enabled);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdatePolicyUnit(
    v_id UUID,
    v_enabled BOOLEAN,
    v_custom_properties_regex text,
    v_description text)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE policy_units
    SET    custom_properties_regex = v_custom_properties_regex,
           enabled = v_enabled,
           description = v_description
    WHERE  id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeletePolicyUnit(v_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   DELETE FROM policy_units
   WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertProvider(
    v_id UUID,
    v_name VARCHAR(128),
    v_description VARCHAR(4000),
    v_url VARCHAR(512),
    v_provider_type VARCHAR(32),
    v_auth_required BOOLEAN,
    v_auth_username VARCHAR(64),
    v_auth_password TEXT,
    v_custom_properties TEXT,
    v_tenant_name VARCHAR DEFAULT NULL,
    v_plugin_type VARCHAR DEFAULT NULL,
    v_agent_configuration TEXT DEFAULT NULL)
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO providers(
        id,
        name,
        description,
        url,
        provider_type,
        auth_required,
        auth_username,
        auth_password,
        custom_properties,
        tenant_name,
        plugin_type,
        agent_configuration)
    VALUES(
        v_id,
        v_name,
        v_description,
        v_url,
        v_provider_type,
        v_auth_required,
        v_auth_username,
        v_auth_password,
        v_custom_properties,
        v_tenant_name,
        v_plugin_type,
        v_agent_configuration);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateProvider(
    v_id UUID,
    v_name VARCHAR(128),
    v_description VARCHAR(4000),
    v_url VARCHAR(512),
    v_provider_type VARCHAR(32),
    v_auth_required BOOLEAN,
    v_auth_username VARCHAR(64),
    v_auth_password TEXT,
    v_custom_properties TEXT,
    v_tenant_name VARCHAR DEFAULT NULL,
    v_plugin_type VARCHAR DEFAULT NULL,
    v_agent_configuration TEXT DEFAULT NULL)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE providers
    SET    name = v_name,
           description = v_description,
           url = v_url,
           provider_type = v_provider_type,
           auth_required = v_auth_required,
           auth_username = v_auth_username,
           auth_password = v_auth_password,
           custom_properties = v_custom_properties,
           tenant_name = v_tenant_name,
           plugin_type = v_plugin_type,
           _update_date = NOW(),
           agent_configuration = v_agent_configuration
    WHERE  id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteProvider(v_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE
    FROM   providers
    WHERE  id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromProviders() RETURNS SETOF providers STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   providers;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromProvidersByType(v_provider_type varchar(32)) RETURNS SETOF providers STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   providers
    WHERE provider_type = v_provider_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetProviderByProviderId(v_id UUID)
RETURNS SETOF providers STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   providers
    WHERE  id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetProviderByName(v_name VARCHAR)
RETURNS SETOF providers STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   providers
    WHERE  name = v_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertStorageQos(v_id uuid,
  v_qos_type SMALLINT,
  v_name VARCHAR(50),
  v_description TEXT,
  v_storage_pool_id uuid,
  v_max_throughput INTEGER,
  v_max_read_throughput INTEGER,
  v_max_write_throughput INTEGER,
  v_max_iops INTEGER,
  v_max_read_iops INTEGER,
  v_max_write_iops INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO qos(id, qos_type, name, description, storage_pool_id, max_throughput, max_read_throughput, max_write_throughput, max_iops, max_read_iops, max_write_iops)
  VALUES(v_id, v_qos_type, v_name, v_description, v_storage_pool_id, v_max_throughput, v_max_read_throughput, v_max_write_throughput, v_max_iops, v_max_read_iops, v_max_write_iops);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertCpuQos(v_id uuid,
  v_qos_type SMALLINT,
  v_name VARCHAR(50),
  v_description TEXT,
  v_storage_pool_id uuid,
  v_cpu_limit INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO qos(id, qos_type, name, description, storage_pool_id, cpu_limit)
  VALUES(v_id, v_qos_type, v_name, v_description, v_storage_pool_id, v_cpu_limit);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertNetworkQos(v_id uuid,
  v_qos_type SMALLINT,
  v_name VARCHAR(50),
  v_description TEXT,
  v_storage_pool_id uuid,
  v_inbound_average INTEGER,
  v_inbound_peak INTEGER,
  v_inbound_burst INTEGER,
  v_outbound_average INTEGER,
  v_outbound_peak INTEGER,
  v_outbound_burst INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO qos(id, qos_type, name, description, storage_pool_id, inbound_average, inbound_peak, inbound_burst, outbound_average, outbound_peak, outbound_burst)
  VALUES(v_id, v_qos_type, v_name, v_description, v_storage_pool_id, v_inbound_average, v_inbound_peak, v_inbound_burst, v_outbound_average, v_outbound_peak, v_outbound_burst);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateStorageQos(v_id uuid,
  v_qos_type SMALLINT,
  v_name VARCHAR(50),
  v_description TEXT,
  v_storage_pool_id uuid,
  v_max_throughput INTEGER,
  v_max_read_throughput INTEGER,
  v_max_write_throughput INTEGER,
  v_max_iops INTEGER,
  v_max_read_iops INTEGER,
  v_max_write_iops INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE qos
      SET qos_type = v_qos_type, name = v_name, description = v_description, storage_pool_id = v_storage_pool_id, max_throughput = v_max_throughput, max_read_throughput = v_max_read_throughput,
      max_write_throughput = v_max_write_throughput, max_iops = v_max_iops, max_read_iops = v_max_read_iops, max_write_iops = v_max_write_iops,
      _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateCpuQos(v_id uuid,
  v_qos_type SMALLINT,
  v_name VARCHAR(50),
  v_description TEXT,
  v_storage_pool_id uuid,
  v_cpu_limit INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE qos
      SET qos_type = v_qos_type, name = v_name, description = v_description, storage_pool_id = v_storage_pool_id, cpu_limit = v_cpu_limit,
      _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateNetworkQos(v_id uuid,
  v_qos_type SMALLINT,
  v_name VARCHAR(50),
  v_description TEXT,
  v_storage_pool_id uuid,
  v_inbound_average INTEGER,
  v_inbound_peak INTEGER,
  v_inbound_burst INTEGER,
  v_outbound_average INTEGER,
  v_outbound_peak INTEGER,
  v_outbound_burst INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE qos
      SET qos_type = v_qos_type, name = v_name, description = v_description, storage_pool_id = v_storage_pool_id, inbound_average = v_inbound_average, inbound_peak = v_inbound_peak, inbound_burst = v_inbound_burst,
      outbound_average = v_outbound_average, outbound_peak = v_outbound_peak, outbound_burst = v_outbound_burst, _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteQos(v_id UUID) RETURNS VOID
   AS $procedure$
BEGIN
   DELETE FROM qos
   WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetQosByQosId(v_id UUID) RETURNS SETOF qos STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM qos
   WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllQosForStoragePoolByQosType(v_storage_pool_id UUID, v_qos_type SMALLINT) RETURNS SETOF qos STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM qos
   WHERE storage_pool_id = v_storage_pool_id
   AND qos_type = v_qos_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllQosForStoragePool(v_storage_pool_id UUID) RETURNS SETOF qos STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM qos
   WHERE storage_pool_id = v_storage_pool_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllQosByQosType(v_qos_type SMALLINT) RETURNS SETOF qos STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM qos
   WHERE qos_type = v_qos_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetQosByDiskProfile(v_disk_profile_id UUID) RETURNS SETOF qos STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT qos.*
   FROM qos
   JOIN disk_profiles ON qos.id = disk_profiles.qos_id
   WHERE disk_profiles.id = v_disk_profile_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetQosByVmId(v_vm_id UUID) RETURNS SETOF qos STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT qos.*
   FROM qos
   JOIN cpu_profiles ON qos.id = cpu_profiles.qos_id
   JOIN vds_groups ON vds_groups.vds_group_id = cpu_profiles.cluster_id
   JOIN vm_static ON vm_static.vm_guid = v_vm_id
   WHERE vm_static.vds_group_id = vds_groups.vds_group_id
         AND vm_static.cpu_profile_id = cpu_profiles.id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertQuota(v_id UUID, v_storage_pool_id UUID, v_quota_name VARCHAR(50), v_description VARCHAR(500), v_threshold_vds_group_percentage INTEGER, v_threshold_storage_percentage INTEGER, v_grace_vds_group_percentage INTEGER, v_grace_storage_percentage INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO quota(id, storage_pool_id, quota_name, description, threshold_vds_group_percentage, threshold_storage_percentage, grace_vds_group_percentage, grace_storage_percentage)
   VALUES(v_id,  v_storage_pool_id, v_quota_name,  v_description,  v_threshold_vds_group_percentage ,  v_threshold_storage_percentage,  v_grace_vds_group_percentage,  v_grace_storage_percentage);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertQuotaLimitation(v_id UUID, v_quota_id UUID, v_storage_id UUID, v_vds_group_id UUID, v_virtual_cpu INTEGER, v_mem_size_mb BIGINT, v_storage_size_gb BIGINT)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO quota_limitation(id, quota_id, storage_id, vds_group_id, virtual_cpu, mem_size_mb, storage_size_gb)
   VALUES(v_id, v_quota_id, v_storage_id, v_vds_group_id, v_virtual_cpu, v_mem_size_mb, v_storage_size_gb);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetQuotaStorageByStorageGuid(v_storage_id UUID, v_id UUID, v_allow_empty BOOLEAN)
RETURNS SETOF quota_storage_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM
   (SELECT  COALESCE(q_storage_view.quota_storage_id, q_g_view.quota_id) as quota_storage_id,
            q_g_view.quota_id as quota_id,
            q_storage_view.storage_id,
            q_storage_view.storage_name,
            COALESCE(q_storage_view.storage_size_gb, q_g_view.storage_size_gb) as storage_size_gb,
            COALESCE(q_storage_view.storage_size_gb_usage, q_g_view.storage_size_gb_usage) as storage_size_gb_usage
    FROM  quota_global_view q_g_view
    LEFT OUTER JOIN quota_storage_view q_storage_view ON q_g_view.quota_id = q_storage_view.quota_id
    AND  (v_storage_id = q_storage_view.storage_id OR v_storage_id IS NULL)
   WHERE q_g_view.quota_id = v_id) sub
   WHERE (v_allow_empty OR storage_size_gb IS NOT NULL);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetQuotaByAdElementId(v_ad_element_id UUID, v_storage_pool_id UUID, v_recursive BOOLEAN)
RETURNS SETOF quota_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT * FROM quota_view WHERE quota_view.quota_id IN
   (SELECT object_id
    FROM PERMISSIONS
    WHERE object_type_id = 17
    AND role_id in (SELECT role_id FROM ROLES_groups where action_group_id = 901)
    AND ad_element_id = v_ad_element_id OR
        (v_recursive AND ad_element_id IN (SELECT * FROM getUserAndGroupsById(v_ad_element_id))))
    AND (v_storage_pool_id = quota_view.storage_pool_id or v_storage_pool_id IS NULL);
  END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION getAllThinQuota()
RETURNS SETOF quota_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM quota_view;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION getQuotaCount()
RETURNS SETOF BIGINT STABLE
   AS $procedure$
BEGIN
    RETURN QUERY SELECT count(*) as num_quota
    FROM quota;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetQuotaStorageByQuotaGuid(v_id UUID)
RETURNS SETOF quota_storage_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM  quota_storage_view
   WHERE quota_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetQuotaVdsGroupByVdsGroupGuid(v_vds_group_id UUID, v_id UUID, v_allow_empty BOOLEAN)
RETURNS SETOF quota_vds_group_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM (SELECT COALESCE(q_vds_view.quota_vds_group_id, q_g_view.quota_id) as quota_vds_group_id,
                q_g_view.quota_id as quota_id,
                q_vds_view.vds_group_id as vds_group_id,
                q_vds_view.vds_group_name as vds_group_name,
                COALESCE(q_vds_view.virtual_cpu,q_g_view.virtual_cpu) as virtual_cpu,
                COALESCE(q_vds_view.virtual_cpu_usage, q_g_view.virtual_cpu_usage) as virtual_cpu_usage,
                COALESCE(q_vds_view.mem_size_mb,q_g_view.mem_size_mb) as mem_size_mb,
                COALESCE(q_vds_view.mem_size_mb_usage, q_g_view.mem_size_mb_usage) as mem_size_mb_usage
         FROM   quota_global_view q_g_view
         LEFT OUTER JOIN quota_vds_group_view q_vds_view ON q_g_view.quota_id = q_vds_view.quota_id
         AND   (v_vds_group_id = q_vds_view.vds_group_id OR v_vds_group_id IS NULL)
         WHERE q_g_view.quota_id = v_id) sub
   WHERE v_allow_empty OR virtual_cpu IS NOT NULL OR mem_size_mb IS NOT NULL;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetQuotaVdsGroupByQuotaGuid(v_id UUID)
RETURNS SETOF quota_vds_group_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT quota_vds_group_view.*
   FROM  quota_vds_group_view
   WHERE quota_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteQuotaByQuotaGuid(v_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   DELETE FROM quota
   WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteQuotaLimitationByQuotaGuid(v_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   DELETE FROM quota_limitation
   WHERE quota_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateQuotaMetaData(v_id UUID, v_storage_pool_id UUID, v_quota_name VARCHAR(50), v_description VARCHAR(500), v_threshold_vds_group_percentage INTEGER, v_threshold_storage_percentage INTEGER, v_grace_vds_group_percentage INTEGER, v_grace_storage_percentage INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
UPDATE quota
   SET storage_pool_id = v_storage_pool_id,
   quota_name = v_quota_name,
   description = v_description,
   _update_date = LOCALTIMESTAMP,
   threshold_vds_group_percentage = v_threshold_vds_group_percentage,
   threshold_storage_percentage = v_threshold_storage_percentage,
   grace_vds_group_percentage = v_grace_vds_group_percentage,
   grace_storage_percentage = v_grace_storage_percentage
   WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetQuotaByStoragePoolGuid(v_storage_pool_id UUID)
RETURNS SETOF quota_global_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM  quota_global_view
   WHERE (storage_pool_id = v_storage_pool_id or v_storage_pool_id IS NULL);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetQuotaByQuotaGuid(v_id UUID)
RETURNS SETOF quota_global_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM quota_global_view
   WHERE quota_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetQuotaByQuotaName(v_quota_name VARCHAR)
RETURNS SETOF quota_global_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM quota_global_view
   WHERE quota_name = v_quota_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllThinQuotasByStorageId(v_storage_id UUID, v_user_id UUID, v_is_filtered boolean)
RETURNS SETOF quota_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT DISTINCT
    quota_id,
    storage_pool_id,
    storage_pool_name,
    quota_name,
    description,
    threshold_vds_group_percentage,
    threshold_storage_percentage,
    grace_vds_group_percentage,
    grace_storage_percentage,
    quota_enforcement_type
   FROM   quota_limitations_view
   WHERE  (storage_id = v_storage_id
   OR     (is_global AND
           NOT is_empty AND
           storage_size_gb IS NOT null AND
           storage_pool_id IN (SELECT storage_pool_id FROM storage_pool_iso_map
               WHERE  storage_id = v_storage_id)))
   AND (NOT v_is_filtered OR
          EXISTS (SELECT 1 FROM permissions p
                  JOIN user_flat_groups u ON
                  u.granted_id = p.ad_element_id WHERE
                  u.user_id = v_user_id AND
                  p.object_type_id = 17 AND -- quota object
                  p.role_id = 'def0000a-0000-0000-0000-def00000000a' AND -- consume quota
                  quota_id = p.object_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllThinQuotasByVDSGroupId(v_vds_group_id UUID, v_user_id UUID, v_is_filtered boolean)
RETURNS SETOF quota_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT DISTINCT
    quota_id,
    storage_pool_id,
    storage_pool_name,
    quota_name,
    description,
    threshold_vds_group_percentage,
    threshold_storage_percentage,
    grace_vds_group_percentage,
    grace_storage_percentage,
    quota_enforcement_type
   FROM   quota_limitations_view
   WHERE  (vds_group_id = v_vds_group_id
   OR     (is_global AND
           NOT is_empty AND
           virtual_cpu IS NOT null AND
           storage_pool_id IN (SELECT storage_pool_id FROM vds_groups
               WHERE  vds_group_id = v_vds_group_id)))
   AND (NOT v_is_filtered OR
          EXISTS (SELECT 1 FROM permissions p
                  JOIN user_flat_groups u ON
                  u.granted_id = p.ad_element_id WHERE
                  u.user_id = v_user_id AND
                  p.object_type_id = 17 AND -- quota object
                  p.role_id = 'def0000a-0000-0000-0000-def00000000a' AND -- consume quota
                  quota_id = p.object_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION IsQuotaInUse(v_quota_id UUID)
RETURNS boolean STABLE
    AS $BODY$
DECLARE
    result boolean := FALSE;
BEGIN
    if EXISTS (SELECT quota_id
                    FROM image_storage_domain_map
                    WHERE quota_id = v_quota_id
    UNION SELECT quota_id
              FROM vm_static
              WHERE quota_id = v_quota_id) then
        result := TRUE;
    END if;
    return result;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertRepo_domain_file_meta_data(v_repo_domain_id UUID,
    v_repo_image_id VARCHAR(256),
    v_repo_image_name VARCHAR(256),
    v_size BIGINT,
    v_date_created TIMESTAMP WITH TIME ZONE,
    v_last_refreshed BIGINT,
    v_file_type INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN

INSERT INTO repo_file_meta_data(repo_domain_id, repo_image_id, repo_image_name, size, date_created,
        last_refreshed, file_type)
    VALUES(v_repo_domain_id, v_repo_image_id, v_repo_image_name, v_size, v_date_created,
        v_last_refreshed, v_file_type);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteRepo_domain_file_list(v_storage_domain_id UUID, v_file_type INTEGER DEFAULT NULL)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM repo_file_meta_data
   WHERE repo_domain_id = v_storage_domain_id
     AND (v_file_type IS NULL OR file_type = v_file_type);

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetRepo_files_by_storage_domain(v_storage_domain_id UUID, v_file_type INTEGER DEFAULT NULL)
RETURNS SETOF repo_file_meta_data STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT repo_file_meta_data.*
   FROM repo_file_meta_data
   WHERE repo_domain_id = v_storage_domain_id
   AND (v_file_type IS NULL OR repo_file_meta_data.file_type = v_file_type)
   ORDER BY repo_file_meta_data.last_refreshed;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS GetRepo_files_in_all_storage_pools_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE GetRepo_files_in_all_storage_pools_rs AS(storage_domain_id UUID, last_refreshed BIGINT, file_type INTEGER);
**************************

CREATE TYPE
********* QUERY **********
Create or replace FUNCTION GetRepo_files_in_all_storage_pools(v_storage_domain_type INTEGER, v_storage_pool_status INTEGER,
   v_vds_status INTEGER, v_storage_domain_status INTEGER)
RETURNS SETOF GetRepo_files_in_all_storage_pools_rs STABLE
   AS $procedure$
BEGIN
 RETURN QUERY SELECT distinct b.storage_domain_id,c.last_refreshed,b.file_type
   FROM storage_domain_file_repos b
   LEFT OUTER JOIN
   (SELECT storage_domain_id,file_type,min(last_refreshed) as last_refreshed
      FROM storage_domain_file_repos a
   	  Group by storage_domain_id,file_type) as c ON b.storage_domain_id = c.storage_domain_id
                                                 AND b.file_type = c.file_type
   WHERE b.storage_domain_type = v_storage_domain_type
     and b.storage_pool_status = v_storage_pool_status
     and b.storage_domain_status = v_storage_domain_status
	 and b.vds_status = v_vds_status;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertSnapshot(
    v_snapshot_id UUID,
    v_vm_id UUID,
    v_snapshot_type VARCHAR(32),
    v_status VARCHAR(32),
    v_description VARCHAR(4000),
    v_creation_date TIMESTAMP WITH TIME ZONE,
    v_app_list TEXT,
    v_vm_configuration TEXT,
    v_memory_volume VARCHAR(255))
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO snapshots(
        snapshot_id,
        status,
        vm_id,
        snapshot_type,
        description,
        creation_date,
        app_list,
        vm_configuration,
        memory_volume)
    VALUES(
        v_snapshot_id,
        v_status,
        v_vm_id,
        v_snapshot_type,
        v_description,
        v_creation_date,
        v_app_list,
        v_vm_configuration,
        v_memory_volume);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateSnapshot(
    v_snapshot_id UUID,
    v_vm_id UUID,
    v_snapshot_type VARCHAR(32),
    v_status VARCHAR(32),
    v_description VARCHAR(4000),
    v_creation_date TIMESTAMP WITH TIME ZONE,
    v_app_list TEXT,
    v_vm_configuration TEXT,
    v_memory_volume VARCHAR(255))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE snapshots
    SET    status = v_status,
           vm_id = v_vm_id,
           snapshot_type = v_snapshot_type,
           description = v_description,
           creation_date = v_creation_date,
           app_list = v_app_list,
           vm_configuration = v_vm_configuration,
           memory_volume = v_memory_volume,
           _update_date = NOW()
    WHERE  snapshot_id = v_snapshot_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateSnapshotStatus(
    v_snapshot_id UUID,
    v_status VARCHAR(32))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE snapshots
    SET    status = v_status
    WHERE  snapshot_id = v_snapshot_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateSnapshotId(
    v_snapshot_id UUID,
    v_new_snapshot_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE snapshots
    SET    snapshot_id = v_new_snapshot_id
    WHERE  snapshot_id = v_snapshot_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteSnapshot(v_snapshot_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE
    FROM   snapshots
    WHERE  snapshot_id = v_snapshot_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromSnapshots() RETURNS SETOF snapshots STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   snapshots;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllSnapshotsByStorageDomainId(v_storage_id UUID) RETURNS SETOF snapshots STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT  snapshots.*
    FROM    snapshots
    JOIN    images ON snapshots.snapshot_id = images.vm_snapshot_id
    JOIN    image_storage_domain_map ON image_storage_domain_map.storage_domain_id = v_storage_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotByVmIdAndType(
    v_vm_id UUID,
    v_snapshot_type VARCHAR(32),
    v_user_id UUID,
    v_is_filtered BOOLEAN)
RETURNS SETOF snapshots STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   snapshots
    WHERE  vm_id = v_vm_id
    AND    snapshot_type = v_snapshot_type
    AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                      FROM   user_vm_permissions_view
                                      WHERE  user_id = v_user_id AND entity_id = v_vm_id))

    ORDER BY creation_date ASC
    LIMIT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotByVmIdAndTypeAndStatus(
    v_vm_id UUID,
    v_snapshot_type VARCHAR(32),
    v_status VARCHAR(32))
RETURNS SETOF snapshots STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   snapshots
    WHERE  vm_id = v_vm_id
    AND    snapshot_type = v_snapshot_type
    AND    status = v_status
    ORDER BY creation_date ASC
    LIMIT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotByVmIdAndStatus(
    v_vm_id UUID,
    v_status VARCHAR(32))
RETURNS SETOF snapshots STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   snapshots
    WHERE  vm_id = v_vm_id
    AND    status = v_status
    ORDER BY creation_date ASC
    LIMIT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS GetAllFromSnapshotsByVmId_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE GetAllFromSnapshotsByVmId_rs AS (snapshot_id UUID, vm_id UUID, snapshot_type VARCHAR(32), status VARCHAR(32), description VARCHAR(4000), creation_date TIMESTAMP WITH TIME ZONE, app_list TEXT, memory_volume VARCHAR(255), vm_configuration TEXT, vm_configuration_available BOOLEAN);
**************************

CREATE TYPE
********* QUERY **********
Create or replace FUNCTION GetAllFromSnapshotsByVmId(
    v_vm_id UUID,
    v_user_id UUID,
    v_is_filtered BOOLEAN,
    v_fill_configuration BOOLEAN) RETURNS SETOF GetAllFromSnapshotsByVmId_rs STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT snapshot_id,
           vm_id,
           snapshot_type,
           status,
           description,
           creation_date,
           app_list,
           memory_volume,
           CASE WHEN v_fill_configuration = TRUE THEN vm_configuration ELSE NULL END,
           vm_configuration IS NOT NULL AND LENGTH(vm_configuration) > 0
    FROM   snapshots
    WHERE  vm_id = v_vm_id
    AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                      FROM   user_vm_permissions_view
                                      WHERE  user_id = v_user_id AND entity_id = v_vm_id))
    ORDER BY creation_date ASC;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotBySnapshotId(v_snapshot_id UUID, v_user_id UUID, v_is_filtered BOOLEAN)
RETURNS SETOF snapshots STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   snapshots
    WHERE  snapshot_id = v_snapshot_id AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = (SELECT vm_id
                                        FROM snapshots where snapshot_id = v_snapshot_id)));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotIdsByVmIdAndType(
    v_vm_id UUID,
    v_snapshot_type VARCHAR(32))
RETURNS SETOF idUuidType STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT snapshot_id
    FROM   snapshots
    WHERE  vm_id = v_vm_id
    AND    snapshot_type = v_snapshot_type
    ORDER BY creation_date ASC;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetSnapshotIdsByVmIdAndTypeAndStatus(
    v_vm_id UUID,
    v_snapshot_type VARCHAR(32),
    v_status VARCHAR(32))
RETURNS SETOF idUuidType STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT snapshot_id
    FROM   snapshots
    WHERE  vm_id = v_vm_id
    AND    snapshot_type = v_snapshot_type
    AND    status = v_status
    ORDER BY creation_date ASC;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION CheckIfSnapshotExistsByVmIdAndType(
    v_vm_id UUID,
    v_snapshot_type VARCHAR(32))
RETURNS SETOF booleanResultType STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT EXISTS(
        SELECT *
        FROM   snapshots
        WHERE  vm_id = v_vm_id
        AND    snapshot_type = v_snapshot_type);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION CheckIfSnapshotExistsByVmIdAndStatus(
    v_vm_id UUID,
    v_status VARCHAR(32))
RETURNS SETOF booleanResultType STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT EXISTS(
        SELECT *
        FROM   snapshots
        WHERE  vm_id = v_vm_id
        AND    status = v_status);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION CheckIfSnapshotExistsByVmIdAndSnapshotId(
    v_vm_id UUID,
    v_snapshot_id UUID)
RETURNS SETOF booleanResultType STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT EXISTS(
        SELECT *
        FROM   snapshots
        WHERE  vm_id = v_vm_id
        AND    snapshot_id = v_snapshot_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNumOfSnapshotsByMemoryVolume(
    v_memory_volume VARCHAR(255))
RETURNS SETOF BIGINT STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT COUNT(*)
    FROM   snapshots
    WHERE  memory_volume = v_memory_volume;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION RemoveMemoryFromSnapshotByVmIdAndType(
    v_vm_id UUID,
    v_snapshot_type VARCHAR(32))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE snapshots
    SET    memory_volume = NULL
    WHERE  vm_id = v_vm_id
    AND    snapshot_type = v_snapshot_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION RemoveMemoryFromSnapshotBySnapshotId(
    v_snapshot_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE snapshots
    SET    memory_volume = NULL
    WHERE  snapshot_id = v_snapshot_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertLUNs(v_LUN_id VARCHAR(50),
	v_physical_volume_id VARCHAR(50) ,
	v_volume_group_id VARCHAR(50) ,
	v_serial VARCHAR(4000) ,
	v_lun_mapping INTEGER ,
	v_vendor_id VARCHAR(50) ,
	v_product_id VARCHAR(50) ,
	v_device_size INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO LUNs(LUN_id, physical_volume_id, volume_group_id, serial, lun_mapping, vendor_id, product_id, device_size)
	VALUES(v_LUN_id, v_physical_volume_id, v_volume_group_id, v_serial, v_lun_mapping, v_vendor_id, v_product_id, v_device_size);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateLUNs(v_LUN_id VARCHAR(50),
    v_physical_volume_id VARCHAR(50) ,
    v_volume_group_id VARCHAR(50) ,
    v_serial VARCHAR(4000) ,
    v_lun_mapping INTEGER ,
    v_vendor_id VARCHAR(50) ,
    v_product_id VARCHAR(50) ,
    v_device_size INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE LUNs
      SET LUN_id = v_LUN_id, physical_volume_id = v_physical_volume_id, volume_group_id = v_volume_group_id,
          serial = v_serial, lun_mapping = v_lun_mapping, vendor_id = v_vendor_id,
          product_id = v_product_id, device_size = v_device_size
      WHERE LUN_id = v_LUN_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteLUN(v_LUN_id VARCHAR(50))
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  VARCHAR(50);
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   LUN_id INTO v_val FROM LUNs  WHERE LUN_id = v_LUN_id     FOR UPDATE;

   DELETE FROM LUNs
   WHERE LUN_id = v_LUN_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromLUNs() RETURNS SETOF luns_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM luns_view;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetLUNsBystorage_server_connection(v_storage_server_connection VARCHAR(50)) RETURNS SETOF luns_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT luns_view.*
   FROM luns_view INNER JOIN
   LUN_storage_server_connection_map
   ON LUN_storage_server_connection_map.LUN_id = luns_view.LUN_id
   WHERE LUN_storage_server_connection_map.storage_server_connection = v_storage_server_connection;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetLUNsByVolumeGroupId(v_volume_group_id VARCHAR(50))
RETURNS SETOF luns_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM luns_view
   WHERE volume_group_id = v_volume_group_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetLUNByLUNId(v_LUN_id VARCHAR(50))
RETURNS SETOF luns_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM luns_view
   WHERE LUN_id = v_LUN_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertstorage_domain_dynamic(v_available_disk_size INTEGER ,
	v_id UUID,
	v_used_disk_size INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO storage_domain_dynamic(available_disk_size, id, used_disk_size)
	VALUES(v_available_disk_size, v_id, v_used_disk_size);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatestorage_domain_dynamic(v_available_disk_size INTEGER ,
	v_id UUID,
	v_used_disk_size INTEGER)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE storage_domain_dynamic
      SET available_disk_size = v_available_disk_size,used_disk_size = v_used_disk_size, _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletestorage_domain_dynamic(v_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM storage_domain_dynamic
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromstorage_domain_dynamic() RETURNS SETOF storage_domain_dynamic STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_dynamic;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domain_dynamicByid(v_id UUID)
RETURNS SETOF storage_domain_dynamic STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_dynamic
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertstorage_pool_iso_map(v_storage_id UUID,
	v_storage_pool_id UUID,
	v_status INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO storage_pool_iso_map(storage_id, storage_pool_id, status)
	VALUES(v_storage_id, v_storage_pool_id, v_status);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletestorage_pool_iso_map(v_storage_id UUID,
	v_storage_pool_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM storage_pool_iso_map
   WHERE storage_id = v_storage_id AND storage_pool_id = v_storage_pool_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromstorage_pool_iso_map() RETURNS SETOF storage_pool_iso_map STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool_iso_map;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_pool_iso_mapBystorage_idAndBystorage_pool_id(v_storage_id UUID,v_storage_pool_id UUID) RETURNS SETOF storage_pool_iso_map STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool_iso_map
   WHERE storage_id = v_storage_id AND storage_pool_id = v_storage_pool_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_pool_iso_mapsBystorage_id(v_storage_id UUID)
RETURNS SETOF storage_pool_iso_map STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool_iso_map
   WHERE storage_id = v_storage_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_pool_iso_mapsByBystorage_pool_id(v_storage_id UUID,
	v_storage_pool_id UUID) RETURNS SETOF storage_pool_iso_map STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool_iso_map
   WHERE storage_pool_id = v_storage_pool_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatestorage_pool_iso_map_status(v_storage_id UUID,
        v_storage_pool_id UUID,
        v_status INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
   UPDATE storage_pool_iso_map
   SET status = v_status
   WHERE storage_pool_id = v_storage_pool_id AND storage_id = v_storage_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertstorage_server_connections(v_connection VARCHAR(250),
	v_id VARCHAR(50),
	v_iqn VARCHAR(128) ,
	v_port VARCHAR(50) ,
	v_portal VARCHAR(50) ,
	v_password text,
	v_storage_type INTEGER,
	v_user_name VARCHAR(50),
	v_mount_options VARCHAR(500),
	v_vfs_type VARCHAR(128),
	v_nfs_version VARCHAR(4),
	v_nfs_timeo smallint,
	v_nfs_retrans smallint)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO storage_server_connections(connection, id, iqn, port,portal,
	password, storage_type, user_name,mount_options,vfs_type,nfs_version,nfs_timeo,nfs_retrans)
	VALUES(v_connection, v_id, v_iqn,v_port,v_portal, v_password, v_storage_type, v_user_name,v_mount_options,v_vfs_type,v_nfs_version,v_nfs_timeo,v_nfs_retrans);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatestorage_server_connections(v_connection VARCHAR(250),
	v_id VARCHAR(50),
	v_iqn VARCHAR(128) ,
	v_password text,
	v_storage_type INTEGER,
	v_port VARCHAR(50) ,
	v_portal VARCHAR(50) ,
	v_user_name VARCHAR(50),
	v_mount_options VARCHAR(500),
	v_vfs_type VARCHAR(128),
	v_nfs_version VARCHAR(4),
	v_nfs_timeo smallint,
	v_nfs_retrans smallint)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE storage_server_connections
      SET connection = v_connection,iqn = v_iqn,password = v_password,port = v_port,
      portal = v_portal,storage_type = v_storage_type,user_name = v_user_name,mount_options = v_mount_options, vfs_type = v_vfs_type, nfs_version = v_nfs_version, nfs_timeo = v_nfs_timeo, nfs_retrans = v_nfs_retrans
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletestorage_server_connections(v_id VARCHAR(50))
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  VARCHAR(50);
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM storage_server_connections  WHERE id = v_id     FOR UPDATE;

   DELETE FROM storage_server_connections
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_server_connectionsByid(v_id VARCHAR(50))
RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_server_connectionsByConnection(v_connection VARCHAR(250))
RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE connection = v_connection;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_server_connectionsByIqn(v_iqn VARCHAR(128))
RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE iqn = v_iqn;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_server_connectionsByIqnAndConnection(v_iqn VARCHAR(128) ,
	v_connection VARCHAR(250)) RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE iqn = v_iqn and (connection = v_connection or connection is NULL);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_server_connectionsByKey(v_iqn VARCHAR(128) ,
	v_connection VARCHAR(250),
	v_port VARCHAR(50) ,
	v_portal VARCHAR(50) ,
	v_username VARCHAR(50) ,
	v_password text) RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE (iqn = v_iqn or iqn is NULL) and
			(connection = v_connection) and
			(port = v_port or port is NULL) and
			(portal = v_portal or portal is NULL) and
			(user_name = v_username or user_name is NULL) and
			(password = v_password or password is NULL);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_server_connectionsByStorageType(v_storage_type INTEGER)
RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections
   WHERE storage_type = v_storage_type;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllstorage_server_connections()
RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetStorageServerConnectionsByIds(v_ids TEXT)
RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_server_connections WHERE id = any(string_to_array(v_ids,',')::VARCHAR[]);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_server_connectionsByVolumeGroupId(v_volume_group_id VARCHAR(50)) RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT DISTINCT storage_server_connections.*
   FROM
   LUN_storage_server_connection_map  LUN_storage_server_connection_map
   INNER JOIN
   LUNs ON LUN_storage_server_connection_map.LUN_id = LUNs.LUN_id INNER JOIN
   storage_domain_static ON LUNs.volume_group_id = storage_domain_static.storage INNER JOIN
   storage_server_connections ON
   LUN_storage_server_connection_map.storage_server_connection = storage_server_connections.id
   WHERE     (storage_domain_static.storage = v_volume_group_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetStorageConnectionsByStorageTypeAndStatus(v_storage_pool_id UUID, v_storage_type integer, v_statuses varchar(20))
RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
DECLARE
  statuses int[];
BEGIN
statuses := string_to_array(v_statuses,',')::integer[];
RETURN QUERY SELECT * FROM (SELECT distinct storage_server_connections.*
   FROM
   LUN_storage_server_connection_map LUN_storage_server_connection_map
   INNER JOIN  LUNs ON LUN_storage_server_connection_map.LUN_id = LUNs.LUN_id
   INNER JOIN  storage_domains ON LUNs.volume_group_id = storage_domains.storage
   INNER JOIN  storage_server_connections ON LUN_storage_server_connection_map.storage_server_connection = storage_server_connections.id
   WHERE     (storage_domains.storage_pool_id = v_storage_pool_id  and storage_domains.status = any(statuses))
   UNION
   SELECT distinct storage_server_connections.*
   FROM         storage_server_connections
   INNER JOIN  storage_domains ON storage_server_connections.id = storage_domains.storage
   WHERE     (storage_domains.storage_pool_id = v_storage_pool_id and storage_domains.status = any(statuses))
   ) connections WHERE (v_storage_type is NULL or connections.storage_type = v_storage_type);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNFSstorage_server_connectionsByStoragePoolId(v_storage_pool_id UUID)
RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT distinct storage_server_connections.*
   FROM    storage_server_connections storage_server_connections
   INNER JOIN
   storage_domain_static_view ON
   storage_server_connections.id = storage_domain_static_view.storage
   WHERE     (storage_domain_static_view.storage_pool_id = v_storage_pool_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_server_connectionsByLunId(v_lunId VARCHAR(50))
RETURNS SETOF storage_server_connections STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT storage_server_connections.*
   FROM  storage_server_connections storage_server_connections
   INNER JOIN lun_storage_server_connection_map ON
   lun_storage_server_connection_map.storage_server_connection = storage_server_connections.id
   WHERE     (lun_storage_server_connection_map.lun_id = v_lunId);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertLUN_storage_server_connection_map(v_LUN_id VARCHAR(50),
	v_storage_server_connection VARCHAR(50))
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO LUN_storage_server_connection_map(LUN_id, storage_server_connection)
	VALUES(v_LUN_id, v_storage_server_connection);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateLUN_storage_server_connection_map(v_LUN_id VARCHAR(50),
	v_storage_server_connection VARCHAR(50))
RETURNS VOID
	
   AS $procedure$
BEGIN
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteLUN_storage_server_connection_map(v_LUN_id VARCHAR(50),
	v_storage_server_connection VARCHAR(50))
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM LUN_storage_server_connection_map
   WHERE LUN_id = v_LUN_id AND storage_server_connection = v_storage_server_connection;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromLUN_storage_server_connection_map()
RETURNS SETOF LUN_storage_server_connection_map STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM LUN_storage_server_connection_map lUN_storage_server_connection_map;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetLUN_storage_server_connection_mapByLUNBystorage_server_conn(v_LUN_id VARCHAR(50),v_storage_server_connection VARCHAR(50)) RETURNS SETOF LUN_storage_server_connection_map STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT *
   FROM LUN_storage_server_connection_map lUN_storage_server_connection_map
   WHERE LUN_id = v_LUN_id AND storage_server_connection = v_storage_server_connection;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertstorage_pool(v_description VARCHAR(4000),
	v_free_text_comment text,
	v_id UUID,
	v_name VARCHAR(40),
	v_status INTEGER,
	v_is_local BOOLEAN,
	v_master_domain_version INTEGER,
	v_spm_vds_id UUID ,
	v_compatibility_version VARCHAR(40),
	v_quota_enforcement_type INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO storage_pool(description, free_text_comment, id, name, status, is_local, master_domain_version,spm_vds_id,compatibility_version,quota_enforcement_type)
	VALUES(v_description, v_free_text_comment, v_id, v_name, v_status, v_is_local, v_master_domain_version,v_spm_vds_id,v_compatibility_version,v_quota_enforcement_type);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatestorage_pool(v_description VARCHAR(4000),
	v_free_text_comment text,
	v_id UUID,
	v_name VARCHAR(40),
	v_status INTEGER,
        v_is_local BOOLEAN,
        v_storage_pool_format_type VARCHAR(50),
	v_master_domain_version INTEGER,
	v_spm_vds_id UUID ,
	v_compatibility_version VARCHAR(40),
	v_quota_enforcement_type INTEGER)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE storage_pool
      SET description = v_description, free_text_comment = v_free_text_comment,  name = v_name, is_local = v_is_local,
      status = v_status,storage_pool_format_type = v_storage_pool_format_type,master_domain_version = v_master_domain_version,
      spm_vds_id = v_spm_vds_id,compatibility_version = v_compatibility_version,
      _update_date = LOCALTIMESTAMP,quota_enforcement_type=v_quota_enforcement_type
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatestorage_pool_partial(v_description VARCHAR(4000),
	v_free_text_comment text,
	v_id UUID,
	v_name VARCHAR(40),
	v_is_local BOOLEAN,
	v_storage_pool_format_type VARCHAR(50),
	v_compatibility_version VARCHAR(40),
	v_quota_enforcement_type INTEGER)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE storage_pool
      SET description = v_description, free_text_comment = v_free_text_comment, name = v_name, is_local = v_is_local,
      storage_pool_format_type = v_storage_pool_format_type,compatibility_version = v_compatibility_version,
      _update_date = LOCALTIMESTAMP,quota_enforcement_type = v_quota_enforcement_type
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatestorage_pool_status(
        v_id UUID,
        v_status INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE storage_pool
      SET
      status = v_status,
      _update_date = LOCALTIMESTAMP
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION IncreaseStoragePoolMasterVersion(
        v_id UUID)
RETURNS INTEGER
   AS $procedure$
DECLARE v_master_domain_version INTEGER;
BEGIN
      UPDATE storage_pool
      SET
      master_domain_version = master_domain_version + 1
      WHERE id = v_id
      RETURNING master_domain_version into v_master_domain_version;

      RETURN v_master_domain_version;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletestorage_pool(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN

         -- Get (and keep) a shared lock with "right to upgrade to exclusive"
    select vm_guid INTO v_val FROM vm_static where vm_guid in (select vm_guid from vms where storage_pool_id = v_id) FOR UPDATE;
    DELETE
    FROM   snapshots
    WHERE  vm_id IN (
        SELECT vm_guid
        FROM   vms
        WHERE  storage_pool_id = v_id);
    delete FROM vm_static where vm_guid in (select vm_guid from vms where storage_pool_id = v_id);

    -- Delete vm pools as empty pools are not supported
    -- Get (and keep) a shared lock with "right to upgrade to exclusive"
    select vm_pool_id INTO v_val FROM vm_pools where vm_pool_id in (select vm_pool_id from vm_pools_view where storage_pool_id = v_id) FOR UPDATE;
    DELETE
    FROM   vm_pools
    WHERE  vm_pool_id IN (
        SELECT vm_pool_id
        FROM   vm_pools_view
        WHERE  storage_pool_id = v_id);

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM storage_pool  WHERE id = v_id     FOR UPDATE;

   DELETE FROM storage_pool
   WHERE id = v_id;

	-- delete StoragePool permissions --
   DELETE FROM permissions where object_id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromstorage_pool(v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF storage_pool STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_storage_pool_permissions_view
                                       WHERE  user_id = v_user_id AND entity_id = id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllByStatus(v_status INTEGER) RETURNS SETOF storage_pool STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE status = v_status;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_poolByid(v_id UUID, v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF storage_pool STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE id = v_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_storage_pool_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = v_id));



END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_poolByName(v_name VARCHAR(40), v_is_case_sensitive BOOLEAN)
RETURNS SETOF storage_pool STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE name = v_name OR (NOT v_is_case_sensitive AND name ilike v_name);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_poolsByStorageDomainId(v_storage_domain_id UUID)
RETURNS SETOF storage_pool STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT storage_pool.*
   FROM storage_pool
   inner join storage_pool_iso_map on storage_pool.id = storage_pool_iso_map.storage_pool_id
   WHERE storage_pool_iso_map.storage_id = v_storage_domain_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmAndTemplatesIdsByStorageDomainId(v_storage_domain_id UUID, v_include_shareable BOOLEAN, v_active_only BOOLEAN)
RETURNS SETOF UUID STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT vd.vm_id
      FROM vm_device vd
      INNER JOIN images_storage_domain_view i ON i.image_group_id = vd.device_id
      WHERE i.storage_id = v_storage_domain_id AND i.active = v_active_only AND i.shareable = v_include_shareable;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_poolsByVdsId(v_vdsId UUID)
RETURNS SETOF storage_pool STABLE
   AS $procedure$
   DECLARE
   v_clusterId  UUID;
BEGIN
select   vds_group_id INTO v_clusterId FROM Vds_static WHERE vds_id = v_vdsId;
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE storage_pool.id in(select storage_pool_id
      FROM vds_groups
      WHERE vds_group_id = v_clusterId);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_poolsByVdsGroupId(v_clusterId UUID)
RETURNS SETOF storage_pool STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_pool
   WHERE storage_pool.id in(select storage_pool_id
      FROM vds_groups
      WHERE vds_group_id = v_clusterId);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION LoadStorageDomainInfoByDomainId(v_storage_domain_id UUID) RETURNS SETOF storage_domains_ovf_info STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM storage_domains_ovf_info ovf
   WHERE ovf.storage_domain_id = v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION LoadStorageDomainInfoByDiskId(v_disk_id UUID) RETURNS SETOF storage_domains_ovf_info STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM storage_domains_ovf_info ovf
   WHERE ovf.ovf_disk_id = v_disk_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertStorageDomainOvfInfo(v_storage_domain_id UUID, v_status INTEGER, v_ovf_disk_id UUID,
v_stored_ovfs_ids TEXT) RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO storage_domains_ovf_info (storage_domain_id, status, ovf_disk_id, stored_ovfs_ids)
VALUES(v_storage_domain_id, v_status, v_ovf_disk_id, v_stored_ovfs_ids);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION LoadStorageDomainsForOvfIds(v_ovfs_ids TEXT) RETURNS SETOF UUID
   AS $procedure$
BEGIN
RETURN QUERY SELECT ovf.storage_domain_id
   FROM storage_domains_ovf_info ovf
   WHERE string_to_array(ovf.stored_ovfs_ids,',') && string_to_array(v_ovfs_ids,',');
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateStorageDomainOvfInfo(v_storage_domain_id UUID, v_status INTEGER, v_ovf_disk_id UUID,
v_stored_ovfs_ids TEXT, v_last_updated TIMESTAMP WITH TIME ZONE) RETURNS VOID
   AS $procedure$
BEGIN
UPDATE storage_domains_ovf_info SET status = v_status, storage_domain_id = v_storage_domain_id,
ovf_disk_id = v_ovf_disk_id, stored_ovfs_ids = v_stored_ovfs_ids, last_updated = v_last_updated
WHERE ovf_disk_id = v_ovf_disk_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteStorageDomainOvfInfo(v_ovf_disk_id UUID) RETURNS VOID
   AS $procedure$
BEGIN
DELETE FROM storage_domains_ovf_info WHERE ovf_disk_id = v_ovf_disk_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateOvfUpdatedInfo(v_storage_domains_ids VARCHAR(5000), v_status INTEGER, v_except_status INTEGER)
    RETURNS VOID
    AS $procedure$
DECLARE
curs_storages_ids CURSOR FOR SELECT * FROM fnSplitterUuid(v_storage_domains_ids);
id UUID;
BEGIN
 OPEN curs_storages_ids;
LOOP
    FETCH curs_storages_ids INTO id;
    IF NOT FOUND THEN
     EXIT;
    END IF;
    UPDATE storage_domains_ovf_info
    SET status = v_status WHERE storage_domain_id = id AND status != v_except_status;
END LOOP;
CLOSE curs_storages_ids;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertstorage_domain_static(v_id UUID,
	v_storage VARCHAR(250),
	v_storage_name VARCHAR(250),
        v_storage_description VARCHAR(4000),
	v_storage_comment text,
	v_storage_type INTEGER,
	v_storage_domain_type INTEGER,
    v_storage_domain_format_type VARCHAR(50),
    v_last_time_used_as_master BIGINT)
RETURNS VOID
   AS $procedure$
   BEGIN
INSERT INTO storage_domain_static(id, storage,storage_name, storage_description, storage_comment, storage_type, storage_domain_type, storage_domain_format_type, last_time_used_as_master)
	VALUES(v_id, v_storage, v_storage_name, v_storage_description, v_storage_comment, v_storage_type, v_storage_domain_type, v_storage_domain_format_type, v_last_time_used_as_master);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domains_List_By_ImageId(v_image_id UUID) RETURNS SETOF storage_domains STABLE
   AS $procedure$
BEGIN
    RETURN QUERY SELECT *
    FROM storage_domains
    WHERE id in (SELECT storage_domain_id
                 FROM image_storage_domain_map
                 WHERE image_id = v_image_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatestorage_domain_static(v_id UUID,
	v_storage VARCHAR(250),
	v_storage_name VARCHAR(250),
	v_storage_description VARCHAR(4000),
	v_storage_comment text,
	v_storage_type INTEGER,
	v_storage_domain_type INTEGER,
	v_storage_domain_format_type INTEGER,
	v_last_time_used_as_master BIGINT)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE storage_domain_static
      SET storage = v_storage, storage_name = v_storage_name, storage_type = v_storage_type,
      storage_domain_type = v_storage_domain_type, _update_date = LOCALTIMESTAMP,
      storage_domain_format_type = v_storage_domain_format_type,
      last_time_used_as_master = v_last_time_used_as_master,
      storage_description = v_storage_description, storage_comment = v_storage_comment
      WHERE id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletestorage_domain_static(v_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN

	-- Get (and keep) a shared lock with "right to upgrade to exclusive"
	-- in order to force locking parent before children
   select   id INTO v_val FROM storage_domain_static  WHERE id = v_id     FOR UPDATE;

   DELETE FROM storage_domain_static
   WHERE id = v_id;

	-- delete Storage permissions --
   DELETE FROM permissions where object_id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromstorage_domain_static() RETURNS SETOF storage_domain_static STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_static;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domain_staticByid(v_id UUID)
RETURNS SETOF storage_domain_static STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_static
   WHERE id = v_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domain_staticByName(v_name VARCHAR(250))
RETURNS SETOF storage_domain_static STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_static
   WHERE storage_name = v_name;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domain_staticByNameFiltered(v_name VARCHAR(250), v_user_id UUID, v_is_filtered BOOLEAN)
RETURNS SETOF storage_domain_static STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_static sds
   WHERE storage_name = v_name  AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_storage_domain_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = sds.id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domain_staticBystorage_pool_id(v_storage_pool_id UUID)
RETURNS SETOF storage_domain_static_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domain_static_view
   WHERE storage_pool_id = v_storage_pool_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS GetStorageDomainIdsByStoragePoolIdAndStatus_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE GetStorageDomainIdsByStoragePoolIdAndStatus_rs AS (storage_id UUID);
**************************

CREATE TYPE
********* QUERY **********
Create or replace FUNCTION GetStorageDomainIdsByStoragePoolIdAndStatus(v_storage_pool_id UUID, v_status INTEGER)
RETURNS SETOF GetStorageDomainIdsByStoragePoolIdAndStatus_rs STABLE
   AS $procedure$
BEGIN
   RETURN QUERY
   SELECT storage_id
   FROM   storage_pool_iso_map
   WHERE  storage_pool_id = v_storage_pool_id
   AND    status = v_status;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domains_By_id(v_id UUID, v_user_id UUID, v_is_filtered BOOLEAN)
RETURNS SETOF storage_domains_without_storage_pools STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains_without_storage_pools
   WHERE id = v_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_storage_domain_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = v_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domains_by_storage_pool_id_with_permitted_action (v_user_id UUID, v_action_group_id integer, v_storage_pool_id UUID)
RETURNS SETOF storage_domains STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage_pool_id = v_storage_pool_id
   AND (SELECT get_entity_permissions(v_user_id, v_action_group_id, id, 11)) IS NOT NULL;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domains_By_id_and_by_storage_pool_id(v_id UUID,
	v_storage_pool_id UUID ) RETURNS SETOF storage_domains STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE id = v_id and storage_pool_id = v_storage_pool_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domains_By_storagePoolId(v_storage_pool_id UUID, v_user_id UUID, v_is_filtered BOOLEAN)
RETURNS SETOF storage_domains STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage_pool_id = v_storage_pool_id
   AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                     FROM   user_storage_domain_permissions_view
                                     WHERE  user_id = v_user_id AND entity_id = id));



END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domain_by_type_and_storagePoolId(v_storage_domain_type INTEGER, v_storage_pool_id UUID)
RETURNS SETOF storage_domains STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage_pool_id = v_storage_pool_id
   AND storage_domain_type = v_storage_domain_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domains_By_connection(v_connection CHARACTER VARYING)
RETURNS SETOF storage_domains STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage IN (
      SELECT id
      FROM storage_server_connections
      WHERE connection = v_connection);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromStorageDomainsByConnectionId(v_connection_id CHARACTER VARYING)
RETURNS SETOF storage_domains STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage = v_connection_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromstorage_domains(v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF storage_domains STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM user_storage_domain_permissions_view
                                       WHERE user_id = v_user_id AND entity_id = id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Remove_Entities_From_storage_domain(v_storage_domain_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   BEGIN
      -- Creating a temporary table which will give all the images and the disks which resids on only the specified storage domain. (copied template disks on multiple storage domains will not be part of this table)
      CREATE TEMPORARY TABLE STORAGE_DOMAIN_MAP_TABLE AS select image_guid as image_id,disk_id
         from images_storage_domain_view where storage_id = v_storage_domain_id
         except select image_guid as image_id, disk_id from images_storage_domain_view where storage_id != v_storage_domain_id;
      exception when others then
         truncate table STORAGE_DOMAIN_MAP_TABLE;
         insert into STORAGE_DOMAIN_MAP_TABLE select image_guid as image_id,disk_id
         from images_storage_domain_view where storage_id = v_storage_domain_id
         except select image_guid as image_id, disk_id from images_storage_domain_view where storage_id != v_storage_domain_id;
   END;

   BEGIN
      -- All the VMs/Templates which have disks both on the specified domain and other domains.
      CREATE TEMPORARY TABLE ENTITY_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE AS
      SELECT DISTINCT vm_static.vm_guid
      FROM vm_static
      INNER JOIN (-- Join vm_static only with VMs and Templates that have images on the storage domain v_storage_domain_id
                  SELECT vm_static.vm_guid
                  FROM vm_static
                  INNER JOIN vm_device vd ON vd.vm_id = vm_static.vm_guid
                  INNER JOIN images i ON i.image_group_id = vd.device_id
                  INNER JOIN STORAGE_DOMAIN_MAP_TABLE ON i.image_guid = STORAGE_DOMAIN_MAP_TABLE.image_id) vm_guids_with_disks_on_storage_domain ON vm_static.vm_guid = vm_guids_with_disks_on_storage_domain.vm_guid
      -- With all the VMs which have images on the storage domain, get all of their images and check if there is an image on another storage domain.
      INNER JOIN vm_device vd ON vd.vm_id = vm_static.vm_guid
      INNER JOIN images i ON i.image_group_id = vd.device_id
      INNER JOIN image_storage_domain_map on i.image_guid = image_storage_domain_map.image_id
      WHERE image_storage_domain_map.storage_domain_id != v_storage_domain_id;
	  exception when others then
         truncate table ENTITY_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE;
         INSERT INTO ENTITY_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE
         SELECT DISTINCT vm_static.vm_guid
         FROM vm_static
         INNER JOIN (SELECT vm_static.vm_guid
                     FROM vm_static
                     INNER JOIN vm_device vd ON vd.vm_id = vm_static.vm_guid
                     INNER JOIN images i ON i.image_group_id = vd.device_id
                     INNER JOIN STORAGE_DOMAIN_MAP_TABLE ON i.image_guid = STORAGE_DOMAIN_MAP_TABLE.image_id) vm_guids_with_disks_on_storage_domain ON vm_static.vm_guid = vm_guids_with_disks_on_storage_domain.vm_guid
         INNER JOIN vm_device vd ON vd.vm_id = vm_static.vm_guid
         INNER JOIN images i ON i.image_group_id = vd.device_id
         INNER JOIN image_storage_domain_map on i.image_guid = image_storage_domain_map.image_id
         WHERE image_storage_domain_map.storage_domain_id != v_storage_domain_id;
   END;

   BEGIN
      -- Templates with any images residing on only the specified storage domain
      CREATE TEMPORARY TABLE TEMPLATES_IDS_TEMPORARY_TABLE AS select vm_device.vm_id as vm_guid
         from images_storage_domain_view
         JOIN vm_device ON vm_device.device_id = images_storage_domain_view.disk_id
         JOIN STORAGE_DOMAIN_MAP_TABLE ON STORAGE_DOMAIN_MAP_TABLE.image_id = images_storage_domain_view.image_guid
         where entity_type = 'TEMPLATE' and storage_id = v_storage_domain_id
           AND vm_device.vm_id not in (SELECT vm_guid from ENTITY_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE);
      exception when others then
         truncate table TEMPLATES_IDS_TEMPORARY_TABLE;
         insert into TEMPLATES_IDS_TEMPORARY_TABLE select vm_device.vm_id as vm_guid
         from images_storage_domain_view
         JOIN vm_device ON vm_device.device_id = images_storage_domain_view.disk_id
         JOIN STORAGE_DOMAIN_MAP_TABLE ON STORAGE_DOMAIN_MAP_TABLE.image_id = images_storage_domain_view.image_guid
         where entity_type = 'TEMPLATE' and storage_id = v_storage_domain_id
           AND vm_device.vm_id not in (SELECT vm_guid from ENTITY_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE);
   END;

   -- Add also Template Versions based on the selected templates
   insert into TEMPLATES_IDS_TEMPORARY_TABLE
     select vm_guid from vm_static
     where vmt_guid in (select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE)
     and entity_type = 'TEMPLATE';

   BEGIN
     -- Vms which resides on the storage domain
     CREATE TEMPORARY TABLE VM_IDS_TEMPORARY_TABLE AS select vm_id,vm_images_view.entity_type as entity_type from vm_images_view
            JOIN vm_device ON vm_device.device_id = vm_images_view.disk_id
            WHERE v_storage_domain_id in (SELECT * FROM fnsplitteruuid(storage_id))
              AND vm_id not in (SELECT vm_guid from ENTITY_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE);
     exception when others then
     truncate table VM_IDS_TEMPORARY_TABLE;
     insert into VM_IDS_TEMPORARY_TABLE select vm_id,vm_images_view.entity_type as entity_type from vm_images_view
            JOIN vm_device ON vm_device.device_id = vm_images_view.disk_id
            WHERE v_storage_domain_id in (SELECT * FROM fnsplitteruuid(storage_id))
              AND vm_id not in (SELECT vm_guid from ENTITY_IDS_ON_OTHER_STORAGE_DOMAINS_TEMPORARY_TABLE);
   END;

   delete FROM permissions where object_id in (select vm_id as vm_guid from VM_IDS_TEMPORARY_TABLE where entity_type <> 'TEMPLATE');
   delete FROM snapshots WHERE vm_id in (select vm_id as vm_guid from VM_IDS_TEMPORARY_TABLE);

   delete FROM image_storage_domain_map where storage_domain_id = v_storage_domain_id;
   delete FROM images where image_guid in (select image_id from STORAGE_DOMAIN_MAP_TABLE);
   delete FROM vm_interface where vmt_guid in(select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE);
   delete FROM permissions where object_id in (select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE);
   delete FROM vm_static where vm_guid in(select vm_id as vm_guid from VM_IDS_TEMPORARY_TABLE where entity_type <> 'TEMPLATE');

   -- Delete devices which are related to VMs/Templates with Multiple Storage Domain (VMs/Templates which has not removed)
   delete FROM vm_device where device_id in (select disk_id from STORAGE_DOMAIN_MAP_TABLE);

   -- Delete pools and snapshots of pools based on templates from the storage domain to be removed
   delete FROM snapshots where vm_id in (select vm_guid FROM vm_static where vmt_guid in (select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE));
   delete FROM vm_static where vmt_guid in (select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE);
   delete FROM vm_static where vm_guid in(select vm_guid from TEMPLATES_IDS_TEMPORARY_TABLE);

   -- Deletes the disks which the only storage domain they are reside on, is the storage domain.
   DELETE FROM base_disks WHERE  disk_id IN (SELECT disk_id FROM STORAGE_DOMAIN_MAP_TABLE);

   -- Deletes the disks's permissions which the only storage domain they are reside on, is the storage domain.
   DELETE FROM permissions WHERE object_id IN (SELECT disk_id FROM STORAGE_DOMAIN_MAP_TABLE);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Force_Delete_storage_domain(v_storage_domain_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   PERFORM Remove_Entities_From_storage_domain(v_storage_domain_id);
   delete FROM permissions where object_id = v_storage_domain_id;
   delete FROM storage_domain_dynamic where id = v_storage_domain_id;
   delete FROM storage_domain_static where id = v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domains_List_By_storageDomainId(v_storage_domain_id UUID)
RETURNS SETOF storage_domains STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage_domains.id = v_storage_domain_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_perms_get_storage_pools_with_permitted_action_on_vds_groups(v_user_id UUID, v_action_group_id integer, v_supports_virt_service boolean, v_supports_gluster_service boolean) RETURNS SETOF storage_pool STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT sp.*
      FROM storage_pool sp
      WHERE sp.id in
        (SELECT vg.storage_pool_id
         FROM vds_groups vg
         WHERE (SELECT get_entity_permissions(v_user_id, v_action_group_id, vg.vds_group_id, 9)) IS NOT NULL
         AND ((v_supports_virt_service = TRUE AND vg.virt_service = TRUE) OR (v_supports_gluster_service = TRUE AND vg.gluster_service = TRUE))
        );
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getstorage_domains_By_storage_pool_id_and_connection(v_storage_pool_id UUID, v_connection CHARACTER VARYING)
RETURNS SETOF storage_domains STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM storage_domains
   WHERE storage_pool_id = v_storage_pool_id
   AND storage IN (
      SELECT id
      FROM storage_server_connections
      WHERE connection = v_connection);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetFailingStorage_domains()
RETURNS SETOF storage_domains STABLE
   AS $procedure$
BEGIN
   RETURN QUERY
    SELECT * FROM storage_domains WHERE recoverable AND status = 4; --inactive
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetFailingVdss()
RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
   RETURN QUERY
    SELECT * FROM vds WHERE recoverable AND status = 10; --non operational
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetStoragePoolsByClusterService(
    v_supports_virt_service BOOLEAN,
    v_supports_gluster_service BOOLEAN) RETURNS SETOF storage_pool STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT sp.* FROM storage_pool SP
   WHERE EXISTS (SELECT 1 FROM vds_groups vg
       WHERE ((v_supports_virt_service = TRUE AND vg.virt_service = TRUE) OR
              (v_supports_gluster_service = TRUE AND vg.gluster_service = TRUE)) AND vg.storage_pool_id = sp.id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetStorageServerConnectionsForDomain(v_storage_domain_id UUID)
 RETURNS SETOF storage_server_connections STABLE
 AS $procedure$
 BEGIN
RETURN QUERY SELECT *
FROM storage_server_connections
WHERE EXISTS  ( SELECT 1
		FROM    storage_domain_static
		WHERE   storage_domain_static.id = v_storage_domain_id
		AND     storage_domain_static.storage_type in (1,4,6) -- file storage domains - nfs,posix,local
		AND     storage_server_connections.id  = storage_domain_static.storage
		UNION ALL
		SELECT 1
		FROM   storage_domain_static
		JOIN   luns ON storage_domain_static.storage  = luns.volume_group_id
		JOIN   lun_storage_server_connection_map ON  luns.lun_id = lun_storage_server_connection_map.lun_id
							 AND storage_server_connections.id  = lun_storage_server_connection_map.storage_server_connection
		WHERE  storage_domain_static.id = v_storage_domain_id
		AND    storage_domain_static.storage_type = 3  -- storage type = iscsi
		);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetDcIdByExternalNetworkId(v_external_id text)
RETURNS SETOF UUID STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT storage_pool_id
    FROM network
    WHERE provider_network_external_id = v_external_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetStorageTypesInPoolByPoolId(v_storage_pool_id UUID)
RETURNS SETOF INTEGER STABLE
   AS $procedure$
BEGIN
   RETURN QUERY
   SELECT DISTINCT storage_type
   FROM   storage_domains
   WHERE  storage_pool_id = v_storage_pool_id
   AND    storage_domain_type IN (0,1);  -- 0 = MASTER, 1 = DATA
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNumberOfImagesInStorageDomain(v_storage_domain_id UUID)
  RETURNS SETOF BIGINT STABLE
AS $procedure$
BEGIN
   RETURN QUERY
   SELECT COUNT(*)
   FROM image_storage_domain_map
   WHERE storage_domain_id = v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS Getsystem_statistics_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE Getsystem_statistics_rs AS (val INTEGER);
**************************

CREATE TYPE
********* QUERY **********
Create or replace FUNCTION Getsystem_statistics(v_entity VARCHAR(10), 
v_status VARCHAR(20)) 
RETURNS Getsystem_statistics_rs STABLE
   AS $procedure$
   DECLARE
   v_i Getsystem_statistics_rs;
   v_sql  VARCHAR(4000);
   v_sys_entity VARCHAR(10);
BEGIN
   v_sql := NULL;

   v_sys_entity := upper(v_entity);
   if v_sys_entity = 'VM' then
      v_sql := 'select count(vm_guid) from vm_dynamic';
   elsif v_sys_entity = 'HOST' then
      v_sql := 'select count(vds_id) from vds_dynamic';
   elsif v_sys_entity = 'USER' then
      v_sql := 'select count(user_id) from users';
   elsif v_sys_entity = 'TSD' then
      v_sql := 'select count(id) from storage_domain_static';
   elsif v_sys_entity = 'ASD' then
      v_sql := 'select count(storage_id) from storage_pool_iso_map';
   else
      raise 'Unknown entity type "%"', v_entity;
   end if;

   if v_status != '' then
      if v_sys_entity = 'USER' then
          v_sql := coalesce(v_sql, '') || ' where active::integer in (' || coalesce(v_status, '') || ')';
      elsif v_sys_entity != 'TSD' then
          v_sql := coalesce(v_sql, '') || ' where status in (' || coalesce(v_status, '') || ')';
      end if;
   end if;
   EXECUTE v_sql INTO v_i;
   RETURN v_i;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Inserttags(v_description VARCHAR(4000) ,
	v_tag_id UUID ,
	v_tag_name VARCHAR(50),
	v_parent_id UUID,
	v_readonly BOOLEAN ,
    v_type INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      INSERT INTO tags(tag_id,description, tag_name,parent_id,readonly,type)
	VALUES(v_tag_id,v_description, v_tag_name,v_parent_id,v_readonly,v_type);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatetags(v_description VARCHAR(4000) ,
	v_tag_id UUID,
	v_tag_name VARCHAR(50),
	v_parent_id UUID,
	v_readonly BOOLEAN ,
    v_type INTEGER)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE tags
      SET description = v_description,tag_name = v_tag_name,parent_id = v_parent_id,
      readonly	= v_readonly,type = v_type,_update_date = LOCALTIMESTAMP
      WHERE tag_id = v_tag_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletetags(v_tag_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN
			-- Get (and keep) a shared lock with "right to upgrade to exclusive"
			-- in order to force locking parent before children
      select   tag_id INTO v_val FROM tags  WHERE tag_id = v_tag_id     FOR UPDATE;
      DELETE FROM tags_user_group_map
      WHERE tag_id = v_tag_id;
      DELETE FROM tags_user_map
      WHERE tag_id = v_tag_id;
      DELETE FROM tags_vm_map
      WHERE tag_id = v_tag_id;
      DELETE FROM tags_vds_map
      WHERE tag_id = v_tag_id;
      DELETE FROM tags_vm_pool_map
      WHERE tag_id = v_tag_id;
      DELETE FROM tags
      WHERE tag_id = v_tag_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromtags() RETURNS SETOF tags STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags.*
      FROM tags;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GettagsBytag_id(v_tag_id UUID) RETURNS SETOF tags STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags.*
      FROM tags
      WHERE tag_id = v_tag_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GettagsByparent_id(v_parent_id UUID) RETURNS SETOF tags STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags.*
      FROM tags
      WHERE parent_id = v_parent_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GettagsBytag_name(v_tag_name VARCHAR(50)) RETURNS SETOF tags STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags.*
      FROM tags
      WHERE tag_name = v_tag_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Inserttags_user_group_map(v_group_id UUID,
 v_tag_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO tags_user_group_map(group_id, tag_id)
	VALUES(v_group_id, v_tag_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletetags_user_group_map(v_group_id UUID,
 v_tag_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM tags_user_group_map
      WHERE group_id = v_group_id AND tag_id = v_tag_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromtags_user_group_map() RETURNS SETOF tags_user_group_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags_user_group_map.*
      FROM tags_user_group_map;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTagUserGroupByGroupIdAndByTagId(v_group_id UUID,
 v_tag_id UUID) RETURNS SETOF tags_user_group_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags_user_group_map.*
      FROM tags_user_group_map
      WHERE group_id = v_group_id AND tag_id = v_tag_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTagsByUserGroupId(v_group_ids VARCHAR(4000)) RETURNS SETOF tags_user_group_map_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT tags_user_group_map_view.*
      FROM tags_user_group_map_view
      WHERE group_id in(select * from fnSplitterUuid(v_group_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetUserGroupTagsByTagIds(v_tag_ids VARCHAR(4000)) RETURNS SETOF tags_user_group_map_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT tags_user_group_map_view.*
      FROM tags_user_group_map_view
      WHERE tag_id in(select * from fnSplitterUuid(v_tag_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Inserttags_user_map(v_tag_id UUID,
 v_user_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO tags_user_map(tag_id, user_id)
	VALUES(v_tag_id, v_user_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletetags_user_map(v_tag_id UUID,
 v_user_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM tags_user_map
      WHERE tag_id = v_tag_id AND user_id = v_user_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromtags_user_map() RETURNS SETOF tags_user_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags_user_map.*
      FROM tags_user_map;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTagUserByTagIdAndByuserId(v_tag_id UUID,
 v_user_id UUID) RETURNS SETOF tags_user_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags_user_map.*
      FROM tags_user_map
      WHERE tag_id = v_tag_id AND user_id = v_user_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTagsByUserId(v_user_ids VARCHAR(4000)) RETURNS SETOF tags_user_map_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT tags_user_map_view.*
      FROM tags_user_map_view
      WHERE user_id in(select * from fnSplitterUuid(v_user_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetUserTagsByTagIds(v_tag_ids VARCHAR(4000)) RETURNS SETOF tags_user_map_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT tags_user_map_view.*
      FROM tags_user_map_view
      WHERE tag_id in(select * from fnSplitterUuid(v_tag_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Inserttags_vds_map(v_tag_id UUID,
 v_vds_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO tags_vds_map(tag_id, vds_id)
	VALUES(v_tag_id, v_vds_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletetags_vds_map(v_tag_id UUID,
 v_vds_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM tags_vds_map
      WHERE tag_id = v_tag_id AND vds_id = v_vds_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromtags_vds_map() RETURNS SETOF tags_vds_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags_vds_map.*
      FROM tags_vds_map;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTagVdsBytagIdAndByVdsId(v_tag_id UUID,
 v_vds_id UUID) RETURNS SETOF tags_vds_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags_vds_map.*
      FROM tags_vds_map
      WHERE tag_id = v_tag_id AND vds_id = v_vds_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTagsByVdsId(v_vds_ids VARCHAR(4000)) RETURNS SETOF tags_vds_map_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT tags_vds_map_view.*
      FROM tags_vds_map_view
      WHERE vds_id in(select * from fnSplitterUuid(v_vds_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsTagsByTagIds(v_tag_ids VARCHAR(4000)) RETURNS SETOF tags_vds_map_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT tags_vds_map_view.*
      FROM tags_vds_map_view
      WHERE tag_id in(select * from fnSplitterUuid(v_tag_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Inserttags_vm_map(v_tag_id UUID,
 v_vm_id UUID,
    v_DefaultDisplayType INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO tags_vm_map(tag_id, vm_id, DefaultDisplayType)
	VALUES(v_tag_id, v_vm_id, v_DefaultDisplayType);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletetags_vm_map(v_tag_id UUID,
 v_vm_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM tags_vm_map
      WHERE tag_id = v_tag_id AND vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromtags_vm_map() RETURNS SETOF tags_vm_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags_vm_map.*
      FROM tags_vm_map;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTagVmByTagIdAndByvmId(v_tag_id UUID,
 v_vm_id UUID) RETURNS SETOF tags_vm_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT tags_vm_map.*
      FROM tags_vm_map
      WHERE tag_id = v_tag_id AND vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTagsByVmId(v_vm_ids VARCHAR(4000)) RETURNS SETOF tags_vm_map_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT tags_vm_map_view.*
      FROM tags_vm_map_view
      WHERE vm_id in(select * from fnSplitterUuid(v_vm_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTagsByTagId(v_tag_ids VARCHAR(4000)) RETURNS SETOF tags_vm_map_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT tags_vm_map_view.*
      FROM tags_vm_map_view
      WHERE tag_id in(select * from fnSplitterUuid(v_tag_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmTagsDefaultDisplayType(v_tag_id UUID,
	v_vm_id UUID,
    v_DefaultDisplayType INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      update tags_vm_map
      set DefaultDisplayType = v_DefaultDisplayType
      where tags_vm_map.tag_id = v_tag_id
      and tags_vm_map.vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetnVmTagsByVmId(v_vm_id UUID) RETURNS SETOF tags_vm_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY select * from tags_vm_map
      where tags_vm_map.vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetnVmTagsByVmIdAndDefaultTag(v_vm_id UUID) RETURNS SETOF tags_vm_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY select tags_vm_map.* from tags_vm_map
      inner join tags on tags.tag_id = tags_vm_map.tag_id
      where tags_vm_map.vm_id = v_vm_id
      and tags.type = 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION RemoveAllVmTagsByVmId(v_vm_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      delete FROM tags_vm_map
      where vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Inserttags_vm_pool_map(v_tag_id UUID,
 v_vm_pool_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO tags_vm_pool_map(tag_id, vm_pool_id)
	VALUES(v_tag_id, v_vm_pool_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Updatetags_vm_pool_map(v_tag_id INTEGER,
	v_vm_pool_id INTEGER)
RETURNS VOID
	
   AS $procedure$
BEGIN
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletetags_vm_pool_map(v_tag_id UUID,
 v_vm_pool_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM tags_vm_pool_map
   WHERE tag_id = v_tag_id AND vm_pool_id = v_vm_pool_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromtags_vm_pool_map() RETURNS SETOF tags_vm_pool_map STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT tags_vm_pool_map.*
   FROM tags_vm_pool_map;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Gettags_vm_pool_mapBytag_idAndByvm_pool_id(v_tag_id UUID,
 v_vm_pool_id UUID) RETURNS SETOF tags_vm_pool_map STABLE
   AS $procedure$
BEGIN

   RETURN QUERY SELECT tags_vm_pool_map.*
   FROM tags_vm_pool_map
   WHERE tag_id = v_tag_id AND vm_pool_id = v_vm_pool_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTagsByVmpoolId(v_vm_pool_ids VARCHAR(4000)) RETURNS SETOF tags_vm_pool_map_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT tags_vm_pool_map_view.*
      FROM tags_vm_pool_map_view
      WHERE vm_pool_id in(select * from fnSplitterUuid(v_vm_pool_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertOVFDataForEntities(v_entity_guid UUID,
   v_entity_name VARCHAR(255),
   v_entity_type VARCHAR(32),
   v_architecture INTEGER,
   v_lowest_comp_version VARCHAR(40),
   v_storage_domain_id UUID,
   v_ovf_data TEXT,
   v_ovf_extra_data TEXT)
RETURNS VOID
   AS $procedure$
BEGIN
        INSERT INTO unregistered_ovf_of_entities(entity_guid, entity_name, entity_type, architecture, lowest_comp_version, storage_domain_id, ovf_extra_data, ovf_data)
        VALUES (v_entity_guid, v_entity_name, v_entity_type, v_architecture, v_lowest_comp_version, v_storage_domain_id, v_ovf_extra_data, v_ovf_data);

        UPDATE unregistered_ovf_of_entities u
        SET ovf_data = vog.ovf_data
        FROM vm_ovf_generations vog
        WHERE vog.vm_guid = u.entity_guid AND u.entity_guid = v_entity_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION RemoveEntityFromUnregistered(v_entity_guid UUID, v_storage_domain_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM unregistered_ovf_of_entities
      WHERE entity_guid = v_entity_guid
        AND (storage_domain_id = v_storage_domain_id OR v_storage_domain_id IS NULL);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllOVFEntitiesForStorageDomainByEntityType(v_storage_domain_id UUID, v_entity_type VARCHAR(20))
RETURNS SETOF unregistered_ovf_of_entities STABLE
   AS $procedure$
BEGIN
        RETURN QUERY SELECT *
        FROM unregistered_ovf_of_entities
        WHERE storage_domain_id = v_storage_domain_id
          AND (entity_type = v_entity_type OR v_entity_type IS NULL);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetOVFDataByEntityIdAndStorageDomain(v_entity_guid UUID, v_storage_domain_id UUID)
RETURNS SETOF unregistered_ovf_of_entities STABLE
   AS $procedure$
BEGIN
        RETURN QUERY SELECT *
        FROM unregistered_ovf_of_entities
        WHERE entity_guid = v_entity_guid
          AND storage_domain_id = v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertUser(v_department VARCHAR(255) ,
	v_domain VARCHAR(255),
	v_email VARCHAR(255) ,
	v_groups VARCHAR,
	v_name VARCHAR(255) ,
	v_note VARCHAR(255) ,
	v_role VARCHAR(255) ,
	v_active BOOLEAN,
	v_surname VARCHAR(255) ,
	v_user_id UUID,
	v_username VARCHAR(255),
	v_group_ids VARCHAR(2048),
	v_external_id TEXT,
	v_namespace VARCHAR(2048))
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO users(department, domain, email, groups, name, note, role, active, surname, user_id, username, group_ids, external_id,namespace)
	VALUES(v_department, v_domain, v_email, v_groups, v_name, v_note, v_role, v_active, v_surname, v_user_id, v_username, v_group_ids, v_external_id, v_namespace);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateUserImpl(
	v_department VARCHAR(255) ,
	v_domain VARCHAR(255),
	v_email VARCHAR(255) ,
	v_groups VARCHAR(4000),
	v_name VARCHAR(255) ,
	v_note VARCHAR(255) ,
	v_role VARCHAR(255) ,
	v_active BOOLEAN,
	v_surname VARCHAR(255) ,
	v_user_id UUID,
	v_username VARCHAR(255),
	v_group_ids VARCHAR(2048),
        v_external_id TEXT,
	v_namespace VARCHAR(2048))
RETURNS INTEGER
	
   AS $procedure$
DECLARE
	updated_rows INT;
BEGIN
      UPDATE users
      SET department = v_department,domain = v_domain,
      email = v_email,groups = v_groups,name = v_name,note = v_note,
      role = v_role,active = v_active,surname = v_surname,
      username = v_username,
      group_ids = v_group_ids,
      external_id = v_external_id,
      namespace = v_namespace,
      _update_date = CURRENT_TIMESTAMP
      WHERE external_id = v_external_id AND domain = v_domain;
      GET DIAGNOSTICS updated_rows = ROW_COUNT;
      RETURN updated_rows;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateUser(
	v_department VARCHAR(255) ,
	v_domain VARCHAR(255),
	v_email VARCHAR(255) ,
	v_groups VARCHAR(4000),
	v_name VARCHAR(255) ,
	v_note VARCHAR(255) ,
	v_role VARCHAR(255) ,
	v_active BOOLEAN,
	v_surname VARCHAR(255) ,
	v_user_id UUID,
	v_username VARCHAR(255),
	v_last_admin_check_status BOOLEAN,
	v_group_ids VARCHAR(2048),
        v_external_id TEXT,
	v_namespace VARCHAR(2048))
RETURNS VOID
	
   AS $procedure$
BEGIN
      PERFORM UpdateUserImpl(v_department, v_domain, v_email, v_groups, v_name, v_note, v_role, v_active, v_surname, v_user_id, v_username, v_group_ids, v_external_id, v_namespace);
      UPDATE users SET
      last_admin_check_status = v_last_admin_check_status
      WHERE domain = v_domain AND external_id = v_external_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertOrUpdateUser(
	v_department VARCHAR(255) ,
	v_domain VARCHAR(255),
	v_email VARCHAR(255) ,
	v_groups VARCHAR,
	v_name VARCHAR(255) ,
	v_note VARCHAR(255) ,
	v_role VARCHAR(255) ,
	v_active BOOLEAN,
	v_surname VARCHAR(255) ,
	v_user_id UUID,
	v_username VARCHAR(255),
	v_group_ids VARCHAR(2048),
	v_external_id TEXT,
	v_namespace VARCHAR(2048))
RETURNS VOID
   AS $procedure$
DECLARE
   updated_rows INT;
BEGIN
       SELECT UpdateUserImpl(v_department, v_domain, v_email, v_groups, v_name, v_note, v_role, v_active, v_surname, v_user_id, v_username, v_group_ids, v_external_id, v_namespace) into updated_rows;
       if (updated_rows = 0) THEN
	    PERFORM InsertUser(v_department, v_domain, v_email, v_groups, v_name, v_note, v_role, v_active, v_surname, v_user_id, v_username, v_group_ids, v_external_id, v_namespace);
        End If;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteUser(v_user_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN
			-- Get (and keep) a shared lock with "right to upgrade to exclusive"
			-- in order to force locking parent before children
      select   user_id INTO v_val FROM users  WHERE user_id = v_user_id     FOR UPDATE;
      DELETE FROM tags_user_map
      WHERE user_id = v_user_id;
      DELETE FROM users
      WHERE user_id = v_user_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromUsers(v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF users STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT users.*
      FROM users
      WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                   FROM   users u, user_db_users_permissions_view p
                                   WHERE  u.user_id = v_user_id AND u.user_id = p.ad_element_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetUserByUserId(v_user_id UUID) RETURNS SETOF users STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT users.*
      FROM users
      WHERE user_id = v_user_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetUserByExternalId(v_domain VARCHAR(255), v_external_id TEXT) RETURNS SETOF users STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT users.*
      FROM users
      WHERE domain = v_domain AND external_id = v_external_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetUserByUserNameAndDomain(v_username VARCHAR(255), v_domain VARCHAR(255)) RETURNS SETOF users STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT users.*
      FROM users
      WHERE username = v_username AND domain = v_domain;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetUsersByVmGuid(v_vm_guid UUID) RETURNS SETOF users STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT users.*
      FROM users
      inner join permissions
      on users.user_id = permissions.ad_element_id
      WHERE permissions.object_type_id = 2
      and	permissions.object_id = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateLastAdminCheckStatus(v_userIds VARCHAR(4000))
RETURNS VOID
   AS $procedure$
   DECLARE
   v_id  UUID;
   v_tempId  VARCHAR(4000);
   myCursor cursor for select id from fnSplitter(v_userIds);
   v_result  INTEGER;
BEGIN
	-- get users and its groups
	-- get their permission based on ad_element_id.
	-- if one permissions role's type is ADMIN(1) then set the user last_admin_check_status to 1
   OPEN myCursor;
   FETCH myCursor into v_tempId;
   WHILE FOUND LOOP
      v_id := CAST(v_tempId AS UUID);
      select   count(*) INTO v_result from users where user_id in(select ad_element_id as user_id from permissions,roles
         where permissions.role_id = roles.id
         and ad_element_id in((select id from ad_groups,users where users.user_id = v_id
               and ad_groups.id in(select * from fnsplitteruuid(users.group_ids))
               union
               select v_id))
         and (roles.role_type = 1 or permissions.role_id = '00000000-0000-0000-0000-000000000001'));
      update users set last_admin_check_status =
      case
      when v_result = 0 then FALSE
      else TRUE
      end
      where user_id = v_id;
      FETCH myCursor into v_tempId;
   END LOOP;
   CLOSE myCursor;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVdcOption(v_option_name VARCHAR(50),
	v_option_value VARCHAR(50),
	v_version VARCHAR(40),
	INOUT v_option_id INTEGER)
   AS $procedure$
BEGIN
INSERT INTO vdc_options(OPTION_NAME, option_value, version)
	VALUES(v_option_name, v_option_value, v_version);

      v_option_id := CURRVAL('vdc_options_seq');
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVdcOption(v_option_name VARCHAR(50),
	v_option_value VARCHAR(50),
	v_option_id INTEGER,
	v_version VARCHAR(40))
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE vdc_options
      SET OPTION_NAME = v_option_name,option_value = v_option_value,version = v_version
      WHERE option_id = v_option_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVdcOption(v_option_id INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM vdc_options
      WHERE option_id = v_option_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVdcOption() RETURNS SETOF vdc_options STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vdc_options.*
      FROM vdc_options;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdcOptionById(v_option_id INTEGER) RETURNS SETOF vdc_options STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vdc_options.*
      FROM vdc_options
      WHERE option_id = v_option_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdcOptionByName(v_option_name VARCHAR(50),
	v_version VARCHAR(40)) RETURNS SETOF vdc_options STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vdc_options.*
      FROM vdc_options
      WHERE OPTION_NAME = v_option_name and version = v_version;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVdsGroups(
	v_vds_group_id UUID,
	v_description VARCHAR(4000),
	v_free_text_comment text,
	v_name VARCHAR(40),
	v_cpu_name VARCHAR(255),
	v_storage_pool_id UUID ,
	v_max_vds_memory_over_commit INTEGER,
	v_count_threads_as_cores BOOLEAN,
	v_compatibility_version VARCHAR(40),
	v_transparent_hugepages BOOLEAN,
	v_migrate_on_error INTEGER,
	v_virt_service BOOLEAN,
	v_gluster_service BOOLEAN,
	v_tunnel_migration BOOLEAN,
	v_emulated_machine VARCHAR(40),
	v_detect_emulated_machine BOOLEAN,
	v_trusted_service BOOLEAN,
	v_ha_reservation BOOLEAN,
	v_optional_reason BOOLEAN,
        v_cluster_policy_id UUID,
        v_cluster_policy_custom_properties text,
	v_enable_balloon BOOLEAN,
	v_architecture INTEGER,
	v_optimization_type SMALLINT,
	v_spice_proxy VARCHAR(255),
	v_enable_ksm BOOLEAN,
        v_serial_number_policy SMALLINT,
        v_custom_serial_number VARCHAR(255),
        v_required_rng_sources varchar(255),
        v_skip_fencing_if_sd_active BOOLEAN,
        v_skip_fencing_if_connectivity_broken BOOLEAN,
        v_hosts_with_broken_connectivity_threshold SMALLINT,
        v_fencing_enabled BOOLEAN
)
RETURNS VOID
   AS $procedure$
BEGIN
      INSERT INTO vds_groups(vds_group_id,description, name, free_text_comment, cpu_name, storage_pool_id,  max_vds_memory_over_commit, count_threads_as_cores, compatibility_version,
        transparent_hugepages, migrate_on_error, virt_service, gluster_service, tunnel_migration, emulated_machine, detect_emulated_machine, trusted_service, ha_reservation, optional_reason, cluster_policy_id,
        cluster_policy_custom_properties, enable_balloon, architecture, optimization_type, spice_proxy, enable_ksm, serial_number_policy, custom_serial_number, required_rng_sources, skip_fencing_if_sd_active, skip_fencing_if_connectivity_broken, hosts_with_broken_connectivity_threshold, fencing_enabled)
	VALUES(v_vds_group_id,v_description, v_name, v_free_text_comment, v_cpu_name, v_storage_pool_id,  v_max_vds_memory_over_commit, v_count_threads_as_cores, v_compatibility_version,
    v_transparent_hugepages, v_migrate_on_error, v_virt_service, v_gluster_service, v_tunnel_migration, v_emulated_machine, v_detect_emulated_machine, v_trusted_service, v_ha_reservation, v_optional_reason, v_cluster_policy_id, v_cluster_policy_custom_properties, v_enable_balloon,
    v_architecture, v_optimization_type, v_spice_proxy, v_enable_ksm, v_serial_number_policy, v_custom_serial_number, v_required_rng_sources, v_skip_fencing_if_sd_active, v_skip_fencing_if_connectivity_broken, v_hosts_with_broken_connectivity_threshold, v_fencing_enabled);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVdsGroup(v_description VARCHAR(4000) ,
	v_free_text_comment text,
	v_name VARCHAR(40),
	v_vds_group_id UUID,
	v_cpu_name VARCHAR(255) ,
	v_storage_pool_id UUID ,
	v_max_vds_memory_over_commit INTEGER,
	v_count_threads_as_cores BOOLEAN,
	v_compatibility_version VARCHAR(40),
	v_transparent_hugepages BOOLEAN ,
	v_migrate_on_error INTEGER,
	v_virt_service BOOLEAN,
	v_gluster_service BOOLEAN,
	v_tunnel_migration BOOLEAN,
	v_emulated_machine VARCHAR(40),
	v_detect_emulated_machine BOOLEAN,
	v_trusted_service BOOLEAN,
	v_ha_reservation BOOLEAN,
	v_optional_reason BOOLEAN,
        v_cluster_policy_id UUID,
        v_cluster_policy_custom_properties text,
	v_enable_balloon BOOLEAN,
	v_architecture INTEGER,
	v_optimization_type SMALLINT,
	v_spice_proxy VARCHAR(255),
	v_enable_ksm BOOLEAN,
        v_serial_number_policy SMALLINT,
        v_custom_serial_number VARCHAR(255),
        v_required_rng_sources varchar(255),
        v_skip_fencing_if_sd_active BOOLEAN,
        v_skip_fencing_if_connectivity_broken BOOLEAN,
        v_hosts_with_broken_connectivity_threshold SMALLINT,
        v_fencing_enabled BOOLEAN
)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE vds_groups
      SET description = v_description, free_text_comment = v_free_text_comment, name = v_name,cpu_name = v_cpu_name,
      storage_pool_id = v_storage_pool_id,_update_date = LOCALTIMESTAMP,
      max_vds_memory_over_commit = v_max_vds_memory_over_commit,
      count_threads_as_cores = v_count_threads_as_cores,
      compatibility_version = v_compatibility_version,transparent_hugepages = v_transparent_hugepages,
      migrate_on_error = v_migrate_on_error,
      virt_service = v_virt_service, gluster_service = v_gluster_service, tunnel_migration = v_tunnel_migration,
      emulated_machine = v_emulated_machine, detect_emulated_machine = v_detect_emulated_machine, trusted_service = v_trusted_service, ha_reservation = v_ha_reservation , optional_reason = v_optional_reason, cluster_policy_id = v_cluster_policy_id,
      cluster_policy_custom_properties = v_cluster_policy_custom_properties, enable_balloon = v_enable_balloon, architecture = v_architecture,
      optimization_type = v_optimization_type, spice_proxy = v_spice_proxy, enable_ksm = v_enable_ksm,
      serial_number_policy = v_serial_number_policy, custom_serial_number = v_custom_serial_number,
      required_rng_sources = v_required_rng_sources,
      skip_fencing_if_sd_active = v_skip_fencing_if_sd_active,
      skip_fencing_if_connectivity_broken = v_skip_fencing_if_connectivity_broken,
      hosts_with_broken_connectivity_threshold = v_hosts_with_broken_connectivity_threshold,
      fencing_enabled = v_fencing_enabled
      WHERE vds_group_id = v_vds_group_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVdsGroup(v_vds_group_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN
		-- Get (and keep) a shared lock with "right to upgrade to exclusive"
		-- in order to force locking parent before children
      select   vds_group_id INTO v_val FROM vds_groups  WHERE vds_group_id = v_vds_group_id     FOR UPDATE;
      DELETE FROM vds_groups
      WHERE vds_group_id = v_vds_group_id;
		-- delete VDS group permissions --
      DELETE FROM permissions where object_id = v_vds_group_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVdsGroups(v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF vds_groups_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                          FROM   user_vds_groups_permissions_view
                                          WHERE  user_id = v_user_id and entity_id = vds_group_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsGroupByVdsGroupId(v_vds_group_id UUID, v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF vds_groups_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE vds_group_id = v_vds_group_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vds_groups_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = v_vds_group_id));

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsGroupByVdsGroupName(v_vds_group_name VARCHAR(40), v_is_case_sensitive BOOLEAN) RETURNS SETOF vds_groups_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE name = v_vds_group_name OR (NOT v_is_case_sensitive AND name ilike v_vds_group_name);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsGroupForUserByVdsGroupName(v_vds_group_name VARCHAR(40), v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF vds_groups_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE name = v_vds_group_name
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vds_groups_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = vds_group_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsGroupsByStoragePoolId(v_storage_pool_id UUID, v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF vds_groups_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE storage_pool_id = v_storage_pool_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vds_groups_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = vds_group_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsGroupWithRunningVms(v_vds_group_id UUID) RETURNS SETOF vds_groups_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE vds_group_id = v_vds_group_id and vds_group_id in(select vds_group_id from vms where vms.status NOT IN(0,13,14));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetIsVdsGroupEmpty(v_vds_group_id UUID) RETURNS BOOLEAN
   AS $procedure$
BEGIN
      RETURN NOT EXISTS(SELECT 1 FROM vm_static WHERE vds_group_id = v_vds_group_id AND vm_guid != '00000000-0000-0000-0000-000000000000') AND NOT EXISTS(SELECT 1 FROM vds_static WHERE vds_group_id = v_vds_group_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_perms_get_vds_groups_with_permitted_action(v_user_id UUID, v_action_group_id integer) RETURNS SETOF vds_groups_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE (SELECT 1 from get_entity_permissions(v_user_id, v_action_group_id, vds_groups_view.vds_group_id, 9)) IS NOT NULL;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVdsGroupEmulatedMachine(v_vds_group_id UUID, v_emulated_machine varchar(40), v_detect_emulated_machine BOOLEAN) RETURNS VOID
   AS $procedure$
BEGIN
    UPDATE vds_groups
    SET emulated_machine = v_emulated_machine, detect_emulated_machine = v_detect_emulated_machine
    WHERE vds_group_id = v_vds_group_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTrustedVdsGroups() RETURNS SETOF vds_groups_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE trusted_service;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsGroupsByClusterPolicyId(v_cluster_policy_id UUID) RETURNS SETOF vds_groups_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vds_groups_view.*
      FROM vds_groups_view
      WHERE cluster_policy_id = v_cluster_policy_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetNumberOfVmsInCluster(v_vds_group_id UUID) RETURNS SETOF BIGINT STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT COUNT (vms.*)
      FROM vm_static vms
      WHERE vms.vds_group_id = v_vds_group_id AND vms.entity_type = 'VM';
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS host_vm_cluster_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE host_vm_cluster_rs AS (vds_group_id UUID,hosts bigint,vms bigint);
**************************

CREATE TYPE
********* QUERY **********
Create or replace FUNCTION GetHostsAndVmsForClusters(v_vds_group_ids UUID[]) RETURNS SETOF host_vm_cluster_rs STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT groups.vds_group_id,COUNT(DISTINCT vds.vds_id) as host_count,COUNT(DISTINCT vms.vm_guid) as vm_count
      FROM vds_groups groups
      LEFT JOIN vm_static vms on vms.vds_group_id = groups.vds_group_id and vms.entity_type::text = 'VM'::text
      LEFT JOIN vds_static vds on vds.vds_group_id = groups.vds_group_id
      WHERE groups.vds_group_id = any(v_vds_group_ids)
      GROUP BY groups.vds_group_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpsertKdumpStatus(
        v_vds_id UUID,
        v_status VARCHAR(20),
        v_address VARCHAR(255))
RETURNS INT
    AS $procedure$
BEGIN
    UPDATE vds_kdump_status
        SET
            status = v_status,
            address = v_address
        WHERE vds_id = v_vds_id;

    IF NOT found THEN
        INSERT INTO vds_kdump_status(
                vds_id,
                status,
                address
            ) VALUES (
                v_vds_id,
                v_status,
                v_address
            );
    END IF;

    RETURN 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpsertKdumpStatusForIp(
        v_ip VARCHAR(20),
        v_status VARCHAR(20),
        v_address VARCHAR(255))
RETURNS INT
    AS $procedure$
DECLARE
    v_vds_id UUID;
    updated_rows INT;
BEGIN
    updated_rows := 0;

    SELECT vds_id
        INTO v_vds_id
        FROM vds_interface
        WHERE addr = v_ip;

    IF v_vds_id IS NOT NULL THEN
        SELECT UpsertKdumpStatus(
                v_vds_id,
                v_status,
                v_address)
            INTO updated_rows;
    END IF;

    RETURN updated_rows;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION RemoveFinishedKdumpStatusForVds(
        v_vds_id UUID)
RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM vds_kdump_status
        WHERE
            vds_id = v_vds_id AND
            status = 'finished';
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetKdumpStatusForVds(
        v_vds_id UUID)
RETURNS SETOF vds_kdump_status STABLE
    AS $procedure$
BEGIN
   RETURN QUERY SELECT *
       FROM vds_kdump_status
       WHERE vds_id = v_vds_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetAllUnfinishedVdsKdumpStatus()
RETURNS SETOF vds_kdump_status STABLE
    AS $procedure$
BEGIN
   RETURN QUERY SELECT *
       FROM vds_kdump_status
       WHERE status <> 'finished';
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Insertvds_spm_id_map(v_storage_pool_id UUID,
 v_vds_id UUID,
 v_vds_spm_id INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO vds_spm_id_map(storage_pool_id, vds_id, vds_spm_id)
	VALUES(v_storage_pool_id, v_vds_id, v_vds_spm_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Deletevds_spm_id_map(v_vds_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM vds_spm_id_map
   WHERE vds_id = v_vds_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteByPoolvds_spm_id_map(v_vds_id UUID, v_storage_pool_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN

   DELETE FROM vds_spm_id_map
   WHERE vds_id = v_vds_id AND storage_pool_id = v_storage_pool_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromvds_spm_id_map() RETURNS SETOF vds_spm_id_map STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vds_spm_id_map.*
   FROM vds_spm_id_map;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getvds_spm_id_mapBystorage_pool_idAndByvds_spm_id(v_storage_pool_id UUID,
 v_vds_spm_id INTEGER) RETURNS SETOF vds_spm_id_map STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vds_spm_id_map.*
   FROM vds_spm_id_map
   WHERE storage_pool_id = v_storage_pool_id AND vds_spm_id = v_vds_spm_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getvds_spm_id_mapBystorage_pool_id(v_storage_pool_id UUID) RETURNS SETOF vds_spm_id_map STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vds_spm_id_map.*
   FROM vds_spm_id_map
   WHERE storage_pool_id = v_storage_pool_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION Getvds_spm_id_mapByvds_id(v_vds_id UUID) RETURNS SETOF vds_spm_id_map STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vds_spm_id_map.*
   FROM vds_spm_id_map
   WHERE vds_id = v_vds_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVdsStatistics(v_cpu_idle DECIMAL(18,0) ,
 v_cpu_load DECIMAL(18,0) ,
 v_cpu_sys DECIMAL(18,0) ,
 v_cpu_user DECIMAL(18,0) ,
 v_usage_cpu_percent INTEGER ,
 v_usage_mem_percent INTEGER ,
 v_usage_network_percent INTEGER ,
 v_vds_id UUID,
 v_mem_available BIGINT ,
 v_mem_free BIGINT,
 v_mem_shared BIGINT ,
    v_swap_free BIGINT ,
 v_swap_total BIGINT ,
 v_ksm_cpu_percent INTEGER ,
 v_ksm_pages BIGINT ,
 v_ksm_state BOOLEAN,
 v_anonymous_hugepages INTEGER,
 v_boot_time BIGINT,
 v_ha_score INTEGER,
 v_ha_configured BOOLEAN,
 v_ha_active BOOLEAN,
 v_ha_global_maintenance BOOLEAN,
 v_ha_local_maintenance BOOLEAN)
RETURNS VOID
   AS $procedure$
BEGIN

   BEGIN
INSERT INTO vds_statistics(cpu_idle, cpu_load, cpu_sys, cpu_user, usage_cpu_percent, usage_mem_percent, usage_network_percent, vds_id, mem_available, mem_free, mem_shared,swap_free,swap_total,ksm_cpu_percent,ksm_pages,ksm_state, anonymous_hugepages, boot_time, ha_score, ha_configured, ha_active, ha_global_maintenance, ha_local_maintenance)
	VALUES(v_cpu_idle, v_cpu_load, v_cpu_sys, v_cpu_user, v_usage_cpu_percent, v_usage_mem_percent, v_usage_network_percent, v_vds_id, v_mem_available, v_mem_free, v_mem_shared,v_swap_free,v_swap_total,v_ksm_cpu_percent,v_ksm_pages,v_ksm_state, v_anonymous_hugepages, v_boot_time, v_ha_score, v_ha_configured, v_ha_active, v_ha_global_maintenance, v_ha_local_maintenance);
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVdsStatistics(v_cpu_idle DECIMAL(18,0) ,
 v_cpu_load DECIMAL(18,0) ,
 v_cpu_sys DECIMAL(18,0) ,
 v_cpu_user DECIMAL(18,0) ,
 v_usage_cpu_percent INTEGER ,
 v_usage_mem_percent INTEGER ,
 v_usage_network_percent INTEGER ,
 v_vds_id UUID,
 v_mem_available BIGINT ,
 v_mem_free BIGINT,
 v_mem_shared BIGINT ,
 v_swap_free BIGINT ,
 v_swap_total BIGINT ,
 v_ksm_cpu_percent INTEGER ,
 v_ksm_pages BIGINT ,
 v_ksm_state BOOLEAN,
 v_anonymous_hugepages INTEGER,
 v_boot_time BIGINT,
 v_ha_score INTEGER,
 v_ha_configured BOOLEAN,
 v_ha_active BOOLEAN,
 v_ha_global_maintenance BOOLEAN,
 v_ha_local_maintenance BOOLEAN)
RETURNS VOID
	
   AS $procedure$
BEGIN

   BEGIN
      UPDATE vds_statistics
      SET cpu_idle = v_cpu_idle,cpu_load = v_cpu_load,cpu_sys = v_cpu_sys,
      cpu_user = v_cpu_user,usage_cpu_percent = v_usage_cpu_percent,usage_mem_percent = v_usage_mem_percent,
      usage_network_percent = v_usage_network_percent,
      mem_available = v_mem_available, mem_free = v_mem_free, mem_shared = v_mem_shared,
      swap_free = v_swap_free,swap_total = v_swap_total,ksm_cpu_percent = v_ksm_cpu_percent,
      ksm_pages = v_ksm_pages,ksm_state = v_ksm_state, anonymous_hugepages = v_anonymous_hugepages,
      boot_time = v_boot_time,
      ha_score = v_ha_score, ha_configured = v_ha_configured, ha_active = v_ha_active,
      ha_global_maintenance = v_ha_global_maintenance, ha_local_maintenance = v_ha_local_maintenance,
      _update_date = LOCALTIMESTAMP
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVdsStatistics(v_vds_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   BEGIN
      DELETE FROM vds_statistics
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVdsStatistics() RETURNS SETOF vds_statistics STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT vds_statistics.*
      FROM vds_statistics;
   END;


   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsStatisticsByVdsId(v_vds_id UUID) RETURNS SETOF vds_statistics STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT vds_statistics.*
      FROM vds_statistics
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVdsDynamic(v_cpu_cores INTEGER ,
 v_cpu_threads INTEGER ,
 v_cpu_model VARCHAR(255) ,
 v_cpu_speed_mh DECIMAL(18,0) ,
 v_if_total_speed VARCHAR(40) ,
 v_kvm_enabled BOOLEAN ,
 v_mem_commited INTEGER ,
 v_physical_mem_mb INTEGER ,
 v_status INTEGER,
 v_vds_id UUID,
 v_vm_active INTEGER ,
 v_vm_count INTEGER ,
 v_vms_cores_count INTEGER ,
 v_vm_migrating INTEGER ,
 v_reserved_mem INTEGER ,
 v_guest_overhead INTEGER ,
 v_rpm_version VARCHAR(255),
 v_software_version VARCHAR(40) ,
 v_version_name VARCHAR(40) ,
 v_build_name VARCHAR(40) ,
 v_previous_status INTEGER ,
 v_cpu_flags VARCHAR(4000) ,
 v_cpu_over_commit_time_stamp TIMESTAMP WITH TIME ZONE ,
 v_pending_vcpus_count INTEGER ,
 v_pending_vmem_size INTEGER ,
 v_cpu_sockets INTEGER ,
 v_net_config_dirty BOOLEAN ,
 v_supported_cluster_levels VARCHAR(40) ,
 v_supported_engines VARCHAR(40) ,
 v_host_os VARCHAR(4000) ,
 v_kvm_version VARCHAR(4000) ,
 v_libvirt_version VARCHAR(4000) ,
 v_spice_version VARCHAR(4000) ,
 v_gluster_version VARCHAR(4000) ,
 v_kernel_version VARCHAR(4000) ,
 v_iscsi_initiator_name VARCHAR(4000) ,
 v_transparent_hugepages_state INTEGER ,
 v_hooks VARCHAR(4000),
 v_hw_manufacturer VARCHAR(255),
 v_hw_product_name VARCHAR(255),
 v_hw_version VARCHAR(255),
 v_hw_serial_number VARCHAR(255),
 v_hw_uuid VARCHAR(255),
 v_hw_family VARCHAR(255),
 v_hbas VARCHAR(255),
 v_supported_emulated_machines VARCHAR(255),
 v_controlled_by_pm_policy BOOLEAN,
 v_kdump_status SMALLINT,
 v_selinux_enforce_mode INTEGER,
 v_auto_numa_balancing SMALLINT,
 v_is_numa_supported BOOLEAN,
 v_supported_rng_sources VARCHAR(255),
 v_is_live_snapshot_supported BOOLEAN,
 v_is_live_merge_supported BOOLEAN)
RETURNS VOID
   AS $procedure$
BEGIN

   BEGIN
INSERT INTO vds_dynamic(cpu_cores, cpu_threads, cpu_model, cpu_speed_mh, if_total_speed, kvm_enabled, mem_commited, physical_mem_mb,	status, vds_id, vm_active, vm_count, vm_migrating, reserved_mem, guest_overhead, rpm_version, software_version, version_name, build_name, previous_status, cpu_flags, cpu_over_commit_time_stamp, vms_cores_count, pending_vcpus_count, pending_vmem_size, cpu_sockets,net_config_dirty, supported_cluster_levels, supported_engines, host_os, kvm_version, libvirt_version, spice_version, gluster_version, kernel_version, iscsi_initiator_name, transparent_hugepages_state, hooks, hw_manufacturer, hw_product_name, hw_version, hw_serial_number, hw_uuid, hw_family, hbas, supported_emulated_machines, controlled_by_pm_policy, kdump_status, selinux_enforce_mode, auto_numa_balancing, is_numa_supported, supported_rng_sources, is_live_snapshot_supported, is_live_merge_supported)
	VALUES(v_cpu_cores,	v_cpu_threads, v_cpu_model,	v_cpu_speed_mh,v_if_total_speed, v_kvm_enabled, v_mem_commited, v_physical_mem_mb,	v_status, v_vds_id, v_vm_active, v_vm_count, v_vm_migrating,	v_reserved_mem, v_guest_overhead, v_rpm_version, v_software_version, v_version_name, v_build_name, v_previous_status, v_cpu_flags, v_cpu_over_commit_time_stamp, v_vms_cores_count,v_pending_vcpus_count, v_pending_vmem_size, v_cpu_sockets, v_net_config_dirty, v_supported_cluster_levels, v_supported_engines, v_host_os, v_kvm_version, v_libvirt_version, v_spice_version, v_gluster_version, v_kernel_version, v_iscsi_initiator_name, v_transparent_hugepages_state, v_hooks, v_hw_manufacturer, v_hw_product_name, v_hw_version, v_hw_serial_number, v_hw_uuid, v_hw_family, v_hbas, v_supported_emulated_machines, v_controlled_by_pm_policy, v_kdump_status, v_selinux_enforce_mode, v_auto_numa_balancing, v_is_numa_supported, v_supported_rng_sources, v_is_live_snapshot_supported, v_is_live_merge_supported);
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION UpdateVdsDynamicPowerManagementPolicyFlag(
 v_vds_id UUID,
 v_controlled_by_pm_policy BOOLEAN
) RETURNS VOID AS $procedure$
BEGIN
  BEGIN
    UPDATE vds_dynamic
    SET controlled_by_pm_policy = v_controlled_by_pm_policy
    WHERE vds_id = v_vds_id;
  END;
  RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVdsDynamic(v_cpu_cores INTEGER ,
 v_cpu_threads INTEGER ,
 v_cpu_model VARCHAR(255) ,
 v_cpu_speed_mh DECIMAL(18,0) ,
 v_if_total_speed VARCHAR(40) ,
 v_kvm_enabled BOOLEAN ,
 v_mem_commited INTEGER ,
 v_physical_mem_mb INTEGER ,
 v_status INTEGER,
 v_vds_id UUID,
 v_vm_active INTEGER ,
 v_vm_count INTEGER ,
 v_vms_cores_count INTEGER ,
 v_vm_migrating INTEGER ,
 v_reserved_mem INTEGER ,
 v_guest_overhead INTEGER ,
 v_rpm_version VARCHAR(255),
 v_software_version VARCHAR(40) ,
 v_version_name VARCHAR(40) ,
 v_build_name VARCHAR(40) ,
 v_previous_status INTEGER ,
 v_cpu_flags VARCHAR(4000) ,
 v_cpu_over_commit_time_stamp TIMESTAMP WITH TIME ZONE ,
 v_pending_vcpus_count INTEGER ,
 v_pending_vmem_size INTEGER ,
 v_cpu_sockets INTEGER ,
 v_net_config_dirty BOOLEAN ,
 v_supported_cluster_levels VARCHAR(40) ,
 v_supported_engines VARCHAR(40) ,
 v_host_os VARCHAR(4000) ,
 v_kvm_version VARCHAR(4000) ,
 v_libvirt_version VARCHAR(4000) ,
 v_spice_version VARCHAR(4000) ,
 v_gluster_version VARCHAR(4000) ,
 v_kernel_version VARCHAR(4000) ,
 v_iscsi_initiator_name VARCHAR(4000) ,
 v_transparent_hugepages_state INTEGER ,
 v_hooks VARCHAR(4000),
 v_non_operational_reason INTEGER,
 v_hw_manufacturer VARCHAR(255),
 v_hw_product_name VARCHAR(255),
 v_hw_version VARCHAR(255),
 v_hw_serial_number VARCHAR(255),
 v_hw_uuid VARCHAR(255),
 v_hw_family VARCHAR(255),
 v_hbas VARCHAR(255),
 v_supported_emulated_machines VARCHAR(255),
 v_kdump_status SMALLINT,
 v_selinux_enforce_mode INTEGER,
 v_auto_numa_balancing SMALLINT,
 v_is_numa_supported BOOLEAN,
 v_supported_rng_sources VARCHAR(255),
 v_is_live_snapshot_supported BOOLEAN,
 v_is_live_merge_supported BOOLEAN)
RETURNS VOID
	
   AS $procedure$
BEGIN

   BEGIN
      UPDATE vds_dynamic
      SET cpu_cores = v_cpu_cores,cpu_threads = v_cpu_threads,
      cpu_model = v_cpu_model,cpu_speed_mh = v_cpu_speed_mh,
      if_total_speed = v_if_total_speed,kvm_enabled = v_kvm_enabled,
      mem_commited = v_mem_commited,physical_mem_mb = v_physical_mem_mb,
      status = v_status,vm_active = v_vm_active,vm_count = v_vm_count,
      vm_migrating = v_vm_migrating,reserved_mem = v_reserved_mem,
      guest_overhead = v_guest_overhead,rpm_version = v_rpm_version, software_version = v_software_version,
      version_name = v_version_name,build_name = v_build_name,previous_status = v_previous_status,
      cpu_flags = v_cpu_flags,cpu_over_commit_time_stamp = v_cpu_over_commit_time_stamp,
      vms_cores_count = v_vms_cores_count,pending_vcpus_count = v_pending_vcpus_count,
      pending_vmem_size = v_pending_vmem_size,
      cpu_sockets = v_cpu_sockets,net_config_dirty = v_net_config_dirty,
      supported_cluster_levels = v_supported_cluster_levels,
      supported_engines = v_supported_engines,host_os = v_host_os,
      kvm_version = v_kvm_version,libvirt_version = v_libvirt_version,spice_version = v_spice_version,
      gluster_version = v_gluster_version,
      kernel_version = v_kernel_version,iscsi_initiator_name = v_iscsi_initiator_name,
      transparent_hugepages_state = v_transparent_hugepages_state,
      hooks = v_hooks,
      _update_date = LOCALTIMESTAMP,non_operational_reason = v_non_operational_reason,
      hw_manufacturer = v_hw_manufacturer, hw_product_name = v_hw_product_name,
      hw_version = v_hw_version, hw_serial_number = v_hw_serial_number,
      hw_uuid = v_hw_uuid, hw_family = v_hw_family, hbas = v_hbas, supported_emulated_machines = v_supported_emulated_machines,
      kdump_status = v_kdump_status, selinux_enforce_mode = v_selinux_enforce_mode,
      auto_numa_balancing = v_auto_numa_balancing,
      is_numa_supported = v_is_numa_supported,
      supported_rng_sources = v_supported_rng_sources,
      is_live_snapshot_supported = v_is_live_snapshot_supported,
      is_live_merge_supported = v_is_live_merge_supported
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVdsDynamic(v_vds_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   BEGIN
      DELETE FROM vds_dynamic
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVdsDynamic() RETURNS SETOF vds_dynamic STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT vds_dynamic.*
      FROM vds_dynamic;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsDynamicByVdsId(v_vds_id UUID) RETURNS SETOF vds_dynamic STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT vds_dynamic.*
      FROM vds_dynamic
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVdsStatic(
    v_free_text_comment text,
    v_vds_id UUID,
    v_host_name VARCHAR(255),
    v_ip VARCHAR(255) ,
    v_vds_unique_id VARCHAR(128) ,
    v_port INTEGER,
    v_protocol SMALLINT,
    v_vds_group_id UUID,
    v_vds_name VARCHAR(255),
    v_server_SSL_enabled BOOLEAN ,
    v_vds_type INTEGER,
    v_vds_strength INTEGER,
    v_pm_type VARCHAR(20) ,
    v_pm_user VARCHAR(50) ,
    v_pm_password VARCHAR(50) ,
    v_pm_port INTEGER ,
    v_pm_options VARCHAR(4000) ,
    v_pm_enabled BOOLEAN,
    v_pm_proxy_preferences VARCHAR(255),
    v_pm_secondary_ip VARCHAR(255),
    v_pm_secondary_type VARCHAR(20),
    v_pm_secondary_user VARCHAR(50),
    v_pm_secondary_password text,
    v_pm_secondary_port INTEGER,
    v_pm_secondary_options VARCHAR(4000),
    v_pm_secondary_concurrent BOOLEAN,
    v_pm_detect_kdump BOOLEAN,
    v_vds_spm_priority INTEGER,
    v_sshKeyFingerprint VARCHAR(128),
    v_console_address VARCHAR(255),
    v_ssh_port INTEGER,
    v_ssh_username VARCHAR(255),
    v_disable_auto_pm BOOLEAN,
    v_host_provider_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   IF v_vds_unique_id IS NULL OR NOT EXISTS(SELECT vds_name FROM vds_static WHERE vds_unique_id = v_vds_unique_id) then
      BEGIN
         INSERT INTO vds_static(vds_id,host_name, free_text_comment, ip, vds_unique_id, port, protocol, vds_group_id, vds_name, server_SSL_enabled,
                               vds_type,vds_strength,pm_type,pm_user,pm_password,pm_port,pm_options,pm_enabled,
                               pm_proxy_preferences, pm_secondary_ip, pm_secondary_type, pm_secondary_user,
                               pm_secondary_password, pm_secondary_port, pm_secondary_options, pm_secondary_concurrent, pm_detect_kdump,
                               vds_spm_priority, sshKeyFingerprint, console_address, ssh_port, ssh_username, disable_auto_pm, host_provider_id)
			VALUES(v_vds_id,v_host_name, v_free_text_comment, v_ip, v_vds_unique_id, v_port, v_protocol, v_vds_group_id, v_vds_name, v_server_SSL_enabled,
                               v_vds_type,v_vds_strength,v_pm_type,v_pm_user,v_pm_password,v_pm_port,v_pm_options,v_pm_enabled,
                               v_pm_proxy_preferences, v_pm_secondary_ip, v_pm_secondary_type, v_pm_secondary_user,
                               v_pm_secondary_password, v_pm_secondary_port, v_pm_secondary_options, v_pm_secondary_concurrent, v_pm_detect_kdump,
                               v_vds_spm_priority, v_sshKeyFingerprint, v_console_address, v_ssh_port, v_ssh_username, v_disable_auto_pm, v_host_provider_id);
      END;
   end if;
   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVdsStatic(v_host_name VARCHAR(255),
    v_free_text_comment text,
	v_ip VARCHAR(255) ,
    v_vds_unique_id VARCHAR(128),
    v_port INTEGER,
    v_protocol SMALLINT,
    v_vds_group_id UUID,
    v_vds_id UUID,
    v_vds_name VARCHAR(255),
    v_server_SSL_enabled BOOLEAN ,
    v_vds_type INTEGER,
    v_vds_strength INTEGER,
    v_pm_type VARCHAR(20) ,
    v_pm_user VARCHAR(50) ,
    v_pm_password VARCHAR(50) ,
    v_pm_port INTEGER ,
    v_pm_options VARCHAR(4000) ,
    v_pm_enabled BOOLEAN,
    v_pm_proxy_preferences VARCHAR(255),
    v_pm_secondary_ip VARCHAR(255),
    v_pm_secondary_type VARCHAR(20),
    v_pm_secondary_user VARCHAR(50),
    v_pm_secondary_password text,
    v_pm_secondary_port INTEGER,
    v_pm_secondary_options VARCHAR(4000),
    v_pm_secondary_concurrent BOOLEAN,
    v_pm_detect_kdump BOOLEAN,
    v_otp_validity BIGINT,
    v_vds_spm_priority INTEGER,
    v_sshKeyFingerprint VARCHAR(128),
    v_console_address VARCHAR(255),
    v_ssh_port INTEGER,
    v_ssh_username VARCHAR(255),
    v_disable_auto_pm BOOLEAN,
    v_host_provider_id UUID)
RETURNS VOID
	
   AS $procedure$
BEGIN

   BEGIN
      UPDATE vds_static
      SET host_name = v_host_name, free_text_comment = v_free_text_comment, ip = v_ip,vds_unique_id = v_vds_unique_id,
      port = v_port, protocol = v_protocol, vds_group_id = v_vds_group_id,vds_name = v_vds_name,server_SSL_enabled = v_server_SSL_enabled,
      vds_type = v_vds_type,
      _update_date = LOCALTIMESTAMP,vds_strength = v_vds_strength,
      pm_type = v_pm_type,pm_user = v_pm_user,pm_password = v_pm_password,
      pm_port = v_pm_port,pm_options = v_pm_options,pm_enabled = v_pm_enabled, pm_proxy_preferences = v_pm_proxy_preferences,
      pm_secondary_ip = v_pm_secondary_ip, pm_secondary_type = v_pm_secondary_type,
      pm_secondary_user = v_pm_secondary_user, pm_secondary_password = v_pm_secondary_password,
      pm_secondary_port = v_pm_secondary_port, pm_secondary_options = v_pm_secondary_options,
      pm_secondary_concurrent = v_pm_secondary_concurrent, pm_detect_kdump = v_pm_detect_kdump,
      otp_validity = v_otp_validity, vds_spm_priority = v_vds_spm_priority, sshKeyFingerprint = v_sshKeyFingerprint, host_provider_id = v_host_provider_id,
      console_address = v_console_address, ssh_port = v_ssh_port, ssh_username = v_ssh_username, disable_auto_pm = v_disable_auto_pm
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVdsStatic(v_vds_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   BEGIN
      UPDATE vm_static
      SET dedicated_vm_for_vds = null,
          migration_support = 0
      WHERE dedicated_vm_for_vds = v_vds_id;
      DELETE FROM tags_vds_map
      WHERE vds_id = v_vds_id;
   -- Delete all Vds Alerts from the database
      PERFORM DeleteAuditLogAlertsByVdsID(v_vds_id);
      DELETE FROM vds_static
      WHERE vds_id = v_vds_id;
	-- delete VDS permissions --
      DELETE FROM permissions where object_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVdsStatic() RETURNS SETOF vds_static STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vds_static.*
   FROM vds_static;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsStaticByVdsId(v_vds_id UUID) RETURNS SETOF vds_static STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT vds_static.*
      FROM vds_static
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsStaticByHostName(v_host_name VARCHAR(255)) RETURNS SETOF vds_static STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vds_static.*
   FROM vds_static
   WHERE host_name = v_host_name;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsStaticByVdsName(v_host_name VARCHAR(255)) RETURNS SETOF vds_static STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vds_static.*
   FROM vds_static
   WHERE vds_name = v_host_name;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsStaticByIp(v_ip VARCHAR(40)) RETURNS SETOF vds_static STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT vds_static.*
      FROM vds_static
      WHERE ip = v_ip;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsByUniqueID(v_vds_unique_id VARCHAR(128)) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE vds_unique_id = v_vds_unique_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsStaticByVdsGroupId(v_vds_group_id UUID) RETURNS SETOF vds_static STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT vds_static.*
      FROM vds_static vds_static
      WHERE vds_group_id = v_vds_group_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetUpAndPrioritizedVds(v_storage_pool_id UUID) RETURNS SETOF vds STABLE
AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT vds.*
      FROM vds vds, vds_groups vdsgroup
      WHERE (vds.status = 3) AND (vds.storage_pool_id = v_storage_pool_id) AND (vds_spm_priority IS NULL OR vds_spm_priority > -1)
      AND vds.vds_group_id = vdsgroup.vds_group_id AND vdsgroup.virt_service = true
      ORDER BY vds_spm_priority DESC, RANDOM();
   END;
   RETURN;
END; $procedure$
  LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVds(v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                          FROM user_vds_permissions_view
                                          WHERE user_id = v_user_id AND entity_id = vds_id));
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsByVdsId(v_vds_id UUID, v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF vds STABLE
   AS $procedure$
DECLARE
v_columns text[];
BEGIN
    BEGIN
      if (v_is_filtered) then
          RETURN QUERY SELECT DISTINCT (rec).*
          FROM fn_db_mask_object('vds') as q (rec vds)
          WHERE (rec).vds_id = v_vds_id
          AND EXISTS (SELECT 1
              FROM   user_vds_permissions_view
              WHERE  user_id = v_user_id AND entity_id = v_vds_id);
      else
          RETURN QUERY SELECT DISTINCT vds.*
          FROM vds
          WHERE vds_id = v_vds_id;
      end if;
    END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsWithoutMigratingVmsByVdsGroupId(v_vds_group_id UUID) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN


	-- this sp returns all vds in given cluster that have no pending vms and no vms in migration states
	BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE vds_group_id = v_vds_group_id and
      pending_vcpus_count = 0
      and	vds.status = 3
      and	vds_id not in(select distinct RUN_ON_VDS from vm_dynamic
         where status in(5,6,11,12));
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVds(v_vds_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   BEGIN
      UPDATE vm_static
      SET dedicated_vm_for_vds = null
      WHERE dedicated_vm_for_vds = v_vds_id;
      DELETE FROM tags_vds_map
      WHERE vds_id = v_vds_id;
   -- Delete all Vds Alerts from the database
      PERFORM DeleteAuditLogAlertsByVdsID(v_vds_id);
      DELETE FROM vds_statistics WHERE vds_id = v_vds_id;
      DELETE FROM vds_dynamic WHERE vds_id = v_vds_id;
      DELETE FROM vds_static WHERE vds_id = v_vds_id;
      DELETE FROM permissions where object_id = v_vds_id;
   END;
   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsByType(v_vds_type INTEGER) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE vds_type = v_vds_type;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsByName(v_vds_name VARCHAR(255)) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE vds_name = v_vds_name;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsByHostName(v_host_name VARCHAR(255)) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE host_name = v_host_name;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsByIp(v_ip VARCHAR(40)) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM vds
      WHERE ip = v_ip;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsByVdsGroupId(v_vds_group_id UUID, v_user_id UUID, v_is_filtered boolean) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
	-- this sp returns all vds for a given cluster
   BEGIN
      if (v_is_filtered) then
          RETURN QUERY SELECT DISTINCT (rec).*
          FROM fn_db_mask_object('vds') as q (rec vds)
          WHERE (rec).vds_group_id = v_vds_group_id
          AND EXISTS (SELECT 1
              FROM   user_vds_permissions_view
              WHERE  user_id = v_user_id AND entity_id = (rec).vds_id);
      else
          RETURN QUERY SELECT DISTINCT vds.*
          FROM vds
          WHERE vds_group_id = v_vds_group_id;
      end if;
    END;
    RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsByStoragePoolId(v_storage_pool_id UUID, v_user_id UUID, v_is_filtered boolean) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT DISTINCT vds.*
      FROM   vds
      WHERE  storage_pool_id = v_storage_pool_id
      AND    (NOT v_is_filtered OR EXISTS (SELECT 1
                                           FROM   user_vds_permissions_view
                                           WHERE  user_id = v_user_id AND entity_id = vds_id));
   END;
   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION getVdsForVdsGroupWithStatus(v_vds_group_id UUID, v_status integer) RETURNS SETOF vds STABLE
    AS $procedure$
BEGIN
    BEGIN
        RETURN QUERY SELECT vds.*
        FROM vds
        WHERE (status = v_status) AND (vds_group_id = v_vds_group_id)
        ORDER BY vds.vds_id ASC;
    END;
    RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION getVdsByStoragePoolIdWithStatus(v_storage_pool_id UUID, v_status integer) RETURNS SETOF vds STABLE
    AS $procedure$
BEGIN
    BEGIN
        RETURN QUERY SELECT vds.*
        FROM vds
        INNER JOIN vds_groups vdsgroup ON vds.vds_group_id = vdsgroup.vds_group_id
        WHERE (vds.status = v_status) AND (vds.storage_pool_id = v_storage_pool_id)
        AND vdsgroup.virt_service = true;
    END;
    RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION getHostsForStorageOperation(v_storage_pool_id UUID, v_local_fs_only BOOLEAN) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
    BEGIN
        RETURN QUERY SELECT vds.*
        FROM vds
        LEFT JOIN vds_groups vg ON vds.vds_group_id = vg.vds_group_id
        LEFT JOIN storage_pool sp ON vds.storage_pool_id = sp.id
        WHERE (v_storage_pool_id IS NULL OR vds.storage_pool_id = v_storage_pool_id)
        AND (vg.virt_service = true)
        AND (NOT v_local_fs_only OR sp.is_local = true)
        AND (v_storage_pool_id IS NOT NULL OR vds.status = 3); -- if DC is unspecified return only hosts with status = UP
    END;
    RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVdsDynamicStatus(
        v_vds_guid UUID,
        v_status INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE vds_dynamic
      SET
      status = v_status
      WHERE vds_id = v_vds_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVdsDynamicNetConfigDirty(
        v_vds_guid UUID,
        v_net_config_dirty BOOLEAN)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE vds_dynamic
      SET
      net_config_dirty = v_net_config_dirty
      WHERE vds_id = v_vds_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdatePartialVdsDynamicCalc(
        v_vds_guid UUID,
        v_vmCount INTEGER,
        v_pendingVcpusCount INTEGER,
        v_pendingVmemSize INTEGER,
        v_memCommited INTEGER,
        v_vmsCoresCount INTEGER)
RETURNS VOID
   AS $procedure$
DECLARE
    sign int;
BEGIN
	IF (v_memCommited = 0 ) THEN
	  sign = 0;
	ELSEIF (v_memCommited > 0) THEN
	  sign = 1;
	ELSE
	  sign = -1;
	END IF;

    UPDATE vds_dynamic
    SET
      vm_count = GREATEST(vm_count + v_vmCount, 0),
      pending_vcpus_count = GREATEST(pending_vcpus_count + v_pendingVcpusCount, 0),
      pending_vmem_size = GREATEST(pending_vmem_size + v_pendingVmemSize, 0),
      mem_commited = GREATEST(mem_commited + sign * (abs(v_memCommited) + guest_overhead), 0),
      vms_cores_count = GREATEST(vms_cores_count + v_vmsCoresCount, 0)
    WHERE vds_id = v_vds_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsByNetworkId(v_network_id UUID) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vds
   WHERE EXISTS (
      SELECT 1
      FROM vds_interface
      INNER JOIN network
      ON network.name = vds_interface.network_name
      INNER JOIN network_cluster
      ON network.id = network_cluster.network_id
      WHERE network_id = v_network_id
      AND vds.vds_group_id = network_cluster.cluster_id
      AND vds_interface.vds_id = vds.vds_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsWithoutNetwork(v_network_id UUID) RETURNS SETOF vds STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT vds.*
   FROM vds
   INNER JOIN network_cluster
   ON vds.vds_group_id = network_cluster.cluster_id
   WHERE network_cluster.network_id = v_network_id
   AND NOT EXISTS (
      SELECT 1
      FROM vds_interface
      INNER JOIN network
      ON network.name = vds_interface.network_name
      INNER JOIN network_cluster
      ON network.id = network_cluster.network_id
      WHERE network_cluster.network_id = v_network_id
      AND vds.vds_group_id = network_cluster.cluster_id
      AND vds_interface.vds_id = vds.vds_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateCpuFlags(
  v_vds_id UUID,
  v_cpu_flags VARCHAR(4000))
  RETURNS VOID
AS $procedure$
BEGIN
      UPDATE vds_dynamic
      SET
      cpu_flags = v_cpu_flags
      WHERE vds_id = v_vds_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVdsCpuStatistics(v_vds_cpu_id UUID,
 v_vds_id UUID,
 v_cpu_core_id INTEGER,
 v_cpu_sys DECIMAL(18,0),
 v_cpu_user DECIMAL(18,0),
 v_cpu_idle DECIMAL(18,0),
 v_usage_cpu_percent INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN

   BEGIN
      INSERT INTO vds_cpu_statistics(vds_cpu_id, vds_id, cpu_core_id, cpu_sys, cpu_user, cpu_idle, usage_cpu_percent)
      VALUES(v_vds_cpu_id, v_vds_id, v_cpu_core_id, v_cpu_sys, v_cpu_user, v_cpu_idle, v_usage_cpu_percent);
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVdsCpuStatistics(v_vds_id UUID,
 v_cpu_core_id INTEGER,
 v_cpu_sys DECIMAL(18,0),
 v_cpu_user DECIMAL(18,0),
 v_cpu_idle DECIMAL(18,0),
 v_usage_cpu_percent INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN

   BEGIN
      UPDATE vds_cpu_statistics
      SET cpu_sys = v_cpu_sys, cpu_user = v_cpu_user, cpu_idle = v_cpu_idle,
      usage_cpu_percent = v_usage_cpu_percent
      WHERE vds_id = v_vds_id and cpu_core_id = v_cpu_core_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVdsCpuStatisticsByVdsId(v_vds_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
   BEGIN
      DELETE FROM vds_cpu_statistics
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVdsCpuStatisticsByVdsId(v_vds_id UUID) RETURNS SETOF vds_cpu_statistics STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT vds_cpu_statistics.*
      FROM vds_cpu_statistics
      WHERE vds_id = v_vds_id;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVdsCpuStatistics() RETURNS SETOF vds_cpu_statistics STABLE
   AS $procedure$
BEGIN
   BEGIN
      RETURN QUERY SELECT vds_cpu_statistics.*
      FROM vds_cpu_statistics;
   END;

   RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVmDevice(
    v_device_id UUID,
    v_vm_id UUID,
    v_device varchar(30),
    v_type varchar(30),
    v_address varchar(255),
    v_boot_order int,
    v_spec_params text,
    v_is_managed boolean,
    v_is_plugged boolean,
    v_is_readonly boolean,
    v_alias varchar(255),
    v_custom_properties text,
    v_snapshot_id uuid)
RETURNS VOID
AS $procedure$
BEGIN
    INSERT INTO vm_device(
        device_id,
        vm_id ,
        device ,
        type,
        address ,
        boot_order ,
        spec_params,
        is_managed,
        is_plugged,
        is_readonly,
        alias,
        custom_properties,
        snapshot_id)
    VALUES(
        v_device_id ,
        v_vm_id ,
        v_device ,
        v_type ,
        v_address ,
        v_boot_order ,
        v_spec_params,
        v_is_managed,
        v_is_plugged,
        v_is_readonly,
        v_alias,
        v_custom_properties,
        v_snapshot_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmDevice(
    v_device_id UUID,
    v_vm_id UUID,
    v_device varchar(30),
    v_type varchar(30),
    v_address varchar(255),
    v_boot_order int,
    v_spec_params text,
    v_is_managed boolean,
    v_is_plugged boolean,
    v_is_readonly boolean,
    v_alias varchar(255),
    v_custom_properties text,
    v_snapshot_id uuid)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE vm_device
    SET
           device = v_device,
           type = v_type,
           address = v_address,
           boot_order = v_boot_order,
           spec_params = v_spec_params,
           is_managed = v_is_managed,
           is_plugged = v_is_plugged,
           is_readonly = v_is_readonly,
           alias = v_alias,
           custom_properties = v_custom_properties,
           snapshot_id = v_snapshot_id,
           _update_date = current_timestamp
    WHERE  device_id = v_device_id and vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmDeviceRuntimeInfo(
    v_device_id UUID,
    v_vm_id UUID,
    v_address varchar(255),
    v_alias varchar(255))
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE vm_device
    SET
           address = v_address,
           alias = v_alias,
           _update_date = current_timestamp
    WHERE  device_id = v_device_id and vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmDeviceForHotPlugDisk(
    v_device_id UUID,
    v_vm_id UUID,
    v_is_plugged boolean)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE vm_device
    SET
           is_plugged = v_is_plugged,
           _update_date = current_timestamp
    WHERE  device_id = v_device_id and vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmDeviceBootOrder(
    v_device_id UUID,
    v_vm_id UUID,
    v_boot_order int)
RETURNS VOID
AS $procedure$
BEGIN
    UPDATE vm_device
    SET
           boot_order = v_boot_order,
           _update_date = current_timestamp
    WHERE  device_id = v_device_id and vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVmDevice(v_device_id UUID, v_vm_id UUID)
RETURNS VOID
AS $procedure$
BEGIN
    DELETE
    FROM   vm_device
    WHERE  device_id = v_device_id
    AND (v_vm_id IS NULL or vm_id = v_vm_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVmDevice() RETURNS SETOF vm_device_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vm_device_view;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmDeviceByDeviceId(v_device_id UUID, v_vm_id UUID)
RETURNS SETOF vm_device_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vm_device_view
    WHERE  device_id = v_device_id
    AND (v_vm_id IS NULL OR vm_id = v_vm_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmDeviceByVmId(v_vm_id UUID)
RETURNS SETOF vm_device_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vm_device_view
    WHERE  vm_id = v_vm_id order by device_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmDeviceByVmIdAndType(v_vm_id UUID, v_type varchar(30))
RETURNS SETOF vm_device_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vm_device_view
    WHERE  vm_id = v_vm_id and type = v_type
    ORDER BY NULLIF(alias,'') NULLS LAST;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmDeviceByVmIdTypeAndDevice(v_vm_id UUID, v_type varchar(30), v_device varchar(30), v_user_id UUID, v_is_filtered BOOLEAN)
RETURNS SETOF vm_device_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    SELECT *
    FROM   vm_device_view
    WHERE  vm_id = v_vm_id and type = v_type and device = v_device
    AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                      FROM   user_vm_permissions_view
                                      WHERE  user_id = v_user_id AND entity_id = v_vm_id))
    ORDER BY NULLIF(alias,'') NULLS LAST;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION GetVmUnmanagedDevicesByVmId(v_vm_id UUID)
RETURNS SETOF vm_device_view STABLE
AS $procedure$
BEGIN
    RETURN QUERY
    select vm_device_view.* from vm_device_view
    where vm_id = v_vm_id and
          is_managed = false;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION isMemBalloonEnabled(v_vm_id UUID)
  RETURNS boolean STABLE AS
$BODY$
declare
    result boolean := false;
begin
    if exists (select 1 from vm_device where vm_id = v_vm_id and type = 'balloon' and device = 'memballoon') then
        result := true;
    end if;
    return result;
end;
$BODY$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION clearVmDeviceAddress(v_device_id UUID)
  RETURNS VOID AS
$BODY$
begin
    update vm_device set address = '' where device_id = v_device_id;
end;
$BODY$
LANGUAGE 'plpgsql';
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllVmJobIds() RETURNS SETOF uuid STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_jobs.vm_job_id
      FROM vm_jobs;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmJobsByVmId(v_vm_id uuid) RETURNS SETOF vm_jobs STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm_jobs.*
   FROM vm_jobs
   WHERE vm_jobs.vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmJobsByVmAndImage(v_vm_id uuid, v_image_group_id uuid) RETURNS SETOF vm_jobs STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm_jobs.*
   FROM vm_jobs
   WHERE vm_jobs.vm_id = v_vm_id
     AND vm_jobs.image_group_id = v_image_group_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmJobs(
    v_vm_job_id UUID,
    v_vm_id UUID,
    v_job_state INTEGER,
    v_job_type INTEGER,
    v_block_job_type INTEGER,
    v_bandwidth INTEGER,
    v_cursor_cur BIGINT,
    v_cursor_end BIGINT,
    v_image_group_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE vm_jobs
      SET vm_job_id=v_vm_job_id, vm_id=v_vm_id, job_state=v_job_state, job_type=v_job_type,
          block_job_type=v_block_job_type, bandwidth=v_bandwidth, cursor_cur=v_cursor_cur,
          cursor_end=v_cursor_end, image_group_id=v_image_group_id
      WHERE vm_job_id = v_vm_job_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVmJobs(v_vm_job_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM vm_jobs
      WHERE vm_job_id = v_vm_job_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVmJobs(
    v_vm_job_id UUID,
    v_vm_id UUID,
    v_job_state INTEGER,
    v_job_type INTEGER,
    v_block_job_type INTEGER,
    v_bandwidth INTEGER,
    v_cursor_cur BIGINT,
    v_cursor_end BIGINT,
    v_image_group_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO vm_jobs(vm_job_id, vm_id, job_state, job_type, block_job_type, bandwidth,
                    cursor_cur, cursor_end, image_group_id)
       VALUES (v_vm_job_id, v_vm_id, v_job_state, v_job_type, v_block_job_type, v_bandwidth,
               v_cursor_cur, v_cursor_end, v_image_group_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVm_pool_map(v_vm_guid UUID,
 v_vm_pool_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO vm_pool_map(vm_guid, vm_pool_id)
	VALUES(v_vm_guid, v_vm_pool_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVm_pool_map(v_vm_guid UUID,
 v_vm_pool_id UUID)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE vm_pool_map
      SET vm_pool_id = v_vm_pool_id
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVm_pool_map(v_vm_guid UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  VARCHAR(50);
BEGIN
		-- Get (and keep) a shared lock with "right to upgrade to exclusive"
		-- in order to force locking parent before children
      select   vm_guid INTO v_val FROM vm_pool_map  WHERE vm_guid = v_vm_guid     FOR UPDATE;
      DELETE FROM vm_pool_map
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVm_pool_map() RETURNS SETOF vm_pool_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_pool_map.*
      FROM vm_pool_map;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVm_pool_mapByvm_pool_id(v_vm_pool_id UUID) RETURNS SETOF vm_pool_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_pool_map.*
      FROM vm_pool_map INNER JOIN vm_static
      ON vm_pool_map.vm_guid = vm_static.vm_guid
      WHERE vm_pool_id = v_vm_pool_id
      ORDER BY vm_static.VM_NAME;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION getVmMapsInVmPoolByVmPoolIdAndStatus(v_vm_pool_id UUID, v_status INTEGER) RETURNS SETOF vm_pool_map STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_pool_id, vm_pool_map.vm_guid
      FROM vm_pool_map, vm_dynamic
      WHERE vm_pool_map.vm_guid = vm_dynamic.vm_guid
      AND vm_pool_id = v_vm_pool_id
      AND vm_dynamic.status = v_status;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVm_pools(v_vm_pool_description VARCHAR(4000),
 v_vm_pool_comment text,
 v_vm_pool_id UUID ,
 v_vm_pool_name VARCHAR(255),
 v_vm_pool_type INTEGER,
 v_parameters VARCHAR(200),
 v_prestarted_vms INTEGER,
 v_vds_group_id UUID,
 v_max_assigned_vms_per_user SMALLINT,
 v_spice_proxy VARCHAR(255))
RETURNS VOID
   AS $procedure$
BEGIN
      INSERT INTO vm_pools(vm_pool_id,vm_pool_description, vm_pool_comment, vm_pool_name, vm_pool_type,parameters, prestarted_vms, vds_group_id, max_assigned_vms_per_user, spice_proxy)
      VALUES(v_vm_pool_id,v_vm_pool_description, v_vm_pool_comment, v_vm_pool_name,v_vm_pool_type,v_parameters, v_prestarted_vms, v_vds_group_id, v_max_assigned_vms_per_user, v_spice_proxy);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVm_pools(v_vm_pool_description VARCHAR(4000),
 v_vm_pool_comment text,
 v_vm_pool_id UUID,
 v_vm_pool_name VARCHAR(255),
 v_vm_pool_type INTEGER,
 v_parameters VARCHAR(200),
 v_prestarted_vms INTEGER,
 v_vds_group_id UUID,
 v_max_assigned_vms_per_user SMALLINT,
 v_spice_proxy VARCHAR(255))
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE vm_pools
      SET vm_pool_description = v_vm_pool_description, vm_pool_comment = v_vm_pool_comment, vm_pool_name = v_vm_pool_name,
      vm_pool_type = v_vm_pool_type,parameters = v_parameters, prestarted_vms = v_prestarted_vms, vds_group_id = v_vds_group_id,
      max_assigned_vms_per_user = v_max_assigned_vms_per_user, spice_proxy = v_spice_proxy
      WHERE vm_pool_id = v_vm_pool_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVm_pools(v_vm_pool_id UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN
		-- Get (and keep) a shared lock with "right to upgrade to exclusive"
		-- in order to force locking parent before children
      select   vm_pool_id INTO v_val FROM vm_pools  WHERE vm_pool_id = v_vm_pool_id     FOR UPDATE;
      DELETE FROM vm_pools
      WHERE vm_pool_id = v_vm_pool_id;

		-- delete VmPool permissions --
      DELETE FROM permissions where object_id = v_vm_pool_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS GetAllFromVm_pools_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
Create type GetAllFromVm_pools_rs AS (vm_pool_id UUID, assigned_vm_count INTEGER, vm_running_count INTEGER, vm_pool_description VARCHAR(4000), vm_pool_comment text, vm_pool_name VARCHAR(255), vm_pool_type INTEGER, parameters VARCHAR(200), prestarted_vms INTEGER, vds_group_id UUID, vds_group_name VARCHAR(40), max_assigned_vms_per_user SMALLINT, spice_proxy VARCHAR(255));
**************************

CREATE TYPE
********* QUERY **********
Create or replace FUNCTION GetAllFromVm_pools() RETURNS SETOF GetAllFromVm_pools_rs
   AS $procedure$
BEGIN
      -- BEGIN TRAN
BEGIN
         CREATE TEMPORARY TABLE tt_VM_POOL_GROUP
         (
            vm_pool_id UUID,
            assigned_vm_count INTEGER
         ) WITH OIDS;
         exception when others then
            truncate table tt_VM_POOL_GROUP;
      END;
      insert INTO tt_VM_POOL_GROUP(vm_pool_id,
					assigned_vm_count)
      select
      vm_pools_view.vm_pool_id,
			  count(vm_pool_map.vm_pool_id)
      from vm_pools_view
      left join vm_pool_map on vm_pools_view.vm_pool_id = vm_pool_map.vm_pool_id
      group by vm_pools_view.vm_pool_id,vm_pool_map.vm_pool_id;
      BEGIN
         CREATE TEMPORARY TABLE tt_VM_POOL_RUNNING
         (
            vm_pool_id UUID,
            vm_running_count INTEGER
         ) WITH OIDS;
         exception when others then
            truncate table tt_VM_POOL_RUNNING;
      END;
      insert INTO tt_VM_POOL_RUNNING(vm_pool_id,
					vm_running_count)
      select vm_pools_view.vm_pool_id, count(vm_pools_view.vm_pool_id)
      from vm_pools_view
      left join vm_pool_map on vm_pools_view.vm_pool_id = vm_pool_map.vm_pool_id
      left join vm_dynamic on vm_pool_map.vm_guid = vm_dynamic.vm_guid
      where vm_dynamic.status > 0
      group by vm_pools_view.vm_pool_id;
      BEGIN
         CREATE TEMPORARY TABLE tt_VM_POOL_PRERESULT
         (
            vm_pool_id UUID,
            assigned_vm_count INTEGER,
            vm_running_count INTEGER
         ) WITH OIDS;
         exception when others then
            truncate table tt_VM_POOL_PRERESULT;
      END;
      insert INTO tt_VM_POOL_PRERESULT(vm_pool_id,
					assigned_vm_count,
					vm_running_count)
      select pg.vm_pool_id, pg.assigned_vm_count, pr.vm_running_count
      from tt_VM_POOL_GROUP pg
      left join tt_VM_POOL_RUNNING pr on pg.vm_pool_id = pr.vm_pool_id;
      update tt_VM_POOL_PRERESULT
      set vm_running_count = 0
      where vm_running_count is NULL;
      BEGIN
         CREATE TEMPORARY TABLE tt_VM_POOL_RESULT
         (
            vm_pool_id UUID,
            assigned_vm_count INTEGER,
            vm_running_count INTEGER,
            vm_pool_description VARCHAR(4000),
            vm_pool_comment text,
            vm_pool_name VARCHAR(255),
            vm_pool_type INTEGER,
            parameters VARCHAR(200),
            prestarted_vms INTEGER,
            vds_group_id UUID,
            vds_group_name VARCHAR(40),
            max_assigned_vms_per_user SMALLINT,
            spice_proxy VARCHAR(255)
         ) WITH OIDS;
         exception when others then
            truncate table tt_VM_POOL_RESULT;
      END;
      insert INTO tt_VM_POOL_RESULT(vm_pool_id,
            assigned_vm_count,
            vm_running_count,
            vm_pool_description,
            vm_pool_comment,
            vm_pool_name,
            vm_pool_type,
            parameters,
            prestarted_vms,
            vds_group_id,
            vds_group_name,
            max_assigned_vms_per_user,
            spice_proxy)
      select ppr.vm_pool_id, ppr.assigned_vm_count, ppr.vm_running_count,
  				 p.vm_pool_description, p.vm_pool_comment, p.vm_pool_name, p.vm_pool_type, p.parameters, p.prestarted_vms,
					 p.vds_group_id, p.vds_group_name, p.max_assigned_vms_per_user, p.spice_proxy
      from tt_VM_POOL_PRERESULT ppr
      inner join vm_pools_view p on ppr.vm_pool_id = p.vm_pool_id;
      RETURN QUERY select *
      from tt_VM_POOL_RESULT;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVm_poolsByvm_pool_id(v_vm_pool_id UUID, v_user_id UUID, v_is_filtered BOOLEAN) RETURNS SETOF vm_pools_full_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_pools_full_view.*
      FROM vm_pools_full_view
      WHERE vm_pool_id = v_vm_pool_id
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_pool_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = v_vm_pool_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVm_poolsByvm_pool_name(v_vm_pool_name VARCHAR(255)) RETURNS SETOF vm_pools_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_pools_view.*
      FROM vm_pools_view
      WHERE vm_pool_name = v_vm_pool_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllVm_poolsByUser_id(v_user_id UUID) RETURNS SETOF vm_pools_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT  DISTINCT vm_pools_view.*
      FROM         users_and_groups_to_vm_pool_map_view INNER JOIN
      vm_pools_view ON
      users_and_groups_to_vm_pool_map_view.vm_pool_id = vm_pools_view.vm_pool_id
      WHERE     (users_and_groups_to_vm_pool_map_view.user_id = v_user_id);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVm_poolsByAdGroup_names(v_ad_group_names VARCHAR(4000)) RETURNS SETOF vm_pools_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT vm_pools_view.*
      FROM         ad_groups INNER JOIN
      users_and_groups_to_vm_pool_map_view ON
      ad_groups.id = users_and_groups_to_vm_pool_map_view.user_id INNER JOIN
      vm_pools_view ON users_and_groups_to_vm_pool_map_view.vm_pool_id = vm_pools_view.vm_pool_id
      WHERE     (ad_groups.name in(select Id from fnSplitter(v_ad_group_names)));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetVmDataFromPoolByPoolId(v_pool_id uuid, v_user_id uuid, v_is_filtered boolean)
  RETURNS SETOF vms STABLE AS $procedure$
BEGIN
     RETURN QUERY SELECT vms.*
     FROM vms WHERE vm_pool_id = v_pool_id
     AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_vm_pool_permissions_view
                                       WHERE  user_id = v_user_id AND entity_id = v_pool_id))
     -- Limiting results to 1 since we only need a single VM from the pool to retrieve the pool data
     LIMIT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION GetVmDataFromPoolByPoolName(v_pool_name VARCHAR(4000), v_user_id uuid, v_is_filtered boolean)
  RETURNS SETOF vms STABLE AS $procedure$
BEGIN
     RETURN QUERY SELECT vms.*
     FROM vms WHERE vm_pool_name = v_pool_name
     AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_vm_pool_permissions_view
                                       WHERE  user_id = v_user_id AND entity_id = vms.vm_guid))
     -- Limiting results to 1 since we only need a single VM from the pool to retrieve the pool data
     LIMIT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateOvfGenerations(v_vms_ids VARCHAR(5000), v_vms_db_generations VARCHAR(5000), v_ovf_data TEXT, v_ovf_data_seperator VARCHAR(10))
    RETURNS VOID
    AS $procedure$
DECLARE
curs_vmids CURSOR FOR SELECT * FROM fnSplitterUuid(v_vms_ids);
curs_newovfgen CURSOR FOR SELECT * FROM fnSplitter(v_vms_db_generations);
curs_newovfdata CURSOR FOR SELECT * FROM fnSplitterWithSeperator(v_ovf_data, v_ovf_data_seperator);
id UUID;
new_ovf_gen BIGINT;
new_ovf_config TEXT;
BEGIN
 OPEN curs_vmids;
 OPEN curs_newovfgen;
 OPEN curs_newovfdata;
LOOP
    FETCH curs_vmids INTO id;
    FETCH curs_newovfgen INTO new_ovf_gen;
    FETCH curs_newovfdata INTO new_ovf_config;
    IF NOT FOUND THEN
     EXIT;
    END IF;
    UPDATE vm_ovf_generations
    SET ovf_generation = new_ovf_gen, ovf_data = new_ovf_config WHERE vm_guid = id;
END LOOP;
CLOSE curs_vmids;
CLOSE curs_newovfgen;
CLOSE curs_newovfdata;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION LoadOvfDataForIds(v_ids VARCHAR(5000)) RETURNS SETOF vm_ovf_generations STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
   FROM vm_ovf_generations ovf
   WHERE ovf.vm_guid IN (SELECT * FROM fnSplitterUuid(v_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetIdsForOvfDeletion(v_storage_pool_id UUID) RETURNS SETOF UUID STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT ovf.vm_guid as vm_guid
   FROM vm_ovf_generations ovf
   WHERE ovf.storage_pool_id = v_storage_pool_id AND ovf.vm_guid NOT IN (SELECT vm_guid FROM vm_static);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetOvfGeneration(v_vm_id UUID) RETURNS SETOF BIGINT STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm.ovf_generation
   FROM vm_ovf_generations vm
   WHERE vm.vm_guid = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplatesIdsForOvfUpdate(v_storage_pool_id UUID) RETURNS SETOF UUID STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT templates.vmt_guid as vm_guid
   FROM vm_templates_view templates, vm_ovf_generations generations
   WHERE generations.vm_guid = templates.vmt_guid
   AND templates.db_generation > generations.ovf_generation
   AND templates.storage_pool_id = v_storage_pool_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsIdsForOvfUpdate(v_storage_pool_id UUID) RETURNS SETOF UUID STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm.vm_guid as vm_guid
   FROM vms vm, vm_ovf_generations ovf_gen
   WHERE vm.vm_guid = ovf_gen.vm_guid
         AND vm.db_generation >  ovf_gen.ovf_generation
         AND vm.storage_pool_id = v_storage_pool_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteOvfGenerations(v_vms_ids VARCHAR(5000))
    RETURNS VOID
    AS $procedure$
BEGIN
    DELETE FROM vm_ovf_generations WHERE vm_guid IN (SELECT * FROM fnSplitterUuid(v_vms_ids))
    -- needed here to ensure that vm with the same id hasn't been added by import vm/template command
    AND vm_guid NOT IN (SELECT vm_guid FROM vm_static);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVmStatistics(v_cpu_sys DECIMAL(18,0) ,
	v_cpu_user DECIMAL(18,0) ,
	v_elapsed_time DECIMAL(18,0) ,
	v_usage_cpu_percent INTEGER ,
	v_usage_mem_percent INTEGER ,
	v_migration_progress_percent INTEGER ,
	v_usage_network_percent INTEGER ,
	v_disks_usage TEXT,
	v_vm_guid UUID)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO vm_statistics(cpu_sys, cpu_user, elapsed_time, usage_cpu_percent, usage_mem_percent, migration_progress_percent, usage_network_percent, disks_usage, vm_guid)
	VALUES(v_cpu_sys, v_cpu_user, v_elapsed_time, v_usage_cpu_percent, v_usage_mem_percent, v_migration_progress_percent, v_usage_network_percent, v_disks_usage, v_vm_guid);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmStatistics(v_cpu_sys DECIMAL(18,0) ,
	v_cpu_user DECIMAL(18,0) ,
	v_elapsed_time DECIMAL(18,0) ,
	v_usage_cpu_percent INTEGER ,
	v_migration_progress_percent INTEGER ,
	v_usage_mem_percent INTEGER ,
	v_usage_network_percent INTEGER ,
	v_disks_usage TEXT ,
	v_vm_guid UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE vm_statistics
      SET cpu_sys = v_cpu_sys,cpu_user = v_cpu_user,elapsed_time = v_elapsed_time,
      usage_cpu_percent = v_usage_cpu_percent,usage_mem_percent = v_usage_mem_percent, migration_progress_percent = v_migration_progress_percent,
      usage_network_percent = v_usage_network_percent,disks_usage = v_disks_usage, _update_date = LOCALTIMESTAMP
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVmStatistics(v_vm_guid UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM vm_statistics
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVmStatistics() RETURNS SETOF vm_statistics STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_statistics.*
      FROM vm_statistics;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmStatisticsByVmGuid(v_vm_guid UUID) RETURNS SETOF vm_statistics STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_statistics.*
      FROM vm_statistics
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVmDynamic(v_app_list text ,
	v_guest_cur_user_name VARCHAR(255) ,
	v_console_cur_user_name VARCHAR(255) ,
	v_guest_last_login_time TIMESTAMP WITH TIME ZONE ,
	v_guest_last_logout_time TIMESTAMP WITH TIME ZONE ,
        v_console_user_id UUID,
	v_guest_os VARCHAR(255) ,
	v_migrating_to_vds UUID ,
	v_run_on_vds UUID ,
	v_status INTEGER,
	v_vm_guid UUID,
	v_vm_host VARCHAR(255) ,
	v_vm_ip VARCHAR(255) ,
	v_vm_fqdn VARCHAR(255) ,
	v_last_start_time TIMESTAMP WITH TIME ZONE ,
	v_last_stop_time TIMESTAMP WITH TIME ZONE ,
	v_vm_pid INTEGER ,
	v_display INTEGER ,
	v_acpi_enable BOOLEAN ,
	v_session INTEGER ,
	v_display_ip VARCHAR(255) ,
	v_display_type INTEGER ,
	v_kvm_enable BOOLEAN ,
	v_boot_sequence INTEGER ,
	v_display_secure_port INTEGER ,
	v_utc_diff INTEGER ,
	v_last_vds_run_on UUID ,
	v_client_ip VARCHAR(255),
	v_guest_requested_memory  INTEGER ,
	v_hibernation_vol_handle VARCHAR(255) ,
	v_exit_status INTEGER,
	v_pause_status INTEGER,
	v_exit_message VARCHAR(4000),
	v_guest_agent_nics_hash INTEGER,
  v_last_watchdog_event NUMERIC,
  v_last_watchdog_action VARCHAR(8),
  v_is_run_once BOOLEAN,
  v_cpu_name VARCHAR(255),
  v_current_cd VARCHAR(4000),
  v_exit_reason INTEGER,
  v_guest_cpu_count INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO vm_dynamic(app_list, guest_cur_user_name, console_cur_user_name, guest_last_login_time, guest_last_logout_time, console_user_id, guest_os, migrating_to_vds, RUN_ON_VDS, status, vm_guid, vm_host, vm_ip, last_start_time, last_stop_time, vm_pid, display, acpi_enable, session, display_ip, display_type, kvm_enable, boot_sequence, display_secure_port, utc_diff, last_vds_run_on, client_ip, guest_requested_memory, hibernation_vol_handle,exit_status,pause_status,exit_message, guest_agent_nics_hash, last_watchdog_event, last_watchdog_action, is_run_once, vm_fqdn, cpu_name, current_cd, exit_reason, guest_cpu_count)
	VALUES(v_app_list, v_guest_cur_user_name, v_console_cur_user_name, v_guest_last_login_time, v_guest_last_logout_time, v_console_user_id, v_guest_os, v_migrating_to_vds, v_run_on_vds, v_status, v_vm_guid, v_vm_host, v_vm_ip, v_last_start_time, v_last_stop_time, v_vm_pid, v_display, v_acpi_enable, v_session, v_display_ip, v_display_type, v_kvm_enable, v_boot_sequence, v_display_secure_port, v_utc_diff, v_last_vds_run_on, v_client_ip, v_guest_requested_memory, v_hibernation_vol_handle, v_exit_status, v_pause_status, v_exit_message, v_guest_agent_nics_hash, v_last_watchdog_event, v_last_watchdog_action, v_is_run_once, v_vm_fqdn, v_cpu_name, v_current_cd, v_exit_reason,
         v_guest_cpu_count);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmDynamic(v_app_list text ,
	v_guest_cur_user_name VARCHAR(255) ,
	v_console_cur_user_name VARCHAR(255) ,
	v_guest_last_login_time TIMESTAMP WITH TIME ZONE ,
	v_guest_last_logout_time TIMESTAMP WITH TIME ZONE ,
        v_console_user_id UUID,
	v_guest_os VARCHAR(255) ,
	v_migrating_to_vds UUID ,
	v_run_on_vds UUID ,
	v_status INTEGER,
	v_vm_guid UUID,
	v_vm_host VARCHAR(255) ,
	v_vm_ip VARCHAR(255) ,
	v_vm_fqdn VARCHAR(255) ,
	v_last_start_time TIMESTAMP WITH TIME ZONE ,
	v_last_stop_time TIMESTAMP WITH TIME ZONE ,
	v_vm_pid INTEGER ,
	v_display INTEGER ,
	v_acpi_enable BOOLEAN ,
	v_session INTEGER ,
	v_display_ip VARCHAR(255) ,
	v_display_type INTEGER ,
	v_kvm_enable BOOLEAN ,
	v_boot_sequence INTEGER ,
	v_display_secure_port INTEGER ,
	v_utc_diff INTEGER ,
	v_last_vds_run_on UUID ,
	v_client_ip VARCHAR(255) ,
	v_guest_requested_memory INTEGER ,
	v_hibernation_vol_handle VARCHAR(255) ,
	v_exit_status INTEGER,
	v_pause_status INTEGER,
	v_exit_message VARCHAR(4000),
  v_hash VARCHAR(30),
  v_guest_agent_nics_hash INTEGER,
  v_last_watchdog_event NUMERIC,
  v_last_watchdog_action VARCHAR(8),
  v_is_run_once BOOLEAN,
  v_cpu_name VARCHAR(255),
  v_current_cd VARCHAR(4000),
  v_reason VARCHAR(4000),
  v_exit_reason INTEGER,
  v_guest_cpu_count INTEGER)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE vm_dynamic
      SET app_list = v_app_list,guest_cur_user_name = v_guest_cur_user_name,
      console_cur_user_name = v_console_cur_user_name,
      guest_last_login_time = v_guest_last_login_time,
      guest_last_logout_time = v_guest_last_logout_time,
      console_user_id = v_console_user_id,
      guest_os = v_guest_os,migrating_to_vds = v_migrating_to_vds,RUN_ON_VDS = v_run_on_vds,
      status = v_status,vm_host = v_vm_host,vm_ip = v_vm_ip,vm_fqdn = v_vm_fqdn,
      last_start_time = v_last_start_time,
      last_stop_time = v_last_stop_time,
      vm_pid = v_vm_pid,display = v_display,acpi_enable = v_acpi_enable,
      session = v_session,display_ip = v_display_ip,
      display_type = v_display_type,kvm_enable = v_kvm_enable,boot_sequence = v_boot_sequence,
      display_secure_port = v_display_secure_port,
      utc_diff = v_utc_diff,last_vds_run_on = v_last_vds_run_on,client_ip = v_client_ip,
      guest_requested_memory = v_guest_requested_memory,
      hibernation_vol_handle = v_hibernation_vol_handle,exit_status = v_exit_status,
      pause_status = v_pause_status,exit_message = v_exit_message, hash=v_hash, guest_agent_nics_hash = v_guest_agent_nics_hash,
      last_watchdog_event = v_last_watchdog_event, last_watchdog_action = v_last_watchdog_action, is_run_once = v_is_run_once, cpu_name = v_cpu_name,
      current_cd = v_current_cd,
      reason = v_reason,
      exit_reason = v_exit_reason,
      guest_cpu_count = v_guest_cpu_count
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateConsoleUserWithOptimisticLocking(
    v_vm_guid UUID,
    v_console_user_id UUID,
    v_guest_cur_user_name VARCHAR(255),
    v_console_cur_user_name VARCHAR(255),
    OUT v_updated BOOLEAN)
    AS $procedure$
BEGIN
    UPDATE vm_dynamic SET
        console_user_id = v_console_user_id,
        guest_cur_user_name = v_guest_cur_user_name,
        console_cur_user_name = v_console_cur_user_name
    WHERE
        vm_guid = v_vm_guid AND
        (console_user_id = v_console_user_id OR console_user_id IS NULL);
    v_updated := FOUND;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmDynamicStatus(
	v_vm_guid UUID,
	v_status INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE vm_dynamic
      SET
      status = v_status
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION ClearMigratingToVds(v_vm_guid UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE vm_dynamic
      SET
      migrating_to_vds = null
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVmDynamic(v_vm_guid UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM vm_dynamic
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVmDynamic() RETURNS SETOF vm_dynamic STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_dynamic.*
      FROM vm_dynamic;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmDynamicByVmGuid(v_vm_guid UUID) RETURNS SETOF vm_dynamic STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_dynamic.*
      FROM vm_dynamic
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVmStatic(v_description VARCHAR(4000),
 v_free_text_comment text,
 v_mem_size_mb INTEGER,
 v_os INTEGER,
 v_vds_group_id UUID,
 v_vm_guid UUID,
 v_vm_name VARCHAR(255),
 v_vmt_guid UUID,
 v_creation_date TIMESTAMP WITH TIME ZONE,
 v_num_of_monitors INTEGER,
 v_single_qxl_pci BOOLEAN,
 v_allow_console_reconnect BOOLEAN,
 v_is_initialized BOOLEAN,
    v_num_of_sockets INTEGER,
    v_cpu_per_socket INTEGER,
 v_usb_policy INTEGER,
 v_time_zone VARCHAR(40) ,
 v_auto_startup BOOLEAN,
 v_is_stateless BOOLEAN,
 v_is_smartcard_enabled BOOLEAN,
 v_is_delete_protected BOOLEAN,
 v_sso_method VARCHAR(32),
 v_dedicated_vm_for_vds UUID ,
    v_fail_back BOOLEAN ,
    v_vm_type INTEGER ,
 v_nice_level INTEGER,
 v_cpu_shares INTEGER,
    v_default_boot_sequence INTEGER,
 v_default_display_type INTEGER,
 v_priority INTEGER,
    v_iso_path VARCHAR(4000) ,
    v_origin INTEGER ,
    v_initrd_url    VARCHAR(4000) ,
    v_kernel_url    VARCHAR(4000) ,
    v_kernel_params VARCHAR(4000) ,
    v_migration_support INTEGER ,
    v_predefined_properties VARCHAR(4000) ,
    v_userdefined_properties VARCHAR(4000),
    v_min_allocated_mem INTEGER,
    v_quota_id UUID,
    v_cpu_pinning VARCHAR(4000),
    v_host_cpu_flags BOOLEAN,
    v_tunnel_migration BOOLEAN,
    v_vnc_keyboard_layout VARCHAR(16),
    v_is_run_and_pause BOOLEAN,
    v_created_by_user_id UUID,
    v_instance_type_id UUID,
    v_image_type_id UUID,
    v_original_template_id UUID,
    v_original_template_name VARCHAR(255),
    v_migration_downtime INTEGER,
    v_template_version_number INTEGER,
    v_serial_number_policy SMALLINT,
    v_custom_serial_number VARCHAR(255),
    v_is_boot_menu_enabled BOOLEAN,
    v_numatune_mode VARCHAR(20),
    v_is_spice_file_transfer_enabled BOOLEAN,
    v_is_spice_copy_paste_enabled BOOLEAN,
    v_cpu_profile_id UUID)
  RETURNS VOID
   AS $procedure$
DECLARE
  v_val  UUID;
BEGIN
-- lock template for child count update
select vm_guid into v_val FROM vm_static WHERE vm_guid = v_vmt_guid for update;
INSERT INTO vm_static(description, free_text_comment, mem_size_mb, os, vds_group_id, vm_guid, VM_NAME, vmt_guid,creation_date,num_of_monitors, single_qxl_pci, allow_console_reconnect,is_initialized,num_of_sockets,cpu_per_socket,usb_policy, time_zone,auto_startup,is_stateless,dedicated_vm_for_vds, fail_back, default_boot_sequence, vm_type, nice_level, cpu_shares, default_display_type, priority,iso_path,origin,initrd_url,kernel_url,kernel_params,migration_support,predefined_properties,userdefined_properties,min_allocated_mem, entity_type, quota_id, cpu_pinning, is_smartcard_enabled,is_delete_protected, sso_method, host_cpu_flags, tunnel_migration, vnc_keyboard_layout, is_run_and_pause, created_by_user_id, instance_type_id, image_type_id, original_template_id, original_template_name, migration_downtime, template_version_number, serial_number_policy, custom_serial_number, is_boot_menu_enabled, numatune_mode, is_spice_file_transfer_enabled, is_spice_copy_paste_enabled, cpu_profile_id)
	VALUES(v_description, v_free_text_comment, v_mem_size_mb, v_os, v_vds_group_id, v_vm_guid, v_vm_name, v_vmt_guid, v_creation_date, v_num_of_monitors,v_single_qxl_pci, v_allow_console_reconnect, v_is_initialized, v_num_of_sockets, v_cpu_per_socket, v_usb_policy, v_time_zone, v_auto_startup,v_is_stateless,v_dedicated_vm_for_vds,v_fail_back, v_default_boot_sequence, v_vm_type, v_nice_level, v_cpu_shares, v_default_display_type, v_priority,v_iso_path,v_origin,v_initrd_url,v_kernel_url,v_kernel_params,v_migration_support,v_predefined_properties,v_userdefined_properties,v_min_allocated_mem, 'VM', v_quota_id, v_cpu_pinning, v_is_smartcard_enabled,v_is_delete_protected, v_sso_method, v_host_cpu_flags, v_tunnel_migration, v_vnc_keyboard_layout, v_is_run_and_pause, v_created_by_user_id, v_instance_type_id, v_image_type_id, v_original_template_id, v_original_template_name, v_migration_downtime, v_template_version_number, v_serial_number_policy, v_custom_serial_number, v_is_boot_menu_enabled, v_numatune_mode, v_is_spice_file_transfer_enabled, v_is_spice_copy_paste_enabled, v_cpu_profile_id);

-- perform deletion from vm_ovf_generations to ensure that no record exists when performing insert to avoid PK violation.
DELETE FROM vm_ovf_generations gen WHERE gen.vm_guid = v_vm_guid;
INSERT INTO vm_ovf_generations(vm_guid, storage_pool_id) VALUES (v_vm_guid, (SELECT storage_pool_id FROM vds_groups vg WHERE vg.vds_group_id = v_vds_group_id));

-- set child_count for the template
UPDATE vm_static SET child_count = child_count+1 where vm_guid = v_vmt_guid;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION IncrementDbGeneration(v_vm_guid UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE vm_static
      SET db_generation  = db_generation + 1
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetDbGeneration(v_vm_guid UUID)
RETURNS SETOF BIGINT STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT db_generation
      FROM vm_static
      WHERE vm_guid = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION IncrementDbGenerationForAllInStoragePool(v_storage_pool_id UUID)
RETURNS VOID
   AS $procedure$
DECLARE
     curs CURSOR FOR SELECT vms.vm_guid FROM vm_static vms
                     WHERE vms.vds_group_id IN (SELECT vgs.vds_group_id FROM vds_groups vgs
                                                WHERE vgs.storage_pool_id=v_storage_pool_id)
                     ORDER BY vm_guid;
     id UUID;
BEGIN
      OPEN curs;
      LOOP
         FETCH curs INTO id;
         IF NOT FOUND THEN
            EXIT;
         END IF;
         UPDATE vm_static SET db_generation  = db_generation + 1 WHERE vm_guid = id;
      END LOOP;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmStatic(v_description VARCHAR(4000) ,
 v_free_text_comment text,
 v_mem_size_mb INTEGER,
 v_os INTEGER,
 v_vds_group_id UUID,
 v_vm_guid UUID,
 v_vm_name VARCHAR(255),
 v_vmt_guid UUID,
 v_creation_date TIMESTAMP WITH TIME ZONE,
 v_num_of_monitors INTEGER,
 v_single_qxl_pci BOOLEAN,
 v_allow_console_reconnect BOOLEAN,
 v_is_initialized BOOLEAN,
    v_num_of_sockets INTEGER,
    v_cpu_per_socket INTEGER,
 v_usb_policy  INTEGER,
 v_time_zone VARCHAR(40) ,
 v_auto_startup BOOLEAN,
 v_is_stateless BOOLEAN,
 v_is_smartcard_enabled BOOLEAN,
 v_is_delete_protected BOOLEAN,
 v_sso_method VARCHAR(32),
 v_dedicated_vm_for_vds UUID ,
    v_fail_back BOOLEAN ,
    v_vm_type INTEGER ,
    v_nice_level INTEGER,
    v_cpu_shares INTEGER,
    v_default_boot_sequence INTEGER,
 v_default_display_type INTEGER,
 v_priority INTEGER,
    v_iso_path VARCHAR(4000) ,
    v_origin INTEGER ,
    v_initrd_url    VARCHAR(4000) ,
    v_kernel_url    VARCHAR(4000) ,
    v_kernel_params VARCHAR(4000) ,
    v_migration_support INTEGER ,
v_predefined_properties VARCHAR(4000),
v_userdefined_properties VARCHAR(4000),
v_min_allocated_mem INTEGER,
v_quota_id UUID,
v_cpu_pinning VARCHAR(4000),
v_host_cpu_flags BOOLEAN,
v_tunnel_migration BOOLEAN,
v_vnc_keyboard_layout	VARCHAR(16),
v_is_run_and_pause BOOLEAN,
v_created_by_user_id UUID,
v_instance_type_id UUID,
v_image_type_id UUID,
v_original_template_id UUID,
v_original_template_name VARCHAR(255),
v_migration_downtime INTEGER,
v_template_version_number INTEGER,
v_serial_number_policy SMALLINT,
v_custom_serial_number VARCHAR(255),
v_is_boot_menu_enabled BOOLEAN,
v_numatune_mode VARCHAR(20),
v_is_spice_file_transfer_enabled BOOLEAN,
v_is_spice_copy_paste_enabled BOOLEAN,
v_cpu_profile_id UUID)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE vm_static
      SET description = v_description, free_text_comment = v_free_text_comment ,mem_size_mb = v_mem_size_mb,os = v_os,vds_group_id = v_vds_group_id,
      VM_NAME = v_vm_name,vmt_guid = v_vmt_guid,
      creation_date = v_creation_date,num_of_monitors = v_num_of_monitors,single_qxl_pci = v_single_qxl_pci,
      allow_console_reconnect = v_allow_console_reconnect,
      is_initialized = v_is_initialized,
      num_of_sockets = v_num_of_sockets,cpu_per_socket = v_cpu_per_socket,
      usb_policy = v_usb_policy,time_zone = v_time_zone,auto_startup = v_auto_startup,
      is_stateless = v_is_stateless,dedicated_vm_for_vds = v_dedicated_vm_for_vds,
      fail_back = v_fail_back,vm_type = v_vm_type,
      nice_level = v_nice_level,
      cpu_shares = v_cpu_shares,
      _update_date = LOCALTIMESTAMP,default_boot_sequence = v_default_boot_sequence,
      default_display_type = v_default_display_type,
      priority = v_priority,iso_path = v_iso_path,origin = v_origin,
      initrd_url = v_initrd_url,kernel_url = v_kernel_url,
      kernel_params = v_kernel_params,migration_support = v_migration_support,
      predefined_properties = v_predefined_properties,userdefined_properties = v_userdefined_properties,
      min_allocated_mem = v_min_allocated_mem, quota_id = v_quota_id, cpu_pinning = v_cpu_pinning, is_smartcard_enabled = v_is_smartcard_enabled,
      is_delete_protected = v_is_delete_protected, sso_method = v_sso_method, host_cpu_flags = v_host_cpu_flags, tunnel_migration = v_tunnel_migration,
      vnc_keyboard_layout = v_vnc_keyboard_layout, is_run_and_pause = v_is_run_and_pause, created_by_user_id = v_created_by_user_id,
      instance_type_id = v_instance_type_id, image_type_id = v_image_type_id, original_template_id = v_original_template_id,
      original_template_name = v_original_template_name,
      migration_downtime = v_migration_downtime, template_version_number = v_template_version_number,
      serial_number_policy = v_serial_number_policy, custom_serial_number = v_custom_serial_number,
      is_boot_menu_enabled = v_is_boot_menu_enabled,
      numatune_mode = v_numatune_mode,
      is_spice_file_transfer_enabled = v_is_spice_file_transfer_enabled, is_spice_copy_paste_enabled = v_is_spice_copy_paste_enabled,
      cpu_profile_id = v_cpu_profile_id
      WHERE vm_guid = v_vm_guid
      AND   entity_type = 'VM';
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVmStatic(v_vm_guid UUID, v_remove_permissions boolean)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
   v_vmt_guid  UUID;
BEGIN
      -- store vmt_guid for setting the child_count
      SELECT   vm_static.vmt_guid INTO v_vmt_guid FROM vm_static WHERE vm_guid = v_vm_guid;

			-- Get (and keep) a shared lock with "right to upgrade to exclusive"
            -- in order to force locking parent before children
      select   vm_guid INTO v_val FROM vm_static  WHERE vm_guid = v_vm_guid     FOR UPDATE;
      DELETE FROM vm_static
      WHERE vm_guid = v_vm_guid
      AND   entity_type = 'VM';

			-- delete VM permissions --
      if v_remove_permissions then
        DELETE FROM permissions where object_id = v_vm_guid;
      end if;

      -- set the child_count for the template
      UPDATE vm_static
          SET child_count = child_count - 1 WHERE vm_guid = v_vmt_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVmStatic() RETURNS SETOF vm_static STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static
   WHERE entity_type = 'VM';

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateOriginalTemplateName(
v_original_template_id UUID,
v_original_template_name VARCHAR(255))
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE vm_static
      SET original_template_name = v_original_template_name
      WHERE original_template_id = v_original_template_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmStaticByVmGuid(v_vm_guid UUID) RETURNS SETOF vm_static STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static
   WHERE vm_guid = v_vm_guid
   AND   entity_type = 'VM';

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS GetNamesOfVmStaticDedicatedToVds_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE GetNamesOfVmStaticDedicatedToVds_rs AS (vm_name CHARACTER VARYING);
**************************

CREATE TYPE
********* QUERY **********
Create or replace FUNCTION GetNamesOfVmStaticDedicatedToVds(v_vds_id UUID) RETURNS SETOF GetNamesOfVmStaticDedicatedToVds_rs STABLE
   AS $procedure$
BEGIN
   RETURN QUERY
      SELECT vm_name
      FROM vm_static
      WHERE dedicated_vm_for_vds = v_vds_id
      AND   migration_support = 2
      AND   entity_type = 'VM';

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVmStaticByStoragePoolId(v_sp_id uuid) RETURNS SETOF vm_static STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static INNER JOIN
        vds_groups ON vm_static.vds_group_id = vds_groups.vds_group_id LEFT OUTER JOIN
        storage_pool ON vm_static.vds_group_id = vds_groups.vds_group_id
        and vds_groups.storage_pool_id = storage_pool.id
   WHERE v_sp_id = storage_pool.id
   AND   entity_type = 'VM';

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmStaticByName(v_vm_name VARCHAR(255)) RETURNS SETOF vm_static STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static
   WHERE VM_NAME = v_vm_name
   AND   entity_type = 'VM';

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmStaticByVdsGroup(v_vds_group_id UUID) RETURNS SETOF vm_static STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static
   WHERE vds_group_id = v_vds_group_id
   AND   entity_type = 'VM';

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmStaticWithFailbackByVdsId(v_vds_id UUID) RETURNS SETOF vm_static STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm_static.*
   FROM vm_static
   WHERE dedicated_vm_for_vds = v_vds_id and fail_back = TRUE
   AND   entity_type = 'VM';

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVms(v_user_id UUID, v_is_filtered boolean) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM user_vm_permissions_view
                                       WHERE user_id = v_user_id AND entity_id = vm_guid))
   ORDER BY vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByIds(v_vms_ids VARCHAR(5000)) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm.*
             FROM vms vm
             WHERE vm.vm_guid IN (SELECT * from fnSplitterUuid(v_vms_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmByVmGuid(v_vm_guid UUID, v_user_id UUID, v_is_filtered boolean) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE vm_guid = v_vm_guid
   AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_vm_permissions_view
                                       WHERE  user_id = v_user_id AND entity_id = v_vm_guid));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmByVmNameForDataCenter(v_data_center_id UUID, v_vm_name VARCHAR(255), v_user_id UUID, v_is_filtered boolean) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE vm_name = v_vm_name
   AND   (v_data_center_id is null OR storage_pool_id = v_data_center_id)
   AND   (NOT v_is_filtered OR EXISTS (SELECT 1
                                       FROM   user_vm_permissions_view
                                       WHERE  user_id = v_user_id AND entity_id = vms.vm_guid));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByVmtGuid(v_vmt_guid UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE vmt_guid = v_vmt_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByUserId(v_user_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
RETURN QUERY select vms.* from vms
   inner join permissions on vms.vm_guid = permissions.object_id
   WHERE permissions.ad_element_id = v_user_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByInstanceTypeId(v_instance_type_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
RETURN QUERY select vms.* from vms
   WHERE instance_type_id = v_instance_type_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByUserIdWithGroupsAndUserRoles(v_user_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   from vms
   inner join permissions_view as perms on vms.vm_guid = perms.object_id
   WHERE (perms.ad_element_id = v_user_id
   or perms.ad_element_id in(select id from getUserAndGroupsById(v_user_id)))
   and perms.role_type = 2;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsRunningOnVds(v_vds_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE run_on_vds = v_vds_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsMigratingToVds(v_vds_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT DISTINCT vms.*
   FROM vms
   WHERE migrating_to_vds = v_vds_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsRunningOnOrMigratingToVds(v_vds_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
    -- use migrating_to_vds column when the VM is in status Migrating From
    RETURN QUERY SELECT DISTINCT V.* FROM VMS V
    WHERE V.RUN_ON_VDS=V_VDS_ID OR (V.STATUS = 5 AND V.MIGRATING_TO_VDS=V_VDS_ID)
    ORDER BY V.VM_NAME;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsDynamicRunningOnVds(v_vds_id UUID) RETURNS SETOF vm_dynamic STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_dynamic.*
      FROM vm_dynamic
      WHERE RUN_ON_VDS = v_vds_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVm(v_vm_guid UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_vmt_guid  UUID;
BEGIN
      select   vm_static.vmt_guid INTO v_vmt_guid FROM vm_static WHERE vm_guid = v_vm_guid;
      UPDATE vm_static
      SET child_count =(SELECT COUNT(*) FROM vm_static WHERE vmt_guid = v_vmt_guid) -1
      WHERE vm_guid = v_vmt_guid;
      DELETE FROM tags_vm_map
      WHERE vm_id = v_vm_guid;
      DELETE
      FROM   snapshots
      WHERE  vm_id = v_vm_guid;
      DELETE FROM vm_statistics WHERE vm_guid = v_vm_guid;
      DELETE FROM vm_dynamic WHERE vm_guid = v_vm_guid;
      DELETE FROM vm_static WHERE vm_guid = v_vm_guid;
      DELETE FROM permissions where object_id = v_vm_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByAdGroupNames(v_ad_group_names VARCHAR(250)) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
RETURN QUERY select distinct vms.* from vms
   inner join permissions on vms.vm_guid = permissions.object_id
   inner join ad_groups on ad_groups.id = permissions.ad_element_id
   WHERE     (ad_groups.name in(select Id from fnSplitter(v_ad_group_names)));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByDiskId(v_disk_guid UUID) RETURNS SETOF vms_with_plug_info STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT vms_with_plug_info.*
      FROM vms_with_plug_info
      WHERE device_id = v_disk_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmByHibernationImageId(v_image_id VARCHAR(4000)) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT vms.*
      FROM vms
      WHERE hibernation_vol_handle like '%' || coalesce(v_image_id,'') || '%';
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllVMsWithDisksOnOtherStorageDomain(v_storage_domain_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT vms.*
      FROM vms
      INNER JOIN (SELECT vm_static.vm_guid
                  FROM vm_static
                  INNER JOIN vm_device vd ON vd.vm_id = vm_static.vm_guid
                  INNER JOIN images i ON i.image_group_id = vd.device_id
                  INNER JOIN (SELECT image_id
                              FROM image_storage_domain_map
                              WHERE image_storage_domain_map.storage_domain_id = v_storage_domain_id) isd_map
                              ON i.image_guid = isd_map.image_id WHERE entity_type = 'VM') vms_with_disks_on_storage_domain ON vms.vm_guid = vms_with_disks_on_storage_domain.vm_guid
      INNER JOIN vm_device vd ON vd.vm_id = vms.vm_guid
      INNER JOIN images i ON i.image_group_id = vd.device_id
      INNER JOIN image_storage_domain_map on i.image_guid = image_storage_domain_map.image_id
      WHERE image_storage_domain_map.storage_domain_id != v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetActiveVmsByStorageDomainId(v_storage_domain_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT vms.*
      FROM vms
      INNER JOIN vm_device vd ON vd.vm_id = vms.vm_guid
      INNER JOIN images i ON i.image_group_id = vd.device_id
      inner join image_storage_domain_map on i.image_guid = image_storage_domain_map.image_id
      WHERE status <> 0 AND
            is_plugged = TRUE AND
            image_storage_domain_map.storage_domain_id = v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByStorageDomainId(v_storage_domain_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT vms.*
      FROM vms
      INNER JOIN vm_device vd ON vd.vm_id = vms.vm_guid
      INNER JOIN images ON images.image_group_id = vd.device_id AND images.active = TRUE
      inner join image_storage_domain_map on images.image_guid = image_storage_domain_map.image_id
      where image_storage_domain_map.storage_domain_id = v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION getAllVmsRelatedToQuotaId(v_quota_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vms.*
      FROM vms
      WHERE quota_id = v_quota_id
      UNION
      SELECT DISTINCT vms.*
      FROM vms
      INNER JOIN vm_device vd ON vd.vm_id = vms.vm_guid
      INNER JOIN images ON images.image_group_id = vd.device_id AND images.active = TRUE
      INNER JOIN image_storage_domain_map ON image_storage_domain_map.image_id = images.image_guid
      WHERE image_storage_domain_map.quota_id = v_quota_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateIsInitialized(v_vm_guid UUID,
 v_is_initialized BOOLEAN)
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE vm_static
      SET is_initialized = v_is_initialized
      WHERE vm_guid = v_vm_guid
      AND   entity_type = 'VM';
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
DROP TYPE IF EXISTS GetOrderedVmGuidsForRunMultipleActions_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE GetOrderedVmGuidsForRunMultipleActions_rs AS (vm_guid UUID);
**************************

CREATE TYPE
********* QUERY **********
Create or replace FUNCTION GetOrderedVmGuidsForRunMultipleActions(v_vm_guids VARCHAR(4000)) RETURNS SETOF GetOrderedVmGuidsForRunMultipleActions_rs STABLE
   AS $procedure$
   DECLARE
   v_ordered_guids GetOrderedVmGuidsForRunMultipleActions_rs;
BEGIN
   FOR v_ordered_guids IN EXECUTE 'SELECT vm_guid from vm_static where vm_guid in( ' || v_vm_guids || ' ) AND entity_type = ''VM''  order by auto_startup desc,priority desc, migration_support desc' LOOP
      RETURN NEXT v_ordered_guids;
   END LOOP;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByNetworkId(v_network_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vms
   WHERE EXISTS (
      SELECT 1
      FROM vm_interface
      INNER JOIN vnic_profiles
      ON vnic_profiles.id = vm_interface.vnic_profile_id
      WHERE vnic_profiles.network_id = v_network_id
      AND vm_interface.vm_guid = vms.vm_guid);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByVnicProfileId(v_vnic_profile_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vms
   WHERE EXISTS (
      SELECT 1
      FROM vm_interface
      WHERE vm_interface.vnic_profile_id = v_vnic_profile_id
      AND vm_interface.vm_guid = vms.vm_guid);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByVdsGroupId(v_vds_group_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vms.*
      FROM vms
      WHERE vds_group_id = v_vds_group_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmsByVmPoolId(v_vm_pool_id UUID) RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vms.*
      FROM vms
      WHERE vm_pool_id = v_vm_pool_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetFailedAutoStartVms() RETURNS SETOF vms STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vms.*
      FROM vms
      WHERE auto_startup = TRUE and status = 0 and exit_status = 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetRunningVmsByClusterId(v_cluster_id UUID) RETURNS SETOF vms STABLE
    AS $procedure$
BEGIN
    RETURN QUERY SELECT DISTINCT vms.*
    FROM vms
    WHERE run_on_vds IS NOT NULL AND
        vds_group_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmInitByVmId(v_vm_id UUID) RETURNS SETOF vm_init STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm_init.*
   FROM vm_init
   WHERE vm_id = v_vm_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmInitByids(v_vm_init_ids TEXT) RETURNS SETOF vm_init STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT *
     FROM vm_init
     WHERE vm_init.vm_id IN (SELECT * from fnSplitterUuid(v_vm_init_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmInit(
    v_vm_id UUID,
    v_host_name TEXT,
    v_domain TEXT,
    v_authorized_keys TEXT,
    v_regenerate_keys BOOLEAN,
    v_time_zone VARCHAR(40),
    v_dns_servers TEXT,
    v_dns_search_domains TEXT,
    v_networks TEXT,
    v_password TEXT,
    v_winkey VARCHAR(30),
    v_custom_script TEXT,
    v_input_locale VARCHAR(256),
    v_ui_language VARCHAR(256),
    v_system_locale VARCHAR(256),
    v_user_locale VARCHAR(256),
    v_user_name VARCHAR(256),
    v_active_directory_ou VARCHAR(256),
    v_org_name VARCHAR(256))
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE vm_init
      SET host_name=v_host_name, domain=v_domain, authorized_keys=v_authorized_keys, regenerate_keys=v_regenerate_keys,
          time_zone=v_time_zone, dns_servers=v_dns_servers, dns_search_domains=v_dns_search_domains,
          networks=v_networks, password=v_password, winkey=v_winkey, custom_script=v_custom_script,
          input_locale=v_input_locale, ui_language=v_ui_language, system_locale=v_system_locale,
          user_locale=v_user_locale, user_name=v_user_name, active_directory_ou=v_active_directory_ou,
          org_name=v_org_name
      WHERE vm_id = v_vm_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVmInit(v_vm_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
      DELETE FROM vm_init
      WHERE vm_id = v_vm_id;

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVmInit(
    v_vm_id UUID,
    v_host_name TEXT,
    v_domain TEXT,
    v_authorized_keys TEXT,
    v_regenerate_keys BOOLEAN,
    v_time_zone VARCHAR(40),
    v_dns_servers TEXT,
    v_dns_search_domains TEXT,
    v_networks TEXT,
    v_password TEXT,
    v_winkey VARCHAR(30),
    v_custom_script TEXT,
    v_input_locale VARCHAR(256),
    v_ui_language VARCHAR(256),
    v_system_locale VARCHAR(256),
    v_user_locale VARCHAR(256),
    v_user_name VARCHAR(256),
    v_active_directory_ou VARCHAR(256),
    v_org_name VARCHAR(256))
RETURNS VOID
   AS $procedure$
BEGIN
INSERT INTO vm_init(vm_id, host_name, domain, authorized_keys, regenerate_keys, time_zone, dns_servers, dns_search_domains,
                    networks, password, winkey, custom_script, input_locale, ui_language,
                    system_locale, user_locale, user_name, active_directory_ou, org_name)
       VALUES(v_vm_id, v_host_name, v_domain, v_authorized_keys, v_regenerate_keys, v_time_zone, v_dns_servers, v_dns_search_domains,
                    v_networks, v_password, v_winkey, v_custom_script, v_input_locale, v_ui_language,
                    v_system_locale, v_user_locale, v_user_name, v_active_directory_ou, v_org_name);

END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmIdsForVersionUpdate(v_base_template_id UUID) RETURNS SETOF UUID STABLE
AS $procedure$
BEGIN
RETURN QUERY select vs.vm_guid
             from vm_static vs
               natural join vm_dynamic
             where (vmt_guid = v_base_template_id or vmt_guid in
                          (select vm_guid from vm_static where vmt_guid = v_base_template_id))
               and template_version_number is null and entity_type='VM' and status=0
                   and (is_stateless = TRUE or
                        (exists (select * from vm_pool_map where vm_guid = vs.vm_guid)
                         and not exists
                        (SELECT *
                         FROM   snapshots
                         WHERE  vm_id = vs.vm_guid
                                AND    snapshot_type = 'STATELESS')));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmCpuProfileIdForClusterId(v_cluster_id UUID, v_cpu_profile_id UUID)
RETURNS VOID
   AS $procedure$
BEGIN
UPDATE vm_static
   SET cpu_profile_id = v_cpu_profile_id
   WHERE vds_group_id = v_cluster_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION InsertVmTemplate(v_child_count INTEGER,
 v_creation_date TIMESTAMP WITH TIME ZONE,
 v_description VARCHAR(4000) ,
 v_free_text_comment text,
 v_mem_size_mb INTEGER,
 v_name VARCHAR(40),
 v_num_of_sockets INTEGER,
 v_cpu_per_socket INTEGER,
 v_os INTEGER,
 v_vmt_guid UUID,
 v_vds_group_id UUID,
 v_num_of_monitors INTEGER,
 v_single_qxl_pci BOOLEAN,
 v_allow_console_reconnect BOOLEAN,
 v_status INTEGER,
 v_usb_policy INTEGER,
 v_time_zone VARCHAR(40) ,
 v_fail_back BOOLEAN ,
 v_vm_type INTEGER ,
 v_nice_level INTEGER,
 v_cpu_shares INTEGER,
 v_default_boot_sequence INTEGER,
 v_default_display_type INTEGER,
 v_priority INTEGER,
 v_auto_startup BOOLEAN,
 v_is_stateless BOOLEAN,
 v_is_smartcard_enabled BOOLEAN,
 v_is_delete_protected BOOLEAN,
 v_sso_method VARCHAR(32),
 v_is_disabled BOOLEAN,
 v_iso_path VARCHAR(4000) ,
 v_origin INTEGER ,
 v_initrd_url    VARCHAR(4000) ,
 v_kernel_url    VARCHAR(4000) ,
 v_kernel_params VARCHAR(4000) ,
 v_quota_id UUID,
 v_migration_support integer,
 v_dedicated_vm_for_vds UUID,
 v_tunnel_migration BOOLEAN,
 v_vnc_keyboard_layout	VARCHAR(16),
 v_min_allocated_mem INTEGER,
 v_is_run_and_pause BOOLEAN,
 v_created_by_user_id UUID,
 v_template_type VARCHAR(40),
 v_migration_downtime INTEGER,
 v_base_template_id UUID,
 v_template_version_name VARCHAR(40),
 v_serial_number_policy SMALLINT,
 v_custom_serial_number VARCHAR(255),
 v_is_boot_menu_enabled BOOLEAN,
 v_is_spice_file_transfer_enabled BOOLEAN,
 v_is_spice_copy_paste_enabled BOOLEAN,
 v_cpu_profile_id UUID,
 v_numatune_mode VARCHAR(20))
RETURNS VOID
   AS $procedure$
DECLARE
v_template_version_number INTEGER;
BEGIN
  -- get current max version and use next
  SELECT max(template_version_number) + 1 into v_template_version_number
  from vm_static
  where vmt_guid = v_base_template_id
        and entity_type = 'TEMPLATE';

  -- if no versions exist it might return null, so this is a new base template
  if v_template_version_number is null then
    v_template_version_number = 1;
  end if;

INSERT
INTO vm_static(
    child_count,
    creation_date,
    description,
    free_text_comment,
    mem_size_mb,
    vm_name,
    num_of_sockets,
    cpu_per_socket,
    os,
    vm_guid,
    vds_group_id,
    num_of_monitors,
    single_qxl_pci,
    allow_console_reconnect,
    template_status,
    usb_policy,
    time_zone,
    fail_back,
    vm_type,
    nice_level,
    cpu_shares,
    default_boot_sequence,
    default_display_type,
    priority,
    auto_startup,
    is_stateless,
    iso_path,
    origin,
    initrd_url,
    kernel_url,
    kernel_params,
    entity_type,
    quota_id,
    migration_support,
    is_disabled,
    dedicated_vm_for_vds,
    is_smartcard_enabled,
    is_delete_protected,
    sso_method,
    tunnel_migration,
    vnc_keyboard_layout,
    min_allocated_mem,
    is_run_and_pause,
    created_by_user_id,
    migration_downtime,
    template_version_number,
    vmt_guid,
    template_version_name,
    serial_number_policy,
    custom_serial_number,
    is_boot_menu_enabled,
    is_spice_file_transfer_enabled,
    is_spice_copy_paste_enabled,
    cpu_profile_id,
    numatune_mode)
VALUES(
    v_child_count,
    v_creation_date,
    v_description,
    v_free_text_comment,
    v_mem_size_mb,
    v_name,
    v_num_of_sockets,
    v_cpu_per_socket,
    v_os,
    v_vmt_guid,
    v_vds_group_id,
    v_num_of_monitors,
    v_single_qxl_pci,
    v_allow_console_reconnect,
    v_status,
    v_usb_policy,
    v_time_zone,
    v_fail_back,
    v_vm_type,
    v_nice_level,
    v_cpu_shares,
    v_default_boot_sequence,
    v_default_display_type,
    v_priority,
    v_auto_startup,
    v_is_stateless,
    v_iso_path,
    v_origin,
    v_initrd_url,
    v_kernel_url,
    v_kernel_params,
    v_template_type,
    v_quota_id,
    v_migration_support,
    v_is_disabled,
    v_dedicated_vm_for_vds,
    v_is_smartcard_enabled,
    v_is_delete_protected,
    v_sso_method,
    v_tunnel_migration,
    v_vnc_keyboard_layout,
    v_min_allocated_mem,
    v_is_run_and_pause,
    v_created_by_user_id,
    v_migration_downtime,
    v_template_version_number,
    v_base_template_id,
    v_template_version_name,
    v_serial_number_policy,
    v_custom_serial_number,
    v_is_boot_menu_enabled,
    v_is_spice_file_transfer_enabled,
    v_is_spice_copy_paste_enabled,
    v_cpu_profile_id,
    v_numatune_mode);
-- perform deletion from vm_ovf_generations to ensure that no record exists when performing insert to avoid PK violation.
DELETE FROM vm_ovf_generations gen WHERE gen.vm_guid = v_vmt_guid;
INSERT INTO vm_ovf_generations(vm_guid, storage_pool_id)
VALUES (v_vmt_guid, (SELECT storage_pool_id
                     FROM vds_groups vg
                     WHERE vg.vds_group_id = v_vds_group_id));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmTemplate(v_child_count INTEGER,
 v_creation_date TIMESTAMP WITH TIME ZONE,
 v_description VARCHAR(4000) ,
 v_free_text_comment text,
 v_mem_size_mb INTEGER,
 v_name VARCHAR(40),
 v_num_of_sockets INTEGER,
 v_cpu_per_socket INTEGER,
 v_os INTEGER,
 v_vmt_guid UUID,
 v_vds_group_id UUID,
 v_num_of_monitors INTEGER,
 v_single_qxl_pci BOOLEAN,
 v_allow_console_reconnect BOOLEAN,
 v_status INTEGER,
 v_usb_policy INTEGER,
 v_time_zone VARCHAR(40) ,
 v_fail_back BOOLEAN ,
 v_vm_type INTEGER ,
 v_nice_level INTEGER,
 v_cpu_shares INTEGER,
 v_default_boot_sequence INTEGER,
 v_default_display_type INTEGER,
 v_priority INTEGER,
 v_auto_startup BOOLEAN,
 v_is_stateless BOOLEAN,
 v_is_smartcard_enabled BOOLEAN,
 v_is_delete_protected BOOLEAN,
 v_sso_method VARCHAR(32),
 v_is_disabled BOOLEAN,
 v_iso_path VARCHAR(4000) ,
 v_origin INTEGER ,
 v_initrd_url VARCHAR(4000) ,
 v_kernel_url VARCHAR(4000) ,
 v_kernel_params VARCHAR(4000),
 v_quota_id UUID,
 v_migration_support integer,
 v_dedicated_vm_for_vds uuid,
 v_tunnel_migration BOOLEAN,
 v_vnc_keyboard_layout VARCHAR(16),
 v_min_allocated_mem INTEGER,
 v_is_run_and_pause BOOLEAN,
 v_created_by_user_id UUID,
 v_template_type VARCHAR(40),
 v_migration_downtime INTEGER,
 v_template_version_name VARCHAR(40),
 v_serial_number_policy SMALLINT,
 v_custom_serial_number VARCHAR(255),
 v_is_boot_menu_enabled BOOLEAN,
 v_is_spice_file_transfer_enabled BOOLEAN,
 v_is_spice_copy_paste_enabled BOOLEAN,
 v_cpu_profile_id UUID,
 v_numatune_mode VARCHAR(20))
RETURNS VOID
	
   AS $procedure$
BEGIN
      UPDATE vm_static
      SET child_count = v_child_count,creation_date = v_creation_date,description = v_description, free_text_comment = v_free_text_comment,
      mem_size_mb = v_mem_size_mb,vm_name = v_name,num_of_sockets = v_num_of_sockets,
      cpu_per_socket = v_cpu_per_socket,os = v_os,
      vds_group_id = v_vds_group_id,num_of_monitors = v_num_of_monitors,
      single_qxl_pci = v_single_qxl_pci, allow_console_reconnect = v_allow_console_reconnect,
      template_status = v_status,usb_policy = v_usb_policy,time_zone = v_time_zone,
      fail_back = v_fail_back,
      vm_type = v_vm_type,
      nice_level = v_nice_level,
      cpu_shares = v_cpu_shares, default_boot_sequence = v_default_boot_sequence,
      default_display_type = v_default_display_type,
      priority = v_priority,auto_startup = v_auto_startup,is_stateless = v_is_stateless,
      iso_path = v_iso_path,origin = v_origin,initrd_url = v_initrd_url,
      kernel_url = v_kernel_url,kernel_params = v_kernel_params, _update_date = CURRENT_TIMESTAMP, quota_id = v_quota_id,
      migration_support = v_migration_support, dedicated_vm_for_vds = v_dedicated_vm_for_vds, is_smartcard_enabled = v_is_smartcard_enabled,
      is_delete_protected = v_is_delete_protected, sso_method = v_sso_method, is_disabled = v_is_disabled, tunnel_migration = v_tunnel_migration,
      vnc_keyboard_layout = v_vnc_keyboard_layout, min_allocated_mem = v_min_allocated_mem, is_run_and_pause = v_is_run_and_pause, created_by_user_id = v_created_by_user_id,
      migration_downtime = v_migration_downtime,
      template_version_name = v_template_version_name,
      serial_number_policy = v_serial_number_policy, custom_serial_number = v_custom_serial_number,
      is_boot_menu_enabled = v_is_boot_menu_enabled,
      is_spice_file_transfer_enabled = v_is_spice_file_transfer_enabled, is_spice_copy_paste_enabled = v_is_spice_copy_paste_enabled, cpu_profile_id = v_cpu_profile_id,
      numatune_mode = v_numatune_mode
      WHERE vm_guid = v_vmt_guid
      AND   entity_type = v_template_type;

      -- update template versions to new name
      update vm_static
        set vm_name = v_name
      where vm_guid <> v_vmt_guid and vmt_guid = v_vmt_guid and entity_type = v_template_type;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION UpdateVmTemplateStatus(
        v_vmt_guid UUID,
        v_status INTEGER)
RETURNS VOID
   AS $procedure$
BEGIN
      UPDATE vm_static
      SET    template_status = v_status
      WHERE  vm_guid = v_vmt_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION DeleteVmTemplates(v_vmt_guid UUID)
RETURNS VOID
   AS $procedure$
   DECLARE
   v_val  UUID;
BEGIN
        -- Get (and keep) a shared lock with "right to upgrade to exclusive"
		-- in order to force locking parent before children
      select   vm_guid INTO v_val FROM vm_static  WHERE vm_guid = v_vmt_guid FOR UPDATE;
      DELETE FROM vm_static
      WHERE vm_guid = v_vmt_guid;
		-- delete Template permissions --
      DELETE FROM permissions where object_id = v_vmt_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllFromVmTemplates(v_user_id UUID, v_is_filtered boolean, v_entity_type VARCHAR(32)) RETURNS SETOF vm_templates_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_templates.*
      FROM vm_templates_view vm_templates
      WHERE entity_type = v_entity_type
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                          FROM   user_vm_template_permissions_view
                                          WHERE  user_id = v_user_id AND entity_id = vmt_guid))
      ORDER BY name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTemplateCount() RETURNS SETOF BIGINT STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT count (vm_templates.*)
      FROM vm_templates_view vm_templates;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplatesByIds(v_vm_templates_ids VARCHAR(5000)) RETURNS SETOF vm_templates_view STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT vm_templates.*
   FROM vm_templates_view vm_templates
   WHERE vm_templates.vmt_guid IN (SELECT * FROM fnSplitterUuid(v_vm_templates_ids));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION getAllVmTemplatesRelatedToQuotaId(v_quota_id UUID) RETURNS SETOF vm_templates_view STABLE
   AS $procedure$
BEGIN
	RETURN QUERY SELECT vm_templates.*
      FROM vm_templates_view vm_templates
      WHERE quota_id = v_quota_id
      UNION
      SELECT DISTINCT vm_templates.*
      FROM vm_templates_view vm_templates
      INNER JOIN vm_device vd ON vd.vm_id = vm_templates.vmt_guid
      INNER JOIN images ON images.image_group_id = vd.device_id AND images.active = TRUE
      INNER JOIN image_storage_domain_map ON image_storage_domain_map.image_id = images.image_guid
      WHERE image_storage_domain_map.quota_id = v_quota_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplateByVmtGuid(v_vmt_guid UUID, v_user_id UUID, v_is_filtered boolean) RETURNS SETOF vm_templates_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_templates.*
      FROM vm_templates_view vm_templates
      WHERE vmt_guid = v_vmt_guid
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_template_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = v_vmt_guid));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplateByVmtName(v_vmt_name VARCHAR(255), v_user_id UUID, v_is_filtered boolean) RETURNS SETOF vm_templates_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_templates.*
      FROM vm_templates_view vm_templates
      WHERE name = v_vmt_name
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                        FROM   user_vm_template_permissions_view
                                        WHERE  user_id = v_user_id AND entity_id = vmt_guid));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplateByVdsGroupId(v_vds_group_id UUID) RETURNS SETOF vm_templates_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_templates.*
      FROM vm_templates_view vm_templates
      WHERE vds_group_id = v_vds_group_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplatesByStoragePoolId(v_storage_pool_id UUID) RETURNS SETOF vm_templates_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT vm_templates.*
      FROM vm_templates_view vm_templates
      where vm_templates.storage_pool_id = v_storage_pool_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplatesByImageId(v_image_guid UUID) RETURNS SETOF vm_templates_with_plug_info STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT *
      FROM vm_templates_with_plug_info t
      WHERE t.image_guid = v_image_guid;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplatesByStorageDomainId(v_storage_domain_id UUID, v_user_id UUID, v_is_filtered boolean) RETURNS SETOF vm_templates_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT DISTINCT vm_templates.*
      FROM vm_templates_view vm_templates
      INNER JOIN vm_device vd ON vd.vm_id = vm_templates.vmt_guid
      INNER JOIN images i ON i.image_group_id = vd.device_id AND i.active = TRUE
      where i.image_guid in(select image_id from image_storage_domain_map where storage_domain_id = v_storage_domain_id)
      AND (NOT v_is_filtered OR EXISTS (SELECT 1
                                      FROM   user_vm_template_permissions_view
                                      WHERE  user_id = v_user_id AND entity_id = vm_templates.vmt_guid));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_perms_get_templates_with_permitted_action(v_user_id UUID, v_action_group_id integer) RETURNS SETOF vm_templates_view STABLE
   AS $procedure$
BEGIN
      RETURN QUERY SELECT vm_templates_view.*
      FROM vm_templates_view, user_vm_template_permissions_view
      WHERE vm_templates_view.vmt_guid = user_vm_template_permissions_view.entity_id AND
            user_vm_template_permissions_view.user_id = v_user_id AND
            (SELECT get_entity_permissions(v_user_id, v_action_group_id, vm_templates_view.vmt_guid, 4) IS NOT NULL);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplatesByNetworkId(v_network_id UUID) RETURNS SETOF vm_templates_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vm_templates_view
   WHERE EXISTS (
      SELECT 1
      FROM vm_interface
      INNER JOIN vnic_profiles
      ON vnic_profiles.id = vm_interface.vnic_profile_id
      WHERE vnic_profiles.network_id = v_network_id
      AND vm_interface.vmt_guid = vm_templates_view.vmt_guid);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetVmTemplatesByVnicProfileId(v_vnic_profile_id UUID) RETURNS SETOF vm_templates_view STABLE
   AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   FROM vm_templates_view
   WHERE EXISTS (
      SELECT 1
      FROM vm_interface
      WHERE vm_interface.vnic_profile_id = v_vnic_profile_id
      AND vm_interface.vmt_guid = vm_templates_view.vmt_guid);
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTemplateVersionsForBaseTemplate(v_base_template_id UUID) RETURNS SETOF vm_templates_view STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   from vm_templates_view
   where base_template_id = v_base_template_id and vmt_guid != v_base_template_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetTemplateWithLatestVersionInChain(v_template_id UUID) RETURNS SETOF vm_templates_view STABLE
AS $procedure$
BEGIN
   RETURN QUERY SELECT *
   from vm_templates_view
   where base_template_id =
      (select vmt_guid from vm_static where vm_guid = v_template_id)
   order by template_version_number desc
   limit 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION GetAllVmTemplatesWithDisksOnOtherStorageDomain(v_storage_domain_id UUID) RETURNS SETOF vm_templates_view STABLE
AS $procedure$
BEGIN
RETURN QUERY SELECT DISTINCT templates.*
      FROM vm_templates_view templates
      INNER JOIN (SELECT vm_static.vm_guid
                  FROM vm_static
                  INNER JOIN vm_device vd ON vd.vm_id = vm_static.vm_guid
                  INNER JOIN images i ON i.image_group_id = vd.device_id
                  INNER JOIN (SELECT image_id
                              FROM image_storage_domain_map
                              WHERE image_storage_domain_map.storage_domain_id = v_storage_domain_id) isd_map
                              ON i.image_guid = isd_map.image_id WHERE entity_type = 'TEMPLATE') vms_with_disks_on_storage_domain ON templates.vmt_guid = vms_with_disks_on_storage_domain.vm_guid
      INNER JOIN vm_device vd ON vd.vm_id = templates.vmt_guid
      INNER JOIN images i ON i.image_group_id = vd.device_id
      INNER JOIN image_storage_domain_map on i.image_guid = image_storage_domain_map.image_id
      WHERE image_storage_domain_map.storage_domain_id != v_storage_domain_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_add_column(v_table varchar(128), v_column varchar(128), v_column_def text)
returns void
AS $procedure$
declare
v_sql text;

begin
	if (not exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ADD COLUMN ' || v_column || ' ' || v_column_def;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_drop_column(v_table varchar(128), v_column varchar(128))
returns void
AS $procedure$
declare
v_sql text;
begin
        if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
            begin
                v_sql := 'ALTER TABLE ' || v_table || ' DROP COLUMN ' || v_column;
                EXECUTE v_sql;
            end;
        end if;
end;$procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_change_column_type(v_table varchar(128), v_column varchar(128),
                                                    v_type varchar(128), v_new_type varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column and (udt_name ilike v_type or data_type ilike v_type))) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' ALTER COLUMN ' || v_column || ' TYPE ' || v_new_type;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_rename_column(v_table varchar(128), v_column varchar(128), v_new_name varchar(128))
returns void
AS $procedure$
declare
v_sql text;

begin
	if (exists (select 1 from information_schema.columns where table_name ilike v_table and column_name ilike v_column)) then
	    begin
		v_sql := 'ALTER TABLE ' || v_table || ' RENAME COLUMN ' || v_column || ' TO ' || v_new_name;
		EXECUTE v_sql;
            end;
	end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (not exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            insert into vdc_options (option_name, option_value, version) values (v_option_name, v_option_value, v_version);
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value_all_versions(v_option_name varchar(100))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name)) then
        begin
            delete from vdc_options where option_name ilike v_option_name;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_value(v_option_name varchar(100), v_version text)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version)))) then
        begin
            delete from vdc_options where option_name ilike v_option_name and version in (select ID from fnSplitter(v_version));
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_delete_config_for_version(v_version text)
returns void
AS $procedure$
BEGIN
     delete from vdc_options where version in (select ID from fnSplitter(v_version));
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_config_value(v_option_name varchar(100), v_option_value varchar(4000),
                                                  v_version varchar(40))
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            update  vdc_options set option_value = v_option_value
            where option_name ilike v_option_name and version = v_version;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_update_default_config_value(v_option_name varchar(100),v_default_option_value varchar(4000),v_option_value varchar(4000),v_version varchar(40),v_ignore_default_value_case boolean)
returns void
AS $procedure$
begin
    if (exists (select 1 from vdc_options where option_name ilike v_option_name and version = v_version)) then
        begin
            if (v_ignore_default_value_case)
            then
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value ilike v_default_option_value and version = v_version;
            else
               update  vdc_options set option_value = v_option_value
               where option_name ilike v_option_name and option_value = v_default_option_value and version = v_version;
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_rename_config_key(v_old_option_name varchar(100),v_new_option_name varchar(100),v_version varchar(40))
returns void
AS $procedure$
DECLARE
    v_current_option_value varchar(4000);
begin
    if (exists (select 1 from vdc_options where option_name ilike v_old_option_name and version = v_version)) then
       v_current_option_value:=option_value from vdc_options where option_name ilike v_old_option_name and version = v_version;
       update vdc_options set option_name = v_new_option_name, option_value = v_current_option_value
           where  option_name ilike v_old_option_name and version = v_version;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_create_constraint (
    v_table varchar(128), v_constraint varchar(128), v_constraint_sql text)
returns void
AS $procedure$
begin
    if  NOT EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' ADD CONSTRAINT ' || v_constraint || ' ' || v_constraint_sql;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace function fn_db_drop_constraint (
    v_table varchar(128), v_constraint varchar(128))
returns void
AS $procedure$
begin
    if  EXISTS (SELECT 1 from pg_constraint where conname ilike v_constraint) then
        execute 'ALTER TABLE ' || v_table ||  ' DROP CONSTRAINT ' || v_constraint || ' CASCADE';
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION CheckDBConnection() RETURNS SETOF integer IMMUTABLE
   AS $procedure$
BEGIN
    RETURN QUERY SELECT 1;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_functions_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'drop function if exists ' || ns.nspname || '.' || proname || '(' || oidvectortypes(proargtypes) || ') cascade;' from pg_proc inner join pg_namespace ns on (pg_proc.pronamespace=ns.oid) where ns.nspname = 'public' order by proname;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_views_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP VIEW if exists ' || table_name || ' CASCADE;' from information_schema.views where table_schema = 'public' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_tables_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP TABLE if exists ' || table_name || ' CASCADE;' from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' order by table_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_seq_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY select 'DROP SEQUENCE if exists ' || sequence_name || ' CASCADE;' from information_schema.sequences  where sequence_schema = 'public' order by sequence_name;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION generate_drop_all_user_types_syntax() RETURNS SETOF text STABLE
   AS $procedure$
BEGIN
RETURN QUERY SELECT 'DROP TYPE if exists ' || c.relname::information_schema.sql_identifier || ' CASCADE;'
   FROM pg_namespace n, pg_class c, pg_type t
   WHERE n.oid = c.relnamespace and t.typrelid = c.oid and c.relkind = 'c'::"char" and
   n.nspname = 'public'
   ORDER BY  c.relname::information_schema.sql_identifier;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_get_column_size( v_table varchar(64), v_column varchar(64)) returns integer STABLE
   AS $procedure$
   declare
   retvalue  integer;
BEGIN
   retvalue := character_maximum_length from information_schema.columns
    where
    table_name ilike v_table and column_name ilike v_column and
    table_schema = 'public' and udt_name in ('char','varchar');
   return retvalue;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION attach_user_to_role (
    v_domain_entry_id text,
    v_user_name VARCHAR(255),
    v_domain VARCHAR(255),
    v_role_name VARCHAR(255)
)
RETURNS void AS
$BODY$
DECLARE
   gen_user_id uuid;
   input_role_id uuid;
BEGIN
   select uuid_generate_v1() into gen_user_id;
   select roles.id into input_role_id from roles where roles.name = v_role_name;
   -- The external identifier is the user identifier converted to an array of
   -- bytes:
   insert into users(user_id,external_id,name,domain,username,groups,active,last_admin_check_status) select gen_user_id, v_domain_entry_id, v_user_name, v_domain, v_user_name,'',true,true where not exists (select gen_user_id,name,domain,username,groups,active from users where external_id = v_domain_entry_id);
   insert into permissions(id,role_id,ad_element_id,object_id,object_type_id) select uuid_generate_v1(),  input_role_id, gen_user_id, getGlobalIds('system'), 1 where not exists(select role_id,ad_element_id,object_id,object_type_id from permissions where role_id = input_role_id and ad_element_id = gen_user_id and object_id= getGlobalIds('system') and object_type_id = 1);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_add_action_group_to_role(v_role_id UUID, v_action_group_id INTEGER)
RETURNS VOID
AS $procedure$
BEGIN
       INSERT INTO roles_groups(role_id,action_group_id)
       SELECT v_role_id, v_action_group_id
       WHERE NOT EXISTS (SELECT 1
                         FROM roles_groups
                         WHERE role_id = v_role_id
                         AND action_group_id = v_action_group_id);
RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_split_config_value(v_option_name character varying, v_old_option_value character varying, v_new_option_value character varying, v_update_from_version character varying)
  RETURNS void AS
$BODY$
declare
v_old_value varchar(4000);
v_cur cursor for select distinct version from vdc_options where version <> 'general' order by version;
v_version varchar(40);
v_index integer;
v_count integer;
v_total_count integer;
v_version_count integer;
begin
    v_total_count := count(version) from vdc_options where option_name = v_option_name;
    v_old_value := option_value from vdc_options where option_name = v_option_name and version = 'general';
    v_version_count := count(distinct version) from vdc_options where version <> 'general';
    if (v_total_count <= v_version_count) then
        begin
            if (v_old_value IS NULL) then
                v_old_value := v_old_option_value;
            end if;
            v_count := count(distinct version) from vdc_options where version <> 'general';
            v_index := 1;
        open v_cur;
        loop
            fetch v_cur into v_version;
            exit when not found;
            -- We shouldn't update if already exists
            if (not exists (select 1 from vdc_options where option_name = v_option_name and version = v_version)) then
                -- Might not work well for versions such as 3.10, but we currently don't have any
                if (v_version >= v_update_from_version) then
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_new_option_value, v_version);
                else
                    insert into vdc_options (option_name, option_value, version) values (v_option_name, v_old_value, v_version);
                end if;
            end if;
            v_index := v_index +1;
        end loop;
        close v_cur;
        delete from vdc_options where option_name = v_option_name and version = 'general';
        end;
    end if;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_grant_action_group_to_all_roles_filter(v_action_group_id integer, uuid[])
  RETURNS void AS
$BODY$
declare
v_role_id_to_filter alias for $2;
begin
    insert into roles_groups (role_id, action_group_id)
    select distinct role_id, v_action_group_id
    from roles_groups rg
    where not ARRAY [role_id] <@ v_role_id_to_filter and not exists (select 1 from roles_groups where role_id = rg.role_id and action_group_id = v_action_group_id);
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION fn_db_mask_object(v_object regclass) RETURNS setof record as
$BODY$
DECLARE
    v_sql TEXT;
    v_table record;
    v_table_name TEXT;
    temprec record;
BEGIN
    -- get full table/view name from v_object (i.e <namespace>.<name>)
    select c.relname, n.nspname INTO v_table
        FROM pg_class c join pg_namespace n on c.relnamespace = n.oid WHERE c.oid = v_object;
    -- try to get filtered query syntax from previous execution
    if exists (select 1 from object_column_white_list_sql where object_name = v_table.relname) then
	select sql into v_sql from object_column_white_list_sql where object_name = v_table.relname;
    else
        v_table_name := quote_ident( v_table.nspname ) || '.' || quote_ident( v_table.relname );
        -- compose sql statement while skipping values for columns not defined in object_column_white_list for this table.
        for temprec in select a.attname, t.typname
                       FROM pg_attribute a join pg_type t on a.atttypid = t.oid
                       WHERE a.attrelid = v_object AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
        loop
            v_sql := coalesce( v_sql || ', ', 'SELECT ' );
            if exists(select 1 from object_column_white_list
               where object_name = v_table.relname and column_name = temprec.attname) then
               v_sql := v_sql || quote_ident( temprec.attname );
            ELSE
               v_sql := v_sql || 'NULL::' || quote_ident( temprec.typname ) || ' as ' || quote_ident( temprec.attname );
            END IF;
        END LOOP;
        v_sql := v_sql || ' FROM ' || v_table_name;
        v_sql := 'SELECT x::' || v_table_name || ' as rec FROM (' || v_sql || ') as x';
        -- save generated query for further use
        insert into object_column_white_list_sql(object_name,sql) values (v_table.relname, v_sql);
    end if;
    RETURN QUERY EXECUTE v_sql;
END; $BODY$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_add_column_to_object_white_list(v_object_name varchar(128), v_column_name varchar(128))
returns void
AS $procedure$
begin
    if (not exists (select 1 from object_column_white_list
                    where object_name = v_object_name and column_name = v_column_name)) then
        begin
            -- verify that there is such object in db
            if exists (select 1 from information_schema.columns
                       where table_name = v_object_name and column_name = v_column_name) then
                insert into object_column_white_list (object_name, column_name) values (v_object_name, v_column_name);
            end if;
        end;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_disk(v_id UUID)
returns void
AS $procedure$
declare
    OK integer;
    LOCKED integer;
begin
    OK:=1;
    LOCKED:=2;
    update images set imagestatus = OK where imagestatus = LOCKED and
    image_group_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_snapshot(v_id UUID)
returns void
AS $procedure$
declare
    OK varchar;
    LOCKED varchar;
begin
    OK:='OK';
    LOCKED:='LOCKED';
    update snapshots set status = OK where status = LOCKED and snapshot_id = v_id;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
create or replace FUNCTION fn_db_unlock_entity(v_object_type varchar(10), v_name varchar(255), v_recursive boolean)
returns void
AS $procedure$
declare
    DOWN integer;
    OK integer;
    LOCKED integer;
    TEMPLATE_OK integer;
    TEMPLATE_LOCKED integer;
    IMAGE_LOCKED integer;
    SNAPSHOT_OK varchar;
    SNAPSHOT_LOCKED varchar;
    v_id UUID;
begin
    DOWN:=0;
    OK:=1;
    LOCKED:=2;
    TEMPLATE_OK:=0;
    TEMPLATE_LOCKED:=1;
    IMAGE_LOCKED:=15;
    SNAPSHOT_OK:='OK';
    SNAPSHOT_LOCKED:='LOCKED';
    v_id := vm_guid from vm_static where vm_name = v_name and entity_type ilike v_object_type;
    -- set VM status to DOWN
    if (v_object_type = 'vm') then
        update vm_dynamic set status = DOWN where status = IMAGE_LOCKED and vm_guid  = v_id;
    -- set Template status to OK
    else
        if (v_object_type = 'template') then
            update vm_static set template_status = TEMPLATE_OK where template_status = TEMPLATE_LOCKED and vm_guid  = v_id;
        end if;
    end if;
    --unlock images and snapshots  if recursive flag is set
    if (v_recursive) then
        update images set imagestatus = OK where imagestatus = LOCKED and
        image_group_id in (select device_id from vm_device where vm_id = v_id and is_plugged);

        update snapshots set status = SNAPSHOT_OK where status ilike SNAPSHOT_LOCKED and vm_id = v_id;
    end if;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
/* Displays DC id , DC name, SPM Host id , SPM Host name and number of async tasks awaiting.

1) create a record type with DC name, DC id, SPM host id, SPM host name, count

2) get all distinct DC ids from async_tasks table

3) Run a cursor for each result in 2)

   a) get DC name
   b) get SPM Host id & name if available
   c) get count of tasks

   return current record

4) return set of generated records
*/
DROP TYPE IF EXISTS async_tasks_info_rs CASCADE;
**************************

DROP TYPE
********* QUERY **********
CREATE TYPE async_tasks_info_rs AS (
        dc_id uuid,
        dc_name character varying,
        spm_host_id uuid,
        spm_host_name character varying,
        task_count integer
);
**************************

CREATE TYPE
********* QUERY **********
create or replace FUNCTION fn_db_get_async_tasks()
returns SETOF async_tasks_info_rs STABLE
AS $procedure$
DECLARE
    v_record async_tasks_info_rs;

    -- selects storage_pool_id uuid found in async_tasks
    v_tasks_cursor cursor for select distinct storage_pool_id from async_tasks;
begin

    OPEN v_tasks_cursor;
    FETCH v_tasks_cursor into v_record.dc_id;
    WHILE FOUND LOOP
        -- get dc_name and SPM Host id
        v_record.dc_name := name from storage_pool where id = v_record.dc_id;
        v_record.spm_host_id :=
            spm_vds_id from storage_pool where id = v_record.dc_id;
        -- get Host name if we have non NULL SPM Host
        if (v_record.spm_host_id IS NOT NULL) then
            v_record.spm_host_name :=
                vds_name from vds_static where vds_id = v_record.spm_host_id;
        else
            v_record.spm_host_name:='';
        end if;
        -- get tasks count for this DC
        v_record.task_count := count(*) from async_tasks
            where position (cast(v_record.dc_id as varchar) in action_parameters) > 0;
        -- return the record
        RETURN NEXT v_record;
        FETCH v_tasks_cursor into v_record.dc_id;
    END LOOP;
    CLOSE v_tasks_cursor;
    -- return full set of generated records
    RETURN;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
Create or replace FUNCTION fn_db_remove_csv_config_value(v_option_name varchar(100), v_value varchar(4000), v_version varchar(40))
returns void
AS $procedure$
DECLARE
v varchar[];
e varchar;
v_result varchar;
v_sep varchar(1);
BEGIN
v_result := '';
v_sep := '';
    v := string_to_array(option_value, ',') from vdc_options where option_name = v_option_name and version = v_version;
    FOR e in select unnest(v)
    LOOP
        IF (e != v_value) THEN
            v_result := v_result || v_sep || e;
            v_sep := ',';
        END IF;
    END LOOP;
    UPDATE vdc_options set option_value = v_result where option_name = v_option_name and version = v_version;
END; $procedure$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
CREATE OR REPLACE FUNCTION __temp_add_object_column_white_list_table()
RETURNS void
AS $function$
BEGIN
   -- This table holds the column white list per object
   IF EXISTS (SELECT * FROM pg_tables WHERE tablename ILIKE 'object_column_white_list') THEN
       truncate table object_column_white_list;
   ELSE
      CREATE TABLE object_column_white_list
      (
         object_name varchar(128) NOT NULL,
         column_name varchar(128) NOT NULL,
         CONSTRAINT pk_object_column_white_list PRIMARY KEY(object_name,column_name)
      ) WITH OIDS;
   END IF;

   -- this table holds generated sql per object and is truncated upon upgrade to reflect schema changes
   IF EXISTS (SELECT * FROM pg_tables WHERE tablename ILIKE 'object_column_white_list_sql') THEN
       truncate table object_column_white_list_sql;
   ELSE
      CREATE TABLE object_column_white_list_sql
      (
         object_name varchar(128) NOT NULL,
         sql text NOT NULL,
         CONSTRAINT pk_object_column_white_list_sql PRIMARY KEY(object_name)
      ) WITH OIDS;

   END IF;
   -----------------------------------
   -- Initial white list settings  ---
   -----------------------------------
   --            vds view
   -----------------------------------
   --  A new added column will not be displayed for the user unless added specifically.
      insert into object_column_white_list(object_name,column_name)
      (select 'vds', column_name
       from information_schema.columns
       where table_name = 'vds' and
       column_name in (
          'vds_group_id', 'vds_group_name', 'vds_group_description',
          'vds_id', 'vds_name', 'ip', 'vds_unique_id', 'host_name', 'port', 'vds_strength',
          'server_ssl_enabled', 'vds_type', 'pm_type', 'pm_user', 'pm_port', 'pm_options',  'pm_enabled',
          'pm_proxy_preferences', 'pm_secondary_ip', 'pm_secondary_type', 'pm_secondary_user', 'pm_secondary_port',
          'pm_secondary_options', 'pm_secondary_concurrent', 'vds_spm_priority', 'hooks', 'status', 'cpu_cores',
          'cpu_model', 'cpu_speed_mh', 'if_total_speed', 'kvm_enabled', 'physical_mem_mb',
          'pending_vcpus_count', 'pending_vmem_size', 'mem_commited', 'vm_active', 'vm_count',
          'vm_migrating', 'vms_cores_count', 'cpu_over_commit_time_stamp', 'hypervisor_type',
          'net_config_dirty', 'max_vds_memory_over_commit', 'storage_pool_id', 'storage_pool_name', 'reserved_mem',
          'guest_overhead', 'software_version', 'version_name', 'build_name', 'previous_status',
          'cpu_idle', 'cpu_load', 'cpu_sys', 'cpu_user', 'usage_mem_percent', 'usage_cpu_percent',
          'usage_network_percent', 'mem_available', 'mem_shared', 'swap_free', 'swap_total', 'ksm_cpu_percent',
          'ksm_pages', 'ksm_state', 'cpu_flags', 'vds_group_cpu_name', 'cpu_sockets', 'vds_spm_id',
          'otp_validity', 'spm_status', 'supported_cluster_levels', 'supported_engines',
          'vds_group_compatibility_version', 'vds_group_virt_service', 'vds_group_gluster_service', 'host_os', 'kvm_version', 'libvirt_version', 'spice_version', 'kernel_version',
          'iscsi_initiator_name', 'transparent_hugepages_state', 'anonymous_hugepages',
          'non_operational_reason', 'recoverable', 'sshkeyfingerprint', 'count_threads_as_cores', 'cpu_threads',
          'hw_manufacturer', 'hw_product_name', 'hw_version', 'hw_serial_number', 'hw_uuid', 'hw_family', 'ssh_port', 'ssh_username', 'boot_time',
          'pm_detect_kdump', 'protocol'));
-- pm_options are missing
END; $function$
LANGUAGE plpgsql;
**************************

CREATE FUNCTION
********* QUERY **********
SELECT * FROM __temp_add_object_column_white_list_table();
**************************

 

********* QUERY **********
DROP FUNCTION __temp_add_object_column_white_list_table();
**************************

DROP FUNCTION
********* QUERY **********
select fn_db_add_column_to_object_white_list('vds', 'selinux_enforce_mode');
**************************

 

********* QUERY **********
select fn_db_add_column_to_object_white_list('vds', 'auto_numa_balancing');
**************************

 

********* QUERY **********
select fn_db_add_column_to_object_white_list('vds', 'is_numa_supported');
**************************

 

********* QUERY **********
select fn_db_add_column_to_object_white_list('vds', 'is_live_snapshot_supported');
**************************

 

********* QUERY **********
select fn_db_add_column_to_object_white_list('vds', 'protocol');
**************************

 

********* QUERY **********
/******************************************************************************************************
                          Snapshot Materialized Views Definitions Section
******************************************************************************************************/
/******************************************************************************************************
                          Snapshot Materialized Views Index Definitions Section
******************************************************************************************************/
/******************************************************************************************************
If your Snapshot Materialized View is my_mt you should create Stored Procedures:
MtDropmy_mtIndexes - Drops indexes on my_mt
MtCreatemy_mtIndexes - Creates needed indexes on my_mt
******************************************************************************************************/
**************************

********* QUERY **********
select RefreshAllMaterializedViews(true);
**************************

 

********* QUERY **********

**************************

2014-10-20 14:42:23 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.db.schema plugin.executeRaw:803 execute-result: ['/usr/share/ovirt-engine/dbscripts/schema.sh', '-s', 'localhost', '-p', '5432', '-u', 'engine', '-d', 'engine', '-l', '/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log', '-c', 'apply'], rc=0
2014-10-20 14:42:23 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.db.schema plugin.execute:861 execute-output: ['/usr/share/ovirt-engine/dbscripts/schema.sh', '-s', 'localhost', '-p', '5432', '-u', 'engine', '-d', 'engine', '-l', '/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log', '-c', 'apply'] stdout:
Creating schema engine@localhost:5432/engine
Creating fresh schema
Creating tables...
Creating functions...
Creating common functions...
Inserting data...
Inserting pre-defined roles...
Saving custom users permissions on database objects...
upgrade script detected a change in Config, View or Stored Procedure...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/pre_upgrade/0000_config.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/pre_upgrade/0010_custom.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/pre_upgrade/0020_add_materialized_views_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/pre_upgrade/0030_materialized_views_extensions.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/pre_upgrade/0040_extend_installed_by_column.sql'...
Dropping materialized views...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0010_add_migration_to_network_cluster.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0020_add_gluster_hooks_roles.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0030_add_edit_admin_vm_props.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0040_add_run_and_pause_to_vm.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0050_repo_file_id.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0060_drop_desktop_device.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0070_drop_iconpath.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0080_drop_roles_relations.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0090_edit_storage_conn_version_support.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0100_update_imagestatus_invalid_to_illegal.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0110_drop_storage_owner.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0120_add_max_assigned_vms_per_user.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0130_add_gluster_services_tables.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0140_add_gluster_server_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0150_add_providers_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0160_increase_guest_ram.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0170_watchdog.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0180_add_device_custom_prop.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0190_add_memory_volume_to_snapshots.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0200_add_gluster_service_roles.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0210_add_hbas_col.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0220_add_call_stack_to_audit_log.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0230_update_removeglusterserver_action_version_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0240_add_gluster_hooks_services_events.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0250_upgrade_utcdiff_and_timezone_for_linux.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0260_add_base_disks_sgio_column.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0270_add_permission_to_configure_sgio.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0280_add_comment_storage_pool.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0290_add_custom_properties_to_providers.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0300_add_tenant_and_plugin_type_to_providers.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0310_add_provided_by_to_network.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0320_base_disks_alignment.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0330_add_emulated_machine_to_host_and_cluster.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0340_upgrade_to_cluster_emulated_machine.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0350_add_vdsm_task_id_and_index_to_async_tasks.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0360_add_root_command_id_to_async_tasks.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0370_add_trusted_service_to_vds_groups.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0380_remove_auto_suspend.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0390_add_created_by_user_id_column.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0400_remove_unused_colums_from_user.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0410_alignment_not_null.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0420_add_storage_static_description_column.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0430_add_tunnel_migration.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0440_add_free_mem_to_vds_statistics.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0450_add_external_tasks_support.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0460_add_network_qos_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0470_add_extend_image_size_action_version_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0480_upgrade_cluster_policy.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0490_add_agent_configuration_to_provider.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0500_add_enable_balloon_to_vds_groups.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0510_add_vds_ssh_fields.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0520_add_comment_network.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0530_add_comment_vds_static.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0540_add_comment_vds_groups.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0550_glance_import_command.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0560_glance_export_command.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0570_add_comment_storage_domain_static.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0580_remove_selection_algorithm_columns.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0590_add_comment_vm_static_and_pool.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0600_add_trusted_service_notifications.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0610_spice_as_default_display_type_on_blank_template.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0620_add_external_id_to_users.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0630_add_missing_event_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0640_default_vdsstatic_values_to_ssh_fields.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0650_add_signle_qxl_pci_column.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0660_alter_os_type_unassigned_to_other.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0670_allow_single_logic_for_policy_unit.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0680_add_cpu_shares_to_vm.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0690_add_enabled_column_to_policy_unit.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0700_add_is_run_once_to_vm_dynamic.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0710_add_profile_to_network_interface.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0720_drop_columns_from_vm_interface.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0730_update_attestation_server.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0740_add_description_to_policy_unit.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0750_add_network_qos_id_to_vnic_profiles.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0760_preserve_network_user_id_for_vnic_profile.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0770_alter_vm_interface_vnic_profile_fk.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0780_convert_empty_timezone_to_null.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0790_remove_migration_domain_filter.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0800_add_vm_vnc_keyboard_layout.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0810_add_app_mode_to_roles.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0820_add_task_id_to_volumeandbricks.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0830_add_stop_rebalance_gluster_volume_to_event_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0840_add_job_start_time_index.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0850_rename_template_user_role.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0860_remove_import_export_permissions_from_vm_user_manager.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0870_add_detect_emulated_machine_to_cluster.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0880_add_dwh_osinfo_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0890_image_domains_permissions.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0900_quota_id_foreign_key.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0910_remove_migration_filter.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0920_add_fqdn_to_vm_dynamic.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0930_add_cpu_name_to_vm_dynamic.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0940_add_cpu_level_policy_unit.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0950_change_policy_names.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0960_add_dwh_heartbeat.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0970_add_start_remove_gluster_volume_brick_to_event_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0980_clear_snapshot_id_of_floating_disks.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_03_0990_pin_to_host_first_in_powersaving_policy.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0010_add_instance_type_to_vm.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0020_add_instance_permissions.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0030_add_ha_score_to_vds_statistics.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0040_add_ha_policy_units.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0050_move_rename_of_other_linux_type.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0060_add_snapshot_id_column_to_vm_device.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0070_index_network_by_external_id.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0080_add_brick_status_change_event_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0090_move_quota_id.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0100_add_cluster_host_permissions_to_gluster_admin_role.sql'...
Skipping upgrade script /usr/share/ovirt-engine/dbscripts/upgrade/03_04_0110_change_policy_names.sql, already installed by 03030950
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0120_add_gluster_version_to_vds_dynamic.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0130_add_start_time_idx_job.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0140_add_sso_method_to_vm_static.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0150_gluster_async_tasks_finished_event_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0160_create_read_only_admin_role.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0170_add_architecture_name_column.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0180_add_vds_group_optimization_field.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0190_gluster_async_tasks_stop_remove-brick_event_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0200_gluster_async_tasks_fromcli_event_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0210_replace_storage_type_all_with_unknown.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0220_add_console_events.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0230_vm_down_error_and_vds_initiated_run_fail_event_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0240_gluster_async_tasks_notfound_fromcli_event_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0250_rename_user_and_group_status_to_active.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0260_add_external_id_to_groups.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0270_add_task_id_idx_gluster_bricks.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0280_add_original_template_to_vm_static.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0290_add_spice_proxy_to_vds_groups_and_vm_pools.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0300_add_label_column_to_networks.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0310_add_labels_column_to_vds_interfaces.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0320_move_anonymousHugePages.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0330_add_admin_operations_action_groups_and_roles.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0340_add_network_labels_action_groups.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0350_relax_network_qos_constraints.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0360_add_qos_id_to_network.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0370_add_qos_overridden_to_vds_interface.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0380_add_last_stop_time_to_vm_dynamic.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0390_add_ha_reservation.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0400_add_var_on_dwh_status.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0410_add_even_guest_distribution_policy.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0420_add_vds_pm_flags.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0430_add_power_management_to_cluster_policy.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0440_create_affinity_group_tables.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0450_add_affinity_group_action_group.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0460_add_affinity_group_filter_and_weight.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0470_add_reboot_command.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0480_add_vm_migration_downtime.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0490_add_enable_ksm_to_vds_groups.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0500_add_iscsi_bond.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0510_set_proxy_preferences_default.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0520_add_tables_for_gluster_volume_and_brick_details.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0530_gluster_refresh_gluster_volume_details-event_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0540_remove_storage_pool_type.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0550_add_template_version_to_vm_static.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0560_add_vm_init_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0570_add_all_basic_filters_to_even_guest_policy.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0580_add_restart_different_host_event.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0590_change_storage_server_connections_password_length.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0600_add_current_cd_to_vm_dynamic.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0610_map_vds_detected_to_event_map.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0620_remove_directory_suffix_from_login_name.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0630_fix_admin_internal_permissions.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_04_0640_fix_even_guest_distribution_parameters.sql'...
Skipping upgrade script /usr/share/ovirt-engine/dbscripts/upgrade/03_05_0010_add_tables_for_gluster_volume_and_brick_details.sql, already installed by 03040520
Skipping upgrade script /usr/share/ovirt-engine/dbscripts/upgrade/03_05_0020_gluster_refresh_gluster_volume_details-event_map.sql, already installed by 03040530
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0030_add_ha_columns_to_vds_statistics.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0040_add_ha_maintenance_events.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0050_event_notification_methods.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0060_event_map_vds_failure.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0070_fix_event_notfication_method.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0080_add_missing_manipulate_users_permissions.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0090_delete_network_labels_action_groups.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0100_allow_values_higher_9_for_cpuovercommit.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0110_add_vm_serial_number_policy.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0120_add_storage_domain_ovf.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0130_add_ovf_data_column.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0140_add_install_vds_upgrade_ovirt_node_action_group.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0150_remove_import_export_permission_from_user_instance_manager_role.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0160_add_host_interface_high_network_use_event.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0170_add_boot_time_to_vds_statistics.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0180_vm_init_add_sysprep_locale.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0190_vm_init_add_user_name.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0200_vm_init_add_active_directory_ou.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0210_change_group_ids.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0220_update_user_ids.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0230_add_host_interface_status_change_events.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0240_change_external_id_to_string.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0250_add_reason_columns.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0260_add_exit_reason_to_vm_dynamic.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0270_update_template_version_naming.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0280_add_vm_boot_menu.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0290_drop_vds_group_id_constraint_from_vm_static.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0300_add_host_kdump_detection.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0310_add_host_kdump_status.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0320_add_vds_interface_custom_properties.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0330_nullify_external_network_labels.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0340_add_migration_progress_percent_to_vm_dynamic.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0350_add_display_network_change_events.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0360_add_audit_log_operation_action_group_and_roles.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0370_add_base_interface_column_to_vds_interfaces.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0380_reintroduce_powersaving_variables.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0390_add_guest_cpu_count_to_vm_dynamic.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0400_index_for_snapshot_type.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0410_add_selinux_to_vds_dynamic.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0420_generalize_messaging_broker_type.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0430_add_numa_tables_and_columns.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0440_add_create_and_update_dates_to_users_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0450_set_default_value_for_numa_tune_mode.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0460_set_display_migration_cluster_network.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0470_update_vm_static_child_count.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0480_add_org_name_for_sysprep.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0490_remove_duplicate_smartcards.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0500_add_rng_device_columns.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0510_unregistered_ovf_of_entities.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0520_fix_description_of_balancing_policy_units.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0530_remove_unused_event.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0540_add_spice_transfer_toggle.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0550_add_live_snapshot_support.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0560_aaa_add_namespace.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0570_deprecate_broken_snapshots.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0580_add_default_instance_types.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0590_set_default_time_zone.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0600_drop_images_fk.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0610_add_command_entity_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0620_lowercase_default_cluster_policies_names.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0630_add_host_protocol.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0640_add_external_variable.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0650_add_vds_kdump_status.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0660_remove_command_from_async_tasks.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0670_add_cmd_entity_callback_enabled.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0680_add_cmd_entity_callback_notified.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0690_add_cmd_entity_return_value.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0700_create_vm_jobs_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0710_add_manipulate_permissions_for_template_admin.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0720_index_for_stoarge_domain_id_in_unregistered_ovf_of_entities.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0730_drop_disk_image_dynamic_fk.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0740_min_allocated_memory_on_instance_type.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0750_delete_orphand_disk_image_dynamic_records.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0760_update_haswell_vds_to_new_name.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0770_set_name_for_internal_user.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0780_add_job_step_ids_to_command_entities.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0790_add_executed_to_command_entities.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0800_update_blank_template_origin_type.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0810_update_sgio_for_readonly_disks.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0820_reset_rng_sources.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0830_add_provider_host_id_vdsstatic.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0840_add_live_merge_supported.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0850_skip_fencing_when_sd_is_alive.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0860_clear_address_for_unplugged_disks.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0870_rename_async_tasks_columns.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0880_add_dwh_hostname_and_uuid.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0890_remove_active_column_from_groups.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0900_skip_fencing_when_connectivity_broken.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0910_disable_fencing_in_cluster.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0920_remove_external_network_labels.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0930_convert_cow_preallocated_to_cow_sparse.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0940_add_qos_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0950_add_disk_profiles_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0960_add_disk_profile_action_groups.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0970_disk_profile_for_disk_image.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0980_add_cpu_profiles_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_0990_add_cpu_limit_to_qos_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_1000_add_cpu_profile_id_to_vm_static.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_1010_remove_blank_template_cpu_profile.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_1020_change_virtio_serial_to_managed_device.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_1030_refactor_network_qos.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_1040_remove_install_vds_upgrade_ovirt_node_action_group.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_1050_async_tasks_add_root_command_id.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/03_05_1060_set_time_drift_validation.sql'...
Creating views...
Creating stored procedures...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/action_version_map_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/ad_groups_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/affinity_groups_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/all_disks_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/async_tasks_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/audit_log_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/base_disks_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/bookmarks_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/business_entity_snapshot_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/cluster_policy_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/command_entities_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/common_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/cpu_profiles_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/custom_actions_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/disk_image_dynamic_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/disk_images_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/disk_lun_map_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/disk_profiles_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/dwh_history_timekeeping_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/dwh_translation_tables_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/event_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/external_variable_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/gluster_hooks_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/gluster_server_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/gluster_services_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/gluster_volumes_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/images_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/image_storage_domain_map_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/inst_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/iscsi_bonds_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/job_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/materialized_views_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/multi_level_administration_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/network_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/numa_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/policy_unit_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/providers_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/qos_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/quota_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/repo_files_meta_data_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/snapshots_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/storages_san_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/storages_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/system_statistics_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/tags_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/tags_vm_pool_map_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/unregistered_OVF_data_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/user_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/vdc_option_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/vds_groups_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/vds_kdump_status_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/vds_spm_id_map_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/vds_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/vm_device_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/vm_jobs_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/vm_pool_maps_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/vm_pools_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/vms_sp.sql...
Creating stored procedures from /usr/share/ovirt-engine/dbscripts/vm_templates_sp.sql...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/post_upgrade/0010_add_object_column_white_list_table.sql'...
Running upgrade sql script '/usr/share/ovirt-engine/dbscripts/upgrade/post_upgrade/0020_create_materialized_views.sql'...
Refreshing materialized views...
Applying custom users permissions on database objects...

2014-10-20 14:42:23 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.db.schema plugin.execute:866 execute-output: ['/usr/share/ovirt-engine/dbscripts/schema.sh', '-s', 'localhost', '-p', '5432', '-u', 'engine', '-d', 'engine', '-l', '/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log', '-c', 'apply'] stderr:


2014-10-20 14:42:23 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.db.connection.Plugin._connection
2014-10-20 14:42:23 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:42:23 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/connection=connection:'<connection object at 0x2dad210; dsn: 'dbname=engine host=localhost port=5432 user=engine password=xxxxxxxxxxxxxxxxxxxxxx sslmode=allow', closed: 0>'
2014-10-20 14:42:23 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/statement=Statement:'<ovirt_engine_setup.engine_common.database.Statement object at 0x4078190>'
2014-10-20 14:42:23 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:42:23 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.appmode.Plugin._misc
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'AutoRegistrationDefaultVdsGroupID'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '00000001-0001-0001-0001-000000000121'}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select inst_update_service_type(
                    %(clusterId)s,
                    %(virt)s,
                    %(gluster)s
                )
            ', args: {'virt': True, 'clusterId': '00000001-0001-0001-0001-000000000121', 'gluster': False}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'inst_update_service_type': ''}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select fn_db_update_config_value(
                        'ApplicationMode',
                        %(mode)s,
                        'general'
                    )
                ', args: {'mode': '1'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'fn_db_update_config_value': ''}]
2014-10-20 14:42:23 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.domain_type.Plugin._misc
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select inst_update_default_storage_pool_type (%(is_local)s)
            ', args: {'is_local': False}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'inst_update_default_storage_pool_type': ''}]
2014-10-20 14:42:23 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.iso_domain.Plugin._add_iso_domain_to_db
2014-10-20 14:42:23 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:23 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.macrange.Plugin._misc
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'MacPoolRanges'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'MacPoolRanges', 'value': '00:1a:4a:e2:37:00-00:1a:4a:e2:37:ff'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._miscAlways
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'ProductRPMVersion'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'ProductRPMVersion', 'value': '3.5.0.1-1.el6'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._miscNewDatabase
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'SSLEnabled'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'SSLEnabled', 'value': 'true'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'EncryptHostCommunication'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'EncryptHostCommunication', 'value': 'true'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'EncryptHostCommunication'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'EncryptHostCommunication', 'value': 'true'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'ConfigDir'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'ConfigDir', 'value': '/etc/ovirt-engine'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'DataDir'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'DataDir', 'value': '/usr/share'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'WebSocketProxy'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'WebSocketProxy', 'value': 'ex1.gecko.hs-heilbronn.de:6100'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.public_glance_repository.Plugin._misc
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select inst_add_glance_provider(
                    %(provider_id)s,
                    %(provider_name)s,
                    %(provider_description)s,
                    %(provider_url)s,
                    %(storage_domain_id)s
                )
            ', args: {'provider_url': 'http://glance.ovirt.org:9292', 'provider_name': 'ovirt-image-repository', 'storage_domain_id': '072fbaa1-08f3-4a40-9f34-a5ca22dd1d74', 'provider_description': 'Public Glance repository for oVirt', 'provider_id': 'ceab03af-7220-4d42-8f5c-9b557f5d29af'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'inst_add_glance_provider': ''}]
2014-10-20 14:42:23 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.legacy.osinfo.Plugin._misc
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'SysPrep2K3Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '/etc/ovirt-engine/sysprep/sysprep.2k3'}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'SysPrep2K3Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'SysPrep2K3Path', 'value': ''}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'SysPrep2K8Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '/etc/ovirt-engine/sysprep/sysprep.2k8x86'}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'SysPrep2K8Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'SysPrep2K8Path', 'value': ''}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'SysPrep2K8R2Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '/etc/ovirt-engine/sysprep/sysprep.2k8'}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'SysPrep2K8R2Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'SysPrep2K8R2Path', 'value': ''}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'SysPrep2K8x64Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '/etc/ovirt-engine/sysprep/sysprep.2k8'}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'SysPrep2K8x64Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'SysPrep2K8x64Path', 'value': ''}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'SysPrepWindows2012x64Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '/etc/ovirt-engine/sysprep/sysprep.2k12x64'}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'SysPrepWindows2012x64Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'SysPrepWindows2012x64Path', 'value': ''}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'SysPrepWindows7Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '/etc/ovirt-engine/sysprep/sysprep.w7'}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'SysPrepWindows7Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'SysPrepWindows7Path', 'value': ''}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'SysPrepWindows7x64Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '/etc/ovirt-engine/sysprep/sysprep.w7x64'}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'SysPrepWindows7x64Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'SysPrepWindows7x64Path', 'value': ''}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'SysPrepWindows8Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '/etc/ovirt-engine/sysprep/sysprep.w8'}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'SysPrepWindows8Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'SysPrepWindows8Path', 'value': ''}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'SysPrepWindows8x64Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '/etc/ovirt-engine/sysprep/sysprep.w8x64'}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'SysPrepWindows8x64Path'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'SysPrepWindows8x64Path', 'value': ''}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'SysPrepXPPath'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '/etc/ovirt-engine/sysprep/sysprep.xp'}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'SysPrepXPPath'}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'SysPrepXPPath', 'value': ''}
2014-10-20 14:42:23 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:23 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.legacy.osinfo osinfo._misc:142 legacy sysprep fixup: []
2014-10-20 14:42:23 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.legacy.osinfo osinfo._misc:143 legacy sysprep remove: set([])
2014-10-20 14:42:23 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._misc
2014-10-20 14:42:23 DEBUG otopi.transaction transaction._prepare:77 preparing 'CA Transaction'
2014-10-20 14:42:23 INFO otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca ca._misc:205 Creating CA
2014-10-20 14:42:23 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/pki/ovirt-engine/cacert.template''
2014-10-20 14:42:23 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/pki/ovirt-engine/cacert.template' missing
2014-10-20 14:42:23 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/pki/ovirt-engine/cert.template''
2014-10-20 14:42:23 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/pki/ovirt-engine/cert.template' missing
2014-10-20 14:42:23 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/pki/ovirt-engine/cert.template''
2014-10-20 14:42:23 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/pki/ovirt-engine/cert.template
2014-10-20 14:42:23 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:23 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/pki/ovirt-engine/cacert.template''
2014-10-20 14:42:23 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/pki/ovirt-engine/cacert.template
2014-10-20 14:42:23 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:23 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-create-ca.sh', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de.17578', '--keystore-password=**FILTERED**'), executable='None', cwd='None', env={'LESSOPEN': '|/usr/bin/lesspipe.sh %s', 'SSH_CLIENT': '141.7.157.203 50719 22', 'CVS_RSH': 'ssh', 'LOGNAME': 'root', 'USER': 'root', 'HOME': '/root', 'PATH': '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin', 'LANG': 'en_US.UTF-8', 'TERM': 'ansi', 'SHELL': '/bin/bash', 'SHLVL': '1', 'G_BROKEN_FILENAMES': '1', 'HISTSIZE': '1000', 'JAVA_HOME': u'/usr/lib/jvm/jre', 'PYTHONPATH': '/usr/share/ovirt-engine/setup/bin/..::', 'OTOPI_LOGFILE': '/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log', 'LS_OPTIONS': '--human --color=always', 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:', 'SSH_TTY': '/dev/pts/0', 'HOSTNAME': 'ex1.gecko.hs-heilbronn.de', 'HISTCONTROL': 'ignoredups', 'PWD': '/root', 'MAIL': '/var/spool/mail/root', 'SSH_CONNECTION': '141.7.157.203 50719 148.251.139.133 22', 'OTOPI_EXECDIR': '/root'}
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-create-ca.sh', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de.17578', '--keystore-password=**FILTERED**'), rc=0
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:861 execute-output: ('/usr/share/ovirt-engine/bin/pki-create-ca.sh', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de.17578', '--keystore-password=**FILTERED**') stdout:


2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:866 execute-output: ('/usr/share/ovirt-engine/bin/pki-create-ca.sh', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de.17578', '--keystore-password=**FILTERED**') stderr:
Generating RSA private key, 2048 bit long modulus
...........................................+++
..........................................................+++
e is 65537 (0x10001)
Using configuration from openssl.conf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'US'
organizationName      :PRINTABLE:'gecko.hs-heilbronn.de'
commonName            :PRINTABLE:'ex1.gecko.hs-heilbronn.de.17578'
Certificate is to be certified until Oct 17 12:42:24 2024 GMT (3650 days)

Write out database with 1 new entries
Data Base Updated
Certificate was added to keystore

2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=engine', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de'), executable='None', cwd='None', env=None
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=engine', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de'), rc=0
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:861 execute-output: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=engine', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de') stdout:


2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:866 execute-output: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=engine', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de') stderr:
Generating RSA private key, 2048 bit long modulus
...............................................................+++
.....................+++
e is 65537 (0x10001)
Using configuration from openssl.conf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'US'
organizationName      :PRINTABLE:'gecko.hs-heilbronn.de'
commonName            :PRINTABLE:'ex1.gecko.hs-heilbronn.de'
Certificate is to be certified until Sep 24 12:42:24 2019 GMT (1800 days)

Write out database with 1 new entries
Data Base Updated

2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=apache', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de'), executable='None', cwd='None', env=None
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=apache', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de'), rc=0
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:861 execute-output: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=apache', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de') stdout:


2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:866 execute-output: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=apache', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de') stderr:
Generating RSA private key, 2048 bit long modulus
............................................................................................................+++
...............................................+++
e is 65537 (0x10001)
Using configuration from openssl.conf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'US'
organizationName      :PRINTABLE:'gecko.hs-heilbronn.de'
commonName            :PRINTABLE:'ex1.gecko.hs-heilbronn.de'
Certificate is to be certified until Sep 24 12:42:24 2019 GMT (1800 days)

Write out database with 1 new entries
Data Base Updated

2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=jboss', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de'), executable='None', cwd='None', env=None
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=jboss', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de'), rc=0
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:861 execute-output: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=jboss', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de') stdout:


2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:866 execute-output: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=jboss', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de') stderr:
Generating RSA private key, 2048 bit long modulus
.......+++
..............+++
e is 65537 (0x10001)
Using configuration from openssl.conf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'US'
organizationName      :PRINTABLE:'gecko.hs-heilbronn.de'
commonName            :PRINTABLE:'ex1.gecko.hs-heilbronn.de'
Certificate is to be certified until Sep 24 12:42:24 2019 GMT (1800 days)

Write out database with 1 new entries
Data Base Updated

2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=websocket-proxy', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de'), executable='None', cwd='None', env=None
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=websocket-proxy', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de'), rc=0
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:861 execute-output: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=websocket-proxy', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de') stdout:


2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:866 execute-output: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=websocket-proxy', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de') stderr:
Generating RSA private key, 2048 bit long modulus
...+++
................................................+++
e is 65537 (0x10001)
Using configuration from openssl.conf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'US'
organizationName      :PRINTABLE:'gecko.hs-heilbronn.de'
commonName            :PRINTABLE:'ex1.gecko.hs-heilbronn.de'
Certificate is to be certified until Sep 24 12:42:24 2019 GMT (1800 days)

Write out database with 1 new entries
Data Base Updated

2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=reports', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de'), executable='None', cwd='None', env=None
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=reports', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de'), rc=0
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:861 execute-output: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=reports', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de') stdout:


2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.execute:866 execute-output: ('/usr/share/ovirt-engine/bin/pki-enroll-pkcs12.sh', '--name=reports', '--password=**FILTERED**', '--subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de') stderr:
Generating RSA private key, 2048 bit long modulus
....+++
...........................................................................................+++
e is 65537 (0x10001)
Using configuration from openssl.conf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'US'
organizationName      :PRINTABLE:'gecko.hs-heilbronn.de'
commonName            :PRINTABLE:'ex1.gecko.hs-heilbronn.de'
Certificate is to be certified until Sep 24 12:42:24 2019 GMT (1800 days)

Write out database with 1 new entries
Data Base Updated

2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=websocket-proxy', '--passin=**FILTERED**', '--key=/etc/pki/ovirt-engine/keys/websocket-proxy.key.nopass'), executable='None', cwd='None', env=None
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=websocket-proxy', '--passin=**FILTERED**', '--key=/etc/pki/ovirt-engine/keys/websocket-proxy.key.nopass'), rc=0
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=reports', '--passin=**FILTERED**', '--key=/etc/pki/ovirt-engine/keys/reports.key.nopass'), executable='None', cwd='None', env=None
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=reports', '--passin=**FILTERED**', '--key=/etc/pki/ovirt-engine/keys/reports.key.nopass'), rc=0
2014-10-20 14:42:24 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=apache', '--passin=**FILTERED**', '--key=/etc/pki/ovirt-engine/keys/apache.key.nopass'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=apache', '--passin=**FILTERED**', '--key=/etc/pki/ovirt-engine/keys/apache.key.nopass'), rc=0
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_FILE_GROUP/ca_pki=list:'[['/etc/pki/ovirt-engine/cert.template', '/etc/pki/ovirt-engine/cacert.template', '/etc/pki/ovirt-engine/certs/apache.cer', '/etc/pki/ovirt-engine/keys/apache.p12', '/etc/pki/ovirt-engine/ca.pem', '/etc/pki/ovirt-engine/private/ca.pem', '/etc/pki/ovirt-engine/certs/engine.cer', '/etc/pki/ovirt-engine/keys/engine.p12', '/etc/pki/ovirt-engine/.truststore', '/etc/pki/ovirt-engine/keys/jboss.p12', '/etc/pki/ovirt-engine/certs/jboss.cer', '/etc/pki/ovirt-engine/cacert.conf', '/etc/pki/ovirt-engine/cert.conf', '/etc/pki/ovirt-engine/certs/websocket-proxy.cer', '/etc/pki/ovirt-engine/keys/websocket-proxy.p12', '/etc/pki/ovirt-engine/keys/websocket-proxy.key.nopass', '/etc/pki/ovirt-engine/keys/reports.key.nopass', '/etc/pki/ovirt-engine/keys/apache.key.nopass', '/etc/pki/ovirt-engine/apache-ca.pem']]'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_LINES_GROUP/ca_pki=dict:'{}'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.ca.Plugin._misc
2014-10-20 14:42:25 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/engine.conf.d/10-setup-pki.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/engine.conf.d/10-setup-pki.conf' missing
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_FILE_GROUP/ca_config=list:'[[]]'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_LINES_GROUP/ca_config=dict:'{}'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._miscEncrypted
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'LocalAdminPassword'}
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'LocalAdminPassword', 'value': 'TBh/aQhb2qDGXjJbdxkjC6dFNv19SkIhmQN3rZwetiV8Y2GDBMLrh5rLCFMSyheAZupW8YMPvakj3C14GZeI0GDJra2JJO8QuR1K7BmPMivkeofOZClIrk8/vU5ShlpcWSdir8uD/bGtkv5lI9q35BqZ/hc1eGZI2py9VCZm7+nCpNOktLeF7MspEAPD3AnY2tfzblQplonXHHrmfVc0nGZMmFdnBpvP2xX/pnKH5Q22j/yxrT5FYL5mQYRzbxtPMZh6Ts4hzmYVkOa0MFQIr9A+yCxD6kujFjvpxk043MssRjT0ehQ5yn0vr9/jSQfk70YK+HQXkmfMO1sUQbs81w=='}
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'AdminPassword'}
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'AdminPassword', 'value': 'pKfx3Zk1jhbhZDiuEj+9dMKTiUCdWLmUFJbpyTUoJT4Xwz9+e0/L39cAMc8ZxVAq8bbMl2VxjUzvEJ2I9L4P7Tk2+3Kntdden4Vg3xOsHFIyzNt9tsWYcZHAiHeKmp4NQLoU86JsBvy3ccnZI7CNpWwvnXBkiD+85OE4yekeVijMlbx8l1d3Rj/hbQRctZvAxn2h8wV0RLHwQ9nNUl0HlVDkEjlPW8T1X/DZW2FRl5wm6tS9WHunTEgJcSi67AjwzwlB7P+agO+CwevEfBYDMa4We1r+441lC3/D69K+pbSxlTqhODRhjf0s9hghpLwWKou0fAUpXs/joqt0xdDPgw=='}
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin.miscOptions
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                    select count(*) as count
                    from vdc_options
                    where
                        option_name=%(name)s and
                        version=%(version)s
                ', args: {'version': 'general', 'name': 'OrganizationName'}
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'count': 1L}]
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                        update vdc_options
                        set
                            option_value=%(value)s
                        where
                            option_name=%(name)s and
                            version=%(version)s
                    ', args: {'version': 'general', 'name': 'OrganizationName', 'value': 'gecko.hs-heilbronn.de'}
2014-10-20 14:42:25 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: []
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh.Plugin._misc
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=engine', '--passin=**FILTERED**', '--key=-'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=engine', '--passin=**FILTERED**', '--key=-'), rc=0
2014-10-20 14:42:25 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/pki/ovirt-engine/keys/engine_id_rsa''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/pki/ovirt-engine/keys/engine_id_rsa' missing
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=engine', '--passin=**FILTERED**', '--cert=-'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=engine', '--passin=**FILTERED**', '--cert=-'), rc=0
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh plugin.execute:861 execute-output: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=engine', '--passin=**FILTERED**', '--cert=-') stdout:
Bag Attributes
    localKeyID: 2C 37 0E C9 43 AD 08 84 6C B8 FE D7 00 09 82 B2 9B BD F7 73 
subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de
issuer=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de.17578
-----BEGIN CERTIFICATE-----
MIIEnjCCA4agAwIBAgICEAEwDQYJKoZIhvcNAQEFBQAwVzELMAkGA1UEBhMCVVMx
HjAcBgNVBAoTFWdlY2tvLmhzLWhlaWxicm9ubi5kZTEoMCYGA1UEAxMfZXgxLmdl
Y2tvLmhzLWhlaWxicm9ubi5kZS4xNzU3ODAiFxExNDEwMTkxMjQyMjQrMDAwMBcN
MTkwOTI0MTI0MjI0WjBRMQswCQYDVQQGEwJVUzEeMBwGA1UEChMVZ2Vja28uaHMt
aGVpbGJyb25uLmRlMSIwIAYDVQQDExlleDEuZ2Vja28uaHMtaGVpbGJyb25uLmRl
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzXVaMylzWyMUB6iHNxl
qJ4VPz0iO3GeQj0FM2RXFwf8cGXh9MmDMPGPLjFyytRU/niZ85V2PiqtKNjZPR0k
n9tHHjU7SwBvP3YzEOOglmlYm7+tf7V/tB5IEpuwhAe7ROLMv9CAqLJ8PZmJ/lES
VOZPh+BDCchy07tsguZpqHyp83cNLTDZaJE/A3dN3dDAJtA2NnYdLRaZ2sRd/lC5
WJTMfwCPz1QFFukPubDa3Y+83QcCWHDLnsEkrcoLjaRHiogd0UQdIAIpRdvuxCcJ
iFHt4dAYFw6b1NTNskWvsctYDk9GTKQDSfymVKbhnwZ/zqdeIInako/SF3ooVueV
2wIDAQABo4IBdDCCAXAwHQYDVR0OBBYEFNuD6r9is5jhdFmDAOaVb4k1zwyOMIGO
BggrBgEFBQcBAQSBgTB/MH0GCCsGAQUFBzAChnFodHRwOi8vZXgxLmdlY2tvLmhz
LWhlaWxicm9ubi5kZTo4MC9vdmlydC1lbmdpbmUvc2VydmljZXMvcGtpLXJlc291
cmNlP3Jlc291cmNlPWNhLWNlcnRpZmljYXRlJmZvcm1hdD1YNTA5LVBFTS1DQTCB
gAYDVR0jBHkwd4AUcRxaoG4Dqkqtw78MfWDiIcmKj42hW6RZMFcxCzAJBgNVBAYT
AlVTMR4wHAYDVQQKExVnZWNrby5ocy1oZWlsYnJvbm4uZGUxKDAmBgNVBAMTH2V4
MS5nZWNrby5ocy1oZWlsYnJvbm4uZGUuMTc1NziCAhAAMAkGA1UdEwQCMAAwDgYD
VR0PAQH/BAQDAgWgMCAGA1UdJQEB/wQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAN
BgkqhkiG9w0BAQUFAAOCAQEAlrCVIEaLswqfDSH61+OrQSFtrGpesKlxE/EOLbGW
pQUGV7yGQClyenGTWVrtoIv6O/5KEs4Aqt/tEJoccpGzt+G4C0CRld6nUyXJH6O2
HGSZxvmvfSQt9R2JjkZfvhIogLlxHFmruwqpEbdRePa9c8Hr1zPtVaqejTA+eaxI
PEz4gdYpYc3jNgYMSAnBBG2BUFi+FCKUYLYiuvgB5vXFtOW4OCjDJD4oWoKqnqsf
5tfutpmQvXcL+Ge0ljy6cULL5oc9arf6JPV3A8XAP2SqG0zzQdih8KDTTjP15mp5
qTGYFwFQGkqul65eISEO2mtlEQIE7tkI8ttXfw2KmBuAGw==
-----END CERTIFICATE-----

2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh plugin.execute:866 execute-output: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=engine', '--passin=**FILTERED**', '--cert=-') stderr:
MAC verified OK

2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PKI/sshPublicKey=str:'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7NdVozKXNbIxQHqIc3GWonhU/PSI7cZ5CPQUzZFcXB/xwZeH0yYMw8Y8uMXLK1FT+eJnzlXY+Kq0o2Nk9HSSf20ceNTtLAG8/djMQ46CWaVibv61/tX+0HkgSm7CEB7tE4sy/0ICosnw9mYn+URJU5k+H4EMJyHLTu2yC5mmofKnzdw0tMNlokT8Dd03d0MAm0DY2dh0tFpnaxF3+ULlYlMx/AI/PVAUW6Q+5sNrdj7zdBwJYcMuewSStyguNpEeKiB3RRB0gAilF2+7EJwmIUe3h0BgXDpvU1M2yRa+xy1gOT0ZMpANJ/KZUpuGfBn/Op14gidqSj9IXeihW55Xb'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._misc
2014-10-20 14:42:25 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/root/.ssh/authorized_keys''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/root/.ssh/authorized_keys' missing
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/uninstallUnremovableFiles=list:'['/etc/exports', '/etc/sysconfig/iptables', '/etc/sysctl.d/ovirt-postgresql.conf', '/var/lib/pgsql/data/postgresql.conf', '/var/lib/pgsql/data/pg_hba.conf', '/root/.ssh/authorized_keys']'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._misc
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._misc
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.upgrade.answerfile_fixup.Plugin._misc
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.selinux.Plugin._misc
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.ssl.Plugin._misc
2014-10-20 14:42:25 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/httpd/conf.d/ssl.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.prepare:196 file '/etc/httpd/conf.d/ssl.conf' exists
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.prepare:230 backup '/etc/httpd/conf.d/ssl.conf'->'/etc/httpd/conf.d/ssl.conf.20141020144225'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/uninstallUnremovableFiles=list:'['/etc/exports', '/etc/sysconfig/iptables', '/etc/sysctl.d/ovirt-postgresql.conf', '/var/lib/pgsql/data/postgresql.conf', '/var/lib/pgsql/data/pg_hba.conf', '/root/.ssh/authorized_keys', '/etc/httpd/conf.d/ssl.conf']'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_FILE_GROUP/ssl=list:'[]'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_LINES_GROUP/ssl=dict:'{'/etc/httpd/conf.d/ssl.conf': [{'removed': 'SSLCertificateFile /etc/pki/tls/certs/localhost.crt', 'added': '# SSLCertificateFile /etc/pki/tls/certs/localhost.crt'}, {'added': 'SSLCertificateFile /etc/pki/ovirt-engine/certs/apache.cer'}, {'removed': 'SSLCertificateKeyFile /etc/pki/tls/private/localhost.key', 'added': '# SSLCertificateKeyFile /etc/pki/tls/private/localhost.key'}, {'added': 'SSLCertificateKeyFile /etc/pki/ovirt-engine/keys/apache.key.nopass'}, {'added': 'SSLCACertificateFile /etc/pki/ovirt-engine/apache-ca.pem'}]}'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._check_separate
2014-10-20 14:42:25 INFO otopi.plugins.ovirt_engine_setup.websocket_proxy.config config._check_separate:153 Configuring WebSocket Proxy
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._misc_VDC
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._misc_config
2014-10-20 14:42:25 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine/ovirt-websocket-proxy.conf.d/10-setup.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine/ovirt-websocket-proxy.conf.d/10-setup.conf' missing
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.pki.Plugin._misc_pki
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.selinux.Plugin._misc
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine_common.apache.misc.Plugin._misc
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configured=bool:'True'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage misc METHOD otopi.plugins.ovirt_engine_common.base.core.postinstall.Plugin._misc
2014-10-20 14:42:25 INFO otopi.plugins.ovirt_engine_common.base.core.postinstall postinstall._misc:59 Generating post install configuration file '/etc/ovirt-engine-setup.conf.d/20-setup-ovirt-post.conf'
2014-10-20 14:42:25 DEBUG otopi.transaction transaction._prepare:77 preparing 'File transaction for '/etc/ovirt-engine-setup.conf.d/20-setup-ovirt-post.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.prepare:194 file '/etc/ovirt-engine-setup.conf.d/20-setup-ovirt-post.conf' missing
2014-10-20 14:42:25 INFO otopi.context context.runSequence:417 Stage: Transaction commit
2014-10-20 14:42:25 DEBUG otopi.context context.runSequence:421 STAGE cleanup
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage cleanup METHOD otopi.plugins.otopi.core.transaction.Plugin._main_end
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine-setup.conf.d/20-setup-ovirt-post.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine-setup.conf.d/20-setup-ovirt-post.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/ovirt-websocket-proxy.conf.d/10-setup.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/ovirt-websocket-proxy.conf.d/10-setup.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/httpd/conf.d/ssl.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/httpd/conf.d/ssl.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/root/.ssh/authorized_keys''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /root/.ssh/authorized_keys
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/pki/ovirt-engine/keys/engine_id_rsa''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/pki/ovirt-engine/keys/engine_id_rsa
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/engine.conf.d/10-setup-pki.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/engine.conf.d/10-setup-pki.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'CA Transaction'
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'Engine schema Transaction'
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/logcollector.conf.d/10-engine-setup.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/logcollector.conf.d
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/imageuploader.conf.d/10-engine-setup.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/imageuploader.conf.d/10-engine-setup.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/isouploader.conf.d/10-engine-setup.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/isouploader.conf.d/10-engine-setup.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/engine.conf.d/10-setup-protocols.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/engine.conf.d/10-setup-protocols.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/notifier/notifier.conf.d/10-setup-jboss.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/notifier/notifier.conf.d/10-setup-jboss.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/engine.conf.d/10-setup-jboss.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/engine.conf.d/10-setup-jboss.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/engine.conf.d/10-setup-database.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/engine.conf.d/10-setup-database.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/httpd/conf.d/ovirt-engine-root-redirect.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/httpd/conf.d/ovirt-engine-root-redirect.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/httpd/conf.d/z-ovirt-engine-proxy.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/httpd/conf.d/z-ovirt-engine-proxy.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/var/lib/images/.keep''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /var/lib/images
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine-setup.conf.d/20-setup-aio.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine-setup.conf.d/20-setup-aio.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/iptables.example''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/iptables.example
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-postgres.xml''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/firewalld/ovirt-postgres.xml
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-fence-kdump-listener.xml''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/firewalld/ovirt-fence-kdump-listener.xml
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-websocket-proxy.xml''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/firewalld/ovirt-websocket-proxy.xml
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-https.xml''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/firewalld/ovirt-https.xml
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-http.xml''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/firewalld/ovirt-http.xml
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/ovirt-engine/firewalld/ovirt-aio.xml''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/ovirt-engine/firewalld
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/sysconfig/iptables''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/sysconfig/iptables
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'File transaction for '/etc/sysctl.d/ovirt-postgresql.conf''
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:327 Executing restorecon for /etc/sysctl.d/ovirt-postgresql.conf
2014-10-20 14:42:25 DEBUG otopi.filetransaction filetransaction.commit:341 restorecon result rc=0, stdout=, stderr=
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'Version Lock Transaction'
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages plugin.executeRaw:785 execute: ('/bin/rpm', '-q', 'ovirt-engine', 'ovirt-engine-backend', 'ovirt-engine-dbscripts', 'ovirt-engine-restapi', 'ovirt-engine-tools', 'ovirt-engine-userportal', 'ovirt-engine-webadmin-portal'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages plugin.executeRaw:803 execute-result: ('/bin/rpm', '-q', 'ovirt-engine', 'ovirt-engine-backend', 'ovirt-engine-dbscripts', 'ovirt-engine-restapi', 'ovirt-engine-tools', 'ovirt-engine-userportal', 'ovirt-engine-webadmin-portal'), rc=0
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages plugin.execute:861 execute-output: ('/bin/rpm', '-q', 'ovirt-engine', 'ovirt-engine-backend', 'ovirt-engine-dbscripts', 'ovirt-engine-restapi', 'ovirt-engine-tools', 'ovirt-engine-userportal', 'ovirt-engine-webadmin-portal') stdout:
ovirt-engine-3.5.0.1-1.el6.noarch
ovirt-engine-backend-3.5.0.1-1.el6.noarch
ovirt-engine-dbscripts-3.5.0.1-1.el6.noarch
ovirt-engine-restapi-3.5.0.1-1.el6.noarch
ovirt-engine-tools-3.5.0.1-1.el6.noarch
ovirt-engine-userportal-3.5.0.1-1.el6.noarch
ovirt-engine-webadmin-portal-3.5.0.1-1.el6.noarch

2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine_common.distro-rpm.packages plugin.execute:866 execute-output: ('/bin/rpm', '-q', 'ovirt-engine', 'ovirt-engine-backend', 'ovirt-engine-dbscripts', 'ovirt-engine-restapi', 'ovirt-engine-tools', 'ovirt-engine-userportal', 'ovirt-engine-webadmin-portal') stderr:


2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'Database Transaction'
2014-10-20 14:42:25 DEBUG otopi.transaction transaction.commit:159 committing 'Yum Transaction'
Loaded plugins: fastestmirror, versionlock
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/modifiedFiles=list:'['/var/lib/pgsql/data/pg_hba.conf', '/var/lib/pgsql/data/postgresql.conf', '/etc/ovirt-engine-setup.conf.d/20-setup-ovirt-post.conf', '/etc/ovirt-engine/ovirt-websocket-proxy.conf.d/10-setup.conf', '/root/.ssh/authorized_keys', '/etc/pki/ovirt-engine/keys/engine_id_rsa', '/etc/ovirt-engine/logcollector.conf.d/10-engine-setup.conf', '/etc/ovirt-engine/imageuploader.conf.d/10-engine-setup.conf', '/etc/ovirt-engine/isouploader.conf.d/10-engine-setup.conf', '/etc/ovirt-engine/engine.conf.d/10-setup-protocols.conf', '/etc/ovirt-engine/notifier/notifier.conf.d/10-setup-jboss.conf', '/etc/ovirt-engine/engine.conf.d/10-setup-jboss.conf', '/etc/ovirt-engine/engine.conf.d/10-setup-database.conf', '/etc/httpd/conf.d/ovirt-engine-root-redirect.conf', '/etc/httpd/conf.d/z-ovirt-engine-proxy.conf', '/var/lib/images/.keep', '/etc/ovirt-engine-setup.conf.d/20-setup-aio.conf', '/etc/ovirt-engine/iptables.example', '/etc/ovirt-engine/firewalld/ovirt-postgres.xml', '/etc/ovirt-engine/firewalld/ovirt-fence-kdump-listener.xml', '/etc/ovirt-engine/firewalld/ovirt-websocket-proxy.xml', '/etc/ovirt-engine/firewalld/ovirt-https.xml', '/etc/ovirt-engine/firewalld/ovirt-http.xml', '/etc/ovirt-engine/firewalld/ovirt-aio.xml', '/etc/sysconfig/iptables', '/etc/sysctl.d/ovirt-postgresql.conf']'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/uninstallUnremovableFiles=list:'['/etc/exports', '/etc/sysconfig/iptables', '/etc/sysctl.d/ovirt-postgresql.conf', '/var/lib/pgsql/data/postgresql.conf', '/var/lib/pgsql/data/pg_hba.conf', '/root/.ssh/authorized_keys', '/etc/httpd/conf.d/ssl.conf', '/etc/yum/pluginconf.d/versionlock.list']'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_FILE_GROUP/ca_config=list:'[['/etc/ovirt-engine/engine.conf.d/10-setup-pki.conf']]'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_FILE_GROUP/versionlock=list:'[]'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_LINES_GROUP/versionlock=dict:'{'/etc/yum/pluginconf.d/versionlock.list': [{'added': u'ovirt-engine-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-backend-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-dbscripts-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-restapi-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-tools-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-userportal-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-webadmin-portal-3.5.0.1-1.el6.noarch'}]}'
2014-10-20 14:42:25 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:42:25 INFO otopi.context context.runSequence:417 Stage: Closing up
2014-10-20 14:42:25 DEBUG otopi.context context.runSequence:421 STAGE closeup
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.otopi.network.firewalld.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.otopi.network.iptables.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:121 check if service firewalld exists
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'firewalld'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'firewalld'), rc=1
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'firewalld') stdout:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'firewalld') stderr:
initctl: Unknown job: firewalld

2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel rhel.exists:133 service firewalld exists False upstart=False
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel rhel.startup:151 set service iptables startup to True
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'iptables'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'iptables'), rc=1
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'iptables') stdout:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'iptables') stderr:
initctl: Unknown job: iptables

2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/chkconfig', 'iptables', 'on'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/chkconfig', 'iptables', 'on'), rc=0
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/chkconfig', 'iptables', 'on') stdout:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/chkconfig', 'iptables', 'on') stderr:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 stopping service iptables
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'iptables'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'iptables'), rc=1
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'iptables') stdout:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'iptables') stderr:
initctl: Unknown job: iptables

2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'iptables', 'stop'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'iptables', 'stop'), rc=0
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'iptables', 'stop') stdout:
iptables: Setting chains to policy ACCEPT: nat mangle filter [  OK  ]
iptables: Flushing firewall rules: [  OK  ]
iptables: Unloading modules: [  OK  ]

2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'iptables', 'stop') stderr:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 starting service iptables
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'iptables'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'iptables'), rc=1
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'iptables') stdout:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'iptables') stderr:
initctl: Unknown job: iptables

2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'iptables', 'start'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'iptables', 'start'), rc=0
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'iptables', 'start') stdout:
iptables: Applying firewall rules: [  OK  ]

2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'iptables', 'start') stderr:


2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_common.base.dialog.titles.Plugin._title_s_summary
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== SUMMARY ==--
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.memcheck.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.exportfs.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.provisioning.postgres.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=engine', '--passin=**FILTERED**', '--cert=-'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=engine', '--passin=**FILTERED**', '--cert=-'), rc=0
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh plugin.execute:861 execute-output: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=engine', '--passin=**FILTERED**', '--cert=-') stdout:
Bag Attributes
    localKeyID: 2C 37 0E C9 43 AD 08 84 6C B8 FE D7 00 09 82 B2 9B BD F7 73 
subject=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de
issuer=/C=US/O=gecko.hs-heilbronn.de/CN=ex1.gecko.hs-heilbronn.de.17578
-----BEGIN CERTIFICATE-----
MIIEnjCCA4agAwIBAgICEAEwDQYJKoZIhvcNAQEFBQAwVzELMAkGA1UEBhMCVVMx
HjAcBgNVBAoTFWdlY2tvLmhzLWhlaWxicm9ubi5kZTEoMCYGA1UEAxMfZXgxLmdl
Y2tvLmhzLWhlaWxicm9ubi5kZS4xNzU3ODAiFxExNDEwMTkxMjQyMjQrMDAwMBcN
MTkwOTI0MTI0MjI0WjBRMQswCQYDVQQGEwJVUzEeMBwGA1UEChMVZ2Vja28uaHMt
aGVpbGJyb25uLmRlMSIwIAYDVQQDExlleDEuZ2Vja28uaHMtaGVpbGJyb25uLmRl
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzXVaMylzWyMUB6iHNxl
qJ4VPz0iO3GeQj0FM2RXFwf8cGXh9MmDMPGPLjFyytRU/niZ85V2PiqtKNjZPR0k
n9tHHjU7SwBvP3YzEOOglmlYm7+tf7V/tB5IEpuwhAe7ROLMv9CAqLJ8PZmJ/lES
VOZPh+BDCchy07tsguZpqHyp83cNLTDZaJE/A3dN3dDAJtA2NnYdLRaZ2sRd/lC5
WJTMfwCPz1QFFukPubDa3Y+83QcCWHDLnsEkrcoLjaRHiogd0UQdIAIpRdvuxCcJ
iFHt4dAYFw6b1NTNskWvsctYDk9GTKQDSfymVKbhnwZ/zqdeIInako/SF3ooVueV
2wIDAQABo4IBdDCCAXAwHQYDVR0OBBYEFNuD6r9is5jhdFmDAOaVb4k1zwyOMIGO
BggrBgEFBQcBAQSBgTB/MH0GCCsGAQUFBzAChnFodHRwOi8vZXgxLmdlY2tvLmhz
LWhlaWxicm9ubi5kZTo4MC9vdmlydC1lbmdpbmUvc2VydmljZXMvcGtpLXJlc291
cmNlP3Jlc291cmNlPWNhLWNlcnRpZmljYXRlJmZvcm1hdD1YNTA5LVBFTS1DQTCB
gAYDVR0jBHkwd4AUcRxaoG4Dqkqtw78MfWDiIcmKj42hW6RZMFcxCzAJBgNVBAYT
AlVTMR4wHAYDVQQKExVnZWNrby5ocy1oZWlsYnJvbm4uZGUxKDAmBgNVBAMTH2V4
MS5nZWNrby5ocy1oZWlsYnJvbm4uZGUuMTc1NziCAhAAMAkGA1UdEwQCMAAwDgYD
VR0PAQH/BAQDAgWgMCAGA1UdJQEB/wQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAN
BgkqhkiG9w0BAQUFAAOCAQEAlrCVIEaLswqfDSH61+OrQSFtrGpesKlxE/EOLbGW
pQUGV7yGQClyenGTWVrtoIv6O/5KEs4Aqt/tEJoccpGzt+G4C0CRld6nUyXJH6O2
HGSZxvmvfSQt9R2JjkZfvhIogLlxHFmruwqpEbdRePa9c8Hr1zPtVaqejTA+eaxI
PEz4gdYpYc3jNgYMSAnBBG2BUFi+FCKUYLYiuvgB5vXFtOW4OCjDJD4oWoKqnqsf
5tfutpmQvXcL+Ge0ljy6cULL5oc9arf6JPV3A8XAP2SqG0zzQdih8KDTTjP15mp5
qTGYFwFQGkqul65eISEO2mtlEQIE7tkI8ttXfw2KmBuAGw==
-----END CERTIFICATE-----

2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ssh plugin.execute:866 execute-output: ('/usr/share/ovirt-engine/bin/pki-pkcs12-extract.sh', '--name=engine', '--passin=**FILTERED**', '--cert=-') stderr:
MAC verified OK

2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 SSH fingerprint: 09:9D:F2:9E:F7:6C:82:23:BB:1E:5D:0E:75:B0:90:79
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.pki.ca.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Internal CA 24:65:92:74:FA:57:C9:BB:4D:0C:7C:83:B5:7E:B1:B7:F5:DC:EC:FC
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.protocols.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Web access is enabled at:
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                     http://ex1.gecko.hs-heilbronn.de:80/ovirt-engine
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                     https://ex1.gecko.hs-heilbronn.de:443/ovirt-engine
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.config.options.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Please use the user "admin" and password specified in order to login
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.base.network.firewall_manager.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_common.base.dialog.titles.Plugin._title_e_summary
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 --== END OF SUMMARY ==--
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_common.base.system.hostile_services.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel rhel.startup:151 set service sshd startup to True
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'sshd'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'sshd'), rc=1
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'sshd') stdout:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'sshd') stderr:
initctl: Unknown job: sshd

2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/chkconfig', 'sshd', 'on'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/chkconfig', 'sshd', 'on'), rc=0
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/chkconfig', 'sshd', 'on') stdout:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/chkconfig', 'sshd', 'on') stderr:


2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd plugin.executeRaw:785 execute: ('/sbin/restorecon', '-r', '/root/.ssh'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd plugin.executeRaw:803 execute-result: ('/sbin/restorecon', '-r', '/root/.ssh'), rc=0
2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd plugin.execute:861 execute-output: ('/sbin/restorecon', '-r', '/root/.ssh') stdout:


2014-10-20 14:42:25 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.sshd plugin.execute:866 execute-output: ('/sbin/restorecon', '-r', '/root/.ssh') stderr:


2014-10-20 14:42:25 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.fence_kdump_listener.config.Plugin._closeup
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 stopping service ovirt-fence-kdump-listener
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener'), rc=1
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener') stdout:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener') stderr:
initctl: Unknown job: ovirt-fence-kdump-listener

2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'ovirt-fence-kdump-listener', 'stop'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'ovirt-fence-kdump-listener', 'stop'), rc=0
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'ovirt-fence-kdump-listener', 'stop') stdout:
Stopping oVirt fence_kdump listener: [FAILED]

2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'ovirt-fence-kdump-listener', 'stop') stderr:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 starting service ovirt-fence-kdump-listener
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener'), executable='None', cwd='None', env=None
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener'), rc=1
2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener') stdout:


2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener') stderr:
initctl: Unknown job: ovirt-fence-kdump-listener

2014-10-20 14:42:25 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'ovirt-fence-kdump-listener', 'start'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'ovirt-fence-kdump-listener', 'start'), rc=0
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'ovirt-fence-kdump-listener', 'start') stdout:
Starting oVirt fence_kdump listener: [  OK  ]

2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'ovirt-fence-kdump-listener', 'start') stderr:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel rhel.startup:151 set service ovirt-fence-kdump-listener startup to True
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener'), rc=1
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener') stdout:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-fence-kdump-listener') stderr:
initctl: Unknown job: ovirt-fence-kdump-listener

2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/chkconfig', 'ovirt-fence-kdump-listener', 'on'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/chkconfig', 'ovirt-fence-kdump-listener', 'on'), rc=0
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/chkconfig', 'ovirt-fence-kdump-listener', 'on') stdout:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/chkconfig', 'ovirt-fence-kdump-listener', 'on') stderr:


2014-10-20 14:42:26 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.legacy.osinfo.Plugin._closeup
2014-10-20 14:42:26 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.engine.Plugin._closeup
2014-10-20 14:42:26 INFO otopi.plugins.ovirt_engine_setup.ovirt_engine.system.engine engine._closeup:54 Starting engine service
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 starting service ovirt-engine
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-engine'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-engine'), rc=1
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stdout:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stderr:
initctl: Unknown job: ovirt-engine

2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'ovirt-engine', 'start'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'ovirt-engine', 'start'), rc=0
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'ovirt-engine', 'start') stdout:
Starting oVirt Engine: [  OK  ]

2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'ovirt-engine', 'start') stderr:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel rhel.startup:151 set service ovirt-engine startup to True
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-engine'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-engine'), rc=1
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stdout:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-engine') stderr:
initctl: Unknown job: ovirt-engine

2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/chkconfig', 'ovirt-engine', 'on'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/chkconfig', 'ovirt-engine', 'on'), rc=0
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/chkconfig', 'ovirt-engine', 'on') stdout:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/chkconfig', 'ovirt-engine', 'on') stderr:


2014-10-20 14:42:26 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_common.ovirt_engine_common.system.apache.Plugin._closeup
2014-10-20 14:42:26 INFO otopi.plugins.ovirt_engine_common.ovirt_engine_common.system.apache apache._closeup:80 Restarting httpd
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel rhel.startup:151 set service httpd startup to True
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'httpd'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'httpd'), rc=1
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'httpd') stdout:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'httpd') stderr:
initctl: Unknown job: httpd

2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/chkconfig', 'httpd', 'on'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/chkconfig', 'httpd', 'on'), rc=0
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/chkconfig', 'httpd', 'on') stdout:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/chkconfig', 'httpd', 'on') stderr:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 stopping service httpd
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'httpd'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'httpd'), rc=1
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'httpd') stdout:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'httpd') stderr:
initctl: Unknown job: httpd

2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'httpd', 'stop'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'httpd', 'stop'), rc=0
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'httpd', 'stop') stdout:
Stopping httpd: [FAILED]

2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'httpd', 'stop') stderr:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 starting service httpd
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'httpd'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'httpd'), rc=1
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'httpd') stdout:


2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'httpd') stderr:
initctl: Unknown job: httpd

2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'httpd', 'start'), executable='None', cwd='None', env=None
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'httpd', 'start'), rc=0
2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'httpd', 'start') stdout:
Starting httpd: [  OK  ]

2014-10-20 14:42:26 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'httpd', 'start') stderr:


2014-10-20 14:42:26 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.system.nfs.Plugin._closeup
2014-10-20 14:42:26 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:26 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm.Plugin._closeup
2014-10-20 14:42:26 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._closeup:194 Connecting to the Engine
2014-10-20 14:42:26 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._waitEngineUp:102 Waiting Engine API response
2014-10-20 14:42:26 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._waitEngineUp:133 Cannot connect to engine
Traceback (most recent call last):
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-setup/ovirt-engine/all-in-one/vdsm.py", line 127, in _waitEngineUp
    insecure=True,
  File "/usr/lib/python2.6/site-packages/ovirtsdk/api.py", line 154, in __init__
    url=''
  File "/usr/lib/python2.6/site-packages/ovirtsdk/infrastructure/proxy.py", line 118, in request
    persistent_auth=self._persistent_auth)
  File "/usr/lib/python2.6/site-packages/ovirtsdk/infrastructure/proxy.py", line 146, in __doRequest
    persistent_auth=persistent_auth
  File "/usr/lib/python2.6/site-packages/ovirtsdk/web/connection.py", line 134, in doRequest
    raise RequestError, response
RequestError: 
status: 503
reason: Service Temporarily Unavailable
detail: 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>503 Service Temporarily Unavailable</title>
</head><body>
<h1>Service Temporarily Unavailable</h1>
<p>The server is temporarily unable to service your
request due to maintenance downtime or capacity
problems. Please try again later.</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at localhost Port 443</address>
</body></html>

2014-10-20 14:42:33 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:164 Database: 'None', Statement: '
                select version, option_value
                from vdc_options
                where option_name = %(name)s
            ', args: {'name': 'SupportedClusterLevels'}
2014-10-20 14:42:33 DEBUG otopi.ovirt_engine_setup.engine_common.database database.execute:214 Result: [{'version': 'general', 'option_value': '3.0,3.1,3.2,3.3,3.4,3.5'}]
2014-10-20 14:42:33 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._closeup:209 SupportedClusterLevels [3.0,3.1,3.2,3.3,3.4,3.5], PACKAGE_VERSION [3.5.0.1],
2014-10-20 14:42:33 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._closeup:221 Creating the local data center
2014-10-20 14:42:33 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._closeup:231 Creating the local cluster into the local data center
2014-10-20 14:42:34 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._closeup:246 Adding the local host to the local cluster
2014-10-20 14:42:35 INFO otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._waitVDSMHostUp:57 Waiting for VDSM host to become operational. This may take several minutes...
2014-10-20 14:42:35 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._waitVDSMHostUp:86 VDSM host in installing state
2014-10-20 14:42:36 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._waitVDSMHostUp:86 VDSM host in installing state
2014-10-20 14:42:38 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._waitVDSMHostUp:86 VDSM host in installing state
2014-10-20 14:42:39 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._waitVDSMHostUp:86 VDSM host in installing state
2014-10-20 14:42:40 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._waitVDSMHostUp:86 VDSM host in installing state
2014-10-20 14:42:41 DEBUG otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._waitVDSMHostUp:86 VDSM host in installing state
2014-10-20 14:42:42 ERROR otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._waitVDSMHostUp:76 The VDSM host was found in a failed state. Please check engine and bootstrap installation logs.
2014-10-20 14:42:42 WARNING otopi.plugins.ovirt_engine_setup.ovirt_engine.all-in-one.vdsm vdsm._closeup:268 Local storage domain not added because the VDSM host was not up. Please add it manually.
2014-10-20 14:42:42 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.config.Plugin._closeup
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 stopping service ovirt-websocket-proxy
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), executable='None', cwd='None', env=None
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), rc=1
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stdout:


2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stderr:
initctl: Unknown job: ovirt-websocket-proxy

2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'ovirt-websocket-proxy', 'stop'), executable='None', cwd='None', env=None
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'ovirt-websocket-proxy', 'stop'), rc=0
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'ovirt-websocket-proxy', 'stop') stdout:
Stopping oVirt Engine websockets proxy: [FAILED]

2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'ovirt-websocket-proxy', 'stop') stderr:


2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel rhel.state:172 starting service ovirt-websocket-proxy
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), executable='None', cwd='None', env=None
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), rc=1
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stdout:


2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stderr:
initctl: Unknown job: ovirt-websocket-proxy

2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/service', 'ovirt-websocket-proxy', 'start'), executable='None', cwd='None', env=None
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/service', 'ovirt-websocket-proxy', 'start'), rc=0
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/service', 'ovirt-websocket-proxy', 'start') stdout:
Starting oVirt Engine websockets proxy: [  OK  ]

2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/service', 'ovirt-websocket-proxy', 'start') stderr:


2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel rhel.startup:151 set service ovirt-websocket-proxy startup to True
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), executable='None', cwd='None', env=None
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy'), rc=1
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stdout:


2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/initctl', 'status', 'ovirt-websocket-proxy') stderr:
initctl: Unknown job: ovirt-websocket-proxy

2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:785 execute: ('/sbin/chkconfig', 'ovirt-websocket-proxy', 'on'), executable='None', cwd='None', env=None
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.executeRaw:803 execute-result: ('/sbin/chkconfig', 'ovirt-websocket-proxy', 'on'), rc=0
2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:861 execute-output: ('/sbin/chkconfig', 'ovirt-websocket-proxy', 'on') stdout:


2014-10-20 14:42:42 DEBUG otopi.plugins.otopi.services.rhel plugin.execute:866 execute-output: ('/sbin/chkconfig', 'ovirt-websocket-proxy', 'on') stderr:


2014-10-20 14:42:42 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.otopi.system.reboot.Plugin._closeup
2014-10-20 14:42:42 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:42 DEBUG otopi.context context._executeMethod:138 Stage closeup METHOD otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event.Plugin._log_setup_event_closeup
2014-10-20 14:42:42 DEBUG otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event plugin.executeRaw:785 execute: ('/usr/share/ovirt-engine/bin/ovirt-engine-log-setup-event.sh', '--notes=End of setup'), executable='None', cwd='None', env=None
2014-10-20 14:42:43 DEBUG otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event plugin.executeRaw:803 execute-result: ('/usr/share/ovirt-engine/bin/ovirt-engine-log-setup-event.sh', '--notes=End of setup'), rc=0
2014-10-20 14:42:43 DEBUG otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event plugin.execute:861 execute-output: ('/usr/share/ovirt-engine/bin/ovirt-engine-log-setup-event.sh', '--notes=End of setup') stdout:


2014-10-20 14:42:43 DEBUG otopi.plugins.ovirt_engine_common.base.distro-rpm.log_setup_event plugin.execute:866 execute-output: ('/usr/share/ovirt-engine/bin/ovirt-engine-log-setup-event.sh', '--notes=End of setup') stderr:


2014-10-20 14:42:43 INFO otopi.context context.runSequence:417 Stage: Clean up
2014-10-20 14:42:43 DEBUG otopi.context context.runSequence:421 STAGE cleanup
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:138 Stage cleanup METHOD otopi.plugins.ovirt_engine_common.base.core.misc.Plugin._cleanup
2014-10-20 14:42:43 DEBUG otopi.plugins.otopi.dialog.human dialog.__logString:215 DIALOG:SEND                 Log file is located at /var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:138 Stage cleanup METHOD otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine.Plugin._cleanup
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:138 Stage cleanup METHOD otopi.plugins.ovirt_engine_setup.websocket_proxy.pki.Plugin._cleanup
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:138 Stage cleanup METHOD otopi.plugins.ovirt_engine_common.base.core.uninstall.Plugin._cleanup
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:138 Stage cleanup METHOD otopi.plugins.ovirt_engine_common.base.core.answerfile.Plugin._cleanup
2014-10-20 14:42:43 INFO otopi.plugins.ovirt_engine_common.base.core.answerfile answerfile._cleanup:75 Generating answer file '/var/lib/ovirt-engine/setup/answers/20141020144243-setup.conf'
2014-10-20 14:42:43 INFO otopi.context context.runSequence:417 Stage: Pre-termination
2014-10-20 14:42:43 DEBUG otopi.context context.runSequence:421 STAGE pre-terminate
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:138 Stage pre-terminate METHOD otopi.plugins.otopi.core.misc.Plugin._preTerminate
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:490 ENVIRONMENT DUMP - BEGIN
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/aborted=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/debug=int:'0'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/error=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/exceptionInfo=list:'[]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/executionDirectory=str:'/root'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/log=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/pluginGroups=str:'otopi:ovirt-engine-common:ovirt-engine-setup'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/pluginPath=str:'/usr/share/otopi/plugins:/usr/share/ovirt-engine/setup/bin/../plugins'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV BASE/suppressEnvironmentKeys=list:'[]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/chkconfig=str:'/sbin/chkconfig'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/chronyc=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/date=str:'/bin/date'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/dig=str:'/usr/bin/dig'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/exportfs=str:'/usr/sbin/exportfs'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/firewall-cmd=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/hwclock=str:'/sbin/hwclock'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/initctl=str:'/sbin/initctl'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/ip=str:'/sbin/ip'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/ntpq=str:'/usr/sbin/ntpq'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/pg_dump=str:'/usr/bin/pg_dump'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/pg_restore=str:'/usr/bin/pg_restore'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/postgresql-setup=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/psql=str:'/usr/bin/psql'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/rc=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/rc-update=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/reboot=str:'/sbin/reboot'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/restorecon=str:'/sbin/restorecon'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/rpm=str:'/bin/rpm'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/selinuxenabled=str:'/usr/sbin/selinuxenabled'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/semanage=str:'/usr/sbin/semanage'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/service=str:'/sbin/service'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/ssh-keygen=str:'/usr/bin/ssh-keygen'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/sshd=str:'/usr/sbin/sshd'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/sysctl=str:'/sbin/sysctl'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV COMMAND/systemctl=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/configFileAppend=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/configFileName=str:'/etc/ovirt-engine-setup.conf'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/failOnPrioOverride=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/internalPackageTransaction=Transaction:'transaction'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logDir=str:'/var/log/ovirt-engine/setup'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFileHandle=file:'<open file '/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log', mode 'a' at 0x213c5d0>'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFileName=str:'/var/log/ovirt-engine/setup/ovirt-engine-setup-20141020143050-b6hof6.log'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFileNamePrefix=str:'ovirt-engine-setup'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilter=_MyLoggerFilter:'filter'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logFilterKeys=list:'['OVESETUP_DB/password', 'OVESETUP_CONFIG/adminPassword', 'OVESETUP_PKI/storePassword', 'OVESETUP_CONFIG/remoteEngineHostRootPassword']'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/logRemoveAtExit=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/mainTransaction=Transaction:'transaction'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/modifiedFiles=list:'['/var/lib/pgsql/data/pg_hba.conf', '/var/lib/pgsql/data/postgresql.conf', '/etc/ovirt-engine-setup.conf.d/20-setup-ovirt-post.conf', '/etc/ovirt-engine/ovirt-websocket-proxy.conf.d/10-setup.conf', '/root/.ssh/authorized_keys', '/etc/pki/ovirt-engine/keys/engine_id_rsa', '/etc/ovirt-engine/logcollector.conf.d/10-engine-setup.conf', '/etc/ovirt-engine/imageuploader.conf.d/10-engine-setup.conf', '/etc/ovirt-engine/isouploader.conf.d/10-engine-setup.conf', '/etc/ovirt-engine/engine.conf.d/10-setup-protocols.conf', '/etc/ovirt-engine/notifier/notifier.conf.d/10-setup-jboss.conf', '/etc/ovirt-engine/engine.conf.d/10-setup-jboss.conf', '/etc/ovirt-engine/engine.conf.d/10-setup-database.conf', '/etc/httpd/conf.d/ovirt-engine-root-redirect.conf', '/etc/httpd/conf.d/z-ovirt-engine-proxy.conf', '/var/lib/images/.keep', '/etc/ovirt-engine-setup.conf.d/20-setup-aio.conf', '/etc/ovirt-engine/iptables.example', '/etc/ovirt-engine/firewalld/ovirt-postgres.xml', '/etc/ovirt-engine/firewalld/ovirt-fence-kdump-listener.xml', '/etc/ovirt-engine/firewalld/ovirt-websocket-proxy.xml', '/etc/ovirt-engine/firewalld/ovirt-https.xml', '/etc/ovirt-engine/firewalld/ovirt-http.xml', '/etc/ovirt-engine/firewalld/ovirt-aio.xml', '/etc/sysconfig/iptables', '/etc/sysctl.d/ovirt-postgresql.conf']'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV CORE/randomizeEvents=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/boundary=str:'--=451b80dc-996f-432e-9e4f-2b29ef6d1141=--'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/cliVersion=int:'1'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/customization=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV DIALOG/dialect=str:'human'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV INFO/PACKAGE_NAME=str:'otopi'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV INFO/PACKAGE_VERSION=str:'1.3.0'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/firewalldAvailable=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/firewalldDisableServices=list:'[]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/firewalldEnable=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/iptablesEnable=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/iptablesRules=str:'# Generated by ovirt-engine installer
#filtering rules
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5900:6923 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 49152:49216 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m udp --dport 7410 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 6100 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

#drop all rule
-A INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/sshEnable=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/sshKey=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK/sshUser=str:''
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-aio=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
    <short>ovirt-aio</short>
    <description>oVirt configured aio service</description>
    <port protocol="tcp" port="5900-6923"/>
    <port protocol="tcp" port="49152-49216"/>
</service>
'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-fence-kdump-listener=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>ovirt-fence-kdump-listener</short>
  <description>oVirt configured fence_kdump listener service</description>
  <port protocol="udp" port="7410"/>
</service>
'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-http=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>ovirt-http</short>
  <description>oVirt configured http service</description>
  <port protocol="tcp" port="80"/>
</service>
'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-https=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>ovirt-https</short>
  <description>oVirt configured https service</description>
  <port protocol="tcp" port="443"/>
</service>
'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-postgres=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>ovirt-postgres</short>
  <description>oVirt configured postgres service</description>
  <port protocol="tcp" port="5432"/>
</service>
'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV NETWORK_FIREWALLD_SERVICE/ovirt-websocket-proxy=str:'<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>ovirt-websocket-proxy</short>
  <description>oVirt configured WebSocket Proxy service</description>
  <port protocol="tcp" port="6100"/>
</service>
'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/enableUpgrade=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/requireRollback=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/versionLockApply=list:'['ovirt-engine', 'ovirt-engine-backend', 'ovirt-engine-dbscripts', 'ovirt-engine-restapi', 'ovirt-engine-tools', 'ovirt-engine-userportal', 'ovirt-engine-webadmin-portal']'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OSETUP_RPMDISTRO/versionLockFilter=list:'['ovirt-engine']'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/configure=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/continueWithoutAIO=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/enable=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/localCluster=str:'local_cluster'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/localDataCenter=str:'local_datacenter'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/localHost=str:'local_host'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/sshdPort=int:'22'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/storageDomainDefaultDir=str:'/var/lib/images'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/storageDomainDir=str:'/var/lib/images'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/storageDomainName=str:'local_storage'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/supported=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_AIO/vdsmCpu=str:'Intel Haswell Family'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configFileOvirtEngine=str:'/etc/httpd/conf.d/z-ovirt-engine-proxy.conf'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configFileOvirtRoot=str:'/etc/httpd/conf.d/ovirt-engine-root-redirect.conf'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configFileSsl=str:'/etc/httpd/conf.d/ssl.conf'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configureRootRedirection=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configureRootRedirectionDefault=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configureSsl=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/configured=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/enable=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/httpdService=str:'httpd'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_APACHE/needRestart=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ASYNC/clearTasks=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ASYNC/clearTasksWait=int:'20'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/addOvirtGlanceRepository=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/adminPassword=str:'**FILTERED**'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/applicationMode=str:'virt'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/firewallManager=str:'iptables'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/firewallManagers=list:'[<otopi.plugins.ovirt_engine_common.base.network.firewall_manager_firewalld._FirewalldManager object at 0x26be810>, <otopi.plugins.ovirt_engine_common.base.network.firewall_manager_human._HumanManager object at 0x26be850>, <otopi.plugins.ovirt_engine_common.base.network.firewall_manager_iptables._IpTablesManager object at 0x26be790>]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/fqdn=str:'ex1.gecko.hs-heilbronn.de'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/fqdnNonLoopback=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/fqdnReverseValidation=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/httpPort=int:'80'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/httpsPort=int:'443'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainACL=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainDefaultMountPoint=str:'/var/lib/exports/iso'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainExists=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainMountPoint=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainName=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainSdUuid=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/isoDomainStorageDir=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/javaHome=unicode:'/usr/lib/jvm/jre'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossAjpPort=int:'8702'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossDebugAddress=str:'127.0.0.1:8787'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossDirectHttpPort=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossDirectHttpsPort=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossHome=str:'/usr/share/ovirt-engine-jboss-as'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossHttpPort=int:'8080'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossHttpsPort=int:'8443'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/jbossNeeded=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/keySize=int:'2048'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/macRangePool=str:'00:1a:4a:e2:37:00-00:1a:4a:e2:37:ff'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/publicHttpPort=int:'80'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/publicHttpsPort=int:'443'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineCer=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineHostClientKey=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineHostKnownHosts=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineHostRootPassword=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineHostSshPort=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineSetupStyle=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/remoteEngineSetupStyles=list:'[<otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine_root_ssh._RootSshManager object at 0x26be0d0>, <otopi.plugins.ovirt_engine_common.base.remote_engine.remote_engine_manual_files._ManualFiles object at 0x26be8d0>]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/storageIsLocal=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/storageType=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/updateFirewall=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/validFirewallManagers=str:''
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/websocketProxyConfig=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/websocketProxyHost=str:'localhost'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/websocketProxyPort=int:'6100'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CONFIG/wspCertificateChain=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/action=str:'setup'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/answerFile=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/developerMode=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/engineStop=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/generatePostInstall=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/generatedByVersion=str:'3.5.0.1'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/offlinePackager=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/originalGeneratedByVersion=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/registerUninstallGroups=RegisterGroups:'<otopi.plugins.ovirt_engine_common.base.core.uninstall.RegisterGroups object at 0x17e2390>'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/remoteEngine=RemoteEngine:'<ovirt_engine_setup.remote_engine.RemoteEngine object at 0x26be890>'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/setupAttributesModules=list:'[<module 'ovirt_engine_setup.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/constants.pyc'>, <module 'ovirt_engine_setup.engine.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine/constants.pyc'>, <module 'ovirt_engine_setup.engine_common.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/engine_common/constants.pyc'>, <module 'ovirt_engine_setup.websocket_proxy.constants' from '/usr/share/ovirt-engine/setup/ovirt_engine_setup/websocket_proxy/constants.pyc'>]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/uninstallUnremovableFiles=list:'['/etc/exports', '/etc/sysconfig/iptables', '/etc/sysctl.d/ovirt-postgresql.conf', '/var/lib/pgsql/data/postgresql.conf', '/var/lib/pgsql/data/pg_hba.conf', '/root/.ssh/authorized_keys', '/etc/httpd/conf.d/ssl.conf', '/etc/yum/pluginconf.d/versionlock.list']'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE/upgradeSupportedVersions=str:'3.0,3.1,3.2,3.3,3.4,3.5'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_FILE_GROUP/ca_config=list:'[['/etc/ovirt-engine/engine.conf.d/10-setup-pki.conf']]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_FILE_GROUP/ca_pki=list:'[['/etc/pki/ovirt-engine/cert.template', '/etc/pki/ovirt-engine/cacert.template', '/etc/pki/ovirt-engine/certs/apache.cer', '/etc/pki/ovirt-engine/keys/apache.p12', '/etc/pki/ovirt-engine/ca.pem', '/etc/pki/ovirt-engine/private/ca.pem', '/etc/pki/ovirt-engine/certs/engine.cer', '/etc/pki/ovirt-engine/keys/engine.p12', '/etc/pki/ovirt-engine/.truststore', '/etc/pki/ovirt-engine/keys/jboss.p12', '/etc/pki/ovirt-engine/certs/jboss.cer', '/etc/pki/ovirt-engine/cacert.conf', '/etc/pki/ovirt-engine/cert.conf', '/etc/pki/ovirt-engine/certs/websocket-proxy.cer', '/etc/pki/ovirt-engine/keys/websocket-proxy.p12', '/etc/pki/ovirt-engine/keys/websocket-proxy.key.nopass', '/etc/pki/ovirt-engine/keys/reports.key.nopass', '/etc/pki/ovirt-engine/keys/apache.key.nopass', '/etc/pki/ovirt-engine/apache-ca.pem']]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_FILE_GROUP/ssl=list:'[]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_FILE_GROUP/versionlock=list:'[]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_LINES_GROUP/ca_config=dict:'{}'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_LINES_GROUP/ca_pki=dict:'{}'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_LINES_GROUP/ssl=dict:'{'/etc/httpd/conf.d/ssl.conf': [{'removed': 'SSLCertificateFile /etc/pki/tls/certs/localhost.crt', 'added': '# SSLCertificateFile /etc/pki/tls/certs/localhost.crt'}, {'added': 'SSLCertificateFile /etc/pki/ovirt-engine/certs/apache.cer'}, {'removed': 'SSLCertificateKeyFile /etc/pki/tls/private/localhost.key', 'added': '# SSLCertificateKeyFile /etc/pki/tls/private/localhost.key'}, {'added': 'SSLCertificateKeyFile /etc/pki/ovirt-engine/keys/apache.key.nopass'}, {'added': 'SSLCACertificateFile /etc/pki/ovirt-engine/apache-ca.pem'}]}'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_CORE_MODIFIED_LINES_GROUP/versionlock=dict:'{'/etc/yum/pluginconf.d/versionlock.list': [{'added': u'ovirt-engine-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-backend-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-dbscripts-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-restapi-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-tools-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-userportal-3.5.0.1-1.el6.noarch'}, {'added': u'ovirt-engine-webadmin-portal-3.5.0.1-1.el6.noarch'}]}'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/connection=connection:'<connection object at 0x2dad210; dsn: 'dbname=engine host=localhost port=5432 user=engine password=xxxxxxxxxxxxxxxxxxxxxx sslmode=allow', closed: 0>'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/database=str:'engine'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/fixDbViolations=NoneType:'None'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/host=str:'localhost'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/newDatabase=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/password=str:'**FILTERED**'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/pgPassFile=str:'/tmp/tmplSY6K_'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/port=int:'5432'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/secured=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/securedHostValidation=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/statement=Statement:'<ovirt_engine_setup.engine_common.database.Statement object at 0x4078190>'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DB/user=str:'engine'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_DIALOG/confirmSettings=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ENGINE_CONFIG/fqdn=str:'ex1.gecko.hs-heilbronn.de'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_ENGINE_CORE/enable=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldServices=list:'[{'directory': 'aio', 'name': 'ovirt-aio'}, {'directory': 'ovirt-common', 'name': 'ovirt-http'}, {'directory': 'ovirt-common', 'name': 'ovirt-https'}, {'directory': 'websocket-proxy', 'name': 'ovirt-websocket-proxy'}, {'directory': 'ovirt-engine', 'name': 'ovirt-fence-kdump-listener'}, {'directory': 'ovirt-common', 'name': 'ovirt-postgres'}]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_NETWORK/firewalldSubst=dict:'{'@WEBSOCKET_PROXY_PORT@': 6100, '@HTTPS_PORT@': 443, '@JBOSS_HTTP_PORT@': None, '@HTTP_PORT@': 80, '@JBOSS_HTTPS_PORT@': None}'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PKI/country=str:'US'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PKI/organization=str:'gecko.hs-heilbronn.de'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PKI/sshPublicKey=str:'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7NdVozKXNbIxQHqIc3GWonhU/PSI7cZ5CPQUzZFcXB/xwZeH0yYMw8Y8uMXLK1FT+eJnzlXY+Kq0o2Nk9HSSf20ceNTtLAG8/djMQ46CWaVibv61/tX+0HkgSm7CEB7tE4sy/0ICosnw9mYn+URJU5k+H4EMJyHLTu2yC5mmofKnzdw0tMNlokT8Dd03d0MAm0DY2dh0tFpnaxF3+ULlYlMx/AI/PVAUW6Q+5sNrdj7zdBwJYcMuewSStyguNpEeKiB3RRB0gAilF2+7EJwmIUe3h0BgXDpvU1M2yRa+xy1gOT0ZMpANJ/KZUpuGfBn/Op14gidqSj9IXeihW55Xb'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PKI/storePassword=str:'**FILTERED**'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresConf=str:'/var/lib/pgsql/data/postgresql.conf'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresListenAddress=str:''*''
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresMaxConn=int:'150'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresPgHba=str:'/var/lib/pgsql/data/pg_hba.conf'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresPgVersion=str:'/var/lib/pgsql/data/PG_VERSION'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresProvisioningEnabled=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_PROVISIONING/postgresService=str:'postgresql'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/enginePackages=str:'ovirt-engine'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/engineSetupPackages=str:'ovirt-engine-setup'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/packagesSetup=list:'['ovirt-engine-setup']'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/packagesUpgradeList=list:'[{'packages': ['ovirt-engine'], 'group': 'ovirt-engine-3.4'}]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_RPMDISTRO/upgradeYumGroup=str:'ovirt-engine-3.4'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/groupEngine=str:'ovirt'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/groupKvm=str:'kvm'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/hostileServices=str:'ovirt-engine-dwhd,ovirt-engine-notifier'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckEnabled=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckMinimumMB=int:'4096'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckRecommendedMB=int:'16384'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/memCheckThreshold=int:'90'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/nfsConfigEnabled=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/nfsConfigEnabled_legacyInPostInstall=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/nfsServiceName=str:'nfs'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/selinuxContexts=list:'[{'pattern': '/var/lib/images(/.*)?', 'type': 'public_content_rw_t'}]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/selinuxRestorePaths=list:'['/var/lib/images']'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/shmmax=int:'68719476736'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userApache=str:'apache'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userEngine=str:'ovirt'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userPostgres=str:'postgres'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userRoot=str:'root'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV OVESETUP_SYSTEM/userVdsm=str:'vdsm'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/keepAliveInterval=int:'30'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumDisabledPlugins=list:'[]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumEnabledPlugins=list:'[]'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumExpireCache=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumRollback=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV PACKAGER/yumpackagerEnabled=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/clockMaxGap=int:'5'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/clockSet=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/commandPath=str:'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/reboot=bool:'False'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/rebootAllow=bool:'True'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:500 ENV SYSTEM/rebootDeferTime=int:'10'
2014-10-20 14:42:43 DEBUG otopi.context context.dumpEnvironment:504 ENVIRONMENT DUMP - END
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:138 Stage pre-terminate METHOD otopi.plugins.otopi.dialog.cli.Plugin._pre_terminate
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:43 INFO otopi.context context.runSequence:417 Stage: Termination
2014-10-20 14:42:43 DEBUG otopi.context context.runSequence:421 STAGE terminate
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:138 Stage terminate METHOD otopi.plugins.ovirt_engine_common.base.core.misc.Plugin._terminate
2014-10-20 14:42:43 INFO otopi.plugins.ovirt_engine_common.base.core.misc misc._terminate:159 Execution of setup completed successfully
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:138 Stage terminate METHOD otopi.plugins.otopi.dialog.human.Plugin._terminate
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:138 Stage terminate METHOD otopi.plugins.otopi.dialog.machine.Plugin._terminate
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:144 condition False
2014-10-20 14:42:43 DEBUG otopi.context context._executeMethod:138 Stage terminate METHOD otopi.plugins.otopi.core.log.Plugin._terminate
[root@ex1 ~]#