Пример #1
0
    def deploy_chef(self, args):
        """ Deploys and configures a Chef Server """
        compute = self._context.getComputeService()

        try:
            name = self.__config.get("deploy-chef", "template")
            log.info("Loading template...")
            options = self._template_options(compute, "deploy-chef")
            template = compute.templateBuilder() \
                    .imageNameMatches(name) \
                    .options(options.blockOnPort(4000, 90)) \
                    .build()

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

            cookbooks = self.__config.get("deploy-chef", "cookbooks")
            with open(self.__scriptdir + "/configure-chef.sh", "r") as f:
                script = f.read() % {'cookbooks': cookbooks}

            log.info("Configuring node with cookbooks: %s..." % cookbooks)
            compute.runScriptOnNode(node.getId(), script)

            log.info("Chef Server configured!")
            log.info("You can access the admin console at: http://%s:4040"
                    % Iterables.getOnlyElement(node.getPrivateAddresses()))

            log.info("These are the certificates to access the API:")
            self._print_node_file(self._context, node,
                    "/etc/chef/validation.pem")
            self._print_node_file(self._context, node, "/etc/chef/webui.pem")

        except RunNodesException, ex:
            self._print_node_errors(ex)
    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)
    def deploy_chef(self, args):
        """ Deploys and configures a Chef Server """
        compute = self._context.getComputeService()

        try:
            name = self.__config.get("deploy-chef", "template")
            log.info("Loading template...")
            vdc, options = self._template_options(compute, "deploy-chef")
            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("kahuna-chef-%s" % identity,
                    1, template))

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

            cookbooks = self.__config.get("deploy-chef", "cookbooks")
            with open("%s/configure-chef.sh" % self.__scriptdir, "r") as f:
                script = f.read() % {'cookbooks': cookbooks}

            log.info("Configuring node with cookbooks: %s..." % cookbooks)
            compute.runScriptOnNode(node.getId(), script)

            log.info("Done! You can access the admin console at: "
                    "http://%s:4040"
                    % Iterables.getOnlyElement(node.getPublicAddresses()))

            log.info("These are the certificates to access the API:")
            webui = ssh.get(self._context, node, "/etc/chef/webui.pem")
            log.info("webui.pem: %s", webui)
            validator = ssh.get(self._context, node,
                "/etc/chef/validation.pem")
            log.info("validation.pem: %s" % validator)

        except RunNodesException, ex:
            self._print_node_errors(ex)
Пример #4
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...")
            options = self._template_options(compute, config_section)
            template = compute.templateBuilder() \
                    .imageNameMatches(name) \
                    .options(options) \
                    .build()

            log.info("Deploying %s..." % template.getImage().getName())
            node = Iterables.getOnlyElement(
                    compute.createNodesInGroup(vapp_name, 1, template))

            # 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")

            # abiquo-aim.ini
            self._complete_file("abiquo-aim.ini", {'redishost': redishost,
                'redisport': redisport, 'nfsto': nfsto})
            self._upload_file_node(self._context, node, "/etc/",
                    "abiquo-aim.ini")

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

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

            log.info("Node configured!")
            log.info("You can access it at: ssh://%s" %
                    Iterables.getOnlyElement(node.getPrivateAddresses()))

        except RunNodesException, ex:
            self._print_node_errors(ex)
Пример #5
0
 def applyAmbiguities(cls, originalRule, ambiguitiesByOriginalForm, model):
     """ generated source for method applyAmbiguities """
     rules = Lists.newArrayList(originalRule)
     # Each literal can potentially multiply the number of rules we have, so
     # we apply each literal separately to the entire list of rules so far.
     for literal in Iterables.concat(ImmutableSet.of(originalRule.getHead()), originalRule.getBody()):
         for rule in rules:
             Preconditions.checkArgument(originalRule.arity() == rule.arity())
             newRules.addAll(applyAmbiguitiesForLiteral(literal, rule, ambiguitiesByOriginalForm, model))
         rules = newRules
     return rules
Пример #6
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')
        (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...")
            template_options = self._template_options(compute, "deploy-abiquo")
            template = compute.templateBuilder() \
                    .imageId(options.template) \
                    .options(template_options) \
                    .build()

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

            self._upload_file_node(self._context, node, "/opt/abiquo/config",
                    options.props, True)

            log.info("Restarting Abiquo Tomcat...")
            compute.runScriptOnNode(node.getId(),
                    "service abiquo-tomcat restart")

            log.info("Abiquo configured at: %s" %
                    Iterables.getOnlyElement(node.getPrivateAddresses()))

        except RunNodesException, ex:
            self._print_node_errors(ex)
Пример #7
0
 def mergeStrata(cls, toMerge, toAdd, strataDependencyGraph):
     """ generated source for method mergeStrata """
     newStratum = ImmutableSet.copyOf(Iterables.concat(toMerge))
     for oldStratum in toMerge:
         toAdd.remove(oldStratum)
     toAdd.add(newStratum)
     # Change the keys
     for oldStratum in toMerge:
         strataDependencyGraph.putAll(newStratum, parents)
         strataDependencyGraph.removeAll(oldStratum)
     # Change the values
     for entry in ImmutableList.copyOf(strataDependencyGraph.entries()):
         if toMerge.contains(entry.getValue()):
             strataDependencyGraph.remove(entry.getKey(), entry.getValue())
             strataDependencyGraph.put(entry.getKey(), newStratum)
Пример #8
0
 def removeUnreachableBasesAndInputs(cls, pn, basesTrueByInit):
     """ generated source for method removeUnreachableBasesAndInputs """
     reachability = Maps.newHashMap()
     numTrueInputs = HashMultiset.create()
     numFalseInputs = HashMultiset.create()
     toAdd = Stack()
     legalsToInputs = Maps.newHashMap()
     for legalProp in Iterables.concat(pn.getLegalPropositions().values()):
         if inputProp != None:
             legalsToInputs.put(legalProp, inputProp)
     for c in pn.getComponents():
         ConcurrencyUtils.checkForInterruption()
         if isinstance(c, (Constant, )):
             if c.getValue():
                 toAdd.add(Pair.of(c, cls.Type.TRUE))
             else:
                 toAdd.add(Pair.of(c, cls.Type.FALSE))
     for p in pn.getInputPropositions().values():
         toAdd.add(Pair.of(p, cls.Type.FALSE))
     for baseProp in pn.getBasePropositions().values():
         if basesTrueByInit.contains(baseProp):
             toAdd.add(Pair.of(baseProp, cls.Type.TRUE))
         else:
             toAdd.add(Pair.of(baseProp, cls.Type.FALSE))
     initProposition = pn.getInitProposition()
     toAdd.add(Pair.of(initProposition, cls.Type.BOTH))
     while not toAdd.isEmpty():
         ConcurrencyUtils.checkForInterruption()
         if oldType == None:
             oldType = cls.Type.NEITHER
         if isinstance(curComp, (Proposition, )):
             typeToAdd = newInputType
         elif isinstance(curComp, (Transition, )):
             typeToAdd = newInputType
         elif isinstance(curComp, (Constant, )):
             typeToAdd = newInputType
         elif isinstance(curComp, (Not, )):
             typeToAdd = newInputType.opposite()
         elif isinstance(curComp, (And, )):
             if newInputType.hasTrue:
                 numTrueInputs.add(curComp)
                 if numTrueInputs.count(curComp) == curComp.getInputs().size():
                     typeToAdd = cls.Type.TRUE
             if newInputType.hasFalse:
                 typeToAdd = typeToAdd.with_(cls.Type.FALSE)
         elif isinstance(curComp, (Or, )):
             if newInputType.hasFalse:
                 numFalseInputs.add(curComp)
                 if numFalseInputs.count(curComp) == curComp.getInputs().size():
                     typeToAdd = cls.Type.FALSE
             if newInputType.hasTrue:
                 typeToAdd = typeToAdd.with_(cls.Type.TRUE)
         else:
             raise RuntimeException("Unhandled component type " + curComp.__class__)
         if oldType.includes(typeToAdd):
             continue 
         reachability.put(curComp, typeToAdd.with_(oldType))
         typeToAdd = typeToAdd.minus(oldType)
         if typeToAdd == cls.Type.NEITHER:
             raise RuntimeException("Something's messed up here")
         for output in curComp.getOutputs():
             toAdd.add(Pair.of(output, typeToAdd))
         if legalsToInputs.containsKey(curComp):
             if inputProp == None:
                 raise IllegalStateException()
             toAdd.add(Pair.of(inputProp, typeToAdd))
     trueConst = Constant(True)
     falseConst = Constant(False)
     pn.addComponent(trueConst)
     pn.addComponent(falseConst)
     for entry in reachability.entrySet():
         if type_ == cls.Type.TRUE or type_ == cls.Type.FALSE:
             if isinstance(c, (Constant, )):
                 continue 
             for input in c.getInputs():
                 input.removeOutput(c)
             c.removeAllInputs()
             if type_ == cls.Type.TRUE ^ (isinstance(c, (Not, ))):
                 c.addInput(trueConst)
                 trueConst.addOutput(c)
             else:
                 c.addInput(falseConst)
                 falseConst.addOutput(c)
     cls.optimizeAwayTrueAndFalse(pn, trueConst, falseConst)
Пример #9
0
    def deploy_rs(self, args):
        """ Deploys and configures custom Abiquo Remote Services """
        parser = OptionParser(usage="scalability deploy-rs <options>")
        parser.add_option('-j', '--jenkins-version',
                help='Download the given version of the wars from Jenkins',
                action='store', dest='jenkins')
        parser.add_option('-r', '--rabbit', help='The RabbitMQ host',
                action='store', dest='rabbit')
        parser.add_option('-n', '--nfs', help='The NFS to mount',
                action='store', dest='nfs')
        parser.add_option('-c', '--count', type="int", default=1,
                help='Number of nodes to deploy (default 1)',
                action='store', dest='count')
        parser.add_option('-s', '--hypervisor-sessions', type="int", default=2,
                help='Number of concurrent hypervisor sessions (default 2)',
                action='store', dest='hypervisorsessions')
        parser.add_option('-l', '--list', help='Upload only those wars (default all rs)',
                default='rs', action='store', dest='wars')
        (options, args) = parser.parse_args(args)

        if not options.jenkins or not options.nfs or not options.rabbit:
            parser.print_help()
            return

        compute = self._context.getComputeService()

        try:
            name = self.__config.get("deploy-rs", "template")
            log.info("Loading template...")
            vdc, template_options = self._template_options(compute,
                "deploy-rs")
            template_options.overrideCores(
                self.__config.getint("deploy-rs", "template_cores"))
            template_options.overrideRam(
                self.__config.getint("deploy-rs", "template_ram"))
            template = compute.templateBuilder() \
                .imageNameMatches(name) \
                .locationId(vdc.getId()) \
                .options(template_options) \
                .build()

            java_opts = self.__config.get("deploy-rs", "tomcat_opts")
            boundary_org = self.__config.get("deploy-rs", "boundary_org")
            boundary_key = self.__config.get("deploy-rs", "boundary_key")
            newrelic_key = self.__config.get("deploy-rs", "newrelic_key")
            tomcat = TomcatScripts(boundary_org, boundary_key, newrelic_key)

            log.info("Deploying %s %s nodes to %s..." % (options.count,
                template.getImage().getName(), vdc.getDescription()))

            # Due to the IpPoolManagement concurrency issue, we need to deploy
            # the nodes one by one
            nodes = []
            responses = []
            for i in xrange(options.count):
                node = Iterables.getOnlyElement(
                    compute.createNodesInGroup("kahuna-rs", 1, template))
                log.info("Created node %s at %s" % (node.getName(),
                    Iterables.getOnlyElement(node.getPublicAddresses())))
                nodes.append(node)

                log.info("Cooking %s with Chef in the background..." %
                    node.getName())
                tomcat_config = {
                    "rabbit": options.rabbit,
                    "datacenter": node.getName(),
                    "nfs": options.nfs,
                    "nfs-mount": True,
                    "java-opts": java_opts,
                    "hypervisor-sessions": options.hypervisorsessions
                }
                install_tomcat = tomcat.install_and_configure(node,
                    tomcat_config, self._install_jenkins_wars(options.jenkins, options.wars))
                bootstrap = hostname.configure(node) + \
                    [ntp.install()] + redis.install("2.6.4") + install_tomcat
                responses.append(compute.submitScriptOnNode(node.getId(),
                    StatementList(bootstrap), RunScriptOptions.NONE))

            log.info("Waiting until all nodes are configured...")
            for i, future in enumerate(responses):
                result = future.get()
                log.info("%s node at %s -> %s" % (nodes[i].getName(),
                    Iterables.getOnlyElement(nodes[i].getPublicAddresses()),
                    "OK" if result.getExitStatus() == 0 else "FAILED"))
            log.info("Done!")

        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
Пример #10
0
    def deploy_api(self, args):
        """ Deploys and configures custom Abiquo APIs """
        parser = OptionParser(usage="scalability deploy-api <options>")
        parser.add_option('-f', '--file',
                help='Path to a local api file to deploy',
                action='store', dest='file')
        parser.add_option('-j', '--jenkins-version',
                help='Download the api 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('-b', '--balancer',
                help='Ip address of the load balancer node',
                action='store', dest='balancer')
        parser.add_option('-c', '--count', type="int", default=1,
                help='Number of nodes to deploy (default 1)',
                action='store', dest='count')
        (options, args) = parser.parse_args(args)

        if options.file and options.jenkins:
            print "Cannot use -f and -j together"
            parser.print_help()
            return

        if not options.file and not options.jenkins \
                or not options.datanode or not options.balancer:
            parser.print_help()
            return

        compute = self._context.getComputeService()

        try:
            name = self.__config.get("deploy-api", "template")
            log.info("Loading template...")
            vdc, template_options = self._template_options(compute,
                "deploy-api")
            template_options.overrideCores(
                self.__config.getint("deploy-api", "template_cores"))
            template_options.overrideRam(
                self.__config.getint("deploy-api", "template_ram"))
            template = compute.templateBuilder() \
                .imageNameMatches(name) \
                .locationId(vdc.getId()) \
                .options(template_options) \
                .build()

            java_opts = self.__config.get("deploy-api", "tomcat_opts")
            boundary_org = self.__config.get("deploy-api", "boundary_org")
            boundary_key = self.__config.get("deploy-api", "boundary_key")
            newrelic_key = self.__config.get("deploy-api", "newrelic_key")
            tomcat = TomcatScripts(boundary_org, boundary_key, newrelic_key)

            log.info("Deploying %s %s nodes to %s..." % (options.count,
                template.getImage().getName(), vdc.getDescription()))

            # Due to the IpPoolManagement concurrency issue, we need to deploy
            # the nodes one by one
            nodes = []
            responses = []
            for i in xrange(options.count):
                node = Iterables.getOnlyElement(
                    compute.createNodesInGroup("kahuna-api", 1, template))
                log.info("Created node %s at %s" % (node.getName(),
                    Iterables.getOnlyElement(node.getPublicAddresses())))
                if options.file:
                    ssh.upload(self._context, node, "/tmp", options.file)
                nodes.append(node)

                log.info("Cooking %s with Chef in the background..." %
                    node.getName())
                tomcat_config = {
                    "rabbit": options.datanode,
                    "redis": options.datanode,
                    "zookeeper": options.datanode,
                    "module": "api",
                    "db-host": options.datanode,
                    #"syslog": options.balancer,
                    "ajp_port": 10000 + i,
                    "java-opts": java_opts
                }
                bootstrap = []
                bootstrap.extend(hostname.configure(node))
                bootstrap.append(ntp.install())
                if options.jenkins:
                    bootstrap.extend(jenkins._download_war(
                        options.jenkins, "api"))
                bootstrap.extend(tomcat.install_and_configure(node,
                    tomcat_config, self._install_local_wars))
                responses.append(compute.submitScriptOnNode(node.getId(),
                    StatementList(bootstrap), RunScriptOptions.NONE))

            log.info("Waiting until all nodes are configured...")
            for i, future in enumerate(responses):
                result = future.get()
                log.info("%s node at %s -> %s" % (nodes[i].getName(),
                    Iterables.getOnlyElement(nodes[i].getPublicAddresses()),
                    "OK" if result.getExitStatus() == 0 else "FAILED"))
            log.info("Done!")

        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()
Пример #11
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)
Пример #12
0
 def getSentences(cls, rule, includeHead):
     """ generated source for method getSentences """
     if includeHead == cls.VarDomainOpts.INCLUDE_HEAD:
         return Iterables.concat(ImmutableList.of(rule.getHead()), rule.getBody())
     else:
         return rule.getBody()
Пример #13
0
 def getRules(cls, description):
     """ generated source for method getRules """
     return Iterables.transform(Iterables.filter(description, Predicate()), Function())
Пример #14
0
 def getPositiveConjuncts(cls, body):
     """ generated source for method getPositiveConjuncts """
     return Iterables.transform(Iterables.filter(body, Predicate()), Function())