Beispiel #1
0
    def process_ip(self, dbag):
        for ip in self.qFile.data["ip_address"]:
            # Find the right device we should use to configure the ip address
            # vif_mac_address is a mac address per ip-address, based on the mac address of the device
            # The original macaddress of the device is sent as device_mac_address, so we will check based
            # on that macaddress.
            if 'device_mac_address' in ip:
                device_name = csHelper.get_device_from_mac_address(
                    ip['device_mac_address'])
                if not device_name:
                    log_message = "Cannot find device while looking for %s. Ignoring for now, it may arrive later.." \
                                  % ip['device_mac_address']
                    logging.warning(log_message)
                    print("Warning! " + log_message)
                else:
                    if ip['vif_mac_address'] != ip['device_mac_address']:
                        log_message = "Found device %s based on macaddress %s so updating databag accordingly. " \
                                      "Ignoring macaddress %s sent by mgt server, as it is not the right one." \
                                      % (device_name, ip['device_mac_address'], ip['vif_mac_address'])
                        ip['vif_mac_address_as_sent_by_mgt_server'] = ip[
                            'vif_mac_address']
                    else:
                        log_message = "The mac address as sent by the management server %s matches the one we found (%s) on device %s so that's good" \
                                      % (ip['vif_mac_address'], ip['device_mac_address'], device_name)
                        logging.info(log_message)

                    logging.warning(log_message)
                    print("[INFO] " + log_message)
                    ip['vif_mac_address'] = ip['device_mac_address']
                    ip['device'] = device_name
                    ip['nic_dev_id'] = device_name.replace("eth", "")
            dbag = cs_ip.merge(dbag, ip)
        return dbag
Beispiel #2
0
    def validate_device_based_on_mac_address(self):
        d_to_merge = self.qFile.data

        mac_address_to_find_device_for = self.get_macaddress_from_databag(
            d_to_merge)
        if not mac_address_to_find_device_for:
            return d_to_merge
        if 'device' not in d_to_merge and 'nic_dev_id' in d_to_merge:
            d_to_merge['device'] = "eth" + str(d_to_merge['nic_dev_id'])
        elif 'device' not in d_to_merge:
            logging.warning(
                "Unable to validate mac_address / device because we couldn't locate the device in the json (need 'device' or 'nic_dev_id' property."
            )
            return d_to_merge

        device_name = csHelper.get_device_from_mac_address(
            mac_address_to_find_device_for)
        if not device_name:
            return d_to_merge
        if device_name != d_to_merge['device']:
            log_message = "Found device %s based on macaddress %s so updating databag accordingly. " \
                          "Ignoring device %s sent by mgt server, as it is not the right one." \
                          % (device_name, mac_address_to_find_device_for, d_to_merge['device'])
            logging.warning(log_message)
            # Keep whatever was sent (for debug purposes)
            if 'device' in d_to_merge:
                d_to_merge['device_as_sent_by_mgtserver'] = d_to_merge[
                    'device']
            if 'dev_id' in d_to_merge:
                d_to_merge['dev_id_as_sent_by_mgtserver'] = d_to_merge[
                    'dev_id']
            # Use the device we found from now on
            d_to_merge['device'] = device_name
        return d_to_merge