Пример #1
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
Пример #2
0
 def getContext(self):
     s = SecurityContext()
     s.userid = self.userid
     s.locationsCount = ComputerLocationManager().getLocationsCount()
     s.userids = ComputerLocationManager().getUsersInSameLocations(self.userid)
     s.filterType = "mine"
     return s
Пример #3
0
def getBackupServerByUUID(uuid):
    """
    @param uuid: Machine uuid
    @type uuid: str

    @returns: the Backup Server URL for the specified UUID
    @rtype: str
    """
    #return 'localhost/backuppc/index.cgi'
    from pulse2.managers.location import ComputerLocationManager
    try:
        entity_uuid = ComputerLocationManager().getMachinesLocations(
            [uuid])[uuid]['uuid']
        parent_entities = [
            entity_uuid
        ] + ComputerLocationManager().getLocationParentPath(entity_uuid)
    except:
        logger.error("Cannot get Entity for this UUID (%s)" % uuid)
        return ''
    url = ''
    for _uuid in parent_entities:
        url = BackuppcDatabase().get_backupserver_by_entity(_uuid)
        if url: return url
    # If we're here, Backup host not mapped
    logger.error(
        "Cannot get BackupServer for this UUID (%s), please check Entity <> BackupServer mappings."
        % uuid)
    return ''
Пример #4
0
def activate():
    config = GlpiConfig("glpi")
    logger = logging.getLogger()
    if config.disable:
        logger.warning("Plugin glpi: disabled by configuration.")
        return False

    if not GlpiLocation().init(config): # does Glpi().activate()
        return False
    if not Glpi().db_check():
        return False

    ComputerManager().register("glpi", GlpiComputers)
    ProvisioningManager().register("glpi", GlpiProvisioner)
    if config.displayLocalisationBar:
        ComputerLocationManager().register("glpi", GlpiLocation)

    if config.check_db_enable:
        scheduleCheckStatus(config.check_db_interval)

    # Register the panel to the DashboardManager
    try:
        from mmc.plugins.dashboard.manager import DashboardManager
        from mmc.plugins.glpi.panel import GlpiPanel
        DM = DashboardManager()
        DM.register_panel(GlpiPanel("glpi"))
    except ImportError:
        pass

    return True
Пример #5
0
def activate_2():
    config = Pulse2Config("pulse2")
    try:
        ComputerLocationManager().select(config.location)
    except Exception, e:
        logging.getLogger().error(e)
        return False
Пример #6
0
 def getMachinesByDict(self, table, params):
     ctx = self.currentContext
     return xmlrpcCleanup(
         map(
             lambda m: ComputerLocationManager().
             doesUserHaveAccessToMachine(ctx.userid, m[0]),
             Inventory().getMachinesByDict(ctx, table, params)))
Пример #7
0
def activate():
    logger = logging.getLogger()
    config = InventoryConfig()
    config.init("inventory")
    logger.debug("Inventory %s" % str(config.disable))
    if config.disable:
        logger.warning("Plugin inventory: disabled by configuration.")
        return False

    # When this module is used by the MMC agent, the global inventory variable is shared.
    # This means an Inventory instance is not created each time a XML-RPC call is done.
    if not InventoryLocation().init(
            config
    ):  # does Inventory().activate() (which does the Inventory().db_check())
        return False

    logger.info("Plugin inventory: Inventory database version is %d" %
                Inventory().dbversion)

    ComputerManager().register("inventory", InventoryComputers)
    ProvisioningManager().register('inventory', InventoryProvisioner)
    ComputerLocationManager().register('inventory', InventoryLocation)

    PossibleQueries().init(config)

    # Register the panel to the DashboardManager
    try:
        from mmc.plugins.dashboard.manager import DashboardManager
        from mmc.plugins.inventory.panel import InventoryPanel
        DM = DashboardManager()
        DM.register_panel(InventoryPanel("inventory"))
    except ImportError:
        pass

    return True
Пример #8
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
Пример #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
Пример #10
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))
Пример #11
0
 def ppa_putPackageDetail(self, pp_api_id, package, need_assign = True):
     # Patching package with entity_id
     ctx = self.currentContext
     locations = ComputerLocationManager().getUserLocations(ctx.userid)
     # Get root location for the user
     root_location_id = locations[0]['uuid'].replace('UUID', '')
     package['entity_id'] = root_location_id
     logging.getLogger().fatal(locations)
     def _ppa_putPackageDetail(result, pp_api_id = pp_api_id, package = package, need_assign = need_assign):
         for upa in result:
             if upa['uuid'] == pp_api_id:
                 return PackagePutA(upa).putPackageDetail(package, need_assign)
         logging.getLogger().warn("Failed to put package details on %s"%(pp_api_id))
         return False
     d = self.upaa_getUserPackageApi()
     d.addCallback(_ppa_putPackageDetail)
     return d
Пример #12
0
def complete_ctx(ctx):
    """
    Set GLPI user locations and profile in current security context.
    """
    if not hasattr(ctx, "locations") or ctx.locations == None:
        logging.getLogger().debug("adding locations in context for user %s" %
                                  (ctx.userid))
        ctx.locations = map(
            __convert,
            mmc.plugins.glpi.database.Glpi().getUserLocations(ctx.userid))
        if type(ctx.locations) == list:
            if hasattr(ctx.locations[0], 'id'):  # GLPI 0.8
                ctx.locationsid = map(lambda e: e.id, ctx.locations)
            elif hasattr(ctx.locations[0], 'ID'):  # GLPI 0.7x
                ctx.locationsid = map(lambda e: e.ID, ctx.locations)
    if not hasattr(ctx, "profile"):
        logging.getLogger().debug("adding profiles in context for user %s" %
                                  (ctx.userid))
        ctx.profile = ComputerLocationManager().getUserProfile(ctx.userid)
Пример #13
0
def activate():
    config = GlpiConfig("glpi")
    logger = logging.getLogger()
    if config.disable:
        logger.warning("Plugin glpi: disabled by configuration.")
        return False

    if not GlpiLocation().init(config):  # does Glpi().activate()
        return False
    if not Glpi().db_check():
        return False

    ComputerManager().register("glpi", GlpiComputers)
    ProvisioningManager().register("glpi", GlpiProvisioner)
    if config.displayLocalisationBar:
        ComputerLocationManager().register("glpi", GlpiLocation)

    if config.check_db_enable:
        scheduleCheckStatus(config.check_db_interval)

    return True
Пример #14
0
 def getUserLocations(self):
     ctx = self.currentContext
     return xmlrpcCleanup(ComputerLocationManager().getUserLocations(
         ctx.userid))
Пример #15
0
def displayLocalisationBar():
    return xmlrpcCleanup(ComputerLocationManager().displayLocalisationBar())
Пример #16
0
 def getLocationName(self, uuid):
     return xmlrpcCleanup(ComputerLocationManager().getLocationName(uuid))
Пример #17
0
 def getLocationParentPath(self, uuid):
     return xmlrpcCleanup(
         ComputerLocationManager().getLocationParentPath(uuid))