Exemple #1
0
    def getApiPackage(self, machine):
        if self.initialized_failed:
            return []
        machine = self.convertMachineIntoH(machine)
        uuid = machine["uuid"]
        try:
            entity_uuid = ComputerLocationManager().getMachinesLocations([uuid])[uuid]["uuid"]
            parent_entities = [entity_uuid] + ComputerLocationManager().getLocationParentPath(entity_uuid)
            url = ""
            entity_uuid = ""
            db = ImagingDatabase()
            for _uuid in parent_entities:
                urlsearch = db.getEntityUrl(_uuid)
                if urlsearch is not None:
                    entity_uuid = _uuid
                    url = urlsearch
                    break
            Entity_Name = ComputerLocationManager().getLocationName(entity_uuid)
            machine["Entity_Name"] = Entity_Name
            serverinfo = db.getImagingServerInfo(entity_uuid)
            machine["entity_uuid"] = entity_uuid
            machine["server"] = urlparse(url).hostname
            machine["servernane"] = serverinfo.name
        except:
            logging.getLogger().error("Cannot get Entity for this machine UUID (%s)" % uuid)

        d = self.callRemote("getApiPackage", machine)
        d.addErrback(self.onError, "MirrorApi:getApiPackage", machine)
        return d
Exemple #2
0
 def getMirror(self, machine):
     if self.initialized_failed:
         return []
     machine = self.convertMachineIntoH(machine)
     uuid = machine['uuid']
     try:
         entity_uuid = ComputerLocationManager().getMachinesLocations(
             [uuid])[uuid]['uuid']
         parent_entities = [
             entity_uuid
         ] + ComputerLocationManager().getLocationParentPath(entity_uuid)
         url = ''
         entity_uuid = ''
         db = ImagingDatabase()
         for _uuid in parent_entities:
             urlsearch = db.getEntityUrl(_uuid)
             if urlsearch is not None:
                 entity_uuid = _uuid
                 url = urlsearch
                 break
         Entity_Name = ComputerLocationManager().getLocationName(
             entity_uuid)
         machine['Entity_Name'] = Entity_Name
         serverinfo = db.getImagingServerInfo(entity_uuid)
         machine['entity_uuid'] = entity_uuid
         machine['server'] = urlparse(url).hostname
         machine['servernane'] = serverinfo.name
     except:
         logging.getLogger().error(
             "Cannot get Entity for this machine UUID (%s)" % uuid)
     d = self.callRemote("getMirror", machine)
     d.addErrback(self.onError, "MirrorApi:getMirror", machine)
     return d
Exemple #3
0
 def getImagingServerEntityUUID(self, imaging_uuid):
     """
     get the imaging server's entity UUID
     """
     db = ImagingDatabase()
     ims = db.getImagingServerByUUID(imaging_uuid)
     en = db.getImagingServerEntity(ims.packageserver_uuid)
     if en != None:
         return en.uuid
     return None
Exemple #4
0
    def delComputersFromProfile(self, computers_UUID, profile_UUID):
        # TODO need to remove the menu and the registering
        if ImagingDatabase().isTargetRegister(profile_UUID, P2IT.PROFILE):
            # put all the computers to their own menu

            ret1 = ImagingDatabase().delComputersFromProfile(
                profile_UUID, computers_UUID)
            ret2 = ImagingDatabase().changeTargetsSynchroState([profile_UUID],
                                                               P2IT.PROFILE,
                                                               P2ISS.TODO)

            return ret1 and ret2
        return True
Exemple #5
0
def activate():
    """
    Read the plugin configuration, initialize it, and run some tests to ensure
    it is ready to operate.
    """
    logger = logging.getLogger()
    config = ImagingConfig("imaging")

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

    # Initialize imaging database
    if not ImagingDatabase().activate(config):
        logger.warning(
            "Plugin imaging: an error occurred during the database initialization"
        )
        return False

    # register ImagingProfile in ComputerProfileManager but only as a client
    ComputerProfileManager().register("imaging", ImagingProfile)

    ComputerImagingManager().register("imaging", ComputerImagingImaging)

    Pulse2Manager().register('imaging', ImagingPulse2Manager)

    ComputerManager().register('imaging', InventoryComputers)

    TaskManager().addTask("imaging.purge_removed_computers",
                          (purge_removed_computers, ),
                          cron_expression=config.purge_interval)

    return True
Exemple #6
0
def purge_removed_computers():
    from mmc.plugins.base.computers import ComputerManager
    from mmc.plugins.base import LdapUserGroupControl

    # Get all imaging targets
    targets = ImagingDatabase().getAllRegisteredComputers()

    # Creating root context to query ComputerManager
    ctx = SecurityContext()
    ctx.userid = 'root'
    ctx.userdn = LdapUserGroupControl().searchUserDN(ctx.userid)

    # Init to_delete computer list
    to_delete = []

    for uuid in targets:
        if ComputerManager().getComputerCount(ctx, {'uuid': uuid}) == 0:
            # If the target computer is not in ComputerManager database anymore
            # we unregister it from imaging
            to_delete.append(uuid)

    # Unregistering orphan targets without backup
    if to_delete:
        logging.getLogger().info('Orphan imaging computer(s) found')
        logging.getLogger().info('Going to purge %s' % ' '.join(to_delete))
        computersUnregister(to_delete, False)

    return True
Exemple #7
0
 def isChildOfImagingServer(self, loc_uuid, main_imaging_server_uuid):
     """
     Check if loc_uuid is child of main_imaging_server_uuid
     """
     parents = ComputerLocationManager().getLocationParentPath(loc_uuid)
     # Check if loc_uuid is child of main_imaging_server_uuid
     if main_imaging_server_uuid in parents:
         # Cool ! Now check if loc_uuid has not his own imaging server
         if not ImagingDatabase().doesLocationHasImagingServer(loc_uuid):
             return True
     return False
Exemple #8
0
    def addComputersToProfile(self, ctx, computers, profile_UUID):
        # TODO need to put the menu and synchronize
        if ImagingDatabase().isTargetRegister(profile_UUID, P2IT.PROFILE):
            ret1 = ImagingDatabase().putComputersInProfile(
                profile_UUID, computers)
            ret2 = ImagingDatabase().changeTargetsSynchroState([profile_UUID],
                                                               P2IT.PROFILE,
                                                               P2ISS.TODO)
            ret3 = ImagingDatabase().changeTargetsSynchroState(
                computers, P2IT.COMPUTER, P2ISS.TODO)

            computers_UUID = map(lambda c: c['uuid'], computers.values())

            def treatResult(result, ret):
                return result and ret

            d = synchroComputers(ctx, computers_UUID, P2IT.COMPUTER_IN_PROFILE)
            d.addCallback(treatResult, ret1 and ret2 and ret3)
            return d
        return True
Exemple #9
0
 def getAllImagingServers(self, user_id, is_associated):
     """
     get all the imaging server that this user can access
     """
     locations = ComputerLocationManager().getUserLocations(user_id)
     locations = map(lambda l:l['uuid'], locations)
     r = ImagingDatabase().getEntitiesImagingServer(locations, is_associated)
     ret = {}
     for ims, loc_uuid in r:
         ims = ims.toH()
         ret[ims['imaging_uuid']] = ims
     return ret
Exemple #10
0
    def delProfile(self, profile_UUID):
        if ImagingDatabase().isTargetRegister(profile_UUID, P2IT.PROFILE):
            # TODO : put all the computers on their own menu
            computers_UUID = map(
                lambda c: c.uuid,
                ComputerProfileManager().getProfileContent(profile_UUID))
            computers = {}
            for uuid in computers_UUID:
                computers[uuid] = {'uuid': uuid}

            ret1 = len(computers) > 0 and ImagingDatabase(
            ).delComputersFromProfile(profile_UUID, computers) or True
            ret2 = len(computers) > 0 and ImagingDatabase(
            ).changeTargetsSynchroState(computers_UUID, P2IT.COMPUTER,
                                        P2ISS.TODO) or True
            # delete the profile itself
            ret3 = ImagingDatabase().delProfile(profile_UUID)
            ret4 = len(computers) > 0 and ImagingDatabase(
            ).switchMenusToDefault(computers_UUID) or True

            return ret1 and ret2 and ret3 and ret4
        return True
Exemple #11
0
 def putPackageServerEntity(self, ps_uuid, e_uuid):
     ims = ImagingDatabase().getImagingServerByPackageServerUUID(ps_uuid)
     entity = ImagingDatabase().getEntityByUUID(e_uuid)
     ImagingDatabase().updateImagingServer(ims[0].getUUID(),
                                           {'fk_entity': entity.id})
Exemple #12
0
 def areForbiddebComputers(self, computer_UUID):
     return ImagingDatabase().areForbiddebComputers(computer_UUID)
Exemple #13
0
 def getForbiddenComputersUUID(self, profile_UUID=None):
     return ImagingDatabase().getForbiddenComputersUUID(profile_UUID)