Пример #1
0
def getRelationships(instance, relstr='', func=None):
    """get the relationships in CMDB"""
    if instance != getInstance():
        initRelationshipCache(instance)
        setInstance(instance)
    qs = 'type=%s' % str(this.reltypes[relstr])
    return getTableResults(instance, 'cmdb_rel_ci', [], func, qs)
Пример #2
0
def getComputerFCPorts(instance):
    """gets all the WWPN of computer FC ports
     returns a hash where:
       key is the sys_id of the computer
       value is a hash where:
         key is the sys_id of the FC port 
         value is the canonlib-formated WWPN"""
    if instance != getInstance():
        initRelationshipCache(instance)
        setInstance(instance)
    result = {}
    from canonlib import getCanonicalHexFromWWNStr
    qs = 'sysparm_query=provided_byISNOTEMPTY'
    it = getTableResults(instance, 'cmdb_ci_fc_port',
                         ['computer', 'wwpn', 'sys_id'])
    for i in it:
        canonwwpn = getCanonicalHexFromWWNStr(i['wwpn'])
        try:
            csysid = i['computer']['value']
            try:
                result[csysid][i['sys_id']] = canonwwpn
            except KeyError:
                result[csysid] = {i['sys_id']: canonwwpn}
        except:
            pass
    return result
Пример #3
0
def purgeOldPuppetRelationships(instance, datetimet):
    """deletes all relationships created by puppet service account
     that is older than datatimet"""
    if instance != getInstance():
        initRelationshipCache(instance)
        setInstance(instance)
    s = "sys_created_by=puppet^sys_created_on<javascript:gs.dateGenerate('%s','%s')" % datetimet
    import urllib
    qs = 'sysparm_query=%s' % urllib.quote(s, "()'")
    fields = ['sys_id', 'sys_created_on']
    result = {}
    it = getTableResults(instance, 'cmdb_rel_ci', fields, None, qs)
    for i in it:
        deleteRelationship(instance, i['sys_id'])
Пример #4
0
def setRelationship(instance, parent, type_str_val, child, verbose=False):
    if instance != getInstance():
        initRelationshipCache(instance)
        setInstance(instance)

    data = {
        'parent': parent,
        'type': this.reltype[type_str_val],
        'child': child
    }
    if verbose:
        print setDataByJson(instance, 'cmdb_rel_ci', data)
    else:
        setDataByJson(instance, 'cmdb_rel_ci', data)
Пример #5
0
def getPuppetRelationships(instance, relstr=''):
    """get CMDB relationships that were populated by puppet service account"""
    if instance != getInstance():
        initRelationshipCache(instance)
        setInstance(instance)
    qs = 'sys_created_by=puppet'
    fields = ['parent', 'child', 'type']
    result = {}
    it = getTableResults(instance, 'cmdb_rel_ci', fields, None, qs)
    for i in it:
        relResultHelper(i, result)
    if relstr:
        try:
            typesysid = this.reltypes[relstr]
            return result[typesysid]
        except:
            pass
    return result
Пример #6
0
def getClusters(instance):
    """get the sys_ids of VMWare clusters"""
    if instance != getInstance():
        initRelationshipCache(instance)
        setInstance(instance)
    vccluster = set(
        map(lambda e: e['sys_id'],
            getTableResults(instance, 'cmdb_ci_vcenter_cluster', ['sys_id'])))
    result = {}
    typesysid = this.reltypes[u'Members::Member of']
    qs = 'type=%s' % str(typesysid)
    fields = ['parent', 'child', 'type']
    for i in getTableResults(instance, 'cmdb_rel_ci', fields, None, qs):
        relResultHelper(i, result, True)
    #for k,v in result[typesysid].items():
    #  print k,"len",len(v)
    return dict(
        filter(lambda (k, v): k in vccluster, result[typesysid].items()))