Exemple #1
0
 def get_ci(self,ci):
     print("Get from redfish")
     import redfish
     
     print(ci.ip_mgmt + " - " + ci.login + " - " + ci.password)
     
     #remote_mgmt = redfish.connect(ci.ip_mgmt, ci.login, ci.password, verify_cert=False)
     remote_mgmt = redfish.connect(ci.ip_mgmt, ci.login, ci.password, simulator=True, enforceSSL=False)
                                    
     ci.ci_type = remote_mgmt.Systems.systems_list[0].get_parameter("@odata.type")
     ci.data = remote_mgmt.Systems.systems_list[0].get_parameters()
             
     #print("Redfish API version : {} \n".format(remote_mgmt.get_api_version()))       
     return True
        config = json.load(json_data)
        json_data.close()
except IOError as e:
    print("Please create a json configuration file")
    print(e)
    sys.exit(1)

URL = config["Managers"]["default"]["url"]
USER_NAME = config["Managers"]["default"]["login"]
PASSWORD = config["Managers"]["default"]["password"]

''' remoteMgmt is a redfish.RedfishConnection object '''
try:
    remote_mgmt = redfish.connect(URL,
                                  USER_NAME,
                                  PASSWORD,
                                  simulator=True,
                                  enforceSSL=False)
except redfish.exception.RedfishException as e:
    sys.stderr.write(e.message)
    sys.stderr.write(e.advices)
    sys.exit(1)


print("Redfish API version : {} \n".format(remote_mgmt.get_api_version()))
print("UUID : {} \n".format(remote_mgmt.Root.get_api_UUID()))
print("System 1 :\n")
print("Bios version : {}\n".format(
    remote_mgmt.Systems.systems_dict["1"].get_bios_version()))
print("System 2 :\n")
print("Bios version : {}\n".format(
    with open(HOME + "/.redfish/inventory") as json_data:
        config = json.load(json_data)
        json_data.close()
except IOError as e:
    print("Please create a json configuration file")
    print(e)
    sys.exit(1)

URL = config["Managers"]["default"]["url"]
USER_NAME = config["Managers"]["default"]["login"]
PASSWORD = config["Managers"]["default"]["password"]
''' remoteMgmt is a redfish.RedfishConnection object '''
try:
    remote_mgmt = redfish.connect(URL,
                                  USER_NAME,
                                  PASSWORD,
                                  simulator=True,
                                  enforceSSL=False)
except redfish.exception.RedfishException as e:
    sys.stderr.write(e.message)
    sys.stderr.write(e.advices)
    sys.exit(1)

print("Redfish API version : {} \n".format(remote_mgmt.get_api_version()))
print("UUID : {} \n".format(remote_mgmt.Root.get_api_UUID()))
print("System 1 :\n")
print("Bios version : {}\n".format(
    remote_mgmt.Systems.systems_dict["1"].get_bios_version()))
print("System 2 :\n")
print("Bios version : {}\n".format(
    remote_mgmt.Systems.systems_dict["2"].get_parameter("SerialNumber")))
        config = json.load(json_data)
        json_data.close()
except IOError as e:
    print("Please create a json configuration file")
    print(e)
    sys.exit(1)

URL = config["Managers"]["default"]["url"]
USER_NAME = config["Managers"]["default"]["login"]
PASSWORD = config["Managers"]["default"]["password"]

''' remote_mgmt is a redfish.RedfishConnection object '''
try:
    remote_mgmt = redfish.connect(URL,
                                  USER_NAME,
                                  PASSWORD,
                                  simulator=False,
                                  verify_cert=False)
except redfish.exception.RedfishException as e:
    sys.stderr.write(str(e.message))
    sys.stderr.write(str(e.advices))
    sys.exit(1)

print("Redfish API version : %s \n" % remote_mgmt.get_api_version())

# Uncomment following line to reset the blade !!!
# remote_mgmt.Systems.systems_dict["1"].reset_system()

print("Bios version : {}\n".format(
    remote_mgmt.Systems.systems_dict["1"].get_bios_version()))
print("Serial Number : {}\n".format(
Exemple #5
0
    def send_data(self):
        print("Started sending data loop")
        # Infinite loop
        
        # For each switch found in the JSON data ,
        # generate sensor uuid from has of seed sensor uuids + cmc + guid
        # each is a device
        """"for switch in query_data["Switch"]:
            switch_guid = str(switch["Node_GUID"])

            # set device UUID from registration
            device_uuid[cmc][switch_guid] = self.myDeviceSensorUUIDsMap[switch_guid]["uuid"]
            
            sensor_uuid[cmc][switch_guid] = {}

            for ibmetric in ibmetrics:

                # set sensor UUIID from registration
                sensor_uuid[cmc][switch_guid][ibmetric] = self.myDeviceSensorUUIDsMap[switch_guid]["sensorUuids"][switch_guid+"-"+ibmetric]
                
                if ibmetric in ["SymbolErrorCounter", "PortXmitData"]:
                    print(
                        switch_guid+"-"+ibmetric
                        + ":"
                        + str(sensor_uuid[cmc][switch_guid][ibmetric])
                    )
        """
        
        # baremetal nodes have python 3.6 hence we don't have time_ns. Here time is a floating point number
        self.timet0 = time.time()
        while True:
            connected = False
            
            if self.myAgent_redfish_acc == "":
                simulator = True
                enforceSSL = False
            else:
                simulator = False
                enforceSSL = True
                
            while not connected:
                try:
                    redfish.config.TORTILLADEBUG = False
                    requests.packages.urllib3.disable_warnings()
                    redfish.config.CONSOLE_LOGGER_LEVEL = logging.CRITICAL
                    redfish_data = redfish.connect(self.myAgent_redfish_ip,
                                                self.myAgent_redfish_acc,
                                                self.myAgent_redfish_pwd,
                                                verify_cert=False,
                                                simulator=simulator,
                                                enforceSSL=enforceSSL)
                    connected = True
                    timestamp = int(round(time.time() * 1000))
                    # reset record_list for each new redfish query
                    record_list = []
                except redfish.exception.RedfishException as e:
                        sys.stderr.write(str(e.message))
                        sys.stderr.write(str(e.advices))
                        print("Sleeping " + str(self.sleepLoopTime) + " seconds")
                        time.sleep(self.sleepLoopTime)
                        continue
        
            for chassis in redfish_data.Chassis.chassis_dict.values():
                                
                chassisName = chassis.get_name()
                
                #{'60dcdc0b-9ee7-447e-9aee-1944e4a6bafe-Computer System Chassis': {'uuid': UUID('637d4053-e962-4687-a8d1-87fd352dcc0e'), 'sensorUuids': {'60dcdc0b-9ee7-447e-9aee-1944e4a6bafe-Computer System Chassis-18-VR P1 Mem 1': UUID('947e869b-e883-4359-b989-59045cc63b77'), 
                chassis_uuid = self.myDeviceSensorUUIDsMap[str(self.myAgent_uuid) + "-" + str(chassisName)]["uuid"]
                
                for sensor, value in chassis.thermal.get_temperatures().items():
                    sensorName = str(self.myAgent_uuid) + "-" + str(chassisName) + "-" + str(sensor)                    
                    sensor_uuid = self.myDeviceSensorUUIDsMap[str(self.myAgent_uuid) + "-" + str(chassisName)]["sensorUuids"][sensorName]
                    record = {}
                    
                    record["sensorUuid"] = sensor_uuid
                    record["sensorValue"] = float(value)
                    record["timestamp"] = timestamp
                    
                    #print(record)
                    record_list.append(record)

                for sensor, value in chassis.thermal.get_fans().items():
                    sensorName = str(self.myAgent_uuid) + "-" + str(chassisName) + "-" + str(sensor)                    
                    sensor_uuid = self.myDeviceSensorUUIDsMap[str(self.myAgent_uuid) + "-" + str(chassisName)]["sensorUuids"][sensorName]
                    
                    valuelist = value.split(None, 1)
                    value = valuelist[0]
                                                
                    record = {}
                    record["sensorUuid"] = sensor_uuid
                    record["sensorValue"] = float(value)
                    record["timestamp"] = timestamp
                    
                    #print(record)
                    record_list.append(record)
            
            # send messages
            self.mqtt_send_triplet_batch(
                    self.myAgent_send_ts_data_topic,
                    record_list,
                    self.sendNumberOfMessages,
                    self.batch_size,
                    self.myAgent_uuid,
                    self.timet0
                )
        
            # Infinite loop
            time.sleep(self.sleepLoopTime)
Exemple #6
0
    def create_my_device_map(self):
        print("Creating my device map")
        
        # store for final device and sensor map according to InfinibandAgent.json syntax
        deviceMap = {}
        
        deviceMap["uuid"] = str(self.myAgent_uuid)
        deviceMap["devices"] = []
        
        # read device json template
        with open(self.device_json_dir + "/iLODevice.json", "r") as f:
                deviceTemplate = json.load(f)
        
        # set my informations in device/sensor map
        # go through high level devices and add each switch as device (deviceUid = myAgentUuid + device guid
        if self.myAgent_redfish_acc == "":
            simulator = True
            enforceSSL = False
        else:
            simulator = False
            enforceSSL = True
        try:

            redfish.config.TORTILLADEBUG = False
            requests.packages.urllib3.disable_warnings()
            redfish.config.CONSOLE_LOGGER_LEVEL = logging.CRITICAL
            redfish_data = redfish.connect(self.myAgent_redfish_ip,
                                        self.myAgent_redfish_acc,
                                        self.myAgent_redfish_pwd,
                                        verify_cert=False,
                                        simulator=simulator,
                                        enforceSSL=enforceSSL)
        except redfish.exception.RedfishException as e:
            sys.stderr.write(str(e.message))
            sys.stderr.write(str(e.advices))
            print("Sleeping " + str(self.sleepLoopTime) + " seconds")
            time.sleep(self.sleepLoopTime)
            pass
        
        # assemble sensor information for device
        #"uuid": null, "id": "guid+metricname", "name": "PortSelect", "type": "Counter", "valueRangeMin": 0.0, "valueRangeMax": 255.0, "currentCollectionFrequency": 0.1, "storageTime": 1}
        
        #got through all devices       
        for chassis in redfish_data.Chassis.chassis_dict.values():
            # reset deviceTemplate for each new device
            deviceTemplate = {}
            
            chassisName = chassis.get_name()
            deviceTemplate["uuid"] = None
            deviceTemplate["id"] = str(self.myAgent_uuid) + "-" + str(chassisName)
            deviceTemplate["name"] = str(chassisName)
            deviceTemplate["type"] = "Redfish iLO"
            deviceTemplate["location"] = "unknown"
            deviceTemplate["sensors"] = []
            
            # assemble sensor information for device                 
            for sensorName, value in chassis.thermal.get_temperatures().items():
                # reset sensorTemplate for each new sensor
                sensorTemplate = {}
                
                sensorTemplate["uuid"] = None
                sensorTemplate["id"] =  str(self.myAgent_uuid) + "-" + str(chassisName) + "-" + str(sensorName)
                sensorTemplate["name"] = str(sensorName) 
                sensorTemplate["type"] = "Counter"
                sensorTemplate["valueRangeMin"] = 0.0 
                sensorTemplate["valueRangeMax"] = 100.0
                sensorTemplate["currentCollectionFrequency"] = 1.0
                sensorTemplate["storageTime"] = 1             

                deviceTemplate["sensors"].append(sensorTemplate)
            
            # assemble sensor information for device
            for sensorName, value in chassis.thermal.get_fans().items():
                # reset sensorTemplate for each new sensor
                sensorTemplate = {}
                
                sensorTemplate["uuid"] = None
                sensorTemplate["id"] =  str(self.myAgent_uuid) + "-" + str(chassisName) + "-" + str(sensorName)
                sensorTemplate["name"] = str(sensorName) 
                sensorTemplate["type"] = "Counter"
                sensorTemplate["valueRangeMin"] = 0.0 
                sensorTemplate["valueRangeMax"] = 100.0
                sensorTemplate["currentCollectionFrequency"] = 1.0
                sensorTemplate["storageTime"] = 1             

                deviceTemplate["sensors"].append(sensorTemplate)
            
            # assemble sensor information for device
            deviceMap["devices"].append(deviceTemplate)
            
        if self.myAgent_debug:
            print("Finished creating my device map")
            print(deviceMap)
        
        return deviceMap
Exemple #7
0
    with open(HOME + "/.redfish/inventory") as json_data:
        config = json.load(json_data)
        json_data.close()
except IOError as e:
    print("Please create a json configuration file")
    print(e)
    sys.exit(1)

URL = config["Managers"]["default"]["url"]
USER_NAME = config["Managers"]["default"]["login"]
PASSWORD = config["Managers"]["default"]["password"]
''' remote_mgmt is a redfish.RedfishConnection object '''
try:
    remote_mgmt = redfish.connect(URL,
                                  USER_NAME,
                                  PASSWORD,
                                  simulator=False,
                                  verify_cert=False)
except redfish.exception.RedfishException as e:
    sys.stderr.write(str(e.message))
    sys.stderr.write(str(e.advices))
    sys.exit(1)

print("Redfish API version : %s \n" % remote_mgmt.get_api_version())

# Uncomment following line to reset the blade !!!
# remote_mgmt.Systems.systems_dict["1"].reset_system()

print("Bios version : {}\n".format(
    remote_mgmt.Systems.systems_dict["1"].get_bios_version()))
print("Serial Number : {}\n".format(
Exemple #8
0
    with open(sys.argv[4], 'a') as f:
        f.write(str(text) + "\n\n")


url = "https://{}/rest/v1/".format(sys.argv[1])
login = sys.argv[2]
password = sys.argv[3]

with open(sys.argv[4], 'w') as f:
    f.write("Querying: " + url + " - " + login + " - " + password + "\n")
    f.write(str(datetime.datetime.now()) + "\n")

try:
    remote_mgmt = redfish.connect(url,
                                  login,
                                  password,
                                  verify_cert=False,
                                  enforceSSL=False)
except Exception as e:
    log(e)
    raise

log("Redfish API version: {}".format(remote_mgmt.get_api_version()))

chassises = remote_mgmt.Chassis
for chassis in chassises.chassis_dict.items():
    log("Data for Chassis {}".format(chassis[0]))
    log(chassis[1].data)

    try:
        power = chassis[1].power