Exemplo n.º 1
0
    def test_12__tweak_options__site(self):
        p = TT.option_parser()
        (options, _) = p.parse_args([])

        defaults = TT.M_DEFAULTS_POST

        self.assertEquals(options.site, None)
        options = TT.tweak_options(options)
        self.assertEquals(options.site, defaults["site"])

        (options, _) = p.parse_args(["--site", "foo"])
        options = TT.tweak_options(options)
        self.assertEquals(options.site, "foo")
Exemplo n.º 2
0
def build(argv):
    """
    Configure and build files.
    """
    defaults = dict(build=True, genconf=True, **MO.M_DEFAULTS)

    p = MO.option_parser(defaults)
    p.add_option("--no-build", action="store_false", dest="build",
                 help="Do not build, generate ks.cfg, vm build scripts, etc.")
    p.add_option("--no-genconf", action="store_false", dest="genconf",
                 help="Do not generate config from context files")
    (options, args) = p.parse_args(argv)

    miniascape.globals.set_loglevel(options.verbose)
    options = MO.tweak_options(options)

    # suppress logs from anyconfig unless the environment variable
    # 'ANYCONFIG_DEBUG' is set to 1.
    if os.environ.get("ANYCONFIG_DEBUG", None) != '1':
        anyconfig.set_loglevel(logging.WARN)

    # configure
    if options.genconf:
        confdir = miniascape.site.configure(options.ctxs, options.tmpldir,
                                            options.workdir, options.site)

    if not options.build:
        return

    # ... and build (generate all).
    cf = miniascape.config.ConfFiles(confdir)

    miniascape.host.gen_host_files(cf, options.tmpldir, options.workdir, True)
    miniascape.guest.gen_all(cf, options.tmpldir, options.workdir)
Exemplo n.º 3
0
    def test_14__tweak_options__ctx(self):
        p = TT.option_parser()
        (options, _) = p.parse_args(["--ctx", "/tmp/foo"])

        # defaults = TT.M_DEFAULTS_POST

        options = TT.tweak_options(options)
        self.assertEquals(options.site, None)
        self.assertEquals(options.ctxs, ["/tmp/foo"])
Exemplo n.º 4
0
def main(argv):
    p = option_parser()
    (options, args) = p.parse_args(argv[1:])

    set_loglevel(options.verbose)
    options = O.tweak_options(options)

    bootstrap(options.site, options.workdir, options.site_template,
              tpaths=options.tmpldir)
Exemplo n.º 5
0
def main(argv):
    p = option_parser()
    (options, args) = p.parse_args(argv[1:])

    set_loglevel(options.verbose)
    options = O.tweak_options(options)

    bootstrap(options.site,
              options.workdir,
              options.site_template,
              tpaths=options.tmpldir)
Exemplo n.º 6
0
def main(argv):
    p = option_parser()
    (options, args) = p.parse_args(argv[1:])

    G.set_loglevel(options.verbose)
    options = O.tweak_options(options)

    cf = miniascape.config.ConfFiles(options.confdir)

    houtdir = os.path.join(options.workdir, G.M_HOST_CONF_SUBDIR)
    if os.path.exists(houtdir) and not options.force:
        yesno = raw_input("Are you sure to generate networks in {} ? "
                          "[y/n]: ".format(options.workdir))
        if not yesno.strip().lower().startswith('y'):
            print("Cancel creation of networks...")
            sys.exit(0)

        options.force = True

    gen_host_files(cf, options.tmpldir, options.workdir, options.force)
Exemplo n.º 7
0
def main(argv):
    p = option_parser()
    (options, args) = p.parse_args(argv[1:])

    G.set_loglevel(options.verbose)
    options = O.tweak_options(options)

    cf = miniascape.config.ConfFiles(options.confdir)

    houtdir = os.path.join(options.workdir, G.M_HOST_CONF_SUBDIR)
    if os.path.exists(houtdir) and not options.force:
        yesno = raw_input("Are you sure to generate networks in {} ? "
                          "[y/n]: ".format(options.workdir))
        if not yesno.strip().lower().startswith('y'):
            print("Cancel creation of networks...")
            sys.exit(0)

        options.force = True

    gen_host_files(cf, options.tmpldir, options.workdir, options.force)
Exemplo n.º 8
0
    def test_10__tweak_options__tmpldir(self):
        p = TT.option_parser()
        (options, _) = p.parse_args([])

        self.assertEquals(options.tmpldir, [])

        # It seems that optparse holds option values permanently so value of
        # options.tmpldir will be same even if p and options (returned from
        # p.parse_args) are re-newed:
        # options = TT.tweak_options(options)
        # self.assertEquals(options.tmpldir, [G.M_TMPL_DIR])

        (options, _) = p.parse_args(["--tmpldir", "/tmp"])

        self.assertNotEquals(options.tmpldir, [])
        self.assertEquals(options.tmpldir, ["/tmp"])

        defaults = TT.M_DEFAULTS_POST
        options = TT.tweak_options(options)

        self.assertEquals(options.tmpldir, ["/tmp", defaults["tmpldir"]])
        self.assertEquals(options.ctxs, [G.site_src_ctx()])