Esempio n. 1
0
    def build_footer(self):
        cancel = menu_btn(on_press=self.do_cancel,
                          label="\n  BACK\n")
        self.apply_button = menu_btn(on_press=self.do_done,
                                     label="\n DONE\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 13, Color.menu_button(
                cancel,
                focus_map='button_primary focus')),
            Text(""),
            ('fixed', 20, Color.menu_button(
                self.apply_button,
                focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        footer = Pile([
            HR(top=0),
            Padding.line_break(""),
            Color.frame_footer(Pile([
                Padding.line_break(""),
                self.buttons]))
        ])

        return footer
    def build_footer(self):
        cancel = menu_btn(on_press=self.do_cancel,
                          label="\n  BACK\n")
        confirm = menu_btn(on_press=self.do_commit,
                           label="\n APPLY CHANGES\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 13, Color.menu_button(
                cancel,
                focus_map='button_primary focus')),
            Text(""),
            ('fixed', 20, Color.menu_button(
                confirm,
                focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        footer = Pile([
            HR(top=0),
            Padding.center_90(self.description_w),
            Padding.line_break(""),
            Color.frame_footer(Pile([
                Padding.line_break(""),
                self.buttons]))
        ])

        return footer
Esempio n. 3
0
    def _build_widget(self):
        total_items = []
        if len(self.controllers) > 0:
            total_items.append(HR())
            cdict = defaultdict(lambda: defaultdict(list))
            for cname, d in self.controllers.items():
                cdict[d['cloud']][d.get('region', None)].append(cname)

            for cloudname, cloud_d in sorted(cdict.items()):
                total_items.append(Color.label(Text("  {}".format(cloudname))))
                for regionname, controllers in cloud_d.items():
                    for controller in sorted(controllers):
                        label = "    {}".format(controller)
                        if regionname:
                            label += " ({})".format(regionname)
                        total_items.append(
                            Color.body(menu_btn(label=label,
                                                on_press=partial(
                                                    self.submit, controller)),
                                       focus_map='menu_button focus'))
                total_items.append(Padding.line_break(""))
            total_items.append(Padding.line_break(""))
        total_items.append(HR())
        total_items.append(
            Color.body(menu_btn(label="Create New",
                                on_press=self.handle_create_new),
                       focus_map='menu_button focus'))
        return Padding.center_80(Filler(Pile(total_items), valign='top'))
    def _build_widget(self):
        total_items = []
        if len(self.controllers) > 0:
            total_items.append(HR())
            cdict = defaultdict(lambda: defaultdict(list))
            for cname, d in self.controllers.items():
                cdict[d['cloud']][d.get('region', None)].append(cname)

            for cloudname, cloud_d in sorted(cdict.items()):
                total_items.append(Color.label(
                    Text("  {}".format(cloudname))))
                for regionname, controllers in cloud_d.items():
                    for controller in sorted(controllers):
                        label = "    {}".format(controller)
                        if regionname:
                            label += " ({})".format(regionname)
                        total_items.append(
                            Color.body(
                                menu_btn(label=label,
                                         on_press=partial(self.submit,
                                                          controller)),
                                focus_map='menu_button focus'
                            )
                        )
                total_items.append(Padding.line_break(""))
            total_items.append(Padding.line_break(""))
        total_items.append(HR())
        total_items.append(
            Color.body(
                menu_btn(label="Create New",
                         on_press=self.handle_create_new),
                focus_map='menu_button focus'
            )
        )
        return Padding.center_80(Filler(Pile(total_items), valign='top'))
Esempio n. 5
0
    def build_footer(self):
        cancel = menu_btn(on_press=self.do_cancel,
                          label="\n  BACK\n")
        self.apply_button = menu_btn(on_press=self.do_commit,
                                     label="\n APPLY\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 13, Color.menu_button(
                cancel,
                focus_map='button_primary focus')),
            Text(""),
            ('fixed', 20, Color.menu_button(
                self.apply_button,
                focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        footer = Pile([
            HR(top=0),
            Padding.center_90(self.description_w),
            Padding.line_break(""),
            Color.frame_footer(Pile([
                Padding.line_break(""),
                self.buttons]))
        ])

        return footer
Esempio n. 6
0
 def _build_widget(self):
     total_items = []
     if len(self.clouds) > 0:
         total_items.append(Text("Choose a Cloud"))
         total_items.append(HR())
         for item in self.clouds:
             total_items.append(
                 Color.body(
                     menu_btn(label=item,
                              on_press=self.submit),
                     focus_map='menu_button focus'
                 )
             )
         total_items.append(Padding.line_break(""))
     total_items.append(Text("Configure a New Cloud"))
     total_items.append(HR())
     for item in ['localhost', 'maas']:
         total_items.append(
             Color.body(
                 menu_btn(label=item,
                          on_press=self.submit),
                 focus_map='menu_button focus'
             )
         )
     return Padding.center_80(Filler(Pile(total_items), valign='top'))
Esempio n. 7
0
 def _build_widget(self):
     total_items = []
     if len(self.public_clouds) > 0:
         total_items.append(Text("Public Clouds"))
         total_items.append(HR())
         for item in self.public_clouds:
             total_items.append(
                 Color.body(menu_btn(label=item, on_press=self.submit),
                            focus_map='menu_button focus'))
         total_items.append(Padding.line_break(""))
     if len(self.custom_clouds) > 0:
         total_items.append(Text("Your Clouds"))
         total_items.append(HR())
         for item in self.custom_clouds:
             total_items.append(
                 Color.body(menu_btn(label=item, on_press=self.submit),
                            focus_map='menu_button focus'))
         total_items.append(Padding.line_break(""))
     new_clouds = juju.get_compatible_clouds(
         ['localhost', 'maas', 'vsphere'])
     if new_clouds:
         total_items.append(Text("Configure a New Cloud"))
         total_items.append(HR())
         for item in sorted(new_clouds):
             total_items.append(
                 Color.body(menu_btn(label=item, on_press=self.submit),
                            focus_map='menu_button focus'))
     return Padding.center_80(Filler(Pile(total_items), valign='top'))
Esempio n. 8
0
 def _build_buttons(self):
     return Columns([
         ('fixed', 2, Text("")),
         ('fixed', 13,
          Color.menu_button(menu_btn(on_press=self.cancel,
                                     label="\n  QUIT\n"),
                            focus_map='button_primary focus')),
         Text(""),
         ('fixed', 13,
          Color.menu_button(menu_btn(on_press=self.login,
                                     label="\n  LOGIN\n"),
                            focus_map='button_primary focus')),
         ('fixed', 2, Text("")),
     ])
Esempio n. 9
0
    def _build_footer(self):
        no = menu_btn(on_press=self.cancel, label="\n  NO\n")
        yes = menu_btn(on_press=self.submit, label="\n  YES\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 11,
             Color.menu_button(no, focus_map='button_primary focus')),
            Text(""),
            ('fixed', 11,
             Color.menu_button(yes, focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        self.footer = Pile([Padding.line_break(""), self.buttons])
        return Color.frame_footer(self.footer)
Esempio n. 10
0
    def _build_widget(self):
        total_items = []
        for controller in sorted(self.controllers):
            models = self.models[controller]['models']
            if len(models) > 0:
                total_items.append(
                    Color.label(
                        Text("{} ({})".format(controller,
                                              models[0].get('cloud', "")))))
                for model in sorted(models, key=itemgetter('name')):
                    if model['name'] == "controller":
                        continue
                    if model['life'] == 'dying':
                        continue

                    label = "  {}, Machine Count: {}{}".format(
                        model['name'], self._total_machines(model),
                        ", Running since: {}".format(
                            model['status'].get('since'))
                        if 'since' in model['status'] else '')
                    total_items.append(
                        Color.body(menu_btn(label=label,
                                            on_press=partial(
                                                self.submit, controller,
                                                model)),
                                   focus_map='menu_button focus'))
                total_items.append(Padding.line_break(""))
            total_items.append(Padding.line_break(""))
        return Padding.center_80(Filler(Pile(total_items), valign='top'))
Esempio n. 11
0
 def build_menuable_items(self):
     """ Builds a list of bundles available to install
     """
     cols = []
     for bundle in app.bundles:
         bundle_metadata = bundle['Meta']['bundle-metadata']
         try:
             conjure_data = bundle['Meta']['extra-info/conjure-up']
             name = conjure_data.get('friendly-name',
                                     bundle['Meta']['id']['Name'])
         except KeyError:
             name = bundle['Meta']['id']['Name']
         self.fname_id_map[name] = bundle
         cols.append(
             Columns(
                 [
                     ("weight", 0.2, Color.body(
                         menu_btn(label=name,
                                  on_press=self.done),
                         focus_map="menu_button focus")),
                     ("weight", 0.3, Text(
                         bundle_metadata.get('Description',
                                             'Needs a description'),
                         align="left"))
                 ],
                 dividechars=1
             )
         )
         cols.append(Padding.line_break(""))
     return Pile(cols)
Esempio n. 12
0
 def build_widget(self):
     """ Provides a rendered spell widget suitable for pile
     """
     return Color.body(menu_btn(label=self.spell['name'],
                                on_press=self.cb,
                                user_data=self.spell),
                       focus_map='menu_button focus')
Esempio n. 13
0
    def _build_footer(self):
        cancel = menu_btn(on_press=self.cancel, label="\n  BACK\n")
        confirm = menu_btn(on_press=self.submit, label="\n ADD CREDENTIAL\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 13,
             Color.menu_button(cancel, focus_map='button_primary focus')),
            Text(""),
            ('fixed', 20,
             Color.menu_button(confirm, focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        footer = Color.frame_footer(
            Pile([Padding.line_break(""), self.buttons]))
        return footer
Esempio n. 14
0
    def button(self, label, callback):
        """ Build a button for the footer with the given label and callback.

        """
        return ('fixed', len(label) + 8,
                Color.menu_button(menu_btn(on_press=callback,
                                           label="\n  {}\n".format(label)),
                                  focus_map='button_primary focus'))
Esempio n. 15
0
 def _build_widget(self):
     total_items = []
     if len(self.clouds) > 0:
         total_items.append(Text("Choose a Cloud"))
         total_items.append(HR())
         for item in self.clouds:
             total_items.append(
                 Color.body(menu_btn(label=item, on_press=self.submit),
                            focus_map='menu_button focus'))
         total_items.append(Padding.line_break(""))
     total_items.append(Text("Configure a New Cloud"))
     total_items.append(HR())
     for item in ['localhost', 'maas']:
         total_items.append(
             Color.body(menu_btn(label=item, on_press=self.submit),
                        focus_map='menu_button focus'))
     return Padding.center_80(Filler(Pile(total_items), valign='top'))
Esempio n. 16
0
 def _build_buttons(self):
     cancel = menu_btn(on_press=self.cancel, label="\n  QUIT\n")
     buttons = [
         Padding.line_break(""),
         Color.menu_button(cancel, focus_map='button_primary focus'),
     ]
     self.buttons_pile = Pile(buttons)
     return self.buttons_pile
Esempio n. 17
0
    def _build_widget(self):
        if len(self.public_clouds) > 0:
            self._add_item(Text("Public Clouds"))
            self._add_item(HR())
            for item in self.public_clouds:
                self._add_item(
                    Color.body(menu_btn(label=item, on_press=self.submit),
                               focus_map='menu_button focus'))
            self._add_item(Padding.line_break(""))
        if len(self.custom_clouds) > 0:
            self._add_item(Text("Your Clouds"))
            self._add_item(HR())
            for item in self.custom_clouds:
                self._add_item(
                    Color.body(menu_btn(label=item, on_press=self.submit),
                               focus_map='menu_button focus'))
            self._add_item(Padding.line_break(""))
        new_clouds = juju.get_compatible_clouds(
            ['localhost', 'maas', 'vsphere'])
        if new_clouds:
            self._add_item(Text("Configure a New Cloud"))
            self._add_item(HR())
            for item in sorted(new_clouds):
                if item == 'localhost':
                    self._add_item(
                        Color.info_context(menu_btn(
                            label=cloud_types.LOCALHOST, on_press=None),
                                           focus_map='disabled_button'))
                    self._add_item(
                        Color.info_context(
                            Padding.center_90(
                                Text("LXD not found, please install and wait "
                                     "for this message to disappear:\n\n"
                                     "  $ sudo snap install lxd\n"
                                     "  $ /snap/bin/lxd init --auto\n"
                                     "  $ /snap/bin/lxc network create lxdbr0 "
                                     "ipv4.address=auto ipv4.nat=true "
                                     "ipv6.address=none ipv6.nat=false "))))
                else:
                    self._add_item(
                        Color.body(menu_btn(label=item, on_press=self.submit),
                                   focus_map='menu_button focus'))

        self.pile.focus_position = 2
        return self.pile
Esempio n. 18
0
 def __init__(self,
              name,
              cb,
              enabled=True,
              enabled_msg=None,
              disabled_msg=None):
     self.name = name
     self._enabled_widget = Color.body(menu_btn(label=self.name,
                                                on_press=cb),
                                       focus_map='menu_button focus')
     self._disabled_widget = Color.info_context(menu_btn(label=name,
                                                         on_press=None),
                                                focus_map='disabled_button')
     self.enabled_msg = enabled_msg or self.default_enabled_msg
     self.disabled_msg = disabled_msg or self.default_disabled_msg
     self._enabled = enabled
     super().__init__(
         self._enabled_widget if enabled else self._disabled_widget)
Esempio n. 19
0
 def _enable_localhost_widget(self):
     """ Sets the proper widget for localhost availability
     """
     idx = self._get_localhost_widget_idx()
     widget = Color.body(menu_btn(label=cloud_types.LOCALHOST,
                                  on_press=self.submit),
                         focus_map='menu_button focus')
     self._update_pile_at_idx(idx, widget)
     del self.pile.contents[idx + 1]
Esempio n. 20
0
 def _build_buttons(self):
     cancel = menu_btn(on_press=self.cancel,
                       label="\n  QUIT\n")
     buttons = [
         Padding.line_break(""),
         Color.menu_button(cancel,
                           focus_map='button_primary focus'),
     ]
     self.buttons_pile = Pile(buttons)
     return self.buttons_pile
Esempio n. 21
0
    def _build_widget(self):
        if len(self.public_clouds) > 0:
            self._add_item(Text("Public Clouds"))
            self._add_item(HR())
            for item in self.public_clouds:
                self._add_item(
                    Color.body(menu_btn(label=item, on_press=self.submit),
                               focus_map='menu_button focus'))
            self._add_item(Padding.line_break(""))
        if len(self.custom_clouds) > 0:
            self._add_item(Text("Your Clouds"))
            self._add_item(HR())
            for item in self.custom_clouds:
                self._add_item(
                    Color.body(menu_btn(label=item, on_press=self.submit),
                               focus_map='menu_button focus'))
            self._add_item(Padding.line_break(""))
        new_clouds = juju.get_compatible_clouds(
            ['localhost', 'maas', 'vsphere'])
        if new_clouds:
            self._add_item(Text("Configure a New Cloud"))
            self._add_item(HR())
            for item in sorted(new_clouds):
                if item == 'localhost':
                    self._add_item(
                        Color.info_context(menu_btn(
                            label=cloud_types.LOCALHOST, on_press=None),
                                           focus_map='disabled_button'))
                    self._add_item(
                        Color.info_context(
                            Padding.center_90(
                                Text("LXD not found, please install with "
                                     "`sudo snap install lxd && lxd init` "
                                     "and wait for this message to disappear.")
                            )))
                else:
                    self._add_item(
                        Color.body(menu_btn(label=item, on_press=self.submit),
                                   focus_map='menu_button focus'))

        self.pile.focus_position = 2
        return self.pile
Esempio n. 22
0
 def _build_widget(self):
     total_items = []
     clouds = [x for x in self.clouds if 'localhost' != x]
     if len(clouds) > 0:
         total_items.append(Text("Choose a Cloud"))
         total_items.append(HR())
         for item in clouds:
             total_items.append(
                 Color.body(menu_btn(label=item, on_press=self.submit),
                            focus_map='menu_button focus'))
         total_items.append(Padding.line_break(""))
     # TODO: add vsphere
     new_clouds = juju.get_compatible_clouds(['localhost', 'maas'])
     if new_clouds:
         total_items.append(Text("Configure a New Cloud"))
         total_items.append(HR())
         for item in new_clouds:
             total_items.append(
                 Color.body(menu_btn(label=item, on_press=self.submit),
                            focus_map='menu_button focus'))
     return Padding.center_80(Filler(Pile(total_items), valign='top'))
Esempio n. 23
0
    def _build_footer(self):
        cancel = menu_btn(on_press=self.cancel,
                          label="\n  BACK\n")
        confirm = menu_btn(on_press=self.submit,
                           label="\n ADD CREDENTIAL\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 13, Color.menu_button(
                cancel,
                focus_map='button_primary focus')),
            Text(""),
            ('fixed', 20, Color.menu_button(
                confirm,
                focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        footer = Color.frame_footer(Pile([
            Padding.line_break(""),
            self.buttons
        ]))
        return footer
Esempio n. 24
0
    def _build_widget(self):
        total_items = [Padding.center_60(HR())]
        for spell in self.spells:
            total_items.append(
                Padding.center_60(
                    Color.body(menu_btn(label=spell['name'],
                                        on_press=self.submit,
                                        user_data=spell),
                               focus_map='menu_button focus')))

        total_items.append(Padding.center_60(HR()))
        total_items.append(Padding.center_20(self._build_buttons()))
        return Filler(Pile(total_items), valign='top')
Esempio n. 25
0
    def _build_widget(self):
        total_items = [
            Padding.center_60(Instruction("Choose a Cloud")),
            Padding.center_60(HR())
        ]
        for item in self.clouds:
            total_items.append(
                Padding.center_60(
                    Color.body(menu_btn(label=item, on_press=self.submit),
                               focus_map='menu_button focus')))

        total_items.append(Padding.center_60(HR()))
        total_items.append(Padding.center_20(self._build_buttons()))
        return Filler(Pile(total_items), valign='top')
Esempio n. 26
0
 def _build_widget(self):
     total_items = []
     clouds = [x for x in self.clouds if 'localhost' != x]
     if len(clouds) > 0:
         total_items.append(Text("Choose a Cloud"))
         total_items.append(HR())
         for item in clouds:
             total_items.append(
                 Color.body(menu_btn(label=item, on_press=self.submit),
                            focus_map='menu_button focus'))
         total_items.append(Padding.line_break(""))
     total_items.append(Text("Configure a New Cloud"))
     total_items.append(HR())
     if self.whitelist:
         new_clouds = self.whitelist
     elif self.blacklist:
         new_clouds = set(['localhost', 'maas']) ^ set(self.blacklist)
     else:
         new_clouds = ['localhost', 'maas']
     for item in new_clouds:
         total_items.append(
             Color.body(menu_btn(label=item, on_press=self.submit),
                        focus_map='menu_button focus'))
     return Padding.center_80(Filler(Pile(total_items), valign='top'))
Esempio n. 27
0
 def build_menuable_items(self):
     """ Builds a list of bundles available to install
     """
     bundles = self.common['config']['bundles']
     cols = []
     for bundle in bundles:
         cols.append(
             Columns(
                 [("weight", 0.2,
                   Color.body(menu_btn(label=bundle['name'],
                                       on_press=self.done),
                              focus_map="button_primary focus")),
                  ("weight", 0.3, Text(bundle['summary'], align="left"))],
                 dividechars=1))
         cols.append(Padding.line_break(""))
     return BoxAdapter(SimpleList(cols), height=len(cols) + 2)
Esempio n. 28
0
    def _build_widget(self):
        total_items = [
            Padding.center_60(HR())
        ]
        for spell in self.spells:
            total_items.append(Padding.center_60(
                Color.body(
                    menu_btn(label=spell,
                             on_press=self.submit),
                    focus_map='menu_button focus'
                )
            ))

        total_items.append(
            Padding.center_60(HR()))
        total_items.append(Padding.center_20(self._build_buttons()))
        return Filler(Pile(total_items), valign='top')
Esempio n. 29
0
    def _build_widget(self):
        total_items = [
            Padding.center_60(Instruction("Choose a Cloud")),
            Padding.center_60(HR())
        ]
        for item in self.clouds:
            total_items.append(Padding.center_60(
                Color.body(
                    menu_btn(label=item,
                             on_press=self.submit),
                    focus_map='menu_button focus'
                )
            ))

        total_items.append(
            Padding.center_60(HR()))
        total_items.append(Padding.center_20(self._build_buttons()))
        return Filler(Pile(total_items), valign='top')
Esempio n. 30
0
    def __init__(self, applications, metadata_controller, controller):
        self.controller = controller
        self.applications = applications
        assert (len(applications) > 0)
        self.metadata_controller = metadata_controller
        self.n_remaining = len(self.applications)

        self.buttons_selected = False
        self.skip_rest_button = menu_btn(label="\n  Deploy all\n",
                                         on_press=self.do_deploy_remaining)

        self.frame = Frame(body=self.build_widgets(),
                           footer=self.build_footer())

        super().__init__(self.frame)

        self.selected_app_w = None
        self.handle_focus_changed()
        self.update_skip_rest_button()
Esempio n. 31
0
    def __init__(self, applications, metadata_controller, controller):
        self.controller = controller
        self.applications = applications
        assert(len(applications) > 0)
        self.metadata_controller = metadata_controller
        self.n_remaining = len(self.applications)

        self.buttons_selected = False
        self.skip_rest_button = menu_btn(
            label="\n  Deploy all\n",
            on_press=self.do_deploy_remaining
        )

        self.frame = Frame(body=self.build_widgets(),
                           footer=self.build_footer())

        super().__init__(self.frame)

        self.selected_app_w = None
        self.handle_focus_changed()
        self.update_skip_rest_button()
Esempio n. 32
0
 def build_menuable_items(self):
     """ Builds a list of bundles available to install
     """
     bundles = self.common['config']['bundles']
     cols = []
     for bundle in bundles:
         cols.append(
             Columns(
                 [
                     ("weight", 0.2, Color.body(
                         menu_btn(label=bundle['name'],
                                  on_press=self.done),
                         focus_map="button_primary focus")),
                     ("weight", 0.3, Text(bundle['summary'],
                                          align="left"))
                 ],
                 dividechars=1
             )
         )
         cols.append(Padding.line_break(""))
     return BoxAdapter(SimpleList(cols),
                       height=len(cols)+2)
Esempio n. 33
0
 def build_menuable_items(self):
     """ Builds a list of bundles available to install
     """
     cols = []
     for bundle in app.bundles:
         bundle_metadata = bundle['Meta']['bundle-metadata']
         try:
             conjure_data = bundle['Meta']['extra-info/conjure-up']
             name = conjure_data.get('friendly-name',
                                     bundle['Meta']['id']['Name'])
         except KeyError:
             name = bundle['Meta']['id']['Name']
         self.fname_id_map[name] = bundle
         cols.append(
             Columns([("weight", 0.2,
                       Color.body(menu_btn(label=name, on_press=self.done),
                                  focus_map="menu_button focus")),
                      ("weight", 0.3,
                       Text(bundle_metadata.get('Description',
                                                'Needs a description'),
                            align="left"))],
                     dividechars=1))
         cols.append(Padding.line_break(""))
     return Pile(cols)
Esempio n. 34
0
 def build_widget(self):
     """ Provides a rendered spell widget suitable for pile
     """
     return Color.body(
         menu_btn(label=self.spell["name"], on_press=self.cb, user_data=self.spell), focus_map="menu_button focus"
     )
Esempio n. 35
0
 def add_choice(self, choice):
     self._pile.contents.append(
         (Color.body(menu_btn(label=choice, on_press=self._select),
                     focus_map='menu_button focus'), self._pile.options()))