示例#1
0
    def manage_entities(self):
        while True:
            choices = self.obtain_choices()
            choice = choice_input_list('MiniCloud', choices.options_list)

            if choice == choices.CLOUD_DEPLOYMENT_OVERVIEW:
                self.topologize()
            elif choice == choices.CLOUD_MGNT:
                self.cloud_mgnt.manage_entities()
            elif choice == choices.CLUSTER_MGNT:
                self.cluster_mgnt.manage_entities()
            elif choice == choices.ROUTER_MGNT:
                self.router_mgnt.manage_entities()
            elif choice == choices.NETWORK_MGNT:
                self.network_mgnt.manage_entities()
            elif choice == choices.INSTANCE_MGNT:
                self.instance_mgnt.manage_entities()
            elif choice == choices.RESET:
                self.reset()
            elif choice == choices.DESTROY_ALL:
                self.drop_all()
                self.end_program()
                break
            else:
                self.end_program()
                break
示例#2
0
    def obtain_entity_name(self, manager=None, input_string=None, filter_f=None, choose_from_display=False,
                           allow_none=False, skip_questioning_if_only_one_entity=False,
                           return_immediately_if_no_entity=False):
        name = None
        if not manager:
            manager = self.manager
        if not input_string:
            input_string = manager.entity_title() + ' name'
        if choose_from_display:
            output()  # skip line first, is nicer

        names = manager.list_entity_names(filter_f)

        if names and choose_from_display:
            name_idx = choice_input_list(input_string, names, add_none=allow_none,
                                         zero_based_return=True, skip_line=False)
            if name_idx == len(names):
                return None
            else:
                return names[name_idx]

        else:
            if not names:
                if return_immediately_if_no_entity:
                    return None
                else:
                    def_name = 'none'
            elif len(names) == 1:
                if skip_questioning_if_only_one_entity:
                    return names[0]
                else:
                    def_name = names[0]
            else:
                def_name = 'show'

            while True:
                name = string_input(input_string, default=def_name)
                if name == 'show':
                    if len(name) > 0:
                        for n in names:
                            print n
                        output('or give \'none\' to return.')
                    else:
                        output('Nothing to show.')
                elif name == 'none':
                    return None
                else:
                    if name in names:
                        break
                    else:
                        output('%s is not a valid %s, pls re-enter or give \'none\'.', (name, manager.entity_name()))
        return name
示例#3
0
    def manage_entities(self):
        choices = self.obtain_choices()
        while True:
            choice = choice_input_list(('%ss' % self.entity_name).title(), choices.options_list)

            if choice == choices.TOPOLOGY:
                self.topologize()
            elif choice == choices.LIST:
                self.list()
            elif choice == choices.ADD:
                self.add()
            elif self.update_supported() and choice == choices.UPDATE:
                self.update()
            elif choice == choices.REMOVE:
                self.remove()
            else:
                if not self.extra_entity_management(choice):
                    break
        pass
示例#4
0
 def obtain_update_data(self, entity):
     options_list = ['Location \t(%s)'   % entity.location,  # 1
                     'Path \t(%s)'       % entity.path,      # 2
                     'Tenant \t(%s)'     % entity.tenant,    # 3
                     'Username \t(%s)'   % entity.username,  # 4
                     'Password \t(%s)'   % entity.password   # 5
                     # none                               # 6
                     ]
     field = choice_input_list('What would you like to update', options_list, add_none=True, default_last=True)
     data = None
     if field < 6:
         if field == 1:
             data = dict(name=entity.name, location=string_input('New location'))
         elif field == 2:
             data = dict(name=entity.name, path=string_input('New path'))
         elif field == 3:
             data = dict(name=entity.name, tenant=string_input('New tenant'))
         elif field == 4:
             data = dict(name=entity.name, username=string_input('New username'))
         elif field == 5:
             data = dict(name=entity.name, password=string_input('New password'))
     return data