Exemple #1
0
 def _get_nics(specs, dbase):
     nics = []
     info = {}
     eth_names = []
     copy = list(specs)
     # first lookup all the network interface names
     while matcher.match_spec(('network', '$eth', '$key', '$value'),
                              copy, info):
         if info['eth'] not in eth_names:
             eth_names.append(info['eth'])
         info = {}
     # then lookup if matching by mac address is used to store the
     # mac address
     for name in eth_names:
         if matcher.match_spec(('network', name, 'serial', '$mac'),
                               specs, info):
             if 'mac' in info:
                 if info['mac'][0:2] == '$$':
                     var = info['mac'][2:]
                     if var in dbase:
                         nics.append({"mac": dbase[var]})
                     else:
                         print('cmdb setting %s not found' % var)
                 else:
                     nics.append({"mac": info['mac']})
             info = {}
     return nics
Exemple #2
0
 def _get_nics(specs, dbase):
     nics = []
     info = {}
     eth_names = []
     copy = list(specs)
     # first lookup all the network interface names
     while matcher.match_spec(('network', '$eth', '$key', '$value'),
                              copy, info):
         if info['eth'] not in eth_names:
             eth_names.append(info['eth'])
         info = {}
     # then lookup if matching by mac address is used to store the
     # mac address
     for name in eth_names:
         if matcher.match_spec(('network', name, 'serial', '$mac'),
                               specs, info):
             if 'mac' in info:
                 if info['mac'][0:2] == '$$':
                     var = info['mac'][2:]
                     if var in dbase:
                         nics.append({"mac": dbase[var]})
                     else:
                         print('cmdb setting %s not found' % var)
                 else:
                     nics.append({"mac": info['mac']})
             info = {}
     return nics
Exemple #3
0
 def _get_value(lines, spec, key):
     info = {}
     if (matcher.match_spec(spec, lines, info)
             and key in info
             and info[key][0] != '$'):
         return int(info[key])
     return None
Exemple #4
0
 def _get_disks(specs):
     disks = []
     info = {}
     while matcher.match_spec(('disk', '$disk', 'size', '$gb'),
                              specs, info):
         if info['gb'].startswith("gt"):
             size = int(info['gb'][3:-1]) + 1
         elif info['gb'].startswith("ge"):
             size = int(info['gb'][3:-1])
         elif info['gb'].startswith("lt"):
             size = int(info['gb'][3:-1]) - 1
         elif info['gb'].startswith("le"):
             size = int(info['gb'][3:-1])
         else:
             size = info['gb']
         disks_size = "%sGi" % size
         disks.append({"size": disks_size})
         info = {}
     return disks
Exemple #5
0
 def _get_disks(specs):
     disks = []
     info = {}
     while matcher.match_spec(('disk', '$disk', 'size', '$gb'),
                              specs, info):
         if info['gb'].startswith("gt"):
             size = int(info['gb'][3:-1]) + 1
         elif info['gb'].startswith("ge"):
             size = int(info['gb'][3:-1])
         elif info['gb'].startswith("lt"):
             size = int(info['gb'][3:-1]) - 1
         elif info['gb'].startswith("le"):
             size = int(info['gb'][3:-1])
         else:
             size = info['gb']
         disks_size = "%sGi" % size
         disks.append({"size": disks_size})
         info = {}
     return disks
Exemple #6
0
def generate_filename_and_macs(items):
    '''Generate a file name for a hardware using DMI information
    (product name and version) then if the DMI serial number is
    available we use it unless we lookup the first mac address.
    As a result, we do have a filename like :

    <dmi_product_name>-<dmi_product_version>-{dmi_serial_num|mac_address}'''

    # Duplicate items as it will be modified by match_* functions
    hw_items = list(items)
    sysvars = {}
    sysvars['sysname'] = ''

    matcher.match_spec(('system', 'product', 'name', '$sysprodname'), hw_items,
                       sysvars)
    if 'sysprodname' in sysvars:
        sysvars['sysname'] = re.sub(r'\W+', '', sysvars['sysprodname']) + '-'

    matcher.match_spec(('system', 'product', 'vendor', '$sysprodvendor'),
                       hw_items, sysvars)
    if 'sysprodvendor' in sysvars:
        sysvars['sysname'] += re.sub(r'\W+', '', sysvars['sysprodvendor']) + \
            '-'

    matcher.match_spec(('system', 'product', 'serial', '$sysserial'), hw_items,
                       sysvars)
    # Let's use any existing DMI serial number or take the first mac address
    if 'sysserial' in sysvars:
        sysvars['sysname'] += re.sub(r'\W+', '', sysvars['sysserial']) + '-'

    # we always need to have the mac addresses for pxemngr
    if matcher.match_multiple(hw_items,
                              ('network', '$eth', 'serial', '$serial'),
                              sysvars):
        if 'sysserial' not in sysvars:
            sysvars['sysname'] += sysvars['serial'][0].replace(':', '-')
    else:
        log('unable to detect network macs')

    return sysvars
Exemple #7
0
def generate_filename_and_macs(items):
    '''Generate a file name for a hardware using DMI information
    (product name and version) then if the DMI serial number is
    available we use it unless we lookup the first mac address.
    As a result, we do have a filename like :

    <dmi_product_name>-<dmi_product_version>-{dmi_serial_num|mac_address}'''

    # Duplicate items as it will be modified by match_* functions
    hw_items = list(items)
    sysvars = {}
    sysvars['sysname'] = ''

    matcher.match_spec(('system', 'product', 'name', '$sysprodname'),
                       hw_items, sysvars)
    if 'sysprodname' in sysvars:
        sysvars['sysname'] = re.sub(r'\W+', '', sysvars['sysprodname']) + '-'

    matcher.match_spec(('system', 'product', 'vendor', '$sysprodvendor'),
                       hw_items, sysvars)
    if 'sysprodvendor' in sysvars:
        sysvars['sysname'] += re.sub(r'\W+', '', sysvars['sysprodvendor']) + \
            '-'

    matcher.match_spec(('system', 'product', 'serial', '$sysserial'),
                       hw_items, sysvars)
    # Let's use any existing DMI serial number or take the first mac address
    if 'sysserial' in sysvars:
        sysvars['sysname'] += re.sub(r'\W+', '', sysvars['sysserial']) + '-'

    # we always need to have the mac addresses for pxemngr
    if matcher.match_multiple(hw_items,
                              ('network', '$eth', 'serial', '$serial'),
                              sysvars):
        if 'sysserial' not in sysvars:
            sysvars['sysname'] += sysvars['serial'][0].replace(':', '-')
    else:
        log('unable to detect network macs')

    return sysvars
Exemple #8
0
 def test_var(self):
     lines = [('disk', '1I:1:1', 'size', '1000GB')]
     spec = ('disk', '$disk8', 'size', '1000GB')
     arr = {}
     self.assertTrue(matcher.match_spec(spec, lines, arr))
     self.assertEqual(arr, {'disk8': '1I:1:1'})
Exemple #9
0
 def test_not_equal(self):
     lines = [('system', 'product', 'serial', 'CZJ31402CD')]
     spec = ('system', 'product', 'serial', 'CZJ31402CE')
     arr = {}
     self.assertFalse(matcher.match_spec(spec, lines, arr))
Exemple #10
0
 def test_var(self):
     lines = [('disk', '1I:1:1', 'size', '1000GB')]
     spec = ('disk', '$disk8', 'size', '1000GB')
     arr = {}
     self.assertTrue(matcher.match_spec(spec, lines, arr))
     self.assertEqual(arr, {'disk8': '1I:1:1'})
Exemple #11
0
 def test_not_equal(self):
     lines = [('system', 'product', 'serial', 'CZJ31402CD')]
     spec = ('system', 'product', 'serial', 'CZJ31402CE')
     arr = {}
     self.assertFalse(matcher.match_spec(spec, lines, arr))
Exemple #12
0
 def _get_value(lines, spec, key):
     info = {}
     if (matcher.match_spec(spec, lines, info) and key in info and info[key][0] != '$'):
         return int(info[key])
     return None