Merge "Static modules loading"
This commit is contained in:
commit
2697096241
|
@ -22,11 +22,11 @@ from fuelmenu.common import timeout
|
|||
from fuelmenu.common import urwidwrapper as widget
|
||||
from fuelmenu.common import utils
|
||||
from fuelmenu import consts
|
||||
from fuelmenu import modules
|
||||
from fuelmenu import settings as settings_module
|
||||
|
||||
|
||||
import logging
|
||||
import operator
|
||||
from optparse import OptionParser
|
||||
import os
|
||||
import signal
|
||||
|
@ -42,44 +42,6 @@ logging.basicConfig(filename=consts.LOGFILE,
|
|||
log = logging.getLogger('fuelmenu.loader')
|
||||
|
||||
|
||||
class Loader(object):
|
||||
|
||||
def __init__(self, parent):
|
||||
self.modlist = []
|
||||
self.choices = []
|
||||
self.child = None
|
||||
self.children = []
|
||||
self.childpage = None
|
||||
self.parent = parent
|
||||
|
||||
def load_modules(self, module_dir):
|
||||
if module_dir not in sys.path:
|
||||
sys.path.append(module_dir)
|
||||
|
||||
modules = [os.path.splitext(f)[0] for f in os.listdir(module_dir)
|
||||
if f.endswith('.py')]
|
||||
|
||||
for module in modules:
|
||||
log.info('loading module %s' % module)
|
||||
try:
|
||||
imported = __import__(module)
|
||||
pass
|
||||
except ImportError as e:
|
||||
log.error('module could not be imported: %s' % e)
|
||||
continue
|
||||
|
||||
clsobj = getattr(imported, module, None)
|
||||
modobj = clsobj(self.parent)
|
||||
|
||||
# add the module to the list
|
||||
self.modlist.append(modobj)
|
||||
# sort modules
|
||||
self.modlist.sort(key=operator.attrgetter('priority'))
|
||||
for module in self.modlist:
|
||||
self.choices.append(module.name)
|
||||
return (self.modlist, self.choices)
|
||||
|
||||
|
||||
class FuelSetup(object):
|
||||
|
||||
def __init__(self):
|
||||
|
@ -172,10 +134,12 @@ class FuelSetup(object):
|
|||
self.header = urwid.AttrWrap(urwid.Text(text_header), 'header')
|
||||
self.footer = urwid.AttrWrap(urwid.Text(text_footer), 'footer')
|
||||
|
||||
# Prepare submodules
|
||||
loader = Loader(self)
|
||||
moduledir = "%s/modules" % (os.path.dirname(__file__))
|
||||
self.children, self.choices = loader.load_modules(module_dir=moduledir)
|
||||
self.children = []
|
||||
for clsobj in modules.__all__:
|
||||
modobj = clsobj(self)
|
||||
self.children.append(modobj)
|
||||
|
||||
self.choices = [m.name for m in self.children]
|
||||
|
||||
if len(self.children) == 0:
|
||||
import sys
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
# coding: utf-8
|
||||
|
||||
# Copyright 2016 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from fuelmenu.modules.bootstrapimg import BootstrapImage
|
||||
from fuelmenu.modules.cobblerconf import CobblerConfig
|
||||
from fuelmenu.modules.dnsandhostname import DnsAndHostname
|
||||
from fuelmenu.modules.feature_groups import FeatureGroups
|
||||
from fuelmenu.modules.fueluser import FuelUser
|
||||
from fuelmenu.modules.interfaces import Interfaces
|
||||
from fuelmenu.modules.ntpsetup import NtpSetup
|
||||
from fuelmenu.modules.restore import Restore
|
||||
from fuelmenu.modules.rootpw import RootPassword
|
||||
from fuelmenu.modules.saveandquit import SaveAndQuit
|
||||
from fuelmenu.modules.security import Security
|
||||
from fuelmenu.modules.servicepws import ServicePasswords
|
||||
from fuelmenu.modules.shell import Shell
|
||||
|
||||
|
||||
# Note that order matters.
|
||||
# objects loading and settings dumping will be made in this order
|
||||
__all__ = [
|
||||
FuelUser,
|
||||
Interfaces,
|
||||
Security,
|
||||
CobblerConfig,
|
||||
DnsAndHostname,
|
||||
BootstrapImage,
|
||||
NtpSetup,
|
||||
RootPassword,
|
||||
FeatureGroups,
|
||||
Shell,
|
||||
Restore,
|
||||
SaveAndQuit,
|
||||
ServicePasswords,
|
||||
]
|
|
@ -42,10 +42,9 @@ BOOTSTRAP_SKIP_BUILD_KEY = "BOOTSTRAP/skip_default_img_build"
|
|||
ADD_REPO_BUTTON_KEY = 'add_repo_button'
|
||||
|
||||
|
||||
class bootstrapimg(urwid.WidgetWrap):
|
||||
class BootstrapImage(urwid.WidgetWrap):
|
||||
def __init__(self, parent):
|
||||
self.name = "Bootstrap Image"
|
||||
self.priority = 55
|
||||
self.visible = True
|
||||
self.parent = parent
|
||||
|
||||
|
|
|
@ -29,10 +29,9 @@ log = logging.getLogger('fuelmenu.pxe_setup')
|
|||
blank = urwid.Divider()
|
||||
|
||||
|
||||
class cobblerconf(urwid.WidgetWrap):
|
||||
class CobblerConfig(urwid.WidgetWrap):
|
||||
def __init__(self, parent):
|
||||
self.name = "PXE Setup"
|
||||
self.priority = 20
|
||||
self.visible = True
|
||||
self.netsettings = dict()
|
||||
self.parent = parent
|
||||
|
|
|
@ -32,10 +32,9 @@ log = logging.getLogger('fuelmenu.mirrors')
|
|||
blank = urwid.Divider()
|
||||
|
||||
|
||||
class dnsandhostname(urwid.WidgetWrap):
|
||||
class DnsAndHostname(urwid.WidgetWrap):
|
||||
def __init__(self, parent):
|
||||
self.name = "DNS & Hostname"
|
||||
self.priority = 50
|
||||
self.visible = True
|
||||
self.netsettings = dict()
|
||||
self.getNetwork()
|
||||
|
|
|
@ -24,10 +24,9 @@ from fuelmenu.common.modulehelper import WidgetType
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class feature_groups(urwid.WidgetWrap):
|
||||
class FeatureGroups(urwid.WidgetWrap):
|
||||
def __init__(self, parent):
|
||||
self.name = "Feature groups"
|
||||
self.priority = 70
|
||||
self.visible = True
|
||||
self.parent = parent
|
||||
|
||||
|
|
|
@ -24,10 +24,9 @@ log = logging.getLogger('fuelmenu.rootpw')
|
|||
blank = urwid.Divider()
|
||||
|
||||
|
||||
class fueluser(urwid.WidgetWrap):
|
||||
class FuelUser(urwid.WidgetWrap):
|
||||
def __init__(self, parent):
|
||||
self.name = "Fuel User"
|
||||
self.priority = 1
|
||||
self.visible = True
|
||||
self.parent = parent
|
||||
# UI text
|
||||
|
|
|
@ -35,10 +35,9 @@ blank = urwid.Divider()
|
|||
# Need to define fields in order so it will render correctly
|
||||
|
||||
|
||||
class interfaces(urwid.WidgetWrap):
|
||||
class Interfaces(urwid.WidgetWrap):
|
||||
def __init__(self, parent):
|
||||
self.name = "Network Setup"
|
||||
self.priority = 5
|
||||
self.visible = True
|
||||
self.netsettings = dict()
|
||||
self.parent = parent
|
||||
|
|
|
@ -25,10 +25,9 @@ log = logging.getLogger('fuelmenu.mirrors')
|
|||
blank = urwid.Divider()
|
||||
|
||||
|
||||
class ntpsetup(urwid.WidgetWrap):
|
||||
class NtpSetup(urwid.WidgetWrap):
|
||||
def __init__(self, parent):
|
||||
self.name = "Time Sync"
|
||||
self.priority = 60
|
||||
self.visible = True
|
||||
self.parent = parent
|
||||
|
||||
|
|
|
@ -64,10 +64,9 @@ KEYS_TO_RESTORE = [
|
|||
]
|
||||
|
||||
|
||||
class restore(urwid.WidgetWrap):
|
||||
class Restore(urwid.WidgetWrap):
|
||||
def __init__(self, parent):
|
||||
self.name = "Restore settings"
|
||||
self.priority = 98
|
||||
self.visible = True
|
||||
self.parent = parent
|
||||
self.deployment = "pre"
|
||||
|
|
|
@ -24,10 +24,9 @@ log = logging.getLogger('fuelmenu.rootpw')
|
|||
blank = urwid.Divider()
|
||||
|
||||
|
||||
class rootpw(urwid.WidgetWrap):
|
||||
class RootPassword(urwid.WidgetWrap):
|
||||
def __init__(self, parent):
|
||||
self.name = "Root Password"
|
||||
self.priority = 60
|
||||
self.visible = True
|
||||
self.parent = parent
|
||||
# UI text
|
||||
|
|
|
@ -23,10 +23,9 @@ import urwid.web_display
|
|||
blank = urwid.Divider()
|
||||
|
||||
|
||||
class saveandquit(object):
|
||||
class SaveAndQuit(object):
|
||||
def __init__(self, parent):
|
||||
self.name = "Quit Setup"
|
||||
self.priority = 99
|
||||
self.visible = True
|
||||
self.parent = parent
|
||||
self.screen = None
|
||||
|
|
|
@ -26,10 +26,9 @@ log = logging.getLogger('fuelmenu.security')
|
|||
SSH_NETWORK = 'ADMIN_NETWORK/ssh_network'
|
||||
|
||||
|
||||
class security(urwid.WidgetWrap):
|
||||
class Security(urwid.WidgetWrap):
|
||||
def __init__(self, parent):
|
||||
self.name = "Security Setup"
|
||||
self.priority = 6
|
||||
self.visible = True
|
||||
self.parent = parent
|
||||
self.screen = None
|
||||
|
|
|
@ -23,10 +23,9 @@ log = logging.getLogger('fuelmenu.servicepws')
|
|||
blank = urwid.Divider()
|
||||
|
||||
|
||||
class servicepws(urwid.WidgetWrap):
|
||||
class ServicePasswords(urwid.WidgetWrap):
|
||||
def __init__(self, parent):
|
||||
self.name = "Service Passwords"
|
||||
self.priority = 99
|
||||
self.visible = False
|
||||
self.parent = parent
|
||||
# UI text
|
||||
|
|
|
@ -23,10 +23,9 @@ import urwid.web_display
|
|||
blank = urwid.Divider()
|
||||
|
||||
|
||||
class shell(object):
|
||||
class Shell(object):
|
||||
def __init__(self, parent):
|
||||
self.name = "Shell Login"
|
||||
self.priority = 90
|
||||
self.visible = True
|
||||
self.parent = parent
|
||||
self.screen = None
|
||||
|
|
Loading…
Reference in New Issue