예제 #1
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])
예제 #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 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
예제 #4
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])
    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)
예제 #6
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
예제 #7
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)