def update(hostname, port, path): from kinetic.admin import AdminClient ac = None try: ac = AdminClient(hostname,port) ac.connect() except: LOG.error("Failed to connect to drive at {0}:{1}".format(hostname,port)) return data = '' try: f = open(path) chunk = 'x' while chunk: chunk = f.read(4096) data += chunk LOG.debug("Read: " + str(len(data))) except: LOG.error("Failed to read update binary at {0}.".format(path)) return LOG.info("Firmware read, Size={0}".format(len(data))) ac.updateFirmware(data) LOG.info("Firmware update sent to drive.") LOG.warn('Warning: Drives are currently rebooting. ' 'Do NOT power off drives or run any other scripts at this time. ' 'Doing so may cause irreversible failure to the drives. ' 'This process can take several minutes.')
def discover(base, timeout, drives_path): current = 1 drives = {} if '.' in base and not base.endswith('.'): base += '.' while current < 255: try: address = base + str(current) c = AdminClient(address, connect_timeout=timeout) config = c.getLog([3]).configuration LOG.info("Discovered a drive at {0} (SN={1})" .format(address, config.serialNumber)) if config.serialNumber in drives: drives[config.serialNumber].availableAt.append(address) else: drives[config.serialNumber] = DiscoveredDrive(config, address) except: pass current += 1 with open(drives_path,'w+') as f: for sn, d in drives.iteritems(): LOG.info("Drive with SN={0} (Version={2}) available at {1}" .format(sn, d.availableAt, d.config.version)) f.write(d.availableAt[0] + "\n") LOG.info("Discovered {0} drives.".format(len(drives)))