コード例 #1
0
def reset():
    """ Resets a RabbitMQ instance """
    return [
        Statements.exec("rabbitmqctl stop_app"),
        Statements.exec("rabbitmqctl reset"),
        Statements.exec("rabbitmqctl start_app")
    ]
コード例 #2
0
ファイル: hostname.py プロジェクト: nacx/kahuna
def configure(node):
    """ Generates the script to set the hostname in a node """
    script = []
    script.append(Statements.exec("hostname %s" % node.getName()))
    script.append(Statements.createOrOverwriteFile(
        "/etc/hostname", [node.getName()]))
    script.append(Statements.exec(
        "sed -i 's/127.0.0.1/127.0.0.1\t%s/' /etc/hosts" % node.getName()))
    return script
コード例 #3
0
 def upload_libs(self):
     """ Uploads necessary libraries to Tomcat lib dir """
     script = []
     script.append(Statements.exec(
         "ensure_cmd_or_install_package_apt wget wget"))
     script.append(Statements.exec(
         "wget -O /usr/share/tomcat6/lib/abiquo.jar %s" % self.__abiquojar))
     script.append(Statements.exec(
         "wget -O /usr/share/tomcat6/lib/mysql.jar %s" % self.__mysqljar))
     return script
コード例 #4
0
def configure(node):
    """ Generates the script to set the hostname in a node """
    script = []
    script.append(Statements.exec("hostname %s" % node.getName()))
    script.append(
        Statements.createOrOverwriteFile("/etc/hostname", [node.getName()]))
    script.append(
        Statements.exec("sed -i 's/127.0.0.1/127.0.0.1\t%s/' /etc/hosts" %
                        node.getName()))
    return script
コード例 #5
0
def mount(nfs_share, mount_point):
    """ Mounts a NFS in the given mount point """
    script = []
    script.append(Statements.exec("{md} %s" % mount_point))
    script.append(
        Statements.appendFile(
            "/etc/fstab",
            ["%s %s nfs defaults 0 0" % (nfs_share, mount_point)]))
    script.append(Statements.exec("mount %s" % mount_point))
    return script
コード例 #6
0
 def _install_local_wars(self):
     """ Copies uploaded wars in the tomcat webapps directory """
     script = []
     script.append(Statements.exec(
         "ensure_cmd_or_install_package_apt unzip unzip"))
     script.append(Statements.exec(
         "mv /tmp/*.war /var/lib/tomcat6/webapps"))
     script.append(Statements.exec(
         "for f in /var/lib/tomcat6/webapps/*.war; "
         "do unzip -d ${f%.war} $f; done"))
     return script
コード例 #7
0
    def _deploy_aim(self, config_section, vapp_name):
        """ Deploys and configures an AIM based hypervisor """
        compute = self._context.getComputeService()

        try:
            name = self.__config.get(config_section, "template")
            log.info("Loading template...")
            vdc, options = self._template_options(compute, config_section)
            template = compute.templateBuilder() \
                .imageNameMatches(name) \
                .locationId(vdc.getId()) \
                .options(options) \
                .build()

            log.info("Deploying %s to %s..." % (template.getImage().getName(),
                vdc.getDescription()))
            identity = self._context.getApiContext().getIdentity()
            node = Iterables.getOnlyElement(
                compute.createNodesInGroup("%s-%s" % (vapp_name, identity),
                    1, template))

            log.info("Created %s at %s" % (node.getName(),
                Iterables.getOnlyElement(node.getPublicAddresses())))

            # Configuration values
            redishost = self.__config.get(config_section, "redis_host")
            redisport = self.__config.get(config_section, "redis_port")
            nfsto = self.__config.get(config_section, "nfs_to")
            nfsfrom = self.__config.get(config_section, "nfs_from")

            bootstrap = []

            with open("%s/abiquo-aim.ini" % self.__scriptdir, "r") as f:
                aim_config = f.read() % {'redishost': redishost,
                    'redisport': redisport, 'nfsto': nfsto}
            bootstrap.append(Statements.createOrOverwriteFile(
                "/etc/abiquo-aim.ini", [aim_config]))

            with open("%s/configure-aim-node.sh" % self.__scriptdir, "r") as f:
                script = f.read() % {'nfsfrom': nfsfrom, 'nfsto': nfsto}
            bootstrap.append(Statements.exec(script))

            log.info("Configuring node...")
            compute.runScriptOnNode(node.getId(), StatementList(bootstrap))

            log.info("Done! You can access it at: %s" %
                Iterables.getOnlyElement(node.getPublicAddresses()))

        except RunNodesException, ex:
            self._print_node_errors(ex)
コード例 #8
0
 def configure_user(self, user, group):
     """ Configures tomcat to run as the given user """
     # Even if the tomcat recipe is configured to use a different user,
     # it fails to restart the service the first time, leaving the
     # environment in an inconsistent state, so we will configure the
     # users manually.
     script = []
     script.append(Statements.exec(
         "sed -i s/TOMCAT6_USER=.*/TOMCAT6_USER=%s/ /etc/default/tomcat6"
         % user))
     script.append(Statements.exec(
         "sed -i s/TOMCAT6_GROUP=.*/TOMCAT6_GROUP=%s/ /etc/default/tomcat6"
         % group))
     return script
コード例 #9
0
 def configure_logging(self, module, sysloghost):
     """ Configures the logger of a given module """
     with open("%s/logback.xml" % self.__templatedir, "r") as f:
         log_config = f.read() % {'sysloghost': sysloghost}
     return Statements.createOrOverwriteFile(
         "/var/lib/tomcat6/webapps/%s/WEB-INF/classes/logback.xml" % module,
         [log_config])
コード例 #10
0
def _download_war(version, file_name, destination="/tmp"):
    """ Downloads a given war from Jenkins """
    if file_name == "rs":
        return _download_rs(version)
    else:
        return [Statements.exec("wget -O %s/%s.war %s/%s/%s.war" %
            (destination, file_name, JENKINS, version, file_name))]
コード例 #11
0
 def _clone_required_cookbooks(self):
     """ Clone the cookbooks required to install Tomcat """
     script = []
     # Tomcat
     script.append(git.clone_opscode_cookbook("java"))
     script.append(git.clone("git://github.com/abiquo/tomcat.git",
         "/var/chef/cookbooks/tomcat", "ajp"))
     # Monitoring
     script.append(git.clone_opscode_cookbook("build-essential"))
     script.append(git.clone_opscode_cookbook("apt"))
     script.append(git.clone_opscode_cookbook("xml"))
     script.append(git.clone_opscode_cookbook("mysql"))
     script.append(git.clone_opscode_cookbook("php"))
     script.append(git.clone_opscode_cookbook("python"))
     script.append(git.clone_opscode_cookbook("apache2"))
     script.append(
         git.clone("git://github.com/escapestudios/chef-newrelic.git",
         "/var/chef/cookbooks/newrelic"))
     script.append(
         git.clone("git://github.com/boundary/boundary_cookbooks.git",
         "/tmp/boundary"))
     # Use only the bprobe cookbook
     script.append(Statements.exec(
         "mv /tmp/boundary/bprobe /var/chef/cookbooks/"))
     return script
コード例 #12
0
ファイル: jenkins.py プロジェクト: ssedano/kahuna
def _download_war(version, file_name, destination="/tmp"):
    """ Downloads a given war from Jenkins """
    if file_name == "rs":
        return _download_rs(version)
    else:
        return [Statements.exec("wget -O %s/%s.war %s/%s/%s.war" %
            (destination, file_name, JENKINS, version, file_name))]
コード例 #13
0
 def configure_abiquo_listener(self):
     """ Adds the Abiquo listener to server.xml """
     return Statements.exec(
         "sed -i -e "
         "'/GlobalResourcesLifecycleListener/a <Listener className="
         "\"com.abiquo.listeners.AbiquoConfigurationListener\"/>' "
         "/etc/tomcat6/server.xml")
コード例 #14
0
    def reset_datanode(self, args):
        """ Resets the datanode (database, redis and rabbitmq) """
        parser = OptionParser(usage="scalability reset-datanode <options>")
        parser.add_option('-j', '--jenkins-version',
                help='Download the database from the given version '
                'from Jenkins', action='store', dest='jenkins')
        parser.add_option('-d', '--datanode',
                help='Ip address of the data node (with rabbit, '
                'redis and zookeper)', action='store', dest='datanode')
        parser.add_option('-u', '--login-user',
                help='Username used to access the datanode',
                action='store', dest='user')
        parser.add_option('-p', '--login-password',
                help='Password used to access the datanode',
                action='store', dest='password')

        (options, args) = parser.parse_args(args)

        if not options.datanode or not options.jenkins \
                or not options.user or not options.password:
            parser.print_help()
            return

        compute = self._context.getComputeService()
        license = self.__config.get("reset-datanode", "license")
        predicate = NodeHasIp(options.datanode)

        try:
            script = []
            script.append(jenkins._download_database(options.jenkins))
            script.append(Statements.exec(
                "mysql -u %s kinton </tmp/kinton-schema-%s.sql" %
                (options.user, options.jenkins)))
            script.append(Statements.exec(
                'mysql -u %s kinton -e "'
                'insert into license (data, version_c) values (\'%s\', 1)"' %
                (options.user, license)))
            script.append(redis.run("flushall"))
            script.extend(rabbitmq.reset())
            print "Cleaning database for datanode at: %s" % options.datanode
            options = RunScriptOptions.Builder \
                .overrideLoginUser(options.user) \
                .overrideLoginPassword(options.password)
            compute.runScriptOnNodesMatching(predicate,
                StatementList(script), options)
        except RunNodesException, ex:
            self._print_node_errors(ex)
コード例 #15
0
 def configure_abiquo_props(self, rabbit, redis, zookeeper, datacenter,
         nfs_share, nfs_directory, hypervisor_sessions):
     """ Configures the abiquo.properties file """
     with open("%s/abiquo.properties" % self.__templatedir, "r") as f:
         abiquo_props = f.read() % {
             'rabbit': rabbit,
             'redis': redis,
             'zookeeper': zookeeper,
             'datacenter': datacenter,
             'nfs': nfs_share,
             'nfsmount': nfs_directory,
             'hypervisorsessions': hypervisor_sessions
         }
     script = []
     script.append(Statements.exec("{md} /opt/abiquo/config"))
     script.append(Statements.createOrOverwriteFile(
         "/opt/abiquo/config/abiquo.properties", [abiquo_props]))
     return script
コード例 #16
0
ファイル: jenkins.py プロジェクト: ssedano/kahuna
def _download_bpm(version, destination="/tmp"):
    """ Downloads a given war from Jenkins """
    script = []
    script.append(_download_war(version, "bpm-async", destination))
    script.append(_download_script(version, "v2v-diskmanager",
        "/usr/local/bin"))
    script.append(_download_script(version, "mechadora", "/usr/local/bin"))
    script.append(Statements.exec("chmod a+x /usr/local/bin/*"))
    return script
コード例 #17
0
def _download_bpm(version, destination="/tmp"):
    """ Downloads a given war from Jenkins """
    script = []
    script.extend(_download_war(version, "bpm-async", destination))
    script.append(_download_script(version, "v2v-diskmanager",
        "/usr/local/bin"))
    script.append(_download_script(version, "mechadora", "/usr/local/bin"))
    script.append(Statements.exec("chmod a+x /usr/local/bin/*"))
    return script
コード例 #18
0
ファイル: jenkins.py プロジェクト: ssedano/kahuna
def download_rs(version):
    """ Downloads all Remote Services stuff from Jenkins """
    script = []
    script.append(Statements.exec(
        "ensure_cmd_or_install_package_apt wget wget"))
    script.append(_download_war(version, "am"))
    script.append(_download_war(version, "nodecollector"))
    script.append(_download_war(version, "ssm"))
    script.append(_download_war(version, "virtualfactory"))
    script.append(_download_war(version, "vsm"))
    script.extend(_download_bpm(version))
    return script
コード例 #19
0
def download_rs(version, destination="/tmp"):
    """ Downloads all Remote Services stuff from Jenkins """
    script = []
    script.append(Statements.exec(
        "ensure_cmd_or_install_package_apt wget wget"))
    script.append(_download_war(version, "am", destination))
    script.append(_download_war(version, "nodecollector", destination))
    script.append(_download_war(version, "ssm", destination))
    script.append(_download_war(version, "virtualfactory", destination))
    script.append(_download_war(version, "vsm", destination))
    script.extend(_download_bpm(version, destination))
    return script
コード例 #20
0
 def configure_context(self, module, dbhost, dbuser, dbpass, jndi):
     """ Configures the context of a given module """
     with open("%s/context.xml" % self.__templatedir, "r") as f:
         context_config = f.read() % {
             'dbhost': dbhost,
             'dbuser': dbuser,
             'dbpass': dbpass,
             'jndi': jndi
         }
     return Statements.createOrOverwriteFile(
         "/etc/tomcat6/Catalina/localhost/%s.xml" % module,
         [context_config])
コード例 #21
0
ファイル: rabbitmq.py プロジェクト: nacx/kahuna
def reset():
    """ Resets a RabbitMQ instance """
    return [Statements.exec("rabbitmqctl stop_app"),
        Statements.exec("rabbitmqctl reset"),
        Statements.exec("rabbitmqctl start_app")]
コード例 #22
0
ファイル: jenkins.py プロジェクト: ssedano/kahuna
def _download_script(version, file_name, destination="/tmp"):
    """ Downloads the given script from Jenkins """
    return Statements.exec("wget -O %s/%s %s/%s/scripts/%s" %
        (destination, file_name, JENKINS, version, file_name))
コード例 #23
0
 def stop(self):
     """ Generates the stop command """
     return Statements.exec("service tomcat6 stop")
コード例 #24
0
ファイル: jenkins.py プロジェクト: ssedano/kahuna
def _download_database(version, destination="/tmp"):
    """ Downloads the given database from Jenkins """
    return Statements.exec("wget -O %s/kinton-schema-%s.sql "
        "%s/%s/database/kinton-schema.sql" %
        (destination, version, JENKINS, version))
コード例 #25
0
def install():
    """ Downloads and installs the NTP daemon """
    return Statements.exec("ensure_cmd_or_install_package_apt ntpd ntp")
コード例 #26
0
def _download_database(version, destination="/tmp"):
    """ Downloads the given database from Jenkins """
    return Statements.exec("wget -O %s/kinton-schema-%s.sql "
        "%s/%s/database/kinton-schema.sql" %
        (destination, version, JENKINS, version))
コード例 #27
0
ファイル: redis.py プロジェクト: nacx/kahuna
def install(version):
    """ Downloads and installs redis """
    script = []
    script.append(Statements.exec("ensure_netutils_apt"))
    script.append(Statements.exec(
        "ensure_cmd_or_install_package_apt make build-essential"))
    script.append(Statements.extractTargzAndFlattenIntoDirectory(
        URI.create("http://redis.googlecode.com/files/redis-%s.tar.gz" %
            version),
        "/usr/local/src/redis"))
    script.append(Statements.exec(
        "(cd /usr/local/src/redis && make && make install)"))
    script.append(Statements.exec("{md} /var/lib/redis"))
    script.append(Statements.exec(
        "sed -i 's/^daemonize no/daemonize yes/' "
        "/usr/local/src/redis/redis.conf"))
    script.append(Statements.exec(
        "sed -i 's/^logfile .*/logfile \/var\/log\/redis.log/' "
        "/usr/local/src/redis/redis.conf"))
    script.append(Statements.exec(
        "sed -i 's/^dbfilename .*/dbfilename redis.rdb/' "
        "/usr/local/src/redis/redis.conf"))
    script.append(Statements.exec(
        "sed -i 's/^dir .*/dir \/var\/lib\/redis/' "
        "/usr/local/src/redis/redis.conf"))
    script.append(Statements.appendFile("/etc/sysctl.conf",
        ["vm.overcommit_memory = 1"]))
    script.append(Statements.exec("sysctl vm.overcommit_memory=1"))
    script.append(Statements.exec(
        "/usr/local/bin/redis-server /usr/local/src/redis/redis.conf"))
    return script
コード例 #28
0
    def deploy_abiquo(self, args):
        """ Deploys and configures an Abiquo platform """
        parser = OptionParser(usage="mothership deploy-abiquo <options>")
        parser.add_option('-t', '--template-id',
                help='The id of the template to deploy',
                action='store', dest='template')
        parser.add_option('-p', '--properties',
                help='Path to the abiquo.properties file to use',
                action='store', dest='props')
        parser.add_option('-j', '--jenkins-version',
                help='Download the given version of the wars from Jenkins',
                action='store', dest='jenkins')
        (options, args) = parser.parse_args(args)

        if not options.template or not options.props:
            parser.print_help()
            return

        compute = self._context.getComputeService()

        try:
            log.info("Loading template...")
            vdc, template_options = self._template_options(compute,
                    "deploy-abiquo")
            template = compute.templateBuilder() \
                .imageId(options.template) \
                .locationId(vdc.getId()) \
                .options(template_options) \
                .build()

            log.info("Deploying %s to %s..." % (template.getImage().getName(),
                vdc.getDescription()))
            node = Iterables.getOnlyElement(
                compute.createNodesInGroup("kahuna-abiquo", 1, template))

            log.info("Created %s at %s" % (node.getName(),
                Iterables.getOnlyElement(node.getPublicAddresses())))

            # Generate the bootstrap script
            bootstrap = []
            bootstrap.append(Statements.exec("service abiquo-tomcat stop"))

            with open(options.props, "r") as f:
                bootstrap.append(Statements.createOrOverwriteFile(
                    "/opt/abiquo/config/abiquo.properties", [f.read()]))

            with open("%s/configure-abiquo.sh" % self.__scriptdir, "r") as f:
                bootstrap.append(Statements.exec(f.read()))

            if options.jenkins:
                with open("%s/configure-from-jenkins.sh" %
                        self.__scriptdir, "r") as f:
                    jenkins_script = f.read() % {'version': options.jenkins}
                bootstrap.append(Statements.exec(jenkins_script))

            bootstrap.append(Statements.exec("service abiquo-tomcat start"))

            log.info("Configuring node with the given properties...")
            compute.runScriptOnNode(node.getId(), StatementList(bootstrap))

            log.info("Done! Abiquo configured at: %s" %
                    Iterables.getOnlyElement(node.getPublicAddresses()))

        except RunNodesException, ex:
            self._print_node_errors(ex)
コード例 #29
0
ファイル: tomcat.py プロジェクト: nacx/kahuna
 def configure_abiquo_listener(self):
     """ Adds the Abiquo listener to server.xml """
     return Statements.exec("sed -i -e "
         "'/GlobalResourcesLifecycleListener/a <Listener className="
         "\"com.abiquo.listeners.AbiquoConfigurationListener\"/>' "
         "/etc/tomcat6/server.xml")
コード例 #30
0
def install(version):
    """ Downloads and installs redis """
    script = []
    script.append(Statements.exec("ensure_netutils_apt"))
    script.append(
        Statements.exec(
            "ensure_cmd_or_install_package_apt make build-essential"))
    script.append(
        Statements.extractTargzAndFlattenIntoDirectory(
            URI.create("http://redis.googlecode.com/files/redis-%s.tar.gz" %
                       version), "/usr/local/src/redis"))
    script.append(
        Statements.exec("(cd /usr/local/src/redis && make && make install)"))
    script.append(Statements.exec("{md} /var/lib/redis"))
    script.append(
        Statements.exec("sed -i 's/^daemonize no/daemonize yes/' "
                        "/usr/local/src/redis/redis.conf"))
    script.append(
        Statements.exec(
            "sed -i 's/^logfile .*/logfile \/var\/log\/redis.log/' "
            "/usr/local/src/redis/redis.conf"))
    script.append(
        Statements.exec("sed -i 's/^dbfilename .*/dbfilename redis.rdb/' "
                        "/usr/local/src/redis/redis.conf"))
    script.append(
        Statements.exec("sed -i 's/^dir .*/dir \/var\/lib\/redis/' "
                        "/usr/local/src/redis/redis.conf"))
    script.append(
        Statements.appendFile("/etc/sysctl.conf",
                              ["vm.overcommit_memory = 1"]))
    script.append(Statements.exec("sysctl vm.overcommit_memory=1"))
    script.append(
        Statements.exec(
            "/usr/local/bin/redis-server /usr/local/src/redis/redis.conf"))
    return script
コード例 #31
0
ファイル: redis.py プロジェクト: nacx/kahuna
def run(command):
    """ Runs the given Redis command """
    return Statements.exec("redis-cli %s" % command)
コード例 #32
0
def _download_script(version, file_name, destination="/tmp"):
    """ Downloads the given script from Jenkins """
    return Statements.exec("wget -O %s/%s %s/%s/scripts/%s" %
        (destination, file_name, JENKINS, version, file_name))
コード例 #33
0
ファイル: ntp.py プロジェクト: nacx/kahuna
def install():
    """ Downloads and installs the NTP daemon """
    return Statements.exec(
        "ensure_cmd_or_install_package_apt ntpd ntp")
コード例 #34
0
def run(command):
    """ Runs the given Redis command """
    return Statements.exec("redis-cli %s" % command)