コード例 #1
0
ファイル: __init__.py プロジェクト: resonancellc/mmc-1
 def getContext(self):
     s = SecurityContext()
     s.userid = self.userid
     s.locationsCount = ComputerLocationManager().getLocationsCount()
     s.userids = ComputerLocationManager().getUsersInSameLocations(self.userid)
     s.filterType = "mine"
     return s
コード例 #2
0
ファイル: __init__.py プロジェクト: resonancellc/pulse2
def getLicensesCount(vendor, software, version, valcount=1):
    ctx = SecurityContext()
    ctx.userid = "root"

    def replace_splat(param):
        if '*' in param:
            return param.replace('*', '%')
        return param

    def check_param(param):
        if param == '' or param == '*' or param == '%':
            return None
        return replace_splat(param)

    software = check_param(software)
    vendor = check_param(vendor)
    version = check_param(version)
    if software is None:
        software = '%'
    rr = xmlrpcCleanup(Glpi().getAllSoftwaresImproved(ctx,
                                                      software,
                                                      vendor=vendor,
                                                      version=version,
                                                      count=valcount))
    return rr
コード例 #3
0
ファイル: __init__.py プロジェクト: gnumaniac/pulse
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
コード例 #4
0
ファイル: __init__.py プロジェクト: inkhey/mmc
def get_machines_update_status():
    """
    Get machine update status as a dict as key
    and status string as value.
    commons status values :"unknown","up-to-date","need_update","update_available",
    "update_planned"
    """
    # Creating root context
    ctx = SecurityContext()
    ctx.userid = 'root'

    machines_status = {}
    uuids = []
    # get computer list who returned update
    machines_update = updateDatabase().get_machines()
    # get uuid for all computer
    ComputerList = ComputerManager().getComputersList(ctx, {}).keys()
    uuids = []
    for uuid in ComputerList:
        uuids.append(int(uuid.lower().replace('uuid', '')))
    #get status of all machines
    for uuid in uuids:
        if uuid in machines_update:
            if len(updateDatabase().get_neutral_updates_for_host(uuid)) == 0:
                if len(updateDatabase().get_eligible_updates_for_host(uuid)) == 0:
                    machines_status["UUID" + str(uuid)] = "up-to-date"
                else:
                    machines_status["UUID" + str(uuid)] = "update_planned"
            else:
                machines_status["UUID" + str(uuid)] = "update_available"
        else:
            machines_status["UUID" + str(uuid)] = "unknown"
    return machines_status
コード例 #5
0
ファイル: __init__.py プロジェクト: tekmans/mmc
 def getContext(self):
     s = SecurityContext()
     s.userid = self.userid
     s.locationsCount = ComputerLocationManager().getLocationsCount()
     s.userids = ComputerLocationManager().getUsersInSameLocations(self.userid)
     s.filterType = "mine"
     return s
コード例 #6
0
def getSubscriptionInfo():
    
    # Creating root context
    ctx = SecurityContext()
    ctx.userid = 'root'
    
    # Get all machine count
    count = ComputerManager().getComputerCount(ctx)
    
    # Get license max_machines
    out, err, ec = runInShell('/usr/sbin/pulse-licensed -G /etc/pulse-licensing/installation_id -l /etc/pulse-licensing/license.dat -p /etc/pulse-licensing/license -i')
    
    if ec == 0:
        data = loads(out)
        for license in data:
            if license['alias'] == 'pulse':
                max_machines = int(license['custon_number'])
                ts_expiration = int(license['licencingtime'])
                break
        else:
            max_machines = 5
    else:
        max_machines = 5
    
    if max_machines == 5:
        ts_expiration = 0

    return [count, max_machines, ts_expiration]
コード例 #7
0
ファイル: __init__.py プロジェクト: neoclust/pulse
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
コード例 #8
0
ファイル: __init__.py プロジェクト: resonancellc/mmc-1
def get_machines_update_status(not_supported=False):
    """
    Get machine update status as a dict as key
    and status string as value.
    commons status values :"not_supported","not_registered",
    "up-to-date","need_update","update_available","update_planned",
    "os_update_disabled".
    The "not_supported" value can be disabled with not_supported param.
    """
    # Creating root context
    ctx = SecurityContext()
    ctx.userid = 'root'

    machines_status = {}
    uuids = []

    # get computer list who returned update
    machines_update = updateDatabase().get_machines()
    # get activated os computers:
    machines_os_enabled = _get_updatable_computers(ctx, activated=True)
    # get disabled os computers:
    machines_os_disabled = _get_updatable_computers(ctx, activated=False)
    # get uuid for all computer
    ComputerList = ComputerManager().getComputersList(ctx, {}).keys()
    uuids = []
    # convert uuid as string number
    for uuid in ComputerList:
        uuids.append(int(uuid.lower().replace('uuid', '')))
    machines_os_enabled = [
        int(uuid.lower().replace('uuid', '')) for uuid in machines_os_enabled
    ]
    machines_os_disabled = [
        int(uuid.lower().replace('uuid', '')) for uuid in machines_os_disabled
    ]
    # get status of all machines
    for uuid in uuids:
        if uuid in machines_os_disabled:
            machines_status["UUID" + str(uuid)] = "os_update_disabled"
        elif uuid in machines_os_enabled:
            if uuid in machines_update:
                # if no neutral update not installed on this machine
                if len(updateDatabase().get_neutral_updates_for_host(uuid,
                                                                     0)) == 0:
                    # if no eligible update
                    if len(updateDatabase().get_eligible_updates_for_host(
                            uuid)) == 0:
                        machines_status["UUID" + str(uuid)] = "up-to-date"
                    else:
                        machines_status["UUID" + str(uuid)] = "update_planned"
                else:
                    machines_status["UUID" + str(uuid)] = "update_available"
            else:
                machines_status["UUID" + str(uuid)] = "not_registered"
        elif not_supported:
            machines_status["UUID" + str(uuid)] = "not_supported"

    return machines_status
コード例 #9
0
ファイル: __init__.py プロジェクト: pruebagit/mmc
def get_machines_update_status(not_supported=False):
    """
    Get machine update status as a dict as key
    and status string as value.
    commons status values :"not_supported","not_registered",
    "up-to-date","need_update","update_available","update_planned",
    "os_update_disabled".
    The "not_supported" value can be disabled with not_supported param.
    """
    # Creating root context
    ctx = SecurityContext()
    ctx.userid = 'root'

    machines_status = {}
    uuids = []

    # get computer list who returned update
    machines_update = updateDatabase().get_machines()
    # get activated os computers:
    machines_os_enabled = _get_updatable_computers(ctx, activated=True)
    # get disabled os computers:
    machines_os_disabled = _get_updatable_computers(ctx, activated=False)
    # get uuid for all computer
    ComputerList = ComputerManager().getComputersList(ctx, {}).keys()
    uuids = []
    # convert uuid as string number
    for uuid in ComputerList:
        uuids.append(int(uuid.lower().replace('uuid', '')))
    machines_os_enabled = [
        int(uuid.lower().replace('uuid', '')) for uuid in machines_os_enabled]
    machines_os_disabled = [
        int(uuid.lower().replace('uuid', '')) for uuid in machines_os_disabled]
    # get status of all machines
    for uuid in uuids:
        if uuid in machines_os_disabled:
            machines_status["UUID" + str(uuid)] = "os_update_disabled"
        elif uuid in machines_os_enabled:
            if uuid in machines_update:
                # if no neutral update not installed on this machine
                if len(updateDatabase().get_neutral_updates_for_host(uuid, 0)) == 0:
                    # if no eligible update
                    if len(updateDatabase().get_eligible_updates_for_host(uuid)) == 0:
                        machines_status["UUID" + str(uuid)] = "up-to-date"
                    else:
                        machines_status["UUID" + str(uuid)] = "update_planned"
                else:
                    machines_status["UUID" + str(uuid)] = "update_available"
            else:
                machines_status["UUID" + str(uuid)] = "not_registered"
        elif not_supported:
            machines_status["UUID" + str(uuid)] = "not_supported"

    return machines_status
コード例 #10
0
def create_update_commands():
    # TODO: ensure that this method is called by taskmanager
    # and not directly by XMLRPC

    # Creating root context
    ctx = SecurityContext()
    ctx.userid = 'root'
    # Get active computer manager
    computer_manager = ComputerManager().getManagerName()

    if computer_manager == 'inventory':
        dyngroup_pattern = '%d==inventory::Hardware/OperatingSystem==%s'
    elif computer_manager == 'glpi':
        dyngroup_pattern = '%d==glpi::Operating system==%s'
    else:
        logging.getLogger().error(
            'Update module: Unsupported computer manager %s' %
            computer_manager)
        return False

    # Get all enabled os_classes
    os_classes = updateDatabase().get_os_classes({'filters': {'enabled': 1}})

    # Create update command for enabled os_classes
    for os_class in os_classes['data']:

        patterns = os_class['pattern'].split('||')
        request = []
        equ_bool = []

        for i in xrange(len(patterns)):
            request.append(dyngroup_pattern % (i + 1, patterns[i]))
            equ_bool.append(str(i + 1))

        request = '||'.join(request)
        equ_bool = 'OR(%s)' % ','.join(equ_bool)

        targets = ComputerManager().getComputersList(ctx, {
            'request': request,
            'equ_bool': equ_bool
        }).keys()

        # Fetching all targets
        for uuid in targets:
            machine_id = int(uuid.lower().replace('uuid', ''))
            updates = updateDatabase().get_eligible_updates_for_host(
                machine_id)

            update_list = [update['uuid'] for update in updates]

            # Create update command for this host with update_list
            create_update_command(ctx, [uuid], update_list)
    return True
コード例 #11
0
ファイル: __init__.py プロジェクト: inkhey/mmc
def create_update_commands():
    # TODO: ensure that this method is called by taskmanager
    # and not directly by XMLRPC

    # Creating root context
    ctx = SecurityContext()
    ctx.userid = 'root'
    # Get active computer manager
    computer_manager = ComputerManager().getManagerName()

    if computer_manager == 'inventory':
        dyngroup_pattern = '%d==inventory::Hardware/OperatingSystem==%s'
    elif computer_manager == 'glpi':
        dyngroup_pattern = '%d==glpi::Operating system==%s'
    else:
        logging.getLogger().error(
            'Update module: Unsupported computer manager %s' %
            computer_manager)
        return False

    # Get all enabled os_classes
    os_classes = updateDatabase().get_os_classes({'filters': {'enabled': 1}})

    # Create update command for enabled os_classes
    for os_class in os_classes['data']:

        patterns = os_class['pattern'].split('||')
        request = []
        equ_bool = []

        for i in xrange(len(patterns)):
            request.append(dyngroup_pattern % (i + 1, patterns[i]))
            equ_bool.append(str(i + 1))

        request = '||'.join(request)
        equ_bool = 'OR(%s)' % ','.join(equ_bool)

        targets = ComputerManager().getComputersList(
            ctx, {
                'request': request, 'equ_bool': equ_bool}).keys()

        # Fetching all targets
        for uuid in targets:
            machine_id = int(uuid.lower().replace('uuid', ''))
            updates = updateDatabase().get_eligible_updates_for_host(
                machine_id)

            update_list = [update['uuid'] for update in updates]

            # Create update command for this host with update_list
            create_update_command(ctx, [uuid], update_list)
    return True
コード例 #12
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
コード例 #13
0
ファイル: database.py プロジェクト: resonancellc/mmc-1
 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
コード例 #14
0
ファイル: __init__.py プロジェクト: resonancellc/mmc-1
def create_update_commands():
    # TODO: ensure that this method is called by taskmanager
    # and not directly by XMLRPC

    # Creating root context
    ctx = SecurityContext()
    ctx.userid = 'root'
    targets = _get_updatable_computers(ctx)
    # Fetching all targets
    for uuid in targets:
        machine_id = int(uuid.lower().replace('uuid', ''))
        updates = updateDatabase().get_eligible_updates_for_host(machine_id)

        update_list = [update['uuid'] for update in updates]

        # Create update command for this host with update_list
        create_update_command(ctx, [uuid], update_list)
    return True
コード例 #15
0
ファイル: __init__.py プロジェクト: pruebagit/mmc
def create_update_commands():
    # TODO: ensure that this method is called by taskmanager
    # and not directly by XMLRPC

    # Creating root context
    ctx = SecurityContext()
    ctx.userid = 'root'
    targets = _get_updatable_computers(ctx)
    # Fetching all targets
    for uuid in targets:
        machine_id = int(uuid.lower().replace('uuid', ''))
        updates = updateDatabase().get_eligible_updates_for_host(
            machine_id)

        update_list = [update['uuid'] for update in updates]

        # Create update command for this host with update_list
        create_update_command(ctx, [uuid], update_list)
    return True
コード例 #16
0
ファイル: __init__.py プロジェクト: pruebagit/mmc
def _get_updates_for_group(params):
    """
    Get updates from uuids list if params['uuids'] is a correct list of uuid
    and from group if params['gid'] is a correct group id
    """
    if 'gid' in params:
        params['uuids'] = []
        # Creating root context
        ctx = SecurityContext()
        ctx.userid = 'root'

        # get uuid for all computer of this group
        ComputerList = ComputerGroupManager().get_group_results(
            ctx, params['gid'], 0, -1, {})
        for uuid in ComputerList:
            params['uuids'].append(int(uuid.lower().replace('uuid', '')))

    # get updates for this group
    updates = updateDatabase().get_updates_for_group(params)
    return updates
コード例 #17
0
ファイル: __init__.py プロジェクト: resonancellc/mmc-1
def _get_updates_for_group(params):
    """
    Get updates from uuids list if params['uuids'] is a correct list of uuid
    and from group if params['gid'] is a correct group id
    """
    if 'gid' in params:
        params['uuids'] = []
        # Creating root context
        ctx = SecurityContext()
        ctx.userid = 'root'

        # get uuid for all computer of this group
        ComputerList = ComputerGroupManager().get_group_results(
            ctx, params['gid'], 0, -1, {})
        for uuid in ComputerList:
            params['uuids'].append(int(uuid.lower().replace('uuid', '')))

    # get updates for this group
    updates = updateDatabase().get_updates_for_group(params)
    return updates
コード例 #18
0
ファイル: __init__.py プロジェクト: AnatomicJC/mmc
def getLicensesCount(vendor, software, version):
    ctx = SecurityContext()
    ctx.userid = "root"

    def replace_splat(param):
        if '*' in param:
            return param.replace('*', '%')
        return param

    def check_param(param):
        if param == '' or param == '*' or param == '%':
            return None
        return replace_splat(param)

    software = check_param(software)
    vendor = check_param(vendor)
    version = check_param(version)
    if software is None:
        software = '%'
    return xmlrpcCleanup(Inventory().getAllSoftwaresImproved(ctx,
                                                     software,
                                                     vendor=vendor,
                                                     version=version,
                                                     count=1))
コード例 #19
0
ファイル: __init__.py プロジェクト: zentyal/mmc
 def getContext(self):
     s = SecurityContext()
     s.userid = self.userid
     return s
コード例 #20
0
ファイル: __init__.py プロジェクト: zentyal/mmc
 def getContext(self, user='******'):
         s = SecurityContext()
         s.userid = user
         s.userdn = LdapUserGroupControl().searchUserDN(s.userid)
         return s
コード例 #21
0
ファイル: __init__.py プロジェクト: jkerihuel/mmc
 def getContext(self):
     s = SecurityContext()
     s.userid = self.userid
     s.userdn = LdapUserGroupControl().searchUserDN(self.userid)
     return s
コード例 #22
0
ファイル: __init__.py プロジェクト: tekmans/mmc
 def getContext(self):
     s = SecurityContext()
     s.userid = self.userid
     s.locations = Inventory().getUserLocations(s.userid)
     s.locationsid = map(lambda e: e.id, s.locations)
     return s
コード例 #23
0
 def getContext(self):
     s = SecurityContext()
     s.userid = self.userid
     s.locations = Inventory().getUserLocations(s.userid)
     s.locationsid = map(lambda e: e.id, s.locations)
     return s
コード例 #24
0
ファイル: __init__.py プロジェクト: resonancellc/pulse2
 def getContext(self):
     s = SecurityContext()
     s.userid = self.userid
     return s
コード例 #25
0
ファイル: __init__.py プロジェクト: gnumaniac/pulse
 def getContext(self):
     s = SecurityContext()
     s.userid = self.userid
     s.userdn = LdapUserGroupControl().searchUserDN(self.userid)
     return s
コード例 #26
0
 def getContext(self, user='******'):
     s = SecurityContext()
     s.userid = user
     s.userdn = LdapUserGroupControl().searchUserDN(s.userid)
     return s