Beispiel #1
0
    def install(self, env):
        import params
        import os
        print "Installing LCM Server:"
        super(LcmServer, self).install(env)
        packagefileonly = 'lcm-complete-' + params.lcm_releaseversion
        package = packagefileonly + '-bin.tar.gz'
        if len(self.sttmpdir) < 4:
            raise IOError("where are you using for temp??")
        Execute("mkdir -p " + self.sttmpdir)
        Execute("rm -rf " + self.sttmpdir + "/*")

        # Create service user, config/home dir and set permissions
        Execute('id -u ' + params.lcm_service_user +
                ' &>/dev/null || useradd -r -s /sbin/nologin ' +
                params.lcm_service_user)
        Execute('mkdir -p ' + params.lcm_install_dir)

        os.chdir(self.sttmpdir)
        #        copy_cache_or_repo shall be used when we have an official release of LCM
        #        kc.copy_cache_or_repo(package, arch='noarch', ver=params.releaseversion, dir="LCM")
        Execute(
            'wget ' +
            'https://github.com/KaveIO/LocalCatalogManager/releases/download/v0.2.5.1-beta/'
            + package)
        Execute('tar -xzf ' + package + ' -C ' + params.lcm_install_dir)
        Execute(params.lcm_home_dir + 'bin/setup-ssl.sh')
        kc.chown_r(params.lcm_install_dir, params.lcm_service_user)
Beispiel #2
0
    def install(self, env):
        import params
        import os
        print "Installing LCM Server:"
        super(LcmServer, self).install(env)
        packagefileonly = 'lcm-complete-' + params.lcm_releaseversion
        package = packagefileonly + '-bin.tar.gz'
        if len(self.sttmpdir) < 4:
            raise IOError("where are you using for temp??")
        Execute("mkdir -p " + self.sttmpdir)
        Execute("rm -rf " + self.sttmpdir + "/*")

        # Create service user, config/home dir and set permissions
        Execute('id -u ' + params.lcm_service_user +
                ' &>/dev/null || useradd -r -s /sbin/nologin ' + params.lcm_service_user)
        Execute('mkdir -p ' + params.lcm_install_dir)

        os.chdir(self.sttmpdir)
#        copy_cache_or_repo shall be used when we have an official release of LCM
#        kc.copy_cache_or_repo(package, arch='noarch', ver=params.releaseversion, dir="LCM")
        Execute('wget ' +
                'https://github.com/KaveIO/LocalCatalogManager/releases/download/v0.2.5.1-beta/' + package)
        Execute('tar -xzf ' + package + ' -C ' + params.lcm_install_dir)
        Execute(params.lcm_home_dir + 'bin/setup-ssl.sh')
        kc.chown_r(params.lcm_install_dir, params.lcm_service_user)
Beispiel #3
0
    def install(self, env):
        import params
        import kavecommon as kc

        super(Twiki, self).install(env)
        env.set_params(params)
        kc.copy_cache_or_repo('TWiki-6.0.0.zip', arch='noarch')
        Execute("mkdir -p " + params.install_dir)
        Execute("unzip -o -q TWiki-6.0.0.zip -d " + params.install_dir)
        Execute("mkdir -p " + params.install_dir + 'authtest')
        kc.chown_r(params.install_dir, "apache")
        Execute("cp " + params.install_dir + "/bin/LocalLib.cfg.txt " + params.install_dir + "/bin/LocalLib.cfg")
        Execute("chown apache:apache " + params.install_dir + "/bin/LocalLib.cfg")
        self.configure(env)
Beispiel #4
0
    def configure(self, env):
        # stop service if running
        # recreate from templates
        # restart
        # read previous jenkins home and jenkins user ...
        orig_juser = "******"
        orig_jhome = "/var/lib/jenkins"
        if os.path.exists(self.config_file_path):
            f = open(self.config_file_path)
            ls = f.readlines()
            f.close()
            for l in ls:
                if l.startswith("JENKINS_USER"):
                    orig_juser_parse = l.split("=")[-1].strip().replace(
                        '"', '')
                    if len(orig_juser_parse):
                        orig_juser = orig_juser_parse
                elif l.startswith("JENKINS_HOME"):
                    orig_jhome_parse = l.split("=")[-1].strip().replace(
                        '"', '')
                    if len(orig_jhome_parse):
                        orig_jhome = orig_jhome_parse

        import params
        env.set_params(params)
        # If jenkins user has changed, create the new user
        if params.JENKINS_USER != orig_juser:
            Execute('useradd ' + params.JENKINS_USER)
        # If jenkins home has changed, create the new directory
        if params.JENKINS_HOME != orig_jhome and not os.path.exists(
                params.JENKINS_HOME):
            Execute('mkdir -p ' + params.JENKINS_HOME)
        # If jenkins home has changed, mv contents of jenkins home directory
        if params.JENKINS_HOME != orig_jhome and os.path.exists(orig_jhome):
            import glob

            if len(glob.glob(orig_jhome + '/*')):
                Execute('mv ' + orig_jhome + '/* ' + params.JENKINS_HOME + "/")
        if not os.path.exists(params.JENKINS_HOME + '/plugins'):
            Execute('mkdir -p ' + params.JENKINS_HOME + '/plugins')

        File(self.config_file_path, content=Template("jenkins.j2"), mode=0600)
        kc.chmod_up(self.config_file_path, "a+rx")
        kc.chmod_up(params.JENKINS_HOME, "a+rx")
        kc.chown_r(self.config_file_path, params.JENKINS_USER)
        kc.chown_r(params.JENKINS_HOME, params.JENKINS_USER)
        if 'noexec' in subprocess.check_output(
                'if mountpoint -q /tmp; then mount | grep "/tmp "; fi',
                shell=True):
            Execute("mount -o remount,exec /tmp")
Beispiel #5
0
    def configure(self, env):
        # stop service if running
        # recreate from templates
        # restart
        # read previous jenkins home and jenkins user ...
        orig_juser = "******"
        orig_jhome = "/var/lib/jenkins"
        if os.path.exists(self.config_file_path):
            f = open(self.config_file_path)
            ls = f.readlines()
            f.close()
            for l in ls:
                if l.startswith("JENKINS_USER"):
                    orig_juser_parse = l.split("=")[-1].strip().replace('"', '')
                    if len(orig_juser_parse):
                        orig_juser = orig_juser_parse
                elif l.startswith("JENKINS_HOME"):
                    orig_jhome_parse = l.split("=")[-1].strip().replace('"', '')
                    if len(orig_jhome_parse):
                        orig_jhome = orig_jhome_parse

        import params
        env.set_params(params)
        # If jenkins user has changed, create the new user
        if params.JENKINS_USER != orig_juser:
            Execute('useradd ' + params.JENKINS_USER)
        # If jenkins home has changed, create the new directory
        if params.JENKINS_HOME != orig_jhome and not os.path.exists(params.JENKINS_HOME):
            Execute('mkdir -p ' + params.JENKINS_HOME)
        # If jenkins home has changed, mv contents of jenkins home directory
        if params.JENKINS_HOME != orig_jhome and os.path.exists(orig_jhome):
            import glob

            if len(glob.glob(orig_jhome + '/*')):
                Execute('mv ' + orig_jhome + '/* ' + params.JENKINS_HOME + "/")
        if not os.path.exists(params.JENKINS_HOME + '/plugins'):
            Execute('mkdir -p ' + params.JENKINS_HOME + '/plugins')

        File(self.config_file_path,
             content=Template("jenkins.j2"),
             mode=0600
             )
        kc.chmod_up(self.config_file_path, "a+rx")
        kc.chmod_up(params.JENKINS_HOME, "a+rx")
        kc.chown_r(self.config_file_path, params.JENKINS_USER)
        kc.chown_r(params.JENKINS_HOME, params.JENKINS_USER)
        if 'noexec' in subprocess.check_output('if mountpoint -q /tmp; then mount | grep "/tmp "; fi', shell=True):
            Execute("mount -o remount,exec /tmp")
Beispiel #6
0
 def install(self, env):
     import params
     import kavecommon as kc
     kc.extra_redhat_repos()
     super(Twiki, self).install(env)
     env.set_params(params)
     kc.copy_cache_or_repo('TWiki-6.0.0.zip', arch='noarch')
     Execute("mkdir -p " + params.install_dir)
     Execute("unzip -o -q TWiki-6.0.0.zip -d " + params.install_dir)
     Execute("mkdir -p " + params.install_dir + 'authtest')
     kc.chown_r(params.install_dir, "apache")
     Execute("cp " + params.install_dir + "/bin/LocalLib.cfg.txt " +
             params.install_dir + "/bin/LocalLib.cfg")
     Execute("chown apache:apache " + params.install_dir +
             "/bin/LocalLib.cfg")
     self.configure(env)
Beispiel #7
0
 def configure_sd(self, env):
     import params
     params.PROG = self.PROG
     env.set_params(params)
     if not os.path.exists('/etc/supervisord.conf'):
         File('/etc/supervisord.conf',
              content=Template("supervisord.conf.j2"),
              mode=0755)
     Execute('mkdir -p /etc/supervisord.d/')
     File("/etc/supervisord.d/" + self.PROG + ".conf",
          content=Template("prog.conf"),
          mode=0644)
     File("/etc/init.d/supervisord",
          content=Template("supervisor.j2"),
          mode=0755)
     kc.chown_r('/etc/supervisord.d/', 'storm')
Beispiel #8
0
    def install(self, env):
        import params

        env.set_params(params)
        self.install_packages(env)
        dlname = 'jenkins-' + str(params.download_version) + '-1.1.noarch.rpm'
        kc.copy_cache_or_repo(dlname, arch='noarch', alternates='http://pkg.jenkins-ci.org/redhat/' + dlname)
        Execute('rpm -qa | grep -qw jenkins || yum -y install ' + dlname)

        self.configure(env)
        # wget all requested plugins
        for plugin in params.plugins.split(','):
            plugin = plugin.strip()
            if not len(plugin):
                continue
            extsources = ["http://updates.jenkins-ci.org/latest/" + plugin + h for h in [".hpi", ".jpi"]]
            mirrorsources = []
            for mirror in kc.mirrors():
                mirrorsources = mirrorsources + \
                    [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch', repo=mirror) for h in [".hpi", ".jpi"]]
            intsources = [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch') for h in [".hpi", ".jpi"]]
            source = kc.failover_source(mirrorsources + intsources + extsources)
            dest = params.JENKINS_HOME + "/plugins/" + source.split('/')[-1]
            Execute(kc.copymethods(source, dest))

        File(params.JENKINS_HOME + '/config.xml',
             content=Template("config.xml.j2"),
             mode=0644
             )
        kc.chown_r(params.JENKINS_HOME + '/config.xml', params.JENKINS_USER)
        Execute('chkconfig jenkins on')
        self.start(env)
        # using curl to create username password for jenkinsl
        curl_command = ('curl -d "username='******'&password1=' + params.JENKINS_ADMIN_PASSWORD
                        + '&email=' + params.JENKINS_ADMIN_EMAIL + '&password2='
                        + params.JENKINS_ADMIN_PASSWORD + '&fullname='
                        + params.JENKINS_ADMIN + '&Submit=Sign%20up" "http://'
                        + params.hostname + ':' + str(params.JENKINS_PORT) + '/securityRealm/createAccount"')
        try:
            Execute(curl_command)
        except Fail as ex:
            print "the curl command met with failure the first time,,,trying in another 60 secs"
            print ex
            import time
            time.sleep(60)
            Execute(curl_command)
Beispiel #9
0
    def install(self, env):
        import params

        env.set_params(params)
        self.install_packages(env)
        dlname = 'jenkins-' + str(params.download_version) + '-1.1.noarch.rpm'
        kc.copy_cache_or_repo(dlname, arch='noarch', alternates='http://pkg.jenkins-ci.org/redhat/' + dlname)
        Execute('rpm -qa | grep -qw jenkins || yum -y install ' + dlname)

        self.configure(env)
        # wget all requested plugins
        for plugin in params.plugins.split(','):
            plugin = plugin.strip()
            if not len(plugin):
                continue
            extsources = ["http://updates.jenkins-ci.org/latest/" + plugin + h for h in [".hpi", ".jpi"]]
            mirrorsources = []
            for mirror in kc.mirrors():
                mirrorsources = mirrorsources + \
                    [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch', repo=mirror) for h in [".hpi", ".jpi"]]
            intsources = [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch') for h in [".hpi", ".jpi"]]
            source = kc.failover_source(mirrorsources + intsources + extsources)
            dest = params.JENKINS_HOME + "/plugins/" + source.split('/')[-1]
            Execute(kc.copymethods(source, dest))

        File(params.JENKINS_HOME + '/config.xml',
             content=Template("config.xml.j2"),
             mode=0644
             )
        kc.chown_r(params.JENKINS_HOME + '/config.xml', params.JENKINS_USER)
        Execute('chkconfig jenkins on')
        self.start(env)
        # using curl to create username password for jenkinsl
        curlCommand = ('curl -d "username='******'&password1=' + params.JENKINS_ADMIN_PASSWORD
                       + '&email=' + params.JENKINS_ADMIN_EMAIL + '&password2='
                       + params.JENKINS_ADMIN_PASSWORD + '&fullname='
                       + params.JENKINS_ADMIN + '&Submit=Sign%20up" "http://'
                       + params.hostname + ':' + str(params.JENKINS_PORT) + '/securityRealm/createAccount"')
        try:
            Execute(curlCommand)
        except Fail as ex:
            print "the curl command met with failure the first time,,,trying in another 60 secs"
            print ex
            import time
            time.sleep(60)
            Execute(curlCommand)
Beispiel #10
0
    def configure(self, env):
        import params
        import kavecommon as kc

        env.set_params(params)
        Execute('chkconfig hue on')
        edit_dirs = self.mandatory_conf_dirs
        for mdir in self.mandatory_conf_dirs:
            Execute("mkdir -p " + mdir)
        for odir in self.optional_conf_dirs:
            if os.path.exists(odir):
                edit_dirs.append(odir)
        for edir in edit_dirs:
            edir = os.path.realpath(edir)
            Execute('chmod -R 755 ' + edir)
            File(edir + '/hue.ini', content=InlineTemplate(params.hue_ini), mode=0644)
            File(edir + '/hue_httpd.conf', content=InlineTemplate(params.hue_httpd_conf), mode=0644)
            kc.chown_r(edir, params.server_user)
        Execute("sed -i 's/USER=\w*/USER=%s/' /etc/init.d/hue " % params.server_user)
 def configure_sd(self, env):
     import params
     params.PROG = self.PROG
     env.set_params(params)
     if not os.path.exists('/etc/supervisord.conf'):
         File('/etc/supervisord.conf',
              content=Template("supervisord.conf.j2"),
              mode=0755
              )
     Execute('mkdir -p /etc/supervisord.d/')
     File("/etc/supervisord.d/" + self.PROG + ".conf",
          content=Template("prog.conf"),
          mode=0644
          )
     File("/etc/init.d/supervisord",
          content=Template("supervisor.j2"),
          mode=0755
          )
     kc.chown_r('/etc/supervisord.d/', 'storm')
Beispiel #12
0
 def write_html(self, env):
     import params
     import kavecommon as kc
     env.set_params(params)
     if os.path.exists(params.www_folder + '/index.html'):
         os.remove(params.www_folder + '/index.html')
     File(params.www_folder + '/index.html',
          content=Template("kavelanding.html.j2"),
          mode=0644)
     File(params.www_folder + '/bootstrap.min.css',
          content=Template("bootstrap.min.css"),
          mode=0644)
     File(params.www_folder + '/LICENSE',
          content=Template("LICENSE"),
          mode=0644)
     File(params.www_folder + '/LICENSE-DOCUMENTATION-IMAGE-SUBCLAUSE',
          content=Template("LICENSE-DOCUMENTATION-IMAGE-SUBCLAUSE"),
          mode=0644)
     File(params.www_folder + '/NOTICE',
          content=Template("NOTICE"),
          mode=0644)
     # HINT: Use this in future: http://jinja.pocoo.org/docs/dev/templates/
     import kavescan as ls
     ls.ambari_user = params.AMBARI_ADMIN
     ls.ambari_password = params.AMBARI_ADMIN_PASS
     cluster_service_host, cluster_host_service, cluster_service_link = ls.collect_config_data(
         params.AMBARI_SHORT_HOST,
         user=params.AMBARI_ADMIN,
         passwd=params.AMBARI_ADMIN_PASS)
     bodyhtml = ls.pretty_print(cluster_service_host,
                                cluster_host_service,
                                cluster_service_link,
                                format="html")
     import json
     clinks = json.loads(params.customlinks)
     if len(clinks.keys()):
         custom_html = "<b>Custom Links</b><p><ul>"
         klist = clinks.keys()
         klist.sort()
         for lname in klist:
             custom_html = custom_html + '\n    <li><a href="' + clinks[
                 lname] + '">' + lname + '</a></li>'
         custom_html = custom_html + "</ul><p>\n"
         bodyhtml.replace('<b>Servers</b>', custom_html + '<b>Servers</b>')
     # HINT: this can be replaced by the correct template language in future
     HUE_LINK_IF_KNOWN = ""
     all_links = []
     for cluster in cluster_service_link:
         if "HUE_SERVER" in cluster_service_link[cluster]:
             HUE_LINK_IF_KNOWN = "<li>" + cluster_service_link[cluster][
                 "HUE_SERVER"][0] + "</li>"
     for cluster in cluster_service_link:
         for service in cluster_service_link[cluster]:
             if len(cluster_service_link[cluster][service]) > 2:
                 continue
             all_links = all_links + [
                 "<li>" + l + "</li>"
                 for l in cluster_service_link[cluster][service]
             ]
     f = open(params.www_folder + '/index.html')
     content = f.read()
     f.close()
     f = open(params.www_folder + '/index.html', 'w')
     if len(cluster_service_link.keys()) == 1:
         content = content.replace(
             "<title>KAVE:",
             "<title>" + cluster_service_link.keys()[0] + "-KAVE:")
     f.write(
         content.replace("THEPAGE!!", bodyhtml).replace(
             "HUE_LINK_IF_KNOWN",
             HUE_LINK_IF_KNOWN).replace("ALL_OTHER_LINKS",
                                        "\n".join(all_links)))
     f.close()
     kc.chown_r(params.www_folder, "apache")
Beispiel #13
0
 def write_html(self, env):
     import params
     import kavecommon as kc
     env.set_params(params)
     if os.path.exists(params.www_folder + '/index.html'):
         os.remove(params.www_folder + '/index.html')
     File(params.www_folder + '/index.html',
          content=Template("kavelanding.html.j2"),
          mode=0644
          )
     File(params.www_folder + '/bootstrap.min.css',
          content=Template("bootstrap.min.css"),
          mode=0644
          )
     File(params.www_folder + '/LICENSE',
          content=Template("LICENSE"),
          mode=0644
          )
     File(params.www_folder + '/LICENSE-DOCUMENTATION-IMAGE-SUBCLAUSE',
          content=Template("LICENSE-DOCUMENTATION-IMAGE-SUBCLAUSE"),
          mode=0644
          )
     File(params.www_folder + '/NOTICE',
          content=Template("NOTICE"),
          mode=0644
          )
     # HINT: Use this in future: http://jinja.pocoo.org/docs/dev/templates/
     import kavescan as ls
     ls.ambari_user = params.AMBARI_ADMIN
     ls.ambari_password = params.AMBARI_ADMIN_PASS
     cluster_service_host, cluster_host_service, cluster_service_link = ls.collect_config_data(
         params.AMBARI_SHORT_HOST, user=params.AMBARI_ADMIN, passwd=params.AMBARI_ADMIN_PASS)
     bodyhtml = ls.pretty_print(cluster_service_host, cluster_host_service, cluster_service_link, format="html")
     import json
     clinks = json.loads(params.customlinks)
     if len(clinks.keys()):
         custom_html = "<b>Custom Links</b><p><ul>"
         klist = clinks.keys()
         klist.sort()
         for lname in klist:
             custom_html = custom_html + '\n    <li><a href="' + clinks[lname] + '">' + lname + '</a></li>'
         custom_html = custom_html + "</ul><p>\n"
         bodyhtml.replace('<b>Servers</b>', custom_html + '<b>Servers</b>')
     # HINT: this can be replaced by the correct template language in future
     HUE_LINK_IF_KNOWN = ""
     all_links = []
     for cluster in cluster_service_link:
         if "HUE_SERVER" in cluster_service_link[cluster]:
             HUE_LINK_IF_KNOWN = "<li>" + cluster_service_link[cluster]["HUE_SERVER"][0] + "</li>"
     for cluster in cluster_service_link:
         for service in cluster_service_link[cluster]:
             if len(cluster_service_link[cluster][service]) > 2:
                 continue
             all_links = all_links + ["<li>" + l + "</li>" for l in cluster_service_link[cluster][service]]
     f = open(params.www_folder + '/index.html')
     content = f.read()
     f.close()
     f = open(params.www_folder + '/index.html', 'w')
     if len(cluster_service_link.keys()) == 1:
         content = content.replace("<title>KAVE:", "<title>" + cluster_service_link.keys()[0] + "-KAVE:")
     f.write(content.replace("THEPAGE!!",
                             bodyhtml).replace("HUE_LINK_IF_KNOWN",
                                               HUE_LINK_IF_KNOWN).replace("ALL_OTHER_LINKS", "\n".join(all_links)))
     f.close()
     kc.chown_r(params.www_folder, "apache")
Beispiel #14
0
 def install(self, env):
     import params
     env.set_params(params)
     self.install_mongo(env)
     Execute("mkdir -p " + params.db_path)
     kc.chown_r(params.db_path, 'mongod')
Beispiel #15
0
    def install(self, env):
        import params

        env.set_params(params)
        self.install_packages(env)
        dlname = 'jenkins-' + str(params.download_version) + '-1.1.noarch.rpm'
        kc.copy_cache_or_repo(dlname,
                              arch='noarch',
                              alternates='http://pkg.jenkins-ci.org/redhat/' +
                              dlname)
        Execute('rpm -qa | grep -qw jenkins || yum -y install ' + dlname)

        self.configure(env)
        # wget all requested plugins
        for plugin in params.plugins.split(','):
            plugin = plugin.strip()
            if not len(plugin):
                continue
            extsources = [
                "http://updates.jenkins-ci.org/latest/" + plugin + h
                for h in [".hpi", ".jpi"]
            ]
            mirrorsources = []
            for mirror in kc.mirrors():
                mirrorsources = mirrorsources + \
                    [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch', repo=mirror) for h in [".hpi", ".jpi"]]
            intsources = [
                kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch')
                for h in [".hpi", ".jpi"]
            ]
            source = kc.failover_source(mirrorsources + intsources +
                                        extsources)
            dest = params.JENKINS_HOME + "/plugins/" + source.split('/')[-1]
            Execute(kc.copymethods(source, dest))

        Execute('mkdir -p /var/lib/jenkins/.ssl')
        cpath = "/var/lib/jenkins/.ssl"
        print str(cpath)
        #         #Change to your company details
        country = "NA"
        state = "NA"
        locality = "NA"
        organization = "NA"
        organizationalun = "NA"
        if len(params.hostname) <= 64:
            commonname = params.hostname
        else:
            commonname = params.hostname.split(".", 1)[0]
        email = "*****@*****.**"
        #         Optional
        password = "******"
        print "Generating key request"
        #         #Generate a key
        Execute(
            str.format(
                'openssl req -x509 -newkey rsa:4096' +
                ' -passout pass:{} -keyout /var/lib/jenkins/.ssl/key.pem -out'
                + ' /var/lib/jenkins/.ssl/cert.pem' +
                ' -days 365 -subj "/C={}/ST={}/L={}/O={}/OU={}/CN={}/emailAddress={} '
                + '"', password, country, state, locality, organization,
                organizationalun, commonname, email))
        #         #Import the key to pckc12
        Execute(
            str.format(
                'openssl pkcs12 -inkey /var/lib/jenkins/.ssl/key.pem' +
                ' -in /var/lib/jenkins/.ssl/cert.pem -export -out /var/lib/jenkins/.ssl/cert.p12'
                + ' -passin pass:{} -passout pass:{}', password, password))
        #         #Import keystore
        Execute(
            str.format(
                'keytool -importkeystore -srckeystore /var/lib/jenkins/.ssl/cert.p12'
                +
                ' -destkeystore /var/lib/jenkins/.ssl/jenkins.jks -srcstoretype pkcs12'
                + ' -deststoretype JKS -srcstorepass {} -deststorepass {}',
                password, password))

        File(params.JENKINS_HOME + '/config.xml',
             content=Template("config.xml.j2"),
             mode=0644)
        kc.chown_r(params.JENKINS_HOME + '/config.xml', params.JENKINS_USER)
        Execute('chkconfig jenkins on')

        self.start(env)
        # using curl to create username password for jenkinsl
        curl_command = ('curl -k -d "username='******'&password1=' + params.JENKINS_ADMIN_PASSWORD +
                        '&email=' + params.JENKINS_ADMIN_EMAIL +
                        '&password2=' + params.JENKINS_ADMIN_PASSWORD +
                        '&fullname=' + params.JENKINS_ADMIN +
                        '&Submit=Sign%20up" "https://' + params.hostname +
                        ':' + str(params.JENKINS_HTTPS_PORT) +
                        '/securityRealm/createAccount"')
        try:
            Execute(curl_command)
        except Fail as ex:
            print "the curl command met with failure the first time,,,trying in another 60 secs"
            print ex
            import time
            time.sleep(60)
            Execute(curl_command)
Beispiel #16
0
    def install(self, env):
        import params

        env.set_params(params)
        self.install_packages(env)
        dlname = 'jenkins-' + str(params.download_version) + '-1.1.noarch.rpm'
        kc.copy_cache_or_repo(dlname, arch='noarch', alternates='http://pkg.jenkins-ci.org/redhat/' + dlname)
        Execute('rpm -qa | grep -qw jenkins || yum -y install ' + dlname)

        self.configure(env)
        # wget all requested plugins
        for plugin in params.plugins.split(','):
            plugin = plugin.strip()
            if not len(plugin):
                continue
            extsources = ["http://updates.jenkins-ci.org/latest/" + plugin + h for h in [".hpi", ".jpi"]]
            mirrorsources = []
            for mirror in kc.mirrors():
                mirrorsources = mirrorsources + \
                    [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch', repo=mirror) for h in [".hpi", ".jpi"]]
            intsources = [kc.repo_url('jenkins_plugins/' + plugin + h, arch='noarch') for h in [".hpi", ".jpi"]]
            source = kc.failover_source(mirrorsources + intsources + extsources)
            dest = params.JENKINS_HOME + "/plugins/" + source.split('/')[-1]
            Execute(kc.copymethods(source, dest))

        Execute('mkdir -p /var/lib/jenkins/.ssl')
        cpath = "/var/lib/jenkins/.ssl"
        print str(cpath)
#         #Change to your company details
        country = "NA"
        state = "NA"
        locality = "NA"
        organization = "NA"
        organizationalun = "NA"
        if len(params.hostname) <= 64:
            commonname = params.hostname
        else:
            commonname = params.hostname.split(".", 1)[0]
        email = "*****@*****.**"
#         Optional
        password = "******"
        print "Generating key request"
#         #Generate a key
        Execute(str.format('openssl req -x509 -newkey rsa:4096' +
                           ' -passout pass:{} -keyout /var/lib/jenkins/.ssl/key.pem -out' +
                           ' /var/lib/jenkins/.ssl/cert.pem' +
                           ' -days 365 -subj "/C={}/ST={}/L={}/O={}/OU={}/CN={}/emailAddress={} ' +
                           '"', password, country, state, locality, organization, organizationalun, commonname, email))
#         #Import the key to pckc12
        Execute(str.format('openssl pkcs12 -inkey /var/lib/jenkins/.ssl/key.pem' +
                           ' -in /var/lib/jenkins/.ssl/cert.pem -export -out /var/lib/jenkins/.ssl/cert.p12' +
                           ' -passin pass:{} -passout pass:{}', password, password))
#         #Import keystore
        Execute(str.format('keytool -importkeystore -srckeystore /var/lib/jenkins/.ssl/cert.p12' +
                           ' -destkeystore /var/lib/jenkins/.ssl/jenkins.jks -srcstoretype pkcs12' +
                           ' -deststoretype JKS -srcstorepass {} -deststorepass {}', password, password))

        File(params.JENKINS_HOME + '/config.xml',
             content=Template("config.xml.j2"),
             mode=0644
             )
        kc.chown_r(params.JENKINS_HOME + '/config.xml', params.JENKINS_USER)
        Execute('chkconfig jenkins on')

        self.start(env)
        # using curl to create username password for jenkinsl
        curl_command = ('curl -k -d "username='******'&password1=' + params.JENKINS_ADMIN_PASSWORD
                        + '&email=' + params.JENKINS_ADMIN_EMAIL + '&password2='
                        + params.JENKINS_ADMIN_PASSWORD + '&fullname='
                        + params.JENKINS_ADMIN + '&Submit=Sign%20up" "https://'
                        + params.hostname + ':' + str(params.JENKINS_HTTPS_PORT) + '/securityRealm/createAccount"')
        try:
            Execute(curl_command)
        except Fail as ex:
            print "the curl command met with failure the first time,,,trying in another 60 secs"
            print ex
            import time
            time.sleep(60)
            Execute(curl_command)