示例#1
0
def main():
    opts = parse_options(sys.argv[1:])

    config = Config('bundle-placer', opts.__dict__)
    config.save()

    setup_logger(cfg_path=config.cfg_path)
    log = logging.getLogger('bundleplacer')
    log.debug(opts.__dict__)

    log.info("Editing file: {}".format(opts.bundle_filename))

    if opts.maas_ip and opts.maas_cred:
        creds = dict(api_host=opts.maas_ip,
                     api_key=opts.maas_cred)
        maas, maas_state = connect_to_maas(creds)
    else:
        maas_state = FakeMaasState()

    placement_controller = PlacementController(config=config,
                                               maas_state=maas_state)

    mainview = PlacerView(placement_controller, config)
    ui = PlacerUI(mainview)

    def unhandled_input(key):
        if key in ['q', 'Q']:
            raise urwid.ExitMainLoop()
    EventLoop.build_loop(ui, STYLES, unhandled_input=unhandled_input)
    mainview.loop = EventLoop.loop
    mainview.update()
    EventLoop.run()
示例#2
0
 def render(self):
     # TODO: demo specific should be changed afterwards
     if self.provider.name == "maas":
         DEMO_BUNDLE = os.path.join(
             Config.share_path(), "data-analytics-with-sql-like.yaml")
         DEMO_METADATA = os.path.join(
             Config.share_path(),
             "data-analytics-with-sql-like-metadata.yaml")
         bundleplacer_cfg = Config('bundle-placer',
                                   {'bundle_filename': DEMO_BUNDLE,
                                    'metadata_filename': DEMO_METADATA})
         placement_controller = PlacementController(
             config=bundleplacer_cfg,
             maas_state=FakeMaasState())
         mainview = PlacerView(placement_controller,
                               bundleplacer_cfg)
         self.common['ui'].set_header(
             title="Bundle Editor: {}".format(
                 self.common['config']['summary']),
             excerpt="Choose where your services should be "
             "placed in your available infrastructure"
         )
         self.common['ui'].set_subheader("Machine Placement")
         self.common['ui'].set_body(mainview)
         mainview.update()
示例#3
0
 def render(self):
     # TODO: demo specific should be changed afterwards
     if self.provider.name == "maas":
         DEMO_BUNDLE = os.path.join(Config.share_path(),
                                    "data-analytics-with-sql-like.yaml")
         DEMO_METADATA = os.path.join(
             Config.share_path(),
             "data-analytics-with-sql-like-metadata.yaml")
         bundleplacer_cfg = Config('bundle-placer', {
             'bundle_filename': DEMO_BUNDLE,
             'metadata_filename': DEMO_METADATA
         })
         placement_controller = PlacementController(
             config=bundleplacer_cfg, maas_state=FakeMaasState())
         mainview = PlacerView(placement_controller, bundleplacer_cfg)
         self.common['ui'].set_header(
             title="Bundle Editor: {}".format(
                 self.common['config']['summary']),
             excerpt="Choose where your services should be "
             "placed in your available infrastructure")
         self.common['ui'].set_subheader("Machine Placement")
         self.common['ui'].set_body(mainview)
         mainview.update()
示例#4
0
文件: cli.py 项目: johnsca/conjure-up
def main():
    if os.getenv("BUNDLE_EDITOR_TESTING"):
        test_args = True
    else:
        test_args = False

    opts = parse_options(sys.argv[1:], test_args)

    config = Config('bundle-placer', opts.__dict__)
    config.save()

    setup_logger(cfg_path=config.cfg_path)
    log = logging.getLogger('bundleplacer')
    log.debug(opts.__dict__)

    log.info("Editing file: {}".format(opts.bundle_filename))

    if opts.maas_ip and opts.maas_cred:
        creds = dict(api_host=opts.maas_ip,
                     api_key=opts.maas_cred)
        maas, maas_state = connect_to_maas(creds)
    elif 'fake_maas' in opts and opts.fake_maas:
        maas = None
        maas_state = FakeMaasState()
    else:
        maas = None
        maas_state = None

    try:
        placement_controller = PlacementController(config=config,
                                                   maas_state=maas_state)
    except Exception as e:
        print("Error: " + e.args[0])
        return

    def cb():
        if maas:
            maas.tag_name(maas.nodes)

        bw = BundleWriter(placement_controller)
        if opts.out_filename:
            outfn = opts.out_filename
        else:
            outfn = opts.bundle_filename
            if os.path.exists(outfn):
                shutil.copy2(outfn, outfn + '~')
        bw.write_bundle(outfn)
        async.shutdown()
        raise urwid.ExitMainLoop()

    has_maas = (maas_state is not None)
    mainview = PlacerView(placement_controller, config, cb, has_maas=has_maas)
    ui = PlacerUI(mainview)

    def unhandled_input(key):
        if key in ['q', 'Q']:
            async.shutdown()
            raise urwid.ExitMainLoop()
    EventLoop.build_loop(ui, STYLES, unhandled_input=unhandled_input)
    mainview.loop = EventLoop.loop
    mainview.update()
    EventLoop.run()