Esempio n. 1
0
 def __init__(self):
     Resource.__init__(self, model)
     self.description = Description(model)
     self.rectangles = Rectangles(model)
     self.circles = Circles(model)
     self.paths = PluginPaths('sample')
     self.domain = 'sample'
     self.messages = messages
     self.api_schema = json.load(open(os.path.join(os.path.dirname(
                                 os.path.abspath(__file__)), 'API.json')))
Esempio n. 2
0
 def __init__(self):
     self.model = DummyModel()
     super(Dummy, self).__init__(self.model)
     self.collectionsample = CollectionSample(self.model)
     self.resourcesample = ResourceSample(self.model)
     self.progresssample = ProgressSample(self.model)
     self.paths = PluginPaths('dummy')
     self.domain = 'dummy'
     self.messages = messages
     self.api_schema = json.load(open(os.path.join(os.path.dirname(
         os.path.abspath(__file__)), 'API.json')))
Esempio n. 3
0
def _load_plugin_conf(name):
    plugin_conf = PluginPaths(name).conf_file
    if not os.path.exists(plugin_conf):
        cherrypy.log.error_log.error("Plugin configuration file %s"
                                     " doesn't exist." % plugin_conf)
        return
    try:
        return Parser().dict_from_file(plugin_conf)
    except ValueError as e:
        cherrypy.log.error_log.error("Failed to load plugin "
                                     "conf from %s: %s" %
                                     (plugin_conf, e.message))
Esempio n. 4
0
def get_all_tabs():
    files = [os.path.join(paths.prefix, 'config/ui/tabs.xml')]

    for plugin, _ in get_enabled_plugins():
        files.append(
            os.path.join(PluginPaths(plugin).ui_dir, 'config/tab-ext.xml'))

    tabs = []
    for f in files:
        root = ET.parse(f)
        tabs.extend([t.text.lower() for t in root.getiterator('title')])

    return tabs
Esempio n. 5
0
 def __init__(self):
     self.model = GingerModel()
     super(Ginger, self).__init__(self.model)
     self.backup = Backup(self.model)
     self.capabilities = Capabilities(self.model)
     self.firmware = Firmware(self.model)
     self.powerprofiles = PowerProfiles(self.model)
     self.sensors = Sensors(self.model)
     self.users = Users(self.model)
     self.network = Network(self.model)
     self.api_schema = json.load(
         open(
             os.path.join(os.path.dirname(os.path.abspath(__file__)),
                          'API.json')))
     self.paths = PluginPaths('ginger')
     self.domain = "ginger"
     self.messages = messages
     self.san_adapters = SanAdapters(self.model)
     self.ibm_sep = Sep(self.model)
Esempio n. 6
0
class ArchivesModel(object):
    _objstore_type = 'ginger_backup_archive'
    _archive_dir = os.path.join(
        PluginPaths('ginger').state_dir, 'ginger_backups')

    def __init__(self, **kargs):
        self._objstore = kargs['objstore']
        self._create_archive_dir()

    @classmethod
    def _create_archive_dir(cls):
        try:
            os.makedirs(cls._archive_dir)
        except OSError as e:
            # It's OK if archive_dir already exists
            if e.errno != errno.EEXIST:
                kimchi_log.error('Error creating archive dir %s: %s',
                                 cls._archive_dir, e)
                raise OperationFailed('GINHBK0003E', {'dir': cls._archive_dir})

    @property
    def _default_include(self):
        # This function builds a new copy of the list for each invocation,
        # so that the caller can modify the returned list as wish without
        # worrying about changing the original reference.
        return list(cherrypy.request.app.config['backup']['default_include'])

    @property
    def _default_exclude(self):
        # See _default_include() comments for explanation.
        return list(cherrypy.request.app.config['backup']['default_exclude'])

    def _create_archive(self, params):
        error = None
        try:
            params['file'] = _tar_create_archive(self._archive_dir,
                                                 params['identity'],
                                                 params['include'],
                                                 params['exclude'])
            params['checksum'] = {
                'algorithm': 'sha256',
                'value': _sha256sum(params['file'])
            }

            with self._objstore as session:
                session.store(self._objstore_type, params['identity'], params)
        except TimeoutExpired as e:
            error = e
            reason = 'GINHBK0010E'
        except Exception as e:
            error = e
            reason = 'GINHBK0009E'

        if error is not None:
            msg = 'Error creating archive %s: %s' % (params['identity'], error)
            kimchi_log.error(msg)

            try:
                with self._objstore as session:
                    session.delete(self._objstore_type,
                                   params['identity'],
                                   ignore_missing=True)
            except Exception as e_session:
                kimchi_log.error(
                    'Error cleaning archive meta data %s. '
                    'Error: %s', params['identity'], e_session)

            if params['file'] != '':
                try:
                    os.unlink(params['file'])
                except Exception as e_file:
                    kimchi_log.error(
                        'Error cleaning archive file %s. '
                        'Error: %s', params['file'], e_file)

            raise OperationFailed(reason, {'identity': params['identity']})

    def create(self, params):
        archive_id = str(uuid.uuid4())
        stamp = int(time.mktime(time.localtime()))

        # Though formally we ask front-end to not send "include" at all when
        # it's empty, but in implementation we try to be tolerant.
        # Front-end can also send [] to indicate the "include" is empty.
        include = params.get('include')
        exclude = params.get('exclude', [])
        if not include:
            include = self._default_include
            if not exclude:
                exclude = self._default_exclude

        ar_params = {
            'identity': archive_id,
            'include': include,
            'exclude': exclude,
            'description': params.get('description', ''),
            'checksum': {},
            'timestamp': stamp,
            'file': ''
        }
        self._create_archive(ar_params)

        return archive_id

    def _session_get_list(self, session):
        # Assume session is already locked.
        return session.get_list(self._objstore_type, sort_key='timestamp')

    def get_list(self):
        with self._objstore as session:
            return self._session_get_list(session)