#
# Created as part of the StratusLab project (http://stratuslab.eu),
# co-funded by the European Commission under the Grant Agreement
# INFSO-RI-261552."
#
# Copyright (c) 2011, SixSq Sarl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os

import stratuslab.system.SystemFactory as SystemFactory
from stratuslab import Util, Defaults

class Registration(object):

    def __init__(self, configHolder):
        configHolder.assign(self)
        self.system = SystemFactory.getSystem(self.frontendSystem, configHolder)
        self.packages = ['apacheds']
        
    def run(self):
        self._installPackages()
        self._configure()
        self._restartService('one-proxy')
        
    def _installPackages(self):
        Util.printStep('Installing packages')
        self.system.installPackages(self.packages)

    def _configure(self):
        Util.printStep('Creating registration configuration file')
        
        registrationTpl = os.path.join(Util.getTemplateDir(), 'registration.cfg.tpl')
        registrationConfFile = os.path.join(Defaults.ETC_DIR, 'registration.cfg') 
        Util.filePutContent(registrationConfFile,
                            Util.fileGetContent(registrationTpl) % self.__dict__)

    def _restartService(self, service):
        Util.printStep("Restarting Jetty7 (one-proxy)")
        cmd = 'service %s restart' % service
        Util.execute(cmd.split(' '))

@@ -729,16 +729,205 @@
 ense.%0A#%0A
+from stratuslab import Util, Defaults%0Afrom stratuslab.Util import printStep, filePutContent, fileGetContent, %5C%0A    restartService%0Afrom stratuslab.installator.Installator import Installator%0A
 import o
@@ -928,17 +928,16 @@
 port os%0A
-%0A
 import s
@@ -988,45 +988,8 @@
 ory%0A
-from stratuslab import Util, Defaults
 %0A%0Acl
@@ -1009,14 +1009,19 @@
 ion(
-object
+Installator
 ):%0A%0A
@@ -1210,24 +1210,55 @@
 cheds'%5D%0A    
+%0A    # TODO: Remove if not used
     %0A    def
@@ -1314,26 +1314,21 @@
    self.
-_configure
+setup
 ()%0A     
@@ -1385,32 +1385,32 @@
 def _install
-Packages
+Frontend
 (self):%0A    
@@ -1405,37 +1405,32 @@
 (self):%0A        
-Util.
 printStep('Insta
@@ -1511,17 +1511,21 @@
 ef _
-configure
+setupFrontend
 (sel
@@ -1528,37 +1528,32 @@
 (self):%0A        
-Util.
 printStep('Creat
@@ -1590,25 +1590,16 @@
  file')%0A
-        %0A
         
@@ -1771,27 +1771,37 @@
     
-Util.filePutContent
+self._writeConfigFromTemplate
 (reg
@@ -1818,16 +1818,33 @@
 onfFile,
+ registrationTpl)
 %0A       
@@ -1836,36 +1836,124 @@
 ionTpl)%0A        
+%0A
     
+def _writeConfigFromTemplate(self, config, tpl):%0A        filePutContent(config,%0A       
                 
@@ -1952,21 +1952,16 @@
         
-Util.
 fileGetC
@@ -1967,29 +1967,17 @@
 Content(
-registrationT
+t
 pl) %25 se
@@ -1989,16 +1989,23 @@
 dict__)%0A
+       
 %0A    def
@@ -2006,18 +2006,16 @@
    def _
-re
 startSer
@@ -2022,159 +2022,58 @@
 vice
-(self, service):%0A        Util.printStep(%22Restarting Jetty7 (one-proxy)%22)%0A        cmd = 'service %25s restart' %25 service%0A        Util.execute(cmd.split(' '))
+sFrontend(self):%0A        restartService('one-proxy')%0A
 %0A

Refactor registration installer