Beispiel #1
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'))
Beispiel #3
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'))
Beispiel #4
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'))
Beispiel #5
0
    def _build_footer(self):
        def _pack(btn):
            return ('fixed', len(btn.label) + 4, btn)

        buttons = []
        buttons.append(('fixed', 2, Text("")))
        buttons.append(_pack(self.button('QUIT', app.ui.quit)))
        if self.show_back_button:
            buttons.append(_pack(self.button('BACK', self.prev_screen)))
        buttons.append(('weight', 2, Text("")))
        buttons.extend([_pack(btn) for btn in self.build_buttons()])
        buttons.append(('fixed', 2, Text("")))
        self.button_row = Columns(buttons, 2)

        self.footer_msg = Text(self.footer)
        footer_widget = Columns([
            Text(''),
            ('pack', self.footer_msg),
            Text(''),
        ])
        footer_widget = Padding.center_90(self.footer_msg)
        if self.footer_height != 'auto':
            footer_widget = BoxAdapter(Filler(footer_widget, valign='bottom'),
                                       self.footer_height)
        footer = Pile([
            Padding.center_90(HR()),
            Color.body(footer_widget),
            Padding.line_break(""),
            Color.frame_footer(
                Pile([
                    Padding.line_break(""),
                    self.button_row,
                ])),
        ])
        return footer
Beispiel #6
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'))
Beispiel #7
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)
Beispiel #8
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')
Beispiel #9
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'))
Beispiel #10
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
Beispiel #11
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]
Beispiel #12
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
Beispiel #13
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'))
Beispiel #14
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')
Beispiel #15
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')
Beispiel #16
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'))
Beispiel #17
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)
Beispiel #18
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')
Beispiel #19
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)
Beispiel #20
0
 def _build_footer(self):
     footer_pile = Pile([
         Padding.center_90(HR()),
         Color.body(
             BoxAdapter(
                 Filler(Columns([
                     Text(''),
                     ('pack', self.message),
                     Text(''),
                 ]),
                        valign='bottom'), 7)),
         Padding.line_break(""),
         Color.frame_footer(
             Columns([('fixed', 2, Text("")),
                      ('fixed', 13, self._build_buttons())])),
     ])
     self.update_message()
     return footer_pile
Beispiel #21
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')
Beispiel #22
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)
Beispiel #23
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)
Beispiel #24
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"
     )
Beispiel #25
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()))