Exemple #1
0
def getinstallhostlist(conf):
    list = []
    exclude_list = map(str.strip, conf['EXCLUDE_SERVERS'].split(','))
    for host in gethostlist(conf):
        if host not in exclude_list:
            list.append(host)
    return list
Exemple #2
0
def getinstallhostlist(conf):
    list = []
    exclude_list = map(str.strip, conf['EXCLUDE_SERVERS'].split(','))
    for host in gethostlist(conf):
        if host not in exclude_list:
            list.append(host)
    return list
def applyPuppetManifest():
    print
    currently_running = []
    lastmarker = None
    for manifest, marker in manifestfiles.getFiles():
        # if the marker has changed then we don't want to proceed until
        # all of the previous puppet runs have finished
        if lastmarker != None and lastmarker != marker:
            waitforpuppet(currently_running)
        lastmarker = marker

        for hostname in gethostlist(controller.CONF):
            if "/%s_" % hostname not in manifest:
                continue

            print "Applying " + manifest
            server = utils.ScriptRunner(hostname)

            running_logfile = "%s.running" % manifest
            finished_logfile = "%s.finished" % manifest
            currently_running.append((hostname, finished_logfile))
            command = "( flock %s/ps.lock puppet apply --modulepath %s/modules %s > %s 2>&1 < /dev/null ; mv %s %s ) > /dev/null 2>&1 < /dev/null &" % (basedefs.VAR_DIR, basedefs.VAR_DIR, manifest, running_logfile, running_logfile, finished_logfile)
            if not manifest.endswith('_horizon.pp'):
                server.append("export FACTERLIB=$FACTERLIB:%s/facts" % basedefs.VAR_DIR)
            server.append(command)
            server.execute()

    # wait for outstanding puppet runs befor exiting
    waitforpuppet(currently_running)
Exemple #4
0
def remove_remote_var_dirs(options, config, messages):
    """
    Removes the temp directories on remote hosts,
    doesn't remove data on localhost
    """
    for host in gethostlist(config):
        try:
            host_dir = config['HOST_DETAILS'][host]['tmpdir']
        except KeyError:
            # Nothing was added to this host yet, so we have nothing to delete
            continue
        if options.debug:
            # we keep temporary directories on hosts in debug mode
            messages.append(
                'Note temporary directory {host_dir} on host {host} was '
                'not deleted for debugging purposes.'.format(**locals()))
            continue
        logging.debug(output_messages.INFO_REMOVE_REMOTE_VAR %
                      (host_dir, host))
        server = utils.ScriptRunner(host)
        server.append('rm -rf %s' % host_dir)
        try:
            server.execute()
        except Exception as e:
            msg = output_messages.ERR_REMOVE_REMOTE_VAR % (host_dir, host)
            logging.error(msg)
            logging.exception(e)
            messages.append(utils.color_text(msg, 'red'))
Exemple #5
0
def applyPuppetManifest():
    print
    currently_running = []
    lastmarker = None
    for manifest, marker in manifestfiles.getFiles():
        # if the marker has changed then we don't want to proceed until
        # all of the previous puppet runs have finished
        if lastmarker != None and lastmarker != marker:
            waitforpuppet(currently_running)
        lastmarker = marker
        
        for hostname in gethostlist(controller.CONF):
            if "/%s_"%hostname not in manifest: continue

            print "Applying "+ manifest
            server = utils.ScriptRunner(hostname)

            logfile = "%s.log"%manifest
            currently_running.append((hostname, logfile))
            command = "( flock %s/ps.lock puppet apply --modulepath %s/modules %s > %s_ 2>&1 < /dev/null ; mv %s_ %s ) > /dev/null 2>&1 < /dev/null &"%(basedefs.VAR_DIR, basedefs.VAR_DIR, manifest, logfile, logfile, logfile)
            server.append(command)
            server.execute()

    # wait for outstanding puppet runs befor exiting
    waitforpuppet(currently_running)
Exemple #6
0
def installdeps(config):
    for hostname in gethostlist(controller.CONF):
        server = utils.ScriptRunner(hostname)
        for package in ("puppet", "openssh-clients", "tar"):
            server.append("rpm -q %s || yum install -y %s" %
                          (package, package))
        server.execute()
Exemple #7
0
def dontMixloopback():
    hosts =  gethostlist(controller.CONF)

    loopback = [h for h in hosts if h in ['127.0.0.1','localhost']]
    if loopback:
        if len(loopback) != len(hosts):
            msg = "You must use 127.0.0.1 or localhost for All in One installs Only"
            print msg
            raise PackStackException(msg)
 def test_gethostlist(self):
     conf = {
         "A_HOST": "1.1.1.1",
         "B_HOSTS": "2.2.2.2,1.1.1.1",
         "C_HOSTS": "3.3.3.3/vdc"
     }
     hosts = gethostlist(conf)
     hosts.sort()
     self.assertEqual(['1.1.1.1', '2.2.2.2', '3.3.3.3'], hosts)
Exemple #9
0
def copyPuppetModules():
    server = utils.ScriptRunner()
    tar_opts = ""
    if platform.linux_distribution()[0] == "Fedora":
        tar_opts += "--exclude create_resources "
    for hostname in gethostlist(controller.CONF):
        server.append("cd %s/puppet"%basedefs.DIR_PROJECT_DIR)
        server.append("tar %s --dereference -czf - modules | ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@%s tar -C %s -xzf -"%(tar_opts, hostname, basedefs.VAR_DIR))
        server.append("cd %s"%basedefs.PUPPET_MANIFEST_DIR)
        server.append("tar %s --dereference -czf - ../manifests | ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@%s tar -C %s -xzf -"%(tar_opts, hostname, basedefs.VAR_DIR))
    server.execute()
Exemple #10
0
def createnrpemanifests():
    for hostname in gethostlist(controller.CONF):
        controller.CONF['CONFIG_NRPE_HOST'] = hostname
        manifestfile = "%s_nagios_nrpe.pp" % hostname
        manifestdata = getManifestTemplate("nagios_nrpe.pp")
        appendManifestFile(manifestfile, manifestdata)

    controller.MESSAGES.append("To use Nagios, browse to http://%s/nagios "
                               "username : nagiosadmin, password : %s" %
                               (controller.CONF['CONFIG_NAGIOS_HOST'],
                                controller.CONF['CONFIG_NAGIOS_PW']))
def copyPuppetModules():
    server = utils.ScriptRunner()
    tar_opts = ""
    if platform.linux_distribution()[0] == "Fedora":
        tar_opts += "--exclude create_resources "
    for hostname in gethostlist(controller.CONF):
        server.append("cd %s/puppet" % basedefs.DIR_PROJECT_DIR)
        server.append("tar %s --dereference -czf - modules facts | ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@%s tar -C %s -xzf -" % (tar_opts, hostname, basedefs.VAR_DIR))
        server.append("cd %s" % basedefs.PUPPET_MANIFEST_DIR)
        server.append("tar %s --dereference -czf - ../manifests | ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@%s tar -C %s -xzf -" % (tar_opts, hostname, basedefs.VAR_DIR))
    server.execute()
Exemple #12
0
def createnrpemanifests():
    for hostname in gethostlist(controller.CONF):
        controller.CONF['CONFIG_NRPE_HOST'] = hostname
        manifestfile = "%s_nagios_nrpe.pp" % hostname
        manifestdata = getManifestTemplate("nagios_nrpe.pp")
        appendManifestFile(manifestfile, manifestdata)

    controller.MESSAGES.append("To use Nagios, browse to http://%s/nagios "
                               "username : nagiosadmin, password : %s" %
                               (controller.CONF['CONFIG_NAGIOS_HOST'],
                                controller.CONF['CONFIG_NAGIOS_PW']))
Exemple #13
0
def installKeys(config):
    with open(controller.CONF["CONFIG_SSH_KEY"]) as fp:
        sshkeydata = fp.read().strip()
    for hostname in gethostlist(controller.CONF):
        if '/' in hostname:
            hostname = hostname.split('/')[0]
        server = utils.ScriptRunner(hostname)
        # TODO replace all that with ssh-copy-id
        server.append("mkdir -p ~/.ssh")
        server.append("chmod 500 ~/.ssh")
        server.append("grep '%s' ~/.ssh/authorized_keys > /dev/null 2>&1 || echo %s >> ~/.ssh/authorized_keys" % (sshkeydata, sshkeydata))
        server.append("chmod 400 ~/.ssh/authorized_keys")
        server.append("restorecon -r ~/.ssh")
        server.execute()
Exemple #14
0
def installKeys():
    
    with open(controller.CONF["CONFIG_SSH_KEY"]) as fp:
        sshkeydata = fp.read().strip()

    for hostname in gethostlist(controller.CONF):
        if '/' in hostname:
            hostname = hostname.split('/')[0]
        server = utils.ScriptRunner(hostname)

        server.append("mkdir -p ~/.ssh")
        server.append("grep '%s' ~/.ssh/authorized_keys > /dev/null 2>&1 || echo %s > ~/.ssh/authorized_keys"%(sshkeydata, sshkeydata))
        server.append("restorecon -r ~/.ssh")
        server.execute()
Exemple #15
0
def create_ntp_manifest(config):
    srvlist = [i.strip()
               for i in config['CONFIG_NTP_SERVERS'].split(',')
               if i.strip()]
    config['CONFIG_NTP_SERVERS'] = ' '.join(srvlist)

    definiton = '\n'.join(['server %s' % i for i in srvlist])
    config['CONFIG_NTP_SERVER_DEF'] = '%s\n' % definiton

    marker = uuid.uuid4().hex[:16]
    for hostname in gethostlist(config):
        manifestdata = getManifestTemplate('ntpd.pp')
        appendManifestFile('%s_ntpd.pp' % hostname,
                           manifestdata,
                           marker=marker)
Exemple #16
0
def create_ntp_manifest():
    servers = ''
    for srv in controller.CONF['CONFIG_NTP_SERVERS'].split(','):
        srv = srv.strip()
        validators.validate_ping(srv)
        servers += 'server %s\n' % srv
        controller.CONF.setdefault('CONFIG_NTP_FIRST_SERVER', srv)
    controller.CONF['CONFIG_NTP_SERVERS'] = servers

    marker = uuid.uuid4().hex[:16]
    for hostname in gethostlist(controller.CONF):
        manifestdata = getManifestTemplate('ntpd.pp')
        appendManifestFile('%s_ntpd.pp' % hostname,
                           manifestdata,
                           marker=marker)
def create_ntp_manifest(config):
    srvlist = [i.strip()
               for i in config['CONFIG_NTP_SERVERS'].split(',')
               if i.strip()]
    config['CONFIG_NTP_SERVERS'] = ' '.join(srvlist)

    definiton = '\n'.join(['server %s' % i for i in srvlist])
    config['CONFIG_NTP_SERVER_DEF'] = '%s\n' % definiton

    marker = uuid.uuid4().hex[:16]
    for hostname in gethostlist(config):
        manifestdata = getManifestTemplate('ntpd.pp')
        appendManifestFile('%s_ntpd.pp' % hostname,
                           manifestdata,
                           marker=marker)
def create_ntp_manifest():
    servers = ''
    for srv in controller.CONF['CONFIG_NTP_SERVERS'].split(','):
        srv = srv.strip()
        validate.validatePing(srv)
        servers += 'server %s\n' % srv
        controller.CONF.setdefault('CONFIG_NTP_FIRST_SERVER', srv)
    controller.CONF['CONFIG_NTP_SERVERS'] = servers

    marker = uuid.uuid4().hex[:16]
    for hostname in gethostlist(controller.CONF):
        manifestdata = getManifestTemplate('ntpd.pp')
        appendManifestFile('%s_ntpd.pp' % hostname,
                           manifestdata,
                           marker=marker)
Exemple #19
0
def copyPuppetModules(config):
    os_modules = ' '.join(
        ('apache', 'cinder', 'concat', 'create_resources', 'firewall',
         'glance', 'horizon', 'inifile', 'keystone', 'memcached', 'mysql',
         'nova', 'openstack', 'packstack', 'qpid', 'quantum', 'rsync', 'ssh',
         'stdlib', 'swift', 'sysctl', 'vlan', 'vswitch', 'xinetd'))

    # write puppet manifest to disk
    manifestfiles.writeManifests()

    server = utils.ScriptRunner()
    tar_opts = ""
    if platform.linux_distribution()[0] == "Fedora":
        tar_opts += "--exclude create_resources "
    for hostname in gethostlist(controller.CONF):
        host_dir = controller.temp_map[hostname]
        puppet_dir = os.path.join(host_dir, basedefs.PUPPET_MANIFEST_RELATIVE)
        server.append("cd %s/puppet" % basedefs.DIR_PROJECT_DIR)
        # copy Packstack facts
        server.append("tar %s --dereference -cpzf - facts | "
                      "ssh -o StrictHostKeyChecking=no "
                      "-o UserKnownHostsFile=/dev/null "
                      "root@%s tar -C %s -xpzf -" %
                      (tar_opts, hostname, host_dir))
        # copy Packstack manifests
        server.append("cd %s" % basedefs.PUPPET_MANIFEST_DIR)
        server.append("tar %s --dereference -cpzf - ../manifests | "
                      "ssh -o StrictHostKeyChecking=no "
                      "-o UserKnownHostsFile=/dev/null "
                      "root@%s tar -C %s -xpzf -" %
                      (tar_opts, hostname, host_dir))

        # copy resources
        for path, localname in controller.resources.get(hostname, []):
            server.append(
                "scp -o StrictHostKeyChecking=no "
                "-o UserKnownHostsFile=/dev/null %s root@%s:%s/resources/%s" %
                (path, hostname, host_dir, localname))

        # copy Puppet modules required by Packstack
        server.append("cd %s/puppet/modules" % basedefs.DIR_PROJECT_DIR)
        server.append("tar %s --dereference -cpzf - %s | "
                      "ssh -o StrictHostKeyChecking=no "
                      "-o UserKnownHostsFile=/dev/null "
                      "root@%s tar -C %s -xpzf -" %
                      (tar_opts, os_modules, hostname,
                       os.path.join(host_dir, 'modules')))
    server.execute()
Exemple #20
0
def createnrpemanifests(config):
    for hostname in gethostlist(controller.CONF):
        controller.CONF['CONFIG_NRPE_HOST'] = hostname
        manifestfile = "%s_nagios_nrpe.pp" % hostname
        manifestdata = getManifestTemplate("nagios_nrpe.pp")
        #Only the Nagios host is allowed to talk to nrpe
        config['FIREWALL_ALLOWED'] = "'%s'" % config['CONFIG_NAGIOS_HOST']
        config['FIREWALL_SERVICE_NAME'] = "nagios-nrpe"
        config['FIREWALL_PORTS'] = '5666'
        manifestdata += getManifestTemplate("firewall.pp")
        appendManifestFile(manifestfile, manifestdata)

    controller.MESSAGES.append("To use Nagios, browse to http://%s/nagios "
                               "username : nagiosadmin, password : %s" %
                               (controller.CONF['CONFIG_NAGIOS_HOST'],
                                controller.CONF['CONFIG_NAGIOS_PW']))
Exemple #21
0
def createnrpemanifests(config):
    for hostname in gethostlist(controller.CONF):
        controller.CONF['CONFIG_NRPE_HOST'] = hostname
        manifestfile = "%s_nagios_nrpe.pp" % hostname
        manifestdata = getManifestTemplate("nagios_nrpe.pp")
        #Only the Nagios host is allowed to talk to nrpe
        config['FIREWALL_ALLOWED'] = "'%s'" % config['CONFIG_NAGIOS_HOST']
        config['FIREWALL_SERVICE_NAME'] = "nagios-nrpe"
        config['FIREWALL_PORTS'] = '5666'
        manifestdata += getManifestTemplate("firewall.pp")
        appendManifestFile(manifestfile, manifestdata)

    controller.MESSAGES.append("To use Nagios, browse to http://%s/nagios "
                               "username : nagiosadmin, password : %s" %
                               (controller.CONF['CONFIG_NAGIOS_HOST'],
                                controller.CONF['CONFIG_NAGIOS_PW']))
Exemple #22
0
def copyPuppetModules():
    os_modules = ' '.join(('apache', 'cinder', 'concat',
                           'create_resources', 'firewall',
                           'glance', 'horizon', 'inifile',
                           'keystone', 'memcached', 'mysql',
                           'nova', 'openstack', 'packstack',
                           'qpid', 'rsync', 'ssh', 'stdlib',
                           'swift', 'sysctl', 'vlan', 'xinetd'))

    # write puppet manifest to disk
    manifestfiles.writeManifests()

    server = utils.ScriptRunner()
    tar_opts = ""
    if platform.linux_distribution()[0] == "Fedora":
        tar_opts += "--exclude create_resources "
    for hostname in gethostlist(controller.CONF):
        host_dir = controller.temp_map[hostname]
        puppet_dir = os.path.join(host_dir, basedefs.PUPPET_MANIFEST_RELATIVE)
        server.append("cd %s/puppet" % basedefs.DIR_PROJECT_DIR)
        # copy Packstack facts
        server.append("tar %s --dereference -cpzf - facts | "
                      "ssh -o StrictHostKeyChecking=no "
                          "-o UserKnownHostsFile=/dev/null "
                          "root@%s tar -C %s -xpzf -" % (tar_opts, hostname, host_dir))
        # copy Packstack manifests
        server.append("cd %s" % basedefs.PUPPET_MANIFEST_DIR)
        server.append("tar %s --dereference -cpzf - ../manifests | "
                      "ssh -o StrictHostKeyChecking=no "
                          "-o UserKnownHostsFile=/dev/null "
                          "root@%s tar -C %s -xpzf -" % (tar_opts, hostname, host_dir))

        # copy resources
        for path, localname in controller.resources.get(hostname, []):
            server.append("scp -o StrictHostKeyChecking=no "
                "-o UserKnownHostsFile=/dev/null %s root@%s:%s/resources/%s" %
                (path, hostname, host_dir, localname))

        # copy Puppet modules required by Packstack
        server.append("cd %s/puppet/modules" % basedefs.DIR_PROJECT_DIR)
        server.append("tar %s --dereference -cpzf - %s | "
                      "ssh -o StrictHostKeyChecking=no "
                          "-o UserKnownHostsFile=/dev/null "
                          "root@%s tar -C %s -xpzf -" %
                                (tar_opts, os_modules, hostname,
                                 os.path.join(host_dir, 'modules')))
    server.execute()
Exemple #23
0
def applyPuppetManifest(config):
    print
    currently_running = []
    lastmarker = None
    for manifest, marker in manifestfiles.getFiles():
        # if the marker has changed then we don't want to proceed until
        # all of the previous puppet runs have finished
        if lastmarker != None and lastmarker != marker:
            waitforpuppet(currently_running)
        lastmarker = marker

        for hostname in gethostlist(controller.CONF):
            if "%s_" % hostname not in manifest:
                continue

            host_dir = controller.temp_map[hostname]
            print "Applying " + manifest
            server = utils.ScriptRunner(hostname)

            man_path = os.path.join(controller.temp_map[hostname],
                                    basedefs.PUPPET_MANIFEST_RELATIVE,
                                    manifest)

            running_logfile = "%s.running" % man_path
            finished_logfile = "%s.finished" % man_path
            currently_running.append((hostname, finished_logfile))
            # The apache puppet module doesn't work if we set FACTERLIB
            # https://github.com/puppetlabs/puppetlabs-apache/pull/138
            if not (manifest.endswith('_horizon.pp')
                    or manifest.endswith('_nagios.pp')):
                server.append("export FACTERLIB=$FACTERLIB:%s/facts" %
                              host_dir)
            server.append("touch %s" % running_logfile)
            server.append("chmod 600 %s" % running_logfile)
            server.append("export PACKSTACK_VAR_DIR=%s" % host_dir)
            loglevel = ''
            if logging.root.level <= logging.DEBUG:
                loglevel = '--debug'
            command = "( flock %s/ps.lock puppet apply %s --modulepath %s/modules %s > %s 2>&1 < /dev/null ; mv %s %s ) > /dev/null 2>&1 < /dev/null &" % (
                host_dir, loglevel, host_dir, man_path, running_logfile,
                running_logfile, finished_logfile)
            server.append(command)
            server.execute()

    # wait for outstanding puppet runs befor exiting
    waitforpuppet(currently_running)
def serverprep():
    for hostname in gethostlist(controller.CONF):
        if '/' in hostname:
            hostname = hostname.split('/')[0]
        server = utils.ScriptRunner(hostname)

        # install epel if on rhel and epel is configured
        if controller.CONF["CONFIG_USE_EPEL"] == 'y':
            server.append("export EPEL_RPM_URL=\"http://download.fedoraproject.org/pub/epel/6/"
                                                "$([ `uname -i` = 'x86_64' ] && echo 'x86_64' || echo 'i386')"
                                                "/epel-release-6-8.noarch.rpm\"")
            server.append("grep 'Red Hat Enterprise Linux' /etc/redhat-release && "
                          "( rpm -q epel-release || rpm -Uvh $EPEL_RPM_URL ) || echo -n ''")

        server.append("mkdir -p %s" % basedefs.PUPPET_MANIFEST_DIR)

        # set highest priority of RHOS repository if EPEL is installed
        server.append("rpm -q epel-release && yum install -y yum-plugin-priorities || true")
        subs_cmd = ('rpm -q epel-release && openstack-config --set %(repo_file)s %(repo)s priority %(priority)s || true')
        server.append(subs_cmd % {"repo_file": "/etc/yum.repos.d/redhat.repo",
                                  "repo": "rhel-server-ost-6-folsom-rpms",
                                  "priority": 1})

        # Add yum repositories if configured
        CONFIG_REPO = controller.CONF["CONFIG_REPO"].strip()
        if CONFIG_REPO:
            for i, url in enumerate(CONFIG_REPO.split(',')):
                reponame = 'packstack_%d' % i
                server.append('echo "[%s]\nname=%s\nbaseurl=%s\nenabled=1\npriority=1\ngpgcheck=0"'
                              ' > /etc/yum.repos.d/%s.repo' % (reponame, reponame, url, reponame))

        # Subscribe to Red Hat Repositories if configured
        RH_USERNAME = controller.CONF["CONFIG_RH_USERNAME"].strip()
        if RH_USERNAME:
            server.append("subscription-manager register --username=%s --password=%s --autosubscribe || true" % (RH_USERNAME, controller.CONF["CONFIG_RH_PASSWORD"].strip()))
            server.append("subscription-manager list --consumed | grep -i openstack || "
                          "subscription-manager subscribe --pool $(subscription-manager list --available | grep -e 'Red Hat OpenStack' -m 1 -A 2 | grep 'Pool Id' | awk '{print $3}')")
            server.append("yum clean all")
            server.append("yum-config-manager --enable rhel-server-ost-6-folsom-rpms")

        server.append("yum clean metadata")
        server.execute(maskList=[controller.CONF["CONFIG_RH_PASSWORD"].strip()])
Exemple #25
0
def applyPuppetManifest():
    print
    currently_running = []
    lastmarker = None
    for manifest, marker in manifestfiles.getFiles():
        # if the marker has changed then we don't want to proceed until
        # all of the previous puppet runs have finished
        if lastmarker != None and lastmarker != marker:
            waitforpuppet(currently_running)
        lastmarker = marker

        for hostname in gethostlist(controller.CONF):
            if "%s_" % hostname not in manifest:
                continue

            host_dir = controller.temp_map[hostname]
            print "Applying " + manifest
            server = utils.ScriptRunner(hostname)

            man_path = os.path.join(controller.temp_map[hostname],
                                    basedefs.PUPPET_MANIFEST_RELATIVE,
                                    manifest)

            running_logfile = "%s.running" % man_path
            finished_logfile = "%s.finished" % man_path
            currently_running.append((hostname, finished_logfile))
            # The apache puppet module doesn't work if we set FACTERLIB
            # https://github.com/puppetlabs/puppetlabs-apache/pull/138
            if not (manifest.endswith('_horizon.pp') or manifest.endswith('_nagios.pp')):
                server.append("export FACTERLIB=$FACTERLIB:%s/facts" % host_dir)
            server.append("touch %s" % running_logfile)
            server.append("chmod 600 %s" % running_logfile)
            server.append("export PACKSTACK_VAR_DIR=%s" % host_dir)
            loglevel = ''
            if logging.root.level <= logging.DEBUG:
                loglevel = '--debug'
            command = "( flock %s/ps.lock puppet apply %s --modulepath %s/modules %s > %s 2>&1 < /dev/null ; mv %s %s ) > /dev/null 2>&1 < /dev/null &" % (host_dir, loglevel, host_dir, man_path, running_logfile, running_logfile, finished_logfile)
            server.append(command)
            server.execute()

    # wait for outstanding puppet runs befor exiting
    waitforpuppet(currently_running)
Exemple #26
0
def remove_remote_var_dirs():
    """
    Removes the temp directories on remote hosts,
    doesn't remove data on localhost
    """
    for host in gethostlist(controller.CONF):
        try:
            host_dir = controller.temp_map[host]
        except KeyError:
            # Nothing was added to this host yet, so we have nothing to delete
            continue
        logging.info(output_messages.INFO_REMOVE_REMOTE_VAR % (host_dir, host))
        server = utils.ScriptRunner(host)
        server.append('rm -rf %s' % host_dir)
        try:
            server.execute()
        except Exception, e:
            msg = output_messages.ERR_REMOVE_REMOTE_VAR % (host_dir, host)
            logging.error(msg)
            logging.exception(e)
            controller.MESSAGES.append(utils.color_text(msg, 'red'))
Exemple #27
0
def remove_remote_var_dirs():
    """
    Removes the temp directories on remote hosts,
    doesn't remove data on localhost
    """
    for host in gethostlist(controller.CONF):
        try:
            host_dir = controller.CONF['HOST_DETAILS'][host]['tmpdir']
        except KeyError:
            # Nothing was added to this host yet, so we have nothing to delete
            continue
        logging.debug(output_messages.INFO_REMOVE_REMOTE_VAR % (host_dir, host))
        server = utils.ScriptRunner(host)
        server.append('rm -rf %s' % host_dir)
        try:
            server.execute()
        except Exception as e:
            msg = output_messages.ERR_REMOVE_REMOTE_VAR % (host_dir, host)
            logging.error(msg)
            logging.exception(e)
            controller.MESSAGES.append(utils.color_text(msg, 'red'))
Exemple #28
0
def copyPuppetModules():
    # write puppet manifest to disk
    manifestfiles.writeManifests()

    server = utils.ScriptRunner()
    tar_opts = ""
    if platform.linux_distribution()[0] == "Fedora":
        tar_opts += "--exclude create_resources "
    for hostname in gethostlist(controller.CONF):
        host_dir = controller.temp_map[hostname]
        puppet_dir = os.path.join(host_dir, basedefs.PUPPET_MANIFEST_RELATIVE)
        server.append("cd %s/puppet" % basedefs.DIR_PROJECT_DIR)
        server.append("tar %s --dereference -cpzf - modules facts | "
                      "ssh -o StrictHostKeyChecking=no "
                          "-o UserKnownHostsFile=/dev/null "
                          "root@%s tar -C %s -xpzf -" % (tar_opts, hostname, host_dir))
        server.append("cd %s" % basedefs.PUPPET_MANIFEST_DIR)
        server.append("tar %s --dereference -cpzf - ../manifests | "
                      "ssh -o StrictHostKeyChecking=no "
                          "-o UserKnownHostsFile=/dev/null "
                          "root@%s tar -C %s -xpzf -" % (tar_opts, hostname, host_dir))
    server.execute()
Exemple #29
0
def serverprep():
    for hostname in gethostlist(controller.CONF):
        if '/' in hostname:
            hostname = hostname.split('/')[0]
        server = utils.ScriptRunner(hostname)

        # install epel if on rhel and epel is configured
        if controller.CONF["CONFIG_USE_EPEL"] == 'y':
            server.append(
                "grep 'Red Hat Enterprise Linux' /etc/redhat-release && ( rpm -q epel-release || \
                           rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm ) || echo -n ''"
            )
        server.append("mkdir -p %s" % basedefs.PUPPET_MANIFEST_DIR)

        # Add yum repositories if configured
        CONFIG_REPO = controller.CONF["CONFIG_REPO"].strip()
        if CONFIG_REPO:
            for i, url in enumerate(CONFIG_REPO.split(',')):
                reponame = 'packstack_%d' % i
                server.append(
                    'echo "[%s]\nname=%s\nbaseurl=%s\nenabled=1\ngpgcheck=0" > /etc/yum.repos.d/%s.repo'
                    % (reponame, reponame, url, reponame))

        # Subscribe to Red Hat Repositories if configured
        RH_USERNAME = controller.CONF["CONFIG_RH_USERNAME"].strip()
        if RH_USERNAME:
            server.append(
                "subscription-manager register --username=%s --password=%s --autosubscribe || true"
                % (RH_USERNAME, controller.CONF["CONFIG_RH_PASSWORD"].strip()))
            server.append(
                "subscription-manager list --consumed | grep -i openstack || "
                "subscription-manager subscribe --pool $(subscription-manager list --available | grep -e 'Red Hat OpenStack' -m 1 -A 2 | grep 'Pool Id' | awk '{print $3}')"
            )
            server.append("yum clean all")
            server.append(
                "yum-config-manager --enable rhel-server-ost-6-folsom-rpms")

        server.execute()
Exemple #30
0
def applyPuppetManifest():
    print
    currently_running = []
    lastmarker = None
    for manifest, marker in manifestfiles.getFiles():
        # if the marker has changed then we don't want to proceed until
        # all of the previous puppet runs have finished
        if lastmarker != None and lastmarker != marker:
            waitforpuppet(currently_running)
        lastmarker = marker

        for hostname in gethostlist(controller.CONF):
            if "%s_" % hostname not in manifest:
                continue

            host_dir = controller.temp_map[hostname]
            print "Applying " + manifest
            server = utils.ScriptRunner(hostname)

            man_path = os.path.join(controller.temp_map[hostname],
                                    basedefs.PUPPET_MANIFEST_RELATIVE,
                                    manifest)

            running_logfile = "%s.running" % man_path
            finished_logfile = "%s.finished" % man_path
            currently_running.append((hostname, finished_logfile))
            if not manifest.endswith('_horizon.pp'):
                server.append("export FACTERLIB=$FACTERLIB:%s/facts" % host_dir)
            server.append("touch %s" % running_logfile)
            server.append("chmod 600 %s" % running_logfile)
            command = "( flock %s/ps.lock puppet apply --modulepath %s/modules %s > %s 2>&1 < /dev/null ; mv %s %s ) > /dev/null 2>&1 < /dev/null &" % (host_dir, host_dir, man_path, running_logfile, running_logfile, finished_logfile)
            server.append(command)
            server.execute()

    # wait for outstanding puppet runs befor exiting
    waitforpuppet(currently_running)
 def test_gethostlist(self):
     conf = {"A_HOST": "1.1.1.1", "B_HOSTS": "2.2.2.2,1.1.1.1", "C_HOSTS": "3.3.3.3/vdc"}
     hosts = gethostlist(conf)
     hosts.sort()
     self.assertEqual(["1.1.1.1", "2.2.2.2", "3.3.3.3"], hosts)
Exemple #32
0
def serverprep():
    config = controller.CONF

    rh_username = config["CONFIG_RH_USER"].strip()
    rh_password = config["CONFIG_RH_PW"].strip()

    sat_registered = set()

    sat_url = config["CONFIG_SATELLITE_URL"].strip()
    if sat_url:
        sat_flags = map(lambda i: i.strip(),
                        config["CONFIG_SATELLITE_FLAGS"].split(','))
        sat_proxy_user = config.get("CONFIG_SATELLITE_PROXY_USER", '')
        sat_proxy_pass = config.get("CONFIG_SATELLITE_PROXY_PW", '')
        sat_args = {
            'username': config["CONFIG_SATELLITE_USER"].strip(),
            'password': config["CONFIG_SATELLITE_PW"].strip(),
            'cacert': config["CONFIG_SATELLITE_CACERT"].strip(),
            'activation_key': config["CONFIG_SATELLITE_AKEY"].strip(),
            'profile_name': config["CONFIG_SATELLITE_PROFILE"].strip(),
            'proxy_host': config["CONFIG_SATELLITE_PROXY"].strip(),
            'proxy_user': sat_proxy_user.strip(),
            'proxy_pass': sat_proxy_pass.strip(),
            'flags': sat_flags
        }

    for hostname in gethostlist(config):
        if '/' in hostname:
            hostname = hostname.split('/')[0]

        # Subscribe to Red Hat Repositories if configured
        if rh_username:
            run_rhsm_reg(hostname, rh_username, rh_password,
                         config["CONFIG_RH_BETA_REPO"] == 'y')

        # Subscribe to RHN Satellite if configured
        if sat_url and hostname not in sat_registered:
            run_rhn_reg(hostname, sat_url, **sat_args)
            sat_registered.add(hostname)

        server = utils.ScriptRunner(hostname)

        # install epel if on rhel (or popular derivative thereof) and epel is configured
        if config["CONFIG_USE_EPEL"] == 'y':
            server.append("REPOFILE=$(mktemp)")
            server.append("cat /etc/yum.conf > $REPOFILE")
            server.append(
                "echo -e '[packstack-epel]\nname=packstack-epel\n"
                "enabled=1\n"
                "mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch'"
                ">> $REPOFILE")

            server.append(
                "grep -e 'Red Hat Enterprise Linux' -e 'CentOS' -e 'Scientific Linux' /etc/redhat-release && "
                "( rpm -q epel-release || yum install -y --nogpg -c $REPOFILE epel-release ) || echo -n ''"
            )
            server.append("rm -rf $REPOFILE")

        # set highest priority of RHOS repository if EPEL is installed and
        # the repo rhel-server-ost-6-folsom-rpms exists in redhat.repo

        # If RHOS has been installed we can diable EPEL when installing openstack-utils
        yum_opts = ""
        if config["CONFIG_RH_USER"].strip():
            yum_opts += "--disablerepo='epel*'"

        server.append(
            "rpm -q epel-release && "
            "yum install -y %s openstack-utils yum-plugin-priorities || true" %
            yum_opts)
        subs_cmd = (
            'rpm -q epel-release && '
            'grep %(repo)s %(repo_file)s && '
            'openstack-config --set %(repo_file)s %(repo)s priority %(priority)s || true'
        )
        server.append(
            subs_cmd % {
                "repo_file": "/etc/yum.repos.d/redhat.repo",
                "repo": "rhel-server-ost-6-folsom-rpms",
                "priority": 1
            })

        # Create the packstack tmp directory
        if hostname not in controller.temp_map:
            # TO-DO: Move this to packstack.installer.setup_controller
            server.append("mkdir -p %s" % basedefs.PACKSTACK_VAR_DIR)
            # Separately create the tmp directory for this packstack run, this will fail if
            # the directory already exists
            host_dir = os.path.join(basedefs.PACKSTACK_VAR_DIR,
                                    uuid.uuid4().hex)
            server.append("mkdir --mode 0700 %s" % host_dir)
            server.append("mkdir %s/resources" % host_dir)
            server.append("mkdir --mode 0700 %s" %
                          os.path.join(host_dir, 'modules'))
            controller.temp_map[hostname] = host_dir

        # Add yum repositories if configured
        CONFIG_REPO = config["CONFIG_REPO"].strip()
        if CONFIG_REPO:
            for i, url in enumerate(CONFIG_REPO.split(',')):
                reponame = 'packstack_%d' % i
                server.append(
                    'echo "[%s]\nname=%s\nbaseurl=%s\nenabled=1\npriority=1\ngpgcheck=0"'
                    ' > /etc/yum.repos.d/%s.repo' %
                    (reponame, reponame, url, reponame))

        server.append("yum clean metadata")
        server.execute()
Exemple #33
0
def createmanifest():
    for hostname in gethostlist(controller.CONF):
        manifestfile = "%s_postscript.pp" % hostname
        manifestdata = getManifestTemplate("postscript.pp")
        appendManifestFile(manifestfile, manifestdata, 'postscript')
Exemple #34
0
def createmanifest():
    manifest_entries = ''
    # I should be adding service entries with nagios_service but it appears to  be broken
    # http://projects.puppetlabs.com/issues/3420
    service_entries = ''
    for hostname in gethostlist(controller.CONF):
        manifest_entries += "nagios_host{'%s': address => '%s', use   => 'linux-server', }\n" % (
            hostname, hostname)

        service_entries += _serviceentry(
            name='load5-%s' % hostname,
            service_description='5 minute load average',
            host_name=hostname,
            check_command="check_nrpe!load5",
            use="generic-service",
            normal_check_interval='5')

        service_entries += _serviceentry(
            name='df_var-%s' % hostname,
            service_description='Percent disk space used on /var',
            host_name=hostname,
            check_command="check_nrpe!df_var",
            use="generic-service")

    manifest_entries += _copy_script(name="keystone-user-list")
    service_entries += _serviceentry(
        name='keystone-user-list',
        service_description='number of keystone users',
        host_name=controller.CONF['CONFIG_NAGIOS_HOST'],
        check_command="keystone-user-list",
        use="generic-service",
        normal_check_interval='5')

    if controller.CONF['CONFIG_GLANCE_INSTALL'] == 'y':
        manifest_entries += _copy_script(name="glance-index")
        service_entries += _serviceentry(
            name='glance-index',
            service_description='number of glance images',
            host_name=controller.CONF['CONFIG_NAGIOS_HOST'],
            check_command="glance-index",
            use="generic-service",
            normal_check_interval='5')

    if controller.CONF['CONFIG_NOVA_INSTALL'] == 'y':
        manifest_entries += _copy_script(name="nova-list")
        service_entries += _serviceentry(
            name='nova-list',
            service_description='number of nova vm instances',
            host_name=controller.CONF['CONFIG_NAGIOS_HOST'],
            check_command="nova-list",
            use="generic-service",
            normal_check_interval='5')

    if controller.CONF['CONFIG_CINDER_INSTALL'] == 'y':
        manifest_entries += _copy_script(name="cinder-list")
        service_entries += _serviceentry(
            name='cinder-list',
            service_description='number of cinder volumes',
            host_name=controller.CONF['CONFIG_NAGIOS_HOST'],
            check_command="cinder-list",
            use="generic-service",
            normal_check_interval='5')

    if controller.CONF['CONFIG_SWIFT_INSTALL'] == 'y':
        manifest_entries += _copy_script(name="swift-list")
        service_entries += _serviceentry(
            name='swift-list',
            service_description='number of swift containers',
            host_name=controller.CONF['CONFIG_NAGIOS_HOST'],
            check_command="swift-list",
            use="generic-service",
            normal_check_interval='5')

    manifest_entries+="file{'/etc/nagios/resource.d/nagios_service.cfg': \n" \
                      "ensure => present, mode => 644,\n" \
                      "content => '%s'}" % service_entries

    controller.CONF['CONFIG_NAGIOS_MANIFEST_CONFIG'] = manifest_entries

    manifestfile = "%s_nagios.pp" % controller.CONF['CONFIG_NAGIOS_HOST']
    manifestdata = getManifestTemplate("nagios_server.pp")
    appendManifestFile(manifestfile, manifestdata)
Exemple #35
0
def createmanifest():
    for hostname in gethostlist(controller.CONF):
        manifestfile = "%s_postscript.pp" % hostname
        manifestdata = getManifestTemplate("postscript.pp")
        appendManifestFile(manifestfile, manifestdata, 'postscript')
Exemple #36
0
def serverprep(config):
    rh_username = None
    sat_url = None
    if is_rhel():
        rh_username = config["CONFIG_RH_USER"].strip()
        rh_password = config["CONFIG_RH_PW"].strip()

        sat_registered = set()

        sat_url = config["CONFIG_SATELLITE_URL"].strip()
        if sat_url:
            flag_list = config["CONFIG_SATELLITE_FLAGS"].split(',')
            sat_flags = [i.strip() for i in flag_list if i.strip()]
            sat_proxy_user = config.get("CONFIG_SATELLITE_PROXY_USER", '')
            sat_proxy_pass = config.get("CONFIG_SATELLITE_PROXY_PW", '')
            sat_args = {'username': config["CONFIG_SATELLITE_USER"].strip(),
                        'password': config["CONFIG_SATELLITE_PW"].strip(),
                        'cacert': config["CONFIG_SATELLITE_CACERT"].strip(),
                        'activation_key': config["CONFIG_SATELLITE_AKEY"].strip(),
                        'profile_name': config["CONFIG_SATELLITE_PROFILE"].strip(),
                        'proxy_host': config["CONFIG_SATELLITE_PROXY"].strip(),
                        'proxy_user': sat_proxy_user.strip(),
                        'proxy_pass': sat_proxy_pass.strip(),
                        'flags': sat_flags}

    for hostname in gethostlist(config):
        if '/' in hostname:
            hostname = hostname.split('/')[0]

        # Subscribe to Red Hat Repositories if configured
        if rh_username:
            run_rhsm_reg(hostname, rh_username, rh_password, config["CONFIG_RH_BETA_REPO"] == 'y')

        # Subscribe to RHN Satellite if configured
        if sat_url and hostname not in sat_registered:
            run_rhn_reg(hostname, sat_url, **sat_args)
            sat_registered.add(hostname)

        server = utils.ScriptRunner(hostname)

        # install epel if on rhel (or popular derivative thereof) and epel is configured
        if config["CONFIG_USE_EPEL"] == 'y':
            server.append("REPOFILE=$(mktemp)")
            server.append("cat /etc/yum.conf > $REPOFILE")
            server.append("echo -e '[packstack-epel]\nname=packstack-epel\n"
                          "enabled=1\n"
                          "mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch'"
                          ">> $REPOFILE")

            server.append("grep -e 'Red Hat Enterprise Linux' -e 'CentOS' -e 'Scientific Linux' /etc/redhat-release && "
                          "( rpm -q epel-release || yum install -y --nogpg -c $REPOFILE epel-release ) || echo -n ''")
            server.append("rm -rf $REPOFILE")


        # set highest priority of RHOS repository if EPEL is installed and
        # the repo rhel-server-ost-6-folsom-rpms exists in redhat.repo

        # If RHOS has been installed we can diable EPEL when installing openstack-utils
        yum_opts = ""
        if rh_username:
            yum_opts += "--disablerepo='epel*'"

        server.append("rpm -q epel-release && "
                      "yum install -y %s openstack-utils yum-plugin-priorities || true" % yum_opts)
        subs_cmd = ('rpm -q epel-release && '
                    'grep %(repo)s %(repo_file)s && '
                    'openstack-config --set %(repo_file)s %(repo)s priority %(priority)s || true')
        server.append(subs_cmd % {"repo_file": "/etc/yum.repos.d/redhat.repo",
                                  "repo": "rhel-server-ost-6-folsom-rpms",
                                  "priority": 1})

        # Create the packstack tmp directory
        if hostname not in controller.temp_map:
            # TO-DO: Move this to packstack.installer.setup_controller
            server.append("mkdir -p %s" % basedefs.PACKSTACK_VAR_DIR)
            # Separately create the tmp directory for this packstack run, this will fail if
            # the directory already exists
            host_dir = os.path.join(basedefs.PACKSTACK_VAR_DIR, uuid.uuid4().hex)
            server.append("mkdir --mode 0700 %s" % host_dir)
            server.append("mkdir %s/resources" % host_dir)
            server.append("mkdir --mode 0700 %s" %
                          os.path.join(host_dir, 'modules'))
            controller.temp_map[hostname] = host_dir

        # Add yum repositories if configured
        CONFIG_REPO = config["CONFIG_REPO"].strip()
        if CONFIG_REPO:
            for i, url in enumerate(CONFIG_REPO.split(',')):
                reponame = 'packstack_%d' % i
                server.append('echo "[%s]\nname=%s\nbaseurl=%s\nenabled=1\npriority=1\ngpgcheck=0"'
                              ' > /etc/yum.repos.d/%s.repo' % (reponame, reponame, url, reponame))

        server.append("yum clean metadata")
        server.execute()
Exemple #37
0
def installdeps():
    for hostname in gethostlist(controller.CONF):
        server = utils.ScriptRunner(hostname)
        for package in ("puppet", "openssh-clients", "tar"):
            server.append("rpm -q %s || yum install -y %s" % (package, package))
        server.execute()
def installpuppet():
    for hostname in gethostlist(controller.CONF):
        server = utils.ScriptRunner(hostname)
        server.append("rpm -q puppet || yum install -y puppet")
        server.execute()
Exemple #39
0
def installpuppet():
    for hostname in gethostlist(controller.CONF):
        server = utils.ScriptRunner(hostname)
        server.append("rpm -q puppet || yum install -y puppet")
        server.execute()
Exemple #40
0
def createmanifest():
    manifest_entries = ''
    # I should be adding service entries with nagios_service but it appears to  be broken
    # http://projects.puppetlabs.com/issues/3420
    service_entries = ''
    for hostname in gethostlist(controller.CONF):
        manifest_entries += "nagios_host{'%s': address => '%s', use   => 'linux-server', }\n" % (hostname, hostname)

        service_entries += _serviceentry(name='load5-%s'%hostname, service_description='5 minute load average',
                                         host_name=hostname, check_command="check_nrpe!load5", use="generic-service",
                                         normal_check_interval='5')

        service_entries += _serviceentry(name='df_var-%s'%hostname,
                                         service_description='Percent disk space used on /var',
                                         host_name=hostname,
                                         check_command="check_nrpe!df_var", use="generic-service")

    manifest_entries += _copy_script(name="keystone-user-list")
    service_entries += _serviceentry(name='keystone-user-list',
        service_description='number of keystone users',
        host_name=controller.CONF['CONFIG_NAGIOS_HOST'],
        check_command="keystone-user-list", use="generic-service",
        normal_check_interval='5')

    if controller.CONF['CONFIG_GLANCE_INSTALL'] == 'y':
        manifest_entries += _copy_script(name="glance-index")
        service_entries += _serviceentry(name='glance-index',
            service_description='number of glance images',
            host_name=controller.CONF['CONFIG_NAGIOS_HOST'],
            check_command="glance-index", use="generic-service",
            normal_check_interval='5')

    if controller.CONF['CONFIG_NOVA_INSTALL'] == 'y':
        manifest_entries += _copy_script(name="nova-list")
        service_entries += _serviceentry(name='nova-list',
            service_description='number of nova vm instances',
            host_name=controller.CONF['CONFIG_NAGIOS_HOST'],
            check_command="nova-list", use="generic-service",
            normal_check_interval='5')

    if controller.CONF['CONFIG_CINDER_INSTALL'] == 'y':
        manifest_entries += _copy_script(name="cinder-list")
        service_entries += _serviceentry(name='cinder-list',
            service_description='number of cinder volumes',
            host_name=controller.CONF['CONFIG_NAGIOS_HOST'],
            check_command="cinder-list", use="generic-service",
            normal_check_interval='5')

    if controller.CONF['CONFIG_SWIFT_INSTALL'] == 'y':
        manifest_entries += _copy_script(name="swift-list")
        service_entries += _serviceentry(name='swift-list',
            service_description='number of swift containers',
            host_name=controller.CONF['CONFIG_NAGIOS_HOST'],
            check_command="swift-list", use="generic-service",
            normal_check_interval='5')

    manifest_entries+="file{'/etc/nagios/resource.d/nagios_service.cfg': \n" \
                      "ensure => present, mode => 644,\n" \
                      "content => '%s'}" % service_entries

    controller.CONF['CONFIG_NAGIOS_MANIFEST_CONFIG'] = manifest_entries

    manifestfile = "%s_nagios.pp" % controller.CONF['CONFIG_NAGIOS_HOST']
    manifestdata = getManifestTemplate("nagios_server.pp")
    appendManifestFile(manifestfile, manifestdata)
 def test_gethostlist(self):
     conf = {"A_HOST": "1.1.1.1", "B_HOSTS": "2.2.2.2,1.1.1.1",
             "C_HOSTS": "3.3.3.3/vdc"}
     hosts = gethostlist(conf)
     hosts.sort()
     self.assertEquals(['1.1.1.1', '2.2.2.2', '3.3.3.3'], hosts)
 def is_all_in_one(config):
     return len(gethostlist(config)) == 1
Exemple #43
0
 def is_all_in_one(config):
     return len(gethostlist(config)) == 1