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()
def initialize(self): """Authenticates against juju/maas and sets up placement controller.""" if getenv("FAKE_API_DATA"): self.juju_state = FakeJujuState() self.maas_state = FakeMaasState() else: self.authenticate_juju() if self.config.is_multi(): creds = self.config.getopt('maascreds') self.maas, self.maas_state = connect_to_maas(creds) self.placement_controller = PlacementController( self.maas_state, self.config) if path.exists(self.config.placements_filename): with open(self.config.placements_filename, 'r') as pf: self.placement_controller.load(pf) self.ui.status_info_message("Loaded placements from file.") log.info("Loaded placements from " "'{}'".format(self.config.placements_filename)) # If we have no machines (so we are a fresh install) but # are reading a placements.yaml from a previous install, # so it has no assignments, only deployments, tell the # controller to use the deployments in the file as # assignments: if len(self.placement_controller.machines_pending()) == 0 and \ len(self.juju_state.machines()) == 0: self.placement_controller.set_assignments_from_deployments() log.info("Using deployments saved from previous install" " as new assignments.") else: if self.config.is_multi(): def_assignments = self.placement_controller.gen_defaults() else: def_assignments = self.placement_controller.gen_single() self.placement_controller.set_all_assignments(def_assignments) pfn = self.config.placements_filename self.placement_controller.set_autosave_filename(pfn) self.placement_controller.do_autosave() if self.config.is_single(): if self.config.getopt('headless'): self.begin_deployment() else: self.begin_deployment_async() return if self.config.getopt('edit_placement') or \ not self.placement_controller.can_deploy(): self.config.setopt( 'current_state', ControllerState.PLACEMENT.value) else: if self.config.getopt('headless'): self.begin_deployment() else: self.begin_deployment_async()
def __init__(self, display_controller, installer, config): self.display_controller = display_controller self.installer = installer self.config = config creds = self.config.getopt('maascreds') if os.getenv("FAKE_API_DATA"): self.maas_client = None self.maas_state = FakeMaasState() else: self.maas_client, self.maas_state = connect_to_maas(creds) self.spinner = Spinner(15, 4) w = self.build_widgets() super().__init__(w) self.update()
def initialize(self): """Authenticates against juju/maas and sets up placement controller.""" if getenv("FAKE_API_DATA"): self.juju_state = FakeJujuState() self.maas_state = FakeMaasState() else: self.authenticate_juju() if self.config.is_multi: creds = self.config.maas_creds self.maas, self.maas_state = connect_to_maas(creds) self.placement_controller = PlacementController( self.maas_state, self.opts) if path.exists(self.config.placements_filename): with open(self.config.placements_filename, 'r') as pf: self.placement_controller.load(pf) self.info_message("Loaded placements from file.") else: if self.config.is_multi: def_assignments = self.placement_controller.gen_defaults() else: def_assignments = self.placement_controller.gen_single() self.placement_controller.set_all_assignments(def_assignments) pfn = self.config.placements_filename self.placement_controller.set_autosave_filename(pfn) self.placement_controller.do_autosave() if self.config.is_single: self.begin_deployment_async() return if self.opts.edit_placement or \ not self.placement_controller.can_deploy(): self.current_state = ControllerState.PLACEMENT else: self.begin_deployment_async()