Ejemplo n.º 1
0
    def update(self, req, body, tenant_id, id):
        LOG.info("Updating module %s.", id)

        context = req.environ[wsgi.CONTEXT_KEY]
        module = models.Module.load(context, id)
        self.authorize_module_action(context, 'update', module)
        original_module = copy.deepcopy(module)
        if 'name' in body['module']:
            module.name = body['module']['name']
        if 'module_type' in body['module']:
            module.type = body['module']['module_type']
        if 'contents' in body['module']:
            module.contents = body['module']['contents']
        if 'description' in body['module']:
            module.description = body['module']['description']
        if 'all_tenants' in body['module']:
            module.tenant_id = (None if body['module']['all_tenants'] else
                                tenant_id)
        ds_changed = False
        ds_ver_changed = False
        if 'datastore' in body['module']:
            if 'type' in body['module']['datastore']:
                module.datastore_id = body['module']['datastore']['type']
                ds_changed = True
            if 'version' in body['module']['datastore']:
                module.datastore_version_id = (
                    body['module']['datastore']['version'])
                ds_ver_changed = True
        if 'all_datastores' in body['module']:
            if ds_changed:
                raise exception.ModuleInvalid(
                    reason=_('You cannot set a datastore and specify '
                             '--all_datastores'))
            module.datastore_id = None
        if 'all_datastore_versions' in body['module']:
            if ds_ver_changed:
                raise exception.ModuleInvalid(
                    reason=_('You cannot set a datastore version and specify '
                             '--all_datastore_versions'))
            module.datastore_version_id = None
        if 'auto_apply' in body['module']:
            module.auto_apply = body['module']['auto_apply']
        if 'visible' in body['module']:
            module.visible = body['module']['visible']
        if 'live_update' in body['module']:
            module.live_update = body['module']['live_update']
        if 'priority_apply' in body['module']:
            module.priority_apply = body['module']['priority_apply']
        if 'apply_order' in body['module']:
            module.apply_order = body['module']['apply_order']
        full_access = None
        if 'full_access' in body['module']:
            full_access = body['module']['full_access']

        models.Module.update(context, module, original_module, full_access)
        view_data = views.DetailedModuleView(module)
        return wsgi.Result(view_data.data(), 200)
 def apply(self, name, datastore, ds_version, data_file, admin_module):
     if not admin_module:
         raise exception.ModuleInvalid(
             reason='Module not created with admin options')
     pkg_cmd, install_opts, uninstall_opts = (
         operating_system.get_package_command())
     if pkg_cmd:
         self._run_pkg_cmd(pkg_cmd, install_opts, data_file)
Ejemplo n.º 3
0
 def validate(modules, datastore_id, datastore_version_id):
     for module in modules:
         if (module.datastore_id and
                 module.datastore_id != datastore_id):
             reason = (_("Module '%(mod)s' cannot be applied "
                         " (Wrong datastore '%(ds)s' - expected '%(ds2)s')")
                       % {'mod': module.name, 'ds': module.datastore_id,
                          'ds2': datastore_id})
             raise exception.ModuleInvalid(reason=reason)
         if (module.datastore_version_id and
                 module.datastore_version_id != datastore_version_id):
             reason = (_("Module '%(mod)s' cannot be applied "
                         " (Wrong datastore version '%(ver)s' "
                         "- expected '%(ver2)s')")
                       % {'mod': module.name,
                          'ver': module.datastore_version_id,
                          'ver2': datastore_version_id})
             raise exception.ModuleInvalid(reason=reason)
Ejemplo n.º 4
0
 def module_apply(self, context, modules=None):
     LOG.info("Applying modules.")
     results = []
     modules = [data['module'] for data in modules]
     try:
         # make sure the modules are applied in the correct order
         modules.sort(key=operator.itemgetter('apply_order'))
         modules.sort(key=operator.itemgetter('priority_apply'),
                      reverse=True)
     except KeyError:
         # If we don't have ordering info then maybe we're running
         # a version of the module feature before ordering was
         # introduced.  In that case, since we don't have any
         # way to order the modules we should just continue.
         pass
     for module in modules:
         id = module.get('id', None)
         module_type = module.get('type', None)
         name = module.get('name', None)
         tenant = module.get('tenant', self.MODULE_APPLY_TO_ALL)
         datastore = module.get('datastore', self.MODULE_APPLY_TO_ALL)
         ds_version = module.get('datastore_version',
                                 self.MODULE_APPLY_TO_ALL)
         contents = module.get('contents', None)
         md5 = module.get('md5', None)
         auto_apply = module.get('auto_apply', True)
         visible = module.get('visible', True)
         is_admin = module.get('is_admin', None)
         if is_admin is None:
             # fall back to the old method of checking for an admin option
             is_admin = (tenant == self.MODULE_APPLY_TO_ALL or
                         not visible or
                         auto_apply)
         if not name:
             raise AttributeError(_("Module name not specified"))
         if not contents:
             raise AttributeError(_("Module contents not specified"))
         driver = self.module_driver_manager.get_driver(module_type)
         if not driver:
             raise exception.ModuleTypeNotFound(
                 _("No driver implemented for module type '%s'") %
                 module_type)
         if (datastore and datastore != self.MODULE_APPLY_TO_ALL and
                 datastore != CONF.datastore_manager):
             reason = (_("Module not valid for datastore %s") %
                       CONF.datastore_manager)
             raise exception.ModuleInvalid(reason=reason)
         result = module_manager.ModuleManager.apply_module(
             driver, module_type, name, tenant, datastore, ds_version,
             contents, id, md5, auto_apply, visible, is_admin)
         results.append(result)
     LOG.info("Returning list of modules: %s", results)
     return results