Ejemplo n.º 1
0
 def setbool_group(self, id, bool, type=0, parent_id=None):
     if type == 2 and parent_id is not None:  # convergence group, get parent group's user context
         _group_user = DyngroupDatabase()._get_group_user(parent_id)
         ctx = self.getContext(user=_group_user)
     else:
         ctx = self.currentContext
     return xmlrpcCleanup(DyngroupDatabase().setbool_group(ctx, id, bool))
Ejemplo n.º 2
0
 def delete_group(self, id):
     ctx = self.currentContext
     if self.isprofile(id):
         grp = DyngroupDatabase().get_group(ctx, id, True)
         profile_UUID = grp.getUUID()
         ComputerProfileManager().delProfile(profile_UUID)
     return xmlrpcCleanup(DyngroupDatabase().delete_group(ctx, id))
Ejemplo n.º 3
0
 def create_group(self, name, visibility, type=0, parent_id=None):
     if type == 2 and parent_id is not None:  # convergence group, get parent group's user context
         _group_user = DyngroupDatabase()._get_group_user(parent_id)
         ctx = self.getContext(user=_group_user)
     else:
         ctx = self.currentContext
     return xmlrpcCleanup(DyngroupDatabase().create_group(
         ctx, name, visibility, type, parent_id))
Ejemplo n.º 4
0
 def get_group(self, id, ro=False, root_context=False):
     grp = DyngroupDatabase().get_group(self.getContext(), id)
     if grp.type == 2:
         _group_user = DyngroupDatabase()._get_group_user(grp.parent_id)
         ctx = self.getContext(user=_group_user)
     else:
         ctx = root_context and self.getContext() or self.currentContext
     grp = DyngroupDatabase().get_group(ctx, id, ro)
     if grp:
         return xmlrpcCleanup(grp.toH())
     return xmlrpcCleanup(False)
Ejemplo n.º 5
0
 def get_profile_entity(self, gid):
     if gid == '':
         return False
     if not self.isprofile(gid):
         return False
     ret = DyngroupDatabase().getProfileEntity(gid)
     return xmlrpcCleanup(ret)
Ejemplo n.º 6
0
 def get_profile_imaging_server(self, gid):
     if gid == '':
         return False
     if not self.isprofile(gid):
         return False
     ret = DyngroupDatabase().getProfileImagingServer(gid)
     return xmlrpcCleanup(ret)
Ejemplo n.º 7
0
    def addmembers_to_group(self, id, uuids):
        ctx = self.currentContext
        # remove all the computers that cant be added to a profile from the list
        didnt_work = []
        are_some_to_remove = False
        if self.isprofile(id):
            computers = []
            uuid2key = {}
            for c in uuids:
                computers.append(uuids[c]['uuid'])
                uuid2key[uuids[c]['uuid']] = c
            didnt_work = ComputerProfileManager().areForbiddebComputers(
                computers)

            if len(didnt_work) > 0:
                logging.getLogger().debug(
                    "Can't add the following computers in that profile %s : %s"
                    % (str(id), str(didnt_work)))
                for i in didnt_work:
                    if uuid2key[i] in uuids:
                        are_some_to_remove = True
                        uuids.pop(uuid2key[i])

        if len(uuids) != 0:
            if self.isprofile(id):
                ComputerProfileManager().addComputersToProfile(ctx, uuids, id)
            else:
                ret = DyngroupDatabase().addmembers_to_group(ctx, id, uuids)
                return [ret]
        return xmlrpcCleanup([not are_some_to_remove, didnt_work])
Ejemplo n.º 8
0
 def reload_group(self, id):
     ctx = self.currentContext
     ret = DyngroupDatabase().reload_group(ctx, id, queryManager)
     # WIP : call ComputerProfileManager to add machines
     #        if self.isprofile(id):
     #            ComputerProfileManager().addComputersToProfile(ctx, [1, 2], id) # fake!
     return xmlrpcCleanup(ret)
Ejemplo n.º 9
0
 def result_group(self, id, start, end, filter):
     ctx = self.currentContext
     return xmlrpcCleanup(
         map(
             lambda g: g.toH(),
             DyngroupDatabase().result_group(ctx, id, start, end, filter,
                                             False)))
Ejemplo n.º 10
0
 def delmembers_to_group(self, id, uuids):
     ctx = self.currentContext
     ret = DyngroupDatabase().delmembers_to_group(ctx, id, uuids)
     # WIP : call ComputerProfileManager to add machines
     if len(uuids) != 0 and self.isprofile(id):
         ComputerProfileManager().delComputersFromProfile(uuids, id)
     return xmlrpcCleanup(ret)
Ejemplo n.º 11
0
def query(ctx, criterion, value):
    logging.getLogger().info(ctx)
    logging.getLogger().info(criterion)
    logging.getLogger().info(value)
    machines = []
    if criterion == 'groupname':
        machines = map(lambda x: x.name, DyngroupDatabase().getMachines(ctx, {'gname':value}))
    return [machines, True]
Ejemplo n.º 12
0
 def add_convergence_datas(self, parent_group_id, deploy_group_id,
                           done_group_id, pid, p_api, command_id, active,
                           params):
     ret = DyngroupDatabase().add_convergence_datas(parent_group_id,
                                                    deploy_group_id,
                                                    done_group_id, pid,
                                                    p_api, command_id,
                                                    active, params)
     return xmlrpcCleanup(ret)
Ejemplo n.º 13
0
    def add_command_api(self, pid, target, params, p_api, mode, gid = None, proxy = [], cmd_type = 0):
        """
        @param target: must be list of UUID
        @type target: list
        """
        ctx = self.currentContext
        if gid:
            grp = DyngroupDatabase().get_group(self.getContext(), gid)
            # If convergence group, get context of group's owner
            if grp.type == 2:
                _group_user = DyngroupDatabase()._get_group_user(grp.parent_id)
                ctx = self.getContext(user=_group_user)
            target = ComputerGroupManager().get_group_results(ctx, gid, 0, -1, '', True)

        g = mmc.plugins.msc.package_api.SendPackageCommand(ctx, p_api, pid, target, params, mode, gid, proxies = proxy, cmd_type = cmd_type)
        g.deferred = defer.Deferred()
        g.send()
        g.deferred.addCallbacks(xmlrpcCleanup, lambda err: err)
        return g.deferred
Ejemplo n.º 14
0
 def get_active_convergence_for_host(self, host_uuid):
     all_convergences = DyngroupDatabase().get_active_convergences()
     host_convergences = []
     for cv in all_convergences:
         # Do next with root context
         ctx = self.getContext()
         if ComputerManager().getRestrictedComputersList(
                 ctx, 0, -1, {
                     'uuid': host_uuid,
                     'gid': cv['gid']
                 }, False, False, True):
             host_convergences.append(cv)
     return host_convergences
Ejemplo n.º 15
0
def activate():
    logger = logging.getLogger()
    global config
    config = DGConfig()
    config.init("dyngroup")

    if config.disable:
        logger.warning("Plugin dyngroup: disabled by configuration.")
        return False

    DyngroupDatabase().activate(config)
    if not DyngroupDatabase().db_check():
        return False

    ComputerGroupManager().register("dyngroup", DyngroupGroup)
    ComputerProfileManager().register("dyngroup", DyngroupProfile)
    ComputerManager().register("dyngroup", DyngroupComputers)

    if config.check_db_enable:
        scheduleCheckStatus(config.check_db_interval)

    return True
Ejemplo n.º 16
0
 def get_all_commands_for_consult(self,
                                  min=0,
                                  max=10,
                                  filt='',
                                  expired=True):
     ctx = self.currentContext
     size, ret1 = MscDatabase().getAllCommandsConsult(
         ctx, min, max, filt, expired)
     ret = []
     logger = logging.getLogger()
     cache = {}
     for c in ret1:
         if c['gid']:
             if cache.has_key("G%s" % (c['gid'])):
                 #if "G%s"%(c['gid']) in cache:
                 c['target'] = cache["G%s" % (c['gid'])]
             else:
                 group = DyngroupDatabase().get_group(ctx, c['gid'], True)
                 if type(
                         group
                 ) == bool:  # we dont have the permission to view the group
                     c['target'] = 'UNVISIBLEGROUP'  # TODO!
                 elif group == None:
                     c['target'] = 'this group has been deleted'
                 elif hasattr(group, 'ro') and group.ro:
                     logger.debug("user %s access to group %s in RO mode" %
                                  (ctx.userid, group.name))
                     c['target'] = group.name
                 else:
                     c['target'] = group.name
                 cache["G%s" % (c['gid'])] = c['target']
         else:
             if cache.has_key("M%s" % (c['uuid'])):
                 #if "M%s"%(c['uuid']) in cache:
                 c['target'] = cache["M%s" % (c['uuid'])]
             else:
                 if not ComputerLocationManager(
                 ).doesUserHaveAccessToMachine(ctx, c['uuid']):
                     c['target'] = "UNVISIBLEMACHINE"
                 elif not ComputerManager().getComputer(
                         ctx, {'uuid': c['uuid']}):
                     c['target'] = "UNVISIBLEMACHINE"
                 cache["M%s" % (c['uuid'])] = c['target']
         # treat c['title'] to remove the date when possible
         # "Bundle (1) - 2009/12/14 10:22:24" => "Bundle (1)"
         date_re = re.compile(" - \d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d")
         c['title'] = date_re.sub('', c['title'])
         ret.append(c)
     return xmlrpcCleanup((size, ret))
Ejemplo n.º 17
0
    def update_machine_cache(self):
        ctx = self.currentContext
        dyndatabase = DyngroupDatabase()

        cache = dyndatabase.getAllMachinesUuid()
        machines = ComputerManager().getRestrictedComputersList(
            ctx, 0, -1, {'uuids': cache.keys()}, False, False, True)

        need_update = {}
        for m in machines:
            if m['hostname'] != cache[m['uuid']]:
                need_update[m['uuid']] = m['hostname']

        dyndatabase.updateNewNames(need_update)
        return len(need_update)
Ejemplo n.º 18
0
def checkPool():
    ret = True
    try:
        pool = DyngroupDatabase().db.pool
        if pool._max_overflow > -1 and pool._overflow >= pool._max_overflow:
            logging.getLogger().error(
                'dyngroup plugin: CHECK: NOK: timeout then overflow (%d vs. %d) detected in SQL pool : check your network connectivity !'
                % (pool._overflow, pool._max_overflow))
            pool.dispose()
            pool = pool.recreate()
            ret = False
    except Exception, e:
        logging.getLogger().warn(
            'dyngroup plugin: CHECK: NOK: got the following error : %s' % (e))
        ret = False
Ejemplo n.º 19
0
 def _get_machine_groups(self, uuid):
     """
     Get groups of one machine with is uuid as number"
     """
     # Creating root context
     ctx = SecurityContext()
     ctx.userid = 'root'
     group_list = []
     groups = DyngroupDatabase().getallgroups(ctx, {})
     groups = map(lambda g: g.toH(), groups)
     for group in groups:
         if 'id' in group:
             result = ComputerGroupManager().get_group_results(
                 ctx, group['id'], 0, -1, {})
             if "UUID" + str(uuid) in result:
                 group_list.append(group['id'])
     return group_list
Ejemplo n.º 20
0
def _get_convergence_soon_ended_commands(all=False):
    """
    @param all: If True, get all convergence active commands
    @type all: Bool

    @return: list of soon ended convergence commands
    @rtype: list
    """
    ret = []
    active_convergence_cmd_ids = DyngroupDatabase()._get_convergence_active_commands_ids()
    if all:
        # Return all active_convergence_cmd_ids
        return active_convergence_cmd_ids
    elif active_convergence_cmd_ids:
        # Get active_convergence_cmd_ids who are soon expired
        ret = MscDatabase()._get_convergence_soon_ended_commands(cmd_ids=active_convergence_cmd_ids)
    return xmlrpcCleanup(ret)
Ejemplo n.º 21
0
    def expire_all_package_commands(self, pid):
        """
        Expires all commands of a given package
        Used usually when a package is dropped

        @param pid: uuid of dropped package
        @type pid: uuid
        """
        # get all cmd_ids with their start_date  of given package id
        cmds = MscDatabase().get_package_cmds(pid)

        if cmds:
            logging.getLogger().info('%d command will be expired' % len(cmds))

            # for all cmd_ids, get start_date and expire them
            for cmd_id, start_date in cmds.items():
                logging.getLogger().info('Expires command %d' % cmd_id)
                end_date = time.strftime("%Y-%m-%d %H:%M:%S")
                self.extend_command(cmd_id, start_date, end_date)
            # Delete convergence groups if any
            DyngroupDatabase().delete_package_convergence(pid)
        return True
Ejemplo n.º 22
0
def getAllGroupName(ctx, value = ''):
    return map(lambda x:x.name, DyngroupDatabase().getallgroups(ctx, {'filter':value}))
Ejemplo n.º 23
0
 def getProfileByNameImagingServer(self, name, is_uuid):
     return DyngroupDatabase().getProfileByNameImagingServer(name, is_uuid)
Ejemplo n.º 24
0
 def getProfileByUUID(self, uuid):
     return DyngroupDatabase().getProfileByUUID(uuid)
Ejemplo n.º 25
0
def _get_convergence_deploy_group_id_and_user(cmd_id):
    return DyngroupDatabase()._get_convergence_deploy_group_id_and_user(cmd_id)
Ejemplo n.º 26
0
def _get_convergence_phases(cmd_id, deploy_group_id):
    return DyngroupDatabase()._get_convergence_phases(cmd_id, deploy_group_id)
Ejemplo n.º 27
0
 def getProfileImagingServerUUID(self, uuid):
     return DyngroupDatabase().getProfileImagingServer(uuid)
Ejemplo n.º 28
0
 def addComputersToProfile(self, ctx, computers_UUID, profile_UUID):
     return DyngroupDatabase().addmembers_to_group(ctx, profile_UUID,
                                                   computers_UUID)
Ejemplo n.º 29
0
 def getProfileContent(self, uuid):
     return DyngroupDatabase().getProfileContent(uuid)
Ejemplo n.º 30
0
 def getComputersProfile(self, uuid):
     return DyngroupDatabase().getComputersProfile(uuid)